@cavos/kit 0.0.1 → 0.0.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.
@@ -0,0 +1,590 @@
1
+ import { Account } from 'starknet';
2
+ import { PublicKey, Connection, TransactionInstruction, Keypair } from '@solana/web3.js';
3
+
4
+ /**
5
+ * Identity for a Cavos wallet. Login (email / social / OTP) only ever produces a
6
+ * stable `userId`; that's all the wallet needs to derive its address. Auth never
7
+ * touches signing — the device key does that, silently.
8
+ *
9
+ * Privy-style UX: the user "logs in" and the wallet is provisioned behind the
10
+ * scenes (device key + auto-deployed smart account). The app never handles keys.
11
+ */
12
+ interface Identity {
13
+ /** Stable, backend-managed user identifier. */
14
+ userId: string;
15
+ /** Optional metadata (email, provider) for display only. */
16
+ email?: string;
17
+ provider?: "google" | "apple" | "email" | "otp" | string;
18
+ }
19
+ /**
20
+ * Authenticates a user and returns their stable identity. Implementations:
21
+ * - `CavosAuth` (hosted, mirrors `@cavos/react`: Google/Apple/email/OTP via the
22
+ * Cavos backend) — the default, Privy-like experience.
23
+ * - any custom provider (the app already authenticated the user elsewhere).
24
+ */
25
+ interface AuthProvider {
26
+ authenticate(): Promise<Identity>;
27
+ }
28
+ /** Trivial provider when the app already has the user's stable id. */
29
+ declare class StaticIdentity implements AuthProvider {
30
+ private readonly identity;
31
+ constructor(identity: Identity);
32
+ authenticate(): Promise<Identity>;
33
+ }
34
+
35
+ /** secp256r1 (P-256) public key of a device signer. */
36
+ interface DevicePublicKey {
37
+ x: bigint;
38
+ y: bigint;
39
+ }
40
+ /** A raw secp256r1 signature over `sha256(tx_hash)`. */
41
+ interface DeviceSignature {
42
+ r: bigint;
43
+ s: bigint;
44
+ /** Recovery parity of the emitted (r, s); the contract normalizes high-s. */
45
+ yParity: boolean;
46
+ }
47
+ /**
48
+ * A silent, device-bound signer. The private key is a secp256r1 key generated
49
+ * and kept on the device (non-extractable WebCrypto key on web, Secure Enclave
50
+ * on native) — it never leaves the device and signs WITHOUT any user-visible
51
+ * prompt (no passkey, no biometrics). OAuth / email only derive identity; they
52
+ * are never involved in signing.
53
+ *
54
+ * `WebCryptoSigner` is the browser implementation. React Native and other
55
+ * platforms provide their own implementation of this interface.
56
+ */
57
+ interface DeviceSigner {
58
+ /** secp256r1 public key of this device signer. */
59
+ getPublicKey(): Promise<DevicePublicKey>;
60
+ /**
61
+ * Sign a transaction hash silently. `txHash` is the 32-byte big-endian tx
62
+ * hash; the signer signs `sha256(txHash)` and returns the raw (r, s, parity).
63
+ */
64
+ sign(txHash: Uint8Array): Promise<DeviceSignature>;
65
+ }
66
+
67
+ /**
68
+ * Off-chain map of `user_id -> wallet`. Because the account address is
69
+ * `f(identity, first_device_pubkey)` (unforgeable, secure), it is NOT derivable
70
+ * from the identity alone on a new device. The backend is the source of truth
71
+ * for "does this user already have a wallet?" — enabling multi-device:
72
+ *
73
+ * - First device, unknown user -> deploy a new wallet, then `register`.
74
+ * - Same user, new device -> `lookup` returns the existing wallet; the
75
+ * new device is added as a signer (recovery
76
+ * approval), NOT a new wallet.
77
+ *
78
+ * The backend implements this (it already manages the user<->address binding).
79
+ */
80
+ interface WalletRegistry {
81
+ /** The user's existing wallet, or null if they don't have one yet. */
82
+ lookup(userId: string): Promise<RegisteredWallet | null>;
83
+ /** Record a freshly deployed wallet for the user (first device). */
84
+ register(params: {
85
+ userId: string;
86
+ address: string;
87
+ initialSigner: DevicePublicKey;
88
+ }): Promise<void>;
89
+ /** Note an additional device signer for the user's wallet (after approval). */
90
+ addDevice?(params: {
91
+ userId: string;
92
+ address: string;
93
+ signer: DevicePublicKey;
94
+ }): Promise<void>;
95
+ }
96
+ interface RegisteredWallet {
97
+ address: string;
98
+ /** Public keys of the devices registered on this wallet (if tracked). */
99
+ devices?: DevicePublicKey[];
100
+ }
101
+ /** Simple in-memory registry for demos / tests. */
102
+ declare class InMemoryWalletRegistry implements WalletRegistry {
103
+ private wallets;
104
+ lookup(userId: string): Promise<RegisteredWallet | null>;
105
+ register(params: {
106
+ userId: string;
107
+ address: string;
108
+ initialSigner: DevicePublicKey;
109
+ }): Promise<void>;
110
+ addDevice(params: {
111
+ userId: string;
112
+ address: string;
113
+ signer: DevicePublicKey;
114
+ }): Promise<void>;
115
+ }
116
+
117
+ /** An account meta candidate for a CPI instruction inside `execute`. Mirrors the
118
+ * on-chain `AccountMetaCandidate` (Borsh). */
119
+ interface InstructionAccount {
120
+ pubkey: string;
121
+ isSigner: boolean;
122
+ isWritable: boolean;
123
+ }
124
+ /** A CPI instruction the device key authorizes via `execute`. Mirrors the
125
+ * on-chain `InstructionData` (Borsh). Serialized canonically and hashed before
126
+ * signing, so a signature binds exactly this instruction set. */
127
+ interface InstructionData {
128
+ programId: string;
129
+ accounts: InstructionAccount[];
130
+ data: Uint8Array;
131
+ }
132
+ interface SolanaAdapterOptions {
133
+ /** Cavos device-account program id (defaults to the deployed one). */
134
+ programId?: string;
135
+ /** RPC connection for reads (`isAuthorizedSigner`) and nonce fetch. */
136
+ connection?: Connection;
137
+ /** Device signer used to authorize guarded actions. */
138
+ signer?: DeviceSigner;
139
+ }
140
+ /**
141
+ * Solana adapter for the Cavos device-signer account. Unlike Starknet (where the
142
+ * account contract verifies the P-256 signature in `__validate__`), Solana
143
+ * verifies it natively via the secp256r1 precompile, so every guarded action is
144
+ * a two-instruction bundle: `[secp256r1 precompile ix, program ix]`. This adapter
145
+ * derives the account PDA, builds those bundles, and reuses the same
146
+ * `DeviceSigner` (P-256 / WebCrypto) as every other chain.
147
+ */
148
+ declare class SolanaAdapter {
149
+ private readonly opts;
150
+ readonly chain: "solana";
151
+ readonly programId: PublicKey;
152
+ constructor(opts?: SolanaAdapterOptions);
153
+ /** Deterministic account address: PDA of [seed, address_seed, initial_signer_x]. */
154
+ computeAddress(addressSeed: Uint8Array, initialSigner: DevicePublicKey): string;
155
+ private pda;
156
+ /** `initialize` instruction creating the account with its first device signer. */
157
+ buildInitialize(addressSeed: Uint8Array, payer: string, initialSigner: DevicePublicKey): TransactionInstruction;
158
+ /** `[precompile, add_signer]` bundle, authorized by an existing device signer. */
159
+ buildAddSigner(account: string, newSigner: DevicePublicKey): Promise<TransactionInstruction[]>;
160
+ /** `[precompile, remove_signer]` bundle, authorized by an existing device signer. */
161
+ buildRemoveSigner(account: string, signer: DevicePublicKey): Promise<TransactionInstruction[]>;
162
+ /** `[precompile, execute_transfer]` bundle moving lamports out of the account. */
163
+ buildExecuteTransfer(account: string, destination: string, amount: bigint): Promise<TransactionInstruction[]>;
164
+ /**
165
+ * `[precompile, execute]` bundle running arbitrary CPI instructions with the
166
+ * account PDA as signer. The device key signs over
167
+ * `DOMAIN_EXECUTE || account || sha256(canonical(instructions)) || nonce`, so
168
+ * the signature commits to the EXACT instruction set the program will invoke —
169
+ * no account/data substitution is possible after signing.
170
+ *
171
+ * The instructions' accounts are passed to the program via `remaining_accounts`
172
+ * (flattened, in order); the program enforces an exact, ordered mapping.
173
+ */
174
+ buildExecute(account: string, instructions: InstructionData[]): Promise<TransactionInstruction[]>;
175
+ /** Read whether `signer` is currently an authorized signer of `account`. */
176
+ isAuthorizedSigner(account: string, signer: DevicePublicKey): Promise<boolean>;
177
+ private guardedKeys;
178
+ /** Sign `message` with the device key and build the matching precompile ix. */
179
+ private signToPrecompile;
180
+ private fetchNonce;
181
+ private fetchSigners;
182
+ private requireConnection;
183
+ }
184
+ /** Compressed SEC1 P-256 pubkey (33 bytes) from {x, y}. */
185
+ declare function compressedPubkey(pk: DevicePublicKey): Uint8Array;
186
+ /** Encode (r, s) as raw 64-byte r‖s, normalized to low-S (precompile requires it). */
187
+ declare function encodeLowSSignature(r: bigint, s: bigint): Uint8Array;
188
+ /** Build the native secp256r1 precompile instruction (single self-contained sig). */
189
+ declare function buildSecp256r1Instruction(compressed: Uint8Array, signature: Uint8Array, message: Uint8Array): TransactionInstruction;
190
+ /** Anchor instruction discriminator = sha256("global:<name>")[..8]. */
191
+ declare function anchorDiscriminator(name: string): Buffer;
192
+ /** Serialize the full instruction set — the bytes `hash_instructions` hashes. */
193
+ declare function serializeInstructions(instructions: InstructionData[]): Buffer;
194
+
195
+ /** Cavos device-account program + Solana primitives. */
196
+ /** Deployed `cavos-device-account` program id (see account-contracts/solana). */
197
+ declare const DEVICE_ACCOUNT_PROGRAM_ID = "FHnoYNfYAmFrwt18gcBGG7G1S5q3RAbCBvrV2D29izNJ";
198
+ /** Native secp256r1 signature-verify precompile (SIMD-0075). */
199
+ declare const SECP256R1_PROGRAM_ID = "Secp256r1SigVerify1111111111111111111111111";
200
+ declare const SOLANA_NETWORKS: {
201
+ readonly "solana-devnet": "https://api.devnet.solana.com";
202
+ readonly "solana-mainnet": "https://api.mainnet-beta.solana.com";
203
+ readonly "solana-localnet": "http://127.0.0.1:8899";
204
+ };
205
+ type SolanaNetwork = keyof typeof SOLANA_NETWORKS;
206
+
207
+ interface SolanaRelayerOptions {
208
+ /** Base URL of the Cavos backend exposing /api/solana/relay. */
209
+ baseUrl: string;
210
+ /** Cavos App ID (authorizes the sponsored request). */
211
+ appId: string;
212
+ network: SolanaNetwork;
213
+ /** Connection used only to fetch a recent blockhash before serializing. */
214
+ connection: Connection;
215
+ }
216
+ /**
217
+ * Client for the Cavos Solana sponsoring relayer. Lets the SDK submit
218
+ * device-account transactions WITHOUT the integrator holding a fee-payer
219
+ * keypair: the relayer co-signs as fee payer and pays the fee/rent. The relayer
220
+ * only pays — the device signature inside the instructions (verified by the
221
+ * secp256r1 precompile) is what authorizes the action, and it does not bind the
222
+ * fee payer, so sponsorship needs no re-signing.
223
+ */
224
+ declare class SolanaRelayer {
225
+ private readonly opts;
226
+ private feePayer?;
227
+ constructor(opts: SolanaRelayerOptions);
228
+ /** The relayer's fee-payer pubkey (fetched + cached from the backend). */
229
+ getFeePayer(): Promise<PublicKey>;
230
+ /**
231
+ * Build a tx with the relayer as fee payer, serialize it unsigned, and POST it
232
+ * to the relayer to co-sign + submit. Returns the confirmed signature.
233
+ */
234
+ send(instructions: TransactionInstruction[]): Promise<string>;
235
+ }
236
+
237
+ interface ConnectSolanaOptions {
238
+ network: SolanaNetwork;
239
+ /** Authenticated user (pass `identity` directly, or an `auth` provider). */
240
+ auth?: AuthProvider;
241
+ identity?: Identity;
242
+ appSalt: string;
243
+ appId?: string;
244
+ backendUrl?: string;
245
+ registry?: WalletRegistry;
246
+ /** RPC override (else the network default). */
247
+ rpcUrl?: string;
248
+ /** Cavos device-account program id override. */
249
+ programId?: string;
250
+ /** Override the device signer factory (native / tests); default WebCrypto. */
251
+ createSigner?: (keyId: string) => Promise<DeviceSigner>;
252
+ /**
253
+ * Gasless sponsorship via the Cavos relayer. When set (or when `appId` +
254
+ * `backendUrl` are given), transactions are co-signed + paid by the Cavos
255
+ * relayer, so the integrator needs NO fee-payer keypair — the user's silent
256
+ * device key (which holds no SOL) gets a seedless, gasless experience.
257
+ */
258
+ relayer?: SolanaRelayer;
259
+ /**
260
+ * Self-funded fallback: a fee-payer keypair the integrator funds. Used only
261
+ * when no `relayer` is configured (tests / advanced). Sponsored relaying is
262
+ * the default path when `appId` is provided.
263
+ */
264
+ feePayer?: Keypair;
265
+ }
266
+ type ConnectStatus$1 = "ready" | "needs-device-approval";
267
+ /**
268
+ * Options for recovering a Solana account after losing every device signer.
269
+ * Mirrors `RecoveryOptions` (Starknet), adapted to the Solana path: the backup
270
+ * key signs the `add_signer` bundle via the secp256r1 precompile and the Cavos
271
+ * relayer sponsors it (no fee-payer keypair needed).
272
+ */
273
+ interface RecoverSolanaOptions {
274
+ /** The recovery code the user stored when they ran setupRecovery. */
275
+ code: string;
276
+ /** Authenticated identity (same user who owns the account). */
277
+ identity: Identity;
278
+ /** Solana network the account lives on. */
279
+ network: SolanaNetwork;
280
+ appSalt: string;
281
+ appId?: string;
282
+ backendUrl?: string;
283
+ registry?: WalletRegistry;
284
+ /** RPC override (else the network default). */
285
+ rpcUrl?: string;
286
+ /** Cavos device-account program id override. */
287
+ programId?: string;
288
+ /** Override the new device's signer (native / tests); default WebCrypto. */
289
+ createSigner?: (keyId: string) => Promise<DeviceSigner>;
290
+ /** Gasless sponsorship via the Cavos relayer (defaults to hosted when appId set). */
291
+ relayer?: SolanaRelayer;
292
+ /** Self-funded fallback when no relayer is configured (tests / advanced). */
293
+ feePayer?: Keypair;
294
+ }
295
+ /**
296
+ * High-level Solana entry — the Solana analogue of `Cavos.connect`. One call
297
+ * derives the deterministic device-bound account, deploys it (PDA `initialize`)
298
+ * if needed, registers it for cross-device recognition, and returns a ready
299
+ * handle whose silent P-256 device key authorizes every action through the
300
+ * native secp256r1 precompile.
301
+ *
302
+ * const cavos = await CavosSolana.connect({ network: "solana-devnet", identity, appSalt, feePayer });
303
+ * if (cavos.status === "ready") await cavos.execute(amount, dest);
304
+ *
305
+ * Gasless by default: when an `appId` is provided the Cavos relayer co-signs +
306
+ * pays (no fee-payer keypair needed). `feePayer` is the self-funded fallback.
307
+ */
308
+ declare class CavosSolana {
309
+ readonly identity: Identity;
310
+ readonly address: string;
311
+ readonly status: ConnectStatus$1;
312
+ readonly connection: Connection;
313
+ private readonly adapter;
314
+ private readonly devicePubkey;
315
+ private readonly relayer?;
316
+ private readonly feePayer?;
317
+ /** Discriminant for the `CavosWallet` union — narrows `execute()` per chain. */
318
+ readonly chain: "solana";
319
+ private constructor();
320
+ get publicKey(): DevicePublicKey;
321
+ static connect(opts: ConnectSolanaOptions): Promise<CavosSolana>;
322
+ /** Authorize an additional device signer (device-signed via precompile). */
323
+ addSigner(pubkey: DevicePublicKey): Promise<string>;
324
+ /** Move `amount` lamports out of the account to `destination` (device-signed). */
325
+ execute(amount: bigint, destination: string): Promise<string>;
326
+ /**
327
+ * Run arbitrary CPI `instructions` with the account PDA as signer (device-
328
+ * signed). The signature commits to sha256 of the canonical Borsh
329
+ * serialization of the instructions, so it binds exactly the operations the
330
+ * program will invoke. Unlocks SPL transfers, swaps, staking, etc.
331
+ *
332
+ * What the relayer will sponsor is constrained by the app's Solana program
333
+ * allowlist (configured in the dashboard) — programs outside the allowlist are
334
+ * rejected before co-signing.
335
+ */
336
+ executeInstructions(instructions: InstructionData[]): Promise<string>;
337
+ /**
338
+ * Register the backup signer derived from `code` as an authorized signer of this
339
+ * account (device-signed via precompile). Idempotent: returns without a tx if
340
+ * the backup signer is already registered. The code never leaves the device —
341
+ * only the derived public key travels on-chain.
342
+ *
343
+ * Self-custodial: anyone who can re-derive the backup key from the code (i.e.
344
+ * the rightful owner) can later recover the account with `CavosSolana.recover`.
345
+ * Run this once, on a registered device, and have the user store the code.
346
+ */
347
+ setupRecovery(code: string): Promise<string | undefined>;
348
+ /**
349
+ * Recover an account after losing every device signer. Derives the backup key
350
+ * from `code`, uses it (not the new device key) to sign an `add_signer` for the
351
+ * new device, and returns a ready CavosSolana bound to the new device. The
352
+ * account address is unchanged.
353
+ *
354
+ * Self-custodial: only someone holding the code (i.e. the rightful owner) can
355
+ * re-derive the backup key. The backend never sees the code.
356
+ *
357
+ * This mirrors `Cavos.recover` (Starknet): the backup key is just another
358
+ * authorized signer, so recovery is an `add_signer(newDevice)` bundle signed by
359
+ * the backup key. The on-chain program needs no recovery-specific entrypoint.
360
+ */
361
+ static recover(opts: RecoverSolanaOptions): Promise<CavosSolana>;
362
+ private send;
363
+ }
364
+
365
+ /** A chain-native contract call (Starknet `Call`-shaped; generic for portability). */
366
+ interface ChainCall {
367
+ contractAddress: string;
368
+ entrypoint: string;
369
+ calldata: string[];
370
+ }
371
+ interface ComputeAddressParams {
372
+ addressSeed: bigint;
373
+ /** First device signer — part of the address, making it unforgeable. */
374
+ initialSigner: DevicePublicKey;
375
+ /** Defaults to `addressSeed` when omitted. */
376
+ salt?: bigint;
377
+ }
378
+ /**
379
+ * Per-chain implementation surface. Phase 1 ships only Starknet, but the kit is
380
+ * designed so Stellar and Solana adapters drop in behind the same interface.
381
+ */
382
+ interface ChainAdapter {
383
+ readonly chain: "starknet" | "stellar" | "solana";
384
+ /** Deterministic address from identity seed + the first device signer. */
385
+ computeAddress(params: ComputeAddressParams): string;
386
+ /** Call(s) to deploy the account with its first device signer (UDC). */
387
+ buildDeploy(params: ComputeAddressParams): ChainCall[];
388
+ buildAddSigner(accountAddress: string, signer: DevicePublicKey): ChainCall;
389
+ buildRemoveSigner(accountAddress: string, signer: DevicePublicKey): ChainCall;
390
+ /** Read whether a pubkey is a currently-authorized signer of the account. */
391
+ isAuthorizedSigner(accountAddress: string, signer: DevicePublicKey): Promise<boolean>;
392
+ /**
393
+ * Compute the signature payload for an outgoing transaction: given the chain's
394
+ * tx hash, obtain a device assertion and serialize it to the chain's expected
395
+ * signature encoding.
396
+ */
397
+ buildSignature(txHash: bigint): Promise<string[]>;
398
+ }
399
+
400
+ /**
401
+ * Multi-device / recovery flow (roadmap §1.2). A new device requests addition;
402
+ * the backend emails an approval prompt styled as a login request; the user
403
+ * approves on an ALREADY-registered device, which signs `add_signer` for the
404
+ * new pubkey. There is no legacy JWT path — recovery is purely device-signer
405
+ * based.
406
+ *
407
+ * The backend lives outside this repo; this is the client contract the kit
408
+ * speaks to. Provide an implementation (HTTP, etc.) when wiring an app.
409
+ */
410
+ interface RecoveryClient {
411
+ /**
412
+ * Step 1 (new device): request that this pubkey be added to the user's
413
+ * account. Triggers the approval email. Returns a request id to poll.
414
+ */
415
+ requestDeviceAddition(params: {
416
+ userId: string;
417
+ accountAddress: string;
418
+ newSigner: DevicePublicKey;
419
+ /** Owner email to send the approval link to (the SDK has it from login). */
420
+ email?: string;
421
+ /** Optional device label (browser/UA) shown in the approval email. */
422
+ deviceLabel?: string;
423
+ }): Promise<{
424
+ requestId: string;
425
+ }>;
426
+ /**
427
+ * Step 3-4 (existing device): fetch a pending addition request so the
428
+ * registered device can approve it by signing `add_signer`.
429
+ */
430
+ getPendingRequest(requestId: string): Promise<PendingDeviceRequest | null>;
431
+ /** Mark a request approved after the `add_signer` tx is submitted. */
432
+ confirmDeviceAddition(params: {
433
+ requestId: string;
434
+ txHash: string;
435
+ }): Promise<void>;
436
+ }
437
+ interface PendingDeviceRequest {
438
+ requestId: string;
439
+ appId?: string;
440
+ userId: string;
441
+ accountAddress: string;
442
+ newSigner: DevicePublicKey;
443
+ createdAt: string;
444
+ status: "pending" | "approved" | "expired";
445
+ }
446
+
447
+ /** The chains the unified `Cavos.connect` can target. */
448
+ type Chain = "starknet" | "solana";
449
+ /**
450
+ * Environment selector. `Cavos.connect` resolves it to the chain's concrete
451
+ * network: starknet → sepolia/mainnet, solana → solana-devnet/solana-mainnet.
452
+ */
453
+ type NetworkEnv = "mainnet" | "testnet";
454
+ /** A connected wallet: discriminated by `chain`, so `execute()` stays native. */
455
+ type CavosWallet = Cavos | CavosSolana;
456
+ interface ConnectOptions {
457
+ /** Target chain. The returned wallet is discriminated by this same value. */
458
+ chain: Chain;
459
+ /** Environment. Resolved to sepolia/devnet (testnet) or mainnet per chain. */
460
+ network: NetworkEnv;
461
+ /** Authenticated user (pass `identity` directly, or an `auth` provider). */
462
+ auth?: AuthProvider;
463
+ identity?: Identity;
464
+ appSalt: string;
465
+ /**
466
+ * Cavos App ID. When set (with `backendUrl`), the kit uses the hosted
467
+ * WalletRegistry + RecoveryClient by default for real multi-device support.
468
+ */
469
+ appId?: string;
470
+ /** Cavos backend base URL. Defaults to https://cavos.xyz. */
471
+ backendUrl?: string;
472
+ /**
473
+ * Off-chain user_id -> wallet map. Defaults to the hosted HttpWalletRegistry
474
+ * when `appId` is set, else an in-memory registry (single-device only).
475
+ */
476
+ registry?: WalletRegistry;
477
+ /**
478
+ * Device-approval relay (Starknet). Defaults to HttpRecoveryClient when
479
+ * `appId` is set; used to request addition of this device when it isn't a
480
+ * signer yet.
481
+ */
482
+ recovery?: RecoveryClient;
483
+ rpcUrl?: string;
484
+ /** Override the device signer factory (native / tests); default WebCrypto. */
485
+ createSigner?: (keyId: string) => Promise<DeviceSigner>;
486
+ /** Cavos paymaster API key (sponsors deploy + execute). Required for Starknet. */
487
+ paymasterApiKey?: string;
488
+ paymasterUrl?: string;
489
+ classHash?: string;
490
+ /** Cavos device-account program id override. */
491
+ programId?: string;
492
+ /** Gasless sponsorship relayer (defaults to the hosted one when `appId` set). */
493
+ relayer?: SolanaRelayer;
494
+ /** Self-funded fee-payer fallback when no relayer is configured. */
495
+ feePayer?: Keypair;
496
+ }
497
+ /** Whether this device can already operate the wallet, or needs to be added. */
498
+ type ConnectStatus = "ready" | "needs-device-approval";
499
+ /** Options for recovering an account after losing every device signer. */
500
+ interface RecoveryOptions {
501
+ /** The recovery code the user stored when they ran setupRecovery. */
502
+ code: string;
503
+ /** Authenticated identity (same user who owns the account). */
504
+ identity: Identity;
505
+ /** Environment (recovery is Starknet-only): testnet → sepolia, mainnet. */
506
+ network: NetworkEnv;
507
+ appSalt: string;
508
+ paymasterApiKey: string;
509
+ appId?: string;
510
+ backendUrl?: string;
511
+ rpcUrl?: string;
512
+ paymasterUrl?: string;
513
+ classHash?: string;
514
+ /** Off-chain user_id -> wallet map. Defaults to the hosted registry. */
515
+ registry?: WalletRegistry;
516
+ /** Override the new device's signer (native / tests); default WebCrypto. */
517
+ createSigner?: (keyId: string) => Promise<DeviceSigner>;
518
+ }
519
+ /**
520
+ * High-level Cavos wallet. One call logs the user in and returns a ready, gas-
521
+ * sponsored smart account controlled by a silent device key.
522
+ *
523
+ * const cavos = await Cavos.connect({ network, identity, appSalt, registry, paymasterApiKey });
524
+ * if (cavos.status === "ready") await cavos.execute(calls);
525
+ *
526
+ * The account address is `f(identity, device_pubkey)` — unforgeable, so it can't
527
+ * be hijacked. The `registry` recognizes returning users across devices: a new
528
+ * device on an existing account is flagged `needs-device-approval` (add it via
529
+ * an already-registered device) instead of creating a second wallet.
530
+ */
531
+ declare class Cavos {
532
+ readonly identity: Identity;
533
+ readonly address: string;
534
+ readonly status: ConnectStatus;
535
+ readonly account: Account;
536
+ private readonly adapter;
537
+ private readonly devicePubkey;
538
+ /** Discriminant for the `CavosWallet` union — narrows `execute()` per chain. */
539
+ readonly chain: "starknet";
540
+ /** Request id of the pending device-addition, when status is needs-device-approval. */
541
+ pendingRequestId: string | null;
542
+ private constructor();
543
+ /**
544
+ * Unified entry point. Pick a `chain` and an `network` environment; the kit
545
+ * resolves the concrete network (sepolia/devnet for testnet, mainnet for
546
+ * mainnet) and returns a chain-native wallet. The result is a discriminated
547
+ * union (`wallet.chain`), so `execute()` keeps each chain's native signature:
548
+ *
549
+ * const wallet = await Cavos.connect({ chain: "solana", network: "testnet", identity, appSalt, appId });
550
+ * if (wallet.chain === "starknet") await wallet.execute(calls);
551
+ * else await wallet.execute(amount, dest);
552
+ */
553
+ static connect(opts: ConnectOptions): Promise<CavosWallet>;
554
+ private static connectStarknet;
555
+ /** This device's public key (e.g. to request addition to an existing wallet). */
556
+ get publicKey(): DevicePublicKey;
557
+ /** Execute a sponsored (gasless) multicall, signed silently by the device. */
558
+ execute(calls: ChainCall[]): Promise<{
559
+ transactionHash: string;
560
+ }>;
561
+ /** Authorize an additional device signer (sponsored). Self-submitted. */
562
+ addSigner(pubkey: DevicePublicKey): Promise<{
563
+ transactionHash: string;
564
+ }>;
565
+ /**
566
+ * Register a self-custodial backup signer derived from `code`, so the account
567
+ * can be recovered after the user loses every device. Idempotent: if the
568
+ * derived backup key is already an authorised signer, this is a no-op.
569
+ *
570
+ * The code never leaves the device — only its deterministic public key is
571
+ * added on-chain as an ordinary signer. Sponsor this like any other
572
+ * add_signer (gasless). Returns the transaction hash (or undefined when the
573
+ * backup was already set up).
574
+ */
575
+ setupRecovery(code: string): Promise<{
576
+ transactionHash: string;
577
+ } | undefined>;
578
+ /**
579
+ * Recover an account after losing every device signer. Derives the backup key
580
+ * from `code`, uses it (not the new device key) to sign an `add_signer` for
581
+ * the new device, and returns a ready Cavos bound to the new device. The
582
+ * account address is unchanged.
583
+ *
584
+ * Self-custodial: only someone holding the code (i.e. the rightful owner) can
585
+ * re-derive the backup key. The backend never sees the code.
586
+ */
587
+ static recover(opts: RecoveryOptions): Promise<Cavos>;
588
+ }
589
+
590
+ export { type AuthProvider as A, buildSecp256r1Instruction as B, type ChainAdapter as C, type DevicePublicKey as D, compressedPubkey as E, encodeLowSSignature as F, serializeInstructions as G, type Identity as I, type NetworkEnv as N, type PendingDeviceRequest as P, type RegisteredWallet as R, SECP256R1_PROGRAM_ID as S, type WalletRegistry as W, type RecoveryClient as a, type DeviceSigner as b, type DeviceSignature as c, type ComputeAddressParams as d, type ChainCall as e, Cavos as f, CavosSolana as g, type CavosWallet as h, type Chain as i, type ConnectOptions as j, type ConnectSolanaOptions as k, type ConnectStatus as l, DEVICE_ACCOUNT_PROGRAM_ID as m, InMemoryWalletRegistry as n, type InstructionAccount as o, type InstructionData as p, type RecoverSolanaOptions as q, type RecoveryOptions as r, SOLANA_NETWORKS as s, SolanaAdapter as t, type SolanaAdapterOptions as u, type SolanaNetwork as v, SolanaRelayer as w, type SolanaRelayerOptions as x, StaticIdentity as y, anchorDiscriminator as z };