-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,13 +237,65 @@ function calcPubKeyRecoveryParam (e, signature, Q) { | |
throw new Error('Unable to find valid recovery factor') | ||
} | ||
|
||
function intAdd (a, b) { | ||
typeforce(types.tuple(types.Buffer, types.Buffer), arguments) | ||
|
||
var A = BigInteger.fromBuffer(a) | ||
var B = BigInteger.fromBuffer(b) | ||
|
||
return A.add(B).toBuffer(32) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dcousens
Author
Contributor
|
||
} | ||
|
||
function intCheck (a) { | ||
typeforce(types.tuple(types.Buffer), arguments) | ||
|
||
var A = BigInteger.fromBuffer(a) | ||
|
||
return A.signum() > 0 && A.compareTo(secp256k1.n) < 0 | ||
} | ||
|
||
function intSign (a) { | ||
typeforce(types.tuple(types.Buffer), arguments) | ||
|
||
return BigInteger.fromBuffer(a).signum() | ||
} | ||
|
||
function pointAdd (p, q) { | ||
typeforce(types.tuple(types.Buffer, types.Buffer), arguments) | ||
|
||
var P = ecurve.Point.decodeFrom(p) | ||
var Q = ecurve.Point.decodeFrom(q) | ||
var R = P.add(Q) | ||
|
||
if (secp256k1.isInfinity(R)) return null | ||
return R.getEncoded(P.compressed) | ||
} | ||
|
||
function pointDerive (d, compressed) { | ||
typeforce(types.tuple(types.Buffer, types.Boolean), arguments) | ||
|
||
d = BigInteger.fromBuffer(d) | ||
return secp256k1.G.multiply(d).getEncoded(compressed) | ||
} | ||
|
||
function pointVerify (q) { | ||
typeforce(types.tuple(types.Buffer), arguments) | ||
var Q = ecurve.Point.decodeFrom(q) | ||
|
||
return secp256k1.validate(Q) | ||
} | ||
|
||
module.exports = { | ||
calcPubKeyRecoveryParam: calcPubKeyRecoveryParam, | ||
deterministicGenerateK: deterministicGenerateK, | ||
recoverPubKey: recoverPubKey, | ||
sign: sign, | ||
verify: verify, | ||
|
||
// TODO: remove | ||
__curve: secp256k1 | ||
intAdd: intAdd, | ||
intCheck: intCheck, | ||
intSign: intSign, | ||
pointAdd: pointAdd, | ||
pointDerive: pointDerive, | ||
pointVerify: pointVerify | ||
} |
3 comments
on commit 0030854
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jprichardson I had hoped to merge something like this.
To save you reading it to find out what it is, it changes d
and Q
to their Buffer
equivalents as part of the ECDSA break out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I see where you're going with this. I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still aiming for this @jprichardson ... but I don't see a sane/performant API for 3.0.0
, so again, 4.0.0
.
c9f0c43 was something I tried recently, but again the issues come up with a sane interface while still allowing for advanced cryptography.
I think perhaps splitting BIP32
out to its own module will mean we manage the "key pair" ourselves there, and that will avoid that use case.
But what about people who want to stealth addresses etc?
I don't want to force serialization... but duck types SUCK!
Hmph.
a + b mod n
?