@hpke/ohttp
Version:
Oblivious HTTP (RFC 9458) client and server using HPKE
57 lines • 2.35 kB
TypeScript
import type { KemInterface } from "@hpke/common";
import { type OhttpSuite } from "./suite.js";
/** Parameters for {@link createOhttpServer}. */
export interface OhttpServerParams {
/** Key identifier (0-255) advertised in the key configuration. */
keyId: number;
/** KEM primitive instance to use. */
kem: KemInterface;
/** KDF/AEAD pairs the gateway supports, in order of preference. */
suites: OhttpSuite[];
/** Existing key pair for `kem`. A new key pair is generated if omitted. */
keyPair?: CryptoKeyPair;
}
/** Context returned by {@link OhttpServer.decapsulateRequest}. */
export interface OhttpServerContext {
/** Decrypted target request. */
readonly request: Request;
/** Encrypts the response into an encapsulated response (`message/ohttp-res`). */
encapsulateResponse(response: Response): Promise<Uint8Array>;
}
/**
* OHTTP server, i.e. the Oblivious Gateway Resource (RFC 9458).
*
* Created with {@link createOhttpServer}.
*/
export interface OhttpServer {
/** Serialized key configuration (`application/ohttp-keys`). */
readonly keyConfig: Uint8Array;
/**
* Handles an HTTP request from the Oblivious Relay Resource.
*
* The encapsulated request is decrypted and passed to `handler`, and the
* response returned by `handler` is encapsulated into a
* `message/ohttp-res` response. This is the counterpart of
* `OhttpClient.fetch()`.
*
* Requests that cannot be processed are answered with a 4xx response
* without calling `handler`. Errors thrown by `handler` are propagated to
* the caller.
*/
handle(request: Request, handler: (request: Request) => Response | Promise<Response>): Promise<Response>;
/**
* Decapsulates an encapsulated request (`message/ohttp-req`), for manual
* communication with the relay.
*/
decapsulateRequest(encapsulatedRequest: Uint8Array): Promise<OhttpServerContext>;
}
/**
* Creates an OHTTP server, i.e. an Oblivious Gateway Resource (RFC 9458).
*
* A key pair is generated unless `keyPair` is given, and the key
* configuration to be published is built up front.
*
* @throws {OhttpError} if the parameters are invalid.
*/
export declare function createOhttpServer(params: OhttpServerParams): Promise<OhttpServer>;
//# sourceMappingURL=server.d.ts.map