@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.
Files changed (129) hide show
  1. package/dist/chunk-10h87ecy.js +4 -0
  2. package/dist/chunk-10h87ecy.js.map +10 -0
  3. package/dist/chunk-2aa1w78q.js +1 -0
  4. package/dist/chunk-31bmhjxx.js +4 -0
  5. package/dist/chunk-31bmhjxx.js.map +10 -0
  6. package/dist/chunk-3t5jkca2.js +5 -0
  7. package/dist/chunk-3t5jkca2.js.map +10 -0
  8. package/dist/{chunk-th8ggrmx.js → chunk-3vygfd50.js} +4 -3
  9. package/dist/{chunk-th8ggrmx.js.map → chunk-3vygfd50.js.map} +3 -3
  10. package/dist/{chunk-yah6cf33.js → chunk-940zcsgd.js} +3 -2
  11. package/dist/{chunk-yah6cf33.js.map → chunk-940zcsgd.js.map} +3 -3
  12. package/dist/{chunk-dcj9twam.js → chunk-bnnq9hg1.js} +3 -2
  13. package/dist/{chunk-dcj9twam.js.map → chunk-bnnq9hg1.js.map} +1 -1
  14. package/dist/chunk-bp34qnvm.js +5 -0
  15. package/dist/chunk-bp34qnvm.js.map +10 -0
  16. package/dist/chunk-etm8zfkk.js +4 -0
  17. package/dist/chunk-etm8zfkk.js.map +10 -0
  18. package/dist/{chunk-qwd1kp32.js → chunk-fa0psb24.js} +3 -2
  19. package/dist/{chunk-qwd1kp32.js.map → chunk-fa0psb24.js.map} +1 -1
  20. package/dist/chunk-kfw1mys1.js +4 -0
  21. package/dist/chunk-kfw1mys1.js.map +10 -0
  22. package/dist/chunk-vb4wtm2w.js +1 -0
  23. package/dist/chunk-wfattb4a.js +1 -0
  24. package/dist/{chunk-0qaxr89s.js → chunk-xwda1ncj.js} +3 -2
  25. package/dist/{chunk-0qaxr89s.js.map → chunk-xwda1ncj.js.map} +1 -1
  26. package/dist/src/bitget/index.cjs +3 -2
  27. package/dist/src/bitget/index.cjs.map +4 -4
  28. package/dist/src/bitget/index.js +3 -2
  29. package/dist/src/bitget/index.js.map +4 -4
  30. package/dist/src/coinbase/index.cjs +1 -0
  31. package/dist/src/coinbase/index.js +3 -2
  32. package/dist/src/coinbase/index.js.map +1 -1
  33. package/dist/src/cosmostation/index.cjs +1 -0
  34. package/dist/src/cosmostation/index.js +3 -2
  35. package/dist/src/cosmostation/index.js.map +1 -1
  36. package/dist/src/ctrl/index.cjs +1 -0
  37. package/dist/src/ctrl/index.js +3 -2
  38. package/dist/src/ctrl/index.js.map +2 -2
  39. package/dist/src/evm-extensions/index.cjs +1 -0
  40. package/dist/src/evm-extensions/index.js +3 -2
  41. package/dist/src/evm-extensions/index.js.map +1 -1
  42. package/dist/src/exodus/index.cjs +1 -0
  43. package/dist/src/exodus/index.js +3 -2
  44. package/dist/src/exodus/index.js.map +1 -1
  45. package/dist/src/index.cjs +3 -2
  46. package/dist/src/index.cjs.map +1 -1
  47. package/dist/src/index.js +3 -2
  48. package/dist/src/index.js.map +1 -1
  49. package/dist/src/keepkey/index.cjs +3 -2
  50. package/dist/src/keepkey/index.cjs.map +4 -5
  51. package/dist/src/keepkey/index.js +3 -2
  52. package/dist/src/keepkey/index.js.map +4 -5
  53. package/dist/src/keepkey-bex/index.cjs +3 -2
  54. package/dist/src/keepkey-bex/index.cjs.map +3 -3
  55. package/dist/src/keepkey-bex/index.js +3 -2
  56. package/dist/src/keepkey-bex/index.js.map +3 -3
  57. package/dist/src/keplr/index.cjs +1 -0
  58. package/dist/src/keplr/index.js +3 -2
  59. package/dist/src/keplr/index.js.map +1 -1
  60. package/dist/src/keystore/index.cjs +1 -0
  61. package/dist/src/keystore/index.js +3 -2
  62. package/dist/src/keystore/index.js.map +1 -1
  63. package/dist/src/ledger/index.cjs +4 -3
  64. package/dist/src/ledger/index.cjs.map +7 -6
  65. package/dist/src/ledger/index.js +4 -3
  66. package/dist/src/ledger/index.js.map +7 -6
  67. package/dist/src/okx/index.cjs +3 -2
  68. package/dist/src/okx/index.cjs.map +4 -4
  69. package/dist/src/okx/index.js +3 -2
  70. package/dist/src/okx/index.js.map +4 -4
  71. package/dist/src/onekey/index.cjs +3 -2
  72. package/dist/src/onekey/index.cjs.map +3 -3
  73. package/dist/src/onekey/index.js +3 -2
  74. package/dist/src/onekey/index.js.map +3 -3
  75. package/dist/src/phantom/index.cjs +1 -0
  76. package/dist/src/phantom/index.js +3 -2
  77. package/dist/src/phantom/index.js.map +1 -1
  78. package/dist/src/polkadotjs/index.cjs +1 -0
  79. package/dist/src/polkadotjs/index.js +3 -2
  80. package/dist/src/polkadotjs/index.js.map +1 -1
  81. package/dist/src/radix/index.cjs +1 -0
  82. package/dist/src/radix/index.js +3 -2
  83. package/dist/src/radix/index.js.map +1 -1
  84. package/dist/src/talisman/index.cjs +1 -0
  85. package/dist/src/talisman/index.js +3 -2
  86. package/dist/src/talisman/index.js.map +1 -1
  87. package/dist/src/trezor/index.cjs +3 -2
  88. package/dist/src/trezor/index.cjs.map +3 -3
  89. package/dist/src/trezor/index.js +3 -2
  90. package/dist/src/trezor/index.js.map +3 -3
  91. package/dist/src/walletconnect/index.cjs +3 -2
  92. package/dist/src/walletconnect/index.cjs.map +5 -5
  93. package/dist/src/walletconnect/index.js +3 -2
  94. package/dist/src/walletconnect/index.js.map +5 -5
  95. package/dist/src/xaman/index.cjs +4 -0
  96. package/dist/src/xaman/index.cjs.map +12 -0
  97. package/dist/src/xaman/index.js +4 -0
  98. package/dist/src/xaman/index.js.map +12 -0
  99. package/package.json +14 -6
  100. package/src/bitget/helpers.ts +65 -30
  101. package/src/bitget/index.ts +1 -1
  102. package/src/keepkey/chains/ripple.ts +118 -0
  103. package/src/keepkey/coins.ts +1 -0
  104. package/src/keepkey/index.ts +5 -0
  105. package/src/keepkey-bex/index.ts +1 -0
  106. package/src/ledger/clients/tron.ts +92 -0
  107. package/src/ledger/helpers/getLedgerAddress.ts +5 -0
  108. package/src/ledger/helpers/getLedgerClient.ts +3 -0
  109. package/src/ledger/index.ts +10 -0
  110. package/src/ledger/types.ts +2 -0
  111. package/src/okx/helpers.ts +71 -38
  112. package/src/okx/index.ts +1 -0
  113. package/src/onekey/index.ts +2 -2
  114. package/src/trezor/index.ts +8 -10
  115. package/src/types.ts +35 -0
  116. package/src/utils.ts +1 -0
  117. package/src/walletconnect/constants.ts +13 -0
  118. package/src/walletconnect/helpers.ts +11 -1
  119. package/src/walletconnect/index.ts +34 -0
  120. package/src/walletconnect/namespaces.ts +6 -0
  121. package/src/xaman/README.md +66 -0
  122. package/src/xaman/helpers.ts +59 -0
  123. package/src/xaman/index.ts +79 -0
  124. package/src/xaman/types.ts +26 -0
  125. package/src/xaman/walletMethods.ts +126 -0
  126. package/dist/chunk-bexr8da2.js +0 -4
  127. package/dist/chunk-bexr8da2.js.map +0 -10
  128. package/dist/chunk-sn6pgje5.js +0 -3
  129. package/dist/chunk-sn6pgje5.js.map +0 -10
@@ -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 ({ from, recipient, amount, asset, memo }: any) => {
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: asset?.symbol === "MUON" ? "umuon" : "uatom",
29
- amount: amount.amount().toString(),
30
+ denom: assetValue?.symbol === "MUON" ? "umuon" : "uatom",
31
+ amount: assetValue.getBaseValue("string"),
30
32
  },
31
33
  ];
32
34
 
33
- const { transactionHash } = await cosmJS.sendTokens(from, recipient, coins, 1.6, memo);
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
- switch (chain) {
62
- case Chain.Ethereum:
63
- case Chain.Base:
64
- case Chain.Avalanche:
65
- case Chain.Arbitrum:
66
- case Chain.Optimism:
67
- case Chain.Polygon:
68
- case Chain.BinanceSmartChain: {
69
- if (!(window.okxwallet && "send" in window.okxwallet)) {
70
- throw new SwapKitError("wallet_okx_not_found", { chain });
71
- }
72
-
73
- const evmWallet = await getWeb3WalletMethods({
74
- chain,
75
- walletProvider: window.okxwallet,
76
- });
77
- const address: string = (await window.okxwallet.send("eth_requestAccounts", [])).result[0];
78
-
79
- return { ...evmWallet, address };
80
- }
81
-
82
- case Chain.Bitcoin: {
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(chain, { signer });
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
- default:
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
@@ -17,6 +17,7 @@ export const okxWallet = createWallet({
17
17
  Chain.Near,
18
18
  Chain.Optimism,
19
19
  Chain.Polygon,
20
+ Chain.Tron,
20
21
  ],
21
22
  connect: ({ addChain, supportedChains, walletType }) =>
22
23
  async function connectOkx(chains: Chain[]) {
@@ -56,8 +56,8 @@ async function getWalletMethodsForExtension(chain: Chain) {
56
56
 
57
57
  await getAddress(getAddressOptions);
58
58
 
59
- async function signTransaction(psbt: any) {
60
- let signedPsbt: any;
59
+ async function signTransaction(psbt: Psbt) {
60
+ let signedPsbt: Psbt | undefined;
61
61
  const signPsbtOptions: SignTransactionOptions = {
62
62
  getProvider,
63
63
  payload: {
@@ -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,6 +15,7 @@ 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
 
@@ -85,3 +86,15 @@ export enum DEFAULT_NEAR_METHODS {
85
86
  }
86
87
 
87
88
  export enum DEFAULT_NEAR_EVENTS {}
89
+
90
+ /**
91
+ * TRON
92
+ */
93
+ export enum DEFAULT_TRON_METHODS {
94
+ TRON_SIGN_MESSAGE = "tron_signMessage",
95
+ TRON_SIGN_TRANSACTION = "tron_signTransaction",
96
+ TRON_SEND_TRANSACTION = "tron_sendTransaction",
97
+ TRON_GET_ACCOUNTS = "tron_getAccounts",
98
+ }
99
+
100
+ export enum DEFAULT_TRON_EVENTS {}
@@ -14,10 +14,18 @@ import {
14
14
  OPTIMISM_MAINNET_ID,
15
15
  POLYGON_MAINNET_ID,
16
16
  THORCHAIN_MAINNET_ID,
17
+ TRON_MAINNET_ID,
17
18
  } from "./constants";
18
19
 
19
20
  export const getAddressByChain = (
20
- chain: EVMChain | Chain.THORChain | Chain.Maya | Chain.Kujira | Chain.Cosmos | Chain.Near,
21
+ chain:
22
+ | EVMChain
23
+ | Chain.THORChain
24
+ | Chain.Maya
25
+ | Chain.Kujira
26
+ | Chain.Cosmos
27
+ | Chain.Near
28
+ | Chain.Tron,
21
29
  accounts: string[],
22
30
  ) => {
23
31
  const account = accounts.find((account) => account.startsWith(chainToChainId(chain))) || "";
@@ -55,6 +63,8 @@ export const chainToChainId = (chain: Chain) => {
55
63
  const { isStagenet } = SKConfig.get("envs");
56
64
  return isStagenet ? NEAR_TESTNET_ID : NEAR_MAINNET_ID;
57
65
  }
66
+ case Chain.Tron:
67
+ return TRON_MAINNET_ID;
58
68
  default:
59
69
  return "";
60
70
  }
@@ -11,6 +11,7 @@ import {
11
11
  } from "@swapkit/helpers";
12
12
  import type { ThorchainDepositParams, createThorchainToolbox } from "@swapkit/toolboxes/cosmos";
13
13
  import type { NearSigner } from "@swapkit/toolboxes/near";
14
+ import type { TronSignedTransaction, TronSigner, TronTransaction } from "@swapkit/toolboxes/tron";
14
15
  import type { WalletConnectModal } from "@walletconnect/modal";
15
16
  import type { SessionTypes, SignClientTypes } from "@walletconnect/types";
16
17
  import type { Transaction } from "near-api-js/lib/transaction";
@@ -47,6 +48,7 @@ export const walletconnectWallet = createWallet({
47
48
  Chain.Optimism,
48
49
  Chain.Polygon,
49
50
  Chain.THORChain,
51
+ Chain.Tron,
50
52
  ],
51
53
  connect: ({ addChain, supportedChains, walletType }) =>
52
54
  async function connectWalletconnect(
@@ -315,6 +317,38 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
315
317
  return toolbox;
316
318
  }
317
319
 
320
+ case Chain.Tron: {
321
+ const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
322
+ const { DEFAULT_TRON_METHODS } = await import("./constants");
323
+
324
+ // Create a Tron signer that uses WalletConnect
325
+ const signer: TronSigner = {
326
+ getAddress() {
327
+ return Promise.resolve(address);
328
+ },
329
+
330
+ async signTransaction(transaction: TronTransaction) {
331
+ if (!walletconnect) {
332
+ throw new SwapKitError("wallet_walletconnect_connection_not_established");
333
+ }
334
+
335
+ const signedTx = await walletconnect.client.request({
336
+ topic: session.topic,
337
+ chainId: chainToChainId(Chain.Tron),
338
+ request: {
339
+ method: DEFAULT_TRON_METHODS.TRON_SIGN_TRANSACTION,
340
+ params: { transaction },
341
+ },
342
+ });
343
+
344
+ return signedTx as TronSignedTransaction;
345
+ },
346
+ };
347
+
348
+ const toolbox = await createTronToolbox({ signer });
349
+ return toolbox;
350
+ }
351
+
318
352
  default:
319
353
  throw new SwapKitError({
320
354
  errorKey: "wallet_chain_not_supported",
@@ -11,6 +11,8 @@ import {
11
11
  DEFAULT_POLKADOT_METHODS,
12
12
  DEFAULT_SOLANA_EVENTS,
13
13
  DEFAULT_SOLANA_METHODS,
14
+ DEFAULT_TRON_EVENTS,
15
+ DEFAULT_TRON_METHODS,
14
16
  } from "./constants";
15
17
 
16
18
  export const getNamespacesFromChains = (chains: string[]) => {
@@ -37,6 +39,8 @@ export const getSupportedMethodsByNamespace = (namespace: string) => {
37
39
  return Object.values(DEFAULT_POLKADOT_METHODS);
38
40
  case "near":
39
41
  return Object.values(DEFAULT_NEAR_METHODS);
42
+ case "tron":
43
+ return Object.values(DEFAULT_TRON_METHODS);
40
44
  default:
41
45
  throw new SwapKitError({
42
46
  errorKey: "wallet_walletconnect_namespace_not_supported",
@@ -57,6 +61,8 @@ export const getSupportedEventsByNamespace = (namespace: string) => {
57
61
  return Object.values(DEFAULT_POLKADOT_EVENTS);
58
62
  case "near":
59
63
  return Object.values(DEFAULT_NEAR_EVENTS);
64
+ case "tron":
65
+ return Object.values(DEFAULT_TRON_EVENTS);
60
66
  default:
61
67
  throw new SwapKitError({
62
68
  errorKey: "wallet_walletconnect_namespace_not_supported",
@@ -0,0 +1,66 @@
1
+ # Xaman Wallet Integration
2
+
3
+ ## Configuration
4
+
5
+ ### Option 1: Configure via SKConfig (Recommended)
6
+
7
+ ```typescript
8
+ import { SwapKit } from "@swapkit/core";
9
+ import { SKConfig } from "@swapkit/helpers";
10
+
11
+ // Set the Xaman API key globally
12
+ SKConfig.setApiKey("xaman", "your-xaman-api-key");
13
+
14
+ // Or configure during SwapKit initialization
15
+ const swapKit = SwapKit({
16
+ config: {
17
+ apiKeys: {
18
+ xaman: "your-xaman-api-key"
19
+ }
20
+ }
21
+ });
22
+
23
+ // Connect to Xaman wallet
24
+ await swapKit.connectWallet(WalletOption.XAMAN, [Chain.Ripple]);
25
+ ```
26
+
27
+ ### Option 2: Pass API key during connection
28
+
29
+ ```typescript
30
+ // Connect with API key override
31
+ await swapKit.connectWallet(WalletOption.XAMAN, [Chain.Ripple], {
32
+ apiKey: "your-xaman-api-key"
33
+ });
34
+ ```
35
+
36
+ ## Usage Example
37
+
38
+ ```typescript
39
+ // Get the connected wallet
40
+ const wallet = swapKit.getWallet(Chain.Ripple);
41
+
42
+ // Send XRP
43
+ const txHash = await wallet.transfer({
44
+ assetValue: AssetValue.from({ chain: Chain.Ripple, value: 1 }),
45
+ recipient: "rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH",
46
+ memo: "Payment memo"
47
+ });
48
+ ```
49
+
50
+ ## Destination Tags
51
+
52
+ For exchange addresses that require destination tags:
53
+
54
+ ```typescript
55
+ // The destination tag should be included in the memo field
56
+ // Format: "DestinationTag:123456"
57
+ const txHash = await wallet.transfer({
58
+ assetValue: AssetValue.from({ chain: Chain.Ripple, value: 10 }),
59
+ recipient: "rExchangeAddress...",
60
+ memo: "DestinationTag:123456"
61
+ });
62
+ ```
63
+
64
+ ## Getting an API Key
65
+
66
+ To use the Xaman wallet, you need to obtain an API key from the [Xaman Developer Console](https://apps.xumm.dev/).
@@ -0,0 +1,59 @@
1
+ import { type AssetValue, Chain, SwapKitError } from "@swapkit/helpers";
2
+ import type { Xumm } from "xumm";
3
+ import { sendXamanTransaction } from "./walletMethods.js";
4
+
5
+ interface GetWalletForChainParams {
6
+ chain: Chain;
7
+ address: string;
8
+ rpcUrl?: string;
9
+ xumm: Xumm;
10
+ }
11
+
12
+ export async function getWalletForChain({ xumm, chain, address, rpcUrl }: GetWalletForChainParams) {
13
+ switch (chain) {
14
+ case Chain.Ripple: {
15
+ const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
16
+
17
+ // const api = apis?.[chain]; // Unused for now
18
+ const toolbox = await getRippleToolbox({ rpcUrl });
19
+
20
+ // Override transfer method to use Xaman transaction flow
21
+ const transfer = async (params: {
22
+ assetValue: AssetValue;
23
+ recipient: string;
24
+ memo?: string;
25
+ }) => {
26
+ const { recipient, assetValue, memo } = params;
27
+
28
+ // Create and subscribe to payment via Xaman
29
+ const paymentResult = await sendXamanTransaction(xumm, {
30
+ from: address,
31
+ destination: recipient,
32
+ amount: assetValue.getValue("string"),
33
+ memo: memo,
34
+ });
35
+
36
+ // If not successful or no transaction ID, throw error
37
+ if (!(paymentResult.result.success && paymentResult.result.transactionId)) {
38
+ throw new SwapKitError("wallet_xaman_transaction_failed");
39
+ }
40
+
41
+ // Return the transaction ID string
42
+ return paymentResult.result.transactionId;
43
+ };
44
+
45
+ return {
46
+ ...toolbox,
47
+ address,
48
+ getAddress: () => address,
49
+ transfer,
50
+ // Expose Xaman-specific methods
51
+ createAndSubscribePayment: sendXamanTransaction,
52
+ disconnect: xumm.logout,
53
+ };
54
+ }
55
+
56
+ default:
57
+ throw new SwapKitError("wallet_chain_not_supported", { wallet: "Xaman", chain });
58
+ }
59
+ }
@@ -0,0 +1,79 @@
1
+ import {
2
+ Chain,
3
+ SKConfig,
4
+ SwapKitError,
5
+ WalletOption,
6
+ createWallet,
7
+ filterSupportedChains,
8
+ } from "@swapkit/helpers";
9
+ import { Xumm } from "xumm";
10
+ import { getWalletSupportedChains } from "../utils";
11
+ import { getWalletForChain } from "./helpers.js";
12
+ import type { XamanConfig } from "./types.js";
13
+ import { connectXamanWallet as connectXamanWalletMethod } from "./walletMethods.js";
14
+
15
+ export const xamanWallet = createWallet({
16
+ name: "connectXaman",
17
+ walletType: WalletOption.XAMAN,
18
+ supportedChains: [Chain.Ripple],
19
+ connect: ({ addChain, supportedChains: walletSupportedChains, walletType }) =>
20
+ async function connectXamanWallet(chains: Chain[], xamanConfigOverwrite?: XamanConfig) {
21
+ const supportedChains = filterSupportedChains({
22
+ chains,
23
+ supportedChains: walletSupportedChains,
24
+ walletType,
25
+ });
26
+
27
+ const { xaman: xamanApiKey } = SKConfig.get("apiKeys");
28
+ const apiKey = xamanConfigOverwrite?.apiKey || xamanApiKey;
29
+
30
+ if (!apiKey) {
31
+ throw new SwapKitError("wallet_missing_api_key", { wallet: "Xaman" });
32
+ }
33
+
34
+ const xumm = new Xumm(apiKey);
35
+
36
+ return new Promise<boolean>((resolve, reject) => {
37
+ xumm.on("success", async () => {
38
+ try {
39
+ const address = await connectXamanWalletMethod(xumm);
40
+
41
+ const promises = supportedChains.map(async (chain) => {
42
+ const rpcUrl = SKConfig.get("rpcUrls")[chain];
43
+ const walletMethods = await getWalletForChain({
44
+ xumm,
45
+ chain,
46
+ address,
47
+ rpcUrl,
48
+ });
49
+
50
+ addChain({
51
+ ...walletMethods,
52
+ chain,
53
+ balance: [],
54
+ walletType: WalletOption.XAMAN,
55
+ address,
56
+ disconnect: xumm.logout,
57
+ });
58
+ });
59
+
60
+ await Promise.all(promises);
61
+ resolve(true);
62
+ } catch (error) {
63
+ reject(error);
64
+ }
65
+ });
66
+
67
+ xumm.on("error", (error) => {
68
+ reject(error);
69
+ });
70
+
71
+ xumm.authorize();
72
+ });
73
+ },
74
+ });
75
+
76
+ export const XAMAN_SUPPORTED_CHAINS = getWalletSupportedChains(xamanWallet);
77
+ export type XamanSupportedChain = (typeof XAMAN_SUPPORTED_CHAINS)[number];
78
+
79
+ export type { XamanConfig } from "./types.js";
@@ -0,0 +1,26 @@
1
+ export interface XamanConfig {
2
+ apiKey: string;
3
+ }
4
+
5
+ export interface XamanPaymentParams {
6
+ destination: string;
7
+ from: string;
8
+ amount: string;
9
+ memo?: string;
10
+ destinationTag?: number;
11
+ }
12
+
13
+ export interface XamanPaymentResult {
14
+ payloadId: string;
15
+ qrCode: string;
16
+ deepLink: string;
17
+ websocketUrl: string;
18
+ result: XamanTransactionResult;
19
+ }
20
+
21
+ export interface XamanTransactionResult {
22
+ success: boolean;
23
+ transactionId?: string;
24
+ account?: string;
25
+ reason?: string;
26
+ }