@swapkit/wallets 4.0.0-beta.38 → 4.0.0-beta.40
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-10h87ecy.js +4 -0
- package/dist/chunk-10h87ecy.js.map +10 -0
- package/dist/chunk-2aa1w78q.js +1 -0
- package/dist/chunk-31bmhjxx.js +4 -0
- package/dist/chunk-31bmhjxx.js.map +10 -0
- package/dist/chunk-3t5jkca2.js +5 -0
- package/dist/chunk-3t5jkca2.js.map +10 -0
- package/dist/{chunk-th8ggrmx.js → chunk-3vygfd50.js} +4 -3
- package/dist/{chunk-th8ggrmx.js.map → chunk-3vygfd50.js.map} +3 -3
- package/dist/{chunk-yah6cf33.js → chunk-940zcsgd.js} +3 -2
- package/dist/{chunk-yah6cf33.js.map → chunk-940zcsgd.js.map} +3 -3
- package/dist/{chunk-dcj9twam.js → chunk-bnnq9hg1.js} +3 -2
- package/dist/{chunk-dcj9twam.js.map → chunk-bnnq9hg1.js.map} +1 -1
- package/dist/chunk-bp34qnvm.js +5 -0
- package/dist/chunk-bp34qnvm.js.map +10 -0
- package/dist/chunk-etm8zfkk.js +4 -0
- package/dist/chunk-etm8zfkk.js.map +10 -0
- package/dist/{chunk-qwd1kp32.js → chunk-fa0psb24.js} +3 -2
- package/dist/{chunk-qwd1kp32.js.map → chunk-fa0psb24.js.map} +1 -1
- package/dist/chunk-kfw1mys1.js +4 -0
- package/dist/chunk-kfw1mys1.js.map +10 -0
- package/dist/chunk-vb4wtm2w.js +1 -0
- package/dist/chunk-wfattb4a.js +1 -0
- package/dist/{chunk-0qaxr89s.js → chunk-xwda1ncj.js} +3 -2
- package/dist/{chunk-0qaxr89s.js.map → chunk-xwda1ncj.js.map} +1 -1
- package/dist/src/bitget/index.cjs +3 -2
- package/dist/src/bitget/index.cjs.map +4 -4
- package/dist/src/bitget/index.js +3 -2
- package/dist/src/bitget/index.js.map +4 -4
- package/dist/src/coinbase/index.cjs +1 -0
- package/dist/src/coinbase/index.js +3 -2
- package/dist/src/coinbase/index.js.map +1 -1
- package/dist/src/cosmostation/index.cjs +1 -0
- package/dist/src/cosmostation/index.js +3 -2
- package/dist/src/cosmostation/index.js.map +1 -1
- package/dist/src/ctrl/index.cjs +1 -0
- package/dist/src/ctrl/index.js +3 -2
- package/dist/src/ctrl/index.js.map +2 -2
- package/dist/src/evm-extensions/index.cjs +1 -0
- package/dist/src/evm-extensions/index.js +3 -2
- package/dist/src/evm-extensions/index.js.map +1 -1
- package/dist/src/exodus/index.cjs +1 -0
- package/dist/src/exodus/index.js +3 -2
- package/dist/src/exodus/index.js.map +1 -1
- package/dist/src/index.cjs +3 -2
- package/dist/src/index.cjs.map +1 -1
- package/dist/src/index.js +3 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/keepkey/index.cjs +3 -2
- package/dist/src/keepkey/index.cjs.map +4 -5
- package/dist/src/keepkey/index.js +3 -2
- package/dist/src/keepkey/index.js.map +4 -5
- package/dist/src/keepkey-bex/index.cjs +3 -2
- package/dist/src/keepkey-bex/index.cjs.map +3 -3
- package/dist/src/keepkey-bex/index.js +3 -2
- package/dist/src/keepkey-bex/index.js.map +3 -3
- package/dist/src/keplr/index.cjs +1 -0
- package/dist/src/keplr/index.js +3 -2
- package/dist/src/keplr/index.js.map +1 -1
- package/dist/src/keystore/index.cjs +1 -0
- package/dist/src/keystore/index.js +3 -2
- package/dist/src/keystore/index.js.map +1 -1
- package/dist/src/ledger/index.cjs +4 -3
- package/dist/src/ledger/index.cjs.map +7 -6
- package/dist/src/ledger/index.js +4 -3
- package/dist/src/ledger/index.js.map +7 -6
- package/dist/src/okx/index.cjs +3 -2
- package/dist/src/okx/index.cjs.map +4 -4
- package/dist/src/okx/index.js +3 -2
- package/dist/src/okx/index.js.map +4 -4
- package/dist/src/onekey/index.cjs +3 -2
- package/dist/src/onekey/index.cjs.map +3 -3
- package/dist/src/onekey/index.js +3 -2
- package/dist/src/onekey/index.js.map +3 -3
- package/dist/src/phantom/index.cjs +1 -0
- package/dist/src/phantom/index.js +3 -2
- package/dist/src/phantom/index.js.map +1 -1
- package/dist/src/polkadotjs/index.cjs +1 -0
- package/dist/src/polkadotjs/index.js +3 -2
- package/dist/src/polkadotjs/index.js.map +1 -1
- package/dist/src/radix/index.cjs +1 -0
- package/dist/src/radix/index.js +3 -2
- package/dist/src/radix/index.js.map +1 -1
- package/dist/src/talisman/index.cjs +1 -0
- package/dist/src/talisman/index.js +3 -2
- package/dist/src/talisman/index.js.map +1 -1
- package/dist/src/trezor/index.cjs +3 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +3 -2
- package/dist/src/trezor/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs +3 -2
- package/dist/src/walletconnect/index.cjs.map +5 -5
- package/dist/src/walletconnect/index.js +3 -2
- package/dist/src/walletconnect/index.js.map +5 -5
- package/dist/src/xaman/index.cjs +4 -0
- package/dist/src/xaman/index.cjs.map +12 -0
- package/dist/src/xaman/index.js +4 -0
- package/dist/src/xaman/index.js.map +12 -0
- package/package.json +14 -6
- package/src/bitget/helpers.ts +65 -30
- package/src/bitget/index.ts +1 -1
- package/src/keepkey/chains/ripple.ts +118 -0
- package/src/keepkey/coins.ts +1 -0
- package/src/keepkey/index.ts +5 -0
- package/src/keepkey-bex/index.ts +1 -0
- package/src/ledger/clients/tron.ts +92 -0
- package/src/ledger/helpers/getLedgerAddress.ts +5 -0
- package/src/ledger/helpers/getLedgerClient.ts +3 -0
- package/src/ledger/index.ts +10 -0
- package/src/ledger/types.ts +2 -0
- package/src/okx/helpers.ts +71 -38
- package/src/okx/index.ts +1 -0
- package/src/onekey/index.ts +2 -2
- package/src/trezor/index.ts +8 -10
- package/src/types.ts +35 -0
- package/src/utils.ts +1 -0
- package/src/walletconnect/constants.ts +13 -0
- package/src/walletconnect/helpers.ts +11 -1
- package/src/walletconnect/index.ts +34 -0
- package/src/walletconnect/namespaces.ts +6 -0
- package/src/xaman/README.md +66 -0
- package/src/xaman/helpers.ts +59 -0
- package/src/xaman/index.ts +79 -0
- package/src/xaman/types.ts +26 -0
- package/src/xaman/walletMethods.ts +126 -0
- package/dist/chunk-bexr8da2.js +0 -4
- package/dist/chunk-bexr8da2.js.map +0 -10
- package/dist/chunk-sn6pgje5.js +0 -3
- package/dist/chunk-sn6pgje5.js.map +0 -10
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"@ledgerhq/hw-app-cosmos": "^6.32.0",
|
|
13
13
|
"@ledgerhq/hw-app-eth": "^6.45.0",
|
|
14
14
|
"@ledgerhq/hw-app-near": "^6.31.0",
|
|
15
|
+
"@ledgerhq/hw-app-trx": "^6.31.3",
|
|
15
16
|
"@ledgerhq/hw-app-xrp": "^6.31.0",
|
|
16
17
|
"@ledgerhq/hw-transport": "^6.31.0",
|
|
17
18
|
"@ledgerhq/hw-transport-webusb": "^6.29.0",
|
|
@@ -23,8 +24,8 @@
|
|
|
23
24
|
"@scure/base": "^1.2.0",
|
|
24
25
|
"@scure/bip39": "^1.6.0",
|
|
25
26
|
"@solana/web3.js": "^1.98.0",
|
|
26
|
-
"@swapkit/helpers": "^4.0.0-beta.
|
|
27
|
-
"@swapkit/toolboxes": "^4.0.0-beta.
|
|
27
|
+
"@swapkit/helpers": "^4.0.0-beta.25",
|
|
28
|
+
"@swapkit/toolboxes": "^4.0.0-beta.37",
|
|
28
29
|
"@trezor/connect-web": "^9.6.0",
|
|
29
30
|
"@walletconnect/modal": "^2.7.0",
|
|
30
31
|
"@walletconnect/sign-client": "^2.21.0",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"@ledgerhq/hw-app-cosmos": "6.32.2",
|
|
51
52
|
"@ledgerhq/hw-app-eth": "6.45.6",
|
|
52
53
|
"@ledgerhq/hw-app-near": "6.31.2",
|
|
54
|
+
"@ledgerhq/hw-app-trx": "6.31.3",
|
|
53
55
|
"@ledgerhq/hw-app-xrp": "6.31.2",
|
|
54
56
|
"@ledgerhq/hw-transport": "6.31.6",
|
|
55
57
|
"@ledgerhq/hw-transport-webusb": "6.29.6",
|
|
@@ -61,8 +63,8 @@
|
|
|
61
63
|
"@scure/base": "1.2.6",
|
|
62
64
|
"@scure/bip39": "1.6.0",
|
|
63
65
|
"@solana/web3.js": "1.98.2",
|
|
64
|
-
"@swapkit/helpers": "4.0.0-beta.
|
|
65
|
-
"@swapkit/toolboxes": "4.0.0-beta.
|
|
66
|
+
"@swapkit/helpers": "4.0.0-beta.25",
|
|
67
|
+
"@swapkit/toolboxes": "4.0.0-beta.37",
|
|
66
68
|
"@trezor/connect-web": "9.6.0",
|
|
67
69
|
"@walletconnect/logger": "2.1.2",
|
|
68
70
|
"@walletconnect/modal": "2.7.0",
|
|
@@ -74,7 +76,8 @@
|
|
|
74
76
|
"near-api-js": "6.1.0",
|
|
75
77
|
"ripple-binary-codec": "2.4.1",
|
|
76
78
|
"sats-connect": "3.5.0",
|
|
77
|
-
"ts-pattern": "5.7.1"
|
|
79
|
+
"ts-pattern": "5.7.1",
|
|
80
|
+
"xumm": "1.8.0"
|
|
78
81
|
},
|
|
79
82
|
"exports": {
|
|
80
83
|
".": {
|
|
@@ -176,6 +179,11 @@
|
|
|
176
179
|
"default": "./dist/src/walletconnect/index.js",
|
|
177
180
|
"require": "./dist/src/walletconnect/index.cjs",
|
|
178
181
|
"types": "./src/walletconnect/index.ts"
|
|
182
|
+
},
|
|
183
|
+
"./xaman": {
|
|
184
|
+
"default": "./dist/src/xaman/index.js",
|
|
185
|
+
"require": "./dist/src/xaman/index.cjs",
|
|
186
|
+
"types": "./src/xaman/index.ts"
|
|
179
187
|
}
|
|
180
188
|
},
|
|
181
189
|
"files": [
|
|
@@ -197,5 +205,5 @@
|
|
|
197
205
|
"type-check:go": "tsgo"
|
|
198
206
|
},
|
|
199
207
|
"type": "module",
|
|
200
|
-
"version": "4.0.0-beta.
|
|
208
|
+
"version": "4.0.0-beta.40"
|
|
201
209
|
}
|
package/src/bitget/helpers.ts
CHANGED
|
@@ -6,33 +6,42 @@ import {
|
|
|
6
6
|
prepareNetworkSwitch,
|
|
7
7
|
switchEVMWalletNetwork,
|
|
8
8
|
} from "@swapkit/helpers";
|
|
9
|
+
import type { TronTransaction } from "@swapkit/toolboxes/tron";
|
|
9
10
|
import { Psbt } from "bitcoinjs-lib";
|
|
10
11
|
import type { Eip1193Provider } from "ethers";
|
|
11
12
|
|
|
12
13
|
export async function getWalletMethods(chain: Chain) {
|
|
14
|
+
const { match, P } = await import("ts-pattern");
|
|
13
15
|
const bitget = window.bitkeep;
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
return match(chain)
|
|
18
|
+
.with(
|
|
19
|
+
P.union(
|
|
20
|
+
Chain.Ethereum,
|
|
21
|
+
Chain.Base,
|
|
22
|
+
Chain.Avalanche,
|
|
23
|
+
Chain.Arbitrum,
|
|
24
|
+
Chain.Optimism,
|
|
25
|
+
Chain.Polygon,
|
|
26
|
+
Chain.BinanceSmartChain,
|
|
27
|
+
),
|
|
28
|
+
async () => {
|
|
29
|
+
if (!(bitget && "ethereum" in bitget)) {
|
|
30
|
+
throw new SwapKitError("wallet_bitkeep_not_found");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const wallet = bitget.ethereum;
|
|
34
|
+
|
|
35
|
+
const [address]: [string] = await wallet.send("eth_requestAccounts", []);
|
|
36
|
+
const evmWallet = await getWeb3WalletMethods({
|
|
37
|
+
chain: chain as EVMChain,
|
|
38
|
+
walletProvider: wallet,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return { ...evmWallet, address };
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
.with(Chain.Bitcoin, async () => {
|
|
36
45
|
if (!(bitget && "unisat" in bitget)) {
|
|
37
46
|
throw new SwapKitError("wallet_bitkeep_not_found");
|
|
38
47
|
}
|
|
@@ -55,9 +64,8 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
55
64
|
const toolbox = await getUtxoToolbox(Chain.Bitcoin, { signer });
|
|
56
65
|
|
|
57
66
|
return { ...toolbox, address };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
case Chain.Cosmos: {
|
|
67
|
+
})
|
|
68
|
+
.with(Chain.Cosmos, async () => {
|
|
61
69
|
if (!(bitget && "keplr" in bitget)) {
|
|
62
70
|
throw new SwapKitError("wallet_bitkeep_not_found");
|
|
63
71
|
}
|
|
@@ -83,9 +91,8 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
83
91
|
});
|
|
84
92
|
|
|
85
93
|
return { ...toolbox, address };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
case Chain.Solana: {
|
|
94
|
+
})
|
|
95
|
+
.with(Chain.Solana, async () => {
|
|
89
96
|
if (!(bitget && "solana" in bitget)) {
|
|
90
97
|
throw new SwapKitError("wallet_bitkeep_not_found");
|
|
91
98
|
}
|
|
@@ -98,11 +105,39 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
98
105
|
const address: string = providerConnection.publicKey.toString();
|
|
99
106
|
|
|
100
107
|
return { ...toolbox, address };
|
|
101
|
-
}
|
|
108
|
+
})
|
|
109
|
+
.with(Chain.Tron, async () => {
|
|
110
|
+
if (!(bitget && "tronLink" in bitget && "tronWeb" in bitget)) {
|
|
111
|
+
throw new SwapKitError("wallet_bitkeep_not_found");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
|
|
115
|
+
const { tronLink, tronWeb } = bitget;
|
|
116
|
+
|
|
117
|
+
// Request account access
|
|
118
|
+
const account = await tronLink.request({ method: "tron_requestAccounts" });
|
|
119
|
+
if (!account?.base58) {
|
|
120
|
+
throw new SwapKitError("wallet_bitkeep_no_accounts", { chain: Chain.Tron });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const address = account.base58;
|
|
124
|
+
|
|
125
|
+
// Create signer compatible with TronSigner interface
|
|
126
|
+
const signer = {
|
|
127
|
+
getAddress: () => Promise.resolve(address),
|
|
128
|
+
signTransaction: async (transaction: TronTransaction) => {
|
|
129
|
+
const signedTx = await tronWeb.trx.sign(transaction);
|
|
130
|
+
return signedTx;
|
|
131
|
+
},
|
|
132
|
+
};
|
|
102
133
|
|
|
103
|
-
|
|
134
|
+
const toolbox = await createTronToolbox({ signer });
|
|
135
|
+
|
|
136
|
+
return { ...toolbox, address };
|
|
137
|
+
})
|
|
138
|
+
.otherwise(() => {
|
|
104
139
|
throw new SwapKitError("wallet_chain_not_supported");
|
|
105
|
-
|
|
140
|
+
});
|
|
106
141
|
}
|
|
107
142
|
|
|
108
143
|
export const getWeb3WalletMethods = async ({
|
package/src/bitget/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { getWalletMethods } from "./helpers";
|
|
|
12
12
|
export const bitgetWallet = createWallet({
|
|
13
13
|
name: "connectBitget",
|
|
14
14
|
walletType: WalletOption.BITGET,
|
|
15
|
-
supportedChains: [...EVMChains, Chain.Cosmos, Chain.Bitcoin, Chain.Solana],
|
|
15
|
+
supportedChains: [...EVMChains, Chain.Cosmos, Chain.Bitcoin, Chain.Solana, Chain.Tron],
|
|
16
16
|
connect: ({ addChain, walletType, supportedChains }) =>
|
|
17
17
|
async function connectBitget(chains: Chain[]) {
|
|
18
18
|
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
2
|
+
import {
|
|
3
|
+
Chain,
|
|
4
|
+
DerivationPath,
|
|
5
|
+
type DerivationPathArray,
|
|
6
|
+
type GenericTransferParams,
|
|
7
|
+
derivationPathToString,
|
|
8
|
+
} from "@swapkit/helpers";
|
|
9
|
+
import { bip32ToAddressNList } from "../coins";
|
|
10
|
+
|
|
11
|
+
import { getRippleToolbox } from "@swapkit/toolboxes/ripple";
|
|
12
|
+
|
|
13
|
+
export const rippleWalletMethods = async ({
|
|
14
|
+
sdk,
|
|
15
|
+
derivationPath,
|
|
16
|
+
}: {
|
|
17
|
+
sdk: KeepKeySdk;
|
|
18
|
+
derivationPath?: DerivationPathArray;
|
|
19
|
+
}) => {
|
|
20
|
+
// Derivation path handling (default to standard XRP 44'/144'/0'/0/0)
|
|
21
|
+
const derivationPathString = derivationPath
|
|
22
|
+
? derivationPathToString(derivationPath)
|
|
23
|
+
: `${DerivationPath[Chain.Ripple]}/0`;
|
|
24
|
+
|
|
25
|
+
// Fetch address from KeepKey
|
|
26
|
+
// @ts-ignore - keepkey-sdk typings may not yet include xrpGetAddress
|
|
27
|
+
const { address } = await (sdk as any).address.xrpGetAddress({
|
|
28
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Inject minimal signer so toolbox's address helpers work
|
|
32
|
+
const signer = {
|
|
33
|
+
getAddress: () => Promise.resolve(address),
|
|
34
|
+
signTransaction: () => {
|
|
35
|
+
throw new Error("signTransaction not supported via toolbox");
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const toolbox = await getRippleToolbox({ signer });
|
|
40
|
+
|
|
41
|
+
const transfer = async ({ recipient, assetValue, memo }: GenericTransferParams) => {
|
|
42
|
+
// Build XRPL Payment tx using toolbox helper
|
|
43
|
+
const tx = await toolbox.createTransaction({
|
|
44
|
+
assetValue,
|
|
45
|
+
recipient,
|
|
46
|
+
memo,
|
|
47
|
+
sender: address,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Convert toolbox Payment tx into KeepKey StdTx wrapper (KeepKey-specific format)
|
|
51
|
+
const stdTx = {
|
|
52
|
+
type: "auth/StdTx",
|
|
53
|
+
value: {
|
|
54
|
+
fee: {
|
|
55
|
+
amount: [
|
|
56
|
+
{
|
|
57
|
+
amount: "1000",
|
|
58
|
+
denom: "drop",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
gas: "28000",
|
|
62
|
+
},
|
|
63
|
+
memo: memo && memo.length > 0 ? memo : "",
|
|
64
|
+
msg: [
|
|
65
|
+
{
|
|
66
|
+
type: "ripple-sdk/MsgSend",
|
|
67
|
+
value: {
|
|
68
|
+
amount: [
|
|
69
|
+
{
|
|
70
|
+
amount: tx.Amount,
|
|
71
|
+
denom: "drop",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
from_address: address,
|
|
75
|
+
to_address: recipient,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
signatures: null,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const unsignedTx = {
|
|
84
|
+
addressNList: bip32ToAddressNList(derivationPathString),
|
|
85
|
+
tx: stdTx,
|
|
86
|
+
flags: tx.Flags === 0 ? undefined : tx.Flags,
|
|
87
|
+
lastLedgerSequence: tx.LastLedgerSequence?.toString(),
|
|
88
|
+
sequence: (tx.Sequence ?? 0).toString(),
|
|
89
|
+
payment: {
|
|
90
|
+
amount: tx.Amount,
|
|
91
|
+
destination: tx.Destination,
|
|
92
|
+
destinationTag: (tx.DestinationTag ?? "0").toString(),
|
|
93
|
+
},
|
|
94
|
+
} as any;
|
|
95
|
+
|
|
96
|
+
// Sign with KeepKey
|
|
97
|
+
// @ts-ignore - typings missing
|
|
98
|
+
const responseSign = JSON.parse(await (sdk as any).xrp.xrpSignTransaction(unsignedTx));
|
|
99
|
+
|
|
100
|
+
// keepkey-sdk may return either { tx_blob } or StdTx with Base64 serializedTx
|
|
101
|
+
const txBlob: string | undefined =
|
|
102
|
+
(responseSign as any).tx_blob ?? (responseSign as any).value?.signatures?.[0]?.serializedTx;
|
|
103
|
+
if (!txBlob) throw new Error("KeepKey XRP sign failed");
|
|
104
|
+
|
|
105
|
+
const buffer = Buffer.from(txBlob, "base64");
|
|
106
|
+
const txBlobHex = buffer.toString("hex");
|
|
107
|
+
|
|
108
|
+
// Broadcast signed tx via toolbox
|
|
109
|
+
return toolbox.broadcastTransaction(txBlobHex);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
...toolbox,
|
|
114
|
+
address,
|
|
115
|
+
getAddress: () => address,
|
|
116
|
+
transfer,
|
|
117
|
+
};
|
|
118
|
+
};
|
package/src/keepkey/coins.ts
CHANGED
package/src/keepkey/index.ts
CHANGED
|
@@ -33,6 +33,7 @@ export const keepkeyWallet = createWallet({
|
|
|
33
33
|
Chain.Dash,
|
|
34
34
|
Chain.Ethereum,
|
|
35
35
|
Chain.Litecoin,
|
|
36
|
+
Chain.Ripple,
|
|
36
37
|
Chain.Optimism,
|
|
37
38
|
Chain.Polygon,
|
|
38
39
|
Chain.THORChain,
|
|
@@ -116,6 +117,10 @@ async function getWalletMethods({
|
|
|
116
117
|
case Chain.Litecoin: {
|
|
117
118
|
return utxoWalletMethods({ sdk, chain, derivationPath });
|
|
118
119
|
}
|
|
120
|
+
case Chain.Ripple: {
|
|
121
|
+
const { rippleWalletMethods } = await import("./chains/ripple");
|
|
122
|
+
return rippleWalletMethods({ sdk, derivationPath });
|
|
123
|
+
}
|
|
119
124
|
default:
|
|
120
125
|
throw new SwapKitError("wallet_keepkey_chain_not_supported", { chain });
|
|
121
126
|
}
|
package/src/keepkey-bex/index.ts
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type TronApp from "@ledgerhq/hw-app-trx";
|
|
2
|
+
import {
|
|
3
|
+
type DerivationPathArray,
|
|
4
|
+
NetworkDerivationPath,
|
|
5
|
+
SwapKitError,
|
|
6
|
+
derivationPathToString,
|
|
7
|
+
} from "@swapkit/helpers";
|
|
8
|
+
import type { TronSigner, TronTransaction } from "@swapkit/toolboxes/tron";
|
|
9
|
+
|
|
10
|
+
import { getLedgerTransport } from "../helpers/getLedgerTransport";
|
|
11
|
+
|
|
12
|
+
export class TronLedgerInterface implements TronSigner {
|
|
13
|
+
derivationPath: string;
|
|
14
|
+
ledgerApp: InstanceType<typeof TronApp> | null = null;
|
|
15
|
+
ledgerTimeout = 50000;
|
|
16
|
+
|
|
17
|
+
constructor(derivationPath?: DerivationPathArray | string) {
|
|
18
|
+
this.derivationPath =
|
|
19
|
+
typeof derivationPath === "string"
|
|
20
|
+
? derivationPath
|
|
21
|
+
: derivationPathToString(derivationPath || NetworkDerivationPath.TRX);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
checkOrCreateTransportAndLedger = async () => {
|
|
25
|
+
if (this.ledgerApp) return;
|
|
26
|
+
await this.createTransportAndLedger();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
createTransportAndLedger = async () => {
|
|
30
|
+
const transport = await getLedgerTransport();
|
|
31
|
+
const TronApp = (await import("@ledgerhq/hw-app-trx")).default;
|
|
32
|
+
|
|
33
|
+
this.ledgerApp = new TronApp(transport);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
getAddress = async (): Promise<string> => {
|
|
37
|
+
const response = await this.getAddressAndPubKey();
|
|
38
|
+
if (!response) throw new SwapKitError("wallet_ledger_failed_to_get_address");
|
|
39
|
+
return response.address;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
getAddressAndPubKey = async () => {
|
|
43
|
+
await this.createTransportAndLedger();
|
|
44
|
+
const result = await this.ledgerApp?.getAddress(this.derivationPath);
|
|
45
|
+
|
|
46
|
+
if (!result) throw new SwapKitError("wallet_ledger_failed_to_get_address");
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
address: result.address,
|
|
50
|
+
publicKey: result.publicKey,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
showAddressAndPubKey = async () => {
|
|
55
|
+
await this.createTransportAndLedger();
|
|
56
|
+
return this.ledgerApp?.getAddress(this.derivationPath, true);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
signTransaction = async (transaction: TronTransaction) => {
|
|
60
|
+
await this.createTransportAndLedger();
|
|
61
|
+
|
|
62
|
+
if (!this.ledgerApp) {
|
|
63
|
+
throw new SwapKitError("wallet_ledger_transport_error");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Tron transactions need to be serialized before signing
|
|
67
|
+
const serializedTx = JSON.stringify(transaction);
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const signature = await this.ledgerApp.signTransaction(
|
|
71
|
+
this.derivationPath,
|
|
72
|
+
serializedTx,
|
|
73
|
+
[], // Token signatures array - empty for native TRX transfers
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (!signature) {
|
|
77
|
+
throw new SwapKitError("wallet_ledger_signing_error");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Return the signed transaction in Tron's expected format
|
|
81
|
+
return {
|
|
82
|
+
...transaction,
|
|
83
|
+
signature: [signature],
|
|
84
|
+
};
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new SwapKitError("wallet_ledger_signing_error", { error });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const TronLedger = (derivationPath?: DerivationPathArray) =>
|
|
92
|
+
new TronLedgerInterface(derivationPath);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Chain, SwapKitError, WalletOption } from "@swapkit/helpers";
|
|
2
2
|
|
|
3
3
|
import type { getNearLedgerClient } from "../clients/near";
|
|
4
|
+
import type { TronLedger } from "../clients/tron";
|
|
4
5
|
import type { XRPLedger } from "../clients/xrp";
|
|
5
6
|
import type { LEDGER_SUPPORTED_CHAINS } from "../index";
|
|
6
7
|
import type { CosmosLedgerClients, EVMLedgerClients, UTXOLedgerClients } from "../types";
|
|
@@ -54,6 +55,10 @@ export const getLedgerAddress = async <
|
|
|
54
55
|
return (ledgerClient as Awaited<ReturnType<typeof XRPLedger>>).address;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
case Chain.Tron: {
|
|
59
|
+
return (ledgerClient as Awaited<ReturnType<typeof TronLedger>>).getAddress();
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
default:
|
|
58
63
|
throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.LEDGER, chain });
|
|
59
64
|
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from "../clients/evm";
|
|
19
19
|
import { getNearLedgerClient } from "../clients/near";
|
|
20
20
|
import { THORChainLedger } from "../clients/thorchain";
|
|
21
|
+
import { TronLedger } from "../clients/tron";
|
|
21
22
|
import {
|
|
22
23
|
BitcoinCashLedger,
|
|
23
24
|
BitcoinLedger,
|
|
@@ -45,6 +46,7 @@ type LedgerSignerMap = {
|
|
|
45
46
|
[Chain.Polygon]: ReturnType<typeof PolygonLedger>;
|
|
46
47
|
[Chain.Ripple]: ReturnType<typeof XRPLedger>;
|
|
47
48
|
[Chain.THORChain]: THORChainLedger;
|
|
49
|
+
[Chain.Tron]: ReturnType<typeof TronLedger>;
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
type LedgerSupportedChain = keyof LedgerSignerMap;
|
|
@@ -78,6 +80,7 @@ export const getLedgerClient = async <T extends LedgerSupportedChain>({
|
|
|
78
80
|
Promise.resolve(LitecoinLedger(derivationPath) as LedgerSignerMap[T]),
|
|
79
81
|
)
|
|
80
82
|
.with(Chain.Ripple, () => Promise.resolve(XRPLedger(derivationPath) as LedgerSignerMap[T]))
|
|
83
|
+
.with(Chain.Tron, () => Promise.resolve(TronLedger(derivationPath) as LedgerSignerMap[T]))
|
|
81
84
|
.with(Chain.Near, async () => {
|
|
82
85
|
const transport = await getLedgerTransport();
|
|
83
86
|
return getNearLedgerClient(transport, derivationPath) as unknown as LedgerSignerMap[T];
|
package/src/ledger/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ export const ledgerWallet = createWallet({
|
|
|
36
36
|
Chain.Polygon,
|
|
37
37
|
Chain.Ripple,
|
|
38
38
|
Chain.THORChain,
|
|
39
|
+
Chain.Tron,
|
|
39
40
|
],
|
|
40
41
|
walletType: WalletOption.LEDGER,
|
|
41
42
|
connect: ({ addChain, supportedChains, walletType }) =>
|
|
@@ -288,6 +289,15 @@ async function getWalletMethods({
|
|
|
288
289
|
return { ...toolbox, address };
|
|
289
290
|
}
|
|
290
291
|
|
|
292
|
+
case Chain.Tron: {
|
|
293
|
+
const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
|
|
294
|
+
const signer = await getLedgerClient({ chain, derivationPath });
|
|
295
|
+
const address = await getLedgerAddress({ chain, ledgerClient: signer });
|
|
296
|
+
const toolbox = await createTronToolbox({ signer });
|
|
297
|
+
|
|
298
|
+
return { ...toolbox, address };
|
|
299
|
+
}
|
|
300
|
+
|
|
291
301
|
default:
|
|
292
302
|
throw new SwapKitError("wallet_ledger_chain_not_supported", { chain });
|
|
293
303
|
}
|
package/src/ledger/types.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
PolygonLedger,
|
|
10
10
|
} from "./clients/evm";
|
|
11
11
|
import type { THORChainLedger } from "./clients/thorchain";
|
|
12
|
+
import type { TronLedger } from "./clients/tron";
|
|
12
13
|
import type {
|
|
13
14
|
BitcoinCashLedger,
|
|
14
15
|
BitcoinLedger,
|
|
@@ -30,6 +31,7 @@ export type EVMLedgerClients =
|
|
|
30
31
|
| ReturnType<typeof EthereumLedger>
|
|
31
32
|
| ReturnType<typeof OptimismLedger>
|
|
32
33
|
| ReturnType<typeof PolygonLedger>;
|
|
34
|
+
export type TronLedgerClient = ReturnType<typeof TronLedger>;
|
|
33
35
|
|
|
34
36
|
export type GetAddressAndPubKeyResponse = {
|
|
35
37
|
bech32_address: string;
|