pwc-sdk-wallet 0.7.9 → 0.8.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.
- package/README.md +101 -5
- package/dist/Vault.d.ts +8 -0
- package/dist/Vault.js +33 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1795,7 +1795,7 @@ console.log('New account address:', newAccount.address);
|
|
|
1795
1795
|
#### Add New Solana Account
|
|
1796
1796
|
```typescript
|
|
1797
1797
|
// Add a new Solana account
|
|
1798
|
-
const newSolanaAccount = vault.
|
|
1798
|
+
const newSolanaAccount = await vault.addNewSolanaAccount();
|
|
1799
1799
|
console.log('New Solana account:', newSolanaAccount.address);
|
|
1800
1800
|
```
|
|
1801
1801
|
|
|
@@ -1827,6 +1827,14 @@ console.log('All accounts:', accounts.map(acc => acc.address));
|
|
|
1827
1827
|
// Get native token balance (ETH, BNB, MATIC, etc.)
|
|
1828
1828
|
const balance = await vault.getNativeBalance(address, '1'); // Ethereum
|
|
1829
1829
|
console.log('ETH Balance:', ethers.formatEther(balance));
|
|
1830
|
+
|
|
1831
|
+
// Get SOL balance on Solana
|
|
1832
|
+
const solBalance = await vault.getNativeBalance(address, 'solana');
|
|
1833
|
+
console.log('SOL Balance:', solBalance.toString(), 'lamports');
|
|
1834
|
+
|
|
1835
|
+
// Get TRX balance on TRON
|
|
1836
|
+
const trxBalance = await vault.getNativeBalance(address, 'tron');
|
|
1837
|
+
console.log('TRX Balance:', trxBalance.toString(), 'SUN');
|
|
1830
1838
|
```
|
|
1831
1839
|
|
|
1832
1840
|
#### Get Token Balance
|
|
@@ -1847,9 +1855,17 @@ console.log('Token:', tokenInfo.name, '(', tokenInfo.symbol, ')');
|
|
|
1847
1855
|
|
|
1848
1856
|
#### Send Native Token
|
|
1849
1857
|
```typescript
|
|
1850
|
-
// Send native tokens (ETH, BNB, etc.)
|
|
1851
|
-
const tx = await vault.sendNativeToken(from, to, amount, '1');
|
|
1858
|
+
// Send native tokens (ETH, BNB, etc.) on EVM chains
|
|
1859
|
+
const tx = await vault.sendNativeToken(from, to, amount, '1'); // Ethereum
|
|
1852
1860
|
console.log('Transaction hash:', tx.hash);
|
|
1861
|
+
|
|
1862
|
+
// Send SOL on Solana
|
|
1863
|
+
const solTx = await vault.sendNativeToken(from, to, amount, 'solana');
|
|
1864
|
+
console.log('Solana transaction hash:', solTx.hash);
|
|
1865
|
+
|
|
1866
|
+
// Send TRX on TRON
|
|
1867
|
+
const trxTx = await vault.sendNativeToken(from, to, amount, 'tron');
|
|
1868
|
+
console.log('TRON transaction hash:', trxTx.hash);
|
|
1853
1869
|
```
|
|
1854
1870
|
|
|
1855
1871
|
#### Send Token
|
|
@@ -2085,7 +2101,8 @@ console.log('Token transfers completed:', result.successfulCount);
|
|
|
2085
2101
|
```typescript
|
|
2086
2102
|
import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
|
|
2087
2103
|
|
|
2088
|
-
|
|
2104
|
+
// Example: EVM chains config
|
|
2105
|
+
const evmConfig: VaultConfig = {
|
|
2089
2106
|
rpcUrls: {
|
|
2090
2107
|
'1': 'https://your-eth-rpc.com',
|
|
2091
2108
|
'56': 'https://your-bsc-rpc.com',
|
|
@@ -2110,9 +2127,37 @@ const config: VaultConfig = {
|
|
|
2110
2127
|
enableBatchProcessing: true,
|
|
2111
2128
|
}
|
|
2112
2129
|
};
|
|
2130
|
+
|
|
2131
|
+
// Example: Solana config
|
|
2132
|
+
const solanaConfig: VaultConfig = {
|
|
2133
|
+
rpcUrls: {
|
|
2134
|
+
'solana': 'https://your-solana-rpc.com',
|
|
2135
|
+
'solana-devnet': 'https://your-devnet-rpc.com'
|
|
2136
|
+
},
|
|
2137
|
+
explorerUrls: {
|
|
2138
|
+
'solana': 'https://solscan.io',
|
|
2139
|
+
'solana-devnet': 'https://solscan.io?cluster=devnet'
|
|
2140
|
+
},
|
|
2141
|
+
defaultChainId: 'solana'
|
|
2142
|
+
};
|
|
2143
|
+
|
|
2144
|
+
// Example: TRON config
|
|
2145
|
+
const tronConfig: VaultConfig = {
|
|
2146
|
+
rpcUrls: {
|
|
2147
|
+
'tron': 'https://your-tron-rpc.com',
|
|
2148
|
+
'tron-shasta': 'https://your-shasta-rpc.com'
|
|
2149
|
+
},
|
|
2150
|
+
explorerUrls: {
|
|
2151
|
+
'tron': 'https://tronscan.org',
|
|
2152
|
+
'tron-shasta': 'https://shasta.tronscan.org'
|
|
2153
|
+
},
|
|
2154
|
+
defaultChainId: 'tron'
|
|
2155
|
+
};
|
|
2113
2156
|
```
|
|
2114
2157
|
|
|
2115
2158
|
#### Usage Example (Recommended for Mobile Apps)
|
|
2159
|
+
|
|
2160
|
+
**For EVM Chains:**
|
|
2116
2161
|
```typescript
|
|
2117
2162
|
import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
|
|
2118
2163
|
const appConfig: VaultConfig = {
|
|
@@ -2125,12 +2170,63 @@ const appConfig: VaultConfig = {
|
|
|
2125
2170
|
const { vault, encryptedVault } = await Vault.createNew(password, 'evm', appConfig);
|
|
2126
2171
|
|
|
2127
2172
|
// Pass config when loading existing vault
|
|
2128
|
-
const vault = await Vault.load(
|
|
2173
|
+
const vault = await Vault.load(password, encryptedVault, appConfig);
|
|
2129
2174
|
|
|
2130
2175
|
// All operations will use the config automatically
|
|
2131
2176
|
await vault.sendToken(from, to, amount, tokenAddress, '1');
|
|
2132
2177
|
```
|
|
2133
2178
|
|
|
2179
|
+
**For Solana:**
|
|
2180
|
+
```typescript
|
|
2181
|
+
import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
|
|
2182
|
+
|
|
2183
|
+
// Configure Solana RPC URLs
|
|
2184
|
+
const solanaConfig: VaultConfig = {
|
|
2185
|
+
rpcUrls: {
|
|
2186
|
+
'solana': 'https://your-solana-rpc.com', // Mainnet
|
|
2187
|
+
'solana-devnet': 'https://your-devnet-rpc.com' // Devnet (optional)
|
|
2188
|
+
},
|
|
2189
|
+
explorerUrls: {
|
|
2190
|
+
'solana': 'https://solscan.io',
|
|
2191
|
+
'solana-devnet': 'https://solscan.io?cluster=devnet'
|
|
2192
|
+
},
|
|
2193
|
+
defaultChainId: 'solana' // Optional: set default chain
|
|
2194
|
+
};
|
|
2195
|
+
|
|
2196
|
+
// Create Solana vault with config
|
|
2197
|
+
const { vault, encryptedVault } = await Vault.createNew('password', 'solana', solanaConfig);
|
|
2198
|
+
|
|
2199
|
+
// Or from mnemonic
|
|
2200
|
+
const { vault, encryptedVault } = await Vault.createFromMnemonic(
|
|
2201
|
+
mnemonic,
|
|
2202
|
+
'password',
|
|
2203
|
+
'solana',
|
|
2204
|
+
solanaConfig
|
|
2205
|
+
);
|
|
2206
|
+
|
|
2207
|
+
// All Solana operations will use the configured RPC URLs
|
|
2208
|
+
const balance = await vault.getNativeBalance(address, 'solana');
|
|
2209
|
+
const tx = await vault.sendSPLToken(from, to, amount, tokenAddress);
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
**For TRON:**
|
|
2213
|
+
```typescript
|
|
2214
|
+
import { Vault, type VaultConfig } from 'pwc-wallet-sdk';
|
|
2215
|
+
|
|
2216
|
+
const tronConfig: VaultConfig = {
|
|
2217
|
+
rpcUrls: {
|
|
2218
|
+
'tron': 'https://your-tron-rpc.com',
|
|
2219
|
+
'tron-shasta': 'https://your-shasta-rpc.com' // Testnet (optional)
|
|
2220
|
+
},
|
|
2221
|
+
explorerUrls: {
|
|
2222
|
+
'tron': 'https://tronscan.org',
|
|
2223
|
+
'tron-shasta': 'https://shasta.tronscan.org'
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
const { vault, encryptedVault } = await Vault.createNew('password', 'tron', tronConfig);
|
|
2228
|
+
```
|
|
2229
|
+
|
|
2134
2230
|
#### Alternative: Global Config (Advanced)
|
|
2135
2231
|
You can also set config globally for all vaults:
|
|
2136
2232
|
```typescript
|
package/dist/Vault.d.ts
CHANGED
|
@@ -136,6 +136,14 @@ export declare class Vault {
|
|
|
136
136
|
* @throws Error if the address is not found in any keyring
|
|
137
137
|
*/
|
|
138
138
|
getPrivateKeyFor(address: string): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the native token balance (ETH, SOL, TRX, etc.) for a specific address.
|
|
141
|
+
* @param address - The account address to check balance for
|
|
142
|
+
* @param chainId - The ID of the blockchain (e.g., '1' for Ethereum, 'solana' for Solana, 'tron' for TRON)
|
|
143
|
+
* @returns Promise resolving to the native token balance as a bigint
|
|
144
|
+
* @throws Error if the balance query fails or chain configuration not found
|
|
145
|
+
*/
|
|
146
|
+
getNativeBalance(address: string, chainId: ChainId): Promise<bigint>;
|
|
139
147
|
/**
|
|
140
148
|
* Gets the token balance for a specific account and token contract.
|
|
141
149
|
* @param accountAddress - The account address to check balance for
|
package/dist/Vault.js
CHANGED
|
@@ -134,12 +134,16 @@ class Vault {
|
|
|
134
134
|
else if (sKeyring.type === 'Solana') {
|
|
135
135
|
keyrings.push(await SolanaKeyring_1.SolanaKeyring.deserialize(sKeyring));
|
|
136
136
|
}
|
|
137
|
+
else if (sKeyring.type === 'Tron') {
|
|
138
|
+
keyrings.push(await TronKeyring_1.TronKeyring.deserialize(sKeyring));
|
|
139
|
+
}
|
|
137
140
|
else {
|
|
138
141
|
throw new Error(`Unknown keyring type: ${sKeyring.type}`);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
catch (error) {
|
|
142
|
-
|
|
145
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
146
|
+
throw new Error(`Failed to deserialize ${sKeyring.type} keyring: ${errorMessage}`);
|
|
143
147
|
}
|
|
144
148
|
}
|
|
145
149
|
const vault = new Vault(keyrings, config);
|
|
@@ -147,6 +151,9 @@ class Vault {
|
|
|
147
151
|
if (keyrings.some(k => k instanceof SolanaKeyring_1.SolanaKeyring)) {
|
|
148
152
|
vault.chainId = 'solana';
|
|
149
153
|
}
|
|
154
|
+
else if (keyrings.some(k => k instanceof TronKeyring_1.TronKeyring)) {
|
|
155
|
+
vault.chainId = 'tron';
|
|
156
|
+
}
|
|
150
157
|
else {
|
|
151
158
|
vault.chainId = '1'; // Default to Ethereum mainnet
|
|
152
159
|
}
|
|
@@ -178,7 +185,8 @@ class Vault {
|
|
|
178
185
|
async addNewSolanaAccount() {
|
|
179
186
|
const solanaKeyring = this.keyrings.find(k => k instanceof SolanaKeyring_1.SolanaKeyring);
|
|
180
187
|
if (!solanaKeyring) {
|
|
181
|
-
|
|
188
|
+
const availableTypes = this.keyrings.map(k => k.type).join(', ') || 'none';
|
|
189
|
+
throw new Error(`No Solana keyring available to create new accounts. Available keyring types: ${availableTypes}. Make sure you created the vault with chainType: 'solana'.`);
|
|
182
190
|
}
|
|
183
191
|
const newAddress = await solanaKeyring.addNewAccount();
|
|
184
192
|
return {
|
|
@@ -380,6 +388,29 @@ class Vault {
|
|
|
380
388
|
throw new Error('Private key not found for the given address.');
|
|
381
389
|
}
|
|
382
390
|
// --- Blockchain Interaction Methods ---
|
|
391
|
+
/**
|
|
392
|
+
* Gets the native token balance (ETH, SOL, TRX, etc.) for a specific address.
|
|
393
|
+
* @param address - The account address to check balance for
|
|
394
|
+
* @param chainId - The ID of the blockchain (e.g., '1' for Ethereum, 'solana' for Solana, 'tron' for TRON)
|
|
395
|
+
* @returns Promise resolving to the native token balance as a bigint
|
|
396
|
+
* @throws Error if the balance query fails or chain configuration not found
|
|
397
|
+
*/
|
|
398
|
+
async getNativeBalance(address, chainId) {
|
|
399
|
+
const chainInfo = (0, chains_1.getChainConfig)(chainId);
|
|
400
|
+
const privateKey = await this.getPrivateKeyFor(address);
|
|
401
|
+
if (chainInfo.type === 'solana') {
|
|
402
|
+
const chainService = new SolanaChainService_1.SolanaChainService(privateKey, chainInfo);
|
|
403
|
+
return chainService.getNativeBalance();
|
|
404
|
+
}
|
|
405
|
+
else if (chainInfo.type === 'tron') {
|
|
406
|
+
const chainService = new TronChainService_1.TronChainService(privateKey, chainInfo);
|
|
407
|
+
return chainService.getNativeBalance();
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
const chainService = new ChainService_1.ChainService(privateKey, chainInfo);
|
|
411
|
+
return chainService.getNativeBalance();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
383
414
|
/**
|
|
384
415
|
* Gets the token balance for a specific account and token contract.
|
|
385
416
|
* @param accountAddress - The account address to check balance for
|
package/package.json
CHANGED