Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: didcomm module #2127

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
  •  
  •  
  •  
15 changes: 9 additions & 6 deletions packages/action-menu/src/ActionMenuApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
MessageSender,
injectable,
getOutboundMessageContext,
MessageHandlerRegistry,
} from '@credo-ts/core'

import { ActionMenuRole } from './ActionMenuRole'
Expand Down Expand Up @@ -45,12 +46,14 @@ export class ActionMenuApi {
this.actionMenuService = actionMenuService
this.agentContext = agentContext

this.agentContext.dependencyManager.registerMessageHandlers([
new ActionMenuProblemReportHandler(this.actionMenuService),
new MenuMessageHandler(this.actionMenuService),
new MenuRequestMessageHandler(this.actionMenuService),
new PerformMessageHandler(this.actionMenuService),
])
this.agentContext.dependencyManager
.resolve(MessageHandlerRegistry)
.registerMessageHandlers([
new ActionMenuProblemReportHandler(this.actionMenuService),
new MenuMessageHandler(this.actionMenuService),
new MenuRequestMessageHandler(this.actionMenuService),
new PerformMessageHandler(this.actionMenuService),
])
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/action-menu/src/ActionMenuModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DependencyManager, FeatureRegistry, Module } from '@credo-ts/core'
import type { DependencyManager, Module } from '@credo-ts/core'

import { Protocol } from '@credo-ts/core'
import { FeatureRegistry, Protocol } from '@credo-ts/core'

import { ActionMenuApi } from './ActionMenuApi'
import { ActionMenuRole } from './ActionMenuRole'
Expand All @@ -16,14 +16,16 @@ export class ActionMenuModule implements Module {
/**
* Registers the dependencies of the question answer module on the dependency manager.
*/
public register(dependencyManager: DependencyManager, featureRegistry: FeatureRegistry) {
public register(dependencyManager: DependencyManager) {
// Services
dependencyManager.registerSingleton(ActionMenuService)

// Repositories
dependencyManager.registerSingleton(ActionMenuRepository)

// Feature Registry
const featureRegistry = dependencyManager.resolve(FeatureRegistry)

featureRegistry.register(
new Protocol({
id: 'https://didcomm.org/action-menu/1.0',
Expand Down
11 changes: 6 additions & 5 deletions packages/action-menu/src/__tests__/ActionMenuModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import { ActionMenuRole } from '../ActionMenuRole'
import { ActionMenuRepository } from '../repository'
import { ActionMenuService } from '../services'

const featureRegistry = {
register: jest.fn(),
} as unknown as FeatureRegistry

const dependencyManager = {
registerInstance: jest.fn(),
registerSingleton: jest.fn(),
registerContextScoped: jest.fn(),
resolve: () => featureRegistry,
} as unknown as DependencyManager

const featureRegistry = {
register: jest.fn(),
} as unknown as FeatureRegistry

describe('ActionMenuModule', () => {
test('registers dependencies on the dependency manager', () => {
const actionMenuModule = new ActionMenuModule()
actionMenuModule.register(dependencyManager, featureRegistry)
actionMenuModule.register(dependencyManager)

expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(2)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(ActionMenuService)
Expand Down
2 changes: 2 additions & 0 deletions packages/action-menu/tests/action-menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const faberAgentOptions = getInMemoryAgentOptions(
{
endpoints: ['rxjs:faber'],
},
{},
modules
)

Expand All @@ -25,6 +26,7 @@ const aliceAgentOptions = getInMemoryAgentOptions(
{
endpoints: ['rxjs:alice'],
},
{},
modules
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { LegacyIndyCredentialFormatService } from '../../../formats'
import type {
AgentContext,
AgentMessage,
DependencyManager,
FeatureRegistry,
CredentialProtocolOptions,
InboundMessageContext,
ProblemReportMessage,
ExtractCredentialFormats,
CredentialProtocol,
FeatureRegistry,
MessageHandlerRegistry,
} from '@credo-ts/core'

import {
Expand Down Expand Up @@ -82,9 +82,9 @@ export class V1CredentialProtocol
/**
* Registers the protocol implementation (handlers, feature registry) on the agent.
*/
public register(dependencyManager: DependencyManager, featureRegistry: FeatureRegistry) {
public register(messageHandlerRegistry: MessageHandlerRegistry, featureRegistry: FeatureRegistry) {
// Register message handlers for the Issue Credential V1 Protocol
dependencyManager.registerMessageHandlers([
messageHandlerRegistry.registerMessageHandlers([
new V1ProposeCredentialHandler(this),
new V1OfferCredentialHandler(this),
new V1RequestCredentialHandler(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import {
} from '@credo-ts/core'
import { Subject } from 'rxjs'

import { ConnectionService } from '../../../../../../core/src/modules/connections/services/ConnectionService'
import { CredentialRepository } from '../../../../../../core/src/modules/credentials/repository/CredentialRepository'
import { DidCommMessageRepository } from '../../../../../../core/src/storage/didcomm/DidCommMessageRepository'
import {
ConnectionService,
CredentialRepository,
DidCommMessageRepository,
} from '../../../../../../core/src/modules/didcomm'
import { getMockConnection, getAgentConfig, getAgentContext, mockFunction } from '../../../../../../core/tests/helpers'
import { LegacyIndyCredentialFormatService } from '../../../../formats/LegacyIndyCredentialFormatService'
import { convertAttributesToCredentialValues } from '../../../../utils/credential'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
} from '@credo-ts/core'
import { Subject } from 'rxjs'

import { ConnectionService } from '../../../../../../core/src/modules/connections/services/ConnectionService'
import { CredentialRepository } from '../../../../../../core/src/modules/credentials/repository/CredentialRepository'
import { DidCommMessageRepository } from '../../../../../../core/src/storage/didcomm/DidCommMessageRepository'
import {
ConnectionService,
CredentialRepository,
DidCommMessageRepository,
} from '../../../../../../core/src/modules/didcomm'
import { getAgentConfig, getAgentContext, getMockConnection, mockFunction } from '../../../../../../core/tests/helpers'
import { LegacyIndyCredentialFormatService } from '../../../../formats/LegacyIndyCredentialFormatService'
import { V1CredentialProtocol } from '../V1CredentialProtocol'
Expand Down
7 changes: 4 additions & 3 deletions packages/anoncreds/src/protocols/proofs/v1/V1ProofProtocol.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { LegacyIndyProofFormatService } from '../../../formats'
import type {
ProofProtocol,
DependencyManager,

Check failure on line 4 in packages/anoncreds/src/protocols/proofs/v1/V1ProofProtocol.ts

View workflow job for this annotation

GitHub Actions / Validate

'DependencyManager' is defined but never used
FeatureRegistry,
AgentContext,
ProofProtocolOptions,
InboundMessageContext,
AgentMessage,
ProblemReportMessage,
GetProofFormatDataReturn,
ProofFormat,
FeatureRegistry,
MessageHandlerRegistry,
} from '@credo-ts/core'

import {
Expand Down Expand Up @@ -77,9 +78,9 @@
/**
* Registers the protocol implementation (handlers, feature registry) on the agent.
*/
public register(dependencyManager: DependencyManager, featureRegistry: FeatureRegistry) {
public register(messageHandlerRegistry: MessageHandlerRegistry, featureRegistry: FeatureRegistry) {
// Register message handlers for the Issue Credential V1 Protocol
dependencyManager.registerMessageHandlers([
messageHandlerRegistry.registerMessageHandlers([
new V1ProposePresentationHandler(this),
new V1RequestPresentationHandler(this),
new V1PresentationHandler(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ describe('V1 Proofs - Connectionless - Indy', () => {
domain: 'https://a-domain.com',
})

for (const transport of faberAgent.outboundTransports) {
await faberAgent.unregisterOutboundTransport(transport)
for (const transport of faberAgent.didcomm.outboundTransports) {
await faberAgent.didcomm.unregisterOutboundTransport(transport)
}

await aliceAgent.oob.receiveInvitationFromUrl(invitationUrl)
Expand Down Expand Up @@ -364,6 +364,7 @@ describe('V1 Proofs - Connectionless - Indy', () => {
{
endpoints: ['rxjs:mediator'],
},
{},
{
mediator: new MediatorModule({
autoAcceptMediationRequests: true,
Expand All @@ -376,8 +377,8 @@ describe('V1 Proofs - Connectionless - Indy', () => {

// Initialize mediator
const mediatorAgent = new Agent(mediatorAgentOptions)
mediatorAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
mediatorAgent.registerInboundTransport(new SubjectInboundTransport(mediatorMessages))
mediatorAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
mediatorAgent.didcomm.registerInboundTransport(new SubjectInboundTransport(mediatorMessages))
await mediatorAgent.initialize()

const faberMediationOutOfBandRecord = await mediatorAgent.oob.createInvitation({
Expand All @@ -393,6 +394,7 @@ describe('V1 Proofs - Connectionless - Indy', () => {
const faberAgentOptions = getInMemoryAgentOptions(
`Connectionless proofs with mediator Faber-${unique}`,
{},
{},
{
...getAnonCredsIndyModules({
autoAcceptProofs: AutoAcceptProof.Always,
Expand All @@ -409,6 +411,7 @@ describe('V1 Proofs - Connectionless - Indy', () => {
const aliceAgentOptions = getInMemoryAgentOptions(
`Connectionless proofs with mediator Alice-${unique}`,
{},
{},
{
...getAnonCredsIndyModules({
autoAcceptProofs: AutoAcceptProof.Always,
Expand All @@ -423,11 +426,11 @@ describe('V1 Proofs - Connectionless - Indy', () => {
)

const faberAgent = new Agent(faberAgentOptions)
faberAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
faberAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
await faberAgent.initialize()

const aliceAgent = new Agent(aliceAgentOptions)
aliceAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
aliceAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
await aliceAgent.initialize()

const [faberReplay, aliceReplay] = setupEventReplaySubjects(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CredentialRecordBinding, CredentialState } from '../../../../../co

import { CredentialExchangeRecord, JsonTransformer } from '../../../../../core/src'
import { Agent } from '../../../../../core/src/agent/Agent'
import { CredentialRepository } from '../../../../../core/src/modules/credentials/repository/CredentialRepository'
import { CredentialRepository } from '../../../../../core/src/modules/didcomm'
import { getAgentConfig, getAgentContext, mockFunction } from '../../../../../core/tests'
import {
migrateIndyCredentialMetadataToAnonCredsMetadata,
Expand Down
1 change: 1 addition & 0 deletions packages/anoncreds/tests/anoncreds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const agent = new Agent(
getInMemoryAgentOptions(
'credo-anoncreds-package',
{},
{},
{
anoncreds: new AnonCredsModule({
autoCreateLinkSecret: false,
Expand Down
7 changes: 6 additions & 1 deletion packages/anoncreds/tests/legacyAnonCredsSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import {
// Helper type to get the type of the agents (with the custom modules) for the credential tests
export type AnonCredsTestsAgent = Agent<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ReturnType<typeof getAnonCredsIndyModules> & { mediationRecipient?: any; mediator?: any }
ReturnType<typeof getAnonCredsIndyModules> & { didcomm?: any; mediationRecipient?: any; mediator?: any }
>

export const getAnonCredsIndyModules = ({
Expand Down Expand Up @@ -327,6 +327,9 @@ export async function setupAnonCredsTests<
{
endpoints: ['rxjs:issuer'],
},
{
logger: testLogger,
},
getAnonCredsIndyModules({
autoAcceptCredentials,
autoAcceptProofs,
Expand All @@ -340,6 +343,7 @@ export async function setupAnonCredsTests<
{
endpoints: ['rxjs:holder'],
},
{},
getAnonCredsIndyModules({
autoAcceptCredentials,
autoAcceptProofs,
Expand All @@ -354,6 +358,7 @@ export async function setupAnonCredsTests<
{
endpoints: ['rxjs:verifier'],
},
{},
getAnonCredsIndyModules({
autoAcceptCredentials,
autoAcceptProofs,
Expand Down
10 changes: 6 additions & 4 deletions packages/askar/tests/askar-inmemory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const aliceInMemoryAgentOptions = getAskarSqliteAgentOptions(
{
endpoints: ['rxjs:alice'],
},
{},
true
)
const bobInMemoryAgentOptions = getAskarSqliteAgentOptions(
'AgentsBob',
{
endpoints: ['rxjs:bob'],
},
{},
true
)

Expand Down Expand Up @@ -50,13 +52,13 @@ describe('Askar In Memory agents', () => {
}

aliceAgent = new Agent(aliceInMemoryAgentOptions)
aliceAgent.registerInboundTransport(new SubjectInboundTransport(aliceMessages))
aliceAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
aliceAgent.didcomm.registerInboundTransport(new SubjectInboundTransport(aliceMessages))
aliceAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
await aliceAgent.initialize()

bobAgent = new Agent(bobInMemoryAgentOptions)
bobAgent.registerInboundTransport(new SubjectInboundTransport(bobMessages))
bobAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
bobAgent.didcomm.registerInboundTransport(new SubjectInboundTransport(bobMessages))
bobAgent.didcomm.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
await bobAgent.initialize()

await e2eTest(aliceAgent, bobAgent)
Expand Down
12 changes: 9 additions & 3 deletions packages/askar/tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AskarWalletPostgresStorageConfig } from '../src/wallet'
import type { Agent, InitConfig } from '@credo-ts/core'
import type { Agent, DidCommModuleConfig, InitConfig } from '@credo-ts/core'

import { ConnectionsModule, HandshakeProtocol, LogLevel, utils } from '@credo-ts/core'
import { DidCommModule, ConnectionsModule, HandshakeProtocol, LogLevel, utils } from '@credo-ts/core'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { registerAriesAskar } from '@hyperledger/aries-askar-shared'
import path from 'path'
Expand Down Expand Up @@ -68,7 +68,12 @@ export function getAskarPostgresAgentOptions(
} as const
}

export function getAskarSqliteAgentOptions(name: string, extraConfig: Partial<InitConfig> = {}, inMemory?: boolean) {
export function getAskarSqliteAgentOptions(
name: string,
didcommConfig: Partial<DidCommModuleConfig> = {},
extraConfig: Partial<InitConfig> = {},
inMemory?: boolean
) {
const random = utils.uuid().slice(0, 4)
const config: InitConfig = {
label: `SQLiteAgent: ${name} - ${random}`,
Expand All @@ -86,6 +91,7 @@ export function getAskarSqliteAgentOptions(name: string, extraConfig: Partial<In
dependencies: agentDependencies,
modules: {
askar: new AskarModule(askarModuleConfig),
didcomm: new DidCommModule(didcommConfig),
connections: new ConnectionsModule({
autoAcceptConnections: true,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { V2IssueCredentialMessage } from '../../core/src/modules/credentials/protocol/v2/messages/V2IssueCredentialMessage'
import type { V2IssueCredentialMessage } from '../../core/src/modules/didcomm'
import type { EventReplaySubject, JsonLdTestsAgent } from '../../core/tests'

import { TypedArrayEncoder } from '../../core/src'
import { KeyType } from '../../core/src/crypto'
import { CredentialState } from '../../core/src/modules/credentials/models'
import { CredentialExchangeRecord } from '../../core/src/modules/credentials/repository/CredentialExchangeRecord'
import { CredentialState, CredentialExchangeRecord } from '../../core/src/modules/didcomm'
import { CREDENTIALS_CONTEXT_V1_URL, SECURITY_CONTEXT_BBS_URL } from '../../core/src/modules/vc'
import { JsonTransformer } from '../../core/src/utils/JsonTransformer'
import { waitForCredentialRecordSubject, setupJsonLdTests, testLogger } from '../../core/tests'
Expand Down
2 changes: 1 addition & 1 deletion packages/cheqd/tests/cheqd-did-registrar.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getInMemoryAgentOptions } from '../../core/tests/helpers'
import { validService } from './setup'
import { cheqdPayerSeeds, getCheqdModules } from './setupCheqdModule'

const agentOptions = getInMemoryAgentOptions('Faber Dids Registrar', {}, getCheqdModules(cheqdPayerSeeds[0]))
const agentOptions = getInMemoryAgentOptions('Faber Dids Registrar', {}, {}, getCheqdModules(cheqdPayerSeeds[0]))

describe('Cheqd DID registrar', () => {
let agent: Agent<ReturnType<typeof getCheqdModules>>
Expand Down
Loading
Loading