@t402/aptos 2.3.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +8 -1
  2. package/dist/{exact-direct → cjs/exact-direct}/client/index.d.ts +2 -2
  3. package/dist/{exact-direct → cjs/exact-direct}/client/index.js +3 -1
  4. package/dist/cjs/exact-direct/client/index.js.map +1 -0
  5. package/dist/{exact-direct → cjs/exact-direct}/facilitator/index.d.ts +1 -1
  6. package/dist/{exact-direct → cjs/exact-direct}/facilitator/index.js +6 -4
  7. package/dist/cjs/exact-direct/facilitator/index.js.map +1 -0
  8. package/dist/{exact-direct → cjs/exact-direct}/server/index.js +5 -3
  9. package/dist/cjs/exact-direct/server/index.js.map +1 -0
  10. package/dist/{index.d.ts → cjs/index.d.ts} +2 -2
  11. package/dist/{index.js → cjs/index.js} +10 -8
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/{types-kOweBf4U.d.cts → cjs/types-DYWWDudq.d.ts} +1 -1
  14. package/dist/esm/chunk-GQ5UPNUB.mjs +241 -0
  15. package/dist/esm/chunk-GQ5UPNUB.mjs.map +1 -0
  16. package/dist/{exact-direct/server/index.mjs → esm/chunk-KKEU3XY7.mjs} +15 -64
  17. package/dist/esm/chunk-KKEU3XY7.mjs.map +1 -0
  18. package/dist/{exact-direct/client/index.mjs → esm/chunk-LXW4POB2.mjs} +12 -81
  19. package/dist/esm/chunk-LXW4POB2.mjs.map +1 -0
  20. package/dist/{exact-direct/facilitator/index.mjs → esm/chunk-TOYLVPBQ.mjs} +17 -110
  21. package/dist/esm/chunk-TOYLVPBQ.mjs.map +1 -0
  22. package/dist/{exact-direct/client/index.d.cts → esm/exact-direct/client/index.d.mts} +2 -2
  23. package/dist/esm/exact-direct/client/index.mjs +10 -0
  24. package/dist/esm/exact-direct/client/index.mjs.map +1 -0
  25. package/dist/{exact-direct/facilitator/index.d.cts → esm/exact-direct/facilitator/index.d.mts} +1 -1
  26. package/dist/esm/exact-direct/facilitator/index.mjs +10 -0
  27. package/dist/esm/exact-direct/facilitator/index.mjs.map +1 -0
  28. package/dist/esm/exact-direct/server/index.mjs +10 -0
  29. package/dist/esm/exact-direct/server/index.mjs.map +1 -0
  30. package/dist/{index.d.cts → esm/index.d.mts} +5 -5
  31. package/dist/esm/index.mjs +115 -0
  32. package/dist/esm/index.mjs.map +1 -0
  33. package/dist/{types-kOweBf4U.d.ts → esm/types-DYWWDudq.d.mts} +1 -1
  34. package/package.json +6 -7
  35. package/dist/exact-direct/client/index.js.map +0 -1
  36. package/dist/exact-direct/client/index.mjs.map +0 -1
  37. package/dist/exact-direct/facilitator/index.js.map +0 -1
  38. package/dist/exact-direct/facilitator/index.mjs.map +0 -1
  39. package/dist/exact-direct/server/index.js.map +0 -1
  40. package/dist/exact-direct/server/index.mjs.map +0 -1
  41. package/dist/index.js.map +0 -1
  42. package/dist/index.mjs +0 -687
  43. package/dist/index.mjs.map +0 -1
  44. /package/dist/{exact-direct → cjs/exact-direct}/server/index.d.ts +0 -0
  45. /package/dist/{exact-direct/server/index.d.cts → esm/exact-direct/server/index.d.mts} +0 -0
package/dist/index.mjs DELETED
@@ -1,687 +0,0 @@
1
- // src/constants.ts
2
- var APTOS_CAIP2_NAMESPACE = "aptos";
3
- var APTOS_MAINNET_CAIP2 = "aptos:1";
4
- var APTOS_TESTNET_CAIP2 = "aptos:2";
5
- var APTOS_DEVNET_CAIP2 = "aptos:149";
6
- var APTOS_NETWORKS = [
7
- APTOS_MAINNET_CAIP2,
8
- APTOS_TESTNET_CAIP2,
9
- APTOS_DEVNET_CAIP2
10
- ];
11
- var APTOS_MAINNET_CHAIN_ID = 1;
12
- var APTOS_TESTNET_CHAIN_ID = 2;
13
- var APTOS_DEVNET_CHAIN_ID = 149;
14
- var DEFAULT_MAINNET_RPC = "https://fullnode.mainnet.aptoslabs.com/v1";
15
- var DEFAULT_TESTNET_RPC = "https://fullnode.testnet.aptoslabs.com/v1";
16
- var DEFAULT_DEVNET_RPC = "https://fullnode.devnet.aptoslabs.com/v1";
17
- var SCHEME_EXACT_DIRECT = "exact-direct";
18
- var PRIMARY_FUNGIBLE_STORE_MODULE = "0x1::primary_fungible_store";
19
- var FUNGIBLE_ASSET_MODULE = "0x1::fungible_asset";
20
- var APTOS_ACCOUNT_MODULE = "0x1::aptos_account";
21
- var FA_TRANSFER_FUNCTION = `${PRIMARY_FUNGIBLE_STORE_MODULE}::transfer`;
22
- var DEFAULT_MAX_GAS_AMOUNT = 100000n;
23
- var DEFAULT_GAS_UNIT_PRICE = 100n;
24
- var DEFAULT_TX_EXPIRATION_SECONDS = 600;
25
-
26
- // src/types.ts
27
- function extractChainId(network) {
28
- const parts = network.split(":");
29
- if (parts.length !== 2 || parts[0] !== "aptos") {
30
- throw new Error(`Invalid Aptos network identifier: ${network}`);
31
- }
32
- const chainId = parseInt(parts[1], 10);
33
- if (isNaN(chainId)) {
34
- throw new Error(`Invalid chain ID in network identifier: ${network}`);
35
- }
36
- return chainId;
37
- }
38
-
39
- // src/tokens.ts
40
- var TOKEN_REGISTRY = {
41
- [APTOS_MAINNET_CAIP2]: [
42
- {
43
- metadataAddress: "0xf73e887a8754f540ee6e1a93bdc6dde2af69fc7ca5de32013e89dd44244473cb",
44
- symbol: "USDT",
45
- name: "Tether USD",
46
- decimals: 6
47
- },
48
- {
49
- metadataAddress: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
50
- symbol: "USDC",
51
- name: "USD Coin",
52
- decimals: 6
53
- }
54
- ],
55
- [APTOS_TESTNET_CAIP2]: [
56
- {
57
- // Testnet USDT (may differ from mainnet)
58
- metadataAddress: "0xf73e887a8754f540ee6e1a93bdc6dde2af69fc7ca5de32013e89dd44244473cb",
59
- symbol: "USDT",
60
- name: "Tether USD",
61
- decimals: 6
62
- }
63
- ],
64
- [APTOS_DEVNET_CAIP2]: []
65
- };
66
- function getTokenConfig(network, symbol) {
67
- const tokens = TOKEN_REGISTRY[network];
68
- if (!tokens) return void 0;
69
- return tokens.find(
70
- (t) => t.symbol.toUpperCase() === symbol.toUpperCase()
71
- );
72
- }
73
- function getSupportedTokens(network) {
74
- return TOKEN_REGISTRY[network] || [];
75
- }
76
- function isTokenSupported(network, symbol) {
77
- return getTokenConfig(network, symbol) !== void 0;
78
- }
79
- function getTokenByAddress(network, metadataAddress) {
80
- const tokens = TOKEN_REGISTRY[network];
81
- if (!tokens) return void 0;
82
- const normalizedAddress = metadataAddress.toLowerCase();
83
- return tokens.find(
84
- (t) => t.metadataAddress.toLowerCase() === normalizedAddress
85
- );
86
- }
87
- var DEFAULT_TOKEN_SYMBOL = "USDT";
88
- function getDefaultToken(network) {
89
- return getTokenConfig(network, DEFAULT_TOKEN_SYMBOL);
90
- }
91
-
92
- // src/utils.ts
93
- function isValidAptosAddress(address) {
94
- if (!address) return false;
95
- if (!address.startsWith("0x")) return false;
96
- const hex = address.slice(2);
97
- if (hex.length === 0 || hex.length > 64) return false;
98
- return /^[0-9a-fA-F]+$/.test(hex);
99
- }
100
- function normalizeAptosAddress(address) {
101
- if (!address.startsWith("0x")) {
102
- throw new Error("Aptos address must start with 0x");
103
- }
104
- const hex = address.slice(2).toLowerCase();
105
- return "0x" + hex.padStart(64, "0");
106
- }
107
- function compareAddresses(addr1, addr2) {
108
- try {
109
- return normalizeAptosAddress(addr1) === normalizeAptosAddress(addr2);
110
- } catch {
111
- return false;
112
- }
113
- }
114
- function isValidTxHash(txHash) {
115
- if (!txHash) return false;
116
- if (!txHash.startsWith("0x")) return false;
117
- const hex = txHash.slice(2);
118
- if (hex.length !== 64) return false;
119
- return /^[0-9a-fA-F]+$/.test(hex);
120
- }
121
- function getDefaultRpcUrl(network) {
122
- switch (network) {
123
- case APTOS_MAINNET_CAIP2:
124
- return DEFAULT_MAINNET_RPC;
125
- case APTOS_TESTNET_CAIP2:
126
- return DEFAULT_TESTNET_RPC;
127
- case APTOS_DEVNET_CAIP2:
128
- return DEFAULT_DEVNET_RPC;
129
- default:
130
- throw new Error(`Unknown Aptos network: ${network}`);
131
- }
132
- }
133
- function isAptosNetwork(network) {
134
- return network.startsWith(`${APTOS_CAIP2_NAMESPACE}:`);
135
- }
136
- function parseAssetIdentifier(asset) {
137
- const parts = asset.split("/");
138
- if (parts.length !== 2) return null;
139
- const network = parts[0];
140
- if (!isAptosNetwork(network)) return null;
141
- const [assetType, address] = parts[1].split(":");
142
- if (assetType !== "fa" || !address) return null;
143
- if (!isValidAptosAddress(address)) return null;
144
- return { network, metadataAddress: address };
145
- }
146
- function createAssetIdentifier(network, metadataAddress) {
147
- return `${network}/fa:${metadataAddress}`;
148
- }
149
- function parseFATransferFromEvents(events) {
150
- const withdrawEvent = events.find(
151
- (e) => e.type === "0x1::fungible_asset::Withdraw" || e.type.includes("::fungible_asset::Withdraw")
152
- );
153
- const depositEvent = events.find(
154
- (e) => e.type === "0x1::fungible_asset::Deposit" || e.type.includes("::fungible_asset::Deposit")
155
- );
156
- if (!withdrawEvent || !depositEvent) {
157
- return null;
158
- }
159
- const withdrawData = withdrawEvent.data;
160
- const depositData = depositEvent.data;
161
- if (!withdrawData.amount || !depositData.store) {
162
- return null;
163
- }
164
- const from = withdrawEvent.guid.accountAddress;
165
- const to = depositEvent.guid.accountAddress;
166
- const amount = BigInt(withdrawData.amount);
167
- return {
168
- from,
169
- to,
170
- amount,
171
- metadataAddress: ""
172
- // Will be filled from transaction details
173
- };
174
- }
175
- function isFATransferTransaction(tx) {
176
- if (!tx.payload) return false;
177
- if (tx.payload.type !== "entry_function_payload") return false;
178
- return tx.payload.function === FA_TRANSFER_FUNCTION || tx.payload.function?.includes("primary_fungible_store::transfer") || false;
179
- }
180
- function extractTransferDetails(tx) {
181
- if (!tx.success) return null;
182
- if (!tx.payload || tx.payload.type !== "entry_function_payload") return null;
183
- const args = tx.payload.arguments;
184
- if (!args || args.length < 3) return null;
185
- const metadataAddress = args[0];
186
- const to = args[1];
187
- const amount = BigInt(args[2]);
188
- return {
189
- from: tx.sender,
190
- to,
191
- amount,
192
- metadataAddress
193
- };
194
- }
195
- function formatAmount(amount, decimals) {
196
- const divisor = BigInt(10 ** decimals);
197
- const wholePart = amount / divisor;
198
- const fractionalPart = amount % divisor;
199
- const paddedFractional = fractionalPart.toString().padStart(decimals, "0");
200
- return `${wholePart}.${paddedFractional}`;
201
- }
202
- function parseAmount(amount, decimals) {
203
- const [whole, fractional = ""] = amount.split(".");
204
- const paddedFractional = fractional.padEnd(decimals, "0").slice(0, decimals);
205
- return BigInt(whole + paddedFractional);
206
- }
207
-
208
- // src/exact-direct/client/scheme.ts
209
- var ExactDirectAptosClient = class {
210
- constructor(signer, config = {}) {
211
- this.signer = signer;
212
- void config;
213
- }
214
- scheme = SCHEME_EXACT_DIRECT;
215
- /**
216
- * Create a payment payload by executing the transfer
217
- */
218
- async createPaymentPayload(t402Version, paymentRequirements) {
219
- this.validateRequirements(paymentRequirements);
220
- const from = await this.signer.getAddress();
221
- const assetInfo = parseAssetIdentifier(paymentRequirements.asset);
222
- if (!assetInfo) {
223
- throw new Error(`Invalid asset identifier: ${paymentRequirements.asset}`);
224
- }
225
- const amount = BigInt(paymentRequirements.amount);
226
- const balance = await this.signer.getBalance(assetInfo.metadataAddress);
227
- if (balance < amount) {
228
- throw new Error(
229
- `Insufficient balance: have ${balance}, need ${amount}`
230
- );
231
- }
232
- const txHash = await this.signer.transfer(
233
- paymentRequirements.payTo,
234
- assetInfo.metadataAddress,
235
- amount
236
- );
237
- const payload = {
238
- txHash,
239
- from,
240
- to: paymentRequirements.payTo,
241
- amount: paymentRequirements.amount,
242
- metadataAddress: assetInfo.metadataAddress
243
- };
244
- return {
245
- t402Version,
246
- payload
247
- };
248
- }
249
- /**
250
- * Validate payment requirements
251
- */
252
- validateRequirements(requirements) {
253
- if (requirements.scheme !== SCHEME_EXACT_DIRECT) {
254
- throw new Error(
255
- `Invalid scheme: expected ${SCHEME_EXACT_DIRECT}, got ${requirements.scheme}`
256
- );
257
- }
258
- if (!requirements.network.startsWith(`${APTOS_CAIP2_NAMESPACE}:`)) {
259
- throw new Error(`Invalid network: ${requirements.network}`);
260
- }
261
- if (!isValidAptosAddress(requirements.payTo)) {
262
- throw new Error(`Invalid payTo address: ${requirements.payTo}`);
263
- }
264
- const amount = BigInt(requirements.amount);
265
- if (amount <= 0n) {
266
- throw new Error(`Invalid amount: ${requirements.amount}`);
267
- }
268
- const assetInfo = parseAssetIdentifier(requirements.asset);
269
- if (!assetInfo) {
270
- throw new Error(`Invalid asset: ${requirements.asset}`);
271
- }
272
- const tokenConfig = getTokenConfig(requirements.network, "USDT");
273
- if (tokenConfig && !compareAddresses(tokenConfig.metadataAddress, assetInfo.metadataAddress)) {
274
- console.warn(
275
- `Using non-standard token: ${assetInfo.metadataAddress}`
276
- );
277
- }
278
- }
279
- };
280
-
281
- // src/exact-direct/client/register.ts
282
- function registerExactDirectAptosClient(client, config) {
283
- const scheme = new ExactDirectAptosClient(config.signer, config.schemeConfig);
284
- if (config.networks && config.networks.length > 0) {
285
- config.networks.forEach((network) => {
286
- client.register(network, scheme);
287
- });
288
- } else {
289
- client.register("aptos:*", scheme);
290
- }
291
- if (config.policies) {
292
- config.policies.forEach((policy) => {
293
- client.registerPolicy(policy);
294
- });
295
- }
296
- return client;
297
- }
298
-
299
- // src/exact-direct/server/scheme.ts
300
- var ExactDirectAptosServer = class {
301
- scheme = SCHEME_EXACT_DIRECT;
302
- moneyParsers = [];
303
- config;
304
- constructor(config = {}) {
305
- this.config = config;
306
- }
307
- /**
308
- * Register a custom money parser in the parser chain.
309
- */
310
- registerMoneyParser(parser) {
311
- this.moneyParsers.push(parser);
312
- return this;
313
- }
314
- /**
315
- * Parse price into Aptos-specific amount
316
- */
317
- async parsePrice(price, network) {
318
- if (!isAptosNetwork(network)) {
319
- throw new Error(`Invalid Aptos network: ${network}`);
320
- }
321
- if (typeof price === "object" && price !== null && "amount" in price) {
322
- if (!price.asset) {
323
- throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
324
- }
325
- return {
326
- amount: price.amount,
327
- asset: price.asset,
328
- extra: price.extra || {}
329
- };
330
- }
331
- const amount = this.parseMoneyToDecimal(price);
332
- for (const parser of this.moneyParsers) {
333
- const result = await parser(amount, network);
334
- if (result !== null) {
335
- return result;
336
- }
337
- }
338
- return this.defaultMoneyConversion(amount, network);
339
- }
340
- /**
341
- * Enhance payment requirements with Aptos-specific details
342
- */
343
- async enhancePaymentRequirements(paymentRequirements, supportedKind, facilitatorExtensions) {
344
- void facilitatorExtensions;
345
- const extra = { ...paymentRequirements.extra };
346
- if (supportedKind.extra?.assetSymbol) {
347
- extra.assetSymbol = supportedKind.extra.assetSymbol;
348
- }
349
- if (supportedKind.extra?.assetDecimals) {
350
- extra.assetDecimals = supportedKind.extra.assetDecimals;
351
- }
352
- return {
353
- ...paymentRequirements,
354
- extra
355
- };
356
- }
357
- /**
358
- * Parse Money (string | number) to a decimal number.
359
- */
360
- parseMoneyToDecimal(money) {
361
- if (typeof money === "number") {
362
- return money;
363
- }
364
- const cleanMoney = money.replace(/^\$/, "").trim();
365
- const amount = parseFloat(cleanMoney);
366
- if (isNaN(amount)) {
367
- throw new Error(`Invalid money format: ${money}`);
368
- }
369
- return amount;
370
- }
371
- /**
372
- * Default money conversion implementation.
373
- */
374
- defaultMoneyConversion(amount, network) {
375
- const token = this.getDefaultAsset(network);
376
- const tokenAmount = parseAmount(amount.toString(), token.decimals);
377
- return {
378
- amount: tokenAmount.toString(),
379
- asset: createAssetIdentifier(network, token.metadataAddress),
380
- extra: {
381
- symbol: token.symbol,
382
- name: token.name,
383
- decimals: token.decimals
384
- }
385
- };
386
- }
387
- /**
388
- * Get the default asset info for a network.
389
- */
390
- getDefaultAsset(network) {
391
- if (this.config.preferredToken) {
392
- const preferred = getTokenConfig(network, this.config.preferredToken);
393
- if (preferred) return preferred;
394
- }
395
- const defaultToken = getDefaultToken(network);
396
- if (defaultToken) return defaultToken;
397
- throw new Error(`No tokens configured for network ${network}`);
398
- }
399
- /**
400
- * Get all supported networks
401
- */
402
- static getSupportedNetworks() {
403
- return Object.keys(TOKEN_REGISTRY);
404
- }
405
- /**
406
- * Check if a network is supported
407
- */
408
- static isNetworkSupported(network) {
409
- return network in TOKEN_REGISTRY;
410
- }
411
- };
412
-
413
- // src/exact-direct/server/register.ts
414
- function registerExactDirectAptosServer(server, config = {}) {
415
- const scheme = new ExactDirectAptosServer(config.schemeConfig);
416
- if (config.networks && config.networks.length > 0) {
417
- config.networks.forEach((network) => {
418
- server.register(network, scheme);
419
- });
420
- } else {
421
- server.register("aptos:*", scheme);
422
- }
423
- return server;
424
- }
425
-
426
- // src/exact-direct/facilitator/scheme.ts
427
- var ExactDirectAptosFacilitator = class {
428
- constructor(signer, config) {
429
- this.signer = signer;
430
- this.config = {
431
- maxTransactionAge: config?.maxTransactionAge ?? 3600,
432
- usedTxCacheDuration: config?.usedTxCacheDuration ?? 24 * 60 * 60 * 1e3
433
- // 24 hours
434
- };
435
- this.startCleanupInterval();
436
- }
437
- scheme = SCHEME_EXACT_DIRECT;
438
- caipFamily = `${APTOS_CAIP2_NAMESPACE}:*`;
439
- config;
440
- usedTxs = /* @__PURE__ */ new Map();
441
- /**
442
- * Get extra data for a supported kind
443
- */
444
- getExtra(network) {
445
- const token = getDefaultToken(network);
446
- if (!token) {
447
- return void 0;
448
- }
449
- return {
450
- assetSymbol: token.symbol,
451
- assetDecimals: token.decimals
452
- };
453
- }
454
- /**
455
- * Get facilitator signer addresses for a network
456
- */
457
- getSigners(network) {
458
- return this.signer.getAddresses(network);
459
- }
460
- /**
461
- * Verify a payment payload
462
- */
463
- async verify(payload, requirements) {
464
- if (payload.accepted.scheme !== SCHEME_EXACT_DIRECT) {
465
- return {
466
- isValid: false,
467
- invalidReason: "invalid_scheme"
468
- };
469
- }
470
- if (!isAptosNetwork(payload.accepted.network)) {
471
- return {
472
- isValid: false,
473
- invalidReason: "invalid_network"
474
- };
475
- }
476
- const aptosPayload = payload.payload;
477
- if (!isValidTxHash(aptosPayload.txHash)) {
478
- return {
479
- isValid: false,
480
- invalidReason: "invalid_tx_hash_format"
481
- };
482
- }
483
- if (this.isTxUsed(aptosPayload.txHash)) {
484
- return {
485
- isValid: false,
486
- invalidReason: "transaction_already_used",
487
- payer: aptosPayload.from
488
- };
489
- }
490
- try {
491
- const tx = await this.signer.queryTransaction(aptosPayload.txHash);
492
- if (!tx) {
493
- return {
494
- isValid: false,
495
- invalidReason: "transaction_not_found",
496
- payer: aptosPayload.from
497
- };
498
- }
499
- if (!tx.success) {
500
- return {
501
- isValid: false,
502
- invalidReason: `transaction_failed: ${tx.vmStatus}`,
503
- payer: aptosPayload.from
504
- };
505
- }
506
- if (this.config.maxTransactionAge > 0) {
507
- const txTimestamp = parseInt(tx.timestamp, 10) / 1e6;
508
- const now = Date.now() / 1e3;
509
- const age = now - txTimestamp;
510
- if (age > this.config.maxTransactionAge) {
511
- return {
512
- isValid: false,
513
- invalidReason: `transaction_too_old: ${Math.round(age)} seconds`,
514
- payer: aptosPayload.from
515
- };
516
- }
517
- }
518
- const transferDetails = extractTransferDetails(tx);
519
- if (!transferDetails) {
520
- return {
521
- isValid: false,
522
- invalidReason: "could_not_extract_transfer_details",
523
- payer: aptosPayload.from
524
- };
525
- }
526
- const expectedAsset = parseAssetIdentifier(requirements.asset);
527
- if (!expectedAsset) {
528
- return {
529
- isValid: false,
530
- invalidReason: `invalid_asset_in_requirements: ${requirements.asset}`,
531
- payer: aptosPayload.from
532
- };
533
- }
534
- if (!compareAddresses(transferDetails.to, requirements.payTo)) {
535
- return {
536
- isValid: false,
537
- invalidReason: `recipient_mismatch: expected ${requirements.payTo}, got ${transferDetails.to}`,
538
- payer: aptosPayload.from
539
- };
540
- }
541
- if (!compareAddresses(
542
- transferDetails.metadataAddress,
543
- expectedAsset.metadataAddress
544
- )) {
545
- return {
546
- isValid: false,
547
- invalidReason: `token_mismatch: expected ${expectedAsset.metadataAddress}, got ${transferDetails.metadataAddress}`,
548
- payer: aptosPayload.from
549
- };
550
- }
551
- const expectedAmount = BigInt(requirements.amount);
552
- if (transferDetails.amount < expectedAmount) {
553
- return {
554
- isValid: false,
555
- invalidReason: `insufficient_amount: expected ${expectedAmount}, got ${transferDetails.amount}`,
556
- payer: aptosPayload.from
557
- };
558
- }
559
- this.markTxUsed(aptosPayload.txHash);
560
- return {
561
- isValid: true,
562
- payer: transferDetails.from
563
- };
564
- } catch (error) {
565
- return {
566
- isValid: false,
567
- invalidReason: `verification_error: ${error instanceof Error ? error.message : String(error)}`,
568
- payer: aptosPayload.from
569
- };
570
- }
571
- }
572
- /**
573
- * Settle a payment (no-op for exact-direct since client already executed)
574
- */
575
- async settle(payload, requirements) {
576
- const verifyResult = await this.verify(payload, requirements);
577
- if (!verifyResult.isValid) {
578
- return {
579
- success: false,
580
- errorReason: verifyResult.invalidReason || "verification_failed",
581
- payer: verifyResult.payer,
582
- transaction: "",
583
- network: requirements.network
584
- };
585
- }
586
- const aptosPayload = payload.payload;
587
- return {
588
- success: true,
589
- transaction: aptosPayload.txHash,
590
- network: requirements.network,
591
- payer: aptosPayload.from
592
- };
593
- }
594
- /**
595
- * Check if a transaction has been used
596
- */
597
- isTxUsed(txHash) {
598
- return this.usedTxs.has(txHash.toLowerCase());
599
- }
600
- /**
601
- * Mark a transaction as used
602
- */
603
- markTxUsed(txHash) {
604
- this.usedTxs.set(txHash.toLowerCase(), Date.now());
605
- }
606
- /**
607
- * Start the cleanup interval for used transactions
608
- */
609
- startCleanupInterval() {
610
- setInterval(
611
- () => {
612
- const cutoff = Date.now() - this.config.usedTxCacheDuration;
613
- for (const [txHash, usedAt] of this.usedTxs.entries()) {
614
- if (usedAt < cutoff) {
615
- this.usedTxs.delete(txHash);
616
- }
617
- }
618
- },
619
- 60 * 60 * 1e3
620
- );
621
- }
622
- };
623
-
624
- // src/exact-direct/facilitator/register.ts
625
- function registerExactDirectAptosFacilitator(facilitator, config) {
626
- const scheme = new ExactDirectAptosFacilitator(
627
- config.signer,
628
- config.schemeConfig
629
- );
630
- if (config.networks && config.networks.length > 0) {
631
- config.networks.forEach((network) => {
632
- facilitator.register(network, scheme);
633
- });
634
- } else {
635
- facilitator.register("aptos:*", scheme);
636
- }
637
- return facilitator;
638
- }
639
- export {
640
- APTOS_ACCOUNT_MODULE,
641
- APTOS_CAIP2_NAMESPACE,
642
- APTOS_DEVNET_CAIP2,
643
- APTOS_DEVNET_CHAIN_ID,
644
- APTOS_MAINNET_CAIP2,
645
- APTOS_MAINNET_CHAIN_ID,
646
- APTOS_NETWORKS,
647
- APTOS_TESTNET_CAIP2,
648
- APTOS_TESTNET_CHAIN_ID,
649
- DEFAULT_DEVNET_RPC,
650
- DEFAULT_GAS_UNIT_PRICE,
651
- DEFAULT_MAINNET_RPC,
652
- DEFAULT_MAX_GAS_AMOUNT,
653
- DEFAULT_TESTNET_RPC,
654
- DEFAULT_TOKEN_SYMBOL,
655
- DEFAULT_TX_EXPIRATION_SECONDS,
656
- ExactDirectAptosClient,
657
- ExactDirectAptosFacilitator,
658
- ExactDirectAptosServer,
659
- FA_TRANSFER_FUNCTION,
660
- FUNGIBLE_ASSET_MODULE,
661
- PRIMARY_FUNGIBLE_STORE_MODULE,
662
- SCHEME_EXACT_DIRECT,
663
- TOKEN_REGISTRY,
664
- compareAddresses,
665
- createAssetIdentifier,
666
- extractChainId,
667
- extractTransferDetails,
668
- formatAmount,
669
- getDefaultRpcUrl,
670
- getDefaultToken,
671
- getSupportedTokens,
672
- getTokenByAddress,
673
- getTokenConfig,
674
- isAptosNetwork,
675
- isFATransferTransaction,
676
- isTokenSupported,
677
- isValidAptosAddress,
678
- isValidTxHash,
679
- normalizeAptosAddress,
680
- parseAmount,
681
- parseAssetIdentifier,
682
- parseFATransferFromEvents,
683
- registerExactDirectAptosClient,
684
- registerExactDirectAptosFacilitator,
685
- registerExactDirectAptosServer
686
- };
687
- //# sourceMappingURL=index.mjs.map