@hpke/ohttp
Version:
Oblivious HTTP (RFC 9458) client and server using HPKE
47 lines • 2.07 kB
TypeScript
import type { CipherSuite } from "@hpke/core";
/**
* Build the 7-byte header:
* keyId (1) || kemId (2) || kdfId (2) || aeadId (2)
*/
export declare function buildHeader(keyId: number, kemId: number, kdfId: number, aeadId: number): Uint8Array;
export interface EncapsulateRequestResult {
encRequest: Uint8Array;
context: RequestContext;
}
/** State retained by the client to decrypt the corresponding response. */
export interface RequestContext {
enc: Uint8Array;
suite: CipherSuite;
senderExport: (exporterContext: ArrayBufferLike, len: number) => Promise<ArrayBuffer>;
}
/**
* Encapsulate an OHTTP request (RFC 9458 Section 4.3).
*
* Returns the encrypted request and a context for decapsulating the response.
*/
export declare function encapsulateRequest(suite: CipherSuite, keyId: number, kemId: number, kdfId: number, aeadId: number, recipientPublicKey: CryptoKey, binaryRequest: Uint8Array): Promise<EncapsulateRequestResult>;
export interface DecapsulateRequestResult {
binaryRequest: Uint8Array;
context: ResponseContext;
}
/** State retained by the gateway to encrypt the response. */
export interface ResponseContext {
enc: Uint8Array;
suite: CipherSuite;
recipientExport: (exporterContext: ArrayBufferLike, len: number) => Promise<ArrayBuffer>;
}
/**
* Decapsulate an OHTTP request on the gateway side (RFC 9458 Section 4.3).
*/
export declare function decapsulateRequest(suite: CipherSuite, recipientKey: CryptoKey, keyId: number, kemId: number, encRequest: Uint8Array): Promise<DecapsulateRequestResult>;
/**
* Encapsulate an OHTTP response on the gateway side (RFC 9458 Section 4.4).
*
* Uses the HPKE exporter to derive response key/nonce.
*/
export declare function encapsulateResponse(ctx: ResponseContext, binaryResponse: Uint8Array): Promise<Uint8Array>;
/**
* Decapsulate an OHTTP response on the client side (RFC 9458 Section 4.4).
*/
export declare function decapsulateResponse(ctx: RequestContext, encResponse: Uint8Array): Promise<Uint8Array>;
//# sourceMappingURL=encapsulation.d.ts.map