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