@t402/ton 2.0.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 (33) hide show
  1. package/dist/cjs/exact/client/index.d.ts +53 -0
  2. package/dist/cjs/exact/client/index.js +181 -0
  3. package/dist/cjs/exact/client/index.js.map +1 -0
  4. package/dist/cjs/exact/facilitator/index.d.ts +79 -0
  5. package/dist/cjs/exact/facilitator/index.js +331 -0
  6. package/dist/cjs/exact/facilitator/index.js.map +1 -0
  7. package/dist/cjs/exact/server/index.d.ts +135 -0
  8. package/dist/cjs/exact/server/index.js +318 -0
  9. package/dist/cjs/exact/server/index.js.map +1 -0
  10. package/dist/cjs/index.d.ts +293 -0
  11. package/dist/cjs/index.js +442 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/signer-CFiw2DST.d.ts +277 -0
  14. package/dist/esm/chunk-6LOUEHJT.mjs +192 -0
  15. package/dist/esm/chunk-6LOUEHJT.mjs.map +1 -0
  16. package/dist/esm/chunk-RST5PY7E.mjs +85 -0
  17. package/dist/esm/chunk-RST5PY7E.mjs.map +1 -0
  18. package/dist/esm/chunk-ZCMWKFVA.mjs +101 -0
  19. package/dist/esm/chunk-ZCMWKFVA.mjs.map +1 -0
  20. package/dist/esm/exact/client/index.d.mts +53 -0
  21. package/dist/esm/exact/client/index.mjs +8 -0
  22. package/dist/esm/exact/client/index.mjs.map +1 -0
  23. package/dist/esm/exact/facilitator/index.d.mts +79 -0
  24. package/dist/esm/exact/facilitator/index.mjs +258 -0
  25. package/dist/esm/exact/facilitator/index.mjs.map +1 -0
  26. package/dist/esm/exact/server/index.d.mts +135 -0
  27. package/dist/esm/exact/server/index.mjs +212 -0
  28. package/dist/esm/exact/server/index.mjs.map +1 -0
  29. package/dist/esm/index.d.mts +293 -0
  30. package/dist/esm/index.mjs +108 -0
  31. package/dist/esm/index.mjs.map +1 -0
  32. package/dist/esm/signer-CFiw2DST.d.mts +277 -0
  33. package/package.json +99 -0
@@ -0,0 +1,135 @@
1
+ import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@t402/core/types';
2
+
3
+ /**
4
+ * TON Server Scheme Implementation
5
+ *
6
+ * Handles price parsing and payment requirement enhancement for
7
+ * TON Jetton payments using the exact scheme.
8
+ */
9
+
10
+ /**
11
+ * Configuration options for ExactTonScheme server
12
+ */
13
+ interface ExactTonSchemeConfig {
14
+ /** Preferred Jetton symbol (e.g., "USDT"). Defaults to network's highest priority token. */
15
+ preferredJetton?: string;
16
+ }
17
+ /**
18
+ * TON server implementation for the Exact payment scheme.
19
+ * Handles price parsing and converts user-friendly amounts to Jetton amounts.
20
+ */
21
+ declare class ExactTonScheme implements SchemeNetworkServer {
22
+ readonly scheme = "exact";
23
+ private moneyParsers;
24
+ private config;
25
+ constructor(config?: ExactTonSchemeConfig);
26
+ /**
27
+ * Register a custom money parser in the parser chain.
28
+ * Multiple parsers can be registered - they will be tried in registration order.
29
+ * Each parser receives a decimal amount (e.g., 1.50 for $1.50).
30
+ * If a parser returns null, the next parser in the chain will be tried.
31
+ * The default parser is always the final fallback.
32
+ *
33
+ * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
34
+ * @returns The server instance for chaining
35
+ *
36
+ * @example
37
+ * tonServer.registerMoneyParser(async (amount, network) => {
38
+ * // Use custom Jetton for large amounts
39
+ * if (amount > 1000) {
40
+ * return {
41
+ * amount: (amount * 1e9).toString(),
42
+ * asset: "EQCustomJettonAddress...",
43
+ * extra: { tier: "premium" }
44
+ * };
45
+ * }
46
+ * return null; // Use next parser
47
+ * });
48
+ */
49
+ registerMoneyParser(parser: MoneyParser): ExactTonScheme;
50
+ /**
51
+ * Parses a price into an asset amount.
52
+ * If price is already an AssetAmount, returns it directly.
53
+ * If price is Money (string | number), parses to decimal and tries custom parsers.
54
+ * Falls back to default conversion if all custom parsers return null.
55
+ *
56
+ * @param price - The price to parse
57
+ * @param network - The network to use
58
+ * @returns Promise that resolves to the parsed asset amount
59
+ */
60
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
61
+ /**
62
+ * Build payment requirements for this scheme/network combination.
63
+ * Adds TON-specific fields like gas sponsor if provided by facilitator.
64
+ *
65
+ * @param paymentRequirements - Base payment requirements with amount/asset already set
66
+ * @param supportedKind - The supported kind from facilitator's /supported endpoint
67
+ * @param extensionKeys - Extensions supported by the facilitator (unused)
68
+ * @returns Enhanced payment requirements ready to be sent to clients
69
+ */
70
+ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
71
+ t402Version: number;
72
+ scheme: string;
73
+ network: Network;
74
+ extra?: Record<string, unknown>;
75
+ }, extensionKeys: string[]): Promise<PaymentRequirements>;
76
+ /**
77
+ * Parse Money (string | number) to a decimal number.
78
+ * Handles formats like "$1.50", "1.50", 1.50, etc.
79
+ *
80
+ * @param money - The money value to parse
81
+ * @returns Decimal number
82
+ */
83
+ private parseMoneyToDecimal;
84
+ /**
85
+ * Default money conversion implementation.
86
+ * Converts decimal amount to the preferred Jetton on the specified network.
87
+ *
88
+ * @param amount - The decimal amount (e.g., 1.50)
89
+ * @param network - The network to use
90
+ * @returns The parsed asset amount
91
+ */
92
+ private defaultMoneyConversion;
93
+ /**
94
+ * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)
95
+ *
96
+ * @param decimalAmount - The decimal amount to convert
97
+ * @param decimals - Number of decimals for the token
98
+ * @returns The token amount as a string
99
+ */
100
+ private convertToTokenAmount;
101
+ /**
102
+ * Get the default asset info for a network.
103
+ * Priority: configured preferredJetton > USDT > first available
104
+ *
105
+ * @param network - The network to get asset info for
106
+ * @returns The Jetton configuration
107
+ */
108
+ private getDefaultAsset;
109
+ /**
110
+ * Get Jetton info for a given symbol on a network
111
+ *
112
+ * @param symbol - The Jetton symbol (e.g., "USDT")
113
+ * @param network - The network to use
114
+ * @returns The Jetton configuration
115
+ */
116
+ private getAssetInfo;
117
+ /**
118
+ * Get the number of decimals for a Jetton on a network
119
+ *
120
+ * @param network - The network to use
121
+ * @param jettonAddress - Optional Jetton address to look up
122
+ * @returns The number of decimals for the Jetton
123
+ */
124
+ private getAssetDecimals;
125
+ /**
126
+ * Get all supported networks
127
+ */
128
+ static getSupportedNetworks(): string[];
129
+ /**
130
+ * Check if a network is supported
131
+ */
132
+ static isNetworkSupported(network: string): boolean;
133
+ }
134
+
135
+ export { ExactTonScheme, type ExactTonSchemeConfig };
@@ -0,0 +1,212 @@
1
+ import {
2
+ JETTON_REGISTRY,
3
+ getDefaultJetton,
4
+ getJettonByAddress,
5
+ getJettonConfig
6
+ } from "../../chunk-RST5PY7E.mjs";
7
+ import {
8
+ SCHEME_EXACT,
9
+ normalizeNetwork
10
+ } from "../../chunk-6LOUEHJT.mjs";
11
+
12
+ // src/exact/server/scheme.ts
13
+ var ExactTonScheme = class {
14
+ constructor(config = {}) {
15
+ this.scheme = SCHEME_EXACT;
16
+ this.moneyParsers = [];
17
+ this.config = config;
18
+ }
19
+ /**
20
+ * Register a custom money parser in the parser chain.
21
+ * Multiple parsers can be registered - they will be tried in registration order.
22
+ * Each parser receives a decimal amount (e.g., 1.50 for $1.50).
23
+ * If a parser returns null, the next parser in the chain will be tried.
24
+ * The default parser is always the final fallback.
25
+ *
26
+ * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
27
+ * @returns The server instance for chaining
28
+ *
29
+ * @example
30
+ * tonServer.registerMoneyParser(async (amount, network) => {
31
+ * // Use custom Jetton for large amounts
32
+ * if (amount > 1000) {
33
+ * return {
34
+ * amount: (amount * 1e9).toString(),
35
+ * asset: "EQCustomJettonAddress...",
36
+ * extra: { tier: "premium" }
37
+ * };
38
+ * }
39
+ * return null; // Use next parser
40
+ * });
41
+ */
42
+ registerMoneyParser(parser) {
43
+ this.moneyParsers.push(parser);
44
+ return this;
45
+ }
46
+ /**
47
+ * Parses a price into an asset amount.
48
+ * If price is already an AssetAmount, returns it directly.
49
+ * If price is Money (string | number), parses to decimal and tries custom parsers.
50
+ * Falls back to default conversion if all custom parsers return null.
51
+ *
52
+ * @param price - The price to parse
53
+ * @param network - The network to use
54
+ * @returns Promise that resolves to the parsed asset amount
55
+ */
56
+ async parsePrice(price, network) {
57
+ const normalizedNetwork = normalizeNetwork(network);
58
+ if (typeof price === "object" && price !== null && "amount" in price) {
59
+ if (!price.asset) {
60
+ throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
61
+ }
62
+ return {
63
+ amount: price.amount,
64
+ asset: price.asset,
65
+ extra: price.extra || {}
66
+ };
67
+ }
68
+ const amount = this.parseMoneyToDecimal(price);
69
+ for (const parser of this.moneyParsers) {
70
+ const result = await parser(amount, normalizedNetwork);
71
+ if (result !== null) {
72
+ return result;
73
+ }
74
+ }
75
+ return this.defaultMoneyConversion(amount, normalizedNetwork);
76
+ }
77
+ /**
78
+ * Build payment requirements for this scheme/network combination.
79
+ * Adds TON-specific fields like gas sponsor if provided by facilitator.
80
+ *
81
+ * @param paymentRequirements - Base payment requirements with amount/asset already set
82
+ * @param supportedKind - The supported kind from facilitator's /supported endpoint
83
+ * @param extensionKeys - Extensions supported by the facilitator (unused)
84
+ * @returns Enhanced payment requirements ready to be sent to clients
85
+ */
86
+ async enhancePaymentRequirements(paymentRequirements, supportedKind, extensionKeys) {
87
+ void extensionKeys;
88
+ const extra = { ...paymentRequirements.extra };
89
+ if (supportedKind.extra?.gasSponsor) {
90
+ extra.gasSponsor = supportedKind.extra.gasSponsor;
91
+ }
92
+ return {
93
+ ...paymentRequirements,
94
+ extra
95
+ };
96
+ }
97
+ /**
98
+ * Parse Money (string | number) to a decimal number.
99
+ * Handles formats like "$1.50", "1.50", 1.50, etc.
100
+ *
101
+ * @param money - The money value to parse
102
+ * @returns Decimal number
103
+ */
104
+ parseMoneyToDecimal(money) {
105
+ if (typeof money === "number") {
106
+ return money;
107
+ }
108
+ const cleanMoney = money.replace(/^\$/, "").trim();
109
+ const amount = parseFloat(cleanMoney);
110
+ if (isNaN(amount)) {
111
+ throw new Error(`Invalid money format: ${money}`);
112
+ }
113
+ return amount;
114
+ }
115
+ /**
116
+ * Default money conversion implementation.
117
+ * Converts decimal amount to the preferred Jetton on the specified network.
118
+ *
119
+ * @param amount - The decimal amount (e.g., 1.50)
120
+ * @param network - The network to use
121
+ * @returns The parsed asset amount
122
+ */
123
+ defaultMoneyConversion(amount, network) {
124
+ const jetton = this.getDefaultAsset(network);
125
+ const tokenAmount = this.convertToTokenAmount(amount.toString(), jetton.decimals);
126
+ return {
127
+ amount: tokenAmount,
128
+ asset: jetton.masterAddress,
129
+ extra: {
130
+ symbol: jetton.symbol,
131
+ name: jetton.name,
132
+ decimals: jetton.decimals
133
+ }
134
+ };
135
+ }
136
+ /**
137
+ * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)
138
+ *
139
+ * @param decimalAmount - The decimal amount to convert
140
+ * @param decimals - Number of decimals for the token
141
+ * @returns The token amount as a string
142
+ */
143
+ convertToTokenAmount(decimalAmount, decimals) {
144
+ const amount = parseFloat(decimalAmount);
145
+ if (isNaN(amount)) {
146
+ throw new Error(`Invalid amount: ${decimalAmount}`);
147
+ }
148
+ const tokenAmount = Math.floor(amount * Math.pow(10, decimals));
149
+ return tokenAmount.toString();
150
+ }
151
+ /**
152
+ * Get the default asset info for a network.
153
+ * Priority: configured preferredJetton > USDT > first available
154
+ *
155
+ * @param network - The network to get asset info for
156
+ * @returns The Jetton configuration
157
+ */
158
+ getDefaultAsset(network) {
159
+ if (this.config.preferredJetton) {
160
+ const preferred = getJettonConfig(network, this.config.preferredJetton);
161
+ if (preferred) return preferred;
162
+ }
163
+ const defaultJetton = getDefaultJetton(network);
164
+ if (defaultJetton) return defaultJetton;
165
+ throw new Error(`No Jettons configured for network ${network}`);
166
+ }
167
+ /**
168
+ * Get Jetton info for a given symbol on a network
169
+ *
170
+ * @param symbol - The Jetton symbol (e.g., "USDT")
171
+ * @param network - The network to use
172
+ * @returns The Jetton configuration
173
+ */
174
+ getAssetInfo(symbol, network) {
175
+ const jetton = getJettonConfig(network, symbol);
176
+ if (jetton) return jetton;
177
+ if (symbol.toUpperCase() === "USD") {
178
+ return this.getDefaultAsset(network);
179
+ }
180
+ throw new Error(`Unsupported Jetton: ${symbol} on network ${network}`);
181
+ }
182
+ /**
183
+ * Get the number of decimals for a Jetton on a network
184
+ *
185
+ * @param network - The network to use
186
+ * @param jettonAddress - Optional Jetton address to look up
187
+ * @returns The number of decimals for the Jetton
188
+ */
189
+ getAssetDecimals(network, jettonAddress) {
190
+ if (jettonAddress) {
191
+ const jetton = getJettonByAddress(network, jettonAddress);
192
+ if (jetton) return jetton.decimals;
193
+ }
194
+ return 6;
195
+ }
196
+ /**
197
+ * Get all supported networks
198
+ */
199
+ static getSupportedNetworks() {
200
+ return Object.keys(JETTON_REGISTRY);
201
+ }
202
+ /**
203
+ * Check if a network is supported
204
+ */
205
+ static isNetworkSupported(network) {
206
+ return network in JETTON_REGISTRY;
207
+ }
208
+ };
209
+ export {
210
+ ExactTonScheme
211
+ };
212
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/exact/server/scheme.ts"],"sourcesContent":["/**\n * TON Server Scheme Implementation\n *\n * Handles price parsing and payment requirement enhancement for\n * TON Jetton payments using the exact scheme.\n */\n\nimport type {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@t402/core/types\";\nimport { SCHEME_EXACT } from \"../../constants.js\";\nimport {\n getDefaultJetton,\n getJettonConfig,\n getJettonByAddress,\n JETTON_REGISTRY,\n} from \"../../tokens.js\";\nimport { normalizeNetwork } from \"../../utils.js\";\n\n/**\n * Configuration options for ExactTonScheme server\n */\nexport interface ExactTonSchemeConfig {\n /** Preferred Jetton symbol (e.g., \"USDT\"). Defaults to network's highest priority token. */\n preferredJetton?: string;\n}\n\n/**\n * TON server implementation for the Exact payment scheme.\n * Handles price parsing and converts user-friendly amounts to Jetton amounts.\n */\nexport class ExactTonScheme implements SchemeNetworkServer {\n readonly scheme = SCHEME_EXACT;\n private moneyParsers: MoneyParser[] = [];\n private config: ExactTonSchemeConfig;\n\n constructor(config: ExactTonSchemeConfig = {}) {\n this.config = config;\n }\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * tonServer.registerMoneyParser(async (amount, network) => {\n * // Use custom Jetton for large amounts\n * if (amount > 1000) {\n * return {\n * amount: (amount * 1e9).toString(),\n * asset: \"EQCustomJettonAddress...\",\n * extra: { tier: \"premium\" }\n * };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactTonScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // Normalize network to CAIP-2 format\n const normalizedNetwork = normalizeNetwork(network);\n\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, normalizedNetwork);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, normalizedNetwork);\n }\n\n /**\n * Build payment requirements for this scheme/network combination.\n * Adds TON-specific fields like gas sponsor if provided by facilitator.\n *\n * @param paymentRequirements - Base payment requirements with amount/asset already set\n * @param supportedKind - The supported kind from facilitator's /supported endpoint\n * @param extensionKeys - Extensions supported by the facilitator (unused)\n * @returns Enhanced payment requirements ready to be sent to clients\n */\n async enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n t402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void extensionKeys;\n\n // Start with existing extra fields\n const extra = { ...paymentRequirements.extra };\n\n // Add gas sponsor from facilitator if provided\n if (supportedKind.extra?.gasSponsor) {\n extra.gasSponsor = supportedKind.extra.gasSponsor;\n }\n\n return {\n ...paymentRequirements,\n extra,\n };\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to the preferred Jetton on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const jetton = this.getDefaultAsset(network);\n\n // Convert decimal amount to token amount\n const tokenAmount = this.convertToTokenAmount(amount.toString(), jetton.decimals);\n\n return {\n amount: tokenAmount,\n asset: jetton.masterAddress,\n extra: {\n symbol: jetton.symbol,\n name: jetton.name,\n decimals: jetton.decimals,\n },\n };\n }\n\n /**\n * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)\n *\n * @param decimalAmount - The decimal amount to convert\n * @param decimals - Number of decimals for the token\n * @returns The token amount as a string\n */\n private convertToTokenAmount(decimalAmount: string, decimals: number): string {\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDT with 6 decimals: 0.10 * 10^6 = 100000)\n const tokenAmount = Math.floor(amount * Math.pow(10, decimals));\n return tokenAmount.toString();\n }\n\n /**\n * Get the default asset info for a network.\n * Priority: configured preferredJetton > USDT > first available\n *\n * @param network - The network to get asset info for\n * @returns The Jetton configuration\n */\n private getDefaultAsset(\n network: Network,\n ): { masterAddress: string; symbol: string; name: string; decimals: number } {\n // If a preferred Jetton is configured, try to use it\n if (this.config.preferredJetton) {\n const preferred = getJettonConfig(network, this.config.preferredJetton);\n if (preferred) return preferred;\n }\n\n // Use the network's default token (sorted by priority)\n const defaultJetton = getDefaultJetton(network);\n if (defaultJetton) return defaultJetton;\n\n throw new Error(`No Jettons configured for network ${network}`);\n }\n\n /**\n * Get Jetton info for a given symbol on a network\n *\n * @param symbol - The Jetton symbol (e.g., \"USDT\")\n * @param network - The network to use\n * @returns The Jetton configuration\n */\n private getAssetInfo(\n symbol: string,\n network: Network,\n ): { masterAddress: string; symbol: string; name: string; decimals: number } {\n const jetton = getJettonConfig(network, symbol);\n if (jetton) return jetton;\n\n // Fallback: treat \"USD\" as request for default stablecoin\n if (symbol.toUpperCase() === \"USD\") {\n return this.getDefaultAsset(network);\n }\n\n throw new Error(`Unsupported Jetton: ${symbol} on network ${network}`);\n }\n\n /**\n * Get the number of decimals for a Jetton on a network\n *\n * @param network - The network to use\n * @param jettonAddress - Optional Jetton address to look up\n * @returns The number of decimals for the Jetton\n */\n private getAssetDecimals(network: Network, jettonAddress?: string): number {\n if (jettonAddress) {\n const jetton = getJettonByAddress(network, jettonAddress);\n if (jetton) return jetton.decimals;\n }\n // Default to 6 decimals (USDT standard)\n return 6;\n }\n\n /**\n * Get all supported networks\n */\n static getSupportedNetworks(): string[] {\n return Object.keys(JETTON_REGISTRY);\n }\n\n /**\n * Check if a network is supported\n */\n static isNetworkSupported(network: string): boolean {\n return network in JETTON_REGISTRY;\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,293 @@
1
+ export { ExactTonScheme } from './exact/client/index.mjs';
2
+ export { C as ClientTonSigner, b as ExactTonPayload, E as ExactTonPayloadV2, F as FacilitatorTonSigner, S as SignMessageParams, T as TransactionConfirmation, V as VerifyMessageParams, c as VerifyMessageResult, W as WaitForTransactionParams, t as toClientTonSigner, a as toFacilitatorTonSigner } from './signer-CFiw2DST.mjs';
3
+ import { Address, Cell } from '@ton/core';
4
+ import { Network } from '@t402/core/types';
5
+
6
+ /**
7
+ * TON Jetton Token Configuration
8
+ *
9
+ * This module provides comprehensive Jetton token definitions including:
10
+ * - USDT (Tether USD on TON)
11
+ * - Network-specific configurations
12
+ * - Helper functions for token lookups
13
+ */
14
+ /**
15
+ * Jetton token configuration
16
+ */
17
+ interface JettonConfig {
18
+ /** Jetton master contract address (friendly format) */
19
+ masterAddress: string;
20
+ /** Token symbol */
21
+ symbol: string;
22
+ /** Token name */
23
+ name: string;
24
+ /** Number of decimal places */
25
+ decimals: number;
26
+ /** Payment priority (lower = higher priority) */
27
+ priority: number;
28
+ }
29
+ /**
30
+ * Network token registry mapping network -> symbol -> config
31
+ */
32
+ type NetworkJettonRegistry = Record<string, Record<string, JettonConfig>>;
33
+ /**
34
+ * USDT Jetton Master Contract Addresses by Network
35
+ *
36
+ * USDT on TON follows the TEP-74 Jetton standard.
37
+ * @see https://docs.tether.to/tether-on-ton
38
+ */
39
+ declare const USDT_ADDRESSES: Record<string, string>;
40
+ /**
41
+ * Complete Jetton registry with all supported tokens per network
42
+ */
43
+ declare const JETTON_REGISTRY: NetworkJettonRegistry;
44
+ /**
45
+ * Get Jetton configuration for a specific token on a network
46
+ *
47
+ * @param network - Network identifier (CAIP-2 format)
48
+ * @param symbol - Token symbol (e.g., "USDT")
49
+ * @returns Jetton configuration or undefined
50
+ */
51
+ declare function getJettonConfig(network: string, symbol: string): JettonConfig | undefined;
52
+ /**
53
+ * Get all Jettons available on a network
54
+ *
55
+ * @param network - Network identifier
56
+ * @returns Array of Jetton configurations sorted by priority
57
+ */
58
+ declare function getNetworkJettons(network: string): JettonConfig[];
59
+ /**
60
+ * Get the default/preferred Jetton for a network
61
+ * Prefers USDT based on priority
62
+ *
63
+ * @param network - Network identifier
64
+ * @returns Default Jetton configuration or undefined
65
+ */
66
+ declare function getDefaultJetton(network: string): JettonConfig | undefined;
67
+ /**
68
+ * Get Jetton by master contract address on a network
69
+ *
70
+ * @param network - Network identifier
71
+ * @param address - Jetton master contract address
72
+ * @returns Jetton configuration or undefined
73
+ */
74
+ declare function getJettonByAddress(network: string, address: string): JettonConfig | undefined;
75
+ /**
76
+ * Get all networks that support a specific Jetton
77
+ *
78
+ * @param symbol - Token symbol
79
+ * @returns Array of network identifiers
80
+ */
81
+ declare function getNetworksForJetton(symbol: string): string[];
82
+ /**
83
+ * Get USDT networks on TON
84
+ *
85
+ * @returns Array of networks supporting USDT
86
+ */
87
+ declare function getUsdtNetworks(): string[];
88
+ /**
89
+ * Check if a network is supported
90
+ *
91
+ * @param network - Network identifier to check
92
+ * @returns true if network has configured Jettons
93
+ */
94
+ declare function isNetworkSupported(network: string): boolean;
95
+ /**
96
+ * Get all supported networks
97
+ *
98
+ * @returns Array of all supported network identifiers
99
+ */
100
+ declare function getSupportedNetworks(): string[];
101
+
102
+ /**
103
+ * TON Network Constants
104
+ *
105
+ * This module provides constants for TON blockchain integration including:
106
+ * - CAIP-2 network identifiers
107
+ * - RPC endpoints
108
+ * - Jetton transfer operation codes
109
+ * - Default gas amounts
110
+ */
111
+ /**
112
+ * CAIP-2 Network Identifiers for TON
113
+ * Using simple identifiers for mainnet/testnet
114
+ */
115
+ declare const TON_MAINNET_CAIP2 = "ton:mainnet";
116
+ declare const TON_TESTNET_CAIP2 = "ton:testnet";
117
+ /**
118
+ * Supported TON networks
119
+ */
120
+ declare const TON_NETWORKS: readonly ["ton:mainnet", "ton:testnet"];
121
+ type TonNetwork = (typeof TON_NETWORKS)[number];
122
+ /**
123
+ * Default RPC endpoints (TonCenter API v2)
124
+ */
125
+ declare const TON_MAINNET_ENDPOINT = "https://toncenter.com/api/v2/jsonRPC";
126
+ declare const TON_TESTNET_ENDPOINT = "https://testnet.toncenter.com/api/v2/jsonRPC";
127
+ /**
128
+ * TON API v4 endpoints (for @ton/ton TonClient4)
129
+ */
130
+ declare const TON_MAINNET_V4_ENDPOINT = "https://mainnet-v4.tonhubapi.com";
131
+ declare const TON_TESTNET_V4_ENDPOINT = "https://testnet-v4.tonhubapi.com";
132
+ /**
133
+ * Network endpoint mapping
134
+ */
135
+ declare const NETWORK_ENDPOINTS: Record<string, string>;
136
+ declare const NETWORK_V4_ENDPOINTS: Record<string, string>;
137
+ /**
138
+ * Jetton Transfer Operation Codes (TEP-74)
139
+ * @see https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md
140
+ */
141
+ declare const JETTON_TRANSFER_OP = 260734629;
142
+ declare const JETTON_INTERNAL_TRANSFER_OP = 395134233;
143
+ declare const JETTON_TRANSFER_NOTIFICATION_OP = 1935855772;
144
+ declare const JETTON_BURN_OP = 1499400124;
145
+ /**
146
+ * Default gas amounts for Jetton transfers
147
+ * TON requires attaching TON for gas to internal messages
148
+ */
149
+ declare const DEFAULT_JETTON_TRANSFER_TON = 100000000n;
150
+ declare const DEFAULT_FORWARD_TON = 1n;
151
+ declare const MIN_JETTON_TRANSFER_TON = 50000000n;
152
+ /**
153
+ * Maximum gas amounts to prevent excessive fees
154
+ */
155
+ declare const MAX_JETTON_TRANSFER_TON = 500000000n;
156
+ /**
157
+ * Scheme identifier for exact payments
158
+ */
159
+ declare const SCHEME_EXACT = "exact";
160
+ /**
161
+ * Default timeout for payment validity (in seconds)
162
+ */
163
+ declare const DEFAULT_VALIDITY_DURATION = 3600;
164
+
165
+ /**
166
+ * TON Utility Functions
167
+ *
168
+ * Helper functions for TON address handling, message building,
169
+ * and network operations.
170
+ */
171
+
172
+ /**
173
+ * Normalize network identifier to CAIP-2 format
174
+ *
175
+ * @param network - Network identifier (may be legacy format)
176
+ * @returns Normalized CAIP-2 network identifier
177
+ * @throws Error if network is not supported
178
+ */
179
+ declare function normalizeNetwork(network: Network): Network;
180
+ /**
181
+ * Get RPC endpoint for a network
182
+ *
183
+ * @param network - Network identifier
184
+ * @returns RPC endpoint URL
185
+ */
186
+ declare function getEndpoint(network: Network): string;
187
+ /**
188
+ * Check if a network identifier is a supported TON network
189
+ *
190
+ * @param network - Network identifier to check
191
+ * @returns true if supported
192
+ */
193
+ declare function isTonNetwork(network: string): boolean;
194
+ /**
195
+ * Validate TON address format
196
+ *
197
+ * @param address - Address to validate
198
+ * @returns true if valid TON address
199
+ */
200
+ declare function validateTonAddress(address: string): boolean;
201
+ /**
202
+ * Parse TON address from string
203
+ *
204
+ * @param address - Address string (friendly or raw format)
205
+ * @returns Parsed Address object
206
+ * @throws Error if invalid format
207
+ */
208
+ declare function parseTonAddress(address: string): Address;
209
+ /**
210
+ * Compare two TON addresses for equality
211
+ * Handles different address formats (friendly, raw, bounceable/non-bounceable)
212
+ *
213
+ * @param addr1 - First address
214
+ * @param addr2 - Second address
215
+ * @returns true if addresses are equal
216
+ */
217
+ declare function addressesEqual(addr1: string, addr2: string): boolean;
218
+ /**
219
+ * Format address to friendly format
220
+ *
221
+ * @param address - Address to format
222
+ * @param options - Formatting options
223
+ * @returns Friendly format address string
224
+ */
225
+ declare function formatAddress(address: string | Address, options?: {
226
+ bounceable?: boolean;
227
+ testOnly?: boolean;
228
+ }): string;
229
+ /**
230
+ * Convert decimal amount to smallest units (e.g., nano-Jettons)
231
+ *
232
+ * @param decimalAmount - Amount in decimal format (e.g., "1.50")
233
+ * @param decimals - Number of decimal places
234
+ * @returns Amount in smallest units as string
235
+ */
236
+ declare function convertToJettonAmount(decimalAmount: string, decimals: number): string;
237
+ /**
238
+ * Convert smallest units to decimal amount
239
+ *
240
+ * @param jettonAmount - Amount in smallest units
241
+ * @param decimals - Number of decimal places
242
+ * @returns Amount in decimal format as string
243
+ */
244
+ declare function convertFromJettonAmount(jettonAmount: string | bigint, decimals: number): string;
245
+ /**
246
+ * Generate a unique query ID for Jetton transfer
247
+ * Uses timestamp + random component for uniqueness
248
+ *
249
+ * @returns BigInt query ID
250
+ */
251
+ declare function generateQueryId(): bigint;
252
+ /**
253
+ * Build Jetton transfer message body (TEP-74)
254
+ *
255
+ * @param params - Transfer parameters
256
+ * @returns Cell containing the transfer message
257
+ */
258
+ declare function buildJettonTransferBody(params: {
259
+ queryId: bigint;
260
+ amount: bigint;
261
+ destination: Address;
262
+ responseDestination: Address;
263
+ forwardAmount?: bigint;
264
+ forwardPayload?: Cell;
265
+ }): Cell;
266
+ /**
267
+ * Parse Jetton transfer message from Cell
268
+ *
269
+ * @param body - Cell containing the message
270
+ * @returns Parsed transfer parameters
271
+ * @throws Error if not a valid Jetton transfer message
272
+ */
273
+ declare function parseJettonTransferBody(body: Cell): {
274
+ op: number;
275
+ queryId: bigint;
276
+ amount: bigint;
277
+ destination: Address;
278
+ responseDestination: Address;
279
+ forwardAmount: bigint;
280
+ forwardPayload?: Cell;
281
+ };
282
+ /**
283
+ * Calculate estimated gas for Jetton transfer
284
+ * Based on typical TON network fees
285
+ *
286
+ * @param params - Optional parameters for estimation
287
+ * @returns Estimated gas in nanoTON
288
+ */
289
+ declare function estimateJettonTransferGas(_params?: {
290
+ hasForwardPayload?: boolean;
291
+ }): bigint;
292
+
293
+ export { DEFAULT_FORWARD_TON, DEFAULT_JETTON_TRANSFER_TON, DEFAULT_VALIDITY_DURATION, JETTON_BURN_OP, JETTON_INTERNAL_TRANSFER_OP, JETTON_REGISTRY, JETTON_TRANSFER_NOTIFICATION_OP, JETTON_TRANSFER_OP, type JettonConfig, MAX_JETTON_TRANSFER_TON, MIN_JETTON_TRANSFER_TON, NETWORK_ENDPOINTS, NETWORK_V4_ENDPOINTS, type NetworkJettonRegistry, SCHEME_EXACT, TON_MAINNET_CAIP2, TON_MAINNET_ENDPOINT, TON_MAINNET_V4_ENDPOINT, TON_NETWORKS, TON_TESTNET_CAIP2, TON_TESTNET_ENDPOINT, TON_TESTNET_V4_ENDPOINT, type TonNetwork, USDT_ADDRESSES, addressesEqual, buildJettonTransferBody, convertFromJettonAmount, convertToJettonAmount, estimateJettonTransferGas, formatAddress, generateQueryId, getDefaultJetton, getEndpoint, getJettonByAddress, getJettonConfig, getNetworkJettons, getNetworksForJetton, getSupportedNetworks, getUsdtNetworks, isNetworkSupported, isTonNetwork, normalizeNetwork, parseJettonTransferBody, parseTonAddress, validateTonAddress };