Skip to main content

@exodus/storage-encrypted

Usage

Storage enhancer for the @exodus/storage-spec interface. It encrypts values on write, and decrypts them on read. To address cases where the encryption keys are available asynchronously, the enhancer accepts a promise that resolves to the encryption/decryption functions.

import pDefer from 'p-defer'
import withEncryption from '@exodus/storage-encrypted'
import { EXODUS_KEY_IDS } from '@exodus/key-ids'

const cryptoFunctions = pDefer()

const storage = withEncryption({
storage: storage.namespace('wayne-foundation-blueprints'),
cryptoFunctionsPromise: cryptoFunctions.promise,
})

const keyId = EXODUS_KEY_IDS.WALLET_INFO

// Crypto functions have to be resolved before the storage can be used
cryptoFunctions.resolve({
// `keychain` is an instance of `@exodus/keychain`
// `seedId` is the bip32 identifier, e.g. one you get via exodus.wallet.getPrimarySeedId()
encrypt: (data) => keychain.sodium.encryptSecretBox({ seedId, keyId, data }),
decrypt: (data) => keychain.sodium.decryptSecretBox({ seedId, keyId, data }),
})