From 9bb65cba9a36b5e9bee7574705b981848550c551 Mon Sep 17 00:00:00 2001 From: yushihang Date: Sun, 31 Mar 2024 12:04:40 +0800 Subject: [PATCH] Add error handling for missing properties in pubSignals as mtpv2Verify() --- src/proof/verifiers/pub-signals-verifier.ts | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/proof/verifiers/pub-signals-verifier.ts b/src/proof/verifiers/pub-signals-verifier.ts index ad6a1787..42988fa5 100644 --- a/src/proof/verifiers/pub-signals-verifier.ts +++ b/src/proof/verifiers/pub-signals-verifier.ts @@ -170,6 +170,14 @@ export class PubSignalsVerifier { byteEncoder.encode(JSON.stringify(pubSignals)) ); + if (!sigV2PubSignals.userID) { + throw new Error('user id is not presented in proof public signals'); + } + + if (!sigV2PubSignals.requestID) { + throw new Error('requestId is not presented in proof public signals'); + } + this.userId = sigV2PubSignals.userID; this.challenge = sigV2PubSignals.requestID; @@ -224,6 +232,14 @@ export class PubSignalsVerifier { let v3PubSignals = new AtomicQueryV3PubSignals(); v3PubSignals = v3PubSignals.pubSignalsUnmarshal(byteEncoder.encode(JSON.stringify(pubSignals))); + if (!v3PubSignals.userID) { + throw new Error('user id is not presented in proof public signals'); + } + + if (!v3PubSignals.requestID) { + throw new Error('requestId is not presented in proof public signals'); + } + this.userId = v3PubSignals.userID; this.challenge = v3PubSignals.requestID; @@ -388,6 +404,14 @@ export class PubSignalsVerifier { byteEncoder.encode(JSON.stringify(pubSignals)) ); + if (!authV2PubSignals.userID) { + throw new Error('user id is not presented in proof public signals'); + } + + if (!authV2PubSignals.challenge) { + throw new Error('challenge is not presented in proof public signals'); + } + this.userId = authV2PubSignals.userID; this.challenge = authV2PubSignals.challenge;