Skip to content

Commit 992c0ff

Browse files
authored
Merge pull request #1 from BitGo/BTC-421-update-secpkak256
feat: update secp256k1 library to v5.0.0
2 parents c43430f + bf99875 commit 992c0ff

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ function sign (
127127
const hash = magicHash(message, messagePrefixArg)
128128
const sigObj = isSigner(privateKey)
129129
? privateKey.sign(hash, extraEntropy)
130-
: secp256k1.sign(hash, privateKey, { data: extraEntropy })
130+
: secp256k1.ecdsaSign(hash, privateKey, { data: extraEntropy })
131131
return encodeSignature(
132132
sigObj.signature,
133-
sigObj.recovery,
133+
sigObj.recid,
134134
compressed,
135135
segwitType
136136
)
@@ -153,11 +153,11 @@ function signAsync (
153153
const hash = magicHash(message, messagePrefixArg)
154154
return isSigner(privateKey)
155155
? privateKey.sign(hash, extraEntropy)
156-
: secp256k1.sign(hash, privateKey, { data: extraEntropy })
156+
: secp256k1.ecdsaSign(hash, privateKey, { data: extraEntropy })
157157
}).then((sigObj) => {
158158
return encodeSignature(
159159
sigObj.signature,
160-
sigObj.recovery,
160+
sigObj.recid,
161161
compressed,
162162
segwitType
163163
)
@@ -188,12 +188,13 @@ function verify (message, address, signature, messagePrefix, checkSegwitAlways)
188188
}
189189

190190
const hash = magicHash(message, messagePrefix)
191-
const publicKey = secp256k1.recover(
192-
hash,
191+
const publicKey = secp256k1.ecdsaRecover(
193192
parsed.signature,
194193
parsed.recovery,
194+
hash,
195195
parsed.compressed
196196
)
197+
197198
const publicKeyHash = hash160(publicKey)
198199
let actual, expected
199200

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"bs58check": "^2.1.2",
3434
"buffer-equals": "^1.0.3",
3535
"create-hash": "^1.1.2",
36-
"secp256k1": "^3.0.1",
36+
"secp256k1": "5.0.0",
3737
"varuint-bitcoin": "^1.0.1"
3838
},
3939
"devDependencies": {

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ fixtures.valid.magicHash.forEach(f => {
2727
fixtures.valid.sign.forEach(f => {
2828
test('sign: ' + f.description, async t => {
2929
const pk = new bitcoin.ECPair(new BigInteger(f.d)).d.toBuffer(32)
30-
const signer = (hash, ex) => secp256k1.sign(hash, pk, { data: ex })
31-
const signerAsync = async (hash, ex) => secp256k1.sign(hash, pk, { data: ex })
30+
const signer = (hash, ex) => secp256k1.ecdsaSign(hash, pk, { data: ex })
31+
const signerAsync = async (hash, ex) => secp256k1.ecdsaSign(hash, pk, { data: ex })
3232
let signature = message.sign(
3333
f.message,
3434
pk,

0 commit comments

Comments
 (0)