Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/veritable-cloudagent",
"version": "0.20.35",
"version": "0.20.46",
"main": "build/index",
"type": "module",
"types": "build/index",
Expand Down
56 changes: 37 additions & 19 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { DrpcModule } from '@credo-ts/drpc'
import { agentDependencies, DidCommHttpInboundTransport, DidCommWsInboundTransport } from '@credo-ts/node'
import { askarNodeJS } from '@openwallet-foundation/askar-nodejs'
import { container } from 'tsyringe'
import type { WebSocketServer } from 'ws'

import { AskarModule, type AskarModuleConfigStoreOptions } from '@credo-ts/askar'
import VeritableAnonCredsRegistry from './anoncreds/index.js'
Expand All @@ -51,11 +52,6 @@ type AgentProofProtocols = [
DidCommProofV2Protocol<[AnonCredsDidCommProofFormatService, DidCommDifPresentationExchangeProofFormatService]>,
]

const inboundTransportMapping = {
http: DidCommHttpInboundTransport,
ws: DidCommWsInboundTransport,
} as const

const outboundTransportMapping = {
http: DidCommHttpOutboundTransport,
ws: DidCommWsOutboundTransport,
Expand All @@ -81,6 +77,7 @@ export type AriesRestConfig = {
ipfsTimeoutMs: number

verifiedDrpcOptions: VerifiedDrpcModuleConfigOptions<AgentProofProtocols>
didcommWsSocketServer?: WebSocketServer

logger: PinoLogger
}
Expand Down Expand Up @@ -212,6 +209,8 @@ export async function setupAgent(restConfig: AriesRestConfig) {
ipfsOrigin,
ipfsTimeoutMs,
verifiedDrpcOptions,
didcommWsSocketServer,
logger,

agentConfig,
askarStoreConfig,
Expand Down Expand Up @@ -246,28 +245,47 @@ export async function setupAgent(restConfig: AriesRestConfig) {
}

// Register inbound transports
let externalWsServerAssigned = false
for (const inboundTransport of inboundTransports) {
const InboundTransport = inboundTransportMapping[inboundTransport.transport]
agent.didcomm.registerInboundTransport(
new InboundTransport({ port: inboundTransport.port, processedMessageListenerTimeoutMs: 30000 })
)
if (inboundTransport.transport === 'http') {
agent.didcomm.registerInboundTransport(
new DidCommHttpInboundTransport({ port: inboundTransport.port, processedMessageListenerTimeoutMs: 30000 })
)
continue
}

if (didcommWsSocketServer && !externalWsServerAssigned) {
agent.didcomm.registerInboundTransport(new DidCommWsInboundTransport({ server: didcommWsSocketServer }))
externalWsServerAssigned = true
continue
}

agent.didcomm.registerInboundTransport(new DidCommWsInboundTransport({ port: inboundTransport.port }))
}

await agent.initialize()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] Credo 0.7.0 does not roll back modules when Agent.initialize() fails. DIDComm transports start before Askar opens the wallet, so a wallet initialisation failure leaves those transports running while the agent is never returned to startCloudagent(). Move agent.initialize() inside this cleanup try.


container.register(Agent, { useValue: agent as Agent })
try {
container.register(Agent, { useValue: agent as Agent })

const existingSecrets = await agent.modules.anoncreds.getLinkSecretIds()
if (existingSecrets.length === 0) {
await agent.modules.anoncreds.createLinkSecret({
setAsDefault: true,
})
}
const existingSecrets = await agent.modules.anoncreds.getLinkSecretIds()
if (existingSecrets.length === 0) {
await agent.modules.anoncreds.createLinkSecret({
setAsDefault: true,
})
}

agent.modules.verifiedDrpc.addRequestListener(verifiedDrpcRequestHandler)
agent.modules.verifiedDrpc.addRequestListener(verifiedDrpcRequestHandler)

const drpcReceiveHandler = container.resolve(DrpcReceiveHandler)
drpcReceiveHandler.start()
// Construct and register explicitly to avoid resolving a stale singleton bound to a previous agent.
const drpcReceiveHandler = new DrpcReceiveHandler(agent, logger)
container.register(DrpcReceiveHandler, { useValue: drpcReceiveHandler })
drpcReceiveHandler.start()
} catch (error) {
// Agent is already initialized at this point; shut it down so the caller's cleanup isn't skipped.
await agent.shutdown()
throw error
}

return agent
}
Loading
Loading