How to use the bsv.crypto function in bsv

To help you get started, we’ve selected a few bsv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github monkeylord / MiniGate / index.js View on Github external
function getScriptHash(address){
    var script = bsv.Script.fromAddress(address)
    var scriptHash = bsv.crypto.Hash.sha256(script.toBuffer()).reverse()
    return scriptHash.toString('hex')
}
github monkeylord / bitcoin-ibe / index.js View on Github external
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)
github monkeylord / bitcoin-ibe / index.js View on Github external
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')