From f5d820d3a79d13db89db8d798148a9d054c37e42 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 28 Oct 2024 12:18:59 +0200 Subject: [PATCH 1/2] remove noop from supported operators for onchain v2 circuits --- package-lock.json | 4 ++-- package.json | 2 +- src/proof/provers/inputs-generator.ts | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8dac2adf..dd55360d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.21.0", + "version": "1.21.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.21.0", + "version": "1.21.1", "license": "MIT or Apache-2.0", "dependencies": { "@noble/curves": "^1.4.0", diff --git a/package.json b/package.json index 54816ae6..b180b0ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.21.0", + "version": "1.21.1", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", diff --git a/src/proof/provers/inputs-generator.ts b/src/proof/provers/inputs-generator.ts index 20cd7874..82e79a2e 100644 --- a/src/proof/provers/inputs-generator.ts +++ b/src/proof/provers/inputs-generator.ts @@ -73,14 +73,22 @@ const v2Operations = [ Operators.NIN, Operators.NE ]; +const v2OnChainOperations = [ + Operators.EQ, + Operators.LT, + Operators.GT, + Operators.IN, + Operators.NIN, + Operators.NE +]; export const circuitValidator: { [k in CircuitId]: { maxQueriesCount: number; supportedOperations: Operators[] }; } = { [CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1, supportedOperations: v2Operations }, - [CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2Operations }, + [CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations }, [CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1, supportedOperations: v2Operations }, - [CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2Operations }, + [CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations }, [CircuitId.AtomicQueryV3]: { maxQueriesCount: 1, supportedOperations: allOperations }, [CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1, supportedOperations: allOperations }, [CircuitId.AuthV2]: { maxQueriesCount: 0, supportedOperations: [] }, @@ -296,7 +304,6 @@ export class InputGenerator { circuitInputs.challenge = params.challenge; const query = circuitQueries[0]; - query.operator = this.transformV2QueryOperator(query.operator); circuitInputs.query = query; circuitInputs.claim = { issuerID: circuitClaimData.issuerId, @@ -381,7 +388,6 @@ export class InputGenerator { circuitInputs.skipClaimRevocationCheck = params.skipRevocation; const query = circuitQueries[0]; - query.operator = this.transformV2QueryOperator(query.operator); circuitInputs.query = query; circuitInputs.currentTimeStamp = getUnixTimestamp(new Date()); From 3289c5e05bac96ce8a399874e72c8e1ec49f4333 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 28 Oct 2024 12:43:55 +0200 Subject: [PATCH 2/2] format and unit test --- src/proof/provers/inputs-generator.ts | 10 ++- tests/handlers/contract-request.test.ts | 96 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/proof/provers/inputs-generator.ts b/src/proof/provers/inputs-generator.ts index 82e79a2e..d684d514 100644 --- a/src/proof/provers/inputs-generator.ts +++ b/src/proof/provers/inputs-generator.ts @@ -86,9 +86,15 @@ export const circuitValidator: { [k in CircuitId]: { maxQueriesCount: number; supportedOperations: Operators[] }; } = { [CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1, supportedOperations: v2Operations }, - [CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations }, + [CircuitId.AtomicQueryMTPV2OnChain]: { + maxQueriesCount: 1, + supportedOperations: v2OnChainOperations + }, [CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1, supportedOperations: v2Operations }, - [CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations }, + [CircuitId.AtomicQuerySigV2OnChain]: { + maxQueriesCount: 1, + supportedOperations: v2OnChainOperations + }, [CircuitId.AtomicQueryV3]: { maxQueriesCount: 1, supportedOperations: allOperations }, [CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1, supportedOperations: allOperations }, [CircuitId.AuthV2]: { maxQueriesCount: 0, supportedOperations: [] }, diff --git a/tests/handlers/contract-request.test.ts b/tests/handlers/contract-request.test.ts index 109da2e0..b968a2c8 100644 --- a/tests/handlers/contract-request.test.ts +++ b/tests/handlers/contract-request.test.ts @@ -321,6 +321,102 @@ describe('contract-request', () => { expect((ciResponse as Map).has('txhash1')).to.be.true; }); + it('$noop operator not supported for OnChain V2', async () => { + const { did: userDID, credential: cred } = await idWallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Amoy, + seed: seedPhrase, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }); + + expect(cred).not.to.be.undefined; + + const { did: issuerDID, credential: issuerAuthCredential } = await idWallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Amoy, + seed: seedPhraseIssuer, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }); + expect(issuerAuthCredential).not.to.be.undefined; + + const claimReq: CredentialRequest = { + credentialSchema: + 'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json', + type: 'KYCAgeCredential', + credentialSubject: { + id: userDID.string(), + birthday: 19960424, + documentType: 99 + }, + expiration: 2793526400, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }; + const issuerCred = await idWallet.issueCredential(issuerDID, claimReq); + + await credWallet.save(issuerCred); + + const proofReq: ZeroKnowledgeProofRequest = { + id: 1, + circuitId: CircuitId.AtomicQueryMTPV2OnChain, + optional: false, + query: { + allowedIssuers: ['*'], + type: claimReq.type, + context: + 'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld' + } + }; + + const transactionData: ContractInvokeTransactionData = { + contract_address: '0x134b1be34911e39a8397ec6289782989729807a4', + method_id: 'b68967e2', + chain_id: 80001 + }; + + const ciRequestBody: ContractInvokeRequestBody = { + reason: 'reason', + transaction_data: transactionData, + scope: [proofReq as ZeroKnowledgeProofRequest] + }; + + const id = uuid.v4(); + const ciRequest: ContractInvokeRequest = { + id, + typ: MediaType.PlainMessage, + type: PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE, + thid: id, + body: ciRequestBody + }; + + const ethSigner = new ethers.Wallet(walletKey); + + const options: ContractInvokeHandlerOptions = { + ethSigner, + challenge: BigInt(112312) + }; + const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest)); + + try { + await contractRequestHandler.handleContractInvokeRequest(userDID, msgBytes, options); + expect.fail(); + } catch (err: unknown) { + expect((err as Error).message).to.be.eq( + `operator $noop is not supported by credentialAtomicQueryMTPV2OnChain` + ); + } + }); + // SKIPPED : integration test it.skip('contract request flow - integration test', async () => { const stateEthConfig = defaultEthConnectionConfig;