@aztec/bb.js 0.0.1-commit.ee80a48 → 0.0.1-commit.f1df4d2

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.
Files changed (32) hide show
  1. package/build/amd64-linux/bb +0 -0
  2. package/build/amd64-macos/bb +0 -0
  3. package/build/amd64-macos/nodejs_module.node +0 -0
  4. package/build/arm64-linux/bb +0 -0
  5. package/build/arm64-macos/bb +0 -0
  6. package/build/arm64-macos/nodejs_module.node +0 -0
  7. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +1 -1
  8. package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.js +1 -1
  9. package/dest/browser/crs/net_crs.d.ts +6 -1
  10. package/dest/browser/crs/net_crs.d.ts.map +1 -1
  11. package/dest/browser/crs/net_crs.js +30 -7
  12. package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  13. package/dest/node/crs/net_crs.d.ts +6 -1
  14. package/dest/node/crs/net_crs.d.ts.map +1 -1
  15. package/dest/node/crs/net_crs.js +30 -7
  16. package/dest/node/crs/net_crs.test.d.ts +2 -0
  17. package/dest/node/crs/net_crs.test.d.ts.map +1 -0
  18. package/dest/node/crs/net_crs.test.js +39 -0
  19. package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
  20. package/dest/node-cjs/crs/net_crs.d.ts +6 -1
  21. package/dest/node-cjs/crs/net_crs.d.ts.map +1 -1
  22. package/dest/node-cjs/crs/net_crs.js +31 -7
  23. package/dest/node-cjs/crs/net_crs.test.d.ts +2 -0
  24. package/dest/node-cjs/crs/net_crs.test.d.ts.map +1 -0
  25. package/dest/node-cjs/crs/net_crs.test.js +41 -0
  26. package/package.json +1 -1
  27. package/src/cbind/generated/api_types.ts +3050 -0
  28. package/src/cbind/generated/async.ts +696 -0
  29. package/src/cbind/generated/curve_constants.ts +53 -0
  30. package/src/cbind/generated/sync.ts +644 -0
  31. package/src/crs/net_crs.test.ts +47 -0
  32. package/src/crs/net_crs.ts +45 -14
@@ -0,0 +1,47 @@
1
+ import { NetCrs, fetchWithFallback } from './net_crs.js';
2
+
3
+ // Expected first G1 point from BN254 CRS (generator point with x=1, y=2 in big-endian)
4
+ const BN254_G1_FIRST_ELEMENT = new Uint8Array([
5
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
6
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
7
+ ]);
8
+
9
+ describe('NetCrs', () => {
10
+ it('should download CRS data from primary host', async () => {
11
+ const crs = new NetCrs(1);
12
+ await crs.init();
13
+
14
+ const g1Data = crs.getG1Data();
15
+ expect(g1Data.length).toBe(64); // 1 point * 64 bytes
16
+
17
+ // Verify first point matches expected generator
18
+ expect(g1Data).toEqual(BN254_G1_FIRST_ELEMENT);
19
+ }, 30000);
20
+
21
+ it('should download G2 data', async () => {
22
+ const crs = new NetCrs(1);
23
+ await crs.init();
24
+
25
+ const g2Data = crs.getG2Data();
26
+ expect(g2Data.length).toBe(128); // G2 point is 128 bytes
27
+ }, 30000);
28
+ });
29
+
30
+ describe('fetchWithFallback', () => {
31
+ it('should fallback to secondary URL when primary fails', async () => {
32
+ const badPrimaryUrl = 'https://nonexistent.invalid/g1.dat';
33
+ const goodFallbackUrl = 'https://crs.aztec-labs.com/g1.dat';
34
+ const options: RequestInit = {
35
+ headers: {
36
+ Range: 'bytes=0-63',
37
+ },
38
+ };
39
+
40
+ const response = await fetchWithFallback(badPrimaryUrl, goodFallbackUrl, options);
41
+ expect(response.ok || response.status === 206).toBe(true);
42
+
43
+ const data = new Uint8Array(await response.arrayBuffer());
44
+ expect(data.length).toBe(64);
45
+ expect(data).toEqual(BN254_G1_FIRST_ELEMENT);
46
+ }, 30000);
47
+ });
@@ -1,4 +1,30 @@
1
1
  import { retry, makeBackoff } from '../retry/index.js';
2
+
3
+ // Primary CRS host (Cloudflare R2)
4
+ const CRS_PRIMARY_HOST = 'https://crs.aztec-cdn.foundation';
5
+ // Fallback CRS host (AWS S3)
6
+ const CRS_FALLBACK_HOST = 'https://crs.aztec-labs.com';
7
+
8
+ /**
9
+ * Fetches data from primary URL, falling back to secondary on failure
10
+ * @internal Exported for testing
11
+ */
12
+ export async function fetchWithFallback(
13
+ primaryUrl: string,
14
+ fallbackUrl: string,
15
+ options: RequestInit,
16
+ ): Promise<Response> {
17
+ try {
18
+ const response = await fetch(primaryUrl, options);
19
+ if (response.ok || response.status === 206) {
20
+ return response;
21
+ }
22
+ throw new Error(`HTTP ${response.status}`);
23
+ } catch {
24
+ return await fetch(fallbackUrl, options);
25
+ }
26
+ }
27
+
2
28
  /**
3
29
  * Downloader for CRS from the web or local.
4
30
  */
@@ -76,14 +102,14 @@ export class NetCrs {
76
102
  }
77
103
 
78
104
  const g1End = this.numPoints * 64 - 1;
105
+ const options: RequestInit = {
106
+ headers: {
107
+ Range: `bytes=0-${g1End}`,
108
+ },
109
+ cache: 'force-cache',
110
+ };
79
111
  return await retry(
80
- () =>
81
- fetch('https://crs.aztec.network/g1.dat', {
82
- headers: {
83
- Range: `bytes=0-${g1End}`,
84
- },
85
- cache: 'force-cache',
86
- }),
112
+ () => fetchWithFallback(`${CRS_PRIMARY_HOST}/g1.dat`, `${CRS_FALLBACK_HOST}/g1.dat`, options),
87
113
  makeBackoff([5, 5, 5]),
88
114
  );
89
115
  }
@@ -92,11 +118,11 @@ export class NetCrs {
92
118
  * Fetches the appropriate range of points from a remote source
93
119
  */
94
120
  private async fetchG2Data(): Promise<Response> {
121
+ const options: RequestInit = {
122
+ cache: 'force-cache',
123
+ };
95
124
  return await retry(
96
- () =>
97
- fetch('https://crs.aztec.network/g2.dat', {
98
- cache: 'force-cache',
99
- }),
125
+ () => fetchWithFallback(`${CRS_PRIMARY_HOST}/g2.dat`, `${CRS_FALLBACK_HOST}/g2.dat`, options),
100
126
  makeBackoff([5, 5, 5]),
101
127
  );
102
128
  }
@@ -153,12 +179,17 @@ export class NetGrumpkinCrs {
153
179
  }
154
180
 
155
181
  const g1End = this.numPoints * 64 - 1;
156
-
157
- return await fetch('https://crs.aztec.network/grumpkin_g1.dat', {
182
+ const options: RequestInit = {
158
183
  headers: {
159
184
  Range: `bytes=0-${g1End}`,
160
185
  },
161
186
  cache: 'force-cache',
162
- });
187
+ };
188
+
189
+ return await fetchWithFallback(
190
+ `${CRS_PRIMARY_HOST}/grumpkin_g1.dat`,
191
+ `${CRS_FALLBACK_HOST}/grumpkin_g1.dat`,
192
+ options,
193
+ );
163
194
  }
164
195
  }