openwallet-foundation/credo-ts

Connections created via oob - unable to send credentials using ConnectionId

Closed this issue · 3 comments

sudddy commented

Hello,

When I receive an invitation from the issuer, connection is established. Here,

  • The holder can send messages to the issuer through the connectionId created through invitation.

But, in the issuer server, the connectionId is nowhere to be found. I can't send back messages from issuer to holder. The conenctionId is different.

One more thing to be noted:

When i receive an invitation from URL using agent.oob.receiveInvitationFromUrl(invitationUrl) the connection received in the backend doesn't have invitationDID.

Again, this goes back the first issue, connections in issuer server is different and holder server is different.

Holder Connection Record

{
   "_tags":{
      "did":"did:peer:1zQmSHPcFfc1iRCRcW5oy9KhyccySDzdZ13J4VMJnXpZpQe1",
      "invitationDid":"did:peer:2.SeyJzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgyIiwidCI6ImRpZC1jb21tdW5pY2F0aW9uIiwicHJpb3JpdHkiOjAsInJlY2lwaWVudEtleXMiOlsiZGlkOmtleTp6Nk1rbmNmV1BUb0ZRS3M5d2hKTGZOSEpaRHVKWU42RWtFY2I1R3NwWGtXV2tvTGsjejZNa25jZldQVG9GUUtzOXdoSkxmTkhKWkR1SllONkVrRWNiNUdzcFhrV1drb0xrIl0sInIiOltdfQ",
      "outOfBandId":"b8b1e8e9-27e6-4d69-a7f8-d9bc29f91b20",
      "role":"requester",
      "state":"request-sent",
      "threadId":"1e90f23e-fad4-46fa-b5ea-0d3f3b858f57"
   },
   "autoAcceptConnection":true,
   "connectionTypes":[
      
   ],
   "createdAt":"2023-08-31T22:23:40.471Z",
   "did":"did:peer:1zQmSHPcFfc1iRCRcW5oy9KhyccySDzdZ13J4VMJnXpZpQe1",
   "id":"53e8aafb-e97a-40d4-be28-1a73f5ea39b0",
   "invitationDid":"did:peer:2.SeyJzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgyIiwidCI6ImRpZC1jb21tdW5pY2F0aW9uIiwicHJpb3JpdHkiOjAsInJlY2lwaWVudEtleXMiOlsiZGlkOmtleTp6Nk1rbmNmV1BUb0ZRS3M5d2hKTGZOSEpaRHVKWU42RWtFY2I1R3NwWGtXV2tvTGsjejZNa25jZldQVG9GUUtzOXdoSkxmTkhKWkR1SllONkVrRWNiNUdzcFhrV1drb0xrIl0sInIiOltdfQ",
   "metadata":{
      
   },
   "outOfBandId":"b8b1e8e9-27e6-4d69-a7f8-d9bc29f91b20",
   "protocol":"https://didcomm.org/connections/1.0",
   "role":"requester",
   "state":"completed",
   "theirDid":"did:peer:1zQmeb9PKfCEwfXZ7YgaYzb6nYpowJJt8vUARsJyo1oa2CHW",
   "theirLabel":"demo-agent-eight-one",
   "threadId":"1e90f23e-fad4-46fa-b5ea-0d3f3b858f57",
   "updatedAt":"2023-08-31T22:23:52.505Z"
}

Received Connection request (Issuer)

{
  connectionRecord: ConnectionRecord {
    _tags: {},
    type: 'ConnectionRecord',
    metadata: Metadata { data: {} },
    connectionTypes: [],
    id: '103c2dd8-eafb-451a-9e11-96b4f8b2e06f',
    createdAt: 2023-08-31T22:46:41.168Z,
    did: undefined,
    invitationDid: undefined,
    theirDid: 'did:peer:1zQmSBhKcpbivn9atz9PSJRFadEFWCBa8ybs1r1CWnrEiRYd',
    theirLabel: 'demo-agent-sudharsan-test',
    state: 'request-received',
    role: 'responder',
    alias: undefined,
    autoAcceptConnection: true,
    threadId: '983f0c15-236a-444d-93fa-f4672c5f615b',
    imageUrl: undefined,
    mediatorId: undefined,
    errorMessage: undefined,
    protocol: 'https://didcomm.org/connections/1.0',
    outOfBandId: '58454009-78de-4245-963c-2137e17b8d65',
    updatedAt: 2023-08-31T22:46:41.549Z
  },
  previousState: null
}

Why is the invitatinDID is undefined? Quite confusing.

Can someone please guide me on this? Thanks.

Note that connectionId value is unique for each agent, so the way to bind two ConnectionRecords from different agents would be their threadId. In the examples you gave, it seems they are not from the same relationship (look at the creation dates: one is 2023-08-31T22:46:41.168Z while the other one is 2023-08-31T22:23:40.471Z, 23 minutes before).

If your holder is able to send messages to the issuer, it means that from its side the connection is completed (so it does not seem to correspond to the one in the example, whose state is 'request-sent'). At issuer side, you can subscribe to BasicMessageStateChanged event, so you can see the received messages and check their connectionId.

