Optionalkey: string | Uint8Array<ArrayBufferLike> | nullOptionaloptions: Get the salt as a base64url string.
Get a header string: Bearer sync-v1 ${authTokenB64}.
Pass in a token, or else this will use the authToken derived from
the main key.
OptionaltokenString: stringget a promise for the auth token.
Get the auth token as a base64url string.
SHA-256 digest of the plaintext, used as the input to content-bound salt derivation. Accepts a stream, a byte array, or a Blob; equivalent content yields the same digest.
Pass the result to encryptStream/header/encryptRecord as
contentDigest. The salt is derived from this digest internally,
so the Keychain API never exposes a raw salt — a fixed salt can
never pair with two different plaintexts.
NOTE: WebCrypto has no incremental hash, so a stream/Blob is drained into memory before hashing.
Plaintext as a ReadableStream, Uint8Array, or Blob.
32-byte SHA-256 digest.
Decrypt in memory, not streaming.
Optionalopts: { size?: number }
Pass the same size that was
given to encryptBytes, so the same-length key is re-derived.
Take an encrypted stream, return a decrypted stream.
The input (encrypted) stream
Optionalopts: { recordSize?: number }
{ recordSize? }. Optional validation hint. Stream
decryption reads the ECE salt and record size from the encrypted
stream header.
The decrypted stream
Returns an object containing ranges, an array of objects
containing offset and length integers specifying the encrypted byte
ranges that are needed to decrypt the client's specified range, and a
decrypt function.
Integer
Integer
Integer
Optionalopts: { recordSize?: number }
Pass the same recordSize
that was used to encrypt the stream; defaults to RECORD_SIZE
(65536).
Encrypt and return some data; don't stream.
NOTE: The key is derived deterministically from the main key via
this.generateKey, not freshly generated — that is why
decryptBytes is able to re-derive the same key and decrypt.
SAFETY: if a caller-supplied iv is reused across two calls with
different plaintexts (same derived key), that is AES-GCM nonce
reuse and breaks confidentiality. Omit iv to get a random one
per call.
Optionalopts: { iv?: Uint8Array<ArrayBufferLike>; size?: number }
Optional params,
iv and size. If size is omitted, default is 16 bytes. iv is
a random 12 bytes, will be generated if not passed in.
Encrypt a single ECE record by index, byte-identical to record
seq of encryptStream({ contentDigest, recordSize }). The salt
is derived from contentDigest internally; no raw salt is
accepted.
Non-final records must be exactly recordPlaintextSize(recordSize)
bytes; the final record must be <= that. The low-level function
throws otherwise.
Zero-based record index.
The record's plaintext slice.
{ isLast, contentDigest, recordSize? }.
The encrypted record bytes.
Take a stream, return an encrypted stream.
With opts.contentDigest, the ECE salt is derived from the digest
internally (deriveContentSalt), so two calls over identical input
produce byte-identical ciphertext (reproducible encryption). With no
opts, a fresh random salt is used (today's behavior).
The salt is never accepted directly: because it is bound to the content digest, a fixed salt can never encrypt two different plaintexts (AES-GCM nonce-reuse is structurally unreachable from this API).
Input plaintext stream.
Optionalopts: { contentDigest?: Uint8Array<ArrayBufferLike>; recordSize?: number }
Optional { contentDigest?, recordSize? }.
Encrypted stream.
Derive a new AES-GCM key from the main key.
OptionalkeyLength: number
Optional size for the key, in bytes, eg,
16 or 32.
Build the 21-byte ECE header for content identified by
contentDigest. The salt is derived internally from the digest,
so this never exposes a raw salt. The header is byte-identical to
the header that encryptStream({ contentDigest, recordSize })
emits for the same input.
{ contentDigest, recordSize? }.
The 21-byte header.
Set the auth token
OptionalauthToken: string | Uint8Array<ArrayBufferLike>
The new token
StaticAuthGet an authentication header as a static method.
StaticHeader
Get the main key as a
base64urlencoded string