@swapkit/wallets 3.0.0-beta.2 → 3.0.0-beta.21
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-2aa1w78q.js +3 -0
- package/dist/chunk-2aa1w78q.js.map +10 -0
- package/dist/{chunk-p1kdg37m.js → chunk-38ztynv0.js} +1 -1
- package/dist/{chunk-p1kdg37m.js.map → chunk-38ztynv0.js.map} +1 -1
- package/dist/chunk-ebfkk1jn.js +4 -0
- package/dist/{chunk-czhtd6cy.js.map → chunk-ebfkk1jn.js.map} +3 -3
- package/dist/chunk-k9q04afa.js +3 -0
- package/dist/{chunk-qadd75nn.js.map → chunk-k9q04afa.js.map} +3 -3
- package/dist/chunk-x5hgx9x9.js +3 -0
- package/dist/chunk-x5hgx9x9.js.map +10 -0
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +3 -3
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +3 -3
- package/dist/src/coinbase/index.cjs +2 -2
- package/dist/src/coinbase/index.cjs.map +3 -3
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +3 -3
- package/dist/src/cosmostation/index.cjs +3 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +3 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +3 -3
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +3 -3
- 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 -2
- 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 -2
- package/dist/src/exodus/index.js.map +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +9 -9
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +9 -9
- 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 -2
- 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 -2
- 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 -2
- package/dist/src/keystore/index.js.map +4 -4
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +16 -15
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +16 -15
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +3 -3
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +3 -3
- package/dist/src/onekey/index.cjs +2 -2
- package/dist/src/onekey/index.cjs.map +3 -3
- package/dist/src/onekey/index.js +2 -2
- package/dist/src/onekey/index.js.map +3 -3
- package/dist/src/phantom/index.js +1 -1
- package/dist/src/polkadotjs/index.js +1 -1
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/talisman/index.js +1 -1
- package/dist/src/trezor/index.cjs +2 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +2 -2
- package/dist/src/trezor/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +4 -4
- package/dist/src/walletconnect/index.js +2 -2
- package/dist/src/walletconnect/index.js.map +4 -4
- package/package.json +32 -27
- package/src/bitget/helpers.ts +4 -4
- package/src/coinbase/signer.ts +4 -4
- package/src/cosmostation/index.ts +142 -0
- package/src/ctrl/walletHelpers.ts +82 -70
- package/src/evm-extensions/index.ts +4 -3
- package/src/exodus/index.ts +8 -9
- package/src/keepkey/chains/cosmos.ts +44 -50
- package/src/keepkey/chains/evm.ts +16 -8
- package/src/keepkey/chains/mayachain.ts +3 -2
- package/src/keepkey/chains/thorchain.ts +3 -2
- package/src/keepkey/chains/utxo.ts +9 -2
- package/src/keepkey/coins.ts +10 -4
- package/src/keepkey/index.ts +15 -7
- package/src/keepkey-bex/index.ts +9 -14
- package/src/keepkey-bex/walletHelpers.ts +1 -1
- package/src/keplr/index.ts +4 -3
- package/src/keystore/helpers.ts +2 -4
- package/src/keystore/index.ts +1 -0
- package/src/ledger/clients/cosmos.ts +5 -4
- package/src/ledger/clients/evm.ts +7 -6
- package/src/ledger/clients/thorchain/helpers.ts +9 -4
- package/src/ledger/clients/thorchain/index.ts +3 -3
- package/src/ledger/clients/thorchain/lib.ts +3 -2
- package/src/ledger/clients/thorchain/utils.ts +20 -9
- package/src/ledger/clients/utxo.ts +3 -5
- package/src/ledger/clients/xrp.ts +66 -0
- package/src/ledger/cosmosTypes.ts +14 -10
- package/src/ledger/helpers/getLedgerAddress.ts +12 -3
- package/src/ledger/helpers/getLedgerClient.ts +56 -45
- package/src/ledger/helpers/getLedgerTransport.ts +5 -3
- package/src/ledger/index.ts +18 -7
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -2
- package/src/okx/helpers.ts +11 -9
- package/src/onekey/index.ts +3 -7
- package/src/radix/index.ts +4 -4
- package/src/trezor/evmSigner.ts +4 -4
- package/src/trezor/index.ts +14 -4
- package/src/types.ts +3 -0
- package/src/utils.ts +4 -0
- package/src/walletconnect/evmSigner.ts +6 -2
- package/src/walletconnect/index.ts +4 -4
- package/dist/chunk-bhfpfqc3.js +0 -3
- package/dist/chunk-bhfpfqc3.js.map +0 -10
- package/dist/chunk-czhtd6cy.js +0 -4
- package/dist/chunk-q81hzyra.js +0 -3
- package/dist/chunk-q81hzyra.js.map +0 -10
- package/dist/chunk-qadd75nn.js +0 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type Xrp from "@ledgerhq/hw-app-xrp";
|
|
2
|
+
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import {
|
|
4
|
+
Chain,
|
|
5
|
+
type DerivationPathArray,
|
|
6
|
+
NetworkDerivationPath,
|
|
7
|
+
derivationPathToString,
|
|
8
|
+
} from "@swapkit/helpers";
|
|
9
|
+
import type { Transaction } from "@swapkit/toolboxes/ripple";
|
|
10
|
+
import { encode } from "ripple-binary-codec";
|
|
11
|
+
import type { Payment } from "xrpl";
|
|
12
|
+
import { getLedgerTransport } from "../helpers";
|
|
13
|
+
|
|
14
|
+
const TF_FULLY_CANONICAL_SIG = 2147483648;
|
|
15
|
+
|
|
16
|
+
function cleanTransactionObject(obj: Record<string, any>) {
|
|
17
|
+
const cleaned: Record<string, any> = {};
|
|
18
|
+
for (const key in obj) {
|
|
19
|
+
if (obj[key] !== null && obj[key] !== undefined) {
|
|
20
|
+
cleaned[key] = obj[key];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return cleaned;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function establishConnection(transport: Transport) {
|
|
27
|
+
const { default: Xrp } = await import("@ledgerhq/hw-app-xrp");
|
|
28
|
+
return new Xrp(transport);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function fetchAddressAndPublicKey({
|
|
32
|
+
instance,
|
|
33
|
+
derivationPath,
|
|
34
|
+
}: { instance: Xrp; derivationPath: string }) {
|
|
35
|
+
return instance.getAddress(derivationPath);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const XRPLedger = async (derivationPath?: DerivationPathArray) => {
|
|
39
|
+
const path = derivationPathToString(derivationPath || NetworkDerivationPath[Chain.Ripple]);
|
|
40
|
+
const transport = await getLedgerTransport();
|
|
41
|
+
const xrpInstance = await establishConnection(transport);
|
|
42
|
+
|
|
43
|
+
const { address, publicKey } = await fetchAddressAndPublicKey({
|
|
44
|
+
instance: xrpInstance,
|
|
45
|
+
derivationPath: path,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
async function sign(transaction: Payment | Transaction) {
|
|
49
|
+
const { hashes } = await import("@swapkit/toolboxes/ripple");
|
|
50
|
+
const cleanedTxWithPubKey = cleanTransactionObject(transaction);
|
|
51
|
+
const transactionJSON = {
|
|
52
|
+
...cleanedTxWithPubKey,
|
|
53
|
+
Flags: transaction.Flags || TF_FULLY_CANONICAL_SIG,
|
|
54
|
+
SigningPubKey: publicKey.toUpperCase(),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const transactionToSignOnLedger = encode(transactionJSON);
|
|
58
|
+
const txnSignature = await xrpInstance.signTransaction(path, transactionToSignOnLedger);
|
|
59
|
+
const tx_blob = encode({ ...transactionJSON, TxnSignature: txnSignature });
|
|
60
|
+
const hash = hashes.hashSignedTx(tx_blob);
|
|
61
|
+
|
|
62
|
+
return { tx_blob, hash };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { address, sign };
|
|
66
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SwapKitError } from "@swapkit/helpers";
|
|
2
|
+
|
|
1
3
|
export interface Coin {
|
|
2
4
|
readonly denom: string;
|
|
3
5
|
readonly amount: string;
|
|
@@ -57,12 +59,14 @@ export class AminoTypes {
|
|
|
57
59
|
toAmino({ typeUrl, value }: EncodeObject): AminoMsg {
|
|
58
60
|
const converter = this.register[typeUrl];
|
|
59
61
|
if (converter === "not_supported_by_chain") {
|
|
60
|
-
throw new
|
|
61
|
-
`The message type '${typeUrl}' cannot be signed using the Amino JSON sign mode because this is not supported by chain.`,
|
|
62
|
-
);
|
|
62
|
+
throw new SwapKitError("wallet_ledger_chain_not_supported", {
|
|
63
|
+
reason: `The message type '${typeUrl}' cannot be signed using the Amino JSON sign mode because this is not supported by chain.`,
|
|
64
|
+
});
|
|
63
65
|
}
|
|
64
66
|
if (!converter) {
|
|
65
|
-
throw new
|
|
67
|
+
throw new SwapKitError("wallet_ledger_invalid_params", {
|
|
68
|
+
reason: `Type URL '${typeUrl}' does not exist in the Amino message type register.`,
|
|
69
|
+
});
|
|
66
70
|
}
|
|
67
71
|
return {
|
|
68
72
|
type: converter.aminoType,
|
|
@@ -76,18 +80,18 @@ export class AminoTypes {
|
|
|
76
80
|
.filter(([_typeUrl, { aminoType }]) => aminoType === type);
|
|
77
81
|
|
|
78
82
|
if (matches.length === 0) {
|
|
79
|
-
throw new
|
|
80
|
-
`Amino type identifier '${type}' does not exist in the Amino message type register.`,
|
|
81
|
-
);
|
|
83
|
+
throw new SwapKitError("wallet_ledger_invalid_params", {
|
|
84
|
+
reason: `Amino type identifier '${type}' does not exist in the Amino message type register.`,
|
|
85
|
+
});
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
if (matches.length > 1) {
|
|
85
|
-
throw new
|
|
86
|
-
`Multiple types are registered with Amino type identifier '${type}': '${matches
|
|
89
|
+
throw new SwapKitError("wallet_ledger_invalid_params", {
|
|
90
|
+
reason: `Multiple types are registered with Amino type identifier '${type}': '${matches
|
|
87
91
|
.map(([key, _value]) => key)
|
|
88
92
|
.sort()
|
|
89
93
|
.join("', '")}'. Thus fromAmino cannot be performed.`,
|
|
90
|
-
);
|
|
94
|
+
});
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
const [typeUrl, converter] = matches[0] as [string, AminoConverter];
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Chain, SwapKitError, WalletOption } from "@swapkit/helpers";
|
|
2
2
|
|
|
3
|
+
import type { XRPLedger } from "../clients/xrp";
|
|
3
4
|
import type { LEDGER_SUPPORTED_CHAINS } from "../index";
|
|
4
5
|
import type { CosmosLedgerClients, EVMLedgerClients, UTXOLedgerClients } from "../types";
|
|
5
6
|
import type { getLedgerClient } from "./getLedgerClient";
|
|
6
7
|
|
|
7
|
-
export const getLedgerAddress = async
|
|
8
|
+
export const getLedgerAddress = async <
|
|
9
|
+
T extends (typeof LEDGER_SUPPORTED_CHAINS)[number],
|
|
10
|
+
L extends Awaited<ReturnType<typeof getLedgerClient<T>>>,
|
|
11
|
+
>({
|
|
8
12
|
chain,
|
|
9
13
|
ledgerClient,
|
|
10
14
|
}: {
|
|
11
|
-
chain:
|
|
12
|
-
ledgerClient:
|
|
15
|
+
chain: T;
|
|
16
|
+
ledgerClient: L;
|
|
13
17
|
}) => {
|
|
14
18
|
if (!ledgerClient) return "";
|
|
15
19
|
|
|
@@ -40,6 +44,11 @@ export const getLedgerAddress = async ({
|
|
|
40
44
|
|
|
41
45
|
return chain === Chain.BitcoinCash ? address.replace("bitcoincash:", "") : address;
|
|
42
46
|
}
|
|
47
|
+
|
|
48
|
+
case Chain.Ripple: {
|
|
49
|
+
return (ledgerClient as Awaited<ReturnType<typeof XRPLedger>>).address;
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
default:
|
|
44
53
|
throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.LEDGER, chain });
|
|
45
54
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Chain,
|
|
3
|
+
type DerivationPathArray,
|
|
4
|
+
type EVMChain,
|
|
5
|
+
SwapKitError,
|
|
6
|
+
WalletOption,
|
|
7
|
+
} from "@swapkit/helpers";
|
|
2
8
|
|
|
3
9
|
import { CosmosLedger } from "../clients/cosmos";
|
|
4
10
|
import {
|
|
@@ -18,6 +24,7 @@ import {
|
|
|
18
24
|
DogecoinLedger,
|
|
19
25
|
LitecoinLedger,
|
|
20
26
|
} from "../clients/utxo";
|
|
27
|
+
import { XRPLedger } from "../clients/xrp";
|
|
21
28
|
|
|
22
29
|
type LedgerSignerMap = {
|
|
23
30
|
[Chain.Arbitrum]: ReturnType<typeof ArbitrumLedger>;
|
|
@@ -33,6 +40,7 @@ type LedgerSignerMap = {
|
|
|
33
40
|
[Chain.Litecoin]: ReturnType<typeof LitecoinLedger>;
|
|
34
41
|
[Chain.Optimism]: ReturnType<typeof OptimismLedger>;
|
|
35
42
|
[Chain.Polygon]: ReturnType<typeof PolygonLedger>;
|
|
43
|
+
[Chain.Ripple]: ReturnType<typeof XRPLedger>;
|
|
36
44
|
[Chain.THORChain]: THORChainLedger;
|
|
37
45
|
};
|
|
38
46
|
|
|
@@ -45,51 +53,54 @@ export const getLedgerClient = async <T extends LedgerSupportedChain>({
|
|
|
45
53
|
chain: T;
|
|
46
54
|
derivationPath?: DerivationPathArray;
|
|
47
55
|
}): Promise<LedgerSignerMap[T]> => {
|
|
48
|
-
|
|
49
|
-
case Chain.THORChain:
|
|
50
|
-
return new THORChainLedger(derivationPath) as LedgerSignerMap[T];
|
|
51
|
-
case Chain.Cosmos:
|
|
52
|
-
return new CosmosLedger(derivationPath) as LedgerSignerMap[T];
|
|
53
|
-
case Chain.Bitcoin:
|
|
54
|
-
return BitcoinLedger(derivationPath) as LedgerSignerMap[T];
|
|
55
|
-
case Chain.BitcoinCash:
|
|
56
|
-
return BitcoinCashLedger(derivationPath) as LedgerSignerMap[T];
|
|
57
|
-
case Chain.Dash:
|
|
58
|
-
return DashLedger(derivationPath) as LedgerSignerMap[T];
|
|
59
|
-
case Chain.Dogecoin:
|
|
60
|
-
return DogecoinLedger(derivationPath) as LedgerSignerMap[T];
|
|
61
|
-
case Chain.Litecoin:
|
|
62
|
-
return LitecoinLedger(derivationPath) as LedgerSignerMap[T];
|
|
63
|
-
|
|
64
|
-
case Chain.Arbitrum:
|
|
65
|
-
case Chain.Avalanche:
|
|
66
|
-
case Chain.BinanceSmartChain:
|
|
67
|
-
case Chain.Ethereum:
|
|
68
|
-
case Chain.Optimism:
|
|
69
|
-
case Chain.Polygon:
|
|
70
|
-
case Chain.Base: {
|
|
71
|
-
const { getProvider } = await import("@swapkit/toolboxes/evm");
|
|
72
|
-
const params = { provider: await getProvider(chain), derivationPath };
|
|
56
|
+
const { match } = await import("ts-pattern");
|
|
73
57
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
58
|
+
return match(chain as LedgerSupportedChain)
|
|
59
|
+
.returnType<Promise<LedgerSignerMap[T]>>()
|
|
60
|
+
.with(Chain.THORChain, () =>
|
|
61
|
+
Promise.resolve(new THORChainLedger(derivationPath) as LedgerSignerMap[T]),
|
|
62
|
+
)
|
|
63
|
+
.with(Chain.Cosmos, () =>
|
|
64
|
+
Promise.resolve(new CosmosLedger(derivationPath) as LedgerSignerMap[T]),
|
|
65
|
+
)
|
|
66
|
+
.with(Chain.Bitcoin, () => Promise.resolve(BitcoinLedger(derivationPath) as LedgerSignerMap[T]))
|
|
67
|
+
.with(Chain.BitcoinCash, () =>
|
|
68
|
+
Promise.resolve(BitcoinCashLedger(derivationPath) as LedgerSignerMap[T]),
|
|
69
|
+
)
|
|
70
|
+
.with(Chain.Dash, () => Promise.resolve(DashLedger(derivationPath) as LedgerSignerMap[T]))
|
|
71
|
+
.with(Chain.Dogecoin, () =>
|
|
72
|
+
Promise.resolve(DogecoinLedger(derivationPath) as LedgerSignerMap[T]),
|
|
73
|
+
)
|
|
74
|
+
.with(Chain.Litecoin, () =>
|
|
75
|
+
Promise.resolve(LitecoinLedger(derivationPath) as LedgerSignerMap[T]),
|
|
76
|
+
)
|
|
77
|
+
.with(Chain.Ripple, () => Promise.resolve(XRPLedger(derivationPath) as LedgerSignerMap[T]))
|
|
78
|
+
.with(
|
|
79
|
+
Chain.Arbitrum,
|
|
80
|
+
Chain.Avalanche,
|
|
81
|
+
Chain.BinanceSmartChain,
|
|
82
|
+
Chain.Ethereum,
|
|
83
|
+
Chain.Optimism,
|
|
84
|
+
Chain.Polygon,
|
|
85
|
+
Chain.Base,
|
|
86
|
+
async () => {
|
|
87
|
+
const { getProvider } = await import("@swapkit/toolboxes/evm");
|
|
88
|
+
const params = { provider: await getProvider(chain as EVMChain), derivationPath };
|
|
91
89
|
|
|
92
|
-
|
|
90
|
+
return match(chain as Chain)
|
|
91
|
+
.with(
|
|
92
|
+
Chain.BinanceSmartChain,
|
|
93
|
+
() => BinanceSmartChainLedger(params) as LedgerSignerMap[T],
|
|
94
|
+
)
|
|
95
|
+
.with(Chain.Avalanche, () => AvalancheLedger(params) as LedgerSignerMap[T])
|
|
96
|
+
.with(Chain.Arbitrum, () => ArbitrumLedger(params) as LedgerSignerMap[T])
|
|
97
|
+
.with(Chain.Optimism, () => OptimismLedger(params) as LedgerSignerMap[T])
|
|
98
|
+
.with(Chain.Polygon, () => PolygonLedger(params) as LedgerSignerMap[T])
|
|
99
|
+
.with(Chain.Base, () => BaseLedger(params) as LedgerSignerMap[T])
|
|
100
|
+
.otherwise(() => EthereumLedger(params) as LedgerSignerMap[T]);
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
.otherwise(() => {
|
|
93
104
|
throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.LEDGER, chain });
|
|
94
|
-
|
|
105
|
+
});
|
|
95
106
|
};
|
|
@@ -20,7 +20,9 @@ const getLedgerDevices = async () => {
|
|
|
20
20
|
const existingDevices = devices.filter((d) => d.vendorId === ledgerUSBVendorId);
|
|
21
21
|
if (existingDevices.length > 0) return existingDevices[0];
|
|
22
22
|
|
|
23
|
-
return navigatorUsb?.requestDevice({
|
|
23
|
+
return navigatorUsb?.requestDevice({
|
|
24
|
+
filters: [{ vendorId: ledgerUSBVendorId }],
|
|
25
|
+
});
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export const getLedgerTransport = async () => {
|
|
@@ -57,9 +59,9 @@ export const getLedgerTransport = async () => {
|
|
|
57
59
|
throw new SwapKitError("wallet_ledger_connection_claimed", error);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
const
|
|
62
|
+
const Transport = (await import("@ledgerhq/hw-transport-webusb")).default;
|
|
61
63
|
const isSupported = await Transport.isSupported();
|
|
62
|
-
if (!isSupported) throw new
|
|
64
|
+
if (!isSupported) throw new SwapKitError("wallet_ledger_webusb_not_supported");
|
|
63
65
|
|
|
64
66
|
const { DisconnectedDevice } = await import("@ledgerhq/errors");
|
|
65
67
|
|
package/src/ledger/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type GenericTransferParams,
|
|
7
7
|
SKConfig,
|
|
8
8
|
StagenetChain,
|
|
9
|
+
SwapKitError,
|
|
9
10
|
WalletOption,
|
|
10
11
|
createWallet,
|
|
11
12
|
filterSupportedChains,
|
|
@@ -32,6 +33,7 @@ export const ledgerWallet = createWallet({
|
|
|
32
33
|
Chain.Litecoin,
|
|
33
34
|
Chain.Optimism,
|
|
34
35
|
Chain.Polygon,
|
|
36
|
+
Chain.Ripple,
|
|
35
37
|
Chain.THORChain,
|
|
36
38
|
],
|
|
37
39
|
walletType: WalletOption.LEDGER,
|
|
@@ -148,7 +150,7 @@ async function getWalletMethods({
|
|
|
148
150
|
const address = await getLedgerAddress({ chain, ledgerClient: signer });
|
|
149
151
|
|
|
150
152
|
const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
|
|
151
|
-
if (!assetValue) throw new
|
|
153
|
+
if (!assetValue) throw new SwapKitError("wallet_ledger_invalid_asset");
|
|
152
154
|
|
|
153
155
|
const sendCoinsMessage = {
|
|
154
156
|
amount: [
|
|
@@ -183,7 +185,7 @@ async function getWalletMethods({
|
|
|
183
185
|
case Chain.THORChain: {
|
|
184
186
|
const { SignMode } = await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js");
|
|
185
187
|
const { TxRaw } = await import("cosmjs-types/cosmos/tx/v1beta1/tx.js");
|
|
186
|
-
const { encodePubkey, makeAuthInfoBytes } = await import("@cosmjs/proto-signing");
|
|
188
|
+
const { encodePubkey, makeAuthInfoBytes } = (await import("@cosmjs/proto-signing")).default;
|
|
187
189
|
const {
|
|
188
190
|
createStargateClient,
|
|
189
191
|
buildEncodedTxBody,
|
|
@@ -208,9 +210,9 @@ async function getWalletMethods({
|
|
|
208
210
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Refactor to reduce complexity
|
|
209
211
|
}: GenericTransferParams | ThorchainDepositParams) => {
|
|
210
212
|
const account = await toolbox.getAccount(address);
|
|
211
|
-
if (!account) throw new
|
|
212
|
-
if (!assetValue) throw new
|
|
213
|
-
if (!value) throw new
|
|
213
|
+
if (!account) throw new SwapKitError("wallet_ledger_invalid_account");
|
|
214
|
+
if (!assetValue) throw new SwapKitError("wallet_ledger_invalid_asset");
|
|
215
|
+
if (!value) throw new SwapKitError("wallet_ledger_pubkey_not_found");
|
|
214
216
|
|
|
215
217
|
const { accountNumber, sequence: sequenceNumber } = account;
|
|
216
218
|
const sequence = (sequenceNumber || 0).toString();
|
|
@@ -230,7 +232,7 @@ async function getWalletMethods({
|
|
|
230
232
|
});
|
|
231
233
|
|
|
232
234
|
const signatures = await signTransaction(rawSendTx, sequence);
|
|
233
|
-
if (!signatures) throw new
|
|
235
|
+
if (!signatures) throw new SwapKitError("wallet_ledger_signing_error");
|
|
234
236
|
|
|
235
237
|
const pubkey = encodePubkey({ type: "tendermint/PubKeySecp256k1", value });
|
|
236
238
|
const msgs = orderedMessages.map(parseAminoMessageForDirectSigning);
|
|
@@ -267,7 +269,16 @@ async function getWalletMethods({
|
|
|
267
269
|
return { ...toolbox, address, deposit, transfer, signMessage };
|
|
268
270
|
}
|
|
269
271
|
|
|
272
|
+
case Chain.Ripple: {
|
|
273
|
+
const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
|
|
274
|
+
const signer = await getLedgerClient({ chain, derivationPath });
|
|
275
|
+
const address = signer.address;
|
|
276
|
+
const toolbox = await getRippleToolbox({ signer });
|
|
277
|
+
|
|
278
|
+
return { ...toolbox, address };
|
|
279
|
+
}
|
|
280
|
+
|
|
270
281
|
default:
|
|
271
|
-
throw new
|
|
282
|
+
throw new SwapKitError("wallet_ledger_chain_not_supported", { chain });
|
|
272
283
|
}
|
|
273
284
|
}
|
|
@@ -32,7 +32,7 @@ export abstract class CosmosLedgerInterface {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
case "cosmos": {
|
|
35
|
-
const
|
|
35
|
+
const CosmosApp = (await import("@ledgerhq/hw-app-cosmos")).default;
|
|
36
36
|
this.ledgerApp =
|
|
37
37
|
forceReconnect || !this.ledgerApp ? new CosmosApp(this.transport) : this.ledgerApp;
|
|
38
38
|
}
|
|
@@ -58,7 +58,6 @@ export abstract class CosmosLedgerInterface {
|
|
|
58
58
|
throw new SwapKitError("wallet_ledger_device_not_found");
|
|
59
59
|
|
|
60
60
|
default: {
|
|
61
|
-
console.error(`Ledger error: ${errorCode} ${message}`);
|
|
62
61
|
break;
|
|
63
62
|
}
|
|
64
63
|
}
|
package/src/okx/helpers.ts
CHANGED
|
@@ -3,16 +3,18 @@ import {
|
|
|
3
3
|
ChainId,
|
|
4
4
|
type EVMChain,
|
|
5
5
|
SKConfig,
|
|
6
|
+
SwapKitError,
|
|
6
7
|
prepareNetworkSwitch,
|
|
7
8
|
switchEVMWalletNetwork,
|
|
8
9
|
} from "@swapkit/helpers";
|
|
10
|
+
import { Psbt } from "bitcoinjs-lib";
|
|
9
11
|
import type { Eip1193Provider } from "ethers";
|
|
10
12
|
|
|
11
13
|
const cosmosTransfer =
|
|
12
14
|
() =>
|
|
13
15
|
async ({ from, recipient, amount, asset, memo }: any) => {
|
|
14
16
|
if (!(window.okxwallet && "keplr" in window.okxwallet)) {
|
|
15
|
-
throw new
|
|
17
|
+
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Cosmos });
|
|
16
18
|
}
|
|
17
19
|
const { createSigningStargateClient } = await import("@swapkit/toolboxes/cosmos");
|
|
18
20
|
|
|
@@ -38,7 +40,7 @@ async function getWeb3WalletMethods({
|
|
|
38
40
|
}: { walletProvider: Eip1193Provider | undefined; chain: EVMChain }) {
|
|
39
41
|
const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
40
42
|
const { BrowserProvider } = await import("ethers");
|
|
41
|
-
if (!walletProvider) throw new
|
|
43
|
+
if (!walletProvider) throw new SwapKitError("wallet_okx_not_found");
|
|
42
44
|
|
|
43
45
|
const provider = new BrowserProvider(walletProvider, "any");
|
|
44
46
|
const signer = await provider.getSigner();
|
|
@@ -49,7 +51,7 @@ async function getWeb3WalletMethods({
|
|
|
49
51
|
await switchEVMWalletNetwork(provider, chain, toolbox.getNetworkParams());
|
|
50
52
|
}
|
|
51
53
|
} catch (_error) {
|
|
52
|
-
throw new
|
|
54
|
+
throw new SwapKitError("wallet_okx_failed_to_switch_network", { chain });
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
return prepareNetworkSwitch({ toolbox, provider, chain });
|
|
@@ -65,7 +67,7 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
65
67
|
case Chain.Polygon:
|
|
66
68
|
case Chain.BinanceSmartChain: {
|
|
67
69
|
if (!(window.okxwallet && "send" in window.okxwallet)) {
|
|
68
|
-
throw new
|
|
70
|
+
throw new SwapKitError("wallet_okx_not_found", { chain });
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
const evmWallet = await getWeb3WalletMethods({
|
|
@@ -79,9 +81,9 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
79
81
|
|
|
80
82
|
case Chain.Bitcoin: {
|
|
81
83
|
if (!(window.okxwallet && "bitcoin" in window.okxwallet)) {
|
|
82
|
-
throw new
|
|
84
|
+
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Bitcoin });
|
|
83
85
|
}
|
|
84
|
-
|
|
86
|
+
|
|
85
87
|
const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
|
|
86
88
|
|
|
87
89
|
const { bitcoin: wallet } = window.okxwallet;
|
|
@@ -106,13 +108,13 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
106
108
|
|
|
107
109
|
case Chain.Cosmos: {
|
|
108
110
|
if (!(window.okxwallet && "keplr" in window.okxwallet)) {
|
|
109
|
-
throw new
|
|
111
|
+
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Cosmos });
|
|
110
112
|
}
|
|
111
113
|
const { keplr: wallet } = window.okxwallet;
|
|
112
114
|
|
|
113
115
|
await wallet.enable(ChainId.Cosmos);
|
|
114
116
|
const accounts = await wallet.getOfflineSignerOnlyAmino(ChainId.Cosmos).getAccounts();
|
|
115
|
-
if (!accounts?.[0]) throw new
|
|
117
|
+
if (!accounts?.[0]) throw new SwapKitError("wallet_okx_no_accounts", { chain: Chain.Cosmos });
|
|
116
118
|
|
|
117
119
|
const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
|
|
118
120
|
const [{ address }] = accounts;
|
|
@@ -122,6 +124,6 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
default:
|
|
125
|
-
throw new
|
|
127
|
+
throw new SwapKitError("wallet_okx_chain_not_supported", { chain });
|
|
126
128
|
}
|
|
127
129
|
}
|
package/src/onekey/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
filterSupportedChains,
|
|
10
10
|
prepareNetworkSwitch,
|
|
11
11
|
} from "@swapkit/helpers";
|
|
12
|
+
import { Psbt } from "bitcoinjs-lib";
|
|
12
13
|
import type {
|
|
13
14
|
BitcoinProvider,
|
|
14
15
|
GetAddressOptions,
|
|
@@ -21,13 +22,9 @@ async function getWalletMethodsForExtension(chain: Chain) {
|
|
|
21
22
|
switch (chain) {
|
|
22
23
|
case Chain.Bitcoin: {
|
|
23
24
|
if (!window.$onekey?.btc) {
|
|
24
|
-
throw new SwapKitError({
|
|
25
|
-
errorKey: "wallet_onekey_not_found",
|
|
26
|
-
info: { chain },
|
|
27
|
-
});
|
|
25
|
+
throw new SwapKitError({ errorKey: "wallet_onekey_not_found", info: { chain } });
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
const { Psbt } = await import("bitcoinjs-lib");
|
|
31
28
|
const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
|
|
32
29
|
const {
|
|
33
30
|
signTransaction: satsSignTransaction,
|
|
@@ -38,8 +35,7 @@ async function getWalletMethodsForExtension(chain: Chain) {
|
|
|
38
35
|
|
|
39
36
|
let address = "";
|
|
40
37
|
|
|
41
|
-
const getProvider
|
|
42
|
-
new Promise((res) => res(window.$onekey?.btc as BitcoinProvider));
|
|
38
|
+
const getProvider = () => new Promise<BitcoinProvider>((res) => res(window.$onekey?.btc));
|
|
43
39
|
|
|
44
40
|
const getAddressOptions: GetAddressOptions = {
|
|
45
41
|
getProvider,
|
package/src/radix/index.ts
CHANGED
|
@@ -162,13 +162,13 @@ async function getWalletMethods() {
|
|
|
162
162
|
const res = await rdt.walletApi.sendRequest();
|
|
163
163
|
|
|
164
164
|
if (!res) {
|
|
165
|
-
throw new
|
|
165
|
+
throw new SwapKitError("wallet_radix_no_account");
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
const newAddress = res.unwrapOr(null)?.accounts[0]?.address;
|
|
169
169
|
|
|
170
170
|
if (!newAddress) {
|
|
171
|
-
throw new
|
|
171
|
+
throw new SwapKitError("wallet_radix_no_account");
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
return newAddress;
|
|
@@ -182,7 +182,7 @@ async function getWalletMethods() {
|
|
|
182
182
|
getAddress,
|
|
183
183
|
getBalance: () => getBalance(address),
|
|
184
184
|
transfer: (_params: { assetValue: AssetValue; recipient: string; from: string }) => {
|
|
185
|
-
throw new
|
|
185
|
+
throw new SwapKitError("wallet_radix_method_not_supported", { method: "transfer" });
|
|
186
186
|
},
|
|
187
187
|
signAndBroadcast: async ({ manifest, message }: { manifest: string; message: string }) => {
|
|
188
188
|
const tx = await rdt.walletApi.sendTransaction({
|
|
@@ -193,7 +193,7 @@ async function getWalletMethods() {
|
|
|
193
193
|
const txResult = tx.unwrapOr(null)?.transactionIntentHash;
|
|
194
194
|
|
|
195
195
|
if (!txResult) {
|
|
196
|
-
throw new
|
|
196
|
+
throw new SwapKitError("wallet_radix_transaction_failed");
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
return txResult;
|
package/src/trezor/evmSigner.ts
CHANGED
|
@@ -35,7 +35,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
|
|
|
35
35
|
|
|
36
36
|
getAddress = async () => {
|
|
37
37
|
if (!this.address) {
|
|
38
|
-
const
|
|
38
|
+
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
39
39
|
|
|
40
40
|
const result = await TrezorConnect.ethereumGetAddress({
|
|
41
41
|
path: derivationPathToString(this.derivationPath),
|
|
@@ -56,7 +56,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
signMessage = async (message: string) => {
|
|
59
|
-
const
|
|
59
|
+
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
60
60
|
|
|
61
61
|
const result = await TrezorConnect.ethereumSignMessage({
|
|
62
62
|
path: derivationPathToString(this.derivationPath),
|
|
@@ -74,7 +74,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
signTypedData(): Promise<string> {
|
|
77
|
-
throw new
|
|
77
|
+
throw new SwapKitError("wallet_trezor_method_not_supported", { method: "signTypedData" });
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
signTransaction = async ({
|
|
@@ -107,7 +107,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
|
|
|
107
107
|
throw new SwapKitError({ errorKey: "wallet_missing_params", info: { gasPrice } });
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const
|
|
110
|
+
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
111
111
|
const { toHexString } = await import("@swapkit/toolboxes/evm");
|
|
112
112
|
const { Transaction } = await import("ethers");
|
|
113
113
|
|
package/src/trezor/index.ts
CHANGED
|
@@ -68,7 +68,7 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
68
68
|
const coin = chain.toLowerCase();
|
|
69
69
|
|
|
70
70
|
const getAddress = async (path: DerivationPathArray = derivationPath) => {
|
|
71
|
-
const
|
|
71
|
+
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
72
72
|
const { success, payload } = await TrezorConnect.getAddress({
|
|
73
73
|
path: derivationPathToString(path),
|
|
74
74
|
coin,
|
|
@@ -95,7 +95,7 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
95
95
|
const address = await getAddress();
|
|
96
96
|
|
|
97
97
|
const signTransaction = async (psbt: Psbt, inputs: UTXOType[], memo = "") => {
|
|
98
|
-
const
|
|
98
|
+
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
99
99
|
const address_n = derivationPath.map((pathElement, index) =>
|
|
100
100
|
index < 3 ? ((pathElement as number) | 0x80000000) >>> 0 : (pathElement as number),
|
|
101
101
|
);
|
|
@@ -229,11 +229,21 @@ export const trezorWallet = createWallet({
|
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
const
|
|
232
|
+
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
233
233
|
const { success } = await TrezorConnect.getDeviceState();
|
|
234
234
|
|
|
235
235
|
if (!success) {
|
|
236
|
-
const
|
|
236
|
+
const trezorConfig = SKConfig.get("integrations").trezor;
|
|
237
|
+
const manifest = trezorConfig
|
|
238
|
+
? {
|
|
239
|
+
...trezorConfig,
|
|
240
|
+
appName: (trezorConfig as any).appName || "SwapKit",
|
|
241
|
+
}
|
|
242
|
+
: {
|
|
243
|
+
appUrl: "",
|
|
244
|
+
email: "",
|
|
245
|
+
appName: "SwapKit",
|
|
246
|
+
};
|
|
237
247
|
TrezorConnect.init({ lazyLoad: true, manifest });
|
|
238
248
|
}
|
|
239
249
|
|
package/src/types.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
|
12
12
|
import type { SubstrateInjectedExtension } from "@swapkit/toolboxes/substrate";
|
|
13
13
|
import type { bitgetWallet } from "./bitget";
|
|
14
14
|
import type { coinbaseWallet } from "./coinbase";
|
|
15
|
+
import type { cosmostationWallet } from "./cosmostation";
|
|
15
16
|
import type { ctrlWallet } from "./ctrl";
|
|
16
17
|
import type { evmWallet } from "./evm-extensions";
|
|
17
18
|
import type { exodusWallet } from "./exodus";
|
|
@@ -34,6 +35,7 @@ export type SKWallets = {
|
|
|
34
35
|
[WalletOption.BRAVE]: typeof evmWallet;
|
|
35
36
|
[WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet;
|
|
36
37
|
[WalletOption.COINBASE_WEB]: typeof evmWallet;
|
|
38
|
+
[WalletOption.COSMOSTATION]: typeof cosmostationWallet;
|
|
37
39
|
[WalletOption.CTRL]: typeof ctrlWallet;
|
|
38
40
|
[WalletOption.EIP6963]: typeof evmWallet;
|
|
39
41
|
[WalletOption.EXODUS]: typeof exodusWallet;
|
|
@@ -64,6 +66,7 @@ export type SKWalletsSupportedChains = {
|
|
|
64
66
|
[WalletOption.BRAVE]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
65
67
|
[WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet.connectCoinbaseWallet.supportedChains;
|
|
66
68
|
[WalletOption.COINBASE_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
69
|
+
[WalletOption.COSMOSTATION]: typeof cosmostationWallet.connectCosmostation.supportedChains;
|
|
67
70
|
[WalletOption.CTRL]: typeof ctrlWallet.connectCtrl.supportedChains;
|
|
68
71
|
[WalletOption.EIP6963]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
69
72
|
[WalletOption.EXODUS]: typeof exodusWallet.connectExodusWallet.supportedChains;
|
package/src/utils.ts
CHANGED
|
@@ -25,6 +25,10 @@ export async function loadWallet<W extends WalletOption>(walletOption: W): Promi
|
|
|
25
25
|
async () => (await import("./walletconnect")).walletconnectWallet,
|
|
26
26
|
)
|
|
27
27
|
.with(WalletOption.KEPLR, WalletOption.LEAP, async () => (await import("./keplr")).keplrWallet)
|
|
28
|
+
.with(
|
|
29
|
+
WalletOption.COSMOSTATION,
|
|
30
|
+
async () => (await import("./cosmostation")).cosmostationWallet,
|
|
31
|
+
)
|
|
28
32
|
.with(
|
|
29
33
|
WalletOption.BRAVE,
|
|
30
34
|
WalletOption.COINBASE_WEB,
|