@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
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Chain,
|
|
3
|
-
EVMChains,
|
|
4
|
-
WalletOption,
|
|
5
|
-
createWallet,
|
|
6
|
-
filterSupportedChains,
|
|
7
|
-
} from "@swapkit/helpers";
|
|
8
|
-
|
|
9
|
-
import { getWalletSupportedChains } from "../helpers";
|
|
10
|
-
import { getWalletMethods } from "./helpers";
|
|
11
|
-
|
|
12
|
-
export const bitgetWallet = createWallet({
|
|
13
|
-
name: "connectBitget",
|
|
14
|
-
walletType: WalletOption.BITGET,
|
|
15
|
-
supportedChains: [...EVMChains, Chain.Cosmos, Chain.Bitcoin, Chain.Solana],
|
|
16
|
-
connect: ({ addChain, walletType, supportedChains }) =>
|
|
17
|
-
async function connectBitget(chains: Chain[]) {
|
|
18
|
-
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
19
|
-
|
|
20
|
-
await Promise.all(
|
|
21
|
-
filteredChains.map(async (chain) => {
|
|
22
|
-
const walletMethods = await getWalletMethods(chain);
|
|
23
|
-
|
|
24
|
-
addChain({ ...walletMethods, chain, balance: [], walletType });
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return true;
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const BITGET_SUPPORTED_CHAINS = getWalletSupportedChains(bitgetWallet);
|
package/src/ctrl/ctrlWallet.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AssetValue,
|
|
3
|
-
Chain,
|
|
4
|
-
ChainToChainId,
|
|
5
|
-
SwapKitError,
|
|
6
|
-
WalletOption,
|
|
7
|
-
createWallet,
|
|
8
|
-
filterSupportedChains,
|
|
9
|
-
} from "@swapkit/helpers";
|
|
10
|
-
import type { NonETHToolbox } from "@swapkit/toolboxes/evm";
|
|
11
|
-
|
|
12
|
-
import { getWalletSupportedChains } from "../helpers";
|
|
13
|
-
import {
|
|
14
|
-
type WalletTxParams,
|
|
15
|
-
getCtrlAddress,
|
|
16
|
-
getCtrlMethods,
|
|
17
|
-
getCtrlProvider,
|
|
18
|
-
solanaTransfer,
|
|
19
|
-
walletTransfer,
|
|
20
|
-
} from "./walletHelpers";
|
|
21
|
-
|
|
22
|
-
export const ctrlWallet = createWallet({
|
|
23
|
-
name: "connectCtrl",
|
|
24
|
-
walletType: WalletOption.CTRL,
|
|
25
|
-
supportedChains: [
|
|
26
|
-
Chain.Arbitrum,
|
|
27
|
-
Chain.Avalanche,
|
|
28
|
-
Chain.Base,
|
|
29
|
-
Chain.BinanceSmartChain,
|
|
30
|
-
Chain.Bitcoin,
|
|
31
|
-
Chain.BitcoinCash,
|
|
32
|
-
Chain.Cosmos,
|
|
33
|
-
Chain.Dogecoin,
|
|
34
|
-
Chain.Ethereum,
|
|
35
|
-
Chain.Kujira,
|
|
36
|
-
Chain.Litecoin,
|
|
37
|
-
Chain.Maya,
|
|
38
|
-
Chain.Optimism,
|
|
39
|
-
Chain.Polygon,
|
|
40
|
-
Chain.Solana,
|
|
41
|
-
Chain.THORChain,
|
|
42
|
-
],
|
|
43
|
-
connect: ({ addChain, walletType, supportedChains }) =>
|
|
44
|
-
async function connectCtrl(chains: Chain[]) {
|
|
45
|
-
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
46
|
-
|
|
47
|
-
const promises = filteredChains.map(async (chain) => {
|
|
48
|
-
const address = await getCtrlAddress(chain);
|
|
49
|
-
const walletMethods = await getWalletMethods(chain);
|
|
50
|
-
|
|
51
|
-
addChain({ ...walletMethods, address, balance: [], chain, walletType });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await Promise.all(promises);
|
|
55
|
-
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
export const CTRL_SUPPORTED_CHAINS = getWalletSupportedChains(ctrlWallet);
|
|
61
|
-
|
|
62
|
-
async function getWalletMethods(chain: (typeof CTRL_SUPPORTED_CHAINS)[number]) {
|
|
63
|
-
switch (chain) {
|
|
64
|
-
case Chain.Solana: {
|
|
65
|
-
const { SOLToolbox } = await import("@swapkit/toolboxes/solana");
|
|
66
|
-
|
|
67
|
-
const toolbox = SOLToolbox();
|
|
68
|
-
const pubKey = await window.xfi?.solana?.connect();
|
|
69
|
-
|
|
70
|
-
if (!pubKey) {
|
|
71
|
-
throw new SwapKitError("wallet_ctrl_not_found");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return { ...toolbox, transfer: solanaTransfer(toolbox, pubKey.publicKey) };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
case Chain.Maya:
|
|
78
|
-
case Chain.THORChain: {
|
|
79
|
-
const { getToolboxByChain, THORCHAIN_GAS_VALUE, MAYA_GAS_VALUE } = await import(
|
|
80
|
-
"@swapkit/toolboxes/cosmos"
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const gasLimit = chain === Chain.Maya ? MAYA_GAS_VALUE : THORCHAIN_GAS_VALUE;
|
|
84
|
-
const toolbox = getToolboxByChain(chain);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
...toolbox(),
|
|
88
|
-
deposit: (tx: WalletTxParams) => walletTransfer({ ...tx, recipient: "" }, "deposit"),
|
|
89
|
-
transfer: (tx: WalletTxParams) => walletTransfer({ ...tx, gasLimit }, "transfer"),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
case Chain.Cosmos:
|
|
94
|
-
case Chain.Kujira: {
|
|
95
|
-
const { getToolboxByChain } = await import("@swapkit/toolboxes/cosmos");
|
|
96
|
-
|
|
97
|
-
const chainId = ChainToChainId[chain];
|
|
98
|
-
|
|
99
|
-
await window.xfi?.keplr?.enable(chainId);
|
|
100
|
-
// @ts-ignore
|
|
101
|
-
const offlineSigner = window.xfi?.keplr?.getOfflineSignerOnlyAmino(chainId);
|
|
102
|
-
|
|
103
|
-
const toolbox = getToolboxByChain(chain)();
|
|
104
|
-
|
|
105
|
-
const transfer = (params: {
|
|
106
|
-
from: string;
|
|
107
|
-
recipient: string;
|
|
108
|
-
assetValue: AssetValue;
|
|
109
|
-
memo: string;
|
|
110
|
-
}) => toolbox.transfer({ signer: offlineSigner, ...params });
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
...toolbox,
|
|
114
|
-
|
|
115
|
-
transfer,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
case Chain.Bitcoin:
|
|
120
|
-
case Chain.BitcoinCash:
|
|
121
|
-
case Chain.Dogecoin:
|
|
122
|
-
case Chain.Litecoin: {
|
|
123
|
-
const { getToolboxByChain } = await import("@swapkit/toolboxes/utxo");
|
|
124
|
-
const toolbox = getToolboxByChain(chain)();
|
|
125
|
-
|
|
126
|
-
return { ...toolbox, transfer: walletTransfer };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
case Chain.Arbitrum:
|
|
130
|
-
case Chain.Avalanche:
|
|
131
|
-
case Chain.Base:
|
|
132
|
-
case Chain.BinanceSmartChain:
|
|
133
|
-
case Chain.Ethereum:
|
|
134
|
-
case Chain.Optimism:
|
|
135
|
-
case Chain.Polygon: {
|
|
136
|
-
const { prepareNetworkSwitch, switchEVMWalletNetwork } = await import("@swapkit/helpers");
|
|
137
|
-
const { getToolboxByChain } = await import("@swapkit/toolboxes/evm");
|
|
138
|
-
const { BrowserProvider } = await import("ethers");
|
|
139
|
-
const ethereumWindowProvider = getCtrlProvider(chain);
|
|
140
|
-
|
|
141
|
-
if (!ethereumWindowProvider) {
|
|
142
|
-
throw new SwapKitError("wallet_ctrl_not_found");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const provider = new BrowserProvider(ethereumWindowProvider, "any");
|
|
146
|
-
const signer = await provider.getSigner();
|
|
147
|
-
const toolbox = getToolboxByChain(chain)({ provider, signer });
|
|
148
|
-
const ctrlMethods = getCtrlMethods(provider);
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
if (chain !== Chain.Ethereum) {
|
|
152
|
-
const networkParams = (toolbox as NonETHToolbox).getNetworkParams();
|
|
153
|
-
await switchEVMWalletNetwork(provider, chain, networkParams);
|
|
154
|
-
}
|
|
155
|
-
} catch (_error) {
|
|
156
|
-
throw new SwapKitError({
|
|
157
|
-
errorKey: "wallet_failed_to_add_or_switch_network",
|
|
158
|
-
info: { wallet: WalletOption.CTRL, chain },
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return prepareNetworkSwitch({
|
|
163
|
-
provider: window.xfi?.ethereum,
|
|
164
|
-
chain,
|
|
165
|
-
toolbox: {
|
|
166
|
-
...toolbox,
|
|
167
|
-
...ctrlMethods,
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
default:
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
}
|
package/src/helpers.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { createWallet } from "@swapkit/helpers";
|
|
2
|
-
|
|
3
|
-
export function getWalletSupportedChains<
|
|
4
|
-
T extends ReturnType<typeof createWallet<any, any, any, any>>,
|
|
5
|
-
>(wallet: T): T[keyof T]["supportedChains"] {
|
|
6
|
-
const walletName = Object.keys(wallet)?.[0] || "";
|
|
7
|
-
return wallet?.[walletName]?.supportedChains || [];
|
|
8
|
-
}
|
package/src/ledger/ledgerLive.ts
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Account,
|
|
3
|
-
BitcoinTransaction,
|
|
4
|
-
CosmosTransaction,
|
|
5
|
-
EthereumTransaction,
|
|
6
|
-
Transaction,
|
|
7
|
-
} from "@ledgerhq/wallet-api-client";
|
|
8
|
-
import { FAMILIES, WalletAPIClient, WindowMessageTransport } from "@ledgerhq/wallet-api-client";
|
|
9
|
-
import {
|
|
10
|
-
AssetValue,
|
|
11
|
-
BaseDecimal,
|
|
12
|
-
Chain,
|
|
13
|
-
FeeOption,
|
|
14
|
-
SwapKitError,
|
|
15
|
-
SwapKitNumber,
|
|
16
|
-
WalletOption,
|
|
17
|
-
createWallet,
|
|
18
|
-
} from "@swapkit/helpers";
|
|
19
|
-
import { ETHToolbox, getProvider } from "@swapkit/toolboxes/evm";
|
|
20
|
-
import type { UTXOTransferParams } from "@swapkit/toolboxes/utxo";
|
|
21
|
-
import { BigNumber as BigNumberJS } from "bignumber.js";
|
|
22
|
-
import { VoidSigner } from "ethers";
|
|
23
|
-
import { getWalletSupportedChains } from "../helpers";
|
|
24
|
-
|
|
25
|
-
export type LedgerAccount = Account & { multichainBalance?: AssetValue[] };
|
|
26
|
-
|
|
27
|
-
export type LedgerLiveTransaction = Transaction;
|
|
28
|
-
export const LEDGER_LIVE_FAMILIES = FAMILIES;
|
|
29
|
-
|
|
30
|
-
export enum LedgerLiveChain {
|
|
31
|
-
BTC = "bitcoin",
|
|
32
|
-
BCH = "bitcoin_cash",
|
|
33
|
-
LTC = "litecoin",
|
|
34
|
-
DOGE = "dogecoin",
|
|
35
|
-
ETH = "ethereum",
|
|
36
|
-
ARB = "arbitrum",
|
|
37
|
-
ATOM = "cosmos",
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const ChainToLedgerLiveChain: Partial<Record<Chain, LedgerLiveChain>> = {
|
|
41
|
-
[Chain.Arbitrum]: LedgerLiveChain.ARB,
|
|
42
|
-
[Chain.BitcoinCash]: LedgerLiveChain.BCH,
|
|
43
|
-
[Chain.Bitcoin]: LedgerLiveChain.BTC,
|
|
44
|
-
[Chain.Cosmos]: LedgerLiveChain.ATOM,
|
|
45
|
-
[Chain.Dogecoin]: LedgerLiveChain.DOGE,
|
|
46
|
-
[Chain.Ethereum]: LedgerLiveChain.ETH,
|
|
47
|
-
[Chain.Litecoin]: LedgerLiveChain.LTC,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const LedgerLiveChainToChain = {
|
|
51
|
-
[LedgerLiveChain.ARB]: Chain.Arbitrum,
|
|
52
|
-
[LedgerLiveChain.ATOM]: Chain.Cosmos,
|
|
53
|
-
[LedgerLiveChain.BCH]: Chain.BitcoinCash,
|
|
54
|
-
[LedgerLiveChain.BTC]: Chain.Bitcoin,
|
|
55
|
-
[LedgerLiveChain.DOGE]: Chain.Dogecoin,
|
|
56
|
-
[LedgerLiveChain.ETH]: Chain.Ethereum,
|
|
57
|
-
[LedgerLiveChain.LTC]: Chain.Litecoin,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const LedgerCurrencyToAsset = {
|
|
61
|
-
arbitrum: AssetValue.from({ chain: Chain.Arbitrum }),
|
|
62
|
-
bitcoin: AssetValue.from({ chain: Chain.Bitcoin }),
|
|
63
|
-
bitcoin_cash: AssetValue.from({ chain: Chain.BitcoinCash }),
|
|
64
|
-
cosmos: AssetValue.from({ chain: Chain.Cosmos }),
|
|
65
|
-
dogecoin: AssetValue.from({ chain: Chain.Dogecoin }),
|
|
66
|
-
ethereum: AssetValue.from({ chain: Chain.Ethereum }),
|
|
67
|
-
litecoin: AssetValue.from({ chain: Chain.Litecoin }),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const isLedgerLiveSupportedOutputAsset = ({ chain }: AssetValue) =>
|
|
71
|
-
[
|
|
72
|
-
Chain.Arbitrum,
|
|
73
|
-
Chain.Bitcoin,
|
|
74
|
-
Chain.BitcoinCash,
|
|
75
|
-
Chain.Cosmos,
|
|
76
|
-
Chain.Dogecoin,
|
|
77
|
-
Chain.Ethereum,
|
|
78
|
-
Chain.Litecoin,
|
|
79
|
-
].includes(chain);
|
|
80
|
-
|
|
81
|
-
export const isLedgerLiveSupportedInputAsset = (assetInput: AssetValue) =>
|
|
82
|
-
[
|
|
83
|
-
AssetValue.from({ chain: Chain.Arbitrum }),
|
|
84
|
-
AssetValue.from({ chain: Chain.Bitcoin }),
|
|
85
|
-
AssetValue.from({ chain: Chain.BitcoinCash }),
|
|
86
|
-
AssetValue.from({ chain: Chain.Cosmos }),
|
|
87
|
-
AssetValue.from({ chain: Chain.Dogecoin }),
|
|
88
|
-
AssetValue.from({ chain: Chain.Ethereum }),
|
|
89
|
-
AssetValue.from({ chain: Chain.Litecoin }),
|
|
90
|
-
AssetValue.from({ asset: "ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831" }),
|
|
91
|
-
AssetValue.from({ asset: "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48" }),
|
|
92
|
-
AssetValue.from({ asset: "ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7" }),
|
|
93
|
-
].find((asset) => asset.eq(assetInput));
|
|
94
|
-
|
|
95
|
-
export const LedgerLive = () => {
|
|
96
|
-
const transport = new WindowMessageTransport();
|
|
97
|
-
|
|
98
|
-
connect();
|
|
99
|
-
|
|
100
|
-
const apiClient = new WalletAPIClient(transport);
|
|
101
|
-
|
|
102
|
-
function connect() {
|
|
103
|
-
transport.connect();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function disconnect() {
|
|
107
|
-
transport.disconnect();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function listAccounts(chain: Chain) {
|
|
111
|
-
if (!ChainToLedgerLiveChain[chain]) {
|
|
112
|
-
throw new Error(`Ledger connect is not supported for ${chain} chain`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return apiClient.account.list({ currencyIds: [ChainToLedgerLiveChain[chain]] });
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function requestAccounts(chains?: Chain[]) {
|
|
119
|
-
const filteredChains = chains?.filter((chain) => chain in LEDGER_LIVE_SUPPORTED_CHAINS);
|
|
120
|
-
if (filteredChains?.length === 0) return Promise.resolve([]);
|
|
121
|
-
return apiClient.account.request({
|
|
122
|
-
currencyIds: (filteredChains || LEDGER_LIVE_SUPPORTED_CHAINS).map(
|
|
123
|
-
(chain) => ChainToLedgerLiveChain[chain] as string,
|
|
124
|
-
),
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function signTransaction(
|
|
129
|
-
accountId: string,
|
|
130
|
-
transaction: LedgerLiveTransaction,
|
|
131
|
-
params?: {
|
|
132
|
-
/**
|
|
133
|
-
* The name of the Ledger Nano app to use for the signing process
|
|
134
|
-
*/
|
|
135
|
-
hwAppId: string;
|
|
136
|
-
},
|
|
137
|
-
) {
|
|
138
|
-
return apiClient.transaction.signAndBroadcast(accountId, transaction, params);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
apiClient,
|
|
143
|
-
connect,
|
|
144
|
-
disconnect,
|
|
145
|
-
listAccounts,
|
|
146
|
-
requestAccounts,
|
|
147
|
-
signTransaction,
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export const getLedgerLiveWallet = async ({
|
|
152
|
-
chain,
|
|
153
|
-
ledgerLiveAccount,
|
|
154
|
-
}: { chain: Chain; ledgerLiveAccount: LedgerAccount }) => {
|
|
155
|
-
switch (chain) {
|
|
156
|
-
case Chain.Arbitrum:
|
|
157
|
-
case Chain.Ethereum: {
|
|
158
|
-
const getAddress = () => ledgerLiveAccount.address;
|
|
159
|
-
|
|
160
|
-
const ledgerLiveClient = EthereumLedgerLive();
|
|
161
|
-
const provider = getProvider(Chain.Ethereum);
|
|
162
|
-
const signer = new VoidSigner(ledgerLiveAccount.address, provider);
|
|
163
|
-
|
|
164
|
-
const toolbox = ETHToolbox({ provider, signer });
|
|
165
|
-
|
|
166
|
-
const sendTransaction = async (unsignedTx: any) => {
|
|
167
|
-
const signedTx = await ledgerLiveClient?.signTransaction(ledgerLiveAccount.id, {
|
|
168
|
-
recipient: unsignedTx.to,
|
|
169
|
-
data: Buffer.from(unsignedTx.data?.substring(2) || "", "hex"),
|
|
170
|
-
amount: new BigNumberJS(unsignedTx.value || 0),
|
|
171
|
-
family: "ethereum",
|
|
172
|
-
});
|
|
173
|
-
if (!signedTx) throw new Error("Could not sign transaction");
|
|
174
|
-
return signedTx;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const transfer = async ({
|
|
178
|
-
assetValue,
|
|
179
|
-
memo,
|
|
180
|
-
recipient,
|
|
181
|
-
}: {
|
|
182
|
-
assetValue: AssetValue;
|
|
183
|
-
memo: string;
|
|
184
|
-
recipient: string;
|
|
185
|
-
}) => {
|
|
186
|
-
if (!assetValue) throw new Error("invalid asset");
|
|
187
|
-
const signedTx = await ledgerLiveClient?.signTransaction(ledgerLiveAccount.id, {
|
|
188
|
-
recipient,
|
|
189
|
-
data: Buffer.from(memo || ""),
|
|
190
|
-
amount: new BigNumberJS(assetValue.getBaseValue("string")),
|
|
191
|
-
family: "ethereum",
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
if (!signedTx) throw new Error("Could not sign transaction");
|
|
195
|
-
|
|
196
|
-
return signedTx;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
...toolbox,
|
|
201
|
-
getAddress,
|
|
202
|
-
address: getAddress(),
|
|
203
|
-
transfer,
|
|
204
|
-
sendTransaction,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
case Chain.Cosmos: {
|
|
209
|
-
const { GaiaToolbox } = await import("@swapkit/toolboxes/cosmos");
|
|
210
|
-
const ledgerLiveClient = CosmosLedgerLive();
|
|
211
|
-
const toolbox = GaiaToolbox();
|
|
212
|
-
|
|
213
|
-
const getAddress = () => ledgerLiveAccount.address;
|
|
214
|
-
|
|
215
|
-
const getBalance = async () => {
|
|
216
|
-
const balance = (await ledgerLiveClient.listAccounts(chain)).find(
|
|
217
|
-
(account) => account.id === ledgerLiveAccount.id,
|
|
218
|
-
)?.balance;
|
|
219
|
-
|
|
220
|
-
return [
|
|
221
|
-
AssetValue.from({
|
|
222
|
-
chain: Chain.Cosmos,
|
|
223
|
-
value: SwapKitNumber.fromBigInt(
|
|
224
|
-
BigInt(balance?.toString(10) || "0"),
|
|
225
|
-
BaseDecimal.GAIA,
|
|
226
|
-
).getValue("string"),
|
|
227
|
-
}),
|
|
228
|
-
];
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const sendTransaction = async (unsignedTx: any) => {
|
|
232
|
-
const signedTx = await ledgerLiveClient?.signTransaction(ledgerLiveAccount.id, {
|
|
233
|
-
family: "cosmos",
|
|
234
|
-
recipient: unsignedTx.to,
|
|
235
|
-
amount: new BigNumberJS(unsignedTx.value || 0),
|
|
236
|
-
memo: unsignedTx.memo || "",
|
|
237
|
-
mode: "send",
|
|
238
|
-
});
|
|
239
|
-
if (!signedTx) throw new Error("Could not sign transaction");
|
|
240
|
-
return signedTx;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const transfer = async ({
|
|
244
|
-
assetValue,
|
|
245
|
-
memo,
|
|
246
|
-
recipient,
|
|
247
|
-
}: {
|
|
248
|
-
assetValue: AssetValue;
|
|
249
|
-
memo: string;
|
|
250
|
-
recipient: string;
|
|
251
|
-
}) => {
|
|
252
|
-
if (!assetValue) throw new Error("invalid asset");
|
|
253
|
-
const signedTx = await ledgerLiveClient?.signTransaction(ledgerLiveAccount.id, {
|
|
254
|
-
family: "cosmos",
|
|
255
|
-
recipient,
|
|
256
|
-
amount: new BigNumberJS(assetValue.getBaseValue("string")),
|
|
257
|
-
memo,
|
|
258
|
-
mode: "send",
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
if (!signedTx) throw new Error("Could not sign transaction");
|
|
262
|
-
|
|
263
|
-
return signedTx;
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
return {
|
|
267
|
-
...toolbox,
|
|
268
|
-
getBalance,
|
|
269
|
-
getAddress,
|
|
270
|
-
address: getAddress(),
|
|
271
|
-
transfer,
|
|
272
|
-
sendTransaction,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
case Chain.Litecoin:
|
|
276
|
-
case Chain.BitcoinCash:
|
|
277
|
-
case Chain.Dogecoin:
|
|
278
|
-
case Chain.Bitcoin: {
|
|
279
|
-
const ledgerLiveClient = BitcoinLedgerLive();
|
|
280
|
-
const { getToolboxByChain } = await import("@swapkit/toolboxes/utxo");
|
|
281
|
-
const toolbox = getToolboxByChain(chain)();
|
|
282
|
-
|
|
283
|
-
const getAddress = () => ledgerLiveAccount.address;
|
|
284
|
-
|
|
285
|
-
const getBalance = async () => {
|
|
286
|
-
const balance = (await ledgerLiveClient.listAccounts(chain)).find(
|
|
287
|
-
(account) => account.id === ledgerLiveAccount.id,
|
|
288
|
-
)?.balance;
|
|
289
|
-
|
|
290
|
-
return [
|
|
291
|
-
AssetValue.from({
|
|
292
|
-
chain,
|
|
293
|
-
value: SwapKitNumber.fromBigInt(
|
|
294
|
-
BigInt(balance?.toString(10) || "0"),
|
|
295
|
-
BaseDecimal.BTC,
|
|
296
|
-
).getValue("string"),
|
|
297
|
-
}),
|
|
298
|
-
];
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const sendTransaction = async (unsignedTx: any) => {
|
|
302
|
-
const signedTx = await ledgerLiveClient?.signTransaction(ledgerLiveAccount.id, {
|
|
303
|
-
recipient: unsignedTx.to,
|
|
304
|
-
opReturnData: Buffer.from(unsignedTx.memo || ""),
|
|
305
|
-
amount: new BigNumberJS(unsignedTx.value || 0),
|
|
306
|
-
family: "bitcoin",
|
|
307
|
-
});
|
|
308
|
-
if (!signedTx) throw new Error("Could not sign transaction");
|
|
309
|
-
return signedTx;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
const transfer = async ({ assetValue, memo, recipient, feeRate }: UTXOTransferParams) => {
|
|
313
|
-
if (!assetValue) throw new Error("invalid asset");
|
|
314
|
-
const gasPrice = (await toolbox.getFeeRates())[FeeOption.Average];
|
|
315
|
-
const signedTx = await ledgerLiveClient?.signTransaction(ledgerLiveAccount.id, {
|
|
316
|
-
recipient,
|
|
317
|
-
opReturnData: Buffer.from(memo || ""),
|
|
318
|
-
amount: new BigNumberJS(assetValue.getBaseValue("string")),
|
|
319
|
-
feePerByte: feeRate ? new BigNumberJS(Math.max(feeRate, gasPrice)) : undefined,
|
|
320
|
-
family: "bitcoin",
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
if (!signedTx) throw new Error("Could not sign transaction");
|
|
324
|
-
|
|
325
|
-
return signedTx;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
return {
|
|
329
|
-
...toolbox,
|
|
330
|
-
getBalance,
|
|
331
|
-
getAddress,
|
|
332
|
-
address: getAddress(),
|
|
333
|
-
transfer,
|
|
334
|
-
sendTransaction,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
default:
|
|
338
|
-
throw new SwapKitError("wallet_chain_not_supported");
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
export const EthereumLedgerLive = () => {
|
|
343
|
-
const baseLedgerLiveClient = LedgerLive();
|
|
344
|
-
|
|
345
|
-
function signTransaction(
|
|
346
|
-
accountId: string,
|
|
347
|
-
transaction: EthereumTransaction,
|
|
348
|
-
params?: { hwAppId: string } | undefined,
|
|
349
|
-
) {
|
|
350
|
-
return baseLedgerLiveClient.apiClient.transaction.signAndBroadcast(
|
|
351
|
-
accountId,
|
|
352
|
-
transaction,
|
|
353
|
-
params,
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return { ...baseLedgerLiveClient, signTransaction };
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
export const BitcoinLedgerLive = () => {
|
|
361
|
-
const baseLedgerLiveClient = LedgerLive();
|
|
362
|
-
|
|
363
|
-
function signTransaction(
|
|
364
|
-
accountId: string,
|
|
365
|
-
transaction: BitcoinTransaction,
|
|
366
|
-
params?: { hwAppId: string } | undefined,
|
|
367
|
-
) {
|
|
368
|
-
return baseLedgerLiveClient.apiClient.transaction.signAndBroadcast(
|
|
369
|
-
accountId,
|
|
370
|
-
transaction,
|
|
371
|
-
params,
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return {
|
|
376
|
-
...baseLedgerLiveClient,
|
|
377
|
-
signTransaction,
|
|
378
|
-
};
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
export const CosmosLedgerLive = () => {
|
|
382
|
-
const baseLedgerLiveClient = LedgerLive();
|
|
383
|
-
|
|
384
|
-
function signTransaction(
|
|
385
|
-
accountId: string,
|
|
386
|
-
transaction: CosmosTransaction,
|
|
387
|
-
params?: { hwAppId: string } | undefined,
|
|
388
|
-
) {
|
|
389
|
-
return baseLedgerLiveClient.apiClient.transaction.signAndBroadcast(
|
|
390
|
-
accountId,
|
|
391
|
-
transaction,
|
|
392
|
-
params,
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
return {
|
|
397
|
-
...baseLedgerLiveClient,
|
|
398
|
-
signTransaction,
|
|
399
|
-
};
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
export const ledgerLiveWallet = createWallet({
|
|
403
|
-
name: "connectLedgerLive",
|
|
404
|
-
walletType: WalletOption.LEDGER_LIVE,
|
|
405
|
-
supportedChains: [
|
|
406
|
-
Chain.Bitcoin,
|
|
407
|
-
Chain.Ethereum,
|
|
408
|
-
Chain.Cosmos,
|
|
409
|
-
Chain.Litecoin,
|
|
410
|
-
Chain.Dogecoin,
|
|
411
|
-
Chain.BitcoinCash,
|
|
412
|
-
],
|
|
413
|
-
connect: ({ addChain, supportedChains, walletType }) =>
|
|
414
|
-
async function connectLedgerLive(
|
|
415
|
-
chains: (typeof supportedChains)[number][],
|
|
416
|
-
ledgerLiveAccount: LedgerAccount,
|
|
417
|
-
) {
|
|
418
|
-
const [chain] = chains;
|
|
419
|
-
if (!chain) return false;
|
|
420
|
-
|
|
421
|
-
const toolbox = await getLedgerLiveWallet({ chain, ledgerLiveAccount });
|
|
422
|
-
|
|
423
|
-
addChain({ ...toolbox, chain, balance: [], walletType });
|
|
424
|
-
|
|
425
|
-
return true;
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
export const LEDGER_LIVE_SUPPORTED_CHAINS = getWalletSupportedChains(ledgerLiveWallet);
|