@swapkit/wallets 4.0.0-beta.39 → 4.0.0-beta.41
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-qh8q7xr1.js → chunk-10h87ecy.js} +3 -3
- package/dist/{chunk-qh8q7xr1.js.map → chunk-10h87ecy.js.map} +1 -1
- package/dist/{chunk-c11abmv4.js → chunk-a3x125xy.js} +4 -4
- package/dist/{chunk-c11abmv4.js.map → chunk-a3x125xy.js.map} +3 -3
- package/dist/{chunk-hafkx3bw.js → chunk-bnnq9hg1.js} +3 -3
- package/dist/{chunk-hafkx3bw.js.map → chunk-bnnq9hg1.js.map} +1 -1
- package/dist/{chunk-5mq0kpmy.js → chunk-bp34qnvm.js} +3 -3
- package/dist/{chunk-5mq0kpmy.js.map → chunk-bp34qnvm.js.map} +1 -1
- package/dist/{chunk-0rgqnhd7.js → chunk-brmp4444.js} +3 -3
- package/dist/{chunk-0rgqnhd7.js.map → chunk-brmp4444.js.map} +3 -3
- package/dist/{chunk-r308an05.js → chunk-fa0psb24.js} +3 -3
- package/dist/{chunk-r308an05.js.map → chunk-fa0psb24.js.map} +1 -1
- package/dist/chunk-hj6ccepz.js +5 -0
- package/dist/chunk-hj6ccepz.js.map +10 -0
- package/dist/{chunk-cgt2fexr.js → chunk-xwda1ncj.js} +3 -3
- package/dist/{chunk-cgt2fexr.js.map → chunk-xwda1ncj.js.map} +1 -1
- package/dist/chunk-xy3yys5z.js +4 -0
- package/dist/chunk-xy3yys5z.js.map +10 -0
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +4 -4
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +4 -4
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +1 -1
- package/dist/src/cosmostation/index.js +2 -2
- package/dist/src/cosmostation/index.js.map +1 -1
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +1 -1
- package/dist/src/evm-extensions/index.js +2 -2
- package/dist/src/evm-extensions/index.js.map +1 -1
- package/dist/src/exodus/index.js +2 -2
- package/dist/src/exodus/index.js.map +1 -1
- package/dist/src/index.cjs +2 -2
- package/dist/src/index.cjs.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +3 -3
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +3 -3
- package/dist/src/keepkey-bex/index.js +2 -2
- package/dist/src/keepkey-bex/index.js.map +1 -1
- package/dist/src/keplr/index.js +2 -2
- package/dist/src/keplr/index.js.map +1 -1
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +1 -1
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +7 -6
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +7 -6
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +4 -4
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +4 -4
- 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 +2 -2
- package/dist/src/phantom/index.js.map +1 -1
- package/dist/src/polkadotjs/index.js +2 -2
- package/dist/src/polkadotjs/index.js.map +1 -1
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +1 -1
- package/dist/src/talisman/index.js +2 -2
- package/dist/src/talisman/index.js.map +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 +5 -5
- package/dist/src/walletconnect/index.js +2 -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 +16 -8
- package/src/bitget/helpers.ts +65 -30
- package/src/bitget/index.ts +1 -1
- package/src/keepkey/chains/cosmos.ts +2 -2
- 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 +19 -4
- 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-9sjqewve.js +0 -5
- package/dist/chunk-9sjqewve.js.map +0 -10
- package/dist/chunk-sn6pgje5.js +0 -4
- package/dist/chunk-sn6pgje5.js.map +0 -10
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 });
|
|
@@ -18,7 +18,7 @@ export const cosmosWalletMethods = async ({
|
|
|
18
18
|
const {
|
|
19
19
|
DEFAULT_COSMOS_FEE_MAINNET,
|
|
20
20
|
getCosmosToolbox,
|
|
21
|
-
|
|
21
|
+
getFeeRateFromSwapKit,
|
|
22
22
|
createStargateClient,
|
|
23
23
|
} = await import("@swapkit/toolboxes/cosmos");
|
|
24
24
|
const derivationPathString = derivationPath
|
|
@@ -33,7 +33,7 @@ export const cosmosWalletMethods = async ({
|
|
|
33
33
|
|
|
34
34
|
if (DEFAULT_COSMOS_FEE_MAINNET.amount[0]) {
|
|
35
35
|
DEFAULT_COSMOS_FEE_MAINNET.amount[0].amount = String(
|
|
36
|
-
await
|
|
36
|
+
await getFeeRateFromSwapKit(ChainId.Cosmos, 500),
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -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;
|
package/src/okx/helpers.ts
CHANGED
|
@@ -2,17 +2,19 @@ import {
|
|
|
2
2
|
Chain,
|
|
3
3
|
ChainId,
|
|
4
4
|
type EVMChain,
|
|
5
|
+
type GenericTransferParams,
|
|
5
6
|
SKConfig,
|
|
6
7
|
SwapKitError,
|
|
7
8
|
prepareNetworkSwitch,
|
|
8
9
|
switchEVMWalletNetwork,
|
|
9
10
|
} from "@swapkit/helpers";
|
|
11
|
+
import type { TronSigner, TronTransaction } from "@swapkit/toolboxes/tron";
|
|
10
12
|
import { Psbt } from "bitcoinjs-lib";
|
|
11
13
|
import type { Eip1193Provider } from "ethers";
|
|
12
14
|
|
|
13
15
|
const cosmosTransfer =
|
|
14
|
-
() =>
|
|
15
|
-
async ({
|
|
16
|
+
(sender: string) =>
|
|
17
|
+
async ({ recipient, assetValue, memo }: GenericTransferParams) => {
|
|
16
18
|
if (!(window.okxwallet && "keplr" in window.okxwallet)) {
|
|
17
19
|
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Cosmos });
|
|
18
20
|
}
|
|
@@ -25,12 +27,12 @@ const cosmosTransfer =
|
|
|
25
27
|
|
|
26
28
|
const coins = [
|
|
27
29
|
{
|
|
28
|
-
denom:
|
|
29
|
-
amount:
|
|
30
|
+
denom: assetValue?.symbol === "MUON" ? "umuon" : "uatom",
|
|
31
|
+
amount: assetValue.getBaseValue("string"),
|
|
30
32
|
},
|
|
31
33
|
];
|
|
32
34
|
|
|
33
|
-
const { transactionHash } = await cosmJS.sendTokens(
|
|
35
|
+
const { transactionHash } = await cosmJS.sendTokens(sender, recipient, coins, 1.6, memo);
|
|
34
36
|
return transactionHash;
|
|
35
37
|
};
|
|
36
38
|
|
|
@@ -58,28 +60,34 @@ async function getWeb3WalletMethods({
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export async function getWalletMethods(chain: Chain) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
const { match, P } = await import("ts-pattern");
|
|
64
|
+
|
|
65
|
+
return match(chain)
|
|
66
|
+
.with(
|
|
67
|
+
P.union(
|
|
68
|
+
Chain.Ethereum,
|
|
69
|
+
Chain.Base,
|
|
70
|
+
Chain.Avalanche,
|
|
71
|
+
Chain.Arbitrum,
|
|
72
|
+
Chain.Optimism,
|
|
73
|
+
Chain.Polygon,
|
|
74
|
+
Chain.BinanceSmartChain,
|
|
75
|
+
),
|
|
76
|
+
async () => {
|
|
77
|
+
if (!(window.okxwallet && "send" in window.okxwallet)) {
|
|
78
|
+
throw new SwapKitError("wallet_okx_not_found", { chain });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const evmWallet = await getWeb3WalletMethods({
|
|
82
|
+
chain: chain as EVMChain,
|
|
83
|
+
walletProvider: window.okxwallet,
|
|
84
|
+
});
|
|
85
|
+
const address: string = (await window.okxwallet.send("eth_requestAccounts", [])).result[0];
|
|
86
|
+
|
|
87
|
+
return { ...evmWallet, address };
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
.with(Chain.Bitcoin, async () => {
|
|
83
91
|
if (!(window.okxwallet && "bitcoin" in window.okxwallet)) {
|
|
84
92
|
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Bitcoin });
|
|
85
93
|
}
|
|
@@ -101,12 +109,11 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
101
109
|
getAddress: async () => Promise.resolve(address),
|
|
102
110
|
};
|
|
103
111
|
|
|
104
|
-
const toolbox = await getUtxoToolbox(
|
|
112
|
+
const toolbox = await getUtxoToolbox(Chain.Bitcoin, { signer });
|
|
105
113
|
|
|
106
114
|
return { ...toolbox, address };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
case Chain.Cosmos: {
|
|
115
|
+
})
|
|
116
|
+
.with(Chain.Cosmos, async () => {
|
|
110
117
|
if (!(window.okxwallet && "keplr" in window.okxwallet)) {
|
|
111
118
|
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Cosmos });
|
|
112
119
|
}
|
|
@@ -120,10 +127,9 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
120
127
|
const [{ address }] = accounts;
|
|
121
128
|
const toolbox = getCosmosToolbox(Chain.Cosmos);
|
|
122
129
|
|
|
123
|
-
return { ...toolbox, address, transfer: cosmosTransfer() };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
case Chain.Near: {
|
|
130
|
+
return { ...toolbox, address, transfer: cosmosTransfer(address) };
|
|
131
|
+
})
|
|
132
|
+
.with(Chain.Near, async () => {
|
|
127
133
|
if (!(window.okxwallet && "near" in window.okxwallet)) {
|
|
128
134
|
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Near });
|
|
129
135
|
}
|
|
@@ -137,9 +143,36 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
137
143
|
const toolbox = await getNearToolbox({ signer });
|
|
138
144
|
|
|
139
145
|
return { ...toolbox, address: accountId };
|
|
140
|
-
}
|
|
146
|
+
})
|
|
147
|
+
.with(Chain.Tron, async () => {
|
|
148
|
+
if (!(window.okxwallet && "tronLink" in window.okxwallet)) {
|
|
149
|
+
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Tron });
|
|
150
|
+
}
|
|
141
151
|
|
|
142
|
-
|
|
152
|
+
const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
|
|
153
|
+
|
|
154
|
+
const tronLink = window.okxwallet.tronLink;
|
|
155
|
+
|
|
156
|
+
// Request account access
|
|
157
|
+
const accounts = await tronLink.request({ method: "tron_requestAccounts" });
|
|
158
|
+
if (!accounts || accounts.length === 0) {
|
|
159
|
+
throw new SwapKitError("wallet_okx_no_accounts", { chain: Chain.Tron });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const address = tronLink.tronWeb.defaultAddress.base58;
|
|
163
|
+
|
|
164
|
+
const signer: TronSigner = {
|
|
165
|
+
getAddress: async () => address,
|
|
166
|
+
signTransaction: async (transaction: TronTransaction) => {
|
|
167
|
+
return await tronLink.tronWeb.trx.sign(transaction);
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const toolbox = await createTronToolbox({ signer });
|
|
172
|
+
|
|
173
|
+
return { ...toolbox, address };
|
|
174
|
+
})
|
|
175
|
+
.otherwise(() => {
|
|
143
176
|
throw new SwapKitError("wallet_okx_chain_not_supported", { chain });
|
|
144
|
-
|
|
177
|
+
});
|
|
145
178
|
}
|
package/src/okx/index.ts
CHANGED
package/src/onekey/index.ts
CHANGED
|
@@ -56,8 +56,8 @@ async function getWalletMethodsForExtension(chain: Chain) {
|
|
|
56
56
|
|
|
57
57
|
await getAddress(getAddressOptions);
|
|
58
58
|
|
|
59
|
-
async function signTransaction(psbt:
|
|
60
|
-
let signedPsbt:
|
|
59
|
+
async function signTransaction(psbt: Psbt) {
|
|
60
|
+
let signedPsbt: Psbt | undefined;
|
|
61
61
|
const signPsbtOptions: SignTransactionOptions = {
|
|
62
62
|
getProvider,
|
|
63
63
|
payload: {
|
package/src/trezor/index.ts
CHANGED
|
@@ -112,16 +112,7 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
112
112
|
amount: value,
|
|
113
113
|
script_type: scriptType.input,
|
|
114
114
|
})),
|
|
115
|
-
|
|
116
|
-
// Lint is not happy with the type of txOutputs
|
|
117
|
-
outputs: psbt.txOutputs.map((output: any) => {
|
|
118
|
-
const outputAddress =
|
|
119
|
-
chain === Chain.BitcoinCash && output.address
|
|
120
|
-
? toolbox.stripPrefix(toCashAddress(output.address))
|
|
121
|
-
: output.address;
|
|
122
|
-
|
|
123
|
-
const isChangeAddress = outputAddress === address;
|
|
124
|
-
|
|
115
|
+
outputs: psbt.txOutputs.map((output) => {
|
|
125
116
|
// OP_RETURN
|
|
126
117
|
if (!output.address) {
|
|
127
118
|
return {
|
|
@@ -131,6 +122,13 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
131
122
|
};
|
|
132
123
|
}
|
|
133
124
|
|
|
125
|
+
const outputAddress =
|
|
126
|
+
chain === Chain.BitcoinCash
|
|
127
|
+
? toolbox.stripPrefix(toCashAddress(output.address))
|
|
128
|
+
: output.address;
|
|
129
|
+
|
|
130
|
+
const isChangeAddress = outputAddress === address;
|
|
131
|
+
|
|
134
132
|
return isChangeAddress
|
|
135
133
|
? { amount: output.value, address_n, script_type: scriptType.output }
|
|
136
134
|
: { amount: output.value, address: outputAddress, script_type: "PAYTOADDRESS" };
|
package/src/types.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type { radixWallet } from "./radix";
|
|
|
30
30
|
import type { talismanWallet } from "./talisman";
|
|
31
31
|
import type { trezorWallet } from "./trezor";
|
|
32
32
|
import type { walletconnectWallet } from "./walletconnect";
|
|
33
|
+
import type { xamanWallet } from "./xaman";
|
|
33
34
|
|
|
34
35
|
export type SKWallets = {
|
|
35
36
|
[WalletOption.BITGET]: typeof bitgetWallet;
|
|
@@ -58,6 +59,7 @@ export type SKWallets = {
|
|
|
58
59
|
[WalletOption.TREZOR]: typeof trezorWallet;
|
|
59
60
|
[WalletOption.TRUSTWALLET_WEB]: typeof evmWallet;
|
|
60
61
|
[WalletOption.WALLETCONNECT]: typeof walletconnectWallet;
|
|
62
|
+
[WalletOption.XAMAN]: typeof xamanWallet;
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
export type SKConnectWallets = SKWallets[keyof SKWallets];
|
|
@@ -89,6 +91,7 @@ export type SKWalletsSupportedChains = {
|
|
|
89
91
|
[WalletOption.TREZOR]: typeof trezorWallet.connectTrezor.supportedChains;
|
|
90
92
|
[WalletOption.TRUSTWALLET_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
|
|
91
93
|
[WalletOption.WALLETCONNECT]: typeof walletconnectWallet.connectWalletconnect.supportedChains;
|
|
94
|
+
[WalletOption.XAMAN]: typeof xamanWallet.connectXaman.supportedChains;
|
|
92
95
|
};
|
|
93
96
|
|
|
94
97
|
type UnisatToSignInputs = {
|
|
@@ -161,6 +164,22 @@ declare global {
|
|
|
161
164
|
};
|
|
162
165
|
solana: SolanaProvider;
|
|
163
166
|
ethereum: EthereumWindowProvider;
|
|
167
|
+
tronLink: {
|
|
168
|
+
request: (args: { method: string; params?: any }) => Promise<any>;
|
|
169
|
+
ready: boolean;
|
|
170
|
+
};
|
|
171
|
+
tronWeb: {
|
|
172
|
+
defaultAddress: {
|
|
173
|
+
base58: string;
|
|
174
|
+
hex: string;
|
|
175
|
+
};
|
|
176
|
+
trx: {
|
|
177
|
+
sign: (transaction: any) => Promise<any>;
|
|
178
|
+
sendRawTransaction: (signedTransaction: any) => Promise<any>;
|
|
179
|
+
getAccount: (address: string) => Promise<any>;
|
|
180
|
+
getBalance: (address: string) => Promise<number>;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
164
183
|
};
|
|
165
184
|
|
|
166
185
|
okxwallet?:
|
|
@@ -207,6 +226,22 @@ declare global {
|
|
|
207
226
|
transactions: any[];
|
|
208
227
|
}) => Promise<any>;
|
|
209
228
|
};
|
|
229
|
+
tronLink: {
|
|
230
|
+
request: (args: { method: string; params?: any }) => Promise<any>;
|
|
231
|
+
ready: boolean;
|
|
232
|
+
tronWeb: {
|
|
233
|
+
defaultAddress: {
|
|
234
|
+
base58: string;
|
|
235
|
+
hex: string;
|
|
236
|
+
};
|
|
237
|
+
trx: {
|
|
238
|
+
sign: (transaction: any) => Promise<any>;
|
|
239
|
+
sendRawTransaction: (signedTransaction: any) => Promise<any>;
|
|
240
|
+
getAccount: (address: string) => Promise<any>;
|
|
241
|
+
getBalance: (address: string) => Promise<number>;
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
};
|
|
210
245
|
}
|
|
211
246
|
| EthereumWindowProvider;
|
|
212
247
|
}
|
package/src/utils.ts
CHANGED
|
@@ -52,6 +52,7 @@ export async function loadWallet<W extends WalletOption>(walletOption: W): Promi
|
|
|
52
52
|
.with(WalletOption.POLKADOT_JS, async () => (await import("./polkadotjs")).polkadotWallet)
|
|
53
53
|
.with(WalletOption.RADIX_WALLET, async () => (await import("./radix")).radixWallet)
|
|
54
54
|
.with(WalletOption.TALISMAN, async () => (await import("./talisman")).talismanWallet)
|
|
55
|
+
.with(WalletOption.XAMAN, async () => (await import("./xaman")).xamanWallet)
|
|
55
56
|
.exhaustive();
|
|
56
57
|
|
|
57
58
|
return wallet as SKWallets[W];
|
|
@@ -15,14 +15,17 @@ export const POLYGON_MAINNET_ID = "eip155:137";
|
|
|
15
15
|
export const BASE_MAINNET_ID = "eip155:8453";
|
|
16
16
|
export const NEAR_MAINNET_ID = "near:mainnet";
|
|
17
17
|
export const NEAR_TESTNET_ID = "near:testnet";
|
|
18
|
+
export const TRON_MAINNET_ID = "tron:0x2b6653dc";
|
|
18
19
|
|
|
19
20
|
export const DEFAULT_LOGGER = "debug";
|
|
20
21
|
|
|
21
22
|
export const DEFAULT_APP_METADATA: ClientMetadata = {
|
|
22
|
-
name: "
|
|
23
|
-
description: "
|
|
24
|
-
url: "https://
|
|
25
|
-
icons: [
|
|
23
|
+
name: "SwapKit",
|
|
24
|
+
description: "SwapKit cross-chain SDK",
|
|
25
|
+
url: "https://swapkit.dev/",
|
|
26
|
+
icons: [
|
|
27
|
+
"https://raw.githubusercontent.com/swapkit/SwapKit/refs/heads/develop/docs/src/assets/logo-black.png",
|
|
28
|
+
],
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -85,3 +88,15 @@ export enum DEFAULT_NEAR_METHODS {
|
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
export enum DEFAULT_NEAR_EVENTS {}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* TRON
|
|
94
|
+
*/
|
|
95
|
+
export enum DEFAULT_TRON_METHODS {
|
|
96
|
+
TRON_SIGN_MESSAGE = "tron_signMessage",
|
|
97
|
+
TRON_SIGN_TRANSACTION = "tron_signTransaction",
|
|
98
|
+
TRON_SEND_TRANSACTION = "tron_sendTransaction",
|
|
99
|
+
TRON_GET_ACCOUNTS = "tron_getAccounts",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export enum DEFAULT_TRON_EVENTS {}
|