@@ -10,7 +10,8 @@ import {
10
10
RandomnessBeacon ,
11
11
G2UnchainedBeacon ,
12
12
isG1G2SwappedBeacon ,
13
- G1UnchainedBeacon
13
+ G1UnchainedBeacon ,
14
+ isG1Rfc9380
14
15
} from './index'
15
16
16
17
async function verifyBeacon ( chainInfo : ChainInfo , beacon : RandomnessBeacon ) : Promise < boolean > {
@@ -32,6 +33,10 @@ async function verifyBeacon(chainInfo: ChainInfo, beacon: RandomnessBeacon): Pro
32
33
return verifySigOnG1 ( beacon . signature , await unchainedBeaconMessage ( beacon ) , publicKey )
33
34
}
34
35
36
+ if ( isG1Rfc9380 ( beacon , chainInfo ) ) {
37
+ return verifySigOnG1 ( beacon . signature , await unchainedBeaconMessage ( beacon ) , publicKey , 'BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_' )
38
+ }
39
+
35
40
console . error ( `Beacon type ${ chainInfo . schemeID } was not supported` )
36
41
return false
37
42
@@ -49,13 +54,19 @@ function normP2(point: G2Hex): PointG2 {
49
54
return point instanceof PointG2 ? point : PointG2 . fromHex ( point ) ;
50
55
}
51
56
52
- async function normP1Hash ( point : G1Hex ) : Promise < PointG1 > {
53
- return point instanceof PointG1 ? point : PointG1 . hashToCurve ( point ) ;
57
+ async function normP1Hash ( point : G1Hex , domainSeparationTag : string ) : Promise < PointG1 > {
58
+ return point instanceof PointG1 ? point : PointG1 . hashToCurve ( point , { DST : domainSeparationTag } ) ;
54
59
}
55
60
56
- export async function verifySigOnG1 ( signature : G1Hex , message : G1Hex , publicKey : G2Hex ) : Promise < boolean > {
61
+ export async function verifySigOnG1 (
62
+ signature : G1Hex ,
63
+ message : G1Hex ,
64
+ publicKey : G2Hex ,
65
+ // default DST is the invalid one used for 'bls-unchained-on-g1' for backwards compat
66
+ domainSeparationTag = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_'
67
+ ) : Promise < boolean > {
57
68
const P = normP2 ( publicKey ) ;
58
- const Hm = await normP1Hash ( message ) ;
69
+ const Hm = await normP1Hash ( message , domainSeparationTag ) ;
59
70
const G = PointG2 . BASE ;
60
71
const S = normP1 ( signature ) ;
61
72
const ePHm = pairing ( Hm , P . negate ( ) , false ) ;
0 commit comments