-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch to exodus/crypto for schnorr signatures (#148)
- Loading branch information
Showing
6 changed files
with
25 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import assert from 'minimalistic-assert' | ||
import ecc from '@exodus/bitcoinerlab-secp256k1' | ||
import * as secp256k1 from '@exodus/crypto/secp256k1' | ||
|
||
export const tweakPrivateKey = ({ hdkey, tweak }) => { | ||
const { privateKey, publicKey } = hdkey | ||
assert(ecc.isPrivate(privateKey), 'tweakPrivateKey: expected valid private key') | ||
assert(ecc.isPointCompressed(publicKey), 'tweakPrivateKey: expected compressed public key') | ||
assert(secp256k1.privateKeyIsValid({ privateKey }), 'tweakPrivateKey: expected valid private key') | ||
assert( | ||
secp256k1.publicKeyIsValid({ publicKey, compressed: true }), | ||
'tweakPrivateKey: expected compressed public key' | ||
) | ||
|
||
let tweakedPrivateKey = publicKey[0] === 3 ? ecc.privateNegate(privateKey) : privateKey | ||
tweakedPrivateKey = ecc.privateAdd(tweakedPrivateKey, tweak) | ||
const tweakedPrivateKey = | ||
publicKey[0] === 3 ? secp256k1.privateKeyTweakNegate({ privateKey }) : privateKey | ||
|
||
return Buffer.from(tweakedPrivateKey) | ||
return secp256k1.privateKeyTweakAdd({ privateKey: tweakedPrivateKey, tweak, format: 'buffer' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters