@cavos/cli 0.0.1

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,192 @@
1
+ import { Call } from 'starknet';
2
+ export { Call } from 'starknet';
3
+
4
+ interface SessionKeyPolicy {
5
+ spendingLimits: Array<{
6
+ token: string;
7
+ limit: bigint;
8
+ }>;
9
+ allowedContracts: string[];
10
+ maxCallsPerTx: number;
11
+ }
12
+ interface AgentConfig {
13
+ appId: string;
14
+ network?: 'mainnet' | 'sepolia';
15
+ backendUrl?: string;
16
+ starknetRpcUrl?: string;
17
+ paymasterApiKey?: string;
18
+ policy?: SessionKeyPolicy;
19
+ sessionDuration?: number;
20
+ renewalGracePeriod?: number;
21
+ }
22
+ interface NonceParams {
23
+ sessionPubKey: string;
24
+ validAfter: bigint;
25
+ validUntil: bigint;
26
+ renewalDeadline: bigint;
27
+ randomness: bigint;
28
+ }
29
+ interface JWTClaims {
30
+ sub: string;
31
+ nonce: string;
32
+ exp: number;
33
+ iss: string;
34
+ aud: string;
35
+ }
36
+ interface SessionStatus {
37
+ registered: boolean;
38
+ expired: boolean;
39
+ canRenew: boolean;
40
+ validUntil?: bigint;
41
+ renewalDeadline?: bigint;
42
+ }
43
+
44
+ declare class CavosAgent {
45
+ private config;
46
+ private provider;
47
+ private session;
48
+ private appSalt;
49
+ constructor(config: AgentConfig);
50
+ /**
51
+ * Login with Firebase email/password.
52
+ * Generates session keys, authenticates, and persists the session.
53
+ */
54
+ login(email: string, password: string, walletName?: string): Promise<void>;
55
+ /**
56
+ * Login using a pre-existing JWT token.
57
+ * Useful for non-interactive agents or CI/CD.
58
+ */
59
+ loginWithJWT(jwt: string, walletName?: string): Promise<void>;
60
+ /**
61
+ * Check if the agent has a valid session.
62
+ */
63
+ isAuthenticated(): boolean;
64
+ /**
65
+ * Get the wallet address.
66
+ */
67
+ getAddress(): string | null;
68
+ /**
69
+ * Logout — clear the persisted session.
70
+ */
71
+ logout(): void;
72
+ /**
73
+ * Execute one or more calls via paymaster.
74
+ * Handles session registration automatically on first call.
75
+ */
76
+ execute(calls: Call | Call[]): Promise<string>;
77
+ /**
78
+ * Transfer ERC-20 tokens.
79
+ */
80
+ transfer(tokenAddress: string, to: string, amount: bigint): Promise<string>;
81
+ /**
82
+ * Approve ERC-20 spending.
83
+ */
84
+ approve(tokenAddress: string, spender: string, amount: bigint): Promise<string>;
85
+ /**
86
+ * Deploy the account contract.
87
+ */
88
+ deploy(): Promise<string>;
89
+ /**
90
+ * Get ERC-20 balance.
91
+ */
92
+ getBalance(tokenAddress?: string): Promise<bigint>;
93
+ /**
94
+ * Check if the account is deployed.
95
+ */
96
+ isDeployed(): Promise<boolean>;
97
+ /**
98
+ * Get on-chain session status.
99
+ */
100
+ getSessionStatus(): Promise<SessionStatus>;
101
+ /**
102
+ * Renew the current session (if in grace period).
103
+ */
104
+ renewSession(): Promise<string>;
105
+ /**
106
+ * Revoke a specific session key (defaults to current).
107
+ */
108
+ revokeSession(sessionKey?: string): Promise<string>;
109
+ /**
110
+ * Emergency revoke all sessions.
111
+ */
112
+ emergencyRevokeAll(): Promise<string>;
113
+ private ensureSession;
114
+ private getSalt;
115
+ private getPaymasterKey;
116
+ private restoreSession;
117
+ }
118
+
119
+ /**
120
+ * Generate a new session key pair.
121
+ */
122
+ declare function generateSessionKeyPair(): {
123
+ privateKey: string;
124
+ publicKey: string;
125
+ };
126
+ /**
127
+ * Build a lightweight session signature (SESSION_V1).
128
+ * Used for transactions after the session is registered on-chain.
129
+ */
130
+ declare function buildSessionSignature(transactionHash: string, sessionPrivateKey: string, sessionPubKey: string, calls?: {
131
+ contractAddress: string;
132
+ }[], policy?: SessionKeyPolicy): string[];
133
+ /**
134
+ * Build the full JWT signature data (OAUTH_JWT_V1) for on-chain verification.
135
+ * Used for the first transaction to register the session.
136
+ */
137
+ declare function buildJWTSignatureData(transactionHash: string, session: {
138
+ jwt: string;
139
+ sessionPrivateKey: string;
140
+ sessionPubKey: string;
141
+ nonce: string;
142
+ nonceParams: NonceParams;
143
+ jwtClaims: {
144
+ sub: string;
145
+ nonce: string;
146
+ exp: number;
147
+ iss: string;
148
+ aud: string;
149
+ };
150
+ sessionPolicy?: SessionKeyPolicy;
151
+ }, salt: string, backendUrl: string): Promise<string[]>;
152
+
153
+ /**
154
+ * Compute the nonce for a session.
155
+ * Must match Cairo: PoseidonTrait::new().update(session_key).update(valid_until).update(randomness).finalize()
156
+ */
157
+ declare function computeNonce(params: NonceParams): string;
158
+ /**
159
+ * Generate nonce parameters for a new session.
160
+ */
161
+ declare function generateNonceParams(sessionPubKey: string, currentTimestamp: bigint, sessionDurationSeconds?: bigint, renewalGraceSeconds?: bigint): NonceParams;
162
+
163
+ /**
164
+ * Compute the address seed from a user's OAuth `sub` claim and a salt.
165
+ * The salt can optionally incorporate a wallet name to allow multiple addresses per sub.
166
+ */
167
+ declare function computeAddressSeed(sub: string, salt: string, walletName?: string): string;
168
+ /**
169
+ * Compute the contract address for an OAuth wallet.
170
+ */
171
+ declare function computeContractAddress(sub: string, salt: string, classHash: string, jwksRegistryAddress: string, walletName?: string): string;
172
+
173
+ /**
174
+ * Compute Merkle root from a list of allowed contract addresses.
175
+ * Uses Poseidon hash, matching the on-chain verification.
176
+ */
177
+ declare function computeMerkleRoot(contracts: string[]): string;
178
+ /**
179
+ * Compute Merkle proof for a given contract address.
180
+ */
181
+ declare function computeMerkleProof(contracts: string[], targetContract: string): string[];
182
+
183
+ declare const TOKENS_SEPOLIA: {
184
+ readonly STRK: "0x04718f5a0Fc34cC1AF16A1cdee98fFB20C31f5cD61D6Ab07201858f4287c938D";
185
+ readonly ETH: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
186
+ };
187
+ declare const TOKENS_MAINNET: {
188
+ readonly STRK: "0x04718f5a0Fc34cC1AF16A1cdee98fFB20C31f5cD61D6Ab07201858f4287c938D";
189
+ readonly ETH: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
190
+ };
191
+
192
+ export { type AgentConfig, CavosAgent, type JWTClaims, type NonceParams, type SessionKeyPolicy, type SessionStatus, TOKENS_MAINNET, TOKENS_SEPOLIA, buildJWTSignatureData, buildSessionSignature, computeAddressSeed, computeContractAddress, computeMerkleProof, computeMerkleRoot, computeNonce, generateNonceParams, generateSessionKeyPair };