Skip to content

Commit 27dd49f

Browse files
committed
use raw C types
1 parent d20d683 commit 27dd49f

File tree

4 files changed

+226
-109
lines changed

4 files changed

+226
-109
lines changed

bun/src/binding.ts

Lines changed: 210 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,220 @@
1+
12
// This file is auto-generated by @chainsafe/bun-ffi-z. Do not edit.
23

34
import path from "node:path";
4-
import {openLibrary} from "@chainsafe/bun-ffi-z";
5+
import { openLibrary } from "@chainsafe/bun-ffi-z";
56

67
const fns = {
7-
secretKeyFromBytes: {
8-
args: ["ptr", "ptr", "u32"],
9-
returns: "u32",
10-
},
11-
secretKeyToBytes: {
12-
args: ["ptr", "ptr"],
13-
returns: "void",
14-
},
15-
secretKeyKeyGen: {
16-
args: ["ptr", "ptr", "u32"],
17-
returns: "u32",
18-
},
19-
secretKeyKeyGenV3: {
20-
args: ["ptr", "ptr", "u32"],
21-
returns: "u32",
22-
},
23-
secretKeyKeyGenV45: {
24-
args: ["ptr", "ptr", "u32", "ptr", "u32"],
25-
returns: "u32",
26-
},
27-
secretKeyDeriveMasterEip2333: {
28-
args: ["ptr", "ptr", "u32"],
29-
returns: "u32",
30-
},
31-
secretKeyDeriveChildEip2333: {
32-
args: ["ptr", "ptr", "u32"],
33-
returns: "u32",
34-
},
35-
secretKeyToPublicKey: {
36-
args: ["ptr", "ptr"],
37-
returns: "void",
38-
},
39-
secretKeySign: {
40-
args: ["ptr", "ptr", "ptr", "u32"],
41-
returns: "u32",
42-
},
43-
publicKeyFromBytes: {
44-
args: ["ptr", "ptr", "u32"],
45-
returns: "u32",
46-
},
47-
publicKeyToBytes: {
48-
args: ["ptr", "ptr"],
49-
returns: "void",
50-
},
51-
publicKeyValidate: {
52-
args: ["ptr"],
53-
returns: "u32",
54-
},
55-
aggregateWithRandomness: {
56-
args: ["ptr", "ptr", "u32", "ptr", "ptr", "bool", "bool"],
57-
returns: "u32",
58-
},
59-
publicKeyAggregateWithRandomness: {
60-
args: ["ptr", "ptr", "u32", "bool"],
61-
returns: "u32",
62-
},
63-
publicKeyAggregate: {
64-
args: ["ptr", "ptr", "u32", "bool"],
65-
returns: "u32",
66-
},
67-
signatureFromBytes: {
68-
args: ["ptr", "ptr", "u32"],
69-
returns: "u32",
70-
},
71-
signatureToBytes: {
72-
args: ["ptr", "ptr"],
73-
returns: "void",
74-
},
75-
signatureValidate: {
76-
args: ["ptr", "bool"],
77-
returns: "u32",
78-
},
79-
signatureVerify: {
80-
args: ["ptr", "bool", "ptr", "u32", "ptr", "bool"],
81-
returns: "u32",
82-
},
83-
signatureAggregateVerify: {
84-
args: ["ptr", "bool", "ptr", "ptr", "u32", "bool"],
85-
returns: "u32",
86-
},
87-
signatureFastAggregateVerify: {
88-
args: ["ptr", "bool", "ptr", "ptr", "u32"],
89-
returns: "u32",
90-
},
91-
signatureVerifyMultipleAggregateSignatures: {
92-
args: ["u32", "ptr", "ptr", "bool", "ptr", "bool"],
93-
returns: "u32",
94-
},
95-
signatureAggregateWithRandomness: {
96-
args: ["ptr", "ptr", "u32", "bool"],
97-
returns: "u32",
98-
},
99-
signatureAggregate: {
100-
args: ["ptr", "ptr", "u32", "bool"],
101-
returns: "u32",
102-
},
8+
"secretKeyFromBytes": {
9+
"args": [
10+
"ptr",
11+
"ptr",
12+
"u32"
13+
],
14+
"returns": "u32"
15+
},
16+
"secretKeyToBytes": {
17+
"args": [
18+
"ptr",
19+
"ptr"
20+
],
21+
"returns": "void"
22+
},
23+
"secretKeyKeyGen": {
24+
"args": [
25+
"ptr",
26+
"ptr",
27+
"u32"
28+
],
29+
"returns": "u32"
30+
},
31+
"secretKeyKeyGenV3": {
32+
"args": [
33+
"ptr",
34+
"ptr",
35+
"u32"
36+
],
37+
"returns": "u32"
38+
},
39+
"secretKeyKeyGenV45": {
40+
"args": [
41+
"ptr",
42+
"ptr",
43+
"u32",
44+
"ptr",
45+
"u32"
46+
],
47+
"returns": "u32"
48+
},
49+
"secretKeyDeriveMasterEip2333": {
50+
"args": [
51+
"ptr",
52+
"ptr",
53+
"u32"
54+
],
55+
"returns": "u32"
56+
},
57+
"secretKeyDeriveChildEip2333": {
58+
"args": [
59+
"ptr",
60+
"ptr",
61+
"u32"
62+
],
63+
"returns": "u32"
64+
},
65+
"secretKeyToPublicKey": {
66+
"args": [
67+
"ptr",
68+
"ptr"
69+
],
70+
"returns": "void"
71+
},
72+
"secretKeySign": {
73+
"args": [
74+
"ptr",
75+
"ptr",
76+
"ptr",
77+
"u32"
78+
],
79+
"returns": "u32"
80+
},
81+
"publicKeyFromBytes": {
82+
"args": [
83+
"ptr",
84+
"ptr",
85+
"u32"
86+
],
87+
"returns": "u32"
88+
},
89+
"publicKeyToBytes": {
90+
"args": [
91+
"ptr",
92+
"ptr"
93+
],
94+
"returns": "void"
95+
},
96+
"publicKeyValidate": {
97+
"args": [
98+
"ptr"
99+
],
100+
"returns": "u32"
101+
},
102+
"aggregateWithRandomness": {
103+
"args": [
104+
"ptr",
105+
"ptr",
106+
"u32",
107+
"ptr",
108+
"ptr",
109+
"bool",
110+
"bool"
111+
],
112+
"returns": "u32"
113+
},
114+
"publicKeyAggregateWithRandomness": {
115+
"args": [
116+
"ptr",
117+
"ptr",
118+
"u32",
119+
"bool"
120+
],
121+
"returns": "u32"
122+
},
123+
"publicKeyAggregate": {
124+
"args": [
125+
"ptr",
126+
"ptr",
127+
"u32",
128+
"bool"
129+
],
130+
"returns": "u32"
131+
},
132+
"signatureFromBytes": {
133+
"args": [
134+
"ptr",
135+
"ptr",
136+
"u32"
137+
],
138+
"returns": "u32"
139+
},
140+
"signatureToBytes": {
141+
"args": [
142+
"ptr",
143+
"ptr"
144+
],
145+
"returns": "void"
146+
},
147+
"signatureValidate": {
148+
"args": [
149+
"ptr",
150+
"bool"
151+
],
152+
"returns": "u32"
153+
},
154+
"signatureVerify": {
155+
"args": [
156+
"ptr",
157+
"bool",
158+
"ptr",
159+
"u32",
160+
"ptr",
161+
"bool"
162+
],
163+
"returns": "u32"
164+
},
165+
"signatureAggregateVerify": {
166+
"args": [
167+
"ptr",
168+
"bool",
169+
"ptr",
170+
"ptr",
171+
"u32",
172+
"bool"
173+
],
174+
"returns": "u32"
175+
},
176+
"signatureFastAggregateVerify": {
177+
"args": [
178+
"ptr",
179+
"bool",
180+
"ptr",
181+
"ptr",
182+
"u32"
183+
],
184+
"returns": "u32"
185+
},
186+
"signatureVerifyMultipleAggregateSignatures": {
187+
"args": [
188+
"u32",
189+
"ptr",
190+
"ptr",
191+
"bool",
192+
"ptr",
193+
"bool"
194+
],
195+
"returns": "u32"
196+
},
197+
"signatureAggregateWithRandomness": {
198+
"args": [
199+
"ptr",
200+
"ptr",
201+
"u32",
202+
"bool"
203+
],
204+
"returns": "u32"
205+
},
206+
"signatureAggregate": {
207+
"args": [
208+
"ptr",
209+
"ptr",
210+
"u32",
211+
"bool"
212+
],
213+
"returns": "u32"
214+
}
103215
} as const;
104216
const lib = await openLibrary(path.join(import.meta.dirname, ".."), fns);
105217

106218
export const binding = lib.symbols;
107219
export const close = lib.close;
220+

src/PublicKey.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//! BLS public key for G1 operations.
1+
//! BLS public key in the 'minimal-pubkey-size' setting.
2+
//!
3+
//! In this setting, a `PublicKey` is `p1_affine` point.
4+
//! Source: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-00#section-2.1
25

3-
pub const Point = c.blst_p1_affine;
4-
5-
point: Point = Point{},
6+
point: c.blst_p1_affine = c.blst_p1_affine{},
67

78
pub const COMPRESS_SIZE = 48;
89
pub const SERIALIZE_SIZE = 96;

src/Signature.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
pub const Point = c.blst_p2_affine;
1+
//! BLS signatures in the 'minimal-pubkey-size' setting.
2+
//!
3+
//! In this setting, a `Signature` is `p2_affine` point.
4+
//! Source: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-00#section-2.1
25

3-
point: Point = Point{},
6+
point: c.blst_p2_affine = c.blst_p2_affine{},
47

58
const Self = @This();
69

src/eth_c_abi.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export fn publicKeyAggregateWithRandomness(
176176
/// Aggregate multiple `blst.PublicKey`s.
177177
///
178178
/// Returns 0 on success, error code on failure.
179-
export fn publicKeyAggregate(out: *PublicKey, pks: [*c]const PublicKey.Point, len: c_uint, pks_validate: bool) c_uint {
179+
export fn publicKeyAggregate(out: *PublicKey, pks: [*c]const c.blst_p1_affine, len: c_uint, pks_validate: bool) c_uint {
180180
const agg_pk = blst.AggregatePublicKey.aggregate(@ptrCast(pks[0..len]), pks_validate) catch |e| return intFromError(e);
181181
out.* = agg_pk.toPublicKey();
182182

@@ -232,10 +232,10 @@ export fn signatureVerify(
232232
///
233233
/// Returns 0 if verification succeeds, 1 if verification fails, error code on error.
234234
export fn signatureAggregateVerify(
235-
sig: *const Signature.Point,
235+
sig: *const c.blst_p2_affine,
236236
sig_groupcheck: bool,
237237
msgs: [*c]const [32]u8,
238-
pks: [*c]const PublicKey.Point,
238+
pks: [*c]const c.blst_p1_affine,
239239
len: c_uint,
240240
pks_validate: bool,
241241
) c_uint {
@@ -258,7 +258,7 @@ export fn signatureFastAggregateVerify(
258258
sig: *const Signature,
259259
sig_groupcheck: bool,
260260
msg: *[32]u8,
261-
pks: [*c]const PublicKey.Point,
261+
pks: [*c]const c.blst_p1_affine,
262262
pks_len: c_uint,
263263
) c_uint {
264264
const res = sig.fastAggregateVerify(
@@ -277,7 +277,7 @@ export fn signatureFastAggregateVerify(
277277
export fn signatureVerifyMultipleAggregateSignatures(
278278
n_elems: c_uint,
279279
msgs: [*c]const [32]u8,
280-
pks: [*c]const *blst.PublicKey.Point,
280+
pks: [*c]const *c.blst_p1_affine,
281281
pks_validate: bool,
282282
sigs: [*c]const *Signature,
283283
sig_groupcheck: bool,
@@ -344,7 +344,7 @@ export fn signatureAggregateWithRandomness(
344344
/// Returns 0 on success, error code on failure.
345345
export fn signatureAggregate(
346346
out: *Signature,
347-
sigs: [*c]const Signature.Point,
347+
sigs: [*c]const c.blst_p2_affine,
348348
len: c_uint,
349349
sigs_groupcheck: bool,
350350
) c_uint {

0 commit comments

Comments
 (0)