@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dynamic Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ function __awaiter(thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ }
30
+
31
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
+ var e = new Error(message);
33
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
+ };
35
+
36
+ exports.__awaiter = __awaiter;
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ /******************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */
16
+
17
+ function __awaiter(thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ }
26
+
27
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
+ var e = new Error(message);
29
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
+ };
31
+
32
+ export { __awaiter };
package/package.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var version = "4.52.0";
7
+
8
+ exports.version = version;
package/package.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ var version = "4.52.0";
3
+
4
+ export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/waas-ton",
3
- "version": "4.51.0",
3
+ "version": "4.52.0",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,11 +18,18 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/assert-package-version": "4.51.1",
22
- "@dynamic-labs/logger": "4.51.1",
21
+ "@dynamic-labs/assert-package-version": "4.52.0",
22
+ "@dynamic-labs/logger": "4.52.0",
23
23
  "@dynamic-labs/sdk-api-core": "0.0.843",
24
+ "@dynamic-labs/ton": "4.52.0",
24
25
  "@ton/core": "0.62.0",
25
26
  "@ton/crypto": "3.3.0",
26
- "@ton/ton": "16.0.0"
27
- }
28
- }
27
+ "@ton/ton": "16.0.0",
28
+ "@dynamic-labs/types": "4.52.0",
29
+ "@dynamic-labs/utils": "4.52.0",
30
+ "@dynamic-labs/waas": "4.52.0",
31
+ "@dynamic-labs/wallet-book": "4.52.0",
32
+ "@dynamic-labs/wallet-connector-core": "4.52.0"
33
+ },
34
+ "peerDependencies": {}
35
+ }
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var DynamicWaasTonConnector = require('./connector/DynamicWaasTonConnector.cjs');
7
+
8
+ const DynamicWaasTonConnectors = () => [
9
+ DynamicWaasTonConnector.DynamicWaasTonConnector,
10
+ ];
11
+
12
+ exports.DynamicWaasTonConnectors = DynamicWaasTonConnectors;
@@ -0,0 +1,2 @@
1
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
2
+ export declare const DynamicWaasTonConnectors: () => WalletConnectorConstructor[];
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ import { DynamicWaasTonConnector } from './connector/DynamicWaasTonConnector.js';
3
+
4
+ const DynamicWaasTonConnectors = () => [
5
+ DynamicWaasTonConnector,
6
+ ];
7
+
8
+ export { DynamicWaasTonConnectors };
@@ -0,0 +1,282 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var ton = require('@ton/ton');
8
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
9
+ var ton$1 = require('@dynamic-labs/ton');
10
+ var utils = require('@dynamic-labs/utils');
11
+ var waas = require('@dynamic-labs/waas');
12
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
13
+ var DynamicWaasTonSigner = require('../signer/DynamicWaasTonSigner.cjs');
14
+ var index = require('../types/index.cjs');
15
+ var prepareTransaction = require('../utils/prepareTransaction/prepareTransaction.cjs');
16
+ require('@ton/crypto');
17
+ var prepareTonTransfer = require('../utils/prepareTonTransfer/prepareTonTransfer.cjs');
18
+ var prepareJettonTransfer = require('../utils/prepareJettonTransfer/prepareJettonTransfer.cjs');
19
+ var getWalletSeqno = require('../utils/getWalletSeqno/getWalletSeqno.cjs');
20
+ var executeTransaction = require('../utils/executeTransaction/executeTransaction.cjs');
21
+ var extractDisplayInfoFromRequest = require('../utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.cjs');
22
+ var convertSendTransactionRequest = require('../utils/convertSendTransactionRequest/convertSendTransactionRequest.cjs');
23
+ var logger = require('../utils/logger/logger.cjs');
24
+ var TonWalletConnector = require('./TonWalletConnector.cjs');
25
+ var logger$1 = require('@dynamic-labs/logger');
26
+
27
+ class DynamicWaasTonConnector extends waas.withDynamicWaas(TonWalletConnector.TonWalletConnector) {
28
+ constructor(props) {
29
+ super(props);
30
+ this.name = 'Dynamic Waas';
31
+ this.overrideKey = 'dynamicwaas';
32
+ this.isEmbeddedWallet = true;
33
+ this.logger = logger.logger;
34
+ this.walletUiUtils = props.walletUiUtils;
35
+ }
36
+ /**
37
+ * Override setEnvironmentId to ensure it's set on the global logger
38
+ */
39
+ setEnvironmentId(environmentId) {
40
+ super.setEnvironmentId(environmentId);
41
+ logger$1.Logger.setEnvironmentId(environmentId);
42
+ }
43
+ getSigner() {
44
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
45
+ return new DynamicWaasTonSigner.DynamicWaasTonSigner({
46
+ walletConnector: this,
47
+ });
48
+ });
49
+ }
50
+ getWalletClientByAddress(_a) {
51
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
52
+ this.setActiveAccountAddress(accountAddress);
53
+ return this.getWaasWalletClient();
54
+ });
55
+ }
56
+ getTonClient(chainId) {
57
+ var _a, _b, _c;
58
+ const targetChainId = chainId || index.CHAIN.MAINNET;
59
+ const network = (_a = this.tonNetworks) === null || _a === void 0 ? void 0 : _a.find((net) => net.chainId === targetChainId);
60
+ if (!network) {
61
+ throw new utils.DynamicError(`Network configuration not found for chainId: ${targetChainId}`);
62
+ }
63
+ const endpoint = ((_b = network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0]) || ((_c = network.rpcUrls) === null || _c === void 0 ? void 0 : _c[0]);
64
+ if (!endpoint) {
65
+ throw new utils.DynamicError(`No RPC endpoint found for chainId: ${targetChainId}`);
66
+ }
67
+ return new ton.TonClient({
68
+ endpoint,
69
+ });
70
+ }
71
+ getActiveAccountAddress() {
72
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
73
+ return this.activeAccountAddress;
74
+ });
75
+ }
76
+ setActiveAccountAddress(accountAddress) {
77
+ this.activeAccountAddress = accountAddress;
78
+ }
79
+ requireSignedSessionId() {
80
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
81
+ var _a;
82
+ const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
83
+ if (!signedSessionId) {
84
+ throw new utils.DynamicError('Signed session ID is required');
85
+ }
86
+ return signedSessionId;
87
+ });
88
+ }
89
+ validateActiveWallet(expectedAddress) {
90
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
91
+ var _a;
92
+ const walletClient = yield this.getWaasWalletClient();
93
+ const signedSessionId = yield this.requireSignedSessionId();
94
+ const targetWallet = yield walletClient.getWallet({
95
+ accountAddress: expectedAddress,
96
+ authToken: (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this),
97
+ signedSessionId,
98
+ });
99
+ if (!targetWallet) {
100
+ throw new utils.DynamicError('Account not found');
101
+ }
102
+ const isWalletActive = walletConnectorCore.isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
103
+ if (!isWalletActive) {
104
+ this.activeAccountAddress = targetWallet.accountAddress;
105
+ }
106
+ });
107
+ }
108
+ getAddress() {
109
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
110
+ return this.activeAccountAddress;
111
+ });
112
+ }
113
+ connect() {
114
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
115
+ yield this.getWaasWalletClient();
116
+ });
117
+ }
118
+ signMessage(message) {
119
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
120
+ return this.walletUiUtils.signMessage({
121
+ handler: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignMessage(message); }),
122
+ message,
123
+ walletConnector: this,
124
+ });
125
+ });
126
+ }
127
+ internalSignMessage(message) {
128
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
129
+ var _a, _b;
130
+ const walletClient = yield this.getWaasWalletClient();
131
+ if (!this.activeAccountAddress) {
132
+ throw new Error('Active account address is required');
133
+ }
134
+ const signedSessionId = yield this.requireSignedSessionId();
135
+ const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
136
+ mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
137
+ }));
138
+ const signedMessage = yield walletClient.signMessage({
139
+ accountAddress: this.activeAccountAddress,
140
+ authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
141
+ message,
142
+ mfaToken,
143
+ signedSessionId,
144
+ });
145
+ return signedMessage;
146
+ });
147
+ }
148
+ endSession() {
149
+ const _super = Object.create(null, {
150
+ endSession: { get: () => super.endSession }
151
+ });
152
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
153
+ yield _super.endSession.call(this);
154
+ this.activeAccountAddress = undefined;
155
+ });
156
+ }
157
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
158
+ signMessageWithContext(_params) {
159
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
160
+ throw new Error('Method not implemented.');
161
+ });
162
+ }
163
+ sendTransaction(request) {
164
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
165
+ if (!this.activeAccountAddress) {
166
+ throw new utils.DynamicError('Active account address is required');
167
+ }
168
+ // TON Connect spec allows 1-4 messages per transaction
169
+ if (request.messages.length < 1 || request.messages.length > 4) {
170
+ throw new utils.DynamicError(`Invalid message count: ${request.messages.length}. Must be between 1 and 4.`);
171
+ }
172
+ const displayInfo = extractDisplayInfoFromRequest.extractDisplayInfoFromRequest(request);
173
+ const uiTransaction = new ton$1.TonUiTransaction({
174
+ client: this.getTonClient(),
175
+ from: this.activeAccountAddress,
176
+ onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSendTransaction(request); }),
177
+ });
178
+ uiTransaction.to = displayInfo.recipient;
179
+ uiTransaction.value = displayInfo.value
180
+ ? BigInt(displayInfo.value)
181
+ : undefined;
182
+ // Handle jetton transfers
183
+ if (displayInfo.jettonAddress && displayInfo.jettonAmount) {
184
+ uiTransaction.nonNativeAddress = displayInfo.jettonAddress;
185
+ uiTransaction.nonNativeValue = BigInt(displayInfo.jettonAmount);
186
+ }
187
+ return this.walletUiUtils.sendTransaction(this, uiTransaction);
188
+ });
189
+ }
190
+ internalSendTransaction(request) {
191
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
192
+ var _a, _b;
193
+ if (!this.activeAccountAddress) {
194
+ throw new utils.DynamicError('Active account address is required');
195
+ }
196
+ const client = this.getTonClient();
197
+ const walletAddress = request.from || this.activeAccountAddress;
198
+ const network = request.network || index.CHAIN.MAINNET;
199
+ const seqno = yield getWalletSeqno.getWalletSeqno(walletAddress, client);
200
+ const actionsArray = convertSendTransactionRequest.convertSendTransactionRequest(request);
201
+ const { hashToSignHex, transactionData } = prepareTransaction.prepareTransaction({
202
+ actionsArray,
203
+ networkGlobalId: network,
204
+ seqno,
205
+ timeout: request.validUntil - Math.floor(Date.now() / 1000),
206
+ validUntil: request.validUntil,
207
+ walletAddress,
208
+ });
209
+ const walletClient = yield this.getWaasWalletClient();
210
+ const signedSessionId = yield this.requireSignedSessionId();
211
+ const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
212
+ mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
213
+ }));
214
+ const signature = yield walletClient.signTransaction({
215
+ authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
216
+ mfaToken,
217
+ senderAddress: this.activeAccountAddress,
218
+ signedSessionId,
219
+ transaction: hashToSignHex,
220
+ });
221
+ const result = yield executeTransaction.executeTransaction({
222
+ client,
223
+ signature,
224
+ transactionData,
225
+ });
226
+ if (!result.success) {
227
+ throw new utils.DynamicError(`Failed to execute transaction: ${result.error || 'Unknown error'}`);
228
+ }
229
+ return result.transactionHash || '';
230
+ });
231
+ }
232
+ internalSendUiTransaction(transaction) {
233
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
234
+ if (!transaction.to) {
235
+ throw new utils.DynamicError('Destination address is required');
236
+ }
237
+ if (!this.activeAccountAddress) {
238
+ throw new utils.DynamicError('Active account address is required');
239
+ }
240
+ const client = this.getTonClient();
241
+ // Handle Jetton (non-native token) transfers
242
+ if (transaction.nonNativeAddress && transaction.nonNativeValue) {
243
+ const request = yield prepareJettonTransfer.prepareJettonTransfer({
244
+ client,
245
+ forwardTonAmount: BigInt(0),
246
+ jettonAmount: transaction.nonNativeValue,
247
+ jettonMasterAddress: transaction.nonNativeAddress,
248
+ recipientAddress: transaction.to,
249
+ timeout: 60,
250
+ walletAddress: this.activeAccountAddress,
251
+ });
252
+ return this.internalSendTransaction(request);
253
+ }
254
+ // Handle native TON transfers
255
+ if (transaction.value) {
256
+ const tonAmount = Number(transaction.value) / ton$1.NANOTON_PER_TON;
257
+ const request = yield prepareTonTransfer.prepareTonTransfer({
258
+ amount: tonAmount,
259
+ client,
260
+ recipient: transaction.to,
261
+ timeout: 60,
262
+ walletAddress: this.activeAccountAddress,
263
+ });
264
+ return this.internalSendTransaction(request);
265
+ }
266
+ throw new utils.DynamicError('Invalid transaction parameters');
267
+ });
268
+ }
269
+ createUiTransaction(from) {
270
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
271
+ yield this.validateActiveWallet(from);
272
+ const client = this.getTonClient();
273
+ return new ton$1.TonUiTransaction({
274
+ client,
275
+ from,
276
+ onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSendUiTransaction(transaction); }),
277
+ });
278
+ });
279
+ }
280
+ }
281
+
282
+ exports.DynamicWaasTonConnector = DynamicWaasTonConnector;
@@ -0,0 +1,153 @@
1
+ import { TonClient } from '@ton/ton';
2
+ import { MFAAction, SignMessageContext } from '@dynamic-labs/sdk-api-core';
3
+ import { IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
4
+ import { IDynamicWaasConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
5
+ import { DynamicWaasTonSigner } from '../signer/DynamicWaasTonSigner';
6
+ import { SendTransactionRequest } from '../types';
7
+ import { Logger } from '../utils';
8
+ import { TonWalletConnector, TonWalletConnectorOpts } from './TonWalletConnector';
9
+ export type DynamicWaasTonConnectorProps = TonWalletConnectorOpts & {
10
+ walletUiUtils: WalletUiUtils<InternalWalletConnector>;
11
+ };
12
+ declare const DynamicWaasTonConnector_base: (abstract new (...args: any[]) => {
13
+ [x: string]: any;
14
+ name: string;
15
+ overrideKey: string;
16
+ isEmbeddedWallet: boolean;
17
+ getSignedSessionId?: (() => Promise<string>) | undefined;
18
+ getMfaToken?: ((props?: {
19
+ mfaAction?: MFAAction | undefined;
20
+ } | undefined) => Promise<string | undefined>) | undefined;
21
+ getAuthToken?: (() => string) | undefined;
22
+ environmentId?: string | undefined;
23
+ baseApiUrl?: string | undefined;
24
+ relayUrl?: string | undefined;
25
+ baseClientKeysharesRelayApiUrl?: string | undefined;
26
+ dynamicWaasClient: import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient | undefined;
27
+ chainName: string;
28
+ authMode: "cookie" | "header";
29
+ logger: Logger;
30
+ __exportHandler: import("@dynamic-labs/waas").WaasExportHandler;
31
+ validateActiveWallet(expectedAddress: string): Promise<void>;
32
+ setGetAuthTokenFunction(getAuthToken: () => string): void;
33
+ setWaasAuthMode(authMode: "cookie" | "header"): void;
34
+ setGetMfaTokenFunction(getMfaToken: (props?: {
35
+ mfaAction?: MFAAction | undefined;
36
+ } | undefined) => Promise<string | undefined>): void;
37
+ setEnvironmentId(environmentId: string): void;
38
+ setBaseApiUrl(baseApiUrl: string): void;
39
+ setBaseClientKeysharesRelayApiUrl(baseClientKeysharesRelayApiUrl?: string | undefined): void;
40
+ setRelayUrl(relayUrl: string): void;
41
+ setGetSignedSessionIdFunction(getSignedSessionId: () => Promise<string>): void;
42
+ delegateKeyShares({ accountAddress, password, }: {
43
+ accountAddress: string;
44
+ password?: string | undefined;
45
+ }): Promise<void>;
46
+ createDynamicWaasClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
47
+ getWaasWalletClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
48
+ createWalletAccount({ thresholdSignatureScheme, password, }?: {
49
+ thresholdSignatureScheme?: string | undefined;
50
+ password?: string | undefined;
51
+ } | undefined): Promise<{
52
+ chainName: string;
53
+ accountAddress: string;
54
+ publicKeyHex: string;
55
+ rawPublicKey: string | Uint8Array | undefined;
56
+ }>;
57
+ importPrivateKey({ privateKey, thresholdSignatureScheme, publicAddressCheck, }: {
58
+ privateKey: string;
59
+ thresholdSignatureScheme?: string | undefined;
60
+ publicAddressCheck?: string | undefined;
61
+ }): Promise<void>;
62
+ exportPrivateKey({ accountAddress, displayContainer, password, }?: {
63
+ accountAddress?: string | undefined;
64
+ displayContainer?: HTMLIFrameElement | undefined;
65
+ password?: string | undefined;
66
+ } | undefined): Promise<void>;
67
+ getExportHandler(): {
68
+ clear: () => void;
69
+ };
70
+ exportClientKeyshares({ accountAddress, password, }: {
71
+ accountAddress: string;
72
+ password?: string | undefined;
73
+ }): Promise<void>;
74
+ backupKeySharesToGoogleDrive({ accountAddress, password, }: {
75
+ accountAddress: string;
76
+ password?: string | undefined;
77
+ }): Promise<void>;
78
+ exportClientKeysharesFromGoogleDrive({ accountAddress, password, }: {
79
+ accountAddress: string;
80
+ password?: string | undefined;
81
+ }): Promise<void>;
82
+ refreshWalletAccountShares({ accountAddress, password, }: {
83
+ accountAddress: string;
84
+ password?: string | undefined;
85
+ }): Promise<void>;
86
+ reshareWalletAccountShares({ accountAddress, thresholdSignatureScheme, password, }: {
87
+ accountAddress: string;
88
+ thresholdSignatureScheme: string;
89
+ password?: string | undefined;
90
+ }): Promise<void>;
91
+ revokeDelegation({ accountAddress, password, }: {
92
+ accountAddress: string;
93
+ password?: string | undefined;
94
+ }): Promise<void>;
95
+ updatePassword({ accountAddress, existingPassword, newPassword, }: {
96
+ accountAddress: string;
97
+ existingPassword: string;
98
+ newPassword: string;
99
+ }): Promise<void>;
100
+ signRawMessage({ accountAddress, message, password, }: {
101
+ accountAddress: string;
102
+ message: string;
103
+ password?: string | undefined;
104
+ }): Promise<string>;
105
+ endSession(): Promise<void>;
106
+ getActiveAccountAddress(): Promise<string | undefined>;
107
+ generateTraceId(): string;
108
+ instrument(message: string, context: import("dist/packages/logger/src").InstrumentOptions & import("dist/packages/waas/utils/instrumentation").InstrumentContext & Record<string, any>): void;
109
+ instrumentAsync<T_1>({ operation, resource, fn, context, }: {
110
+ operation: string;
111
+ resource: string;
112
+ fn: (timing: import("dist/packages/waas/utils/instrumentation").InstrumentationTimer) => Promise<T_1>;
113
+ context?: Record<string, any> | undefined;
114
+ }): Promise<T_1>;
115
+ }) & typeof TonWalletConnector;
116
+ export declare class DynamicWaasTonConnector extends DynamicWaasTonConnector_base implements IDynamicWaasConnector {
117
+ name: string;
118
+ overrideKey: string;
119
+ isEmbeddedWallet: boolean;
120
+ logger: Logger;
121
+ activeAccountAddress: string | undefined;
122
+ protected walletUiUtils: WalletUiUtils<InternalWalletConnector>;
123
+ constructor(props: DynamicWaasTonConnectorProps);
124
+ /**
125
+ * Override setEnvironmentId to ensure it's set on the global logger
126
+ */
127
+ setEnvironmentId(environmentId: string): void;
128
+ getSigner(): Promise<DynamicWaasTonSigner>;
129
+ getWalletClientByAddress({ accountAddress, }: {
130
+ accountAddress: string;
131
+ }): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
132
+ getTonClient(chainId?: string): TonClient;
133
+ getActiveAccountAddress(): Promise<string | undefined>;
134
+ private setActiveAccountAddress;
135
+ private requireSignedSessionId;
136
+ validateActiveWallet(expectedAddress: string): Promise<void>;
137
+ getAddress(): Promise<string | undefined>;
138
+ connect(): Promise<void>;
139
+ signMessage(message: string): Promise<string>;
140
+ internalSignMessage(message: string): Promise<string>;
141
+ endSession(): Promise<void>;
142
+ signMessageWithContext(_params: {
143
+ message: string | {
144
+ raw: string;
145
+ };
146
+ context: SignMessageContext;
147
+ }): Promise<string>;
148
+ sendTransaction(request: SendTransactionRequest): Promise<string>;
149
+ private internalSendTransaction;
150
+ private internalSendUiTransaction;
151
+ createUiTransaction(from: string): Promise<IUITransaction>;
152
+ }
153
+ export {};