Skip to content

Commit a33feb4

Browse files
chore: add type ZeroKnowledgeProofQuery to scope.query (#274)
* add types ZeroKnowledgeProofQuer and DIDDocument
1 parent 9a4541e commit a33feb4

File tree

9 files changed

+54
-31
lines changed

9 files changed

+54
-31
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@0xpolygonid/js-sdk",
3-
"version": "1.20.2",
3+
"version": "1.20.3",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/node/cjs/index.js",
66
"module": "dist/node/esm/index.js",

src/iden3comm/handlers/common.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getRandomBytes } from '@iden3/js-crypto';
22
import {
33
JsonDocumentObject,
44
JWSPackerParams,
5+
ZeroKnowledgeProofQuery,
56
ZeroKnowledgeProofRequest,
67
ZeroKnowledgeProofResponse
78
} from '../types';
@@ -18,11 +19,11 @@ import { Signer } from 'ethers';
1819
* Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
1920
*
2021
* @param requestScope - An array of ZeroKnowledgeProofRequest objects.
21-
* @returns A Map<number, { query: JsonDocumentObject; linkNonce: number }> representing the grouped queries.
22+
* @returns A Map<number, { query: ZeroKnowledgeProofQuery; linkNonce: number }> representing the grouped queries.
2223
*/
2324
const getGroupedQueries = (
2425
requestScope: ZeroKnowledgeProofRequest[]
25-
): Map<number, { query: JsonDocumentObject; linkNonce: number }> =>
26+
): Map<number, { query: ZeroKnowledgeProofQuery; linkNonce: number }> =>
2627
requestScope.reduce((acc, proofReq) => {
2728
const groupId = proofReq.query.groupId as number | undefined;
2829
if (!groupId) {
@@ -54,7 +55,7 @@ const getGroupedQueries = (
5455
});
5556

5657
return acc;
57-
}, new Map<number, { query: JsonDocumentObject; linkNonce: number }>());
58+
}, new Map<number, { query: ZeroKnowledgeProofQuery; linkNonce: number }>());
5859

5960
/**
6061
* Processes zero knowledge proof requests.

src/iden3comm/handlers/credential-proposal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
BasicMessage,
44
CredentialOffer,
55
CredentialsOfferMessage,
6+
DIDDocument,
67
IPackageManager,
78
JsonDocumentObject,
89
PackerParams
@@ -26,7 +27,7 @@ import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handl
2627
export type ProposalRequestCreationOptions = {
2728
credentials: ProposalRequestCredential[];
2829
metadata?: { type: string; data?: JsonDocumentObject };
29-
did_doc?: JsonDocumentObject;
30+
did_doc?: DIDDocument;
3031
};
3132

3233
/**

src/iden3comm/types/protocol/auth.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { ZKProof } from '@iden3/js-jwz';
22
import { BasicMessage, JsonDocumentObject } from '../packer';
33
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
4+
import { ProofType } from '../../../verifiable';
5+
import { CircuitId } from '../../../circuits';
6+
import {
7+
DIDDocument as DidResolverDidDocument,
8+
VerificationMethod as DidResolverVerificationMethod
9+
} from 'did-resolver';
10+
import { RootInfo, StateInfo } from '../../../storage';
411

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

1320
/** AuthorizationMessageResponseBody is struct the represents authorization response data */
1421
export type AuthorizationMessageResponseBody = {
15-
did_doc?: JsonDocumentObject;
22+
did_doc?: DIDDocument;
1623
message?: string;
1724
scope: Array<ZeroKnowledgeProofResponse>;
1825
};
@@ -29,21 +36,32 @@ export type AuthorizationRequestMessageBody = {
2936
callbackUrl: string;
3037
reason?: string;
3138
message?: string;
32-
did_doc?: JsonDocumentObject;
39+
did_doc?: DIDDocument;
3340
scope: Array<ZeroKnowledgeProofRequest>;
3441
};
3542

3643
/** ZeroKnowledgeProofRequest represents structure of zkp request object */
3744
export type ZeroKnowledgeProofRequest = {
3845
id: number;
39-
circuitId: string;
46+
circuitId: CircuitId;
4047
optional?: boolean;
41-
query: JsonDocumentObject;
48+
query: ZeroKnowledgeProofQuery;
4249
params?: {
4350
nullifierSessionId?: string | number;
4451
};
4552
};
4653

54+
/** ZeroKnowledgeProofQuery represents structure of zkp request query object */
55+
export type ZeroKnowledgeProofQuery = {
56+
allowedIssuers: string[];
57+
context: string;
58+
credentialSubject?: JsonDocumentObject;
59+
proofType?: ProofType;
60+
skipClaimRevocationCheck?: boolean;
61+
groupId?: number;
62+
type: string;
63+
};
64+
4765
/** ZeroKnowledgeProofResponse represents structure of zkp response */
4866
export type ZeroKnowledgeProofResponse = {
4967
id: number;
@@ -61,3 +79,15 @@ export type VerifiablePresentation = {
6179
credentialSubject: JsonDocumentObject;
6280
};
6381
};
82+
83+
/** DIDDocument represents structure of DID Document */
84+
export type DIDDocument = DidResolverDidDocument & {
85+
verificationMethod?: VerificationMethod[];
86+
};
87+
88+
/** VerificationMethod represents structure of Verification Method */
89+
export type VerificationMethod = DidResolverVerificationMethod & {
90+
published?: boolean;
91+
info?: StateInfo;
92+
global?: RootInfo;
93+
};

src/iden3comm/types/protocol/proposal-request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BasicMessage, JsonDocumentObject } from '../';
1+
import { BasicMessage, DIDDocument, JsonDocumentObject } from '../';
22
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
33

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

1717
/** @beta ProposalMessage is struct the represents proposal message */

tests/handlers/auth.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ describe('auth', () => {
157157
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
158158
reason: 'reason',
159159
message: 'message',
160-
did_doc: {},
161160
scope: [proofReq as ZeroKnowledgeProofRequest]
162161
};
163162

@@ -227,7 +226,6 @@ describe('auth', () => {
227226
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
228227
reason: 'reason',
229228
message: 'message',
230-
did_doc: {},
231229
scope: [proofReq as ZeroKnowledgeProofRequest]
232230
};
233231

@@ -386,7 +384,6 @@ describe('auth', () => {
386384
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
387385
reason: 'reason',
388386
message: 'message',
389-
did_doc: {},
390387
scope: proofReqs
391388
};
392389

@@ -550,7 +547,6 @@ describe('auth', () => {
550547
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
551548
reason: 'reason',
552549
message: 'message',
553-
did_doc: {},
554550
scope: proofReqs
555551
};
556552

@@ -792,7 +788,6 @@ describe('auth', () => {
792788
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
793789
reason: 'reason',
794790
message: 'message',
795-
did_doc: {},
796791
scope: proofReqs
797792
};
798793

@@ -835,7 +830,7 @@ describe('auth', () => {
835830

836831
const proofRequest: ZeroKnowledgeProofRequest = {
837832
id: 23,
838-
circuitId: 'credentialAtomicQueryMTPV2',
833+
circuitId: CircuitId.AtomicQueryMTPV2,
839834
query: {
840835
allowedIssuers: ['*'],
841836
context:
@@ -997,7 +992,7 @@ describe('auth', () => {
997992

998993
const proofRequest: ZeroKnowledgeProofRequest = {
999994
id: 84239,
1000-
circuitId: 'credentialAtomicQuerySigV2',
995+
circuitId: CircuitId.AtomicQuerySigV2,
1001996
query: {
1002997
allowedIssuers: ['*'],
1003998
context:
@@ -1318,7 +1313,7 @@ describe('auth', () => {
13181313
context:
13191314
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld',
13201315
credentialSubject: { documentType: { $eq: 99 } },
1321-
proofType: 'Iden3SparseMerkleTreeProof',
1316+
proofType: ProofType.Iden3SparseMerkleTreeProof,
13221317
type: 'KYCAgeCredential'
13231318
}
13241319
}
@@ -1467,7 +1462,6 @@ describe('auth', () => {
14671462
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
14681463
reason: 'reason',
14691464
message: 'message',
1470-
did_doc: {},
14711465
scope: [
14721466
{
14731467
id: 1,
@@ -1779,7 +1773,7 @@ describe('auth', () => {
17791773

17801774
const proofRequest: ZeroKnowledgeProofRequest = {
17811775
id: 1,
1782-
circuitId: 'credentialAtomicQuerySigV2',
1776+
circuitId: CircuitId.AtomicQuerySigV2,
17831777
query: {
17841778
allowedIssuers: ['*'],
17851779
context:
@@ -2092,7 +2086,6 @@ describe('auth', () => {
20922086
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
20932087
reason: 'reason',
20942088
message: 'message',
2095-
did_doc: {},
20962089
scope: proofReqs
20972090
};
20982091

@@ -2157,7 +2150,6 @@ describe('auth', () => {
21572150
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
21582151
reason: 'reason',
21592152
message: 'message',
2160-
did_doc: {},
21612153
scope: [proofReq as ZeroKnowledgeProofRequest]
21622154
};
21632155

tests/iden3comm/message-handler.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ describe('MessageHandler', () => {
148148
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
149149
reason: 'reason',
150150
message: 'message',
151-
did_doc: {},
152151
scope: [
153152
{
154153
id: 1,

tests/proofs/sig.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ describe('sig proofs', () => {
309309
scope: [
310310
{
311311
id: 1,
312-
circuitId: 'credentialAtomicQuerySigV2',
312+
circuitId: CircuitId.AtomicQuerySigV2,
313313
query: {
314314
allowedIssuers: ['*'],
315315
context: 'ipfs://QmZ1zsLspwnjifxsncqDkB7EHb2pnaRnBPc5kqQcVxW5rV',
@@ -477,7 +477,7 @@ describe('sig proofs', () => {
477477
expect(credsForMyUserDID.length).to.equal(1);
478478
const vpReq = {
479479
id: 1,
480-
circuitId: 'credentialAtomicQuerySigV2',
480+
circuitId: CircuitId.AtomicQuerySigV2,
481481
query
482482
};
483483
const { proof, vp } = await proofService.generateProof(vpReq, userDID);
@@ -500,7 +500,7 @@ describe('sig proofs', () => {
500500
});
501501
const deliveryVPReq = {
502502
id: 1,
503-
circuitId: 'credentialAtomicQuerySigV2',
503+
circuitId: CircuitId.AtomicQuerySigV2,
504504
query: {
505505
...deliveryCredQuery,
506506
credentialSubject: { 'postalProviderInformation.insured': {} }
@@ -540,7 +540,7 @@ describe('sig proofs', () => {
540540
reason: 'test flow',
541541
scope: [
542542
{
543-
circuitId: 'credentialAtomicQueryV3-beta.1',
543+
circuitId: CircuitId.AtomicQueryV3,
544544
id: 1711115116,
545545
query: {
546546
allowedIssuers: ['*'],
@@ -612,7 +612,7 @@ describe('sig proofs', () => {
612612
reason: 'test flow',
613613
scope: [
614614
{
615-
circuitId: 'credentialAtomicQueryV3-beta.1',
615+
circuitId: CircuitId.AtomicQueryV3,
616616
id: 1711115116,
617617
query: {
618618
allowedIssuers: ['*'],

0 commit comments

Comments
 (0)