Skip to content

filecoin-encryption-envelope

Encrypt, decrypt, and inspect Filecoin Encryption Envelope objects.

Implements the draft format under review in the FEE specification proposal.

import * as fee from 'filecoin-encryption-envelope'

source.pipeThrough(fee.encrypt({ cek }))  // chunked stream, the default
encrypted.pipeThrough(fee.decrypt(cek))    // and back
await fee.decryptRange(object, cek, { offset: 1024, length: 4096 })  // one byte range
fee.aesGcm.encrypt(plaintext, { cek })     // whole-object, opt-in
fee.constants.ALG_A256KW
Namespace Description
aesGcm -
constants -
cose Decode Filecoin Encryption Envelope headers and recipient entries without decrypting the content. Decoding does not authenticate the envelope.
errors -
recipients -
Interface Description
ByteRange A byte range over an object’s plaintext, HTTP Range-header style.
ChunkedEncryptOptions Options for one chunked AES-256-GCM STREAM encryption using a direct CEK.
ChunkedEnvelopeParams Cached values from one chunked envelope’s protected header, for range decryption to reuse.
DecryptOptions Options for decrypt and decryptWith.
ParseOptions Options for parse.
RandomAccessSource One immutable encoded FEE object, readable by byte range.
RangeDecryptOptions Options for decryptRange and decryptRangeWith.
RangeResult -
Type Alias Description
AppMetadata Opaque, string-keyed application metadata. Carried but never interpreted.
CborValue CBOR values supported by this profile.
EnvelopeInfo Only the chunked scheme carries params: scheme 1 is decrypted as one complete object, never by range.
KeyResolver Derives or fetches the CEK for a chunked object, given its EnvelopeInfo and an AbortSignal.
Function Description
ciphertextLengthForPlaintext Detached ciphertext length a plaintext of plaintextLength bytes produces at chunkSize: P + 16 × max(1, ceil(P / S)), adding one 16-byte (TAG_SIZE) authentication tag per chunk — including one tag even for empty input (0).
decrypt Creates a streaming decryptor for a scheme-2 object using either a direct CEK or a KeyResolver.
decryptRange Decrypt one byte range of a chunked object using a direct CEK.
decryptRangeWith Like decryptRange, but recovers the CEK from the envelope’s recipients through unwrapper.
decryptWith Decrypt a scheme-2 object using a CEK recovered by unwrapper.
encrypt Creates a streaming encryptor using scheme 2 (chunked AES-256-GCM STREAM) with a direct CEK.
parse Inspect an encoded FEE object without a key: scheme, content type, application metadata, and recipients. Unauthenticated – see above.