@reclaimprotocol/attestor-core 5.0.1-beta.10 → 5.0.1-beta.12

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.
@@ -0,0 +1,50 @@
1
+ const DEFAULT_REMOTE_BASE_URL = "https://github.com/reclaimprotocol/zk-symmetric-crypto/raw/main/resources/";
2
+ function makeRemoteFileFetch({
3
+ baseUrl = DEFAULT_REMOTE_BASE_URL,
4
+ maxRetries = 3,
5
+ logger
6
+ } = {}) {
7
+ return {
8
+ async fetch(engine, filename) {
9
+ const url = `${baseUrl}/${engine}/${filename}`;
10
+ let lastError;
11
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
12
+ try {
13
+ const res = await fetch(url);
14
+ if (!res.ok) {
15
+ throw new Error(
16
+ `${engine}-${filename} fetch failed with code: ${res.status}`
17
+ );
18
+ }
19
+ const arr = await res.arrayBuffer();
20
+ return new Uint8Array(arr);
21
+ } catch (err) {
22
+ logger?.warn?.(
23
+ { err, attempt, engine, filename },
24
+ "failed to fetch zk resource"
25
+ );
26
+ lastError = err;
27
+ if (attempt < maxRetries) {
28
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * attempt));
29
+ }
30
+ }
31
+ }
32
+ throw lastError || new Error(
33
+ `Failed to fetch ${engine}-${filename} after ${maxRetries} attempts`
34
+ );
35
+ }
36
+ };
37
+ }
38
+ function makeLocalFileFetch(_opts) {
39
+ return {
40
+ async fetch() {
41
+ throw new Error(
42
+ "makeLocalFileFetch is not available in browser. Use makeRemoteFileFetch instead."
43
+ );
44
+ }
45
+ };
46
+ }
47
+ export {
48
+ makeLocalFileFetch,
49
+ makeRemoteFileFetch
50
+ };
@@ -1,11 +1,12 @@
1
1
  import { concatenateUint8Arrays, crypto, generateIV } from "../utils/tls-imports.js";
2
+ import { makeLocalFileFetch, makeRemoteFileFetch } from "../scripts/fallbacks/zk-file-fetch.js";
2
3
  import {
3
4
  ceilToBlockSizeMultiple,
4
5
  CONFIG as ZK_CONFIG,
5
6
  generateProof,
6
7
  getBlockSizeBytes,
7
- makeLocalFileFetch,
8
- makeRemoteFileFetch,
8
+
9
+
9
10
  verifyProof
10
11
  } from "@reclaimprotocol/zk-symmetric-crypto";
11
12
  import { makeGnarkOPRFOperator, makeGnarkZkOperator } from "../scripts/fallbacks/gnark.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Browser fallback for zk-symmetric-crypto file-fetch
3
+ * - makeRemoteFileFetch works in browser (uses fetch API)
4
+ * - makeLocalFileFetch throws since fs/promises is not available
5
+ */
6
+ import type { FileFetch, Logger } from '@reclaimprotocol/zk-symmetric-crypto';
7
+ export type MakeRemoteFileFetchOpts = {
8
+ baseUrl?: string;
9
+ maxRetries?: number;
10
+ logger?: Logger;
11
+ };
12
+ export type MakeLocalFileFetchOpts = {
13
+ basePath?: string;
14
+ };
15
+ /**
16
+ * Fetches ZK resources from a remote server.
17
+ * Works in browser using the fetch API.
18
+ */
19
+ export declare function makeRemoteFileFetch({ baseUrl, maxRetries, logger }?: MakeRemoteFileFetchOpts): FileFetch;
20
+ /**
21
+ * Browser fallback - throws since filesystem is not available in browser.
22
+ * Use makeRemoteFileFetch instead.
23
+ */
24
+ export declare function makeLocalFileFetch(_opts?: MakeLocalFileFetchOpts): FileFetch;
@@ -0,0 +1,50 @@
1
+ const DEFAULT_REMOTE_BASE_URL = "https://github.com/reclaimprotocol/zk-symmetric-crypto/raw/main/resources/";
2
+ function makeRemoteFileFetch({
3
+ baseUrl = DEFAULT_REMOTE_BASE_URL,
4
+ maxRetries = 3,
5
+ logger
6
+ } = {}) {
7
+ return {
8
+ async fetch(engine, filename) {
9
+ const url = `${baseUrl}/${engine}/${filename}`;
10
+ let lastError;
11
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
12
+ try {
13
+ const res = await fetch(url);
14
+ if (!res.ok) {
15
+ throw new Error(
16
+ `${engine}-${filename} fetch failed with code: ${res.status}`
17
+ );
18
+ }
19
+ const arr = await res.arrayBuffer();
20
+ return new Uint8Array(arr);
21
+ } catch (err) {
22
+ logger?.warn?.(
23
+ { err, attempt, engine, filename },
24
+ "failed to fetch zk resource"
25
+ );
26
+ lastError = err;
27
+ if (attempt < maxRetries) {
28
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * attempt));
29
+ }
30
+ }
31
+ }
32
+ throw lastError || new Error(
33
+ `Failed to fetch ${engine}-${filename} after ${maxRetries} attempts`
34
+ );
35
+ }
36
+ };
37
+ }
38
+ function makeLocalFileFetch(_opts) {
39
+ return {
40
+ async fetch() {
41
+ throw new Error(
42
+ "makeLocalFileFetch is not available in browser. Use makeRemoteFileFetch instead."
43
+ );
44
+ }
45
+ };
46
+ }
47
+ export {
48
+ makeLocalFileFetch,
49
+ makeRemoteFileFetch
50
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reclaimprotocol/attestor-core",
3
- "version": "5.0.1-beta.10",
3
+ "version": "5.0.1-beta.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",