Skip to content

Conseal is pre-release. The interface can change between releases.

Crypto core

@consealdev/conseal is the crypto core. It is built only on SubtleCrypto, plus a BIP-39 library for the recovery phrase, and it makes no network calls: your app owns the transport and the storage of every payload. It is ESM only, and runs in browsers and in Node 20 or newer, anything with crypto.subtle. Key storage needs IndexedDB.

import { generateAesKey, seal, unseal } from '@consealdev/conseal';
  • Sealing: AES-256-GCM, with a random IV for each record. Calls: seal, unseal, generateAesKey, importAesKey.
  • Passphrase key wrapping: The account key under a passphrase, with PBKDF2. Calls: wrapKey, unwrapKey, rekey, rekeySecretKey.
  • Secret Key: A second factor combined with the passphrase. Calls: generateSecretKey, combinePassphraseAndSecretKey.
  • Setting up a device: Unwrap the account key and keep it on the device. Calls: init, AEK_KEY_ID.
  • Key storage: Keys in IndexedDB, where a non-extractable key stays non-extractable. Calls: saveCryptoKey, loadCryptoKey, deleteCryptoKey.
  • Recovery phrase: A 24-word BIP-39 phrase that derives the account key. Calls: generateMnemonic, recoverWithMnemonic.
  • Encrypting to a public key: ECDH P-256, for data sent to another account. Calls: generateECDHKeyPair, sealMessage, unsealMessage.
  • Signing: ECDSA P-256, to verify the sender. Calls: generateECDSAKeyPair, sign, verify.
  • Public keys as JWK: Public keys as JSON, to register and fetch. Calls: exportPublicKeyAsJwk, importPublicKeyFromJwk.
  • Passcode envelopes: Data for someone without an account, opened with a passcode. Calls: sealEnvelope, unsealEnvelope, encodeEnvelope, decodeEnvelope.
  • The circle: A user’s devices sharing one key, joined by a confirmed code. Calls: initCircle, createJoinRequest, authorizeJoin, finalizeJoin, deriveVerificationCode.
  • Channels: A key shared between users. Calls: createChannel, unwrapChannelAEK and the channel join calls.
  • Base64 and digest: Encoding and SHA-256. Calls: toBase64, fromBase64, toBase64Url, fromBase64Url, digest.

The terms are in the glossary.

  • Binary in, binary out. Functions take ArrayBuffer or Uint8Array, not strings or File. Convert at the edge, with await file.arrayBuffer() or TextEncoder.
  • Keep keys non-extractable unless they must be wrapped or transferred. Only the key given to wrapKey and the keys in the circle ceremony need to be extractable.
  • Store each iv, salt and ephemeralPublicKey with its ciphertext. None of them is secret, and all of them are needed to decrypt.
  • A wrong passphrase or a tampered record throws. SubtleCrypto raises an OperationError. Catch it at the screen and say “wrong passphrase”, not the raw error.
  • Some risks are the app’s. Script running on your page can use keys the page stored, a weak passphrase is weak, and JavaScript can’t wipe key bytes from memory. The threat model lists them, and the app’s copy shouldn’t claim otherwise.