@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 • 2.91 kB
Source Map (JSON)
{"version":3,"file":"KeyManagementModuleConfig.mjs","names":[],"sources":["../../../src/modules/kms/KeyManagementModuleConfig.ts"],"sourcesContent":["import { KeyManagementError } from './error/KeyManagementError'\nimport type { KeyManagementService } from './KeyManagementService'\n\nexport interface KeyManagementModuleConfigOptions {\n /**\n * The backends to use for key management and cryptographic operations.\n */\n backends?: KeyManagementService[]\n\n /**\n * The default backend to use, indicated by the `backend` property\n * on the `KeyManagementService` instance.\n *\n * If provided and it doesn't match an entry in the `backends` array\n * an error will be thrown.\n *\n * If not provided, the first backend from the `backends` array will be used.\n */\n defaultBackend?: string\n}\n\nexport class KeyManagementModuleConfig {\n #defaultBackend?: string\n #backends: KeyManagementService[]\n\n public constructor(options: KeyManagementModuleConfigOptions) {\n this.#backends = options.backends ?? []\n\n if (options.defaultBackend) {\n const defaultBackend = this.#backends.find((kms) => kms.backend === options.defaultBackend)\n if (!defaultBackend) {\n throw new KeyManagementError(\n `Default backend '${options.defaultBackend}' provided in KeyManagementModuleConfig, but not found in 'backends'. Make sure the backend identifier matches with a registered backend.`\n )\n }\n this.#defaultBackend = options.defaultBackend\n }\n }\n\n public get backends() {\n return this.#backends\n }\n\n public registerBackend(backend: KeyManagementService) {\n this.backends.push(backend)\n }\n\n /**\n * The default backend, used for operations where no explicit `backend` is provided.\n *\n * Returns the backend matching the `defaultBackend` identifier from the config options,\n * or the first registered backend if no `defaultBackend` was configured.\n */\n public get defaultBackend() {\n const backend = this.backends.find((kms) => !this.#defaultBackend || this.#defaultBackend === kms.backend)\n if (!backend) {\n throw new KeyManagementError(\n 'Unable to determine default key management service backend. Make sure at least one backend is registered.'\n )\n }\n\n return backend\n }\n}\n"],"mappings":";;;;;;;AAqBA,IAAa,4BAAb,MAAuC;CAIrC,YAAmB,SAA2C;;;EAC5D,uBAAA,WAAA,MAAiB,QAAQ,YAAY,CAAC,CAAA;EAEtC,IAAI,QAAQ,gBAAgB;GAE1B,IAAI,CAAA,uBAAA,WADmB,IAAA,CAAA,CAAe,MAAM,QAAQ,IAAI,YAAY,QAAQ,cAC1D,GAChB,MAAM,IAAI,mBACR,oBAAoB,QAAQ,eAAe,0IAC7C;GAEF,uBAAA,iBAAA,MAAuB,QAAQ,cAAA;EACjC;CACF;CAEA,IAAW,WAAW;EACpB,OAAA,uBAAA,WAAO,IAAA;CACT;CAEA,gBAAuB,SAA+B;EACpD,KAAK,SAAS,KAAK,OAAO;CAC5B;;;;;;;CAQA,IAAW,iBAAiB;EAC1B,MAAM,UAAU,KAAK,SAAS,MAAM,QAAQ,CAAA,uBAAA,iBAAC,IAAA,KAAA,uBAAA,iBAAwB,IAAA,MAAyB,IAAI,OAAO;EACzG,IAAI,CAAC,SACH,MAAM,IAAI,mBACR,2GACF;EAGF,OAAO;CACT;AACF"}