@dvmkit/dvm-cli 0.4.2 → 0.6.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.
- package/README.md +18 -0
- package/dist/{chunk-JVQFBKDX.js → chunk-3YE43JJR.js} +3 -3
- package/dist/{chunk-2TKOJBBB.js → chunk-4KINCBHL.js} +53 -51
- package/dist/{chunk-CSRGRJB6.js → chunk-EE2MREOM.js} +68 -4
- package/dist/chunk-ERJFRCJO.js +150 -0
- package/dist/chunk-FL2ICZW5.js +383 -0
- package/dist/chunk-FSYEZERJ.js +1667 -0
- package/dist/{chunk-6KEZKHN7.js → chunk-ID5G54HJ.js} +211 -35
- package/dist/{chunk-4NWEJTAW.js → chunk-MJ4X4BEW.js} +7953 -8036
- package/dist/{chunk-KBFK5MM5.js → chunk-QICJRKB7.js} +6972 -1321
- package/dist/{chunk-ECEM3ZAS.js → chunk-R55XNXAR.js} +53 -185
- package/dist/{chunk-OOA6X5MI.js → chunk-SHZMNEXE.js} +58 -17
- package/dist/{chunk-PRN4FHDY.js → chunk-TZWZTS37.js} +38 -23
- package/dist/{chunk-DRO3JP42.js → chunk-VOO5IAK7.js} +582 -83
- package/dist/{chunk-2VVVWBQA.js → chunk-WTM2EICO.js} +2 -352
- package/dist/chunk-XHOFQ3OS.js +717 -0
- package/dist/{chunk-KUBOPQ3N.js → chunk-Z4CZUMUT.js} +937 -1599
- package/dist/{client-OWIOFBKS.js → client-RYDA62DU.js} +11 -8
- package/dist/{dist-2G3QBGID.js → dist-GKCEIY2A.js} +7 -4
- package/dist/dvm.js +866 -121
- package/dist/{internal-DS42OMXR.js → internal-INUTGTXQ.js} +52 -38
- package/dist/{payout-reporter-TQ3YIFLZ-64RGUGTA.js → payout-reporter-3Y2U55ZX-CMKACKA3.js} +2 -2
- package/dist/{pocket-refill-3WMWHMOT.js → pocket-refill-K5T4LZF6.js} +18 -14
- package/dist/{revenue-reporter-VN4WYN74-T7HYTIDM.js → revenue-reporter-MAERPYGK-CCPZXGFA.js} +2 -2
- package/dist/tempo-AXTE4ZEA.js +34 -0
- package/dist/{tempo-lifecycle-TJ62A7UX-OLLWSS3I.js → tempo-lifecycle-ZBBLFBMH-HWI4PLYP.js} +11 -7
- package/dist/{tempo-wallet-RCGBBAJH-TSTQAZKT.js → tempo-wallet-B5XXV3YH-SRQBMYFV.js} +2 -2
- package/dist/{x402-S47Q77UE-33J7AIH3.js → x402-R6HPBY5D-VMSW7Z32.js} +3 -3
- package/package.json +2 -2
- package/skills/dvm/calling.md +2 -0
- package/skills/dvm/credit.md +4 -0
- package/skills/dvm/wallets.md +4 -0
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __dvmCreateRequire } from "node:module";
|
|
3
|
+
const require = __dvmCreateRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
chainId,
|
|
6
|
+
charge2 as charge,
|
|
7
|
+
createEventDispatcher,
|
|
8
|
+
from as from3,
|
|
9
|
+
getResolver,
|
|
10
|
+
getResolver2,
|
|
11
|
+
getSubscriptionScopes,
|
|
12
|
+
http,
|
|
13
|
+
is,
|
|
14
|
+
parse,
|
|
15
|
+
polyfill,
|
|
16
|
+
resolve,
|
|
17
|
+
restore,
|
|
18
|
+
rpcUrl,
|
|
19
|
+
selectChallengeCandidates,
|
|
20
|
+
session2 as session,
|
|
21
|
+
session3 as session2,
|
|
22
|
+
sessionManager,
|
|
23
|
+
sessionManager2,
|
|
24
|
+
signSubscriptionKeyAuthorization,
|
|
25
|
+
subscription,
|
|
26
|
+
toSubscriptionExpiryDate,
|
|
27
|
+
toSubscriptionExpirySeconds,
|
|
28
|
+
toSubscriptionPeriodSeconds,
|
|
29
|
+
validateCredentialHeaderValue,
|
|
30
|
+
verifySubscriptionKeyAuthorization
|
|
31
|
+
} from "./chunk-MJ4X4BEW.js";
|
|
32
|
+
import {
|
|
33
|
+
KeyAuthorization_exports,
|
|
34
|
+
tempo
|
|
35
|
+
} from "./chunk-BECPI5H5.js";
|
|
36
|
+
import {
|
|
37
|
+
Assets_exports2 as Assets_exports,
|
|
38
|
+
Chains_exports,
|
|
39
|
+
authorizationDomain,
|
|
40
|
+
authorizationTypes,
|
|
41
|
+
challengeHash,
|
|
42
|
+
charge as charge2,
|
|
43
|
+
eip3009,
|
|
44
|
+
isRawAddress,
|
|
45
|
+
matches,
|
|
46
|
+
networkOf,
|
|
47
|
+
resolve as resolve2,
|
|
48
|
+
toSource
|
|
49
|
+
} from "./chunk-FL2ICZW5.js";
|
|
50
|
+
import {
|
|
51
|
+
_minLength,
|
|
52
|
+
amount,
|
|
53
|
+
array,
|
|
54
|
+
assert,
|
|
55
|
+
custom,
|
|
56
|
+
encodePaymentSignature,
|
|
57
|
+
evmNetworkPrefix,
|
|
58
|
+
from2 as from,
|
|
59
|
+
from3 as from2,
|
|
60
|
+
number,
|
|
61
|
+
object,
|
|
62
|
+
optional,
|
|
63
|
+
pipe,
|
|
64
|
+
record,
|
|
65
|
+
serialize,
|
|
66
|
+
serialize3 as serialize2,
|
|
67
|
+
string,
|
|
68
|
+
toClient,
|
|
69
|
+
toPaymentRequirements,
|
|
70
|
+
transform
|
|
71
|
+
} from "./chunk-WTM2EICO.js";
|
|
72
|
+
import {
|
|
73
|
+
Hash_exports,
|
|
74
|
+
parseUnits
|
|
75
|
+
} from "./chunk-LH3QPVN6.js";
|
|
76
|
+
import {
|
|
77
|
+
Bytes_exports,
|
|
78
|
+
Hex_exports,
|
|
79
|
+
isAddressEqual
|
|
80
|
+
} from "./chunk-F55NNH2F.js";
|
|
81
|
+
import {
|
|
82
|
+
getAddress
|
|
83
|
+
} from "./chunk-MLDUKBU3.js";
|
|
84
|
+
import {
|
|
85
|
+
__export
|
|
86
|
+
} from "./chunk-IYHTITNZ.js";
|
|
87
|
+
|
|
88
|
+
// node_modules/mppx/dist/x402/internal/RouteBinding.js
|
|
89
|
+
function nonce(parameters) {
|
|
90
|
+
const input = [
|
|
91
|
+
serialize(parameters.accepted),
|
|
92
|
+
serialize(parameters.resource),
|
|
93
|
+
serialize(parameters.extensions)
|
|
94
|
+
].join("|");
|
|
95
|
+
return Hash_exports.sha256(Bytes_exports.fromString(input), { as: "Hex" });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// node_modules/mppx/dist/x402/client/Exact.js
|
|
99
|
+
async function createCredential(parameters) {
|
|
100
|
+
const account = parameters.context?.account ?? parameters.config.account;
|
|
101
|
+
if (!account.signTypedData)
|
|
102
|
+
throw new Error("x402 exact requires a typed-data signer.");
|
|
103
|
+
const request = parameters.challenge.request;
|
|
104
|
+
const accepted = toPaymentRequirements(request);
|
|
105
|
+
assertPolicy(parameters.config, accepted);
|
|
106
|
+
if (!request.resource || !request.extensions?.mppx)
|
|
107
|
+
throw new Error("x402 exact EIP-3009 requires route binding.");
|
|
108
|
+
const extensions = withNonceSalt(request.extensions);
|
|
109
|
+
const transferMethod = accepted.extra?.assetTransferMethod ?? "eip3009";
|
|
110
|
+
if (transferMethod !== "eip3009")
|
|
111
|
+
throw new Error(`x402 exact ${String(transferMethod)} signing is not implemented yet.`);
|
|
112
|
+
const name = accepted.extra?.name;
|
|
113
|
+
const version = accepted.extra?.version;
|
|
114
|
+
if (typeof name !== "string" || typeof version !== "string")
|
|
115
|
+
throw new Error("x402 exact EIP-3009 requires token name and version.");
|
|
116
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
117
|
+
const authorization = {
|
|
118
|
+
from: getAddress(account.address),
|
|
119
|
+
nonce: nonce({
|
|
120
|
+
accepted,
|
|
121
|
+
extensions,
|
|
122
|
+
resource: request.resource
|
|
123
|
+
}),
|
|
124
|
+
to: getAddress(accepted.payTo),
|
|
125
|
+
validAfter: (now - 600).toString(),
|
|
126
|
+
validBefore: (now + accepted.maxTimeoutSeconds).toString(),
|
|
127
|
+
value: accepted.amount
|
|
128
|
+
};
|
|
129
|
+
const signature = await account.signTypedData({
|
|
130
|
+
domain: {
|
|
131
|
+
chainId: chainIdOf(accepted.network),
|
|
132
|
+
name,
|
|
133
|
+
verifyingContract: getAddress(accepted.asset),
|
|
134
|
+
version
|
|
135
|
+
},
|
|
136
|
+
message: {
|
|
137
|
+
...authorization,
|
|
138
|
+
value: BigInt(authorization.value),
|
|
139
|
+
validAfter: BigInt(authorization.validAfter),
|
|
140
|
+
validBefore: BigInt(authorization.validBefore)
|
|
141
|
+
},
|
|
142
|
+
primaryType: "TransferWithAuthorization",
|
|
143
|
+
types: authorizationTypes2
|
|
144
|
+
});
|
|
145
|
+
return encodePaymentSignature({
|
|
146
|
+
accepted,
|
|
147
|
+
extensions,
|
|
148
|
+
payload: {
|
|
149
|
+
authorization,
|
|
150
|
+
signature
|
|
151
|
+
},
|
|
152
|
+
...request.resource ? { resource: request.resource } : {},
|
|
153
|
+
x402Version: 2
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
var authorizationTypes2 = {
|
|
157
|
+
TransferWithAuthorization: [
|
|
158
|
+
{ name: "from", type: "address" },
|
|
159
|
+
{ name: "to", type: "address" },
|
|
160
|
+
{ name: "value", type: "uint256" },
|
|
161
|
+
{ name: "validAfter", type: "uint256" },
|
|
162
|
+
{ name: "validBefore", type: "uint256" },
|
|
163
|
+
{ name: "nonce", type: "bytes32" }
|
|
164
|
+
]
|
|
165
|
+
};
|
|
166
|
+
function chainIdOf(network) {
|
|
167
|
+
return Number(network.slice(evmNetworkPrefix.length));
|
|
168
|
+
}
|
|
169
|
+
function assertPolicy(parameters, accepted) {
|
|
170
|
+
const chainId2 = chainIdOf(accepted.network);
|
|
171
|
+
if (parameters.networks && !parameters.networks.includes(chainId2))
|
|
172
|
+
throw new Error(`x402 exact chain ID is not allowed: ${chainId2}.`);
|
|
173
|
+
const currencies = parameters.currencies ?? parameters.assets;
|
|
174
|
+
if (currencies?.some((currency) => isRawAddress(currency)) && !parameters.networks?.length)
|
|
175
|
+
throw new Error("x402 exact raw currency allowlists require networks.");
|
|
176
|
+
if (currencies) {
|
|
177
|
+
const acceptedCurrency = getAddress(accepted.asset);
|
|
178
|
+
const allowed = currencies.some((currency) => matches(currency, acceptedCurrency, accepted.network));
|
|
179
|
+
if (!allowed)
|
|
180
|
+
throw new Error(`x402 exact currency is not allowed: ${acceptedCurrency}.`);
|
|
181
|
+
}
|
|
182
|
+
if (parameters.maxAtomicAmount !== void 0 && BigInt(accepted.amount) > BigInt(parameters.maxAtomicAmount))
|
|
183
|
+
throw new Error("x402 exact amount exceeds maxAtomicAmount.");
|
|
184
|
+
if (parameters.maxAmount !== void 0) {
|
|
185
|
+
const decimals = decimalsOfAcceptedCurrency(parameters, accepted);
|
|
186
|
+
if (decimals === void 0)
|
|
187
|
+
throw new Error("x402 exact maxAmount requires currency decimals.");
|
|
188
|
+
if (BigInt(accepted.amount) > parseUnits(parameters.maxAmount, decimals))
|
|
189
|
+
throw new Error("x402 exact amount exceeds maxAmount.");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function decimalsOfAcceptedCurrency(parameters, accepted) {
|
|
193
|
+
const currencies = parameters.currencies ?? parameters.assets;
|
|
194
|
+
const acceptedCurrency = getAddress(accepted.asset);
|
|
195
|
+
const currency = currencies?.find((currency2) => matches(currency2, acceptedCurrency, accepted.network));
|
|
196
|
+
const resolved = currency ? resolve2(currency, accepted.network) : void 0;
|
|
197
|
+
if (resolved?.decimals !== void 0)
|
|
198
|
+
return resolved.decimals;
|
|
199
|
+
return parameters.decimals;
|
|
200
|
+
}
|
|
201
|
+
function withNonceSalt(extensions) {
|
|
202
|
+
const mppx = extensions.mppx;
|
|
203
|
+
if (!mppx)
|
|
204
|
+
return extensions;
|
|
205
|
+
return {
|
|
206
|
+
...extensions,
|
|
207
|
+
mppx: {
|
|
208
|
+
...mppx,
|
|
209
|
+
info: {
|
|
210
|
+
...mppx.info,
|
|
211
|
+
nonce: randomNonceSalt()
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function randomNonceSalt() {
|
|
217
|
+
const crypto = globalThis.crypto;
|
|
218
|
+
if (!crypto?.getRandomValues)
|
|
219
|
+
throw new Error("x402 exact requires crypto randomness.");
|
|
220
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
221
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// node_modules/mppx/dist/evm/client/Charge.js
|
|
225
|
+
function charge3(parameters) {
|
|
226
|
+
return toClient(charge2, {
|
|
227
|
+
context: object({
|
|
228
|
+
account: optional(custom())
|
|
229
|
+
}),
|
|
230
|
+
async createCredential({ challenge, context }) {
|
|
231
|
+
if (isX402Challenge(challenge))
|
|
232
|
+
return createCredential({
|
|
233
|
+
challenge,
|
|
234
|
+
config: parameters,
|
|
235
|
+
context
|
|
236
|
+
});
|
|
237
|
+
const account = context?.account ?? parameters.account;
|
|
238
|
+
if (!account.signTypedData)
|
|
239
|
+
throw new Error("EVM authorization requires a typed-data signer.");
|
|
240
|
+
const request = challenge.request;
|
|
241
|
+
assertPolicy2(parameters, request);
|
|
242
|
+
if (!request.methodDetails.credentialTypes?.includes("authorization")) {
|
|
243
|
+
throw new Error("EVM authorization is not accepted by this challenge.");
|
|
244
|
+
}
|
|
245
|
+
if (request.methodDetails.splits?.length) {
|
|
246
|
+
throw new Error("EVM authorization does not support payment splits.");
|
|
247
|
+
}
|
|
248
|
+
const authorization = resolveAuthorization(parameters, request);
|
|
249
|
+
const validBefore = challenge.expires ? Math.floor(new Date(challenge.expires).getTime() / 1e3).toString() : (Math.floor(Date.now() / 1e3) + 300).toString();
|
|
250
|
+
const payload = {
|
|
251
|
+
from: getAddress(account.address),
|
|
252
|
+
nonce: challengeHash(challenge),
|
|
253
|
+
signature: await account.signTypedData({
|
|
254
|
+
domain: authorizationDomain({
|
|
255
|
+
authorization,
|
|
256
|
+
chainId: request.methodDetails.chainId,
|
|
257
|
+
currency: request.currency
|
|
258
|
+
}),
|
|
259
|
+
message: {
|
|
260
|
+
from: getAddress(account.address),
|
|
261
|
+
nonce: challengeHash(challenge),
|
|
262
|
+
to: getAddress(request.recipient),
|
|
263
|
+
validAfter: 0n,
|
|
264
|
+
validBefore: BigInt(validBefore),
|
|
265
|
+
value: BigInt(request.amount)
|
|
266
|
+
},
|
|
267
|
+
primaryType: "TransferWithAuthorization",
|
|
268
|
+
types: authorizationTypes
|
|
269
|
+
}),
|
|
270
|
+
to: getAddress(request.recipient),
|
|
271
|
+
type: "authorization",
|
|
272
|
+
validAfter: "0",
|
|
273
|
+
validBefore,
|
|
274
|
+
value: request.amount
|
|
275
|
+
};
|
|
276
|
+
return serialize2(from({
|
|
277
|
+
challenge,
|
|
278
|
+
payload,
|
|
279
|
+
source: toSource({
|
|
280
|
+
address: getAddress(account.address),
|
|
281
|
+
chainId: request.methodDetails.chainId
|
|
282
|
+
})
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function isX402Challenge(challenge) {
|
|
288
|
+
return is(challenge) && challenge.request.scheme === "exact" && typeof challenge.request.network === "string";
|
|
289
|
+
}
|
|
290
|
+
function assertPolicy2(parameters, request) {
|
|
291
|
+
const chainId2 = request.methodDetails.chainId;
|
|
292
|
+
const network = networkOf(chainId2);
|
|
293
|
+
if (parameters.networks && !parameters.networks.includes(chainId2))
|
|
294
|
+
throw new Error(`EVM chain ID is not allowed: ${chainId2}.`);
|
|
295
|
+
const currencies = parameters.currencies ?? parameters.assets;
|
|
296
|
+
if (currencies?.some((currency) => isRawAddress(currency)) && !parameters.networks?.length)
|
|
297
|
+
throw new Error("EVM raw currency allowlists require networks.");
|
|
298
|
+
if (currencies) {
|
|
299
|
+
const acceptedCurrency = getAddress(request.currency);
|
|
300
|
+
const allowed = currencies.some((currency) => matches(currency, acceptedCurrency, network));
|
|
301
|
+
if (!allowed)
|
|
302
|
+
throw new Error(`EVM currency is not allowed: ${acceptedCurrency}.`);
|
|
303
|
+
}
|
|
304
|
+
if (parameters.maxAtomicAmount !== void 0 && BigInt(request.amount) > BigInt(parameters.maxAtomicAmount))
|
|
305
|
+
throw new Error("EVM charge amount exceeds maxAtomicAmount.");
|
|
306
|
+
if (parameters.maxAmount !== void 0) {
|
|
307
|
+
const decimals = decimalsOfAcceptedCurrency2(parameters, request);
|
|
308
|
+
if (decimals === void 0)
|
|
309
|
+
throw new Error("EVM charge maxAmount requires currency decimals.");
|
|
310
|
+
if (BigInt(request.amount) > parseUnits(parameters.maxAmount, decimals))
|
|
311
|
+
throw new Error("EVM charge amount exceeds maxAmount.");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function resolveAuthorization(parameters, request) {
|
|
315
|
+
const currencies = parameters.currencies ?? parameters.assets;
|
|
316
|
+
const acceptedCurrency = getAddress(request.currency);
|
|
317
|
+
const network = networkOf(request.methodDetails.chainId);
|
|
318
|
+
const currency = currencies?.find((currency2) => matches(currency2, acceptedCurrency, network));
|
|
319
|
+
const resolved = currency ? resolve2(currency, network) : void 0;
|
|
320
|
+
if (resolved?.transfer?.type === eip3009)
|
|
321
|
+
return {
|
|
322
|
+
name: resolved.transfer.name,
|
|
323
|
+
version: resolved.transfer.version
|
|
324
|
+
};
|
|
325
|
+
if (parameters.authorization)
|
|
326
|
+
return parameters.authorization;
|
|
327
|
+
throw new Error("EVM authorization requires token name and version.");
|
|
328
|
+
}
|
|
329
|
+
function decimalsOfAcceptedCurrency2(parameters, request) {
|
|
330
|
+
const currencies = parameters.currencies ?? parameters.assets;
|
|
331
|
+
const acceptedCurrency = getAddress(request.currency);
|
|
332
|
+
const network = networkOf(request.methodDetails.chainId);
|
|
333
|
+
const currency = currencies?.find((currency2) => matches(currency2, acceptedCurrency, network));
|
|
334
|
+
const resolved = currency ? resolve2(currency, network) : void 0;
|
|
335
|
+
if (resolved?.decimals !== void 0)
|
|
336
|
+
return resolved.decimals;
|
|
337
|
+
return parameters.decimals;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// node_modules/mppx/dist/evm/client/Methods.js
|
|
341
|
+
function evm(parameters) {
|
|
342
|
+
return [evm.charge(parameters)];
|
|
343
|
+
}
|
|
344
|
+
(function(evm2) {
|
|
345
|
+
evm2.charge = charge3;
|
|
346
|
+
evm2.assets = Assets_exports;
|
|
347
|
+
evm2.chains = Chains_exports;
|
|
348
|
+
})(evm || (evm = {}));
|
|
349
|
+
|
|
350
|
+
// node_modules/mppx/dist/stripe/Methods.js
|
|
351
|
+
var charge4 = from2({
|
|
352
|
+
name: "stripe",
|
|
353
|
+
intent: "charge",
|
|
354
|
+
schema: {
|
|
355
|
+
credential: {
|
|
356
|
+
payload: object({
|
|
357
|
+
externalId: optional(string()),
|
|
358
|
+
spt: string()
|
|
359
|
+
})
|
|
360
|
+
},
|
|
361
|
+
request: pipe(object({
|
|
362
|
+
amount: amount(),
|
|
363
|
+
currency: string(),
|
|
364
|
+
decimals: number(),
|
|
365
|
+
description: optional(string()),
|
|
366
|
+
externalId: optional(string()),
|
|
367
|
+
metadata: optional(record(string(), string())),
|
|
368
|
+
networkId: string(),
|
|
369
|
+
paymentMethodTypes: array(string()).check(_minLength(1)),
|
|
370
|
+
recipient: optional(string())
|
|
371
|
+
}), transform(({ amount: amount2, decimals, metadata, networkId, paymentMethodTypes, ...rest }) => ({
|
|
372
|
+
...rest,
|
|
373
|
+
amount: parseUnits(amount2, decimals).toString(),
|
|
374
|
+
methodDetails: {
|
|
375
|
+
networkId,
|
|
376
|
+
paymentMethodTypes,
|
|
377
|
+
...metadata !== void 0 && { metadata }
|
|
378
|
+
}
|
|
379
|
+
})))
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// node_modules/mppx/dist/stripe/client/Charge.js
|
|
384
|
+
function charge5(parameters) {
|
|
385
|
+
const { client, createToken, externalId, paymentMethod: defaultPaymentMethod } = parameters;
|
|
386
|
+
return toClient(charge4, {
|
|
387
|
+
context: object({
|
|
388
|
+
paymentMethod: optional(string())
|
|
389
|
+
}),
|
|
390
|
+
async createCredential({ challenge, context }) {
|
|
391
|
+
const paymentMethod = context?.paymentMethod ?? defaultPaymentMethod;
|
|
392
|
+
if (!paymentMethod) {
|
|
393
|
+
throw new Error("paymentMethod is required (pass via context or parameters)");
|
|
394
|
+
}
|
|
395
|
+
const amount2 = challenge.request.amount;
|
|
396
|
+
const currency = challenge.request.currency;
|
|
397
|
+
const requestExternalId = typeof challenge.request.externalId === "string" ? challenge.request.externalId : void 0;
|
|
398
|
+
const networkId = challenge.request.methodDetails?.networkId;
|
|
399
|
+
if (!networkId)
|
|
400
|
+
throw new Error("networkId is required in challenge.methodDetails");
|
|
401
|
+
const metadata = challenge.request.methodDetails?.metadata;
|
|
402
|
+
if (metadata?.externalId) {
|
|
403
|
+
throw new Error("methodDetails.metadata.externalId is reserved; use credential externalId instead");
|
|
404
|
+
}
|
|
405
|
+
const expiresAt = challenge.expires ? Math.floor(new Date(challenge.expires).getTime() / 1e3) : Math.floor(Date.now() / 1e3) + 3600;
|
|
406
|
+
const spt = await createToken({
|
|
407
|
+
amount: amount2,
|
|
408
|
+
challenge,
|
|
409
|
+
client,
|
|
410
|
+
currency,
|
|
411
|
+
expiresAt,
|
|
412
|
+
metadata,
|
|
413
|
+
networkId,
|
|
414
|
+
paymentMethod
|
|
415
|
+
});
|
|
416
|
+
const payloadExternalId = requestExternalId ?? externalId;
|
|
417
|
+
return serialize2({
|
|
418
|
+
challenge,
|
|
419
|
+
payload: {
|
|
420
|
+
spt,
|
|
421
|
+
...payloadExternalId !== void 0 ? { externalId: payloadExternalId } : {}
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// node_modules/mppx/dist/stripe/client/Methods.js
|
|
429
|
+
function stripe(parameters) {
|
|
430
|
+
return [charge5(parameters)];
|
|
431
|
+
}
|
|
432
|
+
(function(stripe2) {
|
|
433
|
+
stripe2.charge = charge5;
|
|
434
|
+
})(stripe || (stripe = {}));
|
|
435
|
+
|
|
436
|
+
// node_modules/mppx/dist/tempo/client/Subscription.js
|
|
437
|
+
var subscriptionContextSchema = object({
|
|
438
|
+
accessKey: optional(custom()),
|
|
439
|
+
account: optional(custom())
|
|
440
|
+
});
|
|
441
|
+
function subscription2(parameters = {}) {
|
|
442
|
+
const getClient = getResolver2({
|
|
443
|
+
chain: tempo,
|
|
444
|
+
getClient: parameters.getClient,
|
|
445
|
+
rpcUrl
|
|
446
|
+
});
|
|
447
|
+
const getAccount = getResolver({ account: parameters.account });
|
|
448
|
+
return toClient(subscription, {
|
|
449
|
+
context: subscriptionContextSchema,
|
|
450
|
+
async createCredential({ challenge, context }) {
|
|
451
|
+
const chainId2 = challenge.request.methodDetails?.chainId ?? chainId.testnet;
|
|
452
|
+
const client = await getClient({ chainId: chainId2 });
|
|
453
|
+
const account = getAccount(client, context);
|
|
454
|
+
const accessKey = context?.accessKey ?? parameters.accessKey ?? challenge.request.methodDetails?.accessKey;
|
|
455
|
+
if (!accessKey) {
|
|
456
|
+
throw new Error("No `accessKey` provided. The subscription challenge must include `accessKey`, or the client must pass one to parameters/context.");
|
|
457
|
+
}
|
|
458
|
+
assertSubscriptionRequestRepresentable(challenge.request);
|
|
459
|
+
await parameters.validateRequest?.(challenge.request);
|
|
460
|
+
const keyAuthorization = await authorizeAccessKey(client, {
|
|
461
|
+
accessKey,
|
|
462
|
+
account,
|
|
463
|
+
chainId: chainId2,
|
|
464
|
+
request: challenge.request
|
|
465
|
+
});
|
|
466
|
+
const verified = verifySubscriptionKeyAuthorization({
|
|
467
|
+
accessKey,
|
|
468
|
+
chainId: chainId2,
|
|
469
|
+
payload: {
|
|
470
|
+
signature: KeyAuthorization_exports.serialize(keyAuthorization),
|
|
471
|
+
type: "keyAuthorization"
|
|
472
|
+
},
|
|
473
|
+
request: challenge.request
|
|
474
|
+
});
|
|
475
|
+
if (!isAddressEqual(verified.source.address, account.address)) {
|
|
476
|
+
throw new Error("keyAuthorization signer does not match the selected account");
|
|
477
|
+
}
|
|
478
|
+
return serialize2({
|
|
479
|
+
challenge,
|
|
480
|
+
payload: {
|
|
481
|
+
signature: KeyAuthorization_exports.serialize(keyAuthorization),
|
|
482
|
+
type: "keyAuthorization"
|
|
483
|
+
},
|
|
484
|
+
source: `did:pkh:eip155:${chainId2}:${account.address.toLowerCase()}`
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
async function authorizeAccessKey(client, parameters) {
|
|
490
|
+
const { accessKey, account, chainId: chainId2, request } = parameters;
|
|
491
|
+
const local = await signSubscriptionKeyAuthorization({
|
|
492
|
+
accessKey,
|
|
493
|
+
account,
|
|
494
|
+
chainId: chainId2,
|
|
495
|
+
request
|
|
496
|
+
});
|
|
497
|
+
if (local)
|
|
498
|
+
return local;
|
|
499
|
+
const result = await client.request({
|
|
500
|
+
method: "wallet_authorizeAccessKey",
|
|
501
|
+
params: [
|
|
502
|
+
{
|
|
503
|
+
address: accessKey.accessKeyAddress,
|
|
504
|
+
expiry: toSubscriptionExpirySeconds(toSubscriptionExpiryDate(request.subscriptionExpires)),
|
|
505
|
+
keyType: accessKey.keyType,
|
|
506
|
+
limits: [
|
|
507
|
+
{
|
|
508
|
+
token: request.currency,
|
|
509
|
+
limit: Hex_exports.fromNumber(BigInt(request.amount)),
|
|
510
|
+
period: toSubscriptionPeriodSeconds(request)
|
|
511
|
+
}
|
|
512
|
+
],
|
|
513
|
+
scopes: getSubscriptionScopes(request)
|
|
514
|
+
}
|
|
515
|
+
]
|
|
516
|
+
});
|
|
517
|
+
return KeyAuthorization_exports.fromRpc(result.keyAuthorization);
|
|
518
|
+
}
|
|
519
|
+
function assertSubscriptionRequestRepresentable(request) {
|
|
520
|
+
toSubscriptionPeriodSeconds(request);
|
|
521
|
+
toSubscriptionExpirySeconds(toSubscriptionExpiryDate(request.subscriptionExpires));
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// node_modules/mppx/dist/tempo/client/Methods.js
|
|
525
|
+
var sessionClient = Object.assign(session, { manager: sessionManager });
|
|
526
|
+
var sessionLegacyClient = Object.assign(sessionManager2, { method: session2 });
|
|
527
|
+
function tempo2(parameters = {}) {
|
|
528
|
+
return [charge(parameters), sessionClient(parameters)];
|
|
529
|
+
}
|
|
530
|
+
(function(tempo3) {
|
|
531
|
+
tempo3.charge = charge;
|
|
532
|
+
tempo3.common = tempo3;
|
|
533
|
+
tempo3.session = sessionClient;
|
|
534
|
+
tempo3.sessionLegacy = sessionLegacyClient;
|
|
535
|
+
tempo3.subscription = subscription2;
|
|
536
|
+
})(tempo2 || (tempo2 = {}));
|
|
537
|
+
|
|
538
|
+
// node_modules/mppx/dist/client/Mppx.js
|
|
539
|
+
var Mppx_exports = {};
|
|
540
|
+
__export(Mppx_exports, {
|
|
541
|
+
create: () => create,
|
|
542
|
+
restore: () => restore2
|
|
543
|
+
});
|
|
544
|
+
function create(config) {
|
|
545
|
+
const { maxPaymentRetries, onChallenge, orderChallenges, polyfill: polyfill2 = true, acceptPaymentPolicy = polyfill2 && typeof globalThis.location !== "undefined" ? "same-origin" : "always", transport = http() } = config;
|
|
546
|
+
const rawFetch = config.fetch ?? globalThis.fetch;
|
|
547
|
+
const methods = config.methods.flat();
|
|
548
|
+
const acceptPayment = resolve(methods, config.paymentPreferences);
|
|
549
|
+
const events = createEventDispatcher();
|
|
550
|
+
const resolvedOnChallenge = onChallenge;
|
|
551
|
+
const config_fetch = {
|
|
552
|
+
acceptPayment,
|
|
553
|
+
acceptPaymentPolicy,
|
|
554
|
+
...config.fetch && { fetch: config.fetch },
|
|
555
|
+
eventDispatcher: events,
|
|
556
|
+
...maxPaymentRetries !== void 0 && { maxPaymentRetries },
|
|
557
|
+
...resolvedOnChallenge && { onChallenge: resolvedOnChallenge },
|
|
558
|
+
...orderChallenges && { orderChallenges },
|
|
559
|
+
methods,
|
|
560
|
+
transport
|
|
561
|
+
};
|
|
562
|
+
const fetch = from3(config_fetch);
|
|
563
|
+
if (polyfill2)
|
|
564
|
+
polyfill(config_fetch);
|
|
565
|
+
function onChallengeReceived(handler) {
|
|
566
|
+
return events.on("challenge.received", handler);
|
|
567
|
+
}
|
|
568
|
+
function onCredentialCreated(handler) {
|
|
569
|
+
return events.on("credential.created", handler);
|
|
570
|
+
}
|
|
571
|
+
function onPaymentFailed(handler) {
|
|
572
|
+
return events.on("payment.failed", handler);
|
|
573
|
+
}
|
|
574
|
+
function onPaymentResponse(handler) {
|
|
575
|
+
return events.on("payment.response", handler);
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
fetch,
|
|
579
|
+
rawFetch,
|
|
580
|
+
methods,
|
|
581
|
+
transport,
|
|
582
|
+
on: events.on,
|
|
583
|
+
onChallengeReceived,
|
|
584
|
+
onCredentialCreated,
|
|
585
|
+
onPaymentFailed,
|
|
586
|
+
onPaymentResponse,
|
|
587
|
+
async createCredential(response, context, options) {
|
|
588
|
+
const challenges = transport.getChallenges ? await transport.getChallenges(response) : [await transport.getChallenge(response)];
|
|
589
|
+
const preferences = resolveChallengePreferences(acceptPayment.entries, options?.acceptPayment);
|
|
590
|
+
let challenge;
|
|
591
|
+
let mi;
|
|
592
|
+
try {
|
|
593
|
+
const candidates = selectChallengeCandidates(challenges, methods, preferences);
|
|
594
|
+
const orderedCandidates = await resolveChallengeOrder(candidates, options?.orderChallenges ?? orderChallenges);
|
|
595
|
+
const selected = orderedCandidates[0];
|
|
596
|
+
if (!selected)
|
|
597
|
+
throw new Error(`No method found for challenges: ${challenges.map((challenge2) => `${challenge2.method}.${challenge2.intent}`).join(", ")}. Available: ${methods.map((m) => `${m.name}.${m.intent}`).join(", ")}`);
|
|
598
|
+
const selectedChallenge = selected.challenge;
|
|
599
|
+
challenge = selectedChallenge;
|
|
600
|
+
mi = selected.method;
|
|
601
|
+
if (challenge.expires)
|
|
602
|
+
assert(challenge.expires, challenge.id);
|
|
603
|
+
const createCredential2 = memoizeCreateCredential((overrideContext) => createCredentialForMethod(selectedChallenge, mi, overrideContext ?? context));
|
|
604
|
+
const eventCredential = await events.emit("challenge.received", createChallengeReceivedPayload({
|
|
605
|
+
challenge: selectedChallenge,
|
|
606
|
+
challenges,
|
|
607
|
+
createCredential: createCredential2,
|
|
608
|
+
method: mi,
|
|
609
|
+
response
|
|
610
|
+
}));
|
|
611
|
+
const credential = eventCredential ?? await createCredential2();
|
|
612
|
+
validateCredentialHeaderValue(credential);
|
|
613
|
+
await events.emit("credential.created", createCredentialCreatedPayload({
|
|
614
|
+
challenge: selectedChallenge,
|
|
615
|
+
credential,
|
|
616
|
+
method: mi,
|
|
617
|
+
response
|
|
618
|
+
}));
|
|
619
|
+
return credential;
|
|
620
|
+
} catch (error) {
|
|
621
|
+
await events.emit("payment.failed", createPaymentFailedPayload({
|
|
622
|
+
challenge,
|
|
623
|
+
challenges,
|
|
624
|
+
error,
|
|
625
|
+
method: mi,
|
|
626
|
+
response
|
|
627
|
+
}));
|
|
628
|
+
throw error;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function restore2() {
|
|
634
|
+
restore();
|
|
635
|
+
}
|
|
636
|
+
function memoizeCreateCredential(createCredential2) {
|
|
637
|
+
let promise;
|
|
638
|
+
return (context) => {
|
|
639
|
+
promise ??= createCredential2(context);
|
|
640
|
+
return promise;
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function createChallengeReceivedPayload(parameters) {
|
|
644
|
+
return Object.freeze({
|
|
645
|
+
challenge: snapshotValue(parameters.challenge),
|
|
646
|
+
challenges: parameters.challenges.map((challenge) => snapshotValue(challenge)),
|
|
647
|
+
createCredential: parameters.createCredential,
|
|
648
|
+
method: snapshotMethod(parameters.method),
|
|
649
|
+
response: snapshotResponse(parameters.response)
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
function createCredentialCreatedPayload(parameters) {
|
|
653
|
+
return Object.freeze({
|
|
654
|
+
challenge: snapshotValue(parameters.challenge),
|
|
655
|
+
credential: parameters.credential,
|
|
656
|
+
method: snapshotMethod(parameters.method),
|
|
657
|
+
response: snapshotResponse(parameters.response)
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
function createPaymentFailedPayload(parameters) {
|
|
661
|
+
return Object.freeze({
|
|
662
|
+
...parameters.challenge ? { challenge: snapshotValue(parameters.challenge) } : {},
|
|
663
|
+
...parameters.challenges ? { challenges: parameters.challenges.map((challenge) => snapshotValue(challenge)) } : {},
|
|
664
|
+
error: parameters.error,
|
|
665
|
+
...parameters.method ? { method: snapshotMethod(parameters.method) } : {},
|
|
666
|
+
response: snapshotResponse(parameters.response)
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
function snapshotMethod(method) {
|
|
670
|
+
return freezeSnapshot(Object.assign({}, method));
|
|
671
|
+
}
|
|
672
|
+
function snapshotResponse(response) {
|
|
673
|
+
if (response instanceof Response)
|
|
674
|
+
return response.clone();
|
|
675
|
+
return snapshotValue(response);
|
|
676
|
+
}
|
|
677
|
+
function snapshotValue(value) {
|
|
678
|
+
try {
|
|
679
|
+
return deepFreeze(structuredClone(value));
|
|
680
|
+
} catch {
|
|
681
|
+
return freezeSnapshot(value);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
function deepFreeze(value) {
|
|
685
|
+
if (!value || typeof value !== "object" || Object.isFrozen(value))
|
|
686
|
+
return value;
|
|
687
|
+
Object.freeze(value);
|
|
688
|
+
for (const child of Object.values(value))
|
|
689
|
+
deepFreeze(child);
|
|
690
|
+
return value;
|
|
691
|
+
}
|
|
692
|
+
function freezeSnapshot(value) {
|
|
693
|
+
if (!value || typeof value !== "object" || Object.isFrozen(value))
|
|
694
|
+
return value;
|
|
695
|
+
Object.freeze(value);
|
|
696
|
+
return value;
|
|
697
|
+
}
|
|
698
|
+
function resolveChallengePreferences(fallback, override) {
|
|
699
|
+
if (!override)
|
|
700
|
+
return fallback;
|
|
701
|
+
return typeof override === "string" ? parse(override) : override;
|
|
702
|
+
}
|
|
703
|
+
async function resolveChallengeOrder(candidates, orderChallenges) {
|
|
704
|
+
return orderChallenges ? orderChallenges(candidates) : candidates;
|
|
705
|
+
}
|
|
706
|
+
async function createCredentialForMethod(challenge, mi, context) {
|
|
707
|
+
const parsedContext = mi.context && context !== void 0 ? mi.context.parse(context) : void 0;
|
|
708
|
+
return mi.createCredential(parsedContext !== void 0 ? { challenge, context: parsedContext } : { challenge });
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export {
|
|
712
|
+
evm,
|
|
713
|
+
stripe,
|
|
714
|
+
sessionClient,
|
|
715
|
+
tempo2 as tempo,
|
|
716
|
+
Mppx_exports
|
|
717
|
+
};
|