allow creating objects without using "new"

This commit is contained in:
Ryan X. Charles 2014-08-13 18:55:33 -04:00
parent a2512226f8
commit f6f7a870fb
6 changed files with 18 additions and 6 deletions

View File

@ -8,7 +8,9 @@ var Random = require('./random');
var bn = require('./bn');
var constants = require('./constants');
var BIP32 = function(str) {
var BIP32 = function BIP32(str) {
if (!(this instanceof BIP32))
return new BIP32(str);
if (str === 'testnet' || str === 'mainnet') {
this.version = constants[str].bip32privkey;
this.fromRandom();

View File

@ -6,7 +6,9 @@ var Privkey = require('./privkey');
var Pubkey = require('./pubkey');
var Random = require('./random');
var ECDSA = function(hash, key, sig, k) {
var ECDSA = function ECDSA(hash, key, sig, k) {
if (!(this instanceof ECDSA))
return new ECDSA(hash, key, sig, k);
this.hash = hash;
this.key = key;
this.sig = sig;

View File

@ -5,7 +5,9 @@ var Random = require('./random');
var Bn = require('./bn');
var point = require('./point');
function Key(privkey, pubkey) {
var Key = function Key(privkey, pubkey) {
if (!(this instanceof Key))
return new Key(privkey, pubkey);
this.privkey = privkey;
this.pubkey = pubkey;
};

View File

@ -3,7 +3,9 @@ var point = require('./point');
var constants = require('./constants');
var base58check = require('./base58check');
var Privkey = function(bn, network, compressed) {
var Privkey = function Privkey(bn, network, compressed) {
if (!(this instanceof Privkey))
return new Privkey(bn, network, compressed);
this.bn = bn;
this.network = network;
this.compressed = compressed;

View File

@ -1,7 +1,9 @@
var Point = require('./point');
var bn = require('./bn');
var Pubkey = function(point) {
var Pubkey = function Pubkey(point) {
if (!(this instanceof Pubkey))
return new Pubkey(point);
if (point && !point.getX() && !point.getY())
throw new Error('pubkey: Invalid point');
this.point = point;

View File

@ -1,6 +1,8 @@
var bn = require('./bn');
var Signature = function(r, s) {
var Signature = function Signature(r, s) {
if (!(this instanceof Signature))
return new Signature(r, s);
this.r = r;
this.s = s;
};