@tcswap/wallet-extensions 4.1.16
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/chunk-7y3ffnf3.js +4 -0
- package/dist/chunk-7y3ffnf3.js.map +10 -0
- package/dist/chunk-fazw0jvt.js +4 -0
- package/dist/chunk-fazw0jvt.js.map +9 -0
- package/dist/chunk-kx2thqhk.js +5 -0
- package/dist/chunk-kx2thqhk.js.map +9 -0
- package/dist/chunk-swh9jwp7.js +4 -0
- package/dist/chunk-swh9jwp7.js.map +10 -0
- package/dist/src/bitget/index.cjs +4 -0
- package/dist/src/bitget/index.cjs.map +11 -0
- package/dist/src/bitget/index.js +4 -0
- package/dist/src/bitget/index.js.map +11 -0
- package/dist/src/cosmostation/index.cjs +4 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +4 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +4 -0
- package/dist/src/ctrl/index.cjs.map +11 -0
- package/dist/src/ctrl/index.js +4 -0
- package/dist/src/ctrl/index.js.map +11 -0
- package/dist/src/evm-extensions/index.cjs +4 -0
- package/dist/src/evm-extensions/index.cjs.map +10 -0
- package/dist/src/evm-extensions/index.js +4 -0
- package/dist/src/evm-extensions/index.js.map +10 -0
- package/dist/src/index.cjs +4 -0
- package/dist/src/index.cjs.map +9 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +9 -0
- package/dist/src/keepkey-bex/index.cjs +4 -0
- package/dist/src/keepkey-bex/index.cjs.map +11 -0
- package/dist/src/keepkey-bex/index.js +4 -0
- package/dist/src/keepkey-bex/index.js.map +11 -0
- package/dist/src/keplr/index.cjs +4 -0
- package/dist/src/keplr/index.cjs.map +11 -0
- package/dist/src/keplr/index.js +4 -0
- package/dist/src/keplr/index.js.map +11 -0
- package/dist/src/okx/index.cjs +4 -0
- package/dist/src/okx/index.cjs.map +11 -0
- package/dist/src/okx/index.js +4 -0
- package/dist/src/okx/index.js.map +11 -0
- package/dist/src/onekey/index.cjs +4 -0
- package/dist/src/onekey/index.cjs.map +10 -0
- package/dist/src/onekey/index.js +4 -0
- package/dist/src/onekey/index.js.map +10 -0
- package/dist/src/phantom/index.cjs +4 -0
- package/dist/src/phantom/index.cjs.map +10 -0
- package/dist/src/phantom/index.js +4 -0
- package/dist/src/phantom/index.js.map +10 -0
- package/dist/src/polkadotjs/index.cjs +4 -0
- package/dist/src/polkadotjs/index.cjs.map +10 -0
- package/dist/src/polkadotjs/index.js +4 -0
- package/dist/src/polkadotjs/index.js.map +10 -0
- package/dist/src/talisman/index.cjs +4 -0
- package/dist/src/talisman/index.cjs.map +10 -0
- package/dist/src/talisman/index.js +4 -0
- package/dist/src/talisman/index.js.map +10 -0
- package/dist/src/tronlink/index.cjs +4 -0
- package/dist/src/tronlink/index.cjs.map +12 -0
- package/dist/src/tronlink/index.js +4 -0
- package/dist/src/tronlink/index.js.map +12 -0
- package/dist/src/vultisig/index.cjs +4 -0
- package/dist/src/vultisig/index.cjs.map +11 -0
- package/dist/src/vultisig/index.js +4 -0
- package/dist/src/vultisig/index.js.map +11 -0
- package/dist/types/bitget/helpers.d.ts +1607 -0
- package/dist/types/bitget/helpers.d.ts.map +1 -0
- package/dist/types/bitget/index.d.ts +11 -0
- package/dist/types/bitget/index.d.ts.map +1 -0
- package/dist/types/cosmostation/index.d.ts +24 -0
- package/dist/types/cosmostation/index.d.ts.map +1 -0
- package/dist/types/ctrl/index.d.ts +14 -0
- package/dist/types/ctrl/index.d.ts.map +1 -0
- package/dist/types/ctrl/walletHelpers.d.ts +23 -0
- package/dist/types/ctrl/walletHelpers.d.ts.map +1 -0
- package/dist/types/evm-extensions/index.d.ts +747 -0
- package/dist/types/evm-extensions/index.d.ts.map +1 -0
- package/dist/types/evm-extensions/types.d.ts +18 -0
- package/dist/types/evm-extensions/types.d.ts.map +1 -0
- package/dist/types/helpers/near.d.ts +60 -0
- package/dist/types/helpers/near.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/keepkey-bex/index.d.ts +14 -0
- package/dist/types/keepkey-bex/index.d.ts.map +1 -0
- package/dist/types/keepkey-bex/walletHelpers.d.ts +48 -0
- package/dist/types/keepkey-bex/walletHelpers.d.ts.map +1 -0
- package/dist/types/keplr/chainRegistry.d.ts +4 -0
- package/dist/types/keplr/chainRegistry.d.ts.map +1 -0
- package/dist/types/keplr/index.d.ts +14 -0
- package/dist/types/keplr/index.d.ts.map +1 -0
- package/dist/types/okx/helpers.d.ts +855 -0
- package/dist/types/okx/helpers.d.ts.map +1 -0
- package/dist/types/okx/index.d.ts +11 -0
- package/dist/types/okx/index.d.ts.map +1 -0
- package/dist/types/okx/types.d.ts +104 -0
- package/dist/types/okx/types.d.ts.map +1 -0
- package/dist/types/onekey/evmSigner.d.ts +32 -0
- package/dist/types/onekey/evmSigner.d.ts.map +1 -0
- package/dist/types/onekey/index.d.ts +14 -0
- package/dist/types/onekey/index.d.ts.map +1 -0
- package/dist/types/phantom/index.d.ts +15 -0
- package/dist/types/phantom/index.d.ts.map +1 -0
- package/dist/types/polkadotjs/index.d.ts +14 -0
- package/dist/types/polkadotjs/index.d.ts.map +1 -0
- package/dist/types/talisman/index.d.ts +14 -0
- package/dist/types/talisman/index.d.ts.map +1 -0
- package/dist/types/tronlink/helpers.d.ts +29 -0
- package/dist/types/tronlink/helpers.d.ts.map +1 -0
- package/dist/types/tronlink/index.d.ts +13 -0
- package/dist/types/tronlink/index.d.ts.map +1 -0
- package/dist/types/tronlink/types.d.ts +55 -0
- package/dist/types/tronlink/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +166 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/vultisig/index.d.ts +14 -0
- package/dist/types/vultisig/index.d.ts.map +1 -0
- package/dist/types/vultisig/walletHelpers.d.ts +37 -0
- package/dist/types/vultisig/walletHelpers.d.ts.map +1 -0
- package/package.json +133 -0
- package/src/bitget/helpers.ts +181 -0
- package/src/bitget/index.ts +26 -0
- package/src/cosmostation/index.ts +122 -0
- package/src/ctrl/index.ts +194 -0
- package/src/ctrl/walletHelpers.ts +186 -0
- package/src/evm-extensions/index.ts +122 -0
- package/src/evm-extensions/types.ts +15 -0
- package/src/helpers/near-browser-provider.d.ts +270 -0
- package/src/helpers/near.ts +174 -0
- package/src/index.ts +1 -0
- package/src/keepkey-bex/index.ts +151 -0
- package/src/keepkey-bex/walletHelpers.ts +241 -0
- package/src/keplr/chainRegistry.ts +240 -0
- package/src/keplr/index.ts +54 -0
- package/src/okx/helpers.ts +192 -0
- package/src/okx/index.ts +43 -0
- package/src/okx/types.ts +117 -0
- package/src/onekey/evmSigner.ts +116 -0
- package/src/onekey/index.ts +182 -0
- package/src/phantom/index.ts +136 -0
- package/src/polkadotjs/index.ts +61 -0
- package/src/talisman/index.ts +132 -0
- package/src/tronlink/helpers.ts +153 -0
- package/src/tronlink/index.ts +49 -0
- package/src/tronlink/types.ts +44 -0
- package/src/types.ts +157 -0
- package/src/vultisig/index.ts +179 -0
- package/src/vultisig/walletHelpers.ts +295 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Keplr } from "@keplr-wallet/types";
|
|
6
|
+
import {
|
|
7
|
+
type AssetValue,
|
|
8
|
+
Chain,
|
|
9
|
+
ChainToChainId,
|
|
10
|
+
type CosmosChain,
|
|
11
|
+
type EVMChain,
|
|
12
|
+
EVMChains,
|
|
13
|
+
type FeeOption,
|
|
14
|
+
providerRequest,
|
|
15
|
+
type TCLikeChain,
|
|
16
|
+
USwapError,
|
|
17
|
+
WalletOption,
|
|
18
|
+
} from "@tcswap/helpers";
|
|
19
|
+
import type { SolanaProvider } from "@tcswap/toolboxes/solana";
|
|
20
|
+
import type { Eip1193Provider } from "ethers";
|
|
21
|
+
import { match } from "ts-pattern";
|
|
22
|
+
import type { NearBrowserWalletProvider } from "../helpers/near";
|
|
23
|
+
|
|
24
|
+
type TransactionMethod = "transfer" | "deposit";
|
|
25
|
+
|
|
26
|
+
type TransactionParams = {
|
|
27
|
+
asset: string | { chain: string; symbol: string; ticker: string };
|
|
28
|
+
amount: number | string | { amount: number; decimals?: number };
|
|
29
|
+
decimal?: number;
|
|
30
|
+
recipient: string;
|
|
31
|
+
memo?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type WalletTxParams = {
|
|
35
|
+
feeOptionKey?: FeeOption;
|
|
36
|
+
from?: string;
|
|
37
|
+
memo?: string;
|
|
38
|
+
recipient: string;
|
|
39
|
+
assetValue: AssetValue;
|
|
40
|
+
gasLimit?: string | bigint;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type CtrlProviderType<T> = T extends typeof Chain.Solana
|
|
44
|
+
? SolanaProvider
|
|
45
|
+
: T extends Exclude<CosmosChain, TCLikeChain>
|
|
46
|
+
? Keplr
|
|
47
|
+
: T extends EVMChain
|
|
48
|
+
? Eip1193Provider
|
|
49
|
+
: T extends typeof Chain.Near
|
|
50
|
+
? NearBrowserWalletProvider
|
|
51
|
+
: undefined;
|
|
52
|
+
|
|
53
|
+
export function getCtrlProvider<T extends Chain>(chain: T): CtrlProviderType<T> {
|
|
54
|
+
if (!window.ctrl) throw new USwapError("wallet_ctrl_not_found");
|
|
55
|
+
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
return match(chain as Chain)
|
|
58
|
+
.with(...EVMChains, () => window.ctrl?.ethereum)
|
|
59
|
+
.with(Chain.Cosmos, Chain.Kujira, Chain.Noble, () => window.ctrl?.keplr)
|
|
60
|
+
.with(Chain.Bitcoin, () => window.ctrl?.bitcoin)
|
|
61
|
+
.with(Chain.BitcoinCash, () => window.ctrl?.bitcoincash)
|
|
62
|
+
.with(Chain.Dogecoin, () => window.ctrl?.dogecoin)
|
|
63
|
+
.with(Chain.Litecoin, () => window.ctrl?.litecoin)
|
|
64
|
+
.with(Chain.Solana, () => window.ctrl?.solana)
|
|
65
|
+
.with(Chain.THORChain, () => window.ctrl?.thorchain)
|
|
66
|
+
.with(Chain.Maya, () => window.ctrl?.mayachain)
|
|
67
|
+
.with(Chain.Near, () => window.ctrl?.near)
|
|
68
|
+
.otherwise(() => undefined);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function transaction({
|
|
72
|
+
method,
|
|
73
|
+
params,
|
|
74
|
+
chain,
|
|
75
|
+
}: {
|
|
76
|
+
method: TransactionMethod;
|
|
77
|
+
params: TransactionParams[];
|
|
78
|
+
chain: Chain;
|
|
79
|
+
}): Promise<string> {
|
|
80
|
+
const client = await getCtrlProvider(chain);
|
|
81
|
+
|
|
82
|
+
return new Promise<string>((resolve, reject) => {
|
|
83
|
+
if (client && "request" in client) {
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
client.request({ method, params }, (err: string, tx: string) => {
|
|
86
|
+
err ? reject(err) : resolve(tx);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function getCtrlAddress(chain: Chain) {
|
|
93
|
+
try {
|
|
94
|
+
const eipProvider = (await getCtrlProvider(chain)) as Eip1193Provider;
|
|
95
|
+
if (!eipProvider) {
|
|
96
|
+
throw new USwapError({ errorKey: "wallet_provider_not_found", info: { chain, wallet: WalletOption.CTRL } });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ([Chain.Cosmos, Chain.Kujira, Chain.Noble].includes(chain as Exclude<CosmosChain, TCLikeChain>)) {
|
|
100
|
+
const provider = await getCtrlProvider(Chain.Cosmos);
|
|
101
|
+
if (!provider || "request" in provider) {
|
|
102
|
+
throw new USwapError({ errorKey: "wallet_provider_not_found", info: { chain, wallet: WalletOption.CTRL } });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Enabling before using the Keplr is recommended.
|
|
106
|
+
// This method will ask the user whether to allow access if they haven't visited this website.
|
|
107
|
+
// Also, it will request that the user unlock the wallet if the wallet is locked.
|
|
108
|
+
const chainId = ChainToChainId[chain];
|
|
109
|
+
await provider.enable(chainId);
|
|
110
|
+
|
|
111
|
+
const offlineSigner = provider.getOfflineSigner(chainId);
|
|
112
|
+
|
|
113
|
+
const [item] = await offlineSigner.getAccounts();
|
|
114
|
+
return item?.address;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (EVMChains.includes(chain as EVMChain)) {
|
|
118
|
+
// For CTRL wallet, we need to use the request method directly on the provider
|
|
119
|
+
if ("request" in eipProvider && typeof eipProvider.request === "function") {
|
|
120
|
+
const accounts = await eipProvider.request({ method: "eth_requestAccounts" });
|
|
121
|
+
return accounts[0];
|
|
122
|
+
}
|
|
123
|
+
const { BrowserProvider } = await import("ethers");
|
|
124
|
+
const provider = new BrowserProvider(eipProvider, "any");
|
|
125
|
+
const [response] = await providerRequest({ method: "eth_requestAccounts", params: [], provider });
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (chain === Chain.Solana) {
|
|
130
|
+
const provider = await getCtrlProvider(Chain.Solana);
|
|
131
|
+
|
|
132
|
+
const accounts = await provider.connect();
|
|
133
|
+
return accounts.publicKey.toString();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (chain === Chain.Near) {
|
|
137
|
+
if (!window.ctrl?.near) {
|
|
138
|
+
throw new USwapError("wallet_ctrl_not_found", { chain: Chain.Near });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!window.ctrl.near.isSignedIn?.()) {
|
|
142
|
+
const result = await window.ctrl.near.request<string[]>?.({ method: "connect" });
|
|
143
|
+
return result?.[0] || "";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return window.ctrl.near.getAccountId?.() || "";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const accounts = await eipProvider.request({ method: "request_accounts", params: [] });
|
|
150
|
+
return accounts[0];
|
|
151
|
+
} catch {
|
|
152
|
+
throw new USwapError({ errorKey: "wallet_provider_not_found", info: { chain, wallet: WalletOption.CTRL } });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function walletTransfer(
|
|
157
|
+
{ assetValue, recipient, memo, gasLimit }: WalletTxParams,
|
|
158
|
+
method: TransactionMethod = "transfer",
|
|
159
|
+
) {
|
|
160
|
+
if (!assetValue) {
|
|
161
|
+
throw new USwapError("wallet_ctrl_asset_not_defined");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* EVM requires amount to be hex string
|
|
166
|
+
* UTXO/Cosmos requires amount to be number
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
const from = await getCtrlAddress(assetValue.chain);
|
|
170
|
+
const params = [
|
|
171
|
+
{
|
|
172
|
+
amount: { amount: assetValue.getBaseValue("number"), decimals: assetValue.decimal },
|
|
173
|
+
asset: {
|
|
174
|
+
chain: assetValue.chain,
|
|
175
|
+
symbol: assetValue.symbol.toUpperCase(),
|
|
176
|
+
ticker: assetValue.symbol.toUpperCase(),
|
|
177
|
+
},
|
|
178
|
+
from,
|
|
179
|
+
gasLimit,
|
|
180
|
+
memo: memo || "",
|
|
181
|
+
recipient,
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
return transaction({ chain: assetValue.chain, method, params });
|
|
186
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type Chain,
|
|
7
|
+
type EVMChain,
|
|
8
|
+
EVMChains,
|
|
9
|
+
filterSupportedChains,
|
|
10
|
+
getChainConfig,
|
|
11
|
+
prepareNetworkSwitch,
|
|
12
|
+
switchEVMWalletNetwork,
|
|
13
|
+
USwapError,
|
|
14
|
+
WalletOption,
|
|
15
|
+
} from "@tcswap/helpers";
|
|
16
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
17
|
+
import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
18
|
+
|
|
19
|
+
export type EVMWalletOptions =
|
|
20
|
+
| WalletOption.BRAVE
|
|
21
|
+
| WalletOption.OKX_MOBILE
|
|
22
|
+
| WalletOption.METAMASK
|
|
23
|
+
| WalletOption.TRUSTWALLET_WEB
|
|
24
|
+
| WalletOption.COINBASE_WEB
|
|
25
|
+
| WalletOption.EIP6963;
|
|
26
|
+
|
|
27
|
+
const getWalletForType = (
|
|
28
|
+
walletType:
|
|
29
|
+
| WalletOption.BRAVE
|
|
30
|
+
| WalletOption.OKX_MOBILE
|
|
31
|
+
| WalletOption.METAMASK
|
|
32
|
+
| WalletOption.TRUSTWALLET_WEB
|
|
33
|
+
| WalletOption.COINBASE_WEB
|
|
34
|
+
| WalletOption.EIP6963,
|
|
35
|
+
) => {
|
|
36
|
+
switch (walletType) {
|
|
37
|
+
case WalletOption.COINBASE_WEB:
|
|
38
|
+
return window.coinbaseWalletExtension;
|
|
39
|
+
case WalletOption.TRUSTWALLET_WEB:
|
|
40
|
+
return window.trustwallet;
|
|
41
|
+
default:
|
|
42
|
+
return window.ethereum;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const getWeb3WalletMethods = async ({
|
|
47
|
+
address,
|
|
48
|
+
walletProvider,
|
|
49
|
+
chain,
|
|
50
|
+
provider,
|
|
51
|
+
}: {
|
|
52
|
+
address: string;
|
|
53
|
+
walletProvider?: Eip1193Provider;
|
|
54
|
+
chain: EVMChain;
|
|
55
|
+
provider: BrowserProvider;
|
|
56
|
+
}) => {
|
|
57
|
+
if (!walletProvider) throw new USwapError("wallet_evm_extensions_not_found");
|
|
58
|
+
const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
59
|
+
|
|
60
|
+
const signer = await provider.getSigner();
|
|
61
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
62
|
+
const { chainIdHex } = getChainConfig(chain);
|
|
63
|
+
|
|
64
|
+
const currentNetwork = await provider.getNetwork();
|
|
65
|
+
if (currentNetwork.chainId.toString() !== chainIdHex) {
|
|
66
|
+
try {
|
|
67
|
+
const networkParams = toolbox.getNetworkParams();
|
|
68
|
+
await switchEVMWalletNetwork(provider, chain, networkParams);
|
|
69
|
+
} catch {
|
|
70
|
+
throw new USwapError("wallet_evm_extensions_failed_to_switch_network", { chain });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return prepareNetworkSwitch({
|
|
75
|
+
chain,
|
|
76
|
+
provider,
|
|
77
|
+
toolbox: { ...toolbox, getBalance: () => toolbox.getBalance(address) },
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const evmWallet = createWallet({
|
|
82
|
+
connect: ({ addChain, supportedChains }) =>
|
|
83
|
+
async function connectEVMWallet(
|
|
84
|
+
chains: Chain[],
|
|
85
|
+
walletType: EVMWalletOptions = WalletOption.METAMASK,
|
|
86
|
+
eip1193Provider?: Eip1193Provider,
|
|
87
|
+
) {
|
|
88
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
89
|
+
const { BrowserProvider } = await import("ethers");
|
|
90
|
+
|
|
91
|
+
await Promise.all(
|
|
92
|
+
filteredChains.map(async (chain) => {
|
|
93
|
+
if (walletType === WalletOption.EIP6963 && !eip1193Provider)
|
|
94
|
+
throw new USwapError("wallet_evm_extensions_no_provider");
|
|
95
|
+
|
|
96
|
+
const windowProvider = eip1193Provider || getWalletForType(walletType);
|
|
97
|
+
const browserProvider = new BrowserProvider(windowProvider, "any");
|
|
98
|
+
|
|
99
|
+
await browserProvider.send("eth_requestAccounts", []);
|
|
100
|
+
const signer = await browserProvider.getSigner();
|
|
101
|
+
const address = await signer.getAddress();
|
|
102
|
+
|
|
103
|
+
const walletMethods = await getWeb3WalletMethods({
|
|
104
|
+
address,
|
|
105
|
+
chain,
|
|
106
|
+
provider: browserProvider,
|
|
107
|
+
walletProvider: windowProvider,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const disconnect = () => browserProvider.send("wallet_revokePermissions", [{ eth_accounts: {} }]);
|
|
111
|
+
addChain({ ...walletMethods, address, chain, disconnect, walletType });
|
|
112
|
+
return;
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
name: "connectEVMWallet",
|
|
119
|
+
supportedChains: [...EVMChains] as EVMChain[],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const EVM_EXTENSIONS_SUPPORTED_CHAINS = getWalletSupportedChains(evmWallet);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Eip1193Provider } from "ethers";
|
|
2
|
+
|
|
3
|
+
export interface EIP6963ProviderInfo {
|
|
4
|
+
walletId: string;
|
|
5
|
+
uuid: string;
|
|
6
|
+
name: string;
|
|
7
|
+
icon: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface EIP6963ProviderDetail {
|
|
11
|
+
info: EIP6963ProviderInfo;
|
|
12
|
+
provider: Eip1193Provider;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type EIP6963AnnounceProviderEvent = { detail: { info: EIP6963ProviderInfo; provider: Eip1193Provider } };
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NEAR Browser Wallet Provider Interface Definitions
|
|
3
|
+
*
|
|
4
|
+
* This file contains the standard TypeScript interface definitions for NEAR browser wallet providers
|
|
5
|
+
* that inject themselves into the window object (e.g., OKX, XDEFI/CTRL, etc.)
|
|
6
|
+
*
|
|
7
|
+
* Based on:
|
|
8
|
+
* - NEAR Protocol wallet-selector library
|
|
9
|
+
* - Common patterns from OKX, XDEFI/CTRL, and other NEAR wallet implementations
|
|
10
|
+
* - NEAR API JS types
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { PublicKey } from "@near-js/crypto";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Transaction action types supported by NEAR
|
|
17
|
+
*/
|
|
18
|
+
export interface NearAction {
|
|
19
|
+
type: "FunctionCall" | "Transfer" | "Stake" | "AddKey" | "DeleteKey" | "DeleteAccount";
|
|
20
|
+
params?: {
|
|
21
|
+
methodName?: string;
|
|
22
|
+
args?: object;
|
|
23
|
+
gas?: string;
|
|
24
|
+
deposit?: string;
|
|
25
|
+
publicKey?: string;
|
|
26
|
+
beneficiaryId?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Transaction structure for NEAR
|
|
32
|
+
*/
|
|
33
|
+
export interface NearTransaction {
|
|
34
|
+
receiverId: string;
|
|
35
|
+
actions: NearAction[];
|
|
36
|
+
// Optional fields
|
|
37
|
+
signerId?: string;
|
|
38
|
+
publicKey?: string;
|
|
39
|
+
nonce?: number;
|
|
40
|
+
recentBlockHash?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Message signing parameters
|
|
45
|
+
*/
|
|
46
|
+
export interface NearSignMessageParams {
|
|
47
|
+
message: string;
|
|
48
|
+
recipient: string;
|
|
49
|
+
nonce: Buffer | Uint8Array;
|
|
50
|
+
callbackUrl?: string;
|
|
51
|
+
state?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Signed message response
|
|
56
|
+
*/
|
|
57
|
+
export interface NearSignedMessage {
|
|
58
|
+
accountId: string;
|
|
59
|
+
publicKey: string;
|
|
60
|
+
signature: string;
|
|
61
|
+
// Optional callback data
|
|
62
|
+
callbackUrl?: string;
|
|
63
|
+
state?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Sign-in request parameters
|
|
68
|
+
*/
|
|
69
|
+
export interface NearSignInParams {
|
|
70
|
+
contractId?: string;
|
|
71
|
+
methodNames?: string[];
|
|
72
|
+
// Success and failure URLs for browser wallets
|
|
73
|
+
successUrl?: string;
|
|
74
|
+
failureUrl?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Account information
|
|
79
|
+
*/
|
|
80
|
+
export interface NearAccount {
|
|
81
|
+
accountId: string;
|
|
82
|
+
publicKey?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Access key information
|
|
87
|
+
*/
|
|
88
|
+
export interface NearAccessKey {
|
|
89
|
+
publicKey: PublicKey;
|
|
90
|
+
accessKey: {
|
|
91
|
+
nonce: number;
|
|
92
|
+
permission: "FullAccess" | { FunctionCall: { allowance?: string; receiverId: string; methodNames: string[] } };
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Transaction execution result
|
|
98
|
+
*/
|
|
99
|
+
export interface NearFinalExecutionOutcome {
|
|
100
|
+
status: object;
|
|
101
|
+
transaction: object;
|
|
102
|
+
transaction_outcome: object;
|
|
103
|
+
receipts_outcome: object[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Standard NEAR browser wallet provider interface
|
|
108
|
+
*
|
|
109
|
+
* This interface represents the common API surface that NEAR browser wallets
|
|
110
|
+
* expose when they inject themselves into the window object.
|
|
111
|
+
*/
|
|
112
|
+
export interface NearBrowserWalletProvider {
|
|
113
|
+
// Connection Management
|
|
114
|
+
/**
|
|
115
|
+
* Request connection to the wallet
|
|
116
|
+
* Returns array of account IDs that were connected
|
|
117
|
+
*/
|
|
118
|
+
connect(): Promise<string[]>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Alternative connection method used by some wallets
|
|
122
|
+
*/
|
|
123
|
+
request?(params: { method: "connect"; params?: any }): Promise<string[]>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Disconnect from the wallet
|
|
127
|
+
*/
|
|
128
|
+
disconnect(): Promise<void>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Sign out from the wallet (some wallets use this instead of disconnect)
|
|
132
|
+
*/
|
|
133
|
+
signOut?(): void;
|
|
134
|
+
|
|
135
|
+
// Account Management
|
|
136
|
+
/**
|
|
137
|
+
* Check if user is signed in
|
|
138
|
+
*/
|
|
139
|
+
isSignedIn?(): boolean;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get the current account ID
|
|
143
|
+
*/
|
|
144
|
+
getAccountId(): string | Promise<string>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get list of accounts (some wallets support multiple accounts)
|
|
148
|
+
*/
|
|
149
|
+
getAccounts?(): Promise<NearAccount[]>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get the public key for the current account
|
|
153
|
+
*/
|
|
154
|
+
getPublicKey?(): Promise<string>;
|
|
155
|
+
|
|
156
|
+
// Legacy sign-in methods (used by some wallets)
|
|
157
|
+
/**
|
|
158
|
+
* Request sign in (legacy method)
|
|
159
|
+
*/
|
|
160
|
+
requestSignIn?(params: NearSignInParams): Promise<NearAccount>;
|
|
161
|
+
|
|
162
|
+
// Signing Operations
|
|
163
|
+
/**
|
|
164
|
+
* Sign a message
|
|
165
|
+
*/
|
|
166
|
+
signMessage(params: NearSignMessageParams): Promise<NearSignedMessage>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Sign and send a single transaction
|
|
170
|
+
*/
|
|
171
|
+
signAndSendTransaction(params: {
|
|
172
|
+
receiverId: string;
|
|
173
|
+
actions: NearAction[];
|
|
174
|
+
// Optional parameters
|
|
175
|
+
signerId?: string;
|
|
176
|
+
publicKey?: string;
|
|
177
|
+
nonce?: number;
|
|
178
|
+
recentBlockHash?: string;
|
|
179
|
+
}): Promise<NearFinalExecutionOutcome>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Sign and send multiple transactions
|
|
183
|
+
*/
|
|
184
|
+
signAndSendTransactions(params: { transactions: NearTransaction[] }): Promise<NearFinalExecutionOutcome[]>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Request signing of transactions (alternative method used by some wallets)
|
|
188
|
+
*/
|
|
189
|
+
requestSignTransactions?(params: { transactions: NearTransaction[] }): Promise<any>;
|
|
190
|
+
|
|
191
|
+
// Verification
|
|
192
|
+
/**
|
|
193
|
+
* Verify ownership of an account
|
|
194
|
+
*/
|
|
195
|
+
verifyOwner?(params: {
|
|
196
|
+
message: string;
|
|
197
|
+
// Additional parameters may vary by wallet
|
|
198
|
+
}): Promise<{
|
|
199
|
+
accountId: string;
|
|
200
|
+
publicKey: string;
|
|
201
|
+
signature: string;
|
|
202
|
+
// Additional fields may be returned
|
|
203
|
+
}>;
|
|
204
|
+
|
|
205
|
+
// Network Information
|
|
206
|
+
/**
|
|
207
|
+
* Get the current network (mainnet, testnet, etc.)
|
|
208
|
+
*/
|
|
209
|
+
getNetwork?(): string | Promise<string>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Check if wallet is connected to mainnet
|
|
213
|
+
*/
|
|
214
|
+
isMainnet?(): boolean;
|
|
215
|
+
|
|
216
|
+
// Wallet Metadata
|
|
217
|
+
/**
|
|
218
|
+
* Wallet name or identifier
|
|
219
|
+
*/
|
|
220
|
+
name?: string;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Wallet version
|
|
224
|
+
*/
|
|
225
|
+
version?: string;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Check if this is a specific wallet (used for wallet detection)
|
|
229
|
+
*/
|
|
230
|
+
isOKX?: boolean;
|
|
231
|
+
isXDEFI?: boolean;
|
|
232
|
+
isCTRL?: boolean;
|
|
233
|
+
|
|
234
|
+
// Event Handling (not all wallets support events)
|
|
235
|
+
on?(event: "accountsChanged" | "networkChanged" | "disconnect", handler: (...args: any[]) => void): void;
|
|
236
|
+
off?(event: string, handler: (...args: any[]) => void): void;
|
|
237
|
+
removeListener?(event: string, handler: (...args: any[]) => void): void;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Extended window interface for NEAR wallets
|
|
242
|
+
*/
|
|
243
|
+
declare global {
|
|
244
|
+
interface Window {
|
|
245
|
+
// Generic NEAR provider (if wallet uses this pattern)
|
|
246
|
+
near?: NearBrowserWalletProvider;
|
|
247
|
+
|
|
248
|
+
// Specific wallet providers
|
|
249
|
+
okxwallet?: { near: NearBrowserWalletProvider };
|
|
250
|
+
|
|
251
|
+
ctrl?: { near: NearBrowserWalletProvider };
|
|
252
|
+
|
|
253
|
+
// Add other wallet-specific providers as needed
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Helper type for wallet detection
|
|
259
|
+
*/
|
|
260
|
+
export type NearWalletType = "okx" | "xdefi" | "ctrl" | "generic";
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Configuration for NEAR network
|
|
264
|
+
*/
|
|
265
|
+
export interface NearNetworkConfig {
|
|
266
|
+
networkId: "mainnet" | "testnet" | "betanet";
|
|
267
|
+
nodeUrl: string;
|
|
268
|
+
walletUrl?: string;
|
|
269
|
+
helperUrl?: string;
|
|
270
|
+
}
|