@zelana/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +139 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1807 -0
- package/dist/keypair.d.ts +110 -0
- package/dist/keypair.d.ts.map +1 -0
- package/dist/shielded.d.ts +227 -0
- package/dist/shielded.d.ts.map +1 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +48 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/zelana.d.ts +213 -0
- package/dist/zelana.d.ts.map +1 -0
- package/package.json +47 -0
package/dist/zelana.d.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zelana SDK - High-level Client
|
|
3
|
+
*
|
|
4
|
+
* Combines keypair management and API client for a convenient developer experience.
|
|
5
|
+
* This is the main entry point for interacting with Zelana L2.
|
|
6
|
+
*/
|
|
7
|
+
import { Keypair } from './keypair';
|
|
8
|
+
import { ApiClient, ApiClientConfig } from './client';
|
|
9
|
+
import type { AccountState, TransferResponse, WithdrawResponse, HealthInfo, StateRoots, BatchStatusInfo, GlobalStats, TxSummary, BatchSummary, PaginationParams, DevDepositResponse, DevSealResponse } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for ZelanaClient
|
|
12
|
+
*/
|
|
13
|
+
export interface ZelanaClientConfig extends ApiClientConfig {
|
|
14
|
+
/** Default chain ID for transactions (default: 1) */
|
|
15
|
+
chainId?: bigint;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* High-level Zelana L2 client
|
|
19
|
+
*
|
|
20
|
+
* Provides a convenient interface for common operations:
|
|
21
|
+
* - Account management (balance, nonce)
|
|
22
|
+
* - Transfers (sign + submit in one call)
|
|
23
|
+
* - Withdrawals (sign + submit in one call)
|
|
24
|
+
* - Transaction queries
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { ZelanaClient, Keypair } from '@zelana/sdk';
|
|
29
|
+
*
|
|
30
|
+
* const keypair = Keypair.generate();
|
|
31
|
+
* const client = new ZelanaClient({
|
|
32
|
+
* baseUrl: 'http://localhost:3000',
|
|
33
|
+
* keypair,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Check balance
|
|
37
|
+
* const account = await client.getAccount();
|
|
38
|
+
* console.log(`Balance: ${account.balance}`);
|
|
39
|
+
*
|
|
40
|
+
* // Send transfer
|
|
41
|
+
* const result = await client.transfer(recipientPubkey, 1_000_000n);
|
|
42
|
+
* console.log(`TX Hash: ${result.txHash}`);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class ZelanaClient {
|
|
46
|
+
private readonly api;
|
|
47
|
+
private readonly keypair;
|
|
48
|
+
private readonly chainId;
|
|
49
|
+
constructor(config: ZelanaClientConfig & {
|
|
50
|
+
keypair?: Keypair;
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Get the underlying API client for low-level operations
|
|
54
|
+
*/
|
|
55
|
+
get apiClient(): ApiClient;
|
|
56
|
+
/**
|
|
57
|
+
* Get the public key of the configured keypair
|
|
58
|
+
*/
|
|
59
|
+
get publicKey(): Uint8Array | null;
|
|
60
|
+
/**
|
|
61
|
+
* Get the public key as hex string
|
|
62
|
+
*/
|
|
63
|
+
get publicKeyHex(): string | null;
|
|
64
|
+
/**
|
|
65
|
+
* Check if the sequencer is healthy
|
|
66
|
+
*/
|
|
67
|
+
isHealthy(): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Get health info
|
|
70
|
+
*/
|
|
71
|
+
health(): Promise<HealthInfo>;
|
|
72
|
+
/**
|
|
73
|
+
* Get current state roots
|
|
74
|
+
*/
|
|
75
|
+
getStateRoots(): Promise<StateRoots>;
|
|
76
|
+
/**
|
|
77
|
+
* Get current batch status
|
|
78
|
+
*/
|
|
79
|
+
getBatchStatus(): Promise<BatchStatusInfo>;
|
|
80
|
+
/**
|
|
81
|
+
* Get global statistics
|
|
82
|
+
*/
|
|
83
|
+
getStats(): Promise<GlobalStats>;
|
|
84
|
+
/**
|
|
85
|
+
* Get account state for the configured keypair
|
|
86
|
+
*/
|
|
87
|
+
getAccount(): Promise<AccountState>;
|
|
88
|
+
/**
|
|
89
|
+
* Get account state by public key
|
|
90
|
+
*/
|
|
91
|
+
getAccountFor(pubkey: Uint8Array | string): Promise<AccountState>;
|
|
92
|
+
/**
|
|
93
|
+
* Get current balance for the configured keypair
|
|
94
|
+
*/
|
|
95
|
+
getBalance(): Promise<bigint>;
|
|
96
|
+
/**
|
|
97
|
+
* Get current nonce for the configured keypair
|
|
98
|
+
*/
|
|
99
|
+
getNonce(): Promise<bigint>;
|
|
100
|
+
/**
|
|
101
|
+
* Transfer funds to another account
|
|
102
|
+
*
|
|
103
|
+
* Signs and submits a transfer transaction in one call.
|
|
104
|
+
* Automatically fetches the current nonce if not provided.
|
|
105
|
+
*
|
|
106
|
+
* @param to - Recipient public key (bytes or hex string)
|
|
107
|
+
* @param amount - Amount to transfer in lamports
|
|
108
|
+
* @param nonce - Optional nonce (auto-fetched if not provided)
|
|
109
|
+
* @returns Transfer response with transaction hash
|
|
110
|
+
*/
|
|
111
|
+
transfer(to: Uint8Array | string, amount: bigint, nonce?: bigint): Promise<TransferResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Transfer all funds to another account (minus a small reserve)
|
|
114
|
+
*
|
|
115
|
+
* @param to - Recipient public key
|
|
116
|
+
* @param reserve - Amount to keep (default: 0)
|
|
117
|
+
*/
|
|
118
|
+
transferAll(to: Uint8Array | string, reserve?: bigint): Promise<TransferResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* Withdraw funds to L1 (Solana)
|
|
121
|
+
*
|
|
122
|
+
* Signs and submits a withdrawal request in one call.
|
|
123
|
+
* Automatically fetches the current nonce if not provided.
|
|
124
|
+
*
|
|
125
|
+
* @param toL1Address - Destination Solana address (bytes or base58)
|
|
126
|
+
* @param amount - Amount to withdraw in lamports
|
|
127
|
+
* @param nonce - Optional nonce (auto-fetched if not provided)
|
|
128
|
+
* @returns Withdrawal response with transaction hash
|
|
129
|
+
*/
|
|
130
|
+
withdraw(toL1Address: Uint8Array | string, amount: bigint, nonce?: bigint): Promise<WithdrawResponse>;
|
|
131
|
+
/**
|
|
132
|
+
* Get withdrawal status
|
|
133
|
+
*/
|
|
134
|
+
getWithdrawalStatus(txHash: string): Promise<import("./types").WithdrawalStatus>;
|
|
135
|
+
/**
|
|
136
|
+
* Get fast withdrawal quote
|
|
137
|
+
*/
|
|
138
|
+
getFastWithdrawQuote(amount: bigint): Promise<import("./types").FastWithdrawQuote>;
|
|
139
|
+
/**
|
|
140
|
+
* Get transaction by hash
|
|
141
|
+
*/
|
|
142
|
+
getTransaction(txHash: string): Promise<TxSummary | null>;
|
|
143
|
+
/**
|
|
144
|
+
* List transactions with optional filters
|
|
145
|
+
*/
|
|
146
|
+
listTransactions(params?: PaginationParams & {
|
|
147
|
+
batchId?: bigint;
|
|
148
|
+
txType?: string;
|
|
149
|
+
status?: string;
|
|
150
|
+
}): Promise<{
|
|
151
|
+
transactions: TxSummary[];
|
|
152
|
+
total: number;
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Get batch by ID
|
|
156
|
+
*/
|
|
157
|
+
getBatch(batchId: bigint): Promise<BatchSummary | null>;
|
|
158
|
+
/**
|
|
159
|
+
* List batches
|
|
160
|
+
*/
|
|
161
|
+
listBatches(params?: PaginationParams): Promise<{
|
|
162
|
+
batches: BatchSummary[];
|
|
163
|
+
total: number;
|
|
164
|
+
}>;
|
|
165
|
+
/**
|
|
166
|
+
* Wait for a transaction to reach a specific status
|
|
167
|
+
*
|
|
168
|
+
* @param txHash - Transaction hash to wait for
|
|
169
|
+
* @param targetStatus - Status to wait for (default: 'executed')
|
|
170
|
+
* @param timeoutMs - Maximum wait time (default: 60000)
|
|
171
|
+
* @param pollIntervalMs - Poll interval (default: 1000)
|
|
172
|
+
*/
|
|
173
|
+
waitForTransaction(txHash: string, targetStatus?: 'included' | 'executed' | 'settled', timeoutMs?: number, pollIntervalMs?: number): Promise<TxSummary>;
|
|
174
|
+
/**
|
|
175
|
+
* Wait for a batch to be settled on L1
|
|
176
|
+
*/
|
|
177
|
+
waitForBatch(batchId: bigint, timeoutMs?: number, pollIntervalMs?: number): Promise<BatchSummary>;
|
|
178
|
+
/**
|
|
179
|
+
* Simulate a deposit from L1 (DEV MODE ONLY)
|
|
180
|
+
*
|
|
181
|
+
* This method is only available when the sequencer is running with DEV_MODE=true.
|
|
182
|
+
* It bypasses the L1 indexer and directly credits funds to the configured keypair's account.
|
|
183
|
+
*
|
|
184
|
+
* @param amount - Amount to deposit in lamports
|
|
185
|
+
* @returns Deposit response with new balance
|
|
186
|
+
* @throws ZelanaError if dev mode is not enabled (404) or no keypair configured
|
|
187
|
+
*/
|
|
188
|
+
devDeposit(amount: bigint): Promise<DevDepositResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Simulate a deposit to a specific account (DEV MODE ONLY)
|
|
191
|
+
*
|
|
192
|
+
* This method is only available when the sequencer is running with DEV_MODE=true.
|
|
193
|
+
* It bypasses the L1 indexer and directly credits funds to the specified account.
|
|
194
|
+
*
|
|
195
|
+
* @param to - Recipient public key (bytes or hex string)
|
|
196
|
+
* @param amount - Amount to deposit in lamports
|
|
197
|
+
* @returns Deposit response with new balance
|
|
198
|
+
* @throws ZelanaError if dev mode is not enabled (404)
|
|
199
|
+
*/
|
|
200
|
+
devDepositTo(to: Uint8Array | string, amount: bigint): Promise<DevDepositResponse>;
|
|
201
|
+
/**
|
|
202
|
+
* Force seal the current batch (DEV MODE ONLY)
|
|
203
|
+
*
|
|
204
|
+
* This method is only available when the sequencer is running with DEV_MODE=true.
|
|
205
|
+
* It forces the current batch to seal immediately, bypassing the normal seal triggers.
|
|
206
|
+
*
|
|
207
|
+
* @param waitForProof - Whether to wait for proof generation (default: false)
|
|
208
|
+
* @returns Seal response with batch ID and transaction count
|
|
209
|
+
* @throws ZelanaError if dev mode is not enabled (404)
|
|
210
|
+
*/
|
|
211
|
+
devSeal(waitForProof?: boolean): Promise<DevSealResponse>;
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=zelana.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zelana.d.ts","sourceRoot":"","sources":["../src/zelana.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAa,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGtD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,eAAe,EACf,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,kBAAkB,GAAG;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;IAM9D;;OAEG;IACH,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,CAEjC;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,IAAI,CAEhC;IAMD;;OAEG;IAC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|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "bun build src/index.ts --outdir dist --target browser && tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
21
|
+
"prepack": "npm run build",
|
|
22
|
+
"prepublishOnly": "npm run build",
|
|
23
|
+
"test": "bun test",
|
|
24
|
+
"typecheck": "tsc --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@noble/ed25519": "^2.1.0",
|
|
28
|
+
"@noble/hashes": "^1.4.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/bun": "latest",
|
|
32
|
+
"typescript": "^5.3.0"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"zelana",
|
|
36
|
+
"solana",
|
|
37
|
+
"l2",
|
|
38
|
+
"rollup",
|
|
39
|
+
"privacy",
|
|
40
|
+
"zk"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/zelana/zelana"
|
|
46
|
+
}
|
|
47
|
+
}
|