Browse Source

allow creating objects without using "new"

patch-2
Ryan X. Charles 11 years ago
parent
commit
f6f7a870fb
  1. 4
      lib/bip32.js
  2. 4
      lib/ecdsa.js
  3. 4
      lib/key.js
  4. 4
      lib/privkey.js
  5. 4
      lib/pubkey.js
  6. 4
      lib/signature.js

4
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();

4
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;

4
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;
};

4
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;

4
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;

4
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;
};

Loading…
Cancel
Save