diff --git a/lib/bip32.js b/lib/bip32.js index 0df8129..9e20626 100644 --- a/lib/bip32.js +++ b/lib/bip32.js @@ -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(); diff --git a/lib/ecdsa.js b/lib/ecdsa.js index 76cd580..38b0ce9 100644 --- a/lib/ecdsa.js +++ b/lib/ecdsa.js @@ -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; diff --git a/lib/key.js b/lib/key.js index cefc341..c48d3f6 100644 --- a/lib/key.js +++ b/lib/key.js @@ -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; }; diff --git a/lib/privkey.js b/lib/privkey.js index 7aa09cd..bed0b23 100644 --- a/lib/privkey.js +++ b/lib/privkey.js @@ -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; diff --git a/lib/pubkey.js b/lib/pubkey.js index ded1060..1199034 100644 --- a/lib/pubkey.js +++ b/lib/pubkey.js @@ -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; diff --git a/lib/signature.js b/lib/signature.js index 451358e..8d911a1 100644 --- a/lib/signature.js +++ b/lib/signature.js @@ -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; };