1+ import { p256 } from '@noble/curves/p256' ;
2+ import { p384 } from '@noble/curves/p384' ;
3+ import { secp256k1 } from '@noble/curves/secp256k1' ;
14import { hexToBytes } from '@noble/hashes/utils' ;
25
36import { UnknownSignatureError } from '@lit-protocol/constants' ;
4- import {
5- curveFunctions ,
6- hashLitMessage ,
7- verifyLitSignature ,
8- } from '@lit-protocol/crypto' ;
7+ import { hashLitMessage } from '@lit-protocol/crypto' ;
98import { log } from '@lit-protocol/misc' ;
10- import { SigType } from '@lit-protocol/types' ;
9+ import { EcdsaSigType , SigType } from '@lit-protocol/types' ;
1110
1211import { getEoaAuthContext } from 'local-tests/setup/session-sigs/get-eoa-session-sigs' ;
1312import { TinnyEnvironment } from 'local-tests/setup/tinny-environment' ;
@@ -19,6 +18,13 @@ interface SigningSchemeConfig {
1918 signingScheme : SigType ;
2019}
2120
21+ // Map the right curve function per signing scheme
22+ export const ecdsaCurveFunctions : Record < EcdsaSigType , any > = {
23+ EcdsaK256Sha256 : secp256k1 ,
24+ EcdsaP256Sha256 : p256 ,
25+ EcdsaP384Sha384 : p384 ,
26+ } as const ;
27+
2228/**
2329 * Test Commands:
2430 * ✅ NETWORK=naga-dev yarn test:local --filter=testUseEoaSessionSigsToPkpSign
@@ -32,9 +38,13 @@ export const testUseEoaSessionSigsToPkpSign = async (
3238 const signingSchemeConfigs : SigningSchemeConfig [ ] = [
3339 // BLS
3440 // {
35- // signingScheme: 'Bls12381G1ProofOfPossession ', // TODO pkpSignature.signature: '{ProofOfPossession:984ffb9ef7a0e6225dd074bade4b9494fab3487ff543f25a90d86f794cbf190ed20179df6eb6dd3eb9a285838d3cf4980e5e7028688e0461bd1cb95c075046fcafa343d3702e7edff70fb8eb8ada130f58fa45140ab2d90f24b1309b026d98d6}'
41+ // signingScheme: 'Bls12381 ', // TODO nodes accept this signing scheme but they throw an unexpected error
3642 // hashesMessage: false,
3743 // },
44+ {
45+ signingScheme : 'Bls12381G1ProofOfPossession' ,
46+ hashesMessage : false ,
47+ } ,
3848 // ECDSA
3949 {
4050 hasRecoveryId : true ,
@@ -59,49 +69,48 @@ export const testUseEoaSessionSigsToPkpSign = async (
5969 signingScheme : 'SchnorrEd25519Sha512' ,
6070 hashesMessage : false ,
6171 } ,
62- // {
63- // signingScheme: 'SchnorrK256Sha256', // TODO signature of length 64 expected, got 65
64- // hashesMessage: false,
65- // },
66- // {
67- // signingScheme: 'SchnorrP256Sha256', // TODO Expected pkpSignature to consistently verify its components
68- // hashesMessage: false,
69- // },
70- // {
71- // signingScheme: 'SchnorrP384Sha384', // TODO Expected pkpSignature to consistently verify its components
72- // hashesMessage: false,
73- // },
74- // {
75- // signingScheme: 'SchnorrRistretto25519Sha512', // TODO curve.verify is not a function
76- // hashesMessage: false,
77- // },
72+ {
73+ signingScheme : 'SchnorrK256Sha256' ,
74+ hashesMessage : false ,
75+ } ,
76+ {
77+ signingScheme : 'SchnorrP256Sha256' ,
78+ hashesMessage : false ,
79+ } ,
80+ {
81+ signingScheme : 'SchnorrP384Sha384' ,
82+ hashesMessage : false ,
83+ } ,
84+ {
85+ signingScheme : 'SchnorrRistretto25519Sha512' ,
86+ hashesMessage : false ,
87+ } ,
7888 {
7989 signingScheme : 'SchnorrEd448Shake256' ,
8090 hashesMessage : false ,
8191 } ,
82- // {
83- // signingScheme: 'SchnorrRedJubjubBlake2b512', // TODO Expected pkpSignature to consistently verify its components
84- // hashesMessage: false,
85- // },
86- // {
87- // signingScheme: 'SchnorrK256Taproot', // TODO Expected pkpSignature to consistently verify its components
88- // hashesMessage: false,
89- // },
90- // {
91- // signingScheme: 'SchnorrRedDecaf377Blake2b512', // TODO Expected pkpSignature to consistently verify its components
92- // hashesMessage: false,
93- // },
94- // {
95- // signingScheme: 'SchnorrkelSubstrate', // TODO Expected pkpSignature to consistently verify its components
96- // hashesMessage: false,
97- // },
92+ {
93+ signingScheme : 'SchnorrRedJubjubBlake2b512' ,
94+ hashesMessage : false ,
95+ } ,
96+ {
97+ signingScheme : 'SchnorrK256Taproot' ,
98+ hashesMessage : false ,
99+ } ,
100+ {
101+ signingScheme : 'SchnorrRedDecaf377Blake2b512' ,
102+ hashesMessage : false ,
103+ } ,
104+ {
105+ signingScheme : 'SchnorrkelSubstrate' ,
106+ hashesMessage : false ,
107+ } ,
98108 ] ;
99109
100110 for ( const signingSchemeConfig of signingSchemeConfigs ) {
101111 try {
102112 const signingScheme = signingSchemeConfig . signingScheme ;
103113 log ( `Checking testUseEoaSessionSigsToPkpSign for ${ signingSchemeConfig } ` ) ;
104- // const eoaSessionSigs = await getEoaSessionSigs(devEnv, alice);
105114
106115 const pkpSignature = await devEnv . litNodeClient . pkpSign ( {
107116 pubKey : alice . pkp . publicKey ,
@@ -119,6 +128,15 @@ export const testUseEoaSessionSigsToPkpSign = async (
119128 'signedData' ,
120129 'publicKey' ,
121130 ] ) {
131+ // Bls12381G1ProofOfPossession signature is a json string with ProofOfPossession, not an hex signature
132+ if (
133+ signingScheme === 'Bls12381G1ProofOfPossession' &&
134+ hexString === 'signature' &&
135+ pkpSignature . signature . startsWith ( '{' )
136+ ) {
137+ continue ;
138+ }
139+
122140 if (
123141 ! pkpSignature [ hexString ] ||
124142 ! pkpSignature [ hexString ] . startsWith ( '0x' )
@@ -139,21 +157,8 @@ export const testUseEoaSessionSigsToPkpSign = async (
139157 ) ;
140158 }
141159
142- // Signature, public key and signed data verification
143- const signatureVerification = verifyLitSignature (
144- signingSchemeConfig . signingScheme ,
145- pkpSignature . publicKey . replace ( '0x' , '' ) ,
146- pkpSignature . signedData . replace ( '0x' , '' ) ,
147- pkpSignature . signature . replace ( '0x' , '' )
148- ) ;
149- if ( ! signatureVerification ) {
150- throw new Error (
151- `Expected pkpSignature to consistently verify its components. Signing Scheme: ${ signingScheme } `
152- ) ;
153- }
154-
155160 if ( signingSchemeConfig . recoversPublicKey ) {
156- const curve = curveFunctions [ signingScheme ] ;
161+ const curve = ecdsaCurveFunctions [ signingScheme ] ;
157162 const signatureBytes = hexToBytes (
158163 pkpSignature . signature . replace ( / ^ 0 x / , '' )
159164 ) ;
@@ -182,7 +187,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
182187 }
183188
184189 const messageHash = signingSchemeConfig . hashesMessage
185- ? hashLitMessage ( signingScheme , alice . loveLetter )
190+ ? hashLitMessage ( signingScheme as EcdsaSigType , alice . loveLetter )
186191 : alice . loveLetter ;
187192 const messageHashHex = Buffer . from ( messageHash ) . toString ( 'hex' ) ;
188193 if ( pkpSignature . signedData . replace ( '0x' , '' ) !== messageHashHex ) {
0 commit comments