How to use the libp2p-crypto.keys.supportedKeys function in libp2p-crypto

To help you get started, we’ve selected a few libp2p-crypto 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 validitylabs / hopr / src / utils / index.js View on Github external
module.exports.privKeyToPeerId = privKey => {
    if (typeof privKey === 'string') privKey = Buffer.from(privKey.replace(/0x/, ''), 'hex')

    if (!Buffer.isBuffer(privKey)) throw Error(`Unable to parse private key to desired representation. Got type '${typeof privKey}'.`)

    if (privKey.length != PRIVKEY_LENGTH)
        throw Error(`Invalid private key. Expected a buffer of size ${PRIVKEY_LENGTH} bytes. Got one of ${privKey.length} bytes.`)

    privKey = new libp2p_crypto.supportedKeys.secp256k1.Secp256k1PrivateKey(privKey)

    return PeerId.createFromPrivKey(privKey.bytes)
}