Context for encrypting multiple messages and exporting secrets on the sender side.
SenderContext instance is obtained from CipherSuite.SetupSender.
This context maintains an internal sequence number that increments with each Seal operation, ensuring nonce uniqueness for the underlying AEAD algorithm.
let suite!: HPKE.CipherSuite
let publicKey!: HPKE.Key // recipient's public key
const { encapsulatedSecret, ctx } = await suite.SetupSender(publicKey)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.SenderContext
// Export a 32-byte secret
const exporterContext: Uint8Array = new TextEncoder().encode('exporter context')
const exportedSecret: Uint8Array = await ctx.Export(exporterContext, 32)
// The recipient can derive the same secret using the same exporterContextSeal(
plaintext,aad?):Promise<Uint8Array>
Encrypts plaintext with additional authenticated data. Each successful call automatically increments the sequence number to ensure nonce uniqueness.
| Parameter | Type | Description |
|---|---|---|
plaintext |
Uint8Array |
Plaintext to encrypt |
aad? |
Uint8Array |
Additional authenticated data |
Promise<Uint8Array>
A Promise that resolves to the ciphertext. The ciphertext is Nt bytes longer than the plaintext.
let ctx!: HPKE.SenderContext
// Encrypt multiple messages with the same context
const aad1: Uint8Array = new TextEncoder().encode('message 1 aad')
const pt1: Uint8Array = new TextEncoder().encode('First message')
const ct1: Uint8Array = await ctx.Seal(pt1, aad1)
const aad2: Uint8Array = new TextEncoder().encode('message 2 aad')
const pt2: Uint8Array = new TextEncoder().encode('Second message')
const ct2: Uint8Array = await ctx.Seal(pt2, aad2)get mode():
number
number
The mode (0x00 = Base, 0x01 = PSK) for this context.
get Nt():
number
number
The length in bytes of an authentication tag for the AEAD algorithm used by this context.
get seq():
number
number
The sequence number for this context's next Seal, initially zero, increments
automatically with each successful Seal. The sequence number provides AEAD nonce
uniqueness. The maximum supported sequence number in this implementation is 2^53-1.