mppx 0.21.1 → 0.21.3
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 +24 -0
- package/dist/Challenge.d.ts +19 -0
- package/dist/Challenge.js +104 -31
- package/dist/Errors.d.ts +68 -0
- package/dist/Errors.js +63 -0
- package/dist/Html.d.ts +1 -1
- package/dist/Html.js +2 -2
- package/dist/Method.d.ts +2 -2
- package/dist/Method.js +6 -1
- package/dist/cli/cli.js +138 -138
- package/dist/cli/internal.js +1 -1
- package/dist/cli/plugins/evm.js +1 -1
- package/dist/cli/plugins/index.js +13 -13
- package/dist/cli/plugins/x402.js +1 -1
- package/dist/cli/utils.d.ts +2 -45
- package/dist/cli/utils.js +2 -79
- package/dist/cli/validate/index.js +5 -2
- package/dist/cli/validate/payment.d.ts +1 -1
- package/dist/cli/validate/payment.js +3 -3
- package/dist/cli/validate/print.d.ts +12 -0
- package/dist/cli/validate/print.js +35 -0
- package/dist/client/Mppx.js +18 -1
- package/dist/client/core.d.ts +6 -0
- package/dist/client/core.js +6 -0
- package/dist/client/index.d.ts +2 -8
- package/dist/client/index.js +2 -6
- package/dist/client/internal/Fetch.d.ts +8 -0
- package/dist/client/internal/Fetch.js +13 -1
- package/dist/client/internal/protocols/Shared.js +1 -1
- package/dist/client/internal/protocols/X402.js +3 -3
- package/dist/evm/client/Charge.js +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/server/Charge.js +1 -1
- package/dist/integrations/x402/Evm.js +1 -1
- package/dist/integrations/x402/Negotiator.js +1 -1
- package/dist/internal/AcceptPayment.d.ts +1 -1
- package/dist/internal/AcceptPayment.js +9 -2
- package/dist/internal/CredentialExpiry.js +1 -1
- package/dist/{mcp/internal/Credential.d.ts → internal/McpCredential.d.ts} +2 -2
- package/dist/{mcp/internal/Credential.js → internal/McpCredential.js} +2 -2
- package/dist/{server/internal → internal}/challengeMeta.js +1 -1
- package/dist/{server/internal → internal}/html/config.d.ts +2 -2
- package/dist/internal/pc.d.ts +46 -0
- package/dist/internal/pc.js +80 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/{x402 → internal/x402}/Header.js +1 -1
- package/dist/{x402 → internal/x402}/Siwx.d.ts +2 -2
- package/dist/{x402 → internal/x402}/Siwx.js +2 -2
- package/dist/{x402 → internal/x402}/Types.d.ts +1 -1
- package/dist/{x402 → internal/x402}/Types.js +1 -1
- package/dist/mcp/server/index.d.ts +1 -1
- package/dist/mcp/server/index.js +1 -1
- package/dist/server/Mppx.d.ts +1 -1
- package/dist/server/Mppx.js +16 -6
- package/dist/server/Transport.d.ts +2 -2
- package/dist/server/Transport.js +4 -4
- package/dist/server/index.d.ts +1 -8
- package/dist/server/index.js +1 -8
- package/dist/{mcp/server/Transport.d.ts → server/internal/mcpSdk.d.ts} +2 -2
- package/dist/{mcp/server/Transport.js → server/internal/mcpSdk.js} +3 -3
- package/dist/stripe/server/Charge.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/Methods.d.ts +3 -0
- package/dist/tempo/Methods.js +3 -1
- package/dist/tempo/client/Charge.js +1 -1
- package/dist/tempo/client/Methods.d.ts +3 -0
- package/dist/tempo/client/index.d.ts +3 -0
- package/dist/tempo/client/index.js +1 -0
- package/dist/tempo/internal/configurable-account.d.ts +26 -0
- package/dist/tempo/internal/configurable-account.js +77 -0
- package/dist/tempo/internal/signature.d.ts +15 -0
- package/dist/tempo/internal/signature.js +43 -0
- package/dist/tempo/server/Charge.d.ts +1 -1
- package/dist/tempo/server/Charge.js +1 -1
- package/dist/tempo/server/Methods.d.ts +139 -4
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/ChannelOps.d.ts +29 -0
- package/dist/tempo/session/client/ChannelOps.js +108 -3
- package/dist/tempo/session/client/CredentialState.d.ts +6 -0
- package/dist/tempo/session/client/CredentialState.js +29 -4
- package/dist/tempo/session/client/Session.d.ts +3 -0
- package/dist/tempo/session/client/SessionManager.js +5 -1
- package/dist/tempo/session/precompile/Chain.d.ts +35 -1
- package/dist/tempo/session/precompile/Chain.js +52 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +46 -5
- package/dist/tempo/session/precompile/Voucher.js +78 -29
- package/dist/tempo/session/precompile/escrow.abi.d.ts +79 -0
- package/dist/tempo/session/precompile/escrow.abi.js +38 -0
- package/dist/tempo/session/server/ChannelStore.d.ts +27 -0
- package/dist/tempo/session/server/ChannelStore.js +24 -3
- package/dist/tempo/session/server/CredentialVerification.d.ts +7 -1
- package/dist/tempo/session/server/CredentialVerification.js +91 -12
- package/dist/tempo/session/server/RequestState.d.ts +2 -0
- package/dist/tempo/session/server/RequestState.js +1 -0
- package/dist/tempo/session/server/Session.d.ts +11 -0
- package/dist/tempo/session/server/Session.js +10 -2
- package/dist/tempo/session/server/SponsorshipLimit.d.ts +11 -3
- package/dist/tempo/session/server/SponsorshipLimit.js +36 -4
- package/dist/tempo/subscription/KeyAuthorization.js +6 -2
- package/dist/{cli/validate → validation}/challenge.d.ts +1 -1
- package/dist/{cli/validate → validation}/challenge.js +4 -4
- package/dist/validation/core.d.ts +29 -2
- package/dist/validation/core.js +41 -10
- package/dist/{cli/validate → validation}/helpers.d.ts +0 -10
- package/dist/{cli/validate → validation}/helpers.js +1 -35
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +1 -1
- package/dist/x402/Assets.d.ts +1 -1
- package/dist/x402/client/Exact.d.ts +1 -1
- package/dist/x402/client/Exact.js +2 -2
- package/dist/x402/index.d.ts +4 -4
- package/dist/x402/index.js +4 -4
- package/dist/x402/internal/RouteBinding.d.ts +1 -1
- package/dist/x402/mcp.js +2 -2
- package/dist/x402/server/EvmCharge.d.ts +2 -2
- package/dist/x402/server/EvmCharge.js +4 -4
- package/dist/x402/server/Facilitator.d.ts +1 -1
- package/dist/x402/server/Facilitator.js +1 -1
- package/package.json +13 -1
- /package/dist/{server/internal → internal}/challengeMeta.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.js +0 -0
- /package/dist/{server/internal → internal}/html/config.js +0 -0
- /package/dist/{server/internal → internal}/html/constants.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/constants.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.js +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.d.ts +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.js +0 -0
- /package/dist/{x402 → internal/x402}/Header.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.js +0 -0
- /package/dist/{cli/validate → validation}/messages.d.ts +0 -0
- /package/dist/{cli/validate → validation}/messages.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# mppx
|
|
2
2
|
|
|
3
|
+
## 0.21.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8e4cd5f: Preserved configured plugin payment policies when using persistent Tempo session accounts.
|
|
8
|
+
- ad2a467: Fixed `Challenge.deserialize` and `Challenge.serialize` to follow the MPP core grammar: payment method identifiers must be `1*LOWERALPHA` (a-z only), and a backslash in a quoted-string is a quoted-pair, so `\u2014` parses to the text `u2014` instead of being decoded. `Challenge.serialize` now throws for characters above U+00FF in any parameter except `description`, which keeps its `\uXXXX` escape so a 402 never fails on an em dash or emoji.
|
|
9
|
+
|
|
10
|
+
`Mppx.create` now throws at startup for a method name outside a-z, or for a `realm` above U+00FF on a transport that sends the Challenge in a header, instead of failing on every 402. `Challenge.deserializeList` skips an offer whose method id is outside a-z rather than rejecting the whole header, and the client keys payment retries without building a header or reading the display-only `description`.
|
|
11
|
+
|
|
12
|
+
The client now refuses a challenge from a server that escaped a parameter bound into the Challenge ID (such as `realm`) as `\uXXXX`, as servers before quoted-pair parsing did for characters above U+00FF: it skips such an offer when another is payable, and otherwise throws `Errors.LegacyUnicodeEscapedChallengeError` before creating, signing or broadcasting anything, since the server would reject the credential.
|
|
13
|
+
|
|
14
|
+
## 0.21.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 60f265c: Fixed `mppx/validation` so it no longer imports the CLI, which pulled in the CLI's bundled `incur` dependency and failed to load from npm. `validate()` and `validateStream()` now take an optional `payment` validator; without one, payment checks are reported as skipped. `mppx validate` passes its own.
|
|
19
|
+
|
|
20
|
+
Moved shared modules so lower layers no longer import higher ones: the HTML payment-page infrastructure and x402 wire helpers now live under `src/internal`, and the MCP SDK server transport lives under `src/server`. Public entry points are unchanged.
|
|
21
|
+
|
|
22
|
+
- 6056a5b: Added `mppx/client/core`, `mppx/tempo/client` and `mppx/tempo/server` entrypoints, so apps can load the client primitives or only the Tempo method without the other payment methods. `mppx/client` and `mppx/server` export the same API as before.
|
|
23
|
+
- db173d9: Fixed Tempo session voucher, close authorization and subscription key authorization verification to reject secp256k1 signatures with a high `s` value, which Tempo does not accept onchain. Voucher and close authorization signing now normalize a signer's high-`s` signature to its low-`s` equivalent.
|
|
24
|
+
- 98d110b: Added TIP-1166 configurable account voucher signers to `tempo/session`. Servers accept configurable account (`0x05`) vouchers and close authorizations when `configurableVouchers` is set (default `false`), advertise it in the challenge, and check each voucher against the signer config commitment recorded at open (`OpeningCommitmentRecorded`). Configurable account clients open channels with their config commitment as the salt, sign vouchers with configurable account signatures, refuse to open against servers that do not advertise `configurableVouchers` (`ConfigurableVouchersUnsupportedError`), and surface top-ups that revert because the signer config changed as `SignerConfigChangedError`. `Voucher.verifyVoucher` and `Voucher.verifyCloseAuthorization` take optional `{ configurable, openingCommitment }` options; without them they accept only primitive signatures, as before.
|
|
25
|
+
- bd9dac5: Fixed `validateStream` to pass its synthesized `Payment: failed` check to `onPaymentResults`, and fixed `validate()` to promise automatic Tempo wallet provisioning only when a payment validator is configured.
|
|
26
|
+
|
|
3
27
|
## 0.21.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/Challenge.d.ts
CHANGED
|
@@ -223,6 +223,10 @@ export declare namespace fromMethod {
|
|
|
223
223
|
* ```
|
|
224
224
|
*/
|
|
225
225
|
export declare function serialize(challenge: Challenge): string;
|
|
226
|
+
/** @internal Throws unless `method` matches the spec's method identifier grammar (a-z only). */
|
|
227
|
+
export declare function assertMethod(method: string): void;
|
|
228
|
+
/** @internal Throws unless `realm` can be sent in a header (no characters above U+00FF). */
|
|
229
|
+
export declare function assertRealm(realm: string): void;
|
|
226
230
|
/**
|
|
227
231
|
* Deserializes a WWW-Authenticate header value to a challenge.
|
|
228
232
|
*
|
|
@@ -241,6 +245,21 @@ export declare function serialize(challenge: Challenge): string;
|
|
|
241
245
|
* @returns The deserialized challenge.
|
|
242
246
|
*/
|
|
243
247
|
export declare function deserialize<const methods extends readonly Method.Method[] | undefined = undefined>(value: string, options?: from.Options<methods>): from.ReturnType<from.Parameters, methods>;
|
|
248
|
+
/**
|
|
249
|
+
* Returns whether a challenge parsed from a header escaped an HMAC-bound parameter as `\\uXXXX`,
|
|
250
|
+
* as servers did before quoted-pair parsing. Paying it would fail verification after the payment
|
|
251
|
+
* may already have moved funds.
|
|
252
|
+
*
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
export declare function isLegacyUnicodeEscaped(challenge: unknown): boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Throws {@link Errors.LegacyUnicodeEscapedChallengeError} for a challenge that
|
|
258
|
+
* {@link isLegacyUnicodeEscaped} reports, before a credential is created for it.
|
|
259
|
+
*
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
export declare function assertNotLegacyUnicodeEscaped(challenge: unknown): void;
|
|
244
263
|
/**
|
|
245
264
|
* Returns whether a `WWW-Authenticate` value contains a Payment challenge.
|
|
246
265
|
*
|
package/dist/Challenge.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { Base64, Bytes, Hash } from 'ox';
|
|
2
2
|
import * as Constants from './Constants.js';
|
|
3
|
+
import * as Errors from './Errors.js';
|
|
3
4
|
import { constantTimeEqual } from './internal/constantTimeEqual.js';
|
|
4
5
|
import * as PaymentRequest from './PaymentRequest.js';
|
|
5
6
|
import * as z from './zod.js';
|
|
6
7
|
const maxRequestParameterLength = 16 * 1024;
|
|
8
|
+
/**
|
|
9
|
+
* Marks a challenge parsed from a header whose HMAC-bound parameter carried a legacy `\\uXXXX`
|
|
10
|
+
* escape. A symbol key, so it survives spreads but stays out of JSON and the wire form.
|
|
11
|
+
*/
|
|
12
|
+
const legacyUnicodeEscape = Symbol('mppx.Challenge.legacyUnicodeEscape');
|
|
13
|
+
/** Auth-params the challenge keeps and binds into its ID (see `idBindingInput`). */
|
|
14
|
+
const boundParams = new Set([
|
|
15
|
+
'digest',
|
|
16
|
+
'expires',
|
|
17
|
+
'header',
|
|
18
|
+
'intent',
|
|
19
|
+
'method',
|
|
20
|
+
'opaque',
|
|
21
|
+
'realm',
|
|
22
|
+
'request',
|
|
23
|
+
]);
|
|
7
24
|
const unsupportedCredentialHeaderMessage = 'Unsupported credential header: challenges may only select Payment-Authorization.';
|
|
8
25
|
/**
|
|
9
26
|
* Thrown when a challenge selects a credential header other than `Payment-Authorization`.
|
|
@@ -193,15 +210,20 @@ export function fromMethod(method, parameters) {
|
|
|
193
210
|
* ```
|
|
194
211
|
*/
|
|
195
212
|
export function serialize(challenge) {
|
|
213
|
+
// Re-serializing drops the backslash that marks a legacy escape, so a signer reading the new
|
|
214
|
+
// header would not see it.
|
|
215
|
+
assertNotLegacyUnicodeEscaped(challenge);
|
|
216
|
+
const { method } = challenge;
|
|
217
|
+
assertMethod(method);
|
|
196
218
|
const parts = [
|
|
197
219
|
authParam('id', challenge.id),
|
|
198
220
|
authParam('realm', challenge.realm),
|
|
199
|
-
authParam('method',
|
|
221
|
+
authParam('method', method),
|
|
200
222
|
authParam('intent', challenge.intent),
|
|
201
223
|
authParam('request', PaymentRequest.serialize(challenge.request)),
|
|
202
224
|
];
|
|
203
225
|
if (challenge.description !== undefined)
|
|
204
|
-
parts.push(authParam('description', challenge.description));
|
|
226
|
+
parts.push(authParam('description', challenge.description, { escapeUnicode: true }));
|
|
205
227
|
if (challenge.digest !== undefined)
|
|
206
228
|
parts.push(authParam('digest', challenge.digest));
|
|
207
229
|
if (challenge.expires !== undefined)
|
|
@@ -215,19 +237,41 @@ export function serialize(challenge) {
|
|
|
215
237
|
parts.push(authParam('opaque', PaymentRequest.serialize(challenge.meta)));
|
|
216
238
|
return `${Constants.Schemes.payment} ${parts.join(', ')}`;
|
|
217
239
|
}
|
|
240
|
+
/** Payment method identifier grammar: `1*LOWERALPHA` (a-z only). */
|
|
241
|
+
const methodPattern = /^[a-z]+$/;
|
|
242
|
+
/** @internal Thrown for a method identifier outside the spec's grammar. */
|
|
243
|
+
class InvalidMethodError extends Error {
|
|
244
|
+
name = 'InvalidMethodError';
|
|
245
|
+
constructor(method) {
|
|
246
|
+
super(`Invalid method: "${method}". Must be lowercase letters a-z per spec.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** @internal Throws unless `method` matches the spec's method identifier grammar (a-z only). */
|
|
250
|
+
export function assertMethod(method) {
|
|
251
|
+
if (!methodPattern.test(method))
|
|
252
|
+
throw new InvalidMethodError(method);
|
|
253
|
+
}
|
|
254
|
+
/** @internal Throws unless `realm` can be sent in a header (no characters above U+00FF). */
|
|
255
|
+
export function assertRealm(realm) {
|
|
256
|
+
if (/[\u0100-\uffff]/.test(realm))
|
|
257
|
+
throw new Error('Invalid realm: characters above U+00FF cannot be sent in a header.');
|
|
258
|
+
}
|
|
218
259
|
/** @internal */
|
|
219
|
-
function authParam(name, value) {
|
|
260
|
+
function authParam(name, value, options = {}) {
|
|
220
261
|
if (/[\r\n]/.test(value))
|
|
221
262
|
throw new Error('Invalid quoted-string value.');
|
|
222
|
-
const escaped = value
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
263
|
+
const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
264
|
+
// Header values must be ByteStrings (code points ≤ 0xFF). Receivers read a
|
|
265
|
+
// backslash as quoted-pair (`\\u2014` is the text `u2014`), so other
|
|
266
|
+
// characters cannot round-trip in a quoted-string.
|
|
267
|
+
if (!/[\u0100-\uffff]/.test(escaped))
|
|
268
|
+
return `${name}="${escaped}"`;
|
|
269
|
+
// The display-only description is not bound into the Challenge ID: keep the
|
|
270
|
+
// `\\uXXXX` escape there so a 402 never fails on an em dash or emoji in a
|
|
271
|
+
// product title. Receivers show the escape text.
|
|
272
|
+
if (options.escapeUnicode)
|
|
273
|
+
return `${name}="${escaped.replace(/[\u0100-\uffff]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`)}"`;
|
|
274
|
+
throw new Error(`Invalid ${name}: characters above U+00FF cannot be sent in a header.`);
|
|
231
275
|
}
|
|
232
276
|
/**
|
|
233
277
|
* Deserializes a WWW-Authenticate header value to a challenge.
|
|
@@ -250,14 +294,15 @@ export function deserialize(value, options) {
|
|
|
250
294
|
const params = extractPaymentAuthParams(value);
|
|
251
295
|
if (!params)
|
|
252
296
|
throw new Error('Missing Payment scheme.');
|
|
253
|
-
const
|
|
297
|
+
const legacyEscaped = new Set();
|
|
298
|
+
const result = parseAuthParams(params, legacyEscaped);
|
|
254
299
|
const { request, opaque, header, ...rest } = result;
|
|
255
300
|
if (!request)
|
|
256
301
|
throw new Error('Missing request parameter.');
|
|
257
302
|
if (request.length > maxRequestParameterLength)
|
|
258
303
|
throw new Error('Request parameter too large.');
|
|
259
|
-
if (rest.method
|
|
260
|
-
|
|
304
|
+
if (rest.method !== undefined)
|
|
305
|
+
assertMethod(rest.method);
|
|
261
306
|
// Validate the raw value before `from` treats `Authorization` as the omitted default: a
|
|
262
307
|
// received challenge may only select `Payment-Authorization`.
|
|
263
308
|
if (header !== undefined && !isPaymentAuthorizationHeader(header))
|
|
@@ -269,9 +314,35 @@ export function deserialize(value, options) {
|
|
|
269
314
|
}, options);
|
|
270
315
|
// Keep the spelling the server sent: the client echoes it unchanged, and the server's challenge
|
|
271
316
|
// ID may bind that exact spelling.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
317
|
+
const parsed = (header === undefined ? challenge : { ...challenge, header });
|
|
318
|
+
// Servers before quoted-pair parsing escaped characters above U+00FF as `\\uXXXX`. Quoted-pair
|
|
319
|
+
// reads those as different text than the server bound into the challenge ID, so the client must
|
|
320
|
+
// not pay such a challenge. `description` and unknown params are not bound.
|
|
321
|
+
if ([...legacyEscaped].some((key) => boundParams.has(key)))
|
|
322
|
+
parsed[legacyUnicodeEscape] = true;
|
|
323
|
+
return parsed;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Returns whether a challenge parsed from a header escaped an HMAC-bound parameter as `\\uXXXX`,
|
|
327
|
+
* as servers did before quoted-pair parsing. Paying it would fail verification after the payment
|
|
328
|
+
* may already have moved funds.
|
|
329
|
+
*
|
|
330
|
+
* @internal
|
|
331
|
+
*/
|
|
332
|
+
export function isLegacyUnicodeEscaped(challenge) {
|
|
333
|
+
return Boolean(challenge &&
|
|
334
|
+
typeof challenge === 'object' &&
|
|
335
|
+
challenge[legacyUnicodeEscape]);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Throws {@link Errors.LegacyUnicodeEscapedChallengeError} for a challenge that
|
|
339
|
+
* {@link isLegacyUnicodeEscaped} reports, before a credential is created for it.
|
|
340
|
+
*
|
|
341
|
+
* @internal
|
|
342
|
+
*/
|
|
343
|
+
export function assertNotLegacyUnicodeEscaped(challenge) {
|
|
344
|
+
if (isLegacyUnicodeEscaped(challenge))
|
|
345
|
+
throw new Errors.LegacyUnicodeEscapedChallengeError();
|
|
275
346
|
}
|
|
276
347
|
/** @internal Extracts the `Payment` scheme from a WWW-Authenticate value that may contain multiple schemes. */
|
|
277
348
|
function extractPaymentAuthParams(header) {
|
|
@@ -285,7 +356,7 @@ function extractPaymentAuthParams(header) {
|
|
|
285
356
|
return header.slice(paramsStart);
|
|
286
357
|
}
|
|
287
358
|
/** @internal Parses auth-params with support for escaped quoted-string values. */
|
|
288
|
-
function parseAuthParams(input) {
|
|
359
|
+
function parseAuthParams(input, legacyEscaped) {
|
|
289
360
|
const result = Object.create(null);
|
|
290
361
|
let i = 0;
|
|
291
362
|
while (i < input.length) {
|
|
@@ -307,8 +378,10 @@ function parseAuthParams(input) {
|
|
|
307
378
|
i++;
|
|
308
379
|
while (i < input.length && /\s/.test(input[i] ?? ''))
|
|
309
380
|
i++;
|
|
310
|
-
const [value, nextIndex] = readAuthParamValue(input, i);
|
|
381
|
+
const [value, nextIndex, legacy] = readAuthParamValue(input, i);
|
|
311
382
|
i = nextIndex;
|
|
383
|
+
if (legacy)
|
|
384
|
+
legacyEscaped?.add(key);
|
|
312
385
|
if (key in result)
|
|
313
386
|
throw new Error(`Duplicate parameter: ${key}`);
|
|
314
387
|
result[key] = value;
|
|
@@ -328,23 +401,19 @@ function readAuthParamValue(input, start) {
|
|
|
328
401
|
function readQuotedAuthParamValue(input, start) {
|
|
329
402
|
let i = start;
|
|
330
403
|
let escaped = false;
|
|
404
|
+
let legacyEscape = false;
|
|
331
405
|
let segmentStart = start;
|
|
332
406
|
let parts;
|
|
333
407
|
while (i < input.length) {
|
|
334
408
|
const char = input[i];
|
|
335
409
|
i++;
|
|
336
410
|
if (escaped) {
|
|
411
|
+
// quoted-pair (RFC 9110): drop the backslash and keep the next character
|
|
412
|
+
// as is, so `\\u2014` is the text `u2014`, not an escape.
|
|
413
|
+
if (char === 'u' && /^[0-9a-fA-F]{4}/.test(input.slice(i, i + 4)))
|
|
414
|
+
legacyEscape = true;
|
|
337
415
|
parts ??= [];
|
|
338
|
-
|
|
339
|
-
// always double raw backslashes, so a bare `\\u` only ever comes from
|
|
340
|
-
// the unicode escape in `authParam`.
|
|
341
|
-
const hex = char === 'u' ? input.slice(i, i + 4) : undefined;
|
|
342
|
-
if (hex && /^[0-9A-Fa-f]{4}$/.test(hex)) {
|
|
343
|
-
parts.push(String.fromCharCode(Number.parseInt(hex, 16)));
|
|
344
|
-
i += 4;
|
|
345
|
-
}
|
|
346
|
-
else
|
|
347
|
-
parts.push(char);
|
|
416
|
+
parts.push(char);
|
|
348
417
|
segmentStart = i;
|
|
349
418
|
escaped = false;
|
|
350
419
|
continue;
|
|
@@ -360,7 +429,7 @@ function readQuotedAuthParamValue(input, start) {
|
|
|
360
429
|
const value = parts
|
|
361
430
|
? [...parts, input.slice(segmentStart, i - 1)].join('')
|
|
362
431
|
: input.slice(start, i - 1);
|
|
363
|
-
return [value, i];
|
|
432
|
+
return [value, i, legacyEscape];
|
|
364
433
|
}
|
|
365
434
|
}
|
|
366
435
|
throw new Error('Unterminated quoted-string.');
|
|
@@ -524,6 +593,10 @@ export function deserializeList(value, options) {
|
|
|
524
593
|
// but must not stop the client from paying another challenge.
|
|
525
594
|
if (error instanceof UnsupportedCredentialHeaderError)
|
|
526
595
|
return [];
|
|
596
|
+
// An offer for a method id outside the grammar can't be paid, but must not stop the
|
|
597
|
+
// client from paying another offer in the same header.
|
|
598
|
+
if (error instanceof InvalidMethodError)
|
|
599
|
+
return [];
|
|
527
600
|
throw error;
|
|
528
601
|
}
|
|
529
602
|
});
|
package/dist/Errors.d.ts
CHANGED
|
@@ -303,6 +303,74 @@ export declare namespace PaymentSimulationError {
|
|
|
303
303
|
sender?: `0x${string}` | undefined;
|
|
304
304
|
};
|
|
305
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* The server escaped an HMAC-bound challenge parameter (such as `realm`) as `\\uXXXX`, as mppx
|
|
308
|
+
* servers before quoted-pair parsing did for characters above U+00FF. The client reads that
|
|
309
|
+
* escape as different text than the server bound into the challenge ID, so the server would
|
|
310
|
+
* reject the credential, possibly after the payment moved funds. The client stops before it
|
|
311
|
+
* creates, signs or broadcasts anything.
|
|
312
|
+
*
|
|
313
|
+
* Upgrade the server, or keep bound parameters within Latin-1.
|
|
314
|
+
*/
|
|
315
|
+
export declare class LegacyUnicodeEscapedChallengeError extends Error {
|
|
316
|
+
readonly name = "LegacyUnicodeEscapedChallengeError";
|
|
317
|
+
constructor();
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* A `tempo/session` client would open a channel whose vouchers a TIP-1166 configurable account
|
|
321
|
+
* signs, but the server's challenge does not advertise `configurableVouchers`, so the server
|
|
322
|
+
* would reject those vouchers. The client stops before it locks a deposit.
|
|
323
|
+
*
|
|
324
|
+
* Pay with a primitive account or access key, or ask the server operator to enable
|
|
325
|
+
* `configurableVouchers` once the chain runs T15.
|
|
326
|
+
*/
|
|
327
|
+
export declare class ConfigurableVouchersUnsupportedError extends Error {
|
|
328
|
+
readonly name = "ConfigurableVouchersUnsupportedError";
|
|
329
|
+
/** Configurable account that would sign the channel's vouchers. */
|
|
330
|
+
readonly signer: `0x${string}`;
|
|
331
|
+
constructor(options: ConfigurableVouchersUnsupportedError.Options);
|
|
332
|
+
}
|
|
333
|
+
export declare namespace ConfigurableVouchersUnsupportedError {
|
|
334
|
+
type Options = {
|
|
335
|
+
/** Configurable account that would sign the channel's vouchers. */
|
|
336
|
+
signer: `0x${string}`;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* A `tempo/session` top-up would revert because the channel signer's TIP-1166 config changed
|
|
341
|
+
* since the channel opened, so the client did not sign it.
|
|
342
|
+
*
|
|
343
|
+
* The escrow reverts a nonzero top-up with `SignerConfigChanged(signer)` when the config
|
|
344
|
+
* commitment recorded at open differs from the signer's current one, or with
|
|
345
|
+
* `RootKeyRetired(signer)` when the signer had no commitment at open and has one now. Vouchers
|
|
346
|
+
* already signed for the channel still settle, since the escrow checks them against the commitment
|
|
347
|
+
* recorded at open, but the channel takes no new funds: close it and open a new one. The
|
|
348
|
+
* simulation error is the `cause`.
|
|
349
|
+
*/
|
|
350
|
+
export declare class SignerConfigChangedError extends Error {
|
|
351
|
+
readonly name = "SignerConfigChangedError";
|
|
352
|
+
/** Channel whose signer config changed. */
|
|
353
|
+
readonly channelId: `0x${string}`;
|
|
354
|
+
/** Escrow error that reverted the top-up. */
|
|
355
|
+
readonly reason: SignerConfigChangedError.Reason;
|
|
356
|
+
/** Voucher signer of the channel. */
|
|
357
|
+
readonly signer: `0x${string}`;
|
|
358
|
+
constructor(options: SignerConfigChangedError.Options);
|
|
359
|
+
}
|
|
360
|
+
export declare namespace SignerConfigChangedError {
|
|
361
|
+
/** `SignerConfigChanged`: the commitment recorded at open differs. `RootKeyRetired`: the signer had none at open. */
|
|
362
|
+
type Reason = 'SignerConfigChanged' | 'RootKeyRetired';
|
|
363
|
+
type Options = {
|
|
364
|
+
/** The simulation error. */
|
|
365
|
+
cause?: unknown;
|
|
366
|
+
/** Channel whose signer config changed. */
|
|
367
|
+
channelId: `0x${string}`;
|
|
368
|
+
/** Escrow error that reverted the top-up. */
|
|
369
|
+
reason: Reason;
|
|
370
|
+
/** Voucher signer of the channel. */
|
|
371
|
+
signer: `0x${string}`;
|
|
372
|
+
};
|
|
373
|
+
}
|
|
306
374
|
/**
|
|
307
375
|
* The access key that signs a Tempo payment has less spending limit left than the payment needs,
|
|
308
376
|
* so the client did not sign it.
|
package/dist/Errors.js
CHANGED
|
@@ -261,6 +261,69 @@ export class PaymentSimulationError extends Error {
|
|
|
261
261
|
Object.defineProperty(this, 'cause', { configurable: true, value: cause, writable: true });
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* The server escaped an HMAC-bound challenge parameter (such as `realm`) as `\\uXXXX`, as mppx
|
|
266
|
+
* servers before quoted-pair parsing did for characters above U+00FF. The client reads that
|
|
267
|
+
* escape as different text than the server bound into the challenge ID, so the server would
|
|
268
|
+
* reject the credential, possibly after the payment moved funds. The client stops before it
|
|
269
|
+
* creates, signs or broadcasts anything.
|
|
270
|
+
*
|
|
271
|
+
* Upgrade the server, or keep bound parameters within Latin-1.
|
|
272
|
+
*/
|
|
273
|
+
export class LegacyUnicodeEscapedChallengeError extends Error {
|
|
274
|
+
name = 'LegacyUnicodeEscapedChallengeError';
|
|
275
|
+
constructor() {
|
|
276
|
+
super('Legacy unicode-escaped challenge: the server escaped a bound parameter as \\uXXXX; upgrade the server.');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* A `tempo/session` client would open a channel whose vouchers a TIP-1166 configurable account
|
|
281
|
+
* signs, but the server's challenge does not advertise `configurableVouchers`, so the server
|
|
282
|
+
* would reject those vouchers. The client stops before it locks a deposit.
|
|
283
|
+
*
|
|
284
|
+
* Pay with a primitive account or access key, or ask the server operator to enable
|
|
285
|
+
* `configurableVouchers` once the chain runs T15.
|
|
286
|
+
*/
|
|
287
|
+
export class ConfigurableVouchersUnsupportedError extends Error {
|
|
288
|
+
name = 'ConfigurableVouchersUnsupportedError';
|
|
289
|
+
/** Configurable account that would sign the channel's vouchers. */
|
|
290
|
+
signer;
|
|
291
|
+
constructor(options) {
|
|
292
|
+
const { signer } = options;
|
|
293
|
+
super(`Configurable account ${signer} signs vouchers with TIP-1166 configurable account signatures, but the session challenge does not advertise \`configurableVouchers\`, so the channel was not opened.`);
|
|
294
|
+
this.signer = signer;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* A `tempo/session` top-up would revert because the channel signer's TIP-1166 config changed
|
|
299
|
+
* since the channel opened, so the client did not sign it.
|
|
300
|
+
*
|
|
301
|
+
* The escrow reverts a nonzero top-up with `SignerConfigChanged(signer)` when the config
|
|
302
|
+
* commitment recorded at open differs from the signer's current one, or with
|
|
303
|
+
* `RootKeyRetired(signer)` when the signer had no commitment at open and has one now. Vouchers
|
|
304
|
+
* already signed for the channel still settle, since the escrow checks them against the commitment
|
|
305
|
+
* recorded at open, but the channel takes no new funds: close it and open a new one. The
|
|
306
|
+
* simulation error is the `cause`.
|
|
307
|
+
*/
|
|
308
|
+
export class SignerConfigChangedError extends Error {
|
|
309
|
+
name = 'SignerConfigChangedError';
|
|
310
|
+
/** Channel whose signer config changed. */
|
|
311
|
+
channelId;
|
|
312
|
+
/** Escrow error that reverted the top-up. */
|
|
313
|
+
reason;
|
|
314
|
+
/** Voucher signer of the channel. */
|
|
315
|
+
signer;
|
|
316
|
+
constructor(options) {
|
|
317
|
+
const { cause, channelId, reason, signer } = options;
|
|
318
|
+
super(`Signer ${signer} of channel ${channelId} changed its account config since the channel opened, so the top-up was not signed. Close the channel and open a new one.`);
|
|
319
|
+
this.channelId = channelId;
|
|
320
|
+
this.reason = reason;
|
|
321
|
+
this.signer = signer;
|
|
322
|
+
// Defined manually (non-enumerable, like native `cause`) so consumers on pre-ES2022 libs still typecheck.
|
|
323
|
+
if (cause !== undefined)
|
|
324
|
+
Object.defineProperty(this, 'cause', { configurable: true, value: cause, writable: true });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
264
327
|
/**
|
|
265
328
|
* The access key that signs a Tempo payment has less spending limit left than the payment needs,
|
|
266
329
|
* so the client did not sign it.
|
package/dist/Html.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Config, type Data, type Text, type Theme, vars } from './internal/html/config.js';
|
|
1
2
|
import type * as Method from './Method.js';
|
|
2
|
-
import { type Config, type Data, type Text, type Theme, vars } from './server/internal/html/config.js';
|
|
3
3
|
export declare function init<method extends Method.Method = Method.Method, config extends Record<string, unknown> = {}>(methodName: method['name']): Context<method, config>;
|
|
4
4
|
export type Context<method extends Method.Method = Method.Method, config extends Record<string, unknown> = {}> = Data<method, config> & {
|
|
5
5
|
error: (message?: string | null | undefined) => void;
|
package/dist/Html.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Json } from 'ox';
|
|
2
|
-
import { attrs, ids, vars, } from './
|
|
3
|
-
import { submitCredential } from './
|
|
2
|
+
import { attrs, ids, vars, } from './internal/html/config.js';
|
|
3
|
+
import { submitCredential } from './internal/html/serviceWorker.client.js';
|
|
4
4
|
export function init(methodName) {
|
|
5
5
|
const element = document.getElementById(ids.data);
|
|
6
6
|
const dataMap = Json.parse(element.textContent);
|
package/dist/Method.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Challenge from './Challenge.js';
|
|
2
2
|
import * as Credential from './Credential.js';
|
|
3
|
+
import type * as Html from './internal/html/config.js';
|
|
3
4
|
import type { DeepReadonly, ExactPartial, LooseOmit, MaybePromise } from './internal/types.js';
|
|
4
5
|
import type * as Receipt from './Receipt.js';
|
|
5
|
-
import type * as Html from './server/internal/html/config.js';
|
|
6
6
|
import type * as Transport from './server/Transport.js';
|
|
7
7
|
import type * as z from './zod.js';
|
|
8
8
|
/**
|
package/dist/Method.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Challenge from './Challenge.js';
|
|
1
2
|
import * as Credential from './Credential.js';
|
|
2
3
|
import * as Errors from './Errors.js';
|
|
3
4
|
import * as CredentialExpiry from './internal/CredentialExpiry.js';
|
|
@@ -125,7 +126,11 @@ export function toClient(method, options) {
|
|
|
125
126
|
...method,
|
|
126
127
|
canHandleChallenge,
|
|
127
128
|
context,
|
|
128
|
-
|
|
129
|
+
// Refuse a legacy `\uXXXX`-escaped challenge before the method signs or broadcasts anything.
|
|
130
|
+
async createCredential(parameters) {
|
|
131
|
+
Challenge.assertNotLegacyUnicodeEscaped(parameters.challenge);
|
|
132
|
+
return createCredential.call(this, parameters);
|
|
133
|
+
},
|
|
129
134
|
};
|
|
130
135
|
}
|
|
131
136
|
/**
|