mppx 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/cli.js +2 -2
  3. package/dist/cli/plugins/index.js +1 -1
  4. package/dist/evm/server/Charge.js +104 -0
  5. package/dist/extensions/identity/attestation/Issuer.d.ts +91 -0
  6. package/dist/extensions/identity/attestation/Issuer.js +159 -0
  7. package/dist/extensions/identity/attestation/Token.js +7 -0
  8. package/dist/extensions/identity/attestation/Types.d.ts +31 -3
  9. package/dist/extensions/identity/attestation/index.d.ts +3 -1
  10. package/dist/extensions/identity/attestation/index.js +3 -1
  11. package/dist/extensions/identity/tempo/Constants.d.ts +4 -0
  12. package/dist/extensions/identity/tempo/Constants.js +4 -0
  13. package/dist/extensions/identity/tempo/client/index.d.ts +63 -0
  14. package/dist/extensions/identity/tempo/client/index.js +151 -0
  15. package/dist/extensions/identity/tempo/index.d.ts +1 -0
  16. package/dist/extensions/identity/tempo/index.js +1 -0
  17. package/dist/extensions/identity/tempo/issuer/index.d.ts +83 -0
  18. package/dist/extensions/identity/tempo/issuer/index.js +183 -0
  19. package/dist/internal/version.d.ts +2 -2
  20. package/dist/internal/version.js +1 -1
  21. package/dist/proxy/internal/Headers.js +1 -0
  22. package/dist/server/Mppx.js +28 -1
  23. package/dist/tempo/server/internal/html.gen.js +1 -1
  24. package/dist/x402/Siwx.d.ts +270 -0
  25. package/dist/x402/Siwx.js +458 -0
  26. package/dist/x402/Types.d.ts +6 -6
  27. package/dist/x402/Types.js +1 -1
  28. package/dist/x402/index.d.ts +1 -0
  29. package/dist/x402/index.js +1 -0
  30. package/dist/x402/server/EvmCharge.d.ts +7 -0
  31. package/dist/x402/server/EvmCharge.js +14 -1
  32. package/package.json +1 -1
@@ -5,6 +5,7 @@ import * as Method from '../../Method.js';
5
5
  import * as Receipt from '../../Receipt.js';
6
6
  import * as ServerTransport from '../../server/Transport.js';
7
7
  import * as X402 from '../../x402/server/EvmCharge.js';
8
+ import * as Siwx from '../../x402/Siwx.js';
8
9
  import * as Assets from '../Assets.js';
9
10
  import * as Methods from '../Methods.js';
10
11
  import * as Types from '../Types.js';
@@ -13,6 +14,7 @@ export function charge(parameters) {
13
14
  const paths = createPaths(config);
14
15
  const transport = httpTransport(paths);
15
16
  return Method.toServer(Methods.charge, {
17
+ ...(config.x402.siwx ? { authorize: siwxAuthorize(config.x402.siwx) } : {}),
16
18
  canOffer: parameters.canOffer,
17
19
  onPaymentSuccess: parameters.onPaymentSuccess,
18
20
  defaults: {
@@ -206,6 +208,108 @@ function httpTransport(paths) {
206
208
  },
207
209
  });
208
210
  }
211
+ /**
212
+ * SIWX nonces each request has claimed, per replay store, shared by the offers of a
213
+ * composed route. Offers with their own stores each record the nonce in theirs.
214
+ */
215
+ const siwxClaims = new WeakMap();
216
+ /**
217
+ * SIWX nonces an offer of each request found already used. Later offers of a composed
218
+ * route refuse them too, so an offer whose store never saw the nonce can't accept a replay.
219
+ */
220
+ const siwxReplays = new WeakMap();
221
+ /**
222
+ * Grants a request that carries a valid x402 SIWX proof without payment, when the
223
+ * server's `grant` approves the wallet. A request without a proof, or one `grant`
224
+ * refuses, gets the route's 402; an invalid proof gets it with the spec's error code.
225
+ */
226
+ function siwxAuthorize(siwx) {
227
+ return async ({ input, request }) => {
228
+ const value = input.headers.get(Siwx.header);
229
+ if (!value)
230
+ return undefined;
231
+ try {
232
+ const payload = Siwx.decode(value);
233
+ const proof = await Siwx.verify({
234
+ chainId: request.methodDetails.chainId,
235
+ options: siwx,
236
+ payload,
237
+ });
238
+ // A copy, as canOffer and selectOffers get, so a grant that reads the body leaves it
239
+ // for the route handler. Taken before the claim, so a body already read can't spend the
240
+ // nonce: grant then gets the request without its body.
241
+ const copy = cloneGrantInput(input);
242
+ // The copy's body tees the request's, so it is cancelled once grant returns: an unread
243
+ // copy would otherwise buffer everything the route handler later streams from the request.
244
+ let granted;
245
+ try {
246
+ // Reserve the nonce before grant, so a replayed proof never reaches grant. A claim this
247
+ // request already made (a composed offer before this one declined) is shared, so a later
248
+ // offer can still grant the wallet; a proof every offer declined stays spent, so it can't
249
+ // be replayed once grant would approve the wallet. Clients sign a fresh proof each time.
250
+ const stores = siwxClaims.get(input) ?? new WeakMap();
251
+ siwxClaims.set(input, stores);
252
+ const claimed = stores.get(siwx.store) ?? new Set();
253
+ stores.set(siwx.store, claimed);
254
+ const key = `${payload.nonce}:${payload.issuedAt}`;
255
+ const replays = siwxReplays.get(input) ?? new Set();
256
+ siwxReplays.set(input, replays);
257
+ if (replays.has(key))
258
+ throw new Siwx.InvalidProofError('invalid_siwx_nonce');
259
+ if (!claimed.has(key)) {
260
+ try {
261
+ await Siwx.claim({ payload, store: siwx.store });
262
+ }
263
+ catch (error) {
264
+ if (error instanceof Siwx.InvalidProofError)
265
+ replays.add(key);
266
+ throw error;
267
+ }
268
+ claimed.add(key);
269
+ }
270
+ granted = Boolean(await siwx.grant({ ...proof, request: copy }));
271
+ }
272
+ finally {
273
+ releaseGrantInput(copy);
274
+ }
275
+ if (!granted)
276
+ return undefined;
277
+ return {
278
+ receipt: {
279
+ method: Methods.charge.name,
280
+ reference: Types.toSource({ address: proof.address, chainId: proof.chainId }),
281
+ status: 'success',
282
+ timestamp: new Date().toISOString(),
283
+ },
284
+ };
285
+ }
286
+ catch (error) {
287
+ if (error instanceof Siwx.InvalidProofError)
288
+ throw new VerificationFailedError({ reason: error.code });
289
+ throw error;
290
+ }
291
+ };
292
+ }
293
+ /** Clones a request for `grant`, falling back to a bodyless copy when its body was read. */
294
+ function cloneGrantInput(input) {
295
+ try {
296
+ return input.clone();
297
+ }
298
+ catch {
299
+ return new globalThis.Request(input.url, {
300
+ headers: new Headers(input.headers),
301
+ method: input.method,
302
+ signal: input.signal,
303
+ });
304
+ }
305
+ }
306
+ /** Cancels a grant copy's body, so its tee branch stops buffering the request's body. */
307
+ function releaseGrantInput(copy) {
308
+ if (!copy.body || copy.bodyUsed)
309
+ return;
310
+ // Not awaited: a tee branch's cancel settles only once the other branch is done too.
311
+ void copy.body.cancel().catch(() => { });
312
+ }
209
313
  function assertAddressEqual(actual, expected, reason) {
210
314
  if (getAddress(actual) === getAddress(expected))
211
315
  return;
@@ -0,0 +1,91 @@
1
+ import type { SigningKey } from '../Types.js';
2
+ import type * as Types from './Types.js';
3
+ /**
4
+ * Creates an attestation issuer: signs audience-bound `Identity-Attestation` tokens with one
5
+ * Ed25519 key and publishes that key as a JSON Web Key Set.
6
+ *
7
+ * It is the building block for any identity provider that already knows who its user is (an
8
+ * OpenID Connect sign-in, a wallet service, Tempo ID): after its own check, it calls `sign` with
9
+ * the fact it verified, one attestation per type, and serves `handle` so servers can fetch its
10
+ * key. `signingKey` may be a {@link SigningKey | Signer} whose private key stays in a KMS, HSM or
11
+ * wallet service.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const issuer = Attestation.Issuer.create({ issuer: 'https://issuer.example', signingKey })
16
+ *
17
+ * // After the user signed in with GitHub:
18
+ * const attestation = await issuer.sign({
19
+ * audience: 'https://api.example',
20
+ * type: 'github',
21
+ * sub: String(user.id),
22
+ * uid: user.accountId,
23
+ * })
24
+ *
25
+ * // In the issuer's fetch handler, before its routes:
26
+ * const answered = await issuer.handle(request)
27
+ * if (answered) return answered
28
+ * ```
29
+ */
30
+ export declare function create(config: create.Config): Issuer;
31
+ export declare namespace create {
32
+ type Config = {
33
+ /** This issuer's URL, which attestations carry as `iss` and servers trust by name. */
34
+ readonly issuer: string;
35
+ /** Ed25519 key pair, or a remote {@link SigningKey | Signer}, that signs attestations. */
36
+ readonly signingKey: SigningKey;
37
+ /** Key identifier. @default the RFC 7638 thumbprint of the public key */
38
+ readonly keyId?: string | undefined;
39
+ /** Seconds each attestation is valid. @default 3600 */
40
+ readonly ttl?: number | undefined;
41
+ };
42
+ }
43
+ /** An attestation issuer from {@link create}. */
44
+ export type Issuer = {
45
+ /** This issuer's URL, without a trailing slash. */
46
+ readonly issuer: string;
47
+ /**
48
+ * Signs one attestation for `audience`. Call it only after checking the fact it states:
49
+ * servers trust it because they trust this issuer.
50
+ */
51
+ readonly sign: (parameters: SignParameters) => Promise<string>;
52
+ /** This issuer's JSON Web Key Set. */
53
+ readonly jwks: () => Promise<{
54
+ readonly keys: readonly JsonWebKey[];
55
+ }>;
56
+ /** Resolves this issuer's key in process, for a server that runs beside it. */
57
+ readonly keyResolver: Types.KeyResolver;
58
+ /**
59
+ * Answers `GET <issuer path>/.well-known/jwks.json` with the key set, and returns `undefined`
60
+ * for every other request.
61
+ */
62
+ readonly handle: (request: Request) => Promise<Response | undefined>;
63
+ };
64
+ /** What {@link Issuer.sign} attests. */
65
+ export type SignParameters = {
66
+ /** Origin of the server the attestation is for, such as `https://api.example`. */
67
+ readonly audience: string;
68
+ /** Attestation type, such as `email` or `github`. */
69
+ readonly type: string;
70
+ /** The attested subject: an address, or the provider's stable account identifier. */
71
+ readonly sub: string;
72
+ /** The issuer's identifier for the user, shared by all of their attestations. */
73
+ readonly uid?: string | undefined;
74
+ /** What the attestation is bound to (RFC 7800). */
75
+ readonly cnf?: Types.Confirmation | undefined;
76
+ /** Other claims to include. Registered claims (`iss`, `aud`, `sub`, `type`, times) win. */
77
+ readonly claims?: Readonly<Record<string, unknown>> | undefined;
78
+ /** Seconds this attestation is valid, instead of the issuer's `ttl`. */
79
+ readonly ttl?: number | undefined;
80
+ };
81
+ /**
82
+ * Thrown by {@link Issuer.sign} for parameters it cannot sign, such as a malformed claim or a token
83
+ * longer than servers accept. Any other error comes from the signing key, such as a remote signer
84
+ * that is unavailable.
85
+ */
86
+ export declare class InvalidParametersError extends TypeError {
87
+ readonly name = "Attestation.Issuer.InvalidParametersError";
88
+ }
89
+ /** Whether a value is a `cnf` object whose `jkt` and `addr`, when present, are strings. */
90
+ export declare function isConfirmation(value: unknown): value is Types.Confirmation;
91
+ //# sourceMappingURL=Issuer.d.ts.map
@@ -0,0 +1,159 @@
1
+ import * as JwkThumbprint from '../internal/JwkThumbprint.js';
2
+ import * as Signer from '../internal/Signer.js';
3
+ import { Constants } from './Constants.js';
4
+ import { isIssuer, sign as signToken } from './Token.js';
5
+ /**
6
+ * Creates an attestation issuer: signs audience-bound `Identity-Attestation` tokens with one
7
+ * Ed25519 key and publishes that key as a JSON Web Key Set.
8
+ *
9
+ * It is the building block for any identity provider that already knows who its user is (an
10
+ * OpenID Connect sign-in, a wallet service, Tempo ID): after its own check, it calls `sign` with
11
+ * the fact it verified, one attestation per type, and serves `handle` so servers can fetch its
12
+ * key. `signingKey` may be a {@link SigningKey | Signer} whose private key stays in a KMS, HSM or
13
+ * wallet service.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const issuer = Attestation.Issuer.create({ issuer: 'https://issuer.example', signingKey })
18
+ *
19
+ * // After the user signed in with GitHub:
20
+ * const attestation = await issuer.sign({
21
+ * audience: 'https://api.example',
22
+ * type: 'github',
23
+ * sub: String(user.id),
24
+ * uid: user.accountId,
25
+ * })
26
+ *
27
+ * // In the issuer's fetch handler, before its routes:
28
+ * const answered = await issuer.handle(request)
29
+ * if (answered) return answered
30
+ * ```
31
+ */
32
+ export function create(config) {
33
+ const issuer = config.issuer.replace(/\/+$/, '');
34
+ // Key discovery appends a path to the issuer, which a query or fragment would swallow.
35
+ if (!isIssuer(issuer) || /[?#]/.test(issuer))
36
+ throw new TypeError('Attestation issuer must be an https URL (http only on localhost) without a query or fragment.');
37
+ if (config.keyId !== undefined && (typeof config.keyId !== 'string' || config.keyId === ''))
38
+ throw new TypeError('Attestation issuer keyId must be a non-empty string.');
39
+ const ttl = config.ttl ?? defaultTtl;
40
+ if (!isTtl(ttl))
41
+ throw new TypeError('Attestation issuer ttl must be a positive integer of seconds.');
42
+ const { publicKey } = Signer.resolve(config.signingKey, ['ed25519']);
43
+ const jwksPath = new URL(issuer).pathname.replace(/\/+$/, '') + Constants.jwksPath;
44
+ const key = (async () => {
45
+ const keyId = config.keyId ?? (await JwkThumbprint.fromKey(publicKey));
46
+ const { crv, kty, x } = await crypto.subtle.exportKey('jwk', publicKey);
47
+ if (kty !== 'OKP' || crv !== 'Ed25519' || !x)
48
+ throw new TypeError('Attestation issuer signingKey must be an Ed25519 key.');
49
+ const jwk = Object.freeze({ alg: Constants.algorithm, crv, kid: keyId, kty, use: 'sig', x });
50
+ return { jwk, keyId };
51
+ })();
52
+ // Fails on the first call rather than as an unhandled rejection.
53
+ key.catch(() => { });
54
+ return {
55
+ issuer,
56
+ async sign(parameters) {
57
+ const { audience, sub, type, uid, cnf, claims } = parameters;
58
+ if (!isIssuer(audience))
59
+ throw new InvalidParametersError('Attestation audience must be an https origin (http only on localhost).');
60
+ if (!isType(type))
61
+ throw new InvalidParametersError('Attestation type must be a structured-field token.');
62
+ if (typeof sub !== 'string' || sub === '')
63
+ throw new InvalidParametersError('Attestation subject must be a non-empty string.');
64
+ const lifetime = parameters.ttl ?? ttl;
65
+ if (!isTtl(lifetime))
66
+ throw new InvalidParametersError('Attestation ttl must be a positive integer of seconds.');
67
+ if (uid !== undefined && (typeof uid !== 'string' || uid === ''))
68
+ throw new InvalidParametersError('Attestation uid must be a non-empty string.');
69
+ if (cnf !== undefined && !isConfirmation(cnf))
70
+ throw new InvalidParametersError('Attestation cnf must be an object whose jkt and addr are strings.');
71
+ if (claims !== undefined &&
72
+ (typeof claims !== 'object' || claims === null || Array.isArray(claims)))
73
+ throw new InvalidParametersError('Attestation claims must be an object.');
74
+ const now = Math.floor(Date.now() / 1_000);
75
+ const payload = {
76
+ ...claims,
77
+ ...(uid !== undefined && { uid }),
78
+ ...(cnf !== undefined && { cnf }),
79
+ aud: new URL(audience).origin,
80
+ exp: now + lifetime,
81
+ iat: now,
82
+ iss: issuer,
83
+ jti: crypto.randomUUID(),
84
+ sub,
85
+ type,
86
+ };
87
+ // Extra claims may carry uid or cnf too: check what is signed, as verify will.
88
+ if (payload.uid !== undefined && (typeof payload.uid !== 'string' || payload.uid === ''))
89
+ throw new InvalidParametersError('Attestation uid must be a non-empty string.');
90
+ if (payload.cnf !== undefined && !isConfirmation(payload.cnf))
91
+ throw new InvalidParametersError('Attestation cnf must be an object whose jkt and addr are strings.');
92
+ // A toJSON hook would make JSON.stringify sign something other than this payload.
93
+ if ('toJSON' in payload ||
94
+ (typeof payload.cnf === 'object' && payload.cnf !== null && 'toJSON' in payload.cnf))
95
+ throw new InvalidParametersError('Attestation claims must not define toJSON.');
96
+ try {
97
+ JSON.stringify(payload);
98
+ }
99
+ catch {
100
+ throw new InvalidParametersError('Attestation claims must be JSON-serializable.');
101
+ }
102
+ const { keyId } = await key;
103
+ // Anything thrown from here on, other than the length check, is the signer's failure.
104
+ const token = await signToken(payload, { key: config.signingKey, keyId });
105
+ // Servers reject longer tokens, so never hand one out.
106
+ if (token.length > Constants.maxLength)
107
+ throw new InvalidParametersError(`Attestation is longer than ${Constants.maxLength} characters.`);
108
+ return token;
109
+ },
110
+ async jwks() {
111
+ return { keys: [(await key).jwk] };
112
+ },
113
+ async keyResolver({ issuer: claimed, keyId }) {
114
+ const current = await key;
115
+ if (claimed.replace(/\/+$/, '') !== issuer || keyId !== current.keyId)
116
+ return undefined;
117
+ return publicKey;
118
+ },
119
+ async handle(request) {
120
+ if (new URL(request.url).pathname !== jwksPath)
121
+ return undefined;
122
+ if (request.method !== 'GET' && request.method !== 'HEAD')
123
+ return undefined;
124
+ return Response.json({ keys: [(await key).jwk] }, {
125
+ headers: {
126
+ 'Access-Control-Allow-Origin': '*',
127
+ 'Cache-Control': 'public, max-age=300',
128
+ },
129
+ });
130
+ },
131
+ };
132
+ }
133
+ /**
134
+ * Thrown by {@link Issuer.sign} for parameters it cannot sign, such as a malformed claim or a token
135
+ * longer than servers accept. Any other error comes from the signing key, such as a remote signer
136
+ * that is unavailable.
137
+ */
138
+ export class InvalidParametersError extends TypeError {
139
+ name = 'Attestation.Issuer.InvalidParametersError';
140
+ }
141
+ /** Whether a value can be sent as a structured-field token in `Identity-Attestation-Required`. */
142
+ function isType(value) {
143
+ return typeof value === 'string' && /^[A-Za-z*][A-Za-z0-9!#$%&'*+\-.^_`|~:/]*$/.test(value);
144
+ }
145
+ /** Whether a value is a usable attestation lifetime: a positive integer of seconds, at most a year. */
146
+ function isTtl(value) {
147
+ return (typeof value === 'number' && Number.isSafeInteger(value) && value > 0 && value <= 31_536_000);
148
+ }
149
+ /** Whether a value is a `cnf` object whose `jkt` and `addr`, when present, are strings. */
150
+ export function isConfirmation(value) {
151
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
152
+ return false;
153
+ const { addr, jkt } = value;
154
+ return ((jkt === undefined || typeof jkt === 'string') &&
155
+ (addr === undefined || typeof addr === 'string'));
156
+ }
157
+ /** Default attestation lifetime, in seconds. */
158
+ const defaultTtl = 3_600;
159
+ //# sourceMappingURL=Issuer.js.map
@@ -70,6 +70,13 @@ export async function verify(token, options) {
70
70
  return invalid('The attestation has no subject.');
71
71
  if (claims.jti !== undefined && typeof claims.jti !== 'string')
72
72
  return invalid('The attestation ID is malformed.');
73
+ if (claims.uid !== undefined && (typeof claims.uid !== 'string' || claims.uid === ''))
74
+ return invalid('The attestation user ID is malformed.');
75
+ if (claims.cnf !== undefined &&
76
+ (!isObject(claims.cnf) ||
77
+ (claims.cnf.jkt !== undefined && typeof claims.cnf.jkt !== 'string') ||
78
+ (claims.cnf.addr !== undefined && typeof claims.cnf.addr !== 'string')))
79
+ return invalid('The attestation confirmation is malformed.');
73
80
  if (!isTime(claims.iat) || !isTime(claims.exp))
74
81
  return invalid('The attestation times are malformed.');
75
82
  const now = options.now ?? Math.floor(Date.now() / 1_000);
@@ -11,9 +11,16 @@ export type Claims = {
11
11
  readonly iss: string;
12
12
  /** Origin of the server the attestation is for, such as `https://api.example`. */
13
13
  readonly aud: string;
14
- /** Attested subject, such as an email address. */
14
+ /**
15
+ * Attested subject: an email address or phone number, or the provider's stable identifier for
16
+ * an account (such as a GitHub user ID), never a handle that can change.
17
+ */
15
18
  readonly sub: string;
16
- /** Attestation type, such as `email`. */
19
+ /**
20
+ * Attestation type: any structured-field token the issuer and server agree on, such as
21
+ * `email`, `phone`, `github`, `x` or `tempo-id`. One attestation states one fact; an issuer
22
+ * that knows several of a user's accounts signs one attestation of each type.
23
+ */
17
24
  readonly type: string;
18
25
  /** Issued-at time, in Unix seconds. */
19
26
  readonly iat: number;
@@ -21,7 +28,28 @@ export type Claims = {
21
28
  readonly exp: number;
22
29
  /** Unique attestation identifier. */
23
30
  readonly jti?: string | undefined;
24
- };
31
+ /**
32
+ * The issuer's identifier for the user behind the subject, the same across that issuer's
33
+ * attestations of every type, so a server can tell that an `email` and a `github`
34
+ * attestation from one issuer name the same user.
35
+ */
36
+ readonly uid?: string | undefined;
37
+ /**
38
+ * Confirmation (RFC 7800): what the attestation is bound to, such as the key that must sign
39
+ * each request (`jkt`, an RFC 7638 thumbprint) or the account that pays (`addr`).
40
+ */
41
+ readonly cnf?: Confirmation | undefined;
42
+ } & Readonly<Record<string, unknown>>;
43
+ /**
44
+ * What an attestation is bound to (RFC 7800 `cnf`). Issuers may add other members; a server
45
+ * enforces the ones it understands.
46
+ */
47
+ export type Confirmation = {
48
+ /** RFC 7638 thumbprint of the key that must sign each request. */
49
+ readonly jkt?: string | undefined;
50
+ /** Address of the account that must pay, such as a Tempo Account. */
51
+ readonly addr?: string | undefined;
52
+ } & Readonly<Record<string, unknown>>;
25
53
  /**
26
54
  * Resolves the issuer's public key for an attestation's `kid`. Returns
27
55
  * `undefined` for an unknown or malformed `kid`, and throws only when the keys
@@ -4,11 +4,13 @@
4
4
  * to and sent in `Identity-Attestation`.
5
5
  *
6
6
  * Servers require one with `Server.verifier`, clients present and obtain them with
7
- * `Client.prover`, and issuers sign them with `sign` and publish their keys as a JSON Web Key
7
+ * `Client.prover`, and issuers sign them with `Issuer.create` (or `sign`) and publish their keys as a JSON Web Key
8
8
  * Set that `Jwks.resolver` reads.
9
9
  */
10
10
  /** Client prover that presents and obtains attestations. */
11
11
  export * as Client from './client/index.js';
12
+ /** Issuer that signs attestations and publishes its key. */
13
+ export * as Issuer from './Issuer.js';
12
14
  /** Issuer JSON Web Key Set resolver. */
13
15
  export * as Jwks from './Jwks.js';
14
16
  /** Server verifier that requires an attestation. */
@@ -4,11 +4,13 @@
4
4
  * to and sent in `Identity-Attestation`.
5
5
  *
6
6
  * Servers require one with `Server.verifier`, clients present and obtain them with
7
- * `Client.prover`, and issuers sign them with `sign` and publish their keys as a JSON Web Key
7
+ * `Client.prover`, and issuers sign them with `Issuer.create` (or `sign`) and publish their keys as a JSON Web Key
8
8
  * Set that `Jwks.resolver` reads.
9
9
  */
10
10
  /** Client prover that presents and obtains attestations. */
11
11
  export * as Client from './client/index.js';
12
+ /** Issuer that signs attestations and publishes its key. */
13
+ export * as Issuer from './Issuer.js';
12
14
  /** Issuer JSON Web Key Set resolver. */
13
15
  export * as Jwks from './Jwks.js';
14
16
  /** Server verifier that requires an attestation. */
@@ -4,6 +4,10 @@ export declare const Constants: {
4
4
  readonly type: 'tempo-id';
5
5
  /** Tempo ID in production: the issuer of every access token. */
6
6
  readonly issuer: 'https://id.tempo.xyz';
7
+ /** Path, relative to a Tempo ID attestation issuer's URL, that exchanges a token for an attestation. */
8
+ readonly attestPath: '/tempo-id/attest';
9
+ /** Attestation types a Tempo ID attestation issuer signs: the user's Tempo ID and verified email. */
10
+ readonly attestationTypes: readonly ('tempo-id' | 'email')[];
7
11
  /** Header that carries the user's ID token, for their email address. */
8
12
  readonly idTokenHeader: 'Tempo-Id-Token';
9
13
  /** Seconds a DPoP proof is accepted after its `iat`. */
@@ -4,6 +4,10 @@ export const Constants = {
4
4
  type: 'tempo-id',
5
5
  /** Tempo ID in production: the issuer of every access token. */
6
6
  issuer: 'https://id.tempo.xyz',
7
+ /** Path, relative to a Tempo ID attestation issuer's URL, that exchanges a token for an attestation. */
8
+ attestPath: '/tempo-id/attest',
9
+ /** Attestation types a Tempo ID attestation issuer signs: the user's Tempo ID and verified email. */
10
+ attestationTypes: ['tempo-id', 'email'],
7
11
  /** Header that carries the user's ID token, for their email address. */
8
12
  idTokenHeader: 'Tempo-Id-Token',
9
13
  /** Seconds a DPoP proof is accepted after its `iat`. */
@@ -31,4 +31,67 @@ export declare namespace prover {
31
31
  readonly scope: Identity.Prover['scope'];
32
32
  };
33
33
  }
34
+ /**
35
+ * Creates a prover that presents Tempo ID attestations, obtaining them from a Tempo ID
36
+ * attestation issuer (`TempoId.Issuer`) when a server asks: an `Attestation.Client.prover` whose
37
+ * `acquire` exchanges the user's access token (and ID token, for `email`) at the issuer.
38
+ *
39
+ * Unlike {@link prover}, the access token goes only to the issuer: servers get short-lived
40
+ * attestations bound to their origin, and verify them like any other issuer's.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const mppx = Mppx.create({
45
+ * identity: [
46
+ * TempoId.Client.attestations({
47
+ * accessToken: () => accounts.session.accessToken(),
48
+ * idToken: () => accounts.session.get()?.idToken,
49
+ * issuer: 'https://attest.example',
50
+ * scope: ['https://api.example'],
51
+ * }),
52
+ * ],
53
+ * methods: [tempo({ account })],
54
+ * })
55
+ * ```
56
+ */
57
+ export declare function attestations(config: attestations.Config): Identity.Prover;
58
+ export declare namespace attestations {
59
+ type Config = Omit<attest.Parameters, 'audience' | 'type'> & {
60
+ /** Origins that may receive attestations and ask for new ones. */
61
+ readonly scope: Identity.Prover['scope'];
62
+ /** Attestation types to obtain. @default ['tempo-id', 'email'] */
63
+ readonly types?: readonly string[] | undefined;
64
+ /** Attestations already held, such as from storage. */
65
+ readonly attestations?: readonly string[] | undefined;
66
+ };
67
+ }
68
+ /**
69
+ * Exchanges a Tempo ID access token for one attestation at a Tempo ID attestation issuer.
70
+ * Resolves with `undefined` when the issuer refuses this user that type (403, such as `email`
71
+ * without a verified address), and throws on any other failure.
72
+ */
73
+ export declare function attest(parameters: attest.Parameters): Promise<{
74
+ readonly attestation: string;
75
+ readonly expiresAt: Date;
76
+ } | undefined>;
77
+ export declare namespace attest {
78
+ type Parameters = {
79
+ /** The Tempo ID attestation issuer's URL. */
80
+ readonly issuer: string;
81
+ /** Origin of the server the attestation is for. */
82
+ readonly audience: string;
83
+ /** Attestation type, such as `tempo-id` or `email`. */
84
+ readonly type: string;
85
+ /** Returns a live Tempo ID access token, such as `accounts.session.accessToken`. */
86
+ readonly accessToken: () => MaybePromise<string>;
87
+ /** The DPoP key that binds the token. Absent, the token is sent as a Bearer token. */
88
+ readonly dpop?: Types.DpopKey | undefined;
89
+ /** Seconds to wait for the issuer before the exchange fails. @default 10 */
90
+ readonly timeout?: number | undefined;
91
+ /** Returns the user's ID token, which `email` needs and an issuer's policy may read. */
92
+ readonly idToken?: (() => MaybePromise<string | undefined>) | undefined;
93
+ /** Fetch implementation. @default globalThis.fetch */
94
+ readonly fetch?: typeof globalThis.fetch | undefined;
95
+ };
96
+ }
34
97
  //# sourceMappingURL=index.d.ts.map