Skip to content

Commit f6355df

Browse files
authored
Fix V3 onchain proof generation (#187)
1 parent 36ddc67 commit f6355df

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@0xpolygonid/js-sdk",
3-
"version": "1.8.0",
3+
"version": "1.8.1",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/node/cjs/index.js",
66
"module": "dist/node/esm/index.js",

Diff for: src/circuits/atomic-query-v3-on-chain.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getNodeAuxValue,
88
prepareCircuitArrayValues
99
} from './common';
10-
import { CircuitError, GISTProof, Query, TreeState, ValueProof } from './models';
10+
import { BJJSignatureProof, CircuitError, GISTProof, Query, TreeState, ValueProof } from './models';
1111
import { Hash, Proof, ZERO_HASH } from '@iden3/js-merkletree';
1212
import { byteDecoder, byteEncoder } from '../utils';
1313
import { ClaimWithSigAndMTPProof } from './atomic-query-v3';
@@ -175,7 +175,10 @@ export class AtomicQueryV3OnChainInputs extends BaseConfig {
175175
valueProof.mtp = new Proof();
176176
}
177177

178-
const treeState = this.claim.nonRevProof.treeState;
178+
let treeState = this.claim.nonRevProof.treeState;
179+
if (this.proofType === ProofType.BJJSignature && this.skipClaimRevocationCheck) {
180+
treeState = this.claim.signatureProof?.issuerAuthNonRevProof.treeState;
181+
}
179182

180183
if (!treeState) {
181184
throw new Error(CircuitError.EmptyTreeState);
@@ -243,38 +246,41 @@ export class AtomicQueryV3OnChainInputs extends BaseConfig {
243246
}
244247

245248
if (this.proofType === ProofType.BJJSignature) {
249+
const sigProof = this.claim.signatureProof as BJJSignatureProof;
246250
s.proofType = '1';
247251

248-
s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
249-
s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
250-
s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
251-
s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
252+
s.issuerClaimSignatureR8x = sigProof.signature.R8[0].toString();
253+
s.issuerClaimSignatureR8y = sigProof.signature.R8[1].toString();
254+
s.issuerClaimSignatureS = sigProof.signature.S.toString();
255+
s.issuerAuthClaim = sigProof.issuerAuthClaim?.marshalJson();
252256
s.issuerAuthClaimMtp = prepareSiblingsStr(
253-
this.claim.signatureProof?.issuerAuthIncProof.proof as Proof,
257+
sigProof.issuerAuthIncProof.proof as Proof,
254258
this.getMTLevel()
255259
);
256260
const issuerAuthTreeState = this.claim.nonRevProof.treeState;
257261

258262
if (!issuerAuthTreeState) {
259263
throw new Error(CircuitError.EmptyTreeState);
260264
}
261-
s.issuerAuthClaimsTreeRoot = issuerAuthTreeState.claimsRoot.bigInt().toString();
262-
s.issuerAuthRevTreeRoot = issuerAuthTreeState.revocationRoot.bigInt().toString();
263-
s.issuerAuthRootsTreeRoot = issuerAuthTreeState.rootOfRoots.bigInt().toString();
265+
s.issuerAuthClaimsTreeRoot = sigProof.issuerAuthIncProof.treeState?.claimsRoot
266+
.bigInt()
267+
.toString();
268+
s.issuerAuthRevTreeRoot = sigProof.issuerAuthIncProof.treeState?.revocationRoot
269+
.bigInt()
270+
.toString();
271+
s.issuerAuthRootsTreeRoot = sigProof.issuerAuthIncProof.treeState?.rootOfRoots
272+
.bigInt()
273+
.toString();
264274
s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(
265-
this.claim.signatureProof?.issuerAuthNonRevProof.proof as Proof,
275+
sigProof.issuerAuthNonRevProof.proof as Proof,
266276
this.getMTLevel()
267277
);
268278

269-
const nodeAuxIssuerAuthNonRev = getNodeAuxValue(
270-
this.claim.signatureProof?.issuerAuthNonRevProof.proof
271-
);
279+
const nodeAuxIssuerAuthNonRev = getNodeAuxValue(sigProof.issuerAuthNonRevProof.proof);
272280
s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
273281
s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
274282
s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
275-
s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
276-
.bigInt()
277-
.toString();
283+
s.issuerAuthState = sigProof.issuerAuthIncProof.treeState?.state.bigInt().toString();
278284

279285
this.fillMTPProofsWithZero(s);
280286
} else if (this.proofType === ProofType.Iden3SparseMerkleTreeProof) {

Diff for: tests/handlers/contract-request.test.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { InMemoryPrivateKeyStore } from '../../src/kms/store';
1717
import { IDataStorage, IStateStorage, IOnChainZKPVerifier } from '../../src/storage/interfaces';
1818
import { InMemoryDataSource, InMemoryMerkleTreeStorage } from '../../src/storage/memory';
1919
import { CredentialRequest, CredentialWallet } from '../../src/credentials';
20-
import { ProofService } from '../../src/proof';
20+
import { IProofService, ProofService } from '../../src/proof';
2121
import { CircuitId } from '../../src/circuits';
2222
import { CredentialStatusType, VerifiableConstants, W3CCredential } from '../../src/verifiable';
2323
import { RootInfo, StateProof } from '../../src/storage/entities/state';
@@ -50,14 +50,15 @@ import { expect } from 'chai';
5050
import { CredentialStatusResolverRegistry } from '../../src/credentials';
5151
import { RHSResolver } from '../../src/credentials';
5252
import { ethers, Signer } from 'ethers';
53+
import { RHS_URL, WALLET_KEY } from '../helpers';
5354

5455
describe('contract-request', () => {
5556
let idWallet: IdentityWallet;
5657
let credWallet: CredentialWallet;
5758

5859
let dataStorage: IDataStorage;
59-
let proofService: ProofService;
60-
let contractRequest: IContractRequestHandler;
60+
let proofService: IProofService;
61+
let contractRequestHandler: IContractRequestHandler;
6162
let packageMgr: IPackageManager;
6263
const rhsUrl = process.env.RHS_URL as string;
6364
const rpcUrl = process.env.RPC_URL as string;
@@ -191,7 +192,7 @@ describe('contract-request', () => {
191192
proofService.generateAuthV2Inputs.bind(proofService),
192193
proofService.verifyState.bind(proofService)
193194
);
194-
contractRequest = new ContractRequestHandler(packageMgr, proofService, mockZKPVerifier);
195+
contractRequestHandler = new ContractRequestHandler(packageMgr, proofService, mockZKPVerifier);
195196
});
196197

197198
it('contract request flow', async () => {
@@ -284,7 +285,7 @@ describe('contract-request', () => {
284285
challenge: BigInt(112312)
285286
};
286287
const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest));
287-
const ciResponse = await contractRequest.handleContractInvokeRequest(
288+
const ciResponse = await contractRequestHandler.handleContractInvokeRequest(
288289
userDID,
289290
msgBytes,
290291
options
@@ -332,7 +333,6 @@ describe('contract-request', () => {
332333
proofService.generateAuthV2Inputs.bind(proofService),
333334
proofService.verifyState.bind(proofService)
334335
);
335-
contractRequest = new ContractRequestHandler(packageMgr, proofService, mockZKPVerifier);
336336

337337
const { did: userDID, credential: cred } = await idWallet.createIdentity({
338338
method: DidMethod.Iden3,
@@ -402,7 +402,7 @@ describe('contract-request', () => {
402402
conf.chainId = 80001;
403403

404404
const zkpVerifier = new OnChainZKPVerifier([conf]);
405-
contractRequest = new ContractRequestHandler(packageMgr, proofService, zkpVerifier);
405+
contractRequestHandler = new ContractRequestHandler(packageMgr, proofService, zkpVerifier);
406406

407407
const transactionData: ContractInvokeTransactionData = {
408408
contract_address: contractAddress,
@@ -434,7 +434,7 @@ describe('contract-request', () => {
434434
challenge
435435
};
436436
const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest));
437-
const ciResponse = await contractRequest.handleContractInvokeRequest(
437+
const ciResponse = await contractRequestHandler.handleContractInvokeRequest(
438438
userDID,
439439
msgBytes,
440440
options
@@ -484,7 +484,6 @@ describe('contract-request', () => {
484484
proofService.generateAuthV2Inputs.bind(proofService),
485485
proofService.verifyState.bind(proofService)
486486
);
487-
contractRequest = new ContractRequestHandler(packageMgr, proofService, mockZKPVerifier);
488487

489488
const { did: userDID, credential: cred } = await idWallet.createIdentity({
490489
method: DidMethod.Iden3,
@@ -531,7 +530,7 @@ describe('contract-request', () => {
531530
await credWallet.save(issuerCred);
532531

533532
const proofReq: ZeroKnowledgeProofRequest = {
534-
id: 1,
533+
id: 200,
535534
circuitId: CircuitId.AtomicQueryV3OnChain,
536535
optional: false,
537536
query: {
@@ -547,14 +546,14 @@ describe('contract-request', () => {
547546
}
548547
};
549548

550-
const contractAddress = '0x6Ee102705DD27c1025fc03E5Db375BAe1c237432';
549+
const contractAddress = '0xD0Fd3E9fDF448e5B86Cc0f73E5Ee7D2F284884c0';
551550
const conf = defaultEthConnectionConfig;
552551
conf.contractAddress = contractAddress;
553552
conf.url = rpcUrl;
554553
conf.chainId = 80001;
555554

556555
const zkpVerifier = new OnChainZKPVerifier([conf]);
557-
contractRequest = new ContractRequestHandler(packageMgr, proofService, zkpVerifier);
556+
contractRequestHandler = new ContractRequestHandler(packageMgr, proofService, zkpVerifier);
558557

559558
const transactionData: ContractInvokeTransactionData = {
560559
contract_address: contractAddress,
@@ -586,7 +585,7 @@ describe('contract-request', () => {
586585
challenge
587586
};
588587
const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest));
589-
const ciResponse = await contractRequest.handleContractInvokeRequest(
588+
const ciResponse = await contractRequestHandler.handleContractInvokeRequest(
590589
userDID,
591590
msgBytes,
592591
options

0 commit comments

Comments
 (0)