Skip to content

Commit

Permalink
chore: add type ZeroKnowledgeProofQuery to scope.query (#274)
Browse files Browse the repository at this point in the history
* add types ZeroKnowledgeProofQuer and DIDDocument
  • Loading branch information
volodymyr-basiuk authored Sep 30, 2024
1 parent 9a4541e commit a33feb4
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.20.2",
"version": "1.20.3",
"description": "SDK to work with Polygon ID",
"main": "dist/node/cjs/index.js",
"module": "dist/node/esm/index.js",
Expand Down
7 changes: 4 additions & 3 deletions src/iden3comm/handlers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getRandomBytes } from '@iden3/js-crypto';
import {
JsonDocumentObject,
JWSPackerParams,
ZeroKnowledgeProofQuery,
ZeroKnowledgeProofRequest,
ZeroKnowledgeProofResponse
} from '../types';
Expand All @@ -18,11 +19,11 @@ import { Signer } from 'ethers';
* Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
*
* @param requestScope - An array of ZeroKnowledgeProofRequest objects.
* @returns A Map<number, { query: JsonDocumentObject; linkNonce: number }> representing the grouped queries.
* @returns A Map<number, { query: ZeroKnowledgeProofQuery; linkNonce: number }> representing the grouped queries.
*/
const getGroupedQueries = (
requestScope: ZeroKnowledgeProofRequest[]
): Map<number, { query: JsonDocumentObject; linkNonce: number }> =>
): Map<number, { query: ZeroKnowledgeProofQuery; linkNonce: number }> =>
requestScope.reduce((acc, proofReq) => {
const groupId = proofReq.query.groupId as number | undefined;
if (!groupId) {
Expand Down Expand Up @@ -54,7 +55,7 @@ const getGroupedQueries = (
});

return acc;
}, new Map<number, { query: JsonDocumentObject; linkNonce: number }>());
}, new Map<number, { query: ZeroKnowledgeProofQuery; linkNonce: number }>());

/**
* Processes zero knowledge proof requests.
Expand Down
3 changes: 2 additions & 1 deletion src/iden3comm/handlers/credential-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BasicMessage,
CredentialOffer,
CredentialsOfferMessage,
DIDDocument,
IPackageManager,
JsonDocumentObject,
PackerParams
Expand All @@ -26,7 +27,7 @@ import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handl
export type ProposalRequestCreationOptions = {
credentials: ProposalRequestCredential[];
metadata?: { type: string; data?: JsonDocumentObject };
did_doc?: JsonDocumentObject;
did_doc?: DIDDocument;
};

/**
Expand Down
38 changes: 34 additions & 4 deletions src/iden3comm/types/protocol/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ZKProof } from '@iden3/js-jwz';
import { BasicMessage, JsonDocumentObject } from '../packer';
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
import { ProofType } from '../../../verifiable';
import { CircuitId } from '../../../circuits';
import {
DIDDocument as DidResolverDidDocument,
VerificationMethod as DidResolverVerificationMethod
} from 'did-resolver';
import { RootInfo, StateInfo } from '../../../storage';

/** AuthorizationResponseMessage is struct the represents iden3message authorization response */
export type AuthorizationResponseMessage = BasicMessage & {
Expand All @@ -12,7 +19,7 @@ export type AuthorizationResponseMessage = BasicMessage & {

/** AuthorizationMessageResponseBody is struct the represents authorization response data */
export type AuthorizationMessageResponseBody = {
did_doc?: JsonDocumentObject;
did_doc?: DIDDocument;
message?: string;
scope: Array<ZeroKnowledgeProofResponse>;
};
Expand All @@ -29,21 +36,32 @@ export type AuthorizationRequestMessageBody = {
callbackUrl: string;
reason?: string;
message?: string;
did_doc?: JsonDocumentObject;
did_doc?: DIDDocument;
scope: Array<ZeroKnowledgeProofRequest>;
};

/** ZeroKnowledgeProofRequest represents structure of zkp request object */
export type ZeroKnowledgeProofRequest = {
id: number;
circuitId: string;
circuitId: CircuitId;
optional?: boolean;
query: JsonDocumentObject;
query: ZeroKnowledgeProofQuery;
params?: {
nullifierSessionId?: string | number;
};
};

/** ZeroKnowledgeProofQuery represents structure of zkp request query object */
export type ZeroKnowledgeProofQuery = {
allowedIssuers: string[];
context: string;
credentialSubject?: JsonDocumentObject;
proofType?: ProofType;
skipClaimRevocationCheck?: boolean;
groupId?: number;
type: string;
};

/** ZeroKnowledgeProofResponse represents structure of zkp response */
export type ZeroKnowledgeProofResponse = {
id: number;
Expand All @@ -61,3 +79,15 @@ export type VerifiablePresentation = {
credentialSubject: JsonDocumentObject;
};
};

/** DIDDocument represents structure of DID Document */
export type DIDDocument = DidResolverDidDocument & {
verificationMethod?: VerificationMethod[];
};

/** VerificationMethod represents structure of Verification Method */
export type VerificationMethod = DidResolverVerificationMethod & {
published?: boolean;
info?: StateInfo;
global?: RootInfo;
};
4 changes: 2 additions & 2 deletions src/iden3comm/types/protocol/proposal-request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicMessage, JsonDocumentObject } from '../';
import { BasicMessage, DIDDocument, JsonDocumentObject } from '../';
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';

/** @beta ProposalRequestMessage is struct the represents proposal-request message */
Expand All @@ -11,7 +11,7 @@ export type ProposalRequestMessage = BasicMessage & {
export type ProposalRequestMessageBody = {
credentials: ProposalRequestCredential[];
metadata?: { type: string; data?: JsonDocumentObject };
did_doc?: JsonDocumentObject;
did_doc?: DIDDocument;
};

/** @beta ProposalMessage is struct the represents proposal message */
Expand Down
16 changes: 4 additions & 12 deletions tests/handlers/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: [proofReq as ZeroKnowledgeProofRequest]
};

Expand Down Expand Up @@ -227,7 +226,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: [proofReq as ZeroKnowledgeProofRequest]
};

Expand Down Expand Up @@ -386,7 +384,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: proofReqs
};

Expand Down Expand Up @@ -550,7 +547,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: proofReqs
};

Expand Down Expand Up @@ -792,7 +788,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: proofReqs
};

Expand Down Expand Up @@ -835,7 +830,7 @@ describe('auth', () => {

const proofRequest: ZeroKnowledgeProofRequest = {
id: 23,
circuitId: 'credentialAtomicQueryMTPV2',
circuitId: CircuitId.AtomicQueryMTPV2,
query: {
allowedIssuers: ['*'],
context:
Expand Down Expand Up @@ -997,7 +992,7 @@ describe('auth', () => {

const proofRequest: ZeroKnowledgeProofRequest = {
id: 84239,
circuitId: 'credentialAtomicQuerySigV2',
circuitId: CircuitId.AtomicQuerySigV2,
query: {
allowedIssuers: ['*'],
context:
Expand Down Expand Up @@ -1318,7 +1313,7 @@ describe('auth', () => {
context:
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld',
credentialSubject: { documentType: { $eq: 99 } },
proofType: 'Iden3SparseMerkleTreeProof',
proofType: ProofType.Iden3SparseMerkleTreeProof,
type: 'KYCAgeCredential'
}
}
Expand Down Expand Up @@ -1467,7 +1462,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: [
{
id: 1,
Expand Down Expand Up @@ -1779,7 +1773,7 @@ describe('auth', () => {

const proofRequest: ZeroKnowledgeProofRequest = {
id: 1,
circuitId: 'credentialAtomicQuerySigV2',
circuitId: CircuitId.AtomicQuerySigV2,
query: {
allowedIssuers: ['*'],
context:
Expand Down Expand Up @@ -2092,7 +2086,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: proofReqs
};

Expand Down Expand Up @@ -2157,7 +2150,6 @@ describe('auth', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: [proofReq as ZeroKnowledgeProofRequest]
};

Expand Down
1 change: 0 additions & 1 deletion tests/iden3comm/message-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ describe('MessageHandler', () => {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
reason: 'reason',
message: 'message',
did_doc: {},
scope: [
{
id: 1,
Expand Down
10 changes: 5 additions & 5 deletions tests/proofs/sig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('sig proofs', () => {
scope: [
{
id: 1,
circuitId: 'credentialAtomicQuerySigV2',
circuitId: CircuitId.AtomicQuerySigV2,
query: {
allowedIssuers: ['*'],
context: 'ipfs://QmZ1zsLspwnjifxsncqDkB7EHb2pnaRnBPc5kqQcVxW5rV',
Expand Down Expand Up @@ -477,7 +477,7 @@ describe('sig proofs', () => {
expect(credsForMyUserDID.length).to.equal(1);
const vpReq = {
id: 1,
circuitId: 'credentialAtomicQuerySigV2',
circuitId: CircuitId.AtomicQuerySigV2,
query
};
const { proof, vp } = await proofService.generateProof(vpReq, userDID);
Expand All @@ -500,7 +500,7 @@ describe('sig proofs', () => {
});
const deliveryVPReq = {
id: 1,
circuitId: 'credentialAtomicQuerySigV2',
circuitId: CircuitId.AtomicQuerySigV2,
query: {
...deliveryCredQuery,
credentialSubject: { 'postalProviderInformation.insured': {} }
Expand Down Expand Up @@ -540,7 +540,7 @@ describe('sig proofs', () => {
reason: 'test flow',
scope: [
{
circuitId: 'credentialAtomicQueryV3-beta.1',
circuitId: CircuitId.AtomicQueryV3,
id: 1711115116,
query: {
allowedIssuers: ['*'],
Expand Down Expand Up @@ -612,7 +612,7 @@ describe('sig proofs', () => {
reason: 'test flow',
scope: [
{
circuitId: 'credentialAtomicQueryV3-beta.1',
circuitId: CircuitId.AtomicQueryV3,
id: 1711115116,
query: {
allowedIssuers: ['*'],
Expand Down

0 comments on commit a33feb4

Please sign in to comment.