How to use the bsv.PrivateKey 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 dfoderick / bitshovel / misc / genWallet.js View on Github external
// generate a wallet.json file
// remember to fund the wallet using the address generated
// the easiest way to do that is go to https://www.moneybutton.com/test
// and use withdraw button
// then review the tx on a block explorer e.g. https://bchsvexplorer.com

const bsv = require('bsv')
const fs = require('fs');

var pk = bsv.PrivateKey()
console.log(pk)
var address = new bsv.Address(pk.publicKey, bsv.Networks.mainnet)
console.log(address.toLegacyAddress())

wallet = {
    "wif": pk.toWIF(),
    "address": address.toLegacyAddress()
}

const sWallet = JSON.stringify(wallet, null, 2);
console.log(sWallet)

fs.writeFile('wallet.json', sWallet, 'utf8', function(err) {
    if(err) {
        return console.log(err);
    }
github unwriter / datapay / index.js View on Github external
callback(new Error("the transaction is already signed and cannot be modified"))
        return;
      }
    }
  } else {
    // construct script only if transaction doesn't exist
    // if a 'transaction' attribute exists, the 'data' should be ignored to avoid confusion
    if (options.data) {
      script = _script(options)
    }
  }
  // Instantiate pay
  if (options.pay && options.pay.key) {
    // key exists => create a signed transaction
    let key = options.pay.key;
    const privateKey = new bitcoin.PrivateKey(key);
    const address = privateKey.toAddress();
    const insight = new explorer.Insight(rpcaddr)
    insight.getUnspentUtxos(address, function (err, res) {
      if (err) {
        callback(err);
        return;
      }

      if (options.pay.filter && options.pay.filter.q && options.pay.filter.q.find) {
        let f = new mingo.Query(options.pay.filter.q.find)
        res = res.filter(function(item) {
          return f.test(item)
        })
      }
      let tx = new bitcoin.Transaction(options.tx).from(res);
github monkeylord / bitcoin-ibe / test / chlidkey.js View on Github external
var chai = require('chai')
var should = chai.should()
var expect = chai.expect

var ibe = require('..')
var bsv = require('bsv')

var aliceKey = bsv.PrivateKey('d51a296b37e924944c811a0c32a98c7a28952a5c2a37d16b44c3c67a466e3d0c')
var bobKey = bsv.PrivateKey('80595f7f87f45b91cd7f2c9cef33a74310ff984ccc1a8b82b8a7ff9f015c5f84')

var Id1 = 'Some coffee'
var Id2 = 'Maybe some suger?'
var Id3 = 'Or Milk?'

describe('IBE-like ChildKey Deriving', function () {
  describe('Standalone', function () {
    describe('Multiplication', function () {
        it('should derive child PrivateKey correctly', function () {
          ibe.childKey_mul(bobKey, Id1).toString().should.equal('9b4694504c8fed986849be252c4c772a28515372bf16a300c321364ae652aa1e')
        })

        it('should derive hardened child PrivateKey correctly', function () {
          ibe.childKey_mul(bobKey, Id1, true).toString().should.equal('b4775eb27ec1c37a197cf1f6ff2d3fde778d9068895533b2edc9785d9131cd8b')
        })
github dfoderick / bitshovel / bitshovel.js View on Github external
function generateWallet(key) {
    let pk = null;
    if (key !== null && key !== undefined && key !== '') {
        pk = bsv.PrivateKey(key)
    } else {
        pk = bsv.PrivateKey()
    }
    const address = new bsv.Address(pk.publicKey, bsv.Networks.mainnet)
    console.log(`generated wallet with address ${address}`);

    const wallet = {
        "wif": pk.toWIF(),
        "address": address.toLegacyAddress()
    }
    return storeWallet(wallet)
}
github dfoderick / bitshovel / bitshovel.js View on Github external
function generateWallet(key) {
    let pk = null;
    if (key !== null && key !== undefined && key !== '') {
        pk = bsv.PrivateKey(key)
    } else {
        pk = bsv.PrivateKey()
    }
    const address = new bsv.Address(pk.publicKey, bsv.Networks.mainnet)
    console.log(`generated wallet with address ${address}`);

    const wallet = {
        "wif": pk.toWIF(),
        "address": address.toLegacyAddress()
    }
    return storeWallet(wallet)
}
github dfoderick / bitshovel / shovelwallet.js View on Github external
let generateWallet = function generateWallet(key) {
    let pk = null;
    if (key !== null && key !== undefined && key !== '') {
        pk = bsv.PrivateKey(key)
    } else {
        pk = bsv.PrivateKey()
    }
    const address = new bsv.Address(pk.publicKey, bsv.Networks.mainnet)
    console.log(`generated wallet with address ${address}`);

    const wallet = {
        "wif": pk.toWIF(),
        "address": address.toLegacyAddress()
    }
    return storeWallet(wallet)
}
github bowstave / meta-writer / index.js View on Github external
function getFundingKey () {
  const data = getDataWithExtension('funding_key')
  if (data.xprv) {
    if (!data.derivationPath) {
      throw new Error('You must have a derivationPath defined for this master private key.')
    }
    return new bsv.HDPrivateKey(data.xprv).deriveChild(data.derivationPath)
  } else if (data.priv) {
    return new bsv.PrivateKey(data.priv)
  }
  return null
}