decrypt
decrypt(
key,options?):ReadableWritablePair<Uint8Array<ArrayBufferLike>,Uint8Array<ArrayBufferLike>>
Defined in: packages/filecoin-encryption-envelope/src/aes-gcm-stream.ts:635
Creates a streaming decryptor for a scheme-2 object using either a direct
CEK or a KeyResolver.
The writable side accepts the encoded object. The readable side emits each plaintext chunk only after its authentication tag has been verified.
A KeyResolver is called at most once, after the envelope is decoded and
before any ciphertext is decrypted. It receives the same EnvelopeInfo
reported by parse and an AbortSignal that aborts if the stream is
cancelled, aborted (including via options.signal), or fails (but not on
successful EOF). The resolver is not called if the stream fails or
options.signal aborts before that point, or if the readable side is never
consumed.
EnvelopeInfo is derived from unauthenticated envelope data, so a resolver
must treat it as untrusted input when deciding which key to derive or fetch.
Plaintext remains protected by the AEAD authentication performed afterward.
FEE borrows the key bytes (whether passed directly or returned by a
KeyResolver) only long enough to import them into a non-extractable
CryptoKey and never zeroes the caller’s buffer. The caller owns every key
it returns — including one FEE discards after cancellation — and should zero
it once the stream settles.
Resolver failures are wrapped in KeyResolutionError unless the stream
aborted; an invalid resolved key is rejected as an invalid CEK. When
options.signal aborts, both sides of the returned pair error with the exact
signal.reason, pending writes are unblocked, and any late key result is
discarded without validating or importing it.
Input blocks may be reused once their corresponding write() resolves.
If decryption later fails, any plaintext already emitted belongs to an
incomplete object and must be discarded.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
key |
Uint8Array<ArrayBufferLike> | KeyResolver |
options? |
DecryptOptions |
Returns
Section titled “Returns”ReadableWritablePair<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>