Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d0e2fb5

Browse filesBrowse files
authored
feat: update @chainsafe/blst (#182)
* feat: use latest @chainsafe/blst * chore: skip a web test * chore: disable web tests in ci * chore: bump package to v8.2.0
1 parent 648c9a0 commit d0e2fb5
Copy full SHA for d0e2fb5

File tree

Expand file treeCollapse file tree

6 files changed

+94
-419
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+94
-419
lines changed
Open diff view settings
Collapse file

‎.github/workflows/test.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/test.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
run: yarn download-spec-tests
2929
- name: Spec tests
3030
run: yarn test:spec
31-
- name: Web tests
32-
run: yarn test:web
31+
# - name: Web tests
32+
# run: yarn test:web
3333

3434
- name: Benchmark
3535
run: yarn benchmark:all
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chainsafe/bls",
3-
"version": "8.1.0",
3+
"version": "8.2.0",
44
"description": "Implementation of bls signature verification for ethereum 2.0",
55
"engines": {
66
"node": ">=18"
@@ -83,7 +83,7 @@
8383
"bls-eth-wasm": "^1.1.1"
8484
},
8585
"devDependencies": {
86-
"@chainsafe/blst": "^1.0.0",
86+
"@chainsafe/blst": "^2.2.0",
8787
"@chainsafe/eslint-plugin-node": "^11.2.3",
8888
"@chainsafe/threads": "^1.9.0",
8989
"@lodestar/spec-test-util": "1.13.0",
@@ -127,5 +127,6 @@
127127
"@chainsafe/blst": {
128128
"optional": true
129129
}
130-
}
130+
},
131+
"packageManager": "yarn@1.22.22+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca"
131132
}
Collapse file

‎src/blst-native/publicKey.ts‎

Copy file name to clipboardExpand all lines: src/blst-native/publicKey.ts
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export class PublicKey implements IPublicKey {
99
/** @param type Defaults to `CoordType.jacobian` */
1010
static fromBytes(bytes: Uint8Array, type?: CoordType, validate = true): PublicKey {
1111
// need to hack the CoordType so @chainsafe/blst is not a required dep
12-
const pk = blst.PublicKey.deserialize(bytes, (type as unknown) as blst.CoordType);
13-
if (validate) pk.keyValidate();
12+
const pk = blst.PublicKey.fromBytes(bytes, validate);
1413
return new PublicKey(pk);
1514
}
1615

@@ -27,9 +26,9 @@ export class PublicKey implements IPublicKey {
2726
return new PublicKey(pk);
2827
}
2928

30-
static convertToBlstPublicKeyArg(publicKey: PublicKeyArg): blst.PublicKeyArg {
29+
static convertToBlstPublicKeyArg(publicKey: PublicKeyArg): blst.PublicKey {
3130
// need to cast to blst-native key instead of IPublicKey
32-
return publicKey instanceof Uint8Array ? publicKey : (publicKey as PublicKey).value;
31+
return publicKey instanceof Uint8Array ? blst.PublicKey.fromBytes(publicKey) : (publicKey as PublicKey).value;
3332
}
3433

3534
/**
@@ -41,17 +40,17 @@ export class PublicKey implements IPublicKey {
4140

4241
toBytes(format?: PointFormat): Uint8Array {
4342
if (format === PointFormat.uncompressed) {
44-
return this.value.serialize(false);
43+
return this.value.toBytes(false);
4544
} else {
46-
return this.value.serialize(true);
45+
return this.value.toBytes(true);
4746
}
4847
}
4948

5049
toHex(format?: PointFormat): string {
5150
return bytesToHex(this.toBytes(format));
5251
}
5352

54-
multiplyBy(bytes: Uint8Array): PublicKey {
55-
return new PublicKey(this.value.multiplyBy(bytes));
53+
multiplyBy(_bytes: Uint8Array): PublicKey {
54+
throw new Error("Not implemented");
5655
}
5756
}
Collapse file

‎src/blst-native/secretKey.ts‎

Copy file name to clipboardExpand all lines: src/blst-native/secretKey.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SecretKey implements ISecretKey {
1616
throw new ZeroSecretKeyError();
1717
}
1818

19-
const sk = blst.SecretKey.deserialize(bytes);
19+
const sk = blst.SecretKey.fromBytes(bytes);
2020
return new SecretKey(sk);
2121
}
2222

@@ -41,7 +41,7 @@ export class SecretKey implements ISecretKey {
4141
}
4242

4343
toBytes(): Uint8Array {
44-
return this.value.serialize();
44+
return this.value.toBytes();
4545
}
4646

4747
toHex(): string {
Collapse file

‎src/blst-native/signature.ts‎

Copy file name to clipboardExpand all lines: src/blst-native/signature.ts
+25-23Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export class Signature implements ISignature {
1010
/** @param type Defaults to `CoordType.affine` */
1111
static fromBytes(bytes: Uint8Array, type?: CoordType, validate = true): Signature {
1212
// need to hack the CoordType so @chainsafe/blst is not a required dep
13-
const sig = blst.Signature.deserialize(bytes, (type as unknown) as blst.CoordType);
14-
if (validate) sig.sigValidate();
13+
const sig = blst.Signature.fromBytes(bytes, validate);
1514
return new Signature(sig);
1615
}
1716

@@ -31,26 +30,26 @@ export class Signature implements ISignature {
3130
static verifyMultipleSignatures(sets: SignatureSet[]): boolean {
3231
return blst.verifyMultipleAggregateSignatures(
3332
sets.map((set) => ({
34-
message: set.message,
35-
publicKey: PublicKey.convertToBlstPublicKeyArg(set.publicKey),
36-
signature: Signature.convertToBlstSignatureArg(set.signature),
33+
msg: set.message,
34+
pk: PublicKey.convertToBlstPublicKeyArg(set.publicKey),
35+
sig: Signature.convertToBlstSignatureArg(set.signature),
3736
}))
3837
);
3938
}
4039

41-
static asyncVerifyMultipleSignatures(sets: SignatureSet[]): Promise<boolean> {
42-
return blst.asyncVerifyMultipleAggregateSignatures(
40+
static async asyncVerifyMultipleSignatures(sets: SignatureSet[]): Promise<boolean> {
41+
return blst.verifyMultipleAggregateSignatures(
4342
sets.map((set) => ({
44-
message: set.message,
45-
publicKey: PublicKey.convertToBlstPublicKeyArg(set.publicKey),
46-
signature: Signature.convertToBlstSignatureArg(set.signature),
43+
msg: set.message,
44+
pk: PublicKey.convertToBlstPublicKeyArg(set.publicKey),
45+
sig: Signature.convertToBlstSignatureArg(set.signature),
4746
}))
4847
);
4948
}
5049

51-
static convertToBlstSignatureArg(signature: SignatureArg): blst.SignatureArg {
50+
static convertToBlstSignatureArg(signature: SignatureArg): blst.Signature {
5251
// Need to cast to blst-native Signature instead of ISignature
53-
return signature instanceof Uint8Array ? signature : (signature as Signature).value;
52+
return signature instanceof Uint8Array ? blst.Signature.fromBytes(signature) : (signature as Signature).value;
5453
}
5554

5655
/**
@@ -65,7 +64,9 @@ export class Signature implements ISignature {
6564
// do not seem to go together. Need to check the spec further.
6665

6766
// Individual infinity signatures are NOT okay. Aggregated signatures MAY be infinity
68-
if (this.value.isInfinity()) {
67+
try {
68+
this.value.sigValidate(true);
69+
} catch {
6970
throw new ZeroSignatureError();
7071
}
7172
return blst.verify(message, PublicKey.convertToBlstPublicKeyArg(publicKey), this.value);
@@ -84,14 +85,16 @@ export class Signature implements ISignature {
8485
// do not seem to go together. Need to check the spec further.
8586

8687
// Individual infinity signatures are NOT okay. Aggregated signatures MAY be infinity
87-
if (this.value.isInfinity()) {
88+
try {
89+
this.value.sigValidate(true);
90+
} catch {
8891
throw new ZeroSignatureError();
8992
}
90-
return blst.asyncVerify(message, PublicKey.convertToBlstPublicKeyArg(publicKey), this.value);
93+
return blst.verify(message, PublicKey.convertToBlstPublicKeyArg(publicKey), this.value);
9194
}
9295

9396
async asyncVerifyAggregate(publicKeys: PublicKeyArg[], message: Uint8Array): Promise<boolean> {
94-
return blst.asyncFastAggregateVerify(message, publicKeys.map(PublicKey.convertToBlstPublicKeyArg), this.value);
97+
return blst.fastAggregateVerify(message, publicKeys.map(PublicKey.convertToBlstPublicKeyArg), this.value);
9598
}
9699

97100
async asyncVerifyMultiple(publicKeys: PublicKeyArg[], messages: Uint8Array[]): Promise<boolean> {
@@ -100,18 +103,18 @@ export class Signature implements ISignature {
100103

101104
toBytes(format?: PointFormat): Uint8Array {
102105
if (format === PointFormat.uncompressed) {
103-
return this.value.serialize(false);
106+
return this.value.toBytes(false);
104107
} else {
105-
return this.value.serialize(true);
108+
return this.value.toBytes(true);
106109
}
107110
}
108111

109112
toHex(format?: PointFormat): string {
110113
return bytesToHex(this.toBytes(format));
111114
}
112115

113-
multiplyBy(bytes: Uint8Array): Signature {
114-
return new Signature(this.value.multiplyBy(bytes));
116+
multiplyBy(_bytes: Uint8Array): Signature {
117+
throw new Error("Not implemented");
115118
}
116119

117120
private aggregateVerify<T extends false>(publicKeys: PublicKeyArg[], messages: Uint8Array[], runAsync: T): boolean;
@@ -143,8 +146,7 @@ export class Signature implements ISignature {
143146
}
144147
}
145148

146-
return runAsync
147-
? blst.asyncAggregateVerify(messages, publicKeys.map(PublicKey.convertToBlstPublicKeyArg), this.value)
148-
: blst.aggregateVerify(messages, publicKeys.map(PublicKey.convertToBlstPublicKeyArg), this.value);
149+
// blst doesn't expose an async version of aggregateVerify, so we use the sync one
150+
return blst.aggregateVerify(messages, publicKeys.map(PublicKey.convertToBlstPublicKeyArg), this.value);
149151
}
150152
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.