@@ -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