@swapkit/wallets 4.0.0-beta.39 → 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 (103) hide show
  1. package/dist/{chunk-qh8q7xr1.js → chunk-10h87ecy.js} +3 -3
  2. package/dist/{chunk-qh8q7xr1.js.map → chunk-10h87ecy.js.map} +1 -1
  3. package/dist/chunk-3t5jkca2.js +5 -0
  4. package/dist/chunk-3t5jkca2.js.map +10 -0
  5. package/dist/{chunk-c11abmv4.js → chunk-3vygfd50.js} +4 -4
  6. package/dist/{chunk-c11abmv4.js.map → chunk-3vygfd50.js.map} +3 -3
  7. package/dist/{chunk-0rgqnhd7.js → chunk-940zcsgd.js} +3 -3
  8. package/dist/{chunk-0rgqnhd7.js.map → chunk-940zcsgd.js.map} +3 -3
  9. package/dist/{chunk-hafkx3bw.js → chunk-bnnq9hg1.js} +3 -3
  10. package/dist/{chunk-hafkx3bw.js.map → chunk-bnnq9hg1.js.map} +1 -1
  11. package/dist/{chunk-5mq0kpmy.js → chunk-bp34qnvm.js} +3 -3
  12. package/dist/{chunk-5mq0kpmy.js.map → chunk-bp34qnvm.js.map} +1 -1
  13. package/dist/{chunk-r308an05.js → chunk-fa0psb24.js} +3 -3
  14. package/dist/{chunk-r308an05.js.map → chunk-fa0psb24.js.map} +1 -1
  15. package/dist/chunk-kfw1mys1.js +4 -0
  16. package/dist/chunk-kfw1mys1.js.map +10 -0
  17. package/dist/{chunk-cgt2fexr.js → chunk-xwda1ncj.js} +3 -3
  18. package/dist/{chunk-cgt2fexr.js.map → chunk-xwda1ncj.js.map} +1 -1
  19. package/dist/src/bitget/index.cjs +2 -2
  20. package/dist/src/bitget/index.cjs.map +4 -4
  21. package/dist/src/bitget/index.js +2 -2
  22. package/dist/src/bitget/index.js.map +4 -4
  23. package/dist/src/coinbase/index.js +2 -2
  24. package/dist/src/coinbase/index.js.map +1 -1
  25. package/dist/src/cosmostation/index.js +2 -2
  26. package/dist/src/cosmostation/index.js.map +1 -1
  27. package/dist/src/ctrl/index.js +2 -2
  28. package/dist/src/ctrl/index.js.map +1 -1
  29. package/dist/src/evm-extensions/index.js +2 -2
  30. package/dist/src/evm-extensions/index.js.map +1 -1
  31. package/dist/src/exodus/index.js +2 -2
  32. package/dist/src/exodus/index.js.map +1 -1
  33. package/dist/src/index.cjs +2 -2
  34. package/dist/src/index.cjs.map +1 -1
  35. package/dist/src/index.js +2 -2
  36. package/dist/src/index.js.map +1 -1
  37. package/dist/src/keepkey/index.js +2 -2
  38. package/dist/src/keepkey/index.js.map +2 -2
  39. package/dist/src/keepkey-bex/index.js +2 -2
  40. package/dist/src/keepkey-bex/index.js.map +1 -1
  41. package/dist/src/keplr/index.js +2 -2
  42. package/dist/src/keplr/index.js.map +1 -1
  43. package/dist/src/keystore/index.js +2 -2
  44. package/dist/src/keystore/index.js.map +1 -1
  45. package/dist/src/ledger/index.cjs +3 -3
  46. package/dist/src/ledger/index.cjs.map +7 -6
  47. package/dist/src/ledger/index.js +3 -3
  48. package/dist/src/ledger/index.js.map +7 -6
  49. package/dist/src/okx/index.cjs +2 -2
  50. package/dist/src/okx/index.cjs.map +4 -4
  51. package/dist/src/okx/index.js +2 -2
  52. package/dist/src/okx/index.js.map +4 -4
  53. package/dist/src/onekey/index.cjs +2 -2
  54. package/dist/src/onekey/index.cjs.map +3 -3
  55. package/dist/src/onekey/index.js +2 -2
  56. package/dist/src/onekey/index.js.map +3 -3
  57. package/dist/src/phantom/index.js +2 -2
  58. package/dist/src/phantom/index.js.map +1 -1
  59. package/dist/src/polkadotjs/index.js +2 -2
  60. package/dist/src/polkadotjs/index.js.map +1 -1
  61. package/dist/src/radix/index.js +2 -2
  62. package/dist/src/radix/index.js.map +1 -1
  63. package/dist/src/talisman/index.js +2 -2
  64. package/dist/src/talisman/index.js.map +1 -1
  65. package/dist/src/trezor/index.cjs +2 -2
  66. package/dist/src/trezor/index.cjs.map +3 -3
  67. package/dist/src/trezor/index.js +2 -2
  68. package/dist/src/trezor/index.js.map +3 -3
  69. package/dist/src/walletconnect/index.cjs +2 -2
  70. package/dist/src/walletconnect/index.cjs.map +5 -5
  71. package/dist/src/walletconnect/index.js +2 -2
  72. package/dist/src/walletconnect/index.js.map +5 -5
  73. package/dist/src/xaman/index.cjs +4 -0
  74. package/dist/src/xaman/index.cjs.map +12 -0
  75. package/dist/src/xaman/index.js +4 -0
  76. package/dist/src/xaman/index.js.map +12 -0
  77. package/package.json +14 -6
  78. package/src/bitget/helpers.ts +65 -30
  79. package/src/bitget/index.ts +1 -1
  80. package/src/ledger/clients/tron.ts +92 -0
  81. package/src/ledger/helpers/getLedgerAddress.ts +5 -0
  82. package/src/ledger/helpers/getLedgerClient.ts +3 -0
  83. package/src/ledger/index.ts +10 -0
  84. package/src/ledger/types.ts +2 -0
  85. package/src/okx/helpers.ts +71 -38
  86. package/src/okx/index.ts +1 -0
  87. package/src/onekey/index.ts +2 -2
  88. package/src/trezor/index.ts +8 -10
  89. package/src/types.ts +35 -0
  90. package/src/utils.ts +1 -0
  91. package/src/walletconnect/constants.ts +13 -0
  92. package/src/walletconnect/helpers.ts +11 -1
  93. package/src/walletconnect/index.ts +34 -0
  94. package/src/walletconnect/namespaces.ts +6 -0
  95. package/src/xaman/README.md +66 -0
  96. package/src/xaman/helpers.ts +59 -0
  97. package/src/xaman/index.ts +79 -0
  98. package/src/xaman/types.ts +26 -0
  99. package/src/xaman/walletMethods.ts +126 -0
  100. package/dist/chunk-9sjqewve.js +0 -5
  101. package/dist/chunk-9sjqewve.js.map +0 -10
  102. package/dist/chunk-sn6pgje5.js +0 -4
  103. package/dist/chunk-sn6pgje5.js.map +0 -10
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/xaman/index.ts", "../src/xaman/helpers.ts", "../src/xaman/walletMethods.ts"],
4
+ "sourcesContent": [
5
+ "import {\n Chain,\n SKConfig,\n SwapKitError,\n WalletOption,\n createWallet,\n filterSupportedChains,\n} from \"@swapkit/helpers\";\nimport { Xumm } from \"xumm\";\nimport { getWalletSupportedChains } from \"../utils\";\nimport { getWalletForChain } from \"./helpers.js\";\nimport type { XamanConfig } from \"./types.js\";\nimport { connectXamanWallet as connectXamanWalletMethod } from \"./walletMethods.js\";\n\nexport const xamanWallet = createWallet({\n name: \"connectXaman\",\n walletType: WalletOption.XAMAN,\n supportedChains: [Chain.Ripple],\n connect: ({ addChain, supportedChains: walletSupportedChains, walletType }) =>\n async function connectXamanWallet(chains: Chain[], xamanConfigOverwrite?: XamanConfig) {\n const supportedChains = filterSupportedChains({\n chains,\n supportedChains: walletSupportedChains,\n walletType,\n });\n\n const { xaman: xamanApiKey } = SKConfig.get(\"apiKeys\");\n const apiKey = xamanConfigOverwrite?.apiKey || xamanApiKey;\n\n if (!apiKey) {\n throw new SwapKitError(\"wallet_missing_api_key\", { wallet: \"Xaman\" });\n }\n\n const xumm = new Xumm(apiKey);\n\n return new Promise<boolean>((resolve, reject) => {\n xumm.on(\"success\", async () => {\n try {\n const address = await connectXamanWalletMethod(xumm);\n\n const promises = supportedChains.map(async (chain) => {\n const rpcUrl = SKConfig.get(\"rpcUrls\")[chain];\n const walletMethods = await getWalletForChain({\n xumm,\n chain,\n address,\n rpcUrl,\n });\n\n addChain({\n ...walletMethods,\n chain,\n balance: [],\n walletType: WalletOption.XAMAN,\n address,\n disconnect: xumm.logout,\n });\n });\n\n await Promise.all(promises);\n resolve(true);\n } catch (error) {\n reject(error);\n }\n });\n\n xumm.on(\"error\", (error) => {\n reject(error);\n });\n\n xumm.authorize();\n });\n },\n});\n\nexport const XAMAN_SUPPORTED_CHAINS = getWalletSupportedChains(xamanWallet);\nexport type XamanSupportedChain = (typeof XAMAN_SUPPORTED_CHAINS)[number];\n\nexport type { XamanConfig } from \"./types.js\";\n",
6
+ "import { type AssetValue, Chain, SwapKitError } from \"@swapkit/helpers\";\nimport type { Xumm } from \"xumm\";\nimport { sendXamanTransaction } from \"./walletMethods.js\";\n\ninterface GetWalletForChainParams {\n chain: Chain;\n address: string;\n rpcUrl?: string;\n xumm: Xumm;\n}\n\nexport async function getWalletForChain({ xumm, chain, address, rpcUrl }: GetWalletForChainParams) {\n switch (chain) {\n case Chain.Ripple: {\n const { getRippleToolbox } = await import(\"@swapkit/toolboxes/ripple\");\n\n // const api = apis?.[chain]; // Unused for now\n const toolbox = await getRippleToolbox({ rpcUrl });\n\n // Override transfer method to use Xaman transaction flow\n const transfer = async (params: {\n assetValue: AssetValue;\n recipient: string;\n memo?: string;\n }) => {\n const { recipient, assetValue, memo } = params;\n\n // Create and subscribe to payment via Xaman\n const paymentResult = await sendXamanTransaction(xumm, {\n from: address,\n destination: recipient,\n amount: assetValue.getValue(\"string\"),\n memo: memo,\n });\n\n // If not successful or no transaction ID, throw error\n if (!(paymentResult.result.success && paymentResult.result.transactionId)) {\n throw new SwapKitError(\"wallet_xaman_transaction_failed\");\n }\n\n // Return the transaction ID string\n return paymentResult.result.transactionId;\n };\n\n return {\n ...toolbox,\n address,\n getAddress: () => address,\n transfer,\n // Expose Xaman-specific methods\n createAndSubscribePayment: sendXamanTransaction,\n disconnect: xumm.logout,\n };\n }\n\n default:\n throw new SwapKitError(\"wallet_chain_not_supported\", { wallet: \"Xaman\", chain });\n }\n}\n",
7
+ "import { SwapKitError } from \"@swapkit/helpers\";\nimport type { Xumm } from \"xumm\";\nimport type { XamanPaymentParams } from \"./types.js\";\n\nexport const connectXamanWallet = async (xumm: Xumm) => {\n if (!xumm) {\n throw new SwapKitError(\"wallet_xaman_not_configured\");\n }\n\n try {\n const user = await xumm.user;\n const account = await user?.account;\n\n if (account) {\n return account;\n }\n\n throw new SwapKitError(\"wallet_xaman_auth_failed\");\n } catch (error) {\n console.error(\"Xaman wallet connection failed:\", error);\n throw new SwapKitError(\"wallet_xaman_connection_failed\");\n }\n};\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: might need refactoring later\nexport const sendXamanTransaction = async (xumm: Xumm, params: XamanPaymentParams) => {\n try {\n // Validate required parameters\n if (!(params.destination && params.amount && params.from)) {\n throw new SwapKitError(\"wallet_xaman_connection_failed\");\n }\n\n // Convert XRP to drops (1 XRP = 1,000,000 drops)\n const amountInDrops = (Number.parseFloat(params.amount) * 1000000).toString();\n\n // Create transaction object\n const transaction = {\n TransactionType: \"Payment\" as const,\n Destination: params.destination,\n Amount: amountInDrops,\n Account: params.from,\n ...(params.destinationTag !== undefined && {\n DestinationTag: params.destinationTag,\n }),\n ...(params.memo && {\n Memos: [\n {\n Memo: {\n MemoData: Buffer.from(params.memo, \"utf8\").toString(\"hex\").toUpperCase(),\n },\n },\n ],\n }),\n };\n\n // Create and subscribe to payload following the official example\n const subscription = await xumm.payload?.createAndSubscribe(transaction, (event) => {\n if (\"signed\" in event.data) {\n // Return event.data to close subscription and resolve promise\n return event.data; // { signed: true|false, payload_uuidv4: '...' }\n }\n return undefined;\n });\n\n if (!subscription) {\n throw new SwapKitError(\"wallet_xaman_transaction_failed\");\n }\n\n const { created } = subscription;\n\n // Handle payload presentation based on runtime environment\n if (xumm.runtime?.xapp) {\n xumm.xapp?.openSignRequest(created);\n } else if (typeof window !== \"undefined\") {\n const url =\n created.pushed && created.next?.no_push_msg_received\n ? created.next.no_push_msg_received\n : created.next?.always;\n if (url) window.open(url);\n }\n\n // Wait until the user signed/rejected\n const resolved = await subscription.resolved;\n\n if (!resolved || typeof resolved !== \"object\" || !(\"signed\" in resolved) || !resolved.signed) {\n throw new SwapKitError(\"wallet_xaman_transaction_failed\");\n }\n\n // Fetch the full payload result using the UUID from resolved data\n const payloadDetails = await xumm.payload?.get((resolved as any).payload_uuidv4);\n\n if (!payloadDetails) {\n throw new SwapKitError(\"wallet_xaman_monitoring_failed\");\n }\n\n // Extract transaction ID from response\n const transactionId = payloadDetails.response?.txid || \"\";\n const account = payloadDetails.response?.account || \"\";\n\n if (!transactionId) {\n throw new SwapKitError(\"wallet_xaman_transaction_failed\");\n }\n\n // Return comprehensive result\n return {\n // Initial payload info for QR codes, deep links, etc.\n payloadId: created.uuid || \"\",\n qrCode: created.refs?.qr_png || \"\",\n deepLink: created.next?.always || \"\",\n websocketUrl: created.refs?.websocket_status || \"\",\n // Final transaction result - SUCCESS with tx hash\n result: {\n success: true,\n transactionId,\n account,\n reason: undefined,\n },\n };\n } catch (error) {\n console.error(\"Xaman payment creation and subscription failed:\", error);\n if (error instanceof SwapKitError) {\n throw error;\n }\n throw new SwapKitError(\"wallet_xaman_transaction_failed\");\n }\n};\n"
8
+ ],
9
+ "mappings": "iGAAA,cACE,cACA,kBACA,kBACA,kBACA,2BACA,yBAEF,eAAS,aCRT,gBAA0B,kBAAO,yBCAjC,uBAAS,yBAIF,IAAM,EAAqB,MAAO,IAAe,CACtD,IAAK,EACH,MAAM,IAAI,EAAa,6BAA6B,EAGtD,GAAI,CAEF,IAAM,EAAU,MADH,MAAM,EAAK,OACI,QAE5B,GAAI,EACF,OAAO,EAGT,MAAM,IAAI,EAAa,0BAA0B,EACjD,MAAO,EAAO,CAEd,MADA,QAAQ,MAAM,kCAAmC,CAAK,EAChD,IAAI,EAAa,gCAAgC,IAK9C,EAAuB,MAAO,EAAY,IAA+B,CACpF,GAAI,CAEF,KAAM,EAAO,aAAe,EAAO,QAAU,EAAO,MAClD,MAAM,IAAI,EAAa,gCAAgC,EAIzD,IAAM,GAAiB,OAAO,WAAW,EAAO,MAAM,EAAI,KAAS,SAAS,EAGtE,EAAc,CAClB,gBAAiB,UACjB,YAAa,EAAO,YACpB,OAAQ,EACR,QAAS,EAAO,QACZ,EAAO,iBAAmB,QAAa,CACzC,eAAgB,EAAO,cACzB,KACI,EAAO,MAAQ,CACjB,MAAO,CACL,CACE,KAAM,CACJ,SAAU,OAAO,KAAK,EAAO,KAAM,MAAM,EAAE,SAAS,KAAK,EAAE,YAAY,CACzE,CACF,CACF,CACF,CACF,EAGM,EAAe,MAAM,EAAK,SAAS,mBAAmB,EAAa,CAAC,IAAU,CAClF,GAAI,WAAY,EAAM,KAEpB,OAAO,EAA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B,EAAyB,CAAW",
10
+ "debugId": "C2B1DD7DD4B9F64064756E2164756E21",
11
+ "names": []
12
+ }
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.24",
27
- "@swapkit/toolboxes": "^4.0.0-beta.36",
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.24",
65
- "@swapkit/toolboxes": "4.0.0-beta.36",
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.39"
208
+ "version": "4.0.0-beta.40"
201
209
  }
@@ -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
- switch (chain) {
16
- case Chain.Ethereum:
17
- case Chain.Base:
18
- case Chain.Avalanche:
19
- case Chain.Arbitrum:
20
- case Chain.Optimism:
21
- case Chain.Polygon:
22
- case Chain.BinanceSmartChain: {
23
- if (!(bitget && "ethereum" in bitget)) {
24
- throw new SwapKitError("wallet_bitkeep_not_found");
25
- }
26
-
27
- const wallet = bitget.ethereum;
28
-
29
- const [address]: [string] = await wallet.send("eth_requestAccounts", []);
30
- const evmWallet = await getWeb3WalletMethods({ chain, walletProvider: wallet });
31
-
32
- return { ...evmWallet, address };
33
- }
34
-
35
- case Chain.Bitcoin: {
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
- default:
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 ({
@@ -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,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];
@@ -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
  }
@@ -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;
@@ -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" };