Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function encryptDerivationPath(derivationPath, hdPassphrase) {
const serializedDerivationPath = cbor.encode(
new CborIndefiniteLengthArray(derivationPath)
)
const cipher = new chacha20.ChaCha20Poly1305(hdPassphrase)
return Buffer.from(
cipher.seal(Buffer.from('serokellfore'), serializedDerivationPath)
)
}
exports.encryptDerivationPath = function(derivationPath, hdPassphrase) {
const serializedDerivationPath = cbor.encode(new CBORIndefiniteLengthArray(derivationPath))
const cipher = new chacha20.ChaCha20Poly1305(hdPassphrase)
return new Buffer(cipher.seal(new Buffer('serokellfore'), serializedDerivationPath))
}
function decryptDerivationPathOrFail(addressPayload, hdPassphrase) {
const cipher = new chacha20.ChaCha20Poly1305(hdPassphrase)
const decipheredDerivationPath = cipher.open(new Buffer('serokellfore'), addressPayload)
try {
return cbor.decode(new Buffer(decipheredDerivationPath))
} catch (err) {
throw new AddressDecodingException('incorrect address or passphrase')
}
}