@lodestar/native 0.0.0-stage → 1.51.0-dev.9bcbf1838a
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/LICENSE +202 -0
- package/README.md +44 -2
- package/package.json +93 -3
- package/src/bindings.js +6 -0
- package/src/bls-verifier.d.ts +62 -0
- package/src/bls-verifier.js +12 -0
- package/src/blst.d.ts +183 -0
- package/src/blst.js +15 -0
- package/src/execution-proof-verifier.d.ts +46 -0
- package/src/execution-proof-verifier.js +17 -0
- package/src/index.d.ts +513 -0
- package/src/index.js +2 -0
- package/src/metrics.d.ts +18 -0
- package/src/metrics.js +8 -0
- package/src/pubkeys.d.ts +59 -0
- package/src/pubkeys.js +72 -0
- package/src/shuffle.d.ts +77 -0
- package/src/shuffle.js +12 -0
- package/src/state-transition.d.ts +11 -0
- package/src/state-transition.js +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lodestar/native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native consensus modules for [Lodestar](https://github.com/ChainSafe/lodestar),
|
|
4
|
+
implemented in Zig and exposed to Node.js through NAPI bindings.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @lodestar/native
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The wrapper and its platform packages use the same version as the Lodestar monorepo.
|
|
13
|
+
Published packages include binaries for Linux (glibc and musl) and macOS, on x64 and arm64.
|
|
14
|
+
|
|
15
|
+
## Development
|
|
16
|
+
|
|
17
|
+
The Zig sources and build files live at the repository root. From that root:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
pnpm install --frozen-lockfile
|
|
21
|
+
pnpm build
|
|
22
|
+
pnpm test:native
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For native-only changes, rebuild with `pnpm build:native`. The output is
|
|
26
|
+
`bindings/zig-out/lib/bindings.node`. Use
|
|
27
|
+
`pnpm --filter @lodestar/native prepare-minimal` or `prepare-gnosis` to select another
|
|
28
|
+
preset. Rebuild before switching presets; they share an output directory.
|
|
29
|
+
|
|
30
|
+
Bindings use their own Vitest configuration and the root workspace lockfile.
|
|
31
|
+
Consensus spec vectors are pinned in [`build.zig.zon`](../build.zig.zon).
|
|
32
|
+
See [contributing](../CONTRIBUTING.md).
|
|
33
|
+
|
|
34
|
+
## Publishing
|
|
35
|
+
|
|
36
|
+
`pnpm release:publish` uses zapi to build and publish the platform packages at the
|
|
37
|
+
shared version, skipping versions already on npm, then runs Lerna for the wrapper and the
|
|
38
|
+
remaining Lodestar packages. The wrapper's `prepack` script pins the platform packages
|
|
39
|
+
as `optionalDependencies`.
|
|
40
|
+
Use `--dist-tag next` or `--dist-tag rc` for pre-releases. `--dry-run` builds and
|
|
41
|
+
prepares the native packages without publishing.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodestar/native",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.51.0-dev.9bcbf1838a",
|
|
4
|
+
"description": "Native consensus modules for Lodestar",
|
|
5
|
+
"files": [
|
|
6
|
+
"src/"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.d.ts",
|
|
12
|
+
"import": "./src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./blst": {
|
|
15
|
+
"types": "./src/blst.d.ts",
|
|
16
|
+
"import": "./src/blst.js"
|
|
17
|
+
},
|
|
18
|
+
"./bls-verifier": {
|
|
19
|
+
"types": "./src/bls-verifier.d.ts",
|
|
20
|
+
"import": "./src/bls-verifier.js"
|
|
21
|
+
},
|
|
22
|
+
"./pubkeys": {
|
|
23
|
+
"types": "./src/pubkeys.d.ts",
|
|
24
|
+
"import": "./src/pubkeys.js"
|
|
25
|
+
},
|
|
26
|
+
"./state-transition": {
|
|
27
|
+
"types": "./src/state-transition.d.ts",
|
|
28
|
+
"import": "./src/state-transition.js"
|
|
29
|
+
},
|
|
30
|
+
"./metrics": {
|
|
31
|
+
"types": "./src/metrics.d.ts",
|
|
32
|
+
"import": "./src/metrics.js"
|
|
33
|
+
},
|
|
34
|
+
"./shuffle": {
|
|
35
|
+
"types": "./src/shuffle.d.ts",
|
|
36
|
+
"import": "./src/shuffle.js"
|
|
37
|
+
},
|
|
38
|
+
"./execution-proof-verifier": {
|
|
39
|
+
"types": "./src/execution-proof-verifier.d.ts",
|
|
40
|
+
"import": "./src/execution-proof-verifier.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"prepare-mainnet": "cd .. && zig build build-lib:bindings -Doptimize=ReleaseSafe -Dcpu=baseline -Dpreset=mainnet --prefix bindings/zig-out",
|
|
45
|
+
"prepare-minimal": "cd .. && zig build build-lib:bindings -Doptimize=ReleaseSafe -Dcpu=baseline -Dpreset=minimal --prefix bindings/zig-out",
|
|
46
|
+
"prepare-gnosis": "cd .. && zig build build-lib:bindings -Doptimize=ReleaseSafe -Dcpu=baseline -Dpreset=gnosis --prefix bindings/zig-out",
|
|
47
|
+
"lint": "biome check",
|
|
48
|
+
"test": "NODE_OPTIONS='--expose-gc' vitest run",
|
|
49
|
+
"benchmark": "NODE_OPTIONS='--import tsx' benchmark 'perf/**/*.test.ts' --isolate --config .benchrc.yaml --defaultBranch unstable",
|
|
50
|
+
"build": "pnpm run prepare-${LODESTAR_PRESET:-mainnet}",
|
|
51
|
+
"build:watch": "pnpm run build --watch",
|
|
52
|
+
"build:release": "pnpm clean && pnpm build",
|
|
53
|
+
"clean": "rm -rf zig-out",
|
|
54
|
+
"check-build": "node -e \"import('./src/index.js')\"",
|
|
55
|
+
"prepack": "zapi prepublish --main-only"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [],
|
|
58
|
+
"author": "ChainSafe Systems",
|
|
59
|
+
"license": "Apache-2.0",
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/ChainSafe/lodestar.git",
|
|
63
|
+
"directory": "bindings"
|
|
64
|
+
},
|
|
65
|
+
"zapi": {
|
|
66
|
+
"binaryName": "bindings",
|
|
67
|
+
"step": "build-lib:bindings",
|
|
68
|
+
"targets": [
|
|
69
|
+
"aarch64-apple-darwin",
|
|
70
|
+
"aarch64-unknown-linux-gnu",
|
|
71
|
+
"aarch64-unknown-linux-musl",
|
|
72
|
+
"x86_64-apple-darwin",
|
|
73
|
+
"x86_64-unknown-linux-gnu",
|
|
74
|
+
"x86_64-unknown-linux-musl"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"@chainsafe/zapi": "4.3.0"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@chainsafe/benchmark": "2.1.0",
|
|
82
|
+
"@chainsafe/ssz": "^1.9.0"
|
|
83
|
+
},
|
|
84
|
+
"publishConfig": {
|
|
85
|
+
"access": "public"
|
|
86
|
+
},
|
|
87
|
+
"gitHead": "0f462737411a514963b5e0c91deda7369d186557",
|
|
88
|
+
"optionalDependencies": {
|
|
89
|
+
"@lodestar/native-aarch64-apple-darwin": "1.51.0-dev.9bcbf1838a",
|
|
90
|
+
"@lodestar/native-aarch64-unknown-linux-gnu": "1.51.0-dev.9bcbf1838a",
|
|
91
|
+
"@lodestar/native-aarch64-unknown-linux-musl": "1.51.0-dev.9bcbf1838a",
|
|
92
|
+
"@lodestar/native-x86_64-apple-darwin": "1.51.0-dev.9bcbf1838a",
|
|
93
|
+
"@lodestar/native-x86_64-unknown-linux-gnu": "1.51.0-dev.9bcbf1838a",
|
|
94
|
+
"@lodestar/native-x86_64-unknown-linux-musl": "1.51.0-dev.9bcbf1838a"
|
|
95
|
+
}
|
|
6
96
|
}
|
package/src/bindings.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const BLS_VERIFIER_SET_TYPE: {
|
|
2
|
+
readonly indexed: 0;
|
|
3
|
+
readonly aggregate: 1;
|
|
4
|
+
readonly single: 2;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export declare const BLS_VERIFIER_MAX_BATCH_SIZE: 256;
|
|
8
|
+
export declare const BLS_VERIFIER_MAX_SAME_MESSAGE_BATCH_SIZE: 128;
|
|
9
|
+
|
|
10
|
+
export type BlsVerifierSetTypeValue = (typeof BLS_VERIFIER_SET_TYPE)[keyof typeof BLS_VERIFIER_SET_TYPE];
|
|
11
|
+
|
|
12
|
+
export type IndexedSignatureSet = {
|
|
13
|
+
type: typeof BLS_VERIFIER_SET_TYPE.indexed;
|
|
14
|
+
index: number;
|
|
15
|
+
message: Uint8Array;
|
|
16
|
+
signature: Uint8Array;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type AggregateSignatureSet = {
|
|
20
|
+
type: typeof BLS_VERIFIER_SET_TYPE.aggregate;
|
|
21
|
+
indices: Uint32Array;
|
|
22
|
+
message: Uint8Array;
|
|
23
|
+
signature: Uint8Array;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type SingleSignatureSet = {
|
|
27
|
+
type: typeof BLS_VERIFIER_SET_TYPE.single;
|
|
28
|
+
pubkey: Uint8Array;
|
|
29
|
+
message: Uint8Array;
|
|
30
|
+
signature: Uint8Array;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type BlsSignatureSet = IndexedSignatureSet | AggregateSignatureSet | SingleSignatureSet;
|
|
34
|
+
|
|
35
|
+
export type SameMessageSignatureSet = {
|
|
36
|
+
index: number;
|
|
37
|
+
signature: Uint8Array;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Verify signature sets using cached pubkeys for indexed and aggregate sets.
|
|
42
|
+
* The verifier validates every signature before pairing.
|
|
43
|
+
*
|
|
44
|
+
* Returns false as soon as one of these conditions are encountered:
|
|
45
|
+
*
|
|
46
|
+
* - A signature is malformed or cryptographically invalid.
|
|
47
|
+
* - A single set public key is malformed or cryptographically invalid.
|
|
48
|
+
*
|
|
49
|
+
* Throws cache and interface errors when encountered before the result is
|
|
50
|
+
* known.
|
|
51
|
+
*/
|
|
52
|
+
export declare function verifySignatureSets(sets: BlsSignatureSet[]): boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Randomly aggregate and verify cached pubkeys and signatures over one message.
|
|
56
|
+
* The verifier validates every signature.
|
|
57
|
+
*
|
|
58
|
+
* Returns false for an input set when its signature is malformed or cryptographically invalid.
|
|
59
|
+
*
|
|
60
|
+
* Returns one result per input. Invalid interface state throws.
|
|
61
|
+
*/
|
|
62
|
+
export declare function verifySignatureSetsSameMessage(sets: SameMessageSignatureSet[], message: Uint8Array): boolean[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import bindings from "./bindings.js";
|
|
2
|
+
|
|
3
|
+
const blsVerifier = bindings.blsVerifier;
|
|
4
|
+
|
|
5
|
+
/** @type {typeof import("./bls-verifier.d.ts").BLS_VERIFIER_SET_TYPE} */
|
|
6
|
+
export const BLS_VERIFIER_SET_TYPE = blsVerifier.SetType;
|
|
7
|
+
|
|
8
|
+
export const BLS_VERIFIER_MAX_BATCH_SIZE = blsVerifier.MAX_BATCH_SIZE;
|
|
9
|
+
export const BLS_VERIFIER_MAX_SAME_MESSAGE_BATCH_SIZE = blsVerifier.MAX_SAME_MESSAGE_BATCH_SIZE;
|
|
10
|
+
|
|
11
|
+
export const verifySignatureSets = blsVerifier.verifySignatureSets;
|
|
12
|
+
export const verifySignatureSetsSameMessage = blsVerifier.verifySignatureSetsSameMessage;
|
package/src/blst.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
export class PublicKey {
|
|
2
|
+
/** Size of a compressed public key in bytes (48). */
|
|
3
|
+
static readonly COMPRESS_SIZE: number;
|
|
4
|
+
/** Size of an uncompressed public key in bytes (96). */
|
|
5
|
+
static readonly SERIALIZE_SIZE: number;
|
|
6
|
+
/**
|
|
7
|
+
* Deserialize a public key from a byte array.
|
|
8
|
+
*
|
|
9
|
+
* If `pkValidate` is `true`, the public key will be infinity and group checked.
|
|
10
|
+
*/
|
|
11
|
+
static fromBytes(bytes: Uint8Array, pkValidate?: boolean): PublicKey;
|
|
12
|
+
/**
|
|
13
|
+
* Deserialize a public key from a hex string.
|
|
14
|
+
*
|
|
15
|
+
* If `pk_validate` is `true`, the public key will be infinity and group checked.
|
|
16
|
+
*/
|
|
17
|
+
static fromHex(hex: string, pkValidate?: boolean | undefined | null): PublicKey;
|
|
18
|
+
validate(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Serialize a public key to a byte array.
|
|
21
|
+
*
|
|
22
|
+
* If `compress` is `false`, the public key will be serialized in uncompressed form.
|
|
23
|
+
*/
|
|
24
|
+
toBytes(compress?: boolean): Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* Serialize a public key to a 0x-prefixed hex string.
|
|
27
|
+
*
|
|
28
|
+
* If `compress` is `false`, the public key will be serialized in uncompressed form.
|
|
29
|
+
*/
|
|
30
|
+
toHex(compress?: boolean): string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class SecretKey {
|
|
34
|
+
static fromBytes(bytes: Uint8Array): SecretKey;
|
|
35
|
+
static fromHex(hex: string): SecretKey;
|
|
36
|
+
static fromKeygen(ikm: Uint8Array, keyInfo?: Uint8Array): SecretKey;
|
|
37
|
+
/** Sign an exact 32-byte Ethereum consensus signing root. */
|
|
38
|
+
sign(msg: Uint8Array): Signature;
|
|
39
|
+
toPublicKey(): PublicKey;
|
|
40
|
+
toBytes(): Uint8Array;
|
|
41
|
+
/**
|
|
42
|
+
* Serialize a secret key to a 0x-prefixed hex string.
|
|
43
|
+
*/
|
|
44
|
+
toHex(): string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class Signature {
|
|
48
|
+
/** Size of a compressed signature in bytes (96). */
|
|
49
|
+
static readonly COMPRESS_SIZE: number;
|
|
50
|
+
/** Size of an uncompressed signature in bytes (192). */
|
|
51
|
+
static readonly SERIALIZE_SIZE: number;
|
|
52
|
+
/**
|
|
53
|
+
* Deserialize a signature from a byte array.
|
|
54
|
+
*
|
|
55
|
+
* If `sigValidate` is `true`, the public key will be infinity and group checked.
|
|
56
|
+
*
|
|
57
|
+
* If `sigInfcheck` is `false`, the infinity check will be skipped.
|
|
58
|
+
*/
|
|
59
|
+
static fromBytes(bytes: Uint8Array, sigValidate?: boolean, sigInfcheck?: boolean): Signature;
|
|
60
|
+
/**
|
|
61
|
+
* Deserialize a signature from a hex string.
|
|
62
|
+
*
|
|
63
|
+
* If `sig_validate` is `true`, the public key will be infinity and group checked.
|
|
64
|
+
*
|
|
65
|
+
* If `sig_infcheck` is `false`, the infinity check will be skipped.
|
|
66
|
+
*/
|
|
67
|
+
static fromHex(
|
|
68
|
+
hex: string,
|
|
69
|
+
sigValidate?: boolean | undefined | null,
|
|
70
|
+
sigInfcheck?: boolean | undefined | null
|
|
71
|
+
): Signature;
|
|
72
|
+
static aggregate(sigs: Signature[], sigsGroupcheck: boolean): Signature;
|
|
73
|
+
/**
|
|
74
|
+
* Serialize a signature to a byte array.
|
|
75
|
+
*
|
|
76
|
+
* If `compress` is `false`, the signature will be serialized in uncompressed form.
|
|
77
|
+
*/
|
|
78
|
+
toBytes(compress?: boolean): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Serialize a signature to a 0x-prefixed hex string.
|
|
81
|
+
*
|
|
82
|
+
* If `compress` is `false`, the signature will be serialized in uncompressed form.
|
|
83
|
+
*/
|
|
84
|
+
toHex(compress?: boolean): string;
|
|
85
|
+
validate(sigInfcheck: boolean): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SignatureSet {
|
|
89
|
+
/** Exact 32-byte Ethereum consensus signing root. */
|
|
90
|
+
msg: Uint8Array;
|
|
91
|
+
pk: PublicKey;
|
|
92
|
+
sig: Signature;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface PkAndSerializedSig {
|
|
96
|
+
pk: PublicKey;
|
|
97
|
+
sig: Uint8Array;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface PkAndSig {
|
|
101
|
+
pk: PublicKey;
|
|
102
|
+
sig: Signature;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Verify a signature against an exact 32-byte Ethereum consensus signing root and public key.
|
|
107
|
+
*
|
|
108
|
+
* If `pkValidate` is `true`, the public key will be infinity and group checked.
|
|
109
|
+
*
|
|
110
|
+
* If `sigGroupcheck` is `true`, the signature will be group checked.
|
|
111
|
+
*/
|
|
112
|
+
export function verify(
|
|
113
|
+
msg: Uint8Array,
|
|
114
|
+
pk: PublicKey,
|
|
115
|
+
sig: Signature,
|
|
116
|
+
pkValidate?: boolean,
|
|
117
|
+
sigGroupcheck?: boolean
|
|
118
|
+
): boolean;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Verify an aggregated signature against exact 32-byte Ethereum consensus signing roots and multiple public keys.
|
|
122
|
+
*
|
|
123
|
+
* If `pksValidate` is `true`, the public keys will be infinity and group checked.
|
|
124
|
+
*
|
|
125
|
+
* If `sigGroupcheck` is `true`, the signatures will be group checked.
|
|
126
|
+
*/
|
|
127
|
+
export function aggregateVerify(
|
|
128
|
+
msgs: Uint8Array[],
|
|
129
|
+
pks: PublicKey[],
|
|
130
|
+
sig: Signature,
|
|
131
|
+
pksValidate?: boolean,
|
|
132
|
+
sigGroupcheck?: boolean
|
|
133
|
+
): boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Verify an aggregated signature against a single exact 32-byte Ethereum consensus signing root and multiple public keys.
|
|
137
|
+
*
|
|
138
|
+
* Proof-of-possession is required for public keys.
|
|
139
|
+
*
|
|
140
|
+
* If `sigsGroupcheck` is `true`, the signatures will be group checked.
|
|
141
|
+
*/
|
|
142
|
+
export function fastAggregateVerify(
|
|
143
|
+
msg: Uint8Array,
|
|
144
|
+
pks: PublicKey[],
|
|
145
|
+
sig: Signature,
|
|
146
|
+
sigsGroupcheck?: boolean
|
|
147
|
+
): boolean;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Verify multiple aggregated signatures against exact 32-byte Ethereum consensus signing roots and multiple public keys.
|
|
151
|
+
*
|
|
152
|
+
* If `pksValidate` is `true`, the public keys will be infinity and group checked.
|
|
153
|
+
*
|
|
154
|
+
* If `sigsGroupcheck` is `true`, the signatures will be group checked.
|
|
155
|
+
*
|
|
156
|
+
* See https://ethresear.ch/t/fast-verification-of-multiple-bls-signatures/5407
|
|
157
|
+
*/
|
|
158
|
+
export function verifyMultipleAggregateSignatures(
|
|
159
|
+
sets: SignatureSet[],
|
|
160
|
+
pksValidate?: boolean,
|
|
161
|
+
sigsGroupcheck?: boolean
|
|
162
|
+
): boolean;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Aggregate multiple signatures into a single signature.
|
|
166
|
+
*
|
|
167
|
+
* If `sigsGroupcheck` is `true`, the signatures will be group checked.
|
|
168
|
+
*/
|
|
169
|
+
export function aggregateSignatures(signatures: Signature[], sigsGroupcheck?: boolean): Signature;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Aggregate multiple public keys into a single public key.
|
|
173
|
+
*
|
|
174
|
+
* If `pksValidate` is `true`, the public keys will be infinity and group checked.
|
|
175
|
+
*/
|
|
176
|
+
export function aggregatePublicKeys(pks: PublicKey[], pksValidate?: boolean): PublicKey;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Aggregate multiple serialized public keys into a single public key.
|
|
180
|
+
*
|
|
181
|
+
* If `pksValidate` is `true`, the public keys will be infinity and group checked.
|
|
182
|
+
*/
|
|
183
|
+
export function aggregateSerializedPublicKeys(serializedPublicKeys: Uint8Array[], pksValidate?: boolean): PublicKey;
|
package/src/blst.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import bindings from "./bindings.js";
|
|
2
|
+
|
|
3
|
+
const blst = bindings.blst;
|
|
4
|
+
|
|
5
|
+
export const PublicKey = blst.PublicKey;
|
|
6
|
+
export const SecretKey = blst.SecretKey;
|
|
7
|
+
export const Signature = blst.Signature;
|
|
8
|
+
|
|
9
|
+
export const verify = blst.verify;
|
|
10
|
+
export const aggregateVerify = blst.aggregateVerify;
|
|
11
|
+
export const fastAggregateVerify = blst.fastAggregateVerify;
|
|
12
|
+
export const verifyMultipleAggregateSignatures = blst.verifyMultipleAggregateSignatures;
|
|
13
|
+
export const aggregateSignatures = blst.aggregateSignatures;
|
|
14
|
+
export const aggregatePublicKeys = blst.aggregatePublicKeys;
|
|
15
|
+
export const aggregateSerializedPublicKeys = blst.aggregateSerializedPublicKeys;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirrors `ere_verifier_new`'s discriminants.
|
|
3
|
+
*
|
|
4
|
+
* Source: https://github.com/eth-act/ere/blob/332d8b1206a85b111b4051d2f8e7162ed3b3bb33/bindings/c/src/lib.rs#L27-L32
|
|
5
|
+
*/
|
|
6
|
+
export declare const ZKVM_KIND: {
|
|
7
|
+
readonly openvm: 0;
|
|
8
|
+
readonly sp1: 1;
|
|
9
|
+
readonly zisk: 2;
|
|
10
|
+
readonly lambdavm: 3;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ZkvmKindValue = (typeof ZKVM_KIND)[keyof typeof ZKVM_KIND];
|
|
14
|
+
|
|
15
|
+
/** False on targets without a prebuilt ere verifier library; registration then throws. */
|
|
16
|
+
export declare const EXECUTION_PROOF_VERIFIER_AVAILABLE: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* EIP-8025 `MAX_PROOF_SIZE` in bytes.
|
|
20
|
+
*
|
|
21
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/a06852f7fad3d6c4557808f48ad7a32ed7cbf996/specs/_features/eip8025/beacon-chain.md#L74
|
|
22
|
+
*/
|
|
23
|
+
export declare const EXECUTION_PROOF_MAX_SIZE: 4194304;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Binds `proofType` to an ere verifier for `zkvmKind` and `programVk`, once per process.
|
|
27
|
+
* Throws when the proof type is already registered, the kind is unknown, or the key does not decode.
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerExecutionProofVerifier(
|
|
30
|
+
proofType: number,
|
|
31
|
+
zkvmKind: ZkvmKindValue,
|
|
32
|
+
programVk: Uint8Array
|
|
33
|
+
): void;
|
|
34
|
+
|
|
35
|
+
export declare function hasExecutionProofVerifier(proofType: number): boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Verifies `proofData` off the JS thread with the verifier registered for `proofType`.
|
|
39
|
+
*
|
|
40
|
+
* Resolves with the public values the proof commits to, or null when the proof is malformed or
|
|
41
|
+
* does not verify.
|
|
42
|
+
*
|
|
43
|
+
* Rejects for an unregistered proof type, an oversized proof, or an internal
|
|
44
|
+
* verifier failure.
|
|
45
|
+
*/
|
|
46
|
+
export declare function verifyExecutionProof(proofType: number, proofData: Uint8Array): Promise<Uint8Array | null>;
|