libsodium sealed cryptobox using tweetnacl
Перейти к файлу
Lucas Garron b982e954b8 Add "deprecated" to the big header in `README.md`. 2022-04-04 17:40:33 -07:00
.github/workflow Added TypeScript type definitions 2020-02-24 15:18:56 -05:00
.gitignore Add build toolchain 2018-09-18 16:06:28 -06:00
.nvmrc Added TypeScript type definitions 2020-02-24 15:18:56 -05:00
.travis.yml mess with CI config 2018-09-17 11:03:51 -06:00
LICENSE first commit 2018-09-17 10:39:28 -06:00
README.md Add "deprecated" to the big header in `README.md`. 2022-04-04 17:40:33 -07:00
index.d.ts Removed namespace in TypeScript definitions and changed tape back to test import 2020-03-05 01:01:33 -05:00
index.js Added TypeScript type definitions 2020-02-24 15:18:56 -05:00
index.test-d.ts Added TypeScript type definitions 2020-02-24 15:18:56 -05:00
package-lock.json Bump to version v0.0.6, to be published and marked as deprecated. 2022-04-04 17:33:04 -07:00
package.json Bump to version v0.0.6, to be published and marked as deprecated. 2022-04-04 17:33:04 -07:00
test.js Removed namespace in TypeScript definitions and changed tape back to test import 2020-03-05 01:01:33 -05:00

README.md

⚠️ tweetsodium is deprecated and unmaintained ⚠️

Consider using libsodium.js, maintained by the same author as libsodium. For example:

import libsodium from "libsodium-wrappers";

// Compatible with the same `Uint8Array` arguments as `tweetsodium.seal()`
async function async_encrypt(messageBytes, publicKey) {
  await libsodium.ready;
  return libsodium.crypto_box_seal(messageBytes, publicKey);
}

// Compatible with the same `Uint8Array` arguments as `tweetsodium.sealOpen()`
async function async_decrypt(messageBytes, publicKey, privateKey) {
  await libsodium.ready;
  return libsodium.crypto_box_seal_open(messageBytes, publicKey, privateKey);
}

Or if you are able to use top-level await:

import libsodium from "libsodium-wrappers";
await libsodium.ready;

// Use:
// - `libsodium.crypto_box_seal` instead of `tweetsodium.seal`
// - `libsodium.crypto_box_seal_open` instead of `tweetsodium.sealOpen`







tweetsodium Build Status

This library implements libsodium's sealed boxes using the tweetnacl-js and blakejs libraries.

Usage

const nacl = require("tweetnacl");
const sodium = require("tweetsodium");

// generate public key to use for encryption and coresponding secret key to use
// for decryption
const keyPair = nacl.box.keyPair();

// encrypts message string using public key
function encrypt(message) {
  const encoder = new TextEncoder();
  const messageBytes = encoder.encode(message);

  return sodium.seal(messageBytes, keyPair.publicKey);
}

// decrypts message using secret key
function decrypt(ciphertext) {
  const encoder = new TextEncoder();
  const ciphertextBytes = encoder.encode(ciphertext);

  return sodium.sealOpen(ciphertextBytes, keyPair.publicKey, keyPair.secretKey);
}