
Security News
Security Community Slams MIT-linked Report Claiming AI Powers 80% of Ransomware
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.
@fileverse/crypto
Advanced tools
Fileverse is a privacy-first and decentralized workspace, with collaborative apps for note-taking, spreadsheets, file-sharing, and presentation slides. This repo contains a comprehensive, type-safe cryptographic library for the end-to-end encrypted Fileverse applications, including dsheets.new and ddocs.new. The library provides a set of easy-to-use cryptographic primitives with a focus on security, type safety, and flexibility, which can be used for any JavaScript/TypeScript applications.
npm install @fileverse/crypto
Elliptic Curve Integrated Encryption Scheme for secure asymmetric encryption.
import {
  generateECKeyPair,
  eciesEncrypt,
  eciesDecrypt,
} from "@fileverse/crypto/ecies";
// Generate a key pair
const keyPair = generateECKeyPair();
// { publicKey: "Uint8Array", privateKey: "Uint8Array" }
// Or generate with base64 encoding
const keyPairB64 = generateECKeyPair("base64");
// { publicKey: string, privateKey: string }
// Encrypt a message
const message = new TextEncoder().encode("Secret message");
const encrypted = eciesEncrypt(keyPair.publicKey, message);
// Decrypt a message
const decrypted = eciesDecrypt(keyPair.privateKey, encrypted);
console.log(new TextDecoder().decode(decrypted)); // "Secret message"
// You can also use the raw format for the encrypted data
const encryptedRaw = eciesEncrypt(keyPair.publicKey, message, "raw");
// { ephemeralPublicKey: string, nonce: string, ciphertext: string, mac: string }
import { generateECKeyPair, deriveSharedSecret } from "@fileverse/crypto/ecies";
const aliceKeyPair = generateECKeyPair();
const bobKeyPair = generateECKeyPair();
// Alice derives shared secret using her private key and Bob's public key
const aliceSharedSecret = deriveSharedSecret(
  aliceKeyPair.privateKey,
  bobKeyPair.publicKey
);
// Bob derives the same shared secret using his private key and Alice's public key
const bobSharedSecret = deriveSharedSecret(
  bobKeyPair.privateKey,
  aliceKeyPair.publicKey
);
// aliceSharedSecret === bobSharedSecret
Fast, secure symmetric encryption using TweetNaCl's secretbox implementation. Perfect for encrypting data when you have a shared secret key.
import {
  generateSecretBoxKey,
  secretBoxEncrypt,
  secretBoxDecrypt,
} from "@fileverse/crypto/nacl";
// Generate a secret key (32 bytes)
const secretKey = generateSecretBoxKey();
// Encrypt a message
const message = new TextEncoder().encode("Secret message");
const encrypted = secretBoxEncrypt(secretKey, message);
// Decrypt the message
const decrypted = secretBoxDecrypt(secretKey, encrypted);
console.log(new TextDecoder().decode(decrypted)); // "Secret message"
// URL-safe base64 encoding
const encryptedUrlSafe = secretBoxEncrypt(secretKey, message, true);
RSA encryption with support for envelope encryption to handle messages of any size.
import {
  generateRSAKeyPair,
  rsaEncrypt,
  rsaDecrypt,
  encryptEnvelope,
  decryptEnvelope,
} from "@fileverse/crypto/webcrypto";
import { toBytes } from "@fileverse/crypto/utils";
// Generate an RSA key pair (default 4096 bits)
const keyPair = await generateRSAKeyPair();
// { publicKey: "base64-encoded-string", privateKey: "base64-encoded-string" }
// Or generate with bytes encoding
const keyPairBytes = await generateRSAKeyPair(4096, "bytes");
// { publicKey: Uint8Array, privateKey: Uint8Array }
// Standard RSA encryption (for small messages)
const message = new TextEncoder().encode("Hello, RSA encryption!");
const encrypted = await rsaEncrypt(keyPairBytes.publicKey, message);
// Decrypt
const decrypted = await rsaDecrypt(keyPairBytes.privateKey, toBytes(encrypted));
console.log(new TextDecoder().decode(decrypted)); // "Hello, RSA encryption!"
// For larger messages, use envelope encryption (hybrid RSA/AES)
const largeMessage = new Uint8Array(1024 * 500); // 500KB message
const envelope = await encryptEnvelope(keyPairBytes.publicKey, largeMessage);
// Decrypt envelope
const decryptedLarge = await decryptEnvelope(keyPairBytes.privateKey, envelope);
HMAC-based Key Derivation Function for deriving secure cryptographic keys.
import { deriveHKDFKey } from "@fileverse/crypto/hkdf";
// Derive a key
const keyMaterial = new TextEncoder().encode("some-secure-key-material");
const salt = new TextEncoder().encode("salt-value");
const info = new TextEncoder().encode("context-info");
// Get key as Uint8Array (default)
const key = deriveHKDFKey(keyMaterial, salt, info);
// Or get key as base64 string
const keyBase64 = deriveHKDFKey(keyMaterial, salt, info, "base64");
Argon2id password hashing for secure password storage and key derivation.
import { getArgon2idHash } from "@fileverse/crypto/argon";
// Hash a password with default options
const password = "mySecurePassword123";
const salt = crypto.getRandomValues(new Uint8Array(16)); // 16-byte salt
// Get hash as Uint8Array (default)
const hash = await getArgon2idHash(password, salt);
// Or get hash as base64 string
const hashBase64 = await getArgon2idHash(password, salt, "base64");
// Use custom Argon2 options
const customOptions = {
  t: 3, // time cost (iterations)
  m: 65536, // memory cost in KiB
  p: 4, // parallelism
  dkLen: 32, // derived key length in bytes
};
const customHash = await getArgon2idHash(
  password,
  salt,
  "base64",
  customOptions
);
Utilities for handling encoding conversions consistently.
import { toBytes, bytesToBase64, encodeData } from "@fileverse/crypto/utils";
// Convert base64 to Uint8Array
const bytes = toBytes("SGVsbG8gV29ybGQ=");
// Convert Uint8Array to base64
const base64 = bytesToBase64(new TextEncoder().encode("Hello World"));
// Generic encoding with type safety
const data = new TextEncoder().encode("Test data");
const bytesResult = encodeData(data, "bytes"); // Returns Uint8Array
const base64Result = encodeData(data, "base64"); // Returns string
generateECKeyPair<E extends EncodingType = "bytes">(encoding?: E): EciesKeyPairType<E>Generates an ECIES key pair with the specified encoding.
encoding: Optional. The encoding type to use ("base64" or "bytes"). Default: "bytes".publicKey and privateKey in the specified encoding.deriveSharedSecret<E extends EncodingType = "bytes">(privateKey: Uint8Array | string, publicKey: Uint8Array | string, encoding?: E): EncodedReturnType<E>Derives a shared secret from a private key and a public key.
privateKey: The private key (base64 string or Uint8Array).publicKey: The public key (base64 string or Uint8Array).encoding: Optional. The encoding type for the result. Default: "bytes".eciesEncrypt(publicKey: string | Uint8Array, data: Uint8Array, format?: "base64" | "raw"): string | EciesCipherEncrypts data using ECIES.
publicKey: The public key (base64 string or Uint8Array).data: The data to encrypt.format: Optional. The format of the result ("base64" or "raw"). Default: "base64".eciesDecrypt(privateKey: string | Uint8Array, encryptedData: string | EciesCipher): Uint8ArrayDecrypts data using ECIES.
privateKey: The private key (base64 string or Uint8Array).encryptedData: The encrypted data (string or EciesCipher object).generateSecretBoxKey(): Uint8ArrayGenerates a cryptographically secure 32-byte secret key for use with secret box encryption.
secretBoxEncrypt(key: Uint8Array, message: Uint8Array, urlSafe?: boolean): stringEncrypts data using NaCl's secretbox authenticated encryption.
key: The 32-byte secret key as a Uint8Array.message: The data to encrypt as a Uint8Array.urlSafe: Optional. Whether to use URL-safe base64 encoding. Default: false.secretBoxDecrypt(key: Uint8Array, encrypted: string): Uint8ArrayDecrypts data that was encrypted with secretBoxEncrypt.
key: The 32-byte secret key as a Uint8Array.encrypted: The encrypted data string returned by secretBoxEncrypt.generateRSAKeyPair<E extends EncodingType = "base64">(keySize?: number, encoding?: E): Promise<RsaKeyPairType<E>>Generates an RSA key pair with the specified key size and encoding.
keySize: Optional. The key size in bits. Default: 4096.encoding: Optional. The encoding type to use ("base64" or "bytes"). Default: "base64".publicKey and privateKey in the specified encoding.rsaEncrypt<E extends "base64" | "bytes" = "base64">(publicKey: Uint8Array, message: Uint8Array, returnFormat?: E): Promise<E extends "base64" ? string : Uint8Array>Encrypts data using RSA-OAEP.
publicKey: The public key as a Uint8Array.message: The data to encrypt.returnFormat: Optional. The format of the result ("base64" or "bytes"). Default: "base64".rsaDecrypt(privateKey: Uint8Array, cipherText: Uint8Array): Promise<Uint8Array>Decrypts data using RSA-OAEP.
privateKey: The private key as a Uint8Array.cipherText: The encrypted data.encryptEnvelope(publicKey: Uint8Array, message: Uint8Array): Promise<string>Encrypts a message of any size using envelope encryption (hybrid RSA/AES).
publicKey: The public key as a Uint8Array.message: The data to encrypt.decryptEnvelope(privateKey: Uint8Array, envelopedCipher: string): Promise<Uint8Array>Decrypts an envelope-encrypted message.
privateKey: The private key as a Uint8Array.envelopedCipher: The enveloped ciphertext.deriveHKDFKey<E extends EncodingType = "bytes">(keyMaterial: Uint8Array, salt: Uint8Array, info: Uint8Array, encoding?: E): EncodedReturnType<E>Derives a key using HKDF.
keyMaterial: The key material.salt: The salt.info: The context info.encoding: Optional. The encoding type for the result. Default: "bytes".getArgon2idHash<E extends EncodingType = "bytes">(password: string, salt: Uint8Array, returnFormat?: E, opts?: ArgonOpts): Promise<EncodedReturnType<E>>Generates an Argon2id hash from a password and salt.
password: The password to hash.salt: The salt as a Uint8Array (recommended: 16 bytes minimum).returnFormat: Optional. The encoding type for the result ("base64" or "bytes"). Default: "bytes".opts: Optional. Argon2 configuration options. Default uses secure defaults.Default Argon2 Options:
t: 2 (time cost/iterations)m: 102400 (memory cost in KiB, ~100MB)p: 8 (parallelism)dkLen: 32 (derived key length in bytes)toBytes(base64: string): Uint8ArrayConverts a base64 string to a Uint8Array.
bytesToBase64(bytes: Uint8Array, urlSafe = false): stringConverts a Uint8Array to a base64 string.
bytes: The bytes to convert.urlSafe: Optional. Whether to use URL-safe base64 encoding. Default: false.encodeData<E extends EncodingType>(data: Uint8Array, encoding: E): EncodedReturnType<E>Encodes data in the specified format.
data: The data to encode.encoding: The encoding type ("base64" or "bytes").This library leverages the following dependencies for cryptographic operations:
# Clone the repository
git clone https://github.com/fileverse/fileverse-cryptography.git
cd crypto
# Install dependencies
npm install
# Run tests
npm test
# Build the library
npm run build
# Run all tests
npm test
# Run specific test files
npx vitest run src/ecies/__tests__/core.test.ts
This library supports all modern browsers that implement the Web Crypto API and TextEncoder/TextDecoder APIs:
GNU GPL
FAQs
Crypto functions and helpers
The npm package @fileverse/crypto receives a total of 24 weekly downloads. As such, @fileverse/crypto popularity was classified as not popular.
We found that @fileverse/crypto demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.

Research
/Security News
Socket researchers found 10 typosquatted npm packages that auto-run on install, show fake CAPTCHAs, fingerprint by IP, and deploy a credential stealer.