How to use the tiny-secp256k1.privateSub function in tiny-secp256k1

To help you get started, we’ve selected a few tiny-secp256k1 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 bitcoinjs / bitcoinjs-lib / test / integration / stealth.js View on Github external
function stealthRecoverLeaked (v, e, Q) {
  const eQ = ecc.pointMultiply(Q, e) // shared secret
  const c = bitcoin.crypto.sha256(eQ)
  const vc = ecc.privateSub(v, c)
  const d = bitcoin.ECPair.fromPrivateKey(vc)

  return d
}
github bitcoinjs / bitcoinjs-lib / test / integration / crypto.js View on Github external
const serQP = master.publicKey
      const d1 = child.privateKey
      const data = Buffer.alloc(37)
      serQP.copy(data, 0)

      // search index space until we find it
      let d2
      for (var i = 0; i < 0x80000000; ++i) {
        data.writeUInt32BE(i, 33)

        // calculate I
        const I = crypto.createHmac('sha512', master.chainCode).update(data).digest()
        const IL = I.slice(0, 32)

        // See bip32.js:273 to understand
        d2 = tinysecp.privateSub(d1, IL)

        const Qp = bip32.fromPrivateKey(d2, Buffer.alloc(32, 0)).publicKey
        if (Qp.equals(serQP)) break
      }

      const node = bip32.fromPrivateKey(d2, master.chainCode, master.network)
      node.depth = master.depth
      node.index = master.index
      node.masterFingerprint = master.masterFingerprint
      return node
    }