@hpke/ohttp
Version:
Oblivious HTTP (RFC 9458) client and server using HPKE
60 lines • 2.23 kB
TypeScript
import type { KemInterface } from "@hpke/common";
import type { OhttpKeyConfig } from "./keyConfig.js";
import { type OhttpSuite } from "./suite.js";
/** Parameters for {@link createOhttpClient}. */
export interface OhttpClientParams {
/** KEM primitive instance to use. */
kem: KemInterface;
/**
* KDF/AEAD pairs the client supports. The first pair advertised by the
* gateway's key configuration that is included here is used.
*/
suites: OhttpSuite[];
/**
* Gateway's key configuration: raw `application/ohttp-keys` bytes or a
* parsed configuration. When the raw bytes contain multiple
* configurations, the first one the client supports is used.
*/
keyConfig: Uint8Array | OhttpKeyConfig;
/**
* URL of the Oblivious Relay Resource. Required only for
* {@link OhttpClient.fetch}.
*/
relayUrl?: string | URL;
}
/** Context returned by {@link OhttpClient.encapsulateRequest}. */
export interface OhttpClientContext {
/** Encapsulated request (`message/ohttp-req`). */
readonly encapsulatedRequest: Uint8Array;
/** Decrypts the corresponding encapsulated response (`message/ohttp-res`). */
decapsulateResponse(encapsulatedResponse: Uint8Array): Promise<Response>;
}
/**
* OHTTP client (RFC 9458).
*
* Created with {@link createOhttpClient}.
*/
export interface OhttpClient {
/**
* Sends an HTTP request through the Oblivious Relay Resource.
*
* The signature mirrors the standard `fetch()` API. Requires `relayUrl`.
*/
fetch(input: Request | string | URL, init?: RequestInit): Promise<Response>;
/**
* Encapsulates a request without sending it, for manual communication
* with the relay.
*/
encapsulateRequest(request: Request): Promise<OhttpClientContext>;
}
/**
* Creates an OHTTP client (RFC 9458).
*
* The gateway's key configuration is validated against the given
* primitives and its public key is imported once, up front.
*
* @throws {OhttpError} if the key configuration is invalid or not supported
* by the given primitives.
*/
export declare function createOhttpClient(params: OhttpClientParams): Promise<OhttpClient>;
//# sourceMappingURL=client.d.ts.map