@getomnichain/omnichain 0.6.3 → 0.7.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 (104) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/cjs/chain_ids.js +2 -2
  3. package/dist/cjs/chain_ids.js.map +1 -1
  4. package/dist/cjs/errors.js +6 -0
  5. package/dist/cjs/errors.js.map +1 -1
  6. package/dist/cjs/index.js +1 -1
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/ton/index.js +12 -0
  9. package/dist/cjs/ton/index.js.map +1 -1
  10. package/dist/cjs/ton/ton_address.js +72 -14
  11. package/dist/cjs/ton/ton_address.js.map +1 -1
  12. package/dist/cjs/ton/ton_asset.js +21 -0
  13. package/dist/cjs/ton/ton_asset.js.map +1 -0
  14. package/dist/cjs/ton/ton_assets.js +10 -0
  15. package/dist/cjs/ton/ton_assets.js.map +1 -0
  16. package/dist/cjs/ton/ton_chain.js +483 -0
  17. package/dist/cjs/ton/ton_chain.js.map +1 -0
  18. package/dist/cjs/ton/ton_chains.js +21 -0
  19. package/dist/cjs/ton/ton_chains.js.map +1 -0
  20. package/dist/cjs/ton/ton_jetton_metadata.js +107 -0
  21. package/dist/cjs/ton/ton_jetton_metadata.js.map +1 -0
  22. package/dist/cjs/ton/ton_messages.js +174 -0
  23. package/dist/cjs/ton/ton_messages.js.map +1 -0
  24. package/dist/cjs/ton/ton_provider.js +456 -0
  25. package/dist/cjs/ton/ton_provider.js.map +1 -0
  26. package/dist/cjs/ton/ton_tonapi.js +243 -0
  27. package/dist/cjs/ton/ton_tonapi.js.map +1 -0
  28. package/dist/cjs/ton/ton_toncenter.js +252 -0
  29. package/dist/cjs/ton/ton_toncenter.js.map +1 -0
  30. package/dist/cjs/ton/ton_transaction_status.js +231 -0
  31. package/dist/cjs/ton/ton_transaction_status.js.map +1 -0
  32. package/dist/cjs/ton/ton_transactions.js +107 -0
  33. package/dist/cjs/ton/ton_transactions.js.map +1 -0
  34. package/dist/cjs/ton/ton_wallet.js +285 -0
  35. package/dist/cjs/ton/ton_wallet.js.map +1 -0
  36. package/dist/esm/chain_ids.js +2 -2
  37. package/dist/esm/chain_ids.js.map +1 -1
  38. package/dist/esm/errors.d.ts +3 -0
  39. package/dist/esm/errors.d.ts.map +1 -1
  40. package/dist/esm/errors.js +5 -0
  41. package/dist/esm/errors.js.map +1 -1
  42. package/dist/esm/index.d.ts +1 -1
  43. package/dist/esm/index.d.ts.map +1 -1
  44. package/dist/esm/index.js +1 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/ton/index.d.ts +12 -0
  47. package/dist/esm/ton/index.d.ts.map +1 -1
  48. package/dist/esm/ton/index.js +12 -0
  49. package/dist/esm/ton/index.js.map +1 -1
  50. package/dist/esm/ton/ton_address.d.ts +26 -2
  51. package/dist/esm/ton/ton_address.d.ts.map +1 -1
  52. package/dist/esm/ton/ton_address.js +70 -14
  53. package/dist/esm/ton/ton_address.js.map +1 -1
  54. package/dist/esm/ton/ton_asset.d.ts +12 -0
  55. package/dist/esm/ton/ton_asset.d.ts.map +1 -0
  56. package/dist/esm/ton/ton_asset.js +17 -0
  57. package/dist/esm/ton/ton_asset.js.map +1 -0
  58. package/dist/esm/ton/ton_assets.d.ts +6 -0
  59. package/dist/esm/ton/ton_assets.d.ts.map +1 -0
  60. package/dist/esm/ton/ton_assets.js +7 -0
  61. package/dist/esm/ton/ton_assets.js.map +1 -0
  62. package/dist/esm/ton/ton_chain.d.ts +205 -0
  63. package/dist/esm/ton/ton_chain.d.ts.map +1 -0
  64. package/dist/esm/ton/ton_chain.js +479 -0
  65. package/dist/esm/ton/ton_chain.js.map +1 -0
  66. package/dist/esm/ton/ton_chains.d.ts +11 -0
  67. package/dist/esm/ton/ton_chains.d.ts.map +1 -0
  68. package/dist/esm/ton/ton_chains.js +18 -0
  69. package/dist/esm/ton/ton_chains.js.map +1 -0
  70. package/dist/esm/ton/ton_jetton_metadata.d.ts +36 -0
  71. package/dist/esm/ton/ton_jetton_metadata.d.ts.map +1 -0
  72. package/dist/esm/ton/ton_jetton_metadata.js +103 -0
  73. package/dist/esm/ton/ton_jetton_metadata.js.map +1 -0
  74. package/dist/esm/ton/ton_messages.d.ts +133 -0
  75. package/dist/esm/ton/ton_messages.d.ts.map +1 -0
  76. package/dist/esm/ton/ton_messages.js +159 -0
  77. package/dist/esm/ton/ton_messages.js.map +1 -0
  78. package/dist/esm/ton/ton_provider.d.ts +261 -0
  79. package/dist/esm/ton/ton_provider.d.ts.map +1 -0
  80. package/dist/esm/ton/ton_provider.js +432 -0
  81. package/dist/esm/ton/ton_provider.js.map +1 -0
  82. package/dist/esm/ton/ton_tonapi.d.ts +39 -0
  83. package/dist/esm/ton/ton_tonapi.d.ts.map +1 -0
  84. package/dist/esm/ton/ton_tonapi.js +239 -0
  85. package/dist/esm/ton/ton_tonapi.js.map +1 -0
  86. package/dist/esm/ton/ton_toncenter.d.ts +25 -0
  87. package/dist/esm/ton/ton_toncenter.d.ts.map +1 -0
  88. package/dist/esm/ton/ton_toncenter.js +248 -0
  89. package/dist/esm/ton/ton_toncenter.js.map +1 -0
  90. package/dist/esm/ton/ton_transaction_status.d.ts +116 -0
  91. package/dist/esm/ton/ton_transaction_status.d.ts.map +1 -0
  92. package/dist/esm/ton/ton_transaction_status.js +226 -0
  93. package/dist/esm/ton/ton_transaction_status.js.map +1 -0
  94. package/dist/esm/ton/ton_transactions.d.ts +54 -0
  95. package/dist/esm/ton/ton_transactions.d.ts.map +1 -0
  96. package/dist/esm/ton/ton_transactions.js +100 -0
  97. package/dist/esm/ton/ton_transactions.js.map +1 -0
  98. package/dist/esm/ton/ton_wallet.d.ts +134 -0
  99. package/dist/esm/ton/ton_wallet.d.ts.map +1 -0
  100. package/dist/esm/ton/ton_wallet.js +278 -0
  101. package/dist/esm/ton/ton_wallet.js.map +1 -0
  102. package/docs/README.md +2 -1
  103. package/docs/ton.md +164 -0
  104. package/package.json +5 -1
@@ -0,0 +1,479 @@
1
+ import { SendMode } from '@ton/core';
2
+ import { signVerify } from '@ton/crypto';
3
+ import { Chain, resolveTransferAmount, } from "../chain.base.js";
4
+ import { ChainType } from "../chain_type.js";
5
+ import { ChainError, ChainErrorKinds } from "../errors.js";
6
+ import { NetworkType } from "../network_type.js";
7
+ import { AssetBalanceChange } from "../transaction_status.js";
8
+ import { TonAddress, tonRawAddress } from "./ton_address.js";
9
+ import { TonAsset } from "./ton_asset.js";
10
+ import { readTonJettonMetadata } from "./ton_jetton_metadata.js";
11
+ import { TON_JETTON_TRANSFER_OP, TonSignedMessage, tonCommentBody, tonJettonTransferBody, tonMessageHash, tonWalletRequestFields, } from "./ton_messages.js";
12
+ import { TonBroadcastUncertainError, TonFallbackProvider, TonProviderError, assertTonTxHash, } from "./ton_provider.js";
13
+ import { ToncenterProvider } from "./ton_toncenter.js";
14
+ import { TonapiProvider } from "./ton_tonapi.js";
15
+ import { TonTransactionStatus, summarizeTonTrace } from "./ton_transaction_status.js";
16
+ import { TonUnsignedTransaction, tonExternalBocHash } from "./ton_transactions.js";
17
+ /** TON a jetton transfer carries to the sender's jetton wallet; the excess returns to `responseDestination`. */
18
+ export const DEFAULT_JETTON_TRANSFER_ATTACHED_NANOTON = 50000000n;
19
+ /** TON forwarded to the jetton recipient with the transfer notification. */
20
+ export const DEFAULT_JETTON_FORWARD_NANOTON = 1n;
21
+ /**
22
+ * How far past a request's `validUntil` the masterchain must be before the
23
+ * request counts as expired; shard blocks and the provider's state can trail
24
+ * the masterchain head by a few seconds.
25
+ */
26
+ export const REQUEST_EXPIRY_MARGIN_SECONDS = 60;
27
+ function strictHex(value, bytes, what) {
28
+ if (!new RegExp(`^[0-9a-fA-F]{${bytes * 2}}$`).test(value)) {
29
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `A TON ${what} is ${bytes * 2} hex characters`);
30
+ }
31
+ return Buffer.from(value, 'hex');
32
+ }
33
+ /**
34
+ * A TON chain, read through TON Center v3 with TonAPI as the fallback.
35
+ *
36
+ * Transaction ids are normalized external-message hashes (lowercase hex), and
37
+ * a transaction's status covers its whole trace.
38
+ */
39
+ export class TonChain extends Chain {
40
+ #init;
41
+ #jettons = new Map();
42
+ #provider;
43
+ _nativeAsset;
44
+ constructor(init) {
45
+ super(init.chainId, init.name, NetworkType.TON, 5, 'TON', init.explorerUrl);
46
+ this.#init = init;
47
+ this.#provider = init.provider ?? null;
48
+ this._nativeAsset = new TonAsset(init.chainId, 'TON', null, TonAsset.NATIVE_DECIMALS);
49
+ }
50
+ /** The configured provider, built on first use so a chain without keys can still be constructed. */
51
+ get provider() {
52
+ if (this.#provider === null) {
53
+ const toncenter = endpointOf('TON Center', this.#init.toncenter, 'TONCENTER_API_KEY');
54
+ if (toncenter === null) {
55
+ throw new ChainError(ChainErrorKinds.RpcNotConfigured, `${this.name}: a TON Center API key is required`, {
56
+ chainId: this.chainId,
57
+ });
58
+ }
59
+ const tonapi = this.#init.tonapi === undefined || this.#init.tonapi === null
60
+ ? null
61
+ : endpointOf('TonAPI', this.#init.tonapi, 'TONAPI_API_KEY');
62
+ this.#provider = new TonFallbackProvider(new ToncenterProvider(toncenter), tonapi === null ? null : new TonapiProvider(tonapi));
63
+ }
64
+ return this.#provider;
65
+ }
66
+ get chainType() {
67
+ return ChainType.TON;
68
+ }
69
+ get nativeToken() {
70
+ return this._nativeAsset;
71
+ }
72
+ get nativeAsset() {
73
+ return this._nativeAsset;
74
+ }
75
+ getWalletExplorerUrl(address) {
76
+ return `${this.explorerBaseUrl}/${new TonAddress(address).toUserFriendly({ bounceable: false })}`;
77
+ }
78
+ /** A jetton master is a contract, so its link uses the bounceable (`EQ…`) form. */
79
+ getTokenExplorerUrl(tokenIdentifier) {
80
+ if (tokenIdentifier === undefined)
81
+ return this.explorerBaseUrl;
82
+ return `${this.explorerBaseUrl}/${new TonAddress(tokenIdentifier).toUserFriendly({ bounceable: true })}`;
83
+ }
84
+ /** `null` for native TON. */
85
+ getAssetExplorerUrl(asset) {
86
+ if (!(asset instanceof TonAsset)) {
87
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `Invalid asset ${String(asset)}, expected TonAsset`, { chainId: this.chainId });
88
+ }
89
+ return asset.jettonMaster === null ? null : this.getTokenExplorerUrl(asset.jettonMaster);
90
+ }
91
+ getTransactionExplorerUrl(txHash) {
92
+ return `${this.explorerBaseUrl}/transaction/${txHash}`;
93
+ }
94
+ validateAddress(raw) {
95
+ try {
96
+ const { workchain } = new TonAddress(raw);
97
+ return workchain === 0 || workchain === -1;
98
+ }
99
+ catch {
100
+ return false;
101
+ }
102
+ }
103
+ validateTokenIdentifier(raw) {
104
+ return raw === undefined || this.validateAddress(raw);
105
+ }
106
+ getAccountState(address) {
107
+ return this.provider.getAccountState(tonRawAddress(address));
108
+ }
109
+ /**
110
+ * The wallet's seqno, read live from its get-method rather than from the
111
+ * indexed account state, which can trail a deploy; 0 while it has no code.
112
+ */
113
+ getSeqno(address) {
114
+ return this.provider.getSeqno(tonRawAddress(address));
115
+ }
116
+ /**
117
+ * Native TON for no identifier; otherwise the jetton whose master
118
+ * `identifier` names, its symbol and decimals read from its TEP-64
119
+ * metadata ({@link getJettonMetadata}). Resolved jettons are kept for the
120
+ * chain's lifetime.
121
+ */
122
+ async resolveAsset(identifier) {
123
+ if (identifier === null || identifier === undefined)
124
+ return this._nativeAsset;
125
+ const master = tonRawAddress(identifier);
126
+ const known = this.#jettons.get(master);
127
+ if (known !== undefined)
128
+ return known;
129
+ const metadata = await this.getJettonMetadata(master);
130
+ // As Python does: a jetton whose metadata names no symbol is called by its address's first characters.
131
+ const symbol = metadata.symbol ?? new TonAddress(master).toUserFriendly({ bounceable: true }).slice(0, 4);
132
+ const asset = new TonAsset(this.chainId, symbol, master, metadata.decimals);
133
+ this.#jettons.set(master, asset);
134
+ return asset;
135
+ }
136
+ /**
137
+ * A jetton's TEP-64 metadata: the master's `get_jetton_data` content, and the
138
+ * off-chain JSON its URI names (https) for what the content lacks. Throws
139
+ * `InvalidTokenIdentifier` for anything that is not a jetton master, and
140
+ * (retryably) when the decimals cannot be read.
141
+ */
142
+ async getJettonMetadata(jettonMaster) {
143
+ return readTonJettonMetadata(await this.provider.getJettonContent(tonRawAddress(jettonMaster)), this.#init.fetchMetadata);
144
+ }
145
+ createAsset(symbol, identifier, decimals) {
146
+ if (identifier === null || identifier === undefined) {
147
+ if (symbol !== 'TON' || decimals !== TonAsset.NATIVE_DECIMALS) {
148
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `Native TON is TON with ${TonAsset.NATIVE_DECIMALS} decimals`, { chainId: this.chainId });
149
+ }
150
+ return this._nativeAsset;
151
+ }
152
+ return this.getJettonAsset(symbol, identifier, decimals);
153
+ }
154
+ getJettonAsset(symbol, jettonMaster, decimals) {
155
+ return new TonAsset(this.chainId, symbol, jettonMaster, decimals);
156
+ }
157
+ /** The jetton wallet `owner` has (or will have) for `jettonMaster`, raw. */
158
+ getJettonWalletAddress(jettonMaster, owner) {
159
+ return this.provider.getJettonWalletAddress(tonRawAddress(jettonMaster), tonRawAddress(owner));
160
+ }
161
+ /** Nanotons, or the jetton's smallest unit when `tokenIdentifier` is a jetton master. */
162
+ async getBalance(owner, tokenIdentifier) {
163
+ if (tokenIdentifier === undefined)
164
+ return (await this.getAccountState(owner)).balance;
165
+ return this.provider.getJettonBalance(await this.getJettonWalletAddress(tokenIdentifier, owner));
166
+ }
167
+ /**
168
+ * A transfer from `from`: native TON (with `memo` as a text comment), or a
169
+ * jetton through the sender's jetton wallet, the excess returned to the
170
+ * sender. `amountHr` takes the jetton's decimals from its metadata.
171
+ *
172
+ * - `isFullBalance`: native TON sends everything the wallet holds (send mode
173
+ * 128 + 2, value 0); a jetton sends the jetton wallet's whole balance.
174
+ * - Native `bounce`, unless given: only to a bounceable (`EQ…`) address
175
+ * that is deployed — a contract that fails then returns the TON, and a
176
+ * wallet not deployed yet still receives it, as TON wallets send.
177
+ * - Jetton transfers are always bounceable unless `bounce` says otherwise,
178
+ * carry {@link DEFAULT_JETTON_TRANSFER_ATTACHED_NANOTON} and forward
179
+ * {@link DEFAULT_JETTON_FORWARD_NANOTON}; `jettonAttachedNanoton`,
180
+ * `forwardTonAmountNanoton` and `sendMode` override.
181
+ */
182
+ async createTransferUnsignedTransaction(req) {
183
+ if (req.from === undefined) {
184
+ throw new ChainError(ChainErrorKinds.InvalidArgument, 'TON transfers need `from`', { chainId: this.chainId });
185
+ }
186
+ if (req.gasPricing !== undefined) {
187
+ throw new ChainError(ChainErrorKinds.InvalidArgument, 'TON transfers take no gasPricing', { chainId: this.chainId });
188
+ }
189
+ const from = req.from;
190
+ const comment = req.memo === undefined ? undefined : tonCommentBody(req.memo);
191
+ const jettonMaster = req.tokenIdentifier;
192
+ if (jettonMaster === undefined) {
193
+ const resolved = resolveTransferAmount(req, TonAsset.NATIVE_DECIMALS);
194
+ const full = resolved.kind === 'full';
195
+ return new TonUnsignedTransaction({
196
+ chainId: this.chainId,
197
+ walletAddress: from,
198
+ messages: [
199
+ {
200
+ to: req.to,
201
+ value: full ? 0n : resolved.amountMr,
202
+ body: comment,
203
+ bounce: req.bounce ?? (await this.bouncesByDefault(req.to)),
204
+ mode: req.sendMode ?? (full ? SendMode.CARRY_ALL_REMAINING_BALANCE | SendMode.IGNORE_ERRORS : undefined),
205
+ },
206
+ ],
207
+ });
208
+ }
209
+ // Only a human-readable amount needs the jetton's decimals, and so its metadata.
210
+ const decimals = req.amountHr === undefined ? 0 : (await this.resolveAsset(jettonMaster)).decimals;
211
+ const resolved = resolveTransferAmount(req, decimals);
212
+ const amount = resolved.kind === 'full' ? await this.getBalance(from, jettonMaster) : resolved.amountMr;
213
+ if (amount === 0n) {
214
+ throw new ChainError(ChainErrorKinds.InsufficientFunds, `${from} holds none of ${jettonMaster}`, { chainId: this.chainId });
215
+ }
216
+ return new TonUnsignedTransaction({
217
+ chainId: this.chainId,
218
+ walletAddress: from,
219
+ messages: [
220
+ {
221
+ to: await this.getJettonWalletAddress(jettonMaster, from),
222
+ value: req.jettonAttachedNanoton ?? DEFAULT_JETTON_TRANSFER_ATTACHED_NANOTON,
223
+ bounce: req.bounce ?? true,
224
+ mode: req.sendMode,
225
+ body: tonJettonTransferBody({
226
+ amount,
227
+ destination: req.to,
228
+ responseDestination: from,
229
+ forwardTonAmount: req.forwardTonAmountNanoton ?? DEFAULT_JETTON_FORWARD_NANOTON,
230
+ forwardPayload: comment,
231
+ }),
232
+ },
233
+ ],
234
+ });
235
+ }
236
+ /**
237
+ * Emulates the whole trace of an external message (signature ignored): what
238
+ * it would cost, and whether every transaction would succeed with nothing
239
+ * bounced. Throws `SimulationFailed` when the message would be refused
240
+ * outright.
241
+ */
242
+ async emulate(boc) {
243
+ const trace = await this.provider.emulate(boc);
244
+ const summary = summarizeTonTrace(this.chainId, trace);
245
+ await this.addJettonBalanceChanges(trace, summary.jettonCredits, summary.balanceChanges);
246
+ return { trace, ...summary };
247
+ }
248
+ /**
249
+ * Sends an external message (base64 BOC or bytes) and returns its normalized
250
+ * hash. Throws `TonBroadcastUncertainError` when the message may have reached
251
+ * the network anyway; re-signing then can pay twice.
252
+ */
253
+ async broadcast(signed, opts) {
254
+ if (opts?.signal !== undefined) {
255
+ throw new ChainError(ChainErrorKinds.FeatureNotSupported, 'TON broadcast does not take a signal', { chainId: this.chainId });
256
+ }
257
+ const boc = typeof signed === 'string' ? signed : Buffer.from(signed).toString('base64');
258
+ const hash = tonExternalBocHash(boc);
259
+ try {
260
+ await this.provider.sendBoc(boc);
261
+ }
262
+ catch (err) {
263
+ if (err instanceof TonBroadcastUncertainError) {
264
+ throw new TonBroadcastUncertainError(err.message, { chainId: this.chainId, txHash: hash }, err);
265
+ }
266
+ if (err instanceof TonProviderError) {
267
+ throw new ChainError(err.kind, err.message, { chainId: this.chainId, txHash: hash }, err);
268
+ }
269
+ throw err;
270
+ }
271
+ return hash;
272
+ }
273
+ broadcastSignedTransaction(signed) {
274
+ if (signed.chainId !== this.chainId) {
275
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `Signed for chain ${signed.chainId}, not ${this.chainId}`);
276
+ }
277
+ return this.broadcast(signed.boc);
278
+ }
279
+ async getTransactionStatus(hashOrHashes, opts = {}) {
280
+ if (Array.isArray(hashOrHashes)) {
281
+ const statuses = [];
282
+ for (const hash of hashOrHashes)
283
+ statuses.push(await this.statusOf(hash, opts));
284
+ return statuses;
285
+ }
286
+ return this.statusOf(hashOrHashes, opts);
287
+ }
288
+ /** The masterchain's latest block. */
289
+ async getChainTipHeight() {
290
+ return (await this.provider.getMasterchainHead()).seqno;
291
+ }
292
+ /**
293
+ * Where a signed request stands, so it is never replaced while it can still
294
+ * execute — the one check to make before signing a replacement, after a
295
+ * `Failed` relayed request or an uncertain broadcast:
296
+ * - `consumed`: the wallet's seqno has moved past the request's, or (given
297
+ * `hash`, for an external request) the request has a trace. It executed —
298
+ * or another request signed with the same seqno did. Do not re-sign it;
299
+ * read its status (`getTransactionStatus(hash)`, or the relay's).
300
+ * - `expired`: the chain's own time (not this machine's) is past
301
+ * `validUntil` by {@link REQUEST_EXPIRY_MARGIN_SECONDS}, with the seqno
302
+ * not moved past it and no trace. It can never execute; replacing it is
303
+ * safe.
304
+ * - `live`: neither yet. It can still execute — a relayed request that
305
+ * failed included: W5 keeps an internal request's seqno only when the
306
+ * transaction succeeds, so anyone can deliver it again from the trace
307
+ * until `validUntil`.
308
+ *
309
+ * `wallet` is the wallet that signed it: the sender of an external request,
310
+ * the target of a relayed one (pass no `hash` for a relayed request; a
311
+ * relay's own hash is the relayer's request). All reads come from one
312
+ * provider.
313
+ */
314
+ async getRequestState(args) {
315
+ if (args.hash !== undefined)
316
+ this.assertTxHash(args.hash);
317
+ const wallet = tonRawAddress(args.wallet);
318
+ return this.onOneProvider('getRequestState', async (provider) => {
319
+ if ((await provider.getSeqno(wallet)) > args.seqno)
320
+ return 'consumed';
321
+ const trace = args.hash === undefined ? null : await provider.getTrace(args.hash);
322
+ if (trace !== null) {
323
+ // A relay's hash names the relayer's request, not the relayed one: its
324
+ // trace says nothing about whether the target's request executed.
325
+ const root = trace.transactions[0];
326
+ if (root !== undefined && root.parent === null) {
327
+ if (root.account !== wallet) {
328
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `${args.hash} is a request of ${root.account}, not of ${wallet}; for a relayed request pass no hash`, { chainId: this.chainId, txHash: args.hash });
329
+ }
330
+ // The provider bound the trace to `hash`, so its root carries the signed request.
331
+ const signedSeqno = tonWalletRequestFields(root.inMsg?.body).seqno;
332
+ if (signedSeqno !== args.seqno) {
333
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `${args.hash} was signed at seqno ${signedSeqno}, not ${args.seqno}`, { chainId: this.chainId, txHash: args.hash });
334
+ }
335
+ }
336
+ return 'consumed';
337
+ }
338
+ const head = await provider.getMasterchainHead();
339
+ return head.utime > args.validUntil + REQUEST_EXPIRY_MARGIN_SECONDS ? 'expired' : 'live';
340
+ });
341
+ }
342
+ /** Native TON bounces only to a bounceable (`EQ…`) address that is deployed. */
343
+ async bouncesByDefault(to) {
344
+ if (new TonAddress(to).isBounceable !== true)
345
+ return false;
346
+ return (await this.getAccountState(to)).status === 'active';
347
+ }
348
+ assertTxHash(hash) {
349
+ try {
350
+ assertTonTxHash(hash);
351
+ }
352
+ catch (err) {
353
+ throw new ChainError(ChainErrorKinds.InvalidArgument, err.message, { chainId: this.chainId });
354
+ }
355
+ }
356
+ onOneProvider(method, run) {
357
+ const provider = this.provider;
358
+ return provider instanceof TonFallbackProvider ? provider.onOneProvider(method, run) : run(provider);
359
+ }
360
+ /**
361
+ * Whether `signedMessage` is `publicKey`'s signature of `message`
362
+ * (`TonWallet.signMessage`: ed25519 over {@link tonMessageHash}). Needs only
363
+ * the public key — 32 bytes, or 64 hex characters — as Tron's and
364
+ * Stellar's do. A signature must be exactly 128 hex characters.
365
+ */
366
+ static verifySignature(publicKey, message, signedMessage) {
367
+ if (!(signedMessage instanceof TonSignedMessage)) {
368
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TonChain expected a TonSignedMessage, got ${signedMessage?.constructor?.name ?? typeof signedMessage}`);
369
+ }
370
+ const key = typeof publicKey === 'string' ? strictHex(publicKey, 32, 'public key') : Buffer.from(publicKey);
371
+ if (key.length !== 32)
372
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `A TON public key is 32 bytes, got ${key.length}`);
373
+ if (!/^[0-9a-fA-F]{128}$/.test(signedMessage.signature))
374
+ return false;
375
+ try {
376
+ return signVerify(tonMessageHash(message), Buffer.from(signedMessage.signature, 'hex'), key);
377
+ }
378
+ catch {
379
+ return false;
380
+ }
381
+ }
382
+ /**
383
+ * TON addresses do not reveal their key, so a signature cannot be checked
384
+ * against an address alone: use `TonChain.verifySignature` with the
385
+ * signer's public key (its W5 address is `WalletContractV5R1.create({
386
+ * publicKey, workchain: 0 }).address`).
387
+ */
388
+ async verifyMessageSignature(_req) {
389
+ throw new ChainError(ChainErrorKinds.FeatureNotSupported, 'TON message signatures need the signer public key; use TonChain.verifySignature(publicKey, message, signature)', { chainId: this.chainId });
390
+ }
391
+ async statusOf(hash, opts) {
392
+ this.assertTxHash(hash);
393
+ const trace = await this.provider.getTrace(hash);
394
+ const masterchainTip = trace === null ? 0 : (await this.provider.getMasterchainHead()).seqno;
395
+ const status = TonTransactionStatus.fromTrace({
396
+ chainId: this.chainId,
397
+ trace,
398
+ masterchainTip,
399
+ minMasterchainDepth: opts.minMasterchainDepth,
400
+ });
401
+ if (trace !== null && status.balanceChanges !== null)
402
+ await this.addJettonBalanceChanges(trace, status.jettonCredits, status.balanceChanges);
403
+ return status;
404
+ }
405
+ /**
406
+ * Adds the jetton balance changes of the trace's wallet-to-wallet jetton
407
+ * transfers (TEP-74 \`transfer\` → \`internal_transfer\`) to
408
+ * \`balanceChanges\`: the sending owner loses the amount and the recipient
409
+ * gains it, in the jetton's asset ({@link resolveAsset}).
410
+ *
411
+ * A transfer counts only once its master vouches for both jetton wallets:
412
+ * the sender's must be the master's wallet for the owner it reports, and
413
+ * the receiving one the master's wallet for the recipient the transfer
414
+ * named. Anything else — a contract posing as a jetton wallet, a mint or a
415
+ * burn — moves no balance here.
416
+ */
417
+ async addJettonBalanceChanges(trace, credits, balanceChanges) {
418
+ const byHash = new Map(trace.transactions.map((tx) => [tx.hash, tx]));
419
+ const walletData = new Map();
420
+ const walletOf = new Map();
421
+ const dataOf = (wallet) => {
422
+ if (!walletData.has(wallet))
423
+ walletData.set(wallet, this.provider.getJettonWalletData(wallet));
424
+ return walletData.get(wallet);
425
+ };
426
+ const walletAddressOf = (master, owner) => {
427
+ const key = `${master}|${owner}`;
428
+ if (!walletOf.has(key))
429
+ walletOf.set(key, this.provider.getJettonWalletAddress(master, owner));
430
+ return walletOf.get(key);
431
+ };
432
+ for (const credit of credits) {
433
+ const received = byHash.get(credit.transaction);
434
+ const sender = received?.parent === null || received?.parent === undefined ? undefined : byHash.get(received.parent);
435
+ const recipient = sender?.inMsg === null || sender?.inMsg === undefined ? null : jettonTransferDestinationOf(sender.inMsg);
436
+ if (credit.senderJettonWallet === null || sender === undefined || recipient === null)
437
+ continue;
438
+ const data = await dataOf(credit.senderJettonWallet);
439
+ if (data === null)
440
+ continue;
441
+ const [senderWallet, recipientWallet] = await Promise.all([
442
+ walletAddressOf(data.jettonMaster, data.owner),
443
+ walletAddressOf(data.jettonMaster, recipient),
444
+ ]);
445
+ if (senderWallet !== credit.senderJettonWallet || recipientWallet !== credit.jettonWallet)
446
+ continue;
447
+ const asset = await this.resolveAsset(data.jettonMaster);
448
+ AssetBalanceChange.upsert(balanceChanges, data.owner, asset, AssetBalanceChange.fromMr(-credit.amount, asset.decimals));
449
+ AssetBalanceChange.upsert(balanceChanges, recipient, asset, AssetBalanceChange.fromMr(credit.amount, asset.decimals));
450
+ }
451
+ }
452
+ }
453
+ /** The recipient owner a jetton \`transfer\` names, raw; \`null\` for any other message. */
454
+ function jettonTransferDestinationOf(message) {
455
+ if (message.opcode !== TON_JETTON_TRANSFER_OP || message.body === null)
456
+ return null;
457
+ try {
458
+ const slice = message.body.beginParse();
459
+ slice.skip(32 + 64);
460
+ slice.loadCoins();
461
+ return slice.loadAddress().toRawString();
462
+ }
463
+ catch {
464
+ return null;
465
+ }
466
+ }
467
+ function endpointOf(name, endpoint, apiKeyEnv) {
468
+ const apiKey = (endpoint.apiKey ?? readEnv()?.[apiKeyEnv] ?? '').trim();
469
+ if (apiKey.length === 0)
470
+ return null;
471
+ if (!/^https:\/\//.test(endpoint.url)) {
472
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `${name} URL must be https, got ${endpoint.url}`);
473
+ }
474
+ return { url: endpoint.url, apiKey, timeoutMs: endpoint.timeoutMs };
475
+ }
476
+ function readEnv() {
477
+ return globalThis.process?.env;
478
+ }
479
+ //# sourceMappingURL=ton_chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ton_chain.js","sourceRoot":"","sources":["../../../ton/ton_chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,QAAQ,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAEL,KAAK,EAIL,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAA6B,MAAM,0BAA0B,CAAC;AAEzF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAmD,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAClH,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO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AAU,EAAE,CAAC;QACxC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QACpB,KAAK,CAAC,SAAS,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAY,EAAE,QAA6B,EAAE,SAAiB;IAChF,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CAAC,eAAe,CAAC,eAAe,EAAE,GAAG,IAAI,2BAA2B,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1G,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,OAAO;IACd,OAAQ,UAAyE,CAAC,OAAO,EAAE,GAAG,CAAC;AACjG,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { TonChain } from './ton_chain.ts';
2
+ export declare const TON_CENTER_MAINNET_URL = "https://toncenter.com";
3
+ export declare const TONAPI_MAINNET_URL = "https://tonapi.io";
4
+ /**
5
+ * TON mainnet. Its keys are read at first use from `TONCENTER_API_KEY` and
6
+ * `TONAPI_API_KEY`; a service that holds them elsewhere builds its own
7
+ * `TonChain` with the same URLs.
8
+ */
9
+ export declare const TonMainnet: TonChain;
10
+ export declare const ALL_TON_CHAINS: ReadonlyArray<TonChain>;
11
+ //# sourceMappingURL=ton_chains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ton_chains.d.ts","sourceRoot":"","sources":["../../../ton/ton_chains.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAC9D,eAAO,MAAM,kBAAkB,sBAAsB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,UAAU,UAMrB,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAgB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { CHAIN_ID_TON_MAINNET } from "../chain_ids.js";
2
+ import { TonChain } from "./ton_chain.js";
3
+ export const TON_CENTER_MAINNET_URL = 'https://toncenter.com';
4
+ export const TONAPI_MAINNET_URL = 'https://tonapi.io';
5
+ /**
6
+ * TON mainnet. Its keys are read at first use from `TONCENTER_API_KEY` and
7
+ * `TONAPI_API_KEY`; a service that holds them elsewhere builds its own
8
+ * `TonChain` with the same URLs.
9
+ */
10
+ export const TonMainnet = new TonChain({
11
+ chainId: CHAIN_ID_TON_MAINNET,
12
+ name: 'TON Mainnet',
13
+ explorerUrl: 'https://tonviewer.com',
14
+ toncenter: { url: TON_CENTER_MAINNET_URL },
15
+ tonapi: { url: TONAPI_MAINNET_URL },
16
+ });
17
+ export const ALL_TON_CHAINS = [TonMainnet];
18
+ //# sourceMappingURL=ton_chains.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ton_chains.js","sourceRoot":"","sources":["../../../ton/ton_chains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,QAAQ,CAAC;IACrC,OAAO,EAAE,oBAAoB;IAC7B,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,uBAAuB;IACpC,SAAS,EAAE,EAAE,GAAG,EAAE,sBAAsB,EAAE;IAC1C,MAAM,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAA4B,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { type Cell } from '@ton/core';
2
+ /** A jetton's TEP-64 metadata, as far as it could be read. */
3
+ export interface TonJettonMetadata {
4
+ symbol: string | null;
5
+ name: string | null;
6
+ /** Always set: the content's, the off-chain JSON's, or TEP-64's default of 9 when neither names one. */
7
+ decimals: number;
8
+ description: string | null;
9
+ image: string | null;
10
+ /** The off-chain metadata URI, when the content names one. */
11
+ uri: string | null;
12
+ }
13
+ /** Fetches a metadata URI's JSON; injectable for tests. */
14
+ export type TonMetadataFetcher = (uri: string) => Promise<unknown>;
15
+ declare const TEP64_KEYS: readonly ["uri", "name", "description", "image", "symbol", "decimals"];
16
+ /**
17
+ * The fields of a jetton master's content cell (`get_jetton_data`, TEP-64):
18
+ * on-chain (prefix 0x00, a dictionary keyed by the SHA-256 of each field
19
+ * name, values snake or chunked), or off-chain (any other prefix, a snake
20
+ * URI — TEP-64's 0x01 and the older variants some jettons use).
21
+ */
22
+ export declare function parseTonJettonContent(content: Cell): {
23
+ fields: Partial<Record<(typeof TEP64_KEYS)[number], string>>;
24
+ uri: string | null;
25
+ };
26
+ /**
27
+ * A jetton's metadata from its content cell, filling what the content lacks
28
+ * from the off-chain JSON its URI names (https only).
29
+ *
30
+ * The decimals decide every amount, so they are never guessed: when the
31
+ * content names none and the off-chain JSON could not be read, this throws
32
+ * (retryably). A symbol that cannot be read is `null`.
33
+ */
34
+ export declare function readTonJettonMetadata(content: Cell, fetchJson?: TonMetadataFetcher): Promise<TonJettonMetadata>;
35
+ export {};
36
+ //# sourceMappingURL=ton_jetton_metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ton_jetton_metadata.d.ts","sourceRoot":"","sources":["../../../ton/ton_jetton_metadata.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,EAA0B,MAAM,WAAW,CAAC;AAK9D,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,wGAAwG;IACxG,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,8DAA8D;IAC9D,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,2DAA2D;AAC3D,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnE,QAAA,MAAM,UAAU,wEAAyE,CAAC;AAK1F;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,IAAI,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAWzI;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,GAAE,kBAAsC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA+BxI"}