mppx 0.18.0 → 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 (90) hide show
  1. package/CHANGELOG.md +15 -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 +135 -135
  7. package/dist/cli/plugins/index.js +12 -12
  8. package/dist/cli/plugins/tempo.js +13 -1
  9. package/dist/client/internal/Fetch.d.ts +5 -0
  10. package/dist/client/internal/Fetch.js +7 -0
  11. package/dist/cloudflare/ChannelStore.d.ts +1 -2
  12. package/dist/cloudflare/ChannelStore.js +14 -20
  13. package/dist/cloudflare/Channels.d.ts +20 -2
  14. package/dist/cloudflare/Channels.js +47 -4
  15. package/dist/cloudflare/index.d.ts +1 -1
  16. package/dist/cloudflare/index.js +1 -1
  17. package/dist/discovery/Discovery.d.ts +116 -9
  18. package/dist/discovery/Discovery.js +169 -0
  19. package/dist/evm/server/Charge.js +2 -3
  20. package/dist/evm/server/Methods.d.ts +1 -1
  21. package/dist/evm/server/Methods.js +3 -2
  22. package/dist/extensions/identity/email-otp/client/index.js +4 -4
  23. package/dist/extensions/identity/index.d.ts +4 -0
  24. package/dist/extensions/identity/index.js +4 -0
  25. package/dist/extensions/identity/link/Constants.d.ts +102 -0
  26. package/dist/extensions/identity/link/Constants.js +16 -0
  27. package/dist/extensions/identity/link/client/index.d.ts +80 -0
  28. package/dist/extensions/identity/link/client/index.js +211 -0
  29. package/dist/extensions/identity/link/index.d.ts +12 -0
  30. package/dist/extensions/identity/link/index.js +12 -0
  31. package/dist/extensions/identity/link/server/index.d.ts +124 -0
  32. package/dist/extensions/identity/link/server/index.js +518 -0
  33. package/dist/extensions/identity/persona/Constants.d.ts +24 -0
  34. package/dist/extensions/identity/persona/Constants.js +24 -0
  35. package/dist/extensions/identity/persona/Did.d.ts +24 -0
  36. package/dist/extensions/identity/persona/Did.js +24 -0
  37. package/dist/extensions/identity/persona/Types.d.ts +21 -0
  38. package/dist/extensions/identity/persona/Types.js +2 -0
  39. package/dist/extensions/identity/persona/index.d.ts +10 -0
  40. package/dist/extensions/identity/persona/index.js +9 -0
  41. package/dist/extensions/identity/persona/server/index.d.ts +152 -0
  42. package/dist/extensions/identity/persona/server/index.js +263 -0
  43. package/dist/identity/Headers.d.ts +6 -1
  44. package/dist/identity/Headers.js +6 -1
  45. package/dist/identity/Server.js +2 -0
  46. package/dist/identity/Types.d.ts +5 -0
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +1 -0
  49. package/dist/internal/version.d.ts +2 -2
  50. package/dist/internal/version.js +1 -1
  51. package/dist/proxy/internal/Headers.js +4 -4
  52. package/dist/server/Mppx.js +5 -2
  53. package/dist/stripe/server/internal/html.gen.js +1 -1
  54. package/dist/tempo/client/Charge.d.ts +11 -8
  55. package/dist/tempo/client/Charge.js +53 -6
  56. package/dist/tempo/index.d.ts +4 -0
  57. package/dist/tempo/index.js +4 -0
  58. package/dist/tempo/internal/auto-swap.d.ts +6 -5
  59. package/dist/tempo/internal/auto-swap.js +17 -2
  60. package/dist/tempo/internal/currencies.d.ts +5 -4
  61. package/dist/tempo/internal/currencies.js +13 -9
  62. package/dist/tempo/internal/defaults.d.ts +7 -0
  63. package/dist/tempo/internal/defaults.js +7 -0
  64. package/dist/tempo/internal/fee-payer.js +8 -2
  65. package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
  66. package/dist/tempo/internal/machine-token-charge.js +82 -1
  67. package/dist/tempo/server/Charge.js +59 -2
  68. package/dist/tempo/server/Methods.d.ts +1 -1
  69. package/dist/tempo/server/internal/html.gen.js +1 -1
  70. package/dist/tempo/server/internal/transport.d.ts +1 -1
  71. package/dist/tempo/server/internal/transport.js +9 -16
  72. package/dist/tempo/session/client/CredentialState.js +31 -0
  73. package/dist/tempo/session/client/Session.d.ts +12 -6
  74. package/dist/tempo/session/client/Session.js +64 -18
  75. package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
  76. package/dist/tempo/session/server/ChannelStore.js +58 -8
  77. package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
  78. package/dist/tempo/session/server/CloseSupervisor.js +110 -12
  79. package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
  80. package/dist/tempo/session/server/CredentialVerification.js +6 -32
  81. package/dist/tempo/session/server/Session.js +6 -3
  82. package/dist/tempo/session/server/Settlement.d.ts +7 -0
  83. package/dist/tempo/session/server/Settlement.js +36 -6
  84. package/dist/tempo/session/server/Sse.d.ts +2 -0
  85. package/dist/tempo/session/server/Sse.js +12 -12
  86. package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
  87. package/dist/tempo/subscription/KeyAuthorization.js +1 -1
  88. package/dist/x402/Assets.d.ts +14 -5
  89. package/dist/x402/Assets.js +11 -16
  90. package/package.json +15 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # mppx
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 7663d93: Fixed Cloudflare settlement recovery for vouchers larger than recorded usage, capturing only the amount owed. Added a settlement backfill for channels left unscheduled before upgrading.
8
+ - 2a00add: Fixed automatic session settlement retries and preserved prepaid stream delivery during channel closure. Fixed mixed-case channel IDs in settlement backfills.
9
+ - e86c670: Added `listOperations` to `mppx/discovery`, which lists a discovery document's operations with typed offers and JSON request schemas. Typed the offers `PaymentInfo` returns.
10
+ - 066a75b: Added `mppx/extensions/identity/link`: server verifiers and client provers for Link agent identity attestations and Link-signed claims, such as a verified email. Added `Identity.Verifier.authorization`, which makes a route refuse a server without `requiresAuth: true`, and stopped proxies from forwarding `Identity-Presentation` headers and upstream identity challenges.
11
+ - 4071a6c: Added MACH onramp links to insufficient-balance errors. `Tempo.machineTokenFundingUrl` builds the Tempo Wallet link that buys MACH, and `PaymentError` gained an optional `fundingUrl`, serialized as a Problem Details extension member. On Tempo mainnet, the `tempo.charge` client now throws `InsufficientBalanceError` with the link when a MACH-enabled charge can't be paid from MACH or the charge currency, the session client does the same for a MACH channel deposit, servers link MACH payments rejected for a low MACH balance, and the `mppx` CLI treats a MACH-enabled charge as payable from a MACH balance.
12
+ - ee48ef6: Removed the package size limits from the package check; it still reports the sizes.
13
+ - 40b9535: Prevented automatic payments during email OTP requests through identity-wrapped fetch clients. Added `Fetch.withoutPayment` to explicitly disable payments for a request.
14
+ - dd571b3: Added `mppx/extensions/identity/persona`: `Persona.Server.create` starts Persona inquiries and returns a payment check and a request-stage verifier that require an approved inquiry, with an onboarding link on rejection and an optional approval cache. `Persona.Server.verifyWallet` links a wallet to a person before KYC, and `Persona.did` builds a wallet's reference ID.
15
+ - 6e32317: Fixed composed subscription routes retaining request-derived dispatch state and accepting overlapping identity policies.
16
+ - 75aee4b: Added the `Currency` module and accepted `viem/tokens` tokens, chain-indexed (`ousd`) or resolved to one chain (`ousd(4217)`), everywhere a currency is configured: Tempo charge and session client `currencies`, `autoSwap.tokenIn`, Tempo server `currencies`, and EVM and x402 `currencies`, with token decimals used for `maxAmount`, `maxDeposit` and `topUpAmount`.
17
+
3
18
  ## 0.18.0
4
19
 
5
20
  ### Minor Changes
@@ -0,0 +1,59 @@
1
+ import type { Address, ResolvedToken } from 'viem';
2
+ import type { Token } from 'viem/tokens';
3
+ /**
4
+ * A currency accepted anywhere mppx takes one: a token address, a chain-indexed token from
5
+ * `viem/tokens` (such as `ousd`), or a token resolved to one chain (such as `ousd(4217)`).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { ousd, usdc } from 'viem/tokens'
10
+ *
11
+ * const currencies = [ousd, usdc(8453), '0x20c0000000000000000000000000000000000000']
12
+ * ```
13
+ */
14
+ export type Currency = Address | Token | ResolvedToken;
15
+ /** A currency resolved to one chain. `decimals` is `undefined` for an address configured without decimals. */
16
+ export type Resolved = Omit<ResolvedToken, 'decimals'> & {
17
+ decimals: number | undefined;
18
+ };
19
+ /** Returns true when a value is a chain-indexed token from `viem/tokens`. */
20
+ export declare function isToken(value: unknown): value is Token;
21
+ /** Returns true when a value is a token resolved to one chain, such as `ousd(4217)`. */
22
+ export declare function isResolvedToken(value: unknown): value is ResolvedToken;
23
+ /** Returns the chain a currency is bound to: a resolved token's `chainId`, otherwise `undefined`. */
24
+ export declare function chainIdOf(currency: Currency): number | undefined;
25
+ /**
26
+ * Resolves a currency for `chainId`: a token by its addresses, a resolved token only on its own
27
+ * chain, and an address on any chain with `decimals`. Returns `undefined` when the currency has no
28
+ * address on `chainId`.
29
+ */
30
+ export declare function resolve(currency: Currency, options: resolve.Options): Resolved | undefined;
31
+ export declare namespace resolve {
32
+ type Options = {
33
+ /** Chain to resolve the currency for. */
34
+ chainId: number;
35
+ /** Decimals of an address currency. Tokens carry their own. */
36
+ decimals?: number | undefined;
37
+ };
38
+ }
39
+ /**
40
+ * Returns the first currency in `currencies` that is `address`, compared case-insensitively, with
41
+ * its decimals: an address as is, and a token on `chainId`, or on any chain it lists when
42
+ * `chainId` is omitted.
43
+ */
44
+ export declare function find(currencies: readonly Currency[], address: string, options?: find.Options): find.ReturnType | undefined;
45
+ export declare namespace find {
46
+ type Options = {
47
+ /** Chain the address is on. When omitted, tokens match on any chain they list. */
48
+ chainId?: number | undefined;
49
+ /** Decimals of an address currency. Tokens carry their own. */
50
+ decimals?: number | undefined;
51
+ };
52
+ type ReturnType = {
53
+ /** The matching currency. */
54
+ currency: Currency;
55
+ /** Its decimals: the token's, or the configured `decimals` for an address. */
56
+ decimals: number | undefined;
57
+ };
58
+ }
59
+ //# sourceMappingURL=Currency.d.ts.map
@@ -0,0 +1,60 @@
1
+ /** Returns true when a value is a chain-indexed token from `viem/tokens`. */
2
+ export function isToken(value) {
3
+ return (typeof value === 'function' &&
4
+ typeof value.addresses === 'object' &&
5
+ typeof value.decimals === 'number');
6
+ }
7
+ /** Returns true when a value is a token resolved to one chain, such as `ousd(4217)`. */
8
+ export function isResolvedToken(value) {
9
+ if (typeof value !== 'object' || value === null)
10
+ return false;
11
+ const { address, chainId, decimals } = value;
12
+ return typeof address === 'string' && typeof chainId === 'number' && typeof decimals === 'number';
13
+ }
14
+ /** Returns the chain a currency is bound to: a resolved token's `chainId`, otherwise `undefined`. */
15
+ export function chainIdOf(currency) {
16
+ return isResolvedToken(currency) ? currency.chainId : undefined;
17
+ }
18
+ /**
19
+ * Resolves a currency for `chainId`: a token by its addresses, a resolved token only on its own
20
+ * chain, and an address on any chain with `decimals`. Returns `undefined` when the currency has no
21
+ * address on `chainId`.
22
+ */
23
+ export function resolve(currency, options) {
24
+ const { chainId, decimals } = options;
25
+ if (typeof currency === 'string')
26
+ return { address: currency, chainId, decimals };
27
+ if (isToken(currency)) {
28
+ if (!currency.addresses[chainId])
29
+ return undefined;
30
+ return currency(chainId);
31
+ }
32
+ if (currency.chainId !== chainId)
33
+ return undefined;
34
+ return currency;
35
+ }
36
+ /**
37
+ * Returns the first currency in `currencies` that is `address`, compared case-insensitively, with
38
+ * its decimals: an address as is, and a token on `chainId`, or on any chain it lists when
39
+ * `chainId` is omitted.
40
+ */
41
+ export function find(currencies, address, options = {}) {
42
+ const { chainId, decimals } = options;
43
+ const matches = (value) => value.toLowerCase() === address.toLowerCase();
44
+ for (const currency of currencies) {
45
+ if (typeof currency === 'string') {
46
+ if (matches(currency))
47
+ return { currency, decimals };
48
+ continue;
49
+ }
50
+ const candidates = chainId !== undefined
51
+ ? [resolve(currency, { chainId })]
52
+ : isToken(currency)
53
+ ? Object.keys(currency.addresses).map((id) => resolve(currency, { chainId: Number(id) }))
54
+ : [currency];
55
+ if (candidates.some((candidate) => candidate && matches(candidate.address)))
56
+ return { currency, decimals: currency.decimals };
57
+ }
58
+ return undefined;
59
+ }
60
+ //# sourceMappingURL=Currency.js.map
package/dist/Errors.d.ts CHANGED
@@ -19,6 +19,11 @@ export declare abstract class PaymentError extends Error {
19
19
  readonly status: number;
20
20
  /** Actionable hint for resolving the error (RFC 9457 extension member). */
21
21
  readonly hint: string | undefined;
22
+ /**
23
+ * Page where the payer can get the funds this payment needs, such as the MACH onramp
24
+ * (RFC 9457 extension member).
25
+ */
26
+ readonly fundingUrl: string | undefined;
22
27
  protected constructor(message: string, options?: PaymentError.Options);
23
28
  /** Converts the error to RFC 9457 Problem Details format. */
24
29
  toProblemDetails(challengeId?: string): PaymentError.ProblemDetails;
@@ -28,6 +33,8 @@ export declare namespace PaymentError {
28
33
  /** Underlying error. Never serialized into Problem Details. */
29
34
  cause?: unknown;
30
35
  details?: Record<string, unknown> | undefined;
36
+ /** Page where the payer can get the funds this payment needs. */
37
+ fundingUrl?: string | undefined;
31
38
  };
32
39
  type ProblemDetails = {
33
40
  /** RFC 9457 Problem Details type URI. */
@@ -42,6 +49,8 @@ export declare namespace PaymentError {
42
49
  details?: Readonly<Record<string, unknown>>;
43
50
  /** Actionable hint for resolving the error (RFC 9457 extension member). */
44
51
  hint?: string;
52
+ /** Page where the payer can get the funds this payment needs (RFC 9457 extension member). */
53
+ fundingUrl?: string;
45
54
  /** Associated challenge ID, if applicable. */
46
55
  challengeId?: string;
47
56
  };
@@ -94,6 +103,8 @@ export declare namespace VerificationFailedError {
94
103
  type Options = {
95
104
  /** Safe method-specific diagnostic context. */
96
105
  details?: Record<string, unknown> | undefined;
106
+ /** Page where the payer can get the funds the payment lacked. */
107
+ fundingUrl?: string | undefined;
97
108
  /** Reason verification failed (e.g., "invalid signature", "insufficient amount"). */
98
109
  reason?: string;
99
110
  };
@@ -381,6 +392,8 @@ export declare class InsufficientBalanceError extends PaymentError {
381
392
  }
382
393
  export declare namespace InsufficientBalanceError {
383
394
  type Options = {
395
+ /** Page where the payer can get the funds, such as the MACH onramp. */
396
+ fundingUrl?: string | undefined;
384
397
  /** Reason for insufficient balance. */
385
398
  reason?: string;
386
399
  };
package/dist/Errors.js CHANGED
@@ -4,6 +4,10 @@ export const Hints = {
4
4
  malformedCredential: 'Use a supported wallet to construct valid credentials for one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md',
5
5
  methodUnsupported: 'Use a supported wallet to pay for this resource using one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md',
6
6
  };
7
+ /** Appends where to get funds to an error message. */
8
+ function withFundingUrl(message, fundingUrl) {
9
+ return fundingUrl ? `${message} Add funds at ${fundingUrl}` : message;
10
+ }
7
11
  /**
8
12
  * Base class for all payment-related errors.
9
13
  */
@@ -14,9 +18,15 @@ export class PaymentError extends Error {
14
18
  status = 402;
15
19
  /** Actionable hint for resolving the error (RFC 9457 extension member). */
16
20
  hint;
21
+ /**
22
+ * Page where the payer can get the funds this payment needs, such as the MACH onramp
23
+ * (RFC 9457 extension member).
24
+ */
25
+ fundingUrl;
17
26
  constructor(message, options = {}) {
18
27
  super(message);
19
28
  this.details = options.details;
29
+ this.fundingUrl = options.fundingUrl;
20
30
  // Defined manually (non-enumerable, like native `cause`) so consumers on pre-ES2022 libs still typecheck.
21
31
  if (options.cause !== undefined)
22
32
  Object.defineProperty(this, 'cause', {
@@ -34,6 +44,7 @@ export class PaymentError extends Error {
34
44
  detail: this.message,
35
45
  ...(this.details && Object.keys(this.details).length > 0 && { details: this.details }),
36
46
  ...(this.hint && { hint: this.hint }),
47
+ ...(this.fundingUrl && { fundingUrl: this.fundingUrl }),
37
48
  ...(challengeId && { challengeId }),
38
49
  };
39
50
  }
@@ -75,10 +86,8 @@ export class VerificationFailedError extends PaymentError {
75
86
  title = 'Verification Failed';
76
87
  type = 'https://paymentauth.org/problems/verification-failed';
77
88
  constructor(options = {}) {
78
- const { details, reason } = options;
79
- super(reason ? `Payment verification failed: ${reason}.` : 'Payment verification failed.', {
80
- details,
81
- });
89
+ const { details, fundingUrl, reason } = options;
90
+ super(withFundingUrl(reason ? `Payment verification failed: ${reason}.` : 'Payment verification failed.', fundingUrl), { details, fundingUrl });
82
91
  }
83
92
  }
84
93
  /**
@@ -319,8 +328,8 @@ export class InsufficientBalanceError extends PaymentError {
319
328
  status = 402;
320
329
  type = 'https://paymentauth.org/problems/session/insufficient-balance';
321
330
  constructor(options = {}) {
322
- const { reason } = options;
323
- super(reason ? `Insufficient balance: ${reason}.` : 'Insufficient balance.');
331
+ const { fundingUrl, reason } = options;
332
+ super(withFundingUrl(reason ? `Insufficient balance: ${reason}.` : 'Insufficient balance.', fundingUrl), { fundingUrl });
324
333
  }
325
334
  }
326
335
  /**