Skip to content

Function: openStream() ​

openStream(secretKey, source, options?): AsyncGenerator<Uint8Array<ArrayBufferLike>>

Defined in: stream.ts:388

Decrypts a stream produced by sealStream. The source may deliver the bytes in pieces of any size. Yields the plaintext chunk by chunk. It throws on the first chunk that fails; a truncated, extended, reordered or modified stream never completes silently.

The prelude is read first (magic, then the header length, which must be 1 to 65,536); each frame length must be 16 to chunkSize + 16. A frame is the last one when the source has no byte after it. The opener is freed when the generator finishes, throws or is closed.

Parameters ​

secretKey ​

SecretKey

The recipient's KEM secret key.

source ​

ByteSource

The encrypted stream, as an async or sync iterable of byte arrays of any sizes.

options? ​

OpenStreamOptions = {}

expectedAad, the associated data the sender used (default none).

Returns ​

AsyncGenerator<Uint8Array<ArrayBufferLike>>

An async generator of the plaintext chunks.

Throws ​

on authentication failure; MalformedCiphertextError for a malformed prelude or frame.

Throws ​

if the header's algorithm differs from the key's.

Throws ​

if the header names an algorithm that streams do not support.

Throws ​

if secretKey is not a SecretKey or a piece of source is not bytes.

Apache-2.0.