crypto#ECDHKeyFormat TypeScript Examples

The following examples show how to use crypto#ECDHKeyFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: diffieHellman.ts    From chain-js with MIT License 6 votes vote down vote up
/** Generates Ephemeral Keypair and sharedSecret - used for ECC curves and some others supported by Node crypto curveType */
export function generateEphemPublicKeyAndSharedSecretType1(
  publicKey: NodeJS.ArrayBufferView,
  curveType: EciesCurveType,
  keyFormat: ECDHKeyFormat,
) {
  assertPublicKeyBufferLengthValid(publicKey as Buffer, 'generateEphemPublicKeyAndSharedSecretType1')
  const ecdh = crypto.createECDH(curveType)
  const encodedEphemPublicKey = ecdh.generateKeys(null, keyFormat)
  const sharedSecret = ecdh.computeSecret(publicKey)
  return { ephemPublicKey: encodedEphemPublicKey, sharedSecret }
}