Skip to content

Commit

Permalink
Merge branch 'main' into feat/did-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoGlastra authored Dec 22, 2021
2 parents 40dbc37 + ef6b8bc commit a92476b
Show file tree
Hide file tree
Showing 79 changed files with 1,473 additions and 253 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ Some features are not yet supported, but are on our roadmap. Check [the roadmap]

- ✅ React Native
- ✅ Node.JS
- ✅ Report Problem Protocol ([RFC 0035](https://github.com/hyperledger/aries-rfcs/blob/main/features/0035-report-problem/README.md))
- ✅ Issue Credential Protocol ([RFC 0036](https://github.com/hyperledger/aries-rfcs/blob/master/features/0036-issue-credential/README.md))
- ✅ Present Proof Protocol ([RFC 0037](https://github.com/hyperledger/aries-rfcs/tree/master/features/0037-present-proof/README.md))
- ✅ Connection Protocol ([RFC 0160](https://github.com/hyperledger/aries-rfcs/blob/master/features/0160-connection-protocol/README.md))
- ✅ Basic Message Protocol ([RFC 0095](https://github.com/hyperledger/aries-rfcs/blob/master/features/0095-basic-message/README.md))
- ✅ Connection Protocol ([RFC 0160](https://github.com/hyperledger/aries-rfcs/blob/master/features/0160-connection-protocol/README.md))
- ✅ Mediator Coordination Protocol ([RFC 0211](https://github.com/hyperledger/aries-rfcs/blob/master/features/0211-route-coordination/README.md))
- ✅ Indy Credentials (with `did:sov` support)
- ✅ HTTP & WebSocket Transport
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export class Agent {
return this.wallet.publicDid
}

public async receiveMessage(inboundPackedMessage: unknown, session?: TransportSession) {
return await this.messageReceiver.receiveMessage(inboundPackedMessage, session)
public async receiveMessage(inboundMessage: unknown, session?: TransportSession) {
return await this.messageReceiver.receiveMessage(inboundMessage, session)
}

public get injectionContainer() {
Expand Down
31 changes: 22 additions & 9 deletions packages/core/src/agent/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Lifecycle, scoped } from 'tsyringe'
import { AgentConfig } from '../agent/AgentConfig'
import { AriesFrameworkError } from '../error/AriesFrameworkError'

import { ProblemReportMessage } from './../modules/problem-reports/messages/ProblemReportMessage'
import { EventEmitter } from './EventEmitter'
import { AgentEventTypes } from './Events'
import { MessageSender } from './MessageSender'
Expand Down Expand Up @@ -45,15 +46,27 @@ class Dispatcher {
try {
outboundMessage = await handler.handle(messageContext)
} catch (error) {
this.logger.error(`Error handling message with type ${message.type}`, {
message: message.toJSON(),
error,
senderVerkey: messageContext.senderVerkey,
recipientVerkey: messageContext.recipientVerkey,
connectionId: messageContext.connection?.id,
})

throw error
const problemReportMessage = error.problemReport

if (problemReportMessage instanceof ProblemReportMessage && messageContext.connection) {
problemReportMessage.setThread({
threadId: messageContext.message.threadId,
})
outboundMessage = {
payload: problemReportMessage,
connection: messageContext.connection,
}
} else {
this.logger.error(`Error handling message with type ${message.type}`, {
message: message.toJSON(),
error,
senderVerkey: messageContext.senderVerkey,
recipientVerkey: messageContext.recipientVerkey,
connectionId: messageContext.connection?.id,
})

throw error
}
}

if (outboundMessage && isOutboundServiceMessage(outboundMessage)) {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/agent/EnvelopeService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Logger } from '../logger'
import type { UnpackedMessageContext, WireMessage } from '../types'
import type { DecryptedMessageContext, EncryptedMessage } from '../types'
import type { AgentMessage } from './AgentMessage'

import { inject, scoped, Lifecycle } from 'tsyringe'
Expand Down Expand Up @@ -28,7 +28,7 @@ class EnvelopeService {
this.config = agentConfig
}

public async packMessage(payload: AgentMessage, keys: EnvelopeKeys): Promise<WireMessage> {
public async packMessage(payload: AgentMessage, keys: EnvelopeKeys): Promise<EncryptedMessage> {
const { routingKeys, senderKey } = keys
let recipientKeys = keys.recipientKeys

Expand All @@ -37,29 +37,29 @@ class EnvelopeService {

this.logger.debug(`Pack outbound message ${message['@type']}`)

let wireMessage = await this.wallet.pack(message, recipientKeys, senderKey ?? undefined)
let encryptedMessage = await this.wallet.pack(message, recipientKeys, senderKey ?? undefined)

// If the message has routing keys (mediator) pack for each mediator
for (const routingKey of routingKeys) {
const forwardMessage = new ForwardMessage({
// Forward to first recipient key
to: recipientKeys[0],
message: wireMessage,
message: encryptedMessage,
})
recipientKeys = [routingKey]
this.logger.debug('Forward message created', forwardMessage)

const forwardJson = forwardMessage.toJSON({ useLegacyDidSovPrefix: this.config.useLegacyDidSovPrefix })

// Forward messages are anon packed
wireMessage = await this.wallet.pack(forwardJson, [routingKey], undefined)
encryptedMessage = await this.wallet.pack(forwardJson, [routingKey], undefined)
}

return wireMessage
return encryptedMessage
}

public async unpackMessage(packedMessage: WireMessage): Promise<UnpackedMessageContext> {
return this.wallet.unpack(packedMessage)
public async unpackMessage(encryptedMessage: EncryptedMessage): Promise<DecryptedMessageContext> {
return this.wallet.unpack(encryptedMessage)
}
}

Expand Down
Loading

0 comments on commit a92476b

Please sign in to comment.