Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getScriptHash(address){
var script = bsv.Script.fromAddress(address)
var scriptHash = bsv.crypto.Hash.sha256(script.toBuffer()).reverse()
return scriptHash.toString('hex')
}
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')
publicKey = PublicKey(publicKey)
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')