From 9a4541ec565344745e48d1178319e2b1e203fe04 Mon Sep 17 00:00:00 2001 From: GopherDID <74898029+vmidyllic@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:45:47 +0300 Subject: [PATCH] Fix/skip claim revocation check onchain (#272) * update cross-chain integration test * fix wrong tree state fullfilment * 1.20.2 * you are the most pretty one --------- Co-authored-by: vbasiuk --- package-lock.json | 4 +- package.json | 2 +- src/circuits/atomic-query-sig-v2-on-chain.ts | 18 ++-- tests/handlers/contract-request.test.ts | 86 +++++++++++++------- 4 files changed, 67 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7671e5a..719365d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.20.1", + "version": "1.20.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.20.1", + "version": "1.20.2", "license": "MIT or Apache-2.0", "dependencies": { "@noble/curves": "^1.4.0", diff --git a/package.json b/package.json index db2d9543..bec45ff3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.20.1", + "version": "1.20.2", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", diff --git a/src/circuits/atomic-query-sig-v2-on-chain.ts b/src/circuits/atomic-query-sig-v2-on-chain.ts index c91c17a3..636f4cc8 100644 --- a/src/circuits/atomic-query-sig-v2-on-chain.ts +++ b/src/circuits/atomic-query-sig-v2-on-chain.ts @@ -113,6 +113,10 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { const valueProof = this.query?.valueProof ?? new ValueProof(); + const treeState = this.skipClaimRevocationCheck + ? this.claim.signatureProof?.issuerAuthNonRevProof.treeState + : this.claim.nonRevProof?.treeState; + const s: Partial = { requestID: this.requestID.toString(), userGenesisID: this.id.bigInt().toString(), @@ -120,16 +124,10 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(), issuerID: this.claim.issuerID?.bigInt().toString(), issuerClaim: this.claim.claim?.marshalJson(), - issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot - ?.bigInt() - .toString(), - issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot - ?.bigInt() - .toString(), - issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots - ?.bigInt() - .toString(), - issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(), + issuerClaimNonRevClaimsTreeRoot: treeState?.claimsRoot?.bigInt().toString(), + issuerClaimNonRevRevTreeRoot: treeState?.revocationRoot?.bigInt().toString(), + issuerClaimNonRevRootsTreeRoot: treeState?.rootOfRoots?.bigInt().toString(), + issuerClaimNonRevState: treeState?.state?.bigInt().toString(), issuerClaimNonRevMtp: this.claim.nonRevProof?.proof && prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()), diff --git a/tests/handlers/contract-request.test.ts b/tests/handlers/contract-request.test.ts index ef9142e2..109da2e0 100644 --- a/tests/handlers/contract-request.test.ts +++ b/tests/handlers/contract-request.test.ts @@ -31,7 +31,9 @@ import { ContractInvokeHandlerOptions, ContractInvokeRequest, ContractInvokeRequestBody, + ContractInvokeResponse, ContractInvokeTransactionData, + ContractMessageHandlerOptions, ContractRequestHandler, DataPrepareHandlerFunc, IContractRequestHandler, @@ -54,6 +56,7 @@ import { CredentialStatusResolverRegistry } from '../../src/credentials'; import { RHSResolver } from '../../src/credentials'; import { ethers, JsonRpcProvider, Signer } from 'ethers'; import { registerKeyProvidersInMemoryKMS, RPC_URL } from '../helpers'; +import { AbstractMessageHandler } from '../../src/iden3comm/handlers/message-handler'; describe('contract-request', () => { let idWallet: IdentityWallet; @@ -647,14 +650,34 @@ describe('contract-request', () => { // cross chain integration test it.skip('cross chain contract request flow - integration test', async () => { - const privadoTestRpcUrl = '<>'; // issuer RPC URL - privado test - const privadoTestStateContract = '0x975556428F077dB5877Ea2474D783D6C69233742'; - const amoyVerifierRpcUrl = '<>'; // verifier RPC URL - amoy - const erc20Verifier = '0x74030e4c5d53ef381A889C01f0bBd3B8336F4a4a'; + const privadoTestRpcUrl = '< >'; + const privadoMainRpcUrl = '< >'; + const amoyRpcUrl = '< >'; + const amoyStateContract = '< >'; + const privadoStateContract = '< >'; + const lineaSepoliaRpc = '< >'; + const erc20Verifier = '0xcfe3f46048cb9dAa40c90fd574F6E1deB534b9e7'; + + const issuerAmoyStateEthConfig = { + ...defaultEthConnectionConfig, + url: amoyRpcUrl, + contractAddress: amoyStateContract, + chainId: 80002 + }; - const issuerStateEthConfig = defaultEthConnectionConfig; - issuerStateEthConfig.url = privadoTestRpcUrl; - issuerStateEthConfig.contractAddress = privadoTestStateContract; // privado test state contract + const issuerStateEthConfig = { + ...defaultEthConnectionConfig, + url: privadoTestRpcUrl, + contractAddress: privadoStateContract, + chainId: 21001 + }; + + const userStateEthConfig = { + ...defaultEthConnectionConfig, + url: privadoMainRpcUrl, + contractAddress: privadoStateContract, + chainId: 21000 + }; const kms = registerKeyProvidersInMemoryKMS(); dataStorage = { @@ -664,7 +687,11 @@ describe('contract-request', () => { new InMemoryDataSource() ), mt: new InMemoryMerkleTreeStorage(40), - states: new EthStateStorage(issuerStateEthConfig) + states: new EthStateStorage([ + issuerAmoyStateEthConfig, + userStateEthConfig, + issuerStateEthConfig + ]) }; const circuitStorage = new FSCircuitStorage({ dirname: path.join(__dirname, '../proofs/testdata') @@ -702,8 +729,8 @@ describe('contract-request', () => { const { did: issuerDID, credential: issuerAuthCredential } = await idWallet.createIdentity({ method: DidMethod.Iden3, - blockchain: Blockchain.Privado, - networkId: NetworkId.Test, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Amoy, seed: seedPhraseIssuer, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, @@ -733,27 +760,30 @@ describe('contract-request', () => { const proofReqs: ZeroKnowledgeProofRequest[] = [ { - id: 4, // 2 - mtp, 4 - sig + id: 138, circuitId: CircuitId.AtomicQuerySigV2OnChain, optional: false, query: { + skipClaimRevocationCheck: true, allowedIssuers: ['*'], type: claimReq.type, context: 'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld', credentialSubject: { birthday: { - $lt: 20020101 + $ne: 20500101 } } } } ]; - const conf = defaultEthConnectionConfig; - conf.contractAddress = erc20Verifier; - conf.url = amoyVerifierRpcUrl; - conf.chainId = 80002; // amoy chain id + const conf = { + ...defaultEthConnectionConfig, + contractAddress: erc20Verifier, + url: lineaSepoliaRpc, + chainId: 59141 + }; const zkpVerifier = new OnChainZKPVerifier([conf], { didResolverUrl: 'https://resolver-dev.privado.id' @@ -762,7 +792,7 @@ describe('contract-request', () => { const transactionData: ContractInvokeTransactionData = { contract_address: erc20Verifier, - method_id: 'fd41d8d4', + method_id: 'ade09fcd', chain_id: conf.chainId }; @@ -778,31 +808,27 @@ describe('contract-request', () => { typ: MediaType.PlainMessage, type: PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE, thid: id, - body: ciRequestBody + body: ciRequestBody, + from: 'did:iden3:polygon:amoy:x6x5sor7zpySUbxeFoAZUYbUh68LQ4ipcvJLRYM6c' }; const ethSigner = new ethers.Wallet(walletKey); const challenge = BytesHelper.bytesToInt(hexToBytes(ethSigner.address)); - const options: ContractInvokeHandlerOptions = { + const options: ContractMessageHandlerOptions = { ethSigner, - challenge + challenge, + senderDid: userDID }; - const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest)); - const ciResponse = await contractRequestHandler.handleContractInvokeRequest( - userDID, - msgBytes, + const ciResponse = await (contractRequestHandler as unknown as AbstractMessageHandler).handle( + ciRequest, options ); expect(ciResponse).not.be.undefined; - expect( - ( - (ciResponse as Map).values().next() - .value as ZeroKnowledgeProofResponse - ).id - ).to.be.equal(proofReqs[0].id); + console.log(ciResponse); + expect((ciResponse as unknown as ContractInvokeResponse).body.scope[0].txHash).not.be.undefined; }); it.skip('contract request flow V3 sig `email-verified` Transak req - integration test', async () => {