@aztec/bb.js 0.73.0-commit.117882ca3ed35a6df177e74f0b3d2f3e7c512184 → 0.74.0
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 +0 -10
- package/dest/browser/barretenberg/index.d.ts.map +1 -1
- package/dest/browser/barretenberg-threads.wasm.gz +0 -0
- package/dest/browser/barretenberg.wasm.gz +0 -0
- package/dest/browser/barretenberg_wasm/index.d.ts.map +1 -1
- package/dest/browser/crs/net_crs.d.ts.map +1 -1
- package/dest/browser/index.js +22 -76
- package/dest/node/barretenberg/index.d.ts.map +1 -1
- package/dest/node/barretenberg/index.js +4 -3
- package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
- package/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -5
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js +2 -2
- package/dest/node/barretenberg_wasm/index.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/index.js +4 -7
- package/dest/node/barretenberg_wasm/index.test.js +3 -3
- package/dest/node/crs/net_crs.d.ts.map +1 -1
- package/dest/node/crs/net_crs.js +5 -6
- package/dest/node/main.d.ts.map +1 -1
- package/dest/node/main.js +9 -9
- package/dest/node-cjs/barretenberg/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg/index.js +4 -3
- package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -5
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.js +2 -2
- package/dest/node-cjs/barretenberg_wasm/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/index.js +4 -7
- package/dest/node-cjs/barretenberg_wasm/index.test.js +3 -3
- package/dest/node-cjs/crs/net_crs.d.ts.map +1 -1
- package/dest/node-cjs/crs/net_crs.js +5 -6
- package/dest/node-cjs/main.d.ts.map +1 -1
- package/dest/node-cjs/main.js +9 -9
- package/package.json +3 -5
- package/src/barretenberg/index.ts +4 -8
- package/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +4 -4
- package/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +1 -1
- package/src/barretenberg_wasm/index.test.ts +2 -2
- package/src/barretenberg_wasm/index.ts +3 -6
- package/src/crs/net_crs.ts +9 -18
- package/src/crs/node/index.ts +1 -3
- package/src/main.ts +10 -13
- package/dest/browser/retry/index.d.ts +0 -26
- package/dest/browser/retry/index.d.ts.map +0 -1
- package/dest/node/barretenberg/__snapshots__/pedersen.test.js.snap +0 -156
- package/dest/node/barretenberg/__snapshots__/poseidon.test.js.snap +0 -40
- package/dest/node/retry/index.d.ts +0 -26
- package/dest/node/retry/index.d.ts.map +0 -1
- package/dest/node/retry/index.js +0 -50
- package/dest/node-cjs/retry/index.d.ts +0 -26
- package/dest/node-cjs/retry/index.d.ts.map +0 -1
- package/dest/node-cjs/retry/index.js +0 -56
- package/src/retry/index.ts +0 -50
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import createDebug from 'debug';
|
|
2
2
|
import { randomBytes } from '../../random/index.js';
|
|
3
3
|
|
|
4
|
-
const debug = createDebug('bb.js:
|
|
4
|
+
const debug = createDebug('bb.js:wasm');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Base implementation of BarretenbergWasm.
|
|
@@ -51,9 +51,9 @@ export class BarretenbergWasmBase {
|
|
|
51
51
|
const m = this.getMemory();
|
|
52
52
|
const str2 = `${str} (mem: ${(m.length / (1024 * 1024)).toFixed(2)}MiB)`;
|
|
53
53
|
this.logger(str2);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (str2.startsWith('WARNING:')) {
|
|
55
|
+
this.logger(new Error().stack!);
|
|
56
|
+
}
|
|
57
57
|
},
|
|
58
58
|
|
|
59
59
|
get_data: (keyAddr: number, outBufAddr: number) => {
|
|
@@ -7,7 +7,7 @@ import { type BarretenbergWasmThreadWorker } from '../barretenberg_wasm_thread/i
|
|
|
7
7
|
import { BarretenbergWasmBase } from '../barretenberg_wasm_base/index.js';
|
|
8
8
|
import { HeapAllocator } from './heap_allocator.js';
|
|
9
9
|
|
|
10
|
-
const debug = createDebug('bb.js:
|
|
10
|
+
const debug = createDebug('bb.js:wasm');
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* This is the "main thread" implementation of BarretenbergWasm.
|
|
@@ -18,7 +18,7 @@ describe('barretenberg wasm', () => {
|
|
|
18
18
|
const length = 1024;
|
|
19
19
|
const ptr = await wasm.call('bbmalloc', length);
|
|
20
20
|
const buf = Buffer.alloc(length, 128);
|
|
21
|
-
await wasm.writeMemory(ptr,
|
|
21
|
+
await wasm.writeMemory(ptr, buf);
|
|
22
22
|
const result = Buffer.from(await wasm.getMemorySlice(ptr, ptr + length));
|
|
23
23
|
await wasm.call('bbfree', ptr);
|
|
24
24
|
expect(result).toStrictEqual(buf);
|
|
@@ -37,7 +37,7 @@ describe('barretenberg wasm', () => {
|
|
|
37
37
|
const length = 1024;
|
|
38
38
|
const ptr = await wasm.call('bbmalloc', length);
|
|
39
39
|
const buf = Buffer.alloc(length, 128);
|
|
40
|
-
await wasm.writeMemory(ptr,
|
|
40
|
+
await wasm.writeMemory(ptr, buf);
|
|
41
41
|
const result = Buffer.from(await wasm.getMemorySlice(ptr, ptr + length));
|
|
42
42
|
await wasm.call('bbfree', ptr);
|
|
43
43
|
expect(result).toStrictEqual(buf);
|
|
@@ -5,7 +5,7 @@ import { getRemoteBarretenbergWasm, getSharedMemoryAvailable } from './helpers/n
|
|
|
5
5
|
import { BarretenbergWasmMain, BarretenbergWasmMainWorker } from './barretenberg_wasm_main/index.js';
|
|
6
6
|
import { fetchCode } from './fetch_code/index.js';
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const debug = createDebug('bb.js:wasm');
|
|
9
9
|
|
|
10
10
|
export async function fetchModuleAndThreads(desiredThreads = 32, wasmPath?: string) {
|
|
11
11
|
const shared = getSharedMemoryAvailable();
|
|
@@ -14,11 +14,8 @@ export async function fetchModuleAndThreads(desiredThreads = 32, wasmPath?: stri
|
|
|
14
14
|
// We limit the number of threads to 32 as we do not benefit from greater numbers.
|
|
15
15
|
const limitedThreads = Math.min(desiredThreads, availableThreads, 32);
|
|
16
16
|
|
|
17
|
-
fetchDebug('Fetching wasm...');
|
|
18
17
|
const code = await fetchCode(shared, wasmPath);
|
|
19
|
-
fetchDebug(`Compiling wasm of ${code.byteLength} bytes...`);
|
|
20
18
|
const module = await WebAssembly.compile(code);
|
|
21
|
-
fetchDebug('Done.');
|
|
22
19
|
return { module, threads: limitedThreads };
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -30,7 +27,7 @@ async function getAvailableThreads(): Promise<number> {
|
|
|
30
27
|
const os = await import('os');
|
|
31
28
|
return os.cpus().length;
|
|
32
29
|
} catch (e) {
|
|
33
|
-
|
|
30
|
+
debug(`Could not detect environment. Falling back to one thread.: {e}`);
|
|
34
31
|
return 1;
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -45,7 +42,7 @@ export class BarretenbergWasm extends BarretenbergWasmMain {
|
|
|
45
42
|
const worker = createMainWorker();
|
|
46
43
|
const wasm = getRemoteBarretenbergWasm<BarretenbergWasmMainWorker>(worker);
|
|
47
44
|
const { module, threads } = await fetchModuleAndThreads(desiredThreads, wasmPath);
|
|
48
|
-
await wasm.init(module, threads, proxy(
|
|
45
|
+
await wasm.init(module, threads, proxy(debug));
|
|
49
46
|
return { worker, wasm };
|
|
50
47
|
}
|
|
51
48
|
}
|
package/src/crs/net_crs.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { retry, makeBackoff } from '../retry/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* Downloader for CRS from the web or local.
|
|
4
3
|
*/
|
|
@@ -29,16 +28,12 @@ export class NetCrs {
|
|
|
29
28
|
|
|
30
29
|
const g1End = this.numPoints * 64 - 1;
|
|
31
30
|
|
|
32
|
-
const response = await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
cache: 'force-cache',
|
|
39
|
-
}),
|
|
40
|
-
makeBackoff([5, 5, 5]),
|
|
41
|
-
);
|
|
31
|
+
const response = await fetch('https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/flat/g1.dat', {
|
|
32
|
+
headers: {
|
|
33
|
+
Range: `bytes=0-${g1End}`,
|
|
34
|
+
},
|
|
35
|
+
cache: 'force-cache',
|
|
36
|
+
});
|
|
42
37
|
|
|
43
38
|
return (this.data = new Uint8Array(await response.arrayBuffer()));
|
|
44
39
|
}
|
|
@@ -47,13 +42,9 @@ export class NetCrs {
|
|
|
47
42
|
* Download the G2 points data.
|
|
48
43
|
*/
|
|
49
44
|
async downloadG2Data() {
|
|
50
|
-
const response2 = await
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
cache: 'force-cache',
|
|
54
|
-
}),
|
|
55
|
-
makeBackoff([5, 5, 5]),
|
|
56
|
-
);
|
|
45
|
+
const response2 = await fetch('https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/flat/g2.dat', {
|
|
46
|
+
cache: 'force-cache',
|
|
47
|
+
});
|
|
57
48
|
|
|
58
49
|
return (this.g2Data = new Uint8Array(await response2.arrayBuffer()));
|
|
59
50
|
}
|
package/src/crs/node/index.ts
CHANGED
|
@@ -45,9 +45,7 @@ export class Crs {
|
|
|
45
45
|
* @returns The points data.
|
|
46
46
|
*/
|
|
47
47
|
getG1Data(): Uint8Array {
|
|
48
|
-
|
|
49
|
-
// This is a backup.
|
|
50
|
-
const length = Math.max(this.numPoints, 1) * 64;
|
|
48
|
+
const length = this.numPoints * 64;
|
|
51
49
|
const fd = openSync(this.path + '/bn254_g1.dat', 'r');
|
|
52
50
|
const buffer = new Uint8Array(length);
|
|
53
51
|
readSync(fd, buffer, 0, length, 0);
|
package/src/main.ts
CHANGED
|
@@ -22,18 +22,18 @@ const debug = createDebug('bb.js');
|
|
|
22
22
|
const MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM = 2 ** 19;
|
|
23
23
|
const threads = +process.env.HARDWARE_CONCURRENCY! || undefined;
|
|
24
24
|
|
|
25
|
-
function getBytecode(bytecodePath: string)
|
|
25
|
+
function getBytecode(bytecodePath: string) {
|
|
26
26
|
const extension = bytecodePath.substring(bytecodePath.lastIndexOf('.') + 1);
|
|
27
27
|
|
|
28
28
|
if (extension == 'json') {
|
|
29
29
|
const encodedCircuit = JSON.parse(readFileSync(bytecodePath, 'utf8'));
|
|
30
30
|
const decompressed = gunzipSync(Buffer.from(encodedCircuit.bytecode, 'base64'));
|
|
31
|
-
return
|
|
31
|
+
return decompressed;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const encodedCircuit = readFileSync(bytecodePath);
|
|
35
35
|
const decompressed = gunzipSync(encodedCircuit);
|
|
36
|
-
return
|
|
36
|
+
return decompressed;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function base64ToUint8Array(base64: string) {
|
|
@@ -62,10 +62,10 @@ async function getGatesUltra(bytecodePath: string, recursive: boolean, honkRecur
|
|
|
62
62
|
return total;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function getWitness(witnessPath: string)
|
|
65
|
+
function getWitness(witnessPath: string) {
|
|
66
66
|
const data = readFileSync(witnessPath);
|
|
67
67
|
const decompressed = gunzipSync(data);
|
|
68
|
-
return
|
|
68
|
+
return decompressed;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async function computeCircuitSize(bytecodePath: string, recursive: boolean, honkRecursion: boolean, api: Barretenberg) {
|
|
@@ -300,7 +300,7 @@ export async function gateCountUltra(bytecodePath: string, recursive: boolean, h
|
|
|
300
300
|
const buffer = Buffer.alloc(8);
|
|
301
301
|
buffer.writeBigInt64LE(BigInt(numberOfGates));
|
|
302
302
|
|
|
303
|
-
process.stdout.write(
|
|
303
|
+
process.stdout.write(buffer);
|
|
304
304
|
} finally {
|
|
305
305
|
await api.destroy();
|
|
306
306
|
}
|
|
@@ -310,7 +310,7 @@ export async function verify(proofPath: string, vkPath: string, crsPath: string)
|
|
|
310
310
|
const { api, acirComposer } = await initLite(crsPath);
|
|
311
311
|
try {
|
|
312
312
|
await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
|
|
313
|
-
const verified = await api.acirVerifyProof(acirComposer,
|
|
313
|
+
const verified = await api.acirVerifyProof(acirComposer, readFileSync(proofPath));
|
|
314
314
|
debug(`verified: ${verified}`);
|
|
315
315
|
return verified;
|
|
316
316
|
} finally {
|
|
@@ -406,7 +406,7 @@ export async function proofAsFields(proofPath: string, vkPath: string, outputPat
|
|
|
406
406
|
const numPublicInputs = readFileSync(vkPath).readUint32BE(8);
|
|
407
407
|
const proofAsFields = await api.acirSerializeProofIntoFields(
|
|
408
408
|
acirComposer,
|
|
409
|
-
|
|
409
|
+
readFileSync(proofPath),
|
|
410
410
|
numPublicInputs,
|
|
411
411
|
);
|
|
412
412
|
const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
|
|
@@ -521,10 +521,7 @@ export async function verifyUltraHonk(
|
|
|
521
521
|
const acirVerifyUltraHonk = options?.keccak
|
|
522
522
|
? api.acirVerifyUltraKeccakHonk.bind(api)
|
|
523
523
|
: api.acirVerifyUltraHonk.bind(api);
|
|
524
|
-
const verified = await acirVerifyUltraHonk(
|
|
525
|
-
Uint8Array.from(readFileSync(proofPath)),
|
|
526
|
-
new RawBuffer(readFileSync(vkPath)),
|
|
527
|
-
);
|
|
524
|
+
const verified = await acirVerifyUltraHonk(readFileSync(proofPath), new RawBuffer(readFileSync(vkPath)));
|
|
528
525
|
|
|
529
526
|
debug(`verified: ${verified}`);
|
|
530
527
|
return verified;
|
|
@@ -537,7 +534,7 @@ export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: stri
|
|
|
537
534
|
const { api } = await initLite(crsPath);
|
|
538
535
|
try {
|
|
539
536
|
debug('outputting proof as vector of fields');
|
|
540
|
-
const proofAsFields = await api.acirProofAsFieldsUltraHonk(
|
|
537
|
+
const proofAsFields = await api.acirProofAsFieldsUltraHonk(readFileSync(proofPath));
|
|
541
538
|
const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
|
|
542
539
|
|
|
543
540
|
if (outputPath === '-') {
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a backoff sequence for retrying operations with an increasing delay.
|
|
3
|
-
* The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
|
|
4
|
-
* This generator can be used in combination with the `retry` function to perform
|
|
5
|
-
* retries with exponential backoff and capped at 64 seconds between attempts.
|
|
6
|
-
*
|
|
7
|
-
* @returns A generator that yields the next backoff value in seconds as an integer.
|
|
8
|
-
*/
|
|
9
|
-
export declare function backoffGenerator(): Generator<number, void, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
|
|
12
|
-
* @param retries - Intervals to retry (in seconds).
|
|
13
|
-
* @returns A generator sequence.
|
|
14
|
-
*/
|
|
15
|
-
export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
|
|
16
|
-
/**
|
|
17
|
-
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
|
|
18
|
-
* It logs the error and retry interval in case an error is caught. The function can be named for better log output.
|
|
19
|
-
*
|
|
20
|
-
* @param fn - The asynchronous function to be retried.
|
|
21
|
-
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
|
|
22
|
-
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
23
|
-
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
24
|
-
*/
|
|
25
|
-
export declare function retry<Result>(fn: () => Promise<Result>, backoff?: Generator<number, void, unknown>): Promise<Result>;
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,mCAAqB,mBAa1F"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`pedersen sync pedersenCommit 1`] = `
|
|
4
|
-
Point {
|
|
5
|
-
"x": Fr {
|
|
6
|
-
"value": Uint8Array [
|
|
7
|
-
40,
|
|
8
|
-
159,
|
|
9
|
-
125,
|
|
10
|
-
144,
|
|
11
|
-
234,
|
|
12
|
-
153,
|
|
13
|
-
219,
|
|
14
|
-
166,
|
|
15
|
-
76,
|
|
16
|
-
75,
|
|
17
|
-
47,
|
|
18
|
-
51,
|
|
19
|
-
253,
|
|
20
|
-
27,
|
|
21
|
-
9,
|
|
22
|
-
101,
|
|
23
|
-
2,
|
|
24
|
-
145,
|
|
25
|
-
223,
|
|
26
|
-
38,
|
|
27
|
-
43,
|
|
28
|
-
114,
|
|
29
|
-
5,
|
|
30
|
-
21,
|
|
31
|
-
90,
|
|
32
|
-
97,
|
|
33
|
-
2,
|
|
34
|
-
6,
|
|
35
|
-
219,
|
|
36
|
-
97,
|
|
37
|
-
109,
|
|
38
|
-
152,
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
"y": Fr {
|
|
42
|
-
"value": Uint8Array [
|
|
43
|
-
5,
|
|
44
|
-
175,
|
|
45
|
-
199,
|
|
46
|
-
200,
|
|
47
|
-
35,
|
|
48
|
-
67,
|
|
49
|
-
88,
|
|
50
|
-
76,
|
|
51
|
-
19,
|
|
52
|
-
203,
|
|
53
|
-
45,
|
|
54
|
-
50,
|
|
55
|
-
137,
|
|
56
|
-
153,
|
|
57
|
-
67,
|
|
58
|
-
200,
|
|
59
|
-
57,
|
|
60
|
-
87,
|
|
61
|
-
22,
|
|
62
|
-
209,
|
|
63
|
-
141,
|
|
64
|
-
173,
|
|
65
|
-
205,
|
|
66
|
-
189,
|
|
67
|
-
23,
|
|
68
|
-
215,
|
|
69
|
-
206,
|
|
70
|
-
3,
|
|
71
|
-
174,
|
|
72
|
-
112,
|
|
73
|
-
128,
|
|
74
|
-
11,
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
exports[`pedersen sync pedersenHash 1`] = `
|
|
81
|
-
Fr {
|
|
82
|
-
"value": Uint8Array [
|
|
83
|
-
4,
|
|
84
|
-
194,
|
|
85
|
-
53,
|
|
86
|
-
42,
|
|
87
|
-
6,
|
|
88
|
-
13,
|
|
89
|
-
74,
|
|
90
|
-
193,
|
|
91
|
-
205,
|
|
92
|
-
251,
|
|
93
|
-
96,
|
|
94
|
-
62,
|
|
95
|
-
188,
|
|
96
|
-
67,
|
|
97
|
-
39,
|
|
98
|
-
181,
|
|
99
|
-
118,
|
|
100
|
-
69,
|
|
101
|
-
151,
|
|
102
|
-
35,
|
|
103
|
-
22,
|
|
104
|
-
20,
|
|
105
|
-
246,
|
|
106
|
-
29,
|
|
107
|
-
36,
|
|
108
|
-
91,
|
|
109
|
-
243,
|
|
110
|
-
87,
|
|
111
|
-
114,
|
|
112
|
-
192,
|
|
113
|
-
134,
|
|
114
|
-
150,
|
|
115
|
-
],
|
|
116
|
-
}
|
|
117
|
-
`;
|
|
118
|
-
|
|
119
|
-
exports[`pedersen sync pedersenHashBuffer 1`] = `
|
|
120
|
-
Fr {
|
|
121
|
-
"value": Uint8Array [
|
|
122
|
-
43,
|
|
123
|
-
213,
|
|
124
|
-
196,
|
|
125
|
-
82,
|
|
126
|
-
160,
|
|
127
|
-
201,
|
|
128
|
-
113,
|
|
129
|
-
98,
|
|
130
|
-
41,
|
|
131
|
-
79,
|
|
132
|
-
201,
|
|
133
|
-
223,
|
|
134
|
-
208,
|
|
135
|
-
241,
|
|
136
|
-
224,
|
|
137
|
-
157,
|
|
138
|
-
14,
|
|
139
|
-
9,
|
|
140
|
-
201,
|
|
141
|
-
95,
|
|
142
|
-
165,
|
|
143
|
-
237,
|
|
144
|
-
63,
|
|
145
|
-
241,
|
|
146
|
-
73,
|
|
147
|
-
251,
|
|
148
|
-
222,
|
|
149
|
-
243,
|
|
150
|
-
102,
|
|
151
|
-
203,
|
|
152
|
-
81,
|
|
153
|
-
249,
|
|
154
|
-
],
|
|
155
|
-
}
|
|
156
|
-
`;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`poseidon sync poseidonHash 1`] = `
|
|
4
|
-
Fr {
|
|
5
|
-
"value": Uint8Array [
|
|
6
|
-
43,
|
|
7
|
-
202,
|
|
8
|
-
235,
|
|
9
|
-
109,
|
|
10
|
-
88,
|
|
11
|
-
187,
|
|
12
|
-
56,
|
|
13
|
-
186,
|
|
14
|
-
247,
|
|
15
|
-
83,
|
|
16
|
-
213,
|
|
17
|
-
140,
|
|
18
|
-
60,
|
|
19
|
-
150,
|
|
20
|
-
97,
|
|
21
|
-
143,
|
|
22
|
-
234,
|
|
23
|
-
130,
|
|
24
|
-
22,
|
|
25
|
-
51,
|
|
26
|
-
69,
|
|
27
|
-
41,
|
|
28
|
-
94,
|
|
29
|
-
180,
|
|
30
|
-
14,
|
|
31
|
-
136,
|
|
32
|
-
52,
|
|
33
|
-
78,
|
|
34
|
-
235,
|
|
35
|
-
12,
|
|
36
|
-
226,
|
|
37
|
-
161,
|
|
38
|
-
],
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a backoff sequence for retrying operations with an increasing delay.
|
|
3
|
-
* The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
|
|
4
|
-
* This generator can be used in combination with the `retry` function to perform
|
|
5
|
-
* retries with exponential backoff and capped at 64 seconds between attempts.
|
|
6
|
-
*
|
|
7
|
-
* @returns A generator that yields the next backoff value in seconds as an integer.
|
|
8
|
-
*/
|
|
9
|
-
export declare function backoffGenerator(): Generator<number, void, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
|
|
12
|
-
* @param retries - Intervals to retry (in seconds).
|
|
13
|
-
* @returns A generator sequence.
|
|
14
|
-
*/
|
|
15
|
-
export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
|
|
16
|
-
/**
|
|
17
|
-
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
|
|
18
|
-
* It logs the error and retry interval in case an error is caught. The function can be named for better log output.
|
|
19
|
-
*
|
|
20
|
-
* @param fn - The asynchronous function to be retried.
|
|
21
|
-
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
|
|
22
|
-
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
23
|
-
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
24
|
-
*/
|
|
25
|
-
export declare function retry<Result>(fn: () => Promise<Result>, backoff?: Generator<number, void, unknown>): Promise<Result>;
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,mCAAqB,mBAa1F"}
|
package/dest/node/retry/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a backoff sequence for retrying operations with an increasing delay.
|
|
3
|
-
* The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
|
|
4
|
-
* This generator can be used in combination with the `retry` function to perform
|
|
5
|
-
* retries with exponential backoff and capped at 64 seconds between attempts.
|
|
6
|
-
*
|
|
7
|
-
* @returns A generator that yields the next backoff value in seconds as an integer.
|
|
8
|
-
*/
|
|
9
|
-
export function* backoffGenerator() {
|
|
10
|
-
const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
|
|
11
|
-
let i = 0;
|
|
12
|
-
while (true) {
|
|
13
|
-
yield v[Math.min(i++, v.length - 1)];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
|
|
18
|
-
* @param retries - Intervals to retry (in seconds).
|
|
19
|
-
* @returns A generator sequence.
|
|
20
|
-
*/
|
|
21
|
-
export function* makeBackoff(retries) {
|
|
22
|
-
for (const retry of retries) {
|
|
23
|
-
yield retry;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
|
|
28
|
-
* It logs the error and retry interval in case an error is caught. The function can be named for better log output.
|
|
29
|
-
*
|
|
30
|
-
* @param fn - The asynchronous function to be retried.
|
|
31
|
-
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
|
|
32
|
-
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
33
|
-
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
34
|
-
*/
|
|
35
|
-
export async function retry(fn, backoff = backoffGenerator()) {
|
|
36
|
-
while (true) {
|
|
37
|
-
try {
|
|
38
|
-
return await fn();
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
const s = backoff.next().value;
|
|
42
|
-
if (s === undefined) {
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
45
|
-
await new Promise(resolve => setTimeout(resolve, s * 1000));
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcmV0cnkvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7R0FPRztBQUNILE1BQU0sU0FBUyxDQUFDLENBQUMsZ0JBQWdCO0lBQy9CLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLENBQUMsQ0FBQztJQUN6QyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUM7SUFDVixPQUFPLElBQUksRUFBRSxDQUFDO1FBQ1osTUFBTSxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsTUFBTSxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDdkMsQ0FBQztBQUNILENBQUM7QUFFRDs7OztHQUlHO0FBQ0gsTUFBTSxTQUFTLENBQUMsQ0FBQyxXQUFXLENBQUMsT0FBaUI7SUFDNUMsS0FBSyxNQUFNLEtBQUssSUFBSSxPQUFPLEVBQUUsQ0FBQztRQUM1QixNQUFNLEtBQUssQ0FBQztJQUNkLENBQUM7QUFDSCxDQUFDO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLEtBQUssQ0FBUyxFQUF5QixFQUFFLE9BQU8sR0FBRyxnQkFBZ0IsRUFBRTtJQUN6RixPQUFPLElBQUksRUFBRSxDQUFDO1FBQ1osSUFBSSxDQUFDO1lBQ0gsT0FBTyxNQUFNLEVBQUUsRUFBRSxDQUFDO1FBQ3BCLENBQUM7UUFBQyxPQUFPLEdBQVEsRUFBRSxDQUFDO1lBQ2xCLE1BQU0sQ0FBQyxHQUFHLE9BQU8sQ0FBQyxJQUFJLEVBQUUsQ0FBQyxLQUFLLENBQUM7WUFDL0IsSUFBSSxDQUFDLEtBQUssU0FBUyxFQUFFLENBQUM7Z0JBQ3BCLE1BQU0sR0FBRyxDQUFDO1lBQ1osQ0FBQztZQUNELE1BQU0sSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxFQUFFLENBQUMsR0FBRyxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQzVELFNBQVM7UUFDWCxDQUFDO0lBQ0gsQ0FBQztBQUNILENBQUMifQ==
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a backoff sequence for retrying operations with an increasing delay.
|
|
3
|
-
* The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
|
|
4
|
-
* This generator can be used in combination with the `retry` function to perform
|
|
5
|
-
* retries with exponential backoff and capped at 64 seconds between attempts.
|
|
6
|
-
*
|
|
7
|
-
* @returns A generator that yields the next backoff value in seconds as an integer.
|
|
8
|
-
*/
|
|
9
|
-
export declare function backoffGenerator(): Generator<number, void, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
|
|
12
|
-
* @param retries - Intervals to retry (in seconds).
|
|
13
|
-
* @returns A generator sequence.
|
|
14
|
-
*/
|
|
15
|
-
export declare function makeBackoff(retries: number[]): Generator<number, void, unknown>;
|
|
16
|
-
/**
|
|
17
|
-
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
|
|
18
|
-
* It logs the error and retry interval in case an error is caught. The function can be named for better log output.
|
|
19
|
-
*
|
|
20
|
-
* @param fn - The asynchronous function to be retried.
|
|
21
|
-
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
|
|
22
|
-
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
23
|
-
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
24
|
-
*/
|
|
25
|
-
export declare function retry<Result>(fn: () => Promise<Result>, backoff?: Generator<number, void, unknown>): Promise<Result>;
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/retry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,mCAAqB,mBAa1F"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retry = exports.makeBackoff = exports.backoffGenerator = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Generates a backoff sequence for retrying operations with an increasing delay.
|
|
6
|
-
* The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
|
|
7
|
-
* This generator can be used in combination with the `retry` function to perform
|
|
8
|
-
* retries with exponential backoff and capped at 64 seconds between attempts.
|
|
9
|
-
*
|
|
10
|
-
* @returns A generator that yields the next backoff value in seconds as an integer.
|
|
11
|
-
*/
|
|
12
|
-
function* backoffGenerator() {
|
|
13
|
-
const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
|
|
14
|
-
let i = 0;
|
|
15
|
-
while (true) {
|
|
16
|
-
yield v[Math.min(i++, v.length - 1)];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.backoffGenerator = backoffGenerator;
|
|
20
|
-
/**
|
|
21
|
-
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
|
|
22
|
-
* @param retries - Intervals to retry (in seconds).
|
|
23
|
-
* @returns A generator sequence.
|
|
24
|
-
*/
|
|
25
|
-
function* makeBackoff(retries) {
|
|
26
|
-
for (const retry of retries) {
|
|
27
|
-
yield retry;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.makeBackoff = makeBackoff;
|
|
31
|
-
/**
|
|
32
|
-
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
|
|
33
|
-
* It logs the error and retry interval in case an error is caught. The function can be named for better log output.
|
|
34
|
-
*
|
|
35
|
-
* @param fn - The asynchronous function to be retried.
|
|
36
|
-
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
|
|
37
|
-
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
38
|
-
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
39
|
-
*/
|
|
40
|
-
async function retry(fn, backoff = backoffGenerator()) {
|
|
41
|
-
while (true) {
|
|
42
|
-
try {
|
|
43
|
-
return await fn();
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
const s = backoff.next().value;
|
|
47
|
-
if (s === undefined) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
await new Promise(resolve => setTimeout(resolve, s * 1000));
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.retry = retry;
|
|
56
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcmV0cnkvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUE7Ozs7Ozs7R0FPRztBQUNILFFBQWUsQ0FBQyxDQUFDLGdCQUFnQjtJQUMvQixNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLEVBQUUsRUFBRSxFQUFFLEVBQUUsRUFBRSxDQUFDLENBQUM7SUFDekMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ1YsT0FBTyxJQUFJLEVBQUUsQ0FBQztRQUNaLE1BQU0sQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLE1BQU0sR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3ZDLENBQUM7QUFDSCxDQUFDO0FBTkQsNENBTUM7QUFFRDs7OztHQUlHO0FBQ0gsUUFBZSxDQUFDLENBQUMsV0FBVyxDQUFDLE9BQWlCO0lBQzVDLEtBQUssTUFBTSxLQUFLLElBQUksT0FBTyxFQUFFLENBQUM7UUFDNUIsTUFBTSxLQUFLLENBQUM7SUFDZCxDQUFDO0FBQ0gsQ0FBQztBQUpELGtDQUlDO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSSxLQUFLLFVBQVUsS0FBSyxDQUFTLEVBQXlCLEVBQUUsT0FBTyxHQUFHLGdCQUFnQixFQUFFO0lBQ3pGLE9BQU8sSUFBSSxFQUFFLENBQUM7UUFDWixJQUFJLENBQUM7WUFDSCxPQUFPLE1BQU0sRUFBRSxFQUFFLENBQUM7UUFDcEIsQ0FBQztRQUFDLE9BQU8sR0FBUSxFQUFFLENBQUM7WUFDbEIsTUFBTSxDQUFDLEdBQUcsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDLEtBQUssQ0FBQztZQUMvQixJQUFJLENBQUMsS0FBSyxTQUFTLEVBQUUsQ0FBQztnQkFDcEIsTUFBTSxHQUFHLENBQUM7WUFDWixDQUFDO1lBQ0QsTUFBTSxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxPQUFPLEVBQUUsQ0FBQyxHQUFHLElBQUksQ0FBQyxDQUFDLENBQUM7WUFDNUQsU0FBUztRQUNYLENBQUM7SUFDSCxDQUFDO0FBQ0gsQ0FBQztBQWJELHNCQWFDIn0=
|