pwc-sdk-wallet 0.8.1 → 0.8.2
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.
- package/dist/Vault.d.ts +5 -5
- package/dist/Vault.js +33 -118
- package/dist/index.d.ts +0 -3
- package/dist/index.js +4 -6
- package/package.json +2 -3
- package/dist/chain/TronChainService.d.ts +0 -130
- package/dist/chain/TronChainService.js +0 -350
- package/dist/keyrings/TronKeyring.d.ts +0 -88
- package/dist/keyrings/TronKeyring.js +0 -286
package/dist/Vault.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Recipient, MultiTransferResult } from './types/multiTransfer';
|
|
|
4
4
|
import { NFTDetailExtended, NFTBalance, NFTOptions } from './types/nft';
|
|
5
5
|
export interface Account {
|
|
6
6
|
address: string;
|
|
7
|
-
type: 'HD' | 'Simple' | 'Solana'
|
|
7
|
+
type: 'HD' | 'Simple' | 'Solana';
|
|
8
8
|
name: string;
|
|
9
9
|
}
|
|
10
10
|
export interface TransactionResponse {
|
|
@@ -51,7 +51,7 @@ export declare class Vault {
|
|
|
51
51
|
/**
|
|
52
52
|
* Creates a new Vault with a fresh mnemonic.
|
|
53
53
|
* @param password - The password used to encrypt the vault data
|
|
54
|
-
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana
|
|
54
|
+
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana). Defaults to 'evm'
|
|
55
55
|
* @returns Promise resolving to an object containing the created vault instance and its encrypted data
|
|
56
56
|
* @throws Error if mnemonic generation or keyring initialization fails
|
|
57
57
|
*/
|
|
@@ -63,7 +63,7 @@ export declare class Vault {
|
|
|
63
63
|
* Creates a new Vault from an existing mnemonic phrase.
|
|
64
64
|
* @param mnemonic - The existing mnemonic phrase (12, 15, 18, 21, or 24 words)
|
|
65
65
|
* @param password - The password used to encrypt the vault data
|
|
66
|
-
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana
|
|
66
|
+
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana). Defaults to 'evm'
|
|
67
67
|
* @returns Promise resolving to an object containing the created vault instance and its encrypted data
|
|
68
68
|
* @throws Error if mnemonic is invalid or keyring initialization fails
|
|
69
69
|
*/
|
|
@@ -92,7 +92,7 @@ export declare class Vault {
|
|
|
92
92
|
*/
|
|
93
93
|
addNewSolanaAccount(): Promise<Account>;
|
|
94
94
|
/**
|
|
95
|
-
* Adds a new TRON account derived from the TRON keyring.
|
|
95
|
+
* Adds a new TRON account derived from the TRON keyring. (TEMPORARILY DISABLED)
|
|
96
96
|
* @returns Promise resolving to the newly created TRON account information
|
|
97
97
|
* @throws Error if no TRON keyring is available in the vault
|
|
98
98
|
*/
|
|
@@ -595,7 +595,7 @@ export declare class Vault {
|
|
|
595
595
|
*/
|
|
596
596
|
sendNativeToken(fromAddress: string, to: string, amount: string, chainId: ChainId): Promise<TransactionResponse>;
|
|
597
597
|
/**
|
|
598
|
-
* Sends TRX (native TRON token) to another address.
|
|
598
|
+
* Sends TRX (native TRON token) to another address. (TEMPORARILY DISABLED)
|
|
599
599
|
* @param fromAddress - The sender's TRON address
|
|
600
600
|
* @param to - The recipient's TRON address
|
|
601
601
|
* @param amount - The amount of TRX to send as a string (e.g., "1.5")
|
package/dist/Vault.js
CHANGED
|
@@ -4,10 +4,10 @@ exports.Vault = void 0;
|
|
|
4
4
|
const HDKeyring_1 = require("./keyrings/HDKeyring");
|
|
5
5
|
const SimpleKeyring_1 = require("./keyrings/SimpleKeyring");
|
|
6
6
|
const SolanaKeyring_1 = require("./keyrings/SolanaKeyring");
|
|
7
|
-
|
|
7
|
+
// import { TronKeyring } from './keyrings/TronKeyring'; // TEMPORARILY DISABLED - tronweb compatibility issues
|
|
8
8
|
const ChainService_1 = require("./chain/ChainService");
|
|
9
9
|
const SolanaChainService_1 = require("./chain/SolanaChainService");
|
|
10
|
-
|
|
10
|
+
// import { TronChainService } from './chain/TronChainService'; // TEMPORARILY DISABLED - tronweb compatibility issues
|
|
11
11
|
const EncryptionService_1 = require("./crypto/EncryptionService");
|
|
12
12
|
const chains_1 = require("./config/chains");
|
|
13
13
|
const constants_1 = require("./config/constants");
|
|
@@ -45,7 +45,7 @@ class Vault {
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates a new Vault with a fresh mnemonic.
|
|
47
47
|
* @param password - The password used to encrypt the vault data
|
|
48
|
-
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana
|
|
48
|
+
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana). Defaults to 'evm'
|
|
49
49
|
* @returns Promise resolving to an object containing the created vault instance and its encrypted data
|
|
50
50
|
* @throws Error if mnemonic generation or keyring initialization fails
|
|
51
51
|
*/
|
|
@@ -59,11 +59,7 @@ class Vault {
|
|
|
59
59
|
return { vault, encryptedVault };
|
|
60
60
|
}
|
|
61
61
|
else if (chainType === 'tron') {
|
|
62
|
-
|
|
63
|
-
const vault = new Vault([tronKeyring], config);
|
|
64
|
-
vault.chainId = 'tron'; // Set TRON chain ID
|
|
65
|
-
const encryptedVault = await vault.encrypt(password);
|
|
66
|
-
return { vault, encryptedVault };
|
|
62
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
67
63
|
}
|
|
68
64
|
else {
|
|
69
65
|
const hdKeyring = new HDKeyring_1.HDKeyring(mnemonic);
|
|
@@ -78,7 +74,7 @@ class Vault {
|
|
|
78
74
|
* Creates a new Vault from an existing mnemonic phrase.
|
|
79
75
|
* @param mnemonic - The existing mnemonic phrase (12, 15, 18, 21, or 24 words)
|
|
80
76
|
* @param password - The password used to encrypt the vault data
|
|
81
|
-
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana
|
|
77
|
+
* @param chainType - The type of blockchain to support ('evm' for Ethereum-compatible chains, 'solana' for Solana). Defaults to 'evm'
|
|
82
78
|
* @returns Promise resolving to an object containing the created vault instance and its encrypted data
|
|
83
79
|
* @throws Error if mnemonic is invalid or keyring initialization fails
|
|
84
80
|
*/
|
|
@@ -91,11 +87,7 @@ class Vault {
|
|
|
91
87
|
return { vault, encryptedVault };
|
|
92
88
|
}
|
|
93
89
|
else if (chainType === 'tron') {
|
|
94
|
-
|
|
95
|
-
const vault = new Vault([tronKeyring], config);
|
|
96
|
-
vault.chainId = 'tron'; // Set TRON chain ID
|
|
97
|
-
const encryptedVault = await vault.encrypt(password);
|
|
98
|
-
return { vault, encryptedVault };
|
|
90
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
99
91
|
}
|
|
100
92
|
else {
|
|
101
93
|
const hdKeyring = new HDKeyring_1.HDKeyring(mnemonic);
|
|
@@ -133,10 +125,10 @@ class Vault {
|
|
|
133
125
|
}
|
|
134
126
|
else if (sKeyring.type === 'Solana') {
|
|
135
127
|
keyrings.push(await SolanaKeyring_1.SolanaKeyring.deserialize(sKeyring));
|
|
136
|
-
}
|
|
128
|
+
} /* TEMPORARILY DISABLED - tronweb compatibility issues
|
|
137
129
|
else if (sKeyring.type === 'Tron') {
|
|
138
|
-
keyrings.push(await
|
|
139
|
-
}
|
|
130
|
+
keyrings.push(await TronKeyring.deserialize(sKeyring));
|
|
131
|
+
} */
|
|
140
132
|
else {
|
|
141
133
|
throw new Error(`Unknown keyring type: ${sKeyring.type}`);
|
|
142
134
|
}
|
|
@@ -150,10 +142,10 @@ class Vault {
|
|
|
150
142
|
// Set chain ID based on keyring type
|
|
151
143
|
if (keyrings.some(k => k instanceof SolanaKeyring_1.SolanaKeyring)) {
|
|
152
144
|
vault.chainId = 'solana';
|
|
153
|
-
}
|
|
154
|
-
else if (keyrings.some(k => k instanceof
|
|
145
|
+
} /* TEMPORARILY DISABLED - tronweb compatibility issues
|
|
146
|
+
else if (keyrings.some(k => k instanceof TronKeyring)) {
|
|
155
147
|
vault.chainId = 'tron';
|
|
156
|
-
}
|
|
148
|
+
} */
|
|
157
149
|
else {
|
|
158
150
|
vault.chainId = '1'; // Default to Ethereum mainnet
|
|
159
151
|
}
|
|
@@ -196,21 +188,12 @@ class Vault {
|
|
|
196
188
|
};
|
|
197
189
|
}
|
|
198
190
|
/**
|
|
199
|
-
* Adds a new TRON account derived from the TRON keyring.
|
|
191
|
+
* Adds a new TRON account derived from the TRON keyring. (TEMPORARILY DISABLED)
|
|
200
192
|
* @returns Promise resolving to the newly created TRON account information
|
|
201
193
|
* @throws Error if no TRON keyring is available in the vault
|
|
202
194
|
*/
|
|
203
195
|
async addNewTronAccount() {
|
|
204
|
-
|
|
205
|
-
if (!tronKeyring) {
|
|
206
|
-
throw new Error('No TRON keyring available to create new accounts.');
|
|
207
|
-
}
|
|
208
|
-
const newAddress = await tronKeyring.addNewAccount();
|
|
209
|
-
return {
|
|
210
|
-
address: newAddress,
|
|
211
|
-
type: 'Tron',
|
|
212
|
-
name: `Tron ${tronKeyring.getAllAccounts().length}`
|
|
213
|
-
};
|
|
196
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
214
197
|
}
|
|
215
198
|
/**
|
|
216
199
|
* Imports an account from a private key and adds it to the vault.
|
|
@@ -271,8 +254,8 @@ class Vault {
|
|
|
271
254
|
name: `Solana ${solanaAccountCount++}`,
|
|
272
255
|
});
|
|
273
256
|
}
|
|
274
|
-
}
|
|
275
|
-
else if (keyring instanceof
|
|
257
|
+
} /* TEMPORARILY DISABLED - tronweb compatibility issues
|
|
258
|
+
else if (keyring instanceof TronKeyring) {
|
|
276
259
|
for (const address of keyring.getAllAccounts()) {
|
|
277
260
|
accounts.push({
|
|
278
261
|
address,
|
|
@@ -281,6 +264,7 @@ class Vault {
|
|
|
281
264
|
});
|
|
282
265
|
}
|
|
283
266
|
}
|
|
267
|
+
*/
|
|
284
268
|
}
|
|
285
269
|
return accounts;
|
|
286
270
|
}
|
|
@@ -401,11 +385,10 @@ class Vault {
|
|
|
401
385
|
if (chainInfo.type === 'solana') {
|
|
402
386
|
const chainService = new SolanaChainService_1.SolanaChainService(privateKey, chainInfo);
|
|
403
387
|
return chainService.getNativeBalance();
|
|
404
|
-
}
|
|
388
|
+
} /* TEMPORARILY DISABLED - tronweb compatibility issues
|
|
405
389
|
else if (chainInfo.type === 'tron') {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
390
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
391
|
+
} */
|
|
409
392
|
else {
|
|
410
393
|
const chainService = new ChainService_1.ChainService(privateKey, chainInfo);
|
|
411
394
|
return chainService.getNativeBalance();
|
|
@@ -1373,17 +1356,10 @@ class Vault {
|
|
|
1373
1356
|
to: result.to,
|
|
1374
1357
|
blockNumber: result.blockNumber || undefined
|
|
1375
1358
|
};
|
|
1376
|
-
}
|
|
1359
|
+
} /* TEMPORARILY DISABLED - tronweb compatibility issues
|
|
1377
1360
|
else if (chainInfo.type === 'tron') {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
return {
|
|
1381
|
-
hash: result.hash,
|
|
1382
|
-
from: result.from,
|
|
1383
|
-
to: result.to,
|
|
1384
|
-
blockNumber: result.blockNumber || undefined
|
|
1385
|
-
};
|
|
1386
|
-
}
|
|
1361
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1362
|
+
} */
|
|
1387
1363
|
else {
|
|
1388
1364
|
const chainService = new ChainService_1.ChainService(privateKey, chainInfo);
|
|
1389
1365
|
// Create transaction request for native token transfer
|
|
@@ -1400,9 +1376,10 @@ class Vault {
|
|
|
1400
1376
|
};
|
|
1401
1377
|
}
|
|
1402
1378
|
}
|
|
1403
|
-
// --- TRON Operations ---
|
|
1379
|
+
// --- TRON Operations --- (TEMPORARILY DISABLED - tronweb compatibility issues)
|
|
1380
|
+
// All TRON-related methods are temporarily disabled due to tronweb compatibility issues with React Native
|
|
1404
1381
|
/**
|
|
1405
|
-
* Sends TRX (native TRON token) to another address.
|
|
1382
|
+
* Sends TRX (native TRON token) to another address. (TEMPORARILY DISABLED)
|
|
1406
1383
|
* @param fromAddress - The sender's TRON address
|
|
1407
1384
|
* @param to - The recipient's TRON address
|
|
1408
1385
|
* @param amount - The amount of TRX to send as a string (e.g., "1.5")
|
|
@@ -1417,19 +1394,7 @@ class Vault {
|
|
|
1417
1394
|
* ```
|
|
1418
1395
|
*/
|
|
1419
1396
|
async sendTRX(fromAddress, to, amount) {
|
|
1420
|
-
|
|
1421
|
-
if (chainInfo.type !== 'tron') {
|
|
1422
|
-
throw new Error('TRON chain configuration not found');
|
|
1423
|
-
}
|
|
1424
|
-
const privateKey = await this.getPrivateKeyFor(fromAddress);
|
|
1425
|
-
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
1426
|
-
const result = await chainService.sendTransaction(to, amount);
|
|
1427
|
-
return {
|
|
1428
|
-
hash: result.hash,
|
|
1429
|
-
from: result.from,
|
|
1430
|
-
to: result.to,
|
|
1431
|
-
blockNumber: result.blockNumber
|
|
1432
|
-
};
|
|
1397
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1433
1398
|
}
|
|
1434
1399
|
/**
|
|
1435
1400
|
* Sends TRC-20 tokens on TRON blockchain.
|
|
@@ -1452,19 +1417,7 @@ class Vault {
|
|
|
1452
1417
|
* ```
|
|
1453
1418
|
*/
|
|
1454
1419
|
async sendTRC20Token(fromAddress, to, amount, tokenAddress) {
|
|
1455
|
-
|
|
1456
|
-
if (chainInfo.type !== 'tron') {
|
|
1457
|
-
throw new Error('TRON chain configuration not found');
|
|
1458
|
-
}
|
|
1459
|
-
const privateKey = await this.getPrivateKeyFor(fromAddress);
|
|
1460
|
-
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
1461
|
-
const result = await chainService.sendToken(to, amount, tokenAddress);
|
|
1462
|
-
return {
|
|
1463
|
-
hash: result.hash,
|
|
1464
|
-
from: result.from,
|
|
1465
|
-
to: result.to,
|
|
1466
|
-
blockNumber: result.blockNumber
|
|
1467
|
-
};
|
|
1420
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1468
1421
|
}
|
|
1469
1422
|
/**
|
|
1470
1423
|
* Gets TRX balance for a specific address on TRON.
|
|
@@ -1473,13 +1426,7 @@ class Vault {
|
|
|
1473
1426
|
* @throws Error if the balance query fails
|
|
1474
1427
|
*/
|
|
1475
1428
|
async getTRXBalance(address) {
|
|
1476
|
-
|
|
1477
|
-
if (chainInfo.type !== 'tron') {
|
|
1478
|
-
throw new Error('TRON chain configuration not found');
|
|
1479
|
-
}
|
|
1480
|
-
const privateKey = await this.getPrivateKeyFor(address);
|
|
1481
|
-
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
1482
|
-
return await chainService.getNativeBalance();
|
|
1429
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1483
1430
|
}
|
|
1484
1431
|
/**
|
|
1485
1432
|
* Gets TRC-20 token balance for a specific address on TRON.
|
|
@@ -1489,13 +1436,7 @@ class Vault {
|
|
|
1489
1436
|
* @throws Error if the balance query fails
|
|
1490
1437
|
*/
|
|
1491
1438
|
async getTRC20TokenBalance(address, tokenAddress) {
|
|
1492
|
-
|
|
1493
|
-
if (chainInfo.type !== 'tron') {
|
|
1494
|
-
throw new Error('TRON chain configuration not found');
|
|
1495
|
-
}
|
|
1496
|
-
const privateKey = await this.getPrivateKeyFor(address);
|
|
1497
|
-
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
1498
|
-
return await chainService.getTokenBalance(tokenAddress);
|
|
1439
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1499
1440
|
}
|
|
1500
1441
|
/**
|
|
1501
1442
|
* Gets TRC-20 token information.
|
|
@@ -1504,21 +1445,7 @@ class Vault {
|
|
|
1504
1445
|
* @throws Error if the token query fails
|
|
1505
1446
|
*/
|
|
1506
1447
|
async getTRC20TokenInfo(tokenAddress) {
|
|
1507
|
-
|
|
1508
|
-
if (chainInfo.type !== 'tron') {
|
|
1509
|
-
throw new Error('TRON chain configuration not found');
|
|
1510
|
-
}
|
|
1511
|
-
// Use a dummy private key for read-only operations
|
|
1512
|
-
const dummyPrivateKey = '0000000000000000000000000000000000000000000000000000000000000001';
|
|
1513
|
-
const chainService = new TronChainService_1.TronChainService(dummyPrivateKey, chainInfo);
|
|
1514
|
-
const tokenInfo = await chainService.getTokenInfo(tokenAddress);
|
|
1515
|
-
return {
|
|
1516
|
-
address: tokenInfo.address,
|
|
1517
|
-
name: tokenInfo.name,
|
|
1518
|
-
symbol: tokenInfo.symbol,
|
|
1519
|
-
decimals: tokenInfo.decimals,
|
|
1520
|
-
totalSupply: tokenInfo.totalSupply
|
|
1521
|
-
};
|
|
1448
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1522
1449
|
}
|
|
1523
1450
|
/**
|
|
1524
1451
|
* Estimates the transaction fee for a TRX transfer.
|
|
@@ -1529,13 +1456,7 @@ class Vault {
|
|
|
1529
1456
|
* @throws Error if the estimation fails
|
|
1530
1457
|
*/
|
|
1531
1458
|
async estimateTRXTransferFee(fromAddress, to, amount) {
|
|
1532
|
-
|
|
1533
|
-
if (chainInfo.type !== 'tron') {
|
|
1534
|
-
throw new Error('TRON chain configuration not found');
|
|
1535
|
-
}
|
|
1536
|
-
const privateKey = await this.getPrivateKeyFor(fromAddress);
|
|
1537
|
-
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
1538
|
-
return await chainService.estimateTransactionFee(to, amount);
|
|
1459
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1539
1460
|
}
|
|
1540
1461
|
/**
|
|
1541
1462
|
* Estimates the transaction fee for a TRC-20 token transfer.
|
|
@@ -1547,13 +1468,7 @@ class Vault {
|
|
|
1547
1468
|
* @throws Error if the estimation fails
|
|
1548
1469
|
*/
|
|
1549
1470
|
async estimateTRC20TransferFee(fromAddress, to, amount, tokenAddress) {
|
|
1550
|
-
|
|
1551
|
-
if (chainInfo.type !== 'tron') {
|
|
1552
|
-
throw new Error('TRON chain configuration not found');
|
|
1553
|
-
}
|
|
1554
|
-
const privateKey = await this.getPrivateKeyFor(fromAddress);
|
|
1555
|
-
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
1556
|
-
return await chainService.estimateTokenTransferFee(to, amount, tokenAddress);
|
|
1471
|
+
throw new Error('TRON support is temporarily disabled due to tronweb compatibility issues with React Native.');
|
|
1557
1472
|
}
|
|
1558
1473
|
}
|
|
1559
1474
|
exports.Vault = Vault;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export type { Account } from './Vault';
|
|
|
3
3
|
export type { ChainId, ChainConfig } from './config/chains';
|
|
4
4
|
export type { EncryptedData } from './crypto/EncryptionService';
|
|
5
5
|
export type { Token } from './chain/ChainService';
|
|
6
|
-
export type { TronTransactionResponse, TronToken } from './chain/TronChainService';
|
|
7
6
|
export type { Recipient, MultiTransferOptions, MultiTransferResult, BatchResult, ValidationResult } from './types/multiTransfer';
|
|
8
7
|
export type { QRCodeData, WalletImportData, TransactionData } from './services/QRCodeService';
|
|
9
8
|
export { SUPPORTED_CHAINS, DERIVATION_PATHS, registerCustomChain, overrideChain, overrideChains, getChainConfig, setupChainConfigs, getAllAvailableChains, clearCustomChains, clearOverrides, clearOverride, getCustomChains, getOverrides, setGlobalRPCConfig, setGlobalExplorerConfig, clearGlobalConfigs } from './config/chains';
|
|
@@ -13,10 +12,8 @@ export { getEnvironmentConfig, validateEnvironmentConfig, getEnvVar, getEnvVarNu
|
|
|
13
12
|
export { HDKeyring } from './keyrings/HDKeyring';
|
|
14
13
|
export { SimpleKeyring } from './keyrings/SimpleKeyring';
|
|
15
14
|
export { SolanaKeyring } from './keyrings/SolanaKeyring';
|
|
16
|
-
export { TronKeyring } from './keyrings/TronKeyring';
|
|
17
15
|
export { ChainService } from './chain/ChainService';
|
|
18
16
|
export { SolanaChainService } from './chain/SolanaChainService';
|
|
19
|
-
export { TronChainService } from './chain/TronChainService';
|
|
20
17
|
export { EncryptionService } from './crypto/EncryptionService';
|
|
21
18
|
export { MultiTransferService } from './services/MultiTransferService';
|
|
22
19
|
export { BatchProcessor } from './services/BatchProcessor';
|
package/dist/index.js
CHANGED
|
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
exports.usePWCWallet = exports.ConnectionModal =
|
|
18
|
+
exports.TransactionModal = exports.DAppBrowser = exports.TransactionHandler = exports.MessageBridgeService = exports.BrowserProviderService = exports.QRCodeService = exports.BatchProcessor = exports.MultiTransferService = exports.EncryptionService = exports.SolanaChainService = exports.ChainService = exports.SolanaKeyring = exports.SimpleKeyring = exports.HDKeyring = exports.getEnvVarBoolean = exports.getEnvVarBigInt = exports.getEnvVarNumber = exports.getEnvVar = exports.validateEnvironmentConfig = exports.getEnvironmentConfig = exports.VALIDATION_CONFIG = exports.CACHE_CONFIG = exports.NETWORK_CONFIG = exports.SECURITY_CONFIG = exports.VANITY_WALLET_CONFIG = exports.clearGlobalGasConfigs = exports.getGasConfig = exports.setGlobalNetworkGasConfig = exports.setGlobalGasConfig = exports.calculateOptimalGasPrice = exports.getNetworkGasConfig = exports.NETWORK_GAS_CONFIG = exports.GAS_CONFIG = exports.clearGlobalConfigs = exports.setGlobalExplorerConfig = exports.setGlobalRPCConfig = exports.getOverrides = exports.getCustomChains = exports.clearOverride = exports.clearOverrides = exports.clearCustomChains = exports.getAllAvailableChains = exports.setupChainConfigs = exports.getChainConfig = exports.overrideChains = exports.overrideChain = exports.registerCustomChain = exports.DERIVATION_PATHS = exports.SUPPORTED_CHAINS = exports.Vault = void 0;
|
|
19
|
+
exports.usePWCWallet = exports.ConnectionModal = void 0;
|
|
20
20
|
// The primary `Vault` class is the main entry point for interacting with the SDK.
|
|
21
21
|
var Vault_1 = require("./Vault");
|
|
22
22
|
Object.defineProperty(exports, "Vault", { enumerable: true, get: function () { return Vault_1.Vault; } });
|
|
@@ -73,15 +73,13 @@ var SimpleKeyring_1 = require("./keyrings/SimpleKeyring");
|
|
|
73
73
|
Object.defineProperty(exports, "SimpleKeyring", { enumerable: true, get: function () { return SimpleKeyring_1.SimpleKeyring; } });
|
|
74
74
|
var SolanaKeyring_1 = require("./keyrings/SolanaKeyring");
|
|
75
75
|
Object.defineProperty(exports, "SolanaKeyring", { enumerable: true, get: function () { return SolanaKeyring_1.SolanaKeyring; } });
|
|
76
|
-
|
|
77
|
-
Object.defineProperty(exports, "TronKeyring", { enumerable: true, get: function () { return TronKeyring_1.TronKeyring; } });
|
|
76
|
+
// export { TronKeyring } from './keyrings/TronKeyring'; // TEMPORARILY DISABLED
|
|
78
77
|
// Chain services
|
|
79
78
|
var ChainService_1 = require("./chain/ChainService");
|
|
80
79
|
Object.defineProperty(exports, "ChainService", { enumerable: true, get: function () { return ChainService_1.ChainService; } });
|
|
81
80
|
var SolanaChainService_1 = require("./chain/SolanaChainService");
|
|
82
81
|
Object.defineProperty(exports, "SolanaChainService", { enumerable: true, get: function () { return SolanaChainService_1.SolanaChainService; } });
|
|
83
|
-
|
|
84
|
-
Object.defineProperty(exports, "TronChainService", { enumerable: true, get: function () { return TronChainService_1.TronChainService; } });
|
|
82
|
+
// export { TronChainService } from './chain/TronChainService'; // TEMPORARILY DISABLED
|
|
85
83
|
// `EncryptionService` provides access to the underlying encryption/decryption methods.
|
|
86
84
|
var EncryptionService_1 = require("./crypto/EncryptionService");
|
|
87
85
|
Object.defineProperty(exports, "EncryptionService", { enumerable: true, get: function () { return EncryptionService_1.EncryptionService; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwc-sdk-wallet",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,8 +50,7 @@
|
|
|
50
50
|
"react-native-permissions": "^5.4.1",
|
|
51
51
|
"react-native-qrcode-svg": "^6.3.15",
|
|
52
52
|
"react-native-svg": "^15.12.0",
|
|
53
|
-
"react-native-webview": "^13.0.0"
|
|
54
|
-
"tronweb": "^5.3.2"
|
|
53
|
+
"react-native-webview": "^13.0.0"
|
|
55
54
|
},
|
|
56
55
|
"peerDependencies": {
|
|
57
56
|
"@react-native-async-storage/async-storage": "^1.21.0",
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { type ChainConfig } from '../config/chains';
|
|
2
|
-
/**
|
|
3
|
-
* Interface representing TRON transaction response.
|
|
4
|
-
* Similar to EVM transaction response but adapted for TRON's transaction structure.
|
|
5
|
-
*/
|
|
6
|
-
export interface TronTransactionResponse {
|
|
7
|
-
/** The transaction hash */
|
|
8
|
-
hash: string;
|
|
9
|
-
/** The sender's address */
|
|
10
|
-
from: string;
|
|
11
|
-
/** The recipient's address */
|
|
12
|
-
to: string;
|
|
13
|
-
/** The block number (optional, not always available immediately) */
|
|
14
|
-
blockNumber?: number;
|
|
15
|
-
/** The transaction fee in SUN (1 TRX = 1,000,000 SUN) */
|
|
16
|
-
fee?: number;
|
|
17
|
-
/** The amount transferred in SUN */
|
|
18
|
-
amount?: bigint;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Interface representing TRON TRC-20 token metadata.
|
|
22
|
-
* Extends the basic token interface with TRON-specific fields.
|
|
23
|
-
*/
|
|
24
|
-
export interface TronToken {
|
|
25
|
-
/** The token contract address */
|
|
26
|
-
address: string;
|
|
27
|
-
/** The token name */
|
|
28
|
-
name: string;
|
|
29
|
-
/** The token symbol */
|
|
30
|
-
symbol: string;
|
|
31
|
-
/** The number of decimal places for the token */
|
|
32
|
-
decimals: number;
|
|
33
|
-
/** The total supply of the token */
|
|
34
|
-
totalSupply?: string;
|
|
35
|
-
/** The token balance for the account */
|
|
36
|
-
balance?: string;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Service for interacting with TRON blockchain.
|
|
40
|
-
* Provides methods for TRX balance checking, TRC-20 token operations, and transaction sending.
|
|
41
|
-
*/
|
|
42
|
-
export declare class TronChainService {
|
|
43
|
-
private tronWeb;
|
|
44
|
-
private privateKey;
|
|
45
|
-
private address;
|
|
46
|
-
/**
|
|
47
|
-
* Creates a new TronChainService instance for the specified TRON network.
|
|
48
|
-
* @param privateKey - The private key to use for signing transactions (hex string)
|
|
49
|
-
* @param chainConfig - The chain configuration to use
|
|
50
|
-
* @throws Error if the chain is not a TRON chain
|
|
51
|
-
*/
|
|
52
|
-
constructor(privateKey: string, chainConfig: ChainConfig);
|
|
53
|
-
/**
|
|
54
|
-
* Gets the native TRX balance for the wallet.
|
|
55
|
-
* @returns Promise resolving to the balance as a bigint in SUN
|
|
56
|
-
* @throws Error if the balance query fails
|
|
57
|
-
*/
|
|
58
|
-
getNativeBalance(): Promise<bigint>;
|
|
59
|
-
/**
|
|
60
|
-
* Sends native TRX to another address.
|
|
61
|
-
* @param to - The recipient's address
|
|
62
|
-
* @param amount - The amount of TRX to send as a string (e.g., "1.5")
|
|
63
|
-
* @returns Promise resolving to the transaction response with hash and details
|
|
64
|
-
* @throws Error if the transaction fails or recipient address is invalid
|
|
65
|
-
*/
|
|
66
|
-
sendTransaction(to: string, amount: string): Promise<TronTransactionResponse>;
|
|
67
|
-
/**
|
|
68
|
-
* Gets the balance of a specific TRC-20 token for the wallet.
|
|
69
|
-
* @param tokenAddress - The token's contract address
|
|
70
|
-
* @returns Promise resolving to the token balance as a bigint
|
|
71
|
-
* @throws Error if the balance query fails (returns 0 if token account doesn't exist)
|
|
72
|
-
*/
|
|
73
|
-
getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
74
|
-
/**
|
|
75
|
-
* Sends TRC-20 tokens to another address.
|
|
76
|
-
* @param to - The recipient's address
|
|
77
|
-
* @param amount - The amount of tokens to send as a string
|
|
78
|
-
* @param tokenAddress - The TRC-20 token contract address
|
|
79
|
-
* @returns Promise resolving to the transaction response with hash and details
|
|
80
|
-
* @throws Error if the transaction fails or recipient address is invalid
|
|
81
|
-
*/
|
|
82
|
-
sendToken(to: string, amount: string, tokenAddress: string): Promise<TronTransactionResponse>;
|
|
83
|
-
/**
|
|
84
|
-
* Gets information about a TRC-20 token.
|
|
85
|
-
* @param tokenAddress - The token's contract address
|
|
86
|
-
* @returns Promise resolving to the token information
|
|
87
|
-
* @throws Error if the token query fails
|
|
88
|
-
*/
|
|
89
|
-
getTokenInfo(tokenAddress: string): Promise<TronToken>;
|
|
90
|
-
/**
|
|
91
|
-
* Estimates the transaction fee for a TRX transfer.
|
|
92
|
-
* @param to - The recipient's address
|
|
93
|
-
* @param amount - The amount of TRX to send
|
|
94
|
-
* @returns Promise resolving to the estimated fee in SUN
|
|
95
|
-
* @throws Error if the estimation fails
|
|
96
|
-
*/
|
|
97
|
-
estimateTransactionFee(to: string, amount: string): Promise<bigint>;
|
|
98
|
-
/**
|
|
99
|
-
* Estimates the transaction fee for a TRC-20 token transfer.
|
|
100
|
-
* @param to - The recipient's address
|
|
101
|
-
* @param amount - The amount of tokens to send
|
|
102
|
-
* @param tokenAddress - The TRC-20 token contract address
|
|
103
|
-
* @returns Promise resolving to the estimated fee in SUN
|
|
104
|
-
* @throws Error if the estimation fails
|
|
105
|
-
*/
|
|
106
|
-
estimateTokenTransferFee(to: string, amount: string, tokenAddress: string): Promise<bigint>;
|
|
107
|
-
/**
|
|
108
|
-
* Gets the current account address.
|
|
109
|
-
* @returns The account address
|
|
110
|
-
*/
|
|
111
|
-
getAddress(): string;
|
|
112
|
-
/**
|
|
113
|
-
* Validates a TRON address format.
|
|
114
|
-
* @param address - The address to validate
|
|
115
|
-
* @returns True if the address is valid, false otherwise
|
|
116
|
-
*/
|
|
117
|
-
static isValidAddress(address: string): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Converts TRX to SUN (smallest unit).
|
|
120
|
-
* @param trx - The amount in TRX
|
|
121
|
-
* @returns The amount in SUN
|
|
122
|
-
*/
|
|
123
|
-
static trxToSun(trx: string): string;
|
|
124
|
-
/**
|
|
125
|
-
* Converts SUN to TRX (human readable unit).
|
|
126
|
-
* @param sun - The amount in SUN
|
|
127
|
-
* @returns The amount in TRX
|
|
128
|
-
*/
|
|
129
|
-
static sunToTrx(sun: string): string;
|
|
130
|
-
}
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TronChainService = void 0;
|
|
7
|
-
const isReactNative = (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') ||
|
|
8
|
-
(typeof window !== 'undefined' && window?.ReactNativeWebView !== undefined) ||
|
|
9
|
-
(typeof global !== 'undefined' && global.__DEV__ !== undefined && typeof navigator !== 'undefined');
|
|
10
|
-
if (isReactNative || (typeof window === 'undefined' && typeof global !== 'undefined')) {
|
|
11
|
-
// Polyfill Buffer
|
|
12
|
-
if (typeof global.Buffer === 'undefined') {
|
|
13
|
-
try {
|
|
14
|
-
global.Buffer = require('buffer').Buffer;
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
console.warn('[PWC SDK] Failed to load buffer polyfill:', e);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Polyfill process
|
|
21
|
-
if (typeof global.process === 'undefined') {
|
|
22
|
-
try {
|
|
23
|
-
global.process = require('process');
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
// Fallback minimal process object
|
|
27
|
-
global.process = {
|
|
28
|
-
env: {},
|
|
29
|
-
version: '',
|
|
30
|
-
versions: {},
|
|
31
|
-
platform: 'react-native',
|
|
32
|
-
nextTick: (fn) => setTimeout(() => fn(), 0),
|
|
33
|
-
browser: true,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Ensure process.env exists
|
|
38
|
-
if (!global.process.env) {
|
|
39
|
-
global.process.env = {};
|
|
40
|
-
}
|
|
41
|
-
// Ensure crypto.getRandomValues is available
|
|
42
|
-
if (typeof global.crypto === 'undefined' || !global.crypto.getRandomValues) {
|
|
43
|
-
try {
|
|
44
|
-
require('react-native-get-random-values');
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
// Fallback if react-native-get-random-values is not installed
|
|
48
|
-
if (typeof global.crypto === 'undefined') {
|
|
49
|
-
global.crypto = {};
|
|
50
|
-
}
|
|
51
|
-
if (!global.crypto.getRandomValues) {
|
|
52
|
-
global.crypto.getRandomValues = function (arr) {
|
|
53
|
-
if (arr) {
|
|
54
|
-
const view = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
55
|
-
for (let i = 0; i < view.length; i++) {
|
|
56
|
-
view[i] = Math.floor(Math.random() * 256);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return arr;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const tronweb_1 = __importDefault(require("tronweb"));
|
|
66
|
-
/**
|
|
67
|
-
* Service for interacting with TRON blockchain.
|
|
68
|
-
* Provides methods for TRX balance checking, TRC-20 token operations, and transaction sending.
|
|
69
|
-
*/
|
|
70
|
-
class TronChainService {
|
|
71
|
-
/**
|
|
72
|
-
* Creates a new TronChainService instance for the specified TRON network.
|
|
73
|
-
* @param privateKey - The private key to use for signing transactions (hex string)
|
|
74
|
-
* @param chainConfig - The chain configuration to use
|
|
75
|
-
* @throws Error if the chain is not a TRON chain
|
|
76
|
-
*/
|
|
77
|
-
constructor(privateKey, chainConfig) {
|
|
78
|
-
if (chainConfig.type !== 'tron') {
|
|
79
|
-
throw new Error('TronChainService only supports TRON chains');
|
|
80
|
-
}
|
|
81
|
-
this.privateKey = privateKey;
|
|
82
|
-
try {
|
|
83
|
-
this.tronWeb = new tronweb_1.default({
|
|
84
|
-
fullHost: chainConfig.rpcUrl,
|
|
85
|
-
privateKey: privateKey
|
|
86
|
-
});
|
|
87
|
-
this.address = this.tronWeb.address.fromPrivateKey(privateKey);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
throw new Error(`Invalid private key format: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Gets the native TRX balance for the wallet.
|
|
95
|
-
* @returns Promise resolving to the balance as a bigint in SUN
|
|
96
|
-
* @throws Error if the balance query fails
|
|
97
|
-
*/
|
|
98
|
-
async getNativeBalance() {
|
|
99
|
-
try {
|
|
100
|
-
const balance = await this.tronWeb.trx.getBalance(this.address);
|
|
101
|
-
return BigInt(balance);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
throw new Error(`Failed to get TRX balance: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Sends native TRX to another address.
|
|
109
|
-
* @param to - The recipient's address
|
|
110
|
-
* @param amount - The amount of TRX to send as a string (e.g., "1.5")
|
|
111
|
-
* @returns Promise resolving to the transaction response with hash and details
|
|
112
|
-
* @throws Error if the transaction fails or recipient address is invalid
|
|
113
|
-
*/
|
|
114
|
-
async sendTransaction(to, amount) {
|
|
115
|
-
try {
|
|
116
|
-
// Validate recipient address
|
|
117
|
-
if (!this.tronWeb.isAddress(to)) {
|
|
118
|
-
throw new Error('Invalid recipient address');
|
|
119
|
-
}
|
|
120
|
-
// Validate amount
|
|
121
|
-
const amountInSun = this.tronWeb.toSun(amount);
|
|
122
|
-
const amountBigInt = BigInt(amountInSun);
|
|
123
|
-
// Check sender balance
|
|
124
|
-
const senderBalance = await this.tronWeb.trx.getBalance(this.address);
|
|
125
|
-
if (BigInt(senderBalance) < amountBigInt) {
|
|
126
|
-
throw new Error(`Insufficient TRX balance. Required: ${amountBigInt} SUN, Available: ${senderBalance} SUN`);
|
|
127
|
-
}
|
|
128
|
-
// Create transaction
|
|
129
|
-
const transaction = await this.tronWeb.transactionBuilder.sendTrx(to, amountInSun, this.address);
|
|
130
|
-
// Sign transaction
|
|
131
|
-
const signedTransaction = await this.tronWeb.trx.sign(transaction);
|
|
132
|
-
// Broadcast transaction
|
|
133
|
-
const result = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
|
|
134
|
-
if (!result.result) {
|
|
135
|
-
throw new Error(`Transaction failed: ${result.message || 'Unknown error'}`);
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
hash: result.txid,
|
|
139
|
-
from: this.address,
|
|
140
|
-
to: to,
|
|
141
|
-
amount: amountBigInt
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
throw new Error(`Failed to send TRX transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Gets the balance of a specific TRC-20 token for the wallet.
|
|
150
|
-
* @param tokenAddress - The token's contract address
|
|
151
|
-
* @returns Promise resolving to the token balance as a bigint
|
|
152
|
-
* @throws Error if the balance query fails (returns 0 if token account doesn't exist)
|
|
153
|
-
*/
|
|
154
|
-
async getTokenBalance(tokenAddress) {
|
|
155
|
-
try {
|
|
156
|
-
if (!this.tronWeb.isAddress(tokenAddress)) {
|
|
157
|
-
throw new Error('Invalid token contract address');
|
|
158
|
-
}
|
|
159
|
-
const contract = await this.tronWeb.contract().at(tokenAddress);
|
|
160
|
-
const balance = await contract.balanceOf(this.address).call();
|
|
161
|
-
return BigInt(balance.toString());
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
// Return 0 if token account doesn't exist or other non-critical errors
|
|
165
|
-
if (error instanceof Error && error.message.includes('not found')) {
|
|
166
|
-
return BigInt(0);
|
|
167
|
-
}
|
|
168
|
-
throw new Error(`Failed to get token balance: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Sends TRC-20 tokens to another address.
|
|
173
|
-
* @param to - The recipient's address
|
|
174
|
-
* @param amount - The amount of tokens to send as a string
|
|
175
|
-
* @param tokenAddress - The TRC-20 token contract address
|
|
176
|
-
* @returns Promise resolving to the transaction response with hash and details
|
|
177
|
-
* @throws Error if the transaction fails or recipient address is invalid
|
|
178
|
-
*/
|
|
179
|
-
async sendToken(to, amount, tokenAddress) {
|
|
180
|
-
try {
|
|
181
|
-
// Validate addresses
|
|
182
|
-
if (!this.tronWeb.isAddress(to)) {
|
|
183
|
-
throw new Error('Invalid recipient address');
|
|
184
|
-
}
|
|
185
|
-
if (!this.tronWeb.isAddress(tokenAddress)) {
|
|
186
|
-
throw new Error('Invalid token contract address');
|
|
187
|
-
}
|
|
188
|
-
// Get token contract
|
|
189
|
-
const contract = await this.tronWeb.contract().at(tokenAddress);
|
|
190
|
-
// Get token decimals
|
|
191
|
-
const decimals = await contract.decimals().call();
|
|
192
|
-
const amountWithDecimals = (parseFloat(amount) * Math.pow(10, decimals)).toString();
|
|
193
|
-
// Check token balance
|
|
194
|
-
const tokenBalance = await contract.balanceOf(this.address).call();
|
|
195
|
-
if (BigInt(tokenBalance.toString()) < BigInt(amountWithDecimals)) {
|
|
196
|
-
throw new Error(`Insufficient token balance. Required: ${amountWithDecimals}, Available: ${tokenBalance}`);
|
|
197
|
-
}
|
|
198
|
-
// Create transfer transaction
|
|
199
|
-
const transaction = await contract.transfer(to, amountWithDecimals).send({
|
|
200
|
-
feeLimit: 100000000, // 100 TRX fee limit
|
|
201
|
-
callValue: 0,
|
|
202
|
-
shouldPollResponse: false
|
|
203
|
-
});
|
|
204
|
-
return {
|
|
205
|
-
hash: transaction,
|
|
206
|
-
from: this.address,
|
|
207
|
-
to: to,
|
|
208
|
-
amount: BigInt(amountWithDecimals)
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
throw new Error(`Failed to send token transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Gets information about a TRC-20 token.
|
|
217
|
-
* @param tokenAddress - The token's contract address
|
|
218
|
-
* @returns Promise resolving to the token information
|
|
219
|
-
* @throws Error if the token query fails
|
|
220
|
-
*/
|
|
221
|
-
async getTokenInfo(tokenAddress) {
|
|
222
|
-
try {
|
|
223
|
-
if (!this.tronWeb.isAddress(tokenAddress)) {
|
|
224
|
-
throw new Error('Invalid token contract address');
|
|
225
|
-
}
|
|
226
|
-
const contract = await this.tronWeb.contract().at(tokenAddress);
|
|
227
|
-
const [name, symbol, decimals, totalSupply, balance] = await Promise.all([
|
|
228
|
-
contract.name().call(),
|
|
229
|
-
contract.symbol().call(),
|
|
230
|
-
contract.decimals().call(),
|
|
231
|
-
contract.totalSupply().call(),
|
|
232
|
-
contract.balanceOf(this.address).call()
|
|
233
|
-
]);
|
|
234
|
-
return {
|
|
235
|
-
address: tokenAddress,
|
|
236
|
-
name: name.toString(),
|
|
237
|
-
symbol: symbol.toString(),
|
|
238
|
-
decimals: parseInt(decimals.toString()),
|
|
239
|
-
totalSupply: totalSupply.toString(),
|
|
240
|
-
balance: balance.toString()
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
throw new Error(`Failed to get token info: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Estimates the transaction fee for a TRX transfer.
|
|
249
|
-
* @param to - The recipient's address
|
|
250
|
-
* @param amount - The amount of TRX to send
|
|
251
|
-
* @returns Promise resolving to the estimated fee in SUN
|
|
252
|
-
* @throws Error if the estimation fails
|
|
253
|
-
*/
|
|
254
|
-
async estimateTransactionFee(to, amount) {
|
|
255
|
-
try {
|
|
256
|
-
if (!this.tronWeb.isAddress(to)) {
|
|
257
|
-
throw new Error('Invalid recipient address');
|
|
258
|
-
}
|
|
259
|
-
const amountInSun = this.tronWeb.toSun(amount);
|
|
260
|
-
// Create transaction to estimate fee
|
|
261
|
-
const transaction = await this.tronWeb.transactionBuilder.sendTrx(to, amountInSun, this.address);
|
|
262
|
-
// Get transaction fee (typically 1.1 TRX = 1,100,000 SUN)
|
|
263
|
-
const fee = transaction.raw_data.contract[0].parameter.value.amount || 0;
|
|
264
|
-
return BigInt(fee);
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
throw new Error(`Failed to estimate transaction fee: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Estimates the transaction fee for a TRC-20 token transfer.
|
|
272
|
-
* @param to - The recipient's address
|
|
273
|
-
* @param amount - The amount of tokens to send
|
|
274
|
-
* @param tokenAddress - The TRC-20 token contract address
|
|
275
|
-
* @returns Promise resolving to the estimated fee in SUN
|
|
276
|
-
* @throws Error if the estimation fails
|
|
277
|
-
*/
|
|
278
|
-
async estimateTokenTransferFee(to, amount, tokenAddress) {
|
|
279
|
-
try {
|
|
280
|
-
if (!this.tronWeb.isAddress(to)) {
|
|
281
|
-
throw new Error('Invalid recipient address');
|
|
282
|
-
}
|
|
283
|
-
if (!this.tronWeb.isAddress(tokenAddress)) {
|
|
284
|
-
throw new Error('Invalid token contract address');
|
|
285
|
-
}
|
|
286
|
-
// TRC-20 transfers typically cost around 13-15 TRX
|
|
287
|
-
// This is a conservative estimate
|
|
288
|
-
return BigInt(15000000); // 15 TRX in SUN
|
|
289
|
-
}
|
|
290
|
-
catch (error) {
|
|
291
|
-
throw new Error(`Failed to estimate token transfer fee: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Gets the current account address.
|
|
296
|
-
* @returns The account address
|
|
297
|
-
*/
|
|
298
|
-
getAddress() {
|
|
299
|
-
return this.address;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Validates a TRON address format.
|
|
303
|
-
* @param address - The address to validate
|
|
304
|
-
* @returns True if the address is valid, false otherwise
|
|
305
|
-
*/
|
|
306
|
-
static isValidAddress(address) {
|
|
307
|
-
try {
|
|
308
|
-
const tronWeb = new tronweb_1.default({
|
|
309
|
-
fullHost: 'https://api.trongrid.io'
|
|
310
|
-
});
|
|
311
|
-
return tronWeb.isAddress(address);
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Converts TRX to SUN (smallest unit).
|
|
319
|
-
* @param trx - The amount in TRX
|
|
320
|
-
* @returns The amount in SUN
|
|
321
|
-
*/
|
|
322
|
-
static trxToSun(trx) {
|
|
323
|
-
try {
|
|
324
|
-
const tronWeb = new tronweb_1.default({
|
|
325
|
-
fullHost: 'https://api.trongrid.io'
|
|
326
|
-
});
|
|
327
|
-
return tronWeb.toSun(trx);
|
|
328
|
-
}
|
|
329
|
-
catch (error) {
|
|
330
|
-
throw new Error(`Failed to convert TRX to SUN: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Converts SUN to TRX (human readable unit).
|
|
335
|
-
* @param sun - The amount in SUN
|
|
336
|
-
* @returns The amount in TRX
|
|
337
|
-
*/
|
|
338
|
-
static sunToTrx(sun) {
|
|
339
|
-
try {
|
|
340
|
-
const tronWeb = new tronweb_1.default({
|
|
341
|
-
fullHost: 'https://api.trongrid.io'
|
|
342
|
-
});
|
|
343
|
-
return tronWeb.fromSun(sun);
|
|
344
|
-
}
|
|
345
|
-
catch (error) {
|
|
346
|
-
throw new Error(`Failed to convert SUN to TRX: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
exports.TronChainService = TronChainService;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TRON keyring for managing multiple TRON accounts
|
|
3
|
-
* derived from a single mnemonic phrase using BIP-44 derivation paths.
|
|
4
|
-
* Supports TRON blockchain with secp256k1 keypairs.
|
|
5
|
-
*/
|
|
6
|
-
export declare class TronKeyring {
|
|
7
|
-
readonly type = "Tron";
|
|
8
|
-
private accounts;
|
|
9
|
-
private privateKeys;
|
|
10
|
-
private mnemonic;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new TronKeyring instance from a mnemonic phrase.
|
|
13
|
-
* @param mnemonic - The mnemonic phrase (12, 15, 18, 21, or 24 words)
|
|
14
|
-
* @throws Error if the mnemonic is invalid
|
|
15
|
-
*/
|
|
16
|
-
constructor(mnemonic: string);
|
|
17
|
-
/**
|
|
18
|
-
* Initializes the keyring by generating the seed and creating the first account.
|
|
19
|
-
* @param mnemonic - The mnemonic phrase to initialize from
|
|
20
|
-
*/
|
|
21
|
-
private initializeFromMnemonic;
|
|
22
|
-
/**
|
|
23
|
-
* Derives a TRON account at a specific index using BIP-44 derivation.
|
|
24
|
-
* @param seed - The seed buffer to derive from
|
|
25
|
-
* @param index - The account index to derive (0-based)
|
|
26
|
-
* @returns The derived TRON account with address and private key
|
|
27
|
-
*/
|
|
28
|
-
private deriveAccount;
|
|
29
|
-
/**
|
|
30
|
-
* Converts a private key to TRON address.
|
|
31
|
-
* @param privateKey - The private key as hex string
|
|
32
|
-
* @returns The TRON address
|
|
33
|
-
*/
|
|
34
|
-
private privateKeyToAddress;
|
|
35
|
-
/**
|
|
36
|
-
* Adds a new TRON account derived from the mnemonic at the next available index.
|
|
37
|
-
* @returns Promise resolving to the address of the newly created account
|
|
38
|
-
* @throws Error if account derivation fails or duplicate address is generated
|
|
39
|
-
*/
|
|
40
|
-
addNewAccount(): Promise<string>;
|
|
41
|
-
/**
|
|
42
|
-
* Gets the private key for a given address managed by this keyring.
|
|
43
|
-
* @param address - The account's address to get the private key for
|
|
44
|
-
* @returns Promise resolving to the private key as a hex string
|
|
45
|
-
* @throws Error if the address is not found in this keyring
|
|
46
|
-
*/
|
|
47
|
-
getPrivateKeyForAddress(address: string): Promise<string>;
|
|
48
|
-
/**
|
|
49
|
-
* Returns the mnemonic phrase. USE WITH CAUTION - this exposes sensitive data.
|
|
50
|
-
* @returns The mnemonic phrase as a string
|
|
51
|
-
*/
|
|
52
|
-
getMnemonic(): string;
|
|
53
|
-
/**
|
|
54
|
-
* Serializes the keyring data for encryption and storage.
|
|
55
|
-
* @returns An object containing the keyring type and mnemonic
|
|
56
|
-
*/
|
|
57
|
-
serialize(): any;
|
|
58
|
-
/**
|
|
59
|
-
* Deserializes data into a TronKeyring instance.
|
|
60
|
-
* @param data - The serialized keyring data
|
|
61
|
-
* @returns Promise resolving to a new TronKeyring instance
|
|
62
|
-
* @throws Error if the data is invalid or missing required fields
|
|
63
|
-
*/
|
|
64
|
-
static deserialize(data: any): Promise<TronKeyring>;
|
|
65
|
-
/**
|
|
66
|
-
* Gets all accounts managed by this keyring.
|
|
67
|
-
* @returns Array of all TRON addresses
|
|
68
|
-
*/
|
|
69
|
-
getAllAccounts(): string[];
|
|
70
|
-
/**
|
|
71
|
-
* Validates a TRON address format.
|
|
72
|
-
* @param address - The address to validate
|
|
73
|
-
* @returns True if the address is valid, false otherwise
|
|
74
|
-
*/
|
|
75
|
-
static isValidAddress(address: string): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Converts a TRON address to hex format (for compatibility with some APIs).
|
|
78
|
-
* @param address - The TRON address in base58 format
|
|
79
|
-
* @returns The address in hex format
|
|
80
|
-
*/
|
|
81
|
-
static addressToHex(address: string): string;
|
|
82
|
-
/**
|
|
83
|
-
* Converts a hex address to TRON address format.
|
|
84
|
-
* @param hexAddress - The address in hex format
|
|
85
|
-
* @returns The address in base58 format
|
|
86
|
-
*/
|
|
87
|
-
static hexToAddress(hexAddress: string): string;
|
|
88
|
-
}
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.TronKeyring = void 0;
|
|
40
|
-
const bip32_1 = require("bip32");
|
|
41
|
-
const ecc = __importStar(require("@bitcoinerlab/secp256k1"));
|
|
42
|
-
const bip39 = __importStar(require("bip39"));
|
|
43
|
-
const chains_1 = require("../config/chains");
|
|
44
|
-
const isReactNative = (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') ||
|
|
45
|
-
(typeof window !== 'undefined' && window?.ReactNativeWebView !== undefined) ||
|
|
46
|
-
(typeof global !== 'undefined' && global.__DEV__ !== undefined && typeof navigator !== 'undefined');
|
|
47
|
-
if (isReactNative || (typeof window === 'undefined' && typeof global !== 'undefined')) {
|
|
48
|
-
// Polyfill Buffer
|
|
49
|
-
if (typeof global.Buffer === 'undefined') {
|
|
50
|
-
try {
|
|
51
|
-
global.Buffer = require('buffer').Buffer;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
console.warn('[PWC SDK] Failed to load buffer polyfill:', e);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// Polyfill process
|
|
58
|
-
if (typeof global.process === 'undefined') {
|
|
59
|
-
try {
|
|
60
|
-
global.process = require('process');
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
// Fallback minimal process object
|
|
64
|
-
global.process = {
|
|
65
|
-
env: {},
|
|
66
|
-
version: '',
|
|
67
|
-
versions: {},
|
|
68
|
-
platform: 'react-native',
|
|
69
|
-
nextTick: (fn) => setTimeout(() => fn(), 0),
|
|
70
|
-
browser: true,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Ensure process.env exists
|
|
75
|
-
if (!global.process.env) {
|
|
76
|
-
global.process.env = {};
|
|
77
|
-
}
|
|
78
|
-
// Ensure crypto.getRandomValues is available
|
|
79
|
-
if (typeof global.crypto === 'undefined' || !global.crypto.getRandomValues) {
|
|
80
|
-
try {
|
|
81
|
-
require('react-native-get-random-values');
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
// Fallback if react-native-get-random-values is not installed
|
|
85
|
-
if (typeof global.crypto === 'undefined') {
|
|
86
|
-
global.crypto = {};
|
|
87
|
-
}
|
|
88
|
-
if (!global.crypto.getRandomValues) {
|
|
89
|
-
global.crypto.getRandomValues = function (arr) {
|
|
90
|
-
if (arr) {
|
|
91
|
-
const view = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
92
|
-
for (let i = 0; i < view.length; i++) {
|
|
93
|
-
view[i] = Math.floor(Math.random() * 256);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return arr;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const tronweb_1 = __importDefault(require("tronweb"));
|
|
103
|
-
/**
|
|
104
|
-
* TRON keyring for managing multiple TRON accounts
|
|
105
|
-
* derived from a single mnemonic phrase using BIP-44 derivation paths.
|
|
106
|
-
* Supports TRON blockchain with secp256k1 keypairs.
|
|
107
|
-
*/
|
|
108
|
-
class TronKeyring {
|
|
109
|
-
/**
|
|
110
|
-
* Creates a new TronKeyring instance from a mnemonic phrase.
|
|
111
|
-
* @param mnemonic - The mnemonic phrase (12, 15, 18, 21, or 24 words)
|
|
112
|
-
* @throws Error if the mnemonic is invalid
|
|
113
|
-
*/
|
|
114
|
-
constructor(mnemonic) {
|
|
115
|
-
this.type = 'Tron';
|
|
116
|
-
this.accounts = [];
|
|
117
|
-
this.privateKeys = new Map();
|
|
118
|
-
if (!bip39.validateMnemonic(mnemonic)) {
|
|
119
|
-
throw new Error('Invalid mnemonic');
|
|
120
|
-
}
|
|
121
|
-
this.mnemonic = mnemonic;
|
|
122
|
-
this.initializeFromMnemonic(mnemonic);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Initializes the keyring by generating the seed and creating the first account.
|
|
126
|
-
* @param mnemonic - The mnemonic phrase to initialize from
|
|
127
|
-
*/
|
|
128
|
-
initializeFromMnemonic(mnemonic) {
|
|
129
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
130
|
-
const firstAccount = this.deriveAccount(seed, 0);
|
|
131
|
-
this.privateKeys.set(firstAccount.address, firstAccount.privateKey);
|
|
132
|
-
this.accounts.push(firstAccount.address);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Derives a TRON account at a specific index using BIP-44 derivation.
|
|
136
|
-
* @param seed - The seed buffer to derive from
|
|
137
|
-
* @param index - The account index to derive (0-based)
|
|
138
|
-
* @returns The derived TRON account with address and private key
|
|
139
|
-
*/
|
|
140
|
-
deriveAccount(seed, index) {
|
|
141
|
-
const path = `${chains_1.DERIVATION_PATHS.TRON.slice(0, -1)}${index}`;
|
|
142
|
-
const bip32 = (0, bip32_1.BIP32Factory)(ecc);
|
|
143
|
-
const root = bip32.fromSeed(seed);
|
|
144
|
-
const child = root.derivePath(path);
|
|
145
|
-
if (!child.privateKey) {
|
|
146
|
-
throw new Error('Failed to derive private key');
|
|
147
|
-
}
|
|
148
|
-
const privateKey = child.privateKey.toString('hex');
|
|
149
|
-
// Generate TRON address from private key
|
|
150
|
-
const address = this.privateKeyToAddress(privateKey);
|
|
151
|
-
return { address, privateKey };
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Converts a private key to TRON address.
|
|
155
|
-
* @param privateKey - The private key as hex string
|
|
156
|
-
* @returns The TRON address
|
|
157
|
-
*/
|
|
158
|
-
privateKeyToAddress(privateKey) {
|
|
159
|
-
try {
|
|
160
|
-
// Create TronWeb instance for address generation
|
|
161
|
-
const tronWeb = new tronweb_1.default({
|
|
162
|
-
fullHost: 'https://api.trongrid.io',
|
|
163
|
-
privateKey: privateKey
|
|
164
|
-
});
|
|
165
|
-
return tronWeb.address.fromPrivateKey(privateKey);
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
throw new Error(`Failed to generate TRON address: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Adds a new TRON account derived from the mnemonic at the next available index.
|
|
173
|
-
* @returns Promise resolving to the address of the newly created account
|
|
174
|
-
* @throws Error if account derivation fails or duplicate address is generated
|
|
175
|
-
*/
|
|
176
|
-
async addNewAccount() {
|
|
177
|
-
const newIndex = this.accounts.length;
|
|
178
|
-
const seed = bip39.mnemonicToSeedSync(this.mnemonic);
|
|
179
|
-
const newAccount = this.deriveAccount(seed, newIndex);
|
|
180
|
-
if (this.accounts.includes(newAccount.address)) {
|
|
181
|
-
throw new Error('Duplicate account derived. Please check derivation path logic.');
|
|
182
|
-
}
|
|
183
|
-
this.privateKeys.set(newAccount.address, newAccount.privateKey);
|
|
184
|
-
this.accounts.push(newAccount.address);
|
|
185
|
-
return newAccount.address;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Gets the private key for a given address managed by this keyring.
|
|
189
|
-
* @param address - The account's address to get the private key for
|
|
190
|
-
* @returns Promise resolving to the private key as a hex string
|
|
191
|
-
* @throws Error if the address is not found in this keyring
|
|
192
|
-
*/
|
|
193
|
-
async getPrivateKeyForAddress(address) {
|
|
194
|
-
const privateKey = this.privateKeys.get(address);
|
|
195
|
-
if (!privateKey) {
|
|
196
|
-
throw new Error('Address not found in this keyring.');
|
|
197
|
-
}
|
|
198
|
-
return privateKey;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Returns the mnemonic phrase. USE WITH CAUTION - this exposes sensitive data.
|
|
202
|
-
* @returns The mnemonic phrase as a string
|
|
203
|
-
*/
|
|
204
|
-
getMnemonic() {
|
|
205
|
-
return this.mnemonic;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Serializes the keyring data for encryption and storage.
|
|
209
|
-
* @returns An object containing the keyring type and mnemonic
|
|
210
|
-
*/
|
|
211
|
-
serialize() {
|
|
212
|
-
return {
|
|
213
|
-
type: this.type,
|
|
214
|
-
mnemonic: this.mnemonic
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Deserializes data into a TronKeyring instance.
|
|
219
|
-
* @param data - The serialized keyring data
|
|
220
|
-
* @returns Promise resolving to a new TronKeyring instance
|
|
221
|
-
* @throws Error if the data is invalid or missing required fields
|
|
222
|
-
*/
|
|
223
|
-
static async deserialize(data) {
|
|
224
|
-
if (data.type !== 'Tron' || !data.mnemonic) {
|
|
225
|
-
throw new Error('Invalid data for TronKeyring deserialization.');
|
|
226
|
-
}
|
|
227
|
-
// Only restore mnemonic, do not restore accounts
|
|
228
|
-
return new TronKeyring(data.mnemonic);
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Gets all accounts managed by this keyring.
|
|
232
|
-
* @returns Array of all TRON addresses
|
|
233
|
-
*/
|
|
234
|
-
getAllAccounts() {
|
|
235
|
-
return [...this.accounts];
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Validates a TRON address format.
|
|
239
|
-
* @param address - The address to validate
|
|
240
|
-
* @returns True if the address is valid, false otherwise
|
|
241
|
-
*/
|
|
242
|
-
static isValidAddress(address) {
|
|
243
|
-
try {
|
|
244
|
-
const tronWeb = new tronweb_1.default({
|
|
245
|
-
fullHost: 'https://api.trongrid.io'
|
|
246
|
-
});
|
|
247
|
-
return tronWeb.isAddress(address);
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Converts a TRON address to hex format (for compatibility with some APIs).
|
|
255
|
-
* @param address - The TRON address in base58 format
|
|
256
|
-
* @returns The address in hex format
|
|
257
|
-
*/
|
|
258
|
-
static addressToHex(address) {
|
|
259
|
-
try {
|
|
260
|
-
const tronWeb = new tronweb_1.default({
|
|
261
|
-
fullHost: 'https://api.trongrid.io'
|
|
262
|
-
});
|
|
263
|
-
return tronWeb.address.toHex(address);
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
throw new Error(`Failed to convert address to hex: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Converts a hex address to TRON address format.
|
|
271
|
-
* @param hexAddress - The address in hex format
|
|
272
|
-
* @returns The address in base58 format
|
|
273
|
-
*/
|
|
274
|
-
static hexToAddress(hexAddress) {
|
|
275
|
-
try {
|
|
276
|
-
const tronWeb = new tronweb_1.default({
|
|
277
|
-
fullHost: 'https://api.trongrid.io'
|
|
278
|
-
});
|
|
279
|
-
return tronWeb.address.fromHex(hexAddress);
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
throw new Error(`Failed to convert hex to address: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
exports.TronKeyring = TronKeyring;
|