import type { AgentContext, DependencyManager, Module } from '@credo-ts/core'import { CredoError, InjectionSymbols, Kms } from '@credo-ts/core'import { NodeInMemoryKeyManagementStorage, NodeKeyManagementService } from '../packages/node/src'import { InMemoryStorageService } from './InMemoryStorageService'export class InMemoryWalletModule implements Module {private inMemoryStorageService = new InMemoryStorageService()private enableKms: booleanprivate enableStorage: booleanpublic constructor(config: { enableKms?: boolean; enableStorage?: boolean } = {}) {this.enableKms = config.enableKms ?? truethis.enableStorage = config.enableStorage ?? true}public register(dependencyManager: DependencyManager) {if (dependencyManager.isRegistered(InjectionSymbols.StorageService)) {throw new CredoError('There is an instance of StorageService already registered')}if (this.enableStorage) {dependencyManager.registerInstance(InjectionSymbols.StorageService, this.inMemoryStorageService)}if (this.enableKms) {const kmsConfig = dependencyManager.resolve(Kms.KeyManagementModuleConfig)// TODO: prevent double registrationkmsConfig.registerBackend(new NodeKeyManagementService(new NodeInMemoryKeyManagementStorage()))}}public async onProvisionContext(agentContext: AgentContext): Promise<void> {if (this.enableStorage) {this.inMemoryStorageService.createRecordsForContext(agentContext)}}public async onDeleteContext(agentContext: AgentContext): Promise<void> {if (this.enableStorage) {this.inMemoryStorageService.deleteRecordsForContext(agentContext)}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。