{"version":3,"file":"W3cDataIntegrityProof.mjs","names":[],"sources":["../../../src/modules/w3c-di/W3cDataIntegrityProof.ts"],"sourcesContent":["import { isObject } from '../../utils/object'\nimport { validateProofRequiredMembers } from './proof-processing/proofValidation'\n\nexport type W3cDataIntegrityDomain = string | string[]\nexport type W3cDataIntegrityPreviousProofReference = string | string[]\n\nexport interface W3cDataIntegrityCryptosuiteProofOptions {\n  id?: string\n  type: 'DataIntegrityProof'\n  cryptosuite: string\n  proofPurpose: string\n  verificationMethod: string\n  created?: string\n  expires?: string\n  challenge?: string\n  domain?: W3cDataIntegrityDomain\n  nonce?: string\n  previousProof?: W3cDataIntegrityPreviousProofReference\n  '@context'?: unknown\n}\n\nexport function createW3cDataIntegrityProofOptions(\n  options: Omit<W3cDataIntegrityCryptosuiteProofOptions, 'type' | '@context' | 'id'>\n): W3cDataIntegrityCryptosuiteProofOptions {\n  return {\n    type: 'DataIntegrityProof',\n    ...options,\n  }\n}\n\nexport interface W3cDataIntegrityCryptosuiteProof extends W3cDataIntegrityCryptosuiteProofOptions {\n  proofValue: string\n}\n\nexport type W3cDataIntegrityUnsecuredDocument = Record<string, unknown>\n\nexport type W3cDataIntegrityProofSet = W3cDataIntegrityCryptosuiteProof | W3cDataIntegrityCryptosuiteProof[]\n\nexport type W3cDataIntegritySingleProofSecuredDocument = W3cDataIntegrityUnsecuredDocument & {\n  proof: W3cDataIntegrityCryptosuiteProof\n}\n\nexport type W3cDataIntegrityProofSetSecuredDocument = W3cDataIntegrityUnsecuredDocument & {\n  proof: W3cDataIntegrityCryptosuiteProof[]\n}\n\nexport type W3cDataIntegritySecuredDocument = W3cDataIntegrityUnsecuredDocument & {\n  proof: W3cDataIntegrityProofSet\n}\n\n/**\n * Enforces required member validation for Data Integrity proofs.\n * See VC Data Integrity v1.0 §4.4 step 4.\n */\nexport function assertIsW3cDataIntegrityProof(proof: unknown): asserts proof is W3cDataIntegrityCryptosuiteProof {\n  const validationError = validateProofRequiredMembers(proof)\n  if (validationError) {\n    throw new TypeError(validationError)\n  }\n}\n\n/**\n * Enforces single-proof secured document shape for VC Data Integrity v1.0 §4.4 flows.\n */\nexport function assertSingleProofDocument(doc: unknown): asserts doc is W3cDataIntegritySingleProofSecuredDocument {\n  if (!isObject(doc)) {\n    throw new TypeError('Secured document must be a non-null object')\n  }\n\n  const securedDocument = doc as Record<string, unknown>\n  if (Array.isArray(securedDocument.proof)) {\n    throw new TypeError('Proof sets are not accepted by verifyProof; call verifyProofSetAndChain instead')\n  }\n\n  assertIsW3cDataIntegrityProof(securedDocument.proof)\n}\n\n/**\n * Enforces proof-set secured document shape for VC Data Integrity v1.0 §4.5 flows.\n */\nexport function assertMultiProofDocument(doc: unknown): asserts doc is W3cDataIntegrityProofSetSecuredDocument {\n  if (!isObject(doc)) {\n    throw new TypeError('Secured document must be a non-null object')\n  }\n\n  const securedDocument = doc as Record<string, unknown>\n  if (!Array.isArray(securedDocument.proof)) {\n    throw new TypeError('Proof set expected for verifyProofSetAndChain')\n  }\n\n  if (securedDocument.proof.length === 0) {\n    throw new TypeError('Proof set expected for verifyProofSetAndChain')\n  }\n}\n\n/**\n * Enforces general secured document shape for Data Integrity single- or multi-proof inputs.\n */\nexport function assertW3cDataIntegrityDocument(doc: unknown): asserts doc is W3cDataIntegritySecuredDocument {\n  if (!isObject(doc)) {\n    throw new TypeError('Secured document must be a non-null object')\n  }\n\n  const securedDocument = doc as Record<string, unknown>\n  if (Array.isArray(securedDocument.proof)) {\n    assertMultiProofDocument(securedDocument)\n    return\n  }\n\n  assertSingleProofDocument(securedDocument)\n}\n"],"mappings":";;;AAqBA,SAAgB,mCACd,SACyC;CACzC,OAAO;EACL,MAAM;EACN,GAAG;CACL;AACF;;;;;AA0BA,SAAgB,8BAA8B,OAAmE;CAC/G,MAAM,kBAAkB,6BAA6B,KAAK;CAC1D,IAAI,iBACF,MAAM,IAAI,UAAU,eAAe;AAEvC;;;;AAKA,SAAgB,0BAA0B,KAAyE;CACjH,IAAI,CAAC,SAAS,GAAG,GACf,MAAM,IAAI,UAAU,4CAA4C;CAGlE,MAAM,kBAAkB;CACxB,IAAI,MAAM,QAAQ,gBAAgB,KAAK,GACrC,MAAM,IAAI,UAAU,iFAAiF;CAGvG,8BAA8B,gBAAgB,KAAK;AACrD;;;;AAKA,SAAgB,yBAAyB,KAAsE;CAC7G,IAAI,CAAC,SAAS,GAAG,GACf,MAAM,IAAI,UAAU,4CAA4C;CAGlE,MAAM,kBAAkB;CACxB,IAAI,CAAC,MAAM,QAAQ,gBAAgB,KAAK,GACtC,MAAM,IAAI,UAAU,+CAA+C;CAGrE,IAAI,gBAAgB,MAAM,WAAW,GACnC,MAAM,IAAI,UAAU,+CAA+C;AAEvE"}