@zubari/sdk 0.5.0 → 0.5.2

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.
Files changed (35) hide show
  1. package/dist/{TransactionService-Djonkbp4.d.ts → TransactionService-BtWUjKt_.d.ts} +14 -2
  2. package/dist/{TransactionService-1Jt8ZRqO.d.mts → TransactionService-Lr_WS6iR.d.mts} +14 -2
  3. package/dist/{WalletManager-BJaLBfX5.d.ts → WalletManager-DQQwVkoa.d.ts} +52 -131
  4. package/dist/{WalletManager-pVFpurEi.d.mts → WalletManager-Sbpx4E1-.d.mts} +52 -131
  5. package/dist/{index-Da7SaweH.d.mts → contracts-B842YprC.d.mts} +152 -82
  6. package/dist/{index-ARbXbNI-.d.ts → contracts-s_CDIruh.d.ts} +152 -82
  7. package/dist/index.d.mts +65 -6
  8. package/dist/index.d.ts +65 -6
  9. package/dist/index.js +1268 -240
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +1250 -240
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/protocols/index.js +23 -5
  14. package/dist/protocols/index.js.map +1 -1
  15. package/dist/protocols/index.mjs +23 -5
  16. package/dist/protocols/index.mjs.map +1 -1
  17. package/dist/react/index.d.mts +3 -4
  18. package/dist/react/index.d.ts +3 -4
  19. package/dist/react/index.js +1011 -151
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react/index.mjs +1010 -150
  22. package/dist/react/index.mjs.map +1 -1
  23. package/dist/services/index.d.mts +1 -1
  24. package/dist/services/index.d.ts +1 -1
  25. package/dist/services/index.js +838 -112
  26. package/dist/services/index.js.map +1 -1
  27. package/dist/services/index.mjs +836 -110
  28. package/dist/services/index.mjs.map +1 -1
  29. package/dist/wallet/index.d.mts +3 -4
  30. package/dist/wallet/index.d.ts +3 -4
  31. package/dist/wallet/index.js +1042 -171
  32. package/dist/wallet/index.js.map +1 -1
  33. package/dist/wallet/index.mjs +1041 -170
  34. package/dist/wallet/index.mjs.map +1 -1
  35. package/package.json +16 -14
@@ -1,9 +1,12 @@
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 { HDKey } from '@scure/bip32';
5
- import { bech32, base58check } from '@scure/base';
6
- import { sha256 } from '@noble/hashes/sha256';
4
+ import { secp256k1 } from '@noble/curves/secp256k1.js';
5
+ import { hmac } from '@noble/hashes/hmac.js';
6
+ import { ripemd160 as ripemd160$1 } from '@noble/hashes/legacy.js';
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';
7
10
  import { ripemd160 } from '@noble/hashes/ripemd160';
8
11
 
9
12
  var __defProp = Object.defineProperty;
@@ -263,14 +266,14 @@ var WdkApiClient = class {
263
266
  /**
264
267
  * Derive address for a specific chain using Tether WDK
265
268
  */
266
- async deriveAddress(seed, chain, network = "testnet") {
269
+ async deriveAddress(seed, chain2, network = "mainnet") {
267
270
  try {
268
271
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
269
272
  method: "POST",
270
273
  headers: {
271
274
  "Content-Type": "application/json"
272
275
  },
273
- body: JSON.stringify({ seed, chain, network })
276
+ body: JSON.stringify({ seed, chain: chain2, network })
274
277
  });
275
278
  return await response.json();
276
279
  } catch (error) {
@@ -283,7 +286,7 @@ var WdkApiClient = class {
283
286
  /**
284
287
  * Derive addresses for all chains using Tether WDK
285
288
  */
286
- async deriveAllAddresses(seed, network = "testnet") {
289
+ async deriveAllAddresses(seed, network = "mainnet") {
287
290
  try {
288
291
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
289
292
  method: "POST",
@@ -303,14 +306,14 @@ var WdkApiClient = class {
303
306
  /**
304
307
  * Send a transaction on a specific chain using Tether WDK
305
308
  */
306
- async sendTransaction(seed, chain, to, amount, network = "testnet") {
309
+ async sendTransaction(seed, chain2, to, amount, network = "mainnet") {
307
310
  try {
308
311
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
309
312
  method: "POST",
310
313
  headers: {
311
314
  "Content-Type": "application/json"
312
315
  },
313
- body: JSON.stringify({ seed, chain, to, amount, network })
316
+ body: JSON.stringify({ seed, chain: chain2, to, amount, network })
314
317
  });
315
318
  return await response.json();
316
319
  } catch (error) {
@@ -324,14 +327,14 @@ var WdkApiClient = class {
324
327
  * Get transaction history for an address on a specific chain
325
328
  * Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
326
329
  */
327
- async getTransactionHistory(seed, chain, network = "testnet", limit = 10) {
330
+ async getTransactionHistory(seed, chain2, network = "mainnet", limit = 10) {
328
331
  try {
329
332
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
330
333
  method: "POST",
331
334
  headers: {
332
335
  "Content-Type": "application/json"
333
336
  },
334
- body: JSON.stringify({ seed, chain, network, limit })
337
+ body: JSON.stringify({ seed, chain: chain2, network, limit })
335
338
  });
336
339
  return await response.json();
337
340
  } catch (error) {
@@ -345,14 +348,14 @@ var WdkApiClient = class {
345
348
  * Get transaction status by hash
346
349
  * Fetches from blockchain explorers to check confirmation status
347
350
  */
348
- async getTransactionStatus(txHash, chain, network = "testnet") {
351
+ async getTransactionStatus(txHash, chain2, network = "mainnet") {
349
352
  try {
350
353
  const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
351
354
  method: "POST",
352
355
  headers: {
353
356
  "Content-Type": "application/json"
354
357
  },
355
- body: JSON.stringify({ txHash, chain, network })
358
+ body: JSON.stringify({ txHash, chain: chain2, network })
356
359
  });
357
360
  return await response.json();
358
361
  } catch (error) {
@@ -1072,6 +1075,589 @@ __export(BrowserAddressDerivation_exports, {
1072
1075
  generateSeedPhrase: () => generateSeedPhrase,
1073
1076
  isValidSeed: () => isValidSeed
1074
1077
  });
1078
+
1079
+ // node_modules/@scure/base/index.js
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
+ };
1075
1661
  var DERIVATION_PATHS = {
1076
1662
  ethereum: "m/44'/60'/0'/0/0",
1077
1663
  bitcoin_mainnet: "m/84'/0'/0'/0/0",
@@ -1085,7 +1671,7 @@ function deriveEthereumAddress(seed) {
1085
1671
  const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS.ethereum);
1086
1672
  return hdNode.address;
1087
1673
  }
1088
- function deriveBitcoinAddress(seed, network = "testnet") {
1674
+ function deriveBitcoinAddress(seed, network = "mainnet") {
1089
1675
  try {
1090
1676
  const seedBytes = mnemonicToSeedSync(seed);
1091
1677
  const hdKey = HDKey.fromMasterSeed(seedBytes);
@@ -1094,7 +1680,7 @@ function deriveBitcoinAddress(seed, network = "testnet") {
1094
1680
  if (!child.publicKey) {
1095
1681
  throw new Error("Failed to derive public key");
1096
1682
  }
1097
- const pubKeyHash = ripemd160(sha256(child.publicKey));
1683
+ const pubKeyHash = ripemd160(sha256$1(child.publicKey));
1098
1684
  const witnessVersion = 0;
1099
1685
  const words = bech32.toWords(pubKeyHash);
1100
1686
  words.unshift(witnessVersion);
@@ -1135,7 +1721,7 @@ async function deriveTonAddress(seed) {
1135
1721
  const publicKey = keypair.publicKey;
1136
1722
  const workchain = 0;
1137
1723
  const flags = 17;
1138
- const hash = sha256(publicKey);
1724
+ const hash = sha256$1(publicKey);
1139
1725
  const addressData = new Uint8Array(34);
1140
1726
  addressData[0] = flags;
1141
1727
  addressData[1] = workchain;
@@ -1172,14 +1758,14 @@ function deriveTronAddress(seed) {
1172
1758
  for (let i = 0; i < 20; i++) {
1173
1759
  addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
1174
1760
  }
1175
- const tronBase58check = base58check(sha256);
1761
+ const tronBase58check = base58check(sha256$1);
1176
1762
  return tronBase58check.encode(addressBytes);
1177
1763
  } catch (error) {
1178
1764
  console.error("TRON address derivation failed:", error);
1179
1765
  throw error;
1180
1766
  }
1181
1767
  }
1182
- function deriveSparkAddress(seed, network = "testnet") {
1768
+ function deriveSparkAddress(seed, network = "mainnet") {
1183
1769
  try {
1184
1770
  const seedBytes = mnemonicToSeedSync(seed);
1185
1771
  const hdKey = HDKey.fromMasterSeed(seedBytes);
@@ -1187,7 +1773,7 @@ function deriveSparkAddress(seed, network = "testnet") {
1187
1773
  if (!child.publicKey) {
1188
1774
  throw new Error("Failed to derive public key");
1189
1775
  }
1190
- const pubKeyHash = ripemd160(sha256(child.publicKey));
1776
+ const pubKeyHash = ripemd160(sha256$1(child.publicKey));
1191
1777
  const witnessVersion = 0;
1192
1778
  const words = bech32.toWords(pubKeyHash);
1193
1779
  words.unshift(witnessVersion);
@@ -1199,7 +1785,7 @@ function deriveSparkAddress(seed, network = "testnet") {
1199
1785
  throw error;
1200
1786
  }
1201
1787
  }
1202
- async function deriveAllAddresses(seed, network = "testnet") {
1788
+ async function deriveAllAddresses(seed, network = "mainnet") {
1203
1789
  const addresses = {
1204
1790
  ethereum: null,
1205
1791
  bitcoin: null,
@@ -1253,6 +1839,60 @@ function generateSeedPhrase() {
1253
1839
 
1254
1840
  // src/services/ZubariWdkService.ts
1255
1841
  var DEFAULT_API_URL3 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
1842
+ var CHAIN_ERROR_MESSAGES = {
1843
+ ethereum: {
1844
+ "insufficient funds": "INSUFFICIENT_FUNDS",
1845
+ "nonce too low": "NONCE_TOO_LOW",
1846
+ "gas too low": "GAS_TOO_LOW",
1847
+ "replacement transaction underpriced": "GAS_TOO_LOW",
1848
+ "transaction underpriced": "GAS_TOO_LOW",
1849
+ "invalid address": "INVALID_ADDRESS"
1850
+ },
1851
+ bitcoin: {
1852
+ "insufficient funds": "INSUFFICIENT_FUNDS",
1853
+ "dust": "DUST_AMOUNT",
1854
+ "mempool": "MEMPOOL_FULL",
1855
+ "invalid address": "INVALID_ADDRESS"
1856
+ },
1857
+ solana: {
1858
+ "insufficient funds": "INSUFFICIENT_FUNDS",
1859
+ "invalid account": "INVALID_ADDRESS",
1860
+ "blockhash not found": "NETWORK_ERROR"
1861
+ },
1862
+ ton: {
1863
+ "insufficient funds": "INSUFFICIENT_FUNDS",
1864
+ "invalid address": "INVALID_ADDRESS"
1865
+ },
1866
+ tron: {
1867
+ "insufficient funds": "INSUFFICIENT_FUNDS",
1868
+ "invalid address": "INVALID_ADDRESS",
1869
+ "bandwidth": "GAS_TOO_LOW"
1870
+ },
1871
+ spark: {
1872
+ "insufficient funds": "INSUFFICIENT_FUNDS",
1873
+ "invoice expired": "TIMEOUT",
1874
+ "no route": "NETWORK_ERROR"
1875
+ }
1876
+ };
1877
+ function parseChainError(chain2, errorMessage) {
1878
+ const errorLower = errorMessage.toLowerCase();
1879
+ const chainErrors = CHAIN_ERROR_MESSAGES[chain2];
1880
+ for (const [pattern, code] of Object.entries(chainErrors)) {
1881
+ if (errorLower.includes(pattern)) {
1882
+ return code;
1883
+ }
1884
+ }
1885
+ if (errorLower.includes("timeout") || errorLower.includes("timed out")) {
1886
+ return "TIMEOUT";
1887
+ }
1888
+ if (errorLower.includes("network") || errorLower.includes("connection")) {
1889
+ return "NETWORK_ERROR";
1890
+ }
1891
+ if (errorLower.includes("rejected") || errorLower.includes("denied")) {
1892
+ return "REJECTED";
1893
+ }
1894
+ return "UNKNOWN";
1895
+ }
1256
1896
  function isBrowser() {
1257
1897
  return typeof window !== "undefined" && typeof window.document !== "undefined";
1258
1898
  }
@@ -1276,7 +1916,7 @@ var ZubariWdkService = class {
1276
1916
  useNativeWdk = false;
1277
1917
  constructor(config = {}) {
1278
1918
  this.config = {
1279
- network: config.network || "testnet",
1919
+ network: config.network || "mainnet",
1280
1920
  apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL3,
1281
1921
  forceApi: config.forceApi ?? false,
1282
1922
  timeout: config.timeout || 3e4
@@ -1374,38 +2014,38 @@ var ZubariWdkService = class {
1374
2014
  * For Ethereum, falls back to local derivation if API fails.
1375
2015
  * For other chains, WDK API is required - no placeholder fallback.
1376
2016
  */
1377
- async deriveAddress(seed, chain) {
2017
+ async deriveAddress(seed, chain2) {
1378
2018
  await this.initialize();
1379
- const path = this.getDerivationPath(chain);
2019
+ const path = this.getDerivationPath(chain2);
1380
2020
  try {
1381
- const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
2021
+ const response = await this.apiClient.deriveAddress(seed, chain2, this.config.network);
1382
2022
  if (response.success && response.address) {
1383
2023
  return {
1384
- chain,
2024
+ chain: chain2,
1385
2025
  address: response.address,
1386
2026
  path: response.path || path
1387
2027
  };
1388
2028
  }
1389
2029
  } catch (error) {
1390
- console.warn(`API address derivation failed for ${chain}:`, error);
1391
- if (chain === "ethereum") {
1392
- return this.deriveBrowserAddress(seed, chain);
2030
+ console.warn(`API address derivation failed for ${chain2}:`, error);
2031
+ if (chain2 === "ethereum") {
2032
+ return this.deriveBrowserAddress(seed, chain2);
1393
2033
  }
1394
2034
  }
1395
2035
  if (this.useNativeWdk && this.nativeWdkService) {
1396
2036
  try {
1397
2037
  const wdk = this.nativeWdkService;
1398
2038
  await wdk.initialize(seed);
1399
- return await wdk.deriveAddress(chain);
2039
+ return await wdk.deriveAddress(chain2);
1400
2040
  } catch (error) {
1401
- console.warn(`Native WDK address derivation failed for ${chain}:`, error);
2041
+ console.warn(`Native WDK address derivation failed for ${chain2}:`, error);
1402
2042
  }
1403
2043
  }
1404
- if (chain === "ethereum") {
1405
- return this.deriveBrowserAddress(seed, chain);
2044
+ if (chain2 === "ethereum") {
2045
+ return this.deriveBrowserAddress(seed, chain2);
1406
2046
  }
1407
2047
  throw new Error(
1408
- `WDK API required for ${chain} address derivation. Ensure the backend is running.`
2048
+ `WDK API required for ${chain2} address derivation. Ensure the backend is running.`
1409
2049
  );
1410
2050
  }
1411
2051
  /**
@@ -1427,7 +2067,7 @@ var ZubariWdkService = class {
1427
2067
  }
1428
2068
  return null;
1429
2069
  };
1430
- return {
2070
+ const addresses = {
1431
2071
  ethereum: extractAddress(response.addresses.ethereum),
1432
2072
  bitcoin: extractAddress(response.addresses.bitcoin),
1433
2073
  ton: extractAddress(response.addresses.ton),
@@ -1435,6 +2075,14 @@ var ZubariWdkService = class {
1435
2075
  solana: extractAddress(response.addresses.solana),
1436
2076
  spark: extractAddress(response.addresses.spark)
1437
2077
  };
2078
+ if (!addresses.spark) {
2079
+ try {
2080
+ addresses.spark = deriveSparkAddress(seed, this.config.network);
2081
+ } catch (e) {
2082
+ console.warn("Browser Spark derivation fallback failed:", e);
2083
+ }
2084
+ }
2085
+ return addresses;
1438
2086
  }
1439
2087
  } catch (error) {
1440
2088
  console.warn("API address derivation failed:", error);
@@ -1477,13 +2125,13 @@ var ZubariWdkService = class {
1477
2125
  /**
1478
2126
  * Get fee rates for a chain
1479
2127
  */
1480
- async getFeeRates(seed, chain) {
2128
+ async getFeeRates(seed, chain2) {
1481
2129
  await this.initialize();
1482
2130
  try {
1483
2131
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
1484
2132
  method: "POST",
1485
2133
  headers: { "Content-Type": "application/json" },
1486
- body: JSON.stringify({ seed, chain, network: this.config.network })
2134
+ body: JSON.stringify({ seed, chain: chain2, network: this.config.network })
1487
2135
  });
1488
2136
  if (response.ok) {
1489
2137
  const data = await response.json();
@@ -1492,20 +2140,20 @@ var ZubariWdkService = class {
1492
2140
  }
1493
2141
  }
1494
2142
  } catch (error) {
1495
- console.warn(`Failed to fetch fee rates for ${chain}:`, error);
2143
+ console.warn(`Failed to fetch fee rates for ${chain2}:`, error);
1496
2144
  }
1497
2145
  return { slow: "0", normal: "0", fast: "0" };
1498
2146
  }
1499
2147
  /**
1500
2148
  * Estimate transaction fee
1501
2149
  */
1502
- async estimateFee(seed, chain, to, amount) {
2150
+ async estimateFee(seed, chain2, to, amount) {
1503
2151
  await this.initialize();
1504
2152
  try {
1505
2153
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
1506
2154
  method: "POST",
1507
2155
  headers: { "Content-Type": "application/json" },
1508
- body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
2156
+ body: JSON.stringify({ seed, chain: chain2, to, amount, network: this.config.network })
1509
2157
  });
1510
2158
  if (response.ok) {
1511
2159
  const data = await response.json();
@@ -1514,52 +2162,122 @@ var ZubariWdkService = class {
1514
2162
  }
1515
2163
  }
1516
2164
  } catch (error) {
1517
- console.warn(`Failed to estimate fee for ${chain}:`, error);
2165
+ console.warn(`Failed to estimate fee for ${chain2}:`, error);
1518
2166
  }
1519
- return { fee: "0", symbol: this.getChainSymbol(chain) };
2167
+ return { fee: "0", symbol: this.getChainSymbol(chain2) };
1520
2168
  }
1521
2169
  /**
1522
- * Send a transaction
2170
+ * Send a transaction on any supported chain
2171
+ *
2172
+ * @param seed - BIP-39 seed phrase
2173
+ * @param chain - Target blockchain (ethereum, bitcoin, solana, ton, tron, spark)
2174
+ * @param to - Recipient address
2175
+ * @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
2176
+ * @returns Transaction result with hash on success, or error details on failure
1523
2177
  */
1524
- async sendTransaction(seed, chain, to, amount) {
2178
+ async sendTransaction(seed, chain2, to, amount) {
1525
2179
  await this.initialize();
2180
+ 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
+ });
1526
2186
  try {
1527
2187
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
1528
2188
  method: "POST",
1529
2189
  headers: { "Content-Type": "application/json" },
1530
- body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
2190
+ body: JSON.stringify({ seed, chain: chain2, to, amount, network: this.config.network })
1531
2191
  });
2192
+ const elapsed = Date.now() - startTime;
1532
2193
  if (response.ok) {
1533
2194
  const data = await response.json();
1534
2195
  let txHash = data.txHash || data.transactionHash || data.hash;
1535
2196
  if (txHash && typeof txHash === "object" && "hash" in txHash) {
1536
2197
  txHash = txHash.hash;
1537
2198
  }
1538
- if (chain === "ethereum" && txHash && (typeof txHash !== "string" || !txHash.startsWith("0x") || txHash.length !== 66)) {
1539
- console.warn(`Invalid Ethereum tx hash format: ${txHash} (length: ${txHash?.length}, expected: 66)`);
2199
+ if (txHash) {
2200
+ const isValid = this.validateTxHash(chain2, txHash);
2201
+ if (!isValid) {
2202
+ console.warn(`[ZubariWdkService] Invalid ${chain2} tx hash format:`, txHash);
2203
+ }
2204
+ }
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
+ if (!data.success) {
2210
+ const errorCode2 = parseChainError(chain2, data.error || "");
2211
+ return {
2212
+ success: false,
2213
+ error: data.error,
2214
+ errorCode: errorCode2,
2215
+ chain: chain2
2216
+ };
1540
2217
  }
1541
2218
  return {
1542
- success: data.success,
2219
+ success: true,
1543
2220
  txHash,
1544
2221
  from: data.from,
1545
2222
  to: data.to,
1546
2223
  amount: data.amount,
1547
- chain: data.chain,
1548
- network: data.network
2224
+ chain: data.chain || chain2,
2225
+ network: data.network || this.config.network
1549
2226
  };
1550
2227
  }
1551
2228
  const errorData = await response.json().catch(() => ({}));
2229
+ const errorMessage = errorData.error || `HTTP ${response.status}`;
2230
+ const errorCode = parseChainError(chain2, errorMessage);
2231
+ console.error(`[ZubariWdkService] ${chain2} transaction FAILED`, {
2232
+ status: response.status,
2233
+ error: errorMessage,
2234
+ errorCode,
2235
+ elapsed: `${elapsed}ms`
2236
+ });
1552
2237
  return {
1553
2238
  success: false,
1554
- error: errorData.error || `HTTP ${response.status}`
2239
+ error: errorMessage,
2240
+ errorCode,
2241
+ chain: chain2
1555
2242
  };
1556
2243
  } catch (error) {
2244
+ const elapsed = Date.now() - startTime;
2245
+ const errorMessage = error instanceof Error ? error.message : "Transaction failed";
2246
+ const errorCode = parseChainError(chain2, errorMessage);
2247
+ console.error(`[ZubariWdkService] ${chain2} transaction ERROR`, {
2248
+ error: errorMessage,
2249
+ errorCode,
2250
+ elapsed: `${elapsed}ms`
2251
+ });
1557
2252
  return {
1558
2253
  success: false,
1559
- error: error instanceof Error ? error.message : "Transaction failed"
2254
+ error: errorMessage,
2255
+ errorCode,
2256
+ chain: chain2
1560
2257
  };
1561
2258
  }
1562
2259
  }
2260
+ /**
2261
+ * Validate transaction hash format for a specific chain
2262
+ */
2263
+ validateTxHash(chain2, txHash) {
2264
+ switch (chain2) {
2265
+ case "ethereum":
2266
+ return /^0x[a-fA-F0-9]{64}$/.test(txHash);
2267
+ case "bitcoin":
2268
+ return /^[a-fA-F0-9]{64}$/.test(txHash);
2269
+ case "solana":
2270
+ return /^[1-9A-HJ-NP-Za-km-z]{80,90}$/.test(txHash);
2271
+ case "ton":
2272
+ return txHash.length >= 40;
2273
+ case "tron":
2274
+ return /^[a-fA-F0-9]{64}$/.test(txHash);
2275
+ case "spark":
2276
+ return txHash.length >= 32;
2277
+ default:
2278
+ return true;
2279
+ }
2280
+ }
1563
2281
  /**
1564
2282
  * Get the network configuration
1565
2283
  */
@@ -1575,7 +2293,7 @@ var ZubariWdkService = class {
1575
2293
  // ==========================================
1576
2294
  // Private Helper Methods
1577
2295
  // ==========================================
1578
- getDerivationPath(chain) {
2296
+ getDerivationPath(chain2) {
1579
2297
  const paths = {
1580
2298
  bitcoin: this.config.network === "testnet" ? "m/84'/1'/0'/0/0" : "m/84'/0'/0'/0/0",
1581
2299
  ethereum: "m/44'/60'/0'/0/0",
@@ -1584,9 +2302,9 @@ var ZubariWdkService = class {
1584
2302
  solana: "m/44'/501'/0'/0'",
1585
2303
  spark: "m/44'/998'/0'/0/0"
1586
2304
  };
1587
- return paths[chain];
2305
+ return paths[chain2];
1588
2306
  }
1589
- getChainSymbol(chain) {
2307
+ getChainSymbol(chain2) {
1590
2308
  const symbols = {
1591
2309
  ethereum: "ETH",
1592
2310
  bitcoin: "BTC",
@@ -1595,16 +2313,16 @@ var ZubariWdkService = class {
1595
2313
  solana: "SOL",
1596
2314
  spark: "SAT"
1597
2315
  };
1598
- return symbols[chain];
2316
+ return symbols[chain2];
1599
2317
  }
1600
2318
  /**
1601
2319
  * Derive address using browser-compatible libraries
1602
2320
  */
1603
- async deriveBrowserAddress(seed, chain) {
1604
- const path = this.getDerivationPath(chain);
2321
+ async deriveBrowserAddress(seed, chain2) {
2322
+ const path = this.getDerivationPath(chain2);
1605
2323
  try {
1606
2324
  let address;
1607
- switch (chain) {
2325
+ switch (chain2) {
1608
2326
  case "ethereum":
1609
2327
  address = deriveEthereumAddress(seed);
1610
2328
  break;
@@ -1624,11 +2342,11 @@ var ZubariWdkService = class {
1624
2342
  address = await deriveTonAddress(seed);
1625
2343
  break;
1626
2344
  default:
1627
- throw new Error(`Unsupported chain: ${chain}`);
2345
+ throw new Error(`Unsupported chain: ${chain2}`);
1628
2346
  }
1629
- return { chain, address, path };
2347
+ return { chain: chain2, address, path };
1630
2348
  } catch (error) {
1631
- console.error(`Browser derivation failed for ${chain}:`, error);
2349
+ console.error(`Browser derivation failed for ${chain2}:`, error);
1632
2350
  throw error;
1633
2351
  }
1634
2352
  }
@@ -1686,8 +2404,8 @@ async function fetchPrices() {
1686
2404
  if (response.ok) {
1687
2405
  const data = await response.json();
1688
2406
  const prices = {};
1689
- for (const [chain, geckoId] of Object.entries(COINGECKO_IDS)) {
1690
- prices[chain] = data[geckoId]?.usd || 0;
2407
+ for (const [chain2, geckoId] of Object.entries(COINGECKO_IDS)) {
2408
+ prices[chain2] = data[geckoId]?.usd || 0;
1691
2409
  }
1692
2410
  priceCache = { prices, timestamp: Date.now() };
1693
2411
  return prices;
@@ -1697,9 +2415,9 @@ async function fetchPrices() {
1697
2415
  }
1698
2416
  return priceCache?.prices || {};
1699
2417
  }
1700
- async function getPriceForChain(chain) {
2418
+ async function getPriceForChain(chain2) {
1701
2419
  const prices = await fetchPrices();
1702
- return prices[chain] || 0;
2420
+ return prices[chain2] || 0;
1703
2421
  }
1704
2422
  var dynamicImport2 = new Function("specifier", "return import(specifier)");
1705
2423
  async function loadWdkModules() {
@@ -1746,7 +2464,7 @@ var DEFAULT_RPC_URLS = {
1746
2464
  // Uses Electrum testnet
1747
2465
  solana: "https://api.devnet.solana.com",
1748
2466
  ton: "https://testnet.toncenter.com/api/v2/jsonRPC",
1749
- tron: "https://api.shasta.trongrid.io",
2467
+ tron: "https://nile.trongrid.io",
1750
2468
  spark: ""
1751
2469
  // Uses Spark testnet
1752
2470
  }
@@ -1765,7 +2483,7 @@ var EXPLORER_URLS = {
1765
2483
  bitcoin: "https://mempool.space/testnet/tx/",
1766
2484
  solana: "https://solscan.io/tx/?cluster=devnet&tx=",
1767
2485
  ton: "https://testnet.tonscan.org/tx/",
1768
- tron: "https://shasta.tronscan.org/#/transaction/",
2486
+ tron: "https://nile.tronscan.org/#/transaction/",
1769
2487
  spark: "https://testnet.spark.info/tx/"
1770
2488
  }
1771
2489
  };
@@ -1776,7 +2494,7 @@ var TransactionService = class {
1776
2494
  wallets = {};
1777
2495
  constructor(config = {}) {
1778
2496
  this.config = {
1779
- network: config.network || "testnet",
2497
+ network: config.network || "mainnet",
1780
2498
  rpcUrls: config.rpcUrls
1781
2499
  };
1782
2500
  }
@@ -1789,19 +2507,19 @@ var TransactionService = class {
1789
2507
  /**
1790
2508
  * Get RPC URL for a chain
1791
2509
  */
1792
- getRpcUrl(chain) {
2510
+ getRpcUrl(chain2) {
1793
2511
  const networkUrls = DEFAULT_RPC_URLS[this.config.network];
1794
- if (this.config.rpcUrls?.[chain]) {
1795
- return this.config.rpcUrls[chain];
2512
+ if (this.config.rpcUrls?.[chain2]) {
2513
+ return this.config.rpcUrls[chain2];
1796
2514
  }
1797
- return networkUrls[chain] || "";
2515
+ return networkUrls[chain2] || "";
1798
2516
  }
1799
2517
  /**
1800
2518
  * Get explorer URL for a transaction
1801
2519
  */
1802
- getExplorerUrl(chain, txHash) {
2520
+ getExplorerUrl(chain2, txHash) {
1803
2521
  const explorers = EXPLORER_URLS[this.config.network];
1804
- const baseUrl = explorers[chain] || "";
2522
+ const baseUrl = explorers[chain2] || "";
1805
2523
  return `${baseUrl}${txHash}`;
1806
2524
  }
1807
2525
  /**
@@ -1825,27 +2543,27 @@ var TransactionService = class {
1825
2543
  * Get or create wallet instance for a specific chain
1826
2544
  */
1827
2545
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1828
- async getWallet(chain) {
2546
+ async getWallet(chain2) {
1829
2547
  if (!this.seed) {
1830
2548
  throw new Error("TransactionService not initialized. Call initialize() first.");
1831
2549
  }
1832
- if (this.wallets[chain]) {
1833
- return this.wallets[chain];
2550
+ if (this.wallets[chain2]) {
2551
+ return this.wallets[chain2];
1834
2552
  }
1835
2553
  const isTestnet = this.config.network === "testnet";
1836
2554
  try {
1837
- switch (chain) {
2555
+ switch (chain2) {
1838
2556
  case "ethereum": {
1839
2557
  const rpcUrl = this.getRpcUrl("ethereum");
1840
2558
  const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
1841
- this.wallets[chain] = wallet;
2559
+ this.wallets[chain2] = wallet;
1842
2560
  return wallet;
1843
2561
  }
1844
2562
  case "bitcoin": {
1845
2563
  const wallet = new WalletManagerBtc(this.seed, {
1846
2564
  network: isTestnet ? "testnet" : "bitcoin"
1847
2565
  });
1848
- this.wallets[chain] = wallet;
2566
+ this.wallets[chain2] = wallet;
1849
2567
  return wallet;
1850
2568
  }
1851
2569
  case "solana": {
@@ -1853,7 +2571,7 @@ var TransactionService = class {
1853
2571
  const wallet = new WalletManagerSolana(this.seed, {
1854
2572
  rpcUrl
1855
2573
  });
1856
- this.wallets[chain] = wallet;
2574
+ this.wallets[chain2] = wallet;
1857
2575
  return wallet;
1858
2576
  }
1859
2577
  case "ton": {
@@ -1861,7 +2579,7 @@ var TransactionService = class {
1861
2579
  const wallet = new WalletManagerTon(this.seed, {
1862
2580
  tonClient: { url }
1863
2581
  });
1864
- this.wallets[chain] = wallet;
2582
+ this.wallets[chain2] = wallet;
1865
2583
  return wallet;
1866
2584
  }
1867
2585
  case "tron": {
@@ -1869,32 +2587,32 @@ var TransactionService = class {
1869
2587
  const wallet = new WalletManagerTron(this.seed, {
1870
2588
  provider: fullHost
1871
2589
  });
1872
- this.wallets[chain] = wallet;
2590
+ this.wallets[chain2] = wallet;
1873
2591
  return wallet;
1874
2592
  }
1875
2593
  case "spark": {
1876
2594
  const wallet = new WalletManagerSpark(this.seed, {
1877
2595
  network: isTestnet ? "TESTNET" : "MAINNET"
1878
2596
  });
1879
- this.wallets[chain] = wallet;
2597
+ this.wallets[chain2] = wallet;
1880
2598
  return wallet;
1881
2599
  }
1882
2600
  default:
1883
- throw new Error(`Unsupported chain: ${chain}`);
2601
+ throw new Error(`Unsupported chain: ${chain2}`);
1884
2602
  }
1885
2603
  } catch (error) {
1886
- console.error(`Failed to initialize ${chain} wallet:`, error);
2604
+ console.error(`Failed to initialize ${chain2} wallet:`, error);
1887
2605
  throw error;
1888
2606
  }
1889
2607
  }
1890
2608
  /**
1891
2609
  * Estimate transaction fee
1892
2610
  */
1893
- async estimateFee(chain, params) {
1894
- const wallet = await this.getWallet(chain);
2611
+ async estimateFee(chain2, params) {
2612
+ const wallet = await this.getWallet(chain2);
1895
2613
  try {
1896
2614
  const feeRates = await wallet.getFeeRates();
1897
- if (chain === "ethereum") {
2615
+ if (chain2 === "ethereum") {
1898
2616
  return {
1899
2617
  slow: {
1900
2618
  fee: `${feeRates.slow || "0"} Gwei`,
@@ -1909,7 +2627,7 @@ var TransactionService = class {
1909
2627
  estimatedTime: "~30 sec"
1910
2628
  }
1911
2629
  };
1912
- } else if (chain === "bitcoin") {
2630
+ } else if (chain2 === "bitcoin") {
1913
2631
  return {
1914
2632
  slow: {
1915
2633
  fee: `${feeRates.slow || feeRates.low || "0"} sat/vB`,
@@ -1941,7 +2659,7 @@ var TransactionService = class {
1941
2659
  };
1942
2660
  }
1943
2661
  } catch (error) {
1944
- console.error(`Error estimating fee for ${chain}:`, error);
2662
+ console.error(`Error estimating fee for ${chain2}:`, error);
1945
2663
  return {
1946
2664
  slow: { fee: "0", estimatedTime: "Unknown" },
1947
2665
  medium: { fee: "0", estimatedTime: "Unknown" },
@@ -1952,8 +2670,8 @@ var TransactionService = class {
1952
2670
  /**
1953
2671
  * Send a transaction
1954
2672
  */
1955
- async send(chain, params) {
1956
- const wallet = await this.getWallet(chain);
2673
+ async send(chain2, params) {
2674
+ const wallet = await this.getWallet(chain2);
1957
2675
  const account = await wallet.getAccount(0);
1958
2676
  const timestamp = Date.now();
1959
2677
  try {
@@ -1973,17 +2691,17 @@ var TransactionService = class {
1973
2691
  }
1974
2692
  return {
1975
2693
  hash: txHash,
1976
- network: chain,
2694
+ network: chain2,
1977
2695
  status: "pending",
1978
- explorerUrl: this.getExplorerUrl(chain, txHash),
2696
+ explorerUrl: this.getExplorerUrl(chain2, txHash),
1979
2697
  timestamp
1980
2698
  };
1981
2699
  } catch (error) {
1982
2700
  const errorMessage = error instanceof Error ? error.message : "Transaction failed";
1983
- console.error(`Transaction failed on ${chain}:`, error);
2701
+ console.error(`Transaction failed on ${chain2}:`, error);
1984
2702
  return {
1985
2703
  hash: "",
1986
- network: chain,
2704
+ network: chain2,
1987
2705
  status: "failed",
1988
2706
  error: errorMessage,
1989
2707
  timestamp
@@ -1993,27 +2711,27 @@ var TransactionService = class {
1993
2711
  /**
1994
2712
  * Get transaction status
1995
2713
  */
1996
- async getTransactionStatus(chain, txHash) {
1997
- const wallet = await this.getWallet(chain);
2714
+ async getTransactionStatus(chain2, txHash) {
2715
+ const wallet = await this.getWallet(chain2);
1998
2716
  try {
1999
2717
  const tx = await wallet.getTransaction(txHash);
2000
2718
  return {
2001
2719
  hash: txHash,
2002
- network: chain,
2720
+ network: chain2,
2003
2721
  status: tx.confirmed ? "confirmed" : "pending",
2004
2722
  blockNumber: tx.blockNumber,
2005
2723
  gasUsed: tx.gasUsed?.toString(),
2006
2724
  fee: tx.fee?.toString(),
2007
- explorerUrl: this.getExplorerUrl(chain, txHash),
2725
+ explorerUrl: this.getExplorerUrl(chain2, txHash),
2008
2726
  timestamp: tx.timestamp || Date.now()
2009
2727
  };
2010
2728
  } catch (error) {
2011
2729
  console.error(`Error getting transaction status for ${txHash}:`, error);
2012
2730
  return {
2013
2731
  hash: txHash,
2014
- network: chain,
2732
+ network: chain2,
2015
2733
  status: "pending",
2016
- explorerUrl: this.getExplorerUrl(chain, txHash),
2734
+ explorerUrl: this.getExplorerUrl(chain2, txHash),
2017
2735
  timestamp: Date.now()
2018
2736
  };
2019
2737
  }
@@ -2021,14 +2739,14 @@ var TransactionService = class {
2021
2739
  /**
2022
2740
  * Get transaction history for an address
2023
2741
  */
2024
- async getTransactionHistory(chain, limit = 10) {
2025
- const wallet = await this.getWallet(chain);
2742
+ async getTransactionHistory(chain2, limit = 10) {
2743
+ const wallet = await this.getWallet(chain2);
2026
2744
  const account = await wallet.getAccount(0);
2027
2745
  try {
2028
2746
  const history = await account.getTransactions({ limit });
2029
2747
  return history.map((tx) => ({
2030
2748
  hash: tx.hash || tx.txHash,
2031
- network: chain,
2749
+ network: chain2,
2032
2750
  type: tx.type || (tx.from === account.address ? "send" : "receive"),
2033
2751
  from: tx.from,
2034
2752
  to: tx.to,
@@ -2040,20 +2758,20 @@ var TransactionService = class {
2040
2758
  blockNumber: tx.blockNumber
2041
2759
  }));
2042
2760
  } catch (error) {
2043
- console.error(`Error getting transaction history for ${chain}:`, error);
2761
+ console.error(`Error getting transaction history for ${chain2}:`, error);
2044
2762
  return [];
2045
2763
  }
2046
2764
  }
2047
2765
  /**
2048
2766
  * Get balance for a specific chain
2049
2767
  */
2050
- async getBalance(chain) {
2051
- const wallet = await this.getWallet(chain);
2768
+ async getBalance(chain2) {
2769
+ const wallet = await this.getWallet(chain2);
2052
2770
  const account = await wallet.getAccount(0);
2053
2771
  try {
2054
2772
  const balance = await account.getBalance();
2055
2773
  const balanceStr = balance.toString();
2056
- const priceUsd = await getPriceForChain(chain);
2774
+ const priceUsd = await getPriceForChain(chain2);
2057
2775
  const balanceNum = parseFloat(balanceStr) || 0;
2058
2776
  const balanceUsd = balanceNum * priceUsd;
2059
2777
  return {
@@ -2061,7 +2779,7 @@ var TransactionService = class {
2061
2779
  balanceUsd
2062
2780
  };
2063
2781
  } catch (error) {
2064
- console.error(`Error getting balance for ${chain}:`, error);
2782
+ console.error(`Error getting balance for ${chain2}:`, error);
2065
2783
  return { balance: "0", balanceUsd: 0 };
2066
2784
  }
2067
2785
  }
@@ -2097,6 +2815,14 @@ function getTransactionService(config) {
2097
2815
  function createTransactionService(config) {
2098
2816
  return new TransactionService(config);
2099
2817
  }
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
+ */
2100
2826
 
2101
2827
  export { BrowserAddressDerivation_exports as BrowserAddressDerivation, SwapService, TransactionService, WdkApiClient, ZubariApiClient, ZubariWdkService, createTransactionService, createZubariApiClient, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariApiClient, getZubariWdkService, isBrowser };
2102
2828
  //# sourceMappingURL=index.mjs.map