Skip to content

Commit

Permalink
Merge pull request #1 from BitGo/BTC-421-update-secpkak256
Browse files Browse the repository at this point in the history
feat: update secp256k1 library to v5.0.0
  • Loading branch information
lcovar authored Sep 14, 2023
2 parents c43430f + bf99875 commit 992c0ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ function sign (
const hash = magicHash(message, messagePrefixArg)
const sigObj = isSigner(privateKey)
? privateKey.sign(hash, extraEntropy)
: secp256k1.sign(hash, privateKey, { data: extraEntropy })
: secp256k1.ecdsaSign(hash, privateKey, { data: extraEntropy })
return encodeSignature(
sigObj.signature,
sigObj.recovery,
sigObj.recid,
compressed,
segwitType
)
Expand All @@ -153,11 +153,11 @@ function signAsync (
const hash = magicHash(message, messagePrefixArg)
return isSigner(privateKey)
? privateKey.sign(hash, extraEntropy)
: secp256k1.sign(hash, privateKey, { data: extraEntropy })
: secp256k1.ecdsaSign(hash, privateKey, { data: extraEntropy })
}).then((sigObj) => {
return encodeSignature(
sigObj.signature,
sigObj.recovery,
sigObj.recid,
compressed,
segwitType
)
Expand Down Expand Up @@ -188,12 +188,13 @@ function verify (message, address, signature, messagePrefix, checkSegwitAlways)
}

const hash = magicHash(message, messagePrefix)
const publicKey = secp256k1.recover(
hash,
const publicKey = secp256k1.ecdsaRecover(
parsed.signature,
parsed.recovery,
hash,
parsed.compressed
)

const publicKeyHash = hash160(publicKey)
let actual, expected

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"bs58check": "^2.1.2",
"buffer-equals": "^1.0.3",
"create-hash": "^1.1.2",
"secp256k1": "^3.0.1",
"secp256k1": "5.0.0",
"varuint-bitcoin": "^1.0.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fixtures.valid.magicHash.forEach(f => {
fixtures.valid.sign.forEach(f => {
test('sign: ' + f.description, async t => {
const pk = new bitcoin.ECPair(new BigInteger(f.d)).d.toBuffer(32)
const signer = (hash, ex) => secp256k1.sign(hash, pk, { data: ex })
const signerAsync = async (hash, ex) => secp256k1.sign(hash, pk, { data: ex })
const signer = (hash, ex) => secp256k1.ecdsaSign(hash, pk, { data: ex })
const signerAsync = async (hash, ex) => secp256k1.ecdsaSign(hash, pk, { data: ex })
let signature = message.sign(
f.message,
pk,
Expand Down

0 comments on commit 992c0ff

Please sign in to comment.