Skip to content

Commit

Permalink
return verification result (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk authored Aug 3, 2023
1 parent 2b951b5 commit 9d19a79
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.0.1",
"version": "1.0.2",
"description": "SDK to work with Polygon ID",
"main": "dist/cjs/index.js",
"module": "dist/esm_esbuild/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/proof/prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ export class NativeProver implements IZKProver {
throw new Error(`verification file doesn't exist for circuit ${circuitId}`);
}

await snarkjs.groth16.verify(
const result = await snarkjs.groth16.verify(
JSON.parse(byteDecoder.decode(circuitData.verificationKey)),
zkp.pub_signals,
zkp.proof
);

// we need to terminate curve manually
await this.terminateCurve();
return true;

return result;
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
Expand Down
29 changes: 28 additions & 1 deletion tests/proofs/sig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,36 @@ describe('sig proofs', () => {
const creds = await credWallet.findByQuery(req.body.scope[0].query);
expect(creds.length).to.not.equal(0);

const { proof, vp } = await proofService.generateProof(req.body.scope[0], userDID);
const { proof, vp, circuitId, pub_signals } = await proofService.generateProof(
req.body.scope[0],
userDID
);
expect(proof).not.to.be.undefined;
expect(vp).to.be.undefined;

const isValid = await proofService.verifyProof(
{
proof,
pub_signals
},
circuitId as CircuitId
);

expect(isValid).to.be.true;

const pi_a = ['99', ...proof.pi_a.slice(1)];
const isNotValid = await proofService.verifyProof(
{
proof: {
...proof,
pi_a
},
pub_signals
},
circuitId as CircuitId
);

expect(isNotValid).to.be.false;
});

it('sigv2 vp-credential', async () => {
Expand Down
2 changes: 1 addition & 1 deletion types/snarkjs.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'snarkjs' {
export namespace groth16 {
export function verify(verKey: object, pubSignals: string[], proof: object): Promise<void>;
export function verify(verKey: object, pubSignals: string[], proof: object): Promise<boolean>;

export function prove(
provingKey: object,
Expand Down

0 comments on commit 9d19a79

Please sign in to comment.