Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should chained deriving working', function () {
bsv.PrivateKey.isValid(bobKey
.childKey(Id1)
.childKey(Id2)
.childKey(Id3)
).should.equal(true)
bsv.PublicKey.isValid(bobKey
.publicKey
.childKey(Id1)
.childKey(Id2)
.childKey(Id3)
).should.equal(true)
})
var bsv = require('bsv')
var PrivateKey = bsv.PrivateKey
var PublicKey = bsv.PublicKey
var Hash = bsv.crypto.Hash
var BN = bsv.crypto.BN
var Point = bsv.crypto.Point
function CKDpriv_mul (privateKey, id, harden = false) {
privateKey = PrivateKey(privateKey)
var key = harden ? privateKey : privateKey.publicKey
//hash function doesn't matter.
var nbuf = Hash.sha256hmac(key.toBuffer(), Buffer.from(id))
var n = BN.fromBuffer(nbuf)
var childPrivkeyBN = privateKey.bn.mul(n).umod(Point.getN())
return PrivateKey(childPrivkeyBN)
}
function CKDpub_mul (publicKey, id, harden = false) {
if(harden)throw new Error('Impossible to derive hardened public key')