UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

1 lines • 4.29 kB
{"version":3,"file":"proofSetValidation.mjs","names":[],"sources":["../../../../src/modules/w3c-di/proof-processing/proofSetValidation.ts"],"sourcesContent":["import type { W3cDataIntegrityProcessingIssue } from '../W3cDataIntegrityError'\nimport { createIssue, W3cDataIntegrityProcessingErrorCode } from '../W3cDataIntegrityError'\nimport type { W3cDataIntegrityCryptosuiteProof } from '../W3cDataIntegrityProof'\n\n/**\n * Implements VC Data Integrity v1.0 §4.5 steps 3.2-3.3 chain-structure validation.\n */\nexport function validateProofChainStructure(\n proofs: W3cDataIntegrityCryptosuiteProof[]\n): W3cDataIntegrityProcessingIssue[] {\n const proofIdToIndexList = new Map<string, number[]>()\n const proofIdToUniqueIndex = new Map<string, number>()\n const issues: W3cDataIntegrityProcessingIssue[] = []\n\n for (const [index, proof] of proofs.entries()) {\n const proofId = 'id' in proof && typeof proof.id === 'string' ? proof.id : undefined\n if (!proofId) continue\n\n const existing = proofIdToIndexList.get(proofId)\n if (existing) {\n existing.push(index)\n } else {\n proofIdToIndexList.set(proofId, [index])\n proofIdToUniqueIndex.set(proofId, index)\n }\n }\n\n for (const [proofId, indices] of proofIdToIndexList.entries()) {\n if (indices.length > 1) {\n proofIdToUniqueIndex.delete(proofId)\n issues.push(\n createIssue(\n W3cDataIntegrityProcessingErrorCode.ProofVerificationError,\n 'Duplicate proof id in proof set',\n `Duplicate proof id '${proofId}' at indices ${indices.join(', ')}`\n )\n )\n }\n }\n\n for (const [index, proof] of proofs.entries()) {\n const previousProofReferences = proof.previousProof\n ? Array.isArray(proof.previousProof)\n ? proof.previousProof\n : [proof.previousProof]\n : []\n\n for (const previousProofReference of previousProofReferences) {\n const referencedProofIndex = proofIdToUniqueIndex.get(previousProofReference)\n\n if (referencedProofIndex === undefined) {\n const duplicateReferenceIndices = proofIdToIndexList.get(previousProofReference)\n const resolutionDetail = duplicateReferenceIndices\n ? `Reference '${previousProofReference}' is ambiguous due to duplicate proof ids at indices ${duplicateReferenceIndices.join(', ')}`\n : `Reference '${previousProofReference}' is not present in this proof set`\n\n issues.push(\n createIssue(\n W3cDataIntegrityProcessingErrorCode.ProofVerificationError,\n 'Proof previousProof reference could not be resolved',\n resolutionDetail\n )\n )\n continue\n }\n\n if (referencedProofIndex >= index) {\n issues.push(\n createIssue(\n W3cDataIntegrityProcessingErrorCode.ProofVerificationError,\n 'Proof previousProof reference must target an earlier proof',\n `Reference targets proof index ${referencedProofIndex}, current proof index ${index}`\n )\n )\n }\n }\n }\n\n if (issues.length > 0) {\n return issues\n }\n\n return []\n}\n"],"mappings":";;;;;AAOA,SAAgB,4BACd,QACmC;CACnC,MAAM,qCAAqB,IAAI,IAAsB;CACrD,MAAM,uCAAuB,IAAI,IAAoB;CACrD,MAAM,SAA4C,CAAC;CAEnD,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,GAAG;EAC7C,MAAM,UAAU,QAAQ,SAAS,OAAO,MAAM,OAAO,WAAW,MAAM,KAAK,KAAA;EAC3E,IAAI,CAAC,SAAS;EAEd,MAAM,WAAW,mBAAmB,IAAI,OAAO;EAC/C,IAAI,UACF,SAAS,KAAK,KAAK;OACd;GACL,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;GACvC,qBAAqB,IAAI,SAAS,KAAK;EACzC;CACF;CAEA,KAAK,MAAM,CAAC,SAAS,YAAY,mBAAmB,QAAQ,GAC1D,IAAI,QAAQ,SAAS,GAAG;EACtB,qBAAqB,OAAO,OAAO;EACnC,OAAO,KACL,YAAA,sDAEE,mCACA,uBAAuB,QAAQ,eAAe,QAAQ,KAAK,IAAI,GACjE,CACF;CACF;CAGF,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,GAAG;EAC7C,MAAM,0BAA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