@zubari/sdk 0.5.3 → 0.5.5
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/{PayoutsProtocol-B5z8SEA-.d.ts → PayoutsProtocol-DAa-9A5C.d.ts} +8 -1
- package/dist/{PayoutsProtocol-CLiMFe54.d.mts → PayoutsProtocol-DKEQhwYH.d.mts} +8 -1
- package/dist/{TransactionService-Lr_WS6iR.d.mts → TransactionService-Cmw33HXX.d.mts} +21 -7
- package/dist/{TransactionService-BtWUjKt_.d.ts → TransactionService-DbNDRzXh.d.ts} +21 -7
- package/dist/{WalletManager-DQQwVkoa.d.ts → WalletManager-CeLlZo2y.d.ts} +23 -2
- package/dist/{WalletManager-Sbpx4E1-.d.mts → WalletManager-DIx8nENh.d.mts} +23 -2
- package/dist/{contracts-B842YprC.d.mts → contracts-JfZDzaV7.d.ts} +11 -2
- package/dist/{contracts-s_CDIruh.d.ts → contracts-pugJnFzl.d.mts} +11 -2
- package/dist/{index-CTyZlHKg.d.mts → index-c90msmwW.d.mts} +2 -1
- package/dist/{index-CTyZlHKg.d.ts → index-c90msmwW.d.ts} +2 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +202 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +189 -182
- package/dist/index.mjs.map +1 -1
- package/dist/protocols/index.d.mts +2 -2
- package/dist/protocols/index.d.ts +2 -2
- package/dist/protocols/index.js +24 -11
- package/dist/protocols/index.js.map +1 -1
- package/dist/protocols/index.mjs +24 -11
- package/dist/protocols/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +167 -154
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +154 -141
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +2 -2
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +145 -125
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +132 -112
- package/dist/services/index.mjs.map +1 -1
- package/dist/storage/index.js +5 -2
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +5 -2
- package/dist/storage/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +3 -3
- package/dist/wallet/index.d.ts +3 -3
- package/dist/wallet/index.js +176 -184
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +163 -171
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { b as NetworkType } from '../index-
|
|
2
|
-
import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-
|
|
3
|
-
export { S as SUPPORTED_CHAINS } from '../WalletManager-
|
|
1
|
+
import { b as NetworkType } from '../index-c90msmwW.mjs';
|
|
2
|
+
import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-DIx8nENh.mjs';
|
|
3
|
+
export { S as SUPPORTED_CHAINS } from '../WalletManager-DIx8nENh.mjs';
|
|
4
4
|
import 'abitype';
|
|
5
5
|
import 'viem';
|
|
6
6
|
import 'ethers';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { b as NetworkType } from '../index-
|
|
2
|
-
import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-
|
|
3
|
-
export { S as SUPPORTED_CHAINS } from '../WalletManager-
|
|
1
|
+
import { b as NetworkType } from '../index-c90msmwW.js';
|
|
2
|
+
import { W as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, b as WalletManager } from '../WalletManager-CeLlZo2y.js';
|
|
3
|
+
export { S as SUPPORTED_CHAINS } from '../WalletManager-CeLlZo2y.js';
|
|
4
4
|
import 'abitype';
|
|
5
5
|
import 'viem';
|
|
6
6
|
import 'ethers';
|
package/dist/react/index.js
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var ethers = require('ethers');
|
|
5
|
-
var bip39 = require('@scure/bip39');
|
|
6
|
-
var english = require('@scure/bip39/wordlists/english');
|
|
7
|
-
var bip32 = require('@scure/bip32');
|
|
8
|
-
var base = require('@scure/base');
|
|
9
|
-
var sha256 = require('@noble/hashes/sha256');
|
|
10
|
-
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
11
5
|
var viem = require('viem');
|
|
12
6
|
var chains = require('viem/chains');
|
|
13
7
|
|
|
@@ -153,7 +147,13 @@ var USDT_ADDRESSES = {
|
|
|
153
147
|
}
|
|
154
148
|
};
|
|
155
149
|
var DERIVATION_PATHS = {
|
|
156
|
-
|
|
150
|
+
bitcoin: "m/84'/0'/0'/0",
|
|
151
|
+
ethereum: "m/44'/60'/0'/0",
|
|
152
|
+
ton: "m/44'/607'/0'",
|
|
153
|
+
tron: "m/44'/195'/0'/0",
|
|
154
|
+
solana: "m/44'/501'/0'",
|
|
155
|
+
spark: "m/44'/998'/0'/0"
|
|
156
|
+
};
|
|
157
157
|
function getNetworkConfig(network, isTestnet = false) {
|
|
158
158
|
const mainnetConfig = NETWORKS[network];
|
|
159
159
|
if (!isTestnet) return mainnetConfig;
|
|
@@ -171,9 +171,28 @@ var WdkApiClient = class {
|
|
|
171
171
|
constructor(config) {
|
|
172
172
|
this.config = {
|
|
173
173
|
baseUrl: config.baseUrl,
|
|
174
|
-
timeout: config.timeout || 3e4
|
|
174
|
+
timeout: config.timeout || 3e4,
|
|
175
|
+
authToken: config.authToken
|
|
175
176
|
};
|
|
176
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Set or update the auth token for authenticated requests
|
|
180
|
+
*/
|
|
181
|
+
setAuthToken(token) {
|
|
182
|
+
this.config.authToken = token;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Build headers for API requests, including Authorization when available
|
|
186
|
+
*/
|
|
187
|
+
getHeaders() {
|
|
188
|
+
const headers = {
|
|
189
|
+
"Content-Type": "application/json"
|
|
190
|
+
};
|
|
191
|
+
if (this.config.authToken) {
|
|
192
|
+
headers["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
193
|
+
}
|
|
194
|
+
return headers;
|
|
195
|
+
}
|
|
177
196
|
/**
|
|
178
197
|
* Generate a new BIP-39 seed phrase using Tether WDK
|
|
179
198
|
*/
|
|
@@ -181,9 +200,7 @@ var WdkApiClient = class {
|
|
|
181
200
|
try {
|
|
182
201
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/generate-seed`, {
|
|
183
202
|
method: "POST",
|
|
184
|
-
headers:
|
|
185
|
-
"Content-Type": "application/json"
|
|
186
|
-
}
|
|
203
|
+
headers: this.getHeaders()
|
|
187
204
|
});
|
|
188
205
|
return await response.json();
|
|
189
206
|
} catch (error) {
|
|
@@ -200,9 +217,7 @@ var WdkApiClient = class {
|
|
|
200
217
|
try {
|
|
201
218
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/validate-seed`, {
|
|
202
219
|
method: "POST",
|
|
203
|
-
headers:
|
|
204
|
-
"Content-Type": "application/json"
|
|
205
|
-
},
|
|
220
|
+
headers: this.getHeaders(),
|
|
206
221
|
body: JSON.stringify({ seed })
|
|
207
222
|
});
|
|
208
223
|
return await response.json();
|
|
@@ -220,9 +235,7 @@ var WdkApiClient = class {
|
|
|
220
235
|
try {
|
|
221
236
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
222
237
|
method: "POST",
|
|
223
|
-
headers:
|
|
224
|
-
"Content-Type": "application/json"
|
|
225
|
-
},
|
|
238
|
+
headers: this.getHeaders(),
|
|
226
239
|
body: JSON.stringify({ seed, chain, network })
|
|
227
240
|
});
|
|
228
241
|
return await response.json();
|
|
@@ -240,9 +253,7 @@ var WdkApiClient = class {
|
|
|
240
253
|
try {
|
|
241
254
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
242
255
|
method: "POST",
|
|
243
|
-
headers:
|
|
244
|
-
"Content-Type": "application/json"
|
|
245
|
-
},
|
|
256
|
+
headers: this.getHeaders(),
|
|
246
257
|
body: JSON.stringify({ seed, network })
|
|
247
258
|
});
|
|
248
259
|
return await response.json();
|
|
@@ -260,9 +271,7 @@ var WdkApiClient = class {
|
|
|
260
271
|
try {
|
|
261
272
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
262
273
|
method: "POST",
|
|
263
|
-
headers:
|
|
264
|
-
"Content-Type": "application/json"
|
|
265
|
-
},
|
|
274
|
+
headers: this.getHeaders(),
|
|
266
275
|
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
267
276
|
});
|
|
268
277
|
return await response.json();
|
|
@@ -281,9 +290,7 @@ var WdkApiClient = class {
|
|
|
281
290
|
try {
|
|
282
291
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
283
292
|
method: "POST",
|
|
284
|
-
headers:
|
|
285
|
-
"Content-Type": "application/json"
|
|
286
|
-
},
|
|
293
|
+
headers: this.getHeaders(),
|
|
287
294
|
body: JSON.stringify({ seed, chain, network, limit })
|
|
288
295
|
});
|
|
289
296
|
return await response.json();
|
|
@@ -302,9 +309,7 @@ var WdkApiClient = class {
|
|
|
302
309
|
try {
|
|
303
310
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
304
311
|
method: "POST",
|
|
305
|
-
headers:
|
|
306
|
-
"Content-Type": "application/json"
|
|
307
|
-
},
|
|
312
|
+
headers: this.getHeaders(),
|
|
308
313
|
body: JSON.stringify({ txHash, chain, network })
|
|
309
314
|
});
|
|
310
315
|
return await response.json();
|
|
@@ -318,42 +323,68 @@ var WdkApiClient = class {
|
|
|
318
323
|
};
|
|
319
324
|
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
320
325
|
var wdkApiClient = null;
|
|
321
|
-
function getWdkApiClient(baseUrl) {
|
|
326
|
+
function getWdkApiClient(baseUrl, authToken) {
|
|
322
327
|
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
323
328
|
wdkApiClient = new WdkApiClient({
|
|
324
|
-
baseUrl: baseUrl || DEFAULT_API_URL
|
|
329
|
+
baseUrl: baseUrl || DEFAULT_API_URL,
|
|
330
|
+
authToken
|
|
325
331
|
});
|
|
326
332
|
}
|
|
327
333
|
return wdkApiClient;
|
|
328
334
|
}
|
|
329
335
|
var DERIVATION_PATHS2 = {
|
|
330
|
-
ethereum:
|
|
331
|
-
bitcoin_mainnet:
|
|
336
|
+
ethereum: `${DERIVATION_PATHS.ethereum}/0`,
|
|
337
|
+
bitcoin_mainnet: `${DERIVATION_PATHS.bitcoin}/0`,
|
|
332
338
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
333
|
-
ton:
|
|
334
|
-
tron:
|
|
335
|
-
solana:
|
|
336
|
-
spark:
|
|
339
|
+
ton: `${DERIVATION_PATHS.ton}/0'/0'`,
|
|
340
|
+
tron: `${DERIVATION_PATHS.tron}/0`,
|
|
341
|
+
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
342
|
+
spark: `${DERIVATION_PATHS.spark}/0`
|
|
337
343
|
};
|
|
344
|
+
var _crypto = null;
|
|
345
|
+
async function loadCrypto() {
|
|
346
|
+
if (_crypto) return _crypto;
|
|
347
|
+
const [bip39, bip39Words, bip32, scureBase, sha256Mod, ripemd160Mod] = await Promise.all([
|
|
348
|
+
import('@scure/bip39'),
|
|
349
|
+
import('@scure/bip39/wordlists/english.js'),
|
|
350
|
+
import('@scure/bip32'),
|
|
351
|
+
import('@scure/base'),
|
|
352
|
+
import('@noble/hashes/sha256'),
|
|
353
|
+
import('@noble/hashes/ripemd160')
|
|
354
|
+
]);
|
|
355
|
+
_crypto = {
|
|
356
|
+
mnemonicToSeedSync: bip39.mnemonicToSeedSync,
|
|
357
|
+
validateMnemonic: bip39.validateMnemonic,
|
|
358
|
+
generateMnemonic: bip39.generateMnemonic,
|
|
359
|
+
wordlist: bip39Words.wordlist,
|
|
360
|
+
HDKey: bip32.HDKey,
|
|
361
|
+
bech32: scureBase.bech32,
|
|
362
|
+
base58check: scureBase.base58check,
|
|
363
|
+
sha256: sha256Mod.sha256,
|
|
364
|
+
ripemd160: ripemd160Mod.ripemd160
|
|
365
|
+
};
|
|
366
|
+
return _crypto;
|
|
367
|
+
}
|
|
338
368
|
function deriveEthereumAddress(seed) {
|
|
339
369
|
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
340
370
|
return hdNode.address;
|
|
341
371
|
}
|
|
342
|
-
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
372
|
+
async function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
343
373
|
try {
|
|
344
|
-
const
|
|
345
|
-
const
|
|
374
|
+
const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
|
|
375
|
+
const seedBytes = mnemonicToSeedSync(seed);
|
|
376
|
+
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
346
377
|
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
347
378
|
const child = hdKey.derive(path);
|
|
348
379
|
if (!child.publicKey) {
|
|
349
380
|
throw new Error("Failed to derive public key");
|
|
350
381
|
}
|
|
351
|
-
const pubKeyHash = ripemd160
|
|
382
|
+
const pubKeyHash = ripemd160(sha256(child.publicKey));
|
|
352
383
|
const witnessVersion = 0;
|
|
353
|
-
const words =
|
|
384
|
+
const words = bech32.toWords(pubKeyHash);
|
|
354
385
|
words.unshift(witnessVersion);
|
|
355
386
|
const hrp = network === "testnet" ? "tb" : "bc";
|
|
356
|
-
const address =
|
|
387
|
+
const address = bech32.encode(hrp, words);
|
|
357
388
|
return address;
|
|
358
389
|
} catch (error) {
|
|
359
390
|
console.error("Bitcoin address derivation failed:", error);
|
|
@@ -362,13 +393,14 @@ function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
|
362
393
|
}
|
|
363
394
|
async function deriveSolanaAddress(seed) {
|
|
364
395
|
try {
|
|
365
|
-
const [ed25519, nacl, bs58Module] = await Promise.all([
|
|
396
|
+
const [crypto2, ed25519, nacl, bs58Module] = await Promise.all([
|
|
397
|
+
loadCrypto(),
|
|
366
398
|
import('ed25519-hd-key'),
|
|
367
399
|
import('tweetnacl'),
|
|
368
400
|
import('bs58')
|
|
369
401
|
]);
|
|
370
402
|
const bs58 = bs58Module.default || bs58Module;
|
|
371
|
-
const seedBytes =
|
|
403
|
+
const seedBytes = crypto2.mnemonicToSeedSync(seed);
|
|
372
404
|
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
373
405
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
374
406
|
return bs58.encode(keypair.publicKey);
|
|
@@ -379,17 +411,18 @@ async function deriveSolanaAddress(seed) {
|
|
|
379
411
|
}
|
|
380
412
|
async function deriveTonAddress(seed) {
|
|
381
413
|
try {
|
|
382
|
-
const [ed25519, nacl] = await Promise.all([
|
|
414
|
+
const [crypto2, ed25519, nacl] = await Promise.all([
|
|
415
|
+
loadCrypto(),
|
|
383
416
|
import('ed25519-hd-key'),
|
|
384
417
|
import('tweetnacl')
|
|
385
418
|
]);
|
|
386
|
-
const seedBytes =
|
|
419
|
+
const seedBytes = crypto2.mnemonicToSeedSync(seed);
|
|
387
420
|
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
388
421
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
389
422
|
const publicKey = keypair.publicKey;
|
|
390
423
|
const workchain = 0;
|
|
391
424
|
const flags = 17;
|
|
392
|
-
const hash =
|
|
425
|
+
const hash = crypto2.sha256(publicKey);
|
|
393
426
|
const addressData = new Uint8Array(34);
|
|
394
427
|
addressData[0] = flags;
|
|
395
428
|
addressData[1] = workchain;
|
|
@@ -417,8 +450,9 @@ function crc16(data) {
|
|
|
417
450
|
}
|
|
418
451
|
return crc;
|
|
419
452
|
}
|
|
420
|
-
function deriveTronAddress(seed) {
|
|
453
|
+
async function deriveTronAddress(seed) {
|
|
421
454
|
try {
|
|
455
|
+
const { sha256, base58check } = await loadCrypto();
|
|
422
456
|
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
423
457
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
424
458
|
const addressBytes = new Uint8Array(21);
|
|
@@ -426,27 +460,28 @@ function deriveTronAddress(seed) {
|
|
|
426
460
|
for (let i = 0; i < 20; i++) {
|
|
427
461
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
428
462
|
}
|
|
429
|
-
const tronBase58check =
|
|
463
|
+
const tronBase58check = base58check(sha256);
|
|
430
464
|
return tronBase58check.encode(addressBytes);
|
|
431
465
|
} catch (error) {
|
|
432
466
|
console.error("TRON address derivation failed:", error);
|
|
433
467
|
throw error;
|
|
434
468
|
}
|
|
435
469
|
}
|
|
436
|
-
function deriveSparkAddress(seed, network = "mainnet") {
|
|
470
|
+
async function deriveSparkAddress(seed, network = "mainnet") {
|
|
437
471
|
try {
|
|
438
|
-
const
|
|
439
|
-
const
|
|
472
|
+
const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
|
|
473
|
+
const seedBytes = mnemonicToSeedSync(seed);
|
|
474
|
+
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
440
475
|
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
441
476
|
if (!child.publicKey) {
|
|
442
477
|
throw new Error("Failed to derive public key");
|
|
443
478
|
}
|
|
444
|
-
const pubKeyHash = ripemd160
|
|
479
|
+
const pubKeyHash = ripemd160(sha256(child.publicKey));
|
|
445
480
|
const witnessVersion = 0;
|
|
446
|
-
const words =
|
|
481
|
+
const words = bech32.toWords(pubKeyHash);
|
|
447
482
|
words.unshift(witnessVersion);
|
|
448
483
|
const hrp = network === "testnet" ? "tsp" : "sp";
|
|
449
|
-
const address =
|
|
484
|
+
const address = bech32.encode(hrp, words);
|
|
450
485
|
return address;
|
|
451
486
|
} catch (error) {
|
|
452
487
|
console.error("Spark address derivation failed:", error);
|
|
@@ -462,47 +497,38 @@ async function deriveAllAddresses(seed, network = "mainnet") {
|
|
|
462
497
|
solana: null,
|
|
463
498
|
spark: null
|
|
464
499
|
};
|
|
500
|
+
await loadCrypto();
|
|
465
501
|
try {
|
|
466
502
|
addresses.ethereum = deriveEthereumAddress(seed);
|
|
467
503
|
} catch (e) {
|
|
468
504
|
console.error("ETH derivation failed:", e);
|
|
469
505
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
try {
|
|
476
|
-
addresses.spark = deriveSparkAddress(seed, network);
|
|
477
|
-
} catch (e) {
|
|
478
|
-
console.error("Spark derivation failed:", e);
|
|
479
|
-
}
|
|
480
|
-
try {
|
|
481
|
-
addresses.tron = deriveTronAddress(seed);
|
|
482
|
-
} catch (e) {
|
|
483
|
-
console.error("TRON derivation failed:", e);
|
|
484
|
-
}
|
|
485
|
-
const [solResult, tonResult] = await Promise.allSettled([
|
|
506
|
+
const [btcResult, sparkResult, tronResult, solResult, tonResult] = await Promise.allSettled([
|
|
507
|
+
deriveBitcoinAddress(seed, network),
|
|
508
|
+
deriveSparkAddress(seed, network),
|
|
509
|
+
deriveTronAddress(seed),
|
|
486
510
|
deriveSolanaAddress(seed),
|
|
487
511
|
deriveTonAddress(seed)
|
|
488
512
|
]);
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
513
|
+
if (btcResult.status === "fulfilled") addresses.bitcoin = btcResult.value;
|
|
514
|
+
else console.error("BTC derivation failed:", btcResult.reason);
|
|
515
|
+
if (sparkResult.status === "fulfilled") addresses.spark = sparkResult.value;
|
|
516
|
+
else console.error("Spark derivation failed:", sparkResult.reason);
|
|
517
|
+
if (tronResult.status === "fulfilled") addresses.tron = tronResult.value;
|
|
518
|
+
else console.error("TRON derivation failed:", tronResult.reason);
|
|
519
|
+
if (solResult.status === "fulfilled") addresses.solana = solResult.value;
|
|
520
|
+
else console.error("SOL derivation failed:", solResult.reason);
|
|
521
|
+
if (tonResult.status === "fulfilled") addresses.ton = tonResult.value;
|
|
522
|
+
else console.error("TON derivation failed:", tonResult.reason);
|
|
499
523
|
return addresses;
|
|
500
524
|
}
|
|
501
|
-
function isValidSeed(seed) {
|
|
502
|
-
|
|
525
|
+
async function isValidSeed(seed) {
|
|
526
|
+
const { validateMnemonic, wordlist } = await loadCrypto();
|
|
527
|
+
return validateMnemonic(seed, wordlist);
|
|
503
528
|
}
|
|
504
|
-
function generateSeedPhrase() {
|
|
505
|
-
|
|
529
|
+
async function generateSeedPhrase() {
|
|
530
|
+
const { generateMnemonic, wordlist } = await loadCrypto();
|
|
531
|
+
return generateMnemonic(wordlist);
|
|
506
532
|
}
|
|
507
533
|
|
|
508
534
|
// src/services/ZubariWdkService.ts
|
|
@@ -745,7 +771,7 @@ var ZubariWdkService = class {
|
|
|
745
771
|
};
|
|
746
772
|
if (!addresses.spark) {
|
|
747
773
|
try {
|
|
748
|
-
addresses.spark = deriveSparkAddress(seed, this.config.network);
|
|
774
|
+
addresses.spark = await deriveSparkAddress(seed, this.config.network);
|
|
749
775
|
} catch (e) {
|
|
750
776
|
console.warn("Browser Spark derivation fallback failed:", e);
|
|
751
777
|
}
|
|
@@ -846,11 +872,6 @@ var ZubariWdkService = class {
|
|
|
846
872
|
async sendTransaction(seed, chain, to, amount) {
|
|
847
873
|
await this.initialize();
|
|
848
874
|
const startTime = Date.now();
|
|
849
|
-
console.log(`[ZubariWdkService] Sending ${chain} transaction`, {
|
|
850
|
-
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
851
|
-
amount,
|
|
852
|
-
network: this.config.network
|
|
853
|
-
});
|
|
854
875
|
try {
|
|
855
876
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
856
877
|
method: "POST",
|
|
@@ -870,10 +891,6 @@ var ZubariWdkService = class {
|
|
|
870
891
|
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
871
892
|
}
|
|
872
893
|
}
|
|
873
|
-
console.log(`[ZubariWdkService] ${chain} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
874
|
-
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
875
|
-
elapsed: `${elapsed}ms`
|
|
876
|
-
});
|
|
877
894
|
if (!data.success) {
|
|
878
895
|
const errorCode2 = parseChainError(chain, data.error || "");
|
|
879
896
|
return {
|
|
@@ -896,12 +913,6 @@ var ZubariWdkService = class {
|
|
|
896
913
|
const errorData = await response.json().catch(() => ({}));
|
|
897
914
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
898
915
|
const errorCode = parseChainError(chain, errorMessage);
|
|
899
|
-
console.error(`[ZubariWdkService] ${chain} transaction FAILED`, {
|
|
900
|
-
status: response.status,
|
|
901
|
-
error: errorMessage,
|
|
902
|
-
errorCode,
|
|
903
|
-
elapsed: `${elapsed}ms`
|
|
904
|
-
});
|
|
905
916
|
return {
|
|
906
917
|
success: false,
|
|
907
918
|
error: errorMessage,
|
|
@@ -909,14 +920,8 @@ var ZubariWdkService = class {
|
|
|
909
920
|
chain
|
|
910
921
|
};
|
|
911
922
|
} catch (error) {
|
|
912
|
-
const elapsed = Date.now() - startTime;
|
|
913
923
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
914
924
|
const errorCode = parseChainError(chain, errorMessage);
|
|
915
|
-
console.error(`[ZubariWdkService] ${chain} transaction ERROR`, {
|
|
916
|
-
error: errorMessage,
|
|
917
|
-
errorCode,
|
|
918
|
-
elapsed: `${elapsed}ms`
|
|
919
|
-
});
|
|
920
925
|
return {
|
|
921
926
|
success: false,
|
|
922
927
|
error: errorMessage,
|
|
@@ -962,15 +967,22 @@ var ZubariWdkService = class {
|
|
|
962
967
|
// Private Helper Methods
|
|
963
968
|
// ==========================================
|
|
964
969
|
getDerivationPath(chain) {
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
970
|
+
const basePath = DERIVATION_PATHS[chain];
|
|
971
|
+
if (chain === "bitcoin" && this.config.network === "testnet") {
|
|
972
|
+
return "m/84'/1'/0'/0/0";
|
|
973
|
+
}
|
|
974
|
+
switch (chain) {
|
|
975
|
+
case "ton":
|
|
976
|
+
return `${basePath}/0'/0'`;
|
|
977
|
+
case "solana":
|
|
978
|
+
return `${basePath}/0'`;
|
|
979
|
+
case "bitcoin":
|
|
980
|
+
case "ethereum":
|
|
981
|
+
case "tron":
|
|
982
|
+
case "spark":
|
|
983
|
+
default:
|
|
984
|
+
return `${basePath}/0`;
|
|
985
|
+
}
|
|
974
986
|
}
|
|
975
987
|
getChainSymbol(chain) {
|
|
976
988
|
const symbols = {
|
|
@@ -995,13 +1007,13 @@ var ZubariWdkService = class {
|
|
|
995
1007
|
address = deriveEthereumAddress(seed);
|
|
996
1008
|
break;
|
|
997
1009
|
case "bitcoin":
|
|
998
|
-
address = deriveBitcoinAddress(seed, this.config.network);
|
|
1010
|
+
address = await deriveBitcoinAddress(seed, this.config.network);
|
|
999
1011
|
break;
|
|
1000
1012
|
case "tron":
|
|
1001
|
-
address = deriveTronAddress(seed);
|
|
1013
|
+
address = await deriveTronAddress(seed);
|
|
1002
1014
|
break;
|
|
1003
1015
|
case "spark":
|
|
1004
|
-
address = deriveSparkAddress(seed, this.config.network);
|
|
1016
|
+
address = await deriveSparkAddress(seed, this.config.network);
|
|
1005
1017
|
break;
|
|
1006
1018
|
case "solana":
|
|
1007
1019
|
address = await deriveSolanaAddress(seed);
|
|
@@ -1039,7 +1051,10 @@ var KeyManager = class {
|
|
|
1039
1051
|
static KEY_LENGTH = 256;
|
|
1040
1052
|
static IV_LENGTH = 12;
|
|
1041
1053
|
static SALT_LENGTH = 16;
|
|
1042
|
-
|
|
1054
|
+
// OWASP 2023 recommends 600,000 iterations for PBKDF2-SHA256 to resist
|
|
1055
|
+
// brute-force attacks with modern GPU hardware.
|
|
1056
|
+
// See: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
|
|
1057
|
+
static PBKDF2_ITERATIONS = 6e5;
|
|
1043
1058
|
/**
|
|
1044
1059
|
* Encrypt a seed phrase with a password
|
|
1045
1060
|
*/
|
|
@@ -1278,7 +1293,7 @@ var WebEncryptedStorageAdapter = class {
|
|
|
1278
1293
|
{
|
|
1279
1294
|
name: "PBKDF2",
|
|
1280
1295
|
salt: salt.buffer,
|
|
1281
|
-
iterations:
|
|
1296
|
+
iterations: 6e5,
|
|
1282
1297
|
hash: "SHA-256"
|
|
1283
1298
|
},
|
|
1284
1299
|
keyMaterial,
|
|
@@ -1591,6 +1606,16 @@ var WalletManager = class _WalletManager {
|
|
|
1591
1606
|
}
|
|
1592
1607
|
/**
|
|
1593
1608
|
* Lock wallet (clear seed from memory)
|
|
1609
|
+
*
|
|
1610
|
+
* SECURITY NOTE: JavaScript strings are immutable and cannot be overwritten
|
|
1611
|
+
* in place. Setting `this.currentSeed = null` removes the reference, but
|
|
1612
|
+
* the original string may persist in memory until garbage collected.
|
|
1613
|
+
* There is no reliable way to zero out a JS string.
|
|
1614
|
+
*
|
|
1615
|
+
* TODO: In a future version, store the seed as a Uint8Array instead of a
|
|
1616
|
+
* string. Uint8Array contents can be explicitly zeroed (e.g.,
|
|
1617
|
+
* `seedBytes.fill(0)`) before releasing the reference, which provides
|
|
1618
|
+
* stronger guarantees that sensitive material is scrubbed from memory.
|
|
1594
1619
|
*/
|
|
1595
1620
|
lock() {
|
|
1596
1621
|
this.currentSeed = null;
|
|
@@ -1807,7 +1832,6 @@ var WalletManager = class _WalletManager {
|
|
|
1807
1832
|
async saveAddressesToStorage(addresses) {
|
|
1808
1833
|
try {
|
|
1809
1834
|
await this.storage.setItem(STORAGE_KEYS.DERIVED_ADDRESSES, JSON.stringify(addresses));
|
|
1810
|
-
console.log("Saved derived addresses to storage:", Object.keys(addresses));
|
|
1811
1835
|
} catch (error) {
|
|
1812
1836
|
console.warn("Failed to save addresses to storage:", error);
|
|
1813
1837
|
}
|
|
@@ -1847,9 +1871,7 @@ var WalletManager = class _WalletManager {
|
|
|
1847
1871
|
const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
|
|
1848
1872
|
if (stored) {
|
|
1849
1873
|
const rawAddresses = JSON.parse(stored);
|
|
1850
|
-
console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
|
|
1851
1874
|
const addresses = this.normalizeAddresses(rawAddresses);
|
|
1852
|
-
console.log("[WalletManager] Normalized addresses:", addresses);
|
|
1853
1875
|
await this.saveAddressesToStorage(addresses);
|
|
1854
1876
|
return addresses;
|
|
1855
1877
|
}
|
|
@@ -1874,11 +1896,8 @@ var WalletManager = class _WalletManager {
|
|
|
1874
1896
|
if (storedAddresses && Object.keys(storedAddresses).length > 1) {
|
|
1875
1897
|
const expectedEthAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
1876
1898
|
if (storedAddresses.ethereum === expectedEthAddress) {
|
|
1877
|
-
console.log("Using addresses from storage (verified by Ethereum address)");
|
|
1878
1899
|
this.derivedAddresses = storedAddresses;
|
|
1879
1900
|
return storedAddresses;
|
|
1880
|
-
} else {
|
|
1881
|
-
console.log("Stored addresses do not match current seed, re-deriving...");
|
|
1882
1901
|
}
|
|
1883
1902
|
}
|
|
1884
1903
|
return await this.deriveAllAddressesWithWdk();
|
|
@@ -1890,9 +1909,7 @@ var WalletManager = class _WalletManager {
|
|
|
1890
1909
|
getAddressForChain(chain) {
|
|
1891
1910
|
const cachedValue = this.derivedAddresses[chain];
|
|
1892
1911
|
if (cachedValue) {
|
|
1893
|
-
console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
|
|
1894
1912
|
const addr = this.normalizeAddress(cachedValue);
|
|
1895
|
-
console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
|
|
1896
1913
|
if (addr) {
|
|
1897
1914
|
this.derivedAddresses[chain] = addr;
|
|
1898
1915
|
return addr;
|
|
@@ -2019,10 +2036,8 @@ var WalletManager = class _WalletManager {
|
|
|
2019
2036
|
const mempoolSpent = data.mempool_stats?.spent_txo_sum || 0;
|
|
2020
2037
|
const satoshis = chainFunded - chainSpent + (mempoolFunded - mempoolSpent);
|
|
2021
2038
|
balance = (satoshis / 1e8).toFixed(8);
|
|
2022
|
-
console.log(`Bitcoin balance for ${address}: ${balance} BTC (${satoshis} sats) via ${apiUrl}`);
|
|
2023
2039
|
break;
|
|
2024
2040
|
}
|
|
2025
|
-
console.log(`No transactions found on ${apiUrl}, trying next...`);
|
|
2026
2041
|
}
|
|
2027
2042
|
} catch (error) {
|
|
2028
2043
|
console.warn(`Failed to fetch from ${apiUrl}:`, error);
|
|
@@ -2125,7 +2140,6 @@ var WalletManager = class _WalletManager {
|
|
|
2125
2140
|
if (data.ok && data.result !== void 0) {
|
|
2126
2141
|
const nanotons = BigInt(data.result);
|
|
2127
2142
|
balance = (Number(nanotons) / 1e9).toFixed(9);
|
|
2128
|
-
console.log(`TON balance for ${address}: ${balance} TON`);
|
|
2129
2143
|
}
|
|
2130
2144
|
}
|
|
2131
2145
|
} catch (error) {
|
|
@@ -2182,7 +2196,6 @@ var WalletManager = class _WalletManager {
|
|
|
2182
2196
|
const data = await response.json();
|
|
2183
2197
|
if (data.success && data.balance !== void 0) {
|
|
2184
2198
|
balance = (parseFloat(data.balance) / 1e8).toFixed(8);
|
|
2185
|
-
console.log(`Spark balance for ${address}: ${balance} BTC`);
|
|
2186
2199
|
}
|
|
2187
2200
|
}
|
|
2188
2201
|
} catch (error) {
|
|
@@ -2203,28 +2216,29 @@ var WalletManager = class _WalletManager {
|
|
|
2203
2216
|
};
|
|
2204
2217
|
}
|
|
2205
2218
|
/**
|
|
2206
|
-
* Fetch balances for all enabled chains
|
|
2219
|
+
* Fetch balances for all enabled chains in parallel.
|
|
2220
|
+
* Uses Promise.allSettled so that one chain failing does not block others.
|
|
2207
2221
|
*/
|
|
2208
2222
|
async fetchAllBalances() {
|
|
2209
|
-
const
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
const networkConfig = this.getChainConfig(chain);
|
|
2217
|
-
balances.push({
|
|
2218
|
-
chain,
|
|
2219
|
-
symbol: networkConfig.nativeCurrency.symbol,
|
|
2220
|
-
balance: "0",
|
|
2221
|
-
balanceUsd: 0,
|
|
2222
|
-
address: this.getAddressForChain(chain) || "",
|
|
2223
|
-
decimals: networkConfig.nativeCurrency.decimals
|
|
2224
|
-
});
|
|
2223
|
+
const results = await Promise.allSettled(
|
|
2224
|
+
this.config.enabledChains.map((chain) => this.fetchBalanceForChain(chain))
|
|
2225
|
+
);
|
|
2226
|
+
return results.map((result, index) => {
|
|
2227
|
+
const chain = this.config.enabledChains[index];
|
|
2228
|
+
if (result.status === "fulfilled") {
|
|
2229
|
+
return result.value;
|
|
2225
2230
|
}
|
|
2226
|
-
|
|
2227
|
-
|
|
2231
|
+
console.error(`Failed to fetch balance for ${chain}:`, result.reason);
|
|
2232
|
+
const networkConfig = this.getChainConfig(chain);
|
|
2233
|
+
return {
|
|
2234
|
+
chain,
|
|
2235
|
+
symbol: networkConfig.nativeCurrency.symbol,
|
|
2236
|
+
balance: "0",
|
|
2237
|
+
balanceUsd: 0,
|
|
2238
|
+
address: this.getAddressForChain(chain) || "",
|
|
2239
|
+
decimals: networkConfig.nativeCurrency.decimals
|
|
2240
|
+
};
|
|
2241
|
+
});
|
|
2228
2242
|
}
|
|
2229
2243
|
/**
|
|
2230
2244
|
* Get extended wallet state with multi-chain info
|
|
@@ -2278,7 +2292,6 @@ var WalletManager = class _WalletManager {
|
|
|
2278
2292
|
});
|
|
2279
2293
|
if (response.ok) {
|
|
2280
2294
|
const data = await response.json();
|
|
2281
|
-
console.log(`Transaction sent on ${chain}:`, data);
|
|
2282
2295
|
let txHash = data.txHash || data.transactionHash || data.hash;
|
|
2283
2296
|
if (txHash && typeof txHash === "object" && "hash" in txHash) {
|
|
2284
2297
|
txHash = txHash.hash;
|