How to use the bsv.HDPrivateKey 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 bowstave / meta-writer / index.js View on Github external
if (options.file && !options.type) {
    console.log('You must specify a mime type for this file, for example, --type "image/jpeg"')
    process.exit(1)
  }

  const p = options.path

  const parts = p.split('/')
  parts.shift() // Skip the first element of the path

  const name = parts.shift()
  const data = getData(name)
  let parentKey = null
  let parentPath = null

  const masterPrivateKey = bsv.HDPrivateKey(data.xprv)
  if (parts.length === 1) {
    if (parts[0] !== '0') {
      throw new Error('Only one root not is allowed.')
    }
  } else {
    parentPath = parts.slice(0, -1).join('/')
    parentKey = masterPrivateKey.deriveChild('m/' + parentPath)
  }

  const childPath = parts.join('/')
  const childKey = masterPrivateKey.deriveChild('m/' + childPath)

  const fundingKey = getFundingKey()

  const oprParts = []
  oprParts.push('OP_RETURN')
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
}
github bowstave / meta-writer / index.js View on Github external
function getDataWithExtension (name) {
  const homeDir = process.env.HOME

  const filename = path.join(homeDir, '.meta-writer', name)

  let data
  try {
    data = JSON.parse(fs.readFileSync(filename))
  } catch (e) {
    const dir = path.join(homeDir, '.meta-writer')
    if (!fs.existsSync(dir)) {
      fs.mkdirSync(dir)
    }

    data = { xprv: bsv.HDPrivateKey().xprivkey }
    fs.writeFileSync(filename, JSON.stringify(data, null, 2))
  }

  if (!data.xprv) {
    throw new Error('Invalid private key.')
  }

  return data
}