@@ -112,7 +112,7 @@ async function decodeSignature(signature: string): Promise<Uint8Array> {
112112 * @param registryBaseUrl - Base URL of the registry service
113113 * @returns The public key in multibase format
114114 */
115- async function getPublicKey ( eName : string , registryBaseUrl : string ) : Promise < string > {
115+ async function getPublicKey ( eName : string , registryBaseUrl : string ) : Promise < string | null > {
116116 // Step 1: Resolve eVault URL from registry
117117 const resolveUrl = new URL ( `/resolve?w3id=${ encodeURIComponent ( eName ) } ` , registryBaseUrl ) . toString ( ) ;
118118 const resolveResponse = await axios . get ( resolveUrl , {
@@ -136,7 +136,7 @@ async function getPublicKey(eName: string, registryBaseUrl: string): Promise<str
136136
137137 const publicKey = whoisResponse . data ?. publicKey ;
138138 if ( ! publicKey ) {
139- throw new Error ( `No public key found for eName: ${ eName } ` ) ;
139+ return null
140140 }
141141
142142 return publicKey ;
@@ -199,24 +199,21 @@ export async function verifySignature(
199199 }
200200
201201 // Get public key from eVault
202- console . log ( "[DEBUG] Step 1: Fetching public key from eVault..." ) ;
203- const publicKeyMultibase = await getPublicKey ( eName , registryBaseUrl ) ;
204- console . log ( `[DEBUG] Public key retrieved (full): ${ publicKeyMultibase } ` ) ;
205- console . log ( `[DEBUG] Public key starts with 'z': ${ publicKeyMultibase . startsWith ( 'z' ) } ` ) ;
202+ const publicKeyMultibase = await getPublicKey ( eName , registryBaseUrl )
206203
204+ if ( ! publicKeyMultibase ) {
205+ return {
206+ valid : true ,
207+ } ;
208+ }
207209 // Decode the public key
208- console . log ( "[DEBUG] Step 2: Decoding public key..." ) ;
209210 const publicKeyBytes = await decodeMultibasePublicKey ( publicKeyMultibase ) ;
210- console . log ( `[DEBUG] Public key bytes length: ${ publicKeyBytes . length } ` ) ;
211- console . log ( `[DEBUG] Public key bytes (hex, first 100 chars): ${ Buffer . from ( publicKeyBytes ) . toString ( 'hex' ) . substring ( 0 , 100 ) } ...` ) ;
212- console . log ( `[DEBUG] Public key bytes (base64): ${ Buffer . from ( publicKeyBytes ) . toString ( 'base64' ) } ` ) ;
213211
214212 // Import the public key for Web Crypto API
215213 // The public key is in SPKI format (SubjectPublicKeyInfo)
216214 // Create a new ArrayBuffer from the Uint8Array
217215 const publicKeyBuffer = new Uint8Array ( publicKeyBytes ) . buffer ;
218216
219- console . log ( "[DEBUG] Step 3: Importing public key into Web Crypto API..." ) ;
220217 let publicKey ;
221218 try {
222219 publicKey = await crypto . subtle . importKey (
@@ -229,31 +226,21 @@ export async function verifySignature(
229226 false ,
230227 [ "verify" ]
231228 ) ;
232- console . log ( "[DEBUG] Public key imported successfully" ) ;
233229 } catch ( importError ) {
234230 console . error ( `[DEBUG] Failed to import public key: ${ importError instanceof Error ? importError . message : String ( importError ) } ` ) ;
235231 throw importError ;
236232 }
237233
238234 // Decode the signature
239- console . log ( "[DEBUG] Step 4: Decoding signature..." ) ;
240235 const signatureBytes = await decodeSignature ( signature ) ;
241- console . log ( `[DEBUG] Signature bytes length: ${ signatureBytes . length } ` ) ;
242- console . log ( `[DEBUG] Signature bytes (hex): ${ Buffer . from ( signatureBytes ) . toString ( 'hex' ) } ` ) ;
243236
244237 // Convert payload to ArrayBuffer
245- console . log ( "[DEBUG] Step 5: Encoding payload..." ) ;
246238 const payloadBuffer = new TextEncoder ( ) . encode ( payload ) ;
247- console . log ( `[DEBUG] Payload: "${ payload } "` ) ;
248- console . log ( `[DEBUG] Payload bytes length: ${ payloadBuffer . byteLength } ` ) ;
249- console . log ( `[DEBUG] Payload bytes (hex): ${ Buffer . from ( payloadBuffer ) . toString ( 'hex' ) } ` ) ;
250239
251240 // Create a new ArrayBuffer from the signature Uint8Array
252241 const signatureBuffer = new Uint8Array ( signatureBytes ) . buffer ;
253242
254243 // Verify the signature
255- console . log ( "[DEBUG] Step 6: Verifying signature with Web Crypto API..." ) ;
256- console . log ( `[DEBUG] Algorithm: ECDSA with P-256 curve, SHA-256 hash` ) ;
257244 const isValid = await crypto . subtle . verify (
258245 {
259246 name : "ECDSA" ,
@@ -263,7 +250,6 @@ export async function verifySignature(
263250 signatureBuffer ,
264251 payloadBuffer
265252 ) ;
266- console . log ( `[DEBUG] Verification result: ${ isValid ? "VALID" : "INVALID" } ` ) ;
267253
268254 return {
269255 valid : isValid ,
0 commit comments