mppx 0.6.19 → 0.6.20

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 (148) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/Challenge.d.ts +2 -2
  3. package/dist/Challenge.d.ts.map +1 -1
  4. package/dist/Challenge.js +1 -1
  5. package/dist/Challenge.js.map +1 -1
  6. package/dist/Method.d.ts +34 -0
  7. package/dist/Method.d.ts.map +1 -1
  8. package/dist/Method.js +3 -1
  9. package/dist/Method.js.map +1 -1
  10. package/dist/Receipt.d.ts +1 -0
  11. package/dist/Receipt.d.ts.map +1 -1
  12. package/dist/Receipt.js +2 -0
  13. package/dist/Receipt.js.map +1 -1
  14. package/dist/client/Methods.d.ts +1 -0
  15. package/dist/client/Methods.d.ts.map +1 -1
  16. package/dist/client/Methods.js +1 -0
  17. package/dist/client/Methods.js.map +1 -1
  18. package/dist/middlewares/elysia.d.ts.map +1 -1
  19. package/dist/middlewares/elysia.js +14 -0
  20. package/dist/middlewares/elysia.js.map +1 -1
  21. package/dist/middlewares/express.d.ts.map +1 -1
  22. package/dist/middlewares/express.js +1 -2
  23. package/dist/middlewares/express.js.map +1 -1
  24. package/dist/middlewares/hono.d.ts.map +1 -1
  25. package/dist/middlewares/hono.js +14 -0
  26. package/dist/middlewares/hono.js.map +1 -1
  27. package/dist/middlewares/nextjs.d.ts.map +1 -1
  28. package/dist/middlewares/nextjs.js +14 -0
  29. package/dist/middlewares/nextjs.js.map +1 -1
  30. package/dist/proxy/Proxy.d.ts.map +1 -1
  31. package/dist/proxy/Proxy.js +2 -2
  32. package/dist/proxy/Proxy.js.map +1 -1
  33. package/dist/proxy/Service.d.ts.map +1 -1
  34. package/dist/proxy/Service.js +1 -1
  35. package/dist/proxy/Service.js.map +1 -1
  36. package/dist/server/Mppx.d.ts +15 -3
  37. package/dist/server/Mppx.d.ts.map +1 -1
  38. package/dist/server/Mppx.js +190 -40
  39. package/dist/server/Mppx.js.map +1 -1
  40. package/dist/stripe/server/internal/html.gen.d.ts +1 -1
  41. package/dist/stripe/server/internal/html.gen.d.ts.map +1 -1
  42. package/dist/stripe/server/internal/html.gen.js +1 -1
  43. package/dist/stripe/server/internal/html.gen.js.map +1 -1
  44. package/dist/tempo/Methods.d.ts +96 -0
  45. package/dist/tempo/Methods.d.ts.map +1 -1
  46. package/dist/tempo/Methods.js +97 -0
  47. package/dist/tempo/Methods.js.map +1 -1
  48. package/dist/tempo/client/Methods.d.ts +3 -0
  49. package/dist/tempo/client/Methods.d.ts.map +1 -1
  50. package/dist/tempo/client/Methods.js +3 -0
  51. package/dist/tempo/client/Methods.js.map +1 -1
  52. package/dist/tempo/client/Subscription.d.ts +114 -0
  53. package/dist/tempo/client/Subscription.d.ts.map +1 -0
  54. package/dist/tempo/client/Subscription.js +100 -0
  55. package/dist/tempo/client/Subscription.js.map +1 -0
  56. package/dist/tempo/client/index.d.ts +1 -0
  57. package/dist/tempo/client/index.d.ts.map +1 -1
  58. package/dist/tempo/client/index.js +1 -0
  59. package/dist/tempo/client/index.js.map +1 -1
  60. package/dist/tempo/index.d.ts +1 -0
  61. package/dist/tempo/index.d.ts.map +1 -1
  62. package/dist/tempo/index.js +1 -0
  63. package/dist/tempo/index.js.map +1 -1
  64. package/dist/tempo/server/Methods.d.ts +5 -0
  65. package/dist/tempo/server/Methods.d.ts.map +1 -1
  66. package/dist/tempo/server/Methods.js +5 -0
  67. package/dist/tempo/server/Methods.js.map +1 -1
  68. package/dist/tempo/server/Subscription.d.ts +221 -0
  69. package/dist/tempo/server/Subscription.d.ts.map +1 -0
  70. package/dist/tempo/server/Subscription.js +637 -0
  71. package/dist/tempo/server/Subscription.js.map +1 -0
  72. package/dist/tempo/server/index.d.ts +1 -0
  73. package/dist/tempo/server/index.d.ts.map +1 -1
  74. package/dist/tempo/server/index.js +1 -0
  75. package/dist/tempo/server/index.js.map +1 -1
  76. package/dist/tempo/server/internal/html.gen.d.ts +1 -1
  77. package/dist/tempo/server/internal/html.gen.d.ts.map +1 -1
  78. package/dist/tempo/server/internal/html.gen.js +1 -1
  79. package/dist/tempo/server/internal/html.gen.js.map +1 -1
  80. package/dist/tempo/subscription/KeyAuthorization.d.ts +282 -0
  81. package/dist/tempo/subscription/KeyAuthorization.d.ts.map +1 -0
  82. package/dist/tempo/subscription/KeyAuthorization.js +297 -0
  83. package/dist/tempo/subscription/KeyAuthorization.js.map +1 -0
  84. package/dist/tempo/subscription/Receipt.d.ts +10 -0
  85. package/dist/tempo/subscription/Receipt.d.ts.map +1 -0
  86. package/dist/tempo/subscription/Receipt.js +16 -0
  87. package/dist/tempo/subscription/Receipt.js.map +1 -0
  88. package/dist/tempo/subscription/Store.d.ts +99 -0
  89. package/dist/tempo/subscription/Store.d.ts.map +1 -0
  90. package/dist/tempo/subscription/Store.js +292 -0
  91. package/dist/tempo/subscription/Store.js.map +1 -0
  92. package/dist/tempo/subscription/Types.d.ts +65 -0
  93. package/dist/tempo/subscription/Types.d.ts.map +1 -0
  94. package/dist/tempo/subscription/Types.js +2 -0
  95. package/dist/tempo/subscription/Types.js.map +1 -0
  96. package/dist/tempo/subscription/index.d.ts +6 -0
  97. package/dist/tempo/subscription/index.d.ts.map +1 -0
  98. package/dist/tempo/subscription/index.js +4 -0
  99. package/dist/tempo/subscription/index.js.map +1 -0
  100. package/dist/zod.d.ts +7 -0
  101. package/dist/zod.d.ts.map +1 -1
  102. package/dist/zod.js +18 -0
  103. package/dist/zod.js.map +1 -1
  104. package/package.json +3 -3
  105. package/src/Challenge.test.ts +13 -0
  106. package/src/Challenge.ts +3 -3
  107. package/src/Method.ts +46 -1
  108. package/src/Receipt.ts +2 -0
  109. package/src/client/Methods.ts +1 -0
  110. package/src/middlewares/elysia.test.ts +31 -1
  111. package/src/middlewares/elysia.ts +13 -0
  112. package/src/middlewares/express.ts +1 -5
  113. package/src/middlewares/hono.test.ts +30 -1
  114. package/src/middlewares/hono.ts +13 -0
  115. package/src/middlewares/nextjs.test.ts +28 -1
  116. package/src/middlewares/nextjs.ts +13 -0
  117. package/src/proxy/Proxy.ts +2 -5
  118. package/src/proxy/Service.test.ts +34 -0
  119. package/src/proxy/Service.ts +7 -0
  120. package/src/server/Mppx.authorize.test.ts +210 -0
  121. package/src/server/Mppx.test-d.ts +23 -1
  122. package/src/server/Mppx.test.ts +73 -3
  123. package/src/server/Mppx.ts +291 -58
  124. package/src/stripe/server/internal/html/package.json +1 -1
  125. package/src/stripe/server/internal/html.gen.ts +1 -1
  126. package/src/tempo/Methods.test.ts +131 -0
  127. package/src/tempo/Methods.ts +136 -0
  128. package/src/tempo/Subscription.integration.test.ts +591 -0
  129. package/src/tempo/client/Methods.ts +3 -0
  130. package/src/tempo/client/Subscription.test.ts +131 -0
  131. package/src/tempo/client/Subscription.ts +155 -0
  132. package/src/tempo/client/index.ts +1 -0
  133. package/src/tempo/index.ts +1 -0
  134. package/src/tempo/server/Methods.ts +5 -0
  135. package/src/tempo/server/Subscription.test.ts +1410 -0
  136. package/src/tempo/server/Subscription.ts +1014 -0
  137. package/src/tempo/server/index.ts +1 -0
  138. package/src/tempo/server/internal/html/package.json +1 -1
  139. package/src/tempo/server/internal/html.gen.ts +1 -1
  140. package/src/tempo/subscription/KeyAuthorization.test.ts +204 -0
  141. package/src/tempo/subscription/KeyAuthorization.ts +394 -0
  142. package/src/tempo/subscription/Receipt.ts +28 -0
  143. package/src/tempo/subscription/Store.test.ts +554 -0
  144. package/src/tempo/subscription/Store.ts +431 -0
  145. package/src/tempo/subscription/Types.ts +68 -0
  146. package/src/tempo/subscription/index.ts +23 -0
  147. package/src/zod.test.ts +23 -1
  148. package/src/zod.ts +24 -0
@@ -1 +1 @@
1
- {"version":3,"file":"html.gen.js","sourceRoot":"","sources":["../../../../src/tempo/server/internal/html.gen.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,IAAI,GAAG,0rvdAA0rvd,CAAA"}
1
+ {"version":3,"file":"html.gen.js","sourceRoot":"","sources":["../../../../src/tempo/server/internal/html.gen.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,IAAI,GAAG,w4keAAw4ke,CAAA"}
@@ -0,0 +1,282 @@
1
+ import { KeyAuthorization, SignatureEnvelope } from 'ox/tempo';
2
+ import { type Address } from 'viem';
3
+ import type * as Methods from '../Methods.js';
4
+ import type { SubscriptionAccessKey, SubscriptionCredentialPayload, SubscriptionPeriodUnit } from './Types.js';
5
+ /** 4-byte selector for TIP-20 `transfer(address,uint256)`. */
6
+ export declare const transferSelector = "0xa9059cbb";
7
+ /** 4-byte selector for TIP-20 `transferWithMemo(address,uint256,bytes)`. */
8
+ export declare const transferWithMemoSelector = "0x95777d59";
9
+ type SubscriptionRequest = ReturnType<typeof Methods.subscription.schema.request.parse>;
10
+ /**
11
+ * Converts a subscription expiry timestamp into the Unix seconds value required by Tempo key
12
+ * authorizations.
13
+ */
14
+ export declare function toSubscriptionExpiryDate(subscriptionExpires: string | Date): Date;
15
+ export declare function toSubscriptionExpirySeconds(subscriptionExpires: Date): number;
16
+ /**
17
+ * Converts the shared subscription period fields into the numeric period accepted by Tempo key
18
+ * authorizations.
19
+ */
20
+ export declare function toSubscriptionPeriodSeconds(request: {
21
+ periodCount: string;
22
+ periodUnit: SubscriptionPeriodUnit;
23
+ }): number;
24
+ /**
25
+ * Verifies that the subscription duration is representable and lasts beyond the payment challenge.
26
+ */
27
+ export declare function assertSubscriptionTiming(parameters: {
28
+ challengeExpires?: string | undefined;
29
+ request: Pick<SubscriptionRequest, 'periodCount' | 'periodUnit' | 'subscriptionExpires'>;
30
+ }): void;
31
+ /** Builds the Tempo access-key call scopes required for a subscription payment. */
32
+ export declare function getSubscriptionScopes(request: Pick<SubscriptionRequest, 'currency' | 'recipient'>): readonly [{
33
+ readonly address: `0x${string}`;
34
+ readonly selector: "0xa9059cbb";
35
+ readonly recipients: readonly [`0x${string}`];
36
+ }, {
37
+ readonly address: `0x${string}`;
38
+ readonly selector: "0x95777d59";
39
+ readonly recipients: readonly [`0x${string}`];
40
+ }];
41
+ /** Builds the RPC `allowedCalls` payload passed to `wallet_authorizeAccessKey`. */
42
+ export declare function getSubscriptionRpcAllowedCalls(request: Pick<SubscriptionRequest, 'currency' | 'recipient'>): readonly [{
43
+ readonly target: `0x${string}`;
44
+ readonly selectorRules: readonly [{
45
+ readonly selector: "0xa9059cbb";
46
+ readonly recipients: readonly [`0x${string}`];
47
+ }, {
48
+ readonly selector: "0x95777d59";
49
+ readonly recipients: readonly [`0x${string}`];
50
+ }];
51
+ }];
52
+ /**
53
+ * Creates and signs a Tempo key authorization for subscription payments when the account can sign
54
+ * arbitrary hashes locally.
55
+ */
56
+ export declare function signSubscriptionKeyAuthorization(parameters: {
57
+ accessKey: SubscriptionAccessKey;
58
+ account: {
59
+ sign?: ((parameters: {
60
+ hash: `0x${string}`;
61
+ }) => Promise<`0x${string}`>) | undefined;
62
+ };
63
+ chainId: number;
64
+ request: Pick<SubscriptionRequest, 'amount' | 'currency' | 'periodCount' | 'periodUnit' | 'recipient' | 'subscriptionExpires'>;
65
+ }): Promise<{
66
+ readonly address: `0x${string}`;
67
+ readonly chainId: bigint;
68
+ readonly expiry: number;
69
+ readonly limits: readonly {
70
+ readonly token: `0x${string}`;
71
+ readonly limit: bigint;
72
+ readonly period: number;
73
+ }[];
74
+ readonly scopes: readonly ({
75
+ readonly address: `0x${string}`;
76
+ readonly selector: "0xa9059cbb";
77
+ readonly recipients: readonly `0x${string}`[];
78
+ } | {
79
+ readonly address: `0x${string}`;
80
+ readonly selector: "0x95777d59";
81
+ readonly recipients: readonly `0x${string}`[];
82
+ })[];
83
+ readonly type: "secp256k1" | "p256" | "webAuthn";
84
+ signature: {
85
+ signature: {
86
+ r: bigint;
87
+ s: bigint;
88
+ yParity: number;
89
+ };
90
+ type: "secp256k1";
91
+ version?: undefined;
92
+ publicKey?: undefined;
93
+ prehash?: undefined;
94
+ metadata?: undefined;
95
+ userAddress?: undefined;
96
+ inner?: undefined;
97
+ keyId?: undefined;
98
+ } | {
99
+ prehash: boolean;
100
+ publicKey: {
101
+ prefix: number;
102
+ x: bigint;
103
+ y: bigint;
104
+ };
105
+ signature: {
106
+ r: bigint;
107
+ s: bigint;
108
+ yParity?: number | undefined;
109
+ };
110
+ type: "p256";
111
+ version?: undefined;
112
+ metadata?: undefined;
113
+ userAddress?: undefined;
114
+ inner?: undefined;
115
+ keyId?: undefined;
116
+ } | {
117
+ metadata: {
118
+ authenticatorData: import("ox/Hex").Hex;
119
+ clientDataJSON: string;
120
+ };
121
+ signature: {
122
+ r: bigint;
123
+ s: bigint;
124
+ yParity?: number | undefined;
125
+ };
126
+ publicKey: {
127
+ prefix: number;
128
+ x: bigint;
129
+ y: bigint;
130
+ };
131
+ type: "webAuthn";
132
+ version?: undefined;
133
+ prehash?: undefined;
134
+ userAddress?: undefined;
135
+ inner?: undefined;
136
+ keyId?: undefined;
137
+ } | {
138
+ userAddress: import("ox/Address").Address;
139
+ inner: {
140
+ signature: {
141
+ r: bigint;
142
+ s: bigint;
143
+ yParity: number;
144
+ };
145
+ type: "secp256k1";
146
+ version?: undefined;
147
+ publicKey?: undefined;
148
+ prehash?: undefined;
149
+ metadata?: undefined;
150
+ userAddress?: undefined;
151
+ inner?: undefined;
152
+ keyId?: undefined;
153
+ } | {
154
+ prehash: boolean;
155
+ publicKey: {
156
+ prefix: number;
157
+ x: bigint;
158
+ y: bigint;
159
+ };
160
+ signature: {
161
+ r: bigint;
162
+ s: bigint;
163
+ yParity?: number | undefined;
164
+ };
165
+ type: "p256";
166
+ version?: undefined;
167
+ metadata?: undefined;
168
+ userAddress?: undefined;
169
+ inner?: undefined;
170
+ keyId?: undefined;
171
+ } | {
172
+ metadata: {
173
+ authenticatorData: import("ox/Hex").Hex;
174
+ clientDataJSON: string;
175
+ };
176
+ signature: {
177
+ r: bigint;
178
+ s: bigint;
179
+ yParity?: number | undefined;
180
+ };
181
+ publicKey: {
182
+ prefix: number;
183
+ x: bigint;
184
+ y: bigint;
185
+ };
186
+ type: "webAuthn";
187
+ version?: undefined;
188
+ prehash?: undefined;
189
+ userAddress?: undefined;
190
+ inner?: undefined;
191
+ keyId?: undefined;
192
+ } | {
193
+ userAddress: import("ox/Address").Address;
194
+ inner: {
195
+ signature: {
196
+ r: bigint;
197
+ s: bigint;
198
+ yParity: number;
199
+ };
200
+ type: "secp256k1";
201
+ version?: undefined;
202
+ publicKey?: undefined;
203
+ prehash?: undefined;
204
+ metadata?: undefined;
205
+ userAddress?: undefined;
206
+ inner?: undefined;
207
+ keyId?: undefined;
208
+ } | {
209
+ prehash: boolean;
210
+ publicKey: {
211
+ prefix: number;
212
+ x: bigint;
213
+ y: bigint;
214
+ };
215
+ signature: {
216
+ r: bigint;
217
+ s: bigint;
218
+ yParity?: number | undefined;
219
+ };
220
+ type: "p256";
221
+ version?: undefined;
222
+ metadata?: undefined;
223
+ userAddress?: undefined;
224
+ inner?: undefined;
225
+ keyId?: undefined;
226
+ } | {
227
+ metadata: {
228
+ authenticatorData: import("ox/Hex").Hex;
229
+ clientDataJSON: string;
230
+ };
231
+ signature: {
232
+ r: bigint;
233
+ s: bigint;
234
+ yParity?: number | undefined;
235
+ };
236
+ publicKey: {
237
+ prefix: number;
238
+ x: bigint;
239
+ y: bigint;
240
+ };
241
+ type: "webAuthn";
242
+ version?: undefined;
243
+ prehash?: undefined;
244
+ userAddress?: undefined;
245
+ inner?: undefined;
246
+ keyId?: undefined;
247
+ } | /*elided*/ any;
248
+ keyId?: `0x${string}` | undefined;
249
+ type: "keychain";
250
+ version?: SignatureEnvelope.KeychainVersion | undefined;
251
+ publicKey?: undefined;
252
+ signature?: undefined;
253
+ prehash?: undefined;
254
+ metadata?: undefined;
255
+ };
256
+ keyId?: `0x${string}` | undefined;
257
+ type: "keychain";
258
+ version?: SignatureEnvelope.KeychainVersion | undefined;
259
+ publicKey?: undefined;
260
+ signature?: undefined;
261
+ prehash?: undefined;
262
+ metadata?: undefined;
263
+ };
264
+ } | undefined>;
265
+ /**
266
+ * Verifies that a subscription credential contains a key authorization scoped to the requested
267
+ * token, recipient, amount, period, expiry, chain, and server-issued access key.
268
+ */
269
+ export declare function verifySubscriptionKeyAuthorization(parameters: {
270
+ accessKey?: SubscriptionAccessKey | undefined;
271
+ chainId: number;
272
+ payload: SubscriptionCredentialPayload;
273
+ request: SubscriptionRequest;
274
+ }): {
275
+ authorization: KeyAuthorization.KeyAuthorization<boolean, bigint, number, `0x${string}`>;
276
+ source: {
277
+ address: Address;
278
+ chainId: number;
279
+ };
280
+ };
281
+ export {};
282
+ //# sourceMappingURL=KeyAuthorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyAuthorization.d.ts","sourceRoot":"","sources":["../../../src/tempo/subscription/KeyAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC9D,OAAO,EAA6B,KAAK,OAAO,EAAE,MAAM,MAAM,CAAA;AAG9D,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAEnB,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAE5C,4EAA4E;AAC5E,eAAO,MAAM,wBAAwB,eAAe,CAAA;AAMpD,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAIvF;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAEjF;AAED,wBAAgB,2BAA2B,CAAC,mBAAmB,EAAE,IAAI,GAAG,MAAM,CAmB7E;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IACnD,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU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7D,SAAS,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAA;IAC7C,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,6BAA6B,CAAA;IACtC,OAAO,EAAE,mBAAmB,CAAA;CAC7B;;;iBAsBwB,OAAO;;;EAI/B"}
@@ -0,0 +1,297 @@
1
+ import { KeyAuthorization, SignatureEnvelope } from 'ox/tempo';
2
+ import { isAddress, isAddressEqual } from 'viem';
3
+ import { VerificationFailedError } from '../../Errors.js';
4
+ /** 4-byte selector for TIP-20 `transfer(address,uint256)`. */
5
+ export const transferSelector = '0xa9059cbb';
6
+ /** 4-byte selector for TIP-20 `transferWithMemo(address,uint256,bytes)`. */
7
+ export const transferWithMemoSelector = '0x95777d59';
8
+ const uint64Max = (1n << 64n) - 1n;
9
+ const secondsPerDay = 86400n;
10
+ const secondsPerWeek = 604800n;
11
+ /**
12
+ * Converts a subscription expiry timestamp into the Unix seconds value required by Tempo key
13
+ * authorizations.
14
+ */
15
+ export function toSubscriptionExpiryDate(subscriptionExpires) {
16
+ return subscriptionExpires instanceof Date ? subscriptionExpires : new Date(subscriptionExpires);
17
+ }
18
+ export function toSubscriptionExpirySeconds(subscriptionExpires) {
19
+ const milliseconds = subscriptionExpires.getTime();
20
+ if (!Number.isFinite(milliseconds)) {
21
+ throw new VerificationFailedError({ reason: 'subscriptionExpires is invalid' });
22
+ }
23
+ if (milliseconds % 1_000 !== 0) {
24
+ throw new VerificationFailedError({
25
+ reason: 'subscriptionExpires must be representable as whole seconds',
26
+ });
27
+ }
28
+ const seconds = milliseconds / 1_000;
29
+ if (seconds <= 0 || !Number.isSafeInteger(seconds)) {
30
+ throw new VerificationFailedError({
31
+ reason: 'subscriptionExpires cannot be represented in a Tempo key authorization',
32
+ });
33
+ }
34
+ return seconds;
35
+ }
36
+ /**
37
+ * Converts the shared subscription period fields into the numeric period accepted by Tempo key
38
+ * authorizations.
39
+ */
40
+ export function toSubscriptionPeriodSeconds(request) {
41
+ if (!/^[1-9]\d*$/.test(request.periodCount)) {
42
+ throw new VerificationFailedError({ reason: 'periodCount is invalid' });
43
+ }
44
+ if (request.periodUnit !== 'day' && request.periodUnit !== 'week') {
45
+ throw new VerificationFailedError({ reason: 'periodUnit is invalid' });
46
+ }
47
+ const unitSeconds = request.periodUnit === 'day' ? secondsPerDay : secondsPerWeek;
48
+ const value = BigInt(request.periodCount) * unitSeconds;
49
+ if (value > uint64Max) {
50
+ throw new VerificationFailedError({
51
+ reason: 'subscription period cannot be represented as an unsigned 64-bit integer',
52
+ });
53
+ }
54
+ if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
55
+ throw new VerificationFailedError({
56
+ reason: 'subscription period cannot be represented exactly by this Tempo client',
57
+ });
58
+ }
59
+ return Number(value);
60
+ }
61
+ /**
62
+ * Verifies that the subscription duration is representable and lasts beyond the payment challenge.
63
+ */
64
+ export function assertSubscriptionTiming(parameters) {
65
+ const { challengeExpires, request } = parameters;
66
+ toSubscriptionPeriodSeconds(request);
67
+ const subscriptionExpiry = toSubscriptionExpirySeconds(toSubscriptionExpiryDate(request.subscriptionExpires));
68
+ if (challengeExpires) {
69
+ const challengeExpiry = Math.floor(new Date(challengeExpires).getTime() / 1_000);
70
+ if (!Number.isFinite(challengeExpiry) || subscriptionExpiry <= challengeExpiry) {
71
+ throw new VerificationFailedError({
72
+ reason: 'subscriptionExpires must be strictly later than challenge expires',
73
+ });
74
+ }
75
+ }
76
+ }
77
+ /** Builds the Tempo access-key call scopes required for a subscription payment. */
78
+ export function getSubscriptionScopes(request) {
79
+ const currency = normalizeAddress(request.currency, 'currency');
80
+ const recipient = normalizeAddress(request.recipient, 'recipient');
81
+ return [
82
+ {
83
+ address: currency,
84
+ selector: transferSelector,
85
+ recipients: [recipient],
86
+ },
87
+ {
88
+ address: currency,
89
+ selector: transferWithMemoSelector,
90
+ recipients: [recipient],
91
+ },
92
+ ];
93
+ }
94
+ /** Builds the RPC `allowedCalls` payload passed to `wallet_authorizeAccessKey`. */
95
+ export function getSubscriptionRpcAllowedCalls(request) {
96
+ const [transfer, transferWithMemo] = getSubscriptionScopes(request);
97
+ return [
98
+ {
99
+ target: normalizeAddress(request.currency, 'currency'),
100
+ selectorRules: [
101
+ {
102
+ selector: transfer.selector,
103
+ recipients: transfer.recipients,
104
+ },
105
+ {
106
+ selector: transferWithMemo.selector,
107
+ recipients: transferWithMemo.recipients,
108
+ },
109
+ ],
110
+ },
111
+ ];
112
+ }
113
+ /**
114
+ * Creates and signs a Tempo key authorization for subscription payments when the account can sign
115
+ * arbitrary hashes locally.
116
+ */
117
+ export async function signSubscriptionKeyAuthorization(parameters) {
118
+ const { accessKey, account, chainId, request } = parameters;
119
+ if (typeof account.sign !== 'function')
120
+ return undefined;
121
+ const authorization = createUnsignedAuthorization({
122
+ accessKey,
123
+ chainId,
124
+ request,
125
+ });
126
+ const signature = await account.sign({
127
+ hash: KeyAuthorization.getSignPayload(authorization),
128
+ });
129
+ return KeyAuthorization.from(authorization, {
130
+ signature: SignatureEnvelope.from(signature),
131
+ });
132
+ }
133
+ /**
134
+ * Verifies that a subscription credential contains a key authorization scoped to the requested
135
+ * token, recipient, amount, period, expiry, chain, and server-issued access key.
136
+ */
137
+ export function verifySubscriptionKeyAuthorization(parameters) {
138
+ const { accessKey, chainId, payload, request } = parameters;
139
+ if (payload.type !== 'keyAuthorization') {
140
+ throw new VerificationFailedError({ reason: 'invalid keyAuthorization payload' });
141
+ }
142
+ const authorization = deserializeAuthorization(payload.signature);
143
+ const signature = getPrimitiveSignature(authorization);
144
+ assertAuthorizationKey({
145
+ accessKey,
146
+ authorization,
147
+ chainId,
148
+ });
149
+ assertAuthorizationExpiry(authorization, request);
150
+ assertAuthorizationLimit(getSingleTokenLimit(authorization), request);
151
+ assertAuthorizationScopes(authorization.scopes, request);
152
+ const source = recoverAuthorizationSource(authorization, signature);
153
+ return {
154
+ authorization,
155
+ source: {
156
+ address: source,
157
+ chainId,
158
+ },
159
+ };
160
+ }
161
+ function createUnsignedAuthorization(parameters) {
162
+ const { accessKey, chainId, request } = parameters;
163
+ return KeyAuthorization.from({
164
+ address: normalizeAddress(accessKey.accessKeyAddress, 'accessKeyAddress'),
165
+ chainId: BigInt(chainId),
166
+ expiry: toSubscriptionExpirySeconds(toSubscriptionExpiryDate(request.subscriptionExpires)),
167
+ limits: [
168
+ {
169
+ token: normalizeAddress(request.currency, 'currency'),
170
+ limit: BigInt(request.amount),
171
+ period: toSubscriptionPeriodSeconds(request),
172
+ },
173
+ ],
174
+ scopes: getSubscriptionScopes(request),
175
+ type: accessKey.keyType,
176
+ });
177
+ }
178
+ function deserializeAuthorization(signature) {
179
+ try {
180
+ return KeyAuthorization.deserialize(signature);
181
+ }
182
+ catch {
183
+ throw new VerificationFailedError({ reason: 'invalid keyAuthorization payload' });
184
+ }
185
+ }
186
+ function getPrimitiveSignature(authorization) {
187
+ const signature = authorization.signature;
188
+ if (!signature || signature.type === 'keychain') {
189
+ throw new VerificationFailedError({
190
+ reason: 'keyAuthorization must use a primitive signature',
191
+ });
192
+ }
193
+ return signature;
194
+ }
195
+ function assertAuthorizationKey(parameters) {
196
+ const { accessKey, authorization, chainId } = parameters;
197
+ if (authorization.chainId !== BigInt(chainId)) {
198
+ throw new VerificationFailedError({ reason: 'keyAuthorization chainId mismatch' });
199
+ }
200
+ if (!accessKey)
201
+ return;
202
+ if (!isAddressEqual(authorization.address, normalizeAddress(accessKey.accessKeyAddress, 'accessKeyAddress'))) {
203
+ throw new VerificationFailedError({ reason: 'keyAuthorization access key mismatch' });
204
+ }
205
+ if (authorization.type !== accessKey.keyType) {
206
+ throw new VerificationFailedError({ reason: 'keyAuthorization key type mismatch' });
207
+ }
208
+ }
209
+ function assertAuthorizationExpiry(authorization, request) {
210
+ assertSubscriptionTiming({ request });
211
+ if (authorization.expiry !==
212
+ toSubscriptionExpirySeconds(toSubscriptionExpiryDate(request.subscriptionExpires))) {
213
+ throw new VerificationFailedError({ reason: 'keyAuthorization expiry mismatch' });
214
+ }
215
+ }
216
+ function getSingleTokenLimit(authorization) {
217
+ const [limit] = authorization.limits ?? [];
218
+ if (!limit || authorization.limits?.length !== 1) {
219
+ throw new VerificationFailedError({
220
+ reason: 'keyAuthorization must contain exactly one token limit',
221
+ });
222
+ }
223
+ return limit;
224
+ }
225
+ function assertAuthorizationLimit(limit, request) {
226
+ if (!isAddressEqual(limit.token, normalizeAddress(request.currency, 'currency'))) {
227
+ throw new VerificationFailedError({ reason: 'keyAuthorization currency mismatch' });
228
+ }
229
+ if (limit.limit !== BigInt(request.amount)) {
230
+ throw new VerificationFailedError({ reason: 'keyAuthorization amount mismatch' });
231
+ }
232
+ if (limit.period !== toSubscriptionPeriodSeconds(request)) {
233
+ throw new VerificationFailedError({ reason: 'keyAuthorization period mismatch' });
234
+ }
235
+ }
236
+ function assertAuthorizationScopes(scopes, request) {
237
+ if (!scopes || scopes.length < 1 || scopes.length > 2) {
238
+ throw new VerificationFailedError({
239
+ reason: 'keyAuthorization must contain recipient-scoped transfer calls',
240
+ });
241
+ }
242
+ const currency = normalizeAddress(request.currency, 'currency');
243
+ const recipient = normalizeAddress(request.recipient, 'recipient');
244
+ const seen = new Set();
245
+ for (const scope of scopes) {
246
+ if (!isAddressEqual(scope.address, currency)) {
247
+ throw new VerificationFailedError({ reason: 'keyAuthorization call target mismatch' });
248
+ }
249
+ const selector = normalizeSelector(scope.selector);
250
+ if (selector !== transferSelector && selector !== transferWithMemoSelector) {
251
+ throw new VerificationFailedError({ reason: 'keyAuthorization selector not allowed' });
252
+ }
253
+ if (seen.has(selector)) {
254
+ throw new VerificationFailedError({ reason: 'keyAuthorization duplicate selector' });
255
+ }
256
+ seen.add(selector);
257
+ if (scope.recipients?.length !== 1 || !isAddressEqual(scope.recipients[0], recipient)) {
258
+ throw new VerificationFailedError({ reason: 'keyAuthorization recipient mismatch' });
259
+ }
260
+ }
261
+ if (!seen.has(transferSelector)) {
262
+ throw new VerificationFailedError({ reason: 'keyAuthorization must allow transfer' });
263
+ }
264
+ if (!seen.has(transferWithMemoSelector)) {
265
+ throw new VerificationFailedError({ reason: 'keyAuthorization must allow transferWithMemo' });
266
+ }
267
+ }
268
+ function recoverAuthorizationSource(authorization, signature) {
269
+ const signPayload = KeyAuthorization.getSignPayload(authorization);
270
+ try {
271
+ const source = SignatureEnvelope.extractAddress({
272
+ payload: signPayload,
273
+ signature,
274
+ });
275
+ if (!SignatureEnvelope.verify(signature, { address: source, payload: signPayload })) {
276
+ throw new VerificationFailedError({ reason: 'keyAuthorization signature is invalid' });
277
+ }
278
+ return source;
279
+ }
280
+ catch (error) {
281
+ if (error instanceof VerificationFailedError)
282
+ throw error;
283
+ throw new VerificationFailedError({ reason: 'keyAuthorization signature is invalid' });
284
+ }
285
+ }
286
+ function normalizeAddress(value, name) {
287
+ if (!isAddress(value)) {
288
+ throw new VerificationFailedError({ reason: `${name} must be an address` });
289
+ }
290
+ return value.toLowerCase();
291
+ }
292
+ function normalizeSelector(value) {
293
+ if (typeof value !== 'string')
294
+ return '';
295
+ return value.toLowerCase();
296
+ }
297
+ //# sourceMappingURL=KeyAuthorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyAuthorization.js","sourceRoot":"","sources":["../../../src/tempo/subscription/KeyAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAgB,MAAM,MAAM,CAAA;AAE9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAQzD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA;AAE5C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAA;AAEpD,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAA;AAClC,MAAM,aAAa,GAAG,MAAO,CAAA;AAC7B,MAAM,cAAc,GAAG,OAAQ,C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MAAM,EAAE,uCAAuC,EAAE,CAAC,CAAA;QACxF,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,uBAAuB;YAAE,MAAM,KAAK,CAAA;QACzD,MAAM,IAAI,uBAAuB,CAAC,EAAE,MAAM,EAAE,uCAAuC,EAAE,CAAC,CAAA;IACxF,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa,EAAE,IAAY;IACnD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,qBAAqB,EAAE,CAAC,CAAA;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,EAAa,CAAA;AACvC,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAA;IACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { SubscriptionRecord, SubscriptionReceipt } from './Types.js';
2
+ /** Creates a subscription receipt from persisted subscription fields. */
3
+ export declare function createSubscriptionReceipt(parameters: createSubscriptionReceipt.Parameters): SubscriptionReceipt;
4
+ export declare namespace createSubscriptionReceipt {
5
+ /** Fields required to build a subscription receipt. */
6
+ type Parameters = Pick<SubscriptionRecord, 'externalId' | 'reference' | 'subscriptionId' | 'timestamp'>;
7
+ }
8
+ /** Converts a stored subscription record into a receipt. */
9
+ export declare function fromRecord(record: SubscriptionRecord): SubscriptionReceipt;
10
+ //# sourceMappingURL=Receipt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Receipt.d.ts","sourceRoot":"","sources":["../../../src/tempo/subscription/Receipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAEzE,yEAAyE;AACzE,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,yBAAyB,CAAC,UAAU,GAC/C,mBAAmB,CASrB;AAED,MAAM,CAAC,OAAO,WAAW,yBAAyB,CAAC;IACjD,uDAAuD;IACvD,KAAK,UAAU,GAAG,IAAI,CACpB,kBAAkB,EAClB,YAAY,GAAG,WAAW,GAAG,gBAAgB,GAAG,WAAW,CAC5D,CAAA;CACF;AAED,4DAA4D;AAC5D,wBAAgB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,mBAAmB,CAE1E"}
@@ -0,0 +1,16 @@
1
+ /** Creates a subscription receipt from persisted subscription fields. */
2
+ export function createSubscriptionReceipt(parameters) {
3
+ return {
4
+ method: 'tempo',
5
+ reference: parameters.reference,
6
+ status: 'success',
7
+ subscriptionId: parameters.subscriptionId,
8
+ timestamp: parameters.timestamp,
9
+ ...(parameters.externalId ? { externalId: parameters.externalId } : {}),
10
+ };
11
+ }
12
+ /** Converts a stored subscription record into a receipt. */
13
+ export function fromRecord(record) {
14
+ return createSubscriptionReceipt(record);
15
+ }
16
+ //# sourceMappingURL=Receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Receipt.js","sourceRoot":"","sources":["../../../src/tempo/subscription/Receipt.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,UAAU,yBAAyB,CACvC,UAAgD;IAEhD,OAAO;QACL,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,MAAM,EAAE,SAAS;QACjB,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxE,CAAA;AACH,CAAC;AAUD,4DAA4D;AAC5D,MAAM,UAAU,UAAU,CAAC,MAA0B;IACnD,OAAO,yBAAyB,CAAC,MAAM,CAAC,CAAA;AAC1C,CAAC"}