@no-witness-labs/midday-sdk 0.2.0 → 0.2.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.
- package/README.md +145 -78
- package/dist/Client.d.ts +542 -70
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +608 -143
- package/dist/Client.js.map +1 -1
- package/dist/Config.d.ts +83 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +72 -15
- package/dist/Config.js.map +1 -1
- package/dist/Providers.d.ts +99 -9
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +142 -39
- package/dist/Providers.js.map +1 -1
- package/dist/Wallet.d.ts +88 -1
- package/dist/Wallet.d.ts.map +1 -1
- package/dist/Wallet.js +162 -51
- package/dist/Wallet.js.map +1 -1
- package/dist/index.d.ts +63 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -4
- package/dist/index.js.map +1 -1
- package/dist/providers/HttpZkConfigProvider.d.ts +229 -0
- package/dist/providers/HttpZkConfigProvider.d.ts.map +1 -0
- package/dist/providers/HttpZkConfigProvider.js +275 -0
- package/dist/providers/HttpZkConfigProvider.js.map +1 -0
- package/dist/providers/IndexedDBPrivateStateProvider.d.ts +270 -0
- package/dist/providers/IndexedDBPrivateStateProvider.d.ts.map +1 -0
- package/dist/providers/IndexedDBPrivateStateProvider.js +513 -0
- package/dist/providers/IndexedDBPrivateStateProvider.js.map +1 -0
- package/dist/providers/errors.d.ts +50 -0
- package/dist/providers/errors.d.ts.map +1 -0
- package/dist/providers/errors.js +32 -0
- package/dist/providers/errors.js.map +1 -0
- package/dist/sdk/Type.d.ts +91 -0
- package/dist/sdk/Type.d.ts.map +1 -0
- package/dist/sdk/Type.js +8 -0
- package/dist/sdk/Type.js.map +1 -0
- package/dist/utils/address.d.ts +56 -0
- package/dist/utils/address.d.ts.map +1 -0
- package/dist/utils/address.js +135 -0
- package/dist/utils/address.js.map +1 -0
- package/dist/utils/coin.d.ts +55 -0
- package/dist/utils/coin.d.ts.map +1 -0
- package/dist/utils/coin.js +84 -0
- package/dist/utils/coin.js.map +1 -0
- package/dist/utils/effect-runtime.d.ts +66 -0
- package/dist/utils/effect-runtime.d.ts.map +1 -0
- package/dist/utils/effect-runtime.js +147 -0
- package/dist/utils/effect-runtime.js.map +1 -0
- package/dist/utils/hex.d.ts +62 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +93 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/wallet/connector.d.ts +191 -0
- package/dist/wallet/connector.d.ts.map +1 -0
- package/dist/wallet/connector.js +183 -0
- package/dist/wallet/connector.js.map +1 -0
- package/dist/wallet/errors.d.ts +22 -0
- package/dist/wallet/errors.d.ts.map +1 -0
- package/dist/wallet/errors.js +16 -0
- package/dist/wallet/errors.js.map +1 -0
- package/dist/wallet/provider.d.ts +102 -0
- package/dist/wallet/provider.d.ts.map +1 -0
- package/dist/wallet/provider.js +139 -0
- package/dist/wallet/provider.js.map +1 -0
- package/package.json +10 -5
package/dist/Client.d.ts
CHANGED
|
@@ -1,80 +1,223 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* High-level client for interacting with Midnight Network contracts.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* ## API Design
|
|
5
|
+
*
|
|
6
|
+
* This module uses a **module-function pattern**:
|
|
7
|
+
*
|
|
8
|
+
* - **Stateless**: Functions operate on Client/Contract data
|
|
9
|
+
* - **Module functions**: `Client.contractFrom(client, options)`, `Contract.deploy(builder)`
|
|
10
|
+
* - **Data-oriented**: Client/Contract are plain data, not instances with methods
|
|
11
|
+
*
|
|
12
|
+
* ### Usage Patterns
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Promise user
|
|
16
|
+
* const client = await Client.create(config);
|
|
17
|
+
* const builder = await Client.contractFrom(client, { module });
|
|
18
|
+
* const contract = await ContractBuilder.deploy(builder);
|
|
19
|
+
* const result = await Contract.call(contract, 'increment');
|
|
20
|
+
*
|
|
21
|
+
* // Effect user
|
|
22
|
+
* const client = yield* Client.effect.create(config);
|
|
23
|
+
* const builder = yield* Client.effect.contractFrom(client, { module });
|
|
24
|
+
* const contract = yield* ContractBuilder.effect.deploy(builder);
|
|
25
|
+
* const result = yield* Contract.effect.call(contract, 'increment');
|
|
26
|
+
* ```
|
|
5
27
|
*
|
|
6
28
|
* @since 0.1.0
|
|
7
29
|
* @module
|
|
8
30
|
*/
|
|
9
|
-
import {
|
|
31
|
+
import { Context, Effect, Layer } from 'effect';
|
|
32
|
+
import type { ZKConfigProvider, PrivateStateProvider } from '@midnight-ntwrk/midnight-js-types';
|
|
10
33
|
import type { NetworkConfig } from './Config.js';
|
|
11
34
|
import type { ContractProviders, StorageConfig } from './Providers.js';
|
|
12
35
|
import type { WalletContext } from './Wallet.js';
|
|
36
|
+
import type { WalletConnection } from './wallet/connector.js';
|
|
37
|
+
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 & {
|
|
38
|
+
readonly _tag: "ClientError";
|
|
39
|
+
} & Readonly<A>;
|
|
40
|
+
/**
|
|
41
|
+
* Error during client initialization or operation.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.3.0
|
|
44
|
+
* @category errors
|
|
45
|
+
*/
|
|
46
|
+
export declare class ClientError extends ClientError_base<{
|
|
47
|
+
readonly cause: unknown;
|
|
48
|
+
readonly message: string;
|
|
49
|
+
}> {
|
|
50
|
+
}
|
|
51
|
+
declare const ContractError_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 & {
|
|
52
|
+
readonly _tag: "ContractError";
|
|
53
|
+
} & Readonly<A>;
|
|
54
|
+
/**
|
|
55
|
+
* Error during contract deployment or calls.
|
|
56
|
+
*
|
|
57
|
+
* @since 0.3.0
|
|
58
|
+
* @category errors
|
|
59
|
+
*/
|
|
60
|
+
export declare class ContractError extends ContractError_base<{
|
|
61
|
+
readonly cause: unknown;
|
|
62
|
+
readonly message: string;
|
|
63
|
+
}> {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Logger interface for client operations.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.2.0
|
|
69
|
+
* @category model
|
|
70
|
+
*/
|
|
71
|
+
export interface Logger {
|
|
72
|
+
info(message: string): void;
|
|
73
|
+
warn(message: string): void;
|
|
74
|
+
error(message: string): void;
|
|
75
|
+
debug(message: string): void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Configuration for creating a client.
|
|
79
|
+
*
|
|
80
|
+
* @since 0.2.0
|
|
81
|
+
* @category model
|
|
82
|
+
*/
|
|
13
83
|
export interface ClientConfig {
|
|
14
84
|
/** Network to connect to (default: 'local') */
|
|
15
85
|
network?: string;
|
|
16
86
|
/** Custom network configuration (overrides network preset) */
|
|
17
87
|
networkConfig?: NetworkConfig;
|
|
18
|
-
/** Wallet seed (
|
|
88
|
+
/** Wallet seed (required for non-local networks) */
|
|
19
89
|
seed?: string;
|
|
90
|
+
/** ZK configuration provider (required) */
|
|
91
|
+
zkConfigProvider: ZKConfigProvider<string>;
|
|
92
|
+
/** Private state provider (required) */
|
|
93
|
+
privateStateProvider: PrivateStateProvider;
|
|
20
94
|
/** Storage configuration */
|
|
21
95
|
storage?: StorageConfig;
|
|
22
96
|
/** Enable logging (default: true) */
|
|
23
97
|
logging?: boolean;
|
|
24
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Options for loading a contract.
|
|
101
|
+
*
|
|
102
|
+
* @since 0.2.0
|
|
103
|
+
* @category model
|
|
104
|
+
*/
|
|
25
105
|
export interface ContractFromOptions {
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* - string (URL): relative to caller's import.meta.url
|
|
31
|
-
*/
|
|
32
|
-
from?: string | 'project' | 'cwd';
|
|
106
|
+
/** Contract module (required in browser) */
|
|
107
|
+
module?: ContractModule;
|
|
108
|
+
/** URL to fetch ZK config from (for HttpZkConfigProvider) */
|
|
109
|
+
zkConfigUrl?: string;
|
|
33
110
|
/** Witnesses for the contract */
|
|
34
111
|
witnesses?: Record<string, unknown>;
|
|
35
|
-
/** Override privateStateId (defaults to
|
|
112
|
+
/** Override privateStateId (defaults to contract name) */
|
|
36
113
|
privateStateId?: string;
|
|
37
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Options for deploying a contract.
|
|
117
|
+
*
|
|
118
|
+
* @since 0.2.0
|
|
119
|
+
* @category model
|
|
120
|
+
*/
|
|
38
121
|
export interface DeployOptions {
|
|
39
122
|
/** Initial private state (defaults to {}) */
|
|
40
123
|
initialPrivateState?: unknown;
|
|
41
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Options for joining a contract.
|
|
127
|
+
*
|
|
128
|
+
* @since 0.2.0
|
|
129
|
+
* @category model
|
|
130
|
+
*/
|
|
42
131
|
export interface JoinOptions {
|
|
43
132
|
/** Initial private state (defaults to {}) */
|
|
44
133
|
initialPrivateState?: unknown;
|
|
45
134
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
readonly logger: Logger;
|
|
53
|
-
/** Load a contract from a build directory path */
|
|
54
|
-
contractFrom(basePath: string, options?: ContractFromOptions): Promise<ContractBuilder>;
|
|
55
|
-
/** Wait for a transaction to be finalized on-chain by its hash */
|
|
56
|
-
waitForTx(txHash: string): Promise<FinalizedTxData>;
|
|
57
|
-
}
|
|
135
|
+
/**
|
|
136
|
+
* Data about a finalized transaction.
|
|
137
|
+
*
|
|
138
|
+
* @since 0.2.0
|
|
139
|
+
* @category model
|
|
140
|
+
*/
|
|
58
141
|
export interface FinalizedTxData {
|
|
59
142
|
txHash: string;
|
|
60
143
|
blockHeight: number;
|
|
61
144
|
blockHash: string;
|
|
62
145
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
146
|
+
/**
|
|
147
|
+
* A contract module definition.
|
|
148
|
+
*
|
|
149
|
+
* @since 0.2.0
|
|
150
|
+
* @category model
|
|
151
|
+
*/
|
|
152
|
+
export interface ContractModule {
|
|
153
|
+
Contract: new (witnesses: unknown) => unknown;
|
|
154
|
+
ledger: (state: unknown) => unknown;
|
|
70
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* A loaded contract module with configuration.
|
|
158
|
+
*
|
|
159
|
+
* @since 0.2.0
|
|
160
|
+
* @category model
|
|
161
|
+
*/
|
|
71
162
|
export interface LoadedContractModule {
|
|
72
163
|
Contract: new (witnesses: unknown) => unknown;
|
|
73
164
|
ledger: (state: unknown) => unknown;
|
|
74
|
-
zkConfigPath: string;
|
|
75
165
|
privateStateId: string;
|
|
76
166
|
witnesses: Record<string, unknown>;
|
|
77
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Result of a contract call.
|
|
170
|
+
*
|
|
171
|
+
* @since 0.2.0
|
|
172
|
+
* @category model
|
|
173
|
+
*/
|
|
174
|
+
export interface CallResult {
|
|
175
|
+
txHash: string;
|
|
176
|
+
blockHeight: number;
|
|
177
|
+
status: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Represents a Midnight client.
|
|
181
|
+
*
|
|
182
|
+
* This is plain data - use module functions to operate on it.
|
|
183
|
+
*
|
|
184
|
+
* @since 0.2.0
|
|
185
|
+
* @category model
|
|
186
|
+
*/
|
|
187
|
+
export interface MidnightClient {
|
|
188
|
+
/** Raw wallet context for advanced use (null if using wallet connector) */
|
|
189
|
+
readonly wallet: WalletContext | null;
|
|
190
|
+
/** Network configuration */
|
|
191
|
+
readonly networkConfig: NetworkConfig;
|
|
192
|
+
/** Logger instance */
|
|
193
|
+
readonly logger: Logger;
|
|
194
|
+
/** Contract providers */
|
|
195
|
+
readonly providers: ContractProviders;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Represents a contract builder for deploying or joining contracts.
|
|
199
|
+
*
|
|
200
|
+
* This is plain data - use module functions to operate on it.
|
|
201
|
+
*
|
|
202
|
+
* @since 0.2.0
|
|
203
|
+
* @category model
|
|
204
|
+
*/
|
|
205
|
+
export interface ContractBuilder {
|
|
206
|
+
/** The loaded contract module */
|
|
207
|
+
readonly module: LoadedContractModule;
|
|
208
|
+
/** Contract providers */
|
|
209
|
+
readonly providers: ContractProviders;
|
|
210
|
+
/** Logger */
|
|
211
|
+
readonly logger: Logger;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Represents a connected contract.
|
|
215
|
+
*
|
|
216
|
+
* This is plain data - use module functions to operate on it.
|
|
217
|
+
*
|
|
218
|
+
* @since 0.2.0
|
|
219
|
+
* @category model
|
|
220
|
+
*/
|
|
78
221
|
export interface ConnectedContract {
|
|
79
222
|
/** The deployed contract address */
|
|
80
223
|
readonly address: string;
|
|
@@ -86,61 +229,390 @@ export interface ConnectedContract {
|
|
|
86
229
|
readonly providers: ContractProviders;
|
|
87
230
|
/** Logger */
|
|
88
231
|
readonly logger: Logger;
|
|
89
|
-
/** Call a contract circuit - waits for transaction to be finalized */
|
|
90
|
-
call(action: string, ...args: unknown[]): Promise<CallResult>;
|
|
91
|
-
/** Query contract public state (raw) - latest */
|
|
92
|
-
state(): Promise<unknown>;
|
|
93
|
-
/** Query contract public state at specific block height (raw) */
|
|
94
|
-
stateAt(blockHeight: number): Promise<unknown>;
|
|
95
|
-
/** Query contract public state (parsed via ledger) - latest */
|
|
96
|
-
ledgerState(): Promise<unknown>;
|
|
97
|
-
/** Query contract public state at specific block height (parsed via ledger) */
|
|
98
|
-
ledgerStateAt(blockHeight: number): Promise<unknown>;
|
|
99
232
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
233
|
+
declare function createEffect(config: ClientConfig): Effect.Effect<MidnightClient, ClientError>;
|
|
234
|
+
declare function fromWalletEffect(connection: WalletConnection, config: {
|
|
235
|
+
zkConfigProvider: ZKConfigProvider<string>;
|
|
236
|
+
privateStateProvider: PrivateStateProvider;
|
|
237
|
+
logging?: boolean;
|
|
238
|
+
}): Effect.Effect<MidnightClient, ClientError>;
|
|
239
|
+
declare function contractFromEffect(client: MidnightClient, options: ContractFromOptions): Effect.Effect<ContractBuilder, ClientError>;
|
|
240
|
+
declare function waitForTxEffect(client: MidnightClient, txHash: string): Effect.Effect<FinalizedTxData, ClientError>;
|
|
241
|
+
/**
|
|
242
|
+
* Create a Midnight client for interacting with contracts using a seed.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const client = await Client.create({
|
|
247
|
+
* seed: 'your-64-char-hex-seed',
|
|
248
|
+
* networkConfig: Config.NETWORKS.local,
|
|
249
|
+
* zkConfigProvider,
|
|
250
|
+
* privateStateProvider,
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @since 0.2.0
|
|
255
|
+
* @category constructors
|
|
256
|
+
*/
|
|
257
|
+
export declare function create(config: ClientConfig): Promise<MidnightClient>;
|
|
258
|
+
/**
|
|
259
|
+
* Create a Midnight client from a connected wallet (browser).
|
|
260
|
+
*
|
|
261
|
+
* @since 0.2.0
|
|
262
|
+
* @category constructors
|
|
263
|
+
*/
|
|
264
|
+
export declare function fromWallet(connection: WalletConnection, config: {
|
|
265
|
+
zkConfigProvider: ZKConfigProvider<string>;
|
|
266
|
+
privateStateProvider: PrivateStateProvider;
|
|
267
|
+
logging?: boolean;
|
|
268
|
+
}): Promise<MidnightClient>;
|
|
269
|
+
/**
|
|
270
|
+
* Load a contract module for a client.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const builder = await Client.contractFrom(client, {
|
|
275
|
+
* module: await import('./contracts/counter/index.js'),
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @since 0.2.0
|
|
280
|
+
* @category operations
|
|
281
|
+
*/
|
|
282
|
+
export declare function contractFrom(client: MidnightClient, options: ContractFromOptions): Promise<ContractBuilder>;
|
|
283
|
+
/**
|
|
284
|
+
* Wait for a transaction to be finalized.
|
|
285
|
+
*
|
|
286
|
+
* @since 0.2.0
|
|
287
|
+
* @category operations
|
|
288
|
+
*/
|
|
289
|
+
export declare function waitForTx(client: MidnightClient, txHash: string): Promise<FinalizedTxData>;
|
|
290
|
+
/**
|
|
291
|
+
* Raw Effect APIs for advanced users.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const client = yield* Client.effect.create(config);
|
|
296
|
+
* const builder = yield* Client.effect.contractFrom(client, { module });
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @since 0.2.0
|
|
300
|
+
* @category effect
|
|
301
|
+
*/
|
|
302
|
+
export declare const effect: {
|
|
303
|
+
create: typeof createEffect;
|
|
304
|
+
fromWallet: typeof fromWalletEffect;
|
|
305
|
+
contractFrom: typeof contractFromEffect;
|
|
306
|
+
waitForTx: typeof waitForTxEffect;
|
|
307
|
+
};
|
|
308
|
+
declare function deployEffect(builder: ContractBuilder, options?: DeployOptions): Effect.Effect<ConnectedContract, ContractError>;
|
|
309
|
+
declare function joinEffect(builder: ContractBuilder, address: string, options?: JoinOptions): Effect.Effect<ConnectedContract, ContractError>;
|
|
310
|
+
/**
|
|
311
|
+
* ContractBuilder module functions.
|
|
312
|
+
*
|
|
313
|
+
* @since 0.2.0
|
|
314
|
+
* @category ContractBuilder
|
|
315
|
+
*/
|
|
316
|
+
export declare const ContractBuilder: {
|
|
317
|
+
/**
|
|
318
|
+
* Deploy a new contract instance.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* const contract = await ContractBuilder.deploy(builder);
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* @since 0.2.0
|
|
326
|
+
* @category lifecycle
|
|
327
|
+
*/
|
|
328
|
+
deploy: (builder: ContractBuilder, options?: DeployOptions) => Promise<ConnectedContract>;
|
|
329
|
+
/**
|
|
330
|
+
* Join an existing contract.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* const contract = await ContractBuilder.join(builder, '0x...');
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @since 0.2.0
|
|
338
|
+
* @category lifecycle
|
|
339
|
+
*/
|
|
340
|
+
join: (builder: ContractBuilder, address: string, options?: JoinOptions) => Promise<ConnectedContract>;
|
|
341
|
+
/**
|
|
342
|
+
* Raw Effect APIs for ContractBuilder.
|
|
343
|
+
*
|
|
344
|
+
* @since 0.2.0
|
|
345
|
+
* @category effect
|
|
346
|
+
*/
|
|
347
|
+
effect: {
|
|
348
|
+
deploy: typeof deployEffect;
|
|
349
|
+
join: typeof joinEffect;
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
declare function callEffect(contract: ConnectedContract, action: string, ...args: unknown[]): Effect.Effect<CallResult, ContractError>;
|
|
353
|
+
declare function stateEffect(contract: ConnectedContract): Effect.Effect<unknown, ContractError>;
|
|
354
|
+
declare function stateAtEffect(contract: ConnectedContract, blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
355
|
+
declare function ledgerStateEffect(contract: ConnectedContract): Effect.Effect<unknown, ContractError>;
|
|
356
|
+
declare function ledgerStateAtEffect(contract: ConnectedContract, blockHeight: number): Effect.Effect<unknown, ContractError>;
|
|
357
|
+
/**
|
|
358
|
+
* Contract module functions.
|
|
359
|
+
*
|
|
360
|
+
* @since 0.2.0
|
|
361
|
+
* @category Contract
|
|
362
|
+
*/
|
|
363
|
+
export declare const Contract: {
|
|
364
|
+
/**
|
|
365
|
+
* Call a contract action.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const result = await Contract.call(contract, 'increment');
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* @since 0.2.0
|
|
373
|
+
* @category operations
|
|
374
|
+
*/
|
|
375
|
+
call: (contract: ConnectedContract, action: string, ...args: unknown[]) => Promise<CallResult>;
|
|
376
|
+
/**
|
|
377
|
+
* Get contract state.
|
|
378
|
+
*
|
|
379
|
+
* @since 0.2.0
|
|
380
|
+
* @category inspection
|
|
381
|
+
*/
|
|
382
|
+
state: (contract: ConnectedContract) => Promise<unknown>;
|
|
383
|
+
/**
|
|
384
|
+
* Get contract state at a specific block height.
|
|
385
|
+
*
|
|
386
|
+
* @since 0.2.0
|
|
387
|
+
* @category inspection
|
|
388
|
+
*/
|
|
389
|
+
stateAt: (contract: ConnectedContract, blockHeight: number) => Promise<unknown>;
|
|
390
|
+
/**
|
|
391
|
+
* Get ledger state (parsed through ledger function).
|
|
392
|
+
*
|
|
393
|
+
* @since 0.2.0
|
|
394
|
+
* @category inspection
|
|
395
|
+
*/
|
|
396
|
+
ledgerState: (contract: ConnectedContract) => Promise<unknown>;
|
|
397
|
+
/**
|
|
398
|
+
* Get ledger state at a specific block height.
|
|
399
|
+
*
|
|
400
|
+
* @since 0.2.0
|
|
401
|
+
* @category inspection
|
|
402
|
+
*/
|
|
403
|
+
ledgerStateAt: (contract: ConnectedContract, blockHeight: number) => Promise<unknown>;
|
|
404
|
+
/**
|
|
405
|
+
* Raw Effect APIs for Contract.
|
|
406
|
+
*
|
|
407
|
+
* @since 0.2.0
|
|
408
|
+
* @category effect
|
|
409
|
+
*/
|
|
410
|
+
effect: {
|
|
411
|
+
call: typeof callEffect;
|
|
412
|
+
state: typeof stateEffect;
|
|
413
|
+
stateAt: typeof stateAtEffect;
|
|
414
|
+
ledgerState: typeof ledgerStateEffect;
|
|
415
|
+
ledgerStateAt: typeof ledgerStateAtEffect;
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Service interface for Client operations.
|
|
420
|
+
*
|
|
421
|
+
* @since 0.2.0
|
|
422
|
+
* @category service
|
|
423
|
+
*/
|
|
424
|
+
export interface ClientServiceImpl {
|
|
425
|
+
readonly create: (config: ClientConfig) => Effect.Effect<MidnightClient, ClientError>;
|
|
426
|
+
readonly fromWallet: (connection: WalletConnection, config: {
|
|
427
|
+
zkConfigProvider: ZKConfigProvider<string>;
|
|
428
|
+
privateStateProvider: PrivateStateProvider;
|
|
429
|
+
logging?: boolean;
|
|
430
|
+
}) => Effect.Effect<MidnightClient, ClientError>;
|
|
431
|
+
readonly contractFrom: (client: MidnightClient, options: ContractFromOptions) => Effect.Effect<ContractBuilder, ClientError>;
|
|
432
|
+
readonly waitForTx: (client: MidnightClient, txHash: string) => Effect.Effect<FinalizedTxData, ClientError>;
|
|
104
433
|
}
|
|
434
|
+
declare const ClientService_base: Context.TagClass<ClientService, "ClientService", ClientServiceImpl>;
|
|
105
435
|
/**
|
|
106
|
-
*
|
|
436
|
+
* Context.Tag for ClientService dependency injection.
|
|
107
437
|
*
|
|
108
438
|
* @example
|
|
109
439
|
* ```typescript
|
|
440
|
+
* const program = Effect.gen(function* () {
|
|
441
|
+
* const clientService = yield* ClientService;
|
|
442
|
+
* const client = yield* clientService.create(config);
|
|
443
|
+
* return client;
|
|
444
|
+
* });
|
|
445
|
+
*
|
|
446
|
+
* Effect.runPromise(program.pipe(Effect.provide(ClientLive)));
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @since 0.2.0
|
|
450
|
+
* @category service
|
|
451
|
+
*/
|
|
452
|
+
export declare class ClientService extends ClientService_base {
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Service interface for ContractBuilder operations.
|
|
456
|
+
*
|
|
457
|
+
* @since 0.2.0
|
|
458
|
+
* @category service
|
|
459
|
+
*/
|
|
460
|
+
export interface ContractBuilderServiceImpl {
|
|
461
|
+
readonly deploy: (builder: ContractBuilder, options?: DeployOptions) => Effect.Effect<ConnectedContract, ContractError>;
|
|
462
|
+
readonly join: (builder: ContractBuilder, address: string, options?: JoinOptions) => Effect.Effect<ConnectedContract, ContractError>;
|
|
463
|
+
}
|
|
464
|
+
declare const ContractBuilderService_base: Context.TagClass<ContractBuilderService, "ContractBuilderService", ContractBuilderServiceImpl>;
|
|
465
|
+
/**
|
|
466
|
+
* Context.Tag for ContractBuilderService dependency injection.
|
|
467
|
+
*
|
|
468
|
+
* @since 0.2.0
|
|
469
|
+
* @category service
|
|
470
|
+
*/
|
|
471
|
+
export declare class ContractBuilderService extends ContractBuilderService_base {
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Service interface for Contract operations.
|
|
475
|
+
*
|
|
476
|
+
* @since 0.2.0
|
|
477
|
+
* @category service
|
|
478
|
+
*/
|
|
479
|
+
export interface ContractServiceImpl {
|
|
480
|
+
readonly call: (contract: ConnectedContract, action: string, ...args: unknown[]) => Effect.Effect<CallResult, ContractError>;
|
|
481
|
+
readonly state: (contract: ConnectedContract) => Effect.Effect<unknown, ContractError>;
|
|
482
|
+
readonly stateAt: (contract: ConnectedContract, blockHeight: number) => Effect.Effect<unknown, ContractError>;
|
|
483
|
+
readonly ledgerState: (contract: ConnectedContract) => Effect.Effect<unknown, ContractError>;
|
|
484
|
+
readonly ledgerStateAt: (contract: ConnectedContract, blockHeight: number) => Effect.Effect<unknown, ContractError>;
|
|
485
|
+
}
|
|
486
|
+
declare const ContractService_base: Context.TagClass<ContractService, "ContractService", ContractServiceImpl>;
|
|
487
|
+
/**
|
|
488
|
+
* Context.Tag for ContractService dependency injection.
|
|
489
|
+
*
|
|
490
|
+
* @since 0.2.0
|
|
491
|
+
* @category service
|
|
492
|
+
*/
|
|
493
|
+
export declare class ContractService extends ContractService_base {
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Live Layer for ClientService.
|
|
497
|
+
*
|
|
498
|
+
* @since 0.2.0
|
|
499
|
+
* @category layer
|
|
500
|
+
*/
|
|
501
|
+
export declare const ClientLive: Layer.Layer<ClientService>;
|
|
502
|
+
/**
|
|
503
|
+
* Live Layer for ContractBuilderService.
|
|
504
|
+
*
|
|
505
|
+
* @since 0.2.0
|
|
506
|
+
* @category layer
|
|
507
|
+
*/
|
|
508
|
+
export declare const ContractBuilderLive: Layer.Layer<ContractBuilderService>;
|
|
509
|
+
/**
|
|
510
|
+
* Live Layer for ContractService.
|
|
511
|
+
*
|
|
512
|
+
* @since 0.2.0
|
|
513
|
+
* @category layer
|
|
514
|
+
*/
|
|
515
|
+
export declare const ContractLive: Layer.Layer<ContractService>;
|
|
516
|
+
/**
|
|
517
|
+
* Create a Layer providing all Client-related factory services.
|
|
518
|
+
*
|
|
519
|
+
* Use this when you want to create clients on-demand within your Effect programs.
|
|
520
|
+
* For pre-initialized clients, use `Client.layer(config)` instead.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```typescript
|
|
524
|
+
* import { Effect } from 'effect';
|
|
110
525
|
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
111
526
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
527
|
+
* const program = Effect.gen(function* () {
|
|
528
|
+
* const clientService = yield* Midday.ClientService;
|
|
529
|
+
* const client = yield* clientService.create(config);
|
|
530
|
+
* return client;
|
|
531
|
+
* });
|
|
532
|
+
*
|
|
533
|
+
* await Effect.runPromise(program.pipe(Effect.provide(Midday.Client.services())));
|
|
534
|
+
* ```
|
|
114
535
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
|
|
536
|
+
* @since 0.3.0
|
|
537
|
+
* @category layer
|
|
538
|
+
*/
|
|
539
|
+
export declare function services(): Layer.Layer<ClientService | ContractBuilderService | ContractService>;
|
|
540
|
+
declare const MidnightClientService_base: Context.TagClass<MidnightClientService, "MidnightClientService", MidnightClient>;
|
|
541
|
+
/**
|
|
542
|
+
* Context.Tag for a pre-initialized MidnightClient.
|
|
543
|
+
*
|
|
544
|
+
* Use with `Client.layer(config)` for dependency injection of a configured client.
|
|
545
|
+
*
|
|
546
|
+
* @since 0.3.0
|
|
547
|
+
* @category service
|
|
548
|
+
*/
|
|
549
|
+
export declare class MidnightClientService extends MidnightClientService_base {
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Create a Layer that provides a pre-initialized MidnightClient.
|
|
553
|
+
*
|
|
554
|
+
* This is the recommended way to inject a client into Effect programs
|
|
555
|
+
* when you have a known configuration at startup. Follows the same pattern
|
|
556
|
+
* as `Cluster.layer(config)`.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* import { Effect } from 'effect';
|
|
561
|
+
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
562
|
+
*
|
|
563
|
+
* const clientLayer = Midday.Client.layer({
|
|
564
|
+
* seed: 'your-64-char-hex-seed',
|
|
565
|
+
* networkConfig: Midday.Config.NETWORKS.local,
|
|
566
|
+
* zkConfigProvider: new Midday.HttpZkConfigProvider('http://localhost:3000/zk'),
|
|
567
|
+
* privateStateProvider: Midday.inMemoryPrivateStateProvider(),
|
|
118
568
|
* });
|
|
119
569
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* indexer: 'https://indexer.testnet.midnight.network/graphql',
|
|
125
|
-
* indexerWS: 'wss://indexer.testnet.midnight.network/graphql/ws',
|
|
126
|
-
* node: 'wss://node.testnet.midnight.network',
|
|
127
|
-
* proofServer: 'https://proof.testnet.midnight.network',
|
|
128
|
-
* }
|
|
570
|
+
* const program = Effect.gen(function* () {
|
|
571
|
+
* const client = yield* Midday.MidnightClientService;
|
|
572
|
+
* const builder = yield* Midday.Client.effect.contractFrom(client, { module });
|
|
573
|
+
* return builder;
|
|
129
574
|
* });
|
|
130
575
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
576
|
+
* await Effect.runPromise(program.pipe(Effect.provide(clientLayer)));
|
|
577
|
+
* ```
|
|
578
|
+
*
|
|
579
|
+
* @since 0.3.0
|
|
580
|
+
* @category layer
|
|
581
|
+
*/
|
|
582
|
+
export declare function layer(config: ClientConfig): Layer.Layer<MidnightClientService, ClientError>;
|
|
583
|
+
/**
|
|
584
|
+
* Create a Layer that provides a pre-initialized MidnightClient from a wallet connection.
|
|
585
|
+
*
|
|
586
|
+
* Use this for browser environments with Lace wallet integration.
|
|
133
587
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```typescript
|
|
590
|
+
* import { Effect } from 'effect';
|
|
591
|
+
* import * as Midday from '@no-witness-labs/midday-sdk';
|
|
136
592
|
*
|
|
137
|
-
* //
|
|
138
|
-
* const
|
|
139
|
-
* console.log(state.counter);
|
|
593
|
+
* // After connecting wallet
|
|
594
|
+
* const connection = await Midday.connectWallet('testnet');
|
|
140
595
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
596
|
+
* const clientLayer = Midday.Client.layerFromWallet(connection, {
|
|
597
|
+
* zkConfigProvider: new Midday.HttpZkConfigProvider('https://cdn.example.com/zk'),
|
|
598
|
+
* privateStateProvider: Midday.indexedDBPrivateStateProvider({ privateStateStoreName: 'my-app' }),
|
|
599
|
+
* });
|
|
600
|
+
*
|
|
601
|
+
* const program = Effect.gen(function* () {
|
|
602
|
+
* const client = yield* Midday.MidnightClientService;
|
|
603
|
+
* // Use client...
|
|
604
|
+
* });
|
|
605
|
+
*
|
|
606
|
+
* await Effect.runPromise(program.pipe(Effect.provide(clientLayer)));
|
|
143
607
|
* ```
|
|
608
|
+
*
|
|
609
|
+
* @since 0.3.0
|
|
610
|
+
* @category layer
|
|
144
611
|
*/
|
|
145
|
-
export declare function
|
|
612
|
+
export declare function layerFromWallet(connection: WalletConnection, config: {
|
|
613
|
+
zkConfigProvider: ZKConfigProvider<string>;
|
|
614
|
+
privateStateProvider: PrivateStateProvider;
|
|
615
|
+
logging?: boolean;
|
|
616
|
+
}): Layer.Layer<MidnightClientService, ClientError>;
|
|
617
|
+
export {};
|
|
146
618
|
//# sourceMappingURL=Client.d.ts.map
|