fix: add more validation to inputs

This commit is contained in:
Arseniy Klempner 2025-12-15 17:39:56 -08:00
parent 08e26da876
commit f97eb56f48
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B

View File

@ -37,7 +37,7 @@ export class Zerokit {
return IdentityCredential.fromBytes(memKeys);
}
public async serializeWitness(
private async serializeWitness(
idSecretHash: Uint8Array,
pathElements: Uint8Array[],
identityPathIndex: Uint8Array[],
@ -113,6 +113,12 @@ export class Zerokit {
);
}
if (messageId < 0 || messageId >= rateLimit) {
throw new Error(
`messageId must be an integer between 0 and ${rateLimit - 1}, got ${messageId}`
);
}
const serializedWitness = await this.serializeWitness(
idSecretHash,
pathElements,
@ -143,6 +149,12 @@ export class Zerokit {
): boolean {
if (signalLength.length !== 8)
throw new Error("signalLength must be 8 bytes");
if (proof.length !== 288) throw new Error("proof must be 288 bytes");
if (roots.length == 0) throw new Error("roots array is empty");
if (roots.find((root) => root.length !== 32)) {
throw new Error("All roots must be 32 bytes");
}
return zerokitRLN.verifyWithRoots(
this.zkRLN,
BytesUtils.concatenate(proof, signalLength, signal),