@privy-io/crypto
JavaScript library for encrypting and decrypting data with Privy.
This library is intended to be used by the @privy-io/privy-browser
and @privy-io/privy-node
libraries to handle all cryptographic operations.
https://www.privy.io
Documentation
See https://docs.privy.io/.
Installation
npm install --save @privy-io/crypto
Usage
import {CryptoEngine, CryptoVersion} from '@privy-io/crypto';
const x0 = CryptoEngine(CryptoVersion.x0);
const plaintext = new TextEncoder().encode('{"ssn": "123-45-6789"}');
const privyEncryption = new x0.Encryption(plaintext, {
wrapperKey: wrapperKey,
wrapperKeyId: wrapperKeyId,
});
const encryptionResult = await privyEncryption.encrypt();
const ciphertext = encryptionResult.ciphertext();
const commitmentId = encryptionResult.commitmentId();
const privyDecryption = new x0.Decryption(ciphertext);
const decryptedDataKey = decryptDataKey(
privyDecryption.wrapperKeyId(),
privyDecryption.encryptedDataKey(),
);
const decryptionResult = await privyDecryption.decrypt(decryptedDataKey);
if (!(await privyDecryption.verify(decryptionResult, commitmentId))) {
throw 'Data integrity check failed.';
}
const decryptedPlaintext = new TextDecoder().decode(decryptionResult.plaintext());
console.log(decryptedPlaintext);
Running tests
To test the module interfaces, run:
npm test
To test the node crypto operations against the browser ones (which use the webcrypto standard), run:
npm run test-webcrypto