@no-witness-labs/midday-sdk 0.2.4 → 0.2.5
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 +248 -332
- 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,25 @@ 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
|
+
*
|
|
90
98
|
* @since 0.2.0
|
|
91
99
|
* @category model
|
|
92
100
|
*/
|
|
93
|
-
export interface
|
|
94
|
-
/** Contract module
|
|
101
|
+
export interface LoadContractOptions {
|
|
102
|
+
/** Contract module */
|
|
95
103
|
module?: ContractModule;
|
|
96
|
-
/**
|
|
97
|
-
|
|
104
|
+
/** ZK configuration provider for this contract */
|
|
105
|
+
zkConfig?: ZKConfigProvider<string>;
|
|
106
|
+
/** Filesystem path to contract directory (auto-loads module + zkConfig) */
|
|
107
|
+
path?: string;
|
|
108
|
+
/** URL to contract module JS file */
|
|
109
|
+
moduleUrl?: string;
|
|
110
|
+
/** Base URL for ZK artifacts */
|
|
111
|
+
zkConfigBaseUrl?: string;
|
|
98
112
|
/** Witnesses for the contract */
|
|
99
113
|
witnesses?: Record<string, unknown>;
|
|
100
114
|
/** Override privateStateId (defaults to contract name) */
|
|
@@ -165,84 +179,166 @@ export interface CallResult {
|
|
|
165
179
|
status: string;
|
|
166
180
|
}
|
|
167
181
|
/**
|
|
168
|
-
*
|
|
182
|
+
* A Midnight client handle with convenience methods.
|
|
169
183
|
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* @since 0.2.0
|
|
184
|
+
* @since 0.5.0
|
|
173
185
|
* @category model
|
|
174
186
|
*/
|
|
175
|
-
export interface
|
|
176
|
-
/** Raw wallet context for advanced use (null if using wallet connector) */
|
|
177
|
-
readonly wallet: WalletContext | null;
|
|
187
|
+
export interface MiddayClient {
|
|
178
188
|
/** Network configuration */
|
|
179
189
|
readonly networkConfig: NetworkConfig;
|
|
180
|
-
/**
|
|
181
|
-
readonly providers:
|
|
182
|
-
/**
|
|
183
|
-
readonly
|
|
190
|
+
/** Base providers (for advanced use - no zkConfig) */
|
|
191
|
+
readonly providers: BaseProviders;
|
|
192
|
+
/** Raw wallet context (null if using wallet connector) */
|
|
193
|
+
readonly wallet: WalletContext | null;
|
|
194
|
+
/**
|
|
195
|
+
* Load a contract module. Returns a Contract in "loaded" state.
|
|
196
|
+
* Call `deploy()` or `join()` on it to connect to the network.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Load from path (Node.js)
|
|
201
|
+
* const contract = await client.loadContract({ path: './contracts/counter' });
|
|
202
|
+
*
|
|
203
|
+
* // Load with direct module + zkConfig
|
|
204
|
+
* const contract = await client.loadContract({ module, zkConfig });
|
|
205
|
+
*
|
|
206
|
+
* // Load from URLs (browser)
|
|
207
|
+
* const contract = await client.loadContract({
|
|
208
|
+
* moduleUrl: 'https://example.com/contract.js',
|
|
209
|
+
* zkConfigBaseUrl: 'https://example.com/zk'
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
loadContract(options: LoadContractOptions): Promise<Contract>;
|
|
214
|
+
/**
|
|
215
|
+
* Wait for a transaction to be finalized.
|
|
216
|
+
*/
|
|
217
|
+
waitForTx(txHash: string): Promise<FinalizedTxData>;
|
|
218
|
+
/** Effect versions of client methods */
|
|
219
|
+
readonly effect: {
|
|
220
|
+
loadContract(options: LoadContractOptions): Effect.Effect<Contract, ClientError>;
|
|
221
|
+
waitForTx(txHash: string): Effect.Effect<FinalizedTxData, ClientError>;
|
|
222
|
+
};
|
|
184
223
|
}
|
|
185
224
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* This is plain data - use module functions to operate on it.
|
|
225
|
+
* Contract state: either "loaded" (pre-deploy) or "deployed" (connected to network).
|
|
189
226
|
*
|
|
190
|
-
* @since 0.
|
|
227
|
+
* @since 0.6.0
|
|
191
228
|
* @category model
|
|
192
229
|
*/
|
|
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
|
-
}
|
|
230
|
+
export type ContractState = 'loaded' | 'deployed';
|
|
201
231
|
/**
|
|
202
|
-
*
|
|
232
|
+
* A contract handle that manages the full lifecycle: load → deploy/join → call.
|
|
203
233
|
*
|
|
204
|
-
*
|
|
234
|
+
* The contract has two states:
|
|
235
|
+
* - **loaded**: Contract module loaded, ready for deploy() or join()
|
|
236
|
+
* - **deployed**: Connected to network, ready for call() and ledgerState()
|
|
205
237
|
*
|
|
206
|
-
* @since 0.
|
|
238
|
+
* @since 0.5.0
|
|
207
239
|
* @category model
|
|
208
240
|
*/
|
|
209
|
-
export interface
|
|
210
|
-
/**
|
|
211
|
-
readonly
|
|
212
|
-
/** The
|
|
213
|
-
readonly
|
|
214
|
-
/** The loaded module
|
|
241
|
+
export interface Contract {
|
|
242
|
+
/** Current state of the contract */
|
|
243
|
+
readonly state: ContractState;
|
|
244
|
+
/** The deployed contract address (undefined until deployed/joined) */
|
|
245
|
+
readonly address: string | undefined;
|
|
246
|
+
/** The loaded contract module */
|
|
215
247
|
readonly module: LoadedContractModule;
|
|
216
|
-
/**
|
|
248
|
+
/** Contract providers (for advanced use) */
|
|
217
249
|
readonly providers: ContractProviders;
|
|
218
|
-
/**
|
|
219
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Deploy a new contract instance.
|
|
252
|
+
* Transitions state from "loaded" to "deployed".
|
|
253
|
+
*
|
|
254
|
+
* @throws {ContractError} If already deployed
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* await contract.deploy();
|
|
258
|
+
* console.log(contract.address); // Now available
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
deploy(options?: DeployOptions): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Join an existing contract at an address.
|
|
264
|
+
* Transitions state from "loaded" to "deployed".
|
|
265
|
+
*
|
|
266
|
+
* @throws {ContractError} If already deployed
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* await contract.join('0x...');
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
join(address: string, options?: JoinOptions): Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Call a contract action.
|
|
275
|
+
*
|
|
276
|
+
* @throws {ContractError} If not deployed
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const result = await contract.call('increment', 5n);
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
call(action: string, ...args: unknown[]): Promise<CallResult>;
|
|
283
|
+
/**
|
|
284
|
+
* Get raw contract state.
|
|
285
|
+
*
|
|
286
|
+
* @throws {ContractError} If not deployed
|
|
287
|
+
*/
|
|
288
|
+
getState(): Promise<unknown>;
|
|
289
|
+
/**
|
|
290
|
+
* Get raw contract state at a specific block height.
|
|
291
|
+
*
|
|
292
|
+
* @throws {ContractError} If not deployed
|
|
293
|
+
*/
|
|
294
|
+
getStateAt(blockHeight: number): Promise<unknown>;
|
|
295
|
+
/**
|
|
296
|
+
* Get parsed ledger state.
|
|
297
|
+
*
|
|
298
|
+
* @throws {ContractError} If not deployed
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const state = await contract.ledgerState() as MyContractLedger;
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
ledgerState(): Promise<unknown>;
|
|
305
|
+
/**
|
|
306
|
+
* Get parsed ledger state at a specific block height.
|
|
307
|
+
*
|
|
308
|
+
* @throws {ContractError} If not deployed
|
|
309
|
+
*/
|
|
310
|
+
ledgerStateAt(blockHeight: number): Promise<unknown>;
|
|
311
|
+
/** Effect versions of contract methods */
|
|
312
|
+
readonly effect: {
|
|
313
|
+
deploy(options?: DeployOptions): Effect.Effect<void, ContractError>;
|
|
314
|
+
join(address: string, options?: JoinOptions): Effect.Effect<void, ContractError>;
|
|
315
|
+
call(action: string, ...args: unknown[]): Effect.Effect<CallResult, ContractError>;
|
|
316
|
+
getState(): Effect.Effect<unknown, ContractError>;
|
|
317
|
+
getStateAt(blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
318
|
+
ledgerState(): Effect.Effect<unknown, ContractError>;
|
|
319
|
+
ledgerStateAt(blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
320
|
+
};
|
|
220
321
|
}
|
|
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
322
|
/**
|
|
230
|
-
* Create a Midnight client for interacting with contracts
|
|
323
|
+
* Create a Midnight client for interacting with contracts.
|
|
231
324
|
*
|
|
232
325
|
* @example
|
|
233
326
|
* ```typescript
|
|
234
|
-
* const client = await Client.create({
|
|
327
|
+
* const client = await Midday.Client.create({
|
|
235
328
|
* seed: 'your-64-char-hex-seed',
|
|
236
|
-
* networkConfig: Config.NETWORKS.local,
|
|
237
|
-
* zkConfigProvider,
|
|
329
|
+
* networkConfig: Midday.Config.NETWORKS.local,
|
|
238
330
|
* privateStateProvider,
|
|
239
331
|
* });
|
|
332
|
+
*
|
|
333
|
+
* const contract = await client.loadContract({ path: './contracts/counter' });
|
|
334
|
+
* await contract.deploy();
|
|
335
|
+
* await contract.call('increment');
|
|
240
336
|
* ```
|
|
241
337
|
*
|
|
242
338
|
* @since 0.2.0
|
|
243
339
|
* @category constructors
|
|
244
340
|
*/
|
|
245
|
-
export declare function create(config: ClientConfig): Promise<
|
|
341
|
+
export declare function create(config: ClientConfig): Promise<MiddayClient>;
|
|
246
342
|
/**
|
|
247
343
|
* Create a Midnight client from a connected wallet (browser).
|
|
248
344
|
*
|
|
@@ -250,235 +346,118 @@ export declare function create(config: ClientConfig): Promise<MidnightClient>;
|
|
|
250
346
|
* @category constructors
|
|
251
347
|
*/
|
|
252
348
|
export declare function fromWallet(connection: WalletConnection, config: {
|
|
253
|
-
zkConfigProvider: ZKConfigProvider<string>;
|
|
254
349
|
privateStateProvider: PrivateStateProvider;
|
|
255
350
|
logging?: boolean;
|
|
256
|
-
}): Promise<
|
|
351
|
+
}): Promise<MiddayClient>;
|
|
257
352
|
/**
|
|
258
|
-
*
|
|
353
|
+
* Raw Effect APIs for advanced users who want to compose Effects.
|
|
259
354
|
*
|
|
260
355
|
* @example
|
|
261
356
|
* ```typescript
|
|
262
|
-
* const
|
|
263
|
-
*
|
|
357
|
+
* const program = Effect.gen(function* () {
|
|
358
|
+
* const client = yield* Midday.Client.effect.create(config);
|
|
359
|
+
* const contract = yield* client.effect.loadContract({ module });
|
|
360
|
+
* yield* contract.effect.deploy();
|
|
361
|
+
* yield* contract.effect.call('increment');
|
|
264
362
|
* });
|
|
265
363
|
* ```
|
|
266
364
|
*
|
|
267
365
|
* @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
366
|
* @category effect
|
|
289
367
|
*/
|
|
290
368
|
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
369
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```typescript
|
|
310
|
-
* const contract = await ContractBuilder.deploy(builder);
|
|
311
|
-
* ```
|
|
312
|
-
*
|
|
313
|
-
* @since 0.2.0
|
|
314
|
-
* @category lifecycle
|
|
370
|
+
* Create a client (Effect version).
|
|
315
371
|
*/
|
|
316
|
-
|
|
372
|
+
create: (config: ClientConfig) => Effect.Effect<MiddayClient, ClientError>;
|
|
317
373
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* const contract = await ContractBuilder.join(builder, '0x...');
|
|
323
|
-
* ```
|
|
324
|
-
*
|
|
325
|
-
* @since 0.2.0
|
|
326
|
-
* @category lifecycle
|
|
374
|
+
* Create a client from wallet (Effect version).
|
|
327
375
|
*/
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
* @since 0.2.0
|
|
333
|
-
* @category effect
|
|
334
|
-
*/
|
|
335
|
-
effect: {
|
|
336
|
-
deploy: typeof deployEffect;
|
|
337
|
-
join: typeof joinEffect;
|
|
338
|
-
};
|
|
376
|
+
fromWallet: (connection: WalletConnection, config: {
|
|
377
|
+
privateStateProvider: PrivateStateProvider;
|
|
378
|
+
logging?: boolean;
|
|
379
|
+
}) => Effect.Effect<MiddayClient, ClientError>;
|
|
339
380
|
};
|
|
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
381
|
/**
|
|
346
|
-
*
|
|
382
|
+
* Result of loading a contract from a path.
|
|
347
383
|
*
|
|
348
|
-
* @since 0.
|
|
349
|
-
* @category
|
|
384
|
+
* @since 0.4.0
|
|
385
|
+
* @category model
|
|
350
386
|
*/
|
|
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
|
-
};
|
|
387
|
+
export interface ContractLoadResult<T = ContractModule> {
|
|
388
|
+
/** The contract module with TypeScript types. */
|
|
389
|
+
readonly module: T;
|
|
390
|
+
/** ZK config provider for circuit artifacts. */
|
|
391
|
+
readonly zkConfig: ZKConfigProvider<string>;
|
|
392
|
+
}
|
|
406
393
|
/**
|
|
407
|
-
*
|
|
394
|
+
* Options for loading a contract.
|
|
408
395
|
*
|
|
409
|
-
* @since 0.
|
|
410
|
-
* @category
|
|
396
|
+
* @since 0.4.0
|
|
397
|
+
* @category model
|
|
411
398
|
*/
|
|
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>;
|
|
399
|
+
export interface ContractLoadOptions {
|
|
400
|
+
/** Subdirectory within the contract path where the compiled module lives. @default 'contract' */
|
|
401
|
+
readonly moduleSubdir?: string;
|
|
402
|
+
/** Module entry point filename. @default 'index.js' */
|
|
403
|
+
readonly moduleEntry?: string;
|
|
421
404
|
}
|
|
422
|
-
declare const ClientService_base: Context.TagClass<ClientService, "ClientService", ClientServiceImpl>;
|
|
423
405
|
/**
|
|
424
|
-
*
|
|
406
|
+
* Load a Compact contract from a directory path.
|
|
407
|
+
*
|
|
408
|
+
* Note: Prefer using `client.loadContract({ path })` which handles this automatically.
|
|
409
|
+
* This function is useful when you need to load the module before creating a client.
|
|
410
|
+
*
|
|
411
|
+
* @param contractPath - Absolute path to the contract directory
|
|
412
|
+
* @param options - Optional loading configuration
|
|
413
|
+
* @returns Promise resolving to the contract module and ZK config provider
|
|
425
414
|
*
|
|
426
415
|
* @example
|
|
427
416
|
* ```typescript
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* const client = yield* clientService.create(config);
|
|
431
|
-
* return client;
|
|
432
|
-
* });
|
|
417
|
+
* // Preferred: let loadContract handle it
|
|
418
|
+
* const contract = await client.loadContract({ path: contractPath });
|
|
433
419
|
*
|
|
434
|
-
*
|
|
420
|
+
* // Alternative: load separately (useful for pre-loading)
|
|
421
|
+
* const { module, zkConfig } = await Midday.Client.loadContractModule(contractPath);
|
|
422
|
+
* const contract = await client.loadContract({ module, zkConfig });
|
|
435
423
|
* ```
|
|
436
424
|
*
|
|
437
|
-
* @since 0.
|
|
438
|
-
* @category
|
|
425
|
+
* @since 0.4.0
|
|
426
|
+
* @category loading
|
|
439
427
|
*/
|
|
440
|
-
export declare
|
|
441
|
-
}
|
|
428
|
+
export declare function loadContractModule<T = ContractModule>(contractPath: string, options?: ContractLoadOptions): Promise<ContractLoadResult<T>>;
|
|
442
429
|
/**
|
|
443
|
-
*
|
|
430
|
+
* Load a contract from URLs (browser environments).
|
|
444
431
|
*
|
|
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.
|
|
432
|
+
* @param moduleUrl - URL to the contract module
|
|
433
|
+
* @param zkConfigBaseUrl - Base URL for ZK artifacts
|
|
434
|
+
* @returns Promise resolving to the contract module and ZK config provider
|
|
455
435
|
*
|
|
456
|
-
* @since 0.
|
|
457
|
-
* @category
|
|
436
|
+
* @since 0.4.0
|
|
437
|
+
* @category loading
|
|
458
438
|
*/
|
|
459
|
-
export declare
|
|
460
|
-
}
|
|
439
|
+
export declare function loadContractModuleFromUrl<T = ContractModule>(moduleUrl: string, zkConfigBaseUrl: string): Promise<ContractLoadResult<T>>;
|
|
461
440
|
/**
|
|
462
|
-
* Service interface for
|
|
441
|
+
* Service interface for Client operations.
|
|
463
442
|
*
|
|
464
443
|
* @since 0.2.0
|
|
465
444
|
* @category service
|
|
466
445
|
*/
|
|
467
|
-
export interface
|
|
468
|
-
readonly
|
|
469
|
-
readonly
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
446
|
+
export interface ClientServiceImpl {
|
|
447
|
+
readonly create: (config: ClientConfig) => Effect.Effect<MiddayClient, ClientError>;
|
|
448
|
+
readonly fromWallet: (connection: WalletConnection, config: {
|
|
449
|
+
privateStateProvider: PrivateStateProvider;
|
|
450
|
+
logging?: boolean;
|
|
451
|
+
}) => Effect.Effect<MiddayClient, ClientError>;
|
|
473
452
|
}
|
|
474
|
-
declare const
|
|
453
|
+
declare const ClientService_base: Context.TagClass<ClientService, "ClientService", ClientServiceImpl>;
|
|
475
454
|
/**
|
|
476
|
-
* Context.Tag for
|
|
455
|
+
* Context.Tag for ClientService dependency injection.
|
|
477
456
|
*
|
|
478
457
|
* @since 0.2.0
|
|
479
458
|
* @category service
|
|
480
459
|
*/
|
|
481
|
-
export declare class
|
|
460
|
+
export declare class ClientService extends ClientService_base {
|
|
482
461
|
}
|
|
483
462
|
/**
|
|
484
463
|
* Live Layer for ClientService.
|
|
@@ -487,77 +466,30 @@ export declare class ContractService extends ContractService_base {
|
|
|
487
466
|
* @category layer
|
|
488
467
|
*/
|
|
489
468
|
export declare const ClientLive: Layer.Layer<ClientService>;
|
|
469
|
+
declare const MiddayClientService_base: Context.TagClass<MiddayClientService, "MiddayClientService", MiddayClient>;
|
|
490
470
|
/**
|
|
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.
|
|
471
|
+
* Context.Tag for a pre-initialized MiddayClient.
|
|
533
472
|
*
|
|
534
473
|
* @since 0.3.0
|
|
535
474
|
* @category service
|
|
536
475
|
*/
|
|
537
|
-
export declare class
|
|
476
|
+
export declare class MiddayClientService extends MiddayClientService_base {
|
|
538
477
|
}
|
|
539
478
|
/**
|
|
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)`.
|
|
479
|
+
* Create a Layer that provides a pre-initialized MiddayClient.
|
|
545
480
|
*
|
|
546
481
|
* @example
|
|
547
482
|
* ```typescript
|
|
548
|
-
* import { Effect } from 'effect';
|
|
549
|
-
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
550
|
-
*
|
|
551
483
|
* const clientLayer = Midday.Client.layer({
|
|
552
484
|
* seed: 'your-64-char-hex-seed',
|
|
553
485
|
* networkConfig: Midday.Config.NETWORKS.local,
|
|
554
|
-
* zkConfigProvider
|
|
555
|
-
* privateStateProvider
|
|
486
|
+
* zkConfigProvider,
|
|
487
|
+
* privateStateProvider,
|
|
556
488
|
* });
|
|
557
489
|
*
|
|
558
490
|
* const program = Effect.gen(function* () {
|
|
559
|
-
* const client = yield* Midday.
|
|
560
|
-
* const builder = yield*
|
|
491
|
+
* const client = yield* Midday.MiddayClientService;
|
|
492
|
+
* const builder = yield* client.effect.loadContract({ module });
|
|
561
493
|
* return builder;
|
|
562
494
|
* });
|
|
563
495
|
*
|
|
@@ -567,32 +499,9 @@ export declare class MidnightClientService extends MidnightClientService_base {
|
|
|
567
499
|
* @since 0.3.0
|
|
568
500
|
* @category layer
|
|
569
501
|
*/
|
|
570
|
-
export declare function layer(config: ClientConfig): Layer.Layer<
|
|
502
|
+
export declare function layer(config: ClientConfig): Layer.Layer<MiddayClientService, ClientError>;
|
|
571
503
|
/**
|
|
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
|
-
* ```
|
|
504
|
+
* Create a Layer that provides a pre-initialized MiddayClient from a wallet connection.
|
|
596
505
|
*
|
|
597
506
|
* @since 0.3.0
|
|
598
507
|
* @category layer
|
|
@@ -601,6 +510,13 @@ export declare function layerFromWallet(connection: WalletConnection, config: {
|
|
|
601
510
|
zkConfigProvider: ZKConfigProvider<string>;
|
|
602
511
|
privateStateProvider: PrivateStateProvider;
|
|
603
512
|
logging?: boolean;
|
|
604
|
-
}): Layer.Layer<
|
|
513
|
+
}): Layer.Layer<MiddayClientService, ClientError>;
|
|
514
|
+
/**
|
|
515
|
+
* Create a Layer providing all Client-related services.
|
|
516
|
+
*
|
|
517
|
+
* @since 0.3.0
|
|
518
|
+
* @category layer
|
|
519
|
+
*/
|
|
520
|
+
export declare function services(): Layer.Layer<ClientService>;
|
|
605
521
|
export {};
|
|
606
522
|
//# sourceMappingURL=Client.d.ts.map
|