mppx 0.13.4 → 0.13.6

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 (73) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/Credential.d.ts +3 -0
  3. package/dist/Credential.js +9 -0
  4. package/dist/Errors.d.ts +63 -2
  5. package/dist/Errors.js +52 -2
  6. package/dist/Method.d.ts +10 -0
  7. package/dist/cli/cli.js +92 -92
  8. package/dist/cli/plugins/evm.js +2 -2
  9. package/dist/cli/plugins/index.js +12 -12
  10. package/dist/client/Mppx.d.ts +2 -0
  11. package/dist/client/Mppx.js +8 -10
  12. package/dist/client/internal/Fetch.js +107 -8
  13. package/dist/client/internal/MethodChallenge.d.ts +2 -0
  14. package/dist/client/internal/MethodChallenge.js +4 -0
  15. package/dist/client/internal/MethodResponse.d.ts +6 -0
  16. package/dist/client/internal/MethodResponse.js +16 -0
  17. package/dist/client/internal/protocols/Mcp.js +36 -5
  18. package/dist/evm/server/Charge.js +3 -1
  19. package/dist/internal/version.d.ts +2 -2
  20. package/dist/internal/version.js +1 -1
  21. package/dist/internal/warnOnce.d.ts +3 -0
  22. package/dist/internal/warnOnce.js +9 -0
  23. package/dist/server/Mppx.d.ts +5 -0
  24. package/dist/server/Mppx.js +45 -18
  25. package/dist/server/Transport.js +10 -0
  26. package/dist/stripe/server/Methods.js +4 -1
  27. package/dist/tempo/Attribution.d.ts +24 -9
  28. package/dist/tempo/Attribution.js +25 -5
  29. package/dist/tempo/client/Charge.d.ts +116 -10
  30. package/dist/tempo/client/Charge.js +117 -22
  31. package/dist/tempo/client/Methods.d.ts +88 -9
  32. package/dist/tempo/index.d.ts +1 -0
  33. package/dist/tempo/index.js +1 -0
  34. package/dist/tempo/internal/auto-swap.d.ts +10 -0
  35. package/dist/tempo/internal/auto-swap.js +35 -8
  36. package/dist/tempo/internal/fee-payer.d.ts +8 -0
  37. package/dist/tempo/internal/fee-payer.js +20 -8
  38. package/dist/tempo/legacy/session/Chain.js +8 -2
  39. package/dist/tempo/server/Charge.d.ts +11 -0
  40. package/dist/tempo/server/Charge.js +160 -29
  41. package/dist/tempo/server/Methods.js +28 -5
  42. package/dist/tempo/server/Relay.js +6 -22
  43. package/dist/tempo/server/Subscription.js +5 -1
  44. package/dist/tempo/server/internal/fallback-store.d.ts +9 -0
  45. package/dist/tempo/server/internal/fallback-store.js +13 -0
  46. package/dist/tempo/server/internal/html.gen.js +1 -1
  47. package/dist/tempo/server/internal/transport.d.ts +3 -0
  48. package/dist/tempo/server/internal/transport.js +5 -1
  49. package/dist/tempo/session/client/ChannelOps.d.ts +2 -0
  50. package/dist/tempo/session/client/ChannelStore.d.ts +12 -1
  51. package/dist/tempo/session/client/ChannelStore.js +47 -0
  52. package/dist/tempo/session/client/CredentialState.js +8 -3
  53. package/dist/tempo/session/client/Session.js +50 -33
  54. package/dist/tempo/session/client/SessionManager.js +186 -65
  55. package/dist/tempo/session/client/Transports.d.ts +6 -0
  56. package/dist/tempo/session/client/Transports.js +52 -7
  57. package/dist/tempo/session/precompile/Chain.d.ts +2 -0
  58. package/dist/tempo/session/precompile/Chain.js +8 -3
  59. package/dist/tempo/session/server/ChannelStore.d.ts +34 -0
  60. package/dist/tempo/session/server/ChannelStore.js +69 -9
  61. package/dist/tempo/session/server/CredentialVerification.d.ts +7 -1
  62. package/dist/tempo/session/server/CredentialVerification.js +220 -48
  63. package/dist/tempo/session/server/MeteredStream.d.ts +6 -5
  64. package/dist/tempo/session/server/MeteredStream.js +10 -26
  65. package/dist/tempo/session/server/Session.d.ts +29 -2
  66. package/dist/tempo/session/server/Session.js +124 -44
  67. package/dist/tempo/session/server/Settlement.d.ts +9 -0
  68. package/dist/tempo/session/server/Settlement.js +23 -3
  69. package/dist/tempo/session/server/Sse.d.ts +4 -3
  70. package/dist/tempo/session/server/Sse.js +3 -3
  71. package/dist/tempo/session/server/Ws.d.ts +9 -1
  72. package/dist/tempo/session/server/Ws.js +1 -0
  73. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- import { Bytes, Hash, Hex, Json } from 'ox';
2
1
  import { PaymentExpiredError, VerificationFailedError } from '../../Errors.js';
3
2
  import * as Receipt from '../../Receipt.js';
4
3
  const defaultApiBaseUrl = 'https://api.tempo.xyz';
@@ -43,9 +42,7 @@ export function configure(method, options) {
43
42
  };
44
43
  const broadcast = async (parameters) => {
45
44
  const input = toRelayInput(parameters.credential);
46
- const receipt = await request.broadcast(input, {
47
- idempotencyKey: idempotencyKey(input),
48
- });
45
+ const receipt = await request.broadcast(input);
49
46
  if (receipt.method !== method.name)
50
47
  throw failure();
51
48
  try {
@@ -72,7 +69,7 @@ function createRequest(options) {
72
69
  const apiBaseUrl = new URL(options.apiBaseUrl ?? defaultApiBaseUrl);
73
70
  if (!apiBaseUrl.pathname.endsWith('/'))
74
71
  apiBaseUrl.pathname += '/';
75
- async function post(path, input, headers) {
72
+ async function post(path, input) {
76
73
  let response;
77
74
  try {
78
75
  response = await fetch(new URL(path, apiBaseUrl), {
@@ -81,7 +78,6 @@ function createRequest(options) {
81
78
  Accept: 'application/json',
82
79
  'content-type': 'application/json',
83
80
  'tempo-api-key': options.apiKey,
84
- ...headers,
85
81
  },
86
82
  method: 'POST',
87
83
  });
@@ -98,10 +94,10 @@ function createRequest(options) {
98
94
  if (!isValidateSuccess(response))
99
95
  throw failure(response);
100
96
  };
101
- const broadcast = async (input, broadcastOptions) => {
102
- const response = await post('v1/mpp/broadcast', input, {
103
- 'idempotency-key': broadcastOptions.idempotencyKey,
104
- });
97
+ const broadcast = async (input) => {
98
+ // A cached settlement receipt must not authorize another protected operation.
99
+ // Omitting the idempotency key leaves credential consumption to the relay.
100
+ const response = await post('v1/mpp/broadcast', input);
105
101
  if (!isBroadcastSuccess(response))
106
102
  throw failure(response);
107
103
  return response.receipt;
@@ -118,18 +114,6 @@ function toRelayInput(credential) {
118
114
  ...(credential.source ? { source: credential.source } : {}),
119
115
  };
120
116
  }
121
- function idempotencyKey(input) {
122
- const payload = input.payload;
123
- if (isRecord(payload) &&
124
- payload.type === 'transaction' &&
125
- typeof payload.signature === 'string' &&
126
- Hex.validate(payload.signature)) {
127
- const transactionHash = Hash.keccak256(Hex.toBytes(payload.signature), { as: 'Hex' });
128
- return `mpp_${transactionHash}`;
129
- }
130
- const hash = Hash.sha256(Bytes.fromString(Json.canonicalize(input)), { as: 'Hex' });
131
- return `mpp_${hash}`;
132
- }
133
117
  function failure(value) {
134
118
  const code = relayErrorCodeFrom(value);
135
119
  if (code === 'expired')
@@ -18,6 +18,7 @@ import * as Methods from '../Methods.js';
18
18
  import { assertSubscriptionTiming, toSubscriptionPeriodSeconds, verifySubscriptionKeyAuthorization, } from '../subscription/KeyAuthorization.js';
19
19
  import * as SubscriptionReceipt from '../subscription/Receipt.js';
20
20
  import * as SubscriptionStore from '../subscription/Store.js';
21
+ import { fallbackStore } from './internal/fallback-store.js';
21
22
  /**
22
23
  * Creates a Tempo subscription method for recurring TIP-20 token payments.
23
24
  *
@@ -25,7 +26,7 @@ import * as SubscriptionStore from '../subscription/Store.js';
25
26
  */
26
27
  export function subscription(p) {
27
28
  const parameters = p;
28
- const rawStore = (parameters.store ?? Store.memory());
29
+ const rawStore = (parameters.store ?? fallbackStore('tempo.subscription'));
29
30
  if (typeof rawStore.update !== 'function') {
30
31
  throw new Error('tempo.subscription() requires an atomic store with `update`.');
31
32
  }
@@ -737,6 +738,7 @@ async function submitSubscriptionPayment(parameters) {
737
738
  };
738
739
  },
739
740
  });
741
+ FeePayer.assertRemainingValidity({ transaction: completed.transaction });
740
742
  return await signTransaction(client, completed.transaction);
741
743
  })();
742
744
  const transaction = Transaction.deserialize(serializedTransaction);
@@ -747,6 +749,8 @@ async function submitSubscriptionPayment(parameters) {
747
749
  calls: transaction.calls,
748
750
  feePayerSignature: undefined,
749
751
  });
752
+ if (feePayer)
753
+ FeePayer.assertRemainingValidity({ transaction });
750
754
  if (!waitForConfirmation) {
751
755
  // Optimistic mode has no receipt to inspect, so it cannot detect a T6
752
756
  // (TIP-1028) held transfer. Use `waitForConfirmation: true` for T6-safe proof.
@@ -0,0 +1,9 @@
1
+ import * as Store from '../../../Store.js';
2
+ /**
3
+ * Creates the in-memory store used when a Tempo server method is configured without `store`.
4
+ *
5
+ * Replay protection backed by this store only covers the current instance, so this warns once
6
+ * per `method` per process.
7
+ */
8
+ export declare function fallbackStore(method: string): Store.AtomicStore;
9
+ //# sourceMappingURL=fallback-store.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { warnOnce } from '../../../internal/warnOnce.js';
2
+ import * as Store from '../../../Store.js';
3
+ /**
4
+ * Creates the in-memory store used when a Tempo server method is configured without `store`.
5
+ *
6
+ * Replay protection backed by this store only covers the current instance, so this warns once
7
+ * per `method` per process.
8
+ */
9
+ 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.`);
11
+ return Store.memory();
12
+ }
13
+ //# sourceMappingURL=fallback-store.js.map