@zubari/sdk 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PayoutsProtocol-B5z8SEA-.d.ts → PayoutsProtocol-DAa-9A5C.d.ts} +8 -1
- package/dist/{PayoutsProtocol-CLiMFe54.d.mts → PayoutsProtocol-DKEQhwYH.d.mts} +8 -1
- package/dist/{TransactionService-BtWUjKt_.d.ts → TransactionService-BEkgF1T6.d.ts} +12 -2
- package/dist/{TransactionService-Lr_WS6iR.d.mts → TransactionService-CF_C3Kqm.d.mts} +12 -2
- package/dist/{WalletManager-DQQwVkoa.d.ts → WalletManager-CeLlZo2y.d.ts} +23 -2
- package/dist/{WalletManager-Sbpx4E1-.d.mts → WalletManager-DIx8nENh.d.mts} +23 -2
- package/dist/{contracts-B842YprC.d.mts → contracts-JfZDzaV7.d.ts} +11 -2
- package/dist/{contracts-s_CDIruh.d.ts → contracts-pugJnFzl.d.mts} +11 -2
- package/dist/{index-CTyZlHKg.d.mts → index-c90msmwW.d.mts} +2 -1
- package/dist/{index-CTyZlHKg.d.ts → index-c90msmwW.d.ts} +2 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +129 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -136
- package/dist/index.mjs.map +1 -1
- package/dist/protocols/index.d.mts +2 -2
- package/dist/protocols/index.d.ts +2 -2
- package/dist/protocols/index.js +24 -11
- package/dist/protocols/index.js.map +1 -1
- package/dist/protocols/index.mjs +24 -11
- package/dist/protocols/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +94 -95
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +94 -95
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +2 -2
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +72 -66
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +72 -66
- package/dist/services/index.mjs.map +1 -1
- package/dist/storage/index.js +5 -2
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +5 -2
- package/dist/storage/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +3 -3
- package/dist/wallet/index.d.ts +3 -3
- package/dist/wallet/index.js +103 -125
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +103 -125
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/services/index.mjs
CHANGED
|
@@ -218,9 +218,28 @@ var WdkApiClient = class {
|
|
|
218
218
|
constructor(config) {
|
|
219
219
|
this.config = {
|
|
220
220
|
baseUrl: config.baseUrl,
|
|
221
|
-
timeout: config.timeout || 3e4
|
|
221
|
+
timeout: config.timeout || 3e4,
|
|
222
|
+
authToken: config.authToken
|
|
222
223
|
};
|
|
223
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Set or update the auth token for authenticated requests
|
|
227
|
+
*/
|
|
228
|
+
setAuthToken(token) {
|
|
229
|
+
this.config.authToken = token;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Build headers for API requests, including Authorization when available
|
|
233
|
+
*/
|
|
234
|
+
getHeaders() {
|
|
235
|
+
const headers = {
|
|
236
|
+
"Content-Type": "application/json"
|
|
237
|
+
};
|
|
238
|
+
if (this.config.authToken) {
|
|
239
|
+
headers["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
240
|
+
}
|
|
241
|
+
return headers;
|
|
242
|
+
}
|
|
224
243
|
/**
|
|
225
244
|
* Generate a new BIP-39 seed phrase using Tether WDK
|
|
226
245
|
*/
|
|
@@ -228,9 +247,7 @@ var WdkApiClient = class {
|
|
|
228
247
|
try {
|
|
229
248
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/generate-seed`, {
|
|
230
249
|
method: "POST",
|
|
231
|
-
headers:
|
|
232
|
-
"Content-Type": "application/json"
|
|
233
|
-
}
|
|
250
|
+
headers: this.getHeaders()
|
|
234
251
|
});
|
|
235
252
|
return await response.json();
|
|
236
253
|
} catch (error) {
|
|
@@ -247,9 +264,7 @@ var WdkApiClient = class {
|
|
|
247
264
|
try {
|
|
248
265
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/validate-seed`, {
|
|
249
266
|
method: "POST",
|
|
250
|
-
headers:
|
|
251
|
-
"Content-Type": "application/json"
|
|
252
|
-
},
|
|
267
|
+
headers: this.getHeaders(),
|
|
253
268
|
body: JSON.stringify({ seed })
|
|
254
269
|
});
|
|
255
270
|
return await response.json();
|
|
@@ -267,9 +282,7 @@ var WdkApiClient = class {
|
|
|
267
282
|
try {
|
|
268
283
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
269
284
|
method: "POST",
|
|
270
|
-
headers:
|
|
271
|
-
"Content-Type": "application/json"
|
|
272
|
-
},
|
|
285
|
+
headers: this.getHeaders(),
|
|
273
286
|
body: JSON.stringify({ seed, chain, network })
|
|
274
287
|
});
|
|
275
288
|
return await response.json();
|
|
@@ -287,9 +300,7 @@ var WdkApiClient = class {
|
|
|
287
300
|
try {
|
|
288
301
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
289
302
|
method: "POST",
|
|
290
|
-
headers:
|
|
291
|
-
"Content-Type": "application/json"
|
|
292
|
-
},
|
|
303
|
+
headers: this.getHeaders(),
|
|
293
304
|
body: JSON.stringify({ seed, network })
|
|
294
305
|
});
|
|
295
306
|
return await response.json();
|
|
@@ -307,9 +318,7 @@ var WdkApiClient = class {
|
|
|
307
318
|
try {
|
|
308
319
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
309
320
|
method: "POST",
|
|
310
|
-
headers:
|
|
311
|
-
"Content-Type": "application/json"
|
|
312
|
-
},
|
|
321
|
+
headers: this.getHeaders(),
|
|
313
322
|
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
314
323
|
});
|
|
315
324
|
return await response.json();
|
|
@@ -328,9 +337,7 @@ var WdkApiClient = class {
|
|
|
328
337
|
try {
|
|
329
338
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
330
339
|
method: "POST",
|
|
331
|
-
headers:
|
|
332
|
-
"Content-Type": "application/json"
|
|
333
|
-
},
|
|
340
|
+
headers: this.getHeaders(),
|
|
334
341
|
body: JSON.stringify({ seed, chain, network, limit })
|
|
335
342
|
});
|
|
336
343
|
return await response.json();
|
|
@@ -349,9 +356,7 @@ var WdkApiClient = class {
|
|
|
349
356
|
try {
|
|
350
357
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
351
358
|
method: "POST",
|
|
352
|
-
headers:
|
|
353
|
-
"Content-Type": "application/json"
|
|
354
|
-
},
|
|
359
|
+
headers: this.getHeaders(),
|
|
355
360
|
body: JSON.stringify({ txHash, chain, network })
|
|
356
361
|
});
|
|
357
362
|
return await response.json();
|
|
@@ -365,11 +370,14 @@ var WdkApiClient = class {
|
|
|
365
370
|
};
|
|
366
371
|
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
367
372
|
var wdkApiClient = null;
|
|
368
|
-
function getWdkApiClient(baseUrl) {
|
|
373
|
+
function getWdkApiClient(baseUrl, authToken) {
|
|
369
374
|
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
370
375
|
wdkApiClient = new WdkApiClient({
|
|
371
|
-
baseUrl: baseUrl || DEFAULT_API_URL
|
|
376
|
+
baseUrl: baseUrl || DEFAULT_API_URL,
|
|
377
|
+
authToken
|
|
372
378
|
});
|
|
379
|
+
} else if (authToken !== void 0) {
|
|
380
|
+
wdkApiClient.setAuthToken(authToken);
|
|
373
381
|
}
|
|
374
382
|
return wdkApiClient;
|
|
375
383
|
}
|
|
@@ -1072,24 +1080,36 @@ __export(BrowserAddressDerivation_exports, {
|
|
|
1072
1080
|
generateSeedPhrase: () => generateSeedPhrase,
|
|
1073
1081
|
isValidSeed: () => isValidSeed
|
|
1074
1082
|
});
|
|
1083
|
+
|
|
1084
|
+
// src/config/networks.ts
|
|
1075
1085
|
var DERIVATION_PATHS = {
|
|
1076
|
-
|
|
1077
|
-
|
|
1086
|
+
bitcoin: "m/84'/0'/0'/0",
|
|
1087
|
+
ethereum: "m/44'/60'/0'/0",
|
|
1088
|
+
ton: "m/44'/607'/0'",
|
|
1089
|
+
tron: "m/44'/195'/0'/0",
|
|
1090
|
+
solana: "m/44'/501'/0'",
|
|
1091
|
+
spark: "m/44'/998'/0'/0"
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
// src/services/BrowserAddressDerivation.ts
|
|
1095
|
+
var DERIVATION_PATHS2 = {
|
|
1096
|
+
ethereum: `${DERIVATION_PATHS.ethereum}/0`,
|
|
1097
|
+
bitcoin_mainnet: `${DERIVATION_PATHS.bitcoin}/0`,
|
|
1078
1098
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
1079
|
-
ton:
|
|
1080
|
-
tron:
|
|
1081
|
-
solana:
|
|
1082
|
-
spark:
|
|
1099
|
+
ton: `${DERIVATION_PATHS.ton}/0'/0'`,
|
|
1100
|
+
tron: `${DERIVATION_PATHS.tron}/0`,
|
|
1101
|
+
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
1102
|
+
spark: `${DERIVATION_PATHS.spark}/0`
|
|
1083
1103
|
};
|
|
1084
1104
|
function deriveEthereumAddress(seed) {
|
|
1085
|
-
const hdNode = HDNodeWallet.fromPhrase(seed, void 0,
|
|
1105
|
+
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
1086
1106
|
return hdNode.address;
|
|
1087
1107
|
}
|
|
1088
1108
|
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
1089
1109
|
try {
|
|
1090
1110
|
const seedBytes = mnemonicToSeedSync(seed);
|
|
1091
1111
|
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
1092
|
-
const path = network === "testnet" ?
|
|
1112
|
+
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
1093
1113
|
const child = hdKey.derive(path);
|
|
1094
1114
|
if (!child.publicKey) {
|
|
1095
1115
|
throw new Error("Failed to derive public key");
|
|
@@ -1115,7 +1135,7 @@ async function deriveSolanaAddress(seed) {
|
|
|
1115
1135
|
]);
|
|
1116
1136
|
const bs58 = bs58Module.default || bs58Module;
|
|
1117
1137
|
const seedBytes = mnemonicToSeedSync(seed);
|
|
1118
|
-
const derived = ed25519.derivePath(
|
|
1138
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
1119
1139
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
1120
1140
|
return bs58.encode(keypair.publicKey);
|
|
1121
1141
|
} catch (error) {
|
|
@@ -1130,7 +1150,7 @@ async function deriveTonAddress(seed) {
|
|
|
1130
1150
|
import('tweetnacl')
|
|
1131
1151
|
]);
|
|
1132
1152
|
const seedBytes = mnemonicToSeedSync(seed);
|
|
1133
|
-
const derived = ed25519.derivePath(
|
|
1153
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
1134
1154
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
1135
1155
|
const publicKey = keypair.publicKey;
|
|
1136
1156
|
const workchain = 0;
|
|
@@ -1165,7 +1185,7 @@ function crc16(data) {
|
|
|
1165
1185
|
}
|
|
1166
1186
|
function deriveTronAddress(seed) {
|
|
1167
1187
|
try {
|
|
1168
|
-
const hdNode = HDNodeWallet.fromPhrase(seed, void 0,
|
|
1188
|
+
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
1169
1189
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
1170
1190
|
const addressBytes = new Uint8Array(21);
|
|
1171
1191
|
addressBytes[0] = 65;
|
|
@@ -1183,7 +1203,7 @@ function deriveSparkAddress(seed, network = "mainnet") {
|
|
|
1183
1203
|
try {
|
|
1184
1204
|
const seedBytes = mnemonicToSeedSync(seed);
|
|
1185
1205
|
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
1186
|
-
const child = hdKey.derive(
|
|
1206
|
+
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
1187
1207
|
if (!child.publicKey) {
|
|
1188
1208
|
throw new Error("Failed to derive public key");
|
|
1189
1209
|
}
|
|
@@ -1592,11 +1612,6 @@ var ZubariWdkService = class {
|
|
|
1592
1612
|
async sendTransaction(seed, chain, to, amount) {
|
|
1593
1613
|
await this.initialize();
|
|
1594
1614
|
const startTime = Date.now();
|
|
1595
|
-
console.log(`[ZubariWdkService] Sending ${chain} transaction`, {
|
|
1596
|
-
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
1597
|
-
amount,
|
|
1598
|
-
network: this.config.network
|
|
1599
|
-
});
|
|
1600
1615
|
try {
|
|
1601
1616
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1602
1617
|
method: "POST",
|
|
@@ -1616,10 +1631,6 @@ var ZubariWdkService = class {
|
|
|
1616
1631
|
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
1617
1632
|
}
|
|
1618
1633
|
}
|
|
1619
|
-
console.log(`[ZubariWdkService] ${chain} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
1620
|
-
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
1621
|
-
elapsed: `${elapsed}ms`
|
|
1622
|
-
});
|
|
1623
1634
|
if (!data.success) {
|
|
1624
1635
|
const errorCode2 = parseChainError(chain, data.error || "");
|
|
1625
1636
|
return {
|
|
@@ -1642,12 +1653,6 @@ var ZubariWdkService = class {
|
|
|
1642
1653
|
const errorData = await response.json().catch(() => ({}));
|
|
1643
1654
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
1644
1655
|
const errorCode = parseChainError(chain, errorMessage);
|
|
1645
|
-
console.error(`[ZubariWdkService] ${chain} transaction FAILED`, {
|
|
1646
|
-
status: response.status,
|
|
1647
|
-
error: errorMessage,
|
|
1648
|
-
errorCode,
|
|
1649
|
-
elapsed: `${elapsed}ms`
|
|
1650
|
-
});
|
|
1651
1656
|
return {
|
|
1652
1657
|
success: false,
|
|
1653
1658
|
error: errorMessage,
|
|
@@ -1655,14 +1660,8 @@ var ZubariWdkService = class {
|
|
|
1655
1660
|
chain
|
|
1656
1661
|
};
|
|
1657
1662
|
} catch (error) {
|
|
1658
|
-
const elapsed = Date.now() - startTime;
|
|
1659
1663
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
1660
1664
|
const errorCode = parseChainError(chain, errorMessage);
|
|
1661
|
-
console.error(`[ZubariWdkService] ${chain} transaction ERROR`, {
|
|
1662
|
-
error: errorMessage,
|
|
1663
|
-
errorCode,
|
|
1664
|
-
elapsed: `${elapsed}ms`
|
|
1665
|
-
});
|
|
1666
1665
|
return {
|
|
1667
1666
|
success: false,
|
|
1668
1667
|
error: errorMessage,
|
|
@@ -1708,15 +1707,22 @@ var ZubariWdkService = class {
|
|
|
1708
1707
|
// Private Helper Methods
|
|
1709
1708
|
// ==========================================
|
|
1710
1709
|
getDerivationPath(chain) {
|
|
1711
|
-
const
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1710
|
+
const basePath = DERIVATION_PATHS[chain];
|
|
1711
|
+
if (chain === "bitcoin" && this.config.network === "testnet") {
|
|
1712
|
+
return "m/84'/1'/0'/0/0";
|
|
1713
|
+
}
|
|
1714
|
+
switch (chain) {
|
|
1715
|
+
case "ton":
|
|
1716
|
+
return `${basePath}/0'/0'`;
|
|
1717
|
+
case "solana":
|
|
1718
|
+
return `${basePath}/0'`;
|
|
1719
|
+
case "bitcoin":
|
|
1720
|
+
case "ethereum":
|
|
1721
|
+
case "tron":
|
|
1722
|
+
case "spark":
|
|
1723
|
+
default:
|
|
1724
|
+
return `${basePath}/0`;
|
|
1725
|
+
}
|
|
1720
1726
|
}
|
|
1721
1727
|
getChainSymbol(chain) {
|
|
1722
1728
|
const symbols = {
|