@caatinga/client 0.2.4 → 2.0.1

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.
@@ -1,7 +1,12 @@
1
- import { StellarWalletsKit, WalletType, WalletNetwork, IConnectWalletConnectParams } from 'stellar-wallets-kit';
1
+ import { StellarWalletsKit, ISupportedWallet, WalletNetwork, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
2
+ export { WalletNetwork } from '@creit.tech/stellar-wallets-kit';
2
3
  import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.cjs';
3
4
  import '@caatinga/core/browser';
4
5
 
6
+ /**
7
+ * Optional WalletConnect metadata. When provided, a WalletConnect module is
8
+ * registered alongside the auto-detected wallets so it shows up in the modal.
9
+ */
5
10
  interface StellarWalletsKitMetadata {
6
11
  name: string;
7
12
  description: string;
@@ -12,35 +17,29 @@ interface StellarWalletsKitMetadata {
12
17
  interface StellarWalletsKitAdapterOptions {
13
18
  kit?: StellarWalletsKit;
14
19
  network?: WalletNetwork;
15
- selectedWallet?: WalletType;
20
+ /** Wallet pre-selected before the user opens the modal. Defaults to Freighter. */
21
+ selectedWalletId?: string;
22
+ /** Override the registered modules. Defaults to every auto-detectable wallet. */
23
+ modules?: ModuleInterface[];
16
24
  walletConnectMetadata?: StellarWalletsKitMetadata;
17
25
  }
18
- interface StellarWalletsKitConnectOptions {
19
- chains?: IConnectWalletConnectParams["chains"];
20
- methods?: IConnectWalletConnectParams["methods"];
21
- pairingTopic?: IConnectWalletConnectParams["pairingTopic"];
22
- }
23
- interface StellarWalletsKitSession {
24
- id: string;
25
- name: string;
26
- description: string;
27
- url: string;
28
- icons: string;
29
- accounts: Array<{
30
- network: "pubnet" | "testnet";
31
- publicKey: string;
32
- }>;
26
+ interface StellarWalletsKitOpenModalOptions {
27
+ modalTitle?: string;
28
+ notAvailableText?: string;
29
+ onClosed?: (error: Error) => void;
33
30
  }
34
31
  interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
35
32
  kit: StellarWalletsKit;
36
- setWallet(wallet: WalletType): Promise<void>;
37
- setNetwork(network: WalletNetwork): Promise<void>;
38
- startWalletConnect(metadata?: StellarWalletsKitMetadata): Promise<void>;
39
- connectWalletConnect(options?: StellarWalletsKitConnectOptions): Promise<void>;
40
- getWalletConnectSessions(): Promise<StellarWalletsKitSession[]>;
41
- setWalletConnectSession(sessionId: string): void;
42
- onWalletConnectSessionDeleted(callback: (sessionId: string) => void): void;
33
+ /**
34
+ * Opens the wallet-selection modal (lists only installed/available wallets),
35
+ * sets the chosen wallet as active, and resolves with the connected address.
36
+ * Rejects if the user closes the modal without selecting a wallet.
37
+ */
38
+ openModal(options?: StellarWalletsKitOpenModalOptions): Promise<string>;
39
+ setWallet(walletId: string): void;
40
+ getSupportedWallets(): Promise<ISupportedWallet[]>;
41
+ disconnect(): Promise<void>;
43
42
  }
44
43
  declare function createStellarWalletsKitAdapter(options?: StellarWalletsKitAdapterOptions): StellarWalletsKitAdapter;
45
44
 
46
- export { type StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, type StellarWalletsKitConnectOptions, type StellarWalletsKitMetadata, type StellarWalletsKitSession, createStellarWalletsKitAdapter };
45
+ export { type StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, type StellarWalletsKitMetadata, type StellarWalletsKitOpenModalOptions, createStellarWalletsKitAdapter };
@@ -1,7 +1,12 @@
1
- import { StellarWalletsKit, WalletType, WalletNetwork, IConnectWalletConnectParams } from 'stellar-wallets-kit';
1
+ import { StellarWalletsKit, ISupportedWallet, WalletNetwork, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
2
+ export { WalletNetwork } from '@creit.tech/stellar-wallets-kit';
2
3
  import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.js';
3
4
  import '@caatinga/core/browser';
4
5
 
6
+ /**
7
+ * Optional WalletConnect metadata. When provided, a WalletConnect module is
8
+ * registered alongside the auto-detected wallets so it shows up in the modal.
9
+ */
5
10
  interface StellarWalletsKitMetadata {
6
11
  name: string;
7
12
  description: string;
@@ -12,35 +17,29 @@ interface StellarWalletsKitMetadata {
12
17
  interface StellarWalletsKitAdapterOptions {
13
18
  kit?: StellarWalletsKit;
14
19
  network?: WalletNetwork;
15
- selectedWallet?: WalletType;
20
+ /** Wallet pre-selected before the user opens the modal. Defaults to Freighter. */
21
+ selectedWalletId?: string;
22
+ /** Override the registered modules. Defaults to every auto-detectable wallet. */
23
+ modules?: ModuleInterface[];
16
24
  walletConnectMetadata?: StellarWalletsKitMetadata;
17
25
  }
18
- interface StellarWalletsKitConnectOptions {
19
- chains?: IConnectWalletConnectParams["chains"];
20
- methods?: IConnectWalletConnectParams["methods"];
21
- pairingTopic?: IConnectWalletConnectParams["pairingTopic"];
22
- }
23
- interface StellarWalletsKitSession {
24
- id: string;
25
- name: string;
26
- description: string;
27
- url: string;
28
- icons: string;
29
- accounts: Array<{
30
- network: "pubnet" | "testnet";
31
- publicKey: string;
32
- }>;
26
+ interface StellarWalletsKitOpenModalOptions {
27
+ modalTitle?: string;
28
+ notAvailableText?: string;
29
+ onClosed?: (error: Error) => void;
33
30
  }
34
31
  interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
35
32
  kit: StellarWalletsKit;
36
- setWallet(wallet: WalletType): Promise<void>;
37
- setNetwork(network: WalletNetwork): Promise<void>;
38
- startWalletConnect(metadata?: StellarWalletsKitMetadata): Promise<void>;
39
- connectWalletConnect(options?: StellarWalletsKitConnectOptions): Promise<void>;
40
- getWalletConnectSessions(): Promise<StellarWalletsKitSession[]>;
41
- setWalletConnectSession(sessionId: string): void;
42
- onWalletConnectSessionDeleted(callback: (sessionId: string) => void): void;
33
+ /**
34
+ * Opens the wallet-selection modal (lists only installed/available wallets),
35
+ * sets the chosen wallet as active, and resolves with the connected address.
36
+ * Rejects if the user closes the modal without selecting a wallet.
37
+ */
38
+ openModal(options?: StellarWalletsKitOpenModalOptions): Promise<string>;
39
+ setWallet(walletId: string): void;
40
+ getSupportedWallets(): Promise<ISupportedWallet[]>;
41
+ disconnect(): Promise<void>;
43
42
  }
44
43
  declare function createStellarWalletsKitAdapter(options?: StellarWalletsKitAdapterOptions): StellarWalletsKitAdapter;
45
44
 
46
- export { type StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, type StellarWalletsKitConnectOptions, type StellarWalletsKitMetadata, type StellarWalletsKitSession, createStellarWalletsKitAdapter };
45
+ export { type StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, type StellarWalletsKitMetadata, type StellarWalletsKitOpenModalOptions, createStellarWalletsKitAdapter };
@@ -2,85 +2,86 @@
2
2
  import {
3
3
  StellarWalletsKit,
4
4
  WalletNetwork,
5
- WalletType
6
- } from "stellar-wallets-kit";
5
+ allowAllModules,
6
+ FREIGHTER_ID
7
+ } from "@creit.tech/stellar-wallets-kit";
8
+ import {
9
+ WalletConnectAllowedMethods,
10
+ WalletConnectModule
11
+ } from "@creit.tech/stellar-wallets-kit/modules/walletconnect.module";
7
12
  function createStellarWalletsKitAdapter(options = {}) {
13
+ const network = options.network ?? WalletNetwork.TESTNET;
8
14
  const kit = options.kit ?? new StellarWalletsKit({
9
- network: options.network ?? WalletNetwork.TESTNET,
10
- selectedWallet: options.selectedWallet ?? WalletType.XBULL
15
+ network,
16
+ selectedWalletId: options.selectedWalletId ?? FREIGHTER_ID,
17
+ modules: options.modules ?? buildModules(network, options.walletConnectMetadata)
11
18
  });
12
- let publicKey;
13
- let isWalletConnectStarted = false;
14
- const sessionDeletedCallbacks = /* @__PURE__ */ new Set();
19
+ let address;
15
20
  return {
16
21
  kit,
17
- async setWallet(wallet) {
18
- await kit.setWallet(wallet);
19
- publicKey = void 0;
20
- },
21
- async setNetwork(network) {
22
- await kit.setNetwork(network);
23
- publicKey = void 0;
22
+ setWallet(walletId) {
23
+ kit.setWallet(walletId);
24
+ address = void 0;
24
25
  },
25
- async getPublicKey() {
26
- publicKey = await kit.getPublicKey();
27
- return publicKey;
26
+ getSupportedWallets() {
27
+ return kit.getSupportedWallets();
28
28
  },
29
- async signTransaction({ xdr, networkPassphrase }) {
30
- const walletNetwork = resolveWalletNetwork(networkPassphrase);
31
- if (walletNetwork) {
32
- await kit.setNetwork(walletNetwork);
33
- }
34
- const signer = publicKey ?? await kit.getPublicKey();
35
- publicKey = signer;
36
- const response = await kit.sign({ xdr, publicKey: signer });
37
- return response.signedXDR;
38
- },
39
- async startWalletConnect(metadata = options.walletConnectMetadata) {
40
- if (!metadata) {
41
- throw new Error("WalletConnect metadata is required before starting WalletConnect.");
42
- }
43
- await kit.startWalletConnect(metadata);
44
- isWalletConnectStarted = true;
45
- for (const callback of sessionDeletedCallbacks) {
46
- kit.onSessionDeleted((sessionId) => {
47
- publicKey = void 0;
48
- callback(sessionId);
29
+ openModal(modalOptions = {}) {
30
+ return new Promise((resolve, reject) => {
31
+ void kit.openModal({
32
+ ...modalOptions.modalTitle ? { modalTitle: modalOptions.modalTitle } : {},
33
+ ...modalOptions.notAvailableText ? { notAvailableText: modalOptions.notAvailableText } : {},
34
+ onWalletSelected: (option) => {
35
+ kit.setWallet(option.id);
36
+ kit.getAddress().then((result) => {
37
+ address = result.address;
38
+ resolve(result.address);
39
+ }).catch((error) => {
40
+ reject(error instanceof Error ? error : new Error(String(error)));
41
+ });
42
+ },
43
+ onClosed: (error) => {
44
+ modalOptions.onClosed?.(error);
45
+ reject(error);
46
+ }
49
47
  });
50
- }
51
- },
52
- async connectWalletConnect(connectOptions) {
53
- await kit.connectWalletConnect(connectOptions);
54
- publicKey = void 0;
55
- },
56
- async getWalletConnectSessions() {
57
- return kit.getSessions();
48
+ });
58
49
  },
59
- setWalletConnectSession(sessionId) {
60
- kit.setSession(sessionId);
61
- publicKey = void 0;
50
+ async getPublicKey() {
51
+ const result = await kit.getAddress();
52
+ address = result.address;
53
+ return result.address;
62
54
  },
63
- onWalletConnectSessionDeleted(callback) {
64
- sessionDeletedCallbacks.add(callback);
65
- if (!isWalletConnectStarted) {
66
- return;
67
- }
68
- kit.onSessionDeleted((sessionId) => {
69
- publicKey = void 0;
70
- callback(sessionId);
55
+ async signTransaction({ xdr, networkPassphrase }) {
56
+ const result = await kit.signTransaction(xdr, {
57
+ networkPassphrase,
58
+ ...address ? { address } : {}
71
59
  });
60
+ return result.signedTxXdr;
61
+ },
62
+ async disconnect() {
63
+ await kit.disconnect();
64
+ address = void 0;
72
65
  }
73
66
  };
74
67
  }
75
- function resolveWalletNetwork(networkPassphrase) {
76
- if (networkPassphrase === "Test SDF Network ; September 2015") {
77
- return WalletNetwork.TESTNET;
78
- }
79
- if (networkPassphrase === "Public Global Stellar Network ; September 2015") {
80
- return WalletNetwork.PUBLIC;
68
+ var HOTWALLET_ID = "hot-wallet";
69
+ function buildModules(network, walletConnectMetadata) {
70
+ const modules = allowAllModules({
71
+ filterBy: (module) => module.productId !== HOTWALLET_ID
72
+ });
73
+ if (walletConnectMetadata) {
74
+ modules.push(
75
+ new WalletConnectModule({
76
+ ...walletConnectMetadata,
77
+ network,
78
+ method: WalletConnectAllowedMethods.SIGN
79
+ })
80
+ );
81
81
  }
82
- return void 0;
82
+ return modules;
83
83
  }
84
84
  export {
85
+ WalletNetwork,
85
86
  createStellarWalletsKitAdapter
86
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caatinga/client",
3
- "version": "0.2.4",
3
+ "version": "2.0.1",
4
4
  "description": "Browser and Node client for Soroban smart contracts — connects generated bindings, Caatinga artifacts, and wallet adapters",
5
5
  "keywords": [
6
6
  "stellar",
@@ -51,23 +51,23 @@
51
51
  "LICENSE"
52
52
  ],
53
53
  "dependencies": {
54
- "@caatinga/core": "^0.2.4"
54
+ "@caatinga/core": "^2.0.1"
55
55
  },
56
56
  "devDependencies": {
57
57
  "tsup": "^8.3.5",
58
- "stellar-wallets-kit": "github:Creit-Tech/Stellar-Wallets-Kit#v0.0.7",
58
+ "@creit.tech/stellar-wallets-kit": "^1.9.5",
59
59
  "typescript": "^5.7.2",
60
60
  "vitest": "^2.1.8"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@stellar/freighter-api": "^4.0.0",
64
- "stellar-wallets-kit": "github:Creit-Tech/Stellar-Wallets-Kit#v0.0.7"
64
+ "@creit.tech/stellar-wallets-kit": "^1.9.5"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@stellar/freighter-api": {
68
68
  "optional": true
69
69
  },
70
- "stellar-wallets-kit": {
70
+ "@creit.tech/stellar-wallets-kit": {
71
71
  "optional": true
72
72
  }
73
73
  },