Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis. Learn more
Socket
Log inDemoInstall

@privy-io/crypto

Package Overview
Dependencies
0
Maintainers
5
Versions
5
Issues
File Explorer

Advanced tools

@privy-io/crypto

Privy encryption and decryption library

    0.0.4latest
    npm

Version published
Maintainers
5
Weekly downloads
644
increased by66.41%

Weekly downloads

Readme

Source

@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

build npm version

Documentation

See https://docs.privy.io/.

Installation

npm install --save @privy-io/crypto

Usage

import {CryptoEngine, CryptoVersion} from '@privy-io/crypto'; // Grab the engine (implementation) corresponding to the version const x0 = CryptoEngine(CryptoVersion.x0); // Crypto module expects Uint8Arrays. const plaintext = new TextEncoder().encode('{"ssn": "123-45-6789"}'); // Encryption const privyEncryption = new x0.Encryption(plaintext, { wrapperKey: wrapperKey, // RSA public key from privy server wrapperKeyId: wrapperKeyId, // Metadata id of RSA public key from Privy's KMS }); const encryptionResult = await privyEncryption.encrypt(); const ciphertext = encryptionResult.ciphertext(); // Commitment id's are computed from the hash of a nonce concatenated with the // plaintext. Can be used for an optional data integrity check. const commitmentId = encryptionResult.commitmentId(); // Decryption const privyDecryption = new x0.Decryption(ciphertext); // This is where Privy would decrypt the encrypted data // key against the Privy server, ultimately doing so in an HSM. const decryptedDataKey = decryptDataKey( privyDecryption.wrapperKeyId(), privyDecryption.encryptedDataKey(), ); const decryptionResult = await privyDecryption.decrypt(decryptedDataKey); // Optional data integrity check. if (!(await privyDecryption.verify(decryptionResult, commitmentId))) { throw 'Data integrity check failed.'; } // Crypto module returns Uint8Arrays. const decryptedPlaintext = new TextDecoder().decode(decryptionResult.plaintext()); console.log(decryptedPlaintext); // {"ssn": "123-45-6789"}

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:

# Requires node >= 15 npm run test-webcrypto

Keywords

FAQs

Last updated on 08 Jun 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc