Context for decrypting multiple messages and exporting secrets on the recipient side.
RecipientContext instance is obtained from CipherSuite.SetupRecipient.
let suite!: HPKE.CipherSuite
let privateKey!: HPKE.Key | HPKE.KeyPair
// ... receive encapsulatedSecret from sender
let encapsulatedSecret!: Uint8Array
const ctx: HPKE.RecipientContext = await suite.SetupRecipient(privateKey, encapsulatedSecret)Export(
exporterContext,length):Promise<Uint8Array>
Exports a secret using a variable-length pseudorandom function (PRF).
The exported secret is indistinguishable from a uniformly random bitstring of equal length.
| Parameter | Type | Description |
|---|---|---|
exporterContext |
Uint8Array |
Context for domain separation |
length |
number |
Desired length of exported secret in bytes |
Promise<Uint8Array>
A Promise that resolves to the exported secret.
let ctx!: HPKE.RecipientContext
// Export a 32-byte secret
const exporterContext: Uint8Array = new TextEncoder().encode('exporter context')
const exported: Uint8Array = await ctx.Export(exporterContext, 32)
// The sender can derive the same secret using the same exporterContextOpen(
ciphertext,aad?):Promise<Uint8Array>
Decrypts ciphertext with additional authenticated data.
Applications must ensure that ciphertexts are presented to Open in the exact order they were
produced by the sender.
| Parameter | Type | Description |
|---|---|---|
ciphertext |
Uint8Array |
Ciphertext to decrypt |
aad? |
Uint8Array |
Additional authenticated data |
Promise<Uint8Array>
A Promise that resolves to the decrypted plaintext.
let ctx!: HPKE.RecipientContext
// Decrypt multiple messages with the same context
let aad1!: Uint8Array | undefined
let ct1!: Uint8Array
const pt1: Uint8Array = await ctx.Open(ct1, aad1)
let aad2!: Uint8Array | undefined
let ct2!: Uint8Array
const pt2: Uint8Array = await ctx.Open(ct2, aad2)get mode():
number
number
The mode (0x00 = Base, 0x01 = PSK) for this context.
get seq():
number
number
The sequence number for this context's next Open, initially zero, increments
automatically with each successful Open. The sequence number provides AEAD nonce
uniqueness. The maximum supported sequence number in this implementation is 2^53-1.