@0xbow/privacy-pools-core-sdk 0.0.0-b21c14ba
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 +73 -0
- package/dist/esm/fetchArtifacts.esm-TV4yMbDL.js +18 -0
- package/dist/esm/fetchArtifacts.esm-TV4yMbDL.js.map +1 -0
- package/dist/esm/fetchArtifacts.node-DC_rCgt3.js +31 -0
- package/dist/esm/fetchArtifacts.node-DC_rCgt3.js.map +1 -0
- package/dist/esm/index-Bw-RoJy9.js +70373 -0
- package/dist/esm/index-Bw-RoJy9.js.map +1 -0
- package/dist/esm/index.mjs +7 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/index.d.mts +1222 -0
- package/dist/node/fetchArtifacts.esm-i9-c1RlE.js +35 -0
- package/dist/node/fetchArtifacts.esm-i9-c1RlE.js.map +1 -0
- package/dist/node/fetchArtifacts.node-C5OS73zV.js +48 -0
- package/dist/node/fetchArtifacts.node-C5OS73zV.js.map +1 -0
- package/dist/node/index-BogHNKL8.js +77423 -0
- package/dist/node/index-BogHNKL8.js.map +1 -0
- package/dist/node/index.mjs +24 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/types/abi/ERC20.d.ts +38 -0
- package/dist/types/abi/IEntrypoint.d.ts +823 -0
- package/dist/types/abi/IPrivacyPool.d.ts +51 -0
- package/dist/types/circuits/circuits.impl.d.ts +120 -0
- package/dist/types/circuits/circuits.interface.d.ts +129 -0
- package/dist/types/circuits/fetchArtifacts.d.ts +1 -0
- package/dist/types/circuits/fetchArtifacts.esm.d.ts +1 -0
- package/dist/types/circuits/fetchArtifacts.node.d.ts +1 -0
- package/dist/types/circuits/index.d.ts +2 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/core/account.service.d.ts +345 -0
- package/dist/types/core/bruteForce.service.d.ts +61 -0
- package/dist/types/core/commitment.service.d.ts +30 -0
- package/dist/types/core/contracts.service.d.ts +114 -0
- package/dist/types/core/data.service.d.ts +52 -0
- package/dist/types/core/sdk.d.ts +45 -0
- package/dist/types/core/withdrawal.service.d.ts +32 -0
- package/dist/types/crypto.d.ts +67 -0
- package/dist/types/dirname.helper.d.ts +2 -0
- package/dist/types/errors/account.error.d.ts +10 -0
- package/dist/types/errors/base.error.d.ts +53 -0
- package/dist/types/errors/data.error.d.ts +7 -0
- package/dist/types/errors/events.error.d.ts +9 -0
- package/dist/types/exceptions/circuitInitialization.exception.d.ts +3 -0
- package/dist/types/exceptions/fetchArtifacts.exception.d.ts +3 -0
- package/dist/types/exceptions/index.d.ts +4 -0
- package/dist/types/exceptions/invalidRpcUrl.exception.d.ts +3 -0
- package/dist/types/exceptions/privacyPool.exception.d.ts +13 -0
- package/dist/types/external.d.ts +7 -0
- package/dist/types/fetchArtifacts.esm-CwvN5XjW.js +34 -0
- package/dist/types/fetchArtifacts.node-VEzDC3k8.js +47 -0
- package/dist/types/filename.helper.d.ts +2 -0
- package/dist/types/index-CPuQ9H-0.js +77436 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +23 -0
- package/dist/types/interfaces/blockchainProvider.interface.d.ts +12 -0
- package/dist/types/interfaces/circuits.interface.d.ts +30 -0
- package/dist/types/interfaces/contracts.interface.d.ts +35 -0
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/internal.d.ts +6 -0
- package/dist/types/keys.d.ts +18 -0
- package/dist/types/providers/blockchainProvider.d.ts +8 -0
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/types/account.d.ts +31 -0
- package/dist/types/types/commitment.d.ts +48 -0
- package/dist/types/types/events.d.ts +72 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/keys.d.ts +5 -0
- package/dist/types/types/withdrawal.d.ts +30 -0
- package/dist/types/utils/logger.d.ts +22 -0
- package/package.json +81 -0
- package/src/abi/ERC20.ts +222 -0
- package/src/abi/IEntrypoint.ts +1059 -0
- package/src/abi/IPrivacyPool.ts +576 -0
- package/src/circuits/circuits.impl.ts +232 -0
- package/src/circuits/circuits.interface.ts +166 -0
- package/src/circuits/fetchArtifacts.esm.ts +12 -0
- package/src/circuits/fetchArtifacts.node.ts +23 -0
- package/src/circuits/fetchArtifacts.ts +7 -0
- package/src/circuits/index.ts +2 -0
- package/src/constants.ts +3 -0
- package/src/core/account.service.ts +1093 -0
- package/src/core/bruteForce.service.ts +120 -0
- package/src/core/commitment.service.ts +84 -0
- package/src/core/contracts.service.ts +450 -0
- package/src/core/data.service.ts +276 -0
- package/src/core/sdk.ts +92 -0
- package/src/core/withdrawal.service.ts +126 -0
- package/src/crypto.ts +226 -0
- package/src/dirname.helper.ts +4 -0
- package/src/errors/account.error.ts +49 -0
- package/src/errors/base.error.ts +125 -0
- package/src/errors/data.error.ts +34 -0
- package/src/errors/events.error.ts +38 -0
- package/src/exceptions/circuitInitialization.exception.ts +6 -0
- package/src/exceptions/fetchArtifacts.exception.ts +7 -0
- package/src/exceptions/index.ts +4 -0
- package/src/exceptions/invalidRpcUrl.exception.ts +6 -0
- package/src/exceptions/privacyPool.exception.ts +19 -0
- package/src/external.ts +13 -0
- package/src/filename.helper.ts +4 -0
- package/src/index.ts +21 -0
- package/src/interfaces/blockchainProvider.interface.ts +13 -0
- package/src/interfaces/circuits.interface.ts +34 -0
- package/src/interfaces/contracts.interface.ts +66 -0
- package/src/interfaces/index.ts +1 -0
- package/src/internal.ts +6 -0
- package/src/keys.ts +42 -0
- package/src/providers/blockchainProvider.ts +30 -0
- package/src/providers/index.ts +1 -0
- package/src/types/account.ts +35 -0
- package/src/types/commitment.ts +50 -0
- package/src/types/events.ts +82 -0
- package/src/types/index.ts +3 -0
- package/src/types/keys.ts +6 -0
- package/src/types/withdrawal.ts +33 -0
- package/src/utils/logger.ts +56 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { CircuitInitialization, FetchArtifact } from "../internal.js";
|
|
2
|
+
import {
|
|
3
|
+
Binaries,
|
|
4
|
+
CircuitArtifacts,
|
|
5
|
+
CircuitName,
|
|
6
|
+
CircuitNameString,
|
|
7
|
+
CircuitsInterface,
|
|
8
|
+
circuitToAsset,
|
|
9
|
+
Version,
|
|
10
|
+
VersionString,
|
|
11
|
+
} from "./circuits.interface.js";
|
|
12
|
+
import { importFetchVersionedArtifact } from "./fetchArtifacts.js";
|
|
13
|
+
|
|
14
|
+
interface CircuitOptions {
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
browser?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Class representing circuit management and artifact handling.
|
|
21
|
+
* Implements the CircuitsInterface.
|
|
22
|
+
*/
|
|
23
|
+
export class Circuits implements CircuitsInterface {
|
|
24
|
+
/**
|
|
25
|
+
* Indicates whether the circuits have been initialized.
|
|
26
|
+
* @type {boolean}
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
protected initialized: boolean = false;
|
|
30
|
+
/**
|
|
31
|
+
* The version of the circuit artifacts being used.
|
|
32
|
+
* @type {VersionString}
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected version: VersionString = Version.Latest;
|
|
36
|
+
/**
|
|
37
|
+
* The binaries containing circuit artifacts such as wasm, vkey, and zkey files.
|
|
38
|
+
* @type {Binaries}
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
protected binaries!: Binaries;
|
|
42
|
+
/**
|
|
43
|
+
* The base URL for fetching circuit artifacts.
|
|
44
|
+
* @type {string}
|
|
45
|
+
* @protected
|
|
46
|
+
*/
|
|
47
|
+
protected baseUrl: string = import.meta.url;
|
|
48
|
+
|
|
49
|
+
protected readonly browser: boolean = true;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Constructor to initialize the Circuits class with an optional custom base URL.
|
|
53
|
+
* @param {string} [options.baseUrl] - The base URL for fetching circuit artifacts (optional).
|
|
54
|
+
* @param {boolean} [options.browser] - Controls how the circuits will be loaded, using either `fetch` if true or `fs` otherwise. Defaults to true.
|
|
55
|
+
*/
|
|
56
|
+
constructor(options?: CircuitOptions) {
|
|
57
|
+
if (options?.baseUrl) {
|
|
58
|
+
this.baseUrl = options.baseUrl;
|
|
59
|
+
}
|
|
60
|
+
if (options?.browser !== undefined) {
|
|
61
|
+
this.browser = options.browser;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Determines whether the environment is a browser.
|
|
67
|
+
* @returns {boolean} True if running in a browser environment, false otherwise.
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
_browser(): boolean {
|
|
71
|
+
return typeof window !== "undefined";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Initializes the circuit manager with binaries and a version.
|
|
76
|
+
* @param {Binaries} binaries - The binaries containing circuit artifacts.
|
|
77
|
+
* @param {VersionString} version - The version of the circuit artifacts.
|
|
78
|
+
* @protected
|
|
79
|
+
*/
|
|
80
|
+
protected _initialize(binaries: Binaries, version: VersionString) {
|
|
81
|
+
this.binaries = binaries;
|
|
82
|
+
this.version = version;
|
|
83
|
+
this.initialized = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Handles initialization of circuit artifacts, fetching them if necessary.
|
|
88
|
+
* @param {VersionString} [version=Version.latest] - The version of the circuit artifacts.
|
|
89
|
+
* @throws {CircuitInitialization} If an error occurs during initialization.
|
|
90
|
+
* @protected
|
|
91
|
+
* @async
|
|
92
|
+
*/
|
|
93
|
+
protected async _handleInitialization(
|
|
94
|
+
version: VersionString = Version.Latest,
|
|
95
|
+
) {
|
|
96
|
+
if (!this.initialized || this.binaries === undefined) {
|
|
97
|
+
try {
|
|
98
|
+
await this.initArtifacts(version);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (e instanceof FetchArtifact) {
|
|
101
|
+
throw new CircuitInitialization(`${e.name}: ${e.message}`);
|
|
102
|
+
} else {
|
|
103
|
+
console.error(e);
|
|
104
|
+
throw new CircuitInitialization(`UnknownError: ${e}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Fetches a versioned artifact from a given path.
|
|
112
|
+
* @param {string} artifactPath - The path to the artifact.
|
|
113
|
+
* @param {VersionString} version - The version of the artifact.
|
|
114
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the artifact as a Uint8Array.
|
|
115
|
+
* @throws {FetchArtifact} If the artifact cannot be fetched.
|
|
116
|
+
* @protected
|
|
117
|
+
* @async
|
|
118
|
+
*/
|
|
119
|
+
async _fetchVersionedArtifact(artifactPath: string): Promise<Uint8Array> {
|
|
120
|
+
const artifactUrl = new URL(artifactPath, this.baseUrl);
|
|
121
|
+
const { fetchVersionedArtifact } = await importFetchVersionedArtifact(
|
|
122
|
+
this.browser,
|
|
123
|
+
);
|
|
124
|
+
return fetchVersionedArtifact(artifactUrl);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Downloads and returns the circuit artifacts for a specific circuit.
|
|
129
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
130
|
+
* @returns {Promise<CircuitArtifacts>} A promise that resolves to the circuit artifacts.
|
|
131
|
+
* @protected
|
|
132
|
+
* @async
|
|
133
|
+
*/
|
|
134
|
+
async _downloadCircuitArtifacts(
|
|
135
|
+
circuitName: CircuitNameString,
|
|
136
|
+
): Promise<CircuitArtifacts> {
|
|
137
|
+
const assetName = circuitToAsset[circuitName];
|
|
138
|
+
|
|
139
|
+
const [wasm, vkey, zkey] = await Promise.all([
|
|
140
|
+
this._fetchVersionedArtifact(["artifacts", assetName.wasm].join("/")),
|
|
141
|
+
this._fetchVersionedArtifact(["artifacts", assetName.vkey].join("/")),
|
|
142
|
+
this._fetchVersionedArtifact(["artifacts", assetName.zkey].join("/")),
|
|
143
|
+
]);
|
|
144
|
+
return { wasm, vkey, zkey };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Downloads all circuit artifacts for the specified version.
|
|
149
|
+
* @param {VersionString} version - The version of the artifacts.
|
|
150
|
+
* @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
|
|
151
|
+
* @async
|
|
152
|
+
*/
|
|
153
|
+
// prettier-ignore
|
|
154
|
+
async downloadArtifacts(version: VersionString): Promise<Binaries> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
155
|
+
const [commitment, withdraw] = await Promise.all([
|
|
156
|
+
this._downloadCircuitArtifacts(CircuitName.Commitment),
|
|
157
|
+
this._downloadCircuitArtifacts(CircuitName.Withdraw),
|
|
158
|
+
]);
|
|
159
|
+
return {
|
|
160
|
+
commitment,
|
|
161
|
+
withdraw,
|
|
162
|
+
} as Binaries;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Initializes the circuit artifacts for the specified version.
|
|
167
|
+
* @param {VersionString} version - The version of the artifacts.
|
|
168
|
+
* @returns {Promise<void>} A promise that resolves when initialization is complete.
|
|
169
|
+
* @async
|
|
170
|
+
*/
|
|
171
|
+
async initArtifacts(version: VersionString): Promise<void> {
|
|
172
|
+
const binaries = await this.downloadArtifacts(version);
|
|
173
|
+
this._initialize(binaries, version);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Retrieves the verification key for a specified circuit.
|
|
178
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
179
|
+
* @param {VersionString} [version=Version.latest] - The version of the artifacts.
|
|
180
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
|
|
181
|
+
* @async
|
|
182
|
+
*/
|
|
183
|
+
async getVerificationKey(
|
|
184
|
+
circuitName: CircuitNameString,
|
|
185
|
+
version: VersionString = Version.Latest,
|
|
186
|
+
): Promise<Uint8Array> {
|
|
187
|
+
await this._handleInitialization(version);
|
|
188
|
+
const artifacts = this.binaries[circuitName];
|
|
189
|
+
if (!artifacts) {
|
|
190
|
+
throw new CircuitInitialization(`Circuit artifacts not found for ${circuitName}`);
|
|
191
|
+
}
|
|
192
|
+
return artifacts.vkey;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Retrieves the proving key for a specified circuit.
|
|
197
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
198
|
+
* @param {VersionString} [version=Version.latest] - The version of the artifacts.
|
|
199
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
|
|
200
|
+
* @async
|
|
201
|
+
*/
|
|
202
|
+
async getProvingKey(
|
|
203
|
+
circuitName: CircuitNameString,
|
|
204
|
+
version: VersionString = Version.Latest,
|
|
205
|
+
): Promise<Uint8Array> {
|
|
206
|
+
await this._handleInitialization(version);
|
|
207
|
+
const artifacts = this.binaries[circuitName];
|
|
208
|
+
if (!artifacts) {
|
|
209
|
+
throw new CircuitInitialization(`Circuit artifacts not found for ${circuitName}`);
|
|
210
|
+
}
|
|
211
|
+
return artifacts.zkey;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Retrieves the wasm file for a specified circuit.
|
|
216
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
217
|
+
* @param {VersionString} [version=Version.latest] - The version of the artifacts.
|
|
218
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
|
|
219
|
+
* @async
|
|
220
|
+
*/
|
|
221
|
+
async getWasm(
|
|
222
|
+
circuitName: CircuitNameString,
|
|
223
|
+
version: VersionString = Version.Latest,
|
|
224
|
+
): Promise<Uint8Array> {
|
|
225
|
+
await this._handleInitialization(version);
|
|
226
|
+
const artifacts = this.binaries[circuitName];
|
|
227
|
+
if (!artifacts) {
|
|
228
|
+
throw new CircuitInitialization(`Circuit artifacts not found for ${circuitName}`);
|
|
229
|
+
}
|
|
230
|
+
return artifacts.wasm;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing available versions of circuit artifacts.
|
|
3
|
+
*/
|
|
4
|
+
export enum Version {
|
|
5
|
+
/**
|
|
6
|
+
* The latest version of the circuit artifacts.
|
|
7
|
+
*/
|
|
8
|
+
Latest = "latest",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Type representing a version string, which is a string literal derived from the Version enum.
|
|
13
|
+
*/
|
|
14
|
+
export type VersionString = `${Version}`;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Enum representing the names of available circuits.
|
|
18
|
+
*/
|
|
19
|
+
export enum CircuitName {
|
|
20
|
+
/**
|
|
21
|
+
* Circuit for commitments.
|
|
22
|
+
*/
|
|
23
|
+
Commitment = "commitment",
|
|
24
|
+
/**
|
|
25
|
+
* Circuit for Merkle tree operations.
|
|
26
|
+
*/
|
|
27
|
+
MerkleTree = "merkleTree",
|
|
28
|
+
/**
|
|
29
|
+
* Circuit for withdrawal operations.
|
|
30
|
+
*/
|
|
31
|
+
Withdraw = "withdraw",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Type representing a circuit name string, which is a string literal derived from the CircuitName enum.
|
|
36
|
+
*/
|
|
37
|
+
export type CircuitNameString = `${CircuitName}`;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Interface representing the artifacts associated with a circuit.
|
|
41
|
+
*/
|
|
42
|
+
export interface CircuitArtifacts {
|
|
43
|
+
/**
|
|
44
|
+
* The precompiled wasm file for the circuit.
|
|
45
|
+
* @type {Uint8Array}
|
|
46
|
+
*/
|
|
47
|
+
wasm: Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* The verification key for the circuit.
|
|
50
|
+
* @type {Uint8Array}
|
|
51
|
+
*/
|
|
52
|
+
vkey: Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* The proving key for the circuit.
|
|
55
|
+
* @type {Uint8Array}
|
|
56
|
+
*/
|
|
57
|
+
zkey: Uint8Array;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Type representing the mapping of circuit names to their respective asset file paths.
|
|
62
|
+
*/
|
|
63
|
+
export type Circ2Asset = {
|
|
64
|
+
[key in CircuitName]: {
|
|
65
|
+
/**
|
|
66
|
+
* The filename of the compiled wasm file.
|
|
67
|
+
*/
|
|
68
|
+
wasm: string;
|
|
69
|
+
/**
|
|
70
|
+
* The filename of the verification key file.
|
|
71
|
+
*/
|
|
72
|
+
vkey: string;
|
|
73
|
+
/**
|
|
74
|
+
* The filename of the proving key file.
|
|
75
|
+
*/
|
|
76
|
+
zkey: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Mapping of circuit names to their respective asset file paths.
|
|
82
|
+
* @const
|
|
83
|
+
*/
|
|
84
|
+
export const circuitToAsset: Circ2Asset = {
|
|
85
|
+
[CircuitName.Commitment]: {
|
|
86
|
+
wasm: "commitment.wasm",
|
|
87
|
+
vkey: "commitment.vkey",
|
|
88
|
+
zkey: "commitment.zkey",
|
|
89
|
+
},
|
|
90
|
+
[CircuitName.MerkleTree]: {
|
|
91
|
+
wasm: "merkleTree.wasm",
|
|
92
|
+
vkey: "merkleTree.vkey",
|
|
93
|
+
zkey: "merkleTree.zkey",
|
|
94
|
+
},
|
|
95
|
+
[CircuitName.Withdraw]: {
|
|
96
|
+
wasm: "withdraw.wasm",
|
|
97
|
+
vkey: "withdraw.vkey",
|
|
98
|
+
zkey: "withdraw.zkey",
|
|
99
|
+
},
|
|
100
|
+
} as const;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Type representing the mapping of circuit name strings to their associated circuit artifacts.
|
|
104
|
+
*/
|
|
105
|
+
export interface Binaries {
|
|
106
|
+
commitment: CircuitArtifacts;
|
|
107
|
+
withdraw: CircuitArtifacts;
|
|
108
|
+
merkleTree?: CircuitArtifacts;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Interface defining the methods required for managing circuits and their artifacts.
|
|
113
|
+
*/
|
|
114
|
+
export interface CircuitsInterface {
|
|
115
|
+
/**
|
|
116
|
+
* Downloads all artifacts for the specified version of circuits.
|
|
117
|
+
* @param {VersionString} version - The version of the artifacts to download.
|
|
118
|
+
* @returns {Promise<Binaries>} A promise that resolves to the binaries containing all circuit artifacts.
|
|
119
|
+
* @async
|
|
120
|
+
*/
|
|
121
|
+
downloadArtifacts(version: VersionString): Promise<Binaries>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Initializes the artifacts for the specified version of circuits.
|
|
125
|
+
* @param {VersionString} version - The version of the artifacts to initialize.
|
|
126
|
+
* @returns {Promise<void>} A promise that resolves when initialization is complete.
|
|
127
|
+
* @async
|
|
128
|
+
*/
|
|
129
|
+
initArtifacts(version: VersionString): Promise<void>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Retrieves the verification key for a specified circuit.
|
|
133
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
134
|
+
* @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
|
|
135
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the verification key.
|
|
136
|
+
* @async
|
|
137
|
+
*/
|
|
138
|
+
getVerificationKey(
|
|
139
|
+
circuitName: CircuitNameString,
|
|
140
|
+
version?: VersionString,
|
|
141
|
+
): Promise<Uint8Array>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves the proving key for a specified circuit.
|
|
145
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
146
|
+
* @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
|
|
147
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the proving key.
|
|
148
|
+
* @async
|
|
149
|
+
*/
|
|
150
|
+
getProvingKey(
|
|
151
|
+
circuitName: CircuitNameString,
|
|
152
|
+
version?: VersionString,
|
|
153
|
+
): Promise<Uint8Array>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves the wasm file for a specified circuit.
|
|
157
|
+
* @param {CircuitNameString} circuitName - The name of the circuit.
|
|
158
|
+
* @param {VersionString} [version] - The version of the artifacts (defaults to the latest).
|
|
159
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the wasm file.
|
|
160
|
+
* @async
|
|
161
|
+
*/
|
|
162
|
+
getWasm(
|
|
163
|
+
circuitName: CircuitNameString,
|
|
164
|
+
version?: VersionString,
|
|
165
|
+
): Promise<Uint8Array>;
|
|
166
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FetchArtifact } from "../exceptions/fetchArtifacts.exception.js";
|
|
2
|
+
|
|
3
|
+
export async function fetchVersionedArtifact(
|
|
4
|
+
artifactUrl: URL,
|
|
5
|
+
): Promise<Uint8Array> {
|
|
6
|
+
const res = await fetch(artifactUrl);
|
|
7
|
+
if (res.status !== 200) {
|
|
8
|
+
throw new FetchArtifact(artifactUrl);
|
|
9
|
+
}
|
|
10
|
+
const aBuf = await res.arrayBuffer();
|
|
11
|
+
return new Uint8Array(aBuf);
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FetchArtifact } from "../exceptions/fetchArtifacts.exception.js";
|
|
2
|
+
|
|
3
|
+
export async function fetchVersionedArtifact(
|
|
4
|
+
artifactUrl: URL,
|
|
5
|
+
): Promise<Uint8Array> {
|
|
6
|
+
try {
|
|
7
|
+
const fs = (await import("fs")).default;
|
|
8
|
+
const readPromise: Promise<Buffer> = new Promise((resolve, reject) => {
|
|
9
|
+
fs.readFile(artifactUrl.pathname, (err, data) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
reject(err);
|
|
12
|
+
} else {
|
|
13
|
+
resolve(data);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
const buf = await readPromise;
|
|
18
|
+
return new Uint8Array(buf);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(error);
|
|
21
|
+
throw new FetchArtifact(artifactUrl);
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/constants.ts
ADDED