@dynamic-labs/waas-ton 4.51.0 → 4.52.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 (75) hide show
  1. package/CHANGELOG.md +6619 -0
  2. package/LICENSE +21 -0
  3. package/_virtual/_tslib.cjs +36 -0
  4. package/_virtual/_tslib.js +32 -0
  5. package/package.cjs +8 -0
  6. package/package.js +4 -0
  7. package/package.json +13 -6
  8. package/src/DynamicWaasTonConnectors.cjs +12 -0
  9. package/src/DynamicWaasTonConnectors.d.ts +2 -0
  10. package/src/DynamicWaasTonConnectors.js +8 -0
  11. package/src/connector/DynamicWaasTonConnector.cjs +282 -0
  12. package/src/connector/DynamicWaasTonConnector.d.ts +153 -0
  13. package/src/connector/DynamicWaasTonConnector.js +278 -0
  14. package/src/connector/TonWalletConnector.cjs +41 -0
  15. package/src/connector/TonWalletConnector.d.ts +29 -0
  16. package/src/connector/TonWalletConnector.js +37 -0
  17. package/src/index.cjs +34 -0
  18. package/src/index.d.ts +7 -0
  19. package/src/index.js +19 -0
  20. package/src/signer/DynamicWaasTonSigner.cjs +61 -0
  21. package/src/signer/DynamicWaasTonSigner.d.ts +20 -0
  22. package/src/signer/DynamicWaasTonSigner.js +57 -0
  23. package/src/types/index.cjs +13 -0
  24. package/src/types/index.d.ts +71 -0
  25. package/src/types/index.js +11 -0
  26. package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.cjs +117 -0
  27. package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.d.ts +9 -0
  28. package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.js +113 -0
  29. package/src/utils/convertSendTransactionRequest/index.d.ts +1 -0
  30. package/src/utils/executeTransaction/executeTransaction.cjs +55 -0
  31. package/src/utils/executeTransaction/executeTransaction.d.ts +25 -0
  32. package/src/utils/executeTransaction/executeTransaction.js +51 -0
  33. package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.cjs +51 -0
  34. package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.d.ts +18 -0
  35. package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.js +47 -0
  36. package/src/utils/extractDisplayInfoFromRequest/index.d.ts +1 -0
  37. package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.cjs +89 -0
  38. package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.d.ts +24 -0
  39. package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.js +85 -0
  40. package/src/utils/getJettonWalletAddress/getJettonWalletAddress.cjs +32 -0
  41. package/src/utils/getJettonWalletAddress/getJettonWalletAddress.d.ts +17 -0
  42. package/src/utils/getJettonWalletAddress/getJettonWalletAddress.js +28 -0
  43. package/src/utils/getWalletSeqno/getWalletSeqno.cjs +22 -0
  44. package/src/utils/getWalletSeqno/getWalletSeqno.d.ts +9 -0
  45. package/src/utils/getWalletSeqno/getWalletSeqno.js +18 -0
  46. package/src/utils/index.d.ts +10 -0
  47. package/src/utils/logger/logger.cjs +14 -0
  48. package/src/utils/logger/logger.d.ts +3 -0
  49. package/src/utils/logger/logger.js +7 -0
  50. package/src/utils/prepareJettonTransfer/prepareJettonTransfer.cjs +78 -0
  51. package/src/utils/prepareJettonTransfer/prepareJettonTransfer.d.ts +31 -0
  52. package/src/utils/prepareJettonTransfer/prepareJettonTransfer.js +74 -0
  53. package/src/utils/prepareTonTransfer/prepareTonTransfer.cjs +45 -0
  54. package/src/utils/prepareTonTransfer/prepareTonTransfer.d.ts +23 -0
  55. package/src/utils/prepareTonTransfer/prepareTonTransfer.js +41 -0
  56. package/src/utils/prepareTransaction/prepareTransaction.cjs +65 -0
  57. package/src/utils/prepareTransaction/prepareTransaction.d.ts +32 -0
  58. package/src/utils/prepareTransaction/prepareTransaction.js +61 -0
  59. package/src/wallet/WaasTonWallet.cjs +31 -0
  60. package/src/wallet/WaasTonWallet.d.ts +10 -0
  61. package/src/wallet/WaasTonWallet.js +27 -0
  62. package/.eslintrc.json +0 -33
  63. package/jest.config.ts +0 -29
  64. package/project.json +0 -47
  65. package/rollup.config.cjs +0 -7
  66. package/src/index.ts +0 -18
  67. package/src/types/index.ts +0 -39
  68. package/src/utils/index.ts +0 -1
  69. package/src/utils/logger/logger.spec.ts +0 -7
  70. package/src/utils/logger/logger.ts +0 -6
  71. package/test/mocks/browserWalletClientMock.ts +0 -38
  72. package/test/setupAfterEnv.config.ts +0 -7
  73. package/tsconfig.json +0 -23
  74. package/tsconfig.lib.json +0 -10
  75. package/tsconfig.spec.json +0 -14
@@ -0,0 +1,278 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { TonClient } from '@ton/ton';
4
+ import { MFAAction } from '@dynamic-labs/sdk-api-core';
5
+ import { TonUiTransaction, NANOTON_PER_TON } from '@dynamic-labs/ton';
6
+ import { DynamicError } from '@dynamic-labs/utils';
7
+ import { withDynamicWaas } from '@dynamic-labs/waas';
8
+ import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
9
+ import { DynamicWaasTonSigner } from '../signer/DynamicWaasTonSigner.js';
10
+ import { CHAIN } from '../types/index.js';
11
+ import { prepareTransaction } from '../utils/prepareTransaction/prepareTransaction.js';
12
+ import '@ton/crypto';
13
+ import { prepareTonTransfer } from '../utils/prepareTonTransfer/prepareTonTransfer.js';
14
+ import { prepareJettonTransfer } from '../utils/prepareJettonTransfer/prepareJettonTransfer.js';
15
+ import { getWalletSeqno } from '../utils/getWalletSeqno/getWalletSeqno.js';
16
+ import { executeTransaction } from '../utils/executeTransaction/executeTransaction.js';
17
+ import { extractDisplayInfoFromRequest } from '../utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.js';
18
+ import { convertSendTransactionRequest } from '../utils/convertSendTransactionRequest/convertSendTransactionRequest.js';
19
+ import { logger } from '../utils/logger/logger.js';
20
+ import { TonWalletConnector } from './TonWalletConnector.js';
21
+ import { Logger } from '@dynamic-labs/logger';
22
+
23
+ class DynamicWaasTonConnector extends withDynamicWaas(TonWalletConnector) {
24
+ constructor(props) {
25
+ super(props);
26
+ this.name = 'Dynamic Waas';
27
+ this.overrideKey = 'dynamicwaas';
28
+ this.isEmbeddedWallet = true;
29
+ this.logger = logger;
30
+ this.walletUiUtils = props.walletUiUtils;
31
+ }
32
+ /**
33
+ * Override setEnvironmentId to ensure it's set on the global logger
34
+ */
35
+ setEnvironmentId(environmentId) {
36
+ super.setEnvironmentId(environmentId);
37
+ Logger.setEnvironmentId(environmentId);
38
+ }
39
+ getSigner() {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return new DynamicWaasTonSigner({
42
+ walletConnector: this,
43
+ });
44
+ });
45
+ }
46
+ getWalletClientByAddress(_a) {
47
+ return __awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
48
+ this.setActiveAccountAddress(accountAddress);
49
+ return this.getWaasWalletClient();
50
+ });
51
+ }
52
+ getTonClient(chainId) {
53
+ var _a, _b, _c;
54
+ const targetChainId = chainId || CHAIN.MAINNET;
55
+ const network = (_a = this.tonNetworks) === null || _a === void 0 ? void 0 : _a.find((net) => net.chainId === targetChainId);
56
+ if (!network) {
57
+ throw new DynamicError(`Network configuration not found for chainId: ${targetChainId}`);
58
+ }
59
+ const endpoint = ((_b = network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0]) || ((_c = network.rpcUrls) === null || _c === void 0 ? void 0 : _c[0]);
60
+ if (!endpoint) {
61
+ throw new DynamicError(`No RPC endpoint found for chainId: ${targetChainId}`);
62
+ }
63
+ return new TonClient({
64
+ endpoint,
65
+ });
66
+ }
67
+ getActiveAccountAddress() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return this.activeAccountAddress;
70
+ });
71
+ }
72
+ setActiveAccountAddress(accountAddress) {
73
+ this.activeAccountAddress = accountAddress;
74
+ }
75
+ requireSignedSessionId() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a;
78
+ const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
79
+ if (!signedSessionId) {
80
+ throw new DynamicError('Signed session ID is required');
81
+ }
82
+ return signedSessionId;
83
+ });
84
+ }
85
+ validateActiveWallet(expectedAddress) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ var _a;
88
+ const walletClient = yield this.getWaasWalletClient();
89
+ const signedSessionId = yield this.requireSignedSessionId();
90
+ const targetWallet = yield walletClient.getWallet({
91
+ accountAddress: expectedAddress,
92
+ authToken: (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this),
93
+ signedSessionId,
94
+ });
95
+ if (!targetWallet) {
96
+ throw new DynamicError('Account not found');
97
+ }
98
+ const isWalletActive = isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
99
+ if (!isWalletActive) {
100
+ this.activeAccountAddress = targetWallet.accountAddress;
101
+ }
102
+ });
103
+ }
104
+ getAddress() {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ return this.activeAccountAddress;
107
+ });
108
+ }
109
+ connect() {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ yield this.getWaasWalletClient();
112
+ });
113
+ }
114
+ signMessage(message) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ return this.walletUiUtils.signMessage({
117
+ handler: () => __awaiter(this, void 0, void 0, function* () { return this.internalSignMessage(message); }),
118
+ message,
119
+ walletConnector: this,
120
+ });
121
+ });
122
+ }
123
+ internalSignMessage(message) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ var _a, _b;
126
+ const walletClient = yield this.getWaasWalletClient();
127
+ if (!this.activeAccountAddress) {
128
+ throw new Error('Active account address is required');
129
+ }
130
+ const signedSessionId = yield this.requireSignedSessionId();
131
+ const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
132
+ mfaAction: MFAAction.WalletWaasSign,
133
+ }));
134
+ const signedMessage = yield walletClient.signMessage({
135
+ accountAddress: this.activeAccountAddress,
136
+ authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
137
+ message,
138
+ mfaToken,
139
+ signedSessionId,
140
+ });
141
+ return signedMessage;
142
+ });
143
+ }
144
+ endSession() {
145
+ const _super = Object.create(null, {
146
+ endSession: { get: () => super.endSession }
147
+ });
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ yield _super.endSession.call(this);
150
+ this.activeAccountAddress = undefined;
151
+ });
152
+ }
153
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
154
+ signMessageWithContext(_params) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ throw new Error('Method not implemented.');
157
+ });
158
+ }
159
+ sendTransaction(request) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ if (!this.activeAccountAddress) {
162
+ throw new DynamicError('Active account address is required');
163
+ }
164
+ // TON Connect spec allows 1-4 messages per transaction
165
+ if (request.messages.length < 1 || request.messages.length > 4) {
166
+ throw new DynamicError(`Invalid message count: ${request.messages.length}. Must be between 1 and 4.`);
167
+ }
168
+ const displayInfo = extractDisplayInfoFromRequest(request);
169
+ const uiTransaction = new TonUiTransaction({
170
+ client: this.getTonClient(),
171
+ from: this.activeAccountAddress,
172
+ onSubmit: () => __awaiter(this, void 0, void 0, function* () { return this.internalSendTransaction(request); }),
173
+ });
174
+ uiTransaction.to = displayInfo.recipient;
175
+ uiTransaction.value = displayInfo.value
176
+ ? BigInt(displayInfo.value)
177
+ : undefined;
178
+ // Handle jetton transfers
179
+ if (displayInfo.jettonAddress && displayInfo.jettonAmount) {
180
+ uiTransaction.nonNativeAddress = displayInfo.jettonAddress;
181
+ uiTransaction.nonNativeValue = BigInt(displayInfo.jettonAmount);
182
+ }
183
+ return this.walletUiUtils.sendTransaction(this, uiTransaction);
184
+ });
185
+ }
186
+ internalSendTransaction(request) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ var _a, _b;
189
+ if (!this.activeAccountAddress) {
190
+ throw new DynamicError('Active account address is required');
191
+ }
192
+ const client = this.getTonClient();
193
+ const walletAddress = request.from || this.activeAccountAddress;
194
+ const network = request.network || CHAIN.MAINNET;
195
+ const seqno = yield getWalletSeqno(walletAddress, client);
196
+ const actionsArray = convertSendTransactionRequest(request);
197
+ const { hashToSignHex, transactionData } = prepareTransaction({
198
+ actionsArray,
199
+ networkGlobalId: network,
200
+ seqno,
201
+ timeout: request.validUntil - Math.floor(Date.now() / 1000),
202
+ validUntil: request.validUntil,
203
+ walletAddress,
204
+ });
205
+ const walletClient = yield this.getWaasWalletClient();
206
+ const signedSessionId = yield this.requireSignedSessionId();
207
+ const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
208
+ mfaAction: MFAAction.WalletWaasSign,
209
+ }));
210
+ const signature = yield walletClient.signTransaction({
211
+ authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
212
+ mfaToken,
213
+ senderAddress: this.activeAccountAddress,
214
+ signedSessionId,
215
+ transaction: hashToSignHex,
216
+ });
217
+ const result = yield executeTransaction({
218
+ client,
219
+ signature,
220
+ transactionData,
221
+ });
222
+ if (!result.success) {
223
+ throw new DynamicError(`Failed to execute transaction: ${result.error || 'Unknown error'}`);
224
+ }
225
+ return result.transactionHash || '';
226
+ });
227
+ }
228
+ internalSendUiTransaction(transaction) {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ if (!transaction.to) {
231
+ throw new DynamicError('Destination address is required');
232
+ }
233
+ if (!this.activeAccountAddress) {
234
+ throw new DynamicError('Active account address is required');
235
+ }
236
+ const client = this.getTonClient();
237
+ // Handle Jetton (non-native token) transfers
238
+ if (transaction.nonNativeAddress && transaction.nonNativeValue) {
239
+ const request = yield prepareJettonTransfer({
240
+ client,
241
+ forwardTonAmount: BigInt(0),
242
+ jettonAmount: transaction.nonNativeValue,
243
+ jettonMasterAddress: transaction.nonNativeAddress,
244
+ recipientAddress: transaction.to,
245
+ timeout: 60,
246
+ walletAddress: this.activeAccountAddress,
247
+ });
248
+ return this.internalSendTransaction(request);
249
+ }
250
+ // Handle native TON transfers
251
+ if (transaction.value) {
252
+ const tonAmount = Number(transaction.value) / NANOTON_PER_TON;
253
+ const request = yield prepareTonTransfer({
254
+ amount: tonAmount,
255
+ client,
256
+ recipient: transaction.to,
257
+ timeout: 60,
258
+ walletAddress: this.activeAccountAddress,
259
+ });
260
+ return this.internalSendTransaction(request);
261
+ }
262
+ throw new DynamicError('Invalid transaction parameters');
263
+ });
264
+ }
265
+ createUiTransaction(from) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ yield this.validateActiveWallet(from);
268
+ const client = this.getTonClient();
269
+ return new TonUiTransaction({
270
+ client,
271
+ from,
272
+ onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () { return this.internalSendUiTransaction(transaction); }),
273
+ });
274
+ });
275
+ }
276
+ }
277
+
278
+ export { DynamicWaasTonConnector };
@@ -0,0 +1,41 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
+ var WaasTonWallet = require('../wallet/WaasTonWallet.cjs');
9
+ var index = require('../types/index.cjs');
10
+
11
+ /**
12
+ * Temp file until we have the ton-core package ready.
13
+ */
14
+ class TonWalletConnector extends walletConnectorCore.WalletConnectorBase {
15
+ constructor(opts) {
16
+ super(opts);
17
+ this.ChainWallet = WaasTonWallet.WaasTonWallet;
18
+ this.connectedChain = 'TON';
19
+ this.supportedChains = ['TON'];
20
+ this.tonNetworks = opts.tonNetworks;
21
+ }
22
+ /**
23
+ * Get the enabled networks for the wallet.
24
+ * Networks are configured via project settings.
25
+ */
26
+ getEnabledNetworks() {
27
+ return this.tonNetworks;
28
+ }
29
+ /**
30
+ * Get the current network ID.
31
+ * Returns the first network's networkId as default.
32
+ */
33
+ getNetwork() {
34
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
35
+ var _a, _b, _c;
36
+ return ((_c = (_b = (_a = this.tonNetworks) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.networkId) === null || _c === void 0 ? void 0 : _c.toString()) || index.CHAIN.MAINNET;
37
+ });
38
+ }
39
+ }
40
+
41
+ exports.TonWalletConnector = TonWalletConnector;
@@ -0,0 +1,29 @@
1
+ import { Chain, WalletConnectorBase, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
2
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
+ import { GenericNetwork } from '@dynamic-labs/types';
4
+ import { WaasTonWallet } from '../wallet/WaasTonWallet';
5
+ export type TonWalletConnectorOpts = {
6
+ walletBook: WalletBookSchema;
7
+ tonNetworks: GenericNetwork[];
8
+ metadata?: WalletMetadata;
9
+ };
10
+ /**
11
+ * Temp file until we have the ton-core package ready.
12
+ */
13
+ export declare abstract class TonWalletConnector extends WalletConnectorBase<typeof WaasTonWallet> {
14
+ ChainWallet: typeof WaasTonWallet;
15
+ connectedChain: Chain;
16
+ supportedChains: Chain[];
17
+ tonNetworks: GenericNetwork[];
18
+ constructor(opts: TonWalletConnectorOpts);
19
+ /**
20
+ * Get the enabled networks for the wallet.
21
+ * Networks are configured via project settings.
22
+ */
23
+ getEnabledNetworks(): GenericNetwork[];
24
+ /**
25
+ * Get the current network ID.
26
+ * Returns the first network's networkId as default.
27
+ */
28
+ getNetwork(): Promise<string | undefined>;
29
+ }
@@ -0,0 +1,37 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
4
+ import { WaasTonWallet } from '../wallet/WaasTonWallet.js';
5
+ import { CHAIN } from '../types/index.js';
6
+
7
+ /**
8
+ * Temp file until we have the ton-core package ready.
9
+ */
10
+ class TonWalletConnector extends WalletConnectorBase {
11
+ constructor(opts) {
12
+ super(opts);
13
+ this.ChainWallet = WaasTonWallet;
14
+ this.connectedChain = 'TON';
15
+ this.supportedChains = ['TON'];
16
+ this.tonNetworks = opts.tonNetworks;
17
+ }
18
+ /**
19
+ * Get the enabled networks for the wallet.
20
+ * Networks are configured via project settings.
21
+ */
22
+ getEnabledNetworks() {
23
+ return this.tonNetworks;
24
+ }
25
+ /**
26
+ * Get the current network ID.
27
+ * Returns the first network's networkId as default.
28
+ */
29
+ getNetwork() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ var _a, _b, _c;
32
+ return ((_c = (_b = (_a = this.tonNetworks) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.networkId) === null || _c === void 0 ? void 0 : _c.toString()) || CHAIN.MAINNET;
33
+ });
34
+ }
35
+ }
36
+
37
+ export { TonWalletConnector };
package/src/index.cjs ADDED
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
+ var _package = require('../package.cjs');
8
+ var DynamicWaasTonConnector = require('./connector/DynamicWaasTonConnector.cjs');
9
+ var DynamicWaasTonConnectors = require('./DynamicWaasTonConnectors.cjs');
10
+ var DynamicWaasTonSigner = require('./signer/DynamicWaasTonSigner.cjs');
11
+ var WaasTonWallet = require('./wallet/WaasTonWallet.cjs');
12
+ require('@ton/ton');
13
+ require('@ton/core');
14
+ require('./types/index.cjs');
15
+ var generateTonConnectProofHash = require('./utils/generateTonConnectProofHash/generateTonConnectProofHash.cjs');
16
+ var prepareTonTransfer = require('./utils/prepareTonTransfer/prepareTonTransfer.cjs');
17
+ var prepareJettonTransfer = require('./utils/prepareJettonTransfer/prepareJettonTransfer.cjs');
18
+ var getJettonWalletAddress = require('./utils/getJettonWalletAddress/getJettonWalletAddress.cjs');
19
+ var getWalletSeqno = require('./utils/getWalletSeqno/getWalletSeqno.cjs');
20
+ var executeTransaction = require('./utils/executeTransaction/executeTransaction.cjs');
21
+ require('./utils/logger/logger.cjs');
22
+
23
+ assertPackageVersion.assertPackageVersion('@dynamic-labs/waas-ton', _package.version);
24
+
25
+ exports.DynamicWaasTonConnector = DynamicWaasTonConnector.DynamicWaasTonConnector;
26
+ exports.DynamicWaasTonConnectors = DynamicWaasTonConnectors.DynamicWaasTonConnectors;
27
+ exports.DynamicWaasTonSigner = DynamicWaasTonSigner.DynamicWaasTonSigner;
28
+ exports.WaasTonWallet = WaasTonWallet.WaasTonWallet;
29
+ exports.generateTonConnectProofHash = generateTonConnectProofHash.generateTonConnectProofHash;
30
+ exports.prepareTonTransfer = prepareTonTransfer.prepareTonTransfer;
31
+ exports.prepareJettonTransfer = prepareJettonTransfer.prepareJettonTransfer;
32
+ exports.getJettonWalletAddress = getJettonWalletAddress.getJettonWalletAddress;
33
+ exports.getWalletSeqno = getWalletSeqno.getWalletSeqno;
34
+ exports.executeTransaction = executeTransaction.executeTransaction;
package/src/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { DynamicWaasTonConnector } from './connector/DynamicWaasTonConnector';
2
+ export { DynamicWaasTonConnectors } from './DynamicWaasTonConnectors';
3
+ export { DynamicWaasTonSigner } from './signer/DynamicWaasTonSigner';
4
+ export { WaasTonWallet } from './wallet/WaasTonWallet';
5
+ export type { TonConnectDomain, TonConnectProof, TonTransactionData, } from './types';
6
+ export { prepareTonTransfer, getWalletSeqno, executeTransaction, generateTonConnectProofHash, getJettonWalletAddress, prepareJettonTransfer, } from './utils';
7
+ export type { PrepareTonTransferParams, ExecuteTransactionParams, ExecuteTransactionResult, GenerateTonConnectProofHashParams, GetJettonWalletAddressParams, PrepareJettonTransferParams, } from './utils';
package/src/index.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use client'
2
+ import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
+ import { version } from '../package.js';
4
+ export { DynamicWaasTonConnector } from './connector/DynamicWaasTonConnector.js';
5
+ export { DynamicWaasTonConnectors } from './DynamicWaasTonConnectors.js';
6
+ export { DynamicWaasTonSigner } from './signer/DynamicWaasTonSigner.js';
7
+ export { WaasTonWallet } from './wallet/WaasTonWallet.js';
8
+ import '@ton/ton';
9
+ import '@ton/core';
10
+ import './types/index.js';
11
+ export { generateTonConnectProofHash } from './utils/generateTonConnectProofHash/generateTonConnectProofHash.js';
12
+ export { prepareTonTransfer } from './utils/prepareTonTransfer/prepareTonTransfer.js';
13
+ export { prepareJettonTransfer } from './utils/prepareJettonTransfer/prepareJettonTransfer.js';
14
+ export { getJettonWalletAddress } from './utils/getJettonWalletAddress/getJettonWalletAddress.js';
15
+ export { getWalletSeqno } from './utils/getWalletSeqno/getWalletSeqno.js';
16
+ export { executeTransaction } from './utils/executeTransaction/executeTransaction.js';
17
+ import './utils/logger/logger.js';
18
+
19
+ assertPackageVersion('@dynamic-labs/waas-ton', version);
@@ -0,0 +1,61 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var utils = require('@dynamic-labs/utils');
8
+ require('@ton/ton');
9
+ require('@ton/core');
10
+ require('../types/index.cjs');
11
+ var generateTonConnectProofHash = require('../utils/generateTonConnectProofHash/generateTonConnectProofHash.cjs');
12
+ require('../utils/prepareJettonTransfer/prepareJettonTransfer.cjs');
13
+ require('../utils/logger/logger.cjs');
14
+
15
+ /**
16
+ * Signer implementation for DynamicWaasTonConnector
17
+ */
18
+ class DynamicWaasTonSigner {
19
+ constructor({ walletConnector, }) {
20
+ this.walletConnector = walletConnector;
21
+ this.accountAddress = this.walletConnector.activeAccountAddress;
22
+ }
23
+ /**
24
+ * Generates a TON Connect proof by constructing the proof message,
25
+ * hashing it according to TON Connect spec, and signing it.
26
+ *
27
+ * @param payload - The payload string to include in the proof
28
+ * @returns Complete TON Connect proof object
29
+ */
30
+ generateTonConnectProof(payload) {
31
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
32
+ if (!this.accountAddress) {
33
+ throw new Error('Active account address is required');
34
+ }
35
+ yield this.walletConnector.getWaasWalletClient();
36
+ const host = utils.PlatformService.getHost();
37
+ const timestamp = Math.floor(Date.now() / 1000);
38
+ const domainLengthBytes = new TextEncoder().encode(host).length;
39
+ const domain = {
40
+ lengthBytes: domainLengthBytes,
41
+ value: host,
42
+ };
43
+ const hashHex = yield generateTonConnectProofHash.generateTonConnectProofHash({
44
+ address: this.accountAddress,
45
+ domain,
46
+ payload,
47
+ timestamp,
48
+ });
49
+ const signature = yield this.walletConnector.signMessage(hashHex);
50
+ return {
51
+ address: this.accountAddress,
52
+ domain,
53
+ payload,
54
+ signature,
55
+ timestamp,
56
+ };
57
+ });
58
+ }
59
+ }
60
+
61
+ exports.DynamicWaasTonSigner = DynamicWaasTonSigner;
@@ -0,0 +1,20 @@
1
+ import { DynamicWaasTonConnector } from '../connector/DynamicWaasTonConnector';
2
+ import type { TonConnectProof } from '../types';
3
+ /**
4
+ * Signer implementation for DynamicWaasTonConnector
5
+ */
6
+ export declare class DynamicWaasTonSigner {
7
+ private readonly accountAddress;
8
+ private walletConnector;
9
+ constructor({ walletConnector, }: {
10
+ walletConnector: DynamicWaasTonConnector;
11
+ });
12
+ /**
13
+ * Generates a TON Connect proof by constructing the proof message,
14
+ * hashing it according to TON Connect spec, and signing it.
15
+ *
16
+ * @param payload - The payload string to include in the proof
17
+ * @returns Complete TON Connect proof object
18
+ */
19
+ generateTonConnectProof(payload: string): Promise<TonConnectProof>;
20
+ }
@@ -0,0 +1,57 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { PlatformService } from '@dynamic-labs/utils';
4
+ import '@ton/ton';
5
+ import '@ton/core';
6
+ import '../types/index.js';
7
+ import { generateTonConnectProofHash } from '../utils/generateTonConnectProofHash/generateTonConnectProofHash.js';
8
+ import '../utils/prepareJettonTransfer/prepareJettonTransfer.js';
9
+ import '../utils/logger/logger.js';
10
+
11
+ /**
12
+ * Signer implementation for DynamicWaasTonConnector
13
+ */
14
+ class DynamicWaasTonSigner {
15
+ constructor({ walletConnector, }) {
16
+ this.walletConnector = walletConnector;
17
+ this.accountAddress = this.walletConnector.activeAccountAddress;
18
+ }
19
+ /**
20
+ * Generates a TON Connect proof by constructing the proof message,
21
+ * hashing it according to TON Connect spec, and signing it.
22
+ *
23
+ * @param payload - The payload string to include in the proof
24
+ * @returns Complete TON Connect proof object
25
+ */
26
+ generateTonConnectProof(payload) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ if (!this.accountAddress) {
29
+ throw new Error('Active account address is required');
30
+ }
31
+ yield this.walletConnector.getWaasWalletClient();
32
+ const host = PlatformService.getHost();
33
+ const timestamp = Math.floor(Date.now() / 1000);
34
+ const domainLengthBytes = new TextEncoder().encode(host).length;
35
+ const domain = {
36
+ lengthBytes: domainLengthBytes,
37
+ value: host,
38
+ };
39
+ const hashHex = yield generateTonConnectProofHash({
40
+ address: this.accountAddress,
41
+ domain,
42
+ payload,
43
+ timestamp,
44
+ });
45
+ const signature = yield this.walletConnector.signMessage(hashHex);
46
+ return {
47
+ address: this.accountAddress,
48
+ domain,
49
+ payload,
50
+ signature,
51
+ timestamp,
52
+ };
53
+ });
54
+ }
55
+ }
56
+
57
+ export { DynamicWaasTonSigner };
@@ -0,0 +1,13 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Network chain identifier for TON
8
+ */
9
+ exports.CHAIN = void 0;
10
+ (function (CHAIN) {
11
+ CHAIN["MAINNET"] = "-239";
12
+ CHAIN["TESTNET"] = "-3";
13
+ })(exports.CHAIN || (exports.CHAIN = {}));
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Domain information for TON Connect protocol
3
+ */
4
+ export interface TonConnectDomain {
5
+ /** Length of domain value in bytes */
6
+ lengthBytes: number;
7
+ /** Domain value (e.g., example.com) */
8
+ value: string;
9
+ }
10
+ /**
11
+ * Complete TON Connect proof object
12
+ */
13
+ export interface TonConnectProof {
14
+ /** Wallet address string */
15
+ address: string;
16
+ /** Domain information */
17
+ domain: TonConnectDomain;
18
+ /** Unix timestamp in seconds */
19
+ timestamp: number;
20
+ /** Payload string */
21
+ payload: string;
22
+ /** Signature as base64 string */
23
+ signature: string;
24
+ }
25
+ /**
26
+ * Network chain identifier for TON
27
+ */
28
+ export declare enum CHAIN {
29
+ MAINNET = "-239",
30
+ TESTNET = "-3"
31
+ }
32
+ /**
33
+ * TON Connect compatible transaction request
34
+ * @see https://ton-connect.github.io/sdk/interfaces/_tonconnect_ui.SendTransactionRequest.html
35
+ */
36
+ export interface SendTransactionRequest {
37
+ /** The sender address from which DApp intends to send the transaction */
38
+ from?: string;
39
+ /** Messages to send */
40
+ messages: {
41
+ /** Receiver's address */
42
+ address: string;
43
+ /** Amount to send in nanoTon */
44
+ amount: string;
45
+ /** Extra currencies to send */
46
+ extraCurrency?: {
47
+ [k: number]: string;
48
+ };
49
+ /** Contract specific data to add to the transaction (base64 encoded BOC) */
50
+ payload?: string;
51
+ /** Contract specific data to add to the transaction (base64 encoded BOC) */
52
+ stateInit?: string;
53
+ }[];
54
+ /** The network where DApp intends to send the transaction */
55
+ network?: CHAIN;
56
+ /** Sending transaction deadline in unix epoch seconds */
57
+ validUntil: number;
58
+ }
59
+ /**
60
+ * Generic transaction data used internally for signing and execution
61
+ */
62
+ export interface TonTransactionData {
63
+ /** Sender wallet address */
64
+ address: string;
65
+ /** Current wallet seqno */
66
+ seqno: number;
67
+ /** Base64-encoded message body (the transaction to be signed) */
68
+ messageBody: string;
69
+ /** Transaction timeout in seconds */
70
+ timeout: number;
71
+ }