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

feat: add support for new out-of-band protocol #531

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
74f3ec7
Create OOB invitation
jakubkoci Oct 20, 2021
e31cafb
Receive OOB connection invitaion
jakubkoci Oct 20, 2021
103ebb3
Send and recevie request via OOB invitation
jakubkoci Nov 4, 2021
6528488
Separate OOB invitation and OOB message handling
jakubkoci Nov 5, 2021
ab6ec4e
Refactor and get rid of unnecessary dependencies to dispatcher and me…
jakubkoci Nov 8, 2021
5cf076d
Allow undefined handshake protocols and request attach attributes
jakubkoci Nov 8, 2021
90b41d6
Remove unused code and logs
jakubkoci Nov 8, 2021
c4ca249
Rename oob tests wallets
jakubkoci Nov 8, 2021
5388c81
Add small changes based on review
jakubkoci Nov 9, 2021
07cf37c
Extract getting supported handshake protocols into discover service
jakubkoci Nov 9, 2021
8e2129e
Pass all oob message props via constructor
jakubkoci Nov 10, 2021
f108330
Unify create and receive oob message methods
jakubkoci Nov 10, 2021
114e45b
Create OOB message with both handshake and requests
jakubkoci Nov 12, 2021
7f637a2
Accept OOB message with both handshake and requests
jakubkoci Nov 12, 2021
ee7ea3a
Check if handshake protocols are supported
jakubkoci Nov 17, 2021
eeb0b3d
Wait until the connection is made before processing requests
jakubkoci Nov 17, 2021
d7edbf0
Reuse connection when it exists
jakubkoci Nov 18, 2021
b7acb63
Refactor logic when connection already exists
jakubkoci Nov 18, 2021
ade0982
Refactor finding of existing connection
jakubkoci Nov 19, 2021
5c9b2a4
Omit version from handshake protocol list
jakubkoci Nov 19, 2021
dcf5668
Update public API and reorganize folder structure
jakubkoci Nov 19, 2021
3a7c38f
Add oob invitation encoding and decoding
jakubkoci Nov 22, 2021
d7be64e
Use filter method for handshake protocols from dispatcher
jakubkoci Nov 24, 2021
dc6d85c
Create a new connection instead of reusing an existing one
jakubkoci Nov 26, 2021
01fd06b
Update according to main branch API changes
jakubkoci Dec 16, 2021
a12a0e8
Use connections module instead of service
jakubkoci Dec 17, 2021
7ec4938
Add support for old url encoded connection invitation
jakubkoci Dec 17, 2021
8514b8a
Iterate over all services and reciepient keys to find a connection
jakubkoci Dec 17, 2021
ab38518
Replace custom event handler with async method provided by framework
jakubkoci Dec 28, 2021
0c5e807
Update types
jakubkoci Dec 28, 2021
95af882
Pass connection label to old invitation message
jakubkoci Dec 29, 2021
e47d834
Rename unpack to plaintext
jakubkoci Dec 29, 2021
97acfcf
Add thread to handshake reuse message
jakubkoci Dec 30, 2021
654be67
Code review updates mainly about API and docs
jakubkoci Jan 8, 2022
9895bd4
Allow dids in services attribute of oob message
jakubkoci Jan 11, 2022
b8fa0c2
Process only first supported requests message
jakubkoci Jan 12, 2022
0769c48
Throw error when there are no services in connection record
jakubkoci Jan 13, 2022
13ad50d
Refactor get requests method
jakubkoci Jan 13, 2022
27578b9
Log error insted of commented code
jakubkoci Jan 13, 2022
2f11716
Update api after rebase
jakubkoci Jan 18, 2022
697b6cb
Throw error instead of resolving did from services attribute
jakubkoci Jan 18, 2022
ae94713
Update structure of oob tests
jakubkoci Jan 18, 2022
1e5cbf1
Add connection record to received message event
jakubkoci Jan 18, 2022
c939b01
Update test of oob with requests witg parsing of encoded invitation
jakubkoci Jan 19, 2022
ecc3830
Make label mandatory
jakubkoci Jan 19, 2022
af2e53f
Update receive message method signature
jakubkoci Jan 19, 2022
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
7 changes: 5 additions & 2 deletions packages/core/src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CredentialsModule } from '../modules/credentials/CredentialsModule'
import { DidsModule } from '../modules/dids/DidsModule'
import { DiscoverFeaturesModule } from '../modules/discover-features'
import { LedgerModule } from '../modules/ledger/LedgerModule'
import { OutOfBandModule } from '../modules/oob/OutOfBandModule'
import { ProofsModule } from '../modules/proofs/ProofsModule'
import { MediatorModule } from '../modules/routing/MediatorModule'
import { RecipientModule } from '../modules/routing/RecipientModule'
Expand Down Expand Up @@ -56,6 +57,7 @@ export class Agent {
public readonly discovery: DiscoverFeaturesModule
public readonly dids: DidsModule
public readonly wallet: Wallet
public readonly oob!: OutOfBandModule

public constructor(initialConfig: InitConfig, dependencies: AgentDependencies) {
// Create child container so we don't interfere with anything outside of this agent
Expand Down Expand Up @@ -105,13 +107,14 @@ export class Agent {
this.ledger = this.container.resolve(LedgerModule)
this.discovery = this.container.resolve(DiscoverFeaturesModule)
this.dids = this.container.resolve(DidsModule)
this.oob = this.container.resolve(OutOfBandModule)

// Listen for new messages (either from transports or somewhere else in the framework / extensions)
this.messageSubscription = this.eventEmitter
.observable<AgentMessageReceivedEvent>(AgentEventTypes.AgentMessageReceived)
.pipe(
takeUntil(this.agentConfig.stop$),
concatMap((e) => this.messageReceiver.receiveMessage(e.payload.message))
concatMap((e) => this.messageReceiver.receiveMessage(e.payload.message, { connection: e.payload.connection }))
)
.subscribe()
}
Expand Down Expand Up @@ -215,7 +218,7 @@ export class Agent {
}

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

public get injectionContainer() {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/agent/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AgentMessageReceivedEvent extends BaseEvent {
type: typeof AgentEventTypes.AgentMessageReceived
payload: {
message: unknown
connection?: ConnectionRecord
}
}

Expand Down
26 changes: 16 additions & 10 deletions packages/core/src/agent/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,42 @@ export class MessageReceiver {
*
* @param inboundMessage the message to receive and handle
*/
public async receiveMessage(inboundMessage: unknown, session?: TransportSession) {
public async receiveMessage(
inboundMessage: unknown,
{ session, connection }: { session?: TransportSession; connection?: ConnectionRecord }
) {
this.logger.debug(`Agent ${this.config.label} received message`)

if (this.isPlaintextMessage(inboundMessage)) {
await this.receivePlaintextMessage(inboundMessage)
await this.receivePlaintextMessage(inboundMessage, connection)
} else {
await this.receiveEncryptedMessage(inboundMessage as EncryptedMessage, session)
}
}

private async receivePlaintextMessage(plaintextMessage: PlaintextMessage) {
private async receivePlaintextMessage(plaintextMessage: PlaintextMessage, connection?: ConnectionRecord) {
const message = await this.transformAndValidate(plaintextMessage)
const messageContext = new InboundMessageContext(message, {})
const messageContext = new InboundMessageContext(message, { connection })
await this.dispatcher.dispatch(messageContext)
}

private async receiveEncryptedMessage(encryptedMessage: EncryptedMessage, session?: TransportSession) {
const { plaintextMessage, senderKey, recipientKey } = await this.decryptMessage(encryptedMessage)

let connection: ConnectionRecord | null = null
let unverifiedConnection: ConnectionRecord | null = null

// Only fetch connection if recipientKey and senderKey are present (AuthCrypt)
if (senderKey && recipientKey) {
connection = await this.connectionService.findByVerkey(recipientKey)
unverifiedConnection = await this.connectionService.findByVerkey(recipientKey)

// Throw error if the recipient key (ourKey) does not match the key of the connection record
if (connection && connection.theirKey !== null && connection.theirKey !== senderKey) {
throw new AriesFrameworkError(
`Inbound message senderKey '${senderKey}' is different from connection.theirKey '${connection.theirKey}'`
)
if (
unverifiedConnection &&
unverifiedConnection.theirKey !== null &&
unverifiedConnection.theirKey === senderKey
) {
connection = unverifiedConnection
}
}

Expand All @@ -115,7 +121,7 @@ export class MessageReceiver {
// We allow unready connections to be attached to the session as we want to be able to
// use return routing to make connections. This is especially useful for creating connections
// with mediators when you don't have a public endpoint yet.
session.connection = connection ?? undefined
session.connection = connection ?? unverifiedConnection ?? undefined
this.transportService.saveSession(session)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export * from './logger'
export * from './error'
export * from './wallet/error'

export * from './agent/Events'

const utils = {
uuid,
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/connections/ConnectionsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ export class ConnectionsModule {
alias: config?.alias,
routing,
})
// if auto accept is enabled (either on the record or the global agent config)
// we directly send a connection request

if (connection.autoAcceptConnection ?? this.agentConfig.autoAcceptConnections) {
connection = await this.acceptInvitation(connection.id)
}

return connection
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export class ConnectionService {
connectionRecord.autoAcceptConnection = config?.autoAcceptConnection
}

connectionRecord.autoAcceptConnection = config?.autoAcceptConnection
await this.updateState(connectionRecord, ConnectionState.Requested)

return {
Expand Down
Loading