@swapkit/wallets 3.0.0-beta.17 → 3.0.0-beta.19

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 (51) hide show
  1. package/dist/{chunk-p1kdg37m.js → chunk-38ztynv0.js} +1 -1
  2. package/dist/{chunk-p1kdg37m.js.map → chunk-38ztynv0.js.map} +1 -1
  3. package/dist/chunk-4ef2xs46.js +3 -0
  4. package/dist/chunk-4ef2xs46.js.map +10 -0
  5. package/dist/{chunk-ta4bdjpy.js → chunk-qgv1myym.js} +1 -1
  6. package/dist/chunk-s6xqbsy0.js +4 -0
  7. package/dist/{chunk-wja505db.js.map → chunk-s6xqbsy0.js.map} +3 -3
  8. package/dist/{chunk-ndpqxys9.js → chunk-sygzrjje.js} +2 -2
  9. package/dist/{chunk-ndpqxys9.js.map → chunk-sygzrjje.js.map} +3 -3
  10. package/dist/chunk-y0g3prs9.js +3 -0
  11. package/dist/chunk-y0g3prs9.js.map +10 -0
  12. package/dist/src/bitget/index.js +1 -1
  13. package/dist/src/coinbase/index.js +1 -1
  14. package/dist/src/ctrl/index.cjs +2 -2
  15. package/dist/src/ctrl/index.cjs.map +3 -3
  16. package/dist/src/ctrl/index.js +2 -2
  17. package/dist/src/ctrl/index.js.map +3 -3
  18. package/dist/src/evm-extensions/index.js +1 -1
  19. package/dist/src/exodus/index.js +1 -1
  20. package/dist/src/index.js +1 -1
  21. package/dist/src/keepkey/index.js +1 -1
  22. package/dist/src/keepkey-bex/index.js +1 -1
  23. package/dist/src/keplr/index.js +1 -1
  24. package/dist/src/keystore/index.js +1 -1
  25. package/dist/src/ledger/index.cjs +3 -3
  26. package/dist/src/ledger/index.cjs.map +8 -7
  27. package/dist/src/ledger/index.js +3 -3
  28. package/dist/src/ledger/index.js.map +8 -7
  29. package/dist/src/okx/index.js +1 -1
  30. package/dist/src/onekey/index.js +1 -1
  31. package/dist/src/phantom/index.js +1 -1
  32. package/dist/src/polkadotjs/index.js +1 -1
  33. package/dist/src/radix/index.js +1 -1
  34. package/dist/src/talisman/index.js +1 -1
  35. package/dist/src/trezor/index.cjs +2 -2
  36. package/dist/src/trezor/index.cjs.map +3 -3
  37. package/dist/src/trezor/index.js +2 -2
  38. package/dist/src/trezor/index.js.map +3 -3
  39. package/dist/src/walletconnect/index.js +1 -1
  40. package/package.json +21 -19
  41. package/src/cosmostation/index.ts +141 -0
  42. package/src/ctrl/walletHelpers.ts +75 -79
  43. package/src/ledger/clients/xrp.ts +66 -0
  44. package/src/ledger/helpers/getLedgerAddress.ts +12 -3
  45. package/src/ledger/helpers/getLedgerClient.ts +4 -0
  46. package/src/ledger/index.ts +10 -0
  47. package/src/trezor/index.ts +11 -1
  48. package/src/types.ts +3 -0
  49. package/src/utils.ts +4 -0
  50. package/dist/chunk-wja505db.js +0 -4
  51. /package/dist/{chunk-ta4bdjpy.js.map → chunk-qgv1myym.js.map} +0 -0
@@ -0,0 +1,66 @@
1
+ import type Xrp from "@ledgerhq/hw-app-xrp";
2
+ import type Transport from "@ledgerhq/hw-transport";
3
+ import {
4
+ Chain,
5
+ type DerivationPathArray,
6
+ NetworkDerivationPath,
7
+ derivationPathToString,
8
+ } from "@swapkit/helpers";
9
+ import type { Transaction } from "@swapkit/toolboxes/ripple";
10
+ import { encode } from "ripple-binary-codec";
11
+ import type { Payment } from "xrpl";
12
+ import { getLedgerTransport } from "../helpers";
13
+
14
+ const TF_FULLY_CANONICAL_SIG = 2147483648;
15
+
16
+ function cleanTransactionObject(obj: Record<string, any>) {
17
+ const cleaned: Record<string, any> = {};
18
+ for (const key in obj) {
19
+ if (obj[key] !== null && obj[key] !== undefined) {
20
+ cleaned[key] = obj[key];
21
+ }
22
+ }
23
+ return cleaned;
24
+ }
25
+
26
+ async function establishConnection(transport: Transport) {
27
+ const { default: Xrp } = await import("@ledgerhq/hw-app-xrp");
28
+ return new Xrp(transport);
29
+ }
30
+
31
+ function fetchAddressAndPublicKey({
32
+ instance,
33
+ derivationPath,
34
+ }: { instance: Xrp; derivationPath: string }) {
35
+ return instance.getAddress(derivationPath);
36
+ }
37
+
38
+ export const XRPLedger = async (derivationPath?: DerivationPathArray) => {
39
+ const path = derivationPathToString(derivationPath || NetworkDerivationPath[Chain.Ripple]);
40
+ const transport = await getLedgerTransport();
41
+ const xrpInstance = await establishConnection(transport);
42
+
43
+ const { address, publicKey } = await fetchAddressAndPublicKey({
44
+ instance: xrpInstance,
45
+ derivationPath: path,
46
+ });
47
+
48
+ async function sign(transaction: Payment | Transaction) {
49
+ const { hashes } = await import("@swapkit/toolboxes/ripple");
50
+ const cleanedTxWithPubKey = cleanTransactionObject(transaction);
51
+ const transactionJSON = {
52
+ ...cleanedTxWithPubKey,
53
+ Flags: transaction.Flags || TF_FULLY_CANONICAL_SIG,
54
+ SigningPubKey: publicKey.toUpperCase(),
55
+ };
56
+
57
+ const transactionToSignOnLedger = encode(transactionJSON);
58
+ const txnSignature = await xrpInstance.signTransaction(path, transactionToSignOnLedger);
59
+ const tx_blob = encode({ ...transactionJSON, TxnSignature: txnSignature });
60
+ const hash = hashes.hashSignedTx(tx_blob);
61
+
62
+ return { tx_blob, hash };
63
+ }
64
+
65
+ return { address, sign };
66
+ };
@@ -1,15 +1,19 @@
1
1
  import { Chain, SwapKitError, WalletOption } from "@swapkit/helpers";
2
2
 
3
+ import type { XRPLedger } from "../clients/xrp";
3
4
  import type { LEDGER_SUPPORTED_CHAINS } from "../index";
4
5
  import type { CosmosLedgerClients, EVMLedgerClients, UTXOLedgerClients } from "../types";
5
6
  import type { getLedgerClient } from "./getLedgerClient";
6
7
 
7
- export const getLedgerAddress = async ({
8
+ export const getLedgerAddress = async <
9
+ T extends (typeof LEDGER_SUPPORTED_CHAINS)[number],
10
+ L extends Awaited<ReturnType<typeof getLedgerClient<T>>>,
11
+ >({
8
12
  chain,
9
13
  ledgerClient,
10
14
  }: {
11
- chain: (typeof LEDGER_SUPPORTED_CHAINS)[number];
12
- ledgerClient: Awaited<ReturnType<typeof getLedgerClient>>;
15
+ chain: T;
16
+ ledgerClient: L;
13
17
  }) => {
14
18
  if (!ledgerClient) return "";
15
19
 
@@ -40,6 +44,11 @@ export const getLedgerAddress = async ({
40
44
 
41
45
  return chain === Chain.BitcoinCash ? address.replace("bitcoincash:", "") : address;
42
46
  }
47
+
48
+ case Chain.Ripple: {
49
+ return (ledgerClient as Awaited<ReturnType<typeof XRPLedger>>).address;
50
+ }
51
+
43
52
  default:
44
53
  throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.LEDGER, chain });
45
54
  }
@@ -18,6 +18,7 @@ import {
18
18
  DogecoinLedger,
19
19
  LitecoinLedger,
20
20
  } from "../clients/utxo";
21
+ import { XRPLedger } from "../clients/xrp";
21
22
 
22
23
  type LedgerSignerMap = {
23
24
  [Chain.Arbitrum]: ReturnType<typeof ArbitrumLedger>;
@@ -33,6 +34,7 @@ type LedgerSignerMap = {
33
34
  [Chain.Litecoin]: ReturnType<typeof LitecoinLedger>;
34
35
  [Chain.Optimism]: ReturnType<typeof OptimismLedger>;
35
36
  [Chain.Polygon]: ReturnType<typeof PolygonLedger>;
37
+ [Chain.Ripple]: ReturnType<typeof XRPLedger>;
36
38
  [Chain.THORChain]: THORChainLedger;
37
39
  };
38
40
 
@@ -60,6 +62,8 @@ export const getLedgerClient = async <T extends LedgerSupportedChain>({
60
62
  return DogecoinLedger(derivationPath) as LedgerSignerMap[T];
61
63
  case Chain.Litecoin:
62
64
  return LitecoinLedger(derivationPath) as LedgerSignerMap[T];
65
+ case Chain.Ripple:
66
+ return XRPLedger(derivationPath) as LedgerSignerMap[T];
63
67
 
64
68
  case Chain.Arbitrum:
65
69
  case Chain.Avalanche:
@@ -32,6 +32,7 @@ export const ledgerWallet = createWallet({
32
32
  Chain.Litecoin,
33
33
  Chain.Optimism,
34
34
  Chain.Polygon,
35
+ Chain.Ripple,
35
36
  Chain.THORChain,
36
37
  ],
37
38
  walletType: WalletOption.LEDGER,
@@ -267,6 +268,15 @@ async function getWalletMethods({
267
268
  return { ...toolbox, address, deposit, transfer, signMessage };
268
269
  }
269
270
 
271
+ case Chain.Ripple: {
272
+ const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
273
+ const signer = await getLedgerClient({ chain, derivationPath });
274
+ const address = signer.address;
275
+ const toolbox = await getRippleToolbox({ signer });
276
+
277
+ return { ...toolbox, address };
278
+ }
279
+
270
280
  default:
271
281
  throw new Error("Unsupported chain");
272
282
  }
@@ -233,7 +233,17 @@ export const trezorWallet = createWallet({
233
233
  const { success } = await TrezorConnect.getDeviceState();
234
234
 
235
235
  if (!success) {
236
- const manifest = SKConfig.get("integrations").trezor || { appUrl: "", email: "" };
236
+ const trezorConfig = SKConfig.get("integrations").trezor;
237
+ const manifest = trezorConfig
238
+ ? {
239
+ ...trezorConfig,
240
+ appName: (trezorConfig as any).appName || "SwapKit",
241
+ }
242
+ : {
243
+ appUrl: "",
244
+ email: "",
245
+ appName: "SwapKit",
246
+ };
237
247
  TrezorConnect.init({ lazyLoad: true, manifest });
238
248
  }
239
249
 
package/src/types.ts CHANGED
@@ -12,6 +12,7 @@ import type { BrowserProvider, Eip1193Provider } from "ethers";
12
12
  import type { SubstrateInjectedExtension } from "@swapkit/toolboxes/substrate";
13
13
  import type { bitgetWallet } from "./bitget";
14
14
  import type { coinbaseWallet } from "./coinbase";
15
+ import type { cosmostationWallet } from "./cosmostation";
15
16
  import type { ctrlWallet } from "./ctrl";
16
17
  import type { evmWallet } from "./evm-extensions";
17
18
  import type { exodusWallet } from "./exodus";
@@ -34,6 +35,7 @@ export type SKWallets = {
34
35
  [WalletOption.BRAVE]: typeof evmWallet;
35
36
  [WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet;
36
37
  [WalletOption.COINBASE_WEB]: typeof evmWallet;
38
+ [WalletOption.COSMOSTATION]: typeof cosmostationWallet;
37
39
  [WalletOption.CTRL]: typeof ctrlWallet;
38
40
  [WalletOption.EIP6963]: typeof evmWallet;
39
41
  [WalletOption.EXODUS]: typeof exodusWallet;
@@ -64,6 +66,7 @@ export type SKWalletsSupportedChains = {
64
66
  [WalletOption.BRAVE]: typeof evmWallet.connectEVMWallet.supportedChains;
65
67
  [WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet.connectCoinbaseWallet.supportedChains;
66
68
  [WalletOption.COINBASE_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
69
+ [WalletOption.COSMOSTATION]: typeof cosmostationWallet.connectCosmostation.supportedChains;
67
70
  [WalletOption.CTRL]: typeof ctrlWallet.connectCtrl.supportedChains;
68
71
  [WalletOption.EIP6963]: typeof evmWallet.connectEVMWallet.supportedChains;
69
72
  [WalletOption.EXODUS]: typeof exodusWallet.connectExodusWallet.supportedChains;
package/src/utils.ts CHANGED
@@ -25,6 +25,10 @@ export async function loadWallet<W extends WalletOption>(walletOption: W): Promi
25
25
  async () => (await import("./walletconnect")).walletconnectWallet,
26
26
  )
27
27
  .with(WalletOption.KEPLR, WalletOption.LEAP, async () => (await import("./keplr")).keplrWallet)
28
+ .with(
29
+ WalletOption.COSMOSTATION,
30
+ async () => (await import("./cosmostation")).cosmostationWallet,
31
+ )
28
32
  .with(
29
33
  WalletOption.BRAVE,
30
34
  WalletOption.COINBASE_WEB,
@@ -1,4 +0,0 @@
1
- import{c as a,d as e}from"./chunk-p1kdg37m.js";import{WalletOption as t}from"@swapkit/helpers";function r(i){let l=Object.keys(i)?.[0]||"";return i?.[l]?.supportedChains||[]}async function p(i){let{match:l}=await import("ts-pattern");return await l(i).with(t.COINBASE_MOBILE,async()=>(await import("./src/coinbase/index.js")).coinbaseWallet).with(t.BITGET,async()=>(await import("./src/bitget/index.js")).bitgetWallet).with(t.CTRL,async()=>(await import("./src/ctrl/index.js")).ctrlWallet).with(t.OKX,async()=>(await import("./src/okx/index.js")).okxWallet).with(t.ONEKEY,async()=>(await import("./src/onekey/index.js")).onekeyWallet).with(t.EXODUS,async()=>(await import("./src/exodus/index.js")).exodusWallet).with(t.KEEPKEY,async()=>(await import("./src/keepkey/index.js")).keepkeyWallet).with(t.KEEPKEY_BEX,async()=>(await import("./src/keepkey-bex/index.js")).keepkeyBexWallet).with(t.WALLETCONNECT,async()=>(await import("./src/walletconnect/index.js")).walletconnectWallet).with(t.KEPLR,t.LEAP,async()=>(await import("./src/keplr/index.js")).keplrWallet).with(t.BRAVE,t.COINBASE_WEB,t.EIP6963,t.METAMASK,t.OKX_MOBILE,t.TRUSTWALLET_WEB,async()=>(await import("./src/evm-extensions/index.js")).evmWallet).with(t.KEYSTORE,async()=>(await import("./src/keystore/index.js")).keystoreWallet).with(t.TREZOR,async()=>(await import("./src/trezor/index.js")).trezorWallet).with(t.LEDGER,t.LEDGER_LIVE,async()=>(await import("./src/ledger/index.js")).ledgerWallet).with(t.PHANTOM,async()=>(await import("./src/phantom/index.js")).phantomWallet).with(t.POLKADOT_JS,async()=>(await import("./src/polkadotjs/index.js")).polkadotWallet).with(t.RADIX_WALLET,async()=>(await import("./src/radix/index.js")).radixWallet).with(t.TALISMAN,async()=>(await import("./src/talisman/index.js")).talismanWallet).exhaustive()}
2
- export{r as a,p as b};
3
-
4
- //# debugId=40B36BBD4009778C64756E2164756E21