How to use the tiny-secp256k1.privateAdd 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 stealthDualReceive (d, r, eG) {
  const eQ = ecc.pointMultiply(eG, d) // shared secret
  const c = bitcoin.crypto.sha256(eQ)
  const rc = ecc.privateAdd(r, c)
  const v = bitcoin.ECPair.fromPrivateKey(rc)

  return v
}
github bitcoinjs / bitcoinjs-lib / test / integration / stealth.js View on Github external
function stealthReceive (d, eG) {
  const eQ = ecc.pointMultiply(eG, d) // shared secret
  const c = bitcoin.crypto.sha256(eQ)
  const dc = ecc.privateAdd(d, c)
  const v = bitcoin.ECPair.fromPrivateKey(dc)

  return v
}
github bitcoinjs / bip32 / ts-src / bip32.ts View on Github external
this.publicKey.copy(data, 0);
      data.writeUInt32BE(index, 33);
    }

    const I = crypto.hmacSHA512(this.chainCode, data);
    const IL = I.slice(0, 32);
    const IR = I.slice(32);

    // if parse256(IL) >= n, proceed with the next value for i
    if (!ecc.isPrivate(IL)) return this.derive(index + 1);

    // Private parent key -> private child key
    let hd: BIP32Interface;
    if (!this.isNeutered()) {
      // ki = parse256(IL) + kpar (mod n)
      const ki = ecc.privateAdd(this.privateKey, IL);

      // In case ki == 0, proceed with the next value for i
      if (ki == null) return this.derive(index + 1);

      hd = fromPrivateKeyLocal(
        ki,
        IR,
        this.network,
        this.depth + 1,
        index,
        this.fingerprint.readUInt32BE(0),
      );

      // Public parent key -> public child key
    } else {
      // Ki = point(parse256(IL)) + Kpar
github bitcoinjs / bip32 / src / bip32.js View on Github external
// data = serP(point(kpar)) || ser32(index)
            //      = serP(Kpar) || ser32(index)
            this.publicKey.copy(data, 0);
            data.writeUInt32BE(index, 33);
        }
        const I = crypto.hmacSHA512(this.chainCode, data);
        const IL = I.slice(0, 32);
        const IR = I.slice(32);
        // if parse256(IL) >= n, proceed with the next value for i
        if (!ecc.isPrivate(IL))
            return this.derive(index + 1);
        // Private parent key -> private child key
        let hd;
        if (!this.isNeutered()) {
            // ki = parse256(IL) + kpar (mod n)
            const ki = ecc.privateAdd(this.privateKey, IL);
            // In case ki == 0, proceed with the next value for i
            if (ki == null)
                return this.derive(index + 1);
            hd = fromPrivateKeyLocal(ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0));
            // Public parent key -> public child key
        }
        else {
            // Ki = point(parse256(IL)) + Kpar
            //    = G*IL + Kpar
            const Ki = ecc.pointAddScalar(this.publicKey, IL, true);
            // In case Ki is the point at infinity, proceed with the next value for i
            if (Ki === null)
                return this.derive(index + 1);
            hd = fromPublicKeyLocal(Ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0));
        }
        return hd;