@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,169 @@
1
+ import { TonConnect, type SendTransactionRequest } from '@tonconnect/sdk';
2
+ import { TonClient } from '@ton/ton';
3
+ import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
4
+ import type { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
5
+ import { TonWallet } from '../../wallet/TonWallet';
6
+ import type { SendJettonOptions, TonConnectConnectorOpts, TonConnectProof, TonTransactionResult } from '../../types';
7
+ /**
8
+ * TON Connect connector implementation
9
+ *
10
+ * Uses the TON Connect SDK to connect with TON wallets that support
11
+ * the TON Connect protocol (Tonkeeper, MyTonWallet, etc.)
12
+ */
13
+ export declare class TonConnectConnector extends WalletConnectorBase<typeof TonWallet> {
14
+ ChainWallet: typeof TonWallet;
15
+ name: string;
16
+ overrideKey: string;
17
+ connectedChain: Chain;
18
+ supportedChains: Chain[];
19
+ canConnectViaQrCode: boolean;
20
+ private tonConnect;
21
+ private tonNetworks;
22
+ private connectedWallet;
23
+ private pendingProofPayload;
24
+ /**
25
+ * Get the TonConnect instance (for discovering wallets and advanced usage)
26
+ */
27
+ getTonConnect(): TonConnect;
28
+ /**
29
+ * Creates a new TON Connect connector
30
+ *
31
+ * @param opts - Configuration options
32
+ */
33
+ constructor(opts: TonConnectConnectorOpts);
34
+ /**
35
+ * Setup event listeners for TON Connect
36
+ */
37
+ setupEventListeners(): void;
38
+ /**
39
+ * Check if TON Connect is available
40
+ */
41
+ isInstalledOnBrowser(): boolean;
42
+ /**
43
+ * Connect to a TON wallet
44
+ * @param tonProofPayload - Optional payload for tonProof authentication
45
+ */
46
+ connect(tonProofPayload?: string): Promise<void>;
47
+ /**
48
+ * Find a wallet matching this connector's overrideKey
49
+ */
50
+ private findMatchingWallet;
51
+ /**
52
+ * Get the current wallet address in user-friendly format (EQ... or UQ...)
53
+ */
54
+ getAddress(): Promise<string | undefined>;
55
+ /**
56
+ * Get connected accounts
57
+ */
58
+ getConnectedAccounts(): Promise<string[]>;
59
+ /**
60
+ * Get the current network
61
+ */
62
+ getNetwork(): Promise<string | undefined>;
63
+ /**
64
+ * Check if current network is testnet
65
+ */
66
+ isTestnet(): Promise<boolean>;
67
+ /**
68
+ * Sign a message
69
+ */
70
+ signMessage(messageToSign: string): Promise<string>;
71
+ /**
72
+ * Send a transaction
73
+ */
74
+ sendTransaction(request: SendTransactionRequest): Promise<TonTransactionResult>;
75
+ /**
76
+ * Send Jetton transaction
77
+ */
78
+ sendJettonTransaction(_options: SendJettonOptions): Promise<TonTransactionResult>;
79
+ /**
80
+ * Get TonClient for the current or specified network.
81
+ */
82
+ getTonClient(chainId?: string): TonClient;
83
+ /**
84
+ * Get balance of an address
85
+ */
86
+ getBalance(address: string): Promise<string | undefined>;
87
+ /**
88
+ * Get enabled networks
89
+ */
90
+ getEnabledNetworks(): GenericNetwork[];
91
+ /**
92
+ * Switch network (TON Connect handles this automatically)
93
+ */
94
+ switchNetwork(): Promise<void>;
95
+ /**
96
+ * Disconnect and cleanup
97
+ */
98
+ endSession(): Promise<void>;
99
+ /**
100
+ * Create a UI transaction for the send balance flow
101
+ */
102
+ createUiTransaction(from: string): Promise<IUITransaction>;
103
+ /**
104
+ * Internal handler for UI transaction submission
105
+ */
106
+ private internalSendUiTransaction;
107
+ /**
108
+ * Convert TON address from raw format (0:hex) to user-friendly format (UQ...)
109
+ * TON Connect SDK expects user-friendly format for message addresses
110
+ */
111
+ private convertAddressToUserFriendly;
112
+ /**
113
+ * Encode a comment as TON message payload
114
+ *
115
+ * TON comments are encoded as a Cell with:
116
+ * - First 32 bits (4 bytes): 0x00000000 (comment opcode)
117
+ * - Then the UTF-8 bytes of the comment
118
+ *
119
+ * For long messages, the comment is split across multiple cells using references.
120
+ * The Cell is then serialized to base64 BOC format for TON Connect SDK
121
+ */
122
+ encodeComment(comment: string): string;
123
+ /**
124
+ * Check if error is a user rejection
125
+ */
126
+ private isUserRejectionError;
127
+ /**
128
+ * Generate a TON Connect proof for authentication
129
+ * @param payload - The payload string to include in the proof
130
+ * @returns TON Connect proof object
131
+ */
132
+ generateTonConnectProof(payload: string): Promise<TonConnectProof>;
133
+ /**
134
+ * Override proveOwnership to use tonProof for wallet verification
135
+ *
136
+ * For TON wallets, we use the tonProof mechanism during connection
137
+ * which is the standard way to prove wallet ownership in TON Connect.
138
+ * The backend expects a specific format with state_init and public_key.
139
+ */
140
+ proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
141
+ /**
142
+ * proveOwnership using tonProof
143
+ *
144
+ * Returns the proof in the format expected by the backend:
145
+ * {
146
+ * address: string,
147
+ * proof: { domain, payload, signature, state_init, timestamp },
148
+ * public_key: string
149
+ * }
150
+ */
151
+ private proveOwnershipWithTonProof;
152
+ /**
153
+ * Extract public key from state_init cell
154
+ *
155
+ * For standard TON wallets, the public key is stored in the data cell:
156
+ * - First 32 bits: seqno (skipped)
157
+ * - Next 256 bits (32 bytes): public key
158
+ *
159
+ * This matches the extraction logic in the backend.
160
+ */
161
+ private extractPublicKeyFromStateInit;
162
+ /**
163
+ * Extract the nonce from a SIWE-style message
164
+ *
165
+ * @param message - The full message to extract nonce from
166
+ * @returns A short payload suitable for tonProof
167
+ */
168
+ private extractNonceFromMessage;
169
+ }