@no-witness-labs/midday-sdk 0.2.4 → 0.2.6
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/README.md +60 -82
- package/dist/Client.d.ts +290 -340
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +318 -359
- package/dist/Client.js.map +1 -1
- package/dist/Config.d.ts +2 -57
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +1 -47
- package/dist/Config.js.map +1 -1
- package/dist/Hash.d.ts +126 -0
- package/dist/Hash.d.ts.map +1 -0
- package/dist/Hash.js +146 -0
- package/dist/Hash.js.map +1 -0
- package/dist/PrivateState.d.ts +9 -0
- package/dist/PrivateState.d.ts.map +1 -0
- package/dist/PrivateState.js +9 -0
- package/dist/PrivateState.js.map +1 -0
- package/dist/Providers.d.ts +42 -63
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +34 -62
- package/dist/Providers.js.map +1 -1
- package/dist/Runtime.d.ts +8 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +8 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/Wallet.d.ts +1 -1
- package/dist/Wallet.d.ts.map +1 -1
- package/dist/Wallet.js +2 -0
- package/dist/Wallet.js.map +1 -1
- package/dist/ZkConfig.d.ts +80 -0
- package/dist/ZkConfig.d.ts.map +1 -0
- package/dist/ZkConfig.js +85 -0
- package/dist/ZkConfig.js.map +1 -0
- package/dist/devnet/Cluster.d.ts +0 -9
- package/dist/devnet/Cluster.d.ts.map +1 -1
- package/dist/devnet/Cluster.js +0 -13
- package/dist/devnet/Cluster.js.map +1 -1
- package/dist/devnet/index.d.ts +9 -8
- package/dist/devnet/index.d.ts.map +1 -1
- package/dist/devnet/index.js +9 -8
- package/dist/devnet/index.js.map +1 -1
- package/dist/index.d.ts +30 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -52
- package/dist/index.js.map +1 -1
- package/dist/providers/HttpZkConfigProvider.d.ts +8 -6
- package/dist/providers/HttpZkConfigProvider.d.ts.map +1 -1
- package/dist/providers/HttpZkConfigProvider.js +8 -6
- package/dist/providers/HttpZkConfigProvider.js.map +1 -1
- package/dist/providers/IndexedDBPrivateStateProvider.d.ts +8 -8
- package/dist/providers/IndexedDBPrivateStateProvider.js +8 -8
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/wallet/connector.d.ts +1 -1
- package/dist/wallet/connector.js +1 -1
- package/dist/wallet/index.d.ts +15 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +18 -0
- package/dist/wallet/index.js.map +1 -0
- package/package.json +1 -1
- package/dist/sdk/Type.d.ts +0 -91
- package/dist/sdk/Type.d.ts.map +0 -1
- package/dist/sdk/Type.js +0 -8
- package/dist/sdk/Type.js.map +0 -1
package/dist/Client.d.ts
CHANGED
|
@@ -3,26 +3,31 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ## API Design
|
|
5
5
|
*
|
|
6
|
-
* This module uses a **
|
|
6
|
+
* This module uses a **Client-centric hub pattern** following the Effect hybrid pattern:
|
|
7
7
|
*
|
|
8
|
-
* - **
|
|
9
|
-
* - **
|
|
10
|
-
* - **
|
|
8
|
+
* - **Effect is source of truth**: All logic in Effect functions
|
|
9
|
+
* - **Client is the hub**: All operations flow from the client
|
|
10
|
+
* - **Two interfaces**: `.effect.method()` for Effect users, `.method()` for Promise users
|
|
11
|
+
* - **Effects call Effects, Promises call Promises**: Never mix execution models
|
|
11
12
|
*
|
|
12
13
|
* ### Usage Patterns
|
|
13
14
|
*
|
|
14
15
|
* ```typescript
|
|
15
|
-
* // Promise user
|
|
16
|
-
* const client = await Client.create(config);
|
|
17
|
-
* const
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const
|
|
24
|
-
*
|
|
25
|
-
*
|
|
16
|
+
* // Promise user - simple flow
|
|
17
|
+
* const client = await Midday.Client.create(config);
|
|
18
|
+
* const contract = await client.loadContract({ path: './contracts/counter' });
|
|
19
|
+
* await contract.deploy();
|
|
20
|
+
* await contract.call('increment');
|
|
21
|
+
* const state = await contract.ledgerState();
|
|
22
|
+
*
|
|
23
|
+
* // Effect user - compositional
|
|
24
|
+
* const program = Effect.gen(function* () {
|
|
25
|
+
* const client = yield* Midday.Client.effect.create(config);
|
|
26
|
+
* const contract = yield* client.effect.loadContract({ path: './contracts/counter' });
|
|
27
|
+
* yield* contract.effect.deploy();
|
|
28
|
+
* yield* contract.effect.call('increment');
|
|
29
|
+
* const state = yield* contract.effect.ledgerState();
|
|
30
|
+
* });
|
|
26
31
|
* ```
|
|
27
32
|
*
|
|
28
33
|
* @since 0.1.0
|
|
@@ -31,7 +36,7 @@
|
|
|
31
36
|
import { Context, Effect, Layer } from 'effect';
|
|
32
37
|
import type { ZKConfigProvider, PrivateStateProvider } from '@midnight-ntwrk/midnight-js-types';
|
|
33
38
|
import type { NetworkConfig } from './Config.js';
|
|
34
|
-
import type { ContractProviders, StorageConfig } from './Providers.js';
|
|
39
|
+
import type { BaseProviders, ContractProviders, StorageConfig } from './Providers.js';
|
|
35
40
|
import type { WalletContext } from './Wallet.js';
|
|
36
41
|
import type { WalletConnection } from './wallet/connector.js';
|
|
37
42
|
declare const ClientError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
@@ -75,8 +80,6 @@ export interface ClientConfig {
|
|
|
75
80
|
networkConfig?: NetworkConfig;
|
|
76
81
|
/** Wallet seed (required for non-local networks) */
|
|
77
82
|
seed?: string;
|
|
78
|
-
/** ZK configuration provider (required) */
|
|
79
|
-
zkConfigProvider: ZKConfigProvider<string>;
|
|
80
83
|
/** Private state provider (required) */
|
|
81
84
|
privateStateProvider: PrivateStateProvider;
|
|
82
85
|
/** Storage configuration */
|
|
@@ -87,14 +90,27 @@ export interface ClientConfig {
|
|
|
87
90
|
/**
|
|
88
91
|
* Options for loading a contract.
|
|
89
92
|
*
|
|
93
|
+
* Exactly one of these must be provided:
|
|
94
|
+
* - `module` + `zkConfig`: Direct module and zkConfig (works everywhere)
|
|
95
|
+
* - `path`: Load from filesystem path (Node.js only)
|
|
96
|
+
* - `moduleUrl` + `zkConfigBaseUrl`: Load from URLs (browser)
|
|
97
|
+
*
|
|
98
|
+
* @typeParam M - The contract module type (for type inference)
|
|
99
|
+
*
|
|
90
100
|
* @since 0.2.0
|
|
91
101
|
* @category model
|
|
92
102
|
*/
|
|
93
|
-
export interface
|
|
94
|
-
/** Contract module
|
|
95
|
-
module?:
|
|
96
|
-
/**
|
|
97
|
-
|
|
103
|
+
export interface LoadContractOptions<M extends ContractModule = ContractModule> {
|
|
104
|
+
/** Contract module */
|
|
105
|
+
module?: M;
|
|
106
|
+
/** ZK configuration provider for this contract */
|
|
107
|
+
zkConfig?: ZKConfigProvider<string>;
|
|
108
|
+
/** Filesystem path to contract directory (auto-loads module + zkConfig) */
|
|
109
|
+
path?: string;
|
|
110
|
+
/** URL to contract module JS file */
|
|
111
|
+
moduleUrl?: string;
|
|
112
|
+
/** Base URL for ZK artifacts */
|
|
113
|
+
zkConfigBaseUrl?: string;
|
|
98
114
|
/** Witnesses for the contract */
|
|
99
115
|
witnesses?: Record<string, unknown>;
|
|
100
116
|
/** Override privateStateId (defaults to contract name) */
|
|
@@ -134,22 +150,50 @@ export interface FinalizedTxData {
|
|
|
134
150
|
/**
|
|
135
151
|
* A contract module definition.
|
|
136
152
|
*
|
|
153
|
+
* @typeParam TLedger - The ledger state type returned by the ledger function
|
|
154
|
+
* @typeParam TCircuits - Union of circuit names (e.g., 'increment' | 'decrement')
|
|
155
|
+
*
|
|
137
156
|
* @since 0.2.0
|
|
138
157
|
* @category model
|
|
139
158
|
*/
|
|
140
|
-
export interface ContractModule {
|
|
141
|
-
Contract: new (witnesses:
|
|
142
|
-
|
|
159
|
+
export interface ContractModule<TLedger = unknown, TCircuits extends string = string> {
|
|
160
|
+
Contract: new (witnesses: any) => {
|
|
161
|
+
impureCircuits: Record<TCircuits, (...args: any[]) => any>;
|
|
162
|
+
};
|
|
163
|
+
ledger: (state: any) => TLedger;
|
|
143
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Infer the Ledger type from a contract module.
|
|
167
|
+
*
|
|
168
|
+
* @since 0.2.6
|
|
169
|
+
* @category type
|
|
170
|
+
*/
|
|
171
|
+
export type InferLedger<M> = M extends ContractModule<infer L, string> ? L : unknown;
|
|
172
|
+
/**
|
|
173
|
+
* Infer the circuit names from a contract module.
|
|
174
|
+
*
|
|
175
|
+
* @since 0.2.6
|
|
176
|
+
* @category type
|
|
177
|
+
*/
|
|
178
|
+
export type InferCircuits<M> = M extends {
|
|
179
|
+
Contract: new (...args: any[]) => {
|
|
180
|
+
impureCircuits: infer IC;
|
|
181
|
+
};
|
|
182
|
+
} ? keyof IC & string : string;
|
|
144
183
|
/**
|
|
145
184
|
* A loaded contract module with configuration.
|
|
146
185
|
*
|
|
186
|
+
* @typeParam TLedger - The ledger state type
|
|
187
|
+
* @typeParam TCircuits - Union of circuit names
|
|
188
|
+
*
|
|
147
189
|
* @since 0.2.0
|
|
148
190
|
* @category model
|
|
149
191
|
*/
|
|
150
|
-
export interface LoadedContractModule {
|
|
151
|
-
Contract: new (witnesses:
|
|
152
|
-
|
|
192
|
+
export interface LoadedContractModule<TLedger = unknown, TCircuits extends string = string> {
|
|
193
|
+
Contract: new (witnesses: any) => {
|
|
194
|
+
impureCircuits: Record<TCircuits, (...args: any[]) => any>;
|
|
195
|
+
};
|
|
196
|
+
ledger: (state: any) => TLedger;
|
|
153
197
|
privateStateId: string;
|
|
154
198
|
witnesses: Record<string, unknown>;
|
|
155
199
|
}
|
|
@@ -165,84 +209,170 @@ export interface CallResult {
|
|
|
165
209
|
status: string;
|
|
166
210
|
}
|
|
167
211
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* This is plain data - use module functions to operate on it.
|
|
212
|
+
* A Midnight client handle with convenience methods.
|
|
171
213
|
*
|
|
172
|
-
* @since 0.
|
|
214
|
+
* @since 0.5.0
|
|
173
215
|
* @category model
|
|
174
216
|
*/
|
|
175
|
-
export interface
|
|
176
|
-
/** Raw wallet context for advanced use (null if using wallet connector) */
|
|
177
|
-
readonly wallet: WalletContext | null;
|
|
217
|
+
export interface MiddayClient {
|
|
178
218
|
/** Network configuration */
|
|
179
219
|
readonly networkConfig: NetworkConfig;
|
|
180
|
-
/**
|
|
181
|
-
readonly providers:
|
|
182
|
-
/**
|
|
183
|
-
readonly
|
|
220
|
+
/** Base providers (for advanced use - no zkConfig) */
|
|
221
|
+
readonly providers: BaseProviders;
|
|
222
|
+
/** Raw wallet context (null if using wallet connector) */
|
|
223
|
+
readonly wallet: WalletContext | null;
|
|
224
|
+
/**
|
|
225
|
+
* Load a contract module. Returns a Contract in "loaded" state.
|
|
226
|
+
* Call `deploy()` or `join()` on it to connect to the network.
|
|
227
|
+
*
|
|
228
|
+
* @typeParam M - Contract module type (inferred from options.module)
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Load with module - types are inferred!
|
|
233
|
+
* import * as CounterContract from './contracts/counter/contract';
|
|
234
|
+
*
|
|
235
|
+
* const contract = await client.loadContract({
|
|
236
|
+
* module: CounterContract,
|
|
237
|
+
* zkConfig: Midday.ZkConfig.fromPath('./contracts/counter'),
|
|
238
|
+
* });
|
|
239
|
+
* const state = await contract.ledgerState(); // state.counter is typed
|
|
240
|
+
* await contract.call('increment'); // autocompletes circuit names
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
loadContract<M extends ContractModule>(options: LoadContractOptions<M>): Promise<Contract<InferLedger<M>, InferCircuits<M>>>;
|
|
244
|
+
/**
|
|
245
|
+
* Wait for a transaction to be finalized.
|
|
246
|
+
*/
|
|
247
|
+
waitForTx(txHash: string): Promise<FinalizedTxData>;
|
|
248
|
+
/** Effect versions of client methods */
|
|
249
|
+
readonly effect: {
|
|
250
|
+
loadContract<M extends ContractModule>(options: LoadContractOptions<M>): Effect.Effect<Contract<InferLedger<M>, InferCircuits<M>>, ClientError>;
|
|
251
|
+
waitForTx(txHash: string): Effect.Effect<FinalizedTxData, ClientError>;
|
|
252
|
+
};
|
|
184
253
|
}
|
|
185
254
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* This is plain data - use module functions to operate on it.
|
|
255
|
+
* Contract state: either "loaded" (pre-deploy) or "deployed" (connected to network).
|
|
189
256
|
*
|
|
190
|
-
* @since 0.
|
|
257
|
+
* @since 0.6.0
|
|
191
258
|
* @category model
|
|
192
259
|
*/
|
|
193
|
-
export
|
|
194
|
-
/** The loaded contract module */
|
|
195
|
-
readonly module: LoadedContractModule;
|
|
196
|
-
/** Contract providers */
|
|
197
|
-
readonly providers: ContractProviders;
|
|
198
|
-
/** Whether logging is enabled */
|
|
199
|
-
readonly logging: boolean;
|
|
200
|
-
}
|
|
260
|
+
export type ContractState = 'loaded' | 'deployed';
|
|
201
261
|
/**
|
|
202
|
-
*
|
|
262
|
+
* A contract handle that manages the full lifecycle: load → deploy/join → call.
|
|
203
263
|
*
|
|
204
|
-
*
|
|
264
|
+
* The contract has two states:
|
|
265
|
+
* - **loaded**: Contract module loaded, ready for deploy() or join()
|
|
266
|
+
* - **deployed**: Connected to network, ready for call() and ledgerState()
|
|
205
267
|
*
|
|
206
|
-
* @
|
|
268
|
+
* @typeParam TLedger - The ledger state type (inferred from module)
|
|
269
|
+
* @typeParam TCircuits - Union of circuit names (inferred from module)
|
|
270
|
+
*
|
|
271
|
+
* @since 0.2.6
|
|
207
272
|
* @category model
|
|
208
273
|
*/
|
|
209
|
-
export interface
|
|
210
|
-
/**
|
|
211
|
-
readonly
|
|
212
|
-
/** The
|
|
213
|
-
readonly
|
|
214
|
-
/** The loaded module
|
|
215
|
-
readonly module: LoadedContractModule
|
|
216
|
-
/**
|
|
274
|
+
export interface Contract<TLedger = unknown, TCircuits extends string = string> {
|
|
275
|
+
/** Current state of the contract */
|
|
276
|
+
readonly state: ContractState;
|
|
277
|
+
/** The deployed contract address (undefined until deployed/joined) */
|
|
278
|
+
readonly address: string | undefined;
|
|
279
|
+
/** The loaded contract module */
|
|
280
|
+
readonly module: LoadedContractModule<TLedger, TCircuits>;
|
|
281
|
+
/** Contract providers (for advanced use) */
|
|
217
282
|
readonly providers: ContractProviders;
|
|
218
|
-
/**
|
|
219
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Deploy a new contract instance.
|
|
285
|
+
* Transitions state from "loaded" to "deployed".
|
|
286
|
+
*
|
|
287
|
+
* @throws {ContractError} If already deployed
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* await contract.deploy();
|
|
291
|
+
* console.log(contract.address); // Now available
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
deploy(options?: DeployOptions): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Join an existing contract at an address.
|
|
297
|
+
* Transitions state from "loaded" to "deployed".
|
|
298
|
+
*
|
|
299
|
+
* @throws {ContractError} If already deployed
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* await contract.join('0x...');
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
join(address: string, options?: JoinOptions): Promise<void>;
|
|
306
|
+
/**
|
|
307
|
+
* Call a contract action.
|
|
308
|
+
*
|
|
309
|
+
* @throws {ContractError} If not deployed
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const result = await contract.call('increment');
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
call(action: TCircuits, ...args: unknown[]): Promise<CallResult>;
|
|
316
|
+
/**
|
|
317
|
+
* Get raw contract state.
|
|
318
|
+
*
|
|
319
|
+
* @throws {ContractError} If not deployed
|
|
320
|
+
*/
|
|
321
|
+
getState(): Promise<unknown>;
|
|
322
|
+
/**
|
|
323
|
+
* Get raw contract state at a specific block height.
|
|
324
|
+
*
|
|
325
|
+
* @throws {ContractError} If not deployed
|
|
326
|
+
*/
|
|
327
|
+
getStateAt(blockHeight: number): Promise<unknown>;
|
|
328
|
+
/**
|
|
329
|
+
* Get parsed ledger state.
|
|
330
|
+
*
|
|
331
|
+
* @throws {ContractError} If not deployed
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* const state = await contract.ledgerState();
|
|
335
|
+
* console.log(state.counter); // Typed!
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
ledgerState(): Promise<TLedger>;
|
|
339
|
+
/**
|
|
340
|
+
* Get parsed ledger state at a specific block height.
|
|
341
|
+
*
|
|
342
|
+
* @throws {ContractError} If not deployed
|
|
343
|
+
*/
|
|
344
|
+
ledgerStateAt(blockHeight: number): Promise<TLedger>;
|
|
345
|
+
/** Effect versions of contract methods */
|
|
346
|
+
readonly effect: {
|
|
347
|
+
deploy(options?: DeployOptions): Effect.Effect<void, ContractError>;
|
|
348
|
+
join(address: string, options?: JoinOptions): Effect.Effect<void, ContractError>;
|
|
349
|
+
call(action: TCircuits, ...args: unknown[]): Effect.Effect<CallResult, ContractError>;
|
|
350
|
+
getState(): Effect.Effect<unknown, ContractError>;
|
|
351
|
+
getStateAt(blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
352
|
+
ledgerState(): Effect.Effect<TLedger, ContractError>;
|
|
353
|
+
ledgerStateAt(blockHeight: number): Effect.Effect<TLedger, ContractError>;
|
|
354
|
+
};
|
|
220
355
|
}
|
|
221
|
-
declare function createEffect(config: ClientConfig): Effect.Effect<MidnightClient, ClientError>;
|
|
222
|
-
declare function fromWalletEffect(connection: WalletConnection, config: {
|
|
223
|
-
zkConfigProvider: ZKConfigProvider<string>;
|
|
224
|
-
privateStateProvider: PrivateStateProvider;
|
|
225
|
-
logging?: boolean;
|
|
226
|
-
}): Effect.Effect<MidnightClient, ClientError>;
|
|
227
|
-
declare function contractFromEffect(client: MidnightClient, options: ContractFromOptions): Effect.Effect<ContractBuilder, ClientError>;
|
|
228
|
-
declare function waitForTxEffect(client: MidnightClient, txHash: string): Effect.Effect<FinalizedTxData, ClientError>;
|
|
229
356
|
/**
|
|
230
|
-
* Create a Midnight client for interacting with contracts
|
|
357
|
+
* Create a Midnight client for interacting with contracts.
|
|
231
358
|
*
|
|
232
359
|
* @example
|
|
233
360
|
* ```typescript
|
|
234
|
-
* const client = await Client.create({
|
|
361
|
+
* const client = await Midday.Client.create({
|
|
235
362
|
* seed: 'your-64-char-hex-seed',
|
|
236
|
-
* networkConfig: Config.NETWORKS.local,
|
|
237
|
-
* zkConfigProvider,
|
|
363
|
+
* networkConfig: Midday.Config.NETWORKS.local,
|
|
238
364
|
* privateStateProvider,
|
|
239
365
|
* });
|
|
366
|
+
*
|
|
367
|
+
* const contract = await client.loadContract({ path: './contracts/counter' });
|
|
368
|
+
* await contract.deploy();
|
|
369
|
+
* await contract.call('increment');
|
|
240
370
|
* ```
|
|
241
371
|
*
|
|
242
372
|
* @since 0.2.0
|
|
243
373
|
* @category constructors
|
|
244
374
|
*/
|
|
245
|
-
export declare function create(config: ClientConfig): Promise<
|
|
375
|
+
export declare function create(config: ClientConfig): Promise<MiddayClient>;
|
|
246
376
|
/**
|
|
247
377
|
* Create a Midnight client from a connected wallet (browser).
|
|
248
378
|
*
|
|
@@ -250,235 +380,118 @@ export declare function create(config: ClientConfig): Promise<MidnightClient>;
|
|
|
250
380
|
* @category constructors
|
|
251
381
|
*/
|
|
252
382
|
export declare function fromWallet(connection: WalletConnection, config: {
|
|
253
|
-
zkConfigProvider: ZKConfigProvider<string>;
|
|
254
383
|
privateStateProvider: PrivateStateProvider;
|
|
255
384
|
logging?: boolean;
|
|
256
|
-
}): Promise<
|
|
385
|
+
}): Promise<MiddayClient>;
|
|
257
386
|
/**
|
|
258
|
-
*
|
|
387
|
+
* Raw Effect APIs for advanced users who want to compose Effects.
|
|
259
388
|
*
|
|
260
389
|
* @example
|
|
261
390
|
* ```typescript
|
|
262
|
-
* const
|
|
263
|
-
*
|
|
391
|
+
* const program = Effect.gen(function* () {
|
|
392
|
+
* const client = yield* Midday.Client.effect.create(config);
|
|
393
|
+
* const contract = yield* client.effect.loadContract({ module });
|
|
394
|
+
* yield* contract.effect.deploy();
|
|
395
|
+
* yield* contract.effect.call('increment');
|
|
264
396
|
* });
|
|
265
397
|
* ```
|
|
266
398
|
*
|
|
267
399
|
* @since 0.2.0
|
|
268
|
-
* @category operations
|
|
269
|
-
*/
|
|
270
|
-
export declare function contractFrom(client: MidnightClient, options: ContractFromOptions): Promise<ContractBuilder>;
|
|
271
|
-
/**
|
|
272
|
-
* Wait for a transaction to be finalized.
|
|
273
|
-
*
|
|
274
|
-
* @since 0.2.0
|
|
275
|
-
* @category operations
|
|
276
|
-
*/
|
|
277
|
-
export declare function waitForTx(client: MidnightClient, txHash: string): Promise<FinalizedTxData>;
|
|
278
|
-
/**
|
|
279
|
-
* Raw Effect APIs for advanced users.
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```typescript
|
|
283
|
-
* const client = yield* Client.effect.create(config);
|
|
284
|
-
* const builder = yield* Client.effect.contractFrom(client, { module });
|
|
285
|
-
* ```
|
|
286
|
-
*
|
|
287
|
-
* @since 0.2.0
|
|
288
400
|
* @category effect
|
|
289
401
|
*/
|
|
290
402
|
export declare const effect: {
|
|
291
|
-
create: typeof createEffect;
|
|
292
|
-
fromWallet: typeof fromWalletEffect;
|
|
293
|
-
contractFrom: typeof contractFromEffect;
|
|
294
|
-
waitForTx: typeof waitForTxEffect;
|
|
295
|
-
};
|
|
296
|
-
declare function deployEffect(builder: ContractBuilder, options?: DeployOptions): Effect.Effect<ConnectedContract, ContractError>;
|
|
297
|
-
declare function joinEffect(builder: ContractBuilder, address: string, options?: JoinOptions): Effect.Effect<ConnectedContract, ContractError>;
|
|
298
|
-
/**
|
|
299
|
-
* ContractBuilder module functions.
|
|
300
|
-
*
|
|
301
|
-
* @since 0.2.0
|
|
302
|
-
* @category ContractBuilder
|
|
303
|
-
*/
|
|
304
|
-
export declare const ContractBuilder: {
|
|
305
|
-
/**
|
|
306
|
-
* Deploy a new contract instance.
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```typescript
|
|
310
|
-
* const contract = await ContractBuilder.deploy(builder);
|
|
311
|
-
* ```
|
|
312
|
-
*
|
|
313
|
-
* @since 0.2.0
|
|
314
|
-
* @category lifecycle
|
|
315
|
-
*/
|
|
316
|
-
deploy: (builder: ContractBuilder, options?: DeployOptions) => Promise<ConnectedContract>;
|
|
317
403
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* const contract = await ContractBuilder.join(builder, '0x...');
|
|
323
|
-
* ```
|
|
324
|
-
*
|
|
325
|
-
* @since 0.2.0
|
|
326
|
-
* @category lifecycle
|
|
404
|
+
* Create a client (Effect version).
|
|
327
405
|
*/
|
|
328
|
-
|
|
406
|
+
create: (config: ClientConfig) => Effect.Effect<MiddayClient, ClientError>;
|
|
329
407
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* @since 0.2.0
|
|
333
|
-
* @category effect
|
|
408
|
+
* Create a client from wallet (Effect version).
|
|
334
409
|
*/
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
410
|
+
fromWallet: (connection: WalletConnection, config: {
|
|
411
|
+
privateStateProvider: PrivateStateProvider;
|
|
412
|
+
logging?: boolean;
|
|
413
|
+
}) => Effect.Effect<MiddayClient, ClientError>;
|
|
339
414
|
};
|
|
340
|
-
declare function callEffect(contract: ConnectedContract, action: string, ...args: unknown[]): Effect.Effect<CallResult, ContractError>;
|
|
341
|
-
declare function stateEffect(contract: ConnectedContract): Effect.Effect<unknown, ContractError>;
|
|
342
|
-
declare function stateAtEffect(contract: ConnectedContract, blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
343
|
-
declare function ledgerStateEffect(contract: ConnectedContract): Effect.Effect<unknown, ContractError>;
|
|
344
|
-
declare function ledgerStateAtEffect(contract: ConnectedContract, blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
345
415
|
/**
|
|
346
|
-
*
|
|
416
|
+
* Result of loading a contract from a path.
|
|
347
417
|
*
|
|
348
|
-
* @since 0.
|
|
349
|
-
* @category
|
|
418
|
+
* @since 0.4.0
|
|
419
|
+
* @category model
|
|
350
420
|
*/
|
|
351
|
-
export
|
|
352
|
-
/**
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
* const result = await Contract.call(contract, 'increment');
|
|
358
|
-
* ```
|
|
359
|
-
*
|
|
360
|
-
* @since 0.2.0
|
|
361
|
-
* @category operations
|
|
362
|
-
*/
|
|
363
|
-
call: (contract: ConnectedContract, action: string, ...args: unknown[]) => Promise<CallResult>;
|
|
364
|
-
/**
|
|
365
|
-
* Get contract state.
|
|
366
|
-
*
|
|
367
|
-
* @since 0.2.0
|
|
368
|
-
* @category inspection
|
|
369
|
-
*/
|
|
370
|
-
state: (contract: ConnectedContract) => Promise<unknown>;
|
|
371
|
-
/**
|
|
372
|
-
* Get contract state at a specific block height.
|
|
373
|
-
*
|
|
374
|
-
* @since 0.2.0
|
|
375
|
-
* @category inspection
|
|
376
|
-
*/
|
|
377
|
-
stateAt: (contract: ConnectedContract, blockHeight: number) => Promise<unknown>;
|
|
378
|
-
/**
|
|
379
|
-
* Get ledger state (parsed through ledger function).
|
|
380
|
-
*
|
|
381
|
-
* @since 0.2.0
|
|
382
|
-
* @category inspection
|
|
383
|
-
*/
|
|
384
|
-
ledgerState: (contract: ConnectedContract) => Promise<unknown>;
|
|
385
|
-
/**
|
|
386
|
-
* Get ledger state at a specific block height.
|
|
387
|
-
*
|
|
388
|
-
* @since 0.2.0
|
|
389
|
-
* @category inspection
|
|
390
|
-
*/
|
|
391
|
-
ledgerStateAt: (contract: ConnectedContract, blockHeight: number) => Promise<unknown>;
|
|
392
|
-
/**
|
|
393
|
-
* Raw Effect APIs for Contract.
|
|
394
|
-
*
|
|
395
|
-
* @since 0.2.0
|
|
396
|
-
* @category effect
|
|
397
|
-
*/
|
|
398
|
-
effect: {
|
|
399
|
-
call: typeof callEffect;
|
|
400
|
-
state: typeof stateEffect;
|
|
401
|
-
stateAt: typeof stateAtEffect;
|
|
402
|
-
ledgerState: typeof ledgerStateEffect;
|
|
403
|
-
ledgerStateAt: typeof ledgerStateAtEffect;
|
|
404
|
-
};
|
|
405
|
-
};
|
|
421
|
+
export interface ContractLoadResult<T = ContractModule> {
|
|
422
|
+
/** The contract module with TypeScript types. */
|
|
423
|
+
readonly module: T;
|
|
424
|
+
/** ZK config provider for circuit artifacts. */
|
|
425
|
+
readonly zkConfig: ZKConfigProvider<string>;
|
|
426
|
+
}
|
|
406
427
|
/**
|
|
407
|
-
*
|
|
428
|
+
* Options for loading a contract.
|
|
408
429
|
*
|
|
409
|
-
* @since 0.
|
|
410
|
-
* @category
|
|
430
|
+
* @since 0.4.0
|
|
431
|
+
* @category model
|
|
411
432
|
*/
|
|
412
|
-
export interface
|
|
413
|
-
|
|
414
|
-
readonly
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
logging?: boolean;
|
|
418
|
-
}) => Effect.Effect<MidnightClient, ClientError>;
|
|
419
|
-
readonly contractFrom: (client: MidnightClient, options: ContractFromOptions) => Effect.Effect<ContractBuilder, ClientError>;
|
|
420
|
-
readonly waitForTx: (client: MidnightClient, txHash: string) => Effect.Effect<FinalizedTxData, ClientError>;
|
|
433
|
+
export interface ContractLoadOptions {
|
|
434
|
+
/** Subdirectory within the contract path where the compiled module lives. @default 'contract' */
|
|
435
|
+
readonly moduleSubdir?: string;
|
|
436
|
+
/** Module entry point filename. @default 'index.js' */
|
|
437
|
+
readonly moduleEntry?: string;
|
|
421
438
|
}
|
|
422
|
-
declare const ClientService_base: Context.TagClass<ClientService, "ClientService", ClientServiceImpl>;
|
|
423
439
|
/**
|
|
424
|
-
*
|
|
440
|
+
* Load a Compact contract from a directory path.
|
|
441
|
+
*
|
|
442
|
+
* Note: Prefer using `client.loadContract({ path })` which handles this automatically.
|
|
443
|
+
* This function is useful when you need to load the module before creating a client.
|
|
444
|
+
*
|
|
445
|
+
* @param contractPath - Absolute path to the contract directory
|
|
446
|
+
* @param options - Optional loading configuration
|
|
447
|
+
* @returns Promise resolving to the contract module and ZK config provider
|
|
425
448
|
*
|
|
426
449
|
* @example
|
|
427
450
|
* ```typescript
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* const client = yield* clientService.create(config);
|
|
431
|
-
* return client;
|
|
432
|
-
* });
|
|
451
|
+
* // Preferred: let loadContract handle it
|
|
452
|
+
* const contract = await client.loadContract({ path: contractPath });
|
|
433
453
|
*
|
|
434
|
-
*
|
|
454
|
+
* // Alternative: load separately (useful for pre-loading)
|
|
455
|
+
* const { module, zkConfig } = await Midday.Client.loadContractModule(contractPath);
|
|
456
|
+
* const contract = await client.loadContract({ module, zkConfig });
|
|
435
457
|
* ```
|
|
436
458
|
*
|
|
437
|
-
* @since 0.
|
|
438
|
-
* @category
|
|
459
|
+
* @since 0.4.0
|
|
460
|
+
* @category loading
|
|
439
461
|
*/
|
|
440
|
-
export declare
|
|
441
|
-
}
|
|
462
|
+
export declare function loadContractModule<T = ContractModule>(contractPath: string, options?: ContractLoadOptions): Promise<ContractLoadResult<T>>;
|
|
442
463
|
/**
|
|
443
|
-
*
|
|
464
|
+
* Load a contract from URLs (browser environments).
|
|
444
465
|
*
|
|
445
|
-
* @
|
|
446
|
-
* @
|
|
447
|
-
|
|
448
|
-
export interface ContractBuilderServiceImpl {
|
|
449
|
-
readonly deploy: (builder: ContractBuilder, options?: DeployOptions) => Effect.Effect<ConnectedContract, ContractError>;
|
|
450
|
-
readonly join: (builder: ContractBuilder, address: string, options?: JoinOptions) => Effect.Effect<ConnectedContract, ContractError>;
|
|
451
|
-
}
|
|
452
|
-
declare const ContractBuilderService_base: Context.TagClass<ContractBuilderService, "ContractBuilderService", ContractBuilderServiceImpl>;
|
|
453
|
-
/**
|
|
454
|
-
* Context.Tag for ContractBuilderService dependency injection.
|
|
466
|
+
* @param moduleUrl - URL to the contract module
|
|
467
|
+
* @param zkConfigBaseUrl - Base URL for ZK artifacts
|
|
468
|
+
* @returns Promise resolving to the contract module and ZK config provider
|
|
455
469
|
*
|
|
456
|
-
* @since 0.
|
|
457
|
-
* @category
|
|
470
|
+
* @since 0.4.0
|
|
471
|
+
* @category loading
|
|
458
472
|
*/
|
|
459
|
-
export declare
|
|
460
|
-
}
|
|
473
|
+
export declare function loadContractModuleFromUrl<T = ContractModule>(moduleUrl: string, zkConfigBaseUrl: string): Promise<ContractLoadResult<T>>;
|
|
461
474
|
/**
|
|
462
|
-
* Service interface for
|
|
475
|
+
* Service interface for Client operations.
|
|
463
476
|
*
|
|
464
477
|
* @since 0.2.0
|
|
465
478
|
* @category service
|
|
466
479
|
*/
|
|
467
|
-
export interface
|
|
468
|
-
readonly
|
|
469
|
-
readonly
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
480
|
+
export interface ClientServiceImpl {
|
|
481
|
+
readonly create: (config: ClientConfig) => Effect.Effect<MiddayClient, ClientError>;
|
|
482
|
+
readonly fromWallet: (connection: WalletConnection, config: {
|
|
483
|
+
privateStateProvider: PrivateStateProvider;
|
|
484
|
+
logging?: boolean;
|
|
485
|
+
}) => Effect.Effect<MiddayClient, ClientError>;
|
|
473
486
|
}
|
|
474
|
-
declare const
|
|
487
|
+
declare const ClientService_base: Context.TagClass<ClientService, "ClientService", ClientServiceImpl>;
|
|
475
488
|
/**
|
|
476
|
-
* Context.Tag for
|
|
489
|
+
* Context.Tag for ClientService dependency injection.
|
|
477
490
|
*
|
|
478
491
|
* @since 0.2.0
|
|
479
492
|
* @category service
|
|
480
493
|
*/
|
|
481
|
-
export declare class
|
|
494
|
+
export declare class ClientService extends ClientService_base {
|
|
482
495
|
}
|
|
483
496
|
/**
|
|
484
497
|
* Live Layer for ClientService.
|
|
@@ -487,77 +500,30 @@ export declare class ContractService extends ContractService_base {
|
|
|
487
500
|
* @category layer
|
|
488
501
|
*/
|
|
489
502
|
export declare const ClientLive: Layer.Layer<ClientService>;
|
|
503
|
+
declare const MiddayClientService_base: Context.TagClass<MiddayClientService, "MiddayClientService", MiddayClient>;
|
|
490
504
|
/**
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
* @since 0.2.0
|
|
494
|
-
* @category layer
|
|
495
|
-
*/
|
|
496
|
-
export declare const ContractBuilderLive: Layer.Layer<ContractBuilderService>;
|
|
497
|
-
/**
|
|
498
|
-
* Live Layer for ContractService.
|
|
499
|
-
*
|
|
500
|
-
* @since 0.2.0
|
|
501
|
-
* @category layer
|
|
502
|
-
*/
|
|
503
|
-
export declare const ContractLive: Layer.Layer<ContractService>;
|
|
504
|
-
/**
|
|
505
|
-
* Create a Layer providing all Client-related factory services.
|
|
506
|
-
*
|
|
507
|
-
* Use this when you want to create clients on-demand within your Effect programs.
|
|
508
|
-
* For pre-initialized clients, use `Client.layer(config)` instead.
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```typescript
|
|
512
|
-
* import { Effect } from 'effect';
|
|
513
|
-
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
514
|
-
*
|
|
515
|
-
* const program = Effect.gen(function* () {
|
|
516
|
-
* const clientService = yield* Midday.ClientService;
|
|
517
|
-
* const client = yield* clientService.create(config);
|
|
518
|
-
* return client;
|
|
519
|
-
* });
|
|
520
|
-
*
|
|
521
|
-
* await Effect.runPromise(program.pipe(Effect.provide(Midday.Client.services())));
|
|
522
|
-
* ```
|
|
523
|
-
*
|
|
524
|
-
* @since 0.3.0
|
|
525
|
-
* @category layer
|
|
526
|
-
*/
|
|
527
|
-
export declare function services(): Layer.Layer<ClientService | ContractBuilderService | ContractService>;
|
|
528
|
-
declare const MidnightClientService_base: Context.TagClass<MidnightClientService, "MidnightClientService", MidnightClient>;
|
|
529
|
-
/**
|
|
530
|
-
* Context.Tag for a pre-initialized MidnightClient.
|
|
531
|
-
*
|
|
532
|
-
* Use with `Client.layer(config)` for dependency injection of a configured client.
|
|
505
|
+
* Context.Tag for a pre-initialized MiddayClient.
|
|
533
506
|
*
|
|
534
507
|
* @since 0.3.0
|
|
535
508
|
* @category service
|
|
536
509
|
*/
|
|
537
|
-
export declare class
|
|
510
|
+
export declare class MiddayClientService extends MiddayClientService_base {
|
|
538
511
|
}
|
|
539
512
|
/**
|
|
540
|
-
* Create a Layer that provides a pre-initialized
|
|
541
|
-
*
|
|
542
|
-
* This is the recommended way to inject a client into Effect programs
|
|
543
|
-
* when you have a known configuration at startup. Follows the same pattern
|
|
544
|
-
* as `Cluster.layer(config)`.
|
|
513
|
+
* Create a Layer that provides a pre-initialized MiddayClient.
|
|
545
514
|
*
|
|
546
515
|
* @example
|
|
547
516
|
* ```typescript
|
|
548
|
-
* import { Effect } from 'effect';
|
|
549
|
-
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
550
|
-
*
|
|
551
517
|
* const clientLayer = Midday.Client.layer({
|
|
552
518
|
* seed: 'your-64-char-hex-seed',
|
|
553
519
|
* networkConfig: Midday.Config.NETWORKS.local,
|
|
554
|
-
* zkConfigProvider
|
|
555
|
-
* privateStateProvider
|
|
520
|
+
* zkConfigProvider,
|
|
521
|
+
* privateStateProvider,
|
|
556
522
|
* });
|
|
557
523
|
*
|
|
558
524
|
* const program = Effect.gen(function* () {
|
|
559
|
-
* const client = yield* Midday.
|
|
560
|
-
* const builder = yield*
|
|
525
|
+
* const client = yield* Midday.MiddayClientService;
|
|
526
|
+
* const builder = yield* client.effect.loadContract({ module });
|
|
561
527
|
* return builder;
|
|
562
528
|
* });
|
|
563
529
|
*
|
|
@@ -567,32 +533,9 @@ export declare class MidnightClientService extends MidnightClientService_base {
|
|
|
567
533
|
* @since 0.3.0
|
|
568
534
|
* @category layer
|
|
569
535
|
*/
|
|
570
|
-
export declare function layer(config: ClientConfig): Layer.Layer<
|
|
536
|
+
export declare function layer(config: ClientConfig): Layer.Layer<MiddayClientService, ClientError>;
|
|
571
537
|
/**
|
|
572
|
-
* Create a Layer that provides a pre-initialized
|
|
573
|
-
*
|
|
574
|
-
* Use this for browser environments with Lace wallet integration.
|
|
575
|
-
*
|
|
576
|
-
* @example
|
|
577
|
-
* ```typescript
|
|
578
|
-
* import { Effect } from 'effect';
|
|
579
|
-
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
580
|
-
*
|
|
581
|
-
* // After connecting wallet
|
|
582
|
-
* const connection = await Midday.connectWallet('testnet');
|
|
583
|
-
*
|
|
584
|
-
* const clientLayer = Midday.Client.layerFromWallet(connection, {
|
|
585
|
-
* zkConfigProvider: new Midday.HttpZkConfigProvider('https://cdn.example.com/zk'),
|
|
586
|
-
* privateStateProvider: Midday.indexedDBPrivateStateProvider({ privateStateStoreName: 'my-app' }),
|
|
587
|
-
* });
|
|
588
|
-
*
|
|
589
|
-
* const program = Effect.gen(function* () {
|
|
590
|
-
* const client = yield* Midday.MidnightClientService;
|
|
591
|
-
* // Use client...
|
|
592
|
-
* });
|
|
593
|
-
*
|
|
594
|
-
* await Effect.runPromise(program.pipe(Effect.provide(clientLayer)));
|
|
595
|
-
* ```
|
|
538
|
+
* Create a Layer that provides a pre-initialized MiddayClient from a wallet connection.
|
|
596
539
|
*
|
|
597
540
|
* @since 0.3.0
|
|
598
541
|
* @category layer
|
|
@@ -601,6 +544,13 @@ export declare function layerFromWallet(connection: WalletConnection, config: {
|
|
|
601
544
|
zkConfigProvider: ZKConfigProvider<string>;
|
|
602
545
|
privateStateProvider: PrivateStateProvider;
|
|
603
546
|
logging?: boolean;
|
|
604
|
-
}): Layer.Layer<
|
|
547
|
+
}): Layer.Layer<MiddayClientService, ClientError>;
|
|
548
|
+
/**
|
|
549
|
+
* Create a Layer providing all Client-related services.
|
|
550
|
+
*
|
|
551
|
+
* @since 0.3.0
|
|
552
|
+
* @category layer
|
|
553
|
+
*/
|
|
554
|
+
export declare function services(): Layer.Layer<ClientService>;
|
|
605
555
|
export {};
|
|
606
556
|
//# sourceMappingURL=Client.d.ts.map
|