@heliuslabs/zolana-web-prover 0.0.0-stage → 0.3.0-alpha
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/CHANGELOG.md +34 -0
- package/README.md +95 -2
- package/dist/LICENSE +201 -0
- package/dist/abortable.d.ts +4 -0
- package/dist/abortable.js +30 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +38 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/key-digests.d.ts +9 -0
- package/dist/key-digests.js +49 -0
- package/dist/key-store.d.ts +67 -0
- package/dist/key-store.js +318 -0
- package/dist/measurement.d.ts +17 -0
- package/dist/measurement.js +0 -0
- package/dist/proof-requests.d.ts +20 -0
- package/dist/proof-requests.js +68 -0
- package/dist/prover-fetch.d.ts +18 -0
- package/dist/prover-fetch.js +74 -0
- package/dist/prover.worker.d.ts +9 -0
- package/dist/prover.worker.js +147 -0
- package/dist/proving-threads.d.ts +6 -0
- package/dist/proving-threads.js +10 -0
- package/dist/runtime/accelerator/LICENSE-APACHE +201 -0
- package/dist/runtime/accelerator/LICENSE-MIT +19 -0
- package/dist/runtime/accelerator/gnark_kernel.d.ts +88 -0
- package/dist/runtime/accelerator/gnark_kernel.js +455 -0
- package/dist/runtime/accelerator/gnark_kernel_bg.wasm +0 -0
- package/dist/runtime/accelerator/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.js +107 -0
- package/dist/runtime/runtime-manifest.json +49 -0
- package/dist/runtime/zolana-prover.wasm +0 -0
- package/dist/scripts/assets.mjs +70 -0
- package/dist/scripts/install-keys.mjs +46 -0
- package/dist/shapes.d.ts +50 -0
- package/dist/shapes.js +86 -0
- package/dist/vendor/wasm_exec.d.ts +0 -0
- package/dist/vendor/wasm_exec.js +575 -0
- package/dist/wasm-prover.d.ts +144 -0
- package/dist/wasm-prover.js +383 -0
- package/package.json +41 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0-alpha — 2026-10-20
|
|
4
|
+
|
|
5
|
+
The runtime ships in the package: an app installs it with npm, its bundler emits the worker, the Go bridge and the accelerator, and threaded proving works in a Chrome extension page.
|
|
6
|
+
|
|
7
|
+
Breaking
|
|
8
|
+
|
|
9
|
+
- `WasmProverOptions.wasmUrl` is gone; the worker loads the Go bridge and the accelerator from beside itself, where Vite and webpack 5 emit them.
|
|
10
|
+
- `zolana-prover-assets` is now `zolana-prover-keys --output <directory> --keys <names>`, which installs proving keys for self-hosting and nothing else.
|
|
11
|
+
|
|
12
|
+
Changed
|
|
13
|
+
|
|
14
|
+
- Runtime 0.3.2, the 0.3.1 accelerator with Rayon's thread helpers for bundlers: its threads start from files the bundler emits rather than from `blob:` URLs, which an extension page refuses, so 0.2.0-alpha proves there only with `threads: 0`.
|
|
15
|
+
- A thread pool that has not started after 30 s fails initialization with `wasm_init_failed` instead of waiting forever.
|
|
16
|
+
- A key downloads in ranged parts of 8 MB kept in the cache as they arrive, so an interrupted download resumes where it stopped.
|
|
17
|
+
- A kept decoded key is checked by its size instead of hashed on every load, about 0.02–0.05 s less per load after a page reload.
|
|
18
|
+
|
|
19
|
+
Added
|
|
20
|
+
|
|
21
|
+
- `neededKeys(maxInputs, outputs, maxMergeInputs)` names the keys spends and merges up to those limits prove with, for `prefetch`.
|
|
22
|
+
- `prover.provingKeys()` lists every key with the bytes the browser keeps of it and whether its decoded form is kept; `ProvingKeyStatus` is exported.
|
|
23
|
+
- `prover.clearKeys()` removes the kept keys, their decoded forms and interrupted downloads.
|
|
24
|
+
|
|
25
|
+
## 0.2.0-alpha — 2026-10-20
|
|
26
|
+
|
|
27
|
+
The first release. `ZolanaWebProver` proves `@heliuslabs/zolana` 0.4.0-alpha transfer and merge requests in a browser worker with the threaded accelerator of runtime 0.3.1, verifies each proof before it returns it, and answers the SDK's `/prove` requests in the page through `createFetch()`. A warm proof takes 0.31 s for two notes to two outputs and 0.97 s for eight, in Chrome at four threads on an Apple M5 Pro.
|
|
28
|
+
|
|
29
|
+
- Keys load on first use from the pinned key set on the Zolana key CDN (`KEY_BASE_URL`), so an app installs none; `keyBaseUrl` points the prover at self-hosted keys. Every key is checked against the size and SHA-256 bundled in the package from the pinned lockfile.
|
|
30
|
+
- `zolana-prover-assets` installs the Go bridge, the pinned accelerator and by default the 2x2 key into the app's public directory; `--keys none` installs no key, and `--keys` picks any pinned transfer or merge key for self-hosting.
|
|
31
|
+
- A key's first load decompresses its points on the accelerator's thread pool, and the Cache API then keeps the decoded raw form in place of the downloaded file, so a later load, including after a reload, takes 0.08 s to 1.8 s for the benchmarked shapes.
|
|
32
|
+
- `prover.prefetch({ shapes, signal, onProgress })` downloads, checks and decodes keys before the proofs that need them, skipping shapes already cached; `onKeyProgress` reports each key's download bytes and decode stage for every load.
|
|
33
|
+
- Keys live in the Cache API store `zolana-proving-keys-<key set>`, and stores of other key sets are deleted on first use; `persistStorage` asks the browser to keep them under storage pressure.
|
|
34
|
+
- `WasmProverError.code` names each failure without backend messages or witness values; `wasm_key_manifest_error` means the requested key is not in the pinned key set.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @heliuslabs/zolana-web-prover
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local Groth16 proving and gnark verification in a browser worker. The core package has no protocol SDK or Solana dependencies. Transaction building, submission and benchmark orchestration live in the repository's browser example, not this package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @heliuslabs/zolana-web-prover
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package contains the worker, the sanitized Go Wasm bridge with its runtime shim, and the threaded accelerator. Import it, and the app's bundler emits them as files beside the worker; the packed-consumer CI builds an app with Vite and with webpack 5 and proves from both. A bundler that does not emit `new URL(…, import.meta.url)` assets and nested module workers (esbuild and Rollup without plugins) cannot load the runtime. Keys load on first use from the pinned key set on the Zolana key CDN, which serves them with CORS, and are checked against the size and SHA-256 bundled in the package, so an app installs none.
|
|
12
|
+
|
|
13
|
+
Serve the document with:
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
17
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use HTTPS (localhost is suitable for development). These headers are required for threaded proving; set `threads: 0` for Go-only proving without cross-origin isolation. Every key is checked against the size and SHA-256 bundled in the package from the pinned proving-keys lockfile, so the key host does not need to be trusted for integrity.
|
|
21
|
+
|
|
22
|
+
In a Chrome extension, prove from an extension page; an extension's service worker cannot start workers. Give the manifest the same isolation and allow WebAssembly:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
"cross_origin_embedder_policy": { "value": "require-corp" },
|
|
26
|
+
"cross_origin_opener_policy": { "value": "same-origin" },
|
|
27
|
+
"content_security_policy": { "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'" }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The packed-consumer CI proves from such a page with Go and with threads.
|
|
31
|
+
|
|
32
|
+
## Prove locally
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { ZolanaWebProver, WasmProverError } from "@heliuslabs/zolana-web-prover";
|
|
36
|
+
|
|
37
|
+
const prover = new ZolanaWebProver({
|
|
38
|
+
proverUrl: "https://local-prover.invalid",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const requestJson = await (await fetch("/fixtures/transfer-2x2.json")).text();
|
|
43
|
+
const { proof, proveMs, verifyMs } = await prover.proveRequest(requestJson);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error instanceof WasmProverError) console.error(error.code);
|
|
46
|
+
} finally {
|
|
47
|
+
prover.terminate();
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`proveRequest` accepts the protocol's `/prove` JSON string and returns its proof JSON only after local verification. No transaction is built or sent. The bridge proves requests from `@heliuslabs/zolana` 0.4.0-alpha and reports each proof's `provingKeySha256`, which that SDK checks against its pinned keys. To connect it, pass `prover.createFetch()` as `fetch` and the same `proverUrl` to `createZolanaClient`, then prove through `LocalKeys.fromKeypair(keypair, client.proofService)`, or, for a browser wallet, `LocalKeys.fromDerivationSeed` with the wallet's signature over `ed25519DerivationMessage(publicKey)` (the repository's [wallet example](https://github.com/helius-labs/zolana-web-sdk/tree/main/examples/wallet) shows the whole flow). Requests to that URL's `/prove/<key>` endpoint, and to the bare `/prove` the Helius gateway routes to, are proved locally with the key the request names; a `<key>` that does not match the request body and any other path below `/prove` (such as `/prove/<key>/indexed`) get a 500 and are never forwarded. All other requests are delegated to the configured fetch implementation.
|
|
52
|
+
|
|
53
|
+
## Self-host proving keys
|
|
54
|
+
|
|
55
|
+
To serve keys yourself, for offline use, a mirror or your own CDN, install the shapes your application's requests need and pass their location as `keyBaseUrl` (for example `keyBaseUrl: "/keys"`):
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npx --no-install zolana-prover-keys --output public/keys --keys transfer_confidential_1_2.key,transfer_confidential_2_2.key
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Names must be confidential-transfer or merge keys present in the pinned proving-keys lockfile; arbitrary names, paths and unsupported circuits are rejected before installation. Bytes still undergo size and SHA-256 checks. Use `keyForProveRequest` or `observeProofRequests` to identify needed shapes without logging witness bodies. A missing key fails rather than substituting a different circuit. Previously downloaded files are not deleted when selecting a new list. The command needs Node.js and network access; for a local mirror of the key set, set `ZOLANA_KEYS_BASE_URL` to a `file:///.../` directory, and the same checks apply.
|
|
62
|
+
|
|
63
|
+
Keys are 9–362 MB each for confidential transfers (16 MB for 2x2, 94 MB for 12x8) and 56–380 MB for merge; deserialized circuits and proving work need additional memory. Only one deserialized key is retained, and changing shapes reloads it. The first load of a shape decompresses the key's curve points on the accelerator's thread pool (1.4 s for 2x2 and 4.9 s for 8x2 in Chrome at four threads on an Apple M5 Pro; slower with `threads: 0`, where Go decompresses them) and stores the decoded raw form in the browser Cache API in place of the downloaded file; later loads, including after a reload, read the raw form in 0.15 s (2x2) and 0.5 s (8x2), plus about 0.15 s to read it from the cache; it is checked by size, not hashed again, since a damaged entry fails its load and is rebuilt from the pinned key. The raw form is about 1.6× the file's size, and storage is subject to the browser's quota. Keys live in the Cache API store `zolana-proving-keys-<key set>`, and stores left by other key sets are deleted on first use. Pass `persistStorage: true` to ask the browser not to evict them under storage pressure (`navigator.storage.persist()`; Firefox asks the user). Install only the shapes you use, and budget separately for download/storage size and runtime memory.
|
|
64
|
+
|
|
65
|
+
A key downloads in ranged parts of 8 MB, each kept in the cache as it arrives, so a download that a closed tab, a lost connection or an abort interrupted resumes where it stopped; a host that ignores ranges sends the whole key instead. The key is checked against the lockfile once it is whole, and a download that resumed from a damaged part starts over once.
|
|
66
|
+
|
|
67
|
+
## Prefetch keys
|
|
68
|
+
|
|
69
|
+
`prefetch` downloads, checks and decodes keys ahead of the proofs that need them, for example right after a wallet connects, so the first send doesn't wait seconds for its key. Shapes whose decoded form is already cached are skipped, and a proof requested meanwhile runs after the shape in progress:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
await prover.prefetch({
|
|
73
|
+
shapes: [shapeByLabel("1x2"), shapeByLabel("2x2")],
|
|
74
|
+
onProgress: ({ keyFile, stage, loaded, total }) => render(keyFile, stage, loaded / total),
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`stage` is `download` while bytes arrive and `decode` once the worker starts loading the key. Pass `onKeyProgress` to the constructor to receive the same events for every load, including the ones a proof triggers. Without the Cache API only the last prefetched shape stays loaded.
|
|
79
|
+
|
|
80
|
+
`neededKeys(maxInputs, outputs, maxMergeInputs)` names the shapes that spends of up to `maxInputs` notes with `outputs` outputs, and merges of up to `maxMergeInputs` notes, prove with, smallest first, for `prefetch`; a transfer has two outputs, the payment and the change. `provingKeys()` lists every key the prover can load with its size, the bytes the browser keeps of it and whether its decoded form is kept, without starting the worker. `clearKeys()` removes the kept keys, their decoded forms and interrupted downloads after any work in progress. These follow the mobile SDK's `ProvingKeys.needed`, `status` and `clear`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const shapes = neededKeys(8, [2], 24); // spends of up to 8 notes, merges of up to 24
|
|
84
|
+
await prover.prefetch({ shapes });
|
|
85
|
+
const kept = (await prover.provingKeys()).reduce((sum, key) => sum + key.downloaded, 0);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Lifecycle and failures
|
|
89
|
+
|
|
90
|
+
- First use initializes the worker automatically. Requests are serialized; only one deserialized key is resident at a time.
|
|
91
|
+
- Cache API access is best-effort. Cached bytes are validated; unavailable storage and quota failures fall back to validated network bytes. Abort and integrity failures remain errors.
|
|
92
|
+
- An `AbortSignal` cancels queued work without interrupting active work. Cancelling active work terminates the runtime and rejects its queued requests. A retained worker factory allows a later request to restart automatically after cancellation or a worker failure.
|
|
93
|
+
- `terminate()` rejects outstanding work, clears the factory and disables automatic restart. Create a new prover, or explicitly call `start(factory)` to reuse the object. A supplied single `Worker` cannot be recreated automatically.
|
|
94
|
+
- `WasmProverError.code` and its fixed message identify failures without serializing backend messages, witness values, causes or stacks from the backend. Core code does not log errors. The fetch adapter returns a JSON 500 with the safe `code` and `message`; cancellation rejects instead. Caller-provided abort reasons and callback errors remain caller-controlled and should not contain secrets.
|
|
95
|
+
|
|
96
|
+
The accelerator comes from the `runtime-v0.3.2` release, built with Rayon's thread helpers for bundlers; the Go bridge is built from source. The TypeScript worker/API boundary additionally redacts backend errors as defense in depth.
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Race work against cancellation even when an I/O implementation ignores signals. */
|
|
2
|
+
export declare function abortable<T>(work: Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
3
|
+
/** Rethrows a cancellation, so a caller that swallows other errors still stops. */
|
|
4
|
+
export declare function rethrowAbort(error: unknown, signal?: AbortSignal): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Race work against cancellation even when an I/O implementation ignores signals. */
|
|
2
|
+
export function abortable(work, signal) {
|
|
3
|
+
if (signal === undefined)
|
|
4
|
+
return work;
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const abort = () => reject(signal.reason);
|
|
7
|
+
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
8
|
+
// Always observe work, including when the signal was already aborted.
|
|
9
|
+
work.then((value) => {
|
|
10
|
+
cleanup();
|
|
11
|
+
if (signal.aborted)
|
|
12
|
+
reject(signal.reason);
|
|
13
|
+
else
|
|
14
|
+
resolve(value);
|
|
15
|
+
}, (error) => {
|
|
16
|
+
cleanup();
|
|
17
|
+
reject(signal.aborted ? signal.reason : error);
|
|
18
|
+
});
|
|
19
|
+
if (signal.aborted)
|
|
20
|
+
abort();
|
|
21
|
+
else
|
|
22
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** Rethrows a cancellation, so a caller that swallows other errors still stops. */
|
|
26
|
+
export function rethrowAbort(error, signal) {
|
|
27
|
+
signal?.throwIfAborted();
|
|
28
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const messages: {
|
|
2
|
+
readonly wasm_prover_error: "Prover operation failed";
|
|
3
|
+
readonly wasm_init_failed: "Prover initialization failed; check runtime assets, threads and isolation headers";
|
|
4
|
+
readonly wasm_worker_failed: "Prover worker failed";
|
|
5
|
+
readonly wasm_worker_not_started: "Prover worker is not started";
|
|
6
|
+
readonly wasm_worker_terminated: "Prover worker terminated";
|
|
7
|
+
readonly wasm_invalid_response: "Invalid prover response";
|
|
8
|
+
readonly wasm_invalid_request: "Unsupported circuit or malformed request";
|
|
9
|
+
readonly wasm_key_manifest_error: "The proving key is not in the pinned key set";
|
|
10
|
+
readonly wasm_key_download_failed: "Proving-key download failed";
|
|
11
|
+
readonly wasm_key_digest_mismatch: "Proving key does not match the lockfile; stage the pinned assets";
|
|
12
|
+
readonly wasm_key_load_failed: "Proving-key loading failed";
|
|
13
|
+
readonly wasm_prove_failed: "Proof generation failed";
|
|
14
|
+
readonly wasm_verify_failed: "Native gnark verification rejected the proof";
|
|
15
|
+
};
|
|
16
|
+
export type WasmProverErrorCode = keyof typeof messages;
|
|
17
|
+
export declare class WasmProverError extends Error {
|
|
18
|
+
readonly code: WasmProverErrorCode;
|
|
19
|
+
constructor(code?: WasmProverErrorCode);
|
|
20
|
+
}
|
|
21
|
+
export declare function operationError(kind: string): WasmProverError;
|
|
22
|
+
export {};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
wasm_prover_error: "Prover operation failed",
|
|
3
|
+
wasm_init_failed: "Prover initialization failed; check runtime assets, threads and isolation headers",
|
|
4
|
+
wasm_worker_failed: "Prover worker failed",
|
|
5
|
+
wasm_worker_not_started: "Prover worker is not started",
|
|
6
|
+
wasm_worker_terminated: "Prover worker terminated",
|
|
7
|
+
wasm_invalid_response: "Invalid prover response",
|
|
8
|
+
wasm_invalid_request: "Unsupported circuit or malformed request",
|
|
9
|
+
wasm_key_manifest_error: "The proving key is not in the pinned key set",
|
|
10
|
+
wasm_key_download_failed: "Proving-key download failed",
|
|
11
|
+
wasm_key_digest_mismatch: "Proving key does not match the lockfile; stage the pinned assets",
|
|
12
|
+
wasm_key_load_failed: "Proving-key loading failed",
|
|
13
|
+
wasm_prove_failed: "Proof generation failed",
|
|
14
|
+
wasm_verify_failed: "Native gnark verification rejected the proof",
|
|
15
|
+
};
|
|
16
|
+
export class WasmProverError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code = "wasm_prover_error") {
|
|
19
|
+
const safeCode = Object.hasOwn(messages, code) ? code : "wasm_prover_error";
|
|
20
|
+
super(messages[safeCode]);
|
|
21
|
+
this.name = "WasmProverError";
|
|
22
|
+
this.code = safeCode;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function operationError(kind) {
|
|
26
|
+
switch (kind) {
|
|
27
|
+
case "init":
|
|
28
|
+
return new WasmProverError("wasm_init_failed");
|
|
29
|
+
case "loadKey":
|
|
30
|
+
return new WasmProverError("wasm_key_load_failed");
|
|
31
|
+
case "prove":
|
|
32
|
+
return new WasmProverError("wasm_prove_failed");
|
|
33
|
+
case "verify":
|
|
34
|
+
return new WasmProverError("wasm_verify_failed");
|
|
35
|
+
default:
|
|
36
|
+
return new WasmProverError("wasm_worker_failed");
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { TRANSFER_SHAPES, MERGE_KEY_BYTES, MERGE_KEY_FILE, MERGE_SHAPE, MERGE_SHAPES, keyForProveRequest, canonicalShape, formatBytes, neededKeys, shapeByLabel, type Shape, type ShapeKey, } from "./shapes.js";
|
|
2
|
+
export { KEY_BASE_URL } from "./key-digests.js";
|
|
3
|
+
export type { KeyProgress, Measurement } from "./measurement.js";
|
|
4
|
+
export type { WasmProverErrorCode } from "./errors.js";
|
|
5
|
+
export { WasmProver, WasmProver as ZolanaWebProver, WasmProverError, type WasmProverOptions, type WorkerRequest, type WorkerResponse, } from "./wasm-prover.js";
|
|
6
|
+
export type { ProvingKeyStatus } from "./key-store.js";
|
|
7
|
+
export { automaticProvingThreads } from "./proving-threads.js";
|
|
8
|
+
export { observeProofRequests } from "./proof-requests.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { TRANSFER_SHAPES, MERGE_KEY_BYTES, MERGE_KEY_FILE, MERGE_SHAPE, MERGE_SHAPES, keyForProveRequest, canonicalShape, formatBytes, neededKeys, shapeByLabel, } from "./shapes.js";
|
|
2
|
+
export { KEY_BASE_URL } from "./key-digests.js";
|
|
3
|
+
export { WasmProver, WasmProver as ZolanaWebProver, WasmProverError, } from "./wasm-prover.js";
|
|
4
|
+
export { automaticProvingThreads } from "./proving-threads.js";
|
|
5
|
+
export { observeProofRequests } from "./proof-requests.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The pinned key set's version folder on the proving-keys CDN. */
|
|
2
|
+
export declare const KEY_SET = "3a1c88f90f609eb1";
|
|
3
|
+
/** Where the pinned key set is served from; the default `keyBaseUrl`. */
|
|
4
|
+
export declare const KEY_BASE_URL = "https://d3gbdb0egjwcw9.cloudfront.net/proving-keys/3a1c88f90f609eb1/";
|
|
5
|
+
/** Size and sha256 of every proving key the browser prover can load. */
|
|
6
|
+
export declare const KEY_DIGESTS: Readonly<Record<string, Readonly<{
|
|
7
|
+
size: number;
|
|
8
|
+
sha256: string;
|
|
9
|
+
}>>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by scripts/generate-key-digests.ts; do not edit.
|
|
2
|
+
/** The pinned key set's version folder on the proving-keys CDN. */
|
|
3
|
+
export const KEY_SET = "3a1c88f90f609eb1";
|
|
4
|
+
/** Where the pinned key set is served from; the default `keyBaseUrl`. */
|
|
5
|
+
export const KEY_BASE_URL = "https://d3gbdb0egjwcw9.cloudfront.net/proving-keys/3a1c88f90f609eb1/";
|
|
6
|
+
/** Size and sha256 of every proving key the browser prover can load. */
|
|
7
|
+
export const KEY_DIGESTS = Object.freeze({
|
|
8
|
+
"merge_24_1.key": { size: 173052578, sha256: "a0dfaa1e73d2d9e1159d2ebab82baa6d0602482d75f24dcbff596322dc389c88" },
|
|
9
|
+
"merge_54_1.key": { size: 379646246, sha256: "951ec83dc53d112a46a1eb9cd308e6abd933291eb3109647a479e2321fce7423" },
|
|
10
|
+
"merge_8_1.key": { size: 55767611, sha256: "f59571876452541eaf20cfc583a082b9b6cc788bf85719bd337398b2d962ad23" },
|
|
11
|
+
"transfer_confidential_1_16.key": { size: 18119894, sha256: "aecae052aeb709ef4656d6da110bd1403d21bc5891e60691ee9cbc0ebb46dcb9" },
|
|
12
|
+
"transfer_confidential_1_2.key": { size: 9268057, sha256: "7ef987966b0dfba5d86eab7c67068be00dbe581d823d45cdbbf6d338bfacb640" },
|
|
13
|
+
"transfer_confidential_1_4.key": { size: 11320903, sha256: "94bddced9e46a0e0c4fbf6bc59c6d083e1d577a60bf4d8520129f41505f4f1dd" },
|
|
14
|
+
"transfer_confidential_1_8.key": { size: 13695140, sha256: "3471ab2908cbe15b757164db5bb7c7f82a89036c557fc26fe66a7148a4338f58" },
|
|
15
|
+
"transfer_confidential_12_2.key": { size: 90894233, sha256: "3415363ec3ae33b730c7445aeb7850aa1bc044443e6ef8a7731e2c56fd1df6e7" },
|
|
16
|
+
"transfer_confidential_12_4.key": { size: 91932405, sha256: "36519896a5e5b4d1ef008d6883548944027eb21ea3e6bc72ba00fde9ea9efa4a" },
|
|
17
|
+
"transfer_confidential_12_8.key": { size: 94355203, sha256: "131973e42165b1222ecfd2692796cfb035d5aa4a08ce7bf5e545795283ee344d" },
|
|
18
|
+
"transfer_confidential_16_2.key": { size: 114870607, sha256: "27370f44f8b9c0c05f9d2c6738ab5294582fd40c869114baf0d7fb15e6d08e2a" },
|
|
19
|
+
"transfer_confidential_16_4.key": { size: 115913395, sha256: "7cdef518b59307d578c2eecb71e811945ee56b1906283e8c70fe0924343dfb2a" },
|
|
20
|
+
"transfer_confidential_16_8.key": { size: 118361316, sha256: "d8052824a163d41ddf8540bc72dbfe94b5c52be21b6a0f3039b2f01f7380641f" },
|
|
21
|
+
"transfer_confidential_2_16.key": { size: 26327780, sha256: "27ef8be4d400bb9c724f79a4928f7f6ff4dc95a970f17c365b38430267986bfd" },
|
|
22
|
+
"transfer_confidential_2_2.key": { size: 16407295, sha256: "e810d52962f4558b0bd50b768a89490759e15a0623d4c2c43318f541b8cc61ff" },
|
|
23
|
+
"transfer_confidential_2_4.key": { size: 17416909, sha256: "c93338402cdc8fd8ec2f70f2de9fa29ee3e35b064ca803f8ad4d18070e4861fe" },
|
|
24
|
+
"transfer_confidential_2_8.key": { size: 21887446, sha256: "a38085e7a38b725909e7fe81be544c6e5a1b4ec3561cc07f941eac15825c578a" },
|
|
25
|
+
"transfer_confidential_24_2.key": { size: 179892108, sha256: "7b98beac6e0f89d568a30f569c690267bc37fcb8472ad88c292b89433c2f91d9" },
|
|
26
|
+
"transfer_confidential_24_4.key": { size: 180955692, sha256: "4e3c664a197a7b2cc5616b7c01dc463e92fa666f2990ee42ceb2d7ae81f1ece4" },
|
|
27
|
+
"transfer_confidential_3_2.key": { size: 24424541, sha256: "0537e6669e6dae3304648bd427bf3f9ec3e5aaa66134d15e0ff142794f2e966b" },
|
|
28
|
+
"transfer_confidential_3_4.key": { size: 25433887, sha256: "4710053ed9a08908c419ede4c9a3138d9f78e6d185c6846a2a9c2f4f846c0d4d" },
|
|
29
|
+
"transfer_confidential_3_8.key": { size: 27804471, sha256: "e559f7256c67be5dc857f601b22c0e929ba615f91032da09db32c00cd98255d1" },
|
|
30
|
+
"transfer_confidential_32_2.key": { size: 228023589, sha256: "70f4a61a248d240ca6b20730e6ab8a88acb9f4153c1e4688f6861bf6339a5a0b" },
|
|
31
|
+
"transfer_confidential_4_16.key": { size: 38204323, sha256: "917cf5f0976d245b08756b1147e04a1f0924c5f5b800d57bd57d305b43e8f432" },
|
|
32
|
+
"transfer_confidential_4_2.key": { size: 30346432, sha256: "aea0c474e4c67499c45f11f30d2d03e53ee5dd7c6b7940a0f61cfefa2e61e38e" },
|
|
33
|
+
"transfer_confidential_4_4.key": { size: 31361454, sha256: "6d83eef0b16f03b8f2b2a469441d67264bc34932d8b261f344f5bb39f29a1fbe" },
|
|
34
|
+
"transfer_confidential_4_8.key": { size: 33727897, sha256: "27fe418512ee0be5cb2f82290eab4ab20ed2d32549e1d8d7bfa1fa5b45df62e9" },
|
|
35
|
+
"transfer_confidential_40_2.key": { size: 275193373, sha256: "530779155340a05cbd90dedc5e94c5960cf5105f2866bdb041e3a56d06c9bb8b" },
|
|
36
|
+
"transfer_confidential_48_2.key": { size: 356237189, sha256: "4738674f40f19233f1963954ae4f96a763d11f1adcd82b4828ca8c420cc5b049" },
|
|
37
|
+
"transfer_confidential_49_2.key": { size: 362114005, sha256: "e39b30ba966198a03158276989d91f1b2fb05f695e56550fec6452d8a3110b6b" },
|
|
38
|
+
"transfer_confidential_5_16.key": { size: 48520274, sha256: "1faf95183f53bd29610ebda52703244ef63f45a2d26706e88bfd3197132bc20e" },
|
|
39
|
+
"transfer_confidential_5_2.key": { size: 36449879, sha256: "ae6699a19d810a7e0ef663dff3fc32e0b8e4bdeae9089c583746f95ae3b0e1e9" },
|
|
40
|
+
"transfer_confidential_5_4.key": { size: 37464519, sha256: "6779a069f3abc85f853b754ff2b58021532d26fe9642eb9ba42744da91733517" },
|
|
41
|
+
"transfer_confidential_5_8.key": { size: 44025900, sha256: "2806aff6bc7bd34233a2ff42a42e5524c680930944c3fc84d6d58e773c033cb5" },
|
|
42
|
+
"transfer_confidential_6_2.key": { size: 46571502, sha256: "fe62dff0397662cb25d89ac9de976cc3d23adfd2b7a72f5f8ad8671d677da605" },
|
|
43
|
+
"transfer_confidential_6_4.key": { size: 47591772, sha256: "116a3d4030047d182eedcc9effa66dd9c66ed9bd3ad9d82c2242dc47eef1f244" },
|
|
44
|
+
"transfer_confidential_6_8.key": { size: 49957349, sha256: "79281967e4aac47dc187d3a6555ab54800cef3928e5696969dcf4afb69b339da" },
|
|
45
|
+
"transfer_confidential_8_16.key": { size: 66535995, sha256: "8adc64d3886619e3b8e65b3b0c98eaac61bfdfbc8a51aa6ba05166b853feb328" },
|
|
46
|
+
"transfer_confidential_8_2.key": { size: 58604067, sha256: "24250fd74a86f1a07847e9dbb769cf9b2bebf20d29f18018186ea7900f69bbe4" },
|
|
47
|
+
"transfer_confidential_8_4.key": { size: 59617404, sha256: "82975fe1145c827a76f8b76e229bb9c8501f993b1a4f7709446b7717f30bd07a" },
|
|
48
|
+
"transfer_confidential_8_8.key": { size: 62007104, sha256: "f8972d03f57baef87702aaddb87a3b831d2377723e930fb25675fe3e473d8aec" },
|
|
49
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proving keys in the browser's Cache API.
|
|
3
|
+
*
|
|
4
|
+
* Keys are 9-380 MB each and immutable (the lockfile pins their sha256 and the
|
|
5
|
+
* CloudFront prefix is version-hashed), so re-downloading one per page load is
|
|
6
|
+
* pure waste. A key downloads in ranged parts kept as they arrive, so an
|
|
7
|
+
* interrupted download resumes where it stopped. After a shape's first load the
|
|
8
|
+
* store keeps the bridge's raw re-encoding instead of the pinned file: the
|
|
9
|
+
* pinned file's compressed points take about 240 ms per MB to decompress in
|
|
10
|
+
* wasm on every load, and the raw form skips that.
|
|
11
|
+
*/
|
|
12
|
+
import { type ShapeKey } from "./shapes.js";
|
|
13
|
+
/** One entry of `KEY_DIGESTS`, copied from `proving-keys.lock`. */
|
|
14
|
+
export interface KeyDigest {
|
|
15
|
+
readonly size: number;
|
|
16
|
+
readonly sha256: string;
|
|
17
|
+
}
|
|
18
|
+
/** A proving key the prover can load and how much of it the browser keeps. */
|
|
19
|
+
export interface ProvingKeyStatus {
|
|
20
|
+
readonly keyFile: string;
|
|
21
|
+
/** The key's size in the lockfile. */
|
|
22
|
+
readonly size: number;
|
|
23
|
+
/**
|
|
24
|
+
* Bytes the browser keeps: `size` once the key downloaded, what an interrupted
|
|
25
|
+
* download left otherwise.
|
|
26
|
+
*/
|
|
27
|
+
readonly downloaded: number;
|
|
28
|
+
/** Whether its decoded form is kept, so its next load skips decompression. */
|
|
29
|
+
readonly decoded: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A key's bytes: the pinned file, or the raw form the bridge wrote at an earlier load. */
|
|
32
|
+
export type KeyBytes = Readonly<{
|
|
33
|
+
bytes: ArrayBuffer;
|
|
34
|
+
raw: boolean;
|
|
35
|
+
source: "cache" | "network";
|
|
36
|
+
/** Whether the store can keep this key's raw form. */
|
|
37
|
+
cacheable: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
export interface KeyStoreOptions {
|
|
40
|
+
/** Where keys are fetched from; the pinned key set on the Zolana CDN by default. */
|
|
41
|
+
readonly keyBaseUrl?: string;
|
|
42
|
+
readonly fetch: typeof globalThis.fetch;
|
|
43
|
+
/** Ask the browser to keep the keys under storage pressure. */
|
|
44
|
+
readonly persistStorage?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare class KeyStore {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(options: KeyStoreOptions);
|
|
49
|
+
url(shape: ShapeKey): string;
|
|
50
|
+
/** The shape's pinned size and sha256; a shape outside the key set has none. */
|
|
51
|
+
digest(shape: ShapeKey): KeyDigest;
|
|
52
|
+
/** Every key, smallest first, with what the browser keeps of it. */
|
|
53
|
+
status(signal: AbortSignal): Promise<readonly ProvingKeyStatus[]>;
|
|
54
|
+
/** Removes the kept keys, their raw forms and interrupted downloads. */
|
|
55
|
+
clear(signal: AbortSignal): Promise<void>;
|
|
56
|
+
/** Whether the store keeps this shape's raw form, written by a bridge of `rawKeyFormat`. */
|
|
57
|
+
rawKept(shape: ShapeKey, rawKeyFormat: string, signal: AbortSignal): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* The shape's key: its raw form when kept, else the pinned file from the
|
|
60
|
+
* cache or, downloaded in parts, from the network.
|
|
61
|
+
*/
|
|
62
|
+
load(shape: ShapeKey, rawKeyFormat: string, signal: AbortSignal, downloaded?: (loaded: number) => void): Promise<KeyBytes>;
|
|
63
|
+
/** The pinned file, after forgetting a raw form the bridge rejected. */
|
|
64
|
+
reload(shape: ShapeKey, signal: AbortSignal, downloaded?: (loaded: number) => void): Promise<KeyBytes>;
|
|
65
|
+
/** Keeps the raw form in place of the pinned file, which is no longer read. */
|
|
66
|
+
keepRaw(shape: ShapeKey, rawKeyFormat: string, raw: Uint8Array<ArrayBuffer>, signal: AbortSignal): Promise<void>;
|
|
67
|
+
}
|