@swapkit/wallets 3.0.0-beta.0 → 3.0.0-beta.10
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-0ttw612a.js +4 -0
- package/dist/chunk-0ttw612a.js.map +10 -0
- package/dist/chunk-8pv8t9qa.js +3 -0
- package/dist/chunk-8pv8t9qa.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-ta4bdjpy.js +3 -0
- package/dist/chunk-ta4bdjpy.js.map +10 -0
- package/dist/chunk-w07sv0jv.js +3 -0
- package/dist/chunk-w07sv0jv.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 +11 -11
- package/dist/src/ledger/index.js +3 -4
- package/dist/src/ledger/index.js.map +11 -11
- 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 +29 -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 +25 -25
- package/src/keepkey/chains/thorchain.ts +20 -14
- 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 +33 -56
- package/src/keystore/index.ts +15 -183
- package/src/ledger/clients/cosmos.ts +2 -2
- package/src/ledger/clients/evm.ts +3 -7
- package/src/ledger/clients/thorchain/lib.ts +0 -19
- package/src/ledger/clients/utxo.ts +5 -4
- package/src/ledger/helpers/getLedgerClient.ts +2 -2
- package/src/ledger/helpers/getLedgerTransport.ts +3 -3
- package/src/ledger/index.ts +21 -22
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -1
- 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/evmSigner.ts +3 -3
- package/src/trezor/index.ts +49 -48
- 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 +38 -39
- package/dist/chunk-bhfpfqc3.js +0 -3
- package/dist/chunk-bhfpfqc3.js.map +0 -10
- package/dist/chunk-f76hj57k.js +0 -3
- package/dist/chunk-f76hj57k.js.map +0 -10
- 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/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);
|