@dynamic-labs/ton 4.60.0 → 4.61.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 (40) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +9 -9
  5. package/src/TonWalletConnector.cjs +1 -1
  6. package/src/TonWalletConnector.js +1 -1
  7. package/src/connectors/TonConnectConnector/TonConnectConnector.cjs +709 -0
  8. package/src/connectors/TonConnectConnector/TonConnectConnector.d.ts +169 -0
  9. package/src/connectors/TonConnectConnector/TonConnectConnector.js +705 -0
  10. package/src/connectors/TonConnectConnector/index.d.ts +1 -0
  11. package/src/consts.d.ts +4 -0
  12. package/src/index.cjs +11 -5
  13. package/src/index.d.ts +6 -1
  14. package/src/index.js +8 -3
  15. package/src/types.d.ts +61 -1
  16. package/src/utils/debugLog/debugLog.cjs +55 -0
  17. package/src/utils/debugLog/debugLog.d.ts +34 -0
  18. package/src/utils/debugLog/debugLog.js +49 -0
  19. package/src/utils/debugLog/index.d.ts +1 -0
  20. package/src/utils/fetchTonWalletConnectors/fetchTonWalletConnectors.cjs +113 -0
  21. package/src/utils/fetchTonWalletConnectors/fetchTonWalletConnectors.d.ts +41 -0
  22. package/src/utils/fetchTonWalletConnectors/fetchTonWalletConnectors.js +108 -0
  23. package/src/utils/fetchTonWalletConnectors/index.d.ts +1 -0
  24. package/src/utils/index.d.ts +1 -0
  25. package/src/waas/connector/DynamicWaasTonConnector.d.ts +6 -9
  26. package/src/wallet/TonWallet/TonWallet.cjs +140 -0
  27. package/src/wallet/TonWallet/TonWallet.d.ts +65 -0
  28. package/src/wallet/TonWallet/TonWallet.js +136 -0
  29. package/src/wallet/TonWallet/index.d.ts +1 -0
  30. package/src/wallet/WaasTonWallet.cjs +1 -1
  31. package/src/wallet/WaasTonWallet.js +1 -1
  32. package/src/wallet/isTonWallet/isTonWallet.cjs +7 -1
  33. package/src/wallet/isTonWallet/isTonWallet.d.ts +7 -1
  34. package/src/wallet/isTonWallet/isTonWallet.js +7 -1
  35. package/src/TonWalletConnectors.cjs +0 -13
  36. package/src/TonWalletConnectors.d.ts +0 -2
  37. package/src/TonWalletConnectors.js +0 -9
  38. package/src/wallet/TonWallet.cjs +0 -109
  39. package/src/wallet/TonWallet.d.ts +0 -60
  40. package/src/wallet/TonWallet.js +0 -105
@@ -0,0 +1 @@
1
+ export { TonConnectConnector } from './TonConnectConnector';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * TON Connect feature identifier for wallet-standard
3
+ */
4
+ export declare const TONCONNECT_FEATURE = "ton-connect:";
package/src/index.cjs CHANGED
@@ -5,8 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
7
  var _package = require('../package.cjs');
8
+ var fetchTonWalletConnectors = require('./utils/fetchTonWalletConnectors/fetchTonWalletConnectors.cjs');
9
+ var DynamicWaasTonConnectors = require('./waas/DynamicWaasTonConnectors.cjs');
8
10
  var TonWalletConnector = require('./TonWalletConnector.cjs');
9
- var TonWallet = require('./wallet/TonWallet.cjs');
11
+ var sdk = require('@tonconnect/sdk');
12
+ var TonWallet = require('./wallet/TonWallet/TonWallet.cjs');
10
13
  var isTonWallet = require('./wallet/isTonWallet/isTonWallet.cjs');
11
14
  var WaasTonWallet = require('./wallet/WaasTonWallet.cjs');
12
15
  var TonUiTransaction = require('./utils/TonUiTransaction/TonUiTransaction.cjs');
@@ -22,13 +25,17 @@ var generateTonConnectProofHash = require('./utils/generateTonConnectProofHash/g
22
25
  require('./utils/logger/logger.cjs');
23
26
  require('../_virtual/_tslib.cjs');
24
27
  require('@ton/ton');
25
- var TonWalletConnectors = require('./TonWalletConnectors.cjs');
26
28
  var DynamicWaasTonConnector = require('./waas/connector/DynamicWaasTonConnector.cjs');
27
- var DynamicWaasTonConnectors = require('./waas/DynamicWaasTonConnectors.cjs');
28
29
 
29
30
  assertPackageVersion.assertPackageVersion('@dynamic-labs/ton', _package.version);
31
+ const TonWalletConnectors = (props) => [...fetchTonWalletConnectors.fetchTonWalletConnectors(props), ...DynamicWaasTonConnectors.DynamicWaasTonConnectors()];
30
32
 
33
+ exports.DynamicWaasTonConnectors = DynamicWaasTonConnectors.DynamicWaasTonConnectors;
31
34
  exports.TonWalletConnector = TonWalletConnector.TonWalletConnector;
35
+ Object.defineProperty(exports, 'CHAIN', {
36
+ enumerable: true,
37
+ get: function () { return sdk.CHAIN; }
38
+ });
32
39
  exports.TonWallet = TonWallet.TonWallet;
33
40
  exports.isTonWallet = isTonWallet.isTonWallet;
34
41
  exports.WaasTonWallet = WaasTonWallet.WaasTonWallet;
@@ -43,6 +50,5 @@ exports.executeTransaction = executeTransaction.executeTransaction;
43
50
  exports.extractDisplayInfoFromRequest = extractDisplayInfoFromRequest.extractDisplayInfoFromRequest;
44
51
  exports.convertSendTransactionRequest = convertSendTransactionRequest.convertSendTransactionRequest;
45
52
  exports.generateTonConnectProofHash = generateTonConnectProofHash.generateTonConnectProofHash;
46
- exports.TonWalletConnectors = TonWalletConnectors.TonWalletConnectors;
47
53
  exports.DynamicWaasTonConnector = DynamicWaasTonConnector.DynamicWaasTonConnector;
48
- exports.DynamicWaasTonConnectors = DynamicWaasTonConnectors.DynamicWaasTonConnectors;
54
+ exports.TonWalletConnectors = TonWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
2
+ import type { GenericNetwork } from '@dynamic-labs/types';
1
3
  export { TonWalletConnector } from './TonWalletConnector';
2
4
  export * from './types';
3
5
  export { TonWallet, isTonWallet, WaasTonWallet } from './wallet';
4
6
  export { TonUiTransaction, NANOTON_PER_TON, prepareTransaction, prepareTonTransfer, prepareJettonTransfer, getJettonWalletAddress, getWalletSeqno, executeTransaction, extractDisplayInfoFromRequest, convertSendTransactionRequest, generateTonConnectProofHash, } from './utils';
5
7
  export type { PrepareTransactionParams, PrepareTransactionResult, PrepareTonTransferParams, PrepareJettonTransferParams, GetJettonWalletAddressParams, ExecuteTransactionParams, ExecuteTransactionResult, GenerateTonConnectProofHashParams, TransactionRequestDisplayInfo, } from './utils';
6
- export { TonWalletConnectors } from './TonWalletConnectors';
7
8
  export { DynamicWaasTonConnector } from './waas/connector/DynamicWaasTonConnector';
8
9
  export type { DynamicWaasTonConnectorProps } from './waas/connector/DynamicWaasTonConnector';
9
10
  export { DynamicWaasTonConnectors } from './waas/DynamicWaasTonConnectors';
11
+ export declare const TonWalletConnectors: (props: {
12
+ walletBook: WalletBookSchema;
13
+ tonNetworks?: GenericNetwork[];
14
+ }) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
package/src/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  'use client'
2
2
  import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
3
  import { version } from '../package.js';
4
+ import { fetchTonWalletConnectors } from './utils/fetchTonWalletConnectors/fetchTonWalletConnectors.js';
5
+ import { DynamicWaasTonConnectors } from './waas/DynamicWaasTonConnectors.js';
6
+ export { DynamicWaasTonConnectors } from './waas/DynamicWaasTonConnectors.js';
4
7
  export { TonWalletConnector } from './TonWalletConnector.js';
5
- export { TonWallet } from './wallet/TonWallet.js';
8
+ export { CHAIN } from '@tonconnect/sdk';
9
+ export { TonWallet } from './wallet/TonWallet/TonWallet.js';
6
10
  export { isTonWallet } from './wallet/isTonWallet/isTonWallet.js';
7
11
  export { WaasTonWallet } from './wallet/WaasTonWallet.js';
8
12
  export { NANOTON_PER_TON, TonUiTransaction } from './utils/TonUiTransaction/TonUiTransaction.js';
@@ -18,8 +22,9 @@ export { generateTonConnectProofHash } from './utils/generateTonConnectProofHash
18
22
  import './utils/logger/logger.js';
19
23
  import '../_virtual/_tslib.js';
20
24
  import '@ton/ton';
21
- export { TonWalletConnectors } from './TonWalletConnectors.js';
22
25
  export { DynamicWaasTonConnector } from './waas/connector/DynamicWaasTonConnector.js';
23
- export { DynamicWaasTonConnectors } from './waas/DynamicWaasTonConnectors.js';
24
26
 
25
27
  assertPackageVersion('@dynamic-labs/ton', version);
28
+ const TonWalletConnectors = (props) => [...fetchTonWalletConnectors(props), ...DynamicWaasTonConnectors()];
29
+
30
+ export { TonWalletConnectors };
package/src/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CHAIN } from '@tonconnect/sdk';
1
+ import { CHAIN } from '@tonconnect/sdk';
2
2
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
3
  import { WalletMetadata } from '@dynamic-labs/wallet-connector-core';
4
4
  import { GenericNetwork } from '@dynamic-labs/types';
@@ -67,6 +67,64 @@ export interface TonTransactionData {
67
67
  /** Transaction timeout in seconds */
68
68
  timeout: number;
69
69
  }
70
+ /**
71
+ * Options for sending TON (native currency) transactions
72
+ */
73
+ export type SendTonOptions = {
74
+ /** Recipient address */
75
+ to: string;
76
+ /** Amount in nanoTON (1 TON = 1,000,000,000 nanoTON) */
77
+ amount: string;
78
+ /** Optional comment/message */
79
+ comment?: string;
80
+ };
81
+ /**
82
+ * Options for sending Jetton (token) transactions
83
+ */
84
+ export type SendJettonOptions = {
85
+ /** Jetton contract address */
86
+ jettonAddress: string;
87
+ /** Recipient address */
88
+ to: string;
89
+ /** Amount in jetton units */
90
+ amount: string;
91
+ /** Optional comment/message */
92
+ comment?: string;
93
+ };
94
+ /**
95
+ * Result of a transaction send operation
96
+ */
97
+ export type TonTransactionResult = {
98
+ /** Transaction hash/ID */
99
+ boc?: string;
100
+ /** Transaction hash in hex format */
101
+ hash?: string;
102
+ };
103
+ /**
104
+ * Network information for TON
105
+ */
106
+ export type TonNetworkInfo = {
107
+ /** Chain ID */
108
+ chainId: number;
109
+ /** Network name (mainnet, testnet) */
110
+ name: string;
111
+ };
112
+ /**
113
+ * Extended SendTransactionRequest with additional options
114
+ * Note: This extends the SendTransactionRequest from @tonconnect/sdk
115
+ */
116
+ export type TonSendTransactionRequest = {
117
+ /** Transaction messages */
118
+ messages: Array<{
119
+ address: string;
120
+ amount: string;
121
+ payload?: string;
122
+ }>;
123
+ /** Transaction validity timestamp (Unix time in seconds) */
124
+ validUntil: number;
125
+ /** Optional comment for the transaction */
126
+ comment?: string;
127
+ };
70
128
  /**
71
129
  * Options for creating a TON Connect connector instance.
72
130
  */
@@ -79,6 +137,8 @@ export type TonConnectConnectorOpts = {
79
137
  metadata?: WalletMetadata;
80
138
  /** Optional manifest URL for TON Connect (required for TON Connect initialization) */
81
139
  manifestUrl?: string;
140
+ /** Optional override key for the connector */
141
+ overrideKey?: string;
82
142
  };
83
143
  /**
84
144
  * TON network configuration.
@@ -0,0 +1,55 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /* eslint-disable no-console */
7
+ const isDebugEnabled = () => typeof window !== 'undefined' && process.env.NODE_ENV === 'development';
8
+ /**
9
+ * Logs debug messages with a specified log level.
10
+ * Only logs in development mode and browser environment.
11
+ *
12
+ * @param level - Log level: 'log' | 'error' | 'warn' | 'info'
13
+ * @param args - Arguments to pass to the console method
14
+ */
15
+ const debugLogWithLevel = (level, ...args) => {
16
+ if (isDebugEnabled()) {
17
+ console[level](...args);
18
+ }
19
+ };
20
+ /**
21
+ * Logs debug messages only in development mode and browser environment.
22
+ * This ensures debug logs don't appear in production or during SSR.
23
+ *
24
+ * @param args - Arguments to pass to console.log
25
+ */
26
+ const debugLog = (...args) => {
27
+ debugLogWithLevel('log', ...args);
28
+ };
29
+ /**
30
+ * Logs multiple debug messages in a single call.
31
+ * Each array represents a separate console.log call.
32
+ * Only logs in development mode and browser environment.
33
+ *
34
+ * @param lines - Arrays of arguments, each array is logged as a separate line
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * debugLogMultiline(
39
+ * ['[TON] Total wallets:', count],
40
+ * ['[TON] Found wallets:', foundCount],
41
+ * ['[TON] Wallet keys:', keys],
42
+ * );
43
+ * ```
44
+ */
45
+ const debugLogMultiline = (...lines) => {
46
+ if (isDebugEnabled()) {
47
+ lines.forEach((args) => {
48
+ console.log(...args);
49
+ });
50
+ }
51
+ };
52
+
53
+ exports.debugLog = debugLog;
54
+ exports.debugLogMultiline = debugLogMultiline;
55
+ exports.debugLogWithLevel = debugLogWithLevel;
@@ -0,0 +1,34 @@
1
+ type LogLevel = 'log' | 'error' | 'warn' | 'info';
2
+ /**
3
+ * Logs debug messages with a specified log level.
4
+ * Only logs in development mode and browser environment.
5
+ *
6
+ * @param level - Log level: 'log' | 'error' | 'warn' | 'info'
7
+ * @param args - Arguments to pass to the console method
8
+ */
9
+ export declare const debugLogWithLevel: (level: LogLevel, ...args: unknown[]) => void;
10
+ /**
11
+ * Logs debug messages only in development mode and browser environment.
12
+ * This ensures debug logs don't appear in production or during SSR.
13
+ *
14
+ * @param args - Arguments to pass to console.log
15
+ */
16
+ export declare const debugLog: (...args: unknown[]) => void;
17
+ /**
18
+ * Logs multiple debug messages in a single call.
19
+ * Each array represents a separate console.log call.
20
+ * Only logs in development mode and browser environment.
21
+ *
22
+ * @param lines - Arrays of arguments, each array is logged as a separate line
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * debugLogMultiline(
27
+ * ['[TON] Total wallets:', count],
28
+ * ['[TON] Found wallets:', foundCount],
29
+ * ['[TON] Wallet keys:', keys],
30
+ * );
31
+ * ```
32
+ */
33
+ export declare const debugLogMultiline: (...lines: unknown[][]) => void;
34
+ export {};
@@ -0,0 +1,49 @@
1
+ 'use client'
2
+ /* eslint-disable no-console */
3
+ const isDebugEnabled = () => typeof window !== 'undefined' && process.env.NODE_ENV === 'development';
4
+ /**
5
+ * Logs debug messages with a specified log level.
6
+ * Only logs in development mode and browser environment.
7
+ *
8
+ * @param level - Log level: 'log' | 'error' | 'warn' | 'info'
9
+ * @param args - Arguments to pass to the console method
10
+ */
11
+ const debugLogWithLevel = (level, ...args) => {
12
+ if (isDebugEnabled()) {
13
+ console[level](...args);
14
+ }
15
+ };
16
+ /**
17
+ * Logs debug messages only in development mode and browser environment.
18
+ * This ensures debug logs don't appear in production or during SSR.
19
+ *
20
+ * @param args - Arguments to pass to console.log
21
+ */
22
+ const debugLog = (...args) => {
23
+ debugLogWithLevel('log', ...args);
24
+ };
25
+ /**
26
+ * Logs multiple debug messages in a single call.
27
+ * Each array represents a separate console.log call.
28
+ * Only logs in development mode and browser environment.
29
+ *
30
+ * @param lines - Arrays of arguments, each array is logged as a separate line
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * debugLogMultiline(
35
+ * ['[TON] Total wallets:', count],
36
+ * ['[TON] Found wallets:', foundCount],
37
+ * ['[TON] Wallet keys:', keys],
38
+ * );
39
+ * ```
40
+ */
41
+ const debugLogMultiline = (...lines) => {
42
+ if (isDebugEnabled()) {
43
+ lines.forEach((args) => {
44
+ console.log(...args);
45
+ });
46
+ }
47
+ };
48
+
49
+ export { debugLog, debugLogMultiline, debugLogWithLevel };
@@ -0,0 +1 @@
1
+ export { debugLog, debugLogWithLevel, debugLogMultiline } from './debugLog';
@@ -0,0 +1,113 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var walletBook = require('@dynamic-labs/wallet-book');
7
+ var TonConnectConnector = require('../../connectors/TonConnectConnector/TonConnectConnector.cjs');
8
+ var debugLog = require('../debugLog/debugLog.cjs');
9
+
10
+ /* eslint-disable @typescript-eslint/no-unused-vars */
11
+ /**
12
+ * Checks if a wallet configuration supports TON Connect.
13
+ *
14
+ * A wallet is considered valid if it has:
15
+ * - An injected config for the 'ton' chain
16
+ *
17
+ * @param wallet - The wallet configuration to check
18
+ * @returns true if the wallet supports TON Connect, false otherwise
19
+ */
20
+ const isValidTonConnectWallet = (wallet) => { var _a; return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'ton')); };
21
+ /**
22
+ * Discovers TON Connect wallets and creates connectors.
23
+ *
24
+ * TON Connect wallets are discovered from the official wallets list maintained at:
25
+ * https://github.com/ton-connect/wallets-list
26
+ *
27
+ * The TON Connect SDK automatically fetches this list when getWallets() is called.
28
+ * When a user clicks to connect, the SDK shows a UI with all available wallets
29
+ * from the official list, so individual connectors aren't needed for each wallet.
30
+ *
31
+ * This function:
32
+ * 1. Creates connectors for wallets found in the wallet book (for custom metadata/icons)
33
+ * 2. Falls back to a generic connector that uses TON Connect SDK's built-in wallet selection
34
+ *
35
+ * @param walletBook - The wallet book schema containing all wallet configurations
36
+ * @param tonNetworks - Optional TON networks configuration
37
+ * @returns Array of wallet connector constructors for TON Connect enabled wallets
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const tonConnectors = fetchTonWalletConnectors({ walletBook, tonNetworks });
42
+ * // Returns connectors for wallets like Tonkeeper, MyTonWallet, etc.
43
+ * ```
44
+ */
45
+ const fetchTonWalletConnectors = ({ walletBook: walletBook$1, tonNetworks = [], }) => {
46
+ var _a;
47
+ // Create connectors from wallet book entries (these provide custom metadata/icons)
48
+ const allWallets = Object.entries((_a = walletBook$1 === null || walletBook$1 === void 0 ? void 0 : walletBook$1.wallets) !== null && _a !== void 0 ? _a : {});
49
+ const tonWallets = allWallets.filter(([_, wallet]) => isValidTonConnectWallet(wallet));
50
+ // Debug logging
51
+ debugLog.debugLogMultiline(['[TON] Total wallets in wallet book:', allWallets.length], ['[TON] TON wallets found:', tonWallets.length], ['[TON] TON wallet keys:', tonWallets.map(([key]) => key)]);
52
+ const walletBookConnectors = tonWallets.map(([key, wallet]) => {
53
+ const { shortName } = wallet;
54
+ const name = shortName || wallet.name;
55
+ return class extends TonConnectConnector.TonConnectConnector {
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ constructor(props) {
58
+ var _a;
59
+ super(Object.assign(Object.assign({}, props), { metadata: {
60
+ brandColor: undefined,
61
+ deepLinks: undefined,
62
+ downloadLinks: undefined,
63
+ groupKey: undefined,
64
+ icon: ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.brand) === null || _a === void 0 ? void 0 : _a.spriteId)
65
+ ? walletBook.renderTemplate('iconicUrl', wallet.brand.spriteId)
66
+ : '',
67
+ id: key,
68
+ name: name,
69
+ rdns: undefined,
70
+ supportedHardwareWallets: undefined,
71
+ walletLimitations: undefined,
72
+ }, overrideKey: key, tonNetworks,
73
+ walletBook: walletBook$1 }));
74
+ this.name = name;
75
+ this.overrideKey = key;
76
+ }
77
+ };
78
+ });
79
+ // If wallets found in wallet book, return them
80
+ if (walletBookConnectors.length > 0) {
81
+ debugLog.debugLog('[TON] Returning', walletBookConnectors.length, 'connector(s) from wallet book');
82
+ return walletBookConnectors;
83
+ }
84
+ // Return a generic connector that uses TON Connect SDK's built-in wallet selection
85
+ // The SDK automatically fetches wallets from the official list at:
86
+ // https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json
87
+ // When connect() is called, it shows a UI with all available wallets
88
+ return [
89
+ class extends TonConnectConnector.TonConnectConnector {
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ constructor(props) {
92
+ super(Object.assign(Object.assign({}, props), { metadata: {
93
+ brandColor: undefined,
94
+ deepLinks: undefined,
95
+ downloadLinks: undefined,
96
+ groupKey: undefined,
97
+ icon: '', // Will use default TON icon from chain icon mapping
98
+ id: 'tonconnect',
99
+ name: 'TON Connect',
100
+ rdns: undefined,
101
+ supportedHardwareWallets: undefined,
102
+ walletLimitations: undefined,
103
+ }, tonNetworks,
104
+ walletBook: walletBook$1 }));
105
+ this.name = 'TON Connect';
106
+ this.overrideKey = 'tonconnect';
107
+ }
108
+ },
109
+ ];
110
+ };
111
+
112
+ exports.fetchTonWalletConnectors = fetchTonWalletConnectors;
113
+ exports.isValidTonConnectWallet = isValidTonConnectWallet;
@@ -0,0 +1,41 @@
1
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
2
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
3
+ import type { GenericNetwork } from '@dynamic-labs/types';
4
+ /**
5
+ * Checks if a wallet configuration supports TON Connect.
6
+ *
7
+ * A wallet is considered valid if it has:
8
+ * - An injected config for the 'ton' chain
9
+ *
10
+ * @param wallet - The wallet configuration to check
11
+ * @returns true if the wallet supports TON Connect, false otherwise
12
+ */
13
+ export declare const isValidTonConnectWallet: (wallet: WalletBookSchema['wallets'][string]) => boolean;
14
+ /**
15
+ * Discovers TON Connect wallets and creates connectors.
16
+ *
17
+ * TON Connect wallets are discovered from the official wallets list maintained at:
18
+ * https://github.com/ton-connect/wallets-list
19
+ *
20
+ * The TON Connect SDK automatically fetches this list when getWallets() is called.
21
+ * When a user clicks to connect, the SDK shows a UI with all available wallets
22
+ * from the official list, so individual connectors aren't needed for each wallet.
23
+ *
24
+ * This function:
25
+ * 1. Creates connectors for wallets found in the wallet book (for custom metadata/icons)
26
+ * 2. Falls back to a generic connector that uses TON Connect SDK's built-in wallet selection
27
+ *
28
+ * @param walletBook - The wallet book schema containing all wallet configurations
29
+ * @param tonNetworks - Optional TON networks configuration
30
+ * @returns Array of wallet connector constructors for TON Connect enabled wallets
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const tonConnectors = fetchTonWalletConnectors({ walletBook, tonNetworks });
35
+ * // Returns connectors for wallets like Tonkeeper, MyTonWallet, etc.
36
+ * ```
37
+ */
38
+ export declare const fetchTonWalletConnectors: ({ walletBook, tonNetworks, }: {
39
+ walletBook: WalletBookSchema;
40
+ tonNetworks?: GenericNetwork[];
41
+ }) => WalletConnectorConstructor[];
@@ -0,0 +1,108 @@
1
+ 'use client'
2
+ import { renderTemplate } from '@dynamic-labs/wallet-book';
3
+ import { TonConnectConnector } from '../../connectors/TonConnectConnector/TonConnectConnector.js';
4
+ import { debugLogMultiline, debugLog } from '../debugLog/debugLog.js';
5
+
6
+ /* eslint-disable @typescript-eslint/no-unused-vars */
7
+ /**
8
+ * Checks if a wallet configuration supports TON Connect.
9
+ *
10
+ * A wallet is considered valid if it has:
11
+ * - An injected config for the 'ton' chain
12
+ *
13
+ * @param wallet - The wallet configuration to check
14
+ * @returns true if the wallet supports TON Connect, false otherwise
15
+ */
16
+ const isValidTonConnectWallet = (wallet) => { var _a; return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'ton')); };
17
+ /**
18
+ * Discovers TON Connect wallets and creates connectors.
19
+ *
20
+ * TON Connect wallets are discovered from the official wallets list maintained at:
21
+ * https://github.com/ton-connect/wallets-list
22
+ *
23
+ * The TON Connect SDK automatically fetches this list when getWallets() is called.
24
+ * When a user clicks to connect, the SDK shows a UI with all available wallets
25
+ * from the official list, so individual connectors aren't needed for each wallet.
26
+ *
27
+ * This function:
28
+ * 1. Creates connectors for wallets found in the wallet book (for custom metadata/icons)
29
+ * 2. Falls back to a generic connector that uses TON Connect SDK's built-in wallet selection
30
+ *
31
+ * @param walletBook - The wallet book schema containing all wallet configurations
32
+ * @param tonNetworks - Optional TON networks configuration
33
+ * @returns Array of wallet connector constructors for TON Connect enabled wallets
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const tonConnectors = fetchTonWalletConnectors({ walletBook, tonNetworks });
38
+ * // Returns connectors for wallets like Tonkeeper, MyTonWallet, etc.
39
+ * ```
40
+ */
41
+ const fetchTonWalletConnectors = ({ walletBook, tonNetworks = [], }) => {
42
+ var _a;
43
+ // Create connectors from wallet book entries (these provide custom metadata/icons)
44
+ const allWallets = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {});
45
+ const tonWallets = allWallets.filter(([_, wallet]) => isValidTonConnectWallet(wallet));
46
+ // Debug logging
47
+ debugLogMultiline(['[TON] Total wallets in wallet book:', allWallets.length], ['[TON] TON wallets found:', tonWallets.length], ['[TON] TON wallet keys:', tonWallets.map(([key]) => key)]);
48
+ const walletBookConnectors = tonWallets.map(([key, wallet]) => {
49
+ const { shortName } = wallet;
50
+ const name = shortName || wallet.name;
51
+ return class extends TonConnectConnector {
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ constructor(props) {
54
+ var _a;
55
+ super(Object.assign(Object.assign({}, props), { metadata: {
56
+ brandColor: undefined,
57
+ deepLinks: undefined,
58
+ downloadLinks: undefined,
59
+ groupKey: undefined,
60
+ icon: ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.brand) === null || _a === void 0 ? void 0 : _a.spriteId)
61
+ ? renderTemplate('iconicUrl', wallet.brand.spriteId)
62
+ : '',
63
+ id: key,
64
+ name: name,
65
+ rdns: undefined,
66
+ supportedHardwareWallets: undefined,
67
+ walletLimitations: undefined,
68
+ }, overrideKey: key, tonNetworks,
69
+ walletBook }));
70
+ this.name = name;
71
+ this.overrideKey = key;
72
+ }
73
+ };
74
+ });
75
+ // If wallets found in wallet book, return them
76
+ if (walletBookConnectors.length > 0) {
77
+ debugLog('[TON] Returning', walletBookConnectors.length, 'connector(s) from wallet book');
78
+ return walletBookConnectors;
79
+ }
80
+ // Return a generic connector that uses TON Connect SDK's built-in wallet selection
81
+ // The SDK automatically fetches wallets from the official list at:
82
+ // https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json
83
+ // When connect() is called, it shows a UI with all available wallets
84
+ return [
85
+ class extends TonConnectConnector {
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ constructor(props) {
88
+ super(Object.assign(Object.assign({}, props), { metadata: {
89
+ brandColor: undefined,
90
+ deepLinks: undefined,
91
+ downloadLinks: undefined,
92
+ groupKey: undefined,
93
+ icon: '', // Will use default TON icon from chain icon mapping
94
+ id: 'tonconnect',
95
+ name: 'TON Connect',
96
+ rdns: undefined,
97
+ supportedHardwareWallets: undefined,
98
+ walletLimitations: undefined,
99
+ }, tonNetworks,
100
+ walletBook }));
101
+ this.name = 'TON Connect';
102
+ this.overrideKey = 'tonconnect';
103
+ }
104
+ },
105
+ ];
106
+ };
107
+
108
+ export { fetchTonWalletConnectors, isValidTonConnectWallet };
@@ -0,0 +1 @@
1
+ export { fetchTonWalletConnectors } from './fetchTonWalletConnectors';
@@ -11,3 +11,4 @@ export * from './generateTonConnectProofHash';
11
11
  export * from './logger/logger';
12
12
  export * from './isWalletDeployed/isWalletDeployed';
13
13
  export * from './createWalletStateInit/createWalletStateInit';
14
+ export * from './debugLog';
@@ -18,7 +18,7 @@ declare const DynamicWaasTonConnector_base: (abstract new (...args: any[]) => {
18
18
  getMfaToken?: ((props?: {
19
19
  mfaAction?: MFAAction | undefined;
20
20
  } | undefined) => Promise<string | undefined>) | undefined;
21
- getPasswordForSigning?: import("dist/packages/waas/src/DynamicWaasMixin").GetPasswordForSigningFn | undefined;
21
+ getWalletPassword?: import("@dynamic-labs/wallet-connector-core").GetWalletPasswordFn | undefined;
22
22
  getAuthToken?: (() => string) | undefined;
23
23
  environmentId?: string | undefined;
24
24
  baseApiUrl?: string | undefined;
@@ -35,7 +35,7 @@ declare const DynamicWaasTonConnector_base: (abstract new (...args: any[]) => {
35
35
  setGetMfaTokenFunction(getMfaToken: (props?: {
36
36
  mfaAction?: MFAAction | undefined;
37
37
  } | undefined) => Promise<string | undefined>): void;
38
- setGetPasswordForSigningFunction(getPasswordForSigning: import("dist/packages/waas/src/DynamicWaasMixin").GetPasswordForSigningFn): void;
38
+ setGetWalletPasswordFunction(getWalletPassword: import("@dynamic-labs/wallet-connector-core").GetWalletPasswordFn): void;
39
39
  getPasswordIfNeeded({ accountAddress, }: {
40
40
  accountAddress: string;
41
41
  }): Promise<string | undefined>;
@@ -45,9 +45,7 @@ declare const DynamicWaasTonConnector_base: (abstract new (...args: any[]) => {
45
45
  setRelayUrl(relayUrl: string): void;
46
46
  setGetSignedSessionIdFunction(getSignedSessionId: () => Promise<string>): void;
47
47
  delegateKeyShares({ accountAddress, password, }: {
48
- accountAddress: string; /**
49
- * Override setEnvironmentId to ensure it's set on the global logger
50
- */
48
+ accountAddress: string;
51
49
  password?: string | undefined;
52
50
  }): Promise<void>;
53
51
  createDynamicWaasClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
@@ -113,7 +111,7 @@ declare const DynamicWaasTonConnector_base: (abstract new (...args: any[]) => {
113
111
  }): Promise<void>;
114
112
  updatePassword({ accountAddress, existingPassword, newPassword, }: {
115
113
  accountAddress: string;
116
- existingPassword: string;
114
+ existingPassword?: string | undefined;
117
115
  newPassword: string;
118
116
  }): Promise<void>;
119
117
  signRawMessage({ accountAddress, message, password, }: {
@@ -123,11 +121,10 @@ declare const DynamicWaasTonConnector_base: (abstract new (...args: any[]) => {
123
121
  }): Promise<string>;
124
122
  unlockWallet({ accountAddress, password, }: {
125
123
  accountAddress: string;
126
- password: string;
124
+ password?: string | undefined;
127
125
  }): Promise<import("@dynamic-labs-wallet/core").GetWalletResponse>;
128
- getWalletRecoveryState({ accountAddress, signedSessionId, }: {
126
+ getWalletRecoveryState({ accountAddress, }: {
129
127
  accountAddress: string;
130
- signedSessionId: string;
131
128
  }): Promise<import("@dynamic-labs-wallet/core").WalletRecoveryState>;
132
129
  endSession(): Promise<void>;
133
130
  getActiveAccountAddress(): Promise<string | undefined>;