Skip to content

Commit

Permalink
Fix/skip claim revocation check onchain (#272)
Browse files Browse the repository at this point in the history
* update cross-chain integration test

* fix wrong tree state fullfilment

* 1.20.2

* you are the most pretty one

---------

Co-authored-by: vbasiuk <[email protected]>
  • Loading branch information
vmidyllic and volodymyr-basiuk committed Sep 30, 2024
1 parent c945356 commit f7f18dd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 40 deletions.
18 changes: 8 additions & 10 deletions src/circuits/atomic-query-sig-v2-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,21 @@ 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<AtomicQuerySigV2OnChainCircuitInputs> = {
requestID: this.requestID.toString(),
userGenesisID: this.id.bigInt().toString(),
profileNonce: this.profileNonce.toString(),
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()),
Expand Down
86 changes: 56 additions & 30 deletions tests/handlers/contract-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import {
ContractInvokeHandlerOptions,
ContractInvokeRequest,
ContractInvokeRequestBody,
ContractInvokeResponse,
ContractInvokeTransactionData,
ContractMessageHandlerOptions,
ContractRequestHandler,
DataPrepareHandlerFunc,
IContractRequestHandler,
Expand All @@ -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;
Expand Down Expand Up @@ -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 = {
Expand All @@ -664,7 +687,11 @@ describe('contract-request', () => {
new InMemoryDataSource<Profile>()
),
mt: new InMemoryMerkleTreeStorage(40),
states: new EthStateStorage(issuerStateEthConfig)
states: new EthStateStorage([
issuerAmoyStateEthConfig,
userStateEthConfig,
issuerStateEthConfig
])
};
const circuitStorage = new FSCircuitStorage({
dirname: path.join(__dirname, '../proofs/testdata')
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand All @@ -762,7 +792,7 @@ describe('contract-request', () => {

const transactionData: ContractInvokeTransactionData = {
contract_address: erc20Verifier,
method_id: 'fd41d8d4',
method_id: 'ade09fcd',
chain_id: conf.chainId
};

Expand All @@ -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<string, ZeroKnowledgeProofResponse>).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 () => {
Expand Down

0 comments on commit f7f18dd

Please sign in to comment.