Skip to content

Commit 3183229

Browse files
committed
ECPair: lazily calculate Q
1 parent 7559ee8 commit 3183229

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/ecpair.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,28 @@ function ECPair (d, Q, options) {
3434
assert(d.compareTo(ECPair.curve.n) < 0, 'Private key must be less than the curve order')
3535

3636
assert(!Q, 'Unexpected publicKey parameter')
37-
Q = ECPair.curve.G.multiply(d)
37+
this.d = d
3838

3939
// enforce Q is a public key if no private key given
4040
} else {
4141
typeForce('Point', Q)
42+
this.__Q = Q
4243
}
4344

4445
this.compressed = compressed
45-
this.d = d
46-
this.Q = Q
4746
this.network = network
4847
}
4948

49+
Object.defineProperty(ECPair.prototype, 'Q', {
50+
get: function() {
51+
if (!this.__Q && this.d) {
52+
this.__Q = ECPair.curve.G.multiply(this.d)
53+
}
54+
55+
return this.__Q
56+
}
57+
})
58+
5059
// Public access to secp256k1 curve
5160
ECPair.curve = ecurve.getCurveByName('secp256k1')
5261

0 commit comments

Comments
 (0)