import { type KeyObject } from "node:crypto"; /** The signing suite. AP2 mandates in this package are ES256 over P-256, always. */ export declare const SIGNING_ALG: "ES256"; /** Fragment of the gate's verification method — also every mandate's `kid`. */ export declare const KEY_FRAGMENT = "gate-signing-key"; /** * Fragment of the merchant's CHECKOUT key — the `kid` on every UCP Checkout this gate quotes. * * A separate key from the mandate key (spec 014, FR-6): a cart the merchant quotes and a mandate * the gate issues are different statements, and the `kid` says which one a signature makes. */ export declare const CHECKOUT_KEY_FRAGMENT = "merchant-checkout-key"; /** A P-256 PRIVATE JWK — what a host injects as `{ mandateSigningKey }`. `d` is the secret. */ export interface PrivateJwkP256 { kty: "EC"; crv: "P-256"; x: string; y: string; d: string; } /** A P-256 public JWK, as it appears in a DID document and in a `cnf` claim. */ export interface PublicJwkP256 { kty: "EC"; crv: "P-256"; x: string; y: string; alg?: string; kid?: string; } export interface GateSigningKey { /** `#gate-signing-key` — the `kid` on every mandate this gate signs. */ kid: string; /** `did:web:`, or `did:web::` for a store served under a path — the * mandates' `iss`. See {@link didWebFor}. */ issuer: string; privateKey: KeyObject; publicJwk: PublicJwkP256; /** True when nobody supplied a key and we made one up at boot. Surfaced by doctor.ts. */ ephemeral: boolean; } /** * `did:web` for an origin, per the did:web method: the authority percent-encoded, then each path * segment as its own colon-separated, percent-encoded part (a trailing slash, the query and the * fragment are ignored). A root origin is `did:web:shop.example`, resolved at * `https://shop.example/.well-known/did.json`; a store served under a path is * `did:web:shop.example:store`, resolved at `https://shop.example/store/did.json` — both of * which `mount()` serves. */ export declare function didWebFor(origin: string): string; /** * Import a PRIVATE P-256 JWK, refusing one that is not what it claims. `label` names the secret * in every error, so the message says which one is broken. * * The public half is DERIVED from `d`, never copied from the JWK's `x` / `y`. Not every node * build refuses a JWK whose `x` / `y` do not belong to its `d` at import — and on those that * accept it, `createPublicKey(privateKey)` hands the imported `x` / `y` straight back rather * than recomputing them, so it is no check at all. Only a scalar multiplication of `d` is; * copying them would publish a key that matches nothing we sign, so every signature would fail * its own check while doctor() stayed green. A mismatch is a broken secret, refused here rather * than at the first verify. */ export declare function importPrivateJwk(jwk: PrivateJwkP256, label: string): { privateKey: KeyObject; x: string; y: string; }; /** * Resolve the gate's signing key. * * `hostKey` is a PRIVATE P-256 JWK the host controls (read it from a secret manager, not * from source). Absent ⇒ an ephemeral key, flagged as such rather than silently accepted. */ export declare function resolveSigningKey(origin: string, hostKey?: PrivateJwkP256, fragment?: string): GateSigningKey; /** A key made up at boot for `issuer#fragment` — flagged `ephemeral`, never silently accepted. */ export declare function ephemeralSigningKey(issuer: string, fragment: string): GateSigningKey; /** Import a P-256 public JWK for verification (a `cnf` key, or our own from a DID doc). */ export declare function importVerifyKey(jwk: PublicJwkP256): KeyObject; /** * The DID document `mount()` serves at `/.well-known/did.json` (a root store) or `/did.json` (a * store served under a path). * * The mandate-signing key, then any further keys this gate signs with — today the merchant's * checkout key (FR-6). `assertionMethod` is the right relationship for issuing statements; * listing `authentication` too would over-state what these keys are for. The mandate key is * listed FIRST, so a reader that takes the first assertion method still gets it. */ export declare function didDocument(key: GateSigningKey, ...more: GateSigningKey[]): Record; /** * The other half of {@link didDocument}: turn a fetched DID document into the * `publicJwk` {@link verifyMandate} takes — so checking a mandate somebody else's gate signed * is a fetch and two calls, not hand-written plumbing. * * A root store's document is at `https://shop.example/.well-known/did.json`; a store served * under a path (`did:web:shop.example:store`) publishes it at `https://shop.example/store/did.json`. * * ```ts * const doc = await (await fetch("https://shop.example/.well-known/did.json")).json(); // or /did.json * const verdict = await verifyMandate(token, { publicJwk: publicJwkFromDidDocument(doc) }); * ``` * * Returns the key with its `kid` set to the verification method's id, which is what makes * `verifyMandate` also check the mandate's `iss` / `kid`. Throws when the document does not * publish an EC P-256 assertion key it controls: a key that is not an assertion method was * never published for signing mandates, and must not be quietly used for it. */ export declare function publicJwkFromDidDocument(doc: unknown, kid?: string): PublicJwkP256;