@cookill/wallet-adapter 2.5.4 → 3.1.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/dist/index.d.ts CHANGED
@@ -1,12 +1,29 @@
1
1
  /**
2
- * @cookill/wallet-adapter v2.5.0
3
- * Sheep Wallet adapter for Rialo blockchain dApps
2
+ * @cookill/wallet-adapter v3.1.0
3
+ * Core type definitions
4
+ *
5
+ * Includes support for:
6
+ * - REX (Rialo Extended Execution) — confidential computation transactions
7
+ * - SfS (Stake-for-Service) — gasless transactions via staking yield
8
+ * - Scan-to-Connect — QR-based cross-device wallet pairing
4
9
  */
5
- type RialoChain = 'rialo:mainnet' | 'rialo:testnet' | 'rialo:devnet' | 'rialo:localnet';
6
10
  type RialoNetwork = 'mainnet' | 'testnet' | 'devnet' | 'localnet';
11
+ type RialoChainId = `rialo:${RialoNetwork}`;
12
+ interface NetworkConfig {
13
+ chainId: RialoChainId;
14
+ name: string;
15
+ rpcUrl: string;
16
+ wsUrl?: string;
17
+ explorerUrl?: string;
18
+ symbol: string;
19
+ decimals: number;
20
+ supportsREX?: boolean;
21
+ supportsSfS?: boolean;
22
+ }
23
+ declare const NETWORKS: Record<RialoNetwork, NetworkConfig>;
7
24
  interface WalletAccount {
8
25
  address: string;
9
- publicKey?: Uint8Array | string;
26
+ publicKey?: string | Uint8Array;
10
27
  label?: string;
11
28
  }
12
29
  interface TransactionRequest {
@@ -14,12 +31,20 @@ interface TransactionRequest {
14
31
  value: string;
15
32
  data?: string;
16
33
  memo?: string;
34
+ /** If true, attempt to pay gas via Stake-for-Service credits */
35
+ gasless?: boolean;
36
+ /** REX confidential execution context */
37
+ rex?: REXConfig;
17
38
  }
18
39
  interface TransactionResult {
19
40
  hash: string;
20
41
  signature?: string;
21
42
  status: 'pending' | 'confirmed' | 'failed';
22
43
  blockNumber?: number;
44
+ /** Whether gas was paid via SfS credits */
45
+ gasless?: boolean;
46
+ /** REX execution proof if confidential */
47
+ rexProof?: string;
23
48
  }
24
49
  interface SignedMessage {
25
50
  signature: string;
@@ -29,17 +54,141 @@ interface SignedMessage {
29
54
  }
30
55
  interface BalanceResult {
31
56
  balance: string;
32
- balanceKelvins: string;
33
57
  formatted: string;
34
58
  }
35
- interface NetworkConfig {
36
- chainId: string;
59
+ /**
60
+ * REX enables privacy-preserving computation on Rialo.
61
+ * Transactions can be executed confidentially using TEEs, MPC, or FHE
62
+ * without exposing inputs to the public blockchain.
63
+ */
64
+ /** Privacy technology used for confidential computation */
65
+ type REXPrivacyMode = 'tee' | 'mpc' | 'fhe' | 'auto';
66
+ interface REXConfig {
67
+ /** Enable confidential execution */
68
+ confidential: boolean;
69
+ /** Privacy technology to use (default: 'auto' — protocol selects optimal) */
70
+ privacyMode?: REXPrivacyMode;
71
+ /** Encrypted inputs (base64-encoded ciphertext) */
72
+ encryptedInputs?: string;
73
+ /** REX program ID to execute */
74
+ programId?: string;
75
+ /** Whether output should remain encrypted for future computation */
76
+ keepEncrypted?: boolean;
77
+ /** Access control — who can decrypt the result */
78
+ accessPolicy?: REXAccessPolicy;
79
+ }
80
+ interface REXAccessPolicy {
81
+ /** Addresses allowed to decrypt the result */
82
+ allowedDecryptors: string[];
83
+ /** Expiry timestamp (ms) for access */
84
+ expiresAt?: number;
85
+ }
86
+ interface REXTransactionResult extends TransactionResult {
87
+ /** Attestation proof from TEE/MPC */
88
+ attestation?: string;
89
+ /** Encrypted output (if keepEncrypted was true) */
90
+ encryptedOutput?: string;
91
+ /** Public output (if computation produced public results) */
92
+ publicOutput?: string;
93
+ }
94
+ /** REX capabilities query result */
95
+ interface REXCapabilities {
96
+ supported: boolean;
97
+ privacyModes: REXPrivacyMode[];
98
+ maxInputSize: number;
99
+ programs: string[];
100
+ }
101
+ /**
102
+ * SfS converts staking yield into service credits that automatically
103
+ * pay for network costs (gas, storage, scheduled executions).
104
+ * Users stake RLO, set a routing fraction, and the ServicePaymaster
105
+ * mints credits from their yield.
106
+ */
107
+ interface SfSPosition {
108
+ /** Position ID */
109
+ id: string;
110
+ /** Staked principal in kelvins */
111
+ principal: string;
112
+ /** Validator/pool receiving the delegation */
113
+ validator: string;
114
+ /** Fraction of yield routed to service credits (0.0 - 1.0) */
115
+ routingFraction: number;
116
+ /** Current service credit balance */
117
+ creditBalance: string;
118
+ /** Estimated credits per epoch */
119
+ creditsPerEpoch: string;
120
+ /** Position status */
121
+ status: 'active' | 'pending' | 'closed';
122
+ /** Creation timestamp */
123
+ createdAt: number;
124
+ }
125
+ interface SfSCreateParams {
126
+ /** Amount of RLO to stake (in kelvins) */
127
+ amount: string;
128
+ /** Validator address to delegate to */
129
+ validator: string;
130
+ /** Fraction of yield to route to service credits (0.0 - 1.0) */
131
+ routingFraction: number;
132
+ }
133
+ interface SfSUpdateParams {
134
+ /** Position ID to update */
135
+ positionId: string;
136
+ /** New routing fraction (0.0 - 1.0) */
137
+ routingFraction?: number;
138
+ }
139
+ interface SfSCreditBalance {
140
+ /** Available service credits */
141
+ available: string;
142
+ /** Credits used this epoch */
143
+ usedThisEpoch: string;
144
+ /** Total credits earned */
145
+ totalEarned: string;
146
+ /** Estimated credits per epoch */
147
+ estimatedPerEpoch: string;
148
+ }
149
+ /**
150
+ * Enables connecting a wallet on one device to a dApp on another device
151
+ * via QR code scanning. Supports bidirectional flow:
152
+ * - dApp shows QR → wallet scans to connect
153
+ * - Wallet shows QR → dApp scans to connect
154
+ */
155
+ interface ScanConnectSession {
156
+ /** Unique session identifier */
157
+ sessionId: string;
158
+ /** Session topic for relay */
159
+ topic: string;
160
+ /** Relay server URL */
161
+ relay: string;
162
+ /** Session encryption key (hex) */
163
+ symmetricKey: string;
164
+ /** Originator: 'dapp' or 'wallet' */
165
+ origin: 'dapp' | 'wallet';
166
+ /** dApp metadata */
167
+ dappMetadata?: ScanConnectDAppMetadata;
168
+ /** Wallet metadata */
169
+ walletMetadata?: ScanConnectWalletMetadata;
170
+ /** Requested chain IDs */
171
+ chains: RialoChainId[];
172
+ /** Expiry timestamp */
173
+ expiresAt: number;
174
+ }
175
+ interface ScanConnectDAppMetadata {
37
176
  name: string;
38
- rpcUrl: string;
39
- wsUrl?: string;
40
- explorerUrl?: string;
41
- symbol: string;
42
- decimals: number;
177
+ url: string;
178
+ icon?: string;
179
+ description?: string;
180
+ }
181
+ interface ScanConnectWalletMetadata {
182
+ name: string;
183
+ icon?: string;
184
+ version?: string;
185
+ }
186
+ /** URI format for scan-to-connect QR codes */
187
+ interface ScanConnectURI {
188
+ /** Full URI string (rialo-wc://...) */
189
+ uri: string;
190
+ /** Parsed session info */
191
+ session: ScanConnectSession;
43
192
  }
44
193
  interface WalletInfo {
45
194
  id: string;
@@ -47,94 +196,213 @@ interface WalletInfo {
47
196
  icon: string;
48
197
  installed?: boolean;
49
198
  downloadUrl?: string;
199
+ supportsREX?: boolean;
200
+ supportsSfS?: boolean;
201
+ supportsScanConnect?: boolean;
50
202
  }
51
- type WalletEvent = 'connect' | 'disconnect' | 'accountsChanged' | 'networkChanged' | 'chainChanged' | 'error';
52
- declare const NETWORKS: Record<RialoNetwork, NetworkConfig>;
203
+ type WalletEventType = 'connect' | 'disconnect' | 'accountsChanged' | 'networkChanged' | 'chainChanged' | 'scanConnect' | 'sfsUpdate' | 'error';
53
204
  interface RialoProvider {
54
205
  isRialo: boolean;
55
206
  isSheepWallet?: boolean;
56
- name?: string;
57
- walletName?: string;
58
207
  version: string;
59
- icon?: string;
60
208
  connect(options?: {
61
209
  silent?: boolean;
62
- }): Promise<WalletAccount[]>;
210
+ }): Promise<Array<string | WalletAccount>>;
63
211
  disconnect(): Promise<void>;
64
212
  isConnected(): Promise<boolean>;
65
- getAccounts(): Promise<WalletAccount[]>;
213
+ getAccounts(): Promise<Array<string | WalletAccount>>;
66
214
  signTransaction(tx: TransactionRequest): Promise<{
67
215
  signature: string;
68
- signedTransaction?: string;
69
216
  rawTransaction?: string;
70
217
  }>;
71
218
  sendTransaction(tx: TransactionRequest): Promise<TransactionResult>;
72
219
  signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult>;
73
- signAllTransactions?(txs: TransactionRequest[]): Promise<{
74
- signedTransactions: string[];
75
- }>;
76
220
  signMessage(message: string | Uint8Array): Promise<SignedMessage>;
77
221
  getNetwork(): Promise<RialoNetwork>;
78
222
  switchNetwork(network: RialoNetwork): Promise<{
79
223
  success: boolean;
80
224
  }>;
81
- getChainId(): Promise<string>;
82
225
  getBalance(address?: string): Promise<BalanceResult | string>;
83
- on(event: WalletEvent, callback: (data: unknown) => void): () => void;
84
- off?(event: WalletEvent, callback: (data: unknown) => void): void;
85
- removeListener(event: WalletEvent, callback: (data: unknown) => void): void;
86
- removeAllListeners(event?: WalletEvent): void;
87
- utils?: {
88
- isValidAddress(address: string): boolean;
89
- formatAddress(address: string, chars?: number): string;
90
- };
91
- features?: string[];
92
- supportsFeature?(feature: string): boolean;
93
- readonly connected?: boolean;
94
- readonly accounts?: WalletAccount[];
95
- readonly address?: string | null;
96
- readonly publicKey?: string | null;
97
- readonly network?: RialoNetwork;
98
- readonly chainId?: string;
99
- }
100
- declare function isRialoInstalled(): boolean;
101
- declare function getRialoProvider(): RialoProvider | undefined;
102
- declare function waitForRialoProvider(timeout?: number): Promise<RialoProvider | undefined>;
103
- declare class RialoWallet {
104
- private provider;
226
+ getREXCapabilities?(): Promise<REXCapabilities>;
227
+ submitREXTransaction?(tx: TransactionRequest): Promise<REXTransactionResult>;
228
+ getSfSPositions?(): Promise<SfSPosition[]>;
229
+ createSfSPosition?(params: SfSCreateParams): Promise<SfSPosition>;
230
+ updateSfSPosition?(params: SfSUpdateParams): Promise<SfSPosition>;
231
+ closeSfSPosition?(positionId: string): Promise<{
232
+ success: boolean;
233
+ }>;
234
+ getSfSCredits?(): Promise<SfSCreditBalance>;
235
+ createScanSession?(origin: 'wallet'): Promise<ScanConnectURI>;
236
+ approveScanSession?(sessionId: string): Promise<WalletAccount[]>;
237
+ rejectScanSession?(sessionId: string): Promise<void>;
238
+ on(event: WalletEventType, callback: (data: unknown) => void): () => void;
239
+ removeListener(event: WalletEventType, callback: (data: unknown) => void): void;
240
+ removeAllListeners(event?: WalletEventType): void;
241
+ }
242
+ declare global {
243
+ interface Window {
244
+ rialo?: RialoProvider;
245
+ }
246
+ }
247
+
248
+ /**
249
+ * @cookill/wallet-adapter v3.0.0
250
+ * Provider detection and access utilities
251
+ *
252
+ * CRITICAL: All provider access is non-blocking and defensive
253
+ */
254
+
255
+ /**
256
+ * Check if Rialo/Sheep Wallet is installed
257
+ * This is synchronous and never blocks
258
+ */
259
+ declare function isInstalled(): boolean;
260
+ /**
261
+ * Get the provider reference (synchronous)
262
+ * Returns undefined if not installed
263
+ */
264
+ declare function getProvider(): RialoProvider | undefined;
265
+ /**
266
+ * Wait for provider to become available
267
+ * Uses polling + event listener, with guaranteed timeout
268
+ *
269
+ * @param timeout Maximum time to wait in ms (default 3000)
270
+ */
271
+ declare function waitForProvider(timeout?: number): Promise<RialoProvider | undefined>;
272
+ /**
273
+ * Promise timeout wrapper
274
+ * Ensures promises never hang indefinitely
275
+ */
276
+ declare function withTimeout<T>(promise: Promise<T>, ms: number, errorMessage?: string): Promise<T>;
277
+
278
+ /**
279
+ * @cookill/wallet-adapter v3.0.0
280
+ * Utility functions
281
+ */
282
+
283
+ /**
284
+ * Format address for display (truncated)
285
+ */
286
+ declare function formatAddress(address: string, chars?: number): string;
287
+ /**
288
+ * Format balance from kelvins to RLO
289
+ */
290
+ declare function formatBalance(kelvins: string | bigint, decimals?: number): string;
291
+ /**
292
+ * Parse RLO amount to kelvins
293
+ */
294
+ declare function parseBalance(rlo: string | number): bigint;
295
+ /**
296
+ * Validate Rialo address format
297
+ */
298
+ declare function isValidAddress(address: string): boolean;
299
+ /**
300
+ * Convert network name to chain ID
301
+ */
302
+ declare function toChainId(network: RialoNetwork): RialoChainId;
303
+ /**
304
+ * Extract network from chain ID
305
+ */
306
+ declare function fromChainId(chainId: RialoChainId): RialoNetwork;
307
+ /**
308
+ * Normalize account data (handles both string and object formats)
309
+ * CRITICAL: Extension can return either string[] or WalletAccount[]
310
+ */
311
+ declare function normalizeAccounts(accounts: Array<string | WalletAccount>): WalletAccount[];
312
+
313
+ /**
314
+ * @cookill/wallet-adapter v3.1.0
315
+ * Pure JavaScript wallet class (no React dependency)
316
+ *
317
+ * Supports:
318
+ * - Standard connect/disconnect/sign operations
319
+ * - REX (Rialo Extended Execution) confidential transactions
320
+ * - SfS (Stake-for-Service) gasless transactions
321
+ * - Scan-to-Connect QR-based pairing
322
+ *
323
+ * Usage:
324
+ * const wallet = new SheepWallet();
325
+ * if (!wallet.isInstalled) { ... prompt install ... }
326
+ * const accounts = await wallet.connect();
327
+ */
328
+
329
+ declare class SheepWallet {
330
+ private _provider;
105
331
  private _connected;
106
332
  private _accounts;
107
333
  private _network;
108
- private _listeners;
334
+ private _cleanupFns;
109
335
  constructor();
110
- private setupEvents;
111
336
  get isInstalled(): boolean;
112
337
  get connected(): boolean;
113
338
  get accounts(): WalletAccount[];
114
339
  get activeAccount(): WalletAccount | undefined;
340
+ get address(): string | undefined;
115
341
  get network(): RialoNetwork;
116
342
  get chainId(): string;
117
343
  connect(): Promise<WalletAccount[]>;
118
344
  disconnect(): Promise<void>;
345
+ checkSession(): Promise<WalletAccount[] | null>;
119
346
  signMessage(message: string): Promise<SignedMessage>;
120
347
  signTransaction(tx: TransactionRequest): Promise<string>;
121
348
  sendTransaction(tx: TransactionRequest): Promise<TransactionResult>;
122
349
  signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult>;
350
+ /**
351
+ * Check if the connected wallet/network supports REX
352
+ */
353
+ getREXCapabilities(): Promise<REXCapabilities>;
354
+ /**
355
+ * Submit a confidential transaction via REX
356
+ * The transaction inputs are encrypted and executed in a TEE/MPC/FHE environment
357
+ */
358
+ submitREXTransaction(tx: TransactionRequest): Promise<REXTransactionResult>;
359
+ /**
360
+ * Send a gasless transaction using Stake-for-Service credits
361
+ * Automatically sets tx.gasless = true
362
+ */
363
+ sendGaslessTransaction(tx: Omit<TransactionRequest, 'gasless'>): Promise<TransactionResult>;
364
+ /**
365
+ * Get all Stake-for-Service positions for the connected account
366
+ */
367
+ getSfSPositions(): Promise<SfSPosition[]>;
368
+ /**
369
+ * Create a new Stake-for-Service position
370
+ * Stakes RLO and routes a fraction of yield to service credits
371
+ */
372
+ createSfSPosition(params: SfSCreateParams): Promise<SfSPosition>;
373
+ /**
374
+ * Update an existing SfS position (e.g., change routing fraction)
375
+ */
376
+ updateSfSPosition(params: SfSUpdateParams): Promise<SfSPosition>;
377
+ /**
378
+ * Close an SfS position and unstake
379
+ */
380
+ closeSfSPosition(positionId: string): Promise<{
381
+ success: boolean;
382
+ }>;
383
+ /**
384
+ * Get current SfS service credit balance
385
+ */
386
+ getSfSCredits(): Promise<SfSCreditBalance>;
387
+ /**
388
+ * Generate a scan-to-connect URI from the wallet side
389
+ * Returns a URI that can be displayed as QR code for dApps to scan
390
+ */
391
+ createScanSession(): Promise<ScanConnectURI>;
392
+ /**
393
+ * Approve a scan-to-connect session (after wallet scans dApp QR)
394
+ */
395
+ approveScanSession(sessionId: string): Promise<WalletAccount[]>;
396
+ /**
397
+ * Reject a scan-to-connect session
398
+ */
399
+ rejectScanSession(sessionId: string): Promise<void>;
123
400
  getBalance(address?: string): Promise<string>;
124
401
  switchNetwork(network: RialoNetwork): Promise<void>;
125
- on(event: WalletEvent, callback: (data: unknown) => void): () => void;
126
- }
127
- declare function formatAddress(address: string, chars?: number): string;
128
- declare function formatBalance(kelvins: string | bigint, decimals?: number): string;
129
- declare function parseBalance(rlo: string | number): bigint;
130
- declare function isValidAddress(address: string): boolean;
131
- declare function toChainId(network: RialoNetwork): RialoChain;
132
- declare function fromChainId(chainId: RialoChain): RialoNetwork;
133
- declare global {
134
- interface Window {
135
- rialo?: RialoProvider;
136
- Rialo?: RialoProvider;
137
- }
402
+ on(event: string, callback: (data: unknown) => void): () => void;
403
+ destroy(): void;
404
+ private _ensureConnected;
405
+ private _setupEvents;
138
406
  }
139
407
 
140
- export { type BalanceResult, NETWORKS, type NetworkConfig, type RialoChain, type RialoNetwork, type RialoProvider, RialoWallet, type SignedMessage, type TransactionRequest, type TransactionResult, type WalletAccount, type WalletEvent, type WalletInfo, RialoWallet as default, formatAddress, formatBalance, fromChainId, getRialoProvider, isRialoInstalled, isValidAddress, parseBalance, toChainId, waitForRialoProvider };
408
+ export { type BalanceResult, NETWORKS, type NetworkConfig, type RialoChainId, type RialoNetwork, type RialoProvider, SheepWallet as RialoWallet, SheepWallet, type SignedMessage, type TransactionRequest, type TransactionResult, type WalletAccount, type WalletEventType, type WalletInfo, SheepWallet as default, formatAddress, formatBalance, fromChainId, getProvider, getProvider as getRialoProvider, isInstalled, isInstalled as isRialoInstalled, isValidAddress, normalizeAccounts, parseBalance, toChainId, waitForProvider, waitForProvider as waitForRialoProvider, withTimeout };