mppx 0.17.6 → 0.18.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 (144) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/Currency.d.ts +59 -0
  3. package/dist/Currency.js +60 -0
  4. package/dist/Errors.d.ts +13 -0
  5. package/dist/Errors.js +15 -6
  6. package/dist/cli/cli.js +138 -138
  7. package/dist/cli/plugins/index.js +12 -12
  8. package/dist/cli/plugins/tempo.js +13 -1
  9. package/dist/client/Mppx.js +13 -4
  10. package/dist/client/internal/Fetch.d.ts +5 -0
  11. package/dist/client/internal/Fetch.js +16 -5
  12. package/dist/cloudflare/ChannelStore.d.ts +1 -2
  13. package/dist/cloudflare/ChannelStore.js +14 -20
  14. package/dist/cloudflare/Channels.d.ts +20 -2
  15. package/dist/cloudflare/Channels.js +47 -4
  16. package/dist/cloudflare/index.d.ts +1 -1
  17. package/dist/cloudflare/index.js +1 -1
  18. package/dist/discovery/Discovery.d.ts +116 -9
  19. package/dist/discovery/Discovery.js +169 -0
  20. package/dist/evm/server/Charge.js +2 -3
  21. package/dist/evm/server/Methods.d.ts +1 -1
  22. package/dist/evm/server/Methods.js +3 -2
  23. package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.d.ts +4 -1
  24. package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.js +4 -1
  25. package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.d.ts +5 -5
  26. package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.js +1 -1
  27. package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts} +40 -26
  28. package/dist/extensions/identity/{email-otp/internal/Attestation.js → attestation/Token.js} +18 -3
  29. package/dist/extensions/identity/{email-otp/internal → attestation}/Types.d.ts +14 -14
  30. package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
  31. package/dist/extensions/identity/attestation/client/index.js +273 -0
  32. package/dist/extensions/identity/attestation/index.d.ts +20 -0
  33. package/dist/extensions/identity/attestation/index.js +18 -0
  34. package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
  35. package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
  36. package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
  37. package/dist/extensions/identity/attestation/server/index.js +119 -0
  38. package/dist/extensions/identity/email-otp/Constants.d.ts +5 -5
  39. package/dist/extensions/identity/email-otp/Constants.js +6 -5
  40. package/dist/extensions/identity/email-otp/Types.d.ts +4 -4
  41. package/dist/extensions/identity/email-otp/client/index.d.ts +22 -15
  42. package/dist/extensions/identity/email-otp/client/index.js +21 -9
  43. package/dist/extensions/identity/email-otp/index.d.ts +3 -8
  44. package/dist/extensions/identity/email-otp/index.js +3 -8
  45. package/dist/extensions/identity/email-otp/server/index.d.ts +16 -16
  46. package/dist/extensions/identity/email-otp/server/index.js +17 -14
  47. package/dist/extensions/identity/index.d.ts +6 -0
  48. package/dist/extensions/identity/index.js +6 -0
  49. package/dist/extensions/identity/internal/Verification.js +9 -5
  50. package/dist/extensions/identity/link/Constants.d.ts +102 -0
  51. package/dist/extensions/identity/link/Constants.js +16 -0
  52. package/dist/extensions/identity/link/client/index.d.ts +80 -0
  53. package/dist/extensions/identity/link/client/index.js +211 -0
  54. package/dist/extensions/identity/link/index.d.ts +12 -0
  55. package/dist/extensions/identity/link/index.js +12 -0
  56. package/dist/extensions/identity/link/server/index.d.ts +124 -0
  57. package/dist/extensions/identity/link/server/index.js +518 -0
  58. package/dist/extensions/identity/persona/Constants.d.ts +24 -0
  59. package/dist/extensions/identity/persona/Constants.js +24 -0
  60. package/dist/extensions/identity/persona/Did.d.ts +24 -0
  61. package/dist/extensions/identity/persona/Did.js +24 -0
  62. package/dist/extensions/identity/persona/Types.d.ts +21 -0
  63. package/dist/extensions/identity/persona/Types.js +2 -0
  64. package/dist/extensions/identity/persona/index.d.ts +10 -0
  65. package/dist/extensions/identity/persona/index.js +9 -0
  66. package/dist/extensions/identity/persona/server/index.d.ts +152 -0
  67. package/dist/extensions/identity/persona/server/index.js +263 -0
  68. package/dist/identity/Callback.d.ts +24 -5
  69. package/dist/identity/Callback.js +35 -11
  70. package/dist/identity/Client.d.ts +78 -5
  71. package/dist/identity/Client.js +165 -48
  72. package/dist/identity/Headers.d.ts +21 -0
  73. package/dist/identity/Headers.js +24 -0
  74. package/dist/identity/Server.d.ts +159 -37
  75. package/dist/identity/Server.js +309 -138
  76. package/dist/identity/Status.d.ts +14 -0
  77. package/dist/identity/Status.js +19 -0
  78. package/dist/identity/Types.d.ts +166 -65
  79. package/dist/identity/index.d.ts +2 -0
  80. package/dist/identity/index.js +2 -0
  81. package/dist/identity/internal/Requirements.d.ts +28 -0
  82. package/dist/identity/internal/Requirements.js +78 -0
  83. package/dist/index.d.ts +1 -0
  84. package/dist/index.js +1 -0
  85. package/dist/integrations/x402/Evm.d.ts +1 -0
  86. package/dist/internal/env.d.ts +14 -0
  87. package/dist/internal/env.js +38 -0
  88. package/dist/internal/version.d.ts +2 -2
  89. package/dist/internal/version.js +1 -1
  90. package/dist/proxy/internal/Headers.d.ts +1 -1
  91. package/dist/proxy/internal/Headers.js +11 -7
  92. package/dist/server/Mppx.d.ts +14 -6
  93. package/dist/server/Mppx.js +256 -149
  94. package/dist/server/internal/challengeMeta.d.ts +0 -6
  95. package/dist/server/internal/challengeMeta.js +3 -17
  96. package/dist/stripe/server/internal/html.gen.js +1 -1
  97. package/dist/tempo/client/Charge.d.ts +11 -8
  98. package/dist/tempo/client/Charge.js +53 -6
  99. package/dist/tempo/index.d.ts +4 -0
  100. package/dist/tempo/index.js +4 -0
  101. package/dist/tempo/internal/auto-swap.d.ts +6 -5
  102. package/dist/tempo/internal/auto-swap.js +17 -2
  103. package/dist/tempo/internal/currencies.d.ts +5 -4
  104. package/dist/tempo/internal/currencies.js +13 -9
  105. package/dist/tempo/internal/defaults.d.ts +7 -0
  106. package/dist/tempo/internal/defaults.js +7 -0
  107. package/dist/tempo/internal/fee-payer.js +8 -2
  108. package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
  109. package/dist/tempo/internal/machine-token-charge.js +82 -1
  110. package/dist/tempo/server/Charge.d.ts +14 -9
  111. package/dist/tempo/server/Charge.js +64 -3
  112. package/dist/tempo/server/Methods.d.ts +1 -1
  113. package/dist/tempo/server/Methods.js +4 -1
  114. package/dist/tempo/server/Subscription.d.ts +8 -0
  115. package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
  116. package/dist/tempo/server/internal/fallback-store.js +12 -3
  117. package/dist/tempo/server/internal/html.gen.js +1 -1
  118. package/dist/tempo/server/internal/transport.d.ts +1 -1
  119. package/dist/tempo/server/internal/transport.js +9 -16
  120. package/dist/tempo/session/client/CredentialState.js +31 -0
  121. package/dist/tempo/session/client/Session.d.ts +12 -6
  122. package/dist/tempo/session/client/Session.js +64 -18
  123. package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
  124. package/dist/tempo/session/server/ChannelStore.js +58 -8
  125. package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
  126. package/dist/tempo/session/server/CloseSupervisor.js +110 -12
  127. package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
  128. package/dist/tempo/session/server/CredentialVerification.js +6 -32
  129. package/dist/tempo/session/server/Session.d.ts +5 -1
  130. package/dist/tempo/session/server/Session.js +6 -3
  131. package/dist/tempo/session/server/Settlement.d.ts +7 -0
  132. package/dist/tempo/session/server/Settlement.js +36 -6
  133. package/dist/tempo/session/server/Sse.d.ts +2 -0
  134. package/dist/tempo/session/server/Sse.js +12 -12
  135. package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
  136. package/dist/tempo/subscription/KeyAuthorization.js +1 -1
  137. package/dist/x402/Assets.d.ts +14 -5
  138. package/dist/x402/Assets.js +11 -16
  139. package/package.json +19 -3
  140. package/dist/extensions/identity/email-otp/internal/Prover.d.ts +0 -46
  141. package/dist/extensions/identity/email-otp/internal/Prover.js +0 -168
  142. package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +0 -56
  143. package/dist/extensions/identity/email-otp/internal/Verifier.js +0 -116
  144. /package/dist/extensions/identity/{email-otp/internal → attestation}/Types.js +0 -0
@@ -0,0 +1,80 @@
1
+ import type * as Identity from '../../../../identity/Types.js';
2
+ import type { MaybePromise } from '../../../../internal/types.js';
3
+ import type * as Types from '../Constants.js';
4
+ /**
5
+ * Creates a prover that answers Link attestation challenges with an Agent Attestation Token.
6
+ *
7
+ * When a server in `scope` answers 401 with `WWW-Authenticate: PrivateToken`, the prover gets a
8
+ * token from `token` (such as `link-cli identity attestations pop`), and resends the request
9
+ * with it in `Authorization`. Later requests to that origin, including paid retries, carry the
10
+ * same token; a rejected one is replaced once. A request that already has an `Authorization`
11
+ * header is left as it is.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const mppx = Mppx.create({
16
+ * identity: [
17
+ * Link.Client.attestation({
18
+ * scope: ['https://api.example'],
19
+ * token: async () => (await linkCli('identity', 'attestations', 'pop')).authorization,
20
+ * }),
21
+ * ],
22
+ * methods: [tempo({ account })],
23
+ * })
24
+ * ```
25
+ */
26
+ export declare function attestation(config: attestation.Config): Identity.Prover;
27
+ export declare namespace attestation {
28
+ type Config = {
29
+ /** Origins that may receive a token, or `'*'` for any origin. */
30
+ readonly scope: Identity.Prover['scope'];
31
+ /**
32
+ * Returns an unused token: Link CLI's `authorization` value (`PrivateToken token="…"`) or the
33
+ * bare token. `undefined` declines.
34
+ */
35
+ readonly token: (parameters: {
36
+ origin: string;
37
+ }) => MaybePromise<string | undefined>;
38
+ /**
39
+ * Gets a token before the first request to an origin instead of after its challenge, so a
40
+ * server that prices requests by the proofs they carry sees it from the start.
41
+ * @default false
42
+ */
43
+ readonly eager?: boolean | undefined;
44
+ };
45
+ }
46
+ /**
47
+ * Creates a prover that answers Link claims challenges with an identity presentation.
48
+ *
49
+ * When a server in `scope` answers 401 with `WWW-Authenticate: Identity-Presentation` and a
50
+ * `urn:stripe:link:claims-required` body, the prover checks that the challenge names the
51
+ * request's own origin as audience, trusts Link, and asks only for claims in `claims`. It then
52
+ * gets a presentation from `present` (such as `link-cli identity credentials present`) and
53
+ * resends the request with it in `Identity-Presentation`. Later requests to that origin carry
54
+ * it until the server asks again.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * Link.Client.claims({
59
+ * claims: ['email', 'email_verified'],
60
+ * present: ({ audience, nonce, claims }) => linkCliPresent({ audience, nonce, claims }),
61
+ * scope: ['https://api.example'],
62
+ * })
63
+ * ```
64
+ */
65
+ export declare function claims(config: claims.Config): Identity.Prover;
66
+ export declare namespace claims {
67
+ type Config = {
68
+ /** Origins that may receive a presentation, or `'*'` for any origin. */
69
+ readonly scope: Identity.Prover['scope'];
70
+ /** Claims the prover may disclose, such as `['email', 'email_verified']`. */
71
+ readonly claims: readonly string[];
72
+ /** Creates a presentation for a challenge, or returns `undefined` to decline. */
73
+ readonly present: Types.Present;
74
+ /** Issuers whose credentials may be presented. Override only for staging and tests. @default ['https://api.link.com'] */
75
+ readonly issuers?: readonly string[] | undefined;
76
+ };
77
+ }
78
+ /** Parses a claims challenge's problem body, or returns `undefined` when it is not one. */
79
+ export declare function claimsChallenge(response: Response): Promise<Types.ClaimsChallenge | undefined>;
80
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,211 @@
1
+ import { Constants } from '../Constants.js';
2
+ /**
3
+ * Creates a prover that answers Link attestation challenges with an Agent Attestation Token.
4
+ *
5
+ * When a server in `scope` answers 401 with `WWW-Authenticate: PrivateToken`, the prover gets a
6
+ * token from `token` (such as `link-cli identity attestations pop`), and resends the request
7
+ * with it in `Authorization`. Later requests to that origin, including paid retries, carry the
8
+ * same token; a rejected one is replaced once. A request that already has an `Authorization`
9
+ * header is left as it is.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const mppx = Mppx.create({
14
+ * identity: [
15
+ * Link.Client.attestation({
16
+ * scope: ['https://api.example'],
17
+ * token: async () => (await linkCli('identity', 'attestations', 'pop')).authorization,
18
+ * }),
19
+ * ],
20
+ * methods: [tempo({ account })],
21
+ * })
22
+ * ```
23
+ */
24
+ export function attestation(config) {
25
+ const tokens = new Map();
26
+ // Every token this prover attached, so a request carrying an older one still retries.
27
+ const sent = new Set();
28
+ // One refresh per origin, shared by concurrent rejections.
29
+ const refreshes = new Map();
30
+ const remember = (origin, authorization) => {
31
+ tokens.set(origin, authorization);
32
+ track(sent, tokens, authorization);
33
+ };
34
+ return {
35
+ scope: config.scope,
36
+ async prove(request) {
37
+ if (request.headers.has('Authorization'))
38
+ return request;
39
+ const origin = new URL(request.url).origin;
40
+ if (config.eager && !tokens.has(origin)) {
41
+ const token = await config.token({ origin });
42
+ if (token)
43
+ remember(origin, toAuthorization(token));
44
+ }
45
+ const token = tokens.get(origin);
46
+ if (!token)
47
+ return request;
48
+ const headers = new Headers(request.headers);
49
+ headers.set('Authorization', token);
50
+ return new Request(request, { headers });
51
+ },
52
+ async retry(response, { request }) {
53
+ if (response.status !== 401)
54
+ return undefined;
55
+ if (!hasChallenge(response, Constants.attestationScheme))
56
+ return undefined;
57
+ const origin = new URL(request.url).origin;
58
+ const authorization = request.headers.get('Authorization');
59
+ // Someone else's Authorization: the token can't be sent alongside it.
60
+ if (authorization && !owns(sent, tokens, authorization))
61
+ return undefined;
62
+ const current = tokens.get(origin);
63
+ // Another request already replaced the rejected token: retry with the new one.
64
+ if (current && current !== authorization)
65
+ return {};
66
+ let refresh = refreshes.get(origin);
67
+ if (!refresh) {
68
+ tokens.delete(origin);
69
+ refresh = Promise.resolve(config.token({ origin }))
70
+ .then((token) => {
71
+ if (!token)
72
+ return undefined;
73
+ const value = toAuthorization(token);
74
+ remember(origin, value);
75
+ return value;
76
+ })
77
+ .finally(() => refreshes.delete(origin));
78
+ refreshes.set(origin, refresh);
79
+ }
80
+ return (await refresh) ? {} : undefined;
81
+ },
82
+ };
83
+ }
84
+ /**
85
+ * Creates a prover that answers Link claims challenges with an identity presentation.
86
+ *
87
+ * When a server in `scope` answers 401 with `WWW-Authenticate: Identity-Presentation` and a
88
+ * `urn:stripe:link:claims-required` body, the prover checks that the challenge names the
89
+ * request's own origin as audience, trusts Link, and asks only for claims in `claims`. It then
90
+ * gets a presentation from `present` (such as `link-cli identity credentials present`) and
91
+ * resends the request with it in `Identity-Presentation`. Later requests to that origin carry
92
+ * it until the server asks again.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * Link.Client.claims({
97
+ * claims: ['email', 'email_verified'],
98
+ * present: ({ audience, nonce, claims }) => linkCliPresent({ audience, nonce, claims }),
99
+ * scope: ['https://api.example'],
100
+ * })
101
+ * ```
102
+ */
103
+ export function claims(config) {
104
+ const allowed = new Set(config.claims);
105
+ const issuers = config.issuers ?? [Constants.issuer];
106
+ const presentations = new Map();
107
+ // Every presentation this prover attached, so it never answers for one the caller set.
108
+ const sent = new Set();
109
+ return {
110
+ scope: config.scope,
111
+ headers: [Constants.presentationHeader.toLowerCase()],
112
+ prove(request) {
113
+ if (request.headers.has(Constants.presentationHeader))
114
+ return request;
115
+ const presentation = presentations.get(new URL(request.url).origin);
116
+ if (!presentation)
117
+ return request;
118
+ const headers = new Headers(request.headers);
119
+ headers.set(Constants.presentationHeader, presentation);
120
+ return new Request(request, { headers });
121
+ },
122
+ async retry(response, { request }) {
123
+ if (response.status !== 401)
124
+ return undefined;
125
+ if (!hasChallenge(response, Constants.presentationHeader))
126
+ return undefined;
127
+ const attached = request.headers.get(Constants.presentationHeader);
128
+ // The caller's own presentation: leave the challenge to them.
129
+ if (attached && !owns(sent, presentations, attached))
130
+ return undefined;
131
+ const origin = new URL(request.url).origin;
132
+ presentations.delete(origin);
133
+ const challenge = await claimsChallenge(response);
134
+ if (!challenge)
135
+ return undefined;
136
+ // Bound to this origin only: a server can't relay another audience's challenge.
137
+ if (challenge.aud.replace(/\/+$/, '') !== origin)
138
+ return undefined;
139
+ if (!challenge.trusted_issuers.some((issuer) => issuers.includes(issuer)))
140
+ return undefined;
141
+ if (!challenge.formats.includes(Constants.format))
142
+ return undefined;
143
+ if (!challenge.claims.every((claim) => allowed.has(claim)))
144
+ return undefined;
145
+ const presentation = await config.present({
146
+ audience: challenge.aud,
147
+ claims: challenge.claims,
148
+ nonce: challenge.nonce,
149
+ purpose: challenge.purpose,
150
+ });
151
+ if (!presentation)
152
+ return undefined;
153
+ presentations.set(origin, presentation);
154
+ track(sent, presentations, presentation);
155
+ return {};
156
+ },
157
+ };
158
+ }
159
+ /** Parses a claims challenge's problem body, or returns `undefined` when it is not one. */
160
+ export async function claimsChallenge(response) {
161
+ const body = (await response
162
+ .clone()
163
+ .json()
164
+ .catch(() => undefined));
165
+ if (!body || body.type !== Constants.claimsRequiredType)
166
+ return undefined;
167
+ const strings = (value) => Array.isArray(value) && value.every((item) => typeof item === 'string');
168
+ if (typeof body.aud !== 'string' || typeof body.nonce !== 'string' || !body.nonce)
169
+ return undefined;
170
+ if (!strings(body.claims) || body.claims.length === 0)
171
+ return undefined;
172
+ if (!strings(body.formats) || !strings(body.trusted_issuers))
173
+ return undefined;
174
+ return {
175
+ aud: body.aud,
176
+ claims: body.claims,
177
+ formats: body.formats,
178
+ nonce: body.nonce,
179
+ ...(typeof body.purpose === 'string' && { purpose: body.purpose }),
180
+ trusted_issuers: body.trusted_issuers,
181
+ type: body.type,
182
+ };
183
+ }
184
+ /** Whether the response challenges with `scheme`. */
185
+ function hasChallenge(response, scheme) {
186
+ const header = response.headers.get('WWW-Authenticate') ?? '';
187
+ return new RegExp(`(^|,)\\s*${scheme}(\\s|,|$)`, 'i').test(header);
188
+ }
189
+ /** Link CLI's `authorization` value as is, or a bare token in the `PrivateToken` scheme. */
190
+ function toAuthorization(token) {
191
+ const value = token.trim();
192
+ if (/^privatetoken\s/i.test(value))
193
+ return value;
194
+ return `${Constants.attestationScheme} token="${value}"`;
195
+ }
196
+ /** Whether this prover attached `value`: an origin's current one, or one it sent before. */
197
+ function owns(sent, current, value) {
198
+ return sent.has(value) || [...current.values()].includes(value);
199
+ }
200
+ /** Remembers a value this prover attached, keeping at most 64 that are no longer current. */
201
+ function track(sent, current, value) {
202
+ sent.add(value);
203
+ const live = new Set(current.values());
204
+ for (const old of sent) {
205
+ if (sent.size <= 64)
206
+ break;
207
+ if (!live.has(old))
208
+ sent.delete(old);
209
+ }
210
+ }
211
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Link agent identity (https://docs.link.com/concepts/agent-identity): Link Agent Attestation
3
+ * Tokens (Privacy Pass `PrivateToken`s in `Authorization`) and selectively disclosed identity
4
+ * presentations (SD-JWT in `Identity-Presentation`). The server verifies them with Link's Agent
5
+ * Identity SDK (`@stripe/agent-identity`); the client gets them from Link CLI or the Link SDK.
6
+ */
7
+ /** Client provers that answer Link attestation and claims challenges. */
8
+ export * as Client from './client/index.js';
9
+ /** Server verifiers that require a Link attestation or Link-signed claims. */
10
+ export * as Server from './server/index.js';
11
+ export * from './Constants.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Link agent identity (https://docs.link.com/concepts/agent-identity): Link Agent Attestation
3
+ * Tokens (Privacy Pass `PrivateToken`s in `Authorization`) and selectively disclosed identity
4
+ * presentations (SD-JWT in `Identity-Presentation`). The server verifies them with Link's Agent
5
+ * Identity SDK (`@stripe/agent-identity`); the client gets them from Link CLI or the Link SDK.
6
+ */
7
+ /** Client provers that answer Link attestation and claims challenges. */
8
+ export * as Client from './client/index.js';
9
+ /** Server verifiers that require a Link attestation or Link-signed claims. */
10
+ export * as Server from './server/index.js';
11
+ export * from './Constants.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,124 @@
1
+ import type * as Identity from '../../../../identity/Types.js';
2
+ import type { MaybePromise } from '../../../../internal/types.js';
3
+ import type * as Types from '../Constants.js';
4
+ /**
5
+ * Creates a request-stage verifier that requires a Link Agent Attestation Token: proof that
6
+ * Link vouches for the agent, with no personal details.
7
+ *
8
+ * A request without one gets 401 with Link's `WWW-Authenticate: PrivateToken` challenge. The
9
+ * token travels in `Authorization`, so create the server with `requiresAuth: true`: Payment
10
+ * credentials then use `Payment-Authorization` and the token stays on the paid retry.
11
+ *
12
+ * Tokens are bearer tokens: the verifier does not make them single use, and a valid one only
13
+ * says Link issued it. Tokens are checked with {@link tokenVerifier}, which needs only Web
14
+ * Crypto, unless `verifier` is set, such as to a `LinkVerifier` from `@stripe/agent-identity`
15
+ * on Node.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const mppx = Mppx.create({ methods, requiresAuth: true })
20
+ * const result = await mppx.charge({ amount: '1', identity: [Link.Server.attestation()] })(request)
21
+ * ```
22
+ */
23
+ export declare function attestation(config?: attestation.Config): Identity.Verifier<Types.VerifiedAttestation>;
24
+ export declare namespace attestation {
25
+ type Config = {
26
+ /**
27
+ * Verifies tokens, shared by every request: a `LinkVerifier` from `@stripe/agent-identity`, or
28
+ * {@link tokenVerifier} with options. @default tokenVerifier()
29
+ */
30
+ readonly verifier?: Types.AttestationVerifier | undefined;
31
+ };
32
+ }
33
+ /**
34
+ * Creates a request-stage verifier that requires claims Link signed, such as a verified email,
35
+ * presented by the credential holder for this server.
36
+ *
37
+ * A request without a presentation gets 401 with `WWW-Authenticate: Identity-Presentation` and
38
+ * Link's `urn:stripe:link:claims-required` problem body, whose nonce is signed with
39
+ * `secretKey` and expires after {@link Constants.nonceTtl} seconds, so no state is kept. The
40
+ * client presents the claims bound to `audience` and that nonce in `Identity-Presentation`.
41
+ * A presentation verifies again until its nonce expires, including on the paid retry.
42
+ *
43
+ * List it before other verifiers of the route: the rejection body is the first rejecting
44
+ * verifier's, and the client needs this one's.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const email = Link.Server.claims({
49
+ * audience: 'https://api.example',
50
+ * claims: ['email', 'email_verified'],
51
+ * purpose: 'Write a haiku about you',
52
+ * secretKey: env.MPP_SECRET_KEY,
53
+ * verifier: link,
54
+ * })
55
+ * if (result.status === 200) result.identity?.get(email)?.email
56
+ * ```
57
+ */
58
+ export declare function claims(config: claims.Config): Identity.Verifier<Types.VerifiedClaims>;
59
+ export declare namespace claims {
60
+ type Config = {
61
+ /**
62
+ * Verifies presentations, shared by every request: a `LinkVerifier` from
63
+ * `@stripe/agent-identity`, or {@link presentationVerifier} with options.
64
+ * @default presentationVerifier({ audience, issuer })
65
+ */
66
+ readonly verifier?: Types.ClaimsVerifier | undefined;
67
+ /** This server's public origin, such as `https://api.example`: the presentation's audience. */
68
+ readonly audience: string;
69
+ /** Claims the presentation must disclose, such as `['email', 'email_verified']`. */
70
+ readonly claims: readonly string[];
71
+ /** Why the server asks, shown to the person whose claims they are. */
72
+ readonly purpose?: string | undefined;
73
+ /** Issuer the challenge names: the verifier's. Override only for staging and tests. @default 'https://api.link.com' */
74
+ readonly issuer?: string | undefined;
75
+ /** Secret that signs challenge nonces, such as the server's `MPP_SECRET_KEY`. */
76
+ readonly secretKey: string;
77
+ /** Seconds a challenge's nonce is accepted for. @default 300 */
78
+ readonly nonceTtl?: number | undefined;
79
+ /** Accepts or rejects (`forbidden`, 403) verified claims. Defaults to any. */
80
+ readonly allow?: ((claims: Types.VerifiedClaims, request: Request) => MaybePromise<boolean>) | undefined;
81
+ };
82
+ }
83
+ /**
84
+ * Creates a verifier of Link Agent Attestation Tokens that needs only Web Crypto and `fetch`,
85
+ * so it runs where `@stripe/agent-identity` can't import Link's RSASSA-PSS token key, such as
86
+ * Cloudflare Workers. It makes the same checks: the key is in the token-key directory of Link's
87
+ * issuer metadata, the token answers Link's stable bearer challenge, and its RSA-PSS (SHA-384)
88
+ * signature verifies. {@link attestation} uses it unless given another verifier.
89
+ */
90
+ export declare function tokenVerifier(config?: tokenVerifier.Config): Types.AttestationVerifier;
91
+ export declare namespace tokenVerifier {
92
+ type Config = {
93
+ /** Fetch used for Link's issuer documents. @default globalThis.fetch */
94
+ readonly fetch?: ((input: string, init: RequestInit) => MaybePromise<Response>) | undefined;
95
+ /** Issuer URL. Override only for staging and tests. @default 'https://api.link.com' */
96
+ readonly issuer?: string | undefined;
97
+ /** Seconds before the token keys are fetched again. @default 300 */
98
+ readonly maxKeyAge?: number | undefined;
99
+ /** Milliseconds each issuer request may take. @default 3000 */
100
+ readonly timeout?: number | undefined;
101
+ };
102
+ }
103
+ /**
104
+ * Creates a verifier of Link identity presentations (SD-JWT VC with a Key Binding JWT) that
105
+ * runs `verifyClaimsPresentation` from `@stripe/agent-identity` wherever `fetch` does,
106
+ * Cloudflare Workers included. It reads Link's issuer metadata itself, so the SDK's
107
+ * Node-only token key import never runs. {@link claims} uses it unless given another verifier.
108
+ */
109
+ export declare function presentationVerifier(config: presentationVerifier.Config): Types.ClaimsVerifier;
110
+ export declare namespace presentationVerifier {
111
+ type Config = {
112
+ /** This server's public origin: the presentation's audience. */
113
+ readonly audience: string;
114
+ /** Seconds a presentation is accepted after it is signed. @default 300, the nonce lifetime */
115
+ readonly maxAge?: number | undefined;
116
+ /** Fetch used for Link's issuer documents. @default globalThis.fetch */
117
+ readonly fetch?: ((input: string, init: RequestInit) => MaybePromise<Response>) | undefined;
118
+ /** Issuer URL. Override only for staging and tests. @default 'https://api.link.com' */
119
+ readonly issuer?: string | undefined;
120
+ /** Milliseconds each issuer request may take. @default 3000 */
121
+ readonly timeout?: number | undefined;
122
+ };
123
+ }
124
+ //# sourceMappingURL=index.d.ts.map