How to use the ECDH function from crypto

Find comprehensive JavaScript crypto.ECDH code examples handpicked from public code repositorys.

89
90
91
92
93
94
95
96
97
98
99
                                            'to return a new instance when ' +
                                            'called without `new`');
}


{
  const ECDH = crypto.ECDH;
  const ecdh = ECDH('prime256v1');
  assert(ecdh instanceof ECDH, 'ECDH is expected to return a new instance ' +
                               'when called without `new`');
}
fork icon0
star icon0
watch icon0

+ 6 other calls in file

89
90
91
92
93
94
95
96
97
98
                         'hybrid');
assert.strictEqual(uncompressed, cafebabePubPtUnComp);
assert.strictEqual(compressed, cafebabePubPtComp);

// Compare to getPublicKey.
const ecdh1 = ECDH('secp256k1');
ecdh1.generateKeys();
ecdh1.setPrivateKey(cafebabeKey, 'hex');
assert.strictEqual(ecdh1.getPublicKey('hex', 'uncompressed'), uncompressed);
assert.strictEqual(ecdh1.getPublicKey('hex', 'compressed'), compressed);
fork icon0
star icon0
watch icon0