@trustware/sdk-staging 1.1.9-staging.5 → 1.1.9-staging.7
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/LICENSE +5 -4
- package/README.md +32 -1
- package/THIRD_PARTY_NOTICES.md +118 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-CwT8Wd1x.d.ts → core-DzqVEWwP.d.ts} +3 -2
- package/dist/{core-Dy_rZl5y.d.cts → core-gNyi5xsp.d.cts} +3 -2
- package/dist/core.cjs +287 -75
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +287 -75
- package/dist/core.mjs.map +1 -1
- package/dist/{detect-d2PUaxE_.d.ts → detect-Cprq6X9o.d.ts} +1 -1
- package/dist/{detect-DVpECOTa.d.cts → detect-DWL4uExV.d.cts} +1 -1
- package/dist/index.cjs +685 -160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +936 -410
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-B5aklGtm.d.cts → manager-DWFNyouP.d.cts} +48 -20
- package/dist/{manager-xFiq0SHr.d.ts → manager-Dn4muk74.d.ts} +48 -20
- package/dist/smart-account.cjs +117 -39
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.mjs +117 -39
- package/dist/smart-account.mjs.map +1 -1
- package/dist/wallet.cjs +308 -72
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +6 -4
- package/dist/wallet.d.ts +6 -4
- package/dist/wallet.mjs +306 -72
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +650 -139
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +868 -355
- package/dist/widget.mjs.map +1 -1
- package/package.json +3 -2
package/dist/core.cjs
CHANGED
|
@@ -75,7 +75,7 @@ var init_constants = __esm({
|
|
|
75
75
|
"src/constants.ts"() {
|
|
76
76
|
"use strict";
|
|
77
77
|
SDK_NAME = "@trustware/sdk";
|
|
78
|
-
SDK_VERSION = "1.1.9-staging.
|
|
78
|
+
SDK_VERSION = "1.1.9-staging.7";
|
|
79
79
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
80
80
|
API_PREFIX = "/api";
|
|
81
81
|
WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
|
|
@@ -284,7 +284,9 @@ var init_chains = __esm({
|
|
|
284
284
|
btc: "bitcoin",
|
|
285
285
|
bitcoin: "bitcoin",
|
|
286
286
|
sei: "cosmos",
|
|
287
|
-
"pacific-1": "cosmos"
|
|
287
|
+
"pacific-1": "cosmos",
|
|
288
|
+
nibiru: "cosmos",
|
|
289
|
+
"cataclysm-1": "cosmos"
|
|
288
290
|
};
|
|
289
291
|
}
|
|
290
292
|
});
|
|
@@ -1480,16 +1482,23 @@ function validateEvmAddress(address) {
|
|
|
1480
1482
|
}
|
|
1481
1483
|
return { isValid: true };
|
|
1482
1484
|
}
|
|
1483
|
-
function
|
|
1485
|
+
function resolveCosmosBech32Prefix(chain) {
|
|
1486
|
+
const chainDef = typeof chain === "object" && chain ? chain : void 0;
|
|
1487
|
+
const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
|
|
1488
|
+
const normalized = String(identifier ?? "").trim().toLowerCase();
|
|
1489
|
+
return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
|
|
1490
|
+
}
|
|
1491
|
+
function validateCosmosAddress(address, chain) {
|
|
1484
1492
|
const trimmed = address.trim();
|
|
1485
|
-
|
|
1493
|
+
const prefix = resolveCosmosBech32Prefix(chain);
|
|
1494
|
+
if (prefix === "sei" && (0, import_viem.isAddress)(trimmed)) {
|
|
1486
1495
|
return { isValid: true };
|
|
1487
1496
|
}
|
|
1488
|
-
const result = validateBech32LikeAddress(trimmed,
|
|
1497
|
+
const result = validateBech32LikeAddress(trimmed, prefix);
|
|
1489
1498
|
if (result.isValid) return result;
|
|
1490
1499
|
return {
|
|
1491
1500
|
isValid: false,
|
|
1492
|
-
error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
|
|
1501
|
+
error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
|
|
1493
1502
|
};
|
|
1494
1503
|
}
|
|
1495
1504
|
function validateSolanaAddress(address) {
|
|
@@ -1539,15 +1548,12 @@ function validateAddressForChain(address, chain) {
|
|
|
1539
1548
|
case "bitcoin":
|
|
1540
1549
|
return validateBtcAddress(trimmed);
|
|
1541
1550
|
case "cosmos":
|
|
1542
|
-
|
|
1543
|
-
return validateSeiAddress(trimmed);
|
|
1544
|
-
}
|
|
1545
|
-
return validateBech32LikeAddress(trimmed, "sei");
|
|
1551
|
+
return validateCosmosAddress(trimmed, chainDef ?? chain);
|
|
1546
1552
|
default:
|
|
1547
1553
|
return { isValid: false, error: "Unsupported or unknown chain type." };
|
|
1548
1554
|
}
|
|
1549
1555
|
}
|
|
1550
|
-
function validateAddressForRouteChain(address, chainType) {
|
|
1556
|
+
function validateAddressForRouteChain(address, chainType, chainRef) {
|
|
1551
1557
|
switch (normalizeChainType(chainType)) {
|
|
1552
1558
|
case "evm":
|
|
1553
1559
|
return validateEvmAddress(address);
|
|
@@ -1556,7 +1562,7 @@ function validateAddressForRouteChain(address, chainType) {
|
|
|
1556
1562
|
case "bitcoin":
|
|
1557
1563
|
return validateBtcAddress(address);
|
|
1558
1564
|
case "cosmos":
|
|
1559
|
-
return
|
|
1565
|
+
return validateCosmosAddress(address, chainRef ?? chainType);
|
|
1560
1566
|
default:
|
|
1561
1567
|
return { isValid: false, error: "Unsupported chain type." };
|
|
1562
1568
|
}
|
|
@@ -1578,14 +1584,18 @@ function validateRouteAddresses(params) {
|
|
|
1578
1584
|
const normalizedDirection = params.direction?.trim().toLowerCase();
|
|
1579
1585
|
const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
|
|
1580
1586
|
if (isDepositFlow) {
|
|
1581
|
-
const fromResult2 = validateAddressForRouteChain(
|
|
1587
|
+
const fromResult2 = validateAddressForRouteChain(
|
|
1588
|
+
fromAddress,
|
|
1589
|
+
fromType,
|
|
1590
|
+
params.fromChain
|
|
1591
|
+
);
|
|
1582
1592
|
if (!fromResult2.isValid) {
|
|
1583
1593
|
return {
|
|
1584
1594
|
isValid: false,
|
|
1585
1595
|
error: `From address: ${fromResult2.error ?? "Invalid address."}`
|
|
1586
1596
|
};
|
|
1587
1597
|
}
|
|
1588
|
-
const toResult2 = toType === "cosmos" ?
|
|
1598
|
+
const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
|
|
1589
1599
|
if (!toResult2.isValid) {
|
|
1590
1600
|
return {
|
|
1591
1601
|
isValid: false,
|
|
@@ -1610,14 +1620,22 @@ function validateRouteAddresses(params) {
|
|
|
1610
1620
|
}
|
|
1611
1621
|
return { isValid: true };
|
|
1612
1622
|
}
|
|
1613
|
-
const fromResult = validateAddressForRouteChain(
|
|
1623
|
+
const fromResult = validateAddressForRouteChain(
|
|
1624
|
+
fromAddress,
|
|
1625
|
+
fromType,
|
|
1626
|
+
params.fromChain
|
|
1627
|
+
);
|
|
1614
1628
|
if (!fromResult.isValid) {
|
|
1615
1629
|
return {
|
|
1616
1630
|
isValid: false,
|
|
1617
1631
|
error: `From address: ${fromResult.error ?? "Invalid address."}`
|
|
1618
1632
|
};
|
|
1619
1633
|
}
|
|
1620
|
-
const toResult = validateAddressForRouteChain(
|
|
1634
|
+
const toResult = validateAddressForRouteChain(
|
|
1635
|
+
toAddress,
|
|
1636
|
+
toType,
|
|
1637
|
+
params.toChain
|
|
1638
|
+
);
|
|
1621
1639
|
if (!toResult.isValid) {
|
|
1622
1640
|
return {
|
|
1623
1641
|
isValid: false,
|
|
@@ -1626,7 +1644,7 @@ function validateRouteAddresses(params) {
|
|
|
1626
1644
|
}
|
|
1627
1645
|
return { isValid: true };
|
|
1628
1646
|
}
|
|
1629
|
-
var import_viem, BECH32_CHARSET;
|
|
1647
|
+
var import_viem, BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
|
|
1630
1648
|
var init_address = __esm({
|
|
1631
1649
|
"src/validation/address.ts"() {
|
|
1632
1650
|
"use strict";
|
|
@@ -1634,6 +1652,12 @@ var init_address = __esm({
|
|
|
1634
1652
|
init_index_node4();
|
|
1635
1653
|
init_chains();
|
|
1636
1654
|
BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
|
|
1655
|
+
COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
|
|
1656
|
+
"pacific-1": "sei",
|
|
1657
|
+
sei: "sei",
|
|
1658
|
+
"cataclysm-1": "nibi",
|
|
1659
|
+
nibiru: "nibi"
|
|
1660
|
+
};
|
|
1637
1661
|
}
|
|
1638
1662
|
});
|
|
1639
1663
|
|
|
@@ -2470,7 +2494,7 @@ var init_walletconnect = __esm({
|
|
|
2470
2494
|
solanaMainnet = {
|
|
2471
2495
|
id: 900,
|
|
2472
2496
|
chainNamespace: "solana",
|
|
2473
|
-
caipNetworkId: "solana:
|
|
2497
|
+
caipNetworkId: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
2474
2498
|
name: "Solana Mainnet",
|
|
2475
2499
|
nativeCurrency: {
|
|
2476
2500
|
name: "Solana",
|
|
@@ -3348,8 +3372,62 @@ function getChainMeta(chainId) {
|
|
|
3348
3372
|
rpcUrls: chain.rpcUrls.default.http
|
|
3349
3373
|
};
|
|
3350
3374
|
}
|
|
3351
|
-
|
|
3375
|
+
function extractSolanaAddress(connector) {
|
|
3376
|
+
const caipAccount = connector.provider.session?.namespaces?.solana?.accounts?.[0];
|
|
3377
|
+
if (!caipAccount) return null;
|
|
3378
|
+
return caipAccount.split(":")[2] ?? null;
|
|
3379
|
+
}
|
|
3380
|
+
function buildWalletConnectSolanaProvider(connector) {
|
|
3381
|
+
return {
|
|
3382
|
+
get publicKey() {
|
|
3383
|
+
const address = extractSolanaAddress(connector);
|
|
3384
|
+
return address ? { toString: () => address } : void 0;
|
|
3385
|
+
},
|
|
3386
|
+
async connect() {
|
|
3387
|
+
const address = extractSolanaAddress(connector);
|
|
3388
|
+
if (!address) {
|
|
3389
|
+
throw new Error(
|
|
3390
|
+
"This wallet did not approve a Solana account over WalletConnect."
|
|
3391
|
+
);
|
|
3392
|
+
}
|
|
3393
|
+
return { publicKey: { toString: () => address } };
|
|
3394
|
+
},
|
|
3395
|
+
async disconnect() {
|
|
3396
|
+
},
|
|
3397
|
+
async signTransaction(transaction) {
|
|
3398
|
+
const tx = transaction;
|
|
3399
|
+
const rawBytes = "version" in tx ? tx.serialize() : tx.serialize({
|
|
3400
|
+
requireAllSignatures: false,
|
|
3401
|
+
verifySignatures: false
|
|
3402
|
+
});
|
|
3403
|
+
const result = await connector.provider.request(
|
|
3404
|
+
{
|
|
3405
|
+
method: "solana_signTransaction",
|
|
3406
|
+
params: { transaction: encodeBase64(rawBytes) }
|
|
3407
|
+
},
|
|
3408
|
+
solanaMainnet.caipNetworkId
|
|
3409
|
+
);
|
|
3410
|
+
if (!result.transaction) {
|
|
3411
|
+
throw new Error(
|
|
3412
|
+
"WalletConnect wallet did not return a signed Solana transaction."
|
|
3413
|
+
);
|
|
3414
|
+
}
|
|
3415
|
+
const signedBytes = decodeBase64(result.transaction);
|
|
3416
|
+
return { serialize: () => signedBytes };
|
|
3417
|
+
},
|
|
3418
|
+
on() {
|
|
3419
|
+
},
|
|
3420
|
+
off() {
|
|
3421
|
+
},
|
|
3422
|
+
removeListener() {
|
|
3423
|
+
}
|
|
3424
|
+
};
|
|
3425
|
+
}
|
|
3426
|
+
async function buildWalletConnectAPI(walletCfg, ecosystem = "evm") {
|
|
3352
3427
|
const connector = await getUniversalConnector(walletCfg);
|
|
3428
|
+
if (ecosystem === "solana") {
|
|
3429
|
+
return toSolanaWalletInterface(buildWalletConnectSolanaProvider(connector));
|
|
3430
|
+
}
|
|
3353
3431
|
const provider = connector.provider;
|
|
3354
3432
|
const api = {
|
|
3355
3433
|
ecosystem: "evm",
|
|
@@ -3559,44 +3637,39 @@ var init_manager = __esm({
|
|
|
3559
3637
|
this.emit();
|
|
3560
3638
|
}
|
|
3561
3639
|
}
|
|
3562
|
-
async connectWalletConnect(walletCfg) {
|
|
3563
|
-
if (this._status === "connected" && this._connectedVia === "walletconnect" && this._wallet) {
|
|
3640
|
+
async connectWalletConnect(walletCfg, ecosystem = "evm") {
|
|
3641
|
+
if (this._status === "connected" && this._connectedVia === "walletconnect" && this._wallet && this._wallet.ecosystem === ecosystem) {
|
|
3564
3642
|
this.emit();
|
|
3565
3643
|
return { error: null, api: this._wallet };
|
|
3566
3644
|
}
|
|
3645
|
+
if (this._connectedVia === "walletconnect" && this._wallet) {
|
|
3646
|
+
await this._wallet.disconnect?.().catch(() => {
|
|
3647
|
+
});
|
|
3648
|
+
resetUniversalConnector();
|
|
3649
|
+
}
|
|
3567
3650
|
this._status = "connecting";
|
|
3568
3651
|
this.clearConnectedState();
|
|
3569
3652
|
this.emit();
|
|
3570
3653
|
try {
|
|
3571
3654
|
const connector = await getUniversalConnector(walletCfg);
|
|
3572
3655
|
await connector.connect();
|
|
3573
|
-
const api = await buildWalletConnectAPI(walletCfg);
|
|
3656
|
+
const api = await buildWalletConnectAPI(walletCfg, ecosystem);
|
|
3657
|
+
try {
|
|
3658
|
+
await api.getAddress();
|
|
3659
|
+
} catch {
|
|
3660
|
+
await api.disconnect?.().catch(() => {
|
|
3661
|
+
});
|
|
3662
|
+
resetUniversalConnector();
|
|
3663
|
+
throw new Error(
|
|
3664
|
+
`This wallet did not approve a${ecosystem === "evm" ? "n" : ""} ${ecosystem === "evm" ? "EVM" : "Solana"} account over WalletConnect.`
|
|
3665
|
+
);
|
|
3666
|
+
}
|
|
3574
3667
|
this._wallet = api;
|
|
3575
3668
|
this._connectedVia = "walletconnect";
|
|
3576
3669
|
this._connectedWalletId = "walletconnect";
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
if (accounts.length === 0) {
|
|
3581
|
-
this.fullReset();
|
|
3582
|
-
this.triggerExternalDisconnect();
|
|
3583
|
-
this.emit();
|
|
3584
|
-
return;
|
|
3585
|
-
}
|
|
3586
|
-
void this.syncIdentityFromWallet("walletconnect");
|
|
3587
|
-
this.emit();
|
|
3588
|
-
},
|
|
3589
|
-
onChainChanged: () => {
|
|
3590
|
-
void this.syncIdentityFromWallet("walletconnect");
|
|
3591
|
-
this.emit();
|
|
3592
|
-
},
|
|
3593
|
-
onDisconnect: () => {
|
|
3594
|
-
this.fullReset();
|
|
3595
|
-
resetUniversalConnector();
|
|
3596
|
-
this.triggerExternalDisconnect();
|
|
3597
|
-
this.emit();
|
|
3598
|
-
}
|
|
3599
|
-
});
|
|
3670
|
+
this._providerCleanup = this.bindWalletConnectProviderEvents(
|
|
3671
|
+
connector.provider
|
|
3672
|
+
);
|
|
3600
3673
|
await this.syncIdentityFromWallet("walletconnect");
|
|
3601
3674
|
this._status = "connected";
|
|
3602
3675
|
this._error = null;
|
|
@@ -3611,6 +3684,100 @@ var init_manager = __esm({
|
|
|
3611
3684
|
return { error: message, api: null };
|
|
3612
3685
|
}
|
|
3613
3686
|
}
|
|
3687
|
+
bindWalletConnectProviderEvents(provider) {
|
|
3688
|
+
return bindWalletConnectEvents(provider, {
|
|
3689
|
+
onAccountsChanged: (accounts) => {
|
|
3690
|
+
if (accounts.length === 0) {
|
|
3691
|
+
this.fullReset();
|
|
3692
|
+
this.triggerExternalDisconnect();
|
|
3693
|
+
this.emit();
|
|
3694
|
+
return;
|
|
3695
|
+
}
|
|
3696
|
+
void this.syncIdentityFromWallet("walletconnect");
|
|
3697
|
+
this.emit();
|
|
3698
|
+
},
|
|
3699
|
+
onChainChanged: () => {
|
|
3700
|
+
void this.syncIdentityFromWallet("walletconnect");
|
|
3701
|
+
this.emit();
|
|
3702
|
+
},
|
|
3703
|
+
onDisconnect: () => {
|
|
3704
|
+
this.fullReset();
|
|
3705
|
+
resetUniversalConnector();
|
|
3706
|
+
this.triggerExternalDisconnect();
|
|
3707
|
+
this.emit();
|
|
3708
|
+
}
|
|
3709
|
+
});
|
|
3710
|
+
}
|
|
3711
|
+
// WalletConnect's own SignClient auto-restores the last persisted session
|
|
3712
|
+
// from storage on every init — including after a fresh page load — but
|
|
3713
|
+
// that restoration happens silently inside the library. Nothing calls back
|
|
3714
|
+
// into our code for it. On mobile, backgrounding the tab to approve in a
|
|
3715
|
+
// wallet app can cause the OS to reload the page before the original
|
|
3716
|
+
// connect() promise ever resolves, so the connect flow that triggered the
|
|
3717
|
+
// approval never gets to record it as "connected" here — even though
|
|
3718
|
+
// WalletConnect itself already has a live, approved session sitting in
|
|
3719
|
+
// storage. Call this on mount to pick that back up.
|
|
3720
|
+
async restoreWalletConnectSession(walletCfg) {
|
|
3721
|
+
if (this._status === "connected" && this._connectedVia === "walletconnect") {
|
|
3722
|
+
return this._wallet?.ecosystem === "solana" ? "solana" : "evm";
|
|
3723
|
+
}
|
|
3724
|
+
if (typeof window === "undefined") return null;
|
|
3725
|
+
try {
|
|
3726
|
+
if (!Object.keys(window.localStorage).some((key) => key.startsWith("wc@2"))) {
|
|
3727
|
+
return null;
|
|
3728
|
+
}
|
|
3729
|
+
} catch {
|
|
3730
|
+
}
|
|
3731
|
+
let connector;
|
|
3732
|
+
try {
|
|
3733
|
+
connector = await getUniversalConnector(walletCfg);
|
|
3734
|
+
} catch (e2) {
|
|
3735
|
+
console.warn(
|
|
3736
|
+
"[Trustware SDK] Failed to restore WalletConnect session:",
|
|
3737
|
+
e2
|
|
3738
|
+
);
|
|
3739
|
+
return null;
|
|
3740
|
+
}
|
|
3741
|
+
const session = connector.provider.session;
|
|
3742
|
+
if (!session) return null;
|
|
3743
|
+
const ecosystem = session.namespaces?.solana?.accounts?.length ? "solana" : session.namespaces?.eip155?.accounts?.length ? "evm" : null;
|
|
3744
|
+
if (!ecosystem) return null;
|
|
3745
|
+
try {
|
|
3746
|
+
const api = await buildWalletConnectAPI(walletCfg, ecosystem);
|
|
3747
|
+
this._wallet = api;
|
|
3748
|
+
this._connectedVia = "walletconnect";
|
|
3749
|
+
this._connectedWalletId = "walletconnect";
|
|
3750
|
+
this._providerCleanup = this.bindWalletConnectProviderEvents(
|
|
3751
|
+
connector.provider
|
|
3752
|
+
);
|
|
3753
|
+
await this.syncIdentityFromWallet("walletconnect");
|
|
3754
|
+
this._status = "connected";
|
|
3755
|
+
this._error = null;
|
|
3756
|
+
this.emit();
|
|
3757
|
+
return ecosystem;
|
|
3758
|
+
} catch {
|
|
3759
|
+
return null;
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
// Forcibly abandon an in-progress connect() call the caller has decided is
|
|
3763
|
+
// stuck (e.g. the UI's own connect timeout elapsed with no response).
|
|
3764
|
+
// There's no clean way to cancel a pending WalletConnect pairing proposal
|
|
3765
|
+
// from this side, so this tears down the whole connector — the next
|
|
3766
|
+
// connect attempt starts against a brand new SignClient/pairing instead of
|
|
3767
|
+
// racing the abandoned one, which would otherwise risk reproducing the
|
|
3768
|
+
// "No matching key. proposal" class of error a real retry needs to avoid.
|
|
3769
|
+
cancelWalletConnectAttempt() {
|
|
3770
|
+
if (this._connectedVia === "walletconnect" && this._status === "connected") {
|
|
3771
|
+
return;
|
|
3772
|
+
}
|
|
3773
|
+
resetUniversalConnector();
|
|
3774
|
+
if (this._status === "connecting") {
|
|
3775
|
+
this.clearConnectedState();
|
|
3776
|
+
this._status = "idle";
|
|
3777
|
+
this._error = null;
|
|
3778
|
+
this.emit();
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3614
3781
|
async disconnect(wagmi) {
|
|
3615
3782
|
if (wagmi && this._connectedVia === "extension") {
|
|
3616
3783
|
await wagmi.disconnect().catch(() => {
|
|
@@ -3858,7 +4025,7 @@ async function buildDepositAddress(body, signal) {
|
|
|
3858
4025
|
route
|
|
3859
4026
|
};
|
|
3860
4027
|
}
|
|
3861
|
-
async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
|
|
4028
|
+
async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
|
|
3862
4029
|
const r = await rateLimitedFetch(
|
|
3863
4030
|
`${apiBase()}/v1/route-intent/${intentId}/receipt`,
|
|
3864
4031
|
{
|
|
@@ -3866,7 +4033,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
|
|
|
3866
4033
|
headers: jsonHeaders({ "Idempotency-Key": txHash }),
|
|
3867
4034
|
body: JSON.stringify({
|
|
3868
4035
|
txHash,
|
|
3869
|
-
...sponsorshipRequestId ? { sponsorshipRequestId } : {}
|
|
4036
|
+
...sponsorshipRequestId ? { sponsorshipRequestId } : {},
|
|
4037
|
+
...eoaAddress ? { eoaAddress } : {}
|
|
3870
4038
|
})
|
|
3871
4039
|
}
|
|
3872
4040
|
);
|
|
@@ -3988,7 +4156,9 @@ var init_chainHelpers = __esm({
|
|
|
3988
4156
|
btc: "bitcoin",
|
|
3989
4157
|
bitcoin: "bitcoin",
|
|
3990
4158
|
sei: "cosmos",
|
|
3991
|
-
"pacific-1": "cosmos"
|
|
4159
|
+
"pacific-1": "cosmos",
|
|
4160
|
+
nibiru: "cosmos",
|
|
4161
|
+
"cataclysm-1": "cosmos"
|
|
3992
4162
|
};
|
|
3993
4163
|
SEI_EVM_CHAIN_ID = "1329";
|
|
3994
4164
|
SEI_COSMOS_CHAIN_ID = "pacific-1";
|
|
@@ -4142,7 +4312,8 @@ function filterSupportedChains(chains) {
|
|
|
4142
4312
|
}
|
|
4143
4313
|
if (chainType === "cosmos") {
|
|
4144
4314
|
const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
|
|
4145
|
-
|
|
4315
|
+
const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
|
|
4316
|
+
if (seiKey !== "sei" && !isNibiru) {
|
|
4146
4317
|
return false;
|
|
4147
4318
|
}
|
|
4148
4319
|
}
|
|
@@ -4242,7 +4413,7 @@ function useChains() {
|
|
|
4242
4413
|
error
|
|
4243
4414
|
};
|
|
4244
4415
|
}
|
|
4245
|
-
var import_react2, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
|
|
4416
|
+
var import_react2, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
|
|
4246
4417
|
var init_useChains = __esm({
|
|
4247
4418
|
"src/core/useChains.ts"() {
|
|
4248
4419
|
"use strict";
|
|
@@ -4253,6 +4424,7 @@ var init_useChains = __esm({
|
|
|
4253
4424
|
init_popularChains();
|
|
4254
4425
|
POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
|
|
4255
4426
|
POPULAR_LIMIT = popularChains_default.popularLimit;
|
|
4427
|
+
NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
|
|
4256
4428
|
}
|
|
4257
4429
|
});
|
|
4258
4430
|
|
|
@@ -6037,46 +6209,80 @@ function normalizeSlippage(v) {
|
|
|
6037
6209
|
if (n > 5) return 5;
|
|
6038
6210
|
return n;
|
|
6039
6211
|
}
|
|
6212
|
+
function warnDeprecatedSwapModeFlag() {
|
|
6213
|
+
if (hasWarnedDeprecatedSwapModeFlag) return;
|
|
6214
|
+
hasWarnedDeprecatedSwapModeFlag = true;
|
|
6215
|
+
console.warn(
|
|
6216
|
+
'[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
|
|
6217
|
+
);
|
|
6218
|
+
}
|
|
6219
|
+
function resolveMode(input) {
|
|
6220
|
+
if (input.mode === "swap") return "swap";
|
|
6221
|
+
if (input.mode === "deposit") return "deposit";
|
|
6222
|
+
if (input.features?.swapMode) {
|
|
6223
|
+
warnDeprecatedSwapModeFlag();
|
|
6224
|
+
return "swap";
|
|
6225
|
+
}
|
|
6226
|
+
return "deposit";
|
|
6227
|
+
}
|
|
6040
6228
|
function resolveConfig(input) {
|
|
6041
6229
|
if (!input?.apiKey) {
|
|
6042
|
-
throw new
|
|
6230
|
+
throw new TrustwareError({
|
|
6231
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
6232
|
+
message: "TrustwareConfig: 'apiKey' is required.",
|
|
6233
|
+
userMessage: "Missing required API key configuration."
|
|
6234
|
+
});
|
|
6043
6235
|
}
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6236
|
+
const mode = resolveMode(input);
|
|
6237
|
+
if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
|
|
6238
|
+
throw new TrustwareError({
|
|
6239
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
6240
|
+
message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
|
|
6241
|
+
userMessage: "Missing required destination chain/token configuration."
|
|
6242
|
+
});
|
|
6048
6243
|
}
|
|
6049
|
-
const toChain = input.routes
|
|
6050
|
-
if (input.routes
|
|
6244
|
+
const toChain = input.routes?.toChain;
|
|
6245
|
+
if (input.routes?.toAddress && toChain) {
|
|
6051
6246
|
const result = validateAddressForChain(input.routes.toAddress, toChain);
|
|
6052
6247
|
if (!result.isValid) {
|
|
6053
6248
|
console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
|
|
6054
|
-
throw new
|
|
6249
|
+
throw new TrustwareError({
|
|
6250
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
6251
|
+
message: `Invalid toAddress: ${result.error}`,
|
|
6252
|
+
userMessage: "The configured destination address is invalid."
|
|
6253
|
+
});
|
|
6055
6254
|
}
|
|
6056
6255
|
}
|
|
6057
|
-
if (input.routes
|
|
6058
|
-
const
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6256
|
+
if (input.routes?.fromAddress) {
|
|
6257
|
+
const fromChain = input.routes.fromChain ?? toChain;
|
|
6258
|
+
if (fromChain) {
|
|
6259
|
+
const result = validateAddressForChain(
|
|
6260
|
+
input.routes.fromAddress,
|
|
6261
|
+
fromChain
|
|
6262
|
+
);
|
|
6263
|
+
if (!result.isValid) {
|
|
6264
|
+
console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
|
|
6265
|
+
throw new TrustwareError({
|
|
6266
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
6267
|
+
message: `Invalid fromAddress: ${result.error}`,
|
|
6268
|
+
userMessage: "The configured source address is invalid."
|
|
6269
|
+
});
|
|
6270
|
+
}
|
|
6065
6271
|
}
|
|
6066
6272
|
}
|
|
6067
6273
|
const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
|
|
6068
6274
|
const routes = {
|
|
6069
|
-
toChain: input.routes
|
|
6070
|
-
toToken: input.routes
|
|
6071
|
-
fromToken: input.routes
|
|
6072
|
-
fromAddress: input.routes
|
|
6073
|
-
fromChain: input.routes
|
|
6074
|
-
toAddress: input.routes
|
|
6275
|
+
toChain: input.routes?.toChain ?? "",
|
|
6276
|
+
toToken: input.routes?.toToken ?? "",
|
|
6277
|
+
fromToken: input.routes?.fromToken,
|
|
6278
|
+
fromAddress: input.routes?.fromAddress,
|
|
6279
|
+
fromChain: input.routes?.fromChain,
|
|
6280
|
+
toAddress: input.routes?.toAddress,
|
|
6075
6281
|
defaultSlippage: normalizeSlippage(
|
|
6076
|
-
input.routes
|
|
6282
|
+
input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
|
|
6077
6283
|
),
|
|
6078
6284
|
options: {
|
|
6079
|
-
...input.routes
|
|
6285
|
+
...input.routes?.options
|
|
6080
6286
|
}
|
|
6081
6287
|
};
|
|
6082
6288
|
const theme = input.theme ?? "system";
|
|
@@ -6095,13 +6301,16 @@ function resolveConfig(input) {
|
|
|
6095
6301
|
tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
|
|
6096
6302
|
balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
|
|
6097
6303
|
shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
|
|
6098
|
-
|
|
6304
|
+
// Always mirrors the canonical `mode`, however the caller set it (new `mode` field
|
|
6305
|
+
// or the deprecated `features.swapMode` flag).
|
|
6306
|
+
swapMode: mode === "swap",
|
|
6099
6307
|
swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
|
|
6100
6308
|
swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
|
|
6101
6309
|
swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
|
|
6102
6310
|
};
|
|
6103
6311
|
return {
|
|
6104
6312
|
apiKey: input.apiKey,
|
|
6313
|
+
mode,
|
|
6105
6314
|
routes,
|
|
6106
6315
|
autoDetectProvider,
|
|
6107
6316
|
theme,
|
|
@@ -6114,12 +6323,15 @@ function resolveConfig(input) {
|
|
|
6114
6323
|
onEvent: input.onEvent
|
|
6115
6324
|
};
|
|
6116
6325
|
}
|
|
6326
|
+
var hasWarnedDeprecatedSwapModeFlag;
|
|
6117
6327
|
var init_merge = __esm({
|
|
6118
6328
|
"src/config/merge.ts"() {
|
|
6119
6329
|
"use strict";
|
|
6120
6330
|
init_defaults();
|
|
6121
6331
|
init_config();
|
|
6122
6332
|
init_index();
|
|
6333
|
+
init_TrustwareError();
|
|
6334
|
+
hasWarnedDeprecatedSwapModeFlag = false;
|
|
6123
6335
|
}
|
|
6124
6336
|
});
|
|
6125
6337
|
|