@zubari/sdk 0.5.2 → 0.5.3
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/index.js +227 -797
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -795
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.js +175 -745
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +173 -743
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.js +113 -707
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +111 -705
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.js +176 -746
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +174 -744
- 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
|
|
|
@@ -268,14 +265,14 @@ var WdkApiClient = class {
|
|
|
268
265
|
/**
|
|
269
266
|
* Derive address for a specific chain using Tether WDK
|
|
270
267
|
*/
|
|
271
|
-
async deriveAddress(seed,
|
|
268
|
+
async deriveAddress(seed, chain, network = "mainnet") {
|
|
272
269
|
try {
|
|
273
270
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
274
271
|
method: "POST",
|
|
275
272
|
headers: {
|
|
276
273
|
"Content-Type": "application/json"
|
|
277
274
|
},
|
|
278
|
-
body: JSON.stringify({ seed, chain
|
|
275
|
+
body: JSON.stringify({ seed, chain, network })
|
|
279
276
|
});
|
|
280
277
|
return await response.json();
|
|
281
278
|
} catch (error) {
|
|
@@ -308,14 +305,14 @@ var WdkApiClient = class {
|
|
|
308
305
|
/**
|
|
309
306
|
* Send a transaction on a specific chain using Tether WDK
|
|
310
307
|
*/
|
|
311
|
-
async sendTransaction(seed,
|
|
308
|
+
async sendTransaction(seed, chain, to, amount, network = "mainnet") {
|
|
312
309
|
try {
|
|
313
310
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
314
311
|
method: "POST",
|
|
315
312
|
headers: {
|
|
316
313
|
"Content-Type": "application/json"
|
|
317
314
|
},
|
|
318
|
-
body: JSON.stringify({ seed, chain
|
|
315
|
+
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
319
316
|
});
|
|
320
317
|
return await response.json();
|
|
321
318
|
} catch (error) {
|
|
@@ -329,14 +326,14 @@ var WdkApiClient = class {
|
|
|
329
326
|
* Get transaction history for an address on a specific chain
|
|
330
327
|
* Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
|
|
331
328
|
*/
|
|
332
|
-
async getTransactionHistory(seed,
|
|
329
|
+
async getTransactionHistory(seed, chain, network = "mainnet", limit = 10) {
|
|
333
330
|
try {
|
|
334
331
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
335
332
|
method: "POST",
|
|
336
333
|
headers: {
|
|
337
334
|
"Content-Type": "application/json"
|
|
338
335
|
},
|
|
339
|
-
body: JSON.stringify({ seed, chain
|
|
336
|
+
body: JSON.stringify({ seed, chain, network, limit })
|
|
340
337
|
});
|
|
341
338
|
return await response.json();
|
|
342
339
|
} catch (error) {
|
|
@@ -350,14 +347,14 @@ var WdkApiClient = class {
|
|
|
350
347
|
* Get transaction status by hash
|
|
351
348
|
* Fetches from blockchain explorers to check confirmation status
|
|
352
349
|
*/
|
|
353
|
-
async getTransactionStatus(txHash,
|
|
350
|
+
async getTransactionStatus(txHash, chain, network = "mainnet") {
|
|
354
351
|
try {
|
|
355
352
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
356
353
|
method: "POST",
|
|
357
354
|
headers: {
|
|
358
355
|
"Content-Type": "application/json"
|
|
359
356
|
},
|
|
360
|
-
body: JSON.stringify({ txHash, chain
|
|
357
|
+
body: JSON.stringify({ txHash, chain, network })
|
|
361
358
|
});
|
|
362
359
|
return await response.json();
|
|
363
360
|
} catch (error) {
|
|
@@ -1077,589 +1074,6 @@ __export(BrowserAddressDerivation_exports, {
|
|
|
1077
1074
|
generateSeedPhrase: () => generateSeedPhrase,
|
|
1078
1075
|
isValidSeed: () => isValidSeed
|
|
1079
1076
|
});
|
|
1080
|
-
|
|
1081
|
-
// node_modules/@scure/base/index.js
|
|
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
|
-
};
|
|
1663
1077
|
var DERIVATION_PATHS = {
|
|
1664
1078
|
ethereum: "m/44'/60'/0'/0/0",
|
|
1665
1079
|
bitcoin_mainnet: "m/84'/0'/0'/0/0",
|
|
@@ -1676,7 +1090,7 @@ function deriveEthereumAddress(seed) {
|
|
|
1676
1090
|
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
1677
1091
|
try {
|
|
1678
1092
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1679
|
-
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
1093
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
1680
1094
|
const path = network === "testnet" ? DERIVATION_PATHS.bitcoin_testnet : DERIVATION_PATHS.bitcoin_mainnet;
|
|
1681
1095
|
const child = hdKey.derive(path);
|
|
1682
1096
|
if (!child.publicKey) {
|
|
@@ -1684,10 +1098,10 @@ function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
|
1684
1098
|
}
|
|
1685
1099
|
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
1686
1100
|
const witnessVersion = 0;
|
|
1687
|
-
const words = bech32.toWords(pubKeyHash);
|
|
1101
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
1688
1102
|
words.unshift(witnessVersion);
|
|
1689
1103
|
const hrp = network === "testnet" ? "tb" : "bc";
|
|
1690
|
-
const address = bech32.encode(hrp, words);
|
|
1104
|
+
const address = base.bech32.encode(hrp, words);
|
|
1691
1105
|
return address;
|
|
1692
1106
|
} catch (error) {
|
|
1693
1107
|
console.error("Bitcoin address derivation failed:", error);
|
|
@@ -1760,7 +1174,7 @@ function deriveTronAddress(seed) {
|
|
|
1760
1174
|
for (let i = 0; i < 20; i++) {
|
|
1761
1175
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
1762
1176
|
}
|
|
1763
|
-
const tronBase58check = base58check(sha256.sha256);
|
|
1177
|
+
const tronBase58check = base.base58check(sha256.sha256);
|
|
1764
1178
|
return tronBase58check.encode(addressBytes);
|
|
1765
1179
|
} catch (error) {
|
|
1766
1180
|
console.error("TRON address derivation failed:", error);
|
|
@@ -1770,17 +1184,17 @@ function deriveTronAddress(seed) {
|
|
|
1770
1184
|
function deriveSparkAddress(seed, network = "mainnet") {
|
|
1771
1185
|
try {
|
|
1772
1186
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1773
|
-
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
1187
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
1774
1188
|
const child = hdKey.derive(DERIVATION_PATHS.spark);
|
|
1775
1189
|
if (!child.publicKey) {
|
|
1776
1190
|
throw new Error("Failed to derive public key");
|
|
1777
1191
|
}
|
|
1778
1192
|
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
1779
1193
|
const witnessVersion = 0;
|
|
1780
|
-
const words = bech32.toWords(pubKeyHash);
|
|
1194
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
1781
1195
|
words.unshift(witnessVersion);
|
|
1782
1196
|
const hrp = network === "testnet" ? "tsp" : "sp";
|
|
1783
|
-
const address = bech32.encode(hrp, words);
|
|
1197
|
+
const address = base.bech32.encode(hrp, words);
|
|
1784
1198
|
return address;
|
|
1785
1199
|
} catch (error) {
|
|
1786
1200
|
console.error("Spark address derivation failed:", error);
|
|
@@ -1876,9 +1290,9 @@ var CHAIN_ERROR_MESSAGES = {
|
|
|
1876
1290
|
"no route": "NETWORK_ERROR"
|
|
1877
1291
|
}
|
|
1878
1292
|
};
|
|
1879
|
-
function parseChainError(
|
|
1293
|
+
function parseChainError(chain, errorMessage) {
|
|
1880
1294
|
const errorLower = errorMessage.toLowerCase();
|
|
1881
|
-
const chainErrors = CHAIN_ERROR_MESSAGES[
|
|
1295
|
+
const chainErrors = CHAIN_ERROR_MESSAGES[chain];
|
|
1882
1296
|
for (const [pattern, code] of Object.entries(chainErrors)) {
|
|
1883
1297
|
if (errorLower.includes(pattern)) {
|
|
1884
1298
|
return code;
|
|
@@ -2016,38 +1430,38 @@ var ZubariWdkService = class {
|
|
|
2016
1430
|
* For Ethereum, falls back to local derivation if API fails.
|
|
2017
1431
|
* For other chains, WDK API is required - no placeholder fallback.
|
|
2018
1432
|
*/
|
|
2019
|
-
async deriveAddress(seed,
|
|
1433
|
+
async deriveAddress(seed, chain) {
|
|
2020
1434
|
await this.initialize();
|
|
2021
|
-
const path = this.getDerivationPath(
|
|
1435
|
+
const path = this.getDerivationPath(chain);
|
|
2022
1436
|
try {
|
|
2023
|
-
const response = await this.apiClient.deriveAddress(seed,
|
|
1437
|
+
const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
|
|
2024
1438
|
if (response.success && response.address) {
|
|
2025
1439
|
return {
|
|
2026
|
-
chain
|
|
1440
|
+
chain,
|
|
2027
1441
|
address: response.address,
|
|
2028
1442
|
path: response.path || path
|
|
2029
1443
|
};
|
|
2030
1444
|
}
|
|
2031
1445
|
} catch (error) {
|
|
2032
|
-
console.warn(`API address derivation failed for ${
|
|
2033
|
-
if (
|
|
2034
|
-
return this.deriveBrowserAddress(seed,
|
|
1446
|
+
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
1447
|
+
if (chain === "ethereum") {
|
|
1448
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
2035
1449
|
}
|
|
2036
1450
|
}
|
|
2037
1451
|
if (this.useNativeWdk && this.nativeWdkService) {
|
|
2038
1452
|
try {
|
|
2039
1453
|
const wdk = this.nativeWdkService;
|
|
2040
1454
|
await wdk.initialize(seed);
|
|
2041
|
-
return await wdk.deriveAddress(
|
|
1455
|
+
return await wdk.deriveAddress(chain);
|
|
2042
1456
|
} catch (error) {
|
|
2043
|
-
console.warn(`Native WDK address derivation failed for ${
|
|
1457
|
+
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
2044
1458
|
}
|
|
2045
1459
|
}
|
|
2046
|
-
if (
|
|
2047
|
-
return this.deriveBrowserAddress(seed,
|
|
1460
|
+
if (chain === "ethereum") {
|
|
1461
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
2048
1462
|
}
|
|
2049
1463
|
throw new Error(
|
|
2050
|
-
`WDK API required for ${
|
|
1464
|
+
`WDK API required for ${chain} address derivation. Ensure the backend is running.`
|
|
2051
1465
|
);
|
|
2052
1466
|
}
|
|
2053
1467
|
/**
|
|
@@ -2127,13 +1541,13 @@ var ZubariWdkService = class {
|
|
|
2127
1541
|
/**
|
|
2128
1542
|
* Get fee rates for a chain
|
|
2129
1543
|
*/
|
|
2130
|
-
async getFeeRates(seed,
|
|
1544
|
+
async getFeeRates(seed, chain) {
|
|
2131
1545
|
await this.initialize();
|
|
2132
1546
|
try {
|
|
2133
1547
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
|
|
2134
1548
|
method: "POST",
|
|
2135
1549
|
headers: { "Content-Type": "application/json" },
|
|
2136
|
-
body: JSON.stringify({ seed, chain
|
|
1550
|
+
body: JSON.stringify({ seed, chain, network: this.config.network })
|
|
2137
1551
|
});
|
|
2138
1552
|
if (response.ok) {
|
|
2139
1553
|
const data = await response.json();
|
|
@@ -2142,20 +1556,20 @@ var ZubariWdkService = class {
|
|
|
2142
1556
|
}
|
|
2143
1557
|
}
|
|
2144
1558
|
} catch (error) {
|
|
2145
|
-
console.warn(`Failed to fetch fee rates for ${
|
|
1559
|
+
console.warn(`Failed to fetch fee rates for ${chain}:`, error);
|
|
2146
1560
|
}
|
|
2147
1561
|
return { slow: "0", normal: "0", fast: "0" };
|
|
2148
1562
|
}
|
|
2149
1563
|
/**
|
|
2150
1564
|
* Estimate transaction fee
|
|
2151
1565
|
*/
|
|
2152
|
-
async estimateFee(seed,
|
|
1566
|
+
async estimateFee(seed, chain, to, amount) {
|
|
2153
1567
|
await this.initialize();
|
|
2154
1568
|
try {
|
|
2155
1569
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
2156
1570
|
method: "POST",
|
|
2157
1571
|
headers: { "Content-Type": "application/json" },
|
|
2158
|
-
body: JSON.stringify({ seed, chain
|
|
1572
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
2159
1573
|
});
|
|
2160
1574
|
if (response.ok) {
|
|
2161
1575
|
const data = await response.json();
|
|
@@ -2164,9 +1578,9 @@ var ZubariWdkService = class {
|
|
|
2164
1578
|
}
|
|
2165
1579
|
}
|
|
2166
1580
|
} catch (error) {
|
|
2167
|
-
console.warn(`Failed to estimate fee for ${
|
|
1581
|
+
console.warn(`Failed to estimate fee for ${chain}:`, error);
|
|
2168
1582
|
}
|
|
2169
|
-
return { fee: "0", symbol: this.getChainSymbol(
|
|
1583
|
+
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
2170
1584
|
}
|
|
2171
1585
|
/**
|
|
2172
1586
|
* Send a transaction on any supported chain
|
|
@@ -2177,10 +1591,10 @@ var ZubariWdkService = class {
|
|
|
2177
1591
|
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
2178
1592
|
* @returns Transaction result with hash on success, or error details on failure
|
|
2179
1593
|
*/
|
|
2180
|
-
async sendTransaction(seed,
|
|
1594
|
+
async sendTransaction(seed, chain, to, amount) {
|
|
2181
1595
|
await this.initialize();
|
|
2182
1596
|
const startTime = Date.now();
|
|
2183
|
-
console.log(`[ZubariWdkService] Sending ${
|
|
1597
|
+
console.log(`[ZubariWdkService] Sending ${chain} transaction`, {
|
|
2184
1598
|
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
2185
1599
|
amount,
|
|
2186
1600
|
network: this.config.network
|
|
@@ -2189,7 +1603,7 @@ var ZubariWdkService = class {
|
|
|
2189
1603
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
2190
1604
|
method: "POST",
|
|
2191
1605
|
headers: { "Content-Type": "application/json" },
|
|
2192
|
-
body: JSON.stringify({ seed, chain
|
|
1606
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
2193
1607
|
});
|
|
2194
1608
|
const elapsed = Date.now() - startTime;
|
|
2195
1609
|
if (response.ok) {
|
|
@@ -2199,22 +1613,22 @@ var ZubariWdkService = class {
|
|
|
2199
1613
|
txHash = txHash.hash;
|
|
2200
1614
|
}
|
|
2201
1615
|
if (txHash) {
|
|
2202
|
-
const isValid = this.validateTxHash(
|
|
1616
|
+
const isValid = this.validateTxHash(chain, txHash);
|
|
2203
1617
|
if (!isValid) {
|
|
2204
|
-
console.warn(`[ZubariWdkService] Invalid ${
|
|
1618
|
+
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
2205
1619
|
}
|
|
2206
1620
|
}
|
|
2207
|
-
console.log(`[ZubariWdkService] ${
|
|
1621
|
+
console.log(`[ZubariWdkService] ${chain} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
2208
1622
|
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
2209
1623
|
elapsed: `${elapsed}ms`
|
|
2210
1624
|
});
|
|
2211
1625
|
if (!data.success) {
|
|
2212
|
-
const errorCode2 = parseChainError(
|
|
1626
|
+
const errorCode2 = parseChainError(chain, data.error || "");
|
|
2213
1627
|
return {
|
|
2214
1628
|
success: false,
|
|
2215
1629
|
error: data.error,
|
|
2216
1630
|
errorCode: errorCode2,
|
|
2217
|
-
chain
|
|
1631
|
+
chain
|
|
2218
1632
|
};
|
|
2219
1633
|
}
|
|
2220
1634
|
return {
|
|
@@ -2223,14 +1637,14 @@ var ZubariWdkService = class {
|
|
|
2223
1637
|
from: data.from,
|
|
2224
1638
|
to: data.to,
|
|
2225
1639
|
amount: data.amount,
|
|
2226
|
-
chain: data.chain ||
|
|
1640
|
+
chain: data.chain || chain,
|
|
2227
1641
|
network: data.network || this.config.network
|
|
2228
1642
|
};
|
|
2229
1643
|
}
|
|
2230
1644
|
const errorData = await response.json().catch(() => ({}));
|
|
2231
1645
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
2232
|
-
const errorCode = parseChainError(
|
|
2233
|
-
console.error(`[ZubariWdkService] ${
|
|
1646
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1647
|
+
console.error(`[ZubariWdkService] ${chain} transaction FAILED`, {
|
|
2234
1648
|
status: response.status,
|
|
2235
1649
|
error: errorMessage,
|
|
2236
1650
|
errorCode,
|
|
@@ -2240,13 +1654,13 @@ var ZubariWdkService = class {
|
|
|
2240
1654
|
success: false,
|
|
2241
1655
|
error: errorMessage,
|
|
2242
1656
|
errorCode,
|
|
2243
|
-
chain
|
|
1657
|
+
chain
|
|
2244
1658
|
};
|
|
2245
1659
|
} catch (error) {
|
|
2246
1660
|
const elapsed = Date.now() - startTime;
|
|
2247
1661
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
2248
|
-
const errorCode = parseChainError(
|
|
2249
|
-
console.error(`[ZubariWdkService] ${
|
|
1662
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1663
|
+
console.error(`[ZubariWdkService] ${chain} transaction ERROR`, {
|
|
2250
1664
|
error: errorMessage,
|
|
2251
1665
|
errorCode,
|
|
2252
1666
|
elapsed: `${elapsed}ms`
|
|
@@ -2255,15 +1669,15 @@ var ZubariWdkService = class {
|
|
|
2255
1669
|
success: false,
|
|
2256
1670
|
error: errorMessage,
|
|
2257
1671
|
errorCode,
|
|
2258
|
-
chain
|
|
1672
|
+
chain
|
|
2259
1673
|
};
|
|
2260
1674
|
}
|
|
2261
1675
|
}
|
|
2262
1676
|
/**
|
|
2263
1677
|
* Validate transaction hash format for a specific chain
|
|
2264
1678
|
*/
|
|
2265
|
-
validateTxHash(
|
|
2266
|
-
switch (
|
|
1679
|
+
validateTxHash(chain, txHash) {
|
|
1680
|
+
switch (chain) {
|
|
2267
1681
|
case "ethereum":
|
|
2268
1682
|
return /^0x[a-fA-F0-9]{64}$/.test(txHash);
|
|
2269
1683
|
case "bitcoin":
|
|
@@ -2295,7 +1709,7 @@ var ZubariWdkService = class {
|
|
|
2295
1709
|
// ==========================================
|
|
2296
1710
|
// Private Helper Methods
|
|
2297
1711
|
// ==========================================
|
|
2298
|
-
getDerivationPath(
|
|
1712
|
+
getDerivationPath(chain) {
|
|
2299
1713
|
const paths = {
|
|
2300
1714
|
bitcoin: this.config.network === "testnet" ? "m/84'/1'/0'/0/0" : "m/84'/0'/0'/0/0",
|
|
2301
1715
|
ethereum: "m/44'/60'/0'/0/0",
|
|
@@ -2304,9 +1718,9 @@ var ZubariWdkService = class {
|
|
|
2304
1718
|
solana: "m/44'/501'/0'/0'",
|
|
2305
1719
|
spark: "m/44'/998'/0'/0/0"
|
|
2306
1720
|
};
|
|
2307
|
-
return paths[
|
|
1721
|
+
return paths[chain];
|
|
2308
1722
|
}
|
|
2309
|
-
getChainSymbol(
|
|
1723
|
+
getChainSymbol(chain) {
|
|
2310
1724
|
const symbols = {
|
|
2311
1725
|
ethereum: "ETH",
|
|
2312
1726
|
bitcoin: "BTC",
|
|
@@ -2315,16 +1729,16 @@ var ZubariWdkService = class {
|
|
|
2315
1729
|
solana: "SOL",
|
|
2316
1730
|
spark: "SAT"
|
|
2317
1731
|
};
|
|
2318
|
-
return symbols[
|
|
1732
|
+
return symbols[chain];
|
|
2319
1733
|
}
|
|
2320
1734
|
/**
|
|
2321
1735
|
* Derive address using browser-compatible libraries
|
|
2322
1736
|
*/
|
|
2323
|
-
async deriveBrowserAddress(seed,
|
|
2324
|
-
const path = this.getDerivationPath(
|
|
1737
|
+
async deriveBrowserAddress(seed, chain) {
|
|
1738
|
+
const path = this.getDerivationPath(chain);
|
|
2325
1739
|
try {
|
|
2326
1740
|
let address;
|
|
2327
|
-
switch (
|
|
1741
|
+
switch (chain) {
|
|
2328
1742
|
case "ethereum":
|
|
2329
1743
|
address = deriveEthereumAddress(seed);
|
|
2330
1744
|
break;
|
|
@@ -2344,11 +1758,11 @@ var ZubariWdkService = class {
|
|
|
2344
1758
|
address = await deriveTonAddress(seed);
|
|
2345
1759
|
break;
|
|
2346
1760
|
default:
|
|
2347
|
-
throw new Error(`Unsupported chain: ${
|
|
1761
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
2348
1762
|
}
|
|
2349
|
-
return { chain
|
|
1763
|
+
return { chain, address, path };
|
|
2350
1764
|
} catch (error) {
|
|
2351
|
-
console.error(`Browser derivation failed for ${
|
|
1765
|
+
console.error(`Browser derivation failed for ${chain}:`, error);
|
|
2352
1766
|
throw error;
|
|
2353
1767
|
}
|
|
2354
1768
|
}
|
|
@@ -2361,7 +1775,7 @@ var ZubariWdkService = class {
|
|
|
2361
1775
|
};
|
|
2362
1776
|
var defaultService = null;
|
|
2363
1777
|
function getZubariWdkService(config) {
|
|
2364
|
-
if (!defaultService || config && config.network !== defaultService.getNetwork()) {
|
|
1778
|
+
if (!defaultService || config && (config.network !== defaultService.getNetwork() || config.apiUrl && config.apiUrl !== defaultService.getApiUrl())) {
|
|
2365
1779
|
defaultService = new ZubariWdkService(config);
|
|
2366
1780
|
}
|
|
2367
1781
|
return defaultService;
|
|
@@ -2406,8 +1820,8 @@ async function fetchPrices() {
|
|
|
2406
1820
|
if (response.ok) {
|
|
2407
1821
|
const data = await response.json();
|
|
2408
1822
|
const prices = {};
|
|
2409
|
-
for (const [
|
|
2410
|
-
prices[
|
|
1823
|
+
for (const [chain, geckoId] of Object.entries(COINGECKO_IDS)) {
|
|
1824
|
+
prices[chain] = data[geckoId]?.usd || 0;
|
|
2411
1825
|
}
|
|
2412
1826
|
priceCache = { prices, timestamp: Date.now() };
|
|
2413
1827
|
return prices;
|
|
@@ -2417,9 +1831,9 @@ async function fetchPrices() {
|
|
|
2417
1831
|
}
|
|
2418
1832
|
return priceCache?.prices || {};
|
|
2419
1833
|
}
|
|
2420
|
-
async function getPriceForChain(
|
|
1834
|
+
async function getPriceForChain(chain) {
|
|
2421
1835
|
const prices = await fetchPrices();
|
|
2422
|
-
return prices[
|
|
1836
|
+
return prices[chain] || 0;
|
|
2423
1837
|
}
|
|
2424
1838
|
var dynamicImport2 = new Function("specifier", "return import(specifier)");
|
|
2425
1839
|
async function loadWdkModules() {
|
|
@@ -2509,19 +1923,19 @@ var TransactionService = class {
|
|
|
2509
1923
|
/**
|
|
2510
1924
|
* Get RPC URL for a chain
|
|
2511
1925
|
*/
|
|
2512
|
-
getRpcUrl(
|
|
1926
|
+
getRpcUrl(chain) {
|
|
2513
1927
|
const networkUrls = DEFAULT_RPC_URLS[this.config.network];
|
|
2514
|
-
if (this.config.rpcUrls?.[
|
|
2515
|
-
return this.config.rpcUrls[
|
|
1928
|
+
if (this.config.rpcUrls?.[chain]) {
|
|
1929
|
+
return this.config.rpcUrls[chain];
|
|
2516
1930
|
}
|
|
2517
|
-
return networkUrls[
|
|
1931
|
+
return networkUrls[chain] || "";
|
|
2518
1932
|
}
|
|
2519
1933
|
/**
|
|
2520
1934
|
* Get explorer URL for a transaction
|
|
2521
1935
|
*/
|
|
2522
|
-
getExplorerUrl(
|
|
1936
|
+
getExplorerUrl(chain, txHash) {
|
|
2523
1937
|
const explorers = EXPLORER_URLS[this.config.network];
|
|
2524
|
-
const baseUrl = explorers[
|
|
1938
|
+
const baseUrl = explorers[chain] || "";
|
|
2525
1939
|
return `${baseUrl}${txHash}`;
|
|
2526
1940
|
}
|
|
2527
1941
|
/**
|
|
@@ -2545,27 +1959,27 @@ var TransactionService = class {
|
|
|
2545
1959
|
* Get or create wallet instance for a specific chain
|
|
2546
1960
|
*/
|
|
2547
1961
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2548
|
-
async getWallet(
|
|
1962
|
+
async getWallet(chain) {
|
|
2549
1963
|
if (!this.seed) {
|
|
2550
1964
|
throw new Error("TransactionService not initialized. Call initialize() first.");
|
|
2551
1965
|
}
|
|
2552
|
-
if (this.wallets[
|
|
2553
|
-
return this.wallets[
|
|
1966
|
+
if (this.wallets[chain]) {
|
|
1967
|
+
return this.wallets[chain];
|
|
2554
1968
|
}
|
|
2555
1969
|
const isTestnet = this.config.network === "testnet";
|
|
2556
1970
|
try {
|
|
2557
|
-
switch (
|
|
1971
|
+
switch (chain) {
|
|
2558
1972
|
case "ethereum": {
|
|
2559
1973
|
const rpcUrl = this.getRpcUrl("ethereum");
|
|
2560
1974
|
const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
|
|
2561
|
-
this.wallets[
|
|
1975
|
+
this.wallets[chain] = wallet;
|
|
2562
1976
|
return wallet;
|
|
2563
1977
|
}
|
|
2564
1978
|
case "bitcoin": {
|
|
2565
1979
|
const wallet = new WalletManagerBtc(this.seed, {
|
|
2566
1980
|
network: isTestnet ? "testnet" : "bitcoin"
|
|
2567
1981
|
});
|
|
2568
|
-
this.wallets[
|
|
1982
|
+
this.wallets[chain] = wallet;
|
|
2569
1983
|
return wallet;
|
|
2570
1984
|
}
|
|
2571
1985
|
case "solana": {
|
|
@@ -2573,7 +1987,7 @@ var TransactionService = class {
|
|
|
2573
1987
|
const wallet = new WalletManagerSolana(this.seed, {
|
|
2574
1988
|
rpcUrl
|
|
2575
1989
|
});
|
|
2576
|
-
this.wallets[
|
|
1990
|
+
this.wallets[chain] = wallet;
|
|
2577
1991
|
return wallet;
|
|
2578
1992
|
}
|
|
2579
1993
|
case "ton": {
|
|
@@ -2581,7 +1995,7 @@ var TransactionService = class {
|
|
|
2581
1995
|
const wallet = new WalletManagerTon(this.seed, {
|
|
2582
1996
|
tonClient: { url }
|
|
2583
1997
|
});
|
|
2584
|
-
this.wallets[
|
|
1998
|
+
this.wallets[chain] = wallet;
|
|
2585
1999
|
return wallet;
|
|
2586
2000
|
}
|
|
2587
2001
|
case "tron": {
|
|
@@ -2589,32 +2003,32 @@ var TransactionService = class {
|
|
|
2589
2003
|
const wallet = new WalletManagerTron(this.seed, {
|
|
2590
2004
|
provider: fullHost
|
|
2591
2005
|
});
|
|
2592
|
-
this.wallets[
|
|
2006
|
+
this.wallets[chain] = wallet;
|
|
2593
2007
|
return wallet;
|
|
2594
2008
|
}
|
|
2595
2009
|
case "spark": {
|
|
2596
2010
|
const wallet = new WalletManagerSpark(this.seed, {
|
|
2597
2011
|
network: isTestnet ? "TESTNET" : "MAINNET"
|
|
2598
2012
|
});
|
|
2599
|
-
this.wallets[
|
|
2013
|
+
this.wallets[chain] = wallet;
|
|
2600
2014
|
return wallet;
|
|
2601
2015
|
}
|
|
2602
2016
|
default:
|
|
2603
|
-
throw new Error(`Unsupported chain: ${
|
|
2017
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
2604
2018
|
}
|
|
2605
2019
|
} catch (error) {
|
|
2606
|
-
console.error(`Failed to initialize ${
|
|
2020
|
+
console.error(`Failed to initialize ${chain} wallet:`, error);
|
|
2607
2021
|
throw error;
|
|
2608
2022
|
}
|
|
2609
2023
|
}
|
|
2610
2024
|
/**
|
|
2611
2025
|
* Estimate transaction fee
|
|
2612
2026
|
*/
|
|
2613
|
-
async estimateFee(
|
|
2614
|
-
const wallet = await this.getWallet(
|
|
2027
|
+
async estimateFee(chain, params) {
|
|
2028
|
+
const wallet = await this.getWallet(chain);
|
|
2615
2029
|
try {
|
|
2616
2030
|
const feeRates = await wallet.getFeeRates();
|
|
2617
|
-
if (
|
|
2031
|
+
if (chain === "ethereum") {
|
|
2618
2032
|
return {
|
|
2619
2033
|
slow: {
|
|
2620
2034
|
fee: `${feeRates.slow || "0"} Gwei`,
|
|
@@ -2629,7 +2043,7 @@ var TransactionService = class {
|
|
|
2629
2043
|
estimatedTime: "~30 sec"
|
|
2630
2044
|
}
|
|
2631
2045
|
};
|
|
2632
|
-
} else if (
|
|
2046
|
+
} else if (chain === "bitcoin") {
|
|
2633
2047
|
return {
|
|
2634
2048
|
slow: {
|
|
2635
2049
|
fee: `${feeRates.slow || feeRates.low || "0"} sat/vB`,
|
|
@@ -2661,7 +2075,7 @@ var TransactionService = class {
|
|
|
2661
2075
|
};
|
|
2662
2076
|
}
|
|
2663
2077
|
} catch (error) {
|
|
2664
|
-
console.error(`Error estimating fee for ${
|
|
2078
|
+
console.error(`Error estimating fee for ${chain}:`, error);
|
|
2665
2079
|
return {
|
|
2666
2080
|
slow: { fee: "0", estimatedTime: "Unknown" },
|
|
2667
2081
|
medium: { fee: "0", estimatedTime: "Unknown" },
|
|
@@ -2672,8 +2086,8 @@ var TransactionService = class {
|
|
|
2672
2086
|
/**
|
|
2673
2087
|
* Send a transaction
|
|
2674
2088
|
*/
|
|
2675
|
-
async send(
|
|
2676
|
-
const wallet = await this.getWallet(
|
|
2089
|
+
async send(chain, params) {
|
|
2090
|
+
const wallet = await this.getWallet(chain);
|
|
2677
2091
|
const account = await wallet.getAccount(0);
|
|
2678
2092
|
const timestamp = Date.now();
|
|
2679
2093
|
try {
|
|
@@ -2693,17 +2107,17 @@ var TransactionService = class {
|
|
|
2693
2107
|
}
|
|
2694
2108
|
return {
|
|
2695
2109
|
hash: txHash,
|
|
2696
|
-
network:
|
|
2110
|
+
network: chain,
|
|
2697
2111
|
status: "pending",
|
|
2698
|
-
explorerUrl: this.getExplorerUrl(
|
|
2112
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
2699
2113
|
timestamp
|
|
2700
2114
|
};
|
|
2701
2115
|
} catch (error) {
|
|
2702
2116
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
2703
|
-
console.error(`Transaction failed on ${
|
|
2117
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
2704
2118
|
return {
|
|
2705
2119
|
hash: "",
|
|
2706
|
-
network:
|
|
2120
|
+
network: chain,
|
|
2707
2121
|
status: "failed",
|
|
2708
2122
|
error: errorMessage,
|
|
2709
2123
|
timestamp
|
|
@@ -2713,27 +2127,27 @@ var TransactionService = class {
|
|
|
2713
2127
|
/**
|
|
2714
2128
|
* Get transaction status
|
|
2715
2129
|
*/
|
|
2716
|
-
async getTransactionStatus(
|
|
2717
|
-
const wallet = await this.getWallet(
|
|
2130
|
+
async getTransactionStatus(chain, txHash) {
|
|
2131
|
+
const wallet = await this.getWallet(chain);
|
|
2718
2132
|
try {
|
|
2719
2133
|
const tx = await wallet.getTransaction(txHash);
|
|
2720
2134
|
return {
|
|
2721
2135
|
hash: txHash,
|
|
2722
|
-
network:
|
|
2136
|
+
network: chain,
|
|
2723
2137
|
status: tx.confirmed ? "confirmed" : "pending",
|
|
2724
2138
|
blockNumber: tx.blockNumber,
|
|
2725
2139
|
gasUsed: tx.gasUsed?.toString(),
|
|
2726
2140
|
fee: tx.fee?.toString(),
|
|
2727
|
-
explorerUrl: this.getExplorerUrl(
|
|
2141
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
2728
2142
|
timestamp: tx.timestamp || Date.now()
|
|
2729
2143
|
};
|
|
2730
2144
|
} catch (error) {
|
|
2731
2145
|
console.error(`Error getting transaction status for ${txHash}:`, error);
|
|
2732
2146
|
return {
|
|
2733
2147
|
hash: txHash,
|
|
2734
|
-
network:
|
|
2148
|
+
network: chain,
|
|
2735
2149
|
status: "pending",
|
|
2736
|
-
explorerUrl: this.getExplorerUrl(
|
|
2150
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
2737
2151
|
timestamp: Date.now()
|
|
2738
2152
|
};
|
|
2739
2153
|
}
|
|
@@ -2741,14 +2155,14 @@ var TransactionService = class {
|
|
|
2741
2155
|
/**
|
|
2742
2156
|
* Get transaction history for an address
|
|
2743
2157
|
*/
|
|
2744
|
-
async getTransactionHistory(
|
|
2745
|
-
const wallet = await this.getWallet(
|
|
2158
|
+
async getTransactionHistory(chain, limit = 10) {
|
|
2159
|
+
const wallet = await this.getWallet(chain);
|
|
2746
2160
|
const account = await wallet.getAccount(0);
|
|
2747
2161
|
try {
|
|
2748
2162
|
const history = await account.getTransactions({ limit });
|
|
2749
2163
|
return history.map((tx) => ({
|
|
2750
2164
|
hash: tx.hash || tx.txHash,
|
|
2751
|
-
network:
|
|
2165
|
+
network: chain,
|
|
2752
2166
|
type: tx.type || (tx.from === account.address ? "send" : "receive"),
|
|
2753
2167
|
from: tx.from,
|
|
2754
2168
|
to: tx.to,
|
|
@@ -2760,20 +2174,20 @@ var TransactionService = class {
|
|
|
2760
2174
|
blockNumber: tx.blockNumber
|
|
2761
2175
|
}));
|
|
2762
2176
|
} catch (error) {
|
|
2763
|
-
console.error(`Error getting transaction history for ${
|
|
2177
|
+
console.error(`Error getting transaction history for ${chain}:`, error);
|
|
2764
2178
|
return [];
|
|
2765
2179
|
}
|
|
2766
2180
|
}
|
|
2767
2181
|
/**
|
|
2768
2182
|
* Get balance for a specific chain
|
|
2769
2183
|
*/
|
|
2770
|
-
async getBalance(
|
|
2771
|
-
const wallet = await this.getWallet(
|
|
2184
|
+
async getBalance(chain) {
|
|
2185
|
+
const wallet = await this.getWallet(chain);
|
|
2772
2186
|
const account = await wallet.getAccount(0);
|
|
2773
2187
|
try {
|
|
2774
2188
|
const balance = await account.getBalance();
|
|
2775
2189
|
const balanceStr = balance.toString();
|
|
2776
|
-
const priceUsd = await getPriceForChain(
|
|
2190
|
+
const priceUsd = await getPriceForChain(chain);
|
|
2777
2191
|
const balanceNum = parseFloat(balanceStr) || 0;
|
|
2778
2192
|
const balanceUsd = balanceNum * priceUsd;
|
|
2779
2193
|
return {
|
|
@@ -2781,7 +2195,7 @@ var TransactionService = class {
|
|
|
2781
2195
|
balanceUsd
|
|
2782
2196
|
};
|
|
2783
2197
|
} catch (error) {
|
|
2784
|
-
console.error(`Error getting balance for ${
|
|
2198
|
+
console.error(`Error getting balance for ${chain}:`, error);
|
|
2785
2199
|
return { balance: "0", balanceUsd: 0 };
|
|
2786
2200
|
}
|
|
2787
2201
|
}
|
|
@@ -2817,14 +2231,6 @@ function getTransactionService(config) {
|
|
|
2817
2231
|
function createTransactionService(config) {
|
|
2818
2232
|
return new TransactionService(config);
|
|
2819
2233
|
}
|
|
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
2234
|
|
|
2829
2235
|
exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
|
|
2830
2236
|
exports.SwapService = SwapService;
|