@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.18 kB
Source Map (JSON)
{"version":3,"file":"CredentialIssuancePurpose.mjs","names":[],"sources":["../../../../../src/modules/vc/linked-data-proofs/proof-purposes/CredentialIssuancePurpose.ts"],"sourcesContent":["import type { JsonObject } from '../../../../types'\nimport { purposes, suites } from '../adapters/jsonld-signatures-adapter'\nimport type { DocumentLoader, Proof } from '../proof-ops/jsonldUtil'\n\nconst AssertionProofPurpose = purposes.AssertionProofPurpose\nconst LinkedDataProof = suites.LinkedDataProof\n/**\n * Creates a proof purpose that will validate whether or not the verification\n * method in a proof was authorized by its declared controller for the\n * proof's purpose.\n */\nexport class CredentialIssuancePurpose extends AssertionProofPurpose {\n /**\n * @param {object} options - The options to use.\n * @param {object} [options.controller] - The description of the controller,\n * if it is not to be dereferenced via a `documentLoader`.\n * @param {string|Date|number} [options.date] - The expected date for\n * the creation of the proof.\n * @param {number} [options.maxTimestampDelta=Infinity] - A maximum number\n * of seconds that the date on the signature can deviate from.\n */\n public constructor(options: { controller?: Record<string, unknown>; date: string; maxTimestampDelta?: number }) {\n options.maxTimestampDelta = options.maxTimestampDelta || Number.POSITIVE_INFINITY\n super(options)\n }\n\n /**\n * Validates the purpose of a proof. This method is called during\n * proof verification, after the proof value has been checked against the\n * given verification method (in the case of a digital signature, the\n * signature has been cryptographically verified against the public key).\n *\n * @param {object} proof - The proof to validate.\n * @param {object} options - The options to use.\n * @param {object} options.document - The document whose signature is\n * being verified.\n * @param {object} options.suite - Signature suite used in\n * the proof.\n * @param {string} options.verificationMethod - Key id URL to the paired\n * public key.\n * @param {object} [options.documentLoader] - A document loader.\n *\n * @throws {Error} If verification method not authorized by controller.\n * @throws {Error} If proof's created timestamp is out of range.\n *\n * @returns {Promise<{valid: boolean, error: Error}>} Resolves on completion.\n */\n public async validate(\n proof: Proof,\n options?: {\n document: JsonObject\n suite: typeof LinkedDataProof\n verificationMethod: string\n documentLoader?: DocumentLoader\n }\n // biome-ignore lint/suspicious/noExplicitAny: no explanation\n ): Promise<{ valid: boolean; error?: any }> {\n try {\n const result = await super.validate(proof, options)\n\n if (!result.valid) {\n throw result.error\n }\n\n // This @ts-expect-error is necessary because the .getValues() method is not part of the public API.\n //@ts-expect-error\n const issuer = jsonld.util.getValues(options.document, 'issuer')\n\n if (!issuer || issuer.length === 0) {\n throw new Error('Credential issuer is required.')\n }\n\n const issuerId = typeof issuer[0] === 'string' ? issuer[0] : issuer[0].id\n\n if (result.controller.id !== issuerId) {\n throw new Error('Credential issuer must match the verification method controller.')\n }\n\n return { valid: true }\n } catch (error) {\n return { valid: false, error }\n }\n }\n}\n"],"mappings":";;AAIA,MAAM,wBAAwB,SAAS;AACf,OAAO;;;;;;AAM/B,IAAa,4BAAb,cAA+C,sBAAsB;;;;;;;;;;CAUnE,YAAmB,SAA6F;EAC9G,QAAQ,oBAAoB,QAAQ,qBAAqB,OAAO;EAChE,MAAM,OAAO;CACf;;;;;;;;;;;;;;;;;;;;;;CAuBA,MAAa,SACX,OACA,SAO0C;EAC1C,IAAI;GACF,MAAM,SAAS,MAAM,MAAM,SAAS,OAAO,OAAO;GAElD,IAAI,CAAC,OAAO,OACV,MAAM,OAAO;GAKf,MAAM,SAAS,OAAO,KAAK,UAAU,QAAQ,UAAU,QAAQ;GAE/D,IAAI,CAAC,UAAU,OAAO,WAAW,GAC/B,MAAM,IAAI,MAAM,gCAAgC;GAGlD,MAAM,WAAW,OAAO,OAAO,OAAO,WAAW,OAAO,KAAK,OAAO,EAAE,CAAC;GAEvE,IAAI,OAAO,WAAW,OAAO,UAC3B,MAAM,IAAI,MAAM,kEAAkE;GAGpF,OAAO,EAAE,OAAO,KAAK;EACvB,SAAS,OAAO;GACd,OAAO;IAAE,OAAO;IAAO;GAAM;EAC/B;CACF;AACF"}