Passcode envelopes
Passcode-protected envelope encryption for recipients without a Conseal account.
Signatures
Section titled “Signatures”sealEnvelope(plaintext: ArrayBuffer, passcode: string): Promise<SealedEnvelope>unsealEnvelope(envelope: SealedEnvelope, passcode: string): Promise<ArrayBuffer>encodeEnvelope(envelope: SealedEnvelope): stringdecodeEnvelope(json: string): SealedEnvelope
interface SealedEnvelope { version: 1 ciphertext: ArrayBuffer iv: Uint8Array wrappedKey: ArrayBuffer salt: Uint8Array}Example
Section titled “Example”import { sealEnvelope, unsealEnvelope, encodeEnvelope, decodeEnvelope } from '@consealdev/conseal'
// Sender: seal the file and upload the result to the serverconst plaintext = await file.arrayBuffer()const envelope = await sealEnvelope(plaintext, 'tiger-moon-7')const json = encodeEnvelope(envelope)// POST json → server returns a link id// Sender shares:// Link → via email/message (comes from sender's own address)// Passcode 'tiger-moon-7' → via separate channel (SMS, phone call)
// Recipient: open the link, enter the passcode, decrypt in browserconst received = await fetch(`/d/${linkId}`).then(r => r.text())const sealed = decodeEnvelope(received)const result = await unsealEnvelope(sealed, 'tiger-moon-7')const blob = new Blob([result])- The server stores the encoded envelope JSON — useless without the passcode.
- A
SealedEnvelopeholdsArrayBufferandUint8Arrayfields, whichJSON.stringifyloses or corrupts, so always go throughencodeEnvelopeanddecodeEnvelope. decodeEnvelopethrows aSyntaxErrorfor text that isn’t JSON, and aTypeErrorfor an unsupportedversionor a missing or malformed field.- The passcode must travel via a different channel than the link (two-channel delivery).
sealEnvelope()takes ~500ms due to PBKDF2 — show a loading indicator.- Throws if the passcode is wrong.