diff --git a/Sources/AriesFramework/connection/ConnectionCommand.swift b/Sources/AriesFramework/connection/ConnectionCommand.swift index a9ae6f3..38537f7 100644 --- a/Sources/AriesFramework/connection/ConnectionCommand.swift +++ b/Sources/AriesFramework/connection/ConnectionCommand.swift @@ -120,28 +120,27 @@ public class ConnectionCommand { handshakeProtocol: HandshakeProtocol?, config: ReceiveOutOfBandInvitationConfig?) async throws -> ConnectionRecord { var connection = try await receiveInvitation(outOfBandInvitation: outOfBandRecord.outOfBandInvitation, - autoAcceptConnection: false, alias: config?.alias) - let message: OutboundMessage - if let handshakeProtocol = handshakeProtocol { - if handshakeProtocol == .Connections { - message = try await agent.connectionService.createRequest(connectionId: connection.id, - label: config?.label, - imageUrl: config?.imageUrl, - autoAcceptConnection: config?.autoAcceptConnection) - } else { - message = try await agent.didExchangeService.createRequest(connectionId: connection.id, - label: config?.label, - autoAcceptConnection: config?.autoAcceptConnection) - } - try await agent.messageSender.send(message: message) - return message.connection - } else { + autoAcceptConnection: false, alias: config?.alias) + guard let handshakeProtocol = handshakeProtocol else { let didDocServices = try outOfBandRecord.outOfBandInvitation.services.compactMap { try $0.asDidDocService() } - let theirDidDoc = try connection.theirDidDoc ?? DidDoc(from: didDocServices) - connection.theirDidDoc = theirDidDoc + connection.theirDidDoc = try connection.theirDidDoc ?? DidDoc(from: didDocServices) try await agent.connectionService.updateState(connectionRecord: &connection, newState: .Complete) return connection + } + let message: OutboundMessage + switch handshakeProtocol { + case .Connections: + message = try await agent.connectionService.createRequest(connectionId: connection.id, + label: config?.label, + imageUrl: config?.imageUrl, + autoAcceptConnection: config?.autoAcceptConnection) + case .DidExchange10, .DidExchange11: + message = try await agent.didExchangeService.createRequest(connectionId: connection.id, + label: config?.label, + autoAcceptConnection: config?.autoAcceptConnection) } + try await agent.messageSender.send(message: message) + return message.connection } } diff --git a/Tests/AriesFrameworkTests/connection-less/ConnectionlessExchangeTest.swift b/Tests/AriesFrameworkTests/connection-less/ConnectionlessExchangeTest.swift index a984f8f..134320d 100644 --- a/Tests/AriesFrameworkTests/connection-less/ConnectionlessExchangeTest.swift +++ b/Tests/AriesFrameworkTests/connection-less/ConnectionlessExchangeTest.swift @@ -13,7 +13,6 @@ class ConnectionlessExchangeTest: XCTestCase { "name": "John", "age": "99" ]) - let receiveInvitationConfig = ReceiveOutOfBandInvitationConfig(autoAcceptConnection: true) override func setUp() async throws { try await super.setUp() @@ -50,7 +49,6 @@ class ConnectionlessExchangeTest: XCTestCase { self.holderAgent.setOutboundTransport(SubjectOutboundTransport(subject: issuerAgent)) let offerOptions = CreateOfferOptions( - connection: nil, credentialDefinitionId: credDefId, attributes: credentialPreview.attributes, comment: "this is credential-offer for you") @@ -60,19 +58,15 @@ class ConnectionlessExchangeTest: XCTestCase { let oobConfig = CreateOutOfBandInvitationConfig( label: "issuer-to-holder-invitation", alias: "issuer-to-holder-invitation", - imageUrl: nil, - goalCode: nil, - goal: nil, handshake: false, messages: [message], multiUseInvitation: false, - autoAcceptConnection: true, - routing: nil) + autoAcceptConnection: true) let oobInvitation = try await issuerAgent.oob.createInvitation(config: oobConfig) let (oob, connection) = try await holderAgent.oob.receiveInvitation(oobInvitation.outOfBandInvitation) XCTAssertNotNil(connection) - XCTAssertEqual(connection?.state, .Complete) // this is a fake connection. + XCTAssertEqual(connection?.state, .Complete) XCTAssertNotNil(oob) try await Task.sleep(nanoseconds: UInt64(5 * SECOND)) @@ -91,19 +85,15 @@ class ConnectionlessExchangeTest: XCTestCase { let oobConfigForProofExchange = CreateOutOfBandInvitationConfig( label: "verifier-to-holder-invitation", alias: "verifier-to-holder-invitation", - imageUrl: nil, - goalCode: nil, - goal: nil, handshake: false, messages: [proofRequestMessage], multiUseInvitation: false, - autoAcceptConnection: true, - routing: nil) + autoAcceptConnection: true) let oobInvitationForProofExchange = try await verifierAgent.oob.createInvitation(config: oobConfigForProofExchange) let (oobForProofExchange, connectionForProofExchange) = try await holderAgent.oob.receiveInvitation(oobInvitationForProofExchange.outOfBandInvitation) XCTAssertNotNil(connectionForProofExchange) - XCTAssertEqual(connectionForProofExchange?.state, .Complete) // this is a fake connection. + XCTAssertEqual(connectionForProofExchange?.state, .Complete) XCTAssertNotNil(oobForProofExchange) try await Task.sleep(nanoseconds: UInt64(5 * SECOND))