ECPair: lazily calculate Q
This commit is contained in:
parent
7559ee880d
commit
31832293dd
1 changed files with 12 additions and 3 deletions
|
@ -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…
Add table
Reference in a new issue