@swapkit/wallets 4.0.0-beta.51 → 4.0.0-beta.52

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 (53) hide show
  1. package/dist/chunk-bk58smyr.js +4 -0
  2. package/dist/chunk-bk58smyr.js.map +10 -0
  3. package/dist/chunk-htvthkj1.js +5 -0
  4. package/dist/chunk-htvthkj1.js.map +10 -0
  5. package/dist/src/bitget/index.js +1 -1
  6. package/dist/src/coinbase/index.js +1 -1
  7. package/dist/src/ctrl/index.js +1 -1
  8. package/dist/src/evm-extensions/index.js +1 -1
  9. package/dist/src/exodus/index.js +1 -1
  10. package/dist/src/index.cjs +2 -2
  11. package/dist/src/index.cjs.map +1 -1
  12. package/dist/src/index.js +2 -2
  13. package/dist/src/index.js.map +1 -1
  14. package/dist/src/keepkey/index.cjs +2 -2
  15. package/dist/src/keepkey/index.cjs.map +4 -4
  16. package/dist/src/keepkey/index.js +2 -2
  17. package/dist/src/keepkey/index.js.map +4 -4
  18. package/dist/src/keepkey-bex/index.js +1 -1
  19. package/dist/src/keystore/index.js +1 -1
  20. package/dist/src/ledger/index.cjs +3 -3
  21. package/dist/src/ledger/index.cjs.map +4 -4
  22. package/dist/src/ledger/index.js +3 -3
  23. package/dist/src/ledger/index.js.map +4 -4
  24. package/dist/src/okx/index.js +1 -1
  25. package/dist/src/onekey/index.js +1 -1
  26. package/dist/src/phantom/index.js +1 -1
  27. package/dist/src/polkadotjs/index.js +1 -1
  28. package/dist/src/radix/index.js +1 -1
  29. package/dist/src/talisman/index.js +1 -1
  30. package/dist/src/trezor/index.js +1 -1
  31. package/dist/src/vultisig/index.cjs +4 -0
  32. package/dist/src/vultisig/index.cjs.map +11 -0
  33. package/dist/src/vultisig/index.js +4 -0
  34. package/dist/src/vultisig/index.js.map +11 -0
  35. package/dist/src/walletconnect/index.cjs +2 -2
  36. package/dist/src/walletconnect/index.cjs.map +3 -3
  37. package/dist/src/walletconnect/index.js +2 -2
  38. package/dist/src/walletconnect/index.js.map +3 -3
  39. package/dist/src/xaman/index.js +1 -1
  40. package/package.json +8 -3
  41. package/src/keepkey/chains/mayachain.ts +2 -1
  42. package/src/keepkey/chains/thorchain.ts +2 -1
  43. package/src/ledger/clients/cosmos.ts +8 -2
  44. package/src/ledger/index.ts +4 -1
  45. package/src/types.ts +32 -0
  46. package/src/utils.ts +1 -0
  47. package/src/vultisig/index.ts +199 -0
  48. package/src/vultisig/walletHelpers.ts +359 -0
  49. package/src/walletconnect/index.ts +8 -2
  50. package/dist/chunk-f0qkch7f.js +0 -4
  51. package/dist/chunk-f0qkch7f.js.map +0 -10
  52. package/dist/chunk-v7ytzdp4.js +0 -5
  53. package/dist/chunk-v7ytzdp4.js.map +0 -10
@@ -191,7 +191,10 @@ async function getWalletMethods({
191
191
  case Chain.THORChain: {
192
192
  const { SignMode } = await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js");
193
193
  const { TxRaw } = await import("cosmjs-types/cosmos/tx/v1beta1/tx.js");
194
- const { encodePubkey, makeAuthInfoBytes } = (await import("@cosmjs/proto-signing")).default;
194
+ const importedSigning = await import("@cosmjs/proto-signing");
195
+ const encodePubkey = importedSigning.encodePubkey ?? importedSigning.default?.encodePubkey;
196
+ const makeAuthInfoBytes =
197
+ importedSigning.makeAuthInfoBytes ?? importedSigning.default?.makeAuthInfoBytes;
195
198
  const {
196
199
  createStargateClient,
197
200
  buildEncodedTxBody,
package/src/types.ts CHANGED
@@ -29,9 +29,22 @@ import type { polkadotWallet } from "./polkadotjs";
29
29
  import type { radixWallet } from "./radix";
30
30
  import type { talismanWallet } from "./talisman";
31
31
  import type { trezorWallet } from "./trezor";
32
+ import type { vultisigWallet } from "./vultisig";
32
33
  import type { walletconnectWallet } from "./walletconnect";
33
34
  import type { xamanWallet } from "./xaman";
34
35
 
36
+ export type Callback = (
37
+ error: Error | null,
38
+ result?: any, // https://github.com/vultisig/vultisig-windows/blob/baeb3e8099a0003404f9664c43b0183c26029041/clients/extension/src/utils/interfaces.ts#L11
39
+ ) => void;
40
+
41
+ export type VultisigCosmosProvider = {
42
+ request(
43
+ request: { method: string; params?: any[] | Record<string, any> },
44
+ callback?: Callback,
45
+ ): Promise<any>;
46
+ };
47
+
35
48
  export type SKWallets = {
36
49
  [WalletOption.BITGET]: typeof bitgetWallet;
37
50
  [WalletOption.BRAVE]: typeof evmWallet;
@@ -58,6 +71,7 @@ export type SKWallets = {
58
71
  [WalletOption.TALISMAN]: typeof talismanWallet;
59
72
  [WalletOption.TREZOR]: typeof trezorWallet;
60
73
  [WalletOption.TRUSTWALLET_WEB]: typeof evmWallet;
74
+ [WalletOption.VULTISIG]: typeof vultisigWallet;
61
75
  [WalletOption.WALLETCONNECT]: typeof walletconnectWallet;
62
76
  [WalletOption.XAMAN]: typeof xamanWallet;
63
77
  };
@@ -90,6 +104,7 @@ export type SKWalletsSupportedChains = {
90
104
  [WalletOption.TALISMAN]: typeof talismanWallet.connectTalisman.supportedChains;
91
105
  [WalletOption.TREZOR]: typeof trezorWallet.connectTrezor.supportedChains;
92
106
  [WalletOption.TRUSTWALLET_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
107
+ [WalletOption.VULTISIG]: typeof vultisigWallet.connectVultisig.supportedChains;
93
108
  [WalletOption.WALLETCONNECT]: typeof walletconnectWallet.connectWalletconnect.supportedChains;
94
109
  [WalletOption.XAMAN]: typeof xamanWallet.connectXaman.supportedChains;
95
110
  };
@@ -129,6 +144,23 @@ declare global {
129
144
  near: NearBrowserWalletProvider;
130
145
  };
131
146
 
147
+ vultisig?: {
148
+ bitcoin: Eip1193Provider;
149
+ bitcoincash: Eip1193Provider;
150
+ dogecoin: Eip1193Provider;
151
+ ethereum: Eip1193Provider;
152
+ keplr: Keplr;
153
+ cosmos: VultisigCosmosProvider;
154
+ litecoin: Eip1193Provider;
155
+ thorchain: Eip1193Provider;
156
+ mayachain: Eip1193Provider;
157
+ solana: SolanaProvider;
158
+ polkadot: Eip1193Provider;
159
+ ripple: Eip1193Provider;
160
+ dash: Eip1193Provider;
161
+ zcash: Eip1193Provider;
162
+ };
163
+
132
164
  bitkeep?: {
133
165
  unisat: {
134
166
  requestAccounts: () => Promise<[string, ...string[]]>;
package/src/utils.ts CHANGED
@@ -15,6 +15,7 @@ export async function loadWallet<W extends WalletOption>(walletOption: W): Promi
15
15
  .with(WalletOption.COINBASE_MOBILE, async () => (await import("./coinbase")).coinbaseWallet)
16
16
  .with(WalletOption.BITGET, async () => (await import("./bitget")).bitgetWallet)
17
17
  .with(WalletOption.CTRL, async () => (await import("./ctrl")).ctrlWallet)
18
+ .with(WalletOption.VULTISIG, async () => (await import("./vultisig")).vultisigWallet)
18
19
  .with(WalletOption.OKX, async () => (await import("./okx")).okxWallet)
19
20
  .with(WalletOption.ONEKEY, async () => (await import("./onekey")).onekeyWallet)
20
21
  .with(WalletOption.EXODUS, async () => (await import("./exodus")).exodusWallet)
@@ -0,0 +1,199 @@
1
+ import {
2
+ Chain,
3
+ type EVMChain,
4
+ type GenericTransferParams,
5
+ SwapKitError,
6
+ type UTXOChain,
7
+ UTXOChains,
8
+ WalletOption,
9
+ createWallet,
10
+ filterSupportedChains,
11
+ } from "@swapkit/helpers";
12
+
13
+ import { getWalletSupportedChains } from "../utils";
14
+ import {
15
+ getVultisigAddress,
16
+ getVultisigMethods,
17
+ getVultisigProvider,
18
+ prepareNetworkSwitchCosmos,
19
+ walletTransfer,
20
+ } from "./walletHelpers";
21
+
22
+ export const vultisigWallet = createWallet({
23
+ name: "connectVultisig",
24
+ walletType: WalletOption.VULTISIG,
25
+ supportedChains: [
26
+ Chain.Arbitrum,
27
+ Chain.Avalanche,
28
+ Chain.Base,
29
+ Chain.BinanceSmartChain,
30
+ Chain.Bitcoin,
31
+ Chain.BitcoinCash,
32
+ Chain.Cosmos,
33
+ Chain.Dash,
34
+ Chain.Dogecoin,
35
+ Chain.Ethereum,
36
+ Chain.Kujira,
37
+ Chain.Litecoin,
38
+ Chain.Maya,
39
+ Chain.Optimism,
40
+ Chain.Polkadot,
41
+ Chain.Polygon,
42
+ Chain.Ripple,
43
+ Chain.Solana,
44
+ Chain.THORChain,
45
+ Chain.Zcash,
46
+ ],
47
+ connect: ({ addChain, walletType, supportedChains }) =>
48
+ async function connectVultisig(chains: Chain[]) {
49
+ const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
50
+
51
+ const promises = filteredChains
52
+ .filter((chain) => chain !== Chain.Cosmos && chain !== Chain.Kujira)
53
+ .map(async (chain) => {
54
+ const address = await getVultisigAddress(chain);
55
+ const walletMethods = await getWalletMethods(chain);
56
+
57
+ addChain({ ...walletMethods, address, chain, walletType });
58
+ });
59
+
60
+ const cosmosIncluded = filteredChains.includes(Chain.Cosmos);
61
+ const kujiraIncluded = filteredChains.includes(Chain.Kujira);
62
+
63
+ // Race condition single cosmos provider exposed.
64
+ if (cosmosIncluded) {
65
+ const addressCosmos = await getVultisigAddress(Chain.Cosmos);
66
+ const walletMethodsCosmos = await getWalletMethods(Chain.Cosmos);
67
+ addChain({
68
+ ...walletMethodsCosmos,
69
+ address: addressCosmos,
70
+ chain: Chain.Cosmos,
71
+ walletType,
72
+ });
73
+ }
74
+ if (kujiraIncluded) {
75
+ const addressKujira = await getVultisigAddress(Chain.Kujira);
76
+ const walletMethodsKujira = await getWalletMethods(Chain.Kujira);
77
+ addChain({
78
+ ...walletMethodsKujira,
79
+ address: addressKujira,
80
+ chain: Chain.Kujira,
81
+ walletType,
82
+ });
83
+ }
84
+ //--//
85
+
86
+ await Promise.all(promises);
87
+
88
+ return true;
89
+ },
90
+ });
91
+
92
+ export const VULTISIG_SUPPORTED_CHAINS = getWalletSupportedChains(vultisigWallet);
93
+
94
+ async function getWalletMethods(chain: (typeof VULTISIG_SUPPORTED_CHAINS)[number]) {
95
+ const { match } = await import("ts-pattern");
96
+ return match(chain)
97
+ .with(Chain.Solana, async () => {
98
+ const { getSolanaToolbox } = await import("@swapkit/toolboxes/solana");
99
+ const solanaProvider = window.vultisig?.solana;
100
+ if (!solanaProvider) throw new SwapKitError("wallet_vultisig_not_found");
101
+ const toolbox = await getSolanaToolbox({ signer: solanaProvider });
102
+ return { ...toolbox };
103
+ })
104
+
105
+ .with(Chain.Maya, Chain.THORChain, async () => {
106
+ const { getCosmosToolbox, THORCHAIN_GAS_VALUE, MAYA_GAS_VALUE } = await import(
107
+ "@swapkit/toolboxes/cosmos"
108
+ );
109
+ const gasLimit = chain === Chain.Maya ? MAYA_GAS_VALUE : THORCHAIN_GAS_VALUE;
110
+ const toolbox = await getCosmosToolbox(chain as Chain.Cosmos | Chain.Kujira);
111
+ return {
112
+ ...toolbox,
113
+ deposit: (tx: GenericTransferParams) =>
114
+ walletTransfer({ ...tx, recipient: "" }, "deposit_transaction"),
115
+ transfer: (tx: GenericTransferParams) =>
116
+ walletTransfer({ ...tx, gasLimit }, "send_transaction"),
117
+ };
118
+ })
119
+
120
+ .with(Chain.Cosmos, Chain.Kujira, async () => {
121
+ const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
122
+ const provider = await getVultisigProvider(chain as Chain.Cosmos | Chain.Kujira);
123
+ const toolbox = await getCosmosToolbox(chain as Chain.Cosmos | Chain.Kujira);
124
+ return prepareNetworkSwitchCosmos({
125
+ provider,
126
+ chain,
127
+ toolbox: {
128
+ ...toolbox,
129
+ transfer: walletTransfer,
130
+ },
131
+ });
132
+ })
133
+
134
+ .with(...UTXOChains, async () => {
135
+ const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
136
+ const toolbox = await getUtxoToolbox(chain as UTXOChain);
137
+ return { ...toolbox, transfer: walletTransfer };
138
+ })
139
+
140
+ .with(
141
+ Chain.Arbitrum,
142
+ Chain.Avalanche,
143
+ Chain.Base,
144
+ Chain.BinanceSmartChain,
145
+ Chain.Ethereum,
146
+ Chain.Optimism,
147
+ Chain.Polygon,
148
+ async () => {
149
+ const { prepareNetworkSwitch, switchEVMWalletNetwork } = await import("@swapkit/helpers");
150
+ const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
151
+ const { BrowserProvider } = await import("ethers");
152
+ const ethereumWindowProvider = await getVultisigProvider(chain as EVMChain);
153
+
154
+ if (!ethereumWindowProvider) {
155
+ throw new SwapKitError("wallet_vultisig_not_found");
156
+ }
157
+
158
+ const provider = new BrowserProvider(ethereumWindowProvider, "any");
159
+ const signer = await provider.getSigner();
160
+ const toolbox = await getEvmToolbox(chain as EVMChain, { provider, signer });
161
+ const vultisigMethods = getVultisigMethods(provider, chain as EVMChain);
162
+
163
+ try {
164
+ if (chain !== Chain.Ethereum) {
165
+ const networkParams = toolbox.getNetworkParams();
166
+ await switchEVMWalletNetwork(provider, chain, networkParams);
167
+ }
168
+ } catch (_error) {
169
+ throw new SwapKitError({
170
+ errorKey: "wallet_failed_to_add_or_switch_network",
171
+ info: { wallet: WalletOption.VULTISIG, chain },
172
+ });
173
+ }
174
+
175
+ return prepareNetworkSwitch({
176
+ provider,
177
+ chain,
178
+ toolbox: {
179
+ ...toolbox,
180
+ ...vultisigMethods,
181
+ },
182
+ });
183
+ },
184
+ )
185
+
186
+ .with(Chain.Ripple, async () => {
187
+ const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
188
+ const toolbox = await getRippleToolbox();
189
+ return { ...toolbox, transfer: walletTransfer };
190
+ })
191
+
192
+ .with(Chain.Polkadot, async () => {
193
+ const { getSubstrateToolbox } = await import("@swapkit/toolboxes/substrate");
194
+ const toolbox = await getSubstrateToolbox(chain as Chain.Polkadot);
195
+ return { ...toolbox, transfer: walletTransfer };
196
+ })
197
+
198
+ .otherwise(async () => null);
199
+ }
@@ -0,0 +1,359 @@
1
+ import {
2
+ type AssetValue,
3
+ Chain,
4
+ ChainToChainId,
5
+ type EVMChain,
6
+ EVMChains,
7
+ type FeeOption,
8
+ type NetworkParams,
9
+ SwapKitError,
10
+ type UTXOChain,
11
+ WalletOption,
12
+ providerRequest,
13
+ } from "@swapkit/helpers";
14
+ import { erc20ABI } from "@swapkit/helpers/contracts";
15
+ import type { getCosmosToolbox } from "@swapkit/toolboxes/cosmos";
16
+ import type { ApproveParams, CallParams, EVMTxParams } from "@swapkit/toolboxes/evm";
17
+ import type { SolanaProvider } from "@swapkit/toolboxes/solana";
18
+ import type { BrowserProvider, Eip1193Provider } from "ethers";
19
+ import type { VultisigCosmosProvider } from "../types";
20
+
21
+ type TransactionMethod = "send_transaction" | "deposit_transaction";
22
+
23
+ type TransactionParams = {
24
+ asset: string | { chain: string; symbol: string; ticker: string };
25
+ amount: number | string | { amount: number; decimals?: number };
26
+ decimal?: number;
27
+ to: string;
28
+ data?: string;
29
+ from?: string;
30
+ };
31
+
32
+ export type WalletTxParams = {
33
+ feeOptionKey?: FeeOption;
34
+ from?: string;
35
+ memo?: string;
36
+ recipient: string;
37
+ assetValue: AssetValue;
38
+ gasLimit?: string | bigint;
39
+ };
40
+
41
+ type VultisigProviderType<T> = T extends Chain.Solana
42
+ ? SolanaProvider
43
+ : T extends Chain.Cosmos | Chain.Kujira
44
+ ? VultisigCosmosProvider
45
+ : T extends EVMChain
46
+ ? Eip1193Provider
47
+ : T extends Chain.Maya | Chain.THORChain | Chain.Ripple | Chain.Polkadot | UTXOChain
48
+ ? Eip1193Provider
49
+ : undefined;
50
+
51
+ export async function getVultisigProvider<T extends Chain>(
52
+ chain: T,
53
+ ): Promise<VultisigProviderType<T>> {
54
+ if (!window.vultisig) throw new SwapKitError("wallet_vultisig_not_found");
55
+ const { match } = await import("ts-pattern");
56
+
57
+ return match(chain as Chain)
58
+ .with(...EVMChains, () => window.vultisig?.ethereum as Eip1193Provider)
59
+ .with(Chain.Cosmos, Chain.Kujira, () => window.vultisig?.cosmos as VultisigCosmosProvider)
60
+ .with(Chain.Bitcoin, () => window.vultisig?.bitcoin as Eip1193Provider)
61
+ .with(Chain.BitcoinCash, () => window.vultisig?.bitcoincash as Eip1193Provider)
62
+ .with(Chain.Dash, () => window.vultisig?.dash as Eip1193Provider)
63
+ .with(Chain.Dogecoin, () => window.vultisig?.dogecoin as Eip1193Provider)
64
+ .with(Chain.Litecoin, () => window.vultisig?.litecoin as Eip1193Provider)
65
+ .with(Chain.Solana, () => window.vultisig?.solana as SolanaProvider)
66
+ .with(Chain.THORChain, () => window.vultisig?.thorchain as Eip1193Provider)
67
+ .with(Chain.Maya, () => window.vultisig?.mayachain as Eip1193Provider)
68
+ .with(Chain.Polkadot, () => window.vultisig?.polkadot as Eip1193Provider)
69
+ .with(Chain.Ripple, () => window.vultisig?.ripple as Eip1193Provider)
70
+ .with(Chain.Zcash, () => window.vultisig?.zcash as Eip1193Provider)
71
+ .otherwise(() => undefined) as VultisigProviderType<T>;
72
+ }
73
+
74
+ async function transaction({
75
+ method,
76
+ params,
77
+ chain,
78
+ }: {
79
+ method: TransactionMethod;
80
+ params: TransactionParams[];
81
+ chain: Chain;
82
+ }): Promise<string> {
83
+ const client = await getVultisigProvider(chain);
84
+ let finalParams:
85
+ | TransactionParams[]
86
+ | {
87
+ from: string;
88
+ to?: string;
89
+ value: string;
90
+ data?: string;
91
+ }[] = params;
92
+
93
+ if (chain === Chain.Cosmos || chain === Chain.Kujira || chain === Chain.Ripple) {
94
+ finalParams = params.map((p) => ({
95
+ from: p.from as string,
96
+ to: p.to as string,
97
+ value: (p.amount as { amount: number; decimals?: number }).amount.toString(),
98
+ data: p.data as string,
99
+ }));
100
+ }
101
+
102
+ return new Promise<string>((resolve, reject) => {
103
+ if (client && "request" in client) {
104
+ // @ts-ignore
105
+ client.request({ method, params: finalParams }, (err: string, tx: string) => {
106
+ err ? reject(err) : resolve(tx);
107
+ });
108
+ }
109
+ });
110
+ }
111
+
112
+ export async function getVultisigAddress(chain: Chain) {
113
+ try {
114
+ const eipProvider = (await getVultisigProvider(chain)) as Eip1193Provider;
115
+ if (!eipProvider) {
116
+ throw new SwapKitError({
117
+ errorKey: "wallet_provider_not_found",
118
+ info: { wallet: WalletOption.VULTISIG, chain },
119
+ });
120
+ }
121
+
122
+ if ([Chain.Cosmos, Chain.Kujira].includes(chain)) {
123
+ const provider = await getVultisigProvider(Chain.Cosmos);
124
+ const chainId = ChainToChainId[chain];
125
+
126
+ await provider.request({
127
+ method: "wallet_switch_chain",
128
+ params: [{ chainId }],
129
+ });
130
+
131
+ let account = await provider.request({
132
+ method: "get_accounts",
133
+ });
134
+ if (!account) {
135
+ const connectedAcount = await provider.request({
136
+ method: "request_accounts",
137
+ });
138
+ account = connectedAcount[0].address;
139
+ }
140
+ return account;
141
+ }
142
+
143
+ if (EVMChains.includes(chain as EVMChain)) {
144
+ if ("request" in eipProvider && typeof eipProvider.request === "function") {
145
+ const accounts = await eipProvider.request({ method: "eth_requestAccounts" });
146
+ return accounts[0];
147
+ }
148
+ const { BrowserProvider } = await import("ethers");
149
+ const provider = new BrowserProvider(eipProvider, "any");
150
+ const [response] = await providerRequest({
151
+ provider,
152
+ method: "eth_requestAccounts",
153
+ params: [],
154
+ });
155
+ return response;
156
+ }
157
+
158
+ if (chain === Chain.Solana) {
159
+ const provider = await getVultisigProvider(Chain.Solana);
160
+
161
+ const accounts = await provider.connect();
162
+ return accounts.publicKey.toString();
163
+ }
164
+
165
+ const accounts = await eipProvider.request({ method: "request_accounts", params: [] });
166
+ return accounts[0];
167
+ } catch (_error) {
168
+ throw new SwapKitError({
169
+ errorKey: "wallet_provider_not_found",
170
+ info: { wallet: WalletOption.VULTISIG, chain },
171
+ });
172
+ }
173
+ }
174
+
175
+ export async function walletTransfer(
176
+ { assetValue, recipient, memo, gasLimit }: WalletTxParams,
177
+ method: TransactionMethod = "send_transaction",
178
+ ) {
179
+ if (!assetValue) {
180
+ throw new SwapKitError("wallet_vultisig_asset_not_defined");
181
+ }
182
+
183
+ /**
184
+ * EVM requires amount to be hex string
185
+ * UTXO/Cosmos requires amount to be number
186
+ */
187
+
188
+ const from = await getVultisigAddress(assetValue.chain);
189
+ const params = [
190
+ {
191
+ amount: {
192
+ amount: assetValue.getBaseValue("number"),
193
+ decimals: assetValue.decimal,
194
+ },
195
+ asset: {
196
+ chain: assetValue.chain,
197
+ symbol: assetValue.symbol.toUpperCase(),
198
+ ticker: assetValue.symbol.toUpperCase(),
199
+ },
200
+ data: memo || "",
201
+ from,
202
+ to: recipient,
203
+ gasLimit,
204
+ },
205
+ ];
206
+
207
+ return transaction({ method, params, chain: assetValue.chain });
208
+ }
209
+
210
+ export function getVultisigMethods(provider: BrowserProvider, chain: EVMChain) {
211
+ return {
212
+ call: async <T>({
213
+ contractAddress,
214
+ abi,
215
+ funcName,
216
+ funcParams = [],
217
+ txOverrides,
218
+ }: CallParams): Promise<T> => {
219
+ if (!contractAddress) {
220
+ throw new SwapKitError("wallet_vultisig_contract_address_not_provided");
221
+ }
222
+ const { createContract, getCreateContractTxObject, isStateChangingCall } = await import(
223
+ "@swapkit/toolboxes/evm"
224
+ );
225
+
226
+ const isStateChanging = isStateChangingCall({ abi, funcName });
227
+
228
+ if (isStateChanging) {
229
+ const createTx = getCreateContractTxObject({ provider, chain });
230
+ const { value, from, to, data } = await createTx({
231
+ contractAddress,
232
+ abi,
233
+ funcName,
234
+ funcParams,
235
+ txOverrides,
236
+ });
237
+
238
+ const signer = await provider.getSigner();
239
+ const tx = await signer.sendTransaction({
240
+ value: BigInt(value || 0),
241
+ from,
242
+ to,
243
+ data: data || "0x",
244
+ });
245
+ return tx.hash as T;
246
+ }
247
+ const contract = createContract(contractAddress, abi, provider);
248
+
249
+ const result = await contract[funcName]?.(...funcParams);
250
+
251
+ return typeof result?.hash === "string" ? result?.hash : result;
252
+ },
253
+ approve: async ({ assetAddress, spenderAddress, amount, from }: ApproveParams) => {
254
+ const { MAX_APPROVAL, getCreateContractTxObject } = await import("@swapkit/toolboxes/evm");
255
+ const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];
256
+ const txOverrides = { from };
257
+
258
+ const functionCallParams = {
259
+ contractAddress: assetAddress,
260
+ abi: erc20ABI,
261
+ funcName: "approve",
262
+ funcParams,
263
+ txOverrides,
264
+ };
265
+
266
+ const createTx = getCreateContractTxObject({ provider, chain });
267
+ const { value, to, data } = await createTx(functionCallParams);
268
+
269
+ const signer = await provider.getSigner();
270
+ const tx = await signer.sendTransaction({
271
+ value: BigInt(value || 0),
272
+ from,
273
+ to,
274
+ data: data || "0x",
275
+ });
276
+ return tx.hash;
277
+ },
278
+ sendTransaction: async (txParams: EVMTxParams) => {
279
+ const { from, to, data, value } = txParams;
280
+ if (!to) {
281
+ throw new SwapKitError("wallet_vultisig_send_transaction_no_address");
282
+ }
283
+
284
+ const signer = await provider.getSigner();
285
+ const tx = await signer.sendTransaction({
286
+ value: BigInt(value || 0),
287
+ from,
288
+ to,
289
+ data: data || "0x",
290
+ });
291
+ return tx.hash;
292
+ },
293
+ };
294
+ }
295
+
296
+ export async function switchCosmosWalletNetwork(
297
+ provider: VultisigCosmosProvider,
298
+ chain: Chain.Cosmos | Chain.Kujira,
299
+ networkParams?: NetworkParams,
300
+ ) {
301
+ try {
302
+ await provider.request({
303
+ method: "wallet_switch_chain",
304
+ params: [{ chainId: ChainToChainId[chain] }],
305
+ });
306
+ } catch (error) {
307
+ if (!networkParams) {
308
+ throw new SwapKitError("helpers_failed_to_switch_network", {
309
+ error: error,
310
+ reason: "networkParams not provided",
311
+ });
312
+ }
313
+ }
314
+ }
315
+
316
+ export function wrapMethodWithNetworkSwitch<T extends (...args: any[]) => any>(
317
+ func: T,
318
+ provider: VultisigCosmosProvider,
319
+ chain: Chain.Cosmos | Chain.Kujira,
320
+ ) {
321
+ return (async (...args: any[]) => {
322
+ try {
323
+ await switchCosmosWalletNetwork(provider, chain);
324
+ } catch (error) {
325
+ throw new SwapKitError({
326
+ errorKey: "helpers_failed_to_switch_network",
327
+ info: { error },
328
+ });
329
+ }
330
+ return func(...args);
331
+ }) as unknown as T;
332
+ }
333
+
334
+ export function prepareNetworkSwitchCosmos<
335
+ T extends Awaited<ReturnType<typeof getCosmosToolbox>>,
336
+ M extends keyof T,
337
+ >({
338
+ toolbox,
339
+ chain,
340
+ provider = window.ethereum,
341
+ methodNames = [],
342
+ }: { toolbox: T; chain: Chain; provider?: VultisigCosmosProvider; methodNames?: M[] }) {
343
+ const methodsToWrap = [...methodNames, "transfer", "getAddress", "getBalance"] as M[];
344
+ const wrappedMethods = methodsToWrap.reduce((object, methodName) => {
345
+ if (!toolbox[methodName]) return object;
346
+
347
+ const method = toolbox[methodName];
348
+
349
+ if (typeof method !== "function") return object;
350
+
351
+ // @ts-expect-error
352
+ const wrappedMethod = wrapMethodWithNetworkSwitch(method, provider, chain);
353
+
354
+ // biome-ignore lint/performance/noAccumulatingSpread: valid use case
355
+ return { ...object, [methodName]: wrappedMethod };
356
+ }, {});
357
+
358
+ return { ...toolbox, ...wrappedMethods };
359
+ }
@@ -132,8 +132,14 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
132
132
  case Chain.THORChain: {
133
133
  const { SignMode } = await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js");
134
134
  const { TxRaw } = await import("cosmjs-types/cosmos/tx/v1beta1/tx.js");
135
- const { encodePubkey, makeAuthInfoBytes } = (await import("@cosmjs/proto-signing")).default;
136
- const { makeSignDoc } = (await import("@cosmjs/amino")).default;
135
+
136
+ const importedSigning = await import("@cosmjs/proto-signing");
137
+ const encodePubkey = importedSigning.encodePubkey ?? importedSigning.default?.encodePubkey;
138
+ const makeAuthInfoBytes =
139
+ importedSigning.makeAuthInfoBytes ?? importedSigning.default?.makeAuthInfoBytes;
140
+ const importedAmino = await import("@cosmjs/amino");
141
+ const makeSignDoc = importedAmino.makeSignDoc ?? importedSigning.default?.makeSignDoc;
142
+
137
143
  const {
138
144
  getCosmosToolbox,
139
145
  buildAminoMsg,
@@ -1,4 +0,0 @@
1
- var s={};l(s,{loadWallet:()=>n,getWalletSupportedChains:()=>o});var t=require("@swapkit/helpers");function o(e){let i=Object.keys(e)?.[0]||"";return e?.[i]?.supportedChains||[]}async function n(e){let{match:i}=await import("ts-pattern");return await i(e).with(t.WalletOption.COINBASE_MOBILE,async()=>(await import("./src/coinbase/index.cjs")).coinbaseWallet).with(t.WalletOption.BITGET,async()=>(await import("./src/bitget/index.cjs")).bitgetWallet).with(t.WalletOption.CTRL,async()=>(await import("./src/ctrl/index.cjs")).ctrlWallet).with(t.WalletOption.OKX,async()=>(await import("./src/okx/index.cjs")).okxWallet).with(t.WalletOption.ONEKEY,async()=>(await import("./src/onekey/index.cjs")).onekeyWallet).with(t.WalletOption.EXODUS,async()=>(await import("./src/exodus/index.cjs")).exodusWallet).with(t.WalletOption.KEEPKEY,async()=>(await import("./src/keepkey/index.cjs")).keepkeyWallet).with(t.WalletOption.KEEPKEY_BEX,async()=>(await import("./src/keepkey-bex/index.cjs")).keepkeyBexWallet).with(t.WalletOption.WALLETCONNECT,async()=>(await import("./src/walletconnect/index.cjs")).walletconnectWallet).with(t.WalletOption.KEPLR,t.WalletOption.LEAP,async()=>(await import("./src/keplr/index.cjs")).keplrWallet).with(t.WalletOption.COSMOSTATION,async()=>(await import("./src/cosmostation/index.cjs")).cosmostationWallet).with(t.WalletOption.BRAVE,t.WalletOption.COINBASE_WEB,t.WalletOption.EIP6963,t.WalletOption.METAMASK,t.WalletOption.OKX_MOBILE,t.WalletOption.TRUSTWALLET_WEB,async()=>(await import("./src/evm-extensions/index.cjs")).evmWallet).with(t.WalletOption.KEYSTORE,async()=>(await import("./src/keystore/index.cjs")).keystoreWallet).with(t.WalletOption.TREZOR,async()=>(await import("./src/trezor/index.cjs")).trezorWallet).with(t.WalletOption.LEDGER,t.WalletOption.LEDGER_LIVE,async()=>(await import("./src/ledger/index.cjs")).ledgerWallet).with(t.WalletOption.PHANTOM,async()=>(await import("./src/phantom/index.cjs")).phantomWallet).with(t.WalletOption.POLKADOT_JS,async()=>(await import("./src/polkadotjs/index.cjs")).polkadotWallet).with(t.WalletOption.RADIX_WALLET,async()=>(await import("./src/radix/index.cjs")).radixWallet).with(t.WalletOption.TALISMAN,async()=>(await import("./src/talisman/index.cjs")).talismanWallet).with(t.WalletOption.XAMAN,async()=>(await import("./src/xaman/index.cjs")).xamanWallet).exhaustive()}
2
-
3
- //# debugId=14000E57951949B364756E2164756E21
4
- //# sourceMappingURL=chunk-f0qkch7f.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils.ts"],
4
- "sourcesContent": [
5
- "import { WalletOption, type createWallet } from \"@swapkit/helpers\";\nimport type { SKWallets } from \"./types\";\n\nexport function getWalletSupportedChains<\n T extends ReturnType<typeof createWallet<any, any, any, any>>,\n>(wallet: T): T[keyof T][\"supportedChains\"] {\n const walletName = Object.keys(wallet)?.[0] || \"\";\n return wallet?.[walletName]?.supportedChains || [];\n}\n\nexport async function loadWallet<W extends WalletOption>(walletOption: W): Promise<SKWallets[W]> {\n const { match } = await import(\"ts-pattern\");\n\n const wallet = await match(walletOption as WalletOption)\n .with(WalletOption.COINBASE_MOBILE, async () => (await import(\"./coinbase\")).coinbaseWallet)\n .with(WalletOption.BITGET, async () => (await import(\"./bitget\")).bitgetWallet)\n .with(WalletOption.CTRL, async () => (await import(\"./ctrl\")).ctrlWallet)\n .with(WalletOption.OKX, async () => (await import(\"./okx\")).okxWallet)\n .with(WalletOption.ONEKEY, async () => (await import(\"./onekey\")).onekeyWallet)\n .with(WalletOption.EXODUS, async () => (await import(\"./exodus\")).exodusWallet)\n .with(WalletOption.KEEPKEY, async () => (await import(\"./keepkey\")).keepkeyWallet)\n .with(WalletOption.KEEPKEY_BEX, async () => (await import(\"./keepkey-bex\")).keepkeyBexWallet)\n .with(\n WalletOption.WALLETCONNECT,\n async () => (await import(\"./walletconnect\")).walletconnectWallet,\n )\n .with(WalletOption.KEPLR, WalletOption.LEAP, async () => (await import(\"./keplr\")).keplrWallet)\n .with(\n WalletOption.COSMOSTATION,\n async () => (await import(\"./cosmostation\")).cosmostationWallet,\n )\n .with(\n WalletOption.BRAVE,\n WalletOption.COINBASE_WEB,\n WalletOption.EIP6963,\n WalletOption.METAMASK,\n WalletOption.OKX_MOBILE,\n WalletOption.TRUSTWALLET_WEB,\n async () => (await import(\"./evm-extensions\")).evmWallet,\n )\n\n .with(WalletOption.KEYSTORE, async () => (await import(\"./keystore\")).keystoreWallet)\n .with(WalletOption.TREZOR, async () => (await import(\"./trezor\")).trezorWallet)\n .with(\n WalletOption.LEDGER,\n // TODO: Remove\n WalletOption.LEDGER_LIVE,\n async () => (await import(\"./ledger\")).ledgerWallet,\n )\n\n .with(WalletOption.PHANTOM, async () => (await import(\"./phantom\")).phantomWallet)\n .with(WalletOption.POLKADOT_JS, async () => (await import(\"./polkadotjs\")).polkadotWallet)\n .with(WalletOption.RADIX_WALLET, async () => (await import(\"./radix\")).radixWallet)\n .with(WalletOption.TALISMAN, async () => (await import(\"./talisman\")).talismanWallet)\n .with(WalletOption.XAMAN, async () => (await import(\"./xaman\")).xamanWallet)\n .exhaustive();\n\n return wallet as SKWallets[W];\n}\n"
6
- ],
7
- "mappings": "gEAAgD,IAAhD,8BAGO,SAAS,CAEf,CAAC,EAA0C,CAC1C,IAAM,EAAa,OAAO,KAAK,CAAM,IAAI,IAAM,GAC/C,OAAO,IAAS,IAAa,iBAAmB,CAAC,EAGnD,eAAsB,CAAkC,CAAC,EAAwC,CAC/F,IAAQ,SAAU,KAAa,sBA8C/B,OA5Ce,MAAM,EAAM,CAA4B,EACpD,KAAK,eAAa,gBAAiB,UAAa,KAAa,qCAAe,cAAc,EAC1F,KAAK,eAAa,OAAQ,UAAa,KAAa,mCAAa,YAAY,EAC7E,KAAK,eAAa,KAAM,UAAa,KAAa,iCAAW,UAAU,EACvE,KAAK,eAAa,IAAK,UAAa,KAAa,gCAAU,SAAS,EACpE,KAAK,eAAa,OAAQ,UAAa,KAAa,mCAAa,YAAY,EAC7E,KAAK,eAAa,OAAQ,UAAa,KAAa,mCAAa,YAAY,EAC7E,KAAK,eAAa,QAAS,UAAa,KAAa,oCAAc,aAAa,EAChF,KAAK,eAAa,YAAa,UAAa,KAAa,wCAAkB,gBAAgB,EAC3F,KACC,eAAa,cACb,UAAa,KAAa,0CAAoB,mBAChD,EACC,KAAK,eAAa,MAAO,eAAa,KAAM,UAAa,KAAa,kCAAY,WAAW,EAC7F,KACC,eAAa,aACb,UAAa,KAAa,yCAAmB,kBAC/C,EACC,KACC,eAAa,MACb,eAAa,aACb,eAAa,QACb,eAAa,SACb,eAAa,WACb,eAAa,gBACb,UAAa,KAAa,2CAAqB,SACjD,EAEC,KAAK,eAAa,SAAU,UAAa,KAAa,qCAAe,cAAc,EACnF,KAAK,eAAa,OAAQ,UAAa,KAAa,mCAAa,YAAY,EAC7E,KACC,eAAa,OAEb,eAAa,YACb,UAAa,KAAa,mCAAa,YACzC,EAEC,KAAK,eAAa,QAAS,UAAa,KAAa,oCAAc,aAAa,EAChF,KAAK,eAAa,YAAa,UAAa,KAAa,uCAAiB,cAAc,EACxF,KAAK,eAAa,aAAc,UAAa,KAAa,kCAAY,WAAW,EACjF,KAAK,eAAa,SAAU,UAAa,KAAa,qCAAe,cAAc,EACnF,KAAK,eAAa,MAAO,UAAa,KAAa,kCAAY,WAAW,EAC1E,WAAW",
8
- "debugId": "14000E57951949B364756E2164756E21",
9
- "names": []
10
- }