diff --git a/package-lock.json b/package-lock.json index 719365d9..dd6652fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.20.2", + "version": "1.20.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.20.2", + "version": "1.20.3", "license": "MIT or Apache-2.0", "dependencies": { "@noble/curves": "^1.4.0", diff --git a/package.json b/package.json index bec45ff3..12efea30 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/iden3comm/handlers/common.ts b/src/iden3comm/handlers/common.ts index d35cbd5e..3a3a49aa 100644 --- a/src/iden3comm/handlers/common.ts +++ b/src/iden3comm/handlers/common.ts @@ -2,6 +2,7 @@ import { getRandomBytes } from '@iden3/js-crypto'; import { JsonDocumentObject, JWSPackerParams, + ZeroKnowledgeProofQuery, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../types'; @@ -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 representing the grouped queries. + * @returns A Map representing the grouped queries. */ const getGroupedQueries = ( requestScope: ZeroKnowledgeProofRequest[] -): Map => +): Map => requestScope.reduce((acc, proofReq) => { const groupId = proofReq.query.groupId as number | undefined; if (!groupId) { @@ -54,7 +55,7 @@ const getGroupedQueries = ( }); return acc; - }, new Map()); + }, new Map()); /** * Processes zero knowledge proof requests. diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index ae2496ec..2471481d 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -3,6 +3,7 @@ import { BasicMessage, CredentialOffer, CredentialsOfferMessage, + DIDDocument, IPackageManager, JsonDocumentObject, PackerParams @@ -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; }; /** diff --git a/src/iden3comm/types/protocol/auth.ts b/src/iden3comm/types/protocol/auth.ts index 6f787cdb..48080219 100644 --- a/src/iden3comm/types/protocol/auth.ts +++ b/src/iden3comm/types/protocol/auth.ts @@ -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 & { @@ -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; }; @@ -29,21 +36,32 @@ export type AuthorizationRequestMessageBody = { callbackUrl: string; reason?: string; message?: string; - did_doc?: JsonDocumentObject; + did_doc?: DIDDocument; scope: Array; }; /** 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; @@ -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; +}; diff --git a/src/iden3comm/types/protocol/proposal-request.ts b/src/iden3comm/types/protocol/proposal-request.ts index 300d2046..fef46747 100644 --- a/src/iden3comm/types/protocol/proposal-request.ts +++ b/src/iden3comm/types/protocol/proposal-request.ts @@ -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 */ @@ -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 */ diff --git a/tests/handlers/auth.test.ts b/tests/handlers/auth.test.ts index 64418d46..d68f1cc8 100644 --- a/tests/handlers/auth.test.ts +++ b/tests/handlers/auth.test.ts @@ -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] }; @@ -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] }; @@ -386,7 +384,6 @@ describe('auth', () => { callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123', reason: 'reason', message: 'message', - did_doc: {}, scope: proofReqs }; @@ -550,7 +547,6 @@ describe('auth', () => { callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123', reason: 'reason', message: 'message', - did_doc: {}, scope: proofReqs }; @@ -792,7 +788,6 @@ describe('auth', () => { callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123', reason: 'reason', message: 'message', - did_doc: {}, scope: proofReqs }; @@ -835,7 +830,7 @@ describe('auth', () => { const proofRequest: ZeroKnowledgeProofRequest = { id: 23, - circuitId: 'credentialAtomicQueryMTPV2', + circuitId: CircuitId.AtomicQueryMTPV2, query: { allowedIssuers: ['*'], context: @@ -997,7 +992,7 @@ describe('auth', () => { const proofRequest: ZeroKnowledgeProofRequest = { id: 84239, - circuitId: 'credentialAtomicQuerySigV2', + circuitId: CircuitId.AtomicQuerySigV2, query: { allowedIssuers: ['*'], context: @@ -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' } } @@ -1467,7 +1462,6 @@ describe('auth', () => { callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123', reason: 'reason', message: 'message', - did_doc: {}, scope: [ { id: 1, @@ -1779,7 +1773,7 @@ describe('auth', () => { const proofRequest: ZeroKnowledgeProofRequest = { id: 1, - circuitId: 'credentialAtomicQuerySigV2', + circuitId: CircuitId.AtomicQuerySigV2, query: { allowedIssuers: ['*'], context: @@ -2092,7 +2086,6 @@ describe('auth', () => { callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123', reason: 'reason', message: 'message', - did_doc: {}, scope: proofReqs }; @@ -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] }; diff --git a/tests/iden3comm/message-handler.test.ts b/tests/iden3comm/message-handler.test.ts index 7de37b91..eb94d104 100644 --- a/tests/iden3comm/message-handler.test.ts +++ b/tests/iden3comm/message-handler.test.ts @@ -148,7 +148,6 @@ describe('MessageHandler', () => { callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123', reason: 'reason', message: 'message', - did_doc: {}, scope: [ { id: 1, diff --git a/tests/proofs/sig.test.ts b/tests/proofs/sig.test.ts index 44bf92fc..5c25f5d8 100644 --- a/tests/proofs/sig.test.ts +++ b/tests/proofs/sig.test.ts @@ -309,7 +309,7 @@ describe('sig proofs', () => { scope: [ { id: 1, - circuitId: 'credentialAtomicQuerySigV2', + circuitId: CircuitId.AtomicQuerySigV2, query: { allowedIssuers: ['*'], context: 'ipfs://QmZ1zsLspwnjifxsncqDkB7EHb2pnaRnBPc5kqQcVxW5rV', @@ -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); @@ -500,7 +500,7 @@ describe('sig proofs', () => { }); const deliveryVPReq = { id: 1, - circuitId: 'credentialAtomicQuerySigV2', + circuitId: CircuitId.AtomicQuerySigV2, query: { ...deliveryCredQuery, credentialSubject: { 'postalProviderInformation.insured': {} } @@ -540,7 +540,7 @@ describe('sig proofs', () => { reason: 'test flow', scope: [ { - circuitId: 'credentialAtomicQueryV3-beta.1', + circuitId: CircuitId.AtomicQueryV3, id: 1711115116, query: { allowedIssuers: ['*'], @@ -612,7 +612,7 @@ describe('sig proofs', () => { reason: 'test flow', scope: [ { - circuitId: 'credentialAtomicQueryV3-beta.1', + circuitId: CircuitId.AtomicQueryV3, id: 1711115116, query: { allowedIssuers: ['*'],