@swapkit/wallets 4.7.0 → 4.8.1
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/src/index.cjs +2 -2
- package/dist/src/index.cjs.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/passkeys/index.cjs +2 -2
- package/dist/src/passkeys/index.cjs.map +3 -3
- package/dist/src/passkeys/index.js +2 -2
- package/dist/src/passkeys/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs.map +2 -2
- package/dist/src/walletconnect/index.js.map +2 -2
- package/dist/src/xaman/index.cjs +2 -2
- package/dist/src/xaman/index.cjs.map +4 -4
- package/dist/src/xaman/index.js +2 -2
- package/dist/src/xaman/index.js.map +4 -4
- package/dist/types/types.d.ts +36 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/walletconnect/index.d.ts.map +1 -1
- package/package.json +8 -16
- package/src/bitget.ts +1 -0
- package/src/coinbase/index.ts +54 -0
- package/src/coinbase/signer.ts +99 -0
- package/src/cosmostation.ts +1 -0
- package/src/ctrl.ts +1 -0
- package/src/evm-extensions.ts +1 -0
- package/src/index.ts +3 -0
- package/src/keepkey-bex.ts +1 -0
- package/src/keepkey.ts +1 -0
- package/src/keplr.ts +1 -0
- package/src/keystore-helpers.ts +93 -0
- package/src/keystore.ts +193 -0
- package/src/ledger.ts +1 -0
- package/src/near-wallet-selector/index.ts +116 -0
- package/src/okx.ts +1 -0
- package/src/onekey.ts +1 -0
- package/src/passkeys/index.ts +183 -0
- package/src/phantom.ts +1 -0
- package/src/polkadotjs.ts +1 -0
- package/src/radix/index.ts +95 -0
- package/src/talisman.ts +1 -0
- package/src/trezor.ts +1 -0
- package/src/tronlink.ts +1 -0
- package/src/types.ts +137 -0
- package/src/utils.ts +58 -0
- package/src/vultisig.ts +1 -0
- package/src/walletconnect/constants.ts +105 -0
- package/src/walletconnect/evmSigner.ts +116 -0
- package/src/walletconnect/helpers.ts +76 -0
- package/src/walletconnect/index.ts +409 -0
- package/src/walletconnect/namespaces.ts +80 -0
- package/src/walletconnect/types.ts +6 -0
- package/src/xaman/helpers.ts +89 -0
- package/src/xaman/index.ts +63 -0
- package/src/xaman/types.ts +35 -0
- package/src/xaman/walletMethods.ts +117 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { WalletOption } from "@swapkit/helpers";
|
|
2
|
+
import type { bitgetWallet } from "@swapkit/wallet-extensions/bitget";
|
|
3
|
+
import type { cosmostationWallet } from "@swapkit/wallet-extensions/cosmostation";
|
|
4
|
+
import type { ctrlWallet } from "@swapkit/wallet-extensions/ctrl";
|
|
5
|
+
import type { evmWallet } from "@swapkit/wallet-extensions/evm-extensions";
|
|
6
|
+
import type { keepkeyBexWallet } from "@swapkit/wallet-extensions/keepkey-bex";
|
|
7
|
+
import type { keplrWallet } from "@swapkit/wallet-extensions/keplr";
|
|
8
|
+
import type { okxWallet } from "@swapkit/wallet-extensions/okx";
|
|
9
|
+
import type { onekeyWallet } from "@swapkit/wallet-extensions/onekey";
|
|
10
|
+
import type { petraWallet } from "@swapkit/wallet-extensions/petra";
|
|
11
|
+
import type { phantomWallet } from "@swapkit/wallet-extensions/phantom";
|
|
12
|
+
import type { polkadotWallet } from "@swapkit/wallet-extensions/polkadotjs";
|
|
13
|
+
import type { talismanWallet } from "@swapkit/wallet-extensions/talisman";
|
|
14
|
+
import type { tronlinkWallet } from "@swapkit/wallet-extensions/tronlink";
|
|
15
|
+
import type { trustwalletWallet } from "@swapkit/wallet-extensions/trustwallet";
|
|
16
|
+
import type { vultisigWallet } from "@swapkit/wallet-extensions/vultisig";
|
|
17
|
+
import type { keepkeyWallet } from "@swapkit/wallet-hardware/keepkey";
|
|
18
|
+
import type { ledgerWallet } from "@swapkit/wallet-hardware/ledger";
|
|
19
|
+
import type { trezorWallet } from "@swapkit/wallet-hardware/trezor";
|
|
20
|
+
import type { coinbaseWallet } from "./coinbase";
|
|
21
|
+
import type { keystoreWallet } from "./keystore";
|
|
22
|
+
import type { walletSelectorWallet } from "./near-wallet-selector";
|
|
23
|
+
import type { passkeysWallet } from "./passkeys";
|
|
24
|
+
import type { radixWallet } from "./radix";
|
|
25
|
+
import type { walletconnectWallet } from "./walletconnect";
|
|
26
|
+
import type { xamanWallet } from "./xaman";
|
|
27
|
+
|
|
28
|
+
export type SKWallets = {
|
|
29
|
+
[WalletOption.BITGET]: typeof bitgetWallet;
|
|
30
|
+
[WalletOption.BRAVE]: typeof evmWallet;
|
|
31
|
+
[WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet;
|
|
32
|
+
[WalletOption.COINBASE_WEB]: typeof evmWallet;
|
|
33
|
+
[WalletOption.COSMOSTATION]: typeof cosmostationWallet;
|
|
34
|
+
[WalletOption.CTRL]: typeof ctrlWallet;
|
|
35
|
+
[WalletOption.EIP6963]: typeof evmWallet;
|
|
36
|
+
[WalletOption.EXODUS]: typeof passkeysWallet;
|
|
37
|
+
[WalletOption.KEEPKEY]: typeof keepkeyWallet;
|
|
38
|
+
[WalletOption.KEEPKEY_BEX]: typeof keepkeyBexWallet;
|
|
39
|
+
[WalletOption.KEPLR]: typeof keplrWallet;
|
|
40
|
+
[WalletOption.KEYSTORE]: typeof keystoreWallet;
|
|
41
|
+
[WalletOption.LEAP]: typeof keplrWallet;
|
|
42
|
+
[WalletOption.LEDGER]: typeof ledgerWallet;
|
|
43
|
+
[WalletOption.METAMASK]: typeof evmWallet;
|
|
44
|
+
[WalletOption.OKX]: typeof okxWallet;
|
|
45
|
+
[WalletOption.OKX_MOBILE]: typeof evmWallet;
|
|
46
|
+
[WalletOption.ONEKEY]: typeof onekeyWallet;
|
|
47
|
+
[WalletOption.PASSKEYS]: typeof passkeysWallet;
|
|
48
|
+
[WalletOption.PETRA]: typeof petraWallet;
|
|
49
|
+
[WalletOption.PHANTOM]: typeof phantomWallet;
|
|
50
|
+
[WalletOption.POLKADOT_JS]: typeof polkadotWallet;
|
|
51
|
+
[WalletOption.RADIX_WALLET]: typeof radixWallet;
|
|
52
|
+
[WalletOption.TALISMAN]: typeof talismanWallet;
|
|
53
|
+
[WalletOption.TREZOR]: typeof trezorWallet;
|
|
54
|
+
[WalletOption.TRONLINK]: typeof tronlinkWallet;
|
|
55
|
+
[WalletOption.TRUSTWALLET_WEB]: typeof trustwalletWallet;
|
|
56
|
+
[WalletOption.VULTISIG]: typeof vultisigWallet;
|
|
57
|
+
[WalletOption.WALLETCONNECT]: typeof walletconnectWallet;
|
|
58
|
+
[WalletOption.WALLET_SELECTOR]: typeof walletSelectorWallet;
|
|
59
|
+
[WalletOption.XAMAN]: typeof xamanWallet;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type SKConnectWallets = SKWallets[keyof SKWallets];
|
|
63
|
+
|
|
64
|
+
export type HDWalletAccountParams = { accountIndex?: number };
|
|
65
|
+
|
|
66
|
+
export type HDWalletDeriveAddressParams = HDWalletAccountParams & { index: number; change?: boolean };
|
|
67
|
+
|
|
68
|
+
export type HDWalletDeriveAddressesParams = HDWalletAccountParams & {
|
|
69
|
+
count: number;
|
|
70
|
+
startIndex?: number;
|
|
71
|
+
change?: boolean;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type HDWalletDerivedAddress = {
|
|
75
|
+
address: string;
|
|
76
|
+
index: number;
|
|
77
|
+
change: boolean;
|
|
78
|
+
path: string;
|
|
79
|
+
accountIndex: number;
|
|
80
|
+
pubkey: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type HDWalletExtendedPublicKey = {
|
|
84
|
+
xpub: string;
|
|
85
|
+
path: string;
|
|
86
|
+
accountIndex: number;
|
|
87
|
+
xpubSegwit?: string;
|
|
88
|
+
chainCode?: string;
|
|
89
|
+
publicKey?: string;
|
|
90
|
+
fingerprint?: number;
|
|
91
|
+
depth?: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type HDWalletDiscoveryMethods = {
|
|
95
|
+
getExtendedPublicKey?: () =>
|
|
96
|
+
| Promise<string | HDWalletExtendedPublicKey | undefined>
|
|
97
|
+
| string
|
|
98
|
+
| HDWalletExtendedPublicKey
|
|
99
|
+
| undefined;
|
|
100
|
+
getExtendedPublicKeyInfo: (params?: HDWalletAccountParams) => Promise<HDWalletExtendedPublicKey | undefined>;
|
|
101
|
+
deriveAddressAtIndex: (params: HDWalletDeriveAddressParams) => Promise<HDWalletDerivedAddress | undefined>;
|
|
102
|
+
deriveAddresses: (params: HDWalletDeriveAddressesParams) => Promise<HDWalletDerivedAddress[]>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type SKWalletsSupportedChains = {
|
|
106
|
+
[WalletOption.BITGET]: typeof bitgetWallet.connectBitget.supportedChains;
|
|
107
|
+
[WalletOption.BRAVE]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
108
|
+
[WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet.connectCoinbaseWallet.supportedChains;
|
|
109
|
+
[WalletOption.COINBASE_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
110
|
+
[WalletOption.COSMOSTATION]: typeof cosmostationWallet.connectCosmostation.supportedChains;
|
|
111
|
+
[WalletOption.CTRL]: typeof ctrlWallet.connectCtrl.supportedChains;
|
|
112
|
+
[WalletOption.EIP6963]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
113
|
+
[WalletOption.EXODUS]: typeof passkeysWallet.connectPasskeys.supportedChains;
|
|
114
|
+
[WalletOption.KEEPKEY]: typeof keepkeyWallet.connectKeepkey.supportedChains;
|
|
115
|
+
[WalletOption.KEEPKEY_BEX]: typeof keepkeyBexWallet.connectKeepkeyBex.supportedChains;
|
|
116
|
+
[WalletOption.KEPLR]: typeof keplrWallet.connectKeplr.supportedChains;
|
|
117
|
+
[WalletOption.KEYSTORE]: typeof keystoreWallet.connectKeystore.supportedChains;
|
|
118
|
+
[WalletOption.LEAP]: typeof keplrWallet.connectKeplr.supportedChains;
|
|
119
|
+
[WalletOption.LEDGER]: typeof ledgerWallet.connectLedger.supportedChains;
|
|
120
|
+
[WalletOption.METAMASK]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
121
|
+
[WalletOption.OKX]: typeof okxWallet.connectOkx.supportedChains;
|
|
122
|
+
[WalletOption.OKX_MOBILE]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
123
|
+
[WalletOption.ONEKEY]: typeof onekeyWallet.connectOnekeyWallet.supportedChains;
|
|
124
|
+
[WalletOption.PASSKEYS]: typeof passkeysWallet.connectPasskeys.supportedChains;
|
|
125
|
+
[WalletOption.PETRA]: typeof petraWallet.connectPetra.supportedChains;
|
|
126
|
+
[WalletOption.PHANTOM]: typeof phantomWallet.connectPhantom.supportedChains;
|
|
127
|
+
[WalletOption.POLKADOT_JS]: typeof polkadotWallet.connectPolkadotJs.supportedChains;
|
|
128
|
+
[WalletOption.RADIX_WALLET]: typeof radixWallet.connectRadixWallet.supportedChains;
|
|
129
|
+
[WalletOption.TALISMAN]: typeof talismanWallet.connectTalisman.supportedChains;
|
|
130
|
+
[WalletOption.TREZOR]: typeof trezorWallet.connectTrezor.supportedChains;
|
|
131
|
+
[WalletOption.TRONLINK]: typeof tronlinkWallet.connectTronLink.supportedChains;
|
|
132
|
+
[WalletOption.TRUSTWALLET_WEB]: typeof trustwalletWallet.connectTrustWallet.supportedChains;
|
|
133
|
+
[WalletOption.VULTISIG]: typeof vultisigWallet.connectVultisig.supportedChains;
|
|
134
|
+
[WalletOption.WALLETCONNECT]: typeof walletconnectWallet.connectWalletconnect.supportedChains;
|
|
135
|
+
[WalletOption.WALLET_SELECTOR]: typeof walletSelectorWallet.connectWalletSelector.supportedChains;
|
|
136
|
+
[WalletOption.XAMAN]: typeof xamanWallet.connectXaman.supportedChains;
|
|
137
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { WalletOption } from "@swapkit/helpers";
|
|
2
|
+
import type { SKWallets } from "./types";
|
|
3
|
+
|
|
4
|
+
export async function loadWallet<W extends WalletOption>(walletOption: W): Promise<SKWallets[W]> {
|
|
5
|
+
const { match } = await import("ts-pattern");
|
|
6
|
+
|
|
7
|
+
const wallet = await match(walletOption as WalletOption)
|
|
8
|
+
.with(WalletOption.COINBASE_MOBILE, async () => (await import("./coinbase")).coinbaseWallet)
|
|
9
|
+
.with(WalletOption.BITGET, async () => (await import("@swapkit/wallet-extensions/bitget")).bitgetWallet)
|
|
10
|
+
.with(WalletOption.CTRL, async () => (await import("@swapkit/wallet-extensions/ctrl")).ctrlWallet)
|
|
11
|
+
.with(WalletOption.VULTISIG, async () => (await import("@swapkit/wallet-extensions/vultisig")).vultisigWallet)
|
|
12
|
+
.with(WalletOption.OKX, async () => (await import("@swapkit/wallet-extensions/okx")).okxWallet)
|
|
13
|
+
.with(WalletOption.ONEKEY, async () => (await import("@swapkit/wallet-extensions/onekey")).onekeyWallet)
|
|
14
|
+
.with(WalletOption.EXODUS, async () => (await import("./passkeys")).passkeysWallet)
|
|
15
|
+
.with(WalletOption.KEEPKEY, async () => (await import("@swapkit/wallet-hardware/keepkey")).keepkeyWallet)
|
|
16
|
+
.with(
|
|
17
|
+
WalletOption.KEEPKEY_BEX,
|
|
18
|
+
async () => (await import("@swapkit/wallet-extensions/keepkey-bex")).keepkeyBexWallet,
|
|
19
|
+
)
|
|
20
|
+
.with(WalletOption.WALLETCONNECT, async () => (await import("./walletconnect")).walletconnectWallet)
|
|
21
|
+
.with(
|
|
22
|
+
WalletOption.KEPLR,
|
|
23
|
+
WalletOption.LEAP,
|
|
24
|
+
async () => (await import("@swapkit/wallet-extensions/keplr")).keplrWallet,
|
|
25
|
+
)
|
|
26
|
+
.with(
|
|
27
|
+
WalletOption.COSMOSTATION,
|
|
28
|
+
async () => (await import("@swapkit/wallet-extensions/cosmostation")).cosmostationWallet,
|
|
29
|
+
)
|
|
30
|
+
.with(
|
|
31
|
+
WalletOption.BRAVE,
|
|
32
|
+
WalletOption.COINBASE_WEB,
|
|
33
|
+
WalletOption.EIP6963,
|
|
34
|
+
WalletOption.METAMASK,
|
|
35
|
+
WalletOption.OKX_MOBILE,
|
|
36
|
+
async () => (await import("@swapkit/wallet-extensions/evm-extensions")).evmWallet,
|
|
37
|
+
)
|
|
38
|
+
.with(
|
|
39
|
+
WalletOption.TRUSTWALLET_WEB,
|
|
40
|
+
async () => (await import("@swapkit/wallet-extensions/trustwallet")).trustwalletWallet,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
.with(WalletOption.KEYSTORE, async () => (await import("./keystore")).keystoreWallet)
|
|
44
|
+
.with(WalletOption.TREZOR, async () => (await import("@swapkit/wallet-hardware/trezor")).trezorWallet)
|
|
45
|
+
.with(WalletOption.LEDGER, async () => (await import("@swapkit/wallet-hardware/ledger")).ledgerWallet)
|
|
46
|
+
.with(WalletOption.PASSKEYS, async () => (await import("./passkeys")).passkeysWallet)
|
|
47
|
+
.with(WalletOption.PETRA, async () => (await import("@swapkit/wallet-extensions/petra")).petraWallet)
|
|
48
|
+
.with(WalletOption.PHANTOM, async () => (await import("@swapkit/wallet-extensions/phantom")).phantomWallet)
|
|
49
|
+
.with(WalletOption.POLKADOT_JS, async () => (await import("@swapkit/wallet-extensions/polkadotjs")).polkadotWallet)
|
|
50
|
+
.with(WalletOption.RADIX_WALLET, async () => (await import("./radix")).radixWallet)
|
|
51
|
+
.with(WalletOption.TALISMAN, async () => (await import("@swapkit/wallet-extensions/talisman")).talismanWallet)
|
|
52
|
+
.with(WalletOption.TRONLINK, async () => (await import("@swapkit/wallet-extensions/tronlink")).tronlinkWallet)
|
|
53
|
+
.with(WalletOption.WALLET_SELECTOR, async () => (await import("./near-wallet-selector")).walletSelectorWallet)
|
|
54
|
+
.with(WalletOption.XAMAN, async () => (await import("./xaman")).xamanWallet)
|
|
55
|
+
.exhaustive();
|
|
56
|
+
|
|
57
|
+
return wallet as SKWallets[W];
|
|
58
|
+
}
|
package/src/vultisig.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@swapkit/wallet-extensions/vultisig";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ClientMetadata } from "./types";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_RELAY_URL = "wss://relay.walletconnect.com";
|
|
4
|
+
|
|
5
|
+
export const ETHEREUM_MAINNET_ID = "eip155:1";
|
|
6
|
+
export const BSC_MAINNET_ID = "eip155:56";
|
|
7
|
+
export const AVALANCHE_MAINNET_ID = "eip155:43114";
|
|
8
|
+
export const THORCHAIN_MAINNET_ID = "cosmos:thorchain";
|
|
9
|
+
export const COSMOS_HUB_MAINNET_ID = "cosmos:cosmoshub-4";
|
|
10
|
+
export const KUJIRA_MAINNET_ID = "cosmos:kaiyo-1";
|
|
11
|
+
export const MAYACHAIN_MAINNET_ID = "cosmos:mayachain-mainnet-v1";
|
|
12
|
+
export const ARBITRUM_ONE_MAINNET_ID = "eip155:42161";
|
|
13
|
+
export const OPTIMISM_MAINNET_ID = "eip155:10";
|
|
14
|
+
export const POLYGON_MAINNET_ID = "eip155:137";
|
|
15
|
+
export const BASE_MAINNET_ID = "eip155:8453";
|
|
16
|
+
export const NEAR_MAINNET_ID = "near:mainnet";
|
|
17
|
+
export const NEAR_TESTNET_ID = "near:testnet";
|
|
18
|
+
export const TRON_MAINNET_ID = "tron:0x2b6653dc";
|
|
19
|
+
export const AURORA_MAINNET_ID = "eip155:1313161554";
|
|
20
|
+
export const BERACHAIN_MAINNET_ID = "eip155:80094";
|
|
21
|
+
export const MONAD_MAINNET_ID = "eip155:143";
|
|
22
|
+
export const XLAYER_MAINNET_ID = "eip155:196";
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_LOGGER = "debug";
|
|
25
|
+
|
|
26
|
+
export const DEFAULT_APP_METADATA: ClientMetadata = {
|
|
27
|
+
description: "SwapKit cross-chain SDK",
|
|
28
|
+
icons: ["https://raw.githubusercontent.com/swapkit/SwapKit/refs/heads/develop/docs/src/assets/logo-black.png"],
|
|
29
|
+
name: "SwapKit",
|
|
30
|
+
url: "https://swapkit.dev/",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* EIP155
|
|
35
|
+
*/
|
|
36
|
+
export enum DEFAULT_EIP155_METHODS {
|
|
37
|
+
ETH_SEND_TRANSACTION = "eth_sendTransaction",
|
|
38
|
+
// not supported by most WC wallets
|
|
39
|
+
// ETH_SIGN_TRANSACTION = 'eth_signTransaction',
|
|
40
|
+
ETH_SIGN = "eth_sign",
|
|
41
|
+
PERSONAL_SIGN = "personal_sign",
|
|
42
|
+
ETH_SIGN_TYPED_DATA = "eth_signTypedData",
|
|
43
|
+
ETH_SIGN_TYPED_DATA_V4 = "eth_signTypedData_v4",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export enum DEFAULT_EIP_155_EVENTS {
|
|
47
|
+
ETH_CHAIN_CHANGED = "chainChanged",
|
|
48
|
+
ETH_ACCOUNTS_CHANGED = "accountsChanged",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* COSMOS
|
|
53
|
+
*/
|
|
54
|
+
export enum DEFAULT_COSMOS_METHODS {
|
|
55
|
+
COSMOS_SIGN_DIRECT = "cosmos_signDirect",
|
|
56
|
+
COSMOS_SIGN_AMINO = "cosmos_signAmino",
|
|
57
|
+
COSMOS_GET_ACCOUNTS = "cosmos_getAccounts",
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export enum DEFAULT_COSMOS_EVENTS {}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* SOLANA
|
|
64
|
+
*/
|
|
65
|
+
export enum DEFAULT_SOLANA_METHODS {
|
|
66
|
+
SOL_SIGN_TRANSACTION = "solana_signTransaction",
|
|
67
|
+
SOL_SIGN_MESSAGE = "solana_signMessage",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export enum DEFAULT_SOLANA_EVENTS {}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* POLKADOT
|
|
74
|
+
*/
|
|
75
|
+
export enum DEFAULT_POLKADOT_METHODS {
|
|
76
|
+
POLKADOT_SIGN_TRANSACTION = "polkadot_signTransaction",
|
|
77
|
+
POLKADOT_SIGN_MESSAGE = "polkadot_signMessage",
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export enum DEFAULT_POLKADOT_EVENTS {}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* NEAR
|
|
84
|
+
*/
|
|
85
|
+
export enum DEFAULT_NEAR_METHODS {
|
|
86
|
+
NEAR_SIGN_IN = "near_signIn",
|
|
87
|
+
NEAR_SIGN_OUT = "near_signOut",
|
|
88
|
+
NEAR_GET_ACCOUNTS = "near_getAccounts",
|
|
89
|
+
NEAR_SIGN_AND_SEND_TRANSACTION = "near_signAndSendTransaction",
|
|
90
|
+
NEAR_SIGN_AND_SEND_TRANSACTIONS = "near_signAndSendTransactions",
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export enum DEFAULT_NEAR_EVENTS {}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* TRON
|
|
97
|
+
*/
|
|
98
|
+
export enum DEFAULT_TRON_METHODS {
|
|
99
|
+
TRON_SIGN_MESSAGE = "tron_signMessage",
|
|
100
|
+
TRON_SIGN_TRANSACTION = "tron_signTransaction",
|
|
101
|
+
TRON_SEND_TRANSACTION = "tron_sendTransaction",
|
|
102
|
+
TRON_GET_ACCOUNTS = "tron_getAccounts",
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export enum DEFAULT_TRON_EVENTS {}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type EVMChain, SwapKitError, WalletOption } from "@swapkit/helpers";
|
|
2
|
+
import type {
|
|
3
|
+
JsonRpcProvider,
|
|
4
|
+
Provider,
|
|
5
|
+
TransactionRequest,
|
|
6
|
+
TransactionResponse,
|
|
7
|
+
TypedDataDomain,
|
|
8
|
+
TypedDataField,
|
|
9
|
+
} from "ethers";
|
|
10
|
+
import { AbstractSigner } from "ethers";
|
|
11
|
+
|
|
12
|
+
import { DEFAULT_EIP155_METHODS } from "./constants";
|
|
13
|
+
import { chainToChainId, getAddressByChain } from "./helpers";
|
|
14
|
+
import type { Walletconnect } from "./index";
|
|
15
|
+
|
|
16
|
+
interface WalletconnectEVMSignerParams {
|
|
17
|
+
chain: EVMChain;
|
|
18
|
+
walletconnect: Walletconnect;
|
|
19
|
+
provider: Provider | JsonRpcProvider;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class WalletconnectSigner extends AbstractSigner {
|
|
23
|
+
address: string;
|
|
24
|
+
|
|
25
|
+
private chain: EVMChain;
|
|
26
|
+
private walletconnect: Walletconnect;
|
|
27
|
+
readonly provider: Provider | JsonRpcProvider;
|
|
28
|
+
|
|
29
|
+
constructor({ chain, provider, walletconnect }: WalletconnectEVMSignerParams) {
|
|
30
|
+
super(provider);
|
|
31
|
+
this.chain = chain;
|
|
32
|
+
this.walletconnect = walletconnect;
|
|
33
|
+
this.provider = provider;
|
|
34
|
+
this.address = "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// biome-ignore lint/suspicious/useAwait: fulfil implementation type
|
|
38
|
+
getAddress = async () => {
|
|
39
|
+
if (!this.walletconnect) {
|
|
40
|
+
throw new SwapKitError("wallet_walletconnect_connection_not_established");
|
|
41
|
+
}
|
|
42
|
+
if (!this.address) {
|
|
43
|
+
this.address = getAddressByChain(this.chain, this.walletconnect.accounts || []);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this.address;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
signMessage = async (message: string) => {
|
|
50
|
+
// this is probably broken
|
|
51
|
+
const txHash = (await this.walletconnect?.client.request({
|
|
52
|
+
chainId: chainToChainId(this.chain),
|
|
53
|
+
request: { method: DEFAULT_EIP155_METHODS.ETH_SIGN, params: [message] },
|
|
54
|
+
topic: this.walletconnect.session.topic || "",
|
|
55
|
+
})) as string;
|
|
56
|
+
|
|
57
|
+
return txHash.startsWith("0x") ? txHash : `0x${txHash}`;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
signTransaction = () => {
|
|
61
|
+
throw new SwapKitError("wallet_walletconnect_method_not_supported", { method: "signTransaction" });
|
|
62
|
+
|
|
63
|
+
// const baseTx = {
|
|
64
|
+
// from,
|
|
65
|
+
// to,
|
|
66
|
+
// value: BigNumber.from(value || 0).toHexString(),
|
|
67
|
+
// data,
|
|
68
|
+
// };
|
|
69
|
+
|
|
70
|
+
// const txHash = (await this.walletconnect?.client.request({
|
|
71
|
+
// chainId: chainToChainId(this.chain),
|
|
72
|
+
// topic: this.walletconnect.session.topic,
|
|
73
|
+
// request: {
|
|
74
|
+
// method: DEFAULT_EIP155_METHODS.ETH_SIGN_TRANSACTION,
|
|
75
|
+
// params: [baseTx],
|
|
76
|
+
// },
|
|
77
|
+
// })) as string;
|
|
78
|
+
|
|
79
|
+
// return txHash.startsWith('0x') ? txHash : `0x${txHash}`;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
signTypedData = (
|
|
83
|
+
_domain: TypedDataDomain,
|
|
84
|
+
_types: Record<string, TypedDataField[]>,
|
|
85
|
+
_value: Record<string, unknown>,
|
|
86
|
+
_explicitPrimaryType?: string,
|
|
87
|
+
) => {
|
|
88
|
+
throw new SwapKitError("wallet_walletconnect_method_not_supported", { method: "signTransaction" });
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
sendTransaction = async ({ from, to, value, data }: TransactionRequest) => {
|
|
92
|
+
const { toHexString } = await import("@swapkit/toolboxes/evm");
|
|
93
|
+
|
|
94
|
+
const baseTx = { data, from, to, value: toHexString(BigInt(value || 0)) };
|
|
95
|
+
const response = await this.walletconnect?.client.request({
|
|
96
|
+
chainId: chainToChainId(this.chain),
|
|
97
|
+
request: { method: DEFAULT_EIP155_METHODS.ETH_SEND_TRANSACTION, params: [baseTx] },
|
|
98
|
+
topic: this.walletconnect.session.topic,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return response as TransactionResponse;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
connect = (provider: Provider | null) => {
|
|
105
|
+
if (!provider) {
|
|
106
|
+
throw new SwapKitError({
|
|
107
|
+
errorKey: "wallet_provider_not_found",
|
|
108
|
+
info: { chain: this.chain, wallet: WalletOption.WALLETCONNECT },
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return new WalletconnectSigner({ chain: this.chain, provider, walletconnect: this.walletconnect });
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export const getEVMSigner = async ({ chain, walletconnect, provider }: WalletconnectEVMSignerParams) =>
|
|
116
|
+
new WalletconnectSigner({ chain, provider, walletconnect });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Chain, type CosmosChain, type EVMChain, SKConfig } from "@swapkit/helpers";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ARBITRUM_ONE_MAINNET_ID,
|
|
5
|
+
AURORA_MAINNET_ID,
|
|
6
|
+
AVALANCHE_MAINNET_ID,
|
|
7
|
+
BASE_MAINNET_ID,
|
|
8
|
+
BERACHAIN_MAINNET_ID,
|
|
9
|
+
BSC_MAINNET_ID,
|
|
10
|
+
COSMOS_HUB_MAINNET_ID,
|
|
11
|
+
ETHEREUM_MAINNET_ID,
|
|
12
|
+
KUJIRA_MAINNET_ID,
|
|
13
|
+
MAYACHAIN_MAINNET_ID,
|
|
14
|
+
MONAD_MAINNET_ID,
|
|
15
|
+
NEAR_MAINNET_ID,
|
|
16
|
+
NEAR_TESTNET_ID,
|
|
17
|
+
OPTIMISM_MAINNET_ID,
|
|
18
|
+
POLYGON_MAINNET_ID,
|
|
19
|
+
THORCHAIN_MAINNET_ID,
|
|
20
|
+
TRON_MAINNET_ID,
|
|
21
|
+
XLAYER_MAINNET_ID,
|
|
22
|
+
} from "./constants";
|
|
23
|
+
|
|
24
|
+
export const getAddressByChain = (
|
|
25
|
+
chain: EVMChain | Exclude<CosmosChain, typeof Chain.Noble> | typeof Chain.Near | typeof Chain.Tron,
|
|
26
|
+
accounts: string[],
|
|
27
|
+
) => {
|
|
28
|
+
const account = accounts.find((account) => account.startsWith(chainToChainId(chain))) || "";
|
|
29
|
+
const address = account?.split(":")?.[2];
|
|
30
|
+
|
|
31
|
+
return address || "";
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const chainToChainId = (chain: Chain) => {
|
|
35
|
+
switch (chain) {
|
|
36
|
+
case Chain.Avalanche:
|
|
37
|
+
return AVALANCHE_MAINNET_ID;
|
|
38
|
+
case Chain.Aurora:
|
|
39
|
+
return AURORA_MAINNET_ID;
|
|
40
|
+
case Chain.Base:
|
|
41
|
+
return BASE_MAINNET_ID;
|
|
42
|
+
case Chain.BinanceSmartChain:
|
|
43
|
+
return BSC_MAINNET_ID;
|
|
44
|
+
case Chain.Berachain:
|
|
45
|
+
return BERACHAIN_MAINNET_ID;
|
|
46
|
+
case Chain.Monad:
|
|
47
|
+
return MONAD_MAINNET_ID;
|
|
48
|
+
case Chain.Ethereum:
|
|
49
|
+
return ETHEREUM_MAINNET_ID;
|
|
50
|
+
case Chain.THORChain:
|
|
51
|
+
return THORCHAIN_MAINNET_ID;
|
|
52
|
+
case Chain.Arbitrum:
|
|
53
|
+
return ARBITRUM_ONE_MAINNET_ID;
|
|
54
|
+
case Chain.Optimism:
|
|
55
|
+
return OPTIMISM_MAINNET_ID;
|
|
56
|
+
case Chain.Polygon:
|
|
57
|
+
return POLYGON_MAINNET_ID;
|
|
58
|
+
case Chain.Maya:
|
|
59
|
+
return MAYACHAIN_MAINNET_ID;
|
|
60
|
+
case Chain.Cosmos:
|
|
61
|
+
return COSMOS_HUB_MAINNET_ID;
|
|
62
|
+
case Chain.Kujira:
|
|
63
|
+
return KUJIRA_MAINNET_ID;
|
|
64
|
+
case Chain.Near: {
|
|
65
|
+
// Use testnet if stagenet is enabled
|
|
66
|
+
const { isStagenet } = SKConfig.get("envs");
|
|
67
|
+
return isStagenet ? NEAR_TESTNET_ID : NEAR_MAINNET_ID;
|
|
68
|
+
}
|
|
69
|
+
case Chain.Tron:
|
|
70
|
+
return TRON_MAINNET_ID;
|
|
71
|
+
case Chain.XLayer:
|
|
72
|
+
return XLAYER_MAINNET_ID;
|
|
73
|
+
default:
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
};
|