diff --git a/packages/action-menu/src/__tests__/ActionMenuModule.test.ts b/packages/action-menu/src/__tests__/ActionMenuModule.test.ts index cab660c322..3ca65477f7 100644 --- a/packages/action-menu/src/__tests__/ActionMenuModule.test.ts +++ b/packages/action-menu/src/__tests__/ActionMenuModule.test.ts @@ -3,6 +3,7 @@ import type { FeatureRegistry } from '@credo-ts/didcomm' import { Protocol } from '@credo-ts/didcomm' +import { getAgentContext } from '../../../core/tests' import { ActionMenuModule } from '../ActionMenuModule' import { ActionMenuRole } from '../ActionMenuRole' import { ActionMenuRepository } from '../repository' @@ -20,13 +21,16 @@ const dependencyManager = { } as unknown as DependencyManager describe('ActionMenuModule', () => { - test('registers dependencies on the dependency manager', () => { + test('registers dependencies on the dependency manager', async () => { const actionMenuModule = new ActionMenuModule() actionMenuModule.register(dependencyManager) expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(2) expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuService) expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuRepository) + expect(featureRegistry.register).toHaveBeenCalledTimes(0) + + await actionMenuModule.initialize(getAgentContext({ dependencyManager })) expect(featureRegistry.register).toHaveBeenCalledTimes(1) expect(featureRegistry.register).toHaveBeenCalledWith( diff --git a/packages/anoncreds/src/protocols/proofs/v1/__tests__/v1-indy-proofs.e2e.test.ts b/packages/anoncreds/src/protocols/proofs/v1/__tests__/v1-indy-proofs.e2e.test.ts index ff71996463..fdaaf2fdb0 100644 --- a/packages/anoncreds/src/protocols/proofs/v1/__tests__/v1-indy-proofs.e2e.test.ts +++ b/packages/anoncreds/src/protocols/proofs/v1/__tests__/v1-indy-proofs.e2e.test.ts @@ -1,8 +1,8 @@ import type { EventReplaySubject } from '../../../../../../core/tests' import type { AnonCredsTestsAgent } from '../../../../../tests/legacyAnonCredsSetup' -import { ProofState, ProofExchangeRecord } from '../../../../../../core/src' import { testLogger, waitForProofExchangeRecord } from '../../../../../../core/tests' +import { ProofState, ProofExchangeRecord } from '../../../../../../didcomm/src' import { issueLegacyAnonCredsCredential, setupAnonCredsTests } from '../../../../../tests/legacyAnonCredsSetup' import { V1ProposePresentationMessage, V1RequestPresentationMessage, V1PresentationMessage } from '../messages' @@ -63,7 +63,7 @@ describe('Present Proof', () => { state: ProofState.ProposalReceived, }) - let aliceProofExchangeRecord = await aliceAgent.proofs.proposeProof({ + let aliceProofExchangeRecord = await aliceAgent.modules.proofs.proposeProof({ connectionId: aliceConnectionId, protocolVersion: 'v1', proofFormats: { @@ -91,7 +91,7 @@ describe('Present Proof', () => { // Faber waits for a presentation proposal from Alice testLogger.test('Faber waits for a presentation proposal from Alice') let faberProofExchangeRecord = await faberProofExchangeRecordPromise - const proposal = await faberAgent.proofs.findProposalMessage(faberProofExchangeRecord.id) + const proposal = await faberAgent.modules.proofs.findProposalMessage(faberProofExchangeRecord.id) expect(proposal).toMatchObject({ type: 'https://didcomm.org/present-proof/1.0/propose-presentation', id: expect.any(String), @@ -129,7 +129,7 @@ describe('Present Proof', () => { // Faber accepts the presentation proposal from Alice testLogger.test('Faber accepts presentation proposal from Alice') - faberProofExchangeRecord = await faberAgent.proofs.acceptProposal({ + faberProofExchangeRecord = await faberAgent.modules.proofs.acceptProposal({ proofRecordId: faberProofExchangeRecord.id, }) @@ -137,7 +137,7 @@ describe('Present Proof', () => { testLogger.test('Alice waits for presentation request from Faber') aliceProofExchangeRecord = await aliceProofExchangeRecordPromise - const request = await faberAgent.proofs.findRequestMessage(faberProofExchangeRecord.id) + const request = await faberAgent.modules.proofs.findRequestMessage(faberProofExchangeRecord.id) expect(request).toMatchObject({ type: 'https://didcomm.org/present-proof/1.0/request-presentation', id: expect.any(String), @@ -158,7 +158,7 @@ describe('Present Proof', () => { // Alice retrieves the requested credentials and accepts the presentation request testLogger.test('Alice accepts presentation request from Faber') - const requestedCredentials = await aliceAgent.proofs.selectCredentialsForRequest({ + const requestedCredentials = await aliceAgent.modules.proofs.selectCredentialsForRequest({ proofRecordId: aliceProofExchangeRecord.id, }) @@ -167,7 +167,7 @@ describe('Present Proof', () => { state: ProofState.PresentationReceived, }) - await aliceAgent.proofs.acceptRequest({ + await aliceAgent.modules.proofs.acceptRequest({ proofRecordId: aliceProofExchangeRecord.id, proofFormats: { indy: requestedCredentials.proofFormats.indy }, }) @@ -176,7 +176,7 @@ describe('Present Proof', () => { testLogger.test('Faber waits for presentation from Alice') faberProofExchangeRecord = await faberProofExchangeRecordPromise - const presentation = await faberAgent.proofs.findPresentationMessage(faberProofExchangeRecord.id) + const presentation = await faberAgent.modules.proofs.findPresentationMessage(faberProofExchangeRecord.id) expect(presentation).toMatchObject({ type: 'https://didcomm.org/present-proof/1.0/presentation', id: expect.any(String), @@ -208,7 +208,7 @@ describe('Present Proof', () => { // Faber accepts the presentation provided by Alice testLogger.test('Faber accepts the presentation provided by Alice') - await faberAgent.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id }) + await faberAgent.modules.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id }) // Alice waits until she received a presentation acknowledgement testLogger.test('Alice waits until she receives a presentation acknowledgement') @@ -233,15 +233,15 @@ describe('Present Proof', () => { state: ProofState.Done, }) - const proposalMessage = await aliceAgent.proofs.findProposalMessage(aliceProofExchangeRecord.id) - const requestMessage = await aliceAgent.proofs.findRequestMessage(aliceProofExchangeRecord.id) - const presentationMessage = await aliceAgent.proofs.findPresentationMessage(aliceProofExchangeRecord.id) + const proposalMessage = await aliceAgent.modules.proofs.findProposalMessage(aliceProofExchangeRecord.id) + const requestMessage = await aliceAgent.modules.proofs.findRequestMessage(aliceProofExchangeRecord.id) + const presentationMessage = await aliceAgent.modules.proofs.findPresentationMessage(aliceProofExchangeRecord.id) expect(proposalMessage).toBeInstanceOf(V1ProposePresentationMessage) expect(requestMessage).toBeInstanceOf(V1RequestPresentationMessage) expect(presentationMessage).toBeInstanceOf(V1PresentationMessage) - const formatData = await aliceAgent.proofs.getFormatData(aliceProofExchangeRecord.id) + const formatData = await aliceAgent.modules.proofs.getFormatData(aliceProofExchangeRecord.id) const proposalPredicateKey = Object.keys(formatData.proposal?.indy?.requested_predicates || {})[0] const requestPredicateKey = Object.keys(formatData.request?.indy?.requested_predicates || {})[0] @@ -312,7 +312,7 @@ describe('Present Proof', () => { // Faber sends a presentation request to Alice testLogger.test('Faber sends a presentation request to Alice') - let faberProofExchangeRecord = await faberAgent.proofs.requestProof({ + let faberProofExchangeRecord = await faberAgent.modules.proofs.requestProof({ protocolVersion: 'v1', connectionId: faberConnectionId, proofFormats: { @@ -349,7 +349,7 @@ describe('Present Proof', () => { testLogger.test('Alice waits for presentation request from Faber') let aliceProofExchangeRecord = await aliceProofExchangeRecordPromise - const request = await faberAgent.proofs.findRequestMessage(faberProofExchangeRecord.id) + const request = await faberAgent.modules.proofs.findRequestMessage(faberProofExchangeRecord.id) expect(request).toMatchObject({ type: 'https://didcomm.org/present-proof/1.0/request-presentation', id: expect.any(String), @@ -374,7 +374,7 @@ describe('Present Proof', () => { // Alice retrieves the requested credentials and accepts the presentation request testLogger.test('Alice accepts presentation request from Faber') - const requestedCredentials = await aliceAgent.proofs.selectCredentialsForRequest({ + const requestedCredentials = await aliceAgent.modules.proofs.selectCredentialsForRequest({ proofRecordId: aliceProofExchangeRecord.id, }) @@ -383,7 +383,7 @@ describe('Present Proof', () => { state: ProofState.PresentationReceived, }) - await aliceAgent.proofs.acceptRequest({ + await aliceAgent.modules.proofs.acceptRequest({ proofRecordId: aliceProofExchangeRecord.id, proofFormats: { indy: requestedCredentials.proofFormats.indy }, }) @@ -392,7 +392,7 @@ describe('Present Proof', () => { testLogger.test('Faber waits for presentation from Alice') faberProofExchangeRecord = await faberProofExchangeRecordPromise - const presentation = await faberAgent.proofs.findPresentationMessage(faberProofExchangeRecord.id) + const presentation = await faberAgent.modules.proofs.findPresentationMessage(faberProofExchangeRecord.id) expect(presentation).toMatchObject({ type: 'https://didcomm.org/present-proof/1.0/presentation', id: expect.any(String), @@ -424,7 +424,7 @@ describe('Present Proof', () => { // Faber accepts the presentation testLogger.test('Faber accept the presentation from Alice') - await faberAgent.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id }) + await faberAgent.modules.proofs.acceptPresentation({ proofRecordId: faberProofExchangeRecord.id }) // Alice waits until she receives a presentation acknowledgement testLogger.test('Alice waits for acceptance by Faber') @@ -452,7 +452,7 @@ describe('Present Proof', () => { test('an attribute group name matches with a predicate group name so an error is thrown', async () => { await expect( - faberAgent.proofs.requestProof({ + faberAgent.modules.proofs.requestProof({ protocolVersion: 'v1', connectionId: faberConnectionId, proofFormats: { @@ -494,7 +494,7 @@ describe('Present Proof', () => { // Faber sends a presentation request to Alice testLogger.test('Faber sends a presentation request to Alice') - let faberProofExchangeRecord = await faberAgent.proofs.requestProof({ + let faberProofExchangeRecord = await faberAgent.modules.proofs.requestProof({ protocolVersion: 'v1', connectionId: faberConnectionId, proofFormats: { @@ -531,7 +531,7 @@ describe('Present Proof', () => { testLogger.test('Alice waits for presentation request from Faber') let aliceProofExchangeRecord = await aliceProofExchangeRecordPromise - const request = await faberAgent.proofs.findRequestMessage(faberProofExchangeRecord.id) + const request = await faberAgent.modules.proofs.findRequestMessage(faberProofExchangeRecord.id) expect(request).toMatchObject({ type: 'https://didcomm.org/present-proof/1.0/request-presentation', id: expect.any(String), @@ -558,7 +558,7 @@ describe('Present Proof', () => { state: ProofState.Abandoned, }) - aliceProofExchangeRecord = await aliceAgent.proofs.sendProblemReport({ + aliceProofExchangeRecord = await aliceAgent.modules.proofs.sendProblemReport({ proofRecordId: aliceProofExchangeRecord.id, description: 'Problem inside proof request', }) diff --git a/packages/anoncreds/tests/legacyAnonCredsSetup.ts b/packages/anoncreds/tests/legacyAnonCredsSetup.ts index 1a08a42e52..b008a29089 100644 --- a/packages/anoncreds/tests/legacyAnonCredsSetup.ts +++ b/packages/anoncreds/tests/legacyAnonCredsSetup.ts @@ -9,15 +9,11 @@ import type { RegisterCredentialDefinitionReturnStateFinished, RegisterSchemaReturnStateFinished, } from '../src' -import type { AutoAcceptProof, ConnectionRecord } from '@credo-ts/core' +import type { AutoAcceptProof, ConnectionRecord } from '@credo-ts/didcomm' +import { TypedArrayEncoder, CacheModule, InMemoryLruCache, Agent, CredoError, DidsModule } from '@credo-ts/core' import { AgentEventTypes, - TypedArrayEncoder, - CacheModule, - InMemoryLruCache, - Agent, - CredoError, AutoAcceptCredential, CredentialEventTypes, CredentialsModule, @@ -27,8 +23,7 @@ import { ProofState, V2CredentialProtocol, V2ProofProtocol, - DidsModule, -} from '@credo-ts/core' +} from '@credo-ts/didcomm' import { randomUUID } from 'crypto' import { sleep } from '../../core/src/utils/sleep' @@ -42,6 +37,7 @@ import { waitForProofExchangeRecordSubject, } from '../../core/tests/helpers' import testLogger from '../../core/tests/logger' +import { getDefaultDidcommModules } from '../../didcomm/src/util/modules' import { IndyVdrAnonCredsRegistry, IndyVdrSovDidResolver, @@ -99,6 +95,7 @@ export const getAnonCredsIndyModules = ({ const legacyIndyProofFormatService = new LegacyIndyProofFormatService() const modules = { + ...getDefaultDidcommModules(), credentials: new CredentialsModule({ autoAcceptCredentials, credentialProtocols: [ @@ -165,7 +162,7 @@ export async function presentLegacyAnonCredsProof({ state: ProofState.RequestReceived, }) - let verifierProofExchangeRecord = await verifierAgent.proofs.requestProof({ + let verifierProofExchangeRecord = await verifierAgent.modules.proofs.requestProof({ connectionId: verifierHolderConnectionId, proofFormats: { indy: { @@ -180,7 +177,7 @@ export async function presentLegacyAnonCredsProof({ let holderProofExchangeRecord = await holderProofExchangeRecordPromise - const selectedCredentials = await holderAgent.proofs.selectCredentialsForRequest({ + const selectedCredentials = await holderAgent.modules.proofs.selectCredentialsForRequest({ proofRecordId: holderProofExchangeRecord.id, }) @@ -189,7 +186,7 @@ export async function presentLegacyAnonCredsProof({ state: ProofState.PresentationReceived, }) - await holderAgent.proofs.acceptRequest({ + await holderAgent.modules.proofs.acceptRequest({ proofRecordId: holderProofExchangeRecord.id, proofFormats: { indy: selectedCredentials.proofFormats.indy }, }) @@ -204,7 +201,7 @@ export async function presentLegacyAnonCredsProof({ state: ProofState.Done, }) - verifierProofExchangeRecord = await verifierAgent.proofs.acceptPresentation({ + verifierProofExchangeRecord = await verifierAgent.modules.proofs.acceptPresentation({ proofRecordId: verifierProofExchangeRecord.id, }) holderProofExchangeRecord = await holderProofExchangeRecordPromise @@ -234,7 +231,7 @@ export async function issueLegacyAnonCredsCredential({ issuerHolderConnectionId: string offer: AnonCredsOfferCredentialFormat }) { - let issuerCredentialExchangeRecord = await issuerAgent.credentials.offerCredential({ + let issuerCredentialExchangeRecord = await issuerAgent.modules.credentials.offerCredential({ comment: 'some comment about credential', connectionId: issuerHolderConnectionId, protocolVersion: 'v1', @@ -249,7 +246,7 @@ export async function issueLegacyAnonCredsCredential({ state: CredentialState.OfferReceived, }) - await holderAgent.credentials.acceptOffer({ + await holderAgent.modules.credentials.acceptOffer({ credentialRecordId: holderCredentialExchangeRecord.id, autoAcceptCredential: AutoAcceptCredential.ContentApproved, }) diff --git a/packages/core/src/agent/__tests__/AgentModules.test.ts b/packages/core/src/agent/__tests__/AgentModules.test.ts index a65c6bd21f..a0394838ea 100644 --- a/packages/core/src/agent/__tests__/AgentModules.test.ts +++ b/packages/core/src/agent/__tests__/AgentModules.test.ts @@ -1,18 +1,10 @@ import type { Module } from '../../plugins' -import { BasicMessagesModule } from '../../../../didcomm/src/modules/basic-messages' import { CacheModule } from '../../modules/cache' -import { CredentialsModule } from '../../../../didcomm/src/modules/credentials' -import { ConnectionsModule, DidCommModule } from '../../../../didcomm/src' -import { DiscoverFeaturesModule } from '../../../../didcomm/src/modules/discover-features' -import { MessagePickupModule } from '../../../../didcomm/src/modules/message-pickup' -import { OutOfBandModule } from '../../../../didcomm/src/modules/oob' -import { MediationRecipientModule, MediatorModule } from '../../../../didcomm/src/modules/routing' import { DidsModule } from '../../modules/dids' import { DifPresentationExchangeModule } from '../../modules/dif-presentation-exchange' import { GenericRecordsModule } from '../../modules/generic-records' import { MdocModule } from '../../modules/mdoc' -import { ProofsModule } from '../../../../didcomm/src/modules/proofs' import { SdJwtVcModule } from '../../modules/sd-jwt-vc' import { W3cCredentialsModule } from '../../modules/vc' import { X509Module } from '../../modules/x509' @@ -59,20 +51,10 @@ describe('AgentModules', () => { const extendedModules = extendModulesWithDefaultModules() expect(extendedModules).toEqual({ - connections: expect.any(ConnectionsModule), - credentials: expect.any(CredentialsModule), - proofs: expect.any(ProofsModule), - mediator: expect.any(MediatorModule), - mediationRecipient: expect.any(MediationRecipientModule), - messagePickup: expect.any(MessagePickupModule), - basicMessages: expect.any(BasicMessagesModule), pex: expect.any(DifPresentationExchangeModule), genericRecords: expect.any(GenericRecordsModule), - discovery: expect.any(DiscoverFeaturesModule), dids: expect.any(DidsModule), - didcomm: expect.any(DidCommModule), wallet: expect.any(WalletModule), - oob: expect.any(OutOfBandModule), w3cCredentials: expect.any(W3cCredentialsModule), sdJwtVc: expect.any(SdJwtVcModule), mdoc: expect.any(MdocModule), @@ -88,20 +70,10 @@ describe('AgentModules', () => { }) expect(extendedModules).toEqual({ - connections: expect.any(ConnectionsModule), - credentials: expect.any(CredentialsModule), - proofs: expect.any(ProofsModule), - mediator: expect.any(MediatorModule), - mediationRecipient: expect.any(MediationRecipientModule), - messagePickup: expect.any(MessagePickupModule), - basicMessages: expect.any(BasicMessagesModule), pex: expect.any(DifPresentationExchangeModule), genericRecords: expect.any(GenericRecordsModule), - discovery: expect.any(DiscoverFeaturesModule), dids: expect.any(DidsModule), - didcomm: expect.any(DidCommModule), wallet: expect.any(WalletModule), - oob: expect.any(OutOfBandModule), w3cCredentials: expect.any(W3cCredentialsModule), cache: expect.any(CacheModule), sdJwtVc: expect.any(SdJwtVcModule), @@ -113,27 +85,17 @@ describe('AgentModules', () => { test('does not override default module if provided as custom module', () => { const myModule = new MyModuleWithApi() - const connections = new ConnectionsModule() + const genericRecords = new GenericRecordsModule() const extendedModules = extendModulesWithDefaultModules({ myModule, - connections, + genericRecords, }) expect(extendedModules).toEqual({ - connections: connections, - credentials: expect.any(CredentialsModule), - proofs: expect.any(ProofsModule), - mediator: expect.any(MediatorModule), - mediationRecipient: expect.any(MediationRecipientModule), - messagePickup: expect.any(MessagePickupModule), - basicMessages: expect.any(BasicMessagesModule), + genericRecords: genericRecords, pex: expect.any(DifPresentationExchangeModule), - genericRecords: expect.any(GenericRecordsModule), - discovery: expect.any(DiscoverFeaturesModule), dids: expect.any(DidsModule), - didcomm: expect.any(DidCommModule), wallet: expect.any(WalletModule), - oob: expect.any(OutOfBandModule), w3cCredentials: expect.any(W3cCredentialsModule), cache: expect.any(CacheModule), sdJwtVc: expect.any(SdJwtVcModule), diff --git a/packages/core/src/storage/migration/__tests__/0.1.test.ts b/packages/core/src/storage/migration/__tests__/0.1.test.ts index d7b7481263..efc5c92c53 100644 --- a/packages/core/src/storage/migration/__tests__/0.1.test.ts +++ b/packages/core/src/storage/migration/__tests__/0.1.test.ts @@ -1,10 +1,11 @@ -import type { V0_1ToV0_2UpdateConfig } from '../updates/0.1-0.2' +import type { V0_1ToV0_2UpdateConfig } from '../../../../src' import { readFileSync } from 'fs' import path from 'path' import { InMemoryStorageService } from '../../../../../../tests/InMemoryStorageService' import { RegisteredAskarTestWallet } from '../../../../../askar/tests/helpers' +import { getDefaultDidcommModules } from '../../../../../didcomm/src/util/modules' import { Agent } from '../../../../src' import { agentDependencies as dependencies } from '../../../../tests/helpers' import { InjectionSymbols } from '../../../constants' @@ -45,6 +46,7 @@ describe('UpdateAssistant | v0.1 - v0.2', () => { { config: { label: 'Test Agent', walletConfig }, dependencies, + modules: getDefaultDidcommModules(), }, dependencyManager ) @@ -108,6 +110,7 @@ describe('UpdateAssistant | v0.1 - v0.2', () => { { config: { label: 'Test Agent', walletConfig }, dependencies, + modules: getDefaultDidcommModules(), }, dependencyManager ) @@ -171,6 +174,7 @@ describe('UpdateAssistant | v0.1 - v0.2', () => { { config: { label: 'Test Agent', walletConfig, autoUpdateStorageOnStartup: true }, dependencies, + modules: getDefaultDidcommModules(), }, dependencyManager ) @@ -237,6 +241,7 @@ describe('UpdateAssistant | v0.1 - v0.2', () => { walletConfig, autoUpdateStorageOnStartup: true, }, + modules: getDefaultDidcommModules(), dependencies, }, dependencyManager diff --git a/packages/core/src/storage/migration/__tests__/0.2.test.ts b/packages/core/src/storage/migration/__tests__/0.2.test.ts index bbb00eb2a8..09890e5dce 100644 --- a/packages/core/src/storage/migration/__tests__/0.2.test.ts +++ b/packages/core/src/storage/migration/__tests__/0.2.test.ts @@ -3,7 +3,9 @@ import path from 'path' import { InMemoryStorageService } from '../../../../../../tests/InMemoryStorageService' import { RegisteredAskarTestWallet } from '../../../../../askar/tests/helpers' -import { Agent, MediatorRoutingRecord } from '../../../../src' +import { MediatorRoutingRecord } from '../../../../../didcomm/src/modules' +import { getDefaultDidcommModules } from '../../../../../didcomm/src/util/modules' +import { Agent } from '../../../../src' import { agentDependencies } from '../../../../tests/helpers' import { InjectionSymbols } from '../../../constants' import { DependencyManager } from '../../../plugins' @@ -42,6 +44,7 @@ describe('UpdateAssistant | v0.2 - v0.3.1', () => { walletConfig, }, dependencies: agentDependencies, + modules: getDefaultDidcommModules(), }, dependencyManager ) @@ -112,6 +115,7 @@ describe('UpdateAssistant | v0.2 - v0.3.1', () => { walletConfig, autoUpdateStorageOnStartup: true, }, + modules: getDefaultDidcommModules(), dependencies: agentDependencies, }, dependencyManager @@ -163,6 +167,7 @@ describe('UpdateAssistant | v0.2 - v0.3.1', () => { autoUpdateStorageOnStartup: true, }, dependencies: agentDependencies, + modules: getDefaultDidcommModules(), }, dependencyManager ) diff --git a/packages/core/src/storage/migration/__tests__/0.4.test.ts b/packages/core/src/storage/migration/__tests__/0.4.test.ts index 943e3f2c87..10985ccb4a 100644 --- a/packages/core/src/storage/migration/__tests__/0.4.test.ts +++ b/packages/core/src/storage/migration/__tests__/0.4.test.ts @@ -3,6 +3,7 @@ import path from 'path' import { InMemoryStorageService } from '../../../../../../tests/InMemoryStorageService' import { RegisteredAskarTestWallet } from '../../../../../askar/tests/helpers' +import { getDefaultDidcommModules } from '../../../../../didcomm/src/util/modules' import { agentDependencies } from '../../../../tests/helpers' import { Agent } from '../../../agent/Agent' import { InjectionSymbols } from '../../../constants' @@ -108,12 +109,14 @@ describe('UpdateAssistant | v0.4 - v0.5', () => { // If we register the AskarModule it will register the storage service, but we use in memory storage here dependencyManager.registerContextScoped(InjectionSymbols.Wallet, RegisteredAskarTestWallet) + // We need core DIDComm modules for this update to fully work const agent = new Agent( { config: { label: 'Test Agent', walletConfig, }, + modules: getDefaultDidcommModules(), dependencies: agentDependencies, }, dependencyManager @@ -171,12 +174,14 @@ describe('UpdateAssistant | v0.4 - v0.5', () => { // If we register the AskarModule it will register the storage service, but we use in memory storage here dependencyManager.registerContextScoped(InjectionSymbols.Wallet, RegisteredAskarTestWallet) + // We need core DIDComm modules for this update to fully work const agent = new Agent( { config: { label: 'Test Agent', walletConfig, }, + modules: getDefaultDidcommModules(), dependencies: agentDependencies, }, dependencyManager diff --git a/packages/core/src/storage/migration/__tests__/backup-askar.test.ts b/packages/core/src/storage/migration/__tests__/backup-askar.test.ts index e0cc031c55..a83129af3e 100644 --- a/packages/core/src/storage/migration/__tests__/backup-askar.test.ts +++ b/packages/core/src/storage/migration/__tests__/backup-askar.test.ts @@ -5,17 +5,18 @@ import { readFileSync, unlinkSync } from 'fs' import path from 'path' import { askarModule } from '../../../../../askar/tests/helpers' +import { CredentialExchangeRecord, CredentialRepository } from '../../../../../didcomm/src/modules/credentials' import { getAgentOptions, getAskarWalletConfig } from '../../../../tests/helpers' import { Agent } from '../../../agent/Agent' import { InjectionSymbols } from '../../../constants' import { CredoError } from '../../../error' -import { CredentialExchangeRecord, CredentialRepository } from '../../../../../didcomm/src/modules/credentials' import { JsonTransformer } from '../../../utils' import { StorageUpdateService } from '../StorageUpdateService' import { UpdateAssistant } from '../UpdateAssistant' const agentOptions = getAgentOptions( 'UpdateAssistant | Backup | Aries Askar', + {}, { walletConfig: getAskarWalletConfig('UpdateAssistant | Backup | Aries Askar', { inMemory: false }), }, diff --git a/packages/core/src/storage/migration/__tests__/backup.test.ts b/packages/core/src/storage/migration/__tests__/backup.test.ts index 165f55c749..094a8739f1 100644 --- a/packages/core/src/storage/migration/__tests__/backup.test.ts +++ b/packages/core/src/storage/migration/__tests__/backup.test.ts @@ -5,17 +5,18 @@ import { readFileSync, unlinkSync } from 'fs' import path from 'path' import { askarModule } from '../../../../../askar/tests/helpers' +import { CredentialExchangeRecord, CredentialRepository } from '../../../../../didcomm/src/modules/credentials' import { getAgentOptions, getAskarWalletConfig } from '../../../../tests/helpers' import { Agent } from '../../../agent/Agent' import { InjectionSymbols } from '../../../constants' import { CredoError } from '../../../error' -import { CredentialExchangeRecord, CredentialRepository } from '../../../../../didcomm/src/modules/credentials' import { JsonTransformer } from '../../../utils' import { StorageUpdateService } from '../StorageUpdateService' import { UpdateAssistant } from '../UpdateAssistant' const agentOptions = getAgentOptions( 'UpdateAssistant | Backup', + {}, { walletConfig: getAskarWalletConfig('UpdateAssistant | Backup', { inMemory: false, diff --git a/packages/core/src/storage/migration/updates.ts b/packages/core/src/storage/migration/updates.ts index 5a21db2e87..84fa9a2267 100644 --- a/packages/core/src/storage/migration/updates.ts +++ b/packages/core/src/storage/migration/updates.ts @@ -28,6 +28,16 @@ export const DEFAULT_UPDATE_CONFIG: UpdateConfig = { } export const supportedUpdates = [ + { + fromVersion: '0.1', + toVersion: '0.2', + doUpdate: () => {}, // Nothing to do in Core module + }, + { + fromVersion: '0.2', + toVersion: '0.3', + doUpdate: () => {}, // Nothing to do in Core module + }, { fromVersion: '0.3', toVersion: '0.3.1', diff --git a/packages/core/src/utils/__tests__/MessageValidator.test.ts b/packages/core/src/utils/__tests__/MessageValidator.test.ts index 077159bd9e..5a3dd5126f 100644 --- a/packages/core/src/utils/__tests__/MessageValidator.test.ts +++ b/packages/core/src/utils/__tests__/MessageValidator.test.ts @@ -1,5 +1,5 @@ +import { ConnectionInvitationMessage } from '../../../../didcomm/src/modules/connections' import { ClassValidationError } from '../../error/ClassValidationError' -import { ConnectionInvitationMessage } from '../../../../didcomm/src/messages' import { MessageValidator } from '../MessageValidator' describe('MessageValidator', () => { diff --git a/packages/core/tests/middleware.test.ts b/packages/core/tests/middleware.test.ts index f126bc2e9b..f624d14296 100644 --- a/packages/core/tests/middleware.test.ts +++ b/packages/core/tests/middleware.test.ts @@ -1,5 +1,5 @@ import type { SubjectMessage } from '../../../tests/transport/SubjectInboundTransport' -import type { ConnectionRecord, InboundMessageContext } from '../src' +import type { ConnectionRecord, InboundMessageContext } from '../../didcomm' import { Subject } from 'rxjs' @@ -11,9 +11,8 @@ import { getOutboundMessageContext, MessageSender, AgentMessage, - JsonTransformer, - Agent, -} from '../src' +} from '../../didcomm/src' +import { JsonTransformer, Agent } from '../src' import { getInMemoryAgentOptions, @@ -46,13 +45,13 @@ describe('Message Handler Middleware E2E', () => { } faberAgent = new Agent(faberConfig) - faberAgent.didcomm.registerInboundTransport(new SubjectInboundTransport(faberMessages)) - faberAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) + faberAgent.modules.didcomm.registerInboundTransport(new SubjectInboundTransport(faberMessages)) + faberAgent.modules.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) await faberAgent.initialize() aliceAgent = new Agent(aliceConfig) - aliceAgent.didcomm.registerInboundTransport(new SubjectInboundTransport(aliceMessages)) - aliceAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) + aliceAgent.modules.didcomm.registerInboundTransport(new SubjectInboundTransport(aliceMessages)) + aliceAgent.modules.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) await aliceAgent.initialize() ;[aliceConnection, faberConnection] = await makeConnection(aliceAgent, faberAgent) }) @@ -66,7 +65,7 @@ describe('Message Handler Middleware E2E', () => { test('Correctly calls the fallback message handler if no message handler is defined', async () => { // Fallback message handler - aliceAgent.didcomm.setFallbackMessageHandler((messageContext) => { + aliceAgent.modules.didcomm.setFallbackMessageHandler((messageContext) => { return getOutboundMessageContext(messageContext.agentContext, { connectionRecord: messageContext.connection, message: new BasicMessage({ @@ -98,17 +97,19 @@ describe('Message Handler Middleware E2E', () => { }) test('Correctly calls the registered message handler middleware', async () => { - aliceAgent.didcomm.registerMessageHandlerMiddleware(async (inboundMessageContext: InboundMessageContext, next) => { - await next() - - if (inboundMessageContext.responseMessage) { - inboundMessageContext.responseMessage.message.setTiming({ - outTime: new Date('2021-01-01'), - }) + aliceAgent.modules.didcomm.registerMessageHandlerMiddleware( + async (inboundMessageContext: InboundMessageContext, next) => { + await next() + + if (inboundMessageContext.responseMessage) { + inboundMessageContext.responseMessage.message.setTiming({ + outTime: new Date('2021-01-01'), + }) + } } - }) + ) - await faberAgent.connections.sendPing(faberConnection.id, {}) + await faberAgent.modules.connections.sendPing(faberConnection.id, {}) const receiveMessage = await waitForAgentMessageProcessedEvent(faberAgent, { messageType: TrustPingResponseMessage.type.messageTypeUri, }) diff --git a/packages/core/tests/oob.test.ts b/packages/core/tests/oob.test.ts index 8c1835a97d..778d9d5edf 100644 --- a/packages/core/tests/oob.test.ts +++ b/packages/core/tests/oob.test.ts @@ -1026,38 +1026,6 @@ describe('out of band', () => { }) }) - test('legacy connectionless exchange without receiving message through oob receiveInvitation, where response is received to invitation', async () => { - const { message, credentialRecord } = await faberAgent.modules.credentials.createOffer(credentialTemplate) - const { message: messageWithService } = await faberAgent.modules.oob.createLegacyConnectionlessInvitation({ - domain: 'http://example.com', - message, - recordId: credentialRecord.id, - }) - - const aliceCredentialRecordPromise = waitForCredentialRecord(aliceAgent, { - state: CredentialState.OfferReceived, - threadId: message.threadId, - timeoutMs: 10000, - }) - await aliceAgent.modules.receiveMessage(messageWithService.toJSON()) - - const aliceCredentialRecord = await aliceCredentialRecordPromise - expect(aliceCredentialRecord.state).toBe(CredentialState.OfferReceived) - - // If we receive the event, we know the processing went well - const faberCredentialRecordPromise = waitForCredentialRecord(faberAgent, { - state: CredentialState.RequestReceived, - threadId: message.threadId, - timeoutMs: 10000, - }) - - await aliceAgent.modules.credentials.acceptOffer({ - credentialRecordId: aliceCredentialRecord.id, - }) - - await faberCredentialRecordPromise - }) - test('add ~service decorator to the message and returns invitation url in createLegacyConnectionlessInvitation', async () => { const { message, credentialRecord } = await faberAgent.modules.credentials.createOffer(credentialTemplate) diff --git a/packages/didcomm/src/updates/0.1-0.2/connection.ts b/packages/didcomm/src/updates/0.1-0.2/connection.ts index 9d3a1d2e05..59ced9e16c 100644 --- a/packages/didcomm/src/updates/0.1-0.2/connection.ts +++ b/packages/didcomm/src/updates/0.1-0.2/connection.ts @@ -1,6 +1,5 @@ -import type { BaseAgent, JsonObject } from '@credo-ts/core' - import type { ConnectionRecord } from '../../modules/connections' +import type { BaseAgent, JsonObject } from '@credo-ts/core' import { DidKey, @@ -22,9 +21,10 @@ import { DidExchangeRole, } from '../../modules/connections' import { convertToNewDidDocument } from '../../modules/connections/services/helpers' +import { convertToNewInvitation } from '../../modules/oob/converters' import { OutOfBandRole } from '../../modules/oob/domain/OutOfBandRole' import { OutOfBandState } from '../../modules/oob/domain/OutOfBandState' -import { convertToNewInvitation, outOfBandServiceToInlineKeysNumAlgo2Did } from '../../modules/oob/helpers' +import { outOfBandServiceToInlineKeysNumAlgo2Did } from '../../modules/oob/helpers' import { OutOfBandRecord, OutOfBandRepository } from '../../modules/oob/repository' /** diff --git a/packages/didcomm/src/updates/0.1-0.2/credential.ts b/packages/didcomm/src/updates/0.1-0.2/credential.ts index 4f36b17241..186764464f 100644 --- a/packages/didcomm/src/updates/0.1-0.2/credential.ts +++ b/packages/didcomm/src/updates/0.1-0.2/credential.ts @@ -1,9 +1,9 @@ -import type { BaseAgent, JsonObject } from '@credo-ts/core' - import type { CredentialExchangeRecord } from '../../modules/credentials' import type { PlaintextMessage } from '../../types' +import type { BaseAgent, JsonObject } from '@credo-ts/core' import { Metadata } from '@credo-ts/core' + import { CredentialState } from '../../modules/credentials/models/CredentialState' import { CredentialRepository } from '../../modules/credentials/repository/CredentialRepository' import { DidCommMessageRole, DidCommMessageRepository, DidCommMessageRecord } from '../../repository' diff --git a/packages/didcomm/src/updates/0.1-0.2/mediation.ts b/packages/didcomm/src/updates/0.1-0.2/mediation.ts index 46e4b1c48c..bf30bb5b6f 100644 --- a/packages/didcomm/src/updates/0.1-0.2/mediation.ts +++ b/packages/didcomm/src/updates/0.1-0.2/mediation.ts @@ -1,6 +1,5 @@ -import type { BaseAgent } from '@credo-ts/core' -import type { V0_1ToV0_2UpdateConfig } from '@credo-ts/core' import type { MediationRecord } from '../../modules/routing' +import type { BaseAgent, V0_1ToV0_2UpdateConfig } from '@credo-ts/core' import { MediationRepository, MediationRole } from '../../modules/routing' diff --git a/packages/tenants/src/updates/__tests__/0.4.test.ts b/packages/tenants/src/updates/__tests__/0.4.test.ts index 11af20ab6a..2ca0225661 100644 --- a/packages/tenants/src/updates/__tests__/0.4.test.ts +++ b/packages/tenants/src/updates/__tests__/0.4.test.ts @@ -1,11 +1,5 @@ -import { - DependencyManager, - InjectionSymbols, - Agent, - UpdateAssistant, - utils, - MediatorRoutingRecord, -} from '@credo-ts/core' +import { DependencyManager, InjectionSymbols, Agent, UpdateAssistant, utils } from '@credo-ts/core' +import { MediatorRoutingRecord } from '@credo-ts/didcomm' import { agentDependencies } from '@credo-ts/node' import { readFileSync } from 'fs' import path from 'path' diff --git a/packages/tenants/tests/tenants-storage-update.test.ts b/packages/tenants/tests/tenants-storage-update.test.ts index 28eb14293f..e443893440 100644 --- a/packages/tenants/tests/tenants-storage-update.test.ts +++ b/packages/tenants/tests/tenants-storage-update.test.ts @@ -1,19 +1,14 @@ import type { InitConfig, FileSystem } from '@credo-ts/core' -import { - UpdateAssistant, - InjectionSymbols, - ConnectionsModule, - Agent, - CacheModule, - InMemoryLruCache, -} from '@credo-ts/core' +import { UpdateAssistant, InjectionSymbols, Agent, CacheModule, InMemoryLruCache } from '@credo-ts/core' +import { ConnectionsModule } from '@credo-ts/didcomm' import { agentDependencies } from '@credo-ts/node' import path from 'path' import { AskarModule, AskarMultiWalletDatabaseScheme } from '../../askar/src' import { ariesAskar } from '../../askar/tests/helpers' import { testLogger } from '../../core/tests' +import { getDefaultDidcommModules } from '../../didcomm/src/util/modules' import { TenantSessionCoordinator } from '../src/context/TenantSessionCoordinator' import { TenantsModule } from '@credo-ts/tenants' @@ -28,6 +23,7 @@ const agentConfig = { } satisfies InitConfig const modules = { + ...getDefaultDidcommModules(), tenants: new TenantsModule(), askar: new AskarModule({ ariesAskar, diff --git a/packages/tenants/tests/tenants.test.ts b/packages/tenants/tests/tenants.test.ts index 03e1581093..0dcdb9b72a 100644 --- a/packages/tenants/tests/tenants.test.ts +++ b/packages/tenants/tests/tenants.test.ts @@ -1,6 +1,8 @@ -import type { DidCommModuleConfigOptions, InitConfig } from '@credo-ts/core' +import type { InitConfig } from '@credo-ts/core' +import type { DidCommModuleConfigOptions } from '@credo-ts/didcomm' -import { ConnectionsModule, OutOfBandRecord, Agent, CacheModule, InMemoryLruCache, DidCommModule } from '@credo-ts/core' +import { Agent, CacheModule, InMemoryLruCache } from '@credo-ts/core' +import { ConnectionsModule, OutOfBandRecord, DidCommModule } from '@credo-ts/didcomm' import { agentDependencies } from '@credo-ts/node' import { InMemoryWalletModule } from '../../../tests/InMemoryWalletModule' @@ -73,16 +75,16 @@ const agent2 = new Agent({ const agent1InboundTransport = new SubjectInboundTransport() const agent2InboundTransport = new SubjectInboundTransport() -agent1.didcomm.registerInboundTransport(agent1InboundTransport) -agent2.didcomm.registerInboundTransport(agent2InboundTransport) +agent1.modules.didcomm.registerInboundTransport(agent1InboundTransport) +agent2.modules.didcomm.registerInboundTransport(agent2InboundTransport) -agent1.didcomm.registerOutboundTransport( +agent1.modules.didcomm.registerOutboundTransport( new SubjectOutboundTransport({ 'rxjs:tenant-agent1': agent1InboundTransport.ourSubject, 'rxjs:tenant-agent2': agent2InboundTransport.ourSubject, }) ) -agent2.didcomm.registerOutboundTransport( +agent2.modules.didcomm.registerOutboundTransport( new SubjectOutboundTransport({ 'rxjs:tenant-agent1': agent1InboundTransport.ourSubject, 'rxjs:tenant-agent2': agent2InboundTransport.ourSubject, @@ -170,27 +172,27 @@ describe('Tenants E2E', () => { }) // Create and receive oob invitation in scope of tenants - const outOfBandRecord = await tenantAgent1.oob.createInvitation() - const { connectionRecord: tenant2ConnectionRecord } = await tenantAgent2.oob.receiveInvitation( + const outOfBandRecord = await tenantAgent1.modules.oob.createInvitation() + const { connectionRecord: tenant2ConnectionRecord } = await tenantAgent2.modules.oob.receiveInvitation( outOfBandRecord.outOfBandInvitation ) // Retrieve all oob records for the base and tenant agent, only the // tenant agent should have a record. - const baseAgentOutOfBandRecords = await agent1.oob.getAll() - const tenantAgent1OutOfBandRecords = await tenantAgent1.oob.getAll() - const tenantAgent2OutOfBandRecords = await tenantAgent2.oob.getAll() + const baseAgentOutOfBandRecords = await agent1.modules.oob.getAll() + const tenantAgent1OutOfBandRecords = await tenantAgent1.modules.oob.getAll() + const tenantAgent2OutOfBandRecords = await tenantAgent2.modules.oob.getAll() expect(baseAgentOutOfBandRecords.length).toBe(0) expect(tenantAgent1OutOfBandRecords.length).toBe(1) expect(tenantAgent2OutOfBandRecords.length).toBe(1) if (!tenant2ConnectionRecord) throw new Error('Receive invitation did not return connection record') - await tenantAgent2.connections.returnWhenIsConnected(tenant2ConnectionRecord.id) + await tenantAgent2.modules.connections.returnWhenIsConnected(tenant2ConnectionRecord.id) // Find the connection record for the created oob invitation - const [connectionRecord] = await tenantAgent1.connections.findAllByOutOfBandId(outOfBandRecord.id) - await tenantAgent1.connections.returnWhenIsConnected(connectionRecord.id) + const [connectionRecord] = await tenantAgent1.modules.connections.findAllByOutOfBandId(outOfBandRecord.id) + await tenantAgent1.modules.connections.returnWhenIsConnected(connectionRecord.id) await tenantAgent1.endSession() await tenantAgent2.endSession() @@ -221,17 +223,17 @@ describe('Tenants E2E', () => { }) // Create and receive oob invitation in scope of tenants - const outOfBandRecord = await tenantAgent1.oob.createInvitation() - const { connectionRecord: tenant2ConnectionRecord } = await tenantAgent2.oob.receiveInvitation( + const outOfBandRecord = await tenantAgent1.modules.oob.createInvitation() + const { connectionRecord: tenant2ConnectionRecord } = await tenantAgent2.modules.oob.receiveInvitation( outOfBandRecord.outOfBandInvitation ) if (!tenant2ConnectionRecord) throw new Error('Receive invitation did not return connection record') - await tenantAgent2.connections.returnWhenIsConnected(tenant2ConnectionRecord.id) + await tenantAgent2.modules.connections.returnWhenIsConnected(tenant2ConnectionRecord.id) // Find the connection record for the created oob invitation - const [connectionRecord] = await tenantAgent1.connections.findAllByOutOfBandId(outOfBandRecord.id) - await tenantAgent1.connections.returnWhenIsConnected(connectionRecord.id) + const [connectionRecord] = await tenantAgent1.modules.connections.findAllByOutOfBandId(outOfBandRecord.id) + await tenantAgent1.modules.connections.returnWhenIsConnected(connectionRecord.id) await tenantAgent1.endSession() await tenantAgent2.endSession() @@ -249,7 +251,7 @@ describe('Tenants E2E', () => { }) await agent1.modules.tenants.withTenantAgent({ tenantId: tenantRecord.id }, async (tenantAgent) => { - const outOfBandRecord = await tenantAgent.oob.createInvitation() + const outOfBandRecord = await tenantAgent.modules.oob.createInvitation() expect(outOfBandRecord).toBeInstanceOf(OutOfBandRecord) expect(tenantAgent.context.contextCorrelationId).toBe(tenantRecord.id) @@ -260,15 +262,15 @@ describe('Tenants E2E', () => { }) test('fallback middleware for the tenant manager propagated to the tenant', async () => { - expect(agent1.didcomm.fallbackMessageHandler).toBeUndefined() + expect(agent1.modules.didcomm.fallbackMessageHandler).toBeUndefined() const fallbackFunction = async () => { // empty } - agent1.didcomm.setFallbackMessageHandler(fallbackFunction) + agent1.modules.didcomm.setFallbackMessageHandler(fallbackFunction) - expect(agent1.didcomm.fallbackMessageHandler).toBe(fallbackFunction) + expect(agent1.modules.didcomm.fallbackMessageHandler).toBe(fallbackFunction) const tenantRecord = await agent1.modules.tenants.createTenant({ config: { @@ -280,7 +282,7 @@ describe('Tenants E2E', () => { tenantId: tenantRecord.id, }) - expect(tenantAgent.didcomm.fallbackMessageHandler).toBe(fallbackFunction) + expect(tenantAgent.modules.didcomm.fallbackMessageHandler).toBe(fallbackFunction) await tenantAgent.endSession() })