Add tests for low R signing
This commit is contained in:
parent
ccd439b805
commit
b5577607d4
3 changed files with 30 additions and 8 deletions
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -731,9 +731,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"nan": {
|
"nan": {
|
||||||
"version": "2.12.1",
|
"version": "2.13.2",
|
||||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.12.1.tgz",
|
"resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz",
|
||||||
"integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw=="
|
"integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw=="
|
||||||
},
|
},
|
||||||
"nyc": {
|
"nyc": {
|
||||||
"version": "13.3.0",
|
"version": "13.3.0",
|
||||||
|
@ -1911,15 +1911,15 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tiny-secp256k1": {
|
"tiny-secp256k1": {
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-1.1.0.tgz",
|
||||||
"integrity": "sha512-Wz2kMPWtCI5XBftFeF3bUL8uz2+VlasniKwOkRPjvL7h1QVd9rbhrve/HWUu747kJKzVf1XHonzcdM4Ut8fvww==",
|
"integrity": "sha512-DIl0SCUIVcPrk/oOiq8/YgQ69Beayw4XSW2icyXJN8xfKMmxo5XM8gXVG1Ex+rYsHg2xuEpNFeeU6J4CtqQFrA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bindings": "^1.3.0",
|
"bindings": "^1.3.0",
|
||||||
"bn.js": "^4.11.8",
|
"bn.js": "^4.11.8",
|
||||||
"create-hmac": "^1.1.7",
|
"create-hmac": "^1.1.7",
|
||||||
"elliptic": "^6.4.0",
|
"elliptic": "^6.4.0",
|
||||||
"nan": "^2.10.0"
|
"nan": "^2.12.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"to-fast-properties": {
|
"to-fast-properties": {
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
"merkle-lib": "^2.0.10",
|
"merkle-lib": "^2.0.10",
|
||||||
"pushdata-bitcoin": "^1.0.1",
|
"pushdata-bitcoin": "^1.0.1",
|
||||||
"randombytes": "^2.0.1",
|
"randombytes": "^2.0.1",
|
||||||
"tiny-secp256k1": "^1.0.0",
|
"tiny-secp256k1": "^1.1.0",
|
||||||
"typeforce": "^1.11.3",
|
"typeforce": "^1.11.3",
|
||||||
"varuint-bitcoin": "^1.0.4",
|
"varuint-bitcoin": "^1.0.4",
|
||||||
"wif": "^2.0.1"
|
"wif": "^2.0.1"
|
||||||
|
|
|
@ -259,4 +259,26 @@ describe('ECPair', () => {
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe('optional low R signing', () => {
|
||||||
|
const sig = Buffer.from('95a6619140fca3366f1d3b013b0367c4f86e39508a50fdce' +
|
||||||
|
'e5245fbb8bd60aa6086449e28cf15387cf9f85100bfd0838624ca96759e59f65c10a00' +
|
||||||
|
'16b86f5229', 'hex')
|
||||||
|
const sigLowR = Buffer.from('6a2660c226e8055afad317eeba918a304be79208d505' +
|
||||||
|
'3bc5ea4a5e4c5892b4a061c717c5284ae5202d721c0e49b4717b79966280906b1d3b52' +
|
||||||
|
'95d1fdde963c35', 'hex')
|
||||||
|
const lowRKeyPair = ECPair.fromWIF('L3nThUzbAwpUiBAjR5zCu66ybXSPMr2zZ3ikp' +
|
||||||
|
'ScpTPiYTxBynfZu')
|
||||||
|
const dataToSign = Buffer.from('b6c5c548a7f6164c8aa7af5350901626ebd69f9ae' +
|
||||||
|
'2c1ecf8871f5088ec204cfe', 'hex')
|
||||||
|
|
||||||
|
it('signs with normal R by default', () => {
|
||||||
|
const signed = lowRKeyPair.sign(dataToSign)
|
||||||
|
assert.deepStrictEqual(sig, signed)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('signs with low R when true is passed', () => {
|
||||||
|
const signed = lowRKeyPair.sign(dataToSign, true)
|
||||||
|
assert.deepStrictEqual(sigLowR, signed)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue