@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.42 kB
Source Map (JSON)
{"version":3,"file":"SignatureSuiteRegistry.mjs","names":[],"sources":["../../../../src/modules/vc/linked-data-proofs/SignatureSuiteRegistry.ts"],"sourcesContent":["import { CredoError } from '../../../error'\nimport { injectable } from '../../../plugins'\nimport { PublicJwk, type SupportedPublicJwkClass } from '../../kms/jwk/PublicJwk'\n\nimport { suites } from './adapters/jsonld-signatures-adapter'\n\nconst LinkedDataSignature = suites.LinkedDataSignature\n\n/**\n * @deprecated Registration token retained for backward compatibility.\n * Will be removed in 0.8.\n */\nexport const SignatureSuiteToken = Symbol('SignatureSuiteToken')\n\nexport interface SuiteInfo {\n suiteClass: typeof LinkedDataSignature\n proofType: string\n verificationMethodTypes: string[]\n supportedPublicJwkTypes: SupportedPublicJwkClass[]\n}\n\n@injectable()\nexport class SignatureSuiteRegistry {\n private suiteMapping: SuiteInfo[]\n\n public constructor(suites: SuiteInfo[] = []) {\n this.suiteMapping = [...suites]\n }\n\n /**\n * @deprecated Pass suites to the constructor instead.\n * Will be removed in 0.8.\n */\n public registerSuite(suiteInfo: SuiteInfo) {\n this.suiteMapping.push(suiteInfo)\n }\n\n /**\n * @deprecated Pass suites to the constructor instead.\n * Will be removed in 0.8.\n */\n public registerSuites(suites: SuiteInfo[]) {\n for (const suite of suites) {\n this.registerSuite(suite)\n }\n }\n\n public get supportedProofTypes(): string[] {\n return this.suiteMapping.map((x) => x.proofType)\n }\n\n /**\n * @deprecated recommended to always search by key type instead as that will have broader support\n */\n public getByVerificationMethodType(verificationMethodType: string) {\n return this.suiteMapping.find((x) => x.verificationMethodTypes.includes(verificationMethodType))\n }\n\n public getAllByPublicJwkType(publicJwkType: SupportedPublicJwkClass | PublicJwk) {\n const publicJwkClass = publicJwkType instanceof PublicJwk ? publicJwkType.JwkClass : publicJwkType\n return this.suiteMapping.filter((x) => x.supportedPublicJwkTypes.includes(publicJwkClass))\n }\n\n public getByProofType(proofType: string) {\n const suiteInfo = this.suiteMapping.find((x) => x.proofType === proofType)\n\n if (!suiteInfo) {\n throw new CredoError(`No signature suite for proof type: ${proofType}`)\n }\n\n return suiteInfo\n }\n\n /**\n * Returns the `@context` url that the signature suite for the given proof type adds to documents\n * it signs (see `LinkedDataSignature.ensureSuiteContext`), or undefined if the proof type is not\n * registered or its suite does not declare a context url.\n */\n public findContextUrlByProofType(proofType: string): string | undefined {\n const suiteClass = this.suiteMapping.find((x) => x.proofType === proofType)?.suiteClass as\n | { CONTEXT_URL?: unknown }\n | undefined\n\n return typeof suiteClass?.CONTEXT_URL === 'string' ? suiteClass.CONTEXT_URL : undefined\n }\n\n public getVerificationMethodTypesByProofType(proofType: string): string[] {\n const suiteInfo = this.suiteMapping.find((suiteInfo) => suiteInfo.proofType === proofType)\n\n if (!suiteInfo) {\n throw new CredoError(`No verification method type found for proof type: ${proofType}`)\n }\n\n return suiteInfo.verificationMethodTypes\n }\n}\n"],"mappings":";;;;;;;;AAM4B,OAAO;;;;;AAMnC,MAAa,sBAAsB,OAAO,qBAAqB;AAUxD,IAAM,yBAAN,MAAM,uBAAuB;CAGlC,YAAmB,SAAsB,CAAC,GAAG;EAC3C,KAAK,eAAe,CAAC,GAAG,MAAM;CAChC;;;;;CAMA,cAAqB,WAAsB;EACzC,KAAK,aAAa,KAAK,SAAS;CAClC;;;;;CAMA,eAAsB,QAAqB;EACzC,KAAK,MAAM,SAAS,QAClB,KAAK,cAAc,KAAK;CAE5B;CAEA,IAAW,sBAAgC;EACzC,OAAO,KAAK,aAAa,KAAK,MAAM,EAAE,SAAS;CACjD;;;;CAKA,4BAAmC,wBAAgC;EACjE,OAAO,KAAK,aAAa,MAAM,MAAM,EAAE,wBAAwB,SAAS,sBAAsB,CAAC;CACjG;CAEA,sBAA6B,eAAo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