Skip to content

Commit 3289c5e

Browse files
format and unit test
1 parent f5d820d commit 3289c5e

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

src/proof/provers/inputs-generator.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ export const circuitValidator: {
8686
[k in CircuitId]: { maxQueriesCount: number; supportedOperations: Operators[] };
8787
} = {
8888
[CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1, supportedOperations: v2Operations },
89-
[CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations },
89+
[CircuitId.AtomicQueryMTPV2OnChain]: {
90+
maxQueriesCount: 1,
91+
supportedOperations: v2OnChainOperations
92+
},
9093
[CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1, supportedOperations: v2Operations },
91-
[CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1, supportedOperations: v2OnChainOperations },
94+
[CircuitId.AtomicQuerySigV2OnChain]: {
95+
maxQueriesCount: 1,
96+
supportedOperations: v2OnChainOperations
97+
},
9298
[CircuitId.AtomicQueryV3]: { maxQueriesCount: 1, supportedOperations: allOperations },
9399
[CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1, supportedOperations: allOperations },
94100
[CircuitId.AuthV2]: { maxQueriesCount: 0, supportedOperations: [] },

tests/handlers/contract-request.test.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,102 @@ describe('contract-request', () => {
321321
expect((ciResponse as Map<string, ZeroKnowledgeProofResponse>).has('txhash1')).to.be.true;
322322
});
323323

324+
it('$noop operator not supported for OnChain V2', async () => {
325+
const { did: userDID, credential: cred } = await idWallet.createIdentity({
326+
method: DidMethod.Iden3,
327+
blockchain: Blockchain.Polygon,
328+
networkId: NetworkId.Amoy,
329+
seed: seedPhrase,
330+
revocationOpts: {
331+
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
332+
id: rhsUrl
333+
}
334+
});
335+
336+
expect(cred).not.to.be.undefined;
337+
338+
const { did: issuerDID, credential: issuerAuthCredential } = await idWallet.createIdentity({
339+
method: DidMethod.Iden3,
340+
blockchain: Blockchain.Polygon,
341+
networkId: NetworkId.Amoy,
342+
seed: seedPhraseIssuer,
343+
revocationOpts: {
344+
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
345+
id: rhsUrl
346+
}
347+
});
348+
expect(issuerAuthCredential).not.to.be.undefined;
349+
350+
const claimReq: CredentialRequest = {
351+
credentialSchema:
352+
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json',
353+
type: 'KYCAgeCredential',
354+
credentialSubject: {
355+
id: userDID.string(),
356+
birthday: 19960424,
357+
documentType: 99
358+
},
359+
expiration: 2793526400,
360+
revocationOpts: {
361+
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
362+
id: rhsUrl
363+
}
364+
};
365+
const issuerCred = await idWallet.issueCredential(issuerDID, claimReq);
366+
367+
await credWallet.save(issuerCred);
368+
369+
const proofReq: ZeroKnowledgeProofRequest = {
370+
id: 1,
371+
circuitId: CircuitId.AtomicQueryMTPV2OnChain,
372+
optional: false,
373+
query: {
374+
allowedIssuers: ['*'],
375+
type: claimReq.type,
376+
context:
377+
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld'
378+
}
379+
};
380+
381+
const transactionData: ContractInvokeTransactionData = {
382+
contract_address: '0x134b1be34911e39a8397ec6289782989729807a4',
383+
method_id: 'b68967e2',
384+
chain_id: 80001
385+
};
386+
387+
const ciRequestBody: ContractInvokeRequestBody = {
388+
reason: 'reason',
389+
transaction_data: transactionData,
390+
scope: [proofReq as ZeroKnowledgeProofRequest]
391+
};
392+
393+
const id = uuid.v4();
394+
const ciRequest: ContractInvokeRequest = {
395+
id,
396+
typ: MediaType.PlainMessage,
397+
type: PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE,
398+
thid: id,
399+
body: ciRequestBody
400+
};
401+
402+
const ethSigner = new ethers.Wallet(walletKey);
403+
404+
const options: ContractInvokeHandlerOptions = {
405+
ethSigner,
406+
challenge: BigInt(112312)
407+
};
408+
const msgBytes = byteEncoder.encode(JSON.stringify(ciRequest));
409+
410+
try {
411+
await contractRequestHandler.handleContractInvokeRequest(userDID, msgBytes, options);
412+
expect.fail();
413+
} catch (err: unknown) {
414+
expect((err as Error).message).to.be.eq(
415+
`operator $noop is not supported by credentialAtomicQueryMTPV2OnChain`
416+
);
417+
}
418+
});
419+
324420
// SKIPPED : integration test
325421
it.skip('contract request flow - integration test', async () => {
326422
const stateEthConfig = defaultEthConnectionConfig;

0 commit comments

Comments
 (0)