@swapkit/wallets 3.0.0-beta.0 → 3.0.0-beta.2
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-czhtd6cy.js +4 -0
- package/dist/chunk-czhtd6cy.js.map +10 -0
- package/dist/{chunk-5m175wfy.js → chunk-p1kdg37m.js} +2 -2
- package/dist/{chunk-5m175wfy.js.map → chunk-p1kdg37m.js.map} +1 -1
- package/dist/{chunk-f76hj57k.js → chunk-q81hzyra.js} +2 -2
- package/dist/{chunk-f76hj57k.js.map → chunk-q81hzyra.js.map} +1 -1
- package/dist/chunk-qadd75nn.js +3 -0
- package/dist/chunk-qadd75nn.js.map +10 -0
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +5 -5
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +5 -5
- package/dist/src/coinbase/index.cjs +2 -2
- package/dist/src/coinbase/index.cjs.map +4 -4
- package/dist/src/coinbase/index.js +2 -3
- package/dist/src/coinbase/index.js.map +4 -4
- package/dist/src/ctrl/index.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +5 -5
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +5 -5
- package/dist/src/evm-extensions/index.cjs +2 -2
- package/dist/src/evm-extensions/index.cjs.map +3 -3
- package/dist/src/evm-extensions/index.js +2 -3
- package/dist/src/evm-extensions/index.js.map +3 -3
- package/dist/src/exodus/index.cjs +2 -2
- package/dist/src/exodus/index.cjs.map +3 -3
- package/dist/src/exodus/index.js +2 -3
- package/dist/src/exodus/index.js.map +3 -3
- package/dist/src/index.cjs +2 -2
- package/dist/src/index.cjs.map +3 -4
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +3 -4
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +7 -7
- package/dist/src/keepkey/index.js +2 -3
- package/dist/src/keepkey/index.js.map +7 -7
- package/dist/src/keepkey-bex/index.cjs +2 -2
- package/dist/src/keepkey-bex/index.cjs.map +4 -4
- package/dist/src/keepkey-bex/index.js +2 -3
- package/dist/src/keepkey-bex/index.js.map +4 -4
- package/dist/src/keplr/index.cjs +2 -2
- package/dist/src/keplr/index.cjs.map +3 -3
- package/dist/src/keplr/index.js +2 -3
- package/dist/src/keplr/index.js.map +3 -3
- package/dist/src/keystore/index.cjs +2 -2
- package/dist/src/keystore/index.cjs.map +4 -4
- package/dist/src/keystore/index.js +2 -3
- package/dist/src/keystore/index.js.map +4 -4
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +8 -8
- package/dist/src/ledger/index.js +3 -4
- package/dist/src/ledger/index.js.map +8 -8
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +4 -4
- package/dist/src/okx/index.js +2 -3
- package/dist/src/okx/index.js.map +4 -4
- package/dist/src/onekey/index.cjs +3 -0
- package/dist/src/onekey/index.cjs.map +10 -0
- package/dist/src/onekey/index.js +3 -0
- package/dist/src/onekey/index.js.map +10 -0
- package/dist/src/phantom/index.cjs +2 -2
- package/dist/src/phantom/index.cjs.map +3 -3
- package/dist/src/phantom/index.js +2 -3
- package/dist/src/phantom/index.js.map +3 -3
- package/dist/src/polkadotjs/index.cjs +2 -2
- package/dist/src/polkadotjs/index.cjs.map +3 -3
- package/dist/src/polkadotjs/index.js +2 -3
- package/dist/src/polkadotjs/index.js.map +3 -3
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -3
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/talisman/index.cjs +2 -2
- package/dist/src/talisman/index.cjs.map +3 -3
- package/dist/src/talisman/index.js +2 -3
- package/dist/src/talisman/index.js.map +3 -3
- package/dist/src/trezor/index.cjs +2 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +2 -3
- package/dist/src/trezor/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +5 -5
- package/dist/src/walletconnect/index.js +2 -3
- package/dist/src/walletconnect/index.js.map +5 -5
- package/package.json +31 -26
- package/src/bitget/helpers.ts +33 -93
- package/src/bitget/index.ts +32 -54
- package/src/coinbase/index.ts +2 -2
- package/src/coinbase/signer.ts +46 -42
- package/src/ctrl/index.ts +157 -22
- package/src/ctrl/walletHelpers.ts +45 -94
- package/src/evm-extensions/index.ts +21 -40
- package/src/exodus/index.ts +18 -28
- package/src/index.ts +2 -37
- package/src/keepkey/chains/cosmos.ts +10 -7
- package/src/keepkey/chains/mayachain.ts +24 -24
- package/src/keepkey/chains/thorchain.ts +19 -13
- package/src/keepkey/chains/utxo.ts +36 -48
- package/src/keepkey/index.ts +9 -23
- package/src/keepkey-bex/index.ts +25 -23
- package/src/keepkey-bex/walletHelpers.ts +8 -36
- package/src/keplr/index.ts +6 -53
- package/src/keystore/helpers.ts +34 -55
- package/src/keystore/index.ts +15 -183
- package/src/ledger/clients/evm.ts +3 -7
- package/src/ledger/clients/thorchain/lib.ts +0 -19
- package/src/ledger/clients/utxo.ts +3 -2
- package/src/ledger/helpers/getLedgerClient.ts +2 -2
- package/src/ledger/index.ts +20 -21
- package/src/ledger/types.ts +1 -1
- package/src/okx/helpers.ts +23 -33
- package/src/okx/index.ts +4 -47
- package/src/onekey/evmSigner.ts +133 -0
- package/src/onekey/index.ts +213 -0
- package/src/phantom/index.ts +18 -42
- package/src/polkadotjs/index.ts +5 -7
- package/src/radix/index.ts +31 -47
- package/src/talisman/index.ts +15 -32
- package/src/trezor/index.ts +46 -45
- package/src/types.ts +199 -0
- package/src/utils.ts +54 -0
- package/src/walletconnect/constants.ts +1 -1
- package/src/walletconnect/helpers.ts +2 -2
- package/src/walletconnect/index.ts +36 -37
- package/dist/chunk-ha78se5g.js +0 -4
- package/dist/chunk-ha78se5g.js.map +0 -10
- package/dist/chunk-yvbvzc0q.js +0 -3
- package/dist/chunk-yvbvzc0q.js.map +0 -10
- package/src/bitget/bitgetWallet.ts +0 -32
- package/src/ctrl/ctrlWallet.ts +0 -175
- package/src/helpers.ts +0 -8
- package/src/ledger/ledgerLive.ts +0 -429
package/src/trezor/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Chain,
|
|
3
3
|
type DerivationPathArray,
|
|
4
4
|
FeeOption,
|
|
5
|
+
type GenericTransferParams,
|
|
5
6
|
SKConfig,
|
|
6
7
|
SwapKitError,
|
|
7
8
|
WalletOption,
|
|
@@ -9,8 +10,9 @@ import {
|
|
|
9
10
|
derivationPathToString,
|
|
10
11
|
filterSupportedChains,
|
|
11
12
|
} from "@swapkit/helpers";
|
|
12
|
-
import type {
|
|
13
|
-
import {
|
|
13
|
+
import type { UTXOToolboxes, UTXOType } from "@swapkit/toolboxes/utxo";
|
|
14
|
+
import type { Psbt } from "bitcoinjs-lib";
|
|
15
|
+
import { getWalletSupportedChains } from "../utils";
|
|
14
16
|
|
|
15
17
|
function getScriptType(derivationPath: DerivationPathArray) {
|
|
16
18
|
switch (derivationPath[0]) {
|
|
@@ -25,10 +27,10 @@ function getScriptType(derivationPath: DerivationPathArray) {
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
async function
|
|
30
|
+
async function getTrezorWallet<T extends Chain>({
|
|
29
31
|
chain,
|
|
30
32
|
derivationPath,
|
|
31
|
-
}: { chain:
|
|
33
|
+
}: { chain: T; derivationPath: DerivationPathArray }) {
|
|
32
34
|
switch (chain) {
|
|
33
35
|
case Chain.BinanceSmartChain:
|
|
34
36
|
case Chain.Avalanche:
|
|
@@ -37,15 +39,15 @@ async function getToolbox({
|
|
|
37
39
|
case Chain.Polygon:
|
|
38
40
|
case Chain.Base:
|
|
39
41
|
case Chain.Ethereum: {
|
|
40
|
-
const { getProvider,
|
|
42
|
+
const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
41
43
|
const { getEVMSigner } = await import("./evmSigner");
|
|
42
44
|
|
|
43
|
-
const provider = getProvider(chain);
|
|
45
|
+
const provider = await getProvider(chain);
|
|
44
46
|
const signer = await getEVMSigner({ chain, derivationPath, provider });
|
|
45
47
|
const address = await signer.getAddress();
|
|
46
|
-
const toolbox =
|
|
48
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
47
49
|
|
|
48
|
-
return {
|
|
50
|
+
return { ...toolbox, address };
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
case Chain.Bitcoin:
|
|
@@ -53,10 +55,7 @@ async function getToolbox({
|
|
|
53
55
|
case Chain.Dash:
|
|
54
56
|
case Chain.Dogecoin:
|
|
55
57
|
case Chain.Litecoin: {
|
|
56
|
-
const { toCashAddress,
|
|
57
|
-
"@swapkit/toolboxes/utxo"
|
|
58
|
-
);
|
|
59
|
-
|
|
58
|
+
const { toCashAddress, getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
|
|
60
59
|
const scriptType = getScriptType(derivationPath);
|
|
61
60
|
|
|
62
61
|
if (!scriptType) {
|
|
@@ -67,7 +66,6 @@ async function getToolbox({
|
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
const coin = chain.toLowerCase();
|
|
70
|
-
const toolbox = getToolboxByChain(chain)();
|
|
71
69
|
|
|
72
70
|
const getAddress = async (path: DerivationPathArray = derivationPath) => {
|
|
73
71
|
const { default: TrezorConnect } = await import("@trezor/connect-web");
|
|
@@ -86,9 +84,12 @@ async function getToolbox({
|
|
|
86
84
|
});
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
if (chain === Chain.BitcoinCash) {
|
|
88
|
+
const toolbox = await getUtxoToolbox(chain as Chain.BitcoinCash);
|
|
89
|
+
return toolbox.stripPrefix(payload.address);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return payload.address;
|
|
92
93
|
};
|
|
93
94
|
|
|
94
95
|
const address = await getAddress();
|
|
@@ -98,32 +99,28 @@ async function getToolbox({
|
|
|
98
99
|
const address_n = derivationPath.map((pathElement, index) =>
|
|
99
100
|
index < 3 ? ((pathElement as number) | 0x80000000) >>> 0 : (pathElement as number),
|
|
100
101
|
);
|
|
102
|
+
const toolbox = await getUtxoToolbox(chain as Chain.BitcoinCash);
|
|
101
103
|
|
|
102
104
|
const result = await TrezorConnect.signTransaction({
|
|
103
105
|
coin,
|
|
104
|
-
inputs: inputs.map((
|
|
106
|
+
inputs: inputs.map(({ hash, index, value }) => ({
|
|
105
107
|
// Hardens the first 3 elements of the derivation path - required by trezor
|
|
106
108
|
address_n,
|
|
107
|
-
prev_hash:
|
|
108
|
-
prev_index:
|
|
109
|
+
prev_hash: hash,
|
|
110
|
+
prev_index: index,
|
|
109
111
|
// object needs amount but does not use it for signing
|
|
110
|
-
amount:
|
|
112
|
+
amount: value,
|
|
111
113
|
script_type: scriptType.input,
|
|
112
114
|
})),
|
|
113
115
|
|
|
114
116
|
// Lint is not happy with the type of txOutputs
|
|
115
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor
|
|
116
117
|
outputs: psbt.txOutputs.map((output: any) => {
|
|
117
118
|
const outputAddress =
|
|
118
119
|
chain === Chain.BitcoinCash && output.address
|
|
119
|
-
? toCashAddress(output.address)
|
|
120
|
+
? toolbox.stripPrefix(toCashAddress(output.address))
|
|
120
121
|
: output.address;
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
const isChangeAddress =
|
|
124
|
-
chain === Chain.BitcoinCash && outputAddress
|
|
125
|
-
? (toolbox as ReturnType<typeof BCHToolbox>).stripPrefix(outputAddress) === address
|
|
126
|
-
: outputAddress === address;
|
|
123
|
+
const isChangeAddress = outputAddress === address;
|
|
127
124
|
|
|
128
125
|
// OP_RETURN
|
|
129
126
|
if (!output.address) {
|
|
@@ -134,17 +131,13 @@ async function getToolbox({
|
|
|
134
131
|
};
|
|
135
132
|
}
|
|
136
133
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Outgoing UTXO
|
|
143
|
-
return { address: outputAddress, amount: output.value, script_type: "PAYTOADDRESS" };
|
|
134
|
+
return isChangeAddress
|
|
135
|
+
? { amount: output.value, address_n, script_type: scriptType.output }
|
|
136
|
+
: { amount: output.value, address: outputAddress, script_type: "PAYTOADDRESS" };
|
|
144
137
|
}),
|
|
145
138
|
});
|
|
146
139
|
|
|
147
|
-
if (result.success
|
|
140
|
+
if (result.success) {
|
|
148
141
|
return result.payload.serializedTx;
|
|
149
142
|
}
|
|
150
143
|
|
|
@@ -158,30 +151,36 @@ async function getToolbox({
|
|
|
158
151
|
};
|
|
159
152
|
|
|
160
153
|
const transfer = async ({
|
|
161
|
-
from,
|
|
162
154
|
recipient,
|
|
163
155
|
feeOptionKey,
|
|
164
156
|
feeRate: paramFeeRate,
|
|
165
157
|
memo,
|
|
166
158
|
...rest
|
|
167
|
-
}:
|
|
168
|
-
if (!(
|
|
159
|
+
}: GenericTransferParams) => {
|
|
160
|
+
if (!(address && recipient)) {
|
|
169
161
|
throw new SwapKitError({
|
|
170
162
|
errorKey: "wallet_missing_params",
|
|
171
|
-
info: { wallet: WalletOption.TREZOR, memo,
|
|
163
|
+
info: { wallet: WalletOption.TREZOR, memo, address, recipient },
|
|
172
164
|
});
|
|
173
165
|
}
|
|
174
166
|
|
|
167
|
+
const toolbox = await getUtxoToolbox(chain);
|
|
168
|
+
|
|
175
169
|
const feeRate =
|
|
176
170
|
paramFeeRate || (await toolbox.getFeeRates())[feeOptionKey || FeeOption.Fast];
|
|
177
171
|
|
|
178
|
-
const
|
|
172
|
+
const createTxMethod =
|
|
173
|
+
chain === Chain.BitcoinCash
|
|
174
|
+
? (toolbox as UTXOToolboxes["BCH"]).buildTx
|
|
175
|
+
: (toolbox as UTXOToolboxes["BTC"]).createTransaction;
|
|
176
|
+
|
|
177
|
+
const { psbt, inputs } = await createTxMethod({
|
|
179
178
|
...rest,
|
|
180
179
|
memo,
|
|
181
180
|
recipient,
|
|
182
181
|
feeRate,
|
|
183
|
-
sender:
|
|
184
|
-
fetchTxHex:
|
|
182
|
+
sender: address,
|
|
183
|
+
fetchTxHex: true,
|
|
185
184
|
});
|
|
186
185
|
|
|
187
186
|
const txHex = await signTransaction(psbt, inputs, memo);
|
|
@@ -190,7 +189,9 @@ async function getToolbox({
|
|
|
190
189
|
return tx;
|
|
191
190
|
};
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
const toolbox = await getUtxoToolbox(chain);
|
|
193
|
+
|
|
194
|
+
return { ...toolbox, address, transfer, signTransaction };
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
default:
|
|
@@ -236,9 +237,9 @@ export const trezorWallet = createWallet({
|
|
|
236
237
|
TrezorConnect.init({ lazyLoad: true, manifest });
|
|
237
238
|
}
|
|
238
239
|
|
|
239
|
-
const
|
|
240
|
+
const wallet = await getTrezorWallet({ chain, derivationPath });
|
|
240
241
|
|
|
241
|
-
addChain({ ...
|
|
242
|
+
addChain({ ...wallet, chain, walletType });
|
|
242
243
|
|
|
243
244
|
return true;
|
|
244
245
|
},
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AminoSignResponse,
|
|
3
|
+
OfflineAminoSigner,
|
|
4
|
+
StdSignDoc,
|
|
5
|
+
StdSignature,
|
|
6
|
+
} from "@cosmjs/amino";
|
|
7
|
+
import type { Keplr } from "@keplr-wallet/types";
|
|
8
|
+
import { type EthereumWindowProvider, WalletOption } from "@swapkit/helpers";
|
|
9
|
+
import type { SolanaProvider } from "@swapkit/toolboxes/solana";
|
|
10
|
+
import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
11
|
+
|
|
12
|
+
import type { SubstrateInjectedExtension } from "@swapkit/toolboxes/substrate";
|
|
13
|
+
import type { bitgetWallet } from "./bitget";
|
|
14
|
+
import type { coinbaseWallet } from "./coinbase";
|
|
15
|
+
import type { ctrlWallet } from "./ctrl";
|
|
16
|
+
import type { evmWallet } from "./evm-extensions";
|
|
17
|
+
import type { exodusWallet } from "./exodus";
|
|
18
|
+
import type { keepkeyWallet } from "./keepkey";
|
|
19
|
+
import type { keepkeyBexWallet } from "./keepkey-bex";
|
|
20
|
+
import type { keplrWallet } from "./keplr";
|
|
21
|
+
import type { keystoreWallet } from "./keystore";
|
|
22
|
+
import type { ledgerWallet } from "./ledger";
|
|
23
|
+
import type { okxWallet } from "./okx";
|
|
24
|
+
import type { onekeyWallet } from "./onekey";
|
|
25
|
+
import type { phantomWallet } from "./phantom";
|
|
26
|
+
import type { polkadotWallet } from "./polkadotjs";
|
|
27
|
+
import type { radixWallet } from "./radix";
|
|
28
|
+
import type { talismanWallet } from "./talisman";
|
|
29
|
+
import type { trezorWallet } from "./trezor";
|
|
30
|
+
import type { walletconnectWallet } from "./walletconnect";
|
|
31
|
+
|
|
32
|
+
export type SKWallets = {
|
|
33
|
+
[WalletOption.BITGET]: typeof bitgetWallet;
|
|
34
|
+
[WalletOption.BRAVE]: typeof evmWallet;
|
|
35
|
+
[WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet;
|
|
36
|
+
[WalletOption.COINBASE_WEB]: typeof evmWallet;
|
|
37
|
+
[WalletOption.CTRL]: typeof ctrlWallet;
|
|
38
|
+
[WalletOption.EIP6963]: typeof evmWallet;
|
|
39
|
+
[WalletOption.EXODUS]: typeof exodusWallet;
|
|
40
|
+
[WalletOption.KEEPKEY]: typeof keepkeyWallet;
|
|
41
|
+
[WalletOption.KEEPKEY_BEX]: typeof keepkeyBexWallet;
|
|
42
|
+
[WalletOption.KEPLR]: typeof keplrWallet;
|
|
43
|
+
[WalletOption.KEYSTORE]: typeof keystoreWallet;
|
|
44
|
+
[WalletOption.LEAP]: typeof keplrWallet;
|
|
45
|
+
[WalletOption.LEDGER]: typeof ledgerWallet;
|
|
46
|
+
[WalletOption.LEDGER_LIVE]: typeof ledgerWallet;
|
|
47
|
+
[WalletOption.METAMASK]: typeof evmWallet;
|
|
48
|
+
[WalletOption.OKX]: typeof okxWallet;
|
|
49
|
+
[WalletOption.OKX_MOBILE]: typeof evmWallet;
|
|
50
|
+
[WalletOption.ONEKEY]: typeof onekeyWallet;
|
|
51
|
+
[WalletOption.PHANTOM]: typeof phantomWallet;
|
|
52
|
+
[WalletOption.POLKADOT_JS]: typeof polkadotWallet;
|
|
53
|
+
[WalletOption.RADIX_WALLET]: typeof radixWallet;
|
|
54
|
+
[WalletOption.TALISMAN]: typeof talismanWallet;
|
|
55
|
+
[WalletOption.TREZOR]: typeof trezorWallet;
|
|
56
|
+
[WalletOption.TRUSTWALLET_WEB]: typeof evmWallet;
|
|
57
|
+
[WalletOption.WALLETCONNECT]: typeof walletconnectWallet;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type SKConnectWallets = SKWallets[keyof SKWallets];
|
|
61
|
+
|
|
62
|
+
export type SKWalletsSupportedChains = {
|
|
63
|
+
[WalletOption.BITGET]: typeof bitgetWallet.connectBitget.supportedChains;
|
|
64
|
+
[WalletOption.BRAVE]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
65
|
+
[WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet.connectCoinbaseWallet.supportedChains;
|
|
66
|
+
[WalletOption.COINBASE_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
67
|
+
[WalletOption.CTRL]: typeof ctrlWallet.connectCtrl.supportedChains;
|
|
68
|
+
[WalletOption.EIP6963]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
69
|
+
[WalletOption.EXODUS]: typeof exodusWallet.connectExodusWallet.supportedChains;
|
|
70
|
+
[WalletOption.KEEPKEY]: typeof keepkeyWallet.connectKeepkey.supportedChains;
|
|
71
|
+
[WalletOption.KEEPKEY_BEX]: typeof keepkeyBexWallet.connectKeepkeyBex.supportedChains;
|
|
72
|
+
[WalletOption.KEPLR]: typeof keplrWallet.connectKeplr.supportedChains;
|
|
73
|
+
[WalletOption.KEYSTORE]: typeof keystoreWallet.connectKeystore.supportedChains;
|
|
74
|
+
[WalletOption.LEAP]: typeof keplrWallet.connectKeplr.supportedChains;
|
|
75
|
+
[WalletOption.LEDGER]: typeof ledgerWallet.connectLedger.supportedChains;
|
|
76
|
+
[WalletOption.LEDGER_LIVE]: typeof ledgerWallet.connectLedger.supportedChains;
|
|
77
|
+
[WalletOption.METAMASK]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
78
|
+
[WalletOption.OKX]: typeof okxWallet.connectOkx.supportedChains;
|
|
79
|
+
[WalletOption.OKX_MOBILE]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
80
|
+
[WalletOption.ONEKEY]: typeof onekeyWallet.connectOnekeyWallet.supportedChains;
|
|
81
|
+
[WalletOption.PHANTOM]: typeof phantomWallet.connectPhantom.supportedChains;
|
|
82
|
+
[WalletOption.POLKADOT_JS]: typeof polkadotWallet.connectPolkadotJs.supportedChains;
|
|
83
|
+
[WalletOption.RADIX_WALLET]: typeof radixWallet.connectRadixWallet.supportedChains;
|
|
84
|
+
[WalletOption.TALISMAN]: typeof talismanWallet.connectTalisman.supportedChains;
|
|
85
|
+
[WalletOption.TREZOR]: typeof trezorWallet.connectTrezor.supportedChains;
|
|
86
|
+
[WalletOption.TRUSTWALLET_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
87
|
+
[WalletOption.WALLETCONNECT]: typeof walletconnectWallet.connectWalletconnect.supportedChains;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type UnisatToSignInputs = {
|
|
91
|
+
index: number;
|
|
92
|
+
sighashTypes?: number[];
|
|
93
|
+
disableTweakSigner?: boolean;
|
|
94
|
+
} & ({ address: string } | { publicKey: string });
|
|
95
|
+
|
|
96
|
+
declare global {
|
|
97
|
+
interface Window {
|
|
98
|
+
injectedWeb3?: SubstrateInjectedExtension;
|
|
99
|
+
talismanEth?: EthereumWindowProvider;
|
|
100
|
+
$onekey?: any;
|
|
101
|
+
braveSolana: any;
|
|
102
|
+
coinbaseWalletExtension: EthereumWindowProvider;
|
|
103
|
+
ethereum: EthereumWindowProvider;
|
|
104
|
+
keplr: Keplr;
|
|
105
|
+
leap: Keplr;
|
|
106
|
+
trustwallet: EthereumWindowProvider;
|
|
107
|
+
phantom: {
|
|
108
|
+
solana: SolanaProvider;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
xfi?: {
|
|
112
|
+
binance: Eip1193Provider;
|
|
113
|
+
bitcoin: Eip1193Provider;
|
|
114
|
+
bitcoincash: Eip1193Provider;
|
|
115
|
+
dogecoin: Eip1193Provider;
|
|
116
|
+
ethereum: BrowserProvider;
|
|
117
|
+
keplr: Keplr;
|
|
118
|
+
litecoin: Eip1193Provider;
|
|
119
|
+
thorchain: Eip1193Provider;
|
|
120
|
+
mayachain: Eip1193Provider;
|
|
121
|
+
solana: SolanaProvider & { isXDEFI: boolean };
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
bitkeep?: {
|
|
125
|
+
unisat: {
|
|
126
|
+
requestAccounts: () => Promise<[string, ...string[]]>;
|
|
127
|
+
signMessage: (message: string, type?: "ecdsa" | "bip322-simple") => Promise<string>;
|
|
128
|
+
signPsbt: (
|
|
129
|
+
psbtHex: string,
|
|
130
|
+
{
|
|
131
|
+
autoFinalized,
|
|
132
|
+
toSignInputs,
|
|
133
|
+
}: { autoFinalized?: boolean; toSignInputs?: UnisatToSignInputs[] },
|
|
134
|
+
) => Promise<string>;
|
|
135
|
+
};
|
|
136
|
+
keplr: {
|
|
137
|
+
enable: (chainId: string | string[]) => Promise<void>;
|
|
138
|
+
signAmino: (
|
|
139
|
+
chainId: string,
|
|
140
|
+
signer: string,
|
|
141
|
+
signDoc: StdSignDoc,
|
|
142
|
+
signOptions: any,
|
|
143
|
+
) => Promise<AminoSignResponse>;
|
|
144
|
+
signArbitrary: (
|
|
145
|
+
chainId: string,
|
|
146
|
+
signer: string,
|
|
147
|
+
data: string | Uint8Array,
|
|
148
|
+
) => Promise<StdSignature>;
|
|
149
|
+
verifyArbitrary: (
|
|
150
|
+
chainId: string,
|
|
151
|
+
signer: string,
|
|
152
|
+
data: string | Uint8Array,
|
|
153
|
+
signature: StdSignature,
|
|
154
|
+
) => Promise<boolean>;
|
|
155
|
+
getOfflineSignerOnlyAmino: (chainId: string) => OfflineAminoSigner;
|
|
156
|
+
};
|
|
157
|
+
solana: SolanaProvider;
|
|
158
|
+
ethereum: EthereumWindowProvider;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
okxwallet?:
|
|
162
|
+
| {
|
|
163
|
+
bitcoin: {
|
|
164
|
+
connect: () => Promise<{
|
|
165
|
+
address: string;
|
|
166
|
+
publicKey: string;
|
|
167
|
+
}>;
|
|
168
|
+
disconnect: () => Promise<void>;
|
|
169
|
+
signMessage: (message: string, { from }: { from: string }) => Promise<string>;
|
|
170
|
+
signPsbt: (
|
|
171
|
+
psbtHex: string,
|
|
172
|
+
{ from, type }: { from: string; type: string },
|
|
173
|
+
) => Promise<string>;
|
|
174
|
+
};
|
|
175
|
+
keplr: {
|
|
176
|
+
enable: (chainId: string | string[]) => Promise<void>;
|
|
177
|
+
signAmino: (
|
|
178
|
+
chainId: string,
|
|
179
|
+
signer: string,
|
|
180
|
+
signDoc: StdSignDoc,
|
|
181
|
+
signOptions: any,
|
|
182
|
+
) => Promise<AminoSignResponse>;
|
|
183
|
+
signArbitrary: (
|
|
184
|
+
chainId: string,
|
|
185
|
+
signer: string,
|
|
186
|
+
data: string | Uint8Array,
|
|
187
|
+
) => Promise<StdSignature>;
|
|
188
|
+
verifyArbitrary: (
|
|
189
|
+
chainId: string,
|
|
190
|
+
signer: string,
|
|
191
|
+
data: string | Uint8Array,
|
|
192
|
+
signature: StdSignature,
|
|
193
|
+
) => Promise<boolean>;
|
|
194
|
+
getOfflineSignerOnlyAmino: (chainId: string) => OfflineAminoSigner;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
| EthereumWindowProvider;
|
|
198
|
+
}
|
|
199
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { WalletOption, type createWallet } from "@swapkit/helpers";
|
|
2
|
+
import type { SKWallets } from "./types";
|
|
3
|
+
|
|
4
|
+
export function getWalletSupportedChains<
|
|
5
|
+
T extends ReturnType<typeof createWallet<any, any, any, any>>,
|
|
6
|
+
>(wallet: T): T[keyof T]["supportedChains"] {
|
|
7
|
+
const walletName = Object.keys(wallet)?.[0] || "";
|
|
8
|
+
return wallet?.[walletName]?.supportedChains || [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function loadWallet<W extends WalletOption>(walletOption: W): Promise<SKWallets[W]> {
|
|
12
|
+
const { match } = await import("ts-pattern");
|
|
13
|
+
|
|
14
|
+
const wallet = await match(walletOption as WalletOption)
|
|
15
|
+
.with(WalletOption.COINBASE_MOBILE, async () => (await import("./coinbase")).coinbaseWallet)
|
|
16
|
+
.with(WalletOption.BITGET, async () => (await import("./bitget")).bitgetWallet)
|
|
17
|
+
.with(WalletOption.CTRL, async () => (await import("./ctrl")).ctrlWallet)
|
|
18
|
+
.with(WalletOption.OKX, async () => (await import("./okx")).okxWallet)
|
|
19
|
+
.with(WalletOption.ONEKEY, async () => (await import("./onekey")).onekeyWallet)
|
|
20
|
+
.with(WalletOption.EXODUS, async () => (await import("./exodus")).exodusWallet)
|
|
21
|
+
.with(WalletOption.KEEPKEY, async () => (await import("./keepkey")).keepkeyWallet)
|
|
22
|
+
.with(WalletOption.KEEPKEY_BEX, async () => (await import("./keepkey-bex")).keepkeyBexWallet)
|
|
23
|
+
.with(
|
|
24
|
+
WalletOption.WALLETCONNECT,
|
|
25
|
+
async () => (await import("./walletconnect")).walletconnectWallet,
|
|
26
|
+
)
|
|
27
|
+
.with(WalletOption.KEPLR, WalletOption.LEAP, async () => (await import("./keplr")).keplrWallet)
|
|
28
|
+
.with(
|
|
29
|
+
WalletOption.BRAVE,
|
|
30
|
+
WalletOption.COINBASE_WEB,
|
|
31
|
+
WalletOption.EIP6963,
|
|
32
|
+
WalletOption.METAMASK,
|
|
33
|
+
WalletOption.OKX_MOBILE,
|
|
34
|
+
WalletOption.TRUSTWALLET_WEB,
|
|
35
|
+
async () => (await import("./evm-extensions")).evmWallet,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
.with(WalletOption.KEYSTORE, async () => (await import("./keystore")).keystoreWallet)
|
|
39
|
+
.with(WalletOption.TREZOR, async () => (await import("./trezor")).trezorWallet)
|
|
40
|
+
.with(
|
|
41
|
+
WalletOption.LEDGER,
|
|
42
|
+
// TODO: Remove
|
|
43
|
+
WalletOption.LEDGER_LIVE,
|
|
44
|
+
async () => (await import("./ledger")).ledgerWallet,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
.with(WalletOption.PHANTOM, async () => (await import("./phantom")).phantomWallet)
|
|
48
|
+
.with(WalletOption.POLKADOT_JS, async () => (await import("./polkadotjs")).polkadotWallet)
|
|
49
|
+
.with(WalletOption.RADIX_WALLET, async () => (await import("./radix")).radixWallet)
|
|
50
|
+
.with(WalletOption.TALISMAN, async () => (await import("./talisman")).talismanWallet)
|
|
51
|
+
.exhaustive();
|
|
52
|
+
|
|
53
|
+
return wallet as SKWallets[W];
|
|
54
|
+
}
|
|
@@ -4,7 +4,7 @@ export const DEFAULT_RELAY_URL = "wss://relay.walletconnect.com";
|
|
|
4
4
|
|
|
5
5
|
export const ETHEREUM_MAINNET_ID = "eip155:1";
|
|
6
6
|
export const BSC_MAINNET_ID = "eip155:56";
|
|
7
|
-
export const
|
|
7
|
+
export const AVALANCHE_MAINNET_ID = "eip155:43114";
|
|
8
8
|
export const THORCHAIN_MAINNET_ID = "cosmos:thorchain";
|
|
9
9
|
export const COSMOS_HUB_MAINNET_ID = "cosmos:cosmoshub-4";
|
|
10
10
|
export const KUJIRA_MAINNET_ID = "cosmos:kaiyo-1";
|
|
@@ -2,7 +2,7 @@ import { Chain, type EVMChain } from "@swapkit/helpers";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
ARBITRUM_ONE_MAINNET_ID,
|
|
5
|
-
|
|
5
|
+
AVALANCHE_MAINNET_ID,
|
|
6
6
|
BASE_MAINNET_ID,
|
|
7
7
|
BSC_MAINNET_ID,
|
|
8
8
|
COSMOS_HUB_MAINNET_ID,
|
|
@@ -27,7 +27,7 @@ export const getAddressByChain = (
|
|
|
27
27
|
export const chainToChainId = (chain: Chain) => {
|
|
28
28
|
switch (chain) {
|
|
29
29
|
case Chain.Avalanche:
|
|
30
|
-
return
|
|
30
|
+
return AVALANCHE_MAINNET_ID;
|
|
31
31
|
case Chain.Base:
|
|
32
32
|
return BASE_MAINNET_ID;
|
|
33
33
|
case Chain.BinanceSmartChain:
|
|
@@ -2,21 +2,18 @@ import type { StdSignDoc } from "@cosmjs/amino";
|
|
|
2
2
|
import {
|
|
3
3
|
Chain,
|
|
4
4
|
ChainId,
|
|
5
|
+
type GenericTransferParams,
|
|
5
6
|
SKConfig,
|
|
6
7
|
SwapKitError,
|
|
7
8
|
WalletOption,
|
|
8
9
|
createWallet,
|
|
9
10
|
filterSupportedChains,
|
|
10
11
|
} from "@swapkit/helpers";
|
|
11
|
-
import type {
|
|
12
|
-
BaseCosmosToolboxType,
|
|
13
|
-
DepositParam,
|
|
14
|
-
TransferParams,
|
|
15
|
-
} from "@swapkit/toolboxes/cosmos";
|
|
12
|
+
import type { ThorchainDepositParams, createThorchainToolbox } from "@swapkit/toolboxes/cosmos";
|
|
16
13
|
import type { WalletConnectModalSign } from "@walletconnect/modal-sign-html";
|
|
17
14
|
import type { SessionTypes, SignClientTypes } from "@walletconnect/types";
|
|
18
15
|
|
|
19
|
-
import { getWalletSupportedChains } from "../
|
|
16
|
+
import { getWalletSupportedChains } from "../utils";
|
|
20
17
|
import {
|
|
21
18
|
DEFAULT_APP_METADATA,
|
|
22
19
|
DEFAULT_COSMOS_METHODS,
|
|
@@ -76,31 +73,12 @@ export const walletconnectWallet = createWallet({
|
|
|
76
73
|
const address = getAddressByChain(chain, accounts);
|
|
77
74
|
const toolbox = await getToolbox({ session, address, chain, walletconnect });
|
|
78
75
|
|
|
79
|
-
async function getAccount(accountAddress: string) {
|
|
80
|
-
const account = await (toolbox as BaseCosmosToolboxType).getAccount(accountAddress);
|
|
81
|
-
const [{ address, algo, pubkey }] = (await walletconnect?.client.request({
|
|
82
|
-
chainId: THORCHAIN_MAINNET_ID,
|
|
83
|
-
topic: session.topic,
|
|
84
|
-
request: {
|
|
85
|
-
method: DEFAULT_COSMOS_METHODS.COSMOS_GET_ACCOUNTS,
|
|
86
|
-
params: {},
|
|
87
|
-
},
|
|
88
|
-
})) as [{ address: string; algo: string; pubkey: string }];
|
|
89
|
-
|
|
90
|
-
return { ...account, address, pubkey: { type: algo, value: pubkey } };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
76
|
addChain({
|
|
94
77
|
...toolbox,
|
|
95
78
|
address,
|
|
96
|
-
balance: [],
|
|
97
79
|
chain,
|
|
98
80
|
disconnect: walletconnect.disconnect,
|
|
99
81
|
walletType: WalletOption.WALLETCONNECT,
|
|
100
|
-
getAccount:
|
|
101
|
-
chain === Chain.THORChain
|
|
102
|
-
? getAccount
|
|
103
|
-
: (toolbox as BaseCosmosToolboxType).getAccount,
|
|
104
82
|
});
|
|
105
83
|
}),
|
|
106
84
|
);
|
|
@@ -131,13 +109,13 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
131
109
|
case Chain.Ethereum:
|
|
132
110
|
case Chain.Optimism:
|
|
133
111
|
case Chain.Polygon: {
|
|
134
|
-
const { getProvider,
|
|
112
|
+
const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
135
113
|
|
|
136
|
-
const provider = getProvider(chain);
|
|
114
|
+
const provider = await getProvider(chain);
|
|
137
115
|
const signer = await getEVMSigner({ walletconnect, chain, provider });
|
|
138
|
-
const toolbox =
|
|
116
|
+
const toolbox = await getEvmToolbox(chain, { provider, signer });
|
|
139
117
|
|
|
140
|
-
return toolbox
|
|
118
|
+
return toolbox;
|
|
141
119
|
}
|
|
142
120
|
|
|
143
121
|
case Chain.THORChain: {
|
|
@@ -146,7 +124,7 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
146
124
|
const { encodePubkey, makeAuthInfoBytes } = await import("@cosmjs/proto-signing");
|
|
147
125
|
const { makeSignDoc } = await import("@cosmjs/amino");
|
|
148
126
|
const {
|
|
149
|
-
|
|
127
|
+
getCosmosToolbox,
|
|
150
128
|
buildAminoMsg,
|
|
151
129
|
buildEncodedTxBody,
|
|
152
130
|
createStargateClient,
|
|
@@ -154,7 +132,29 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
154
132
|
getDefaultChainFee,
|
|
155
133
|
parseAminoMessageForDirectSigning,
|
|
156
134
|
} = await import("@swapkit/toolboxes/cosmos");
|
|
157
|
-
const toolbox =
|
|
135
|
+
const toolbox = await getCosmosToolbox(Chain.THORChain);
|
|
136
|
+
|
|
137
|
+
async function getAccount(accountAddress: string) {
|
|
138
|
+
const cosmosToolbox = toolbox;
|
|
139
|
+
const account = await (
|
|
140
|
+
cosmosToolbox as Awaited<ReturnType<typeof createThorchainToolbox>>
|
|
141
|
+
).getAccount(accountAddress);
|
|
142
|
+
|
|
143
|
+
if (chain !== Chain.THORChain) {
|
|
144
|
+
return account;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const [{ address, algo, pubkey }] = (await walletconnect?.client.request({
|
|
148
|
+
chainId: THORCHAIN_MAINNET_ID,
|
|
149
|
+
topic: session.topic,
|
|
150
|
+
request: {
|
|
151
|
+
method: DEFAULT_COSMOS_METHODS.COSMOS_GET_ACCOUNTS,
|
|
152
|
+
params: {},
|
|
153
|
+
},
|
|
154
|
+
})) as [{ address: string; algo: string; pubkey: string }];
|
|
155
|
+
|
|
156
|
+
return { ...account, address, pubkey: { type: algo, value: pubkey } };
|
|
157
|
+
}
|
|
158
158
|
|
|
159
159
|
const fee = getDefaultChainFee(chain);
|
|
160
160
|
|
|
@@ -172,7 +172,7 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
172
172
|
assetValue,
|
|
173
173
|
memo,
|
|
174
174
|
...rest
|
|
175
|
-
}:
|
|
175
|
+
}: GenericTransferParams | ThorchainDepositParams) {
|
|
176
176
|
const account = await toolbox.getAccount(address);
|
|
177
177
|
if (!account) {
|
|
178
178
|
throw new SwapKitError({ errorKey: "wallet_missing_params", info: { account } });
|
|
@@ -187,9 +187,7 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
187
187
|
|
|
188
188
|
const { accountNumber, sequence = 0 } = account;
|
|
189
189
|
|
|
190
|
-
const msgs = [
|
|
191
|
-
buildAminoMsg({ chain: Chain.THORChain, assetValue, memo, from: address, ...rest }),
|
|
192
|
-
];
|
|
190
|
+
const msgs = [buildAminoMsg({ assetValue, memo, sender: address, ...rest })];
|
|
193
191
|
|
|
194
192
|
const chainId = ChainId.THORChain;
|
|
195
193
|
|
|
@@ -239,8 +237,9 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
239
237
|
|
|
240
238
|
return {
|
|
241
239
|
...toolbox,
|
|
242
|
-
transfer: (params:
|
|
243
|
-
deposit: (params:
|
|
240
|
+
transfer: (params: GenericTransferParams) => thorchainTransfer(params),
|
|
241
|
+
deposit: (params: ThorchainDepositParams) => thorchainTransfer(params),
|
|
242
|
+
getAccount,
|
|
244
243
|
};
|
|
245
244
|
}
|
|
246
245
|
default:
|
package/dist/chunk-ha78se5g.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/helpers.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { createWallet } from \"@swapkit/helpers\";\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"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "AAEO,SAAS,CAEf,CAAC,EAA0C,CAC1C,IAAM,EAAa,OAAO,KAAK,CAAM,IAAI,IAAM,GAC/C,OAAO,IAAS,IAAa,iBAAmB,CAAC",
|
|
8
|
-
"debugId": "F206E598AB17CDC064756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/chunk-yvbvzc0q.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/helpers.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { createWallet } from \"@swapkit/helpers\";\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"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "+CAEO,SAAS,CAEf,CAAC,EAA0C,CAC1C,IAAM,EAAa,OAAO,KAAK,CAAM,IAAI,IAAM,GAC/C,OAAO,IAAS,IAAa,iBAAmB,CAAC",
|
|
8
|
-
"debugId": "C48D3544860CE65864756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|