cilantro-react 0.1.0 → 0.1.2

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/dist/index.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React$1 from 'react';
2
3
  import { ReactNode } from 'react';
4
+ import { WalletControllerFindAllResult, WalletControllerListSignersResult, WalletControllerSubmitTransactionResult } from 'cilantro-sdk/wallet';
5
+ export { WalletControllerFindAllResult, WalletControllerFindOneResult, WalletControllerListSignersResult, WalletControllerSubmitTransactionResult } from 'cilantro-sdk/wallet';
3
6
  import { SignerInfo } from 'cilantro-sdk/helpers';
7
+ import { DelegatedKeyControllerFindAllResult } from 'cilantro-sdk/delegated-keys';
8
+ export { DelegatedKeyControllerFindAllResult } from 'cilantro-sdk/delegated-keys';
4
9
  import { Transaction, PublicKey } from '@solana/web3.js';
10
+ export { AuthControllerLogin200Data } from 'cilantro-sdk/auth';
11
+ export { TransactionControllerSendRawPasskeyTransactionResult } from 'cilantro-sdk/transactions';
5
12
 
6
13
  interface CilantroProviderProps {
7
14
  children: ReactNode;
@@ -17,6 +24,7 @@ interface CilantroProviderProps {
17
24
  }
18
25
  declare function CilantroProvider({ children, platformApiKey, apiUrl, jwtStorageKey, walletStorageKey, onLoginSuccess, onLogout, onRegisterSuccess, }: CilantroProviderProps): react_jsx_runtime.JSX.Element;
19
26
 
27
+ /** Minimal user view; populated from SDK login result data.user when available. */
20
28
  interface User {
21
29
  username?: string;
22
30
  email?: string;
@@ -43,16 +51,14 @@ interface CilantroAuthProviderProps {
43
51
  declare function CilantroAuthProvider({ children, platformApiKey, apiUrl, jwtStorageKey, onLoginSuccess, onLogout, onRegisterSuccess, }: CilantroAuthProviderProps): react_jsx_runtime.JSX.Element;
44
52
  declare function useCilantroAuth(): CilantroAuthContextType;
45
53
 
46
- interface WalletData {
47
- id: string;
48
- walletId: string;
49
- walletName?: string;
54
+ /** SDK wallet list item type (element of WalletsListResponseDto.data). */
55
+ type WalletDataDto = WalletControllerFindAllResult["data"] extends readonly (infer E)[] ? E : WalletControllerFindAllResult["data"] extends (infer E)[] ? E : never;
56
+ /** WalletDataDto with backward-compat aliases (id, address, active) for existing UI. */
57
+ type WalletData = WalletDataDto & {
58
+ id?: string;
50
59
  address?: string;
51
- walletAddress?: string;
52
- chain?: string;
53
60
  active?: boolean;
54
- [key: string]: unknown;
55
- }
61
+ };
56
62
  interface WalletContextType {
57
63
  selectedWallet: WalletData | null;
58
64
  wallets: WalletData[];
@@ -67,6 +73,29 @@ interface WalletProviderProps {
67
73
  declare function WalletProvider({ children, storageKey }: WalletProviderProps): react_jsx_runtime.JSX.Element;
68
74
  declare function useWallets(): WalletContextType;
69
75
 
76
+ interface UseSelectedWalletResult {
77
+ selectedWallet: WalletData | null;
78
+ isLoading: boolean;
79
+ refreshWallets: () => Promise<void>;
80
+ }
81
+ /**
82
+ * Returns the currently selected wallet, loading state, and refresh.
83
+ * Use when you only need the current wallet, not the full wallet list.
84
+ * Must be used inside CilantroProvider (WalletProvider).
85
+ */
86
+ declare function useSelectedWallet(): UseSelectedWalletResult;
87
+
88
+ /**
89
+ * Returns the address of the currently selected wallet.
90
+ * Handles both `address` and `walletAddress` on WalletData.
91
+ * Must be used inside CilantroProvider (WalletProvider).
92
+ */
93
+ declare function useWalletAddress(): string | null;
94
+
95
+ /**
96
+ * Normalized signer shape aligned with SDK SignerDataDto / WalletSignerDataDto.
97
+ * Uses SDK field names (signerId, signerType, signerPubkey, authId); id is an alias for signerId or WalletSignerDataDto.id.
98
+ */
70
99
  interface SignerData extends Omit<SignerInfo, "signerId"> {
71
100
  id: string;
72
101
  signerId: string;
@@ -96,6 +125,60 @@ interface UseSignersResult {
96
125
  }
97
126
  declare function useSigners(options?: UseSignersOptions): UseSignersResult;
98
127
 
128
+ type SignersListResponseDto = WalletControllerListSignersResult;
129
+ interface UseSignersRawOptions {
130
+ /** Wallet ID to load signers for. When null/undefined, response is null. */
131
+ walletId?: string | null;
132
+ }
133
+ interface UseSignersRawResult {
134
+ /** Exact SDK response from listSigners (success, data: { authenticationSigners, onChainSigners }). */
135
+ signersRaw: SignersListResponseDto | null;
136
+ isLoading: boolean;
137
+ error: string | null;
138
+ refresh: () => Promise<void>;
139
+ }
140
+ /**
141
+ * Load signers for a wallet and return the exact SDK shape (SignersListResponseDto).
142
+ * Use when you need SDK-exact output; for a normalized list use useSigners instead.
143
+ * Must be used inside CilantroProvider (auth required).
144
+ */
145
+ declare function useSignersRaw(options?: UseSignersRawOptions): UseSignersRawResult;
146
+
147
+ interface UseSignersForSelectedWalletOptions {
148
+ /** Override wallet ID; when omitted, uses the selected wallet from context. */
149
+ walletId?: string | null;
150
+ }
151
+ /**
152
+ * Returns signers for the currently selected wallet (or the given walletId override).
153
+ * Composes useWallets + useSigners so you don't have to pass walletId yourself.
154
+ * Must be used inside CilantroProvider.
155
+ */
156
+ declare function useSignersForSelectedWallet(options?: UseSignersForSelectedWalletOptions): UseSignersResult;
157
+
158
+ /** SDK delegated key type (element of DelegatedKeysListResponseDto.data). Canonical id is delegatedKeyId. */
159
+ type DelegatedKeyDataDto = DelegatedKeyControllerFindAllResult["data"] extends readonly (infer E)[] ? E : DelegatedKeyControllerFindAllResult["data"] extends (infer E)[] ? E : never;
160
+ /** DelegatedKeyDataDto with backward-compat id alias (id = delegatedKeyId) for existing UI. */
161
+ type DelegatedKeyData = DelegatedKeyDataDto & {
162
+ id?: string;
163
+ };
164
+ interface UseDelegatedKeysOptions {
165
+ /** Wallet ID to load delegated keys for. When null/undefined, keys are empty. */
166
+ walletId?: string | null;
167
+ /** When true (default), filter to active keys and non-expired only. */
168
+ filterActive?: boolean;
169
+ }
170
+ interface UseDelegatedKeysResult {
171
+ keys: DelegatedKeyData[];
172
+ isLoading: boolean;
173
+ error: string | null;
174
+ refresh: () => Promise<void>;
175
+ }
176
+ /**
177
+ * Load delegated keys for a wallet. Use for custom delegated-key UI or logic.
178
+ * Must be used inside CilantroProvider (auth required).
179
+ */
180
+ declare function useDelegatedKeys(options?: UseDelegatedKeysOptions): UseDelegatedKeysResult;
181
+
99
182
  type SigningMethod = "wallet-adapter" | "sdk-signer";
100
183
  interface UseSignerSelectionOptions {
101
184
  /** Override wallet ID; if not set, uses selected wallet from WalletProvider */
@@ -114,6 +197,33 @@ interface UseSignerSelectionResult {
114
197
  }
115
198
  declare function useSignerSelection(options?: UseSignerSelectionOptions): UseSignerSelectionResult;
116
199
 
200
+ interface UseCanSignOptions {
201
+ /** Override signing method; when omitted, uses default "sdk-signer". */
202
+ signingMethod?: SigningMethod | null;
203
+ /** When true (default for sdk-signer), require a selected signer. When false, only wallet is required. */
204
+ requireSigner?: boolean;
205
+ /** When using wallet-adapter, pass true when the adapter is connected. Omit if not using wallet-adapter. */
206
+ walletAdapterConnected?: boolean;
207
+ }
208
+ interface UseCanSignResult {
209
+ /** True when the user has a valid token. */
210
+ hasToken: boolean;
211
+ /** True when a wallet is selected. */
212
+ hasWallet: boolean;
213
+ /** True when a signer is selected (sdk-signer) or wallet-adapter is connected (when walletAdapterConnected is passed). */
214
+ hasSigner: boolean;
215
+ /** True when ready to sign a message (hasToken + hasWallet + hasSigner for current method). */
216
+ canSignMessage: boolean;
217
+ /** True when ready to sign/send a transaction (same as canSignMessage; connection is required for send). */
218
+ canSignTransaction: boolean;
219
+ }
220
+ /**
221
+ * Derived "is the user ready to sign?" for disabling sign buttons or showing prompts.
222
+ * For wallet-adapter, pass walletAdapterConnected when your adapter is connected so canSign reflects it.
223
+ * Must be used inside CilantroProvider.
224
+ */
225
+ declare function useCanSign(options?: UseCanSignOptions): UseCanSignResult;
226
+
117
227
  /**
118
228
  * Type Utilities - common types and utilities for SDK interactions
119
229
  */
@@ -198,12 +308,16 @@ interface WalletSelectorClassNames {
198
308
  trigger?: string;
199
309
  content?: string;
200
310
  item?: string;
311
+ skeleton?: string;
312
+ loading?: string;
201
313
  }
202
314
  interface WalletSelectorProps {
203
315
  value?: string;
204
316
  onWalletChange?: (walletId: string, wallet: WalletData | null) => void;
205
317
  className?: string;
206
318
  classNames?: WalletSelectorClassNames;
319
+ /** When true (default), show skeleton in trigger while loading; when false, show "Loading..." text. */
320
+ useSkeleton?: boolean;
207
321
  placeholder?: string;
208
322
  renderTrigger?: (props: {
209
323
  selectedWallet: WalletData | null;
@@ -233,6 +347,8 @@ interface SignerSelectorClassNames {
233
347
  list?: string;
234
348
  item?: string;
235
349
  message?: string;
350
+ skeleton?: string;
351
+ loading?: string;
236
352
  }
237
353
  interface SignerSelectorProps {
238
354
  /** Wallet ID (signers are loaded for this wallet when used with useSigners) */
@@ -249,6 +365,8 @@ interface SignerSelectorProps {
249
365
  className?: string;
250
366
  /** Override class names for sub-elements */
251
367
  classNames?: SignerSelectorClassNames;
368
+ /** When true (default), show skeleton rows while loading; when false, show "Loading signers..." text. */
369
+ useSkeleton?: boolean;
252
370
  /** Custom list render (headless) */
253
371
  renderList?: (props: {
254
372
  signers: SignerData[];
@@ -267,25 +385,16 @@ interface SignerSelectorProps {
267
385
  isLoading: boolean;
268
386
  }) => React.ReactNode;
269
387
  }
270
- declare function SignerSelector({ selectedWalletId, availableSigners, selectedSigner, isLoadingSigners, onSignerSelect, className, classNames, renderList, children, }: SignerSelectorProps): react_jsx_runtime.JSX.Element | null;
388
+ declare function SignerSelector({ selectedWalletId, availableSigners, selectedSigner, isLoadingSigners, onSignerSelect, className, classNames, useSkeleton, renderList, children, }: SignerSelectorProps): react_jsx_runtime.JSX.Element | null;
271
389
 
272
- interface DelegatedKeyData {
273
- id: string;
274
- walletId: string;
275
- name?: string;
276
- publicKey: string;
277
- permissions: Record<string, unknown>;
278
- isActive?: boolean;
279
- createdAt?: string;
280
- expiresAt?: string;
281
- [key: string]: unknown;
282
- }
283
390
  interface DelegatedKeySelectorClassNames {
284
391
  root?: string;
285
392
  trigger?: string;
286
393
  content?: string;
287
394
  item?: string;
288
395
  message?: string;
396
+ skeleton?: string;
397
+ loading?: string;
289
398
  }
290
399
  interface DelegatedKeySelectorProps {
291
400
  walletId: string;
@@ -294,6 +403,8 @@ interface DelegatedKeySelectorProps {
294
403
  filterActive?: boolean;
295
404
  className?: string;
296
405
  classNames?: DelegatedKeySelectorClassNames;
406
+ /** When true (default), show skeleton trigger while loading; when false, show "Loading delegated keys..." text. */
407
+ useSkeleton?: boolean;
297
408
  placeholder?: string;
298
409
  children?: (props: {
299
410
  keys: DelegatedKeyData[];
@@ -500,6 +611,8 @@ declare function AuthForm({ defaultMode, className, classNames, onSuccess, onErr
500
611
  interface AuthGuardClassNames {
501
612
  root?: string;
502
613
  fallback?: string;
614
+ skeleton?: string;
615
+ loading?: string;
503
616
  }
504
617
  interface AuthGuardProps {
505
618
  children: ReactNode;
@@ -510,12 +623,14 @@ interface AuthGuardProps {
510
623
  classNames?: AuthGuardClassNames;
511
624
  /** When true, show fallback (login) instead of children when unauthenticated. When false, render null when unauthenticated. */
512
625
  showFallback?: boolean;
626
+ /** When true, show a small skeleton card while loading; when false (default), show "Loading..." text. */
627
+ useSkeleton?: boolean;
513
628
  }
514
629
  /**
515
630
  * Wraps content and shows fallback (e.g. LoginForm) when the user is not authenticated.
516
631
  * Use inside CilantroAuthProvider.
517
632
  */
518
- declare function AuthGuard({ children, fallback, className, classNames, showFallback, }: AuthGuardProps): react_jsx_runtime.JSX.Element | null;
633
+ declare function AuthGuard({ children, fallback, className, classNames, showFallback, useSkeleton, }: AuthGuardProps): react_jsx_runtime.JSX.Element | null;
519
634
 
520
635
  type AddSignerType = "email" | "phone" | "passkey" | "external";
521
636
  interface AddSignerFormClassNames {
@@ -549,6 +664,8 @@ interface SignerListClassNames {
549
664
  item?: string;
550
665
  addButton?: string;
551
666
  message?: string;
667
+ skeleton?: string;
668
+ loading?: string;
552
669
  }
553
670
  interface SignerListProps {
554
671
  walletId: string;
@@ -556,6 +673,8 @@ interface SignerListProps {
556
673
  classNames?: SignerListClassNames;
557
674
  /** Callback when a signer is added (e.g. to refresh parent state) */
558
675
  onSignerAdded?: () => void;
676
+ /** When true (default), show skeleton rows while loading; when false, show "Loading signers..." text. */
677
+ useSkeleton?: boolean;
559
678
  /** Custom render for the list of signers */
560
679
  children?: (props: {
561
680
  signers: SignerData[];
@@ -565,18 +684,44 @@ interface SignerListProps {
565
684
  openAddSigner: () => void;
566
685
  }) => React.ReactNode;
567
686
  }
568
- declare function SignerList({ walletId, className, classNames, onSignerAdded, children, }: SignerListProps): react_jsx_runtime.JSX.Element;
687
+ declare function SignerList({ walletId, className, classNames, onSignerAdded, useSkeleton, children, }: SignerListProps): react_jsx_runtime.JSX.Element;
688
+
689
+ interface SkeletonProps extends React$1.HTMLAttributes<HTMLDivElement> {
690
+ }
691
+ declare const Skeleton: React$1.ForwardRefExoticComponent<SkeletonProps & React$1.RefAttributes<HTMLDivElement>>;
692
+
693
+ type Theme = "light" | "dark" | "system";
694
+ type ResolvedTheme = "light" | "dark";
695
+ interface ThemeProviderProps {
696
+ /** Current theme: "light", "dark", or "system" (follows prefers-color-scheme). */
697
+ theme?: Theme;
698
+ /** Default theme when theme is "system" or for initial render. */
699
+ defaultTheme?: ResolvedTheme;
700
+ /** Optional localStorage key for persisting theme when using "system". */
701
+ storageKey?: string;
702
+ /** Optional class for the wrapper div. */
703
+ className?: string;
704
+ children: React$1.ReactNode;
705
+ /** When true, inject the default theme CSS variables (light/dark). Your app must still use Tailwind. */
706
+ injectStyles?: boolean;
707
+ }
708
+ declare function ThemeProvider({ theme, defaultTheme, storageKey, className, children, injectStyles, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
569
709
 
570
710
  declare function extractErrorMessage(error: unknown): string;
571
711
 
572
712
  declare function getSignerPublicKey(walletId: string, signer: SignerData, signerType: string, signerId: string): Promise<PublicKey>;
573
713
 
574
- declare function signMessageWithSigner(walletId: string, signer: SignerData, messageText: string): Promise<{
714
+ /** Result shape aligned with SDK SignMessageDataDto (signature base64, message) plus optional helper fields. */
715
+ interface SignMessageResult {
716
+ /** Signature in base64 (SDK SignMessageDataDto shape). */
575
717
  signature: string;
718
+ /** Original message that was signed (SDK SignMessageDataDto shape). */
719
+ message: string;
576
720
  publicKey?: string;
577
721
  signerType: string;
578
722
  signer?: string;
579
- }>;
723
+ }
724
+ declare function signMessageWithSigner(walletId: string, signer: SignerData, messageText: string): Promise<SignMessageResult>;
580
725
 
581
726
  /** Connection-like interface for sign-and-send (passkey). Consumer provides from their Solana config. */
582
727
  interface SignAndSendConnection {
@@ -590,14 +735,19 @@ interface SignAndSendConnection {
590
735
  lastValidBlockHeight: number;
591
736
  }) => Promise<void>;
592
737
  }
738
+ /** SDK submit transaction data (SubmitTransactionResponseDto.data). */
739
+ type SubmitTransactionDataDto = WalletControllerSubmitTransactionResult["data"];
593
740
  declare function signTransactionWithSigner(walletId: string, signer: SignerData, transactionBuffer: Uint8Array): Promise<{
594
741
  signature: string;
595
742
  signerType: string;
596
743
  }>;
597
- declare function signAndSendTransactionWithSigner(walletId: string, signer: SignerData, transaction: Transaction, connection?: SignAndSendConnection | null): Promise<{
744
+ /** Result of sign-and-send; status is the SDK SubmitTransactionDataDto.status, confirmationStatus is the same for backward compat. */
745
+ interface SignAndSendResult {
598
746
  signature: string;
747
+ status: string;
599
748
  confirmationStatus: string;
600
- }>;
749
+ }
750
+ declare function signAndSendTransactionWithSigner(walletId: string, signer: SignerData, transaction: Transaction, connection?: SignAndSendConnection | null): Promise<SignAndSendResult>;
601
751
 
602
752
  declare function getWalletData(walletId: string): Promise<{
603
753
  walletPublicKey: PublicKey;
@@ -613,4 +763,4 @@ declare const SIGNER_TYPES: {
613
763
  };
614
764
  type SignerType = (typeof SIGNER_TYPES)[keyof typeof SIGNER_TYPES];
615
765
 
616
- export { type ActionState, AddSignerForm, type AddSignerFormClassNames, type AddSignerFormProps, type AddSignerType, type ApiResponse, AuthForm, type AuthFormClassNames, type AuthFormMode, type AuthFormProps, AuthGuard, type AuthGuardClassNames, type AuthGuardProps, type CilantroAuthContextType, CilantroAuthProvider, type CilantroAuthProviderProps, CilantroProvider, type DelegatedKeyData, DelegatedKeySelector, type DelegatedKeySelectorClassNames, type DelegatedKeySelectorProps, type ErrorResponse, LoginForm, type LoginFormClassNames, type LoginFormProps, MessageSigningForm, type MessageSigningFormClassNames, type MessageSigningFormProps, RegisterForm, type RegisterFormClassNames, type RegisterFormProps, SIGNER_TYPES, type SignAndSendConnection, type SignerData, SignerList, type SignerListClassNames, type SignerListProps, SignerSelector, type SignerSelectorClassNames, type SignerSelectorProps, type SignerType, type SigningMethod, TransactionSigningForm, type TransactionSigningFormClassNames, type TransactionSigningFormProps, type UseMessageSigningOptions, type UseMessageSigningResult, type UseSignerSelectionOptions, type UseSignerSelectionResult, type UseSignersOptions, type UseSignersResult, type UseTransactionSigningOptions, type UseTransactionSigningResult, type User, type WalletContextType, type WalletData, WalletProvider, type WalletProviderProps, WalletSelector, type WalletSelectorClassNames, type WalletSelectorProps, extractErrorMessage, extractResponseData, getSignerPublicKey, getWalletData, signAndSendTransactionWithSigner, signMessageWithSigner, signTransactionWithSigner, useCilantroAuth, useMessageSigning, useSignerSelection, useSigners, useTransactionSigning, useWallets };
766
+ export { type ActionState, AddSignerForm, type AddSignerFormClassNames, type AddSignerFormProps, type AddSignerType, type ApiResponse, AuthForm, type AuthFormClassNames, type AuthFormMode, type AuthFormProps, AuthGuard, type AuthGuardClassNames, type AuthGuardProps, type CilantroAuthContextType, CilantroAuthProvider, type CilantroAuthProviderProps, CilantroProvider, type DelegatedKeyData, type DelegatedKeyDataDto, DelegatedKeySelector, type DelegatedKeySelectorClassNames, type DelegatedKeySelectorProps, type ErrorResponse, LoginForm, type LoginFormClassNames, type LoginFormProps, MessageSigningForm, type MessageSigningFormClassNames, type MessageSigningFormProps, RegisterForm, type RegisterFormClassNames, type RegisterFormProps, type ResolvedTheme, SIGNER_TYPES, type SignAndSendConnection, type SignAndSendResult, type SignMessageResult, type SignerData, SignerList, type SignerListClassNames, type SignerListProps, SignerSelector, type SignerSelectorClassNames, type SignerSelectorProps, type SignerType, type SignersListResponseDto, type SigningMethod, Skeleton, type SubmitTransactionDataDto, type Theme, ThemeProvider, type ThemeProviderProps, TransactionSigningForm, type TransactionSigningFormClassNames, type TransactionSigningFormProps, type UseCanSignOptions, type UseCanSignResult, type UseDelegatedKeysOptions, type UseDelegatedKeysResult, type UseMessageSigningOptions, type UseMessageSigningResult, type UseSelectedWalletResult, type UseSignerSelectionOptions, type UseSignerSelectionResult, type UseSignersForSelectedWalletOptions, type UseSignersOptions, type UseSignersRawOptions, type UseSignersRawResult, type UseSignersResult, type UseTransactionSigningOptions, type UseTransactionSigningResult, type User, type WalletContextType, type WalletData, type WalletDataDto, WalletProvider, type WalletProviderProps, WalletSelector, type WalletSelectorClassNames, type WalletSelectorProps, extractErrorMessage, extractResponseData, getSignerPublicKey, getWalletData, signAndSendTransactionWithSigner, signMessageWithSigner, signTransactionWithSigner, useCanSign, useCilantroAuth, useDelegatedKeys, useMessageSigning, useSelectedWallet, useSignerSelection, useSigners, useSignersForSelectedWallet, useSignersRaw, useTransactionSigning, useWalletAddress, useWallets };