Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x, latest]
node-version: [14.x, 16.x, 18.x, latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
22 changes: 11 additions & 11 deletions lib/hdkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var Buffer = require('safe-buffer').Buffer
var crypto = require('crypto')
var bs58check = require('bs58check')
var RIPEMD160 = require('ripemd160')
var secp256k1 = require('@exodus/secp256k1')
var secp256k1 = require('@exodus/bitcoinerlab-secp256k1')

var MASTER_SECRET = Buffer.from('Bitcoin seed', 'utf8')
var HARDENED_OFFSET = 0x80000000
Expand Down Expand Up @@ -33,10 +33,10 @@ Object.defineProperty(HDKey.prototype, 'privateKey', {
},
set: function (value) {
assert.equal(value.length, 32, 'Private key must be 32 bytes.')
assert(secp256k1.privateKeyVerify(value) === true, 'Invalid private key')
assert(secp256k1.isPrivate(value) === true, 'Invalid private key')

this._privateKey = value
this._publicKey = Buffer.from(secp256k1.publicKeyCreate(value, true))
this._publicKey = Buffer.from(secp256k1.pointFromScalar(value, true))
this._identifier = hash160(this.publicKey)
this._fingerprint = this._identifier.slice(0, 4).readUInt32BE(0)
}
Expand All @@ -55,9 +55,9 @@ Object.defineProperty(HDKey.prototype, 'publicKey', {
},
set: function (value) {
assert(value.length === 33 || value.length === 65, 'Public key must be 33 or 65 bytes.')
assert(secp256k1.publicKeyVerify(value) === true, 'Invalid public key')
assert(secp256k1.isPoint(value) === true, 'Invalid public key')
// force compressed point (performs public key verification)
const publicKey = (value.length === 65) ? secp256k1.publicKeyConvert(value, true) : value
const publicKey = (value.length === 65) ? secp256k1.pointCompress(value, true) : value
setPublicKey(this, publicKey)
}
})
Expand Down Expand Up @@ -131,7 +131,7 @@ HDKey.prototype.deriveChild = function (index) {
if (this.privateKey) {
// ki = parse256(IL) + kpar (mod n)
try {
hd.privateKey = Buffer.from(secp256k1.privateKeyTweakAdd(Buffer.from(this.privateKey), IL))
hd.privateKey = Buffer.from(secp256k1.privateAdd(Buffer.from(this.privateKey), IL))
// throw if IL >= n || (privateKey + IL) === 0
} catch (err) {
// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
Expand All @@ -142,7 +142,7 @@ HDKey.prototype.deriveChild = function (index) {
// Ki = point(parse256(IL)) + Kpar
// = G*IL + Kpar
try {
hd.publicKey = Buffer.from(secp256k1.publicKeyTweakAdd(Buffer.from(this.publicKey), IL, true))
hd.publicKey = Buffer.from(secp256k1.pointAddScalar(Buffer.from(this.publicKey), IL, true))
// throw if IL >= n || (g**IL + publicKey) is infinity
} catch (err) {
// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
Expand All @@ -159,14 +159,14 @@ HDKey.prototype.deriveChild = function (index) {
}

HDKey.prototype.sign = function (hash) {
return Buffer.from(secp256k1.ecdsaSign(Uint8Array.from(hash), Uint8Array.from(this.privateKey)).signature)
return Buffer.from(secp256k1.sign(Uint8Array.from(hash), Uint8Array.from(this.privateKey)))
}

HDKey.prototype.verify = function (hash, signature) {
return secp256k1.ecdsaVerify(
Uint8Array.from(signature),
return secp256k1.verify(
Uint8Array.from(hash),
Uint8Array.from(this.publicKey)
Uint8Array.from(this.publicKey),
Uint8Array.from(signature)
)
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@exodus/hdkey",
"version": "2.1.0-exodus.0",
"version": "2.1.1-exodus.1",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not bundle this in with these changes, reverted e1b5ed9

"description": "Bitcoin BIP32 hierarchical deterministic keys",
"main": "lib/hdkey.js",
"repository": {
Expand Down Expand Up @@ -34,10 +34,10 @@
"standard": "^7.1.1"
},
"dependencies": {
"@exodus/bitcoinerlab-secp256k1": "^1.0.5-exodus.1",
"bs58check": "^2.1.2",
"ripemd160": "^2.0.2",
"safe-buffer": "^5.1.1",
"@exodus/secp256k1": "^4.0.2-exodus.0"
"safe-buffer": "^5.1.1"
},
"scripts": {
"lint": "standard",
Expand Down
4 changes: 2 additions & 2 deletions test/hdkey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ describe('hdkey', function () {

assert.throws(function () {
hdkey.verify(Buffer.alloc(99), a)
}, /message.*length/)
}, /Expected Scalar/)
assert.throws(function () {
hdkey.verify(ma, Buffer.alloc(99))
}, /signature.*length/)
}, /Expected Signature/)
})
})

Expand Down