Skip to content

Commit

Permalink
Updates after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Koci <[email protected]>
  • Loading branch information
jakubkoci committed May 12, 2022
1 parent 9882a0b commit 8c438aa
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 70 deletions.
10 changes: 0 additions & 10 deletions packages/core/src/agent/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import type { Key } from '../modules/dids/domain/Key'
import type { OutOfBandRecord } from '../modules/oob/repository'
import type { OutboundMessage, OutboundServiceMessage } from '../types'
import type { AgentMessage } from './AgentMessage'
<<<<<<< HEAD

import { IndyAgentService } from '../modules/dids'
import { DidCommService } from '../modules/dids/domain/service/DidCommService'
=======
import type { ResolvedDidCommService } from './MessageSender'
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))

export function createOutboundMessage<T extends AgentMessage = AgentMessage>(
connection: ConnectionRecord,
Expand All @@ -35,10 +29,6 @@ export function isOutboundServiceMessage(
message: OutboundMessage | OutboundServiceMessage
): message is OutboundServiceMessage {
const service = (message as OutboundServiceMessage).service
<<<<<<< HEAD
return service instanceof IndyAgentService || service instanceof DidCommService
=======

return service !== undefined
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export class V1IssueCredentialHandler implements Handler {

return createOutboundServiceMessage({
payload: message,
service: recipientService.toDidCommService(),
senderKey: ourService.recipientKeys[0],
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export class V1OfferCredentialHandler implements Handler {
})
return createOutboundServiceMessage({
payload: message,
service: recipientService.toDidCommService(),
senderKey: ourService.recipientKeys[0],
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export class V1RequestCredentialHandler implements Handler {
})
return createOutboundServiceMessage({
payload: message,
service: recipientService.toDidCommService(),
senderKey: ourService.recipientKeys[0],
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
})
}
this.agentConfig.logger.error(`Could not automatically create credential request`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class V2IssueCredentialHandler implements Handler {

return createOutboundServiceMessage({
payload: message,
service: recipientService.toDidCommService(),
senderKey: ourService.recipientKeys[0],
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export class V2OfferCredentialHandler implements Handler {
})
return createOutboundServiceMessage({
payload: message,
service: recipientService.toDidCommService(),
senderKey: ourService.recipientKeys[0],
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export class V2RequestCredentialHandler implements Handler {

return createOutboundServiceMessage({
payload: message,
service: recipientService.toDidCommService(),
senderKey: ourService.recipientKeys[0],
service: recipientService.resolvedDidCommService,
senderKey: ourService.resolvedDidCommService.recipientKeys[0],
})
}
this.agentConfig.logger.error(`Could not automatically create credential request`)
Expand Down
12 changes: 2 additions & 10 deletions packages/core/src/modules/dids/__tests__/peer-did.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ describe('peer dids', () => {
tags: {
// We need to save the recipientKeys, so we can find the associated did
// of a key when we receive a message from another connection.
<<<<<<< HEAD
recipientKeys: didDocument.recipientKeys,
=======
recipientKeyFingerprints: peerDid.didDocument.recipientKeys.map((key) => key.fingerprint),
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
},
})

Expand Down Expand Up @@ -158,11 +154,7 @@ describe('peer dids', () => {
tags: {
// We need to save the recipientKeys, so we can find the associated did
// of a key when we receive a message from another connection.
<<<<<<< HEAD
recipientKeys: didDocument.recipientKeys,
=======
recipientKeyFingerprints: didPeer.didDocument.recipientKeys.map((key) => key.fingerprint),
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
},
})

Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/modules/dids/domain/DidDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,10 @@ export class DidDocument {
* Get all DIDComm services ordered by priority descending. This means the highest
* priority will be the first entry.
*/
<<<<<<< HEAD
public get didCommServices(): Array<IndyAgentService | DidCommService> {
const didCommServiceTypes = [IndyAgentService.type, DidCommService.type]
const services = (this.service?.filter((service) => didCommServiceTypes.includes(service.type)) ?? []) as Array<
IndyAgentService | DidCommService
=======
public get didCommServices(): Array<IndyAgentService | DidCommV1Service> {
const didCommServiceTypes = [IndyAgentService.type, DidCommV1Service.type]
const services = this.service.filter((service) => didCommServiceTypes.includes(service.type)) as Array<
const services = (this.service?.filter((service) => didCommServiceTypes.includes(service.type)) ?? []) as Array<
IndyAgentService | DidCommV1Service
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))
>

// Sort services based on indicated priority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,10 @@ describe('Did | DidDocument', () => {
expect(verificationMethods[2]).toBeInstanceOf(VerificationMethod)

// Check Service
<<<<<<< HEAD
const services = didDocument.service ?? []
expect(services[0]).toBeInstanceOf(DidDocumentService)
expect(services[1]).toBeInstanceOf(IndyAgentService)
expect(services[2]).toBeInstanceOf(DidCommService)
=======
expect(didDocument.service[0]).toBeInstanceOf(DidDocumentService)
expect(didDocument.service[1]).toBeInstanceOf(IndyAgentService)
expect(didDocument.service[2]).toBeInstanceOf(DidCommV1Service)
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))
expect(services[2]).toBeInstanceOf(DidCommV1Service)

// Check Authentication
const authentication = didDocument.authentication ?? []
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/modules/dids/methods/peer/peerDidNumAlgo0.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Key } from '../../domain/Key'
import { getKeyDidMappingByKeyType } from '../../domain/key-type'
import { getDidDocumentForKey } from '../../domain/keyDidDocument'
import { parseDid } from '../../domain/parse'

import { getNumAlgoFromPeerDid, isValidPeerDid, PeerDidNumAlgo } from './didPeer'

export function keyToNumAlgo0DidDocument(key: Key) {
const { getDidDocument } = getKeyDidMappingByKeyType(key.keyType)

const did = `did:peer:0${key.fingerprint}`

return getDidDocument(did, key)
return getDidDocumentForKey(did, key)
}

export function didToNumAlgo0DidDocument(did: string) {
Expand All @@ -26,7 +24,5 @@ export function didToNumAlgo0DidDocument(did: string) {

const key = Key.fromFingerprint(parsed.id.substring(1))

const { getDidDocument } = getKeyDidMappingByKeyType(key.keyType)

return getDidDocument(did, key)
return getDidDocumentForKey(did, key)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { InboundMessageContext } from '../../../agent/models/InboundMessageConte
import { Attachment } from '../../../decorators/attachment/Attachment'
import { AriesFrameworkError } from '../../../error'
import { IndyWallet } from '../../../wallet/IndyWallet'
import { ConnectionRepository, ConnectionState } from '../../connections'
import { ConnectionRepository, DidExchangeState } from '../../connections'
import { ConnectionService } from '../../connections/services/ConnectionService'
import { DidRepository } from '../../dids/repository'
import { DeliveryRequestMessage, MessageDeliveryMessage, MessagesReceivedMessage, StatusMessage } from '../messages'
import { MediationRole, MediationState } from '../models'
import { MediationRecord, MediationRepository } from '../repository'
import { MediationRecipientService } from '../services'
import { DidRepository } from '../../dids/repository'

jest.mock('../repository/MediationRepository')
const MediationRepositoryMock = MediationRepository as jest.Mock<MediationRepository>
Expand All @@ -34,7 +34,7 @@ const MessageSenderMock = MessageSender as jest.Mock<MessageSender>
const connectionImageUrl = 'https://example.com/image.png'

const mockConnection = getMockConnection({
state: ConnectionState.Complete,
state: DidExchangeState.Completed,
})

describe('MediationRecipientService', () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/core/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ import {
import { KeyType } from '../src/crypto'
import { Attachment, AttachmentData } from '../src/decorators/attachment/Attachment'
import { AutoAcceptCredential } from '../src/modules/credentials/CredentialAutoAcceptType'
<<<<<<< HEAD
import { CredentialProtocolVersion } from '../src/modules/credentials/CredentialProtocolVersion'
import { V1CredentialPreview } from '../src/modules/credentials/protocol/v1/V1CredentialPreview'
import { DidCommService } from '../src/modules/dids'
=======
import { DidCommV1Service, DidKey, Key } from '../src/modules/dids'
>>>>>>> 73d296f6 (fix: always encode keys according to RFCs (#733))
import { OutOfBandRole } from '../src/modules/oob/domain/OutOfBandRole'
import { OutOfBandState } from '../src/modules/oob/domain/OutOfBandState'
import { OutOfBandInvitation } from '../src/modules/oob/messages'
Expand Down
31 changes: 22 additions & 9 deletions packages/core/tests/postgres.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { SubjectMessage } from '../../../tests/transport/SubjectInboundTransport'
import type { IndyPostgresStorageConfig } from '../../node/src'
import type { ConnectionRecord } from '../src/modules/connections'
Expand All @@ -21,8 +22,7 @@ const bobPostgresConfig = getBasePostgresConfig('AgentsBob', {
describe('postgres agents', () => {
let aliceAgent: Agent
let bobAgent: Agent
let aliceConnection: ConnectionRecord
let bobConnection: ConnectionRecord
let aliceConnectionAtAliceBob: ConnectionRecord

afterAll(async () => {
await bobAgent.shutdown()
Expand Down Expand Up @@ -67,19 +67,32 @@ describe('postgres agents', () => {
bobAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap))
await bobAgent.initialize()

const aliceConnectionAtAliceBob = await aliceAgent.connections.createConnection()
const bobConnectionAtBobAlice = await bobAgent.connections.receiveInvitation(aliceConnectionAtAliceBob.invitation)
const aliceOutOfBandRecord = await aliceAgent.oob.createInvitation()

aliceConnection = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.connectionRecord.id)
bobConnection = await bobAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice.id)
const invitation = aliceOutOfBandRecord.outOfBandInvitation
const invitationUrl = invitation.toUrl({ domain: 'https://example.com' })

expect(aliceConnection).toBeConnectedWith(bobConnection)
expect(bobConnection).toBeConnectedWith(aliceConnection)
// Receive invitation first time with alice agent
let { connectionRecord: bobConnectionAtBobAlice } = await bobAgent.oob.receiveInvitationFromUrl(invitationUrl)
bobConnectionAtBobAlice = await aliceAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice!.id)

let aliceConnectionAtAliceBob = await aliceAgent.connections.getByThreadId(bobConnectionAtBobAlice.threadId!)
aliceConnectionAtAliceBob = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.id)
// ===========================================================================

// const aliceConnectionAtAliceBob = await aliceAgent.connections.createConnection()
// const bobConnectionAtBobAlice = await bobAgent.connections.receiveInvitation(aliceConnectionAtAliceBob.invitation)

// aliceConnection = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.connectionRecord.id)
// bobConnection = await bobAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice.id)

expect(aliceConnectionAtAliceBob).toBeConnectedWith(bobConnectionAtBobAlice)
expect(bobConnectionAtBobAlice).toBeConnectedWith(aliceConnectionAtAliceBob)
})

test('send a message to connection', async () => {
const message = 'hello, world'
await aliceAgent.basicMessages.sendMessage(aliceConnection.id, message)
await aliceAgent.basicMessages.sendMessage(aliceConnectionAtAliceBob.id, message)

const basicMessage = await waitForBasicMessage(bobAgent, {
content: message,
Expand Down

0 comments on commit 8c438aa

Please sign in to comment.