@d13co/use-wallet 4.5.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.
@@ -0,0 +1,1410 @@
1
+ import { Store } from '@tanstack/store';
2
+ import algosdk from 'algosdk';
3
+ import AVMWebProviderSDK from '@agoralabs-sh/avm-web-provider';
4
+ import { InstanceWithExtensions, SDKBase } from '@magic-sdk/provider';
5
+ import { AlgorandExtension } from '@magic-ext/algorand';
6
+ import { MagicUserMetadata } from 'magic-sdk';
7
+ import * as liquid_accounts_evm from 'liquid-accounts-evm';
8
+ import { LiquidEvmSdk, SignTypedDataParams } from 'liquid-accounts-evm';
9
+ import { AlgorandClient } from '@algorandfoundation/algokit-utils';
10
+ import { SDKProvider } from '@metamask/sdk';
11
+ import { EIP1193Provider } from 'viem';
12
+ import { WalletConnectModalConfig } from '@walletconnect/modal';
13
+ import { SignClientTypes } from '@walletconnect/types';
14
+
15
+ declare enum LogLevel {
16
+ DEBUG = 0,
17
+ INFO = 1,
18
+ WARN = 2,
19
+ ERROR = 3
20
+ }
21
+ declare class Logger {
22
+ private static instance;
23
+ private level;
24
+ private isClient;
25
+ private constructor();
26
+ static getInstance(): Logger;
27
+ static setLevel(level: LogLevel): void;
28
+ private log;
29
+ createScopedLogger(scope: string): {
30
+ debug: (message: string, ...args: any[]) => void;
31
+ info: (message: string, ...args: any[]) => void;
32
+ warn: (message: string, ...args: any[]) => void;
33
+ error: (message: string, ...args: any[]) => void;
34
+ };
35
+ debug(message: string, ...args: any[]): void;
36
+ info(message: string, ...args: any[]): void;
37
+ warn(message: string, ...args: any[]): void;
38
+ error(message: string, ...args: any[]): void;
39
+ setIsClient(isClient: boolean): void;
40
+ }
41
+ declare const logger: Logger;
42
+
43
+ interface AlgodConfig {
44
+ token: string | algosdk.AlgodTokenHeader | algosdk.CustomTokenHeader | algosdk.BaseHTTPClient;
45
+ baseServer: string;
46
+ port?: string | number;
47
+ headers?: Record<string, string>;
48
+ }
49
+ interface NetworkConfig {
50
+ algod: AlgodConfig;
51
+ genesisHash?: string;
52
+ genesisId?: string;
53
+ isTestnet?: boolean;
54
+ caipChainId?: string;
55
+ }
56
+ declare const DEFAULT_NETWORK_CONFIG: Record<string, NetworkConfig>;
57
+ type DefaultNetworkConfig = Omit<Partial<NetworkConfig>, 'genesisHash' | 'genesisId' | 'caipChainId'>;
58
+ declare class NetworkConfigBuilder {
59
+ private networks;
60
+ constructor();
61
+ mainnet(config: DefaultNetworkConfig): this;
62
+ testnet(config: DefaultNetworkConfig): this;
63
+ betanet(config: DefaultNetworkConfig): this;
64
+ fnet(config: DefaultNetworkConfig): this;
65
+ localnet(config: Partial<NetworkConfig>): this;
66
+ addNetwork(id: string, config: NetworkConfig): this;
67
+ build(): {
68
+ [k: string]: NetworkConfig;
69
+ };
70
+ }
71
+ declare enum NetworkId {
72
+ MAINNET = "mainnet",
73
+ TESTNET = "testnet",
74
+ BETANET = "betanet",
75
+ FNET = "fnet",
76
+ LOCALNET = "localnet"
77
+ }
78
+
79
+ declare abstract class BaseWallet {
80
+ readonly id: WalletId;
81
+ /** Unique key for this wallet instance. Used for state storage and session isolation. */
82
+ readonly walletKey: WalletKey;
83
+ readonly metadata: WalletMetadata;
84
+ protected store: Store<State>;
85
+ protected getAlgodClient: () => algosdk.Algodv2;
86
+ protected managerUIHooks: UIHooks;
87
+ subscribe: (callback: (state: State) => void) => () => void;
88
+ protected logger: ReturnType<typeof logger.createScopedLogger>;
89
+ protected constructor({ id, walletKey, metadata, store, subscribe, getAlgodClient, managerUIHooks }: WalletConstructor<WalletId>);
90
+ static defaultMetadata: WalletMetadata;
91
+ abstract connect(args?: Record<string, any>): Promise<WalletAccount[]>;
92
+ abstract disconnect(): Promise<void>;
93
+ abstract resumeSession(): Promise<void>;
94
+ setActive: () => void;
95
+ setActiveAccount: (account: string) => void;
96
+ abstract signTransactions<T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]): Promise<(Uint8Array | null)[]>;
97
+ transactionSigner: (txnGroup: algosdk.Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>;
98
+ canSignData: boolean;
99
+ signData: (_data: string, _metadata: SignMetadata) => Promise<SignDataResponse>;
100
+ get name(): string;
101
+ get accounts(): WalletAccount[];
102
+ get addresses(): string[];
103
+ get activeAccount(): WalletAccount | null;
104
+ get activeAddress(): string | null;
105
+ get activeNetwork(): string;
106
+ get isConnected(): boolean;
107
+ get isActive(): boolean;
108
+ get activeNetworkConfig(): NetworkConfig;
109
+ protected onDisconnect: () => void;
110
+ protected manageWalletConnectSession: (action: "backup" | "restore", targetWalletKey?: WalletKey) => void;
111
+ }
112
+
113
+ type CustomProvider = {
114
+ connect(args?: Record<string, any>): Promise<WalletAccount[]>;
115
+ disconnect?(): Promise<void>;
116
+ resumeSession?(): Promise<WalletAccount[] | void>;
117
+ signTransactions?<T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]): Promise<(Uint8Array | null)[]>;
118
+ transactionSigner?(txnGroup: algosdk.Transaction[], indexesToSign: number[]): Promise<Uint8Array[]>;
119
+ signData?(data: string, metadata: SignMetadata): Promise<SignDataResponse>;
120
+ };
121
+ interface CustomWalletOptions {
122
+ provider: CustomProvider;
123
+ }
124
+ declare class CustomWallet extends BaseWallet {
125
+ private provider;
126
+ protected store: Store<State>;
127
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.CUSTOM>);
128
+ static defaultMetadata: {
129
+ name: string;
130
+ icon: string;
131
+ };
132
+ connect: (args?: Record<string, any>) => Promise<WalletAccount[]>;
133
+ disconnect: () => Promise<void>;
134
+ resumeSession: () => Promise<void>;
135
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
136
+ transactionSigner: (txnGroup: algosdk.Transaction[], indexesToSign: number[]) => Promise<Uint8Array[]>;
137
+ signData: (data: string, metadata: SignMetadata) => Promise<SignDataResponse>;
138
+ }
139
+
140
+ interface DeflyWalletConnectOptions {
141
+ bridge?: string;
142
+ shouldShowSignTxnToast?: boolean;
143
+ chainId?: 416001 | 416002 | 416003 | 4160;
144
+ }
145
+ declare class DeflyWallet extends BaseWallet {
146
+ private client;
147
+ private options;
148
+ protected store: Store<State>;
149
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.DEFLY>);
150
+ static defaultMetadata: {
151
+ name: string;
152
+ icon: string;
153
+ };
154
+ private initializeClient;
155
+ connect: () => Promise<WalletAccount[]>;
156
+ disconnect: () => Promise<void>;
157
+ setActive: () => void;
158
+ resumeSession: () => Promise<void>;
159
+ private processTxns;
160
+ private processEncodedTxns;
161
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
162
+ }
163
+
164
+ declare abstract class AVMProvider extends BaseWallet {
165
+ avmWebClient: AVMWebProviderSDK.AVMWebClient | null;
166
+ protected avmWebProviderSDK: typeof AVMWebProviderSDK | null;
167
+ protected providerId: string;
168
+ constructor(args: WalletConstructor<WalletId> & {
169
+ providerId: string;
170
+ });
171
+ protected _initializeAVMWebProviderSDK(): Promise<typeof AVMWebProviderSDK>;
172
+ protected _initializeAVMWebClient(): Promise<AVMWebProviderSDK.AVMWebClient>;
173
+ protected _getGenesisHash(): Promise<string>;
174
+ protected _mapAVMWebProviderAccountToWalletAccounts(accounts: AVMWebProviderSDK.IAccount[]): WalletAccount[];
175
+ protected processTxns(txnGroup: algosdk.Transaction[], indexesToSign?: number[]): AVMWebProviderSDK.IARC0001Transaction[];
176
+ protected processEncodedTxns(txnGroup: Uint8Array[], indexesToSign?: number[]): AVMWebProviderSDK.IARC0001Transaction[];
177
+ /**
178
+ * Abstract methods
179
+ * These methods must be implemented by specific wallet providers
180
+ */
181
+ protected abstract _enable(): Promise<AVMWebProviderSDK.IEnableResult>;
182
+ protected abstract _disable(): Promise<AVMWebProviderSDK.IDisableResult>;
183
+ protected abstract _signTransactions(txns: AVMWebProviderSDK.IARC0001Transaction[]): Promise<AVMWebProviderSDK.ISignTransactionsResult>;
184
+ /**
185
+ * Common methods
186
+ * These methods can be overridden by specific wallet providers if needed
187
+ */
188
+ connect(): Promise<WalletAccount[]>;
189
+ disconnect(): Promise<void>;
190
+ resumeSession(): Promise<void>;
191
+ signTransactions<T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]): Promise<(Uint8Array | null)[]>;
192
+ }
193
+
194
+ declare const DEFLY_WEB_PROVIDER_ID = "95426e60-5f2e-49e9-b912-c488577be962";
195
+ declare class DeflyWebWallet extends AVMProvider {
196
+ constructor({ id, store, subscribe, getAlgodClient, metadata }: WalletConstructor<WalletId.DEFLY_WEB>);
197
+ static defaultMetadata: {
198
+ name: string;
199
+ icon: string;
200
+ };
201
+ /**
202
+ * Calls the "enable" method on the provider. This method will timeout after 3 minutes.
203
+ * @returns {Promise<AVMWebProviderSDK.IEnableResult>} a promise that resolves to the result.
204
+ * @protected
205
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
206
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
207
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
208
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
209
+ * @throws {UnknownError} if the response result is empty.
210
+ */
211
+ protected _enable(): Promise<AVMWebProviderSDK.IEnableResult>;
212
+ /**
213
+ * Calls the "disable" method on the provider. This method will timeout after 0.75 seconds.
214
+ * @returns {Promise<AVMWebProviderSDK.IDisableResult>} a promise that resolves to the result.
215
+ * @protected
216
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
217
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
218
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
219
+ * @throws {UnknownError} if the response result is empty.
220
+ */
221
+ protected _disable(): Promise<AVMWebProviderSDK.IDisableResult>;
222
+ /**
223
+ * Calls the "signTransactions" method to sign the supplied ARC-0001 transactions. This method will timeout after 3
224
+ * minutes.
225
+ * @returns {Promise<AVMWebProviderSDK.ISignTransactionsResult>} a promise that resolves to the result.
226
+ * @protected
227
+ * @throws {InvalidInputError} if computed group ID for the txns does not match the assigned group ID.
228
+ * @throws {InvalidGroupIdError} if the unsigned txns is malformed or not conforming to ARC-0001.
229
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
230
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
231
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
232
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
233
+ * @throws {UnauthorizedSignerError} if a signer in the request is not authorized by the provider.
234
+ * @throws {UnknownError} if the response result is empty.
235
+ */
236
+ protected _signTransactions(txns: AVMWebProviderSDK.IARC0001Transaction[]): Promise<AVMWebProviderSDK.ISignTransactionsResult>;
237
+ }
238
+
239
+ /** @see https://docs.exodus.com/api-reference/algorand-provider-arc-api/ */
240
+ interface EnableNetworkOpts {
241
+ genesisID?: string;
242
+ genesisHash?: string;
243
+ }
244
+ interface EnableAccountsOpts {
245
+ accounts?: string[];
246
+ }
247
+ type ExodusOptions = EnableNetworkOpts & EnableAccountsOpts;
248
+ interface EnableNetworkResult {
249
+ genesisID: string;
250
+ genesisHash: string;
251
+ }
252
+ interface EnableAccountsResult {
253
+ accounts: string[];
254
+ }
255
+ type EnableResult = EnableNetworkResult & EnableAccountsResult;
256
+ type SignTxnsResult = (string | null)[];
257
+ interface Exodus {
258
+ isConnected: boolean;
259
+ address: string | null;
260
+ enable: (options?: ExodusOptions) => Promise<EnableResult>;
261
+ signTxns: (transactions: WalletTransaction[]) => Promise<SignTxnsResult>;
262
+ }
263
+ type WindowExtended = {
264
+ algorand: Exodus;
265
+ } & Window & typeof globalThis;
266
+ declare class ExodusWallet extends BaseWallet {
267
+ private client;
268
+ private options;
269
+ protected store: Store<State>;
270
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.EXODUS>);
271
+ static defaultMetadata: {
272
+ name: string;
273
+ icon: string;
274
+ };
275
+ private initializeClient;
276
+ connect: () => Promise<WalletAccount[]>;
277
+ disconnect: () => Promise<void>;
278
+ resumeSession: () => Promise<void>;
279
+ private processTxns;
280
+ private processEncodedTxns;
281
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
282
+ }
283
+
284
+ declare const KIBISIS_AVM_WEB_PROVIDER_ID = "f6d1c86b-4493-42fb-b88d-a62407b4cdf6";
285
+ declare const ICON: string;
286
+ declare class KibisisWallet extends AVMProvider {
287
+ constructor({ id, store, subscribe, getAlgodClient, metadata }: WalletConstructor<WalletId.KIBISIS>);
288
+ static defaultMetadata: {
289
+ name: string;
290
+ icon: string;
291
+ };
292
+ /**
293
+ * Calls the "enable" method on the provider. This method will timeout after 3 minutes.
294
+ * @returns {Promise<AVMWebProviderSDK.IEnableResult>} a promise that resolves to the result.
295
+ * @protected
296
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
297
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
298
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
299
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
300
+ * @throws {UnknownError} if the response result is empty.
301
+ */
302
+ protected _enable(): Promise<AVMWebProviderSDK.IEnableResult>;
303
+ /**
304
+ * Calls the "disable" method on the provider. This method will timeout after 0.75 seconds.
305
+ * @returns {Promise<AVMWebProviderSDK.IDisableResult>} a promise that resolves to the result.
306
+ * @protected
307
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
308
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
309
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
310
+ * @throws {UnknownError} if the response result is empty.
311
+ */
312
+ protected _disable(): Promise<AVMWebProviderSDK.IDisableResult>;
313
+ /**
314
+ * Calls the "signTransactions" method to sign the supplied ARC-0001 transactions. This method will timeout after 3
315
+ * minutes.
316
+ * @returns {Promise<AVMWebProviderSDK.ISignTransactionsResult>} a promise that resolves to the result.
317
+ * @protected
318
+ * @throws {InvalidInputError} if computed group ID for the txns does not match the assigned group ID.
319
+ * @throws {InvalidGroupIdError} if the unsigned txns is malformed or not conforming to ARC-0001.
320
+ * @throws {MethodCanceledError} if the method was cancelled by the user.
321
+ * @throws {MethodNotSupportedError} if the method is not supported for the configured network.
322
+ * @throws {MethodTimedOutError} if the method timed out by lack of response (>= 3 minutes).
323
+ * @throws {NetworkNotSupportedError} if the network is not supported for the configured network.
324
+ * @throws {UnauthorizedSignerError} if a signer in the request is not authorized by the provider.
325
+ * @throws {UnknownError} if the response result is empty.
326
+ */
327
+ protected _signTransactions(txns: AVMWebProviderSDK.IARC0001Transaction[]): Promise<AVMWebProviderSDK.ISignTransactionsResult>;
328
+ }
329
+
330
+ interface KmdConstructor {
331
+ token: string | algosdk.KMDTokenHeader | algosdk.CustomTokenHeader;
332
+ baseServer?: string;
333
+ port?: string | number;
334
+ headers?: Record<string, string>;
335
+ promptForPassword: () => Promise<string>;
336
+ }
337
+ type KmdOptions = Partial<Pick<KmdConstructor, 'token' | 'promptForPassword'>> & Omit<KmdConstructor, 'token' | 'promptForPassword'> & {
338
+ wallet?: string;
339
+ };
340
+ declare class KmdWallet extends BaseWallet {
341
+ private client;
342
+ private options;
343
+ private walletName;
344
+ private walletId;
345
+ private password;
346
+ protected store: Store<State>;
347
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.KMD>);
348
+ static defaultMetadata: {
349
+ name: string;
350
+ icon: string;
351
+ };
352
+ private initializeClient;
353
+ connect: () => Promise<WalletAccount[]>;
354
+ disconnect: () => Promise<void>;
355
+ resumeSession: () => Promise<void>;
356
+ private processTxns;
357
+ private processEncodedTxns;
358
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
359
+ private fetchWalletId;
360
+ private fetchToken;
361
+ private releaseToken;
362
+ private getPassword;
363
+ private fetchAccounts;
364
+ }
365
+
366
+ interface LuteConnectOptions {
367
+ siteName?: string;
368
+ }
369
+ declare class LuteWallet extends BaseWallet {
370
+ private client;
371
+ private options;
372
+ protected store: Store<State>;
373
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.LUTE>);
374
+ static defaultMetadata: {
375
+ name: string;
376
+ icon: string;
377
+ };
378
+ private initializeClient;
379
+ private getGenesisId;
380
+ connect: () => Promise<WalletAccount[]>;
381
+ disconnect: () => Promise<void>;
382
+ resumeSession: () => Promise<void>;
383
+ private processTxns;
384
+ private processEncodedTxns;
385
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
386
+ canSignData: boolean;
387
+ signData: (data: string, metadata: SignMetadata) => Promise<SignDataResponse>;
388
+ }
389
+
390
+ /** @see https://magic.link/docs/blockchains/other-chains/other/algorand */
391
+ interface MagicAuthOptions {
392
+ apiKey?: string;
393
+ }
394
+ type MagicAuthClient = InstanceWithExtensions<SDKBase, {
395
+ algorand: AlgorandExtension;
396
+ }>;
397
+ declare class MagicAuth extends BaseWallet {
398
+ private client;
399
+ private options;
400
+ protected store: Store<State>;
401
+ userInfo: MagicUserMetadata | null;
402
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.MAGIC>);
403
+ static defaultMetadata: {
404
+ name: string;
405
+ icon: string;
406
+ };
407
+ private initializeClient;
408
+ connect: (args?: Record<string, any>) => Promise<WalletAccount[]>;
409
+ disconnect: () => Promise<void>;
410
+ resumeSession: () => Promise<void>;
411
+ private processTxns;
412
+ private processEncodedTxns;
413
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
414
+ }
415
+
416
+ interface EvmAccount {
417
+ evmAddress: string;
418
+ algorandAddress: string;
419
+ }
420
+ interface LiquidEvmOptions {
421
+ uiHooks?: {
422
+ onConnect?: (evmAccount: EvmAccount) => void;
423
+ onBeforeSign?: (txnGroup: algosdk.Transaction[] | Uint8Array[], indexesToSign?: number[]) => Promise<void>;
424
+ onAfterSign?: (success: boolean, errorMessage?: string) => void;
425
+ };
426
+ }
427
+ /**
428
+ * Abstract base class for EVM-based wallets that use the Liquid Accounts system
429
+ * to derive Algorand addresses from EVM addresses.
430
+ *
431
+ * This class provides common functionality for:
432
+ * - Initializing the Liquid EVM SDK
433
+ * - Deriving Algorand accounts from EVM addresses
434
+ * - Signing Algorand transactions using EVM signatures
435
+ * - Managing the mapping between EVM and Algorand addresses
436
+ *
437
+ * Subclasses must implement provider-specific methods:
438
+ * - initializeProvider(): Initialize the specific EVM wallet SDK/provider
439
+ * - getProvider(): Get the EVM provider instance
440
+ * - signWithProvider(): Sign a message with the specific EVM wallet
441
+ */
442
+ declare abstract class LiquidEvmBaseWallet extends BaseWallet {
443
+ protected liquidEvmSdk: LiquidEvmSdk | null;
444
+ protected algorandClient: AlgorandClient | null;
445
+ protected evmAddressMap: Map<string, string>;
446
+ protected options: LiquidEvmOptions;
447
+ protected store: Store<State>;
448
+ constructor(params: WalletConstructor<any>);
449
+ /**
450
+ * Default metadata for Liquid EVM wallets.
451
+ * Subclasses MUST override this with their own metadata including isLiquid: "EVM"
452
+ */
453
+ static defaultMetadata: LiquidEvmMetadata;
454
+ /**
455
+ * Typed metadata accessor that guarantees isLiquid: "EVM" is present
456
+ */
457
+ readonly metadata: LiquidEvmMetadata;
458
+ /**
459
+ * Initialize the provider-specific SDK or connection.
460
+ * Called during connect/resume to set up the wallet.
461
+ */
462
+ protected abstract initializeProvider(): Promise<void>;
463
+ /**
464
+ * Get the EVM provider instance.
465
+ * This should return the provider object that can make eth_* RPC calls.
466
+ */
467
+ protected abstract getProvider(): Promise<any>;
468
+ /**
469
+ * Sign EIP-712 typed data with the specific EVM wallet provider.
470
+ * @param typedData - The EIP-712 typed data (domain, types, primaryType, message)
471
+ * @param evmAddress - The EVM address to sign with
472
+ * @returns The signature as a hex string (with 0x prefix)
473
+ */
474
+ protected abstract signWithProvider(typedData: SignTypedDataParams, evmAddress: string): Promise<string>;
475
+ /**
476
+ * Ensure the wallet is on the Algorand chain (4160).
477
+ * Queries the current chain first, and only switches/adds if needed.
478
+ */
479
+ protected ensureAlgorandChain(): Promise<void>;
480
+ /**
481
+ * Initialize the Liquid EVM SDK for deriving Algorand addresses
482
+ */
483
+ protected initializeEvmSdk(): Promise<LiquidEvmSdk>;
484
+ /**
485
+ * Derive Algorand accounts from EVM addresses
486
+ */
487
+ protected deriveAlgorandAccounts(evmAddresses: string[]): Promise<WalletAccount[]>;
488
+ /**
489
+ * Convert bytes to hex string with 0x prefix
490
+ */
491
+ protected bytesToHex(bytes: Uint8Array): string;
492
+ /**
493
+ * Process transaction group to extract transactions that need signing
494
+ */
495
+ protected processTxns(txnGroup: algosdk.Transaction[], indexesToSign?: number[]): algosdk.Transaction[];
496
+ /**
497
+ * Process encoded transaction group to extract transactions that need signing
498
+ */
499
+ protected processEncodedTxns(txnGroup: Uint8Array[], indexesToSign?: number[]): algosdk.Transaction[];
500
+ /**
501
+ * Sign Algorand transactions using EVM wallet signatures
502
+ */
503
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
504
+ /**
505
+ * Helper to compare and update accounts if needed during session resume
506
+ */
507
+ protected resumeWithAccounts(evmAddresses: string[], setAccountsFn: (accounts: WalletAccount[]) => void): Promise<void>;
508
+ protected notifyConnect(evmAddress: string, algorandAddress: string): void;
509
+ }
510
+
511
+ interface MetaMaskWalletOptions extends LiquidEvmOptions {
512
+ dappMetadata?: {
513
+ name?: string;
514
+ url?: string;
515
+ iconUrl?: string;
516
+ };
517
+ }
518
+ declare class MetaMaskWallet extends LiquidEvmBaseWallet {
519
+ private metamaskSdk;
520
+ private provider;
521
+ protected options: MetaMaskWalletOptions;
522
+ constructor(params: WalletConstructor<WalletId.METAMASK>);
523
+ static defaultMetadata: {
524
+ name: string;
525
+ icon: string;
526
+ isLiquid: "EVM";
527
+ };
528
+ protected initializeProvider(): Promise<void>;
529
+ protected getProvider(): Promise<SDKProvider>;
530
+ protected signWithProvider(typedData: liquid_accounts_evm.SignTypedDataParams, evmAddress: string): Promise<string>;
531
+ connect: () => Promise<WalletAccount[]>;
532
+ disconnect: () => Promise<void>;
533
+ resumeSession: () => Promise<void>;
534
+ }
535
+
536
+ interface MnemonicConstructor {
537
+ persistToStorage?: boolean;
538
+ promptForMnemonic: () => Promise<string | null>;
539
+ }
540
+ type MnemonicOptions = Partial<Pick<MnemonicConstructor, 'promptForMnemonic'>> & Omit<MnemonicConstructor, 'promptForMnemonic'>;
541
+ declare const LOCAL_STORAGE_MNEMONIC_KEY = "@txnlab/use-wallet:v4_mnemonic";
542
+ declare class MnemonicWallet extends BaseWallet {
543
+ private account;
544
+ private options;
545
+ protected store: Store<State>;
546
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.MNEMONIC>);
547
+ static defaultMetadata: {
548
+ name: string;
549
+ icon: string;
550
+ };
551
+ private loadMnemonicFromStorage;
552
+ private saveMnemonicToStorage;
553
+ private removeMnemonicFromStorage;
554
+ private checkMainnet;
555
+ private initializeAccount;
556
+ connect: () => Promise<WalletAccount[]>;
557
+ disconnect: () => Promise<void>;
558
+ resumeSession: () => Promise<void>;
559
+ private processTxns;
560
+ private processEncodedTxns;
561
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
562
+ }
563
+
564
+ interface PeraWalletConnectOptions {
565
+ bridge?: string;
566
+ shouldShowSignTxnToast?: boolean;
567
+ chainId?: 416001 | 416002 | 416003 | 4160;
568
+ compactMode?: boolean;
569
+ }
570
+ declare class PeraWallet extends BaseWallet {
571
+ private client;
572
+ private options;
573
+ protected store: Store<State>;
574
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.PERA>);
575
+ static defaultMetadata: {
576
+ name: string;
577
+ icon: string;
578
+ };
579
+ private initializeClient;
580
+ connect: () => Promise<WalletAccount[]>;
581
+ disconnect: () => Promise<void>;
582
+ setActive: () => void;
583
+ resumeSession: () => Promise<void>;
584
+ private processTxns;
585
+ private processEncodedTxns;
586
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
587
+ }
588
+
589
+ interface RainbowWalletOptions extends LiquidEvmOptions {
590
+ dappMetadata?: {
591
+ name?: string;
592
+ url?: string;
593
+ iconUrl?: string;
594
+ };
595
+ }
596
+ declare class RainbowWallet extends LiquidEvmBaseWallet {
597
+ private provider;
598
+ protected options: RainbowWalletOptions;
599
+ constructor(params: WalletConstructor<WalletId.RAINBOW>);
600
+ static defaultMetadata: {
601
+ name: string;
602
+ icon: string;
603
+ isLiquid: "EVM";
604
+ };
605
+ protected initializeProvider(): Promise<void>;
606
+ protected getProvider(): Promise<EIP1193Provider>;
607
+ protected signWithProvider(typedData: liquid_accounts_evm.SignTypedDataParams, evmAddress: string): Promise<string>;
608
+ connect: () => Promise<WalletAccount[]>;
609
+ disconnect: () => Promise<void>;
610
+ resumeSession: () => Promise<void>;
611
+ }
612
+
613
+ interface SignClientOptions {
614
+ projectId: string;
615
+ relayUrl?: string;
616
+ metadata?: SignClientTypes.Metadata;
617
+ }
618
+ type WalletConnectModalOptions = Pick<WalletConnectModalConfig, 'enableExplorer' | 'explorerRecommendedWalletIds' | 'privacyPolicyUrl' | 'termsOfServiceUrl' | 'themeMode' | 'themeVariables'>;
619
+ type WalletConnectBaseOptions = SignClientOptions & WalletConnectModalOptions;
620
+ interface WalletConnectOptions extends WalletConnectBaseOptions {
621
+ /**
622
+ * Optional skin to apply to this WalletConnect instance.
623
+ * Can be either:
624
+ * - A string ID referencing a built-in skin (e.g., 'biatec')
625
+ * - A full skin object with id, name, and icon
626
+ *
627
+ * When a skin is applied, the wallet will use the skin's metadata
628
+ * and a unique walletKey for state isolation.
629
+ */
630
+ skin?: WalletConnectSkinOption;
631
+ }
632
+ type SignTxnsResponse = Array<Uint8Array | number[] | string | null | undefined>;
633
+ declare class SessionError extends Error {
634
+ constructor(message: string);
635
+ }
636
+ declare class WalletConnect extends BaseWallet {
637
+ private client;
638
+ private options;
639
+ private modal;
640
+ private modalOptions;
641
+ private session;
642
+ protected store: Store<State>;
643
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.WALLETCONNECT>);
644
+ static defaultMetadata: {
645
+ name: string;
646
+ icon: string;
647
+ };
648
+ /**
649
+ * Get metadata from the current window. This is adapted from the @walletconnect/utils
650
+ * implementation, to avoid requiring the entire package as a dependency.
651
+ * @see https://github.com/WalletConnect/walletconnect-utils/blob/master/browser/window-metadata/src/index.ts
652
+ */
653
+ private getWindowMetadata;
654
+ private initializeClient;
655
+ private initializeModal;
656
+ private onSessionConnected;
657
+ get activeChainId(): string;
658
+ connect: () => Promise<WalletAccount[]>;
659
+ disconnect: () => Promise<void>;
660
+ resumeSession: () => Promise<void>;
661
+ private processTxns;
662
+ private processEncodedTxns;
663
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
664
+ }
665
+
666
+ /**
667
+ * Web3Auth Wallet Provider for Algorand
668
+ *
669
+ * SECURITY CONSIDERATIONS:
670
+ * - Web3Auth exposes the raw private key for non-EVM chains like Algorand
671
+ * - This implementation uses SecureKeyContainer to minimize key exposure
672
+ * - Keys are never persisted to localStorage or any storage
673
+ * - Keys are cleared from memory immediately after signing operations
674
+ * - Session resumption requires re-authentication (keys are not cached)
675
+ *
676
+ * @see https://web3auth.io/docs
677
+ */
678
+
679
+ /**
680
+ * Parameters for custom authentication (e.g., Firebase, custom JWT)
681
+ */
682
+ interface Web3AuthCustomAuth {
683
+ /**
684
+ * Custom verifier name configured in Web3Auth dashboard
685
+ */
686
+ verifier: string;
687
+ /**
688
+ * User identifier (e.g., email, Firebase UID)
689
+ */
690
+ verifierId: string;
691
+ /**
692
+ * JWT token from your authentication provider (e.g., Firebase ID token)
693
+ */
694
+ idToken: string;
695
+ }
696
+ /**
697
+ * Credentials returned by getAuthCredentials callback
698
+ */
699
+ interface Web3AuthCredentials {
700
+ /**
701
+ * JWT token from your authentication provider (e.g., Firebase ID token)
702
+ */
703
+ idToken: string;
704
+ /**
705
+ * User identifier (e.g., email, Firebase UID)
706
+ */
707
+ verifierId: string;
708
+ /**
709
+ * Custom verifier name (optional, uses options.verifier if not provided)
710
+ */
711
+ verifier?: string;
712
+ }
713
+ /**
714
+ * Web3Auth configuration options
715
+ */
716
+ interface Web3AuthOptions {
717
+ /**
718
+ * Web3Auth Client ID from the dashboard
719
+ * @see https://dashboard.web3auth.io
720
+ */
721
+ clientId: string;
722
+ /**
723
+ * Web3Auth network (mainnet, testnet, sapphire_mainnet, sapphire_devnet, cyan, aqua)
724
+ * @default 'sapphire_mainnet'
725
+ */
726
+ web3AuthNetwork?: 'mainnet' | 'testnet' | 'sapphire_mainnet' | 'sapphire_devnet' | 'cyan' | 'aqua';
727
+ /**
728
+ * Login provider to use (google, facebook, twitter, discord, etc.)
729
+ * If not specified, the Web3Auth modal will be shown
730
+ */
731
+ loginProvider?: 'google' | 'facebook' | 'twitter' | 'discord' | 'reddit' | 'twitch' | 'apple' | 'line' | 'github' | 'kakao' | 'linkedin' | 'weibo' | 'wechat' | 'email_passwordless' | 'sms_passwordless';
732
+ /**
733
+ * Login hint for email_passwordless or sms_passwordless
734
+ */
735
+ loginHint?: string;
736
+ /**
737
+ * UI configuration for the Web3Auth modal
738
+ */
739
+ uiConfig?: {
740
+ appName?: string;
741
+ appUrl?: string;
742
+ logoLight?: string;
743
+ logoDark?: string;
744
+ defaultLanguage?: string;
745
+ mode?: 'light' | 'dark' | 'auto';
746
+ theme?: Record<string, string>;
747
+ };
748
+ /**
749
+ * Whether to use the popup flow instead of redirect
750
+ * @default true
751
+ */
752
+ usePopup?: boolean;
753
+ /**
754
+ * Default verifier name for custom authentication.
755
+ * When set, connect() can be called with just { idToken, verifierId }
756
+ */
757
+ verifier?: string;
758
+ /**
759
+ * Callback to get fresh authentication credentials when session expires.
760
+ * Required for automatic re-authentication with Single Factor Auth (SFA).
761
+ *
762
+ * If not provided and the session expires, signTransactions() will throw
763
+ * an error requiring the user to call connect() with fresh credentials.
764
+ *
765
+ * @example
766
+ * ```typescript
767
+ * getAuthCredentials: async () => {
768
+ * const user = firebase.auth().currentUser
769
+ * if (!user) throw new Error('Not logged in')
770
+ * const idToken = await user.getIdToken(true)
771
+ * return { idToken, verifierId: user.email || user.uid }
772
+ * }
773
+ * ```
774
+ */
775
+ getAuthCredentials?: () => Promise<Web3AuthCredentials>;
776
+ }
777
+ declare class Web3AuthWallet extends BaseWallet {
778
+ private web3auth;
779
+ private web3authSFA;
780
+ private options;
781
+ private userInfo;
782
+ /**
783
+ * SECURITY: We store only the address, NEVER the private key.
784
+ * Keys are fetched fresh from Web3Auth and immediately cleared after use.
785
+ */
786
+ private _address;
787
+ /** Track which SDK is currently in use */
788
+ private usingSFA;
789
+ protected store: Store<State>;
790
+ constructor({ id, store, subscribe, getAlgodClient, options, metadata }: WalletConstructor<WalletId.WEB3AUTH>);
791
+ private loadMetadata;
792
+ private saveMetadata;
793
+ private clearMetadata;
794
+ static defaultMetadata: {
795
+ name: string;
796
+ icon: string;
797
+ };
798
+ /**
799
+ * Initialize the Web3Auth client
800
+ */
801
+ private initializeClient;
802
+ /**
803
+ * Initialize the Web3Auth Single Factor Auth client for custom JWT authentication
804
+ */
805
+ private initializeSFAClient;
806
+ /**
807
+ * SECURITY: Fetch the private key from Web3Auth and return it in a SecureKeyContainer.
808
+ * The caller MUST call container.clear() when done.
809
+ *
810
+ * @returns SecureKeyContainer holding the private key
811
+ */
812
+ private getSecureKey;
813
+ /**
814
+ * Convert a hex string to Uint8Array
815
+ */
816
+ private hexToBytes;
817
+ /**
818
+ * Connect to Web3Auth
819
+ *
820
+ * @param args - Optional connection arguments
821
+ * @param args.idToken - JWT token for custom authentication (e.g., Firebase ID token)
822
+ * @param args.verifierId - User identifier for custom authentication (e.g., email, uid)
823
+ * @param args.verifier - Custom verifier name (uses options.verifier if not provided)
824
+ *
825
+ * @example
826
+ * // Standard modal connection
827
+ * await wallet.connect()
828
+ *
829
+ * @example
830
+ * // Custom authentication with Firebase
831
+ * await wallet.connect({
832
+ * idToken: firebaseIdToken,
833
+ * verifierId: user.email,
834
+ * verifier: 'my-firebase-verifier'
835
+ * })
836
+ */
837
+ connect: (args?: {
838
+ idToken?: string;
839
+ verifierId?: string;
840
+ verifier?: string;
841
+ }) => Promise<WalletAccount[]>;
842
+ /**
843
+ * Disconnect from Web3Auth
844
+ */
845
+ disconnect: () => Promise<void>;
846
+ /**
847
+ * Resume session from cached state
848
+ *
849
+ * LAZY AUTHENTICATION: We do NOT connect to Web3Auth here.
850
+ * We simply restore the cached address from localStorage.
851
+ * Web3Auth connection is deferred until signTransactions() is called.
852
+ */
853
+ resumeSession: () => Promise<void>;
854
+ /**
855
+ * Check if Web3Auth is currently connected with a valid session
856
+ */
857
+ private isWeb3AuthConnected;
858
+ /**
859
+ * Ensure Web3Auth is connected and ready for signing.
860
+ * Re-authenticates if the session has expired.
861
+ *
862
+ * This is called lazily when signTransactions() is invoked,
863
+ */
864
+ private ensureConnected;
865
+ /**
866
+ * Re-authenticate using Single Factor Auth (Firebase, custom JWT)
867
+ *
868
+ * Requires getAuthCredentials callback to be configured in options.
869
+ * If the callback returns credentials for a different user, this will
870
+ * disconnect the current wallet (the user logged out and back in as someone else).
871
+ */
872
+ private reconnectSFA;
873
+ /**
874
+ * Re-authenticate using the Web3Auth modal
875
+ *
876
+ * Shows the Web3Auth login modal for the user to authenticate again.
877
+ * If they log in as a different user, this will disconnect the current wallet.
878
+ */
879
+ private reconnectModal;
880
+ /**
881
+ * Verify that the current Web3Auth session matches the cached address.
882
+ *
883
+ * If the address doesn't match (user logged in as someone else),
884
+ * this disconnects the wallet entirely - it's a different identity.
885
+ */
886
+ private verifyAddressMatch;
887
+ /**
888
+ * Process transactions for signing
889
+ */
890
+ private processTxns;
891
+ /**
892
+ * Process encoded transactions for signing
893
+ */
894
+ private processEncodedTxns;
895
+ /**
896
+ * Sign transactions
897
+ *
898
+ * LAZY AUTHENTICATION: If the Web3Auth session has expired, this will
899
+ * automatically re-authenticate before signing.
900
+ *
901
+ * SECURITY: The private key is fetched fresh, used for signing,
902
+ * and immediately cleared from memory. The key is never stored
903
+ * between signing operations.
904
+ */
905
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
906
+ }
907
+
908
+ /**
909
+ * @deprecated BiatecWallet is deprecated and will be removed in v5.
910
+ * Use WalletConnect with the 'biatec' skin instead:
911
+ *
912
+ * ```typescript
913
+ * { id: WalletId.WALLETCONNECT, options: { projectId: '...', skin: 'biatec' } }
914
+ * ```
915
+ */
916
+ declare class BiatecWallet extends WalletConnect {
917
+ private static deprecationWarningShown;
918
+ constructor(args: WalletConstructor<WalletId.BIATEC>);
919
+ static defaultMetadata: {
920
+ name: string;
921
+ icon: string;
922
+ };
923
+ }
924
+
925
+ interface W3WalletProvider {
926
+ isConnected: () => Promise<boolean>;
927
+ account: () => Promise<WalletAccount>;
928
+ signTxns: (transactions: WalletTransaction[]) => Promise<(string | null)[]>;
929
+ }
930
+ declare class W3Wallet extends BaseWallet {
931
+ private client;
932
+ protected store: Store<State>;
933
+ constructor({ id, store, subscribe, getAlgodClient, metadata }: WalletConstructor<WalletId.W3_WALLET>);
934
+ static defaultMetadata: {
935
+ name: string;
936
+ icon: string;
937
+ };
938
+ private initializeClient;
939
+ connect: () => Promise<WalletAccount[]>;
940
+ disconnect: () => Promise<void>;
941
+ resumeSession: () => Promise<void>;
942
+ private processTxns;
943
+ private processEncodedTxns;
944
+ signTransactions: <T extends algosdk.Transaction[] | Uint8Array[]>(txnGroup: T | T[], indexesToSign?: number[]) => Promise<(Uint8Array | null)[]>;
945
+ }
946
+
947
+ declare enum WalletId {
948
+ BIATEC = "biatec",
949
+ DEFLY = "defly",
950
+ DEFLY_WEB = "defly-web",
951
+ CUSTOM = "custom",
952
+ EXODUS = "exodus",
953
+ KIBISIS = "kibisis",
954
+ KMD = "kmd",
955
+ LUTE = "lute",
956
+ MAGIC = "magic",
957
+ METAMASK = "metamask",
958
+ MNEMONIC = "mnemonic",
959
+ PERA = "pera",
960
+ RAINBOW = "rainbow",
961
+ WALLETCONNECT = "walletconnect",
962
+ WEB3AUTH = "web3auth",
963
+ W3_WALLET = "w3-wallet"
964
+ }
965
+ /**
966
+ * Metadata for a WalletConnect skin. Used to customize the appearance of
967
+ * a WalletConnect-based wallet in the UI.
968
+ */
969
+ interface WalletConnectSkin {
970
+ /** Unique identifier for the skin (e.g., 'biatec', 'voiwallet') */
971
+ id: string;
972
+ /** Display name for the wallet */
973
+ name: string;
974
+ /** Wallet icon as a data URI or URL */
975
+ icon: string;
976
+ }
977
+ /**
978
+ * Skin option can be either:
979
+ * - A string ID referencing a built-in skin (e.g., 'biatec')
980
+ * - A full WalletConnectSkin object for custom skins
981
+ */
982
+ type WalletConnectSkinOption = string | WalletConnectSkin;
983
+ /**
984
+ * Composite key type that can be either:
985
+ * - A standard WalletId (for backward compatibility)
986
+ * - A composite string for skinned WalletConnect instances (e.g., 'walletconnect:biatec')
987
+ */
988
+ type WalletKey = WalletId | `${WalletId.WALLETCONNECT}:${string}`;
989
+ type WalletMap = {
990
+ [WalletId.BIATEC]: typeof BiatecWallet;
991
+ [WalletId.CUSTOM]: typeof CustomWallet;
992
+ [WalletId.DEFLY]: typeof DeflyWallet;
993
+ [WalletId.DEFLY_WEB]: typeof DeflyWebWallet;
994
+ [WalletId.EXODUS]: typeof ExodusWallet;
995
+ [WalletId.KIBISIS]: typeof KibisisWallet;
996
+ [WalletId.KMD]: typeof KmdWallet;
997
+ [WalletId.LUTE]: typeof LuteWallet;
998
+ [WalletId.MAGIC]: typeof MagicAuth;
999
+ [WalletId.METAMASK]: typeof MetaMaskWallet;
1000
+ [WalletId.MNEMONIC]: typeof MnemonicWallet;
1001
+ [WalletId.PERA]: typeof PeraWallet;
1002
+ [WalletId.RAINBOW]: typeof RainbowWallet;
1003
+ [WalletId.WALLETCONNECT]: typeof WalletConnect;
1004
+ [WalletId.WEB3AUTH]: typeof Web3AuthWallet;
1005
+ [WalletId.W3_WALLET]: typeof W3Wallet;
1006
+ };
1007
+ type WalletOptionsMap = {
1008
+ [WalletId.BIATEC]: WalletConnectOptions;
1009
+ [WalletId.CUSTOM]: CustomWalletOptions;
1010
+ [WalletId.DEFLY]: DeflyWalletConnectOptions;
1011
+ [WalletId.DEFLY_WEB]: Record<string, never>;
1012
+ [WalletId.EXODUS]: ExodusOptions;
1013
+ [WalletId.KIBISIS]: Record<string, never>;
1014
+ [WalletId.KMD]: KmdOptions;
1015
+ [WalletId.LUTE]: LuteConnectOptions;
1016
+ [WalletId.MAGIC]: MagicAuthOptions;
1017
+ [WalletId.METAMASK]: MetaMaskWalletOptions;
1018
+ [WalletId.MNEMONIC]: MnemonicOptions;
1019
+ [WalletId.PERA]: PeraWalletConnectOptions;
1020
+ [WalletId.RAINBOW]: RainbowWalletOptions;
1021
+ [WalletId.WALLETCONNECT]: WalletConnectOptions;
1022
+ [WalletId.WEB3AUTH]: Web3AuthOptions;
1023
+ [WalletId.W3_WALLET]: Record<string, never>;
1024
+ };
1025
+ type SupportedWallet = WalletIdConfig<WalletId> | WalletId;
1026
+ type WalletConfigMap = {
1027
+ [K in keyof WalletOptionsMap]: {
1028
+ options?: WalletOptionsMap[K];
1029
+ metadata?: Partial<WalletMetadata>;
1030
+ };
1031
+ };
1032
+ type WalletOptions<T extends keyof WalletOptionsMap> = WalletOptionsMap[T];
1033
+ type WalletConfig<T extends keyof WalletConfigMap> = WalletConfigMap[T];
1034
+ type WalletIdConfig<T extends keyof WalletConfigMap> = {
1035
+ [K in T]: {
1036
+ id: K;
1037
+ } & WalletConfigMap[K];
1038
+ }[T];
1039
+ type NonEmptyArray<T> = [T, ...T[]];
1040
+ type SupportedWallets = NonEmptyArray<SupportedWallet>;
1041
+ type WalletMetadata = {
1042
+ name: string;
1043
+ icon: string;
1044
+ isLiquid?: 'EVM';
1045
+ };
1046
+ type LiquidEvmMetadata = WalletMetadata & {
1047
+ isLiquid: 'EVM';
1048
+ };
1049
+ interface UIHooks {
1050
+ onBeforeSign?: (txnGroup: algosdk.Transaction[] | Uint8Array[], indexesToSign?: number[]) => Promise<void>;
1051
+ onAfterSign?: (success: boolean, errorMessage?: string) => void;
1052
+ onConnect?: (evmAccount: {
1053
+ evmAddress: string;
1054
+ algorandAddress: string;
1055
+ }) => void;
1056
+ }
1057
+ interface BaseWalletConstructor {
1058
+ id: WalletId;
1059
+ /** Optional wallet key override. Defaults to id. Used for skinned WalletConnect instances. */
1060
+ walletKey?: WalletKey;
1061
+ metadata: Partial<WalletMetadata> | undefined;
1062
+ getAlgodClient: () => algosdk.Algodv2;
1063
+ store: Store<State>;
1064
+ subscribe: (callback: (state: State) => void) => () => void;
1065
+ managerUIHooks?: UIHooks;
1066
+ }
1067
+ type WalletConstructor<T extends keyof WalletOptionsMap> = BaseWalletConstructor & {
1068
+ options?: WalletOptions<T>;
1069
+ defaultMetadata?: WalletMetadata;
1070
+ };
1071
+ type WalletAccount = {
1072
+ name: string;
1073
+ address: string;
1074
+ };
1075
+ /** @see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0001.md#interface-multisigmetadata */
1076
+ interface MultisigMetadata {
1077
+ /**
1078
+ * Multisig version.
1079
+ */
1080
+ version: number;
1081
+ /**
1082
+ * Multisig threshold value. Authorization requires a subset of signatures,
1083
+ * equal to or greater than the threshold value.
1084
+ */
1085
+ threshold: number;
1086
+ /**
1087
+ * List of Algorand addresses of possible signers for this
1088
+ * multisig. Order is important.
1089
+ */
1090
+ addrs: string[];
1091
+ }
1092
+ /** @see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0001.md#interface-wallettransaction */
1093
+ interface WalletTransaction {
1094
+ /**
1095
+ * Base64 encoding of the canonical msgpack encoding of a Transaction.
1096
+ */
1097
+ txn: string;
1098
+ /**
1099
+ * Optional authorized address used to sign the transaction when the account
1100
+ * is rekeyed. Also called the signor/sgnr.
1101
+ */
1102
+ authAddr?: string;
1103
+ /**
1104
+ * Multisig metadata used to sign the transaction
1105
+ */
1106
+ msig?: MultisigMetadata;
1107
+ /**
1108
+ * Optional list of addresses that must sign the transactions
1109
+ */
1110
+ signers?: string[];
1111
+ /**
1112
+ * Optional base64 encoding of the canonical msgpack encoding of a
1113
+ * SignedTxn corresponding to txn, when signers=[]
1114
+ */
1115
+ stxn?: string;
1116
+ /**
1117
+ * Optional message explaining the reason of the transaction
1118
+ */
1119
+ message?: string;
1120
+ /**
1121
+ * Optional message explaining the reason of this group of transaction
1122
+ * Field only allowed in the first transaction of a group
1123
+ */
1124
+ groupMessage?: string;
1125
+ }
1126
+ /** @see https://github.com/perawallet/connect/blob/1.3.4/src/util/model/peraWalletModels.ts */
1127
+ interface SignerTransaction {
1128
+ txn: algosdk.Transaction;
1129
+ /**
1130
+ * Optional authorized address used to sign the transaction when
1131
+ * the account is rekeyed. Also called the signor/sgnr.
1132
+ */
1133
+ authAddr?: string;
1134
+ /**
1135
+ * Optional list of addresses that must sign the transactions.
1136
+ * Wallet skips to sign this txn if signers is empty array.
1137
+ * If undefined, wallet tries to sign it.
1138
+ */
1139
+ signers?: string[];
1140
+ /**
1141
+ * Optional message explaining the reason of the transaction
1142
+ */
1143
+ message?: string;
1144
+ }
1145
+ interface JsonRpcRequest<T = any> {
1146
+ id: number;
1147
+ jsonrpc: string;
1148
+ method: string;
1149
+ params: T;
1150
+ }
1151
+ declare class SignTxnsError extends Error {
1152
+ code: number;
1153
+ data?: any;
1154
+ constructor(message: string, code: number, data?: any);
1155
+ }
1156
+ interface Siwa {
1157
+ domain: string;
1158
+ account_address: string;
1159
+ uri: string;
1160
+ version: string;
1161
+ statement?: string;
1162
+ nonce?: string;
1163
+ 'issued-at'?: string;
1164
+ 'expiration-time'?: string;
1165
+ 'not-before'?: string;
1166
+ 'request-id'?: string;
1167
+ chain_id: '283';
1168
+ resources?: string[];
1169
+ type: 'ed25519';
1170
+ }
1171
+ declare class SignDataError extends Error {
1172
+ code: number;
1173
+ data?: any;
1174
+ constructor(message: string, code: number, data?: any);
1175
+ }
1176
+ interface SignData {
1177
+ data: string;
1178
+ signer: Uint8Array;
1179
+ domain: string;
1180
+ authenticatorData: Uint8Array;
1181
+ requestId?: string;
1182
+ hdPath?: string;
1183
+ signature?: Uint8Array;
1184
+ }
1185
+ interface SignDataResponse extends SignData {
1186
+ signature: Uint8Array;
1187
+ }
1188
+ declare enum ScopeType {
1189
+ UNKNOWN = -1,
1190
+ AUTH = 1
1191
+ }
1192
+ interface SignMetadata {
1193
+ scope: ScopeType;
1194
+ encoding: string;
1195
+ }
1196
+
1197
+ type WalletState = {
1198
+ accounts: WalletAccount[];
1199
+ activeAccount: WalletAccount | null;
1200
+ };
1201
+ type WalletStateMap = Partial<Record<WalletKey, WalletState>>;
1202
+ type ManagerStatus = 'initializing' | 'ready';
1203
+ interface State {
1204
+ wallets: WalletStateMap;
1205
+ activeWallet: WalletKey | null;
1206
+ activeNetwork: string;
1207
+ algodClient: algosdk.Algodv2;
1208
+ managerStatus: ManagerStatus;
1209
+ networkConfig: Record<string, NetworkConfig>;
1210
+ customNetworkConfigs: Record<string, Partial<NetworkConfig>>;
1211
+ }
1212
+ declare const DEFAULT_STATE: State;
1213
+
1214
+ interface WalletManagerOptions {
1215
+ resetNetwork?: boolean;
1216
+ debug?: boolean;
1217
+ logLevel?: LogLevel;
1218
+ }
1219
+ interface WalletManagerConfig {
1220
+ wallets?: SupportedWallet[];
1221
+ networks?: Record<string, NetworkConfig>;
1222
+ defaultNetwork?: string;
1223
+ options?: WalletManagerOptions;
1224
+ }
1225
+ declare class WalletManager {
1226
+ _clients: Map<WalletKey, BaseWallet>;
1227
+ private baseNetworkConfig;
1228
+ private _uiHooks;
1229
+ store: Store<State>;
1230
+ subscribe: (callback: (state: State) => void) => () => void;
1231
+ options: {
1232
+ resetNetwork: boolean;
1233
+ };
1234
+ private logger;
1235
+ constructor({ wallets, networks, defaultNetwork, options }?: WalletManagerConfig);
1236
+ private initializeLogger;
1237
+ private determineLogLevel;
1238
+ get algodClient(): algosdk.Algodv2;
1239
+ set algodClient(algodClient: algosdk.Algodv2);
1240
+ private loadPersistedState;
1241
+ private savePersistedState;
1242
+ get status(): ManagerStatus;
1243
+ get isReady(): boolean;
1244
+ /**
1245
+ * Derive the wallet key from wallet config.
1246
+ * For WalletConnect with a skin option, returns 'walletconnect:skinId'.
1247
+ * For other wallets, returns the wallet ID.
1248
+ */
1249
+ private deriveWalletKey;
1250
+ private initializeWallets;
1251
+ get wallets(): BaseWallet[];
1252
+ getWallet(walletKey: WalletKey): BaseWallet | undefined;
1253
+ resumeSessions(): Promise<void>;
1254
+ disconnect(): Promise<void>;
1255
+ registerUIHook<K extends keyof UIHooks>(name: K, callback: UIHooks[K]): void;
1256
+ unregisterUIHook(name: keyof UIHooks): void;
1257
+ private initNetworkConfig;
1258
+ private createAlgodClient;
1259
+ getAlgodClient: () => algosdk.Algodv2;
1260
+ setActiveNetwork: (networkId: NetworkId | string) => Promise<void>;
1261
+ updateAlgodConfig(networkId: string, algodConfig: Partial<AlgodConfig>): void;
1262
+ resetNetworkConfig(networkId: string): void;
1263
+ get activeNetwork(): string;
1264
+ get networkConfig(): Record<string, NetworkConfig>;
1265
+ get activeNetworkConfig(): NetworkConfig;
1266
+ get activeWallet(): BaseWallet | null;
1267
+ get activeWalletAccounts(): WalletAccount[] | null;
1268
+ get activeWalletAddresses(): string[] | null;
1269
+ get activeAccount(): WalletAccount | null;
1270
+ get activeAddress(): string | null;
1271
+ get signTransactions(): BaseWallet['signTransactions'];
1272
+ get transactionSigner(): algosdk.TransactionSigner;
1273
+ }
1274
+
1275
+ declare class StorageAdapter {
1276
+ static getItem(key: string): string | null;
1277
+ static setItem(key: string, value: string): void;
1278
+ static removeItem(key: string): void;
1279
+ }
1280
+
1281
+ /**
1282
+ * Secure key handling utilities for managing sensitive cryptographic material.
1283
+ *
1284
+ * These utilities provide defense-in-depth for private key handling:
1285
+ * 1. Memory zeroing - Overwrites key material before releasing references
1286
+ * 2. Scoped key access - Keys are only available within controlled callbacks
1287
+ * 3. Automatic cleanup - Keys are cleared after use via try/finally patterns
1288
+ * 4. No persistence - Keys are never stored to disk/localStorage
1289
+ */
1290
+ /**
1291
+ * Securely zeros out a Uint8Array by overwriting all bytes with zeros.
1292
+ * This helps prevent key material from lingering in memory.
1293
+ *
1294
+ * Note: JavaScript doesn't guarantee immediate memory clearing due to GC,
1295
+ * but this provides defense-in-depth by:
1296
+ * 1. Overwriting the buffer contents immediately
1297
+ * 2. Reducing the window where key material is accessible
1298
+ * 3. Preventing accidental key leakage through references
1299
+ */
1300
+ declare function zeroMemory(buffer: Uint8Array): void;
1301
+ /**
1302
+ * Securely zeros out a string by creating a mutable copy and clearing it.
1303
+ * Returns an empty string. The original string in memory may still exist
1304
+ * due to string immutability in JS, but this clears any mutable references.
1305
+ */
1306
+ declare function zeroString(str: string): string;
1307
+ /**
1308
+ * A secure container for holding private key material.
1309
+ * Provides controlled access and automatic cleanup.
1310
+ */
1311
+ declare class SecureKeyContainer {
1312
+ private _secretKey;
1313
+ private _isCleared;
1314
+ constructor(secretKey: Uint8Array);
1315
+ /**
1316
+ * Check if the key has been cleared
1317
+ */
1318
+ get isCleared(): boolean;
1319
+ /**
1320
+ * Execute a callback with access to the secret key.
1321
+ * The key is automatically cleared if an error occurs.
1322
+ */
1323
+ useKey<T>(callback: (secretKey: Uint8Array) => Promise<T>): Promise<T>;
1324
+ /**
1325
+ * Execute a synchronous callback with access to the secret key.
1326
+ */
1327
+ useKeySync<T>(callback: (secretKey: Uint8Array) => T): T;
1328
+ /**
1329
+ * Securely clear the key from memory.
1330
+ * This should be called when the key is no longer needed.
1331
+ */
1332
+ clear(): void;
1333
+ }
1334
+ /**
1335
+ * Execute a function with a temporary secret key that is automatically
1336
+ * cleared after the function completes (success or error).
1337
+ *
1338
+ * This is the preferred pattern for one-time key operations.
1339
+ */
1340
+ declare function withSecureKey<T>(secretKey: Uint8Array, callback: (container: SecureKeyContainer) => Promise<T>): Promise<T>;
1341
+ /**
1342
+ * Synchronous version of withSecureKey for non-async operations.
1343
+ */
1344
+ declare function withSecureKeySync<T>(secretKey: Uint8Array, callback: (container: SecureKeyContainer) => T): T;
1345
+
1346
+ /**
1347
+ * Fallback configuration for Webpack to handle optional wallet dependencies.
1348
+ * This allows applications to build without these packages installed,
1349
+ * enabling users to include only the wallet packages they need.
1350
+ * Each package is set to 'false', which means Webpack will provide an empty module
1351
+ * if the package is not found, preventing build errors for unused wallets.
1352
+ */
1353
+ declare const webpackFallback: {
1354
+ '@agoralabs-sh/avm-web-provider': boolean;
1355
+ '@blockshake/defly-connect': boolean;
1356
+ '@magic-ext/algorand': boolean;
1357
+ '@perawallet/connect': boolean;
1358
+ '@walletconnect/modal': boolean;
1359
+ '@walletconnect/sign-client': boolean;
1360
+ '@web3auth/base': boolean;
1361
+ '@web3auth/base-provider': boolean;
1362
+ '@web3auth/modal': boolean;
1363
+ '@web3auth/single-factor-auth': boolean;
1364
+ 'lute-connect': boolean;
1365
+ 'magic-sdk': boolean;
1366
+ };
1367
+
1368
+ /**
1369
+ * Built-in skins that ship with the library.
1370
+ * PRs to add new WalletConnect-compatible wallets should add entries here.
1371
+ */
1372
+ declare const BUILTIN_SKINS: Record<string, WalletConnectSkin>;
1373
+ /**
1374
+ * Register a custom WalletConnect skin at runtime.
1375
+ * This allows developers to add their own wallet skins without PRing the library.
1376
+ *
1377
+ * @param skin - The skin definition to register
1378
+ * @throws Error if attempting to override a built-in skin
1379
+ *
1380
+ * @example
1381
+ * ```typescript
1382
+ * import { registerSkin } from '@txnlab/use-wallet'
1383
+ *
1384
+ * registerSkin({
1385
+ * id: 'mywallet',
1386
+ * name: 'My Custom Wallet',
1387
+ * icon: 'data:image/svg+xml;base64,...'
1388
+ * })
1389
+ * ```
1390
+ */
1391
+ declare function registerSkin(skin: WalletConnectSkin): void;
1392
+ /**
1393
+ * Get a skin by its ID from either built-in or custom registries.
1394
+ *
1395
+ * @param skinId - The skin identifier
1396
+ * @returns The skin definition, or undefined if not found
1397
+ */
1398
+ declare function getSkin(skinId: string): WalletConnectSkin | undefined;
1399
+ /**
1400
+ * Resolve a skin option to a full WalletConnectSkin object.
1401
+ *
1402
+ * If the option is a string, looks up the skin in the registries.
1403
+ * If the option is a full skin object, registers it as a custom skin and returns it.
1404
+ *
1405
+ * @param skinOption - Either a skin ID string or a full skin definition
1406
+ * @returns The resolved skin, or undefined if not found (when string ID provided)
1407
+ */
1408
+ declare function resolveSkin(skinOption: WalletConnectSkinOption): WalletConnectSkin | undefined;
1409
+
1410
+ export { type AlgodConfig, BUILTIN_SKINS, BaseWallet, type BaseWalletConstructor, BiatecWallet, type CustomProvider, CustomWallet, type CustomWalletOptions, DEFAULT_NETWORK_CONFIG, DEFAULT_STATE, DEFLY_WEB_PROVIDER_ID, DeflyWallet, type DeflyWalletConnectOptions, DeflyWebWallet, type EnableResult, type Exodus, type ExodusOptions, ExodusWallet, ICON, type JsonRpcRequest, KIBISIS_AVM_WEB_PROVIDER_ID, KibisisWallet, type KmdOptions, KmdWallet, LOCAL_STORAGE_MNEMONIC_KEY, LiquidEvmBaseWallet, type LiquidEvmMetadata, type LiquidEvmOptions, LogLevel, type LuteConnectOptions, LuteWallet, MagicAuth, type MagicAuthClient, type MagicAuthOptions, type ManagerStatus, MetaMaskWallet, type MetaMaskWalletOptions, type MnemonicOptions, MnemonicWallet, type MultisigMetadata, type NetworkConfig, NetworkConfigBuilder, NetworkId, PeraWallet, type PeraWalletConnectOptions, RainbowWallet, type RainbowWalletOptions, ScopeType, SecureKeyContainer, SessionError, type SignData, SignDataError, type SignDataResponse, type SignMetadata, SignTxnsError, type SignTxnsResponse, type SignTxnsResult, type SignerTransaction, type Siwa, type State, StorageAdapter, type SupportedWallet, type SupportedWallets, type UIHooks, W3Wallet, type W3WalletProvider, type WalletAccount, type WalletConfig, type WalletConfigMap, WalletConnect, type WalletConnectOptions, type WalletConnectSkin, type WalletConnectSkinOption, type WalletConstructor, WalletId, type WalletIdConfig, type WalletKey, WalletManager, type WalletManagerConfig, type WalletManagerOptions, type WalletMap, type WalletMetadata, type WalletOptions, type WalletOptionsMap, type WalletState, type WalletTransaction, type Web3AuthCredentials, type Web3AuthCustomAuth, type Web3AuthOptions, Web3AuthWallet, type WindowExtended, getSkin, registerSkin, resolveSkin, webpackFallback, withSecureKey, withSecureKeySync, zeroMemory, zeroString };