How to use the bsv.PublicKey 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 / bitcoin-ibe / test / chlidkey.js View on Github external
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)
    })
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')