@zubari/sdk 0.5.2 → 0.5.4
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-BtWUjKt_.d.ts → TransactionService-BEkgF1T6.d.ts} +12 -2
- package/dist/{TransactionService-Lr_WS6iR.d.mts → TransactionService-CF_C3Kqm.d.mts} +12 -2
- 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 +339 -916
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +337 -914
- 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 +255 -826
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +253 -824
- 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 +179 -767
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +177 -765
- 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 +262 -854
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +260 -852
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/services/index.js
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
var ethers = require('ethers');
|
|
4
4
|
var bip39 = require('@scure/bip39');
|
|
5
5
|
var english = require('@scure/bip39/wordlists/english');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var legacy_js = require('@noble/hashes/legacy.js');
|
|
9
|
-
var sha2_js = require('@noble/hashes/sha2.js');
|
|
10
|
-
var utils_js = require('@noble/hashes/utils.js');
|
|
6
|
+
var bip32 = require('@scure/bip32');
|
|
7
|
+
var base = require('@scure/base');
|
|
11
8
|
var sha256 = require('@noble/hashes/sha256');
|
|
12
9
|
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
13
10
|
|
|
@@ -223,9 +220,28 @@ var WdkApiClient = class {
|
|
|
223
220
|
constructor(config) {
|
|
224
221
|
this.config = {
|
|
225
222
|
baseUrl: config.baseUrl,
|
|
226
|
-
timeout: config.timeout || 3e4
|
|
223
|
+
timeout: config.timeout || 3e4,
|
|
224
|
+
authToken: config.authToken
|
|
227
225
|
};
|
|
228
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Set or update the auth token for authenticated requests
|
|
229
|
+
*/
|
|
230
|
+
setAuthToken(token) {
|
|
231
|
+
this.config.authToken = token;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Build headers for API requests, including Authorization when available
|
|
235
|
+
*/
|
|
236
|
+
getHeaders() {
|
|
237
|
+
const headers = {
|
|
238
|
+
"Content-Type": "application/json"
|
|
239
|
+
};
|
|
240
|
+
if (this.config.authToken) {
|
|
241
|
+
headers["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
242
|
+
}
|
|
243
|
+
return headers;
|
|
244
|
+
}
|
|
229
245
|
/**
|
|
230
246
|
* Generate a new BIP-39 seed phrase using Tether WDK
|
|
231
247
|
*/
|
|
@@ -233,9 +249,7 @@ var WdkApiClient = class {
|
|
|
233
249
|
try {
|
|
234
250
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/generate-seed`, {
|
|
235
251
|
method: "POST",
|
|
236
|
-
headers:
|
|
237
|
-
"Content-Type": "application/json"
|
|
238
|
-
}
|
|
252
|
+
headers: this.getHeaders()
|
|
239
253
|
});
|
|
240
254
|
return await response.json();
|
|
241
255
|
} catch (error) {
|
|
@@ -252,9 +266,7 @@ var WdkApiClient = class {
|
|
|
252
266
|
try {
|
|
253
267
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/validate-seed`, {
|
|
254
268
|
method: "POST",
|
|
255
|
-
headers:
|
|
256
|
-
"Content-Type": "application/json"
|
|
257
|
-
},
|
|
269
|
+
headers: this.getHeaders(),
|
|
258
270
|
body: JSON.stringify({ seed })
|
|
259
271
|
});
|
|
260
272
|
return await response.json();
|
|
@@ -268,14 +280,12 @@ var WdkApiClient = class {
|
|
|
268
280
|
/**
|
|
269
281
|
* Derive address for a specific chain using Tether WDK
|
|
270
282
|
*/
|
|
271
|
-
async deriveAddress(seed,
|
|
283
|
+
async deriveAddress(seed, chain, network = "mainnet") {
|
|
272
284
|
try {
|
|
273
285
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
274
286
|
method: "POST",
|
|
275
|
-
headers:
|
|
276
|
-
|
|
277
|
-
},
|
|
278
|
-
body: JSON.stringify({ seed, chain: chain2, network })
|
|
287
|
+
headers: this.getHeaders(),
|
|
288
|
+
body: JSON.stringify({ seed, chain, network })
|
|
279
289
|
});
|
|
280
290
|
return await response.json();
|
|
281
291
|
} catch (error) {
|
|
@@ -292,9 +302,7 @@ var WdkApiClient = class {
|
|
|
292
302
|
try {
|
|
293
303
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
294
304
|
method: "POST",
|
|
295
|
-
headers:
|
|
296
|
-
"Content-Type": "application/json"
|
|
297
|
-
},
|
|
305
|
+
headers: this.getHeaders(),
|
|
298
306
|
body: JSON.stringify({ seed, network })
|
|
299
307
|
});
|
|
300
308
|
return await response.json();
|
|
@@ -308,14 +316,12 @@ var WdkApiClient = class {
|
|
|
308
316
|
/**
|
|
309
317
|
* Send a transaction on a specific chain using Tether WDK
|
|
310
318
|
*/
|
|
311
|
-
async sendTransaction(seed,
|
|
319
|
+
async sendTransaction(seed, chain, to, amount, network = "mainnet") {
|
|
312
320
|
try {
|
|
313
321
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
314
322
|
method: "POST",
|
|
315
|
-
headers:
|
|
316
|
-
|
|
317
|
-
},
|
|
318
|
-
body: JSON.stringify({ seed, chain: chain2, to, amount, network })
|
|
323
|
+
headers: this.getHeaders(),
|
|
324
|
+
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
319
325
|
});
|
|
320
326
|
return await response.json();
|
|
321
327
|
} catch (error) {
|
|
@@ -329,14 +335,12 @@ var WdkApiClient = class {
|
|
|
329
335
|
* Get transaction history for an address on a specific chain
|
|
330
336
|
* Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
|
|
331
337
|
*/
|
|
332
|
-
async getTransactionHistory(seed,
|
|
338
|
+
async getTransactionHistory(seed, chain, network = "mainnet", limit = 10) {
|
|
333
339
|
try {
|
|
334
340
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
335
341
|
method: "POST",
|
|
336
|
-
headers:
|
|
337
|
-
|
|
338
|
-
},
|
|
339
|
-
body: JSON.stringify({ seed, chain: chain2, network, limit })
|
|
342
|
+
headers: this.getHeaders(),
|
|
343
|
+
body: JSON.stringify({ seed, chain, network, limit })
|
|
340
344
|
});
|
|
341
345
|
return await response.json();
|
|
342
346
|
} catch (error) {
|
|
@@ -350,14 +354,12 @@ var WdkApiClient = class {
|
|
|
350
354
|
* Get transaction status by hash
|
|
351
355
|
* Fetches from blockchain explorers to check confirmation status
|
|
352
356
|
*/
|
|
353
|
-
async getTransactionStatus(txHash,
|
|
357
|
+
async getTransactionStatus(txHash, chain, network = "mainnet") {
|
|
354
358
|
try {
|
|
355
359
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
356
360
|
method: "POST",
|
|
357
|
-
headers:
|
|
358
|
-
|
|
359
|
-
},
|
|
360
|
-
body: JSON.stringify({ txHash, chain: chain2, network })
|
|
361
|
+
headers: this.getHeaders(),
|
|
362
|
+
body: JSON.stringify({ txHash, chain, network })
|
|
361
363
|
});
|
|
362
364
|
return await response.json();
|
|
363
365
|
} catch (error) {
|
|
@@ -370,11 +372,14 @@ var WdkApiClient = class {
|
|
|
370
372
|
};
|
|
371
373
|
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
372
374
|
var wdkApiClient = null;
|
|
373
|
-
function getWdkApiClient(baseUrl) {
|
|
375
|
+
function getWdkApiClient(baseUrl, authToken) {
|
|
374
376
|
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
375
377
|
wdkApiClient = new WdkApiClient({
|
|
376
|
-
baseUrl: baseUrl || DEFAULT_API_URL
|
|
378
|
+
baseUrl: baseUrl || DEFAULT_API_URL,
|
|
379
|
+
authToken
|
|
377
380
|
});
|
|
381
|
+
} else if (authToken !== void 0) {
|
|
382
|
+
wdkApiClient.setAuthToken(authToken);
|
|
378
383
|
}
|
|
379
384
|
return wdkApiClient;
|
|
380
385
|
}
|
|
@@ -1078,616 +1083,45 @@ __export(BrowserAddressDerivation_exports, {
|
|
|
1078
1083
|
isValidSeed: () => isValidSeed
|
|
1079
1084
|
});
|
|
1080
1085
|
|
|
1081
|
-
//
|
|
1082
|
-
function isBytes(a) {
|
|
1083
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1084
|
-
}
|
|
1085
|
-
function isArrayOf(isString, arr) {
|
|
1086
|
-
if (!Array.isArray(arr))
|
|
1087
|
-
return false;
|
|
1088
|
-
if (arr.length === 0)
|
|
1089
|
-
return true;
|
|
1090
|
-
if (isString) {
|
|
1091
|
-
return arr.every((item) => typeof item === "string");
|
|
1092
|
-
} else {
|
|
1093
|
-
return arr.every((item) => Number.isSafeInteger(item));
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
function afn(input) {
|
|
1097
|
-
if (typeof input !== "function")
|
|
1098
|
-
throw new Error("function expected");
|
|
1099
|
-
return true;
|
|
1100
|
-
}
|
|
1101
|
-
function astr(label, input) {
|
|
1102
|
-
if (typeof input !== "string")
|
|
1103
|
-
throw new Error(`${label}: string expected`);
|
|
1104
|
-
return true;
|
|
1105
|
-
}
|
|
1106
|
-
function anumber(n) {
|
|
1107
|
-
if (!Number.isSafeInteger(n))
|
|
1108
|
-
throw new Error(`invalid integer: ${n}`);
|
|
1109
|
-
}
|
|
1110
|
-
function aArr(input) {
|
|
1111
|
-
if (!Array.isArray(input))
|
|
1112
|
-
throw new Error("array expected");
|
|
1113
|
-
}
|
|
1114
|
-
function astrArr(label, input) {
|
|
1115
|
-
if (!isArrayOf(true, input))
|
|
1116
|
-
throw new Error(`${label}: array of strings expected`);
|
|
1117
|
-
}
|
|
1118
|
-
function anumArr(label, input) {
|
|
1119
|
-
if (!isArrayOf(false, input))
|
|
1120
|
-
throw new Error(`${label}: array of numbers expected`);
|
|
1121
|
-
}
|
|
1122
|
-
// @__NO_SIDE_EFFECTS__
|
|
1123
|
-
function chain(...args) {
|
|
1124
|
-
const id = (a) => a;
|
|
1125
|
-
const wrap = (a, b) => (c) => a(b(c));
|
|
1126
|
-
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
|
1127
|
-
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
|
1128
|
-
return { encode, decode };
|
|
1129
|
-
}
|
|
1130
|
-
// @__NO_SIDE_EFFECTS__
|
|
1131
|
-
function alphabet(letters) {
|
|
1132
|
-
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
1133
|
-
const len = lettersA.length;
|
|
1134
|
-
astrArr("alphabet", lettersA);
|
|
1135
|
-
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
1136
|
-
return {
|
|
1137
|
-
encode: (digits) => {
|
|
1138
|
-
aArr(digits);
|
|
1139
|
-
return digits.map((i) => {
|
|
1140
|
-
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
1141
|
-
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
1142
|
-
return lettersA[i];
|
|
1143
|
-
});
|
|
1144
|
-
},
|
|
1145
|
-
decode: (input) => {
|
|
1146
|
-
aArr(input);
|
|
1147
|
-
return input.map((letter) => {
|
|
1148
|
-
astr("alphabet.decode", letter);
|
|
1149
|
-
const i = indexes.get(letter);
|
|
1150
|
-
if (i === void 0)
|
|
1151
|
-
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
1152
|
-
return i;
|
|
1153
|
-
});
|
|
1154
|
-
}
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
// @__NO_SIDE_EFFECTS__
|
|
1158
|
-
function join(separator = "") {
|
|
1159
|
-
astr("join", separator);
|
|
1160
|
-
return {
|
|
1161
|
-
encode: (from) => {
|
|
1162
|
-
astrArr("join.decode", from);
|
|
1163
|
-
return from.join(separator);
|
|
1164
|
-
},
|
|
1165
|
-
decode: (to) => {
|
|
1166
|
-
astr("join.decode", to);
|
|
1167
|
-
return to.split(separator);
|
|
1168
|
-
}
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
function convertRadix(data, from, to) {
|
|
1172
|
-
if (from < 2)
|
|
1173
|
-
throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
1174
|
-
if (to < 2)
|
|
1175
|
-
throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
1176
|
-
aArr(data);
|
|
1177
|
-
if (!data.length)
|
|
1178
|
-
return [];
|
|
1179
|
-
let pos = 0;
|
|
1180
|
-
const res = [];
|
|
1181
|
-
const digits = Array.from(data, (d) => {
|
|
1182
|
-
anumber(d);
|
|
1183
|
-
if (d < 0 || d >= from)
|
|
1184
|
-
throw new Error(`invalid integer: ${d}`);
|
|
1185
|
-
return d;
|
|
1186
|
-
});
|
|
1187
|
-
const dlen = digits.length;
|
|
1188
|
-
while (true) {
|
|
1189
|
-
let carry = 0;
|
|
1190
|
-
let done = true;
|
|
1191
|
-
for (let i = pos; i < dlen; i++) {
|
|
1192
|
-
const digit = digits[i];
|
|
1193
|
-
const fromCarry = from * carry;
|
|
1194
|
-
const digitBase = fromCarry + digit;
|
|
1195
|
-
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
|
|
1196
|
-
throw new Error("convertRadix: carry overflow");
|
|
1197
|
-
}
|
|
1198
|
-
const div = digitBase / to;
|
|
1199
|
-
carry = digitBase % to;
|
|
1200
|
-
const rounded = Math.floor(div);
|
|
1201
|
-
digits[i] = rounded;
|
|
1202
|
-
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
1203
|
-
throw new Error("convertRadix: carry overflow");
|
|
1204
|
-
if (!done)
|
|
1205
|
-
continue;
|
|
1206
|
-
else if (!rounded)
|
|
1207
|
-
pos = i;
|
|
1208
|
-
else
|
|
1209
|
-
done = false;
|
|
1210
|
-
}
|
|
1211
|
-
res.push(carry);
|
|
1212
|
-
if (done)
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
|
|
1216
|
-
res.push(0);
|
|
1217
|
-
return res.reverse();
|
|
1218
|
-
}
|
|
1219
|
-
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
1220
|
-
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
1221
|
-
var powers = /* @__PURE__ */ (() => {
|
|
1222
|
-
let res = [];
|
|
1223
|
-
for (let i = 0; i < 40; i++)
|
|
1224
|
-
res.push(2 ** i);
|
|
1225
|
-
return res;
|
|
1226
|
-
})();
|
|
1227
|
-
function convertRadix2(data, from, to, padding) {
|
|
1228
|
-
aArr(data);
|
|
1229
|
-
if (from <= 0 || from > 32)
|
|
1230
|
-
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
1231
|
-
if (to <= 0 || to > 32)
|
|
1232
|
-
throw new Error(`convertRadix2: wrong to=${to}`);
|
|
1233
|
-
if (/* @__PURE__ */ radix2carry(from, to) > 32) {
|
|
1234
|
-
throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
1235
|
-
}
|
|
1236
|
-
let carry = 0;
|
|
1237
|
-
let pos = 0;
|
|
1238
|
-
const max = powers[from];
|
|
1239
|
-
const mask = powers[to] - 1;
|
|
1240
|
-
const res = [];
|
|
1241
|
-
for (const n of data) {
|
|
1242
|
-
anumber(n);
|
|
1243
|
-
if (n >= max)
|
|
1244
|
-
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
1245
|
-
carry = carry << from | n;
|
|
1246
|
-
if (pos + from > 32)
|
|
1247
|
-
throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
1248
|
-
pos += from;
|
|
1249
|
-
for (; pos >= to; pos -= to)
|
|
1250
|
-
res.push((carry >> pos - to & mask) >>> 0);
|
|
1251
|
-
const pow = powers[pos];
|
|
1252
|
-
if (pow === void 0)
|
|
1253
|
-
throw new Error("invalid carry");
|
|
1254
|
-
carry &= pow - 1;
|
|
1255
|
-
}
|
|
1256
|
-
carry = carry << to - pos & mask;
|
|
1257
|
-
if (!padding && pos >= from)
|
|
1258
|
-
throw new Error("Excess padding");
|
|
1259
|
-
if (!padding && carry > 0)
|
|
1260
|
-
throw new Error(`Non-zero padding: ${carry}`);
|
|
1261
|
-
if (padding && pos > 0)
|
|
1262
|
-
res.push(carry >>> 0);
|
|
1263
|
-
return res;
|
|
1264
|
-
}
|
|
1265
|
-
// @__NO_SIDE_EFFECTS__
|
|
1266
|
-
function radix(num) {
|
|
1267
|
-
anumber(num);
|
|
1268
|
-
const _256 = 2 ** 8;
|
|
1269
|
-
return {
|
|
1270
|
-
encode: (bytes) => {
|
|
1271
|
-
if (!isBytes(bytes))
|
|
1272
|
-
throw new Error("radix.encode input should be Uint8Array");
|
|
1273
|
-
return convertRadix(Array.from(bytes), _256, num);
|
|
1274
|
-
},
|
|
1275
|
-
decode: (digits) => {
|
|
1276
|
-
anumArr("radix.decode", digits);
|
|
1277
|
-
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
1278
|
-
}
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
// @__NO_SIDE_EFFECTS__
|
|
1282
|
-
function radix2(bits, revPadding = false) {
|
|
1283
|
-
anumber(bits);
|
|
1284
|
-
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
1285
|
-
throw new Error("radix2: carry overflow");
|
|
1286
|
-
return {
|
|
1287
|
-
encode: (bytes) => {
|
|
1288
|
-
if (!isBytes(bytes))
|
|
1289
|
-
throw new Error("radix2.encode input should be Uint8Array");
|
|
1290
|
-
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
1291
|
-
},
|
|
1292
|
-
decode: (digits) => {
|
|
1293
|
-
anumArr("radix2.decode", digits);
|
|
1294
|
-
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
1295
|
-
}
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
function unsafeWrapper(fn) {
|
|
1299
|
-
afn(fn);
|
|
1300
|
-
return function(...args) {
|
|
1301
|
-
try {
|
|
1302
|
-
return fn.apply(null, args);
|
|
1303
|
-
} catch (e) {
|
|
1304
|
-
}
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
function checksum(len, fn) {
|
|
1308
|
-
anumber(len);
|
|
1309
|
-
afn(fn);
|
|
1310
|
-
return {
|
|
1311
|
-
encode(data) {
|
|
1312
|
-
if (!isBytes(data))
|
|
1313
|
-
throw new Error("checksum.encode: input should be Uint8Array");
|
|
1314
|
-
const sum = fn(data).slice(0, len);
|
|
1315
|
-
const res = new Uint8Array(data.length + len);
|
|
1316
|
-
res.set(data);
|
|
1317
|
-
res.set(sum, data.length);
|
|
1318
|
-
return res;
|
|
1319
|
-
},
|
|
1320
|
-
decode(data) {
|
|
1321
|
-
if (!isBytes(data))
|
|
1322
|
-
throw new Error("checksum.decode: input should be Uint8Array");
|
|
1323
|
-
const payload = data.slice(0, -len);
|
|
1324
|
-
const oldChecksum = data.slice(-len);
|
|
1325
|
-
const newChecksum = fn(payload).slice(0, len);
|
|
1326
|
-
for (let i = 0; i < len; i++)
|
|
1327
|
-
if (newChecksum[i] !== oldChecksum[i])
|
|
1328
|
-
throw new Error("Invalid checksum");
|
|
1329
|
-
return payload;
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
1334
|
-
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1335
|
-
var createBase58check = (sha2563) => /* @__PURE__ */ chain(checksum(4, (data) => sha2563(sha2563(data))), base58);
|
|
1336
|
-
var base58check = createBase58check;
|
|
1337
|
-
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
1338
|
-
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
1339
|
-
function bech32Polymod(pre) {
|
|
1340
|
-
const b = pre >> 25;
|
|
1341
|
-
let chk = (pre & 33554431) << 5;
|
|
1342
|
-
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
|
|
1343
|
-
if ((b >> i & 1) === 1)
|
|
1344
|
-
chk ^= POLYMOD_GENERATORS[i];
|
|
1345
|
-
}
|
|
1346
|
-
return chk;
|
|
1347
|
-
}
|
|
1348
|
-
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
1349
|
-
const len = prefix.length;
|
|
1350
|
-
let chk = 1;
|
|
1351
|
-
for (let i = 0; i < len; i++) {
|
|
1352
|
-
const c = prefix.charCodeAt(i);
|
|
1353
|
-
if (c < 33 || c > 126)
|
|
1354
|
-
throw new Error(`Invalid prefix (${prefix})`);
|
|
1355
|
-
chk = bech32Polymod(chk) ^ c >> 5;
|
|
1356
|
-
}
|
|
1357
|
-
chk = bech32Polymod(chk);
|
|
1358
|
-
for (let i = 0; i < len; i++)
|
|
1359
|
-
chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
1360
|
-
for (let v of words)
|
|
1361
|
-
chk = bech32Polymod(chk) ^ v;
|
|
1362
|
-
for (let i = 0; i < 6; i++)
|
|
1363
|
-
chk = bech32Polymod(chk);
|
|
1364
|
-
chk ^= encodingConst;
|
|
1365
|
-
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
1366
|
-
}
|
|
1367
|
-
// @__NO_SIDE_EFFECTS__
|
|
1368
|
-
function genBech32(encoding) {
|
|
1369
|
-
const ENCODING_CONST = 1 ;
|
|
1370
|
-
const _words = /* @__PURE__ */ radix2(5);
|
|
1371
|
-
const fromWords = _words.decode;
|
|
1372
|
-
const toWords = _words.encode;
|
|
1373
|
-
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
1374
|
-
function encode(prefix, words, limit = 90) {
|
|
1375
|
-
astr("bech32.encode prefix", prefix);
|
|
1376
|
-
if (isBytes(words))
|
|
1377
|
-
words = Array.from(words);
|
|
1378
|
-
anumArr("bech32.encode", words);
|
|
1379
|
-
const plen = prefix.length;
|
|
1380
|
-
if (plen === 0)
|
|
1381
|
-
throw new TypeError(`Invalid prefix length ${plen}`);
|
|
1382
|
-
const actualLength = plen + 7 + words.length;
|
|
1383
|
-
if (limit !== false && actualLength > limit)
|
|
1384
|
-
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
1385
|
-
const lowered = prefix.toLowerCase();
|
|
1386
|
-
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
1387
|
-
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
1388
|
-
}
|
|
1389
|
-
function decode(str, limit = 90) {
|
|
1390
|
-
astr("bech32.decode input", str);
|
|
1391
|
-
const slen = str.length;
|
|
1392
|
-
if (slen < 8 || limit !== false && slen > limit)
|
|
1393
|
-
throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
1394
|
-
const lowered = str.toLowerCase();
|
|
1395
|
-
if (str !== lowered && str !== str.toUpperCase())
|
|
1396
|
-
throw new Error(`String must be lowercase or uppercase`);
|
|
1397
|
-
const sepIndex = lowered.lastIndexOf("1");
|
|
1398
|
-
if (sepIndex === 0 || sepIndex === -1)
|
|
1399
|
-
throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
1400
|
-
const prefix = lowered.slice(0, sepIndex);
|
|
1401
|
-
const data = lowered.slice(sepIndex + 1);
|
|
1402
|
-
if (data.length < 6)
|
|
1403
|
-
throw new Error("Data must be at least 6 characters long");
|
|
1404
|
-
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
1405
|
-
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
1406
|
-
if (!data.endsWith(sum))
|
|
1407
|
-
throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
1408
|
-
return { prefix, words };
|
|
1409
|
-
}
|
|
1410
|
-
const decodeUnsafe = unsafeWrapper(decode);
|
|
1411
|
-
function decodeToBytes(str) {
|
|
1412
|
-
const { prefix, words } = decode(str, false);
|
|
1413
|
-
return { prefix, words, bytes: fromWords(words) };
|
|
1414
|
-
}
|
|
1415
|
-
function encodeFromBytes(prefix, bytes) {
|
|
1416
|
-
return encode(prefix, toWords(bytes));
|
|
1417
|
-
}
|
|
1418
|
-
return {
|
|
1419
|
-
encode,
|
|
1420
|
-
decode,
|
|
1421
|
-
encodeFromBytes,
|
|
1422
|
-
decodeToBytes,
|
|
1423
|
-
decodeUnsafe,
|
|
1424
|
-
fromWords,
|
|
1425
|
-
fromWordsUnsafe,
|
|
1426
|
-
toWords
|
|
1427
|
-
};
|
|
1428
|
-
}
|
|
1429
|
-
var bech32 = /* @__PURE__ */ genBech32();
|
|
1430
|
-
|
|
1431
|
-
// node_modules/@scure/bip32/index.js
|
|
1432
|
-
var Point = secp256k1_js.secp256k1.Point;
|
|
1433
|
-
var { Fn } = Point;
|
|
1434
|
-
var base58check2 = createBase58check(sha2_js.sha256);
|
|
1435
|
-
var MASTER_SECRET = Uint8Array.from("Bitcoin seed".split(""), (char) => char.charCodeAt(0));
|
|
1436
|
-
var BITCOIN_VERSIONS = { private: 76066276, public: 76067358 };
|
|
1437
|
-
var HARDENED_OFFSET = 2147483648;
|
|
1438
|
-
var hash160 = (data) => legacy_js.ripemd160(sha2_js.sha256(data));
|
|
1439
|
-
var fromU32 = (data) => utils_js.createView(data).getUint32(0, false);
|
|
1440
|
-
var toU32 = (n) => {
|
|
1441
|
-
if (!Number.isSafeInteger(n) || n < 0 || n > 2 ** 32 - 1) {
|
|
1442
|
-
throw new Error("invalid number, should be from 0 to 2**32-1, got " + n);
|
|
1443
|
-
}
|
|
1444
|
-
const buf = new Uint8Array(4);
|
|
1445
|
-
utils_js.createView(buf).setUint32(0, n, false);
|
|
1446
|
-
return buf;
|
|
1447
|
-
};
|
|
1448
|
-
var HDKey = class _HDKey {
|
|
1449
|
-
get fingerprint() {
|
|
1450
|
-
if (!this.pubHash) {
|
|
1451
|
-
throw new Error("No publicKey set!");
|
|
1452
|
-
}
|
|
1453
|
-
return fromU32(this.pubHash);
|
|
1454
|
-
}
|
|
1455
|
-
get identifier() {
|
|
1456
|
-
return this.pubHash;
|
|
1457
|
-
}
|
|
1458
|
-
get pubKeyHash() {
|
|
1459
|
-
return this.pubHash;
|
|
1460
|
-
}
|
|
1461
|
-
get privateKey() {
|
|
1462
|
-
return this._privateKey || null;
|
|
1463
|
-
}
|
|
1464
|
-
get publicKey() {
|
|
1465
|
-
return this._publicKey || null;
|
|
1466
|
-
}
|
|
1467
|
-
get privateExtendedKey() {
|
|
1468
|
-
const priv = this._privateKey;
|
|
1469
|
-
if (!priv) {
|
|
1470
|
-
throw new Error("No private key");
|
|
1471
|
-
}
|
|
1472
|
-
return base58check2.encode(this.serialize(this.versions.private, utils_js.concatBytes(Uint8Array.of(0), priv)));
|
|
1473
|
-
}
|
|
1474
|
-
get publicExtendedKey() {
|
|
1475
|
-
if (!this._publicKey) {
|
|
1476
|
-
throw new Error("No public key");
|
|
1477
|
-
}
|
|
1478
|
-
return base58check2.encode(this.serialize(this.versions.public, this._publicKey));
|
|
1479
|
-
}
|
|
1480
|
-
static fromMasterSeed(seed, versions = BITCOIN_VERSIONS) {
|
|
1481
|
-
utils_js.abytes(seed);
|
|
1482
|
-
if (8 * seed.length < 128 || 8 * seed.length > 512) {
|
|
1483
|
-
throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got " + seed.length);
|
|
1484
|
-
}
|
|
1485
|
-
const I = hmac_js.hmac(sha2_js.sha512, MASTER_SECRET, seed);
|
|
1486
|
-
const privateKey = I.slice(0, 32);
|
|
1487
|
-
const chainCode = I.slice(32);
|
|
1488
|
-
return new _HDKey({ versions, chainCode, privateKey });
|
|
1489
|
-
}
|
|
1490
|
-
static fromExtendedKey(base58key, versions = BITCOIN_VERSIONS) {
|
|
1491
|
-
const keyBuffer = base58check2.decode(base58key);
|
|
1492
|
-
const keyView = utils_js.createView(keyBuffer);
|
|
1493
|
-
const version = keyView.getUint32(0, false);
|
|
1494
|
-
const opt = {
|
|
1495
|
-
versions,
|
|
1496
|
-
depth: keyBuffer[4],
|
|
1497
|
-
parentFingerprint: keyView.getUint32(5, false),
|
|
1498
|
-
index: keyView.getUint32(9, false),
|
|
1499
|
-
chainCode: keyBuffer.slice(13, 45)
|
|
1500
|
-
};
|
|
1501
|
-
const key = keyBuffer.slice(45);
|
|
1502
|
-
const isPriv = key[0] === 0;
|
|
1503
|
-
if (version !== versions[isPriv ? "private" : "public"]) {
|
|
1504
|
-
throw new Error("Version mismatch");
|
|
1505
|
-
}
|
|
1506
|
-
if (isPriv) {
|
|
1507
|
-
return new _HDKey({ ...opt, privateKey: key.slice(1) });
|
|
1508
|
-
} else {
|
|
1509
|
-
return new _HDKey({ ...opt, publicKey: key });
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
static fromJSON(json) {
|
|
1513
|
-
return _HDKey.fromExtendedKey(json.xpriv);
|
|
1514
|
-
}
|
|
1515
|
-
versions;
|
|
1516
|
-
depth = 0;
|
|
1517
|
-
index = 0;
|
|
1518
|
-
chainCode = null;
|
|
1519
|
-
parentFingerprint = 0;
|
|
1520
|
-
_privateKey;
|
|
1521
|
-
_publicKey;
|
|
1522
|
-
pubHash;
|
|
1523
|
-
constructor(opt) {
|
|
1524
|
-
if (!opt || typeof opt !== "object") {
|
|
1525
|
-
throw new Error("HDKey.constructor must not be called directly");
|
|
1526
|
-
}
|
|
1527
|
-
this.versions = opt.versions || BITCOIN_VERSIONS;
|
|
1528
|
-
this.depth = opt.depth || 0;
|
|
1529
|
-
this.chainCode = opt.chainCode || null;
|
|
1530
|
-
this.index = opt.index || 0;
|
|
1531
|
-
this.parentFingerprint = opt.parentFingerprint || 0;
|
|
1532
|
-
if (!this.depth) {
|
|
1533
|
-
if (this.parentFingerprint || this.index) {
|
|
1534
|
-
throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
if (this.depth > 255) {
|
|
1538
|
-
throw new Error("HDKey: depth exceeds the serializable value 255");
|
|
1539
|
-
}
|
|
1540
|
-
if (opt.publicKey && opt.privateKey) {
|
|
1541
|
-
throw new Error("HDKey: publicKey and privateKey at same time.");
|
|
1542
|
-
}
|
|
1543
|
-
if (opt.privateKey) {
|
|
1544
|
-
if (!secp256k1_js.secp256k1.utils.isValidSecretKey(opt.privateKey))
|
|
1545
|
-
throw new Error("Invalid private key");
|
|
1546
|
-
this._privateKey = opt.privateKey;
|
|
1547
|
-
this._publicKey = secp256k1_js.secp256k1.getPublicKey(opt.privateKey, true);
|
|
1548
|
-
} else if (opt.publicKey) {
|
|
1549
|
-
this._publicKey = Point.fromBytes(opt.publicKey).toBytes(true);
|
|
1550
|
-
} else {
|
|
1551
|
-
throw new Error("HDKey: no public or private key provided");
|
|
1552
|
-
}
|
|
1553
|
-
this.pubHash = hash160(this._publicKey);
|
|
1554
|
-
}
|
|
1555
|
-
derive(path) {
|
|
1556
|
-
if (!/^[mM]'?/.test(path)) {
|
|
1557
|
-
throw new Error('Path must start with "m" or "M"');
|
|
1558
|
-
}
|
|
1559
|
-
if (/^[mM]'?$/.test(path)) {
|
|
1560
|
-
return this;
|
|
1561
|
-
}
|
|
1562
|
-
const parts = path.replace(/^[mM]'?\//, "").split("/");
|
|
1563
|
-
let child = this;
|
|
1564
|
-
for (const c of parts) {
|
|
1565
|
-
const m = /^(\d+)('?)$/.exec(c);
|
|
1566
|
-
const m1 = m && m[1];
|
|
1567
|
-
if (!m || m.length !== 3 || typeof m1 !== "string")
|
|
1568
|
-
throw new Error("invalid child index: " + c);
|
|
1569
|
-
let idx = +m1;
|
|
1570
|
-
if (!Number.isSafeInteger(idx) || idx >= HARDENED_OFFSET) {
|
|
1571
|
-
throw new Error("Invalid index");
|
|
1572
|
-
}
|
|
1573
|
-
if (m[2] === "'") {
|
|
1574
|
-
idx += HARDENED_OFFSET;
|
|
1575
|
-
}
|
|
1576
|
-
child = child.deriveChild(idx);
|
|
1577
|
-
}
|
|
1578
|
-
return child;
|
|
1579
|
-
}
|
|
1580
|
-
deriveChild(index) {
|
|
1581
|
-
if (!this._publicKey || !this.chainCode) {
|
|
1582
|
-
throw new Error("No publicKey or chainCode set");
|
|
1583
|
-
}
|
|
1584
|
-
let data = toU32(index);
|
|
1585
|
-
if (index >= HARDENED_OFFSET) {
|
|
1586
|
-
const priv = this._privateKey;
|
|
1587
|
-
if (!priv) {
|
|
1588
|
-
throw new Error("Could not derive hardened child key");
|
|
1589
|
-
}
|
|
1590
|
-
data = utils_js.concatBytes(Uint8Array.of(0), priv, data);
|
|
1591
|
-
} else {
|
|
1592
|
-
data = utils_js.concatBytes(this._publicKey, data);
|
|
1593
|
-
}
|
|
1594
|
-
const I = hmac_js.hmac(sha2_js.sha512, this.chainCode, data);
|
|
1595
|
-
const childTweak = I.slice(0, 32);
|
|
1596
|
-
const chainCode = I.slice(32);
|
|
1597
|
-
if (!secp256k1_js.secp256k1.utils.isValidSecretKey(childTweak)) {
|
|
1598
|
-
throw new Error("Tweak bigger than curve order");
|
|
1599
|
-
}
|
|
1600
|
-
const opt = {
|
|
1601
|
-
versions: this.versions,
|
|
1602
|
-
chainCode,
|
|
1603
|
-
depth: this.depth + 1,
|
|
1604
|
-
parentFingerprint: this.fingerprint,
|
|
1605
|
-
index
|
|
1606
|
-
};
|
|
1607
|
-
const ctweak = Fn.fromBytes(childTweak);
|
|
1608
|
-
try {
|
|
1609
|
-
if (this._privateKey) {
|
|
1610
|
-
const added = Fn.create(Fn.fromBytes(this._privateKey) + ctweak);
|
|
1611
|
-
if (!Fn.isValidNot0(added)) {
|
|
1612
|
-
throw new Error("The tweak was out of range or the resulted private key is invalid");
|
|
1613
|
-
}
|
|
1614
|
-
opt.privateKey = Fn.toBytes(added);
|
|
1615
|
-
} else {
|
|
1616
|
-
const added = Point.fromBytes(this._publicKey).add(Point.BASE.multiply(ctweak));
|
|
1617
|
-
if (added.equals(Point.ZERO)) {
|
|
1618
|
-
throw new Error("The tweak was equal to negative P, which made the result key invalid");
|
|
1619
|
-
}
|
|
1620
|
-
opt.publicKey = added.toBytes(true);
|
|
1621
|
-
}
|
|
1622
|
-
return new _HDKey(opt);
|
|
1623
|
-
} catch (err) {
|
|
1624
|
-
return this.deriveChild(index + 1);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
sign(hash) {
|
|
1628
|
-
if (!this._privateKey) {
|
|
1629
|
-
throw new Error("No privateKey set!");
|
|
1630
|
-
}
|
|
1631
|
-
utils_js.abytes(hash, 32);
|
|
1632
|
-
return secp256k1_js.secp256k1.sign(hash, this._privateKey, { prehash: false });
|
|
1633
|
-
}
|
|
1634
|
-
verify(hash, signature) {
|
|
1635
|
-
utils_js.abytes(hash, 32);
|
|
1636
|
-
utils_js.abytes(signature, 64);
|
|
1637
|
-
if (!this._publicKey) {
|
|
1638
|
-
throw new Error("No publicKey set!");
|
|
1639
|
-
}
|
|
1640
|
-
return secp256k1_js.secp256k1.verify(signature, hash, this._publicKey, { prehash: false });
|
|
1641
|
-
}
|
|
1642
|
-
wipePrivateData() {
|
|
1643
|
-
if (this._privateKey) {
|
|
1644
|
-
this._privateKey.fill(0);
|
|
1645
|
-
this._privateKey = void 0;
|
|
1646
|
-
}
|
|
1647
|
-
return this;
|
|
1648
|
-
}
|
|
1649
|
-
toJSON() {
|
|
1650
|
-
return {
|
|
1651
|
-
xpriv: this.privateExtendedKey,
|
|
1652
|
-
xpub: this.publicExtendedKey
|
|
1653
|
-
};
|
|
1654
|
-
}
|
|
1655
|
-
serialize(version, key) {
|
|
1656
|
-
if (!this.chainCode) {
|
|
1657
|
-
throw new Error("No chainCode set");
|
|
1658
|
-
}
|
|
1659
|
-
utils_js.abytes(key, 33);
|
|
1660
|
-
return utils_js.concatBytes(toU32(version), new Uint8Array([this.depth]), toU32(this.parentFingerprint), toU32(this.index), this.chainCode, key);
|
|
1661
|
-
}
|
|
1662
|
-
};
|
|
1086
|
+
// src/config/networks.ts
|
|
1663
1087
|
var DERIVATION_PATHS = {
|
|
1664
|
-
|
|
1665
|
-
|
|
1088
|
+
bitcoin: "m/84'/0'/0'/0",
|
|
1089
|
+
ethereum: "m/44'/60'/0'/0",
|
|
1090
|
+
ton: "m/44'/607'/0'",
|
|
1091
|
+
tron: "m/44'/195'/0'/0",
|
|
1092
|
+
solana: "m/44'/501'/0'",
|
|
1093
|
+
spark: "m/44'/998'/0'/0"
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
// src/services/BrowserAddressDerivation.ts
|
|
1097
|
+
var DERIVATION_PATHS2 = {
|
|
1098
|
+
ethereum: `${DERIVATION_PATHS.ethereum}/0`,
|
|
1099
|
+
bitcoin_mainnet: `${DERIVATION_PATHS.bitcoin}/0`,
|
|
1666
1100
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
1667
|
-
ton:
|
|
1668
|
-
tron:
|
|
1669
|
-
solana:
|
|
1670
|
-
spark:
|
|
1101
|
+
ton: `${DERIVATION_PATHS.ton}/0'/0'`,
|
|
1102
|
+
tron: `${DERIVATION_PATHS.tron}/0`,
|
|
1103
|
+
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
1104
|
+
spark: `${DERIVATION_PATHS.spark}/0`
|
|
1671
1105
|
};
|
|
1672
1106
|
function deriveEthereumAddress(seed) {
|
|
1673
|
-
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0,
|
|
1107
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
1674
1108
|
return hdNode.address;
|
|
1675
1109
|
}
|
|
1676
1110
|
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
1677
1111
|
try {
|
|
1678
1112
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1679
|
-
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
1680
|
-
const path = network === "testnet" ?
|
|
1113
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
1114
|
+
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
1681
1115
|
const child = hdKey.derive(path);
|
|
1682
1116
|
if (!child.publicKey) {
|
|
1683
1117
|
throw new Error("Failed to derive public key");
|
|
1684
1118
|
}
|
|
1685
1119
|
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
1686
1120
|
const witnessVersion = 0;
|
|
1687
|
-
const words = bech32.toWords(pubKeyHash);
|
|
1121
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
1688
1122
|
words.unshift(witnessVersion);
|
|
1689
1123
|
const hrp = network === "testnet" ? "tb" : "bc";
|
|
1690
|
-
const address = bech32.encode(hrp, words);
|
|
1124
|
+
const address = base.bech32.encode(hrp, words);
|
|
1691
1125
|
return address;
|
|
1692
1126
|
} catch (error) {
|
|
1693
1127
|
console.error("Bitcoin address derivation failed:", error);
|
|
@@ -1703,7 +1137,7 @@ async function deriveSolanaAddress(seed) {
|
|
|
1703
1137
|
]);
|
|
1704
1138
|
const bs58 = bs58Module.default || bs58Module;
|
|
1705
1139
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1706
|
-
const derived = ed25519.derivePath(
|
|
1140
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
1707
1141
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
1708
1142
|
return bs58.encode(keypair.publicKey);
|
|
1709
1143
|
} catch (error) {
|
|
@@ -1718,7 +1152,7 @@ async function deriveTonAddress(seed) {
|
|
|
1718
1152
|
import('tweetnacl')
|
|
1719
1153
|
]);
|
|
1720
1154
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1721
|
-
const derived = ed25519.derivePath(
|
|
1155
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
1722
1156
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
1723
1157
|
const publicKey = keypair.publicKey;
|
|
1724
1158
|
const workchain = 0;
|
|
@@ -1753,14 +1187,14 @@ function crc16(data) {
|
|
|
1753
1187
|
}
|
|
1754
1188
|
function deriveTronAddress(seed) {
|
|
1755
1189
|
try {
|
|
1756
|
-
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0,
|
|
1190
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
1757
1191
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
1758
1192
|
const addressBytes = new Uint8Array(21);
|
|
1759
1193
|
addressBytes[0] = 65;
|
|
1760
1194
|
for (let i = 0; i < 20; i++) {
|
|
1761
1195
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
1762
1196
|
}
|
|
1763
|
-
const tronBase58check = base58check(sha256.sha256);
|
|
1197
|
+
const tronBase58check = base.base58check(sha256.sha256);
|
|
1764
1198
|
return tronBase58check.encode(addressBytes);
|
|
1765
1199
|
} catch (error) {
|
|
1766
1200
|
console.error("TRON address derivation failed:", error);
|
|
@@ -1770,17 +1204,17 @@ function deriveTronAddress(seed) {
|
|
|
1770
1204
|
function deriveSparkAddress(seed, network = "mainnet") {
|
|
1771
1205
|
try {
|
|
1772
1206
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1773
|
-
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
1774
|
-
const child = hdKey.derive(
|
|
1207
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
1208
|
+
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
1775
1209
|
if (!child.publicKey) {
|
|
1776
1210
|
throw new Error("Failed to derive public key");
|
|
1777
1211
|
}
|
|
1778
1212
|
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
1779
1213
|
const witnessVersion = 0;
|
|
1780
|
-
const words = bech32.toWords(pubKeyHash);
|
|
1214
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
1781
1215
|
words.unshift(witnessVersion);
|
|
1782
1216
|
const hrp = network === "testnet" ? "tsp" : "sp";
|
|
1783
|
-
const address = bech32.encode(hrp, words);
|
|
1217
|
+
const address = base.bech32.encode(hrp, words);
|
|
1784
1218
|
return address;
|
|
1785
1219
|
} catch (error) {
|
|
1786
1220
|
console.error("Spark address derivation failed:", error);
|
|
@@ -1876,9 +1310,9 @@ var CHAIN_ERROR_MESSAGES = {
|
|
|
1876
1310
|
"no route": "NETWORK_ERROR"
|
|
1877
1311
|
}
|
|
1878
1312
|
};
|
|
1879
|
-
function parseChainError(
|
|
1313
|
+
function parseChainError(chain, errorMessage) {
|
|
1880
1314
|
const errorLower = errorMessage.toLowerCase();
|
|
1881
|
-
const chainErrors = CHAIN_ERROR_MESSAGES[
|
|
1315
|
+
const chainErrors = CHAIN_ERROR_MESSAGES[chain];
|
|
1882
1316
|
for (const [pattern, code] of Object.entries(chainErrors)) {
|
|
1883
1317
|
if (errorLower.includes(pattern)) {
|
|
1884
1318
|
return code;
|
|
@@ -2016,38 +1450,38 @@ var ZubariWdkService = class {
|
|
|
2016
1450
|
* For Ethereum, falls back to local derivation if API fails.
|
|
2017
1451
|
* For other chains, WDK API is required - no placeholder fallback.
|
|
2018
1452
|
*/
|
|
2019
|
-
async deriveAddress(seed,
|
|
1453
|
+
async deriveAddress(seed, chain) {
|
|
2020
1454
|
await this.initialize();
|
|
2021
|
-
const path = this.getDerivationPath(
|
|
1455
|
+
const path = this.getDerivationPath(chain);
|
|
2022
1456
|
try {
|
|
2023
|
-
const response = await this.apiClient.deriveAddress(seed,
|
|
1457
|
+
const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
|
|
2024
1458
|
if (response.success && response.address) {
|
|
2025
1459
|
return {
|
|
2026
|
-
chain
|
|
1460
|
+
chain,
|
|
2027
1461
|
address: response.address,
|
|
2028
1462
|
path: response.path || path
|
|
2029
1463
|
};
|
|
2030
1464
|
}
|
|
2031
1465
|
} catch (error) {
|
|
2032
|
-
console.warn(`API address derivation failed for ${
|
|
2033
|
-
if (
|
|
2034
|
-
return this.deriveBrowserAddress(seed,
|
|
1466
|
+
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
1467
|
+
if (chain === "ethereum") {
|
|
1468
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
2035
1469
|
}
|
|
2036
1470
|
}
|
|
2037
1471
|
if (this.useNativeWdk && this.nativeWdkService) {
|
|
2038
1472
|
try {
|
|
2039
1473
|
const wdk = this.nativeWdkService;
|
|
2040
1474
|
await wdk.initialize(seed);
|
|
2041
|
-
return await wdk.deriveAddress(
|
|
1475
|
+
return await wdk.deriveAddress(chain);
|
|
2042
1476
|
} catch (error) {
|
|
2043
|
-
console.warn(`Native WDK address derivation failed for ${
|
|
1477
|
+
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
2044
1478
|
}
|
|
2045
1479
|
}
|
|
2046
|
-
if (
|
|
2047
|
-
return this.deriveBrowserAddress(seed,
|
|
1480
|
+
if (chain === "ethereum") {
|
|
1481
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
2048
1482
|
}
|
|
2049
1483
|
throw new Error(
|
|
2050
|
-
`WDK API required for ${
|
|
1484
|
+
`WDK API required for ${chain} address derivation. Ensure the backend is running.`
|
|
2051
1485
|
);
|
|
2052
1486
|
}
|
|
2053
1487
|
/**
|
|
@@ -2127,13 +1561,13 @@ var ZubariWdkService = class {
|
|
|
2127
1561
|
/**
|
|
2128
1562
|
* Get fee rates for a chain
|
|
2129
1563
|
*/
|
|
2130
|
-
async getFeeRates(seed,
|
|
1564
|
+
async getFeeRates(seed, chain) {
|
|
2131
1565
|
await this.initialize();
|
|
2132
1566
|
try {
|
|
2133
1567
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
|
|
2134
1568
|
method: "POST",
|
|
2135
1569
|
headers: { "Content-Type": "application/json" },
|
|
2136
|
-
body: JSON.stringify({ seed, chain
|
|
1570
|
+
body: JSON.stringify({ seed, chain, network: this.config.network })
|
|
2137
1571
|
});
|
|
2138
1572
|
if (response.ok) {
|
|
2139
1573
|
const data = await response.json();
|
|
@@ -2142,20 +1576,20 @@ var ZubariWdkService = class {
|
|
|
2142
1576
|
}
|
|
2143
1577
|
}
|
|
2144
1578
|
} catch (error) {
|
|
2145
|
-
console.warn(`Failed to fetch fee rates for ${
|
|
1579
|
+
console.warn(`Failed to fetch fee rates for ${chain}:`, error);
|
|
2146
1580
|
}
|
|
2147
1581
|
return { slow: "0", normal: "0", fast: "0" };
|
|
2148
1582
|
}
|
|
2149
1583
|
/**
|
|
2150
1584
|
* Estimate transaction fee
|
|
2151
1585
|
*/
|
|
2152
|
-
async estimateFee(seed,
|
|
1586
|
+
async estimateFee(seed, chain, to, amount) {
|
|
2153
1587
|
await this.initialize();
|
|
2154
1588
|
try {
|
|
2155
1589
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
2156
1590
|
method: "POST",
|
|
2157
1591
|
headers: { "Content-Type": "application/json" },
|
|
2158
|
-
body: JSON.stringify({ seed, chain
|
|
1592
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
2159
1593
|
});
|
|
2160
1594
|
if (response.ok) {
|
|
2161
1595
|
const data = await response.json();
|
|
@@ -2164,9 +1598,9 @@ var ZubariWdkService = class {
|
|
|
2164
1598
|
}
|
|
2165
1599
|
}
|
|
2166
1600
|
} catch (error) {
|
|
2167
|
-
console.warn(`Failed to estimate fee for ${
|
|
1601
|
+
console.warn(`Failed to estimate fee for ${chain}:`, error);
|
|
2168
1602
|
}
|
|
2169
|
-
return { fee: "0", symbol: this.getChainSymbol(
|
|
1603
|
+
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
2170
1604
|
}
|
|
2171
1605
|
/**
|
|
2172
1606
|
* Send a transaction on any supported chain
|
|
@@ -2177,19 +1611,14 @@ var ZubariWdkService = class {
|
|
|
2177
1611
|
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
2178
1612
|
* @returns Transaction result with hash on success, or error details on failure
|
|
2179
1613
|
*/
|
|
2180
|
-
async sendTransaction(seed,
|
|
1614
|
+
async sendTransaction(seed, chain, to, amount) {
|
|
2181
1615
|
await this.initialize();
|
|
2182
1616
|
const startTime = Date.now();
|
|
2183
|
-
console.log(`[ZubariWdkService] Sending ${chain2} transaction`, {
|
|
2184
|
-
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
2185
|
-
amount,
|
|
2186
|
-
network: this.config.network
|
|
2187
|
-
});
|
|
2188
1617
|
try {
|
|
2189
1618
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
2190
1619
|
method: "POST",
|
|
2191
1620
|
headers: { "Content-Type": "application/json" },
|
|
2192
|
-
body: JSON.stringify({ seed, chain
|
|
1621
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
2193
1622
|
});
|
|
2194
1623
|
const elapsed = Date.now() - startTime;
|
|
2195
1624
|
if (response.ok) {
|
|
@@ -2199,22 +1628,18 @@ var ZubariWdkService = class {
|
|
|
2199
1628
|
txHash = txHash.hash;
|
|
2200
1629
|
}
|
|
2201
1630
|
if (txHash) {
|
|
2202
|
-
const isValid = this.validateTxHash(
|
|
1631
|
+
const isValid = this.validateTxHash(chain, txHash);
|
|
2203
1632
|
if (!isValid) {
|
|
2204
|
-
console.warn(`[ZubariWdkService] Invalid ${
|
|
1633
|
+
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
2205
1634
|
}
|
|
2206
1635
|
}
|
|
2207
|
-
console.log(`[ZubariWdkService] ${chain2} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
2208
|
-
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
2209
|
-
elapsed: `${elapsed}ms`
|
|
2210
|
-
});
|
|
2211
1636
|
if (!data.success) {
|
|
2212
|
-
const errorCode2 = parseChainError(
|
|
1637
|
+
const errorCode2 = parseChainError(chain, data.error || "");
|
|
2213
1638
|
return {
|
|
2214
1639
|
success: false,
|
|
2215
1640
|
error: data.error,
|
|
2216
1641
|
errorCode: errorCode2,
|
|
2217
|
-
chain
|
|
1642
|
+
chain
|
|
2218
1643
|
};
|
|
2219
1644
|
}
|
|
2220
1645
|
return {
|
|
@@ -2223,47 +1648,35 @@ var ZubariWdkService = class {
|
|
|
2223
1648
|
from: data.from,
|
|
2224
1649
|
to: data.to,
|
|
2225
1650
|
amount: data.amount,
|
|
2226
|
-
chain: data.chain ||
|
|
1651
|
+
chain: data.chain || chain,
|
|
2227
1652
|
network: data.network || this.config.network
|
|
2228
1653
|
};
|
|
2229
1654
|
}
|
|
2230
1655
|
const errorData = await response.json().catch(() => ({}));
|
|
2231
1656
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
2232
|
-
const errorCode = parseChainError(
|
|
2233
|
-
console.error(`[ZubariWdkService] ${chain2} transaction FAILED`, {
|
|
2234
|
-
status: response.status,
|
|
2235
|
-
error: errorMessage,
|
|
2236
|
-
errorCode,
|
|
2237
|
-
elapsed: `${elapsed}ms`
|
|
2238
|
-
});
|
|
1657
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
2239
1658
|
return {
|
|
2240
1659
|
success: false,
|
|
2241
1660
|
error: errorMessage,
|
|
2242
1661
|
errorCode,
|
|
2243
|
-
chain
|
|
1662
|
+
chain
|
|
2244
1663
|
};
|
|
2245
1664
|
} catch (error) {
|
|
2246
|
-
const elapsed = Date.now() - startTime;
|
|
2247
1665
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
2248
|
-
const errorCode = parseChainError(
|
|
2249
|
-
console.error(`[ZubariWdkService] ${chain2} transaction ERROR`, {
|
|
2250
|
-
error: errorMessage,
|
|
2251
|
-
errorCode,
|
|
2252
|
-
elapsed: `${elapsed}ms`
|
|
2253
|
-
});
|
|
1666
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
2254
1667
|
return {
|
|
2255
1668
|
success: false,
|
|
2256
1669
|
error: errorMessage,
|
|
2257
1670
|
errorCode,
|
|
2258
|
-
chain
|
|
1671
|
+
chain
|
|
2259
1672
|
};
|
|
2260
1673
|
}
|
|
2261
1674
|
}
|
|
2262
1675
|
/**
|
|
2263
1676
|
* Validate transaction hash format for a specific chain
|
|
2264
1677
|
*/
|
|
2265
|
-
validateTxHash(
|
|
2266
|
-
switch (
|
|
1678
|
+
validateTxHash(chain, txHash) {
|
|
1679
|
+
switch (chain) {
|
|
2267
1680
|
case "ethereum":
|
|
2268
1681
|
return /^0x[a-fA-F0-9]{64}$/.test(txHash);
|
|
2269
1682
|
case "bitcoin":
|
|
@@ -2295,18 +1708,25 @@ var ZubariWdkService = class {
|
|
|
2295
1708
|
// ==========================================
|
|
2296
1709
|
// Private Helper Methods
|
|
2297
1710
|
// ==========================================
|
|
2298
|
-
getDerivationPath(
|
|
2299
|
-
const
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
1711
|
+
getDerivationPath(chain) {
|
|
1712
|
+
const basePath = DERIVATION_PATHS[chain];
|
|
1713
|
+
if (chain === "bitcoin" && this.config.network === "testnet") {
|
|
1714
|
+
return "m/84'/1'/0'/0/0";
|
|
1715
|
+
}
|
|
1716
|
+
switch (chain) {
|
|
1717
|
+
case "ton":
|
|
1718
|
+
return `${basePath}/0'/0'`;
|
|
1719
|
+
case "solana":
|
|
1720
|
+
return `${basePath}/0'`;
|
|
1721
|
+
case "bitcoin":
|
|
1722
|
+
case "ethereum":
|
|
1723
|
+
case "tron":
|
|
1724
|
+
case "spark":
|
|
1725
|
+
default:
|
|
1726
|
+
return `${basePath}/0`;
|
|
1727
|
+
}
|
|
2308
1728
|
}
|
|
2309
|
-
getChainSymbol(
|
|
1729
|
+
getChainSymbol(chain) {
|
|
2310
1730
|
const symbols = {
|
|
2311
1731
|
ethereum: "ETH",
|
|
2312
1732
|
bitcoin: "BTC",
|
|
@@ -2315,16 +1735,16 @@ var ZubariWdkService = class {
|
|
|
2315
1735
|
solana: "SOL",
|
|
2316
1736
|
spark: "SAT"
|
|
2317
1737
|
};
|
|
2318
|
-
return symbols[
|
|
1738
|
+
return symbols[chain];
|
|
2319
1739
|
}
|
|
2320
1740
|
/**
|
|
2321
1741
|
* Derive address using browser-compatible libraries
|
|
2322
1742
|
*/
|
|
2323
|
-
async deriveBrowserAddress(seed,
|
|
2324
|
-
const path = this.getDerivationPath(
|
|
1743
|
+
async deriveBrowserAddress(seed, chain) {
|
|
1744
|
+
const path = this.getDerivationPath(chain);
|
|
2325
1745
|
try {
|
|
2326
1746
|
let address;
|
|
2327
|
-
switch (
|
|
1747
|
+
switch (chain) {
|
|
2328
1748
|
case "ethereum":
|
|
2329
1749
|
address = deriveEthereumAddress(seed);
|
|
2330
1750
|
break;
|
|
@@ -2344,11 +1764,11 @@ var ZubariWdkService = class {
|
|
|
2344
1764
|
address = await deriveTonAddress(seed);
|
|
2345
1765
|
break;
|
|
2346
1766
|
default:
|
|
2347
|
-
throw new Error(`Unsupported chain: ${
|
|
1767
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
2348
1768
|
}
|
|
2349
|
-
return { chain
|
|
1769
|
+
return { chain, address, path };
|
|
2350
1770
|
} catch (error) {
|
|
2351
|
-
console.error(`Browser derivation failed for ${
|
|
1771
|
+
console.error(`Browser derivation failed for ${chain}:`, error);
|
|
2352
1772
|
throw error;
|
|
2353
1773
|
}
|
|
2354
1774
|
}
|
|
@@ -2361,7 +1781,7 @@ var ZubariWdkService = class {
|
|
|
2361
1781
|
};
|
|
2362
1782
|
var defaultService = null;
|
|
2363
1783
|
function getZubariWdkService(config) {
|
|
2364
|
-
if (!defaultService || config && config.network !== defaultService.getNetwork()) {
|
|
1784
|
+
if (!defaultService || config && (config.network !== defaultService.getNetwork() || config.apiUrl && config.apiUrl !== defaultService.getApiUrl())) {
|
|
2365
1785
|
defaultService = new ZubariWdkService(config);
|
|
2366
1786
|
}
|
|
2367
1787
|
return defaultService;
|
|
@@ -2406,8 +1826,8 @@ async function fetchPrices() {
|
|
|
2406
1826
|
if (response.ok) {
|
|
2407
1827
|
const data = await response.json();
|
|
2408
1828
|
const prices = {};
|
|
2409
|
-
for (const [
|
|
2410
|
-
prices[
|
|
1829
|
+
for (const [chain, geckoId] of Object.entries(COINGECKO_IDS)) {
|
|
1830
|
+
prices[chain] = data[geckoId]?.usd || 0;
|
|
2411
1831
|
}
|
|
2412
1832
|
priceCache = { prices, timestamp: Date.now() };
|
|
2413
1833
|
return prices;
|
|
@@ -2417,9 +1837,9 @@ async function fetchPrices() {
|
|
|
2417
1837
|
}
|
|
2418
1838
|
return priceCache?.prices || {};
|
|
2419
1839
|
}
|
|
2420
|
-
async function getPriceForChain(
|
|
1840
|
+
async function getPriceForChain(chain) {
|
|
2421
1841
|
const prices = await fetchPrices();
|
|
2422
|
-
return prices[
|
|
1842
|
+
return prices[chain] || 0;
|
|
2423
1843
|
}
|
|
2424
1844
|
var dynamicImport2 = new Function("specifier", "return import(specifier)");
|
|
2425
1845
|
async function loadWdkModules() {
|
|
@@ -2509,19 +1929,19 @@ var TransactionService = class {
|
|
|
2509
1929
|
/**
|
|
2510
1930
|
* Get RPC URL for a chain
|
|
2511
1931
|
*/
|
|
2512
|
-
getRpcUrl(
|
|
1932
|
+
getRpcUrl(chain) {
|
|
2513
1933
|
const networkUrls = DEFAULT_RPC_URLS[this.config.network];
|
|
2514
|
-
if (this.config.rpcUrls?.[
|
|
2515
|
-
return this.config.rpcUrls[
|
|
1934
|
+
if (this.config.rpcUrls?.[chain]) {
|
|
1935
|
+
return this.config.rpcUrls[chain];
|
|
2516
1936
|
}
|
|
2517
|
-
return networkUrls[
|
|
1937
|
+
return networkUrls[chain] || "";
|
|
2518
1938
|
}
|
|
2519
1939
|
/**
|
|
2520
1940
|
* Get explorer URL for a transaction
|
|
2521
1941
|
*/
|
|
2522
|
-
getExplorerUrl(
|
|
1942
|
+
getExplorerUrl(chain, txHash) {
|
|
2523
1943
|
const explorers = EXPLORER_URLS[this.config.network];
|
|
2524
|
-
const baseUrl = explorers[
|
|
1944
|
+
const baseUrl = explorers[chain] || "";
|
|
2525
1945
|
return `${baseUrl}${txHash}`;
|
|
2526
1946
|
}
|
|
2527
1947
|
/**
|
|
@@ -2545,27 +1965,27 @@ var TransactionService = class {
|
|
|
2545
1965
|
* Get or create wallet instance for a specific chain
|
|
2546
1966
|
*/
|
|
2547
1967
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2548
|
-
async getWallet(
|
|
1968
|
+
async getWallet(chain) {
|
|
2549
1969
|
if (!this.seed) {
|
|
2550
1970
|
throw new Error("TransactionService not initialized. Call initialize() first.");
|
|
2551
1971
|
}
|
|
2552
|
-
if (this.wallets[
|
|
2553
|
-
return this.wallets[
|
|
1972
|
+
if (this.wallets[chain]) {
|
|
1973
|
+
return this.wallets[chain];
|
|
2554
1974
|
}
|
|
2555
1975
|
const isTestnet = this.config.network === "testnet";
|
|
2556
1976
|
try {
|
|
2557
|
-
switch (
|
|
1977
|
+
switch (chain) {
|
|
2558
1978
|
case "ethereum": {
|
|
2559
1979
|
const rpcUrl = this.getRpcUrl("ethereum");
|
|
2560
1980
|
const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
|
|
2561
|
-
this.wallets[
|
|
1981
|
+
this.wallets[chain] = wallet;
|
|
2562
1982
|
return wallet;
|
|
2563
1983
|
}
|
|
2564
1984
|
case "bitcoin": {
|
|
2565
1985
|
const wallet = new WalletManagerBtc(this.seed, {
|
|
2566
1986
|
network: isTestnet ? "testnet" : "bitcoin"
|
|
2567
1987
|
});
|
|
2568
|
-
this.wallets[
|
|
1988
|
+
this.wallets[chain] = wallet;
|
|
2569
1989
|
return wallet;
|
|
2570
1990
|
}
|
|
2571
1991
|
case "solana": {
|
|
@@ -2573,7 +1993,7 @@ var TransactionService = class {
|
|
|
2573
1993
|
const wallet = new WalletManagerSolana(this.seed, {
|
|
2574
1994
|
rpcUrl
|
|
2575
1995
|
});
|
|
2576
|
-
this.wallets[
|
|
1996
|
+
this.wallets[chain] = wallet;
|
|
2577
1997
|
return wallet;
|
|
2578
1998
|
}
|
|
2579
1999
|
case "ton": {
|
|
@@ -2581,7 +2001,7 @@ var TransactionService = class {
|
|
|
2581
2001
|
const wallet = new WalletManagerTon(this.seed, {
|
|
2582
2002
|
tonClient: { url }
|
|
2583
2003
|
});
|
|
2584
|
-
this.wallets[
|
|
2004
|
+
this.wallets[chain] = wallet;
|
|
2585
2005
|
return wallet;
|
|
2586
2006
|
}
|
|
2587
2007
|
case "tron": {
|
|
@@ -2589,32 +2009,32 @@ var TransactionService = class {
|
|
|
2589
2009
|
const wallet = new WalletManagerTron(this.seed, {
|
|
2590
2010
|
provider: fullHost
|
|
2591
2011
|
});
|
|
2592
|
-
this.wallets[
|
|
2012
|
+
this.wallets[chain] = wallet;
|
|
2593
2013
|
return wallet;
|
|
2594
2014
|
}
|
|
2595
2015
|
case "spark": {
|
|
2596
2016
|
const wallet = new WalletManagerSpark(this.seed, {
|
|
2597
2017
|
network: isTestnet ? "TESTNET" : "MAINNET"
|
|
2598
2018
|
});
|
|
2599
|
-
this.wallets[
|
|
2019
|
+
this.wallets[chain] = wallet;
|
|
2600
2020
|
return wallet;
|
|
2601
2021
|
}
|
|
2602
2022
|
default:
|
|
2603
|
-
throw new Error(`Unsupported chain: ${
|
|
2023
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
2604
2024
|
}
|
|
2605
2025
|
} catch (error) {
|
|
2606
|
-
console.error(`Failed to initialize ${
|
|
2026
|
+
console.error(`Failed to initialize ${chain} wallet:`, error);
|
|
2607
2027
|
throw error;
|
|
2608
2028
|
}
|
|
2609
2029
|
}
|
|
2610
2030
|
/**
|
|
2611
2031
|
* Estimate transaction fee
|
|
2612
2032
|
*/
|
|
2613
|
-
async estimateFee(
|
|
2614
|
-
const wallet = await this.getWallet(
|
|
2033
|
+
async estimateFee(chain, params) {
|
|
2034
|
+
const wallet = await this.getWallet(chain);
|
|
2615
2035
|
try {
|
|
2616
2036
|
const feeRates = await wallet.getFeeRates();
|
|
2617
|
-
if (
|
|
2037
|
+
if (chain === "ethereum") {
|
|
2618
2038
|
return {
|
|
2619
2039
|
slow: {
|
|
2620
2040
|
fee: `${feeRates.slow || "0"} Gwei`,
|
|
@@ -2629,7 +2049,7 @@ var TransactionService = class {
|
|
|
2629
2049
|
estimatedTime: "~30 sec"
|
|
2630
2050
|
}
|
|
2631
2051
|
};
|
|
2632
|
-
} else if (
|
|
2052
|
+
} else if (chain === "bitcoin") {
|
|
2633
2053
|
return {
|
|
2634
2054
|
slow: {
|
|
2635
2055
|
fee: `${feeRates.slow || feeRates.low || "0"} sat/vB`,
|
|
@@ -2661,7 +2081,7 @@ var TransactionService = class {
|
|
|
2661
2081
|
};
|
|
2662
2082
|
}
|
|
2663
2083
|
} catch (error) {
|
|
2664
|
-
console.error(`Error estimating fee for ${
|
|
2084
|
+
console.error(`Error estimating fee for ${chain}:`, error);
|
|
2665
2085
|
return {
|
|
2666
2086
|
slow: { fee: "0", estimatedTime: "Unknown" },
|
|
2667
2087
|
medium: { fee: "0", estimatedTime: "Unknown" },
|
|
@@ -2672,8 +2092,8 @@ var TransactionService = class {
|
|
|
2672
2092
|
/**
|
|
2673
2093
|
* Send a transaction
|
|
2674
2094
|
*/
|
|
2675
|
-
async send(
|
|
2676
|
-
const wallet = await this.getWallet(
|
|
2095
|
+
async send(chain, params) {
|
|
2096
|
+
const wallet = await this.getWallet(chain);
|
|
2677
2097
|
const account = await wallet.getAccount(0);
|
|
2678
2098
|
const timestamp = Date.now();
|
|
2679
2099
|
try {
|
|
@@ -2693,17 +2113,17 @@ var TransactionService = class {
|
|
|
2693
2113
|
}
|
|
2694
2114
|
return {
|
|
2695
2115
|
hash: txHash,
|
|
2696
|
-
network:
|
|
2116
|
+
network: chain,
|
|
2697
2117
|
status: "pending",
|
|
2698
|
-
explorerUrl: this.getExplorerUrl(
|
|
2118
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
2699
2119
|
timestamp
|
|
2700
2120
|
};
|
|
2701
2121
|
} catch (error) {
|
|
2702
2122
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
2703
|
-
console.error(`Transaction failed on ${
|
|
2123
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
2704
2124
|
return {
|
|
2705
2125
|
hash: "",
|
|
2706
|
-
network:
|
|
2126
|
+
network: chain,
|
|
2707
2127
|
status: "failed",
|
|
2708
2128
|
error: errorMessage,
|
|
2709
2129
|
timestamp
|
|
@@ -2713,27 +2133,27 @@ var TransactionService = class {
|
|
|
2713
2133
|
/**
|
|
2714
2134
|
* Get transaction status
|
|
2715
2135
|
*/
|
|
2716
|
-
async getTransactionStatus(
|
|
2717
|
-
const wallet = await this.getWallet(
|
|
2136
|
+
async getTransactionStatus(chain, txHash) {
|
|
2137
|
+
const wallet = await this.getWallet(chain);
|
|
2718
2138
|
try {
|
|
2719
2139
|
const tx = await wallet.getTransaction(txHash);
|
|
2720
2140
|
return {
|
|
2721
2141
|
hash: txHash,
|
|
2722
|
-
network:
|
|
2142
|
+
network: chain,
|
|
2723
2143
|
status: tx.confirmed ? "confirmed" : "pending",
|
|
2724
2144
|
blockNumber: tx.blockNumber,
|
|
2725
2145
|
gasUsed: tx.gasUsed?.toString(),
|
|
2726
2146
|
fee: tx.fee?.toString(),
|
|
2727
|
-
explorerUrl: this.getExplorerUrl(
|
|
2147
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
2728
2148
|
timestamp: tx.timestamp || Date.now()
|
|
2729
2149
|
};
|
|
2730
2150
|
} catch (error) {
|
|
2731
2151
|
console.error(`Error getting transaction status for ${txHash}:`, error);
|
|
2732
2152
|
return {
|
|
2733
2153
|
hash: txHash,
|
|
2734
|
-
network:
|
|
2154
|
+
network: chain,
|
|
2735
2155
|
status: "pending",
|
|
2736
|
-
explorerUrl: this.getExplorerUrl(
|
|
2156
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
2737
2157
|
timestamp: Date.now()
|
|
2738
2158
|
};
|
|
2739
2159
|
}
|
|
@@ -2741,14 +2161,14 @@ var TransactionService = class {
|
|
|
2741
2161
|
/**
|
|
2742
2162
|
* Get transaction history for an address
|
|
2743
2163
|
*/
|
|
2744
|
-
async getTransactionHistory(
|
|
2745
|
-
const wallet = await this.getWallet(
|
|
2164
|
+
async getTransactionHistory(chain, limit = 10) {
|
|
2165
|
+
const wallet = await this.getWallet(chain);
|
|
2746
2166
|
const account = await wallet.getAccount(0);
|
|
2747
2167
|
try {
|
|
2748
2168
|
const history = await account.getTransactions({ limit });
|
|
2749
2169
|
return history.map((tx) => ({
|
|
2750
2170
|
hash: tx.hash || tx.txHash,
|
|
2751
|
-
network:
|
|
2171
|
+
network: chain,
|
|
2752
2172
|
type: tx.type || (tx.from === account.address ? "send" : "receive"),
|
|
2753
2173
|
from: tx.from,
|
|
2754
2174
|
to: tx.to,
|
|
@@ -2760,20 +2180,20 @@ var TransactionService = class {
|
|
|
2760
2180
|
blockNumber: tx.blockNumber
|
|
2761
2181
|
}));
|
|
2762
2182
|
} catch (error) {
|
|
2763
|
-
console.error(`Error getting transaction history for ${
|
|
2183
|
+
console.error(`Error getting transaction history for ${chain}:`, error);
|
|
2764
2184
|
return [];
|
|
2765
2185
|
}
|
|
2766
2186
|
}
|
|
2767
2187
|
/**
|
|
2768
2188
|
* Get balance for a specific chain
|
|
2769
2189
|
*/
|
|
2770
|
-
async getBalance(
|
|
2771
|
-
const wallet = await this.getWallet(
|
|
2190
|
+
async getBalance(chain) {
|
|
2191
|
+
const wallet = await this.getWallet(chain);
|
|
2772
2192
|
const account = await wallet.getAccount(0);
|
|
2773
2193
|
try {
|
|
2774
2194
|
const balance = await account.getBalance();
|
|
2775
2195
|
const balanceStr = balance.toString();
|
|
2776
|
-
const priceUsd = await getPriceForChain(
|
|
2196
|
+
const priceUsd = await getPriceForChain(chain);
|
|
2777
2197
|
const balanceNum = parseFloat(balanceStr) || 0;
|
|
2778
2198
|
const balanceUsd = balanceNum * priceUsd;
|
|
2779
2199
|
return {
|
|
@@ -2781,7 +2201,7 @@ var TransactionService = class {
|
|
|
2781
2201
|
balanceUsd
|
|
2782
2202
|
};
|
|
2783
2203
|
} catch (error) {
|
|
2784
|
-
console.error(`Error getting balance for ${
|
|
2204
|
+
console.error(`Error getting balance for ${chain}:`, error);
|
|
2785
2205
|
return { balance: "0", balanceUsd: 0 };
|
|
2786
2206
|
}
|
|
2787
2207
|
}
|
|
@@ -2817,14 +2237,6 @@ function getTransactionService(config) {
|
|
|
2817
2237
|
function createTransactionService(config) {
|
|
2818
2238
|
return new TransactionService(config);
|
|
2819
2239
|
}
|
|
2820
|
-
/*! Bundled license information:
|
|
2821
|
-
|
|
2822
|
-
@scure/base/index.js:
|
|
2823
|
-
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2824
|
-
|
|
2825
|
-
@scure/bip32/index.js:
|
|
2826
|
-
(*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
2827
|
-
*/
|
|
2828
2240
|
|
|
2829
2241
|
exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
|
|
2830
2242
|
exports.SwapService = SwapService;
|