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.
- package/CHANGELOG.md +43 -0
- package/dist/Currency.d.ts +59 -0
- package/dist/Currency.js +60 -0
- package/dist/Errors.d.ts +13 -0
- package/dist/Errors.js +15 -6
- package/dist/cli/cli.js +138 -138
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/plugins/tempo.js +13 -1
- package/dist/client/Mppx.js +13 -4
- package/dist/client/internal/Fetch.d.ts +5 -0
- package/dist/client/internal/Fetch.js +16 -5
- package/dist/cloudflare/ChannelStore.d.ts +1 -2
- package/dist/cloudflare/ChannelStore.js +14 -20
- package/dist/cloudflare/Channels.d.ts +20 -2
- package/dist/cloudflare/Channels.js +47 -4
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/discovery/Discovery.d.ts +116 -9
- package/dist/discovery/Discovery.js +169 -0
- package/dist/evm/server/Charge.js +2 -3
- package/dist/evm/server/Methods.d.ts +1 -1
- package/dist/evm/server/Methods.js +3 -2
- package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.d.ts +4 -1
- package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.js +4 -1
- package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.d.ts +5 -5
- package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.js +1 -1
- package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts} +40 -26
- package/dist/extensions/identity/{email-otp/internal/Attestation.js → attestation/Token.js} +18 -3
- package/dist/extensions/identity/{email-otp/internal → attestation}/Types.d.ts +14 -14
- package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/client/index.js +273 -0
- package/dist/extensions/identity/attestation/index.d.ts +20 -0
- package/dist/extensions/identity/attestation/index.js +18 -0
- package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
- package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
- package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/server/index.js +119 -0
- package/dist/extensions/identity/email-otp/Constants.d.ts +5 -5
- package/dist/extensions/identity/email-otp/Constants.js +6 -5
- package/dist/extensions/identity/email-otp/Types.d.ts +4 -4
- package/dist/extensions/identity/email-otp/client/index.d.ts +22 -15
- package/dist/extensions/identity/email-otp/client/index.js +21 -9
- package/dist/extensions/identity/email-otp/index.d.ts +3 -8
- package/dist/extensions/identity/email-otp/index.js +3 -8
- package/dist/extensions/identity/email-otp/server/index.d.ts +16 -16
- package/dist/extensions/identity/email-otp/server/index.js +17 -14
- package/dist/extensions/identity/index.d.ts +6 -0
- package/dist/extensions/identity/index.js +6 -0
- package/dist/extensions/identity/internal/Verification.js +9 -5
- package/dist/extensions/identity/link/Constants.d.ts +102 -0
- package/dist/extensions/identity/link/Constants.js +16 -0
- package/dist/extensions/identity/link/client/index.d.ts +80 -0
- package/dist/extensions/identity/link/client/index.js +211 -0
- package/dist/extensions/identity/link/index.d.ts +12 -0
- package/dist/extensions/identity/link/index.js +12 -0
- package/dist/extensions/identity/link/server/index.d.ts +124 -0
- package/dist/extensions/identity/link/server/index.js +518 -0
- package/dist/extensions/identity/persona/Constants.d.ts +24 -0
- package/dist/extensions/identity/persona/Constants.js +24 -0
- package/dist/extensions/identity/persona/Did.d.ts +24 -0
- package/dist/extensions/identity/persona/Did.js +24 -0
- package/dist/extensions/identity/persona/Types.d.ts +21 -0
- package/dist/extensions/identity/persona/Types.js +2 -0
- package/dist/extensions/identity/persona/index.d.ts +10 -0
- package/dist/extensions/identity/persona/index.js +9 -0
- package/dist/extensions/identity/persona/server/index.d.ts +152 -0
- package/dist/extensions/identity/persona/server/index.js +263 -0
- package/dist/identity/Callback.d.ts +24 -5
- package/dist/identity/Callback.js +35 -11
- package/dist/identity/Client.d.ts +78 -5
- package/dist/identity/Client.js +165 -48
- package/dist/identity/Headers.d.ts +21 -0
- package/dist/identity/Headers.js +24 -0
- package/dist/identity/Server.d.ts +159 -37
- package/dist/identity/Server.js +309 -138
- package/dist/identity/Status.d.ts +14 -0
- package/dist/identity/Status.js +19 -0
- package/dist/identity/Types.d.ts +166 -65
- package/dist/identity/index.d.ts +2 -0
- package/dist/identity/index.js +2 -0
- package/dist/identity/internal/Requirements.d.ts +28 -0
- package/dist/identity/internal/Requirements.js +78 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/integrations/x402/Evm.d.ts +1 -0
- package/dist/internal/env.d.ts +14 -0
- package/dist/internal/env.js +38 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/proxy/internal/Headers.d.ts +1 -1
- package/dist/proxy/internal/Headers.js +11 -7
- package/dist/server/Mppx.d.ts +14 -6
- package/dist/server/Mppx.js +256 -149
- package/dist/server/internal/challengeMeta.d.ts +0 -6
- package/dist/server/internal/challengeMeta.js +3 -17
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/client/Charge.d.ts +11 -8
- package/dist/tempo/client/Charge.js +53 -6
- package/dist/tempo/index.d.ts +4 -0
- package/dist/tempo/index.js +4 -0
- package/dist/tempo/internal/auto-swap.d.ts +6 -5
- package/dist/tempo/internal/auto-swap.js +17 -2
- package/dist/tempo/internal/currencies.d.ts +5 -4
- package/dist/tempo/internal/currencies.js +13 -9
- package/dist/tempo/internal/defaults.d.ts +7 -0
- package/dist/tempo/internal/defaults.js +7 -0
- package/dist/tempo/internal/fee-payer.js +8 -2
- package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
- package/dist/tempo/internal/machine-token-charge.js +82 -1
- package/dist/tempo/server/Charge.d.ts +14 -9
- package/dist/tempo/server/Charge.js +64 -3
- package/dist/tempo/server/Methods.d.ts +1 -1
- package/dist/tempo/server/Methods.js +4 -1
- package/dist/tempo/server/Subscription.d.ts +8 -0
- package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
- package/dist/tempo/server/internal/fallback-store.js +12 -3
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/transport.d.ts +1 -1
- package/dist/tempo/server/internal/transport.js +9 -16
- package/dist/tempo/session/client/CredentialState.js +31 -0
- package/dist/tempo/session/client/Session.d.ts +12 -6
- package/dist/tempo/session/client/Session.js +64 -18
- package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
- package/dist/tempo/session/server/ChannelStore.js +58 -8
- package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
- package/dist/tempo/session/server/CloseSupervisor.js +110 -12
- package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
- package/dist/tempo/session/server/CredentialVerification.js +6 -32
- package/dist/tempo/session/server/Session.d.ts +5 -1
- package/dist/tempo/session/server/Session.js +6 -3
- package/dist/tempo/session/server/Settlement.d.ts +7 -0
- package/dist/tempo/session/server/Settlement.js +36 -6
- package/dist/tempo/session/server/Sse.d.ts +2 -0
- package/dist/tempo/session/server/Sse.js +12 -12
- package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
- package/dist/tempo/subscription/KeyAuthorization.js +1 -1
- package/dist/x402/Assets.d.ts +14 -5
- package/dist/x402/Assets.js +11 -16
- package/package.json +19 -3
- package/dist/extensions/identity/email-otp/internal/Prover.d.ts +0 -46
- package/dist/extensions/identity/email-otp/internal/Prover.js +0 -168
- package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +0 -56
- package/dist/extensions/identity/email-otp/internal/Verifier.js +0 -116
- /package/dist/extensions/identity/{email-otp/internal → attestation}/Types.js +0 -0
package/dist/identity/Types.d.ts
CHANGED
|
@@ -4,109 +4,210 @@ import type { MaybePromise } from '../internal/types.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* When a verifier runs on the server.
|
|
6
6
|
*
|
|
7
|
-
* `request`
|
|
8
|
-
*
|
|
9
|
-
* challenge headers to the 402 (through `challenge`) and run on the paid
|
|
10
|
-
* retry, before the credential is settled.
|
|
7
|
+
* @deprecated Every verifier runs at the `request` stage. Use `identity: { payment }` with an
|
|
8
|
+
* {@link PaymentCheck} for checks on the paid retry.
|
|
11
9
|
*/
|
|
12
10
|
export type Stage = 'request' | 'payment';
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* The fixed status of a rejected identity outcome. Each maps to one HTTP status code
|
|
13
|
+
* (`Identity.Status.codes`), and the highest in `Identity.Status.precedence` decides
|
|
14
|
+
* when several verifiers reject.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* - `missing`: no proof was presented (401).
|
|
17
|
+
* - `invalid`: a proof was presented but did not verify (401).
|
|
18
|
+
* - `forbidden`: the proof verified, but the identity is not allowed (403).
|
|
19
|
+
* - `unavailable`: the proof could not be checked right now, such as an issuer outage (503).
|
|
18
20
|
*/
|
|
19
|
-
export type
|
|
20
|
-
/** The MPP challenge being answered (or, for provers, selected). */
|
|
21
|
-
challenge?: Challenge.Challenge | undefined;
|
|
22
|
-
/** The payment credential submitted with the request. */
|
|
23
|
-
credential?: Credential.Credential | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* The identity nonce of the 402 being answered.
|
|
26
|
-
*
|
|
27
|
-
* Every payment offer in one 402 carries the same HMAC-bound nonce, so a proof
|
|
28
|
-
* bound to it is bound to that 402 whichever offer the client pays.
|
|
29
|
-
*/
|
|
30
|
-
nonce?: string | undefined;
|
|
31
|
-
};
|
|
32
|
-
/** Context passed to a payment-stage verifier's `challenge` hook. */
|
|
33
|
-
export type ChallengeContext = {
|
|
34
|
-
/** The identity nonce shared by every payment offer in the 402. Bind the proof request to it. */
|
|
35
|
-
nonce: string;
|
|
36
|
-
};
|
|
21
|
+
export type RejectionStatus = 'missing' | 'invalid' | 'forbidden' | 'unavailable';
|
|
37
22
|
/**
|
|
38
|
-
* The outcome of one identity verifier.
|
|
23
|
+
* The outcome of one identity verifier or payment check.
|
|
39
24
|
*
|
|
40
|
-
* `
|
|
41
|
-
*
|
|
42
|
-
*
|
|
25
|
+
* `valid` carries the verified value. Every other status rejects the request with
|
|
26
|
+
* its fixed HTTP status code; `headers` (such as a protocol challenge) are returned
|
|
27
|
+
* to the client.
|
|
43
28
|
*/
|
|
44
29
|
export type Verification<value = unknown> = {
|
|
45
|
-
status: '
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
readonly status: 'valid';
|
|
31
|
+
readonly value: value;
|
|
32
|
+
} | {
|
|
33
|
+
readonly status: 'missing';
|
|
34
|
+
/**
|
|
35
|
+
* HTTP status of the rejection.
|
|
36
|
+
*
|
|
37
|
+
* @deprecated Return `status: 'forbidden'` or `'unavailable'` instead. Still honored when set:
|
|
38
|
+
* 403 maps to `forbidden`, 503 to `unavailable`, and any other code is sent as is.
|
|
39
|
+
*/
|
|
40
|
+
readonly code?: number | undefined;
|
|
48
41
|
/** Headers returned to the client, such as a protocol challenge. */
|
|
49
|
-
headers?: HeadersInit | undefined;
|
|
42
|
+
readonly headers?: HeadersInit | undefined;
|
|
50
43
|
/** Human-readable reason. */
|
|
51
|
-
reason?: string | undefined;
|
|
44
|
+
readonly reason?: string | undefined;
|
|
52
45
|
} | {
|
|
53
|
-
status: 'invalid';
|
|
54
|
-
/**
|
|
55
|
-
|
|
46
|
+
readonly status: 'invalid';
|
|
47
|
+
/**
|
|
48
|
+
* HTTP status of the rejection.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated Return `status: 'forbidden'` or `'unavailable'` instead. Still honored when set:
|
|
51
|
+
* 403 maps to `forbidden`, 503 to `unavailable`, and any other code is sent as is.
|
|
52
|
+
*/
|
|
53
|
+
readonly code?: number | undefined;
|
|
56
54
|
/** Headers returned to the client, such as a protocol error object. */
|
|
57
|
-
headers?: HeadersInit | undefined;
|
|
55
|
+
readonly headers?: HeadersInit | undefined;
|
|
58
56
|
/** Human-readable reason. */
|
|
59
|
-
reason: string;
|
|
57
|
+
readonly reason: string;
|
|
60
58
|
} | {
|
|
61
|
-
status: '
|
|
62
|
-
|
|
59
|
+
readonly status: 'forbidden' | 'unavailable';
|
|
60
|
+
/** Headers returned to the client. */
|
|
61
|
+
readonly headers?: HeadersInit | undefined;
|
|
62
|
+
/** Human-readable reason. */
|
|
63
|
+
readonly reason: string;
|
|
63
64
|
};
|
|
64
|
-
/** Verifies one identity protocol on the server. */
|
|
65
|
+
/** Verifies one identity protocol on the server, before any payment Challenge is issued. */
|
|
65
66
|
export type Verifier<value = unknown> = {
|
|
66
|
-
/** When the verifier runs. @default 'request' */
|
|
67
|
-
stage?: Stage | undefined;
|
|
68
67
|
/**
|
|
69
|
-
*
|
|
68
|
+
* When the verifier runs.
|
|
70
69
|
*
|
|
71
|
-
*
|
|
70
|
+
* @deprecated Omit it. `'request'` is accepted; `'payment'` throws: use `identity: { payment }`.
|
|
71
|
+
*/
|
|
72
|
+
readonly stage?: Stage | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated Ignored. Payment-stage verifiers were replaced by `identity: { payment }`, whose
|
|
75
|
+
* `requires` is sent in the 402's `Identity-Required` header.
|
|
72
76
|
*/
|
|
73
|
-
challenge?: ((request: Request, context:
|
|
77
|
+
readonly challenge?: ((request: Request, context: {
|
|
78
|
+
readonly nonce: string;
|
|
79
|
+
}) => unknown) | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The verifier reads its credential from `Authorization`. A route that uses it needs a server
|
|
82
|
+
* created with `requiresAuth: true`, so Payment Credentials travel in `Payment-Authorization`.
|
|
83
|
+
*/
|
|
84
|
+
readonly authorization?: boolean | undefined;
|
|
74
85
|
/** Returns the protocol's verification outcome for the request. */
|
|
75
|
-
verify: (request: Request
|
|
86
|
+
readonly verify: (request: Request) => MaybePromise<Verification<value>>;
|
|
76
87
|
};
|
|
77
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* One identity a payment check requires, sent in the 402's `Identity-Required` header as a
|
|
90
|
+
* structured-field list item: the `type` token with an `issuer` string parameter when set.
|
|
91
|
+
*
|
|
92
|
+
* @experimental Unstable: may change or be removed in any release.
|
|
93
|
+
*/
|
|
94
|
+
export type Requirement = {
|
|
95
|
+
/** Identity type, a structured-field token such as `kyc`. */
|
|
96
|
+
readonly type: string;
|
|
97
|
+
/** Issuer the identity must come from, such as `https://kyc.example`. */
|
|
98
|
+
readonly issuer?: string | undefined;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Checks the payer's identity on the paid retry, before the Credential is settled.
|
|
102
|
+
*
|
|
103
|
+
* Every 402 the route issues carries `requires` in its `Identity-Required` header. `verify`
|
|
104
|
+
* runs once on the paid retry with the answered Challenge and its Credential, after the
|
|
105
|
+
* Credential's HMAC, pinned fields, expiry and payload are checked; any status other than
|
|
106
|
+
* `valid` rejects with its fixed status code and no fresh 402, because the client may already
|
|
107
|
+
* have pushed the payment. On a route with `authorize`, `verify` first runs without a
|
|
108
|
+
* Credential, and only a `valid` result lets `authorize` run. x402 Credentials name no
|
|
109
|
+
* Challenge the client could bind a proof to, so a route with a payment check rejects them as
|
|
110
|
+
* `invalid` before settlement.
|
|
111
|
+
*
|
|
112
|
+
* @experimental Unstable: may change or be removed in any release.
|
|
113
|
+
*/
|
|
114
|
+
export type PaymentCheck<value = unknown> = {
|
|
115
|
+
/** Identities the check requires, advertised in every 402 of the route. */
|
|
116
|
+
readonly requires: readonly Requirement[];
|
|
117
|
+
/** Returns the check's outcome for the paid retry (or, without a Credential, for `authorize`). */
|
|
118
|
+
readonly verify: (parameters: {
|
|
119
|
+
readonly request: Request;
|
|
120
|
+
readonly challenge: Challenge.Challenge;
|
|
121
|
+
readonly credential?: Credential.Credential | undefined;
|
|
122
|
+
}) => MaybePromise<Verification<value>>;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* The `identity` option of an HTTP route.
|
|
126
|
+
*
|
|
127
|
+
* A list of request-stage verifiers, all of which must be valid, or an object with those
|
|
128
|
+
* verifiers under `request` and an experimental payment check under `payment`.
|
|
129
|
+
*/
|
|
130
|
+
export type Route = readonly Verifier[] | {
|
|
131
|
+
/** Request-stage verifiers, all of which must be valid. */
|
|
132
|
+
readonly request?: readonly Verifier[] | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Identity check on the paid retry.
|
|
135
|
+
*
|
|
136
|
+
* @experimental Unstable: may change or be removed in any release.
|
|
137
|
+
*/
|
|
138
|
+
readonly payment?: PaymentCheck | undefined;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Why a route rejected a request's identity, returned as `rejection` on the result's
|
|
142
|
+
* non-200 branch, whose `challenge` holds the rejection response to send as is.
|
|
143
|
+
*/
|
|
144
|
+
export type Rejection = {
|
|
145
|
+
/** `request` for a request-stage verifier, `payment` for the payment check on the paid retry. */
|
|
146
|
+
readonly stage: 'request' | 'payment';
|
|
147
|
+
/** The deciding fixed status. */
|
|
148
|
+
readonly status: RejectionStatus;
|
|
149
|
+
/** Human-readable reason, also the rejection response's body. */
|
|
150
|
+
readonly reason: string;
|
|
151
|
+
};
|
|
152
|
+
/** Verified identity values, looked up by the verifier or payment check that produced them. */
|
|
78
153
|
export type Results = {
|
|
79
|
-
/** Returns the verified value for a verifier, or `undefined` if it did not run or match. */
|
|
80
|
-
get<value>(verifier: Verifier<value>): value | undefined;
|
|
154
|
+
/** Returns the verified value for a verifier or payment check, or `undefined` if it did not run or match. */
|
|
155
|
+
get<value>(verifier: Verifier<value> | PaymentCheck<value>): value | undefined;
|
|
81
156
|
};
|
|
82
157
|
/**
|
|
83
158
|
* Values shared by every prover contributing to one HTTP attempt.
|
|
84
159
|
*
|
|
85
160
|
* Every retry gets a new context, so single-use nonces are never replayed.
|
|
86
161
|
*/
|
|
87
|
-
export type ProveContext =
|
|
88
|
-
/** Unix timestamp, in seconds, at which the attempt was created. */
|
|
162
|
+
export type ProveContext = {
|
|
163
|
+
/** Unix timestamp, in seconds, at which the attempt was created (RFC 9421 `created`). */
|
|
89
164
|
readonly created: number;
|
|
90
|
-
/** Base64url-encoded random value identifying the attempt. */
|
|
165
|
+
/** Base64url-encoded random value identifying the attempt (RFC 9421 `nonce`). */
|
|
91
166
|
readonly nonce: string;
|
|
167
|
+
/** On a paid attempt, the Challenge being answered, so a proof can bind to its `id`. */
|
|
168
|
+
readonly challenge?: Challenge.Challenge | undefined;
|
|
169
|
+
};
|
|
170
|
+
/** Passed to {@link Prover.prepare} for a 402 before the payment retry. */
|
|
171
|
+
export type PrepareContext = {
|
|
172
|
+
/** The Challenge the client selected; `prove` receives the same Challenge on the paid retry. */
|
|
173
|
+
readonly challenge: Challenge.Challenge;
|
|
174
|
+
/**
|
|
175
|
+
* The identities the 402's `Identity-Required` header lists.
|
|
176
|
+
*
|
|
177
|
+
* @experimental Unstable: may change or be removed in any release.
|
|
178
|
+
*/
|
|
179
|
+
readonly requirements: readonly Requirement[];
|
|
180
|
+
};
|
|
181
|
+
/** Passed to {@link Prover.retry} with a rejected response. */
|
|
182
|
+
export type RetryContext = {
|
|
183
|
+
/** The request that got the response, as sent: proved by every in-scope prover. */
|
|
184
|
+
readonly request: Request;
|
|
92
185
|
};
|
|
93
186
|
/** Adds one identity protocol to outbound requests on the client. */
|
|
94
187
|
export type Prover = {
|
|
95
188
|
/** Origins the prover may run for, such as `['https://shop.example']`, or `'*'` for any origin. */
|
|
96
|
-
scope: readonly string[] | '*';
|
|
97
|
-
/** Returns a new request carrying the protocol's identity material. */
|
|
98
|
-
prove: (request: Request, context: ProveContext) => MaybePromise<Request>;
|
|
189
|
+
readonly scope: readonly string[] | '*';
|
|
99
190
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* The context carries the selected challenge; `prove` receives the same challenge
|
|
103
|
-
* on the paid retry.
|
|
191
|
+
* Extra sensitive request headers the prover writes, such as a bearer token. Like those in
|
|
192
|
+
* `Identity.Headers.request`, the client strips them on a cross-origin redirect.
|
|
104
193
|
*/
|
|
105
|
-
|
|
194
|
+
readonly headers?: readonly string[] | undefined;
|
|
195
|
+
/** Returns a new request carrying the protocol's identity material. */
|
|
196
|
+
readonly prove: (request: Request, context: ProveContext) => MaybePromise<Request>;
|
|
197
|
+
/** Prepares a proof from a 402 before the payment retry, such as for the identities it requires. */
|
|
198
|
+
readonly prepare?: ((response: Response, context: PrepareContext) => MaybePromise<void>) | undefined;
|
|
106
199
|
/**
|
|
107
|
-
* Inspects a rejected (non-402) response
|
|
108
|
-
*
|
|
200
|
+
* Inspects a rejected (non-402) response and decides whether to resend the request once.
|
|
201
|
+
*
|
|
202
|
+
* `context.request` is the request that got the response, so a prover can tell which of its
|
|
203
|
+
* proofs the server rejected. Return headers to resend the request with: they are set on the
|
|
204
|
+
* request before every in-scope prover proves it again, so signing provers cover them.
|
|
205
|
+
* Same-named headers returned by several provers are combined, comma-separated. Payment
|
|
206
|
+
* credential headers (`Authorization`, `Payment-Authorization`, `Payment-Signature`,
|
|
207
|
+
* `X-Payment`, the header the Challenge names, and any header holding a Payment credential) are
|
|
208
|
+
* ignored. Return `false` or `undefined` not to resend. Paid attempts are never resent. `true`
|
|
209
|
+
* resends with no extra headers and is deprecated: return `{}` instead.
|
|
109
210
|
*/
|
|
110
|
-
retry?: ((response: Response) => MaybePromise<boolean | undefined>) | undefined;
|
|
211
|
+
readonly retry?: ((response: Response, context: RetryContext) => MaybePromise<HeadersInit | boolean | undefined>) | undefined;
|
|
111
212
|
};
|
|
112
213
|
//# sourceMappingURL=Types.d.ts.map
|
package/dist/identity/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * as Client from './Client.js';
|
|
2
|
+
export * as Headers from './Headers.js';
|
|
2
3
|
export * as Server from './Server.js';
|
|
4
|
+
export * as Status from './Status.js';
|
|
3
5
|
export { anyOf } from './Server.js';
|
|
4
6
|
export { from, Rejection } from './Callback.js';
|
|
5
7
|
export * as Store from '../Store.js';
|
package/dist/identity/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * as Client from './Client.js';
|
|
2
|
+
export * as Headers from './Headers.js';
|
|
2
3
|
export * as Server from './Server.js';
|
|
4
|
+
export * as Status from './Status.js';
|
|
3
5
|
export { anyOf } from './Server.js';
|
|
4
6
|
export { from, Rejection } from './Callback.js';
|
|
5
7
|
export * as Store from '../Store.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as Types from '../Types.js';
|
|
2
|
+
/** The response header in which a 402 lists the identities its payment check requires. */
|
|
3
|
+
export declare const header = "Identity-Required";
|
|
4
|
+
/**
|
|
5
|
+
* Serializes requirements as a structured-field list: each `type` token with an `issuer`
|
|
6
|
+
* string parameter when set. Throws a `TypeError` for a type that is not a token.
|
|
7
|
+
*/
|
|
8
|
+
export declare function serialize(requirements: readonly Types.Requirement[]): string;
|
|
9
|
+
/** Parses an `Identity-Required` value, skipping members that are not requirements. */
|
|
10
|
+
export declare function parse(value: string | null): readonly Types.Requirement[];
|
|
11
|
+
/**
|
|
12
|
+
* Headers that list requirements as a structured-field list, whose values `anyOf` groups into
|
|
13
|
+
* one inner list of alternatives. Lowercase, as `Headers` yields names.
|
|
14
|
+
*/
|
|
15
|
+
export declare const alternativeHeaders: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* Combines the values the rejected members of an `anyOf` sent in one requirements header:
|
|
18
|
+
*
|
|
19
|
+
* - Each value is one item or one inner list: their items, deduplicated, become one inner list
|
|
20
|
+
* of alternatives, any one of which meets it (a single item stays bare).
|
|
21
|
+
* - Otherwise (a member lists several requirements, or a value is malformed): the values are
|
|
22
|
+
* kept as they are. Inner lists do not nest, so "a and b, or c" is sent as all three, and a
|
|
23
|
+
* client asks for more than the route needs, never less.
|
|
24
|
+
*/
|
|
25
|
+
export declare function alternatives(values: readonly string[]): string;
|
|
26
|
+
/** Returns the distinct requirements of several lists, in first-seen order. */
|
|
27
|
+
export declare function merge(lists: readonly (readonly Types.Requirement[])[]): readonly Types.Requirement[];
|
|
28
|
+
//# sourceMappingURL=Requirements.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { isInnerList, parseList, serializeItem, serializeList, Token } from 'structured-headers';
|
|
2
|
+
/** The response header in which a 402 lists the identities its payment check requires. */
|
|
3
|
+
export const header = 'Identity-Required';
|
|
4
|
+
/**
|
|
5
|
+
* Serializes requirements as a structured-field list: each `type` token with an `issuer`
|
|
6
|
+
* string parameter when set. Throws a `TypeError` for a type that is not a token.
|
|
7
|
+
*/
|
|
8
|
+
export function serialize(requirements) {
|
|
9
|
+
return serializeList(requirements.map(({ issuer, type }) => [new Token(type), new Map(issuer === undefined ? [] : [['issuer', issuer]])]));
|
|
10
|
+
}
|
|
11
|
+
/** Parses an `Identity-Required` value, skipping members that are not requirements. */
|
|
12
|
+
export function parse(value) {
|
|
13
|
+
if (!value)
|
|
14
|
+
return [];
|
|
15
|
+
let list;
|
|
16
|
+
try {
|
|
17
|
+
list = parseList(value);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const requirements = [];
|
|
23
|
+
for (const member of list) {
|
|
24
|
+
if (isInnerList(member) || !(member[0] instanceof Token))
|
|
25
|
+
continue;
|
|
26
|
+
const issuer = member[1].get('issuer');
|
|
27
|
+
requirements.push(Object.freeze({
|
|
28
|
+
type: member[0].toString(),
|
|
29
|
+
...(typeof issuer === 'string' && { issuer }),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
return Object.freeze(requirements);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Headers that list requirements as a structured-field list, whose values `anyOf` groups into
|
|
36
|
+
* one inner list of alternatives. Lowercase, as `Headers` yields names.
|
|
37
|
+
*/
|
|
38
|
+
export const alternativeHeaders = Object.freeze([
|
|
39
|
+
'identity-attestation-required',
|
|
40
|
+
]);
|
|
41
|
+
/**
|
|
42
|
+
* Combines the values the rejected members of an `anyOf` sent in one requirements header:
|
|
43
|
+
*
|
|
44
|
+
* - Each value is one item or one inner list: their items, deduplicated, become one inner list
|
|
45
|
+
* of alternatives, any one of which meets it (a single item stays bare).
|
|
46
|
+
* - Otherwise (a member lists several requirements, or a value is malformed): the values are
|
|
47
|
+
* kept as they are. Inner lists do not nest, so "a and b, or c" is sent as all three, and a
|
|
48
|
+
* client asks for more than the route needs, never less.
|
|
49
|
+
*/
|
|
50
|
+
export function alternatives(values) {
|
|
51
|
+
const items = [];
|
|
52
|
+
for (const value of values) {
|
|
53
|
+
let list;
|
|
54
|
+
try {
|
|
55
|
+
list = parseList(value);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return values.join(', ');
|
|
59
|
+
}
|
|
60
|
+
const [member] = list;
|
|
61
|
+
if (list.length !== 1 || !member)
|
|
62
|
+
return values.join(', ');
|
|
63
|
+
items.push(...(isInnerList(member) ? member[0] : [member]));
|
|
64
|
+
}
|
|
65
|
+
const unique = [...new Map(items.map((item) => [serializeItem(item), item])).values()];
|
|
66
|
+
return serializeList(unique.length === 1 ? unique : [[unique, new Map()]]);
|
|
67
|
+
}
|
|
68
|
+
/** Returns the distinct requirements of several lists, in first-seen order. */
|
|
69
|
+
export function merge(lists) {
|
|
70
|
+
const seen = new Map();
|
|
71
|
+
for (const requirement of lists.flat()) {
|
|
72
|
+
const key = JSON.stringify([requirement.type, requirement.issuer ?? null]);
|
|
73
|
+
if (!seen.has(key))
|
|
74
|
+
seen.set(key, requirement);
|
|
75
|
+
}
|
|
76
|
+
return Object.freeze([...seen.values()]);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=Requirements.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * as BodyDigest from './BodyDigest.js';
|
|
|
2
2
|
export * as Challenge from './Challenge.js';
|
|
3
3
|
export * as Constants from './Constants.js';
|
|
4
4
|
export * as Credential from './Credential.js';
|
|
5
|
+
export * as Currency from './Currency.js';
|
|
5
6
|
export * as Errors from './Errors.js';
|
|
6
7
|
export * as Expires from './Expires.js';
|
|
7
8
|
export * as evm from './evm/index.js';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * as BodyDigest from './BodyDigest.js';
|
|
|
2
2
|
export * as Challenge from './Challenge.js';
|
|
3
3
|
export * as Constants from './Constants.js';
|
|
4
4
|
export * as Credential from './Credential.js';
|
|
5
|
+
export * as Currency from './Currency.js';
|
|
5
6
|
export * as Errors from './Errors.js';
|
|
6
7
|
export * as Expires from './Expires.js';
|
|
7
8
|
export * as evm from './evm/index.js';
|
package/dist/internal/env.d.ts
CHANGED
|
@@ -15,5 +15,19 @@ declare const variables: {
|
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export declare function get(key: keyof typeof variables): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Describes why the current runtime looks like production or a multi-instance platform, or
|
|
20
|
+
* returns `undefined` for local development and tests.
|
|
21
|
+
*
|
|
22
|
+
* Checks `NODE_ENV=production`, the platform variables of serverless and multi-replica hosts
|
|
23
|
+
* (Vercel, AWS Lambda, Netlify, Fly.io, Cloud Run, Render, Railway, Heroku, Deno Deploy), and the
|
|
24
|
+
* Cloudflare Workers runtime. Instance-local state is unsafe in all of them.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* Env.sharedRuntime() // e.g. "VERCEL is set", or undefined locally
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function sharedRuntime(): string | undefined;
|
|
18
32
|
export {};
|
|
19
33
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/internal/env.js
CHANGED
|
@@ -32,6 +32,44 @@ export function get(key) {
|
|
|
32
32
|
}
|
|
33
33
|
return defaults[key];
|
|
34
34
|
}
|
|
35
|
+
/** Environment variables that mark a platform which may run several instances of one server. */
|
|
36
|
+
const sharedPlatforms = [
|
|
37
|
+
'AWS_LAMBDA_FUNCTION_NAME',
|
|
38
|
+
'DENO_DEPLOYMENT_ID',
|
|
39
|
+
'DYNO',
|
|
40
|
+
'FLY_APP_NAME',
|
|
41
|
+
'K_SERVICE',
|
|
42
|
+
'NETLIFY',
|
|
43
|
+
'RAILWAY_ENVIRONMENT',
|
|
44
|
+
'RENDER',
|
|
45
|
+
'VERCEL',
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Describes why the current runtime looks like production or a multi-instance platform, or
|
|
49
|
+
* returns `undefined` for local development and tests.
|
|
50
|
+
*
|
|
51
|
+
* Checks `NODE_ENV=production`, the platform variables of serverless and multi-replica hosts
|
|
52
|
+
* (Vercel, AWS Lambda, Netlify, Fly.io, Cloud Run, Render, Railway, Heroku, Deno Deploy), and the
|
|
53
|
+
* Cloudflare Workers runtime. Instance-local state is unsafe in all of them.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* Env.sharedRuntime() // e.g. "VERCEL is set", or undefined locally
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function sharedRuntime() {
|
|
61
|
+
if (read('NODE_ENV') === 'production')
|
|
62
|
+
return 'NODE_ENV is "production"';
|
|
63
|
+
for (const name of sharedPlatforms)
|
|
64
|
+
if (read(name))
|
|
65
|
+
return `${name} is set`;
|
|
66
|
+
try {
|
|
67
|
+
if (globalThis.navigator?.userAgent === 'Cloudflare-Workers')
|
|
68
|
+
return 'the runtime is Cloudflare Workers';
|
|
69
|
+
}
|
|
70
|
+
catch { }
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
35
73
|
/** Reads a single environment variable, probing available runtime APIs. */
|
|
36
74
|
function read(name) {
|
|
37
75
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Current mppx package version. */
|
|
2
|
-
export declare const version = "0.
|
|
2
|
+
export declare const version = "0.18.1";
|
|
3
3
|
/** Canonical SDK identifier for this mppx release. */
|
|
4
|
-
export declare const sdkIdentifier = "mppx/0.
|
|
4
|
+
export declare const sdkIdentifier = "mppx/0.18.1";
|
|
5
5
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/internal/version.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by scripts/sync-version.ts.
|
|
2
2
|
/** Current mppx package version. */
|
|
3
|
-
export const version = '0.
|
|
3
|
+
export const version = '0.18.1';
|
|
4
4
|
/** Canonical SDK identifier for this mppx release. */
|
|
5
5
|
export const sdkIdentifier = `mppx/${version}`;
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Strips hop-by-hop, auth, encoding, cookie, and forwarding headers from a request before proxying upstream. */
|
|
1
|
+
/** Strips hop-by-hop, auth, identity, encoding, cookie, and forwarding headers from a request before proxying upstream. */
|
|
2
2
|
export declare function scrub(headers: Headers): Headers;
|
|
3
3
|
/**
|
|
4
4
|
* Strips re-streaming headers (`content-encoding`, `content-length`) and
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as IdentityHeaders from '../../identity/Headers.js';
|
|
1
2
|
const hopByHopHeaders = new Set([
|
|
2
3
|
'connection',
|
|
3
4
|
'keep-alive',
|
|
@@ -11,8 +12,6 @@ const hopByHopHeaders = new Set([
|
|
|
11
12
|
// Payment credentials are consumed by the proxy and must never reach upstream services.
|
|
12
13
|
const paymentHeaders = new Set([
|
|
13
14
|
'accept-payment',
|
|
14
|
-
'identity-attestation',
|
|
15
|
-
'identity-attestation-required',
|
|
16
15
|
'authorization',
|
|
17
16
|
'payment-authorization',
|
|
18
17
|
'payment-receipt',
|
|
@@ -23,13 +22,15 @@ const paymentHeaders = new Set([
|
|
|
23
22
|
'payment-signature',
|
|
24
23
|
'www-authenticate',
|
|
25
24
|
]);
|
|
26
|
-
/** Strips hop-by-hop, auth, encoding, cookie, and forwarding headers from a request before proxying upstream. */
|
|
25
|
+
/** Strips hop-by-hop, auth, identity, encoding, cookie, and forwarding headers from a request before proxying upstream. */
|
|
27
26
|
export function scrub(headers) {
|
|
28
27
|
const scrubbed = new Headers();
|
|
29
28
|
for (const [name, value] of headers) {
|
|
30
29
|
const lower = name.toLowerCase();
|
|
31
30
|
if (paymentHeaders.has(lower))
|
|
32
31
|
continue;
|
|
32
|
+
if (IdentityHeaders.request.includes(lower))
|
|
33
|
+
continue;
|
|
33
34
|
if (lower === 'accept-encoding')
|
|
34
35
|
continue;
|
|
35
36
|
if (lower === 'content-length')
|
|
@@ -67,12 +68,15 @@ export function scrubResponse(response) {
|
|
|
67
68
|
headers.delete(name);
|
|
68
69
|
}
|
|
69
70
|
headers.delete('payment-authorization');
|
|
71
|
+
// The proxy decides which identity the client presents, so upstream identity headers never pass.
|
|
72
|
+
for (const name of [...IdentityHeaders.request, ...IdentityHeaders.response])
|
|
73
|
+
headers.delete(name);
|
|
70
74
|
const authorization = headers.get('authorization');
|
|
71
75
|
if (authorization && /^\s*Payment(?:\s|$)/i.test(authorization))
|
|
72
76
|
headers.delete('authorization');
|
|
73
77
|
const authenticate = headers.get('www-authenticate');
|
|
74
78
|
if (authenticate) {
|
|
75
|
-
const remaining =
|
|
79
|
+
const remaining = removeChallenges(authenticate);
|
|
76
80
|
if (remaining)
|
|
77
81
|
headers.set('www-authenticate', remaining);
|
|
78
82
|
else
|
|
@@ -84,8 +88,8 @@ export function scrubResponse(response) {
|
|
|
84
88
|
headers,
|
|
85
89
|
});
|
|
86
90
|
}
|
|
87
|
-
/** Removes Payment authentication challenges while preserving other schemes. */
|
|
88
|
-
function
|
|
91
|
+
/** Removes Payment and identity authentication challenges while preserving other schemes. */
|
|
92
|
+
function removeChallenges(value) {
|
|
89
93
|
const starts = [];
|
|
90
94
|
let inQuotes = false;
|
|
91
95
|
let escaped = false;
|
|
@@ -121,7 +125,7 @@ function removePaymentChallenges(value) {
|
|
|
121
125
|
index = afterScheme - 1;
|
|
122
126
|
}
|
|
123
127
|
return starts
|
|
124
|
-
.filter(({ scheme }) => scheme !== 'payment')
|
|
128
|
+
.filter(({ scheme }) => scheme !== 'payment' && !IdentityHeaders.challenges.includes(scheme))
|
|
125
129
|
.map(({ index }) => {
|
|
126
130
|
const originalPosition = starts.findIndex((start) => start.index === index);
|
|
127
131
|
const end = starts[originalPosition + 1]?.index ?? value.length;
|
package/dist/server/Mppx.d.ts
CHANGED
|
@@ -278,11 +278,12 @@ type IntentHandlers<methods extends readonly Method.AnyServer[], transport exten
|
|
|
278
278
|
}>, transport>;
|
|
279
279
|
};
|
|
280
280
|
/**
|
|
281
|
-
* Route identity option. HTTP routes accept identity verifiers, all of which must be valid
|
|
282
|
-
* use `Identity.anyOf` to accept one of several protocols
|
|
281
|
+
* Route identity option. HTTP routes accept identity verifiers, all of which must be valid
|
|
282
|
+
* (use `Identity.anyOf` to accept one of several protocols), or `{ request, payment }` with an
|
|
283
|
+
* experimental payment check. Other transports reject it.
|
|
283
284
|
*/
|
|
284
285
|
type RouteIdentity<transport extends Transport.AnyTransport> = Transport.InputOf<transport> extends Request ? Transport.ChallengeOutputOf<transport> extends Response ? {
|
|
285
|
-
identity?:
|
|
286
|
+
identity?: Identity.Route | undefined;
|
|
286
287
|
} : {
|
|
287
288
|
identity?: never;
|
|
288
289
|
} : {
|
|
@@ -388,7 +389,14 @@ declare namespace MethodFn {
|
|
|
388
389
|
scope?: string | undefined;
|
|
389
390
|
} & Method.WithDefaults<z.input<method['schema']['request']>, defaults>;
|
|
390
391
|
type Response<transport extends Transport.AnyTransport = Transport.Http> = {
|
|
392
|
+
/** The 402 Challenge response, or the identity rejection response when `rejection` is set. */
|
|
391
393
|
challenge: Transport.ChallengeOutputOf<transport>;
|
|
394
|
+
/**
|
|
395
|
+
* Set when the route rejected the request's identity. `challenge` then holds the
|
|
396
|
+
* rejection response (`Identity.Status.codes[rejection.status]`, no Payment Challenge) to
|
|
397
|
+
* send as is. It stays on this non-200 branch so callers never run paid work.
|
|
398
|
+
*/
|
|
399
|
+
rejection?: Identity.Rejection | undefined;
|
|
392
400
|
status: 402;
|
|
393
401
|
} | {
|
|
394
402
|
status: 200;
|
|
@@ -412,10 +420,10 @@ type ConfiguredHandler<transport extends Transport.AnyTransport = Transport.Http
|
|
|
412
420
|
scope?: string | undefined;
|
|
413
421
|
_canonicalRequest: Record<string, unknown>;
|
|
414
422
|
_stableBinding?: Method.StableBindingFn<Method.Method> | undefined;
|
|
415
|
-
/**
|
|
416
|
-
_paymentIdentity?: readonly Identity.Verifier[] | undefined;
|
|
417
|
-
/** Whether the route requires identity verifiers (request or payment stage). */
|
|
423
|
+
/** Whether the route requires identity (request-stage verifiers or a payment check). */
|
|
418
424
|
_identity?: boolean | undefined;
|
|
425
|
+
/** The route's payment check, compared across composed offers. */
|
|
426
|
+
_paymentCheck?: Identity.PaymentCheck | undefined;
|
|
419
427
|
_transport: Transport.AnyTransport;
|
|
420
428
|
};
|
|
421
429
|
};
|