diff --git a/packages/tenants/src/context/TenantSessionCoordinator.ts b/packages/tenants/src/context/TenantSessionCoordinator.ts index cdc7428a86..f78a66125a 100644 --- a/packages/tenants/src/context/TenantSessionCoordinator.ts +++ b/packages/tenants/src/context/TenantSessionCoordinator.ts @@ -10,6 +10,7 @@ import { InjectionSymbols, Logger, WalletApi, + WalletError, } from '@aries-framework/core' import { Mutex, withTimeout } from 'async-mutex' @@ -180,7 +181,14 @@ export class TenantSessionCoordinator { private async createAgentContext(tenantRecord: TenantRecord) { const tenantDependencyManager = this.rootAgentContext.dependencyManager.createChild() - const tenantConfig = this.rootAgentContext.config.extend(tenantRecord.config) + + const tenantConfig = this.rootAgentContext.config.extend({ + ...tenantRecord.config, + walletConfig: { + ...this.rootAgentContext.config?.walletConfig, + ...tenantRecord.config.walletConfig, + }, + }) const agentContext = new AgentContext({ contextCorrelationId: tenantRecord.id, @@ -194,7 +202,11 @@ export class TenantSessionCoordinator { // and will also write the storage version to the storage, which is needed by the update assistant. We either // need to move this out of the module, or just keep using the module here. const walletApi = agentContext.dependencyManager.resolve(WalletApi) - await walletApi.initialize(tenantRecord.config.walletConfig) + + if (!tenantConfig.walletConfig) { + throw new WalletError('Cannot initialize tenant without Wallet config.') + } + await walletApi.initialize(tenantConfig.walletConfig) return agentContext } diff --git a/packages/tenants/src/context/__tests__/TenantSessionCoordinator.test.ts b/packages/tenants/src/context/__tests__/TenantSessionCoordinator.test.ts index dd659db44c..48653f5655 100644 --- a/packages/tenants/src/context/__tests__/TenantSessionCoordinator.test.ts +++ b/packages/tenants/src/context/__tests__/TenantSessionCoordinator.test.ts @@ -1,7 +1,7 @@ import type { TenantAgentContextMapping } from '../TenantSessionCoordinator' import type { DependencyManager } from '@aries-framework/core' -import { AgentContext, AgentConfig, WalletApi } from '@aries-framework/core' +import { AgentConfig, AgentContext, WalletApi, KeyDerivationMethod } from '@aries-framework/core' import { Mutex, withTimeout } from 'async-mutex' import { getAgentConfig, getAgentContext, mockFunction } from '../../../../core/tests/helpers' @@ -91,19 +91,18 @@ describe('TenantSessionCoordinator', () => { registerInstance: jest.fn(), resolve: jest.fn(() => wallet), } as unknown as DependencyManager - const mockConfig = jest.fn() as unknown as AgentConfig createChildSpy.mockReturnValue(tenantDependencyManager) - extendSpy.mockReturnValue(mockConfig) const tenantAgentContext = await tenantSessionCoordinator.getContextForSession(tenantRecord) - expect(wallet.initialize).toHaveBeenCalledWith(tenantRecord.config.walletConfig) + const extendedWalletConfig = { ...tenantRecord.config.walletConfig, keyDerivationMethod: KeyDerivationMethod.Raw } + expect(wallet.initialize).toHaveBeenCalledWith(extendedWalletConfig) expect(tenantSessionMutexMock.acquireSession).toHaveBeenCalledTimes(1) - expect(extendSpy).toHaveBeenCalledWith(tenantRecord.config) + expect(extendSpy).toHaveBeenCalledWith({ ...tenantRecord.config, walletConfig: extendedWalletConfig }) expect(createChildSpy).toHaveBeenCalledWith() expect(tenantDependencyManager.registerInstance).toHaveBeenCalledWith(AgentContext, expect.any(AgentContext)) - expect(tenantDependencyManager.registerInstance).toHaveBeenCalledWith(AgentConfig, mockConfig) + expect(tenantDependencyManager.registerInstance).toHaveBeenCalledWith(AgentConfig, expect.any(AgentConfig)) expect(tenantSessionCoordinator.tenantAgentContextMapping.tenant1).toEqual({ agentContext: tenantAgentContext, @@ -138,7 +137,8 @@ describe('TenantSessionCoordinator', () => { await expect(tenantSessionCoordinator.getContextForSession(tenantRecord)).rejects.toThrowError('Test error') - expect(wallet.initialize).toHaveBeenCalledWith(tenantRecord.config.walletConfig) + const extendedWalletConfig = { ...tenantRecord.config.walletConfig, keyDerivationMethod: KeyDerivationMethod.Raw } + expect(wallet.initialize).toHaveBeenCalledWith(extendedWalletConfig) expect(tenantSessionMutexMock.acquireSession).toHaveBeenCalledTimes(1) expect(tenantSessionMutexMock.releaseSession).toHaveBeenCalledTimes(1) }) @@ -194,8 +194,9 @@ describe('TenantSessionCoordinator', () => { }) // Initialize should only be called once + const extendedWalletConfig = { ...tenantRecord.config.walletConfig, keyDerivationMethod: KeyDerivationMethod.Raw } + expect(wallet.initialize).toHaveBeenCalledWith(extendedWalletConfig) expect(wallet.initialize).toHaveBeenCalledTimes(1) - expect(wallet.initialize).toHaveBeenCalledWith(tenantRecord.config.walletConfig) expect(tenantAgentContext1).toBe(tenantAgentContext2) })