@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,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Chain, DerivationPathArray } from "@tcswap/helpers";
|
|
6
|
+
import { USwapError, WalletOption } from "@tcswap/helpers";
|
|
7
|
+
import type { JsonRpcProvider, Provider, Signer, TypedDataDomain, TypedDataField } from "ethers";
|
|
8
|
+
|
|
9
|
+
type OneKeyEVMSignerParams = {
|
|
10
|
+
chain: Chain;
|
|
11
|
+
derivationPath: DerivationPathArray;
|
|
12
|
+
provider: Provider | JsonRpcProvider;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export async function getEVMSigner({ chain, derivationPath, provider }: OneKeyEVMSignerParams) {
|
|
16
|
+
const { AbstractSigner, BrowserProvider } = await import("ethers");
|
|
17
|
+
|
|
18
|
+
class OneKeySigner extends AbstractSigner {
|
|
19
|
+
address: string;
|
|
20
|
+
chain: Chain;
|
|
21
|
+
derivationPath: DerivationPathArray;
|
|
22
|
+
readonly provider: Provider | JsonRpcProvider;
|
|
23
|
+
|
|
24
|
+
constructor({ chain, derivationPath, provider }: OneKeyEVMSignerParams) {
|
|
25
|
+
super(provider);
|
|
26
|
+
|
|
27
|
+
this.address = "";
|
|
28
|
+
this.chain = chain;
|
|
29
|
+
this.derivationPath = derivationPath;
|
|
30
|
+
this.provider = provider;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
connect(provider: null | Provider): Signer {
|
|
34
|
+
if (!provider) {
|
|
35
|
+
throw new USwapError({
|
|
36
|
+
errorKey: "wallet_provider_not_found",
|
|
37
|
+
info: { chain: this.chain, wallet: WalletOption.ONEKEY },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new OneKeySigner({ chain: this.chain, derivationPath: this.derivationPath, provider });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
signTypedData(
|
|
45
|
+
domain: TypedDataDomain,
|
|
46
|
+
types: Record<string, TypedDataField[]>,
|
|
47
|
+
value: Record<string, any>,
|
|
48
|
+
): Promise<string> {
|
|
49
|
+
if (!window.$onekey?.ethereum) {
|
|
50
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain: this.chain } });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.getAddress().then(async (_address) => {
|
|
54
|
+
try {
|
|
55
|
+
const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
|
|
56
|
+
return signer.signTypedData(domain, types, value);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new USwapError({
|
|
59
|
+
errorKey: "core_wallet_sign_message_not_supported",
|
|
60
|
+
info: { error, wallet: WalletOption.ONEKEY },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getAddress = async () => {
|
|
67
|
+
if (this.address) return this.address;
|
|
68
|
+
|
|
69
|
+
if (!window.$onekey?.ethereum) {
|
|
70
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain: this.chain } });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
|
|
74
|
+
this.address = await signer.getAddress();
|
|
75
|
+
return this.address;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
signMessage = async (message: string) => {
|
|
79
|
+
if (!window.$onekey?.ethereum) {
|
|
80
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain: this.chain } });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
|
|
84
|
+
return signer.signMessage(message);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
signTransaction = async (transaction: any) => {
|
|
88
|
+
if (!window.$onekey?.ethereum) {
|
|
89
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain: this.chain } });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
|
|
93
|
+
const { to, value, gasLimit, gasPrice, data, maxFeePerGas, maxPriorityFeePerGas } = transaction;
|
|
94
|
+
|
|
95
|
+
if (!to) throw new USwapError("toolbox_evm_no_to_address");
|
|
96
|
+
if (!gasLimit) throw new USwapError("toolbox_evm_no_gas_price");
|
|
97
|
+
|
|
98
|
+
const tx: any = { data, gasLimit, to };
|
|
99
|
+
|
|
100
|
+
if (value) {
|
|
101
|
+
tx.value = value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (maxFeePerGas && maxPriorityFeePerGas) {
|
|
105
|
+
tx.maxFeePerGas = maxFeePerGas;
|
|
106
|
+
tx.maxPriorityFeePerGas = maxPriorityFeePerGas;
|
|
107
|
+
} else if (gasPrice) {
|
|
108
|
+
tx.gasPrice = gasPrice;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return signer.signTransaction(tx);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return new OneKeySigner({ chain, derivationPath, provider });
|
|
116
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
addEVMWalletNetwork,
|
|
7
|
+
Chain,
|
|
8
|
+
filterSupportedChains,
|
|
9
|
+
type NetworkParams,
|
|
10
|
+
prepareNetworkSwitch,
|
|
11
|
+
USwapError,
|
|
12
|
+
WalletOption,
|
|
13
|
+
} from "@tcswap/helpers";
|
|
14
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
15
|
+
import { Psbt } from "bitcoinjs-lib";
|
|
16
|
+
import type { BitcoinProvider, GetAddressOptions, GetAddressResponse, SignTransactionOptions } from "sats-connect";
|
|
17
|
+
|
|
18
|
+
async function getWalletMethodsForExtension(chain: Chain) {
|
|
19
|
+
switch (chain) {
|
|
20
|
+
case Chain.Bitcoin: {
|
|
21
|
+
if (!window.$onekey?.btc) {
|
|
22
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain } });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { getUtxoToolbox } = await import("@tcswap/toolboxes/utxo");
|
|
26
|
+
const {
|
|
27
|
+
signTransaction: satsSignTransaction,
|
|
28
|
+
getAddress,
|
|
29
|
+
AddressPurpose,
|
|
30
|
+
BitcoinNetworkType,
|
|
31
|
+
} = await import("sats-connect");
|
|
32
|
+
|
|
33
|
+
let address = "";
|
|
34
|
+
|
|
35
|
+
const getProvider = () => new Promise<BitcoinProvider>((res) => res(window.$onekey?.btc));
|
|
36
|
+
|
|
37
|
+
const getAddressOptions: GetAddressOptions = {
|
|
38
|
+
getProvider,
|
|
39
|
+
onCancel: () => {
|
|
40
|
+
throw new USwapError("wallet_connection_rejected_by_user");
|
|
41
|
+
},
|
|
42
|
+
onFinish: (response: GetAddressResponse) => {
|
|
43
|
+
if (response.addresses[0]?.address) {
|
|
44
|
+
address = response.addresses[0].address;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
payload: {
|
|
48
|
+
message: "Address for receiving and sending payments",
|
|
49
|
+
network: { type: BitcoinNetworkType.Mainnet },
|
|
50
|
+
purposes: [AddressPurpose.Payment],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
await getAddress(getAddressOptions);
|
|
55
|
+
|
|
56
|
+
async function signTransaction(psbt: Psbt) {
|
|
57
|
+
let signedPsbt: Psbt | undefined;
|
|
58
|
+
const signPsbtOptions: SignTransactionOptions = {
|
|
59
|
+
getProvider,
|
|
60
|
+
onCancel: () => {
|
|
61
|
+
throw new USwapError("wallet_connection_rejected_by_user");
|
|
62
|
+
},
|
|
63
|
+
onFinish: (response) => {
|
|
64
|
+
signedPsbt = Psbt.fromBase64(response.psbtBase64);
|
|
65
|
+
},
|
|
66
|
+
payload: {
|
|
67
|
+
broadcast: false,
|
|
68
|
+
inputsToSign: [{ address, signingIndexes: psbt.txInputs.map((_: any, index: number) => index) }],
|
|
69
|
+
message: "Sign transaction",
|
|
70
|
+
network: { type: BitcoinNetworkType.Mainnet },
|
|
71
|
+
psbtBase64: psbt.toBase64(),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
await satsSignTransaction(signPsbtOptions);
|
|
76
|
+
if (!signedPsbt) throw new USwapError("wallet_onekey_sign_transaction_error");
|
|
77
|
+
return signedPsbt;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const signer = { getAddress: () => Promise.resolve(address), signTransaction };
|
|
81
|
+
|
|
82
|
+
const toolbox = await getUtxoToolbox(chain, { signer });
|
|
83
|
+
|
|
84
|
+
return { ...toolbox, address };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
case Chain.Solana: {
|
|
88
|
+
if (!window.$onekey?.sol) {
|
|
89
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain } });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const { getSolanaToolbox } = await import("@tcswap/toolboxes/solana");
|
|
93
|
+
|
|
94
|
+
const signer = window.$onekey.sol;
|
|
95
|
+
const address = await signer.getAddress();
|
|
96
|
+
const toolbox = await getSolanaToolbox({ signer });
|
|
97
|
+
|
|
98
|
+
return { ...toolbox, address };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
case Chain.Arbitrum:
|
|
102
|
+
case Chain.Aurora:
|
|
103
|
+
case Chain.Avalanche:
|
|
104
|
+
case Chain.Base:
|
|
105
|
+
case Chain.BinanceSmartChain:
|
|
106
|
+
case Chain.Ethereum:
|
|
107
|
+
case Chain.Gnosis:
|
|
108
|
+
case Chain.Optimism:
|
|
109
|
+
case Chain.Polygon:
|
|
110
|
+
case Chain.XLayer: {
|
|
111
|
+
const { getProvider, getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
112
|
+
if (!window.$onekey?.ethereum) {
|
|
113
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { chain } });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const { BrowserProvider } = await import("ethers");
|
|
117
|
+
const provider = new BrowserProvider(window.$onekey.ethereum, "any");
|
|
118
|
+
|
|
119
|
+
await provider.send("eth_requestAccounts", []);
|
|
120
|
+
const jsonRpcProvider = await getProvider(chain);
|
|
121
|
+
const signer = await provider.getSigner();
|
|
122
|
+
const address = await signer.getAddress();
|
|
123
|
+
|
|
124
|
+
const toolbox = await getEvmToolbox(chain, { provider: jsonRpcProvider, signer });
|
|
125
|
+
try {
|
|
126
|
+
if (chain !== Chain.Ethereum) {
|
|
127
|
+
const networkParams = toolbox.getNetworkParams() as NetworkParams;
|
|
128
|
+
|
|
129
|
+
await addEVMWalletNetwork(provider, networkParams);
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw new USwapError({ errorKey: "wallet_failed_to_add_or_switch_network", info: { chain, error } });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { address, ...prepareNetworkSwitch({ chain, provider, toolbox }) };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
default:
|
|
139
|
+
throw new USwapError({ errorKey: "wallet_chain_not_supported", info: { chain, wallet: WalletOption.ONEKEY } });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const onekeyWallet = createWallet({
|
|
144
|
+
connect: ({ addChain, walletType, supportedChains }) =>
|
|
145
|
+
async function connectOnekeyWallet(chains: Chain[]) {
|
|
146
|
+
if (!window.$onekey) {
|
|
147
|
+
throw new USwapError({ errorKey: "wallet_onekey_not_found", info: { wallet: WalletOption.ONEKEY } });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
151
|
+
|
|
152
|
+
await Promise.all(
|
|
153
|
+
filteredChains.map(async (chain) => {
|
|
154
|
+
const walletMethods = await getWalletMethodsForExtension(chain);
|
|
155
|
+
|
|
156
|
+
const address = (await walletMethods.getAddress()) || "F";
|
|
157
|
+
|
|
158
|
+
addChain({ ...walletMethods, address, chain, walletType });
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return true;
|
|
163
|
+
},
|
|
164
|
+
name: "connectOnekeyWallet",
|
|
165
|
+
supportedChains: [
|
|
166
|
+
Chain.Arbitrum,
|
|
167
|
+
Chain.Aurora,
|
|
168
|
+
Chain.Avalanche,
|
|
169
|
+
Chain.Base,
|
|
170
|
+
Chain.BinanceSmartChain,
|
|
171
|
+
Chain.Bitcoin,
|
|
172
|
+
Chain.Ethereum,
|
|
173
|
+
Chain.Gnosis,
|
|
174
|
+
Chain.Optimism,
|
|
175
|
+
Chain.Polygon,
|
|
176
|
+
Chain.Solana,
|
|
177
|
+
Chain.XLayer,
|
|
178
|
+
],
|
|
179
|
+
walletType: WalletOption.ONEKEY,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const ONEKEY_WALLET_SUPPORTED_CHAINS = getWalletSupportedChains(onekeyWallet);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type AssetValue,
|
|
7
|
+
Chain,
|
|
8
|
+
filterSupportedChains,
|
|
9
|
+
type GenericTransferParams,
|
|
10
|
+
USwapError,
|
|
11
|
+
WalletOption,
|
|
12
|
+
} from "@tcswap/helpers";
|
|
13
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
14
|
+
|
|
15
|
+
export const phantomWallet = createWallet({
|
|
16
|
+
connect: ({ addChain, supportedChains, walletType }) =>
|
|
17
|
+
async function connectPhantom(chains: Chain[]) {
|
|
18
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await Promise.all(
|
|
22
|
+
filteredChains.map(async (chain) => {
|
|
23
|
+
const { address, ...methods } = await getWalletMethods(chain);
|
|
24
|
+
|
|
25
|
+
addChain({ ...methods, address, chain, walletType });
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return true;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof USwapError) throw error;
|
|
32
|
+
|
|
33
|
+
throw new USwapError("wallet_connection_rejected_by_user", error);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
name: "connectPhantom",
|
|
37
|
+
supportedChains: [Chain.Bitcoin, Chain.Ethereum, Chain.Monad, Chain.Solana],
|
|
38
|
+
walletType: WalletOption.PHANTOM,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const PHANTOM_SUPPORTED_CHAINS = getWalletSupportedChains(phantomWallet);
|
|
42
|
+
export type PhantomSupportedChain = (typeof PHANTOM_SUPPORTED_CHAINS)[number];
|
|
43
|
+
|
|
44
|
+
async function getWalletMethods(chain: PhantomSupportedChain) {
|
|
45
|
+
const phantom: any = window?.phantom;
|
|
46
|
+
|
|
47
|
+
switch (chain) {
|
|
48
|
+
case Chain.Bitcoin: {
|
|
49
|
+
const provider = phantom?.bitcoin;
|
|
50
|
+
if (!provider?.isPhantom) {
|
|
51
|
+
throw new USwapError("wallet_phantom_not_found");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { getUtxoToolbox } = await import("@tcswap/toolboxes/utxo");
|
|
55
|
+
const [{ address }] = await provider.requestAccounts();
|
|
56
|
+
const toolbox = await getUtxoToolbox(chain);
|
|
57
|
+
|
|
58
|
+
return { ...toolbox, address };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
case Chain.Ethereum:
|
|
62
|
+
case Chain.Monad: {
|
|
63
|
+
const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
64
|
+
const { prepareNetworkSwitch, switchEVMWalletNetwork } = await import("@tcswap/helpers");
|
|
65
|
+
const { BrowserProvider } = await import("ethers");
|
|
66
|
+
|
|
67
|
+
const provider = new BrowserProvider(phantom?.ethereum, "any");
|
|
68
|
+
const [address] = await provider.send("eth_requestAccounts", []);
|
|
69
|
+
|
|
70
|
+
const signer = await provider.getSigner();
|
|
71
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
72
|
+
|
|
73
|
+
if (chain !== Chain.Ethereum) {
|
|
74
|
+
const networkParams = toolbox.getNetworkParams();
|
|
75
|
+
await switchEVMWalletNetwork(provider, chain, networkParams);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { ...prepareNetworkSwitch({ chain, provider, toolbox }), address };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
case Chain.Solana: {
|
|
82
|
+
const { getSolanaToolbox } = await import("@tcswap/toolboxes/solana");
|
|
83
|
+
const provider = phantom?.solana;
|
|
84
|
+
if (!provider?.isPhantom) {
|
|
85
|
+
throw new USwapError("wallet_phantom_not_found");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const providerConnection = await provider.connect();
|
|
89
|
+
const address: string = providerConnection.publicKey.toString();
|
|
90
|
+
const toolbox = await getSolanaToolbox({ signer: provider });
|
|
91
|
+
|
|
92
|
+
const transfer = async ({
|
|
93
|
+
recipient,
|
|
94
|
+
assetValue,
|
|
95
|
+
isProgramDerivedAddress,
|
|
96
|
+
}: GenericTransferParams & { assetValue: AssetValue; isProgramDerivedAddress?: boolean }) => {
|
|
97
|
+
const { PublicKey } = await import("@solana/web3.js");
|
|
98
|
+
const validateAddress = await toolbox.getAddressValidator();
|
|
99
|
+
|
|
100
|
+
if (!(isProgramDerivedAddress || validateAddress(recipient))) {
|
|
101
|
+
throw new USwapError("core_transaction_invalid_recipient_address");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const fromPubkey = new PublicKey(address);
|
|
105
|
+
const connection = await toolbox.getConnection();
|
|
106
|
+
|
|
107
|
+
const transaction = await toolbox.createTransaction({
|
|
108
|
+
assetValue,
|
|
109
|
+
isProgramDerivedAddress,
|
|
110
|
+
recipient,
|
|
111
|
+
sender: address,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (!transaction) {
|
|
115
|
+
throw new USwapError("core_transaction_invalid_sender_address");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const blockHash = await connection.getLatestBlockhash();
|
|
119
|
+
transaction.recentBlockhash = blockHash.blockhash;
|
|
120
|
+
transaction.feePayer = fromPubkey;
|
|
121
|
+
|
|
122
|
+
const signedTransaction = await provider.signTransaction(transaction);
|
|
123
|
+
|
|
124
|
+
const txid = await connection.sendRawTransaction(signedTransaction.serialize());
|
|
125
|
+
|
|
126
|
+
return txid;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return { ...toolbox, address, transfer };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
default: {
|
|
133
|
+
throw new USwapError("wallet_chain_not_supported", { chain, wallet: WalletOption.PHANTOM });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Chain, filterSupportedChains, USwapError, WalletOption } from "@tcswap/helpers";
|
|
6
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
7
|
+
|
|
8
|
+
export const polkadotWallet = createWallet({
|
|
9
|
+
connect: ({ addChain, supportedChains, walletType }) =>
|
|
10
|
+
async function connectPolkadotJs(chains: Chain[]) {
|
|
11
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
12
|
+
|
|
13
|
+
await Promise.all(
|
|
14
|
+
filteredChains.map(async (chain) => {
|
|
15
|
+
const { address, ...walletMethods } = await getWalletMethods(chain);
|
|
16
|
+
|
|
17
|
+
addChain({ ...walletMethods, address, chain, walletType });
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
name: "connectPolkadotJs",
|
|
24
|
+
supportedChains: [Chain.Polkadot],
|
|
25
|
+
walletType: WalletOption.POLKADOT_JS,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const POLKADOT_SUPPORTED_CHAINS = getWalletSupportedChains(polkadotWallet);
|
|
29
|
+
|
|
30
|
+
async function getWalletMethods(chain: Chain) {
|
|
31
|
+
switch (chain) {
|
|
32
|
+
case Chain.Polkadot: {
|
|
33
|
+
const { getSubstrateToolbox } = await import("@tcswap/toolboxes/substrate");
|
|
34
|
+
const injectedExtension = window?.injectedWeb3?.["polkadot-js"];
|
|
35
|
+
|
|
36
|
+
const rawExtension = await injectedExtension?.enable?.("polkadot-js");
|
|
37
|
+
if (!rawExtension) {
|
|
38
|
+
throw new USwapError({ errorKey: "wallet_polkadot_not_found", info: { chain } });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const toolbox = await getSubstrateToolbox(chain, { signer: rawExtension.signer });
|
|
42
|
+
const [account] = await rawExtension.accounts.get();
|
|
43
|
+
|
|
44
|
+
if (!account?.address) {
|
|
45
|
+
throw new USwapError({
|
|
46
|
+
errorKey: "wallet_missing_params",
|
|
47
|
+
info: { address: account?.address, wallet: WalletOption.POLKADOT_JS },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const address = toolbox.convertAddress(account.address, 0);
|
|
52
|
+
return { ...toolbox, address, getAddress: () => address };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
default:
|
|
56
|
+
throw new USwapError({
|
|
57
|
+
errorKey: "wallet_chain_not_supported",
|
|
58
|
+
info: { chain, wallet: WalletOption.POLKADOT_JS },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Chain,
|
|
7
|
+
type EVMChain,
|
|
8
|
+
filterSupportedChains,
|
|
9
|
+
prepareNetworkSwitch,
|
|
10
|
+
switchEVMWalletNetwork,
|
|
11
|
+
USwapError,
|
|
12
|
+
WalletOption,
|
|
13
|
+
} from "@tcswap/helpers";
|
|
14
|
+
import { createWallet, getWalletSupportedChains } from "@tcswap/wallet-core";
|
|
15
|
+
import type { Eip1193Provider } from "ethers";
|
|
16
|
+
|
|
17
|
+
export const talismanWallet = createWallet({
|
|
18
|
+
connect: ({ addChain, supportedChains, walletType }) =>
|
|
19
|
+
async function connectTalisman(chains: Chain[]) {
|
|
20
|
+
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
21
|
+
|
|
22
|
+
await Promise.all(
|
|
23
|
+
filteredChains.map(async (chain) => {
|
|
24
|
+
const walletMethods = await getWalletMethods(chain);
|
|
25
|
+
|
|
26
|
+
addChain({ ...walletMethods, chain, walletType });
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
},
|
|
32
|
+
name: "connectTalisman",
|
|
33
|
+
supportedChains: [
|
|
34
|
+
Chain.Ethereum,
|
|
35
|
+
Chain.Arbitrum,
|
|
36
|
+
Chain.Avalanche,
|
|
37
|
+
Chain.Base,
|
|
38
|
+
Chain.Monad,
|
|
39
|
+
Chain.Polygon,
|
|
40
|
+
Chain.BinanceSmartChain,
|
|
41
|
+
Chain.Optimism,
|
|
42
|
+
Chain.XLayer,
|
|
43
|
+
Chain.Polkadot,
|
|
44
|
+
Chain.Chainflip,
|
|
45
|
+
],
|
|
46
|
+
walletType: WalletOption.TALISMAN,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const TALISMAN_SUPPORTED_CHAINS = getWalletSupportedChains(talismanWallet);
|
|
50
|
+
|
|
51
|
+
async function getWeb3WalletMethods({
|
|
52
|
+
walletProvider,
|
|
53
|
+
chain,
|
|
54
|
+
}: {
|
|
55
|
+
walletProvider: Eip1193Provider | undefined;
|
|
56
|
+
chain: EVMChain;
|
|
57
|
+
}) {
|
|
58
|
+
const { getEvmToolbox } = await import("@tcswap/toolboxes/evm");
|
|
59
|
+
const { BrowserProvider } = await import("ethers");
|
|
60
|
+
|
|
61
|
+
if (!walletProvider) {
|
|
62
|
+
throw new USwapError({ errorKey: "wallet_provider_not_found", info: { chain, wallet: WalletOption.TALISMAN } });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const provider = new BrowserProvider(walletProvider, "any");
|
|
66
|
+
const signer = await provider.getSigner();
|
|
67
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
if (chain !== Chain.Ethereum) {
|
|
71
|
+
await switchEVMWalletNetwork(provider, chain, toolbox.getNetworkParams());
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
throw new USwapError({
|
|
75
|
+
errorKey: "wallet_failed_to_add_or_switch_network",
|
|
76
|
+
info: { chain, wallet: WalletOption.TALISMAN },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return prepareNetworkSwitch({ chain, provider, toolbox });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function getWalletMethods(chain: Chain) {
|
|
84
|
+
switch (chain) {
|
|
85
|
+
case Chain.Ethereum:
|
|
86
|
+
case Chain.Arbitrum:
|
|
87
|
+
case Chain.Optimism:
|
|
88
|
+
case Chain.Polygon:
|
|
89
|
+
case Chain.Avalanche:
|
|
90
|
+
case Chain.BinanceSmartChain:
|
|
91
|
+
case Chain.Base:
|
|
92
|
+
case Chain.Monad:
|
|
93
|
+
case Chain.XLayer: {
|
|
94
|
+
if (!(window.talismanEth && "send" in window.talismanEth)) {
|
|
95
|
+
throw new USwapError({ errorKey: "wallet_talisman_not_found", info: { chain } });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const evmWallet = await getWeb3WalletMethods({ chain, walletProvider: window.talismanEth });
|
|
99
|
+
const address: string = (await window.talismanEth.send("eth_requestAccounts", []))[0];
|
|
100
|
+
|
|
101
|
+
return { ...evmWallet, address };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
case Chain.Polkadot:
|
|
105
|
+
case Chain.Chainflip: {
|
|
106
|
+
const { getSubstrateToolbox, SubstrateNetwork } = await import("@tcswap/toolboxes/substrate");
|
|
107
|
+
|
|
108
|
+
const injectedExtension = window?.injectedWeb3?.talisman;
|
|
109
|
+
const rawExtension = await injectedExtension?.enable?.("talisman");
|
|
110
|
+
|
|
111
|
+
if (!rawExtension) {
|
|
112
|
+
throw new USwapError({ errorKey: "wallet_talisman_not_enabled", info: { chain } });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const toolbox = await getSubstrateToolbox(chain, { signer: rawExtension.signer });
|
|
116
|
+
const accounts = await rawExtension.accounts.get();
|
|
117
|
+
|
|
118
|
+
if (!accounts[0]?.address) {
|
|
119
|
+
throw new USwapError({
|
|
120
|
+
errorKey: "wallet_missing_params",
|
|
121
|
+
info: { accounts, address: accounts[0]?.address, wallet: WalletOption.TALISMAN },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const address = toolbox.convertAddress(accounts[0].address, SubstrateNetwork[chain].prefix);
|
|
125
|
+
|
|
126
|
+
return { ...toolbox, address };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
default:
|
|
130
|
+
throw new USwapError({ errorKey: "wallet_chain_not_supported", info: { chain, wallet: WalletOption.TALISMAN } });
|
|
131
|
+
}
|
|
132
|
+
}
|