@trustware/sdk-staging 1.1.8-staging.5 → 1.1.8-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/dist/wallet.cjs CHANGED
@@ -250,7 +250,7 @@ var init_constants = __esm({
250
250
  "src/constants.ts"() {
251
251
  "use strict";
252
252
  SDK_NAME = "@trustware/sdk";
253
- SDK_VERSION = "1.1.8-staging.5";
253
+ SDK_VERSION = "1.1.8-staging.7";
254
254
  API_ROOT = "https://bv-staging-api.trustware.io";
255
255
  API_PREFIX = "/api";
256
256
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -259,20 +259,12 @@ var init_constants = __esm({
259
259
  });
260
260
 
261
261
  // src/config/defaults.ts
262
- var DEFAULT_SLIPPAGE, DEFAULT_AUTO_DETECT_PROVIDER, DEFAULT_THEME, DEFAULT_MESSAGES;
262
+ var DEFAULT_SLIPPAGE, DEFAULT_AUTO_DETECT_PROVIDER, DEFAULT_MESSAGES;
263
263
  var init_defaults = __esm({
264
264
  "src/config/defaults.ts"() {
265
265
  "use strict";
266
266
  DEFAULT_SLIPPAGE = 1;
267
267
  DEFAULT_AUTO_DETECT_PROVIDER = false;
268
- DEFAULT_THEME = {
269
- primaryColor: "#4F46E5",
270
- secondaryColor: "#6366F1",
271
- backgroundColor: "#FFFFFF",
272
- textColor: "#111827",
273
- borderColor: "#E5E7EB",
274
- radius: 8
275
- };
276
268
  DEFAULT_MESSAGES = {
277
269
  title: "Trustware SDK",
278
270
  description: "Seamlessly bridge assets across chains with Trustware."
@@ -332,10 +324,7 @@ var init_store = __esm({
332
324
  ...this._cfg,
333
325
  ...patch,
334
326
  routes: { ...this._cfg.routes, ...patch.routes ?? {} },
335
- theme: {
336
- ...this._cfg.theme,
337
- ...patch.theme ?? {}
338
- },
327
+ theme: patch.theme ?? this._cfg.theme,
339
328
  messages: {
340
329
  ...this._cfg.messages,
341
330
  ...patch.messages ?? {}
@@ -1398,6 +1387,7 @@ var init_metadata = __esm({
1398
1387
  "rainbow",
1399
1388
  "phantom-evm",
1400
1389
  "phantom-solana",
1390
+ "metamask-solana",
1401
1391
  "solflare",
1402
1392
  "okx",
1403
1393
  "brave",
@@ -1477,6 +1467,15 @@ var init_metadata = __esm({
1477
1467
  ios: "https://apps.apple.com/app/phantom-crypto-wallet/id1598432977",
1478
1468
  deepLink: (url) => `phantom://browse/${encodeURIComponent(url)}`
1479
1469
  },
1470
+ {
1471
+ id: "metamask-solana",
1472
+ name: "MetaMask (Solana)",
1473
+ category: "injected",
1474
+ ecosystem: "solana",
1475
+ logo: `${ASSETS_BASE_URL}/assets/wallets/metamask.svg`,
1476
+ emoji: "\u{1F98A}",
1477
+ homepage: "https://metamask.io/"
1478
+ },
1480
1479
  {
1481
1480
  id: "solflare",
1482
1481
  name: "Solflare",
@@ -3452,7 +3451,7 @@ function resolveConfig(input) {
3452
3451
  ...input.routes.options
3453
3452
  }
3454
3453
  };
3455
- const theme = deepMerge(DEFAULT_THEME, input.theme);
3454
+ const theme = input.theme ?? "system";
3456
3455
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
3457
3456
  const retry = {
3458
3457
  autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
@@ -3673,6 +3672,134 @@ var init_sdkRpc = __esm({
3673
3672
  });
3674
3673
 
3675
3674
  // src/wallets/solana.ts
3675
+ function encodeBase58(bytes) {
3676
+ const digits = [0];
3677
+ for (const byte of bytes) {
3678
+ let carry = byte;
3679
+ for (let i = 0; i < digits.length; i++) {
3680
+ carry += digits[i] << 8;
3681
+ digits[i] = carry % 58;
3682
+ carry = carry / 58 | 0;
3683
+ }
3684
+ while (carry > 0) {
3685
+ digits.push(carry % 58);
3686
+ carry = carry / 58 | 0;
3687
+ }
3688
+ }
3689
+ let result = "";
3690
+ for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
3691
+ result += "1";
3692
+ }
3693
+ for (let i = digits.length - 1; i >= 0; i--) {
3694
+ result += BASE58_ALPHABET[digits[i]];
3695
+ }
3696
+ return result;
3697
+ }
3698
+ function collectWalletStandardWallets() {
3699
+ if (typeof window === "undefined") return [];
3700
+ const collected = [];
3701
+ const api = {
3702
+ register(...wallets) {
3703
+ collected.push(...wallets);
3704
+ return () => {
3705
+ };
3706
+ }
3707
+ };
3708
+ try {
3709
+ window.dispatchEvent(
3710
+ Object.assign(
3711
+ new Event("wallet-standard:app-ready", { bubbles: false }),
3712
+ {
3713
+ detail: api
3714
+ }
3715
+ )
3716
+ );
3717
+ } catch {
3718
+ }
3719
+ return collected;
3720
+ }
3721
+ function walletStandardToSolanaProvider(wallet) {
3722
+ let currentAccount = wallet.accounts[0] ?? null;
3723
+ const provider = {
3724
+ get isConnected() {
3725
+ return !!currentAccount;
3726
+ },
3727
+ get publicKey() {
3728
+ if (!currentAccount) return void 0;
3729
+ const addr = currentAccount.address;
3730
+ return { toString: () => addr };
3731
+ },
3732
+ async connect() {
3733
+ const feature = wallet.features["standard:connect"];
3734
+ if (!feature?.connect)
3735
+ throw new Error("Wallet Standard connect not available");
3736
+ const result = await feature.connect({ silent: false });
3737
+ currentAccount = result.accounts[0] ?? null;
3738
+ if (!currentAccount)
3739
+ throw new Error("No Solana account returned from MetaMask");
3740
+ return { publicKey: { toString: () => currentAccount.address } };
3741
+ },
3742
+ async disconnect() {
3743
+ const feature = wallet.features["standard:disconnect"];
3744
+ await feature?.disconnect?.();
3745
+ currentAccount = null;
3746
+ },
3747
+ async signAndSendTransaction(transaction, options) {
3748
+ const feature = wallet.features["solana:signAndSendTransaction"];
3749
+ if (!feature?.signAndSendTransaction || !currentAccount) {
3750
+ throw new Error("signAndSendTransaction not available");
3751
+ }
3752
+ const txBytes = transaction.serialize();
3753
+ const results = await feature.signAndSendTransaction({
3754
+ account: currentAccount,
3755
+ transaction: txBytes,
3756
+ chain: SOLANA_MAINNET_CHAIN,
3757
+ options
3758
+ });
3759
+ const sig = results[0]?.signature;
3760
+ if (!sig) throw new Error("No signature returned");
3761
+ return typeof sig === "string" ? sig : encodeBase58(sig);
3762
+ },
3763
+ async signTransaction(transaction) {
3764
+ const feature = wallet.features["solana:signTransaction"];
3765
+ if (!feature?.signTransaction || !currentAccount) {
3766
+ throw new Error("signTransaction not available");
3767
+ }
3768
+ const txBytes = transaction.serialize();
3769
+ const results = await feature.signTransaction({
3770
+ account: currentAccount,
3771
+ transaction: txBytes,
3772
+ chain: SOLANA_MAINNET_CHAIN
3773
+ });
3774
+ const signed = results[0]?.signedTransaction;
3775
+ if (!signed) throw new Error("No signed transaction returned");
3776
+ return { serialize: () => signed };
3777
+ },
3778
+ on() {
3779
+ },
3780
+ off() {
3781
+ },
3782
+ removeListener() {
3783
+ }
3784
+ };
3785
+ return provider;
3786
+ }
3787
+ function detectMetaMaskSolanaWallet(wallets) {
3788
+ const meta = wallets.find((w) => w.id === "metamask-solana");
3789
+ if (!meta) return [];
3790
+ const standardWallets = collectWalletStandardWallets();
3791
+ const mmWallet = standardWallets.find(
3792
+ (w) => w.name.toLowerCase().includes("metamask") && w.chains.some((c) => c.startsWith("solana:"))
3793
+ );
3794
+ if (!mmWallet) return [];
3795
+ return [
3796
+ {
3797
+ meta,
3798
+ provider: walletStandardToSolanaProvider(mmWallet),
3799
+ via: "solana-window"
3800
+ }
3801
+ ];
3802
+ }
3676
3803
  function getPublicKeyString(provider) {
3677
3804
  const publicKey = provider?.publicKey;
3678
3805
  if (!publicKey) return null;
@@ -3734,12 +3861,13 @@ function getSolanaProviders() {
3734
3861
  }
3735
3862
  function detectSolanaWallets(wallets) {
3736
3863
  const providers = getSolanaProviders();
3737
- return SOLANA_WALLET_IDS.flatMap((walletId) => {
3864
+ const windowDetected = SOLANA_WALLET_IDS.flatMap((walletId) => {
3738
3865
  const provider = providers[walletId];
3739
3866
  const meta = wallets.find((item) => item.id === walletId);
3740
3867
  if (!provider || !meta) return [];
3741
3868
  return [{ meta, provider, via: "solana-window" }];
3742
3869
  });
3870
+ return [...windowDetected, ...detectMetaMaskSolanaWallet(wallets)];
3743
3871
  }
3744
3872
  function bindSolanaProviderEvents(provider, handlers) {
3745
3873
  const onConnect = () => handlers.onConnect?.();
@@ -3804,7 +3932,7 @@ function toSolanaWalletInterface(provider) {
3804
3932
  }
3805
3933
  };
3806
3934
  }
3807
- var SOLANA_WALLET_IDS;
3935
+ var SOLANA_WALLET_IDS, SOLANA_MAINNET_CHAIN, BASE58_ALPHABET;
3808
3936
  var init_solana = __esm({
3809
3937
  "src/wallets/solana.ts"() {
3810
3938
  "use strict";
@@ -3814,6 +3942,8 @@ var init_solana = __esm({
3814
3942
  "solflare",
3815
3943
  "backpack"
3816
3944
  ];
3945
+ SOLANA_MAINNET_CHAIN = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
3946
+ BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
3817
3947
  }
3818
3948
  });
3819
3949