But actually it will be more interesting to subscribe to ConnectionStateChanged event if you want to know exactly when the connection with the holder has been established. This binding can be done by checking that a connection corresponds to a given out of band invitation you've created. In AFJ docs you can see a full code example of setting up an event listener for a particular invitation: https://aries.js.org/guides/0.4/tutorials/create-a-connection .

sudddy commented

@genaris Thanks for your elaborate reply.

It seems like the issue was happening related to dids of routing keys.

I'm running MobileAgent(holder) - Mediator - Nodejs(Issuer). When the connection is established via a mediator, this happens.

DEBUG: Resolving services for connection theirDid did:peer:1zQmPqicAm8WovPvWNJ2ExvhmvbswucySDGpq2YgZHBazjJS.
DEBUG: resolving didUrl did:peer:1zQmPqicAm8WovPvWNJ2ExvhmvbswucySDGpq2YgZHBazjJS
DEBUG: resolving didUrl did:key:z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR#z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR
ERROR: Unable to retrieve services for connection 'dbf5c88e-524b-4fd5-b158-a704d8d6df04. Unable to resolve did document for did 'did:key:z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR#z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR': unsupportedDidMethod No did resolver registered for did method key
ERROR: Failed to process message {
  "error": {
    "name": "MessageSendingError",
    "message": "Unable to retrieve services for connection 'dbf5c88e-524b-4fd5-b158-a704d8d6df04",
    "stack": "MessageSendingError: Unable to retrieve services for connection 'dbf5c88e-524b-4fd5-b158-a704d8d6df04\n    at MessageSender.sendMessage (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageSender.ts:241:13)\n    at async Dispatcher.dispatch (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/Dispatcher.ts:95:9)\n    at async MessageReceiver.receiveEncryptedMessage (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageReceiver.ts:168:5)\n    at async MessageReceiver.receiveMessage (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageReceiver.ts:96:9)",
    "cause": {
      "name": "AriesFrameworkError",
      "message": "Unable to resolve did document for did 'did:key:z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR#z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR': unsupportedDidMethod No did resolver registered for did method key",
      "stack": "AriesFrameworkError: Unable to resolve did document for did 'did:key:z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR#z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR': unsupportedDidMethod No did resolver registered for did method key\n    at DidResolverService.resolveDidDocument (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/modules/dids/services/DidResolverService.ts:66:13)\n    at async DidCommDocumentService.resolveServicesFromDid (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/modules/didcomm/services/DidCommDocumentService.ts:43:38)\n    at async MessageSender.retrieveServicesByConnection (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageSender.ts:474:25)\n    at async MessageSender.sendMessage (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageSender.ts:232:38)\n    at async Dispatcher.dispatch (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/Dispatcher.ts:95:9)\n    at async MessageReceiver.receiveEncryptedMessage (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageReceiver.ts:168:5)\n    at async MessageReceiver.receiveMessage (/Users/sudharsansrinivasan/Desktop/interview-prep/test-backend/node_modules/@aries-framework/core/src/agent/MessageReceiver.ts:96:9)"
    },
    "outboundMessageContext": {
      "message": {
        "@type": "https://didcomm.org/didexchange/1.0/response",
        "@id": "1e0f8dbc-cef3-4a3a-b9b5-1c8d3539461a",
        "did": "did:peer:1zQmTHAtKpSUEyECMS9N2wutrWoW22kGPaYvigcHuism9V23",
        "~thread": {
          "thid": "e1cc22c8-d03a-4cb9-8875-3f9496f53a14"
        },
        "did_doc~attach": {
          "@id": "d1122d19-1413-4da7-9567-19ffa73aba5f",
          "mime-type": "application/json",
          "data": {
            "base64": "eyJAY29udGV4dCI6WyJodHRwczovL3czaWQub3JnL2RpZC92MSJdLCJpZCI6ImRpZDpwZWVyOjF6UW1USEF0S3BTVUV5RUNNUzlOMnd1dHJXb1cyMmtHUGFZdmlnY0h1aXNtOVYyMyIsInNlcnZpY2UiOlt7ImlkIjoiI2lubGluZS0wIiwic2VydmljZUVuZHBvaW50IjoiaHR0cDovL2xvY2FsaG9zdDo1MDAxIiwidHlwZSI6ImRpZC1jb21tdW5pY2F0aW9uIiwicHJpb3JpdHkiOjAsInJlY2lwaWVudEtleXMiOlsiIzkwNWViZThjLTRkYTItNDBiZi1iOTBiLTZiMmE4NjBiMzI3MyJdLCJyb3V0aW5nS2V5cyI6WyJkaWQ6a2V5Ono2TWtybUpiUnZ3cHJpOGlMZlEyMUpCMXM1enVYRUE2cXR6UVBUSHlSRXpON0twUiN6Nk1rcm1KYlJ2d3ByaThpTGZRMjFKQjFzNXp1WEVBNnF0elFQVEh5UkV6TjdLcFIiXX1dLCJhdXRoZW50aWNhdGlvbiI6W3siaWQiOiIjOTA1ZWJlOGMtNGRhMi00MGJmLWI5MGItNmIyYTg2MGIzMjczIiwidHlwZSI6IkVkMjU1MTlWZXJpZmljYXRpb25LZXkyMDE4IiwiY29udHJvbGxlciI6IiNpZCIsInB1YmxpY0tleUJhc2U1OCI6IjZWRjVON3lyanVYbWNlR1B3WVIxNUxlU0c4bTVxTlNKZUNWVmtmQWZCa1h4In1dLCJrZXlBZ3JlZW1lbnQiOlt7ImlkIjoiI2YzMzUyYmY5LWU0NzUtNDM4MC05YTJhLWYzYWNlZGNkNDgzMCIsInR5cGUiOiJYMjU1MTlLZXlBZ3JlZW1lbnRLZXkyMDE5IiwiY29udHJvbGxlciI6IiNpZCIsInB1YmxpY0tleUJhc2U1OCI6IkMza01vVjVQTFhSNVFEUmJpcU10Q0poZFEycUF1VmE1bmV0WGNONzFmUGpHIn1dfQ==",
            "jws": {
              "protected": "eyJhbGciOiJFZERTQSIsImp3ayI6eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6IlVZYWN1aHlGd1VJeF96eWE2cWlEQnVKTEpLYWxYenp6c0hmbTc5STBuWjgifX0",
              "signature": "gibA0nuWOA5D3w0DgpRwBlDtZBWQK4DW0_7evyvIR5LbM2qhBf5mzSlvsST7qBx5GWGUCStfrOA9n6xd6HvZAg",
              "header": {
                "kid": "did:key:z6MkjwW7xNEJ5T2Ej976d7NqvSCS5i2wFFgfLDQRaw8g6yKL"
              }
            }
          }
        }
      },
      "outOfBand": {
        "_tags": {
          "invitationId": "18e3aff0-b9fa-46c2-8c53-54a5e4cfab2c",
          "recipientKeyFingerprints": [
            "z6MkjwW7xNEJ5T2Ej976d7NqvSCS5i2wFFgfLDQRaw8g6yKL"
          ],
          "role": "sender",
          "state": "await-response",
          "threadId": "18e3aff0-b9fa-46c2-8c53-54a5e4cfab2c"
        },
        "metadata": {},
        "id": "5c0e0297-b504-425f-a693-9b2870f1b73f",
        "createdAt": "2023-09-05T03:47:08.319Z",
        "outOfBandInvitation": {
          "@type": "https://didcomm.org/out-of-band/1.1/invitation",
          "@id": "18e3aff0-b9fa-46c2-8c53-54a5e4cfab2c",
          "label": "agent-new-test",
          "accept": [
            "didcomm/aip1",
            "didcomm/aip2;env=rfc19"
          ],
          "handshake_protocols": [
            "https://didcomm.org/didexchange/1.0",
            "https://didcomm.org/connections/1.0"
          ],
          "services": [
            {
              "id": "#inline-0",
              "serviceEndpoint": "http://localhost:5001",
              "type": "did-communication",
              "recipientKeys": [
                "did:key:z6MkjwW7xNEJ5T2Ej976d7NqvSCS5i2wFFgfLDQRaw8g6yKL"
              ],
              "routingKeys": [
                "did:key:z6MkrmJbRvwpri8iLfQ21JB1s5zuXEA6qtzQPTHyREzN7KpR"
              ]
            }
          ]
        },
        "role": "sender",
        "state": "await-response",
        "autoAcceptConnection": true,
        "reusable": false,
        "mediatorId": "2f06e2ec-21bc-45d6-846c-e38e4399cbb1",
        "updatedAt": "2023-09-05T03:47:08.319Z"
      },
      "agentContext": {
        "contextCorrelationId": "default"
      },
      "connection": {
        "_tags": {},
        "metadata": {},
        "connectionTypes": [],
        "id": "dbf5c88e-524b-4fd5-b158-a704d8d6df04",
        "createdAt": "2023-09-05T03:47:14.604Z",
        "did": "did:peer:1zQmTHAtKpSUEyECMS9N2wutrWoW22kGPaYvigcHuism9V23",
        "theirDid": "did:peer:1zQmPqicAm8WovPvWNJ2ExvhmvbswucySDGpq2YgZHBazjJS",
        "theirLabel": "agent-new-start-holder-one",
        "state": "response-sent",
        "role": "responder",
        "autoAcceptConnection": true,
        "threadId": "e1cc22c8-d03a-4cb9-8875-3f9496f53a14",
        "mediatorId": "2f06e2ec-21bc-45d6-846c-e38e4399cbb1",
        "protocol": "https://didcomm.org/didexchange/1.0",
        "outOfBandId": "5c0e0297-b504-425f-a693-9b2870f1b73f",
        "updatedAt": "2023-09-05T03:47:16.774Z"
      }
    }
  }
}

sudddy commented

Fixed the issue :

Added did resolver to the agent configuration:

 resolvers: [
          new IndyVdrIndyDidResolver(),
          new PeerDidResolver(),
          new KeyDidResolver(),
        ],
      })