mppx 0.17.6 → 0.18.0

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 (72) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cli/cli.js +139 -139
  3. package/dist/cli/plugins/index.js +6 -6
  4. package/dist/client/Mppx.js +13 -4
  5. package/dist/client/internal/Fetch.js +9 -5
  6. package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.d.ts +4 -1
  7. package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.js +4 -1
  8. package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.d.ts +5 -5
  9. package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.js +1 -1
  10. package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts} +40 -26
  11. package/dist/extensions/identity/{email-otp/internal/Attestation.js → attestation/Token.js} +18 -3
  12. package/dist/extensions/identity/{email-otp/internal → attestation}/Types.d.ts +14 -14
  13. package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
  14. package/dist/extensions/identity/attestation/client/index.js +273 -0
  15. package/dist/extensions/identity/attestation/index.d.ts +20 -0
  16. package/dist/extensions/identity/attestation/index.js +18 -0
  17. package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
  18. package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
  19. package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
  20. package/dist/extensions/identity/attestation/server/index.js +119 -0
  21. package/dist/extensions/identity/email-otp/Constants.d.ts +5 -5
  22. package/dist/extensions/identity/email-otp/Constants.js +6 -5
  23. package/dist/extensions/identity/email-otp/Types.d.ts +4 -4
  24. package/dist/extensions/identity/email-otp/client/index.d.ts +22 -15
  25. package/dist/extensions/identity/email-otp/client/index.js +17 -5
  26. package/dist/extensions/identity/email-otp/index.d.ts +3 -8
  27. package/dist/extensions/identity/email-otp/index.js +3 -8
  28. package/dist/extensions/identity/email-otp/server/index.d.ts +16 -16
  29. package/dist/extensions/identity/email-otp/server/index.js +17 -14
  30. package/dist/extensions/identity/index.d.ts +2 -0
  31. package/dist/extensions/identity/index.js +2 -0
  32. package/dist/extensions/identity/internal/Verification.js +9 -5
  33. package/dist/identity/Callback.d.ts +24 -5
  34. package/dist/identity/Callback.js +35 -11
  35. package/dist/identity/Client.d.ts +78 -5
  36. package/dist/identity/Client.js +165 -48
  37. package/dist/identity/Headers.d.ts +16 -0
  38. package/dist/identity/Headers.js +19 -0
  39. package/dist/identity/Server.d.ts +159 -37
  40. package/dist/identity/Server.js +307 -138
  41. package/dist/identity/Status.d.ts +14 -0
  42. package/dist/identity/Status.js +19 -0
  43. package/dist/identity/Types.d.ts +161 -65
  44. package/dist/identity/index.d.ts +2 -0
  45. package/dist/identity/index.js +2 -0
  46. package/dist/identity/internal/Requirements.d.ts +28 -0
  47. package/dist/identity/internal/Requirements.js +78 -0
  48. package/dist/integrations/x402/Evm.d.ts +1 -0
  49. package/dist/internal/env.d.ts +14 -0
  50. package/dist/internal/env.js +38 -0
  51. package/dist/internal/version.d.ts +2 -2
  52. package/dist/internal/version.js +1 -1
  53. package/dist/proxy/internal/Headers.d.ts +1 -1
  54. package/dist/proxy/internal/Headers.js +7 -3
  55. package/dist/server/Mppx.d.ts +14 -6
  56. package/dist/server/Mppx.js +252 -148
  57. package/dist/server/internal/challengeMeta.d.ts +0 -6
  58. package/dist/server/internal/challengeMeta.js +3 -17
  59. package/dist/tempo/server/Charge.d.ts +14 -9
  60. package/dist/tempo/server/Charge.js +5 -1
  61. package/dist/tempo/server/Methods.js +4 -1
  62. package/dist/tempo/server/Subscription.d.ts +8 -0
  63. package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
  64. package/dist/tempo/server/internal/fallback-store.js +12 -3
  65. package/dist/tempo/server/internal/html.gen.js +1 -1
  66. package/dist/tempo/session/server/Session.d.ts +5 -1
  67. package/package.json +5 -1
  68. package/dist/extensions/identity/email-otp/internal/Prover.d.ts +0 -46
  69. package/dist/extensions/identity/email-otp/internal/Prover.js +0 -168
  70. package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +0 -56
  71. package/dist/extensions/identity/email-otp/internal/Verifier.js +0 -116
  72. /package/dist/extensions/identity/{email-otp/internal → attestation}/Types.js +0 -0
@@ -6,25 +6,11 @@ export function withNonce(meta) {
6
6
  // Ox uses runtime-specific secure randomness, including Node without global Web Crypto.
7
7
  return { ...meta, [nonceKey]: Secp256k1.randomPrivateKey() };
8
8
  }
9
- /** Reserved metadata key for the HMAC-bound identity nonce shared by every offer in one 402. */
10
- const identityKey = '_mppx_identity';
11
- /** Returns fresh randomness for an identity nonce. */
12
- export function createNonce() {
13
- return Secp256k1.randomPrivateKey();
14
- }
15
- /** Adds an identity nonce to challenge metadata. */
16
- export function withIdentity(meta, nonce) {
17
- if (nonce === undefined)
18
- return meta;
19
- return { ...meta, [identityKey]: nonce };
20
- }
21
- /** Reads the identity nonce from challenge metadata. */
22
- export function identity(meta) {
23
- return meta?.[identityKey];
24
- }
9
+ /** Issuance-only identity nonce of earlier mppx releases with payment-stage verifiers; still ignored. */
10
+ const legacyIdentityKey = '_mppx_identity';
25
11
  /** Removes issuance-only metadata when comparing stable route requirements. */
26
12
  export function routeMeta(meta) {
27
- const { [nonceKey]: _, [identityKey]: __, ...rest } = meta ?? {};
13
+ const { [nonceKey]: _, [legacyIdentityKey]: __, ...rest } = meta ?? {};
28
14
  return Object.keys(rest).length ? rest : undefined;
29
15
  }
30
16
  //# sourceMappingURL=challengeMeta.js.map
@@ -93,16 +93,21 @@ export declare namespace charge {
93
93
  /**
94
94
  * Store for charge replay protection.
95
95
  *
96
- * Non-zero charge flows default to an in-memory store if omitted. For
97
- * zero-dollar proof auth, replay prevention is enabled only when a store
98
- * is explicitly provided; otherwise proofs remain reusable until the
99
- * challenge expires.
100
- *
101
96
  * Replay protection requires a {@link Store.AtomicStore} so replay markers
102
- * can be written atomically.
97
+ * can be written atomically. Use a shared store, such as `Store.redis()`,
98
+ * `Store.upstash()`, `Store.postgres()` or `Store.durableObject()`, so
99
+ * consumed hashes and proofs are visible across all server instances.
103
100
  *
104
- * Use a shared store in multi-instance deployments so consumed hashes and
105
- * proofs are visible across all server instances.
101
+ * If omitted, this throws in production (`NODE_ENV=production`), on
102
+ * multi-instance platforms (such as Vercel, AWS Lambda, Netlify, Fly.io,
103
+ * Cloud Run, Render, Railway or Heroku) and on Cloudflare Workers. Elsewhere,
104
+ * such as local development and tests, it warns and falls back to an
105
+ * in-memory store. Pass `Store.memory()` explicitly to accept replay
106
+ * protection scoped to one instance.
107
+ *
108
+ * For zero-dollar proof auth, replay prevention is enabled only when a store
109
+ * is explicitly provided; otherwise proofs remain reusable until the
110
+ * challenge expires.
106
111
  */
107
112
  store?: Store.AtomicStore | undefined;
108
113
  /**
@@ -173,7 +178,7 @@ export declare namespace charge {
173
178
  maxInFlightReservations?: number | undefined;
174
179
  /** Maximum aggregate declared fee exposure. @default `feePayerPolicy.maxTotalFee * 10` */
175
180
  maxInFlightTotalFee?: bigint | undefined;
176
- /** Atomic store shared by every process using the sponsor. Defaults to `store`. */
181
+ /** Atomic store shared by every process using the sponsor. Defaults to `store`, under the same production rule. */
177
182
  store?: Store.AtomicStore | undefined;
178
183
  };
179
184
  /** Tempo API relay configuration for server-side charges. */
@@ -38,8 +38,12 @@ export function charge(parameters = {}) {
38
38
  if (configuredAllowedFeeTokens?.length === 0)
39
39
  throw new Error('`allowedFeeTokens` must contain at least one token.');
40
40
  const storeKeyPrefix = parameters.storeKeyPrefix ?? '';
41
+ // A relay validates and broadcasts credentials and enforces single use itself, so it never
42
+ // reads the local replay store and needs no shared one.
41
43
  const rawStore = (parameters.store ??
42
- fallbackStore('tempo.charge'));
44
+ (relay
45
+ ? Store.memory()
46
+ : fallbackStore('tempo.charge')));
43
47
  const store = Store.from(rawStore, { keyPrefix: storeKeyPrefix });
44
48
  const { maxInFlightReservations: legacyMaxInFlightReservations, maxInFlightTotalFee: legacyMaxInFlightTotalFee, ...transactionFeePayerPolicy } = feePayerPolicy ?? {};
45
49
  const sponsorBudgetConfig = sponsorBudget === false ? undefined : (sponsorBudget ?? {});
@@ -116,7 +116,10 @@ function sharedSponsorBudget(parameters = {}) {
116
116
  return false;
117
117
  return {
118
118
  ...parameters.sponsorBudget,
119
- store: parameters.sponsorBudget?.store ?? parameters.store ?? Store.memory(),
119
+ // A relay finalizes credentials itself, so it needs no shared local store.
120
+ store: parameters.sponsorBudget?.store ??
121
+ parameters.store ??
122
+ (parameters.relay ? Store.memory() : fallbackStore('tempo.charge')),
120
123
  };
121
124
  }
122
125
  /** Creates OUSD-first charge offers, with explicit currency lists replacing the defaults. */
@@ -246,6 +246,14 @@ export declare namespace subscription {
246
246
  /** Custom renewal hooks must preserve amount, currency, recipient, period, expiry, and lookup key. */
247
247
  subscription: SubscriptionRecord;
248
248
  }) => Promise<RenewalResult>;
249
+ /**
250
+ * Atomic store for subscriptions and credential replay protection, shared by every
251
+ * server instance.
252
+ *
253
+ * If omitted, this throws in production (`NODE_ENV=production`), on multi-instance
254
+ * platforms and on Cloudflare Workers, and otherwise warns and falls back to an in-memory
255
+ * store. Pass `Store.memory()` explicitly to accept state scoped to one instance.
256
+ */
249
257
  store?: Store.AtomicStore<Record<string, unknown>> | undefined;
250
258
  /**
251
259
  * Prefix prepended to all subscription store keys.
@@ -2,8 +2,13 @@ import * as Store from '../../../Store.js';
2
2
  /**
3
3
  * Creates the in-memory store used when a Tempo server method is configured without `store`.
4
4
  *
5
- * Replay protection backed by this store only covers the current instance, so this warns once
6
- * per `method` per process.
5
+ * Replay protection backed by this store only covers the current instance, so a credential
6
+ * accepted by one instance could be accepted again by another. In production or on a
7
+ * multi-instance platform (see {@link Env.sharedRuntime}) this throws instead, so the server fails
8
+ * closed at construction. Elsewhere, such as local development and tests, it warns once per
9
+ * `method` per process and returns a memory store.
10
+ *
11
+ * Pass `store: Store.memory()` explicitly to accept instance-local state anywhere.
7
12
  */
8
13
  export declare function fallbackStore(method: string): Store.AtomicStore;
9
14
  //# sourceMappingURL=fallback-store.d.ts.map
@@ -1,13 +1,22 @@
1
+ import * as Env from '../../../internal/env.js';
1
2
  import { warnOnce } from '../../../internal/warnOnce.js';
2
3
  import * as Store from '../../../Store.js';
3
4
  /**
4
5
  * Creates the in-memory store used when a Tempo server method is configured without `store`.
5
6
  *
6
- * Replay protection backed by this store only covers the current instance, so this warns once
7
- * per `method` per process.
7
+ * Replay protection backed by this store only covers the current instance, so a credential
8
+ * accepted by one instance could be accepted again by another. In production or on a
9
+ * multi-instance platform (see {@link Env.sharedRuntime}) this throws instead, so the server fails
10
+ * closed at construction. Elsewhere, such as local development and tests, it warns once per
11
+ * `method` per process and returns a memory store.
12
+ *
13
+ * Pass `store: Store.memory()` explicitly to accept instance-local state anywhere.
8
14
  */
9
15
  export function fallbackStore(method) {
10
- warnOnce(`memory-store:${method}`, `${method}() has no \`store\` configured and is using an in-memory store. Replay protection and payment state are scoped to this instance, so a credential accepted by one replica, serverless isolate, or per-request \`Mppx\` instance can be accepted again by another. Pass a shared atomic store (e.g. \`Store.redis()\`, \`Store.upstash()\`, or \`Store.cloudflare()\` with \`update\`) when running more than one instance.`);
16
+ const runtime = Env.sharedRuntime();
17
+ if (runtime)
18
+ throw new Error(`${method}() has no \`store\` configured, and ${runtime}, so this server may run as several instances. An in-memory store would let a credential accepted by one instance be accepted again by another. Pass a shared atomic store, such as \`Store.redis()\`, \`Store.upstash()\`, \`Store.postgres()\`, \`Store.sql()\`, \`Store.d1()\`, \`Store.durableObject()\` or \`Store.cloudflare()\` with \`update\`, or pass \`store: Store.memory()\` to accept replay protection scoped to this instance.`);
19
+ warnOnce(`memory-store:${method}`, `${method}() has no \`store\` configured and is using an in-memory store. Replay protection and payment state are scoped to this instance, so a credential accepted by one replica, serverless isolate, or per-request \`Mppx\` instance can be accepted again by another. Pass a shared atomic store (e.g. \`Store.redis()\`, \`Store.upstash()\`, or \`Store.cloudflare()\` with \`update\`) when running more than one instance. In production this throws; pass \`store: Store.memory()\` explicitly to keep instance-local state.`);
11
20
  return Store.memory();
12
21
  }
13
22
  //# sourceMappingURL=fallback-store.js.map