-
Notifications
You must be signed in to change notification settings - Fork 44
validate provingMethodAlg #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,10 +42,9 @@ export class DefaultZKPPacker extends ZKPPacker { | |
| * @throws If the circuit data (proving key or wasm) is not found for the given circuit ID. | ||
| */ | ||
| async pack(payload: Uint8Array, params: ZKPPackerParams): Promise<Uint8Array> { | ||
| const provingMethodAlg = params.provingMethodAlg; | ||
| const circuitId = provingMethodAlg.circuitId as CircuitId; | ||
| const provingParamsKey = provingMethodAlg.toString(); | ||
|
|
||
| this.validateZKPPackerParams(params); | ||
| const provingParamsKey = params.provingMethodAlg.toString(); | ||
| const circuitId = params.provingMethodAlg.circuitId; | ||
| if (!this.provingParamsMap.has(provingParamsKey)) { | ||
| const { provingKey, wasm } = await this.circuitStorage.loadCircuitData( | ||
| circuitId as CircuitId, | ||
|
Comment on lines
+47
to
50
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,6 +128,7 @@ export class ZKPPacker implements IPacker { | |||||||||||||||||||||||||||||||||||||
| * @returns `Promise<Uint8Array>` | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| async pack(payload: Uint8Array, params: ZKPPackerParams): Promise<Uint8Array> { | ||||||||||||||||||||||||||||||||||||||
| this.validateZKPPackerParams(params); | ||||||||||||||||||||||||||||||||||||||
| const provingMethod = await getProvingMethod(params.provingMethodAlg); | ||||||||||||||||||||||||||||||||||||||
| const provingParams = this.provingParamsMap.get(params.provingMethodAlg.toString()); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -229,6 +230,19 @@ export class ZKPPacker implements IPacker { | |||||||||||||||||||||||||||||||||||||
| !alg?.length || alg.some((a) => supportedAlgArr.includes(a as AcceptJwzAlgorithms)); | ||||||||||||||||||||||||||||||||||||||
| return algSupported && circuitIdSupported; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| protected validateZKPPackerParams(value: ZKPPackerParams) { | ||||||||||||||||||||||||||||||||||||||
| const { provingMethodAlg } = value; | ||||||||||||||||||||||||||||||||||||||
| if (!(provingMethodAlg instanceof ProvingMethodAlg)) { | ||||||||||||||||||||||||||||||||||||||
| throw new TypeError('provingMethodAlg must be an instance of ProvingMethodAlg'); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (!provingMethodAlg.alg) { | ||||||||||||||||||||||||||||||||||||||
| throw new Error(`provingMethodAlg.alg is required and must be a non-empty string`); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (!provingMethodAlg.circuitId) { | ||||||||||||||||||||||||||||||||||||||
| throw new Error(`provingMethodAlg.circuitId is required and must be a non-empty string`); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+239
to
+243
|
||||||||||||||||||||||||||||||||||||||
| if (!provingMethodAlg.alg) { | |
| throw new Error(`provingMethodAlg.alg is required and must be a non-empty string`); | |
| } | |
| if (!provingMethodAlg.circuitId) { | |
| throw new Error(`provingMethodAlg.circuitId is required and must be a non-empty string`); | |
| if ( | |
| typeof provingMethodAlg.alg !== 'string' || | |
| provingMethodAlg.alg.trim() === '' | |
| ) { | |
| throw new TypeError('provingMethodAlg.alg is required and must be a non-empty string'); | |
| } | |
| if ( | |
| typeof provingMethodAlg.circuitId !== 'string' || | |
| provingMethodAlg.circuitId.trim() === '' | |
| ) { | |
| throw new TypeError( | |
| 'provingMethodAlg.circuitId is required and must be a non-empty string' | |
| ); |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new validation logic lacks test coverage. Consider adding tests that verify the validation correctly handles invalid inputs such as: 1) provingMethodAlg that is not an instance of ProvingMethodAlg, 2) provingMethodAlg with missing or empty alg property, 3) provingMethodAlg with missing or empty circuitId property. Tests should verify that the appropriate error types and messages are thrown in each case. The existing test file tests/iden3comm/zkp.test.ts would be an appropriate location for these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation is called here and then again in the parent class's pack method at line 131 of zkp.ts, resulting in redundant validation. Consider removing this call since the parent class already performs the validation, or remove the validation from the parent class if you want each subclass to control its own validation timing.