UNPKG

@practicaloptimism/uniplexer

Version:

A multiplexer for 3rd party service providers and application protocols

23 lines (16 loc) 743 B
import * as randombytes from 'randombytes' import { curve } from '../variables' import { CRYPTOGRAPHY_KEY_ALGORITHM } from '../constants/asymmetric-cryptography' import { GenerateKeyPair, AsymmetricKeyPair } from '../../../@utility/data-structures/asymmetric-cryptography' const generateKeyPair: GenerateKeyPair = (): Promise<AsymmetricKeyPair[]> => { const bytes = randombytes(16) const privateKey = bytes.toString('hex') const publicKey = curve.keyFromPrivate(bytes).getPublic('hex') const keyPair = new AsymmetricKeyPair() keyPair.privateKey = `${CRYPTOGRAPHY_KEY_ALGORITHM}:${privateKey}` keyPair.publicKey = `${CRYPTOGRAPHY_KEY_ALGORITHM}:${publicKey}` return Promise.resolve([keyPair]) } export { generateKeyPair }