mppx 0.17.6 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/Currency.d.ts +59 -0
  3. package/dist/Currency.js +60 -0
  4. package/dist/Errors.d.ts +13 -0
  5. package/dist/Errors.js +15 -6
  6. package/dist/cli/cli.js +138 -138
  7. package/dist/cli/plugins/index.js +12 -12
  8. package/dist/cli/plugins/tempo.js +13 -1
  9. package/dist/client/Mppx.js +13 -4
  10. package/dist/client/internal/Fetch.d.ts +5 -0
  11. package/dist/client/internal/Fetch.js +16 -5
  12. package/dist/cloudflare/ChannelStore.d.ts +1 -2
  13. package/dist/cloudflare/ChannelStore.js +14 -20
  14. package/dist/cloudflare/Channels.d.ts +20 -2
  15. package/dist/cloudflare/Channels.js +47 -4
  16. package/dist/cloudflare/index.d.ts +1 -1
  17. package/dist/cloudflare/index.js +1 -1
  18. package/dist/discovery/Discovery.d.ts +116 -9
  19. package/dist/discovery/Discovery.js +169 -0
  20. package/dist/evm/server/Charge.js +2 -3
  21. package/dist/evm/server/Methods.d.ts +1 -1
  22. package/dist/evm/server/Methods.js +3 -2
  23. package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.d.ts +4 -1
  24. package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.js +4 -1
  25. package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.d.ts +5 -5
  26. package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.js +1 -1
  27. package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts} +40 -26
  28. package/dist/extensions/identity/{email-otp/internal/Attestation.js → attestation/Token.js} +18 -3
  29. package/dist/extensions/identity/{email-otp/internal → attestation}/Types.d.ts +14 -14
  30. package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
  31. package/dist/extensions/identity/attestation/client/index.js +273 -0
  32. package/dist/extensions/identity/attestation/index.d.ts +20 -0
  33. package/dist/extensions/identity/attestation/index.js +18 -0
  34. package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
  35. package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
  36. package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
  37. package/dist/extensions/identity/attestation/server/index.js +119 -0
  38. package/dist/extensions/identity/email-otp/Constants.d.ts +5 -5
  39. package/dist/extensions/identity/email-otp/Constants.js +6 -5
  40. package/dist/extensions/identity/email-otp/Types.d.ts +4 -4
  41. package/dist/extensions/identity/email-otp/client/index.d.ts +22 -15
  42. package/dist/extensions/identity/email-otp/client/index.js +21 -9
  43. package/dist/extensions/identity/email-otp/index.d.ts +3 -8
  44. package/dist/extensions/identity/email-otp/index.js +3 -8
  45. package/dist/extensions/identity/email-otp/server/index.d.ts +16 -16
  46. package/dist/extensions/identity/email-otp/server/index.js +17 -14
  47. package/dist/extensions/identity/index.d.ts +6 -0
  48. package/dist/extensions/identity/index.js +6 -0
  49. package/dist/extensions/identity/internal/Verification.js +9 -5
  50. package/dist/extensions/identity/link/Constants.d.ts +102 -0
  51. package/dist/extensions/identity/link/Constants.js +16 -0
  52. package/dist/extensions/identity/link/client/index.d.ts +80 -0
  53. package/dist/extensions/identity/link/client/index.js +211 -0
  54. package/dist/extensions/identity/link/index.d.ts +12 -0
  55. package/dist/extensions/identity/link/index.js +12 -0
  56. package/dist/extensions/identity/link/server/index.d.ts +124 -0
  57. package/dist/extensions/identity/link/server/index.js +518 -0
  58. package/dist/extensions/identity/persona/Constants.d.ts +24 -0
  59. package/dist/extensions/identity/persona/Constants.js +24 -0
  60. package/dist/extensions/identity/persona/Did.d.ts +24 -0
  61. package/dist/extensions/identity/persona/Did.js +24 -0
  62. package/dist/extensions/identity/persona/Types.d.ts +21 -0
  63. package/dist/extensions/identity/persona/Types.js +2 -0
  64. package/dist/extensions/identity/persona/index.d.ts +10 -0
  65. package/dist/extensions/identity/persona/index.js +9 -0
  66. package/dist/extensions/identity/persona/server/index.d.ts +152 -0
  67. package/dist/extensions/identity/persona/server/index.js +263 -0
  68. package/dist/identity/Callback.d.ts +24 -5
  69. package/dist/identity/Callback.js +35 -11
  70. package/dist/identity/Client.d.ts +78 -5
  71. package/dist/identity/Client.js +165 -48
  72. package/dist/identity/Headers.d.ts +21 -0
  73. package/dist/identity/Headers.js +24 -0
  74. package/dist/identity/Server.d.ts +159 -37
  75. package/dist/identity/Server.js +309 -138
  76. package/dist/identity/Status.d.ts +14 -0
  77. package/dist/identity/Status.js +19 -0
  78. package/dist/identity/Types.d.ts +166 -65
  79. package/dist/identity/index.d.ts +2 -0
  80. package/dist/identity/index.js +2 -0
  81. package/dist/identity/internal/Requirements.d.ts +28 -0
  82. package/dist/identity/internal/Requirements.js +78 -0
  83. package/dist/index.d.ts +1 -0
  84. package/dist/index.js +1 -0
  85. package/dist/integrations/x402/Evm.d.ts +1 -0
  86. package/dist/internal/env.d.ts +14 -0
  87. package/dist/internal/env.js +38 -0
  88. package/dist/internal/version.d.ts +2 -2
  89. package/dist/internal/version.js +1 -1
  90. package/dist/proxy/internal/Headers.d.ts +1 -1
  91. package/dist/proxy/internal/Headers.js +11 -7
  92. package/dist/server/Mppx.d.ts +14 -6
  93. package/dist/server/Mppx.js +256 -149
  94. package/dist/server/internal/challengeMeta.d.ts +0 -6
  95. package/dist/server/internal/challengeMeta.js +3 -17
  96. package/dist/stripe/server/internal/html.gen.js +1 -1
  97. package/dist/tempo/client/Charge.d.ts +11 -8
  98. package/dist/tempo/client/Charge.js +53 -6
  99. package/dist/tempo/index.d.ts +4 -0
  100. package/dist/tempo/index.js +4 -0
  101. package/dist/tempo/internal/auto-swap.d.ts +6 -5
  102. package/dist/tempo/internal/auto-swap.js +17 -2
  103. package/dist/tempo/internal/currencies.d.ts +5 -4
  104. package/dist/tempo/internal/currencies.js +13 -9
  105. package/dist/tempo/internal/defaults.d.ts +7 -0
  106. package/dist/tempo/internal/defaults.js +7 -0
  107. package/dist/tempo/internal/fee-payer.js +8 -2
  108. package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
  109. package/dist/tempo/internal/machine-token-charge.js +82 -1
  110. package/dist/tempo/server/Charge.d.ts +14 -9
  111. package/dist/tempo/server/Charge.js +64 -3
  112. package/dist/tempo/server/Methods.d.ts +1 -1
  113. package/dist/tempo/server/Methods.js +4 -1
  114. package/dist/tempo/server/Subscription.d.ts +8 -0
  115. package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
  116. package/dist/tempo/server/internal/fallback-store.js +12 -3
  117. package/dist/tempo/server/internal/html.gen.js +1 -1
  118. package/dist/tempo/server/internal/transport.d.ts +1 -1
  119. package/dist/tempo/server/internal/transport.js +9 -16
  120. package/dist/tempo/session/client/CredentialState.js +31 -0
  121. package/dist/tempo/session/client/Session.d.ts +12 -6
  122. package/dist/tempo/session/client/Session.js +64 -18
  123. package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
  124. package/dist/tempo/session/server/ChannelStore.js +58 -8
  125. package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
  126. package/dist/tempo/session/server/CloseSupervisor.js +110 -12
  127. package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
  128. package/dist/tempo/session/server/CredentialVerification.js +6 -32
  129. package/dist/tempo/session/server/Session.d.ts +5 -1
  130. package/dist/tempo/session/server/Session.js +6 -3
  131. package/dist/tempo/session/server/Settlement.d.ts +7 -0
  132. package/dist/tempo/session/server/Settlement.js +36 -6
  133. package/dist/tempo/session/server/Sse.d.ts +2 -0
  134. package/dist/tempo/session/server/Sse.js +12 -12
  135. package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
  136. package/dist/tempo/subscription/KeyAuthorization.js +1 -1
  137. package/dist/x402/Assets.d.ts +14 -5
  138. package/dist/x402/Assets.js +11 -16
  139. package/package.json +19 -3
  140. package/dist/extensions/identity/email-otp/internal/Prover.d.ts +0 -46
  141. package/dist/extensions/identity/email-otp/internal/Prover.js +0 -168
  142. package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +0 -56
  143. package/dist/extensions/identity/email-otp/internal/Verifier.js +0 -116
  144. /package/dist/extensions/identity/{email-otp/internal → attestation}/Types.js +0 -0
@@ -1,5 +1,6 @@
1
1
  import type * as Hex from 'ox/Hex';
2
2
  import { type Address, type Client } from 'viem';
3
+ import * as Errors from '../../Errors.js';
3
4
  /** ABI for the first-party machine-token settlement swapper. */
4
5
  export declare const machineTokenSwapperAbi: readonly [{
5
6
  readonly name: "swapTo";
@@ -75,5 +76,56 @@ export declare function matchRoute(parameters: {
75
76
  }): Route | undefined;
76
77
  /** Returns the trusted sender that settles the configured charge route on a chain. */
77
78
  export declare function getSettlementSender(chainId: number | undefined): Address | undefined;
79
+ /**
80
+ * Builds the Tempo Wallet link that buys MACH.
81
+ *
82
+ * Returns `undefined` on chains other than Tempo mainnet (4217), where the wallet sells no MACH.
83
+ * `amount` is in MACH base units (6 decimals) and is rounded up to whole cents.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import { Tempo } from 'mppx'
88
+ *
89
+ * Tempo.machineTokenFundingUrl({ address: '0x…', amount: 1_250_000n })
90
+ * // https://wallet.tempo.xyz/agent?action=fund&intent=mach&chainId=4217&address=0x…&amount=1.25
91
+ * ```
92
+ */
93
+ export declare function fundingUrl(parameters?: {
94
+ /** Payer to fund. The wallet asks the user to sign in with this address. */
95
+ address?: Address | undefined;
96
+ /** MACH to buy, in base units. */
97
+ amount?: bigint | undefined;
98
+ /** Chain of the payment. Defaults to Tempo mainnet. */
99
+ chainId?: number | undefined;
100
+ }): string | undefined;
101
+ /**
102
+ * Returns `account`'s MACH balance, or `undefined` when the chain has no machine-token deployment or
103
+ * the balance can't be read.
104
+ */
105
+ export declare function getBalance(client: Client, parameters: {
106
+ account: Address;
107
+ chainId: number | undefined;
108
+ }): Promise<bigint | undefined>;
109
+ /**
110
+ * Returns how far `account`'s MACH balance falls short of `amount`, with a reason and the MACH onramp
111
+ * link (on Tempo mainnet) to report it.
112
+ *
113
+ * Returns `undefined` when the chain has no machine-token deployment, the account holds enough MACH,
114
+ * or its balance can't be read.
115
+ */
116
+ export declare function getShortfall(client: Client, parameters: {
117
+ account: Address;
118
+ amount: bigint;
119
+ chainId: number | undefined;
120
+ }): Promise<{
121
+ fundingUrl: string | undefined;
122
+ reason: string;
123
+ shortfall: bigint;
124
+ } | undefined>;
125
+ /**
126
+ * Returns an `InsufficientBalanceError` that links to the MACH onramp when `account` holds less
127
+ * MACH than `amount`. See `getShortfall`.
128
+ */
129
+ export declare function getInsufficientBalanceError(client: Client, parameters: Parameters<typeof getShortfall>[1]): Promise<Errors.InsufficientBalanceError | undefined>;
78
130
  export {};
79
131
  //# sourceMappingURL=machine-token-charge.d.ts.map
@@ -1,6 +1,7 @@
1
- import { decodeFunctionData, encodeFunctionData, isAddress, isAddressEqual, parseAbi, } from 'viem';
1
+ import { decodeFunctionData, encodeFunctionData, formatUnits, getAddress, isAddress, isAddressEqual, parseAbi, } from 'viem';
2
2
  import { call, readContract } from 'viem/actions';
3
3
  import { Abis, Actions } from 'viem/tempo';
4
+ import * as Errors from '../../Errors.js';
4
5
  import * as defaults from './defaults.js';
5
6
  /** ABI for the first-party machine-token settlement swapper. */
6
7
  export const machineTokenSwapperAbi = parseAbi([
@@ -106,4 +107,84 @@ export function matchRoute(parameters) {
106
107
  export function getSettlementSender(chainId) {
107
108
  return getDeployment(chainId)?.swap;
108
109
  }
110
+ /** MACH base units per cent: MACH has 6 decimals and trades 1:1 with USD. */
111
+ const unitsPerCent = 10n ** BigInt(defaults.decimals - 2);
112
+ /**
113
+ * Builds the Tempo Wallet link that buys MACH.
114
+ *
115
+ * Returns `undefined` on chains other than Tempo mainnet (4217), where the wallet sells no MACH.
116
+ * `amount` is in MACH base units (6 decimals) and is rounded up to whole cents.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import { Tempo } from 'mppx'
121
+ *
122
+ * Tempo.machineTokenFundingUrl({ address: '0x…', amount: 1_250_000n })
123
+ * // https://wallet.tempo.xyz/agent?action=fund&intent=mach&chainId=4217&address=0x…&amount=1.25
124
+ * ```
125
+ */
126
+ export function fundingUrl(parameters = {}) {
127
+ const { address, amount, chainId = defaults.chainId.mainnet } = parameters;
128
+ if (chainId !== defaults.chainId.mainnet)
129
+ return undefined;
130
+ const url = new URL(defaults.machineTokenFundingBaseUrl);
131
+ if (address && isAddress(address, { strict: false }))
132
+ url.searchParams.set('address', getAddress(address));
133
+ if (amount !== undefined && amount > 0n) {
134
+ const cents = (amount + unitsPerCent - 1n) / unitsPerCent;
135
+ const fraction = cents % 100n;
136
+ const whole = (cents / 100n).toString();
137
+ url.searchParams.set('amount', fraction === 0n
138
+ ? whole
139
+ : `${whole}.${fraction.toString().padStart(2, '0').replace(/0$/, '')}`);
140
+ }
141
+ return url.toString();
142
+ }
143
+ /**
144
+ * Returns `account`'s MACH balance, or `undefined` when the chain has no machine-token deployment or
145
+ * the balance can't be read.
146
+ */
147
+ export async function getBalance(client, parameters) {
148
+ const deployment = getDeployment(parameters.chainId);
149
+ if (!deployment)
150
+ return undefined;
151
+ const balance = await readContract(client, Actions.token.getBalance.call(client, {
152
+ account: parameters.account,
153
+ token: deployment.token,
154
+ })).catch(() => undefined);
155
+ return typeof balance === 'bigint' ? balance : undefined;
156
+ }
157
+ /**
158
+ * Returns how far `account`'s MACH balance falls short of `amount`, with a reason and the MACH onramp
159
+ * link (on Tempo mainnet) to report it.
160
+ *
161
+ * Returns `undefined` when the chain has no machine-token deployment, the account holds enough MACH,
162
+ * or its balance can't be read.
163
+ */
164
+ export async function getShortfall(client, parameters) {
165
+ const { account, amount, chainId } = parameters;
166
+ const balance = await getBalance(client, { account, chainId });
167
+ if (balance === undefined || balance >= amount)
168
+ return undefined;
169
+ const format = (value) => `${formatUnits(value, defaults.decimals)} MACH`;
170
+ const shortfall = amount - balance;
171
+ return {
172
+ fundingUrl: fundingUrl({ address: account, amount: shortfall, chainId }),
173
+ reason: `requested ${format(amount)}, available ${format(balance)}`,
174
+ shortfall,
175
+ };
176
+ }
177
+ /**
178
+ * Returns an `InsufficientBalanceError` that links to the MACH onramp when `account` holds less
179
+ * MACH than `amount`. See `getShortfall`.
180
+ */
181
+ export async function getInsufficientBalanceError(client, parameters) {
182
+ const shortfall = await getShortfall(client, parameters);
183
+ if (!shortfall)
184
+ return undefined;
185
+ return new Errors.InsufficientBalanceError({
186
+ fundingUrl: shortfall.fundingUrl,
187
+ reason: shortfall.reason,
188
+ });
189
+ }
109
190
  //# sourceMappingURL=machine-token-charge.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 ?? {});
@@ -301,7 +305,25 @@ export function charge(parameters = {}) {
301
305
  FeePayer.assertAllowedFeeToken(transaction, context.allowedFeeTokens);
302
306
  }
303
307
  else {
304
- await viem_call(client, FeePayer.simulationTransaction(transaction, { feePayer: false }));
308
+ await viem_call(client, FeePayer.simulationTransaction(transaction, { feePayer: false })).catch(async (error) => {
309
+ // A settled transaction that is sent again fails simulation too: answer it as the
310
+ // replay it is, before any MACH shortfall is read off the payer's spent balance.
311
+ // The chain is checked too: replay-sharded stores keep markers that `get` can't read.
312
+ // Settlement broadcasts the canonical envelope (below), so the chain knows that hash.
313
+ const hash = keccak256(serializedTransaction);
314
+ const canonicalHash = keccak256(await Transaction.serialize(Transaction.deserialize(serializedTransaction)));
315
+ if ((await isHashUsed(store, hash)) ||
316
+ (await isHashUsed(store, canonicalHash)) ||
317
+ (await getTransactionReceipt(client, { hash: canonicalHash }).then(() => true, () => false)))
318
+ throw new CredentialReplayedError({ reason: 'Transaction hash has already been used' });
319
+ throw await explainMachineTokenFailure(error, {
320
+ amount,
321
+ chainId: chainId ?? client.chain?.id,
322
+ client,
323
+ fundingCurrency,
324
+ payer: transaction.from,
325
+ });
326
+ });
305
327
  }
306
328
  return {
307
329
  fundingCurrency,
@@ -785,7 +807,15 @@ export function charge(parameters = {}) {
785
807
  if (claimedFinalHash)
786
808
  await releaseHashUse(store, claimedFinalHash);
787
809
  await releaseHashUse(store, hash);
788
- throw error;
810
+ if (broadcastAttempted)
811
+ throw error;
812
+ throw await explainMachineTokenFailure(error, {
813
+ amount,
814
+ chainId: chainId ?? client.chain?.id,
815
+ client,
816
+ fundingCurrency,
817
+ payer: transaction.from,
818
+ });
789
819
  }
790
820
  }
791
821
  }
@@ -793,6 +823,29 @@ export function charge(parameters = {}) {
793
823
  });
794
824
  return relay ? Relay.configure(method, relay) : method;
795
825
  }
826
+ /**
827
+ * Explains why a MACH-route payment failed before broadcast. When the payer holds too little MACH,
828
+ * returns a `VerificationFailedError` that links to the MACH onramp (on Tempo mainnet); otherwise
829
+ * returns `error` unchanged. Typed payment errors are kept as they are.
830
+ */
831
+ async function explainMachineTokenFailure(error, parameters) {
832
+ const { amount, chainId, client, fundingCurrency, payer } = parameters;
833
+ if (error instanceof PaymentError || !payer || !fundingCurrency)
834
+ return error;
835
+ if (!MachineTokenCharge.isMachineToken({ chainId, currency: fundingCurrency }))
836
+ return error;
837
+ const shortfall = await MachineTokenCharge.getShortfall(client, {
838
+ account: payer,
839
+ amount: BigInt(amount),
840
+ chainId,
841
+ });
842
+ if (!shortfall)
843
+ return error;
844
+ return new VerificationFailedError({
845
+ fundingUrl: shortfall.fundingUrl,
846
+ reason: `insufficient MACH balance (${shortfall.reason})`,
847
+ });
848
+ }
796
849
  function chargeBinding(request) {
797
850
  // Exhaustively destructure so new charge request fields require an explicit binding decision.
798
851
  const { amount, currency, description, externalId, methodDetails, recipient, ...requestRest } = request;
@@ -1050,6 +1103,14 @@ async function tryClaimZoneWithdrawal(store, portal, senderTag, expires) {
1050
1103
  async function tryClaimHash(store, hash, expires) {
1051
1104
  return Store.tryClaim(store, getHashStoreKey(hash), expires);
1052
1105
  }
1106
+ /** Whether a live replay marker holds `hash`, read without claiming it. */
1107
+ async function isHashUsed(store, hash) {
1108
+ const current = await store.get(getHashStoreKey(hash));
1109
+ if (current === null || current === undefined)
1110
+ return false;
1111
+ const expires = typeof current === 'object' && 'expires' in current ? current.expires : undefined;
1112
+ return typeof expires !== 'number' || expires > Date.now();
1113
+ }
1053
1114
  /** @internal */
1054
1115
  async function releaseHashUse(store, hash) {
1055
1116
  await store.delete(getHashStoreKey(hash));
@@ -2415,7 +2415,7 @@ type SharedParameters = Omit<charge_.Parameters, 'machineTokenEnabled'> & sessio
2415
2415
  machineTokenEnabled?: boolean | undefined;
2416
2416
  };
2417
2417
  export declare namespace tempo {
2418
- /** An accepted address or chain-indexed USD token definition from `viem/tokens`. */
2418
+ /** An accepted address or USD token from `viem/tokens`, chain-indexed or resolved to one chain. */
2419
2419
  type Currency = Currencies.Currency;
2420
2420
  /** Shared charge/session configuration with mutually exclusive currency options. */
2421
2421
  type Parameters = Omit<SharedParameters, 'currency'> & ({
@@ -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