How to use the peer-id.createFromProtobuf function in peer-id

To help you get started, we’ve selected a few peer-id 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
const [salt, iv, ciphertext] = rlp.decode(encryptedSerializedKeyPair)

    const scryptParams = { N: 8192, r: 8, p: 16 }

    const question = 'Please type in the password that was used to encrypt the key.'

    let plaintext
    do {
        const pw = await this.askForPassword(question)

        const key = scrypt.hashSync(pw, scryptParams, 32, salt)

        plaintext = chacha.chacha20(key, iv).update(ciphertext)
    } while (!plaintext.slice(0, 16).equals(Buffer.alloc(16, 0)))

    const peerId = await PeerId.createFromProtobuf(plaintext)
    console.log(`Successfully restored ID \x1b[34m${peerId.toB58String()}\x1b[0m.`)

    return peerId
}