@midnightntwrk/midnight-js-node-zk-config-provider 0.0.0-stage → 5.0.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 +83 -2
- package/dist/index.d.ts +81 -0
- package/dist/index.js +239 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -3
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Node ZK Config Provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ZK configuration provider that reads proving keys, verifier keys, and ZK intermediate representation from the local filesystem. Designed for Node.js environments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @midnightntwrk/midnight-js-node-zk-config-provider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { NodeZkConfigProvider } from '@midnightntwrk/midnight-js-node-zk-config-provider';
|
|
15
|
+
|
|
16
|
+
const zkConfigProvider = new NodeZkConfigProvider('/path/to/zk-artifacts');
|
|
17
|
+
|
|
18
|
+
const proverKey = await zkConfigProvider.getProverKey('myCircuit');
|
|
19
|
+
const verifierKey = await zkConfigProvider.getVerifierKey('myCircuit');
|
|
20
|
+
const zkir = await zkConfigProvider.getZKIR('myCircuit');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
| Parameter | Required | Description |
|
|
26
|
+
| ----------- | -------- | ------------------------------------------ |
|
|
27
|
+
| `directory` | ✓ | Base directory path for ZK artifact files |
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
### NodeZkConfigProvider
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
class NodeZkConfigProvider<K extends string> extends ZKConfigProvider<K> {
|
|
35
|
+
constructor(directory: string);
|
|
36
|
+
|
|
37
|
+
getProverKey(circuitId: K): Promise<ProverKey>;
|
|
38
|
+
getVerifierKey(circuitId: K): Promise<VerifierKey>;
|
|
39
|
+
getZKIR(circuitId: K): Promise<ZKIR>;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Directory Structure
|
|
44
|
+
|
|
45
|
+
The provider expects the following directory structure:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
{directory}/
|
|
49
|
+
├── compiler/
|
|
50
|
+
│ ├── contract-manifest.json # Integrity manifest (compactc 0.33 and later)
|
|
51
|
+
│ └── contract-info.json # Compiler description, carries runtime-version
|
|
52
|
+
├── keys/
|
|
53
|
+
│ ├── {circuitId}.prover # Prover key (binary)
|
|
54
|
+
│ └── {circuitId}.verifier # Verifier key (binary)
|
|
55
|
+
└── zkir/
|
|
56
|
+
└── {circuitId}.bzkir # ZK intermediate representation (binary)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`compiler/` is what lets the framework establish which ledger era a contract's
|
|
60
|
+
artifacts belong to. The integrity manifest is preferred, because
|
|
61
|
+
`expectedManifestHash` pins it to a digest the application controls;
|
|
62
|
+
`contract-info.json` is the fallback for bundles built before compactc emitted a
|
|
63
|
+
manifest, and it is verified against the manifest whenever one is present.
|
|
64
|
+
Every contract operation reads the declared `runtime-version`, for contracts of
|
|
65
|
+
every era: a bundle that ships neither file is refused with `EraMismatchError`
|
|
66
|
+
reason `'artifact-era-undeclared'`. A custom `ZKConfigProvider` must override
|
|
67
|
+
`getArtifactRuntimeVersion()` for the same reason.
|
|
68
|
+
|
|
69
|
+
## Exports
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { NodeZkConfigProvider } from '@midnightntwrk/midnight-js-node-zk-config-provider';
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Resources
|
|
76
|
+
|
|
77
|
+
- [Midnight Network](https://midnight.network)
|
|
78
|
+
- [Developer Hub](https://midnight.network/developer-hub)
|
|
79
|
+
|
|
80
|
+
## Terms & License
|
|
81
|
+
|
|
82
|
+
By using this package, you agree to [Midnight's Terms and Conditions](https://midnight.network/static/terms.pdf) and [Privacy Policy](https://midnight.network/static/privacy-policy.pdf).
|
|
83
|
+
|
|
84
|
+
Licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ZKConfigProvider, ProverKey, VerifierKey, ZKIR, ZKConfigRegistry } from '@midnightntwrk/midnight-js-types';
|
|
2
|
+
import { ZkConfigIntegrityOptions } from '@midnightntwrk/midnight-js-utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {@link ZKConfigProvider} that reads keys and zkIR from the local filesystem and verifies them
|
|
6
|
+
* against the `compactc` integrity manifest.
|
|
7
|
+
* @typeParam K - The type of the circuit ID used by the provider.
|
|
8
|
+
*/
|
|
9
|
+
declare class NodeZkConfigProvider<K extends string> extends ZKConfigProvider<K> {
|
|
10
|
+
readonly directory: string;
|
|
11
|
+
private readonly integrityOptions;
|
|
12
|
+
private manifestPromise?;
|
|
13
|
+
private runtimeVersionPromise?;
|
|
14
|
+
/**
|
|
15
|
+
* @param directory The base directory containing the key and ZKIR subdirectories.
|
|
16
|
+
* @param integrityOptions Integrity-verification options.
|
|
17
|
+
*/
|
|
18
|
+
constructor(directory: string, integrityOptions?: ZkConfigIntegrityOptions);
|
|
19
|
+
private readFile;
|
|
20
|
+
private loadManifest;
|
|
21
|
+
private readManifest;
|
|
22
|
+
/**
|
|
23
|
+
* Reports the `compact-runtime` this bundle was built against, preferring the source an
|
|
24
|
+
* application can anchor to a hash it controls.
|
|
25
|
+
*
|
|
26
|
+
* The INTEGRITY MANIFEST is consulted first; `compiler/contract-info.json` is the fallback, for
|
|
27
|
+
* bundles that carry no manifest at all. The fallback goes through the same integrity gate as
|
|
28
|
+
* every key and ZKIR, so under the default `require` an unvouched-for description is refused.
|
|
29
|
+
*
|
|
30
|
+
* Cached per provider instance. A FAILED read is not cached.
|
|
31
|
+
*
|
|
32
|
+
* The reasoning behind that ordering is in
|
|
33
|
+
* `packages/utils/docs/artifact-runtime-version.md`.
|
|
34
|
+
*
|
|
35
|
+
* @returns The declared runtime version, verbatim.
|
|
36
|
+
* @throws ZkArtifactContractInfoError if the description is absent or declares no runtime version.
|
|
37
|
+
* @throws ZkArtifactIntegrityError if the description is not covered by the manifest under a mode
|
|
38
|
+
* that requires it.
|
|
39
|
+
*/
|
|
40
|
+
getArtifactRuntimeVersion(): Promise<string>;
|
|
41
|
+
private readRuntimeVersion;
|
|
42
|
+
private verifyArtifact;
|
|
43
|
+
getProverKey(circuitId: K): Promise<ProverKey>;
|
|
44
|
+
getVerifierKey(circuitId: K): Promise<VerifierKey>;
|
|
45
|
+
getZKIR(circuitId: K): Promise<ZKIR>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a {@link ZKConfigRegistry} by discovering every compiled contract artifact bundle under
|
|
49
|
+
* a directory tree.
|
|
50
|
+
*
|
|
51
|
+
* This is the zero-configuration way to provide ZK artifacts for transactions that make
|
|
52
|
+
* cross-contract calls: point it at the project's artifact root (for example the directory
|
|
53
|
+
* containing the `compactc` `managed/<contract>` outputs, or the project root itself) and every
|
|
54
|
+
* bundle found — any directory containing `keys/` and `zkir/` subdirectories — becomes a registry
|
|
55
|
+
* source. No addresses are registered and no per-contract enumeration is needed; the registry
|
|
56
|
+
* binds deployed contracts to bundles by verifier key at resolution time.
|
|
57
|
+
*
|
|
58
|
+
* `node_modules` and hidden directories are not descended into, and discovery stops at a bundle
|
|
59
|
+
* (bundles do not nest).
|
|
60
|
+
*
|
|
61
|
+
* @param artifactRoot The directory to search for artifact bundles.
|
|
62
|
+
* @throws ConfigurationError If no artifact bundle exists under `artifactRoot`.
|
|
63
|
+
*/
|
|
64
|
+
declare const nodeZkConfigRegistry: (artifactRoot: string) => Promise<ZKConfigRegistry>;
|
|
65
|
+
/**
|
|
66
|
+
* Options for {@link nodeZkConfigProvider}. Combines the artifact `directory` with integrity options.
|
|
67
|
+
*/
|
|
68
|
+
interface NodeZkConfigProviderOptions extends ZkConfigIntegrityOptions {
|
|
69
|
+
/** The base directory containing the key and ZKIR subdirectories. */
|
|
70
|
+
readonly directory: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Factory for {@link NodeZkConfigProvider} following the `provider(options)` convention.
|
|
74
|
+
*
|
|
75
|
+
* @typeParam K - The circuit-ID union. It is not inferred from `options`, so supply it explicitly
|
|
76
|
+
* (e.g. `nodeZkConfigProvider<'a' | 'b'>({ … })`) to keep `getProverKey` narrowed; it otherwise widens to `string`.
|
|
77
|
+
*/
|
|
78
|
+
declare function nodeZkConfigProvider<K extends string>(options: NodeZkConfigProviderOptions): NodeZkConfigProvider<K>;
|
|
79
|
+
|
|
80
|
+
export { NodeZkConfigProvider, nodeZkConfigProvider, nodeZkConfigRegistry };
|
|
81
|
+
export type { NodeZkConfigProviderOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { InvalidArgumentError, ConfigurationError } from '@midnightntwrk/midnight-js-protocol/errors';
|
|
2
|
+
import { ZKConfigProvider, createProverKey, createVerifierKey, createZKIR, ZKConfigRegistry } from '@midnightntwrk/midnight-js-types';
|
|
3
|
+
import { assertSafeName, ZK_MANIFEST_DIR, ZK_MANIFEST_FILE_NAME, ZkArtifactIntegrityError, assertManifestHash, parseZkArtifactManifest, ZK_CONTRACT_INFO_FILE_NAME, ZkArtifactContractInfoError, verifyZkArtifactIntegrity, parseZkArtifactRuntimeVersion } from '@midnightntwrk/midnight-js-utils';
|
|
4
|
+
import * as fs from 'fs/promises';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* This file is part of midnight-js.
|
|
9
|
+
* Copyright (C) Midnight Foundation
|
|
10
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* You may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
const KEY_DIR = 'keys';
|
|
22
|
+
const PROVER_EXT = '.prover';
|
|
23
|
+
const VERIFIER_EXT = '.verifier';
|
|
24
|
+
const ZKIR_DIR = 'zkir';
|
|
25
|
+
const ZKIR_EXT = '.bzkir';
|
|
26
|
+
const isErrnoException = (error) => error instanceof Error && 'code' in error;
|
|
27
|
+
/**
|
|
28
|
+
* {@link ZKConfigProvider} that reads keys and zkIR from the local filesystem and verifies them
|
|
29
|
+
* against the `compactc` integrity manifest.
|
|
30
|
+
* @typeParam K - The type of the circuit ID used by the provider.
|
|
31
|
+
*/
|
|
32
|
+
class NodeZkConfigProvider extends ZKConfigProvider {
|
|
33
|
+
directory;
|
|
34
|
+
integrityOptions;
|
|
35
|
+
manifestPromise;
|
|
36
|
+
runtimeVersionPromise;
|
|
37
|
+
/**
|
|
38
|
+
* @param directory The base directory containing the key and ZKIR subdirectories.
|
|
39
|
+
* @param integrityOptions Integrity-verification options.
|
|
40
|
+
*/
|
|
41
|
+
constructor(directory, integrityOptions = {}) {
|
|
42
|
+
super();
|
|
43
|
+
this.directory = directory;
|
|
44
|
+
this.integrityOptions = integrityOptions;
|
|
45
|
+
}
|
|
46
|
+
async readFile(subDir, circuitId, ext) {
|
|
47
|
+
assertSafeName(circuitId, 'circuitId');
|
|
48
|
+
const baseDir = path.resolve(this.directory, subDir);
|
|
49
|
+
const target = path.resolve(baseDir, circuitId + ext);
|
|
50
|
+
const rel = path.relative(baseDir, target);
|
|
51
|
+
if (rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) {
|
|
52
|
+
throw new InvalidArgumentError(`Invalid circuitId: ${JSON.stringify(circuitId)}`);
|
|
53
|
+
}
|
|
54
|
+
return fs.readFile(target);
|
|
55
|
+
}
|
|
56
|
+
loadManifest() {
|
|
57
|
+
if (this.manifestPromise === undefined) {
|
|
58
|
+
const promise = this.readManifest();
|
|
59
|
+
this.manifestPromise = promise;
|
|
60
|
+
promise.catch(() => {
|
|
61
|
+
if (this.manifestPromise === promise) {
|
|
62
|
+
this.manifestPromise = undefined;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return this.manifestPromise;
|
|
67
|
+
}
|
|
68
|
+
async readManifest() {
|
|
69
|
+
const manifestPath = path.resolve(this.directory, ZK_MANIFEST_DIR, ZK_MANIFEST_FILE_NAME);
|
|
70
|
+
const { expectedManifestHash } = this.integrityOptions;
|
|
71
|
+
let bytes;
|
|
72
|
+
try {
|
|
73
|
+
bytes = await fs.readFile(manifestPath);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (isErrnoException(error) && error.code === 'ENOENT') {
|
|
77
|
+
if (expectedManifestHash !== undefined) {
|
|
78
|
+
throw new ZkArtifactIntegrityError(`Expected ZK artifact manifest at ${manifestPath} but it was not found`, { cause: error });
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
if (expectedManifestHash !== undefined) {
|
|
85
|
+
assertManifestHash(bytes, expectedManifestHash);
|
|
86
|
+
}
|
|
87
|
+
return parseZkArtifactManifest(bytes.toString('utf-8'));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Reports the `compact-runtime` this bundle was built against, preferring the source an
|
|
91
|
+
* application can anchor to a hash it controls.
|
|
92
|
+
*
|
|
93
|
+
* The INTEGRITY MANIFEST is consulted first; `compiler/contract-info.json` is the fallback, for
|
|
94
|
+
* bundles that carry no manifest at all. The fallback goes through the same integrity gate as
|
|
95
|
+
* every key and ZKIR, so under the default `require` an unvouched-for description is refused.
|
|
96
|
+
*
|
|
97
|
+
* Cached per provider instance. A FAILED read is not cached.
|
|
98
|
+
*
|
|
99
|
+
* The reasoning behind that ordering is in
|
|
100
|
+
* `packages/utils/docs/artifact-runtime-version.md`.
|
|
101
|
+
*
|
|
102
|
+
* @returns The declared runtime version, verbatim.
|
|
103
|
+
* @throws ZkArtifactContractInfoError if the description is absent or declares no runtime version.
|
|
104
|
+
* @throws ZkArtifactIntegrityError if the description is not covered by the manifest under a mode
|
|
105
|
+
* that requires it.
|
|
106
|
+
*/
|
|
107
|
+
async getArtifactRuntimeVersion() {
|
|
108
|
+
// The cached promise CLEARS ITSELF on failure, so a transient error is retried rather than
|
|
109
|
+
// remembered. Written as one self-clearing chain rather than as a stored promise compared
|
|
110
|
+
// against the slot: nothing can replace the slot between the rejection and this handler, so a
|
|
111
|
+
// comparison would only add a branch no test can reach.
|
|
112
|
+
this.runtimeVersionPromise ??= this.readRuntimeVersion().catch((error) => {
|
|
113
|
+
this.runtimeVersionPromise = undefined;
|
|
114
|
+
throw error;
|
|
115
|
+
});
|
|
116
|
+
return this.runtimeVersionPromise;
|
|
117
|
+
}
|
|
118
|
+
async readRuntimeVersion() {
|
|
119
|
+
const manifest = await this.loadManifest();
|
|
120
|
+
if (manifest?.runtimeVersion !== undefined) {
|
|
121
|
+
return manifest.runtimeVersion;
|
|
122
|
+
}
|
|
123
|
+
const infoPath = path.resolve(this.directory, ZK_MANIFEST_DIR, ZK_CONTRACT_INFO_FILE_NAME);
|
|
124
|
+
let bytes;
|
|
125
|
+
try {
|
|
126
|
+
bytes = await fs.readFile(infoPath);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (isErrnoException(error) && error.code === 'ENOENT') {
|
|
130
|
+
throw new ZkArtifactContractInfoError(`No ${ZK_CONTRACT_INFO_FILE_NAME} was found at ${infoPath}, so the era of these artifacts ` +
|
|
131
|
+
`cannot be established. Serve the compiler output directory that compactc emits beside ` +
|
|
132
|
+
`the keys.`, { cause: error });
|
|
133
|
+
}
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
verifyZkArtifactIntegrity({
|
|
137
|
+
manifest,
|
|
138
|
+
relativePath: `${ZK_MANIFEST_DIR}/${ZK_CONTRACT_INFO_FILE_NAME}`,
|
|
139
|
+
bytes,
|
|
140
|
+
mode: this.integrityOptions.verify ?? 'require',
|
|
141
|
+
onWarn: this.integrityOptions.onWarn
|
|
142
|
+
});
|
|
143
|
+
return parseZkArtifactRuntimeVersion(bytes.toString('utf-8'));
|
|
144
|
+
}
|
|
145
|
+
async verifyArtifact(subDir, fileName, bytes) {
|
|
146
|
+
const manifest = await this.loadManifest();
|
|
147
|
+
verifyZkArtifactIntegrity({
|
|
148
|
+
manifest,
|
|
149
|
+
relativePath: `${subDir}/${fileName}`,
|
|
150
|
+
bytes,
|
|
151
|
+
mode: this.integrityOptions.verify ?? 'require',
|
|
152
|
+
onWarn: this.integrityOptions.onWarn
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async getProverKey(circuitId) {
|
|
156
|
+
const bytes = await this.readFile(KEY_DIR, circuitId, PROVER_EXT);
|
|
157
|
+
await this.verifyArtifact(KEY_DIR, `${circuitId}${PROVER_EXT}`, bytes);
|
|
158
|
+
return createProverKey(bytes);
|
|
159
|
+
}
|
|
160
|
+
async getVerifierKey(circuitId) {
|
|
161
|
+
const bytes = await this.readFile(KEY_DIR, circuitId, VERIFIER_EXT);
|
|
162
|
+
await this.verifyArtifact(KEY_DIR, `${circuitId}${VERIFIER_EXT}`, bytes);
|
|
163
|
+
return createVerifierKey(bytes);
|
|
164
|
+
}
|
|
165
|
+
async getZKIR(circuitId) {
|
|
166
|
+
const bytes = await this.readFile(ZKIR_DIR, circuitId, ZKIR_EXT);
|
|
167
|
+
await this.verifyArtifact(ZKIR_DIR, `${circuitId}${ZKIR_EXT}`, bytes);
|
|
168
|
+
return createZKIR(bytes);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns `true` if `directory` is a compiled contract artifact bundle — a `compactc` output
|
|
173
|
+
* directory containing `keys/` and `zkir/` subdirectories.
|
|
174
|
+
*/
|
|
175
|
+
const isArtifactBundle = async (directory) => {
|
|
176
|
+
const isDir = async (subDir) => {
|
|
177
|
+
try {
|
|
178
|
+
return (await fs.stat(path.join(directory, subDir))).isDirectory();
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
// Only a genuinely absent path means "not a bundle here". Any other failure (e.g. EACCES) is a
|
|
182
|
+
// real IO error and must propagate rather than silently drop a bundle, consistent with
|
|
183
|
+
// `readManifest` in this file.
|
|
184
|
+
if (isErrnoException(error) && (error.code === 'ENOENT' || error.code === 'ENOTDIR')) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
return (await isDir(KEY_DIR)) && (await isDir(ZKIR_DIR));
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Creates a {@link ZKConfigRegistry} by discovering every compiled contract artifact bundle under
|
|
194
|
+
* a directory tree.
|
|
195
|
+
*
|
|
196
|
+
* This is the zero-configuration way to provide ZK artifacts for transactions that make
|
|
197
|
+
* cross-contract calls: point it at the project's artifact root (for example the directory
|
|
198
|
+
* containing the `compactc` `managed/<contract>` outputs, or the project root itself) and every
|
|
199
|
+
* bundle found — any directory containing `keys/` and `zkir/` subdirectories — becomes a registry
|
|
200
|
+
* source. No addresses are registered and no per-contract enumeration is needed; the registry
|
|
201
|
+
* binds deployed contracts to bundles by verifier key at resolution time.
|
|
202
|
+
*
|
|
203
|
+
* `node_modules` and hidden directories are not descended into, and discovery stops at a bundle
|
|
204
|
+
* (bundles do not nest).
|
|
205
|
+
*
|
|
206
|
+
* @param artifactRoot The directory to search for artifact bundles.
|
|
207
|
+
* @throws ConfigurationError If no artifact bundle exists under `artifactRoot`.
|
|
208
|
+
*/
|
|
209
|
+
const nodeZkConfigRegistry = async (artifactRoot) => {
|
|
210
|
+
const sources = [];
|
|
211
|
+
const visit = async (directory) => {
|
|
212
|
+
if (await isArtifactBundle(directory)) {
|
|
213
|
+
sources.push(new NodeZkConfigProvider(directory));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
217
|
+
await Promise.all(entries
|
|
218
|
+
.filter((entry) => entry.isDirectory() && entry.name !== 'node_modules' && !entry.name.startsWith('.'))
|
|
219
|
+
.map((entry) => visit(path.join(directory, entry.name))));
|
|
220
|
+
};
|
|
221
|
+
await visit(path.resolve(artifactRoot));
|
|
222
|
+
if (sources.length === 0) {
|
|
223
|
+
throw new ConfigurationError(`No compiled contract artifact bundles (directories containing '${KEY_DIR}/' and '${ZKIR_DIR}/' subdirectories) found under '${artifactRoot}'`);
|
|
224
|
+
}
|
|
225
|
+
return new ZKConfigRegistry(sources);
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Factory for {@link NodeZkConfigProvider} following the `provider(options)` convention.
|
|
229
|
+
*
|
|
230
|
+
* @typeParam K - The circuit-ID union. It is not inferred from `options`, so supply it explicitly
|
|
231
|
+
* (e.g. `nodeZkConfigProvider<'a' | 'b'>({ … })`) to keep `getProverKey` narrowed; it otherwise widens to `string`.
|
|
232
|
+
*/
|
|
233
|
+
function nodeZkConfigProvider(options) {
|
|
234
|
+
const { directory, ...integrityOptions } = options;
|
|
235
|
+
return new NodeZkConfigProvider(directory, integrityOptions);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { NodeZkConfigProvider, nodeZkConfigProvider, nodeZkConfigRegistry };
|
|
239
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/node-zk-config-provider.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,QAAA,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AACpE,QAAA,MAAM,OAAO,CAAC,GAAG,CACf;aACG,MAAM,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;aACrG,GAAG,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAC3D;AACH,IAAA,CAAC;IACD,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACvC,IAAA,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,kBAAkB,CAC1B,CAAA,+DAAA,EAAkE,OAAO,CAAA,QAAA,EAAW,QAAQ,CAAA,gCAAA,EAAmC,YAAY,CAAA,CAAA,CAAG,CAC/I;IACH;AACA,IAAA,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC;AACtC;AAUA;;;;;AAKG;AACG,SAAU,oBAAoB,CAAmB,OAAoC,EAAA;IACzF,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,EAAE,GAAG,OAAO;AAClD,IAAA,OAAO,IAAI,oBAAoB,CAAI,SAAS,EAAE,gBAAgB,CAAC;AACjE;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnightntwrk/midnight-js-node-zk-config-provider",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "MidnightJS module for reading proving and verifying keys and ZK intermediate representation",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/midnightntwrk/midnight-js.git",
|
|
16
|
+
"directory": "packages/node-zk-config-provider"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/midnightntwrk/midnight-js/tree/main/packages/node-zk-config-provider#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/midnightntwrk/midnight-js/issues"
|
|
21
|
+
},
|
|
22
|
+
"author": "Midnight Foundation",
|
|
23
|
+
"packageManager": "yarn@4.14.1",
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"clean": "rm -rf dist tsconfig.build.tsbuildinfo .rollup.cache reports coverage",
|
|
27
|
+
"build": "rollup -c rollup.config.mjs",
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@midnightntwrk/midnight-js-protocol": "5.0.2",
|
|
32
|
+
"@midnightntwrk/midnight-js-types": "5.0.2",
|
|
33
|
+
"@midnightntwrk/midnight-js-utils": "5.0.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"rollup": "^4.68.2",
|
|
37
|
+
"vite": "^8.3.4",
|
|
38
|
+
"vitest": "^5.0.4"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist/"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22.12"
|
|
45
|
+
}
|
|
6
46
|
}
|