@caatinga/client 2.0.2 → 2.2.0
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/README.md +34 -2
- package/dist/chunk-HKAMQDUV.js +169 -0
- package/dist/index.cjs +192 -54
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +46 -68
- package/dist/react.cjs +252 -0
- package/dist/react.d.cts +32 -0
- package/dist/react.d.ts +32 -0
- package/dist/react.js +68 -0
- package/dist/stellar-wallets-kit.cjs +58 -45
- package/dist/stellar-wallets-kit.d.cts +10 -5
- package/dist/stellar-wallets-kit.d.ts +10 -5
- package/dist/stellar-wallets-kit.js +57 -50
- package/dist/wallet-session-DeLp8S1c.d.ts +56 -0
- package/dist/wallet-session-ed2Dgs9A.d.cts +56 -0
- package/package.json +20 -5
|
@@ -20,81 +20,94 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/stellar-wallets-kit.ts
|
|
21
21
|
var stellar_wallets_kit_exports = {};
|
|
22
22
|
__export(stellar_wallets_kit_exports, {
|
|
23
|
-
WalletNetwork: () =>
|
|
23
|
+
WalletNetwork: () => import_types.Networks,
|
|
24
24
|
createStellarWalletsKitAdapter: () => createStellarWalletsKitAdapter
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(stellar_wallets_kit_exports);
|
|
27
27
|
|
|
28
28
|
// src/adapters/stellar-wallets-kit.ts
|
|
29
|
-
var
|
|
30
|
-
var
|
|
29
|
+
var import_sdk = require("@creit.tech/stellar-wallets-kit/sdk");
|
|
30
|
+
var import_types = require("@creit.tech/stellar-wallets-kit/types");
|
|
31
|
+
var import_utils = require("@creit.tech/stellar-wallets-kit/modules/utils");
|
|
32
|
+
var import_freighter = require("@creit.tech/stellar-wallets-kit/modules/freighter");
|
|
33
|
+
var import_hotwallet = require("@creit.tech/stellar-wallets-kit/modules/hotwallet");
|
|
34
|
+
var import_wallet_connect = require("@creit.tech/stellar-wallets-kit/modules/wallet-connect");
|
|
35
|
+
var kitInitialized = false;
|
|
31
36
|
function createStellarWalletsKitAdapter(options = {}) {
|
|
32
|
-
const network = options.network ??
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const network = options.network ?? import_types.Networks.TESTNET;
|
|
38
|
+
if (!kitInitialized) {
|
|
39
|
+
import_sdk.StellarWalletsKit.init({
|
|
40
|
+
network,
|
|
41
|
+
selectedWalletId: options.selectedWalletId ?? import_freighter.FREIGHTER_ID,
|
|
42
|
+
modules: options.modules ?? buildModules(options.walletConnectMetadata),
|
|
43
|
+
...options.initParams
|
|
44
|
+
});
|
|
45
|
+
kitInitialized = true;
|
|
46
|
+
} else if (options.network !== void 0) {
|
|
47
|
+
import_sdk.StellarWalletsKit.setNetwork(network);
|
|
48
|
+
}
|
|
38
49
|
let address;
|
|
39
50
|
return {
|
|
40
|
-
kit,
|
|
51
|
+
kit: import_sdk.StellarWalletsKit,
|
|
41
52
|
setWallet(walletId) {
|
|
42
|
-
|
|
53
|
+
import_sdk.StellarWalletsKit.setWallet(walletId);
|
|
43
54
|
address = void 0;
|
|
44
55
|
},
|
|
56
|
+
getWalletId() {
|
|
57
|
+
try {
|
|
58
|
+
return import_sdk.StellarWalletsKit.selectedModule.productId;
|
|
59
|
+
} catch {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
45
63
|
getSupportedWallets() {
|
|
46
|
-
return
|
|
64
|
+
return import_sdk.StellarWalletsKit.refreshSupportedWallets();
|
|
47
65
|
},
|
|
48
|
-
openModal(modalOptions = {}) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}).catch((error) => {
|
|
59
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
onClosed: (error) => {
|
|
63
|
-
modalOptions.onClosed?.(error);
|
|
64
|
-
reject(error);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
66
|
+
async openModal(modalOptions = {}) {
|
|
67
|
+
try {
|
|
68
|
+
const result = await import_sdk.StellarWalletsKit.authModal();
|
|
69
|
+
address = result.address;
|
|
70
|
+
return result.address;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
73
|
+
modalOptions.onClosed?.(normalized);
|
|
74
|
+
throw normalized;
|
|
75
|
+
}
|
|
68
76
|
},
|
|
69
77
|
async getPublicKey() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
try {
|
|
79
|
+
const cached = await import_sdk.StellarWalletsKit.getAddress();
|
|
80
|
+
address = cached.address;
|
|
81
|
+
return cached.address;
|
|
82
|
+
} catch {
|
|
83
|
+
const fetched = await import_sdk.StellarWalletsKit.fetchAddress();
|
|
84
|
+
address = fetched.address;
|
|
85
|
+
return fetched.address;
|
|
86
|
+
}
|
|
73
87
|
},
|
|
74
88
|
async signTransaction({ xdr, networkPassphrase }) {
|
|
75
|
-
const result = await
|
|
89
|
+
const result = await import_sdk.StellarWalletsKit.signTransaction(xdr, {
|
|
76
90
|
networkPassphrase,
|
|
77
91
|
...address ? { address } : {}
|
|
78
92
|
});
|
|
79
93
|
return result.signedTxXdr;
|
|
80
94
|
},
|
|
81
95
|
async disconnect() {
|
|
82
|
-
await
|
|
96
|
+
await import_sdk.StellarWalletsKit.disconnect();
|
|
83
97
|
address = void 0;
|
|
84
98
|
}
|
|
85
99
|
};
|
|
86
100
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
filterBy: (module2) => module2.productId !== HOTWALLET_ID
|
|
101
|
+
function buildModules(walletConnectMetadata) {
|
|
102
|
+
const modules = (0, import_utils.defaultModules)({
|
|
103
|
+
filterBy: (module2) => module2.productId !== import_hotwallet.HOTWALLET_ID
|
|
91
104
|
});
|
|
92
105
|
if (walletConnectMetadata) {
|
|
106
|
+
const { projectId, name, description, url, icons } = walletConnectMetadata;
|
|
93
107
|
modules.push(
|
|
94
|
-
new
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
method: import_walletconnect.WalletConnectAllowedMethods.SIGN
|
|
108
|
+
new import_wallet_connect.WalletConnectModule({
|
|
109
|
+
projectId,
|
|
110
|
+
metadata: { name, description, url, icons }
|
|
98
111
|
})
|
|
99
112
|
);
|
|
100
113
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StellarWalletsKit
|
|
2
|
-
|
|
1
|
+
import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit/sdk';
|
|
2
|
+
import { ISupportedWallet, Networks, ModuleInterface, StellarWalletsKitInitParams } from '@creit.tech/stellar-wallets-kit/types';
|
|
3
|
+
export { Networks as WalletNetwork } from '@creit.tech/stellar-wallets-kit/types';
|
|
3
4
|
import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.cjs';
|
|
4
5
|
import '@caatinga/core/browser';
|
|
5
6
|
|
|
@@ -15,13 +16,14 @@ interface StellarWalletsKitMetadata {
|
|
|
15
16
|
projectId: string;
|
|
16
17
|
}
|
|
17
18
|
interface StellarWalletsKitAdapterOptions {
|
|
18
|
-
|
|
19
|
-
network?: WalletNetwork;
|
|
19
|
+
network?: Networks;
|
|
20
20
|
/** Wallet pre-selected before the user opens the modal. Defaults to Freighter. */
|
|
21
21
|
selectedWalletId?: string;
|
|
22
22
|
/** Override the registered modules. Defaults to every auto-detectable wallet. */
|
|
23
23
|
modules?: ModuleInterface[];
|
|
24
24
|
walletConnectMetadata?: StellarWalletsKitMetadata;
|
|
25
|
+
/** Extra SWK init options (theme, authModal flags, etc.). */
|
|
26
|
+
initParams?: Omit<StellarWalletsKitInitParams, "modules" | "network" | "selectedWalletId">;
|
|
25
27
|
}
|
|
26
28
|
interface StellarWalletsKitOpenModalOptions {
|
|
27
29
|
modalTitle?: string;
|
|
@@ -29,7 +31,8 @@ interface StellarWalletsKitOpenModalOptions {
|
|
|
29
31
|
onClosed?: (error: Error) => void;
|
|
30
32
|
}
|
|
31
33
|
interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
|
|
32
|
-
|
|
34
|
+
/** SWK 2.x uses static methods on this class (no per-app instance). */
|
|
35
|
+
kit: typeof StellarWalletsKit;
|
|
33
36
|
/**
|
|
34
37
|
* Opens the wallet-selection modal (lists only installed/available wallets),
|
|
35
38
|
* sets the chosen wallet as active, and resolves with the connected address.
|
|
@@ -37,6 +40,8 @@ interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
|
|
|
37
40
|
*/
|
|
38
41
|
openModal(options?: StellarWalletsKitOpenModalOptions): Promise<string>;
|
|
39
42
|
setWallet(walletId: string): void;
|
|
43
|
+
/** Id of the wallet currently selected in the kit, or undefined before any selection. */
|
|
44
|
+
getWalletId(): string | undefined;
|
|
40
45
|
getSupportedWallets(): Promise<ISupportedWallet[]>;
|
|
41
46
|
disconnect(): Promise<void>;
|
|
42
47
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StellarWalletsKit
|
|
2
|
-
|
|
1
|
+
import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit/sdk';
|
|
2
|
+
import { ISupportedWallet, Networks, ModuleInterface, StellarWalletsKitInitParams } from '@creit.tech/stellar-wallets-kit/types';
|
|
3
|
+
export { Networks as WalletNetwork } from '@creit.tech/stellar-wallets-kit/types';
|
|
3
4
|
import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.js';
|
|
4
5
|
import '@caatinga/core/browser';
|
|
5
6
|
|
|
@@ -15,13 +16,14 @@ interface StellarWalletsKitMetadata {
|
|
|
15
16
|
projectId: string;
|
|
16
17
|
}
|
|
17
18
|
interface StellarWalletsKitAdapterOptions {
|
|
18
|
-
|
|
19
|
-
network?: WalletNetwork;
|
|
19
|
+
network?: Networks;
|
|
20
20
|
/** Wallet pre-selected before the user opens the modal. Defaults to Freighter. */
|
|
21
21
|
selectedWalletId?: string;
|
|
22
22
|
/** Override the registered modules. Defaults to every auto-detectable wallet. */
|
|
23
23
|
modules?: ModuleInterface[];
|
|
24
24
|
walletConnectMetadata?: StellarWalletsKitMetadata;
|
|
25
|
+
/** Extra SWK init options (theme, authModal flags, etc.). */
|
|
26
|
+
initParams?: Omit<StellarWalletsKitInitParams, "modules" | "network" | "selectedWalletId">;
|
|
25
27
|
}
|
|
26
28
|
interface StellarWalletsKitOpenModalOptions {
|
|
27
29
|
modalTitle?: string;
|
|
@@ -29,7 +31,8 @@ interface StellarWalletsKitOpenModalOptions {
|
|
|
29
31
|
onClosed?: (error: Error) => void;
|
|
30
32
|
}
|
|
31
33
|
interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
|
|
32
|
-
|
|
34
|
+
/** SWK 2.x uses static methods on this class (no per-app instance). */
|
|
35
|
+
kit: typeof StellarWalletsKit;
|
|
33
36
|
/**
|
|
34
37
|
* Opens the wallet-selection modal (lists only installed/available wallets),
|
|
35
38
|
* sets the chosen wallet as active, and resolves with the connected address.
|
|
@@ -37,6 +40,8 @@ interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
|
|
|
37
40
|
*/
|
|
38
41
|
openModal(options?: StellarWalletsKitOpenModalOptions): Promise<string>;
|
|
39
42
|
setWallet(walletId: string): void;
|
|
43
|
+
/** Id of the wallet currently selected in the kit, or undefined before any selection. */
|
|
44
|
+
getWalletId(): string | undefined;
|
|
40
45
|
getSupportedWallets(): Promise<ISupportedWallet[]>;
|
|
41
46
|
disconnect(): Promise<void>;
|
|
42
47
|
}
|
|
@@ -1,87 +1,94 @@
|
|
|
1
1
|
// src/adapters/stellar-wallets-kit.ts
|
|
2
|
+
import { StellarWalletsKit } from "@creit.tech/stellar-wallets-kit/sdk";
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "@creit.tech/stellar-wallets-kit";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
WalletConnectModule
|
|
11
|
-
} from "@creit.tech/stellar-wallets-kit/modules/walletconnect.module";
|
|
4
|
+
Networks
|
|
5
|
+
} from "@creit.tech/stellar-wallets-kit/types";
|
|
6
|
+
import { defaultModules } from "@creit.tech/stellar-wallets-kit/modules/utils";
|
|
7
|
+
import { FREIGHTER_ID } from "@creit.tech/stellar-wallets-kit/modules/freighter";
|
|
8
|
+
import { HOTWALLET_ID } from "@creit.tech/stellar-wallets-kit/modules/hotwallet";
|
|
9
|
+
import { WalletConnectModule } from "@creit.tech/stellar-wallets-kit/modules/wallet-connect";
|
|
10
|
+
var kitInitialized = false;
|
|
12
11
|
function createStellarWalletsKitAdapter(options = {}) {
|
|
13
|
-
const network = options.network ??
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const network = options.network ?? Networks.TESTNET;
|
|
13
|
+
if (!kitInitialized) {
|
|
14
|
+
StellarWalletsKit.init({
|
|
15
|
+
network,
|
|
16
|
+
selectedWalletId: options.selectedWalletId ?? FREIGHTER_ID,
|
|
17
|
+
modules: options.modules ?? buildModules(options.walletConnectMetadata),
|
|
18
|
+
...options.initParams
|
|
19
|
+
});
|
|
20
|
+
kitInitialized = true;
|
|
21
|
+
} else if (options.network !== void 0) {
|
|
22
|
+
StellarWalletsKit.setNetwork(network);
|
|
23
|
+
}
|
|
19
24
|
let address;
|
|
20
25
|
return {
|
|
21
|
-
kit,
|
|
26
|
+
kit: StellarWalletsKit,
|
|
22
27
|
setWallet(walletId) {
|
|
23
|
-
|
|
28
|
+
StellarWalletsKit.setWallet(walletId);
|
|
24
29
|
address = void 0;
|
|
25
30
|
},
|
|
31
|
+
getWalletId() {
|
|
32
|
+
try {
|
|
33
|
+
return StellarWalletsKit.selectedModule.productId;
|
|
34
|
+
} catch {
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
26
38
|
getSupportedWallets() {
|
|
27
|
-
return
|
|
39
|
+
return StellarWalletsKit.refreshSupportedWallets();
|
|
28
40
|
},
|
|
29
|
-
openModal(modalOptions = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
41
|
+
async openModal(modalOptions = {}) {
|
|
42
|
+
try {
|
|
43
|
+
const result = await StellarWalletsKit.authModal();
|
|
44
|
+
address = result.address;
|
|
45
|
+
return result.address;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
48
|
+
modalOptions.onClosed?.(normalized);
|
|
49
|
+
throw normalized;
|
|
50
|
+
}
|
|
49
51
|
},
|
|
50
52
|
async getPublicKey() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
try {
|
|
54
|
+
const cached = await StellarWalletsKit.getAddress();
|
|
55
|
+
address = cached.address;
|
|
56
|
+
return cached.address;
|
|
57
|
+
} catch {
|
|
58
|
+
const fetched = await StellarWalletsKit.fetchAddress();
|
|
59
|
+
address = fetched.address;
|
|
60
|
+
return fetched.address;
|
|
61
|
+
}
|
|
54
62
|
},
|
|
55
63
|
async signTransaction({ xdr, networkPassphrase }) {
|
|
56
|
-
const result = await
|
|
64
|
+
const result = await StellarWalletsKit.signTransaction(xdr, {
|
|
57
65
|
networkPassphrase,
|
|
58
66
|
...address ? { address } : {}
|
|
59
67
|
});
|
|
60
68
|
return result.signedTxXdr;
|
|
61
69
|
},
|
|
62
70
|
async disconnect() {
|
|
63
|
-
await
|
|
71
|
+
await StellarWalletsKit.disconnect();
|
|
64
72
|
address = void 0;
|
|
65
73
|
}
|
|
66
74
|
};
|
|
67
75
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const modules = allowAllModules({
|
|
76
|
+
function buildModules(walletConnectMetadata) {
|
|
77
|
+
const modules = defaultModules({
|
|
71
78
|
filterBy: (module) => module.productId !== HOTWALLET_ID
|
|
72
79
|
});
|
|
73
80
|
if (walletConnectMetadata) {
|
|
81
|
+
const { projectId, name, description, url, icons } = walletConnectMetadata;
|
|
74
82
|
modules.push(
|
|
75
83
|
new WalletConnectModule({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
method: WalletConnectAllowedMethods.SIGN
|
|
84
|
+
projectId,
|
|
85
|
+
metadata: { name, description, url, icons }
|
|
79
86
|
})
|
|
80
87
|
);
|
|
81
88
|
}
|
|
82
89
|
return modules;
|
|
83
90
|
}
|
|
84
91
|
export {
|
|
85
|
-
WalletNetwork,
|
|
92
|
+
Networks as WalletNetwork,
|
|
86
93
|
createStellarWalletsKitAdapter
|
|
87
94
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Optional adapter capabilities the session takes advantage of when present.
|
|
5
|
+
* The minimal {@link CaatingaWalletAdapter} contract stays untouched: adapters
|
|
6
|
+
* that only implement `getPublicKey`/`signTransaction` (e.g. Freighter) work,
|
|
7
|
+
* richer adapters (e.g. Stellar Wallets Kit) get modal-based connect, real
|
|
8
|
+
* disconnect, and wallet-id persistence for free.
|
|
9
|
+
*/
|
|
10
|
+
interface CaatingaWalletCapabilities {
|
|
11
|
+
openModal?(): Promise<string>;
|
|
12
|
+
disconnect?(): Promise<void>;
|
|
13
|
+
setWallet?(walletId: string): void;
|
|
14
|
+
getWalletId?(): string | undefined;
|
|
15
|
+
}
|
|
16
|
+
type WalletSessionStatus = "disconnected" | "connecting" | "connected";
|
|
17
|
+
interface WalletSessionState {
|
|
18
|
+
status: WalletSessionStatus;
|
|
19
|
+
publicKey: string | null;
|
|
20
|
+
error: Error | null;
|
|
21
|
+
}
|
|
22
|
+
/** Minimal storage contract so tests and non-browser hosts can inject their own. */
|
|
23
|
+
interface WalletSessionStorage {
|
|
24
|
+
getItem(key: string): string | null;
|
|
25
|
+
setItem(key: string, value: string): void;
|
|
26
|
+
removeItem(key: string): void;
|
|
27
|
+
}
|
|
28
|
+
interface WalletSessionOptions {
|
|
29
|
+
/** Persist the connection across page loads so `restore()` can reconnect silently. */
|
|
30
|
+
persist?: boolean;
|
|
31
|
+
/** Storage backend for persistence. Defaults to `window.localStorage` when available. */
|
|
32
|
+
storage?: WalletSessionStorage;
|
|
33
|
+
/** Persistence key. Defaults to {@link WALLET_SESSION_STORAGE_KEY}. */
|
|
34
|
+
storageKey?: string;
|
|
35
|
+
/** Optional timeout (ms) applied to connect/restore wallet calls. */
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}
|
|
38
|
+
interface WalletSession {
|
|
39
|
+
adapter: CaatingaWalletAdapter;
|
|
40
|
+
getState(): WalletSessionState;
|
|
41
|
+
/** Subscribe to state transitions. Returns an unsubscribe function. */
|
|
42
|
+
subscribe(listener: () => void): () => void;
|
|
43
|
+
/** Connect via the adapter modal when available, else `getPublicKey()`. */
|
|
44
|
+
connect(): Promise<string>;
|
|
45
|
+
disconnect(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Silent reconnect from persisted state. Resolves the public key on success,
|
|
48
|
+
* `null` when nothing was persisted or reconnection failed — never rejects
|
|
49
|
+
* and never sets `state.error` (no error toast on page load).
|
|
50
|
+
*/
|
|
51
|
+
restore(): Promise<string | null>;
|
|
52
|
+
}
|
|
53
|
+
declare const WALLET_SESSION_STORAGE_KEY = "caatinga:wallet-session";
|
|
54
|
+
declare function createWalletSession(adapter: CaatingaWalletAdapter, options?: WalletSessionOptions): WalletSession;
|
|
55
|
+
|
|
56
|
+
export { type CaatingaWalletCapabilities as C, WALLET_SESSION_STORAGE_KEY as W, type WalletSession as a, type WalletSessionOptions as b, type WalletSessionState as c, type WalletSessionStatus as d, type WalletSessionStorage as e, createWalletSession as f };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Optional adapter capabilities the session takes advantage of when present.
|
|
5
|
+
* The minimal {@link CaatingaWalletAdapter} contract stays untouched: adapters
|
|
6
|
+
* that only implement `getPublicKey`/`signTransaction` (e.g. Freighter) work,
|
|
7
|
+
* richer adapters (e.g. Stellar Wallets Kit) get modal-based connect, real
|
|
8
|
+
* disconnect, and wallet-id persistence for free.
|
|
9
|
+
*/
|
|
10
|
+
interface CaatingaWalletCapabilities {
|
|
11
|
+
openModal?(): Promise<string>;
|
|
12
|
+
disconnect?(): Promise<void>;
|
|
13
|
+
setWallet?(walletId: string): void;
|
|
14
|
+
getWalletId?(): string | undefined;
|
|
15
|
+
}
|
|
16
|
+
type WalletSessionStatus = "disconnected" | "connecting" | "connected";
|
|
17
|
+
interface WalletSessionState {
|
|
18
|
+
status: WalletSessionStatus;
|
|
19
|
+
publicKey: string | null;
|
|
20
|
+
error: Error | null;
|
|
21
|
+
}
|
|
22
|
+
/** Minimal storage contract so tests and non-browser hosts can inject their own. */
|
|
23
|
+
interface WalletSessionStorage {
|
|
24
|
+
getItem(key: string): string | null;
|
|
25
|
+
setItem(key: string, value: string): void;
|
|
26
|
+
removeItem(key: string): void;
|
|
27
|
+
}
|
|
28
|
+
interface WalletSessionOptions {
|
|
29
|
+
/** Persist the connection across page loads so `restore()` can reconnect silently. */
|
|
30
|
+
persist?: boolean;
|
|
31
|
+
/** Storage backend for persistence. Defaults to `window.localStorage` when available. */
|
|
32
|
+
storage?: WalletSessionStorage;
|
|
33
|
+
/** Persistence key. Defaults to {@link WALLET_SESSION_STORAGE_KEY}. */
|
|
34
|
+
storageKey?: string;
|
|
35
|
+
/** Optional timeout (ms) applied to connect/restore wallet calls. */
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}
|
|
38
|
+
interface WalletSession {
|
|
39
|
+
adapter: CaatingaWalletAdapter;
|
|
40
|
+
getState(): WalletSessionState;
|
|
41
|
+
/** Subscribe to state transitions. Returns an unsubscribe function. */
|
|
42
|
+
subscribe(listener: () => void): () => void;
|
|
43
|
+
/** Connect via the adapter modal when available, else `getPublicKey()`. */
|
|
44
|
+
connect(): Promise<string>;
|
|
45
|
+
disconnect(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Silent reconnect from persisted state. Resolves the public key on success,
|
|
48
|
+
* `null` when nothing was persisted or reconnection failed — never rejects
|
|
49
|
+
* and never sets `state.error` (no error toast on page load).
|
|
50
|
+
*/
|
|
51
|
+
restore(): Promise<string | null>;
|
|
52
|
+
}
|
|
53
|
+
declare const WALLET_SESSION_STORAGE_KEY = "caatinga:wallet-session";
|
|
54
|
+
declare function createWalletSession(adapter: CaatingaWalletAdapter, options?: WalletSessionOptions): WalletSession;
|
|
55
|
+
|
|
56
|
+
export { type CaatingaWalletCapabilities as C, WALLET_SESSION_STORAGE_KEY as W, type WalletSession as a, type WalletSessionOptions as b, type WalletSessionState as c, type WalletSessionStatus as d, type WalletSessionStorage as e, createWalletSession as f };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caatinga/client",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
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",
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"types": "./dist/stellar-wallets-kit.d.ts",
|
|
44
44
|
"import": "./dist/stellar-wallets-kit.js",
|
|
45
45
|
"require": "./dist/stellar-wallets-kit.cjs"
|
|
46
|
+
},
|
|
47
|
+
"./react": {
|
|
48
|
+
"types": "./dist/react.d.ts",
|
|
49
|
+
"import": "./dist/react.js",
|
|
50
|
+
"require": "./dist/react.cjs"
|
|
46
51
|
}
|
|
47
52
|
},
|
|
48
53
|
"files": [
|
|
@@ -51,17 +56,24 @@
|
|
|
51
56
|
"LICENSE"
|
|
52
57
|
],
|
|
53
58
|
"dependencies": {
|
|
54
|
-
"@caatinga/core": "^2.0
|
|
59
|
+
"@caatinga/core": "^2.2.0"
|
|
55
60
|
},
|
|
56
61
|
"devDependencies": {
|
|
57
62
|
"tsup": "^8.3.5",
|
|
58
|
-
"@creit.tech/stellar-wallets-kit": "^
|
|
63
|
+
"@creit.tech/stellar-wallets-kit": "^2.3.0",
|
|
64
|
+
"@testing-library/dom": "^10.4.0",
|
|
65
|
+
"@testing-library/react": "^16.1.0",
|
|
66
|
+
"@types/react": "^18.3.18",
|
|
67
|
+
"jsdom": "^25.0.1",
|
|
68
|
+
"react": "^18.3.1",
|
|
69
|
+
"react-dom": "^18.3.1",
|
|
59
70
|
"typescript": "^5.7.2",
|
|
60
71
|
"vitest": "^2.1.8"
|
|
61
72
|
},
|
|
62
73
|
"peerDependencies": {
|
|
63
74
|
"@stellar/freighter-api": "^4.0.0",
|
|
64
|
-
"@creit.tech/stellar-wallets-kit": "^
|
|
75
|
+
"@creit.tech/stellar-wallets-kit": "^2.3.0",
|
|
76
|
+
"react": ">=18"
|
|
65
77
|
},
|
|
66
78
|
"peerDependenciesMeta": {
|
|
67
79
|
"@stellar/freighter-api": {
|
|
@@ -69,10 +81,13 @@
|
|
|
69
81
|
},
|
|
70
82
|
"@creit.tech/stellar-wallets-kit": {
|
|
71
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"react": {
|
|
86
|
+
"optional": true
|
|
72
87
|
}
|
|
73
88
|
},
|
|
74
89
|
"scripts": {
|
|
75
|
-
"build": "tsup src/index.ts src/freighter.ts src/stellar-wallets-kit.ts --format esm,cjs --dts",
|
|
90
|
+
"build": "tsup src/index.ts src/freighter.ts src/stellar-wallets-kit.ts src/react.ts --format esm,cjs --dts",
|
|
76
91
|
"test": "vitest run --pool=threads",
|
|
77
92
|
"pretypecheck": "pnpm --filter @caatinga/core run build",
|
|
78
93
|
"typecheck": "tsc --noEmit"
|