Skip to content

Commit

Permalink
refactor: move to separate didcomm package
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Dec 19, 2024
1 parent 9d934af commit ededb58
Show file tree
Hide file tree
Showing 706 changed files with 6,083 additions and 6,156 deletions.
2 changes: 1 addition & 1 deletion demo/src/Alice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConnectionRecord, CredentialExchangeRecord, ProofExchangeRecord } from '@credo-ts/core'
import type { ConnectionRecord, CredentialExchangeRecord, ProofExchangeRecord } from '@credo-ts/didcomm'

import { BaseAgent } from './BaseAgent'
import { greenText, Output, redText } from './OutputClass'
Expand Down
2 changes: 1 addition & 1 deletion demo/src/AliceInquirer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CredentialExchangeRecord, ProofExchangeRecord } from '@credo-ts/core'
import type { CredentialExchangeRecord, ProofExchangeRecord } from '@credo-ts/didcomm'

import { clear } from 'console'
import { textSync } from 'figlet'
Expand Down
1 change: 1 addition & 0 deletions packages/action-menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@credo-ts/core": "workspace:*",
"@credo-ts/didcomm": "workspace:*",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"rxjs": "^7.8.0"
Expand Down
24 changes: 10 additions & 14 deletions packages/action-menu/src/ActionMenuApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ import type {
SendMenuOptions,
} from './ActionMenuApiOptions'

import {
AgentContext,
CredoError,
ConnectionService,
MessageSender,
injectable,
getOutboundMessageContext,
} from '@credo-ts/core'
import { AgentContext, CredoError, injectable } from '@credo-ts/core'
import { ConnectionService, MessageSender, getOutboundMessageContext, MessageHandlerRegistry } from '@credo-ts/didcomm'

import { ActionMenuRole } from './ActionMenuRole'
import {
Expand Down Expand Up @@ -45,12 +39,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
13 changes: 8 additions & 5 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 { AgentContext, DependencyManager, Module } from '@credo-ts/core'

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

import { ActionMenuApi } from './ActionMenuApi'
import { ActionMenuRole } from './ActionMenuRole'
Expand All @@ -16,19 +16,22 @@ 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)
}

public async initialize(agentContext: AgentContext): Promise<void> {
// Feature Registry
const featureRegistry = agentContext.dependencyManager.resolve(FeatureRegistry)

featureRegistry.register(
new Protocol({
id: 'https://didcomm.org/action-menu/1.0',
roles: [ActionMenuRole.Requester, ActionMenuRole.Responder],
})
)
}))
}
}
16 changes: 9 additions & 7 deletions packages/action-menu/src/__tests__/ActionMenuModule.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import type { DependencyManager, FeatureRegistry } from '@credo-ts/core'
import type { DependencyManager } from '@credo-ts/core'
import type { FeatureRegistry } from '@credo-ts/didcomm'

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

import { ActionMenuModule } from '../ActionMenuModule'
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ActionMenuProblemReportReason } from './ActionMenuProblemReportReason'
import type { ProblemReportErrorOptions } from '@credo-ts/core'
import type { ProblemReportErrorOptions } from '@credo-ts/didcomm'

import { ProblemReportError } from '@credo-ts/core'
import { ProblemReportError } from '@credo-ts/didcomm'

import { ActionMenuProblemReportMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ActionMenuService } from '../services'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/didcomm'

import { ActionMenuProblemReportMessage } from '../messages'

Expand Down
2 changes: 1 addition & 1 deletion packages/action-menu/src/handlers/MenuMessageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ActionMenuService } from '../services'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/didcomm'

import { MenuMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ActionMenuService } from '../services'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/didcomm'

import { MenuRequestMessage } from '../messages'

Expand Down
2 changes: 1 addition & 1 deletion packages/action-menu/src/handlers/PerformMessageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ActionMenuService } from '../services'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/didcomm'

import { PerformMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ProblemReportMessageOptions } from '@credo-ts/core'
import type { ProblemReportMessageOptions } from '@credo-ts/didcomm'

import { IsValidMessageType, parseMessageType, ProblemReportMessage } from '@credo-ts/core'
import { IsValidMessageType, parseMessageType, ProblemReportMessage } from '@credo-ts/didcomm'

export type ActionMenuProblemReportMessageOptions = ProblemReportMessageOptions

Expand Down
2 changes: 1 addition & 1 deletion packages/action-menu/src/messages/MenuMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ActionMenuOptionOptions } from '../models'

import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/core'
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/didcomm'
import { Expose, Type } from 'class-transformer'
import { IsInstance, IsOptional, IsString } from 'class-validator'

Expand Down
2 changes: 1 addition & 1 deletion packages/action-menu/src/messages/MenuRequestMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/core'
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/didcomm'

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/action-menu/src/messages/PerformMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/core'
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/didcomm'
import { IsOptional, IsString } from 'class-validator'

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/action-menu/src/services/ActionMenuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
} from './ActionMenuServiceOptions'
import type { ActionMenuStateChangedEvent } from '../ActionMenuEvents'
import type { ActionMenuProblemReportMessage } from '../messages'
import type { AgentContext, InboundMessageContext, Logger, Query, QueryOptions } from '@credo-ts/core'
import type { AgentContext, Logger, Query, QueryOptions } from '@credo-ts/core'
import type { InboundMessageContext } from '@credo-ts/didcomm'

import { AgentConfig, EventEmitter, CredoError, injectable } from '@credo-ts/core'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ActionMenuRole } from '../ActionMenuRole'
import type { ActionMenuSelection } from '../models'
import type { ActionMenu } from '../models/ActionMenu'
import type { ActionMenuRecord } from '../repository'
import type { ConnectionRecord } from '@credo-ts/core'
import type { ConnectionRecord } from '@credo-ts/didcomm'

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { ActionMenuStateChangedEvent } from '../../ActionMenuEvents'
import type { ActionMenuSelection } from '../../models'
import type { AgentContext, AgentConfig, Repository } from '@credo-ts/core'

import { DidExchangeState, EventEmitter, InboundMessageContext } from '@credo-ts/core'
import { EventEmitter } from '@credo-ts/core'
import { DidExchangeState, InboundMessageContext } from '@credo-ts/didcomm'
import { Subject } from 'rxjs'

import {
Expand Down
4 changes: 3 additions & 1 deletion packages/action-menu/tests/action-menu.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConnectionRecord } from '@credo-ts/core'
import type { ConnectionRecord } from '@credo-ts/didcomm'

import { Agent } from '@credo-ts/core'

Expand All @@ -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
1 change: 1 addition & 0 deletions packages/anoncreds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@astronautlabs/jsonpath": "^1.1.2",
"@credo-ts/core": "workspace:*",
"@credo-ts/didcomm": "workspace:*",
"@sphereon/pex-models": "^2.3.1",
"big-integer": "^1.6.51",
"bn.js": "^5.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnonCredsCredential, AnonCredsCredentialOffer, AnonCredsCredentialRequest } from '../models'
import type { CredentialPreviewAttributeOptions, CredentialFormat, LinkedAttachment } from '@credo-ts/core'
import type { CredentialPreviewAttributeOptions, CredentialFormat, LinkedAttachment } from '@credo-ts/didcomm'

export interface AnonCredsCredentialProposalFormat {
schema_issuer_id?: string
Expand Down
17 changes: 4 additions & 13 deletions packages/anoncreds/src/formats/AnonCredsCredentialFormatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { AnonCredsCredentialFormat, AnonCredsCredentialProposalFormat } fro
import type { AnonCredsCredential, AnonCredsCredentialOffer, AnonCredsCredentialRequest } from '../models'
import type { AnonCredsIssuerService, AnonCredsHolderService } from '../services'
import type { AnonCredsCredentialMetadata, AnonCredsCredentialRequestMetadata } from '../utils/metadata'
import type { AgentContext } from '@credo-ts/core'
import type {
CredentialFormatService,
AgentContext,
CredentialFormatCreateProposalOptions,
CredentialFormatCreateProposalReturn,
CredentialFormatProcessOptions,
Expand All @@ -22,19 +22,10 @@ import type {
CredentialExchangeRecord,
CredentialPreviewAttributeOptions,
LinkedAttachment,
} from '@credo-ts/core'
} from '@credo-ts/didcomm'

import {
ProblemReportError,
MessageValidator,
CredentialFormatSpec,
CredoError,
Attachment,
JsonEncoder,
utils,
CredentialProblemReportReason,
JsonTransformer,
} from '@credo-ts/core'
import { MessageValidator, CredoError, JsonEncoder, utils, JsonTransformer } from '@credo-ts/core'
import { ProblemReportError, CredentialFormatSpec, Attachment, CredentialProblemReportReason } from '@credo-ts/didcomm'

import { AnonCredsCredentialProposal } from '../models/AnonCredsCredentialProposal'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/anoncreds/src/formats/AnonCredsProofFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
AnonCredsRequestedPredicateMatch,
AnonCredsSelectedCredentials,
} from '../models'
import type { ProofFormat } from '@credo-ts/core'
import type { ProofFormat } from '@credo-ts/didcomm'

export interface AnonCredsPresentationPreviewAttribute {
name: string
Expand Down
7 changes: 4 additions & 3 deletions packages/anoncreds/src/formats/AnonCredsProofFormatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type {
AnonCredsProofRequest,
} from '../models'
import type { AnonCredsHolderService, AnonCredsVerifierService } from '../services'
import type { AgentContext } from '@credo-ts/core'
import type {
ProofFormatService,
AgentContext,
ProofFormatCreateReturn,
FormatCreateRequestOptions,
ProofFormatCreateProposalOptions,
Expand All @@ -24,9 +24,10 @@ import type {
ProofFormatAutoRespondProposalOptions,
ProofFormatAutoRespondRequestOptions,
ProofFormatAutoRespondPresentationOptions,
} from '@credo-ts/core'
} from '@credo-ts/didcomm'

import { CredoError, Attachment, AttachmentData, JsonEncoder, ProofFormatSpec, JsonTransformer } from '@credo-ts/core'
import { CredoError, JsonEncoder, JsonTransformer } from '@credo-ts/core'
import { Attachment, AttachmentData, ProofFormatSpec } from '@credo-ts/didcomm'

import { AnonCredsProofRequest as AnonCredsProofRequestClass } from '../models/AnonCredsProofRequest'
import { AnonCredsVerifierServiceSymbol, AnonCredsHolderServiceSymbol } from '../services'
Expand Down
Loading

0 comments on commit ededb58

Please sign in to comment.