Browse Source

ECPair: lazily calculate Q

hk-custom-address
Daniel Cousens 10 years ago
parent
commit
31832293dd
  1. 15
      src/ecpair.js

15
src/ecpair.js

@ -34,19 +34,28 @@ function ECPair (d, Q, options) {
assert(d.compareTo(ECPair.curve.n) < 0, 'Private key must be less than the curve order') assert(d.compareTo(ECPair.curve.n) < 0, 'Private key must be less than the curve order')
assert(!Q, 'Unexpected publicKey parameter') assert(!Q, 'Unexpected publicKey parameter')
Q = ECPair.curve.G.multiply(d) this.d = d
// enforce Q is a public key if no private key given // enforce Q is a public key if no private key given
} else { } else {
typeForce('Point', Q) typeForce('Point', Q)
this.__Q = Q
} }
this.compressed = compressed this.compressed = compressed
this.d = d
this.Q = Q
this.network = network this.network = network
} }
Object.defineProperty(ECPair.prototype, 'Q', {
get: function() {
if (!this.__Q && this.d) {
this.__Q = ECPair.curve.G.multiply(this.d)
}
return this.__Q
}
})
// Public access to secp256k1 curve // Public access to secp256k1 curve
ECPair.curve = ecurve.getCurveByName('secp256k1') ECPair.curve = ecurve.getCurveByName('secp256k1')

Loading…
Cancel
Save