openwallet-foundation / credo-ts

Typescript framework for building decentralized identity and verifiable credential solutions
https://credo.js.org
Apache License 2.0
273 stars 200 forks source link

Connection Reuse in edge wallets #2010

Open sairanjit opened 3 months ago

sairanjit commented 3 months ago

The scenario is User 1 and User 2 connection with reuse works fine with passing invitationDid. But it fails if I create invitation from User 1 using invitationDid and try to accept it with User 3 . The error I am getting is

ERROR: Error handling message with type https://didcomm.org/didexchange/1.1/request

{
    "message": {
        "@type": "https://didcomm.org/didexchange/1.1/request",
        "@id": "be1bce6d-ae00-4fa0-9c01-5addb3767c7b",
        "label": "Holder Agent 2",
        "did": "did:peer:1zQmRYToLZF56Xd5itnQ954cLLncVDsPV656mx8pWqo9dp9C",
        "~thread": {
            "pthid": "301e9db3-d422-4c4e-8c3e-8b6b8c2ec421"
        },
        "did_doc~attach": {
            "@id": "490e4548-7136-4cb5-a54a-107e1b877d67",
            "mime-type": "application/json",
            "data": {
                "base64": "eyJAY29udGV4dCI6WyJodHRwczovL3czaWQub3JnL2RpZC92MSJdLCJpZCI6ImRpZDpwZWVyOjF6UW1SWVRvTFpGNTZYZDVpdG5ROTU0Y0xMbmNWRHNQVjY1Nm14OHBXcW85ZHA5QyIsInNlcnZpY2UiOlt7ImlkIjoiI2lubGluZS0wIiwic2VydmljZUVuZHBvaW50IjoiaHR0cDovLzE5Mi4xNjguMS4yNzozMDAwIiwidHlwZSI6ImRpZC1jb21tdW5pY2F0aW9uIiwicHJpb3JpdHkiOjAsInJlY2lwaWVudEtleXMiOlsiI2tleS0xIl0sInJvdXRpbmdLZXlzIjpbImRpZDprZXk6ejZNa3VQTHB4N01Vb2tNSmZCNGhKd2E4UjVETHAxMWlTZGtRVmNMN0RhTmZ1dG5XI3o2TWt1UExweDdNVW9rTUpmQjRoSndhOFI1RExwMTFpU2RrUVZjTDdEYU5mdXRuVyJdfV0sImF1dGhlbnRpY2F0aW9uIjpbeyJpZCI6IiNrZXktMSIsInR5cGUiOiJFZDI1NTE5VmVyaWZpY2F0aW9uS2V5MjAxOCIsImNvbnRyb2xsZXIiOiIjaWQiLCJwdWJsaWNLZXlCYXNlNTgiOiI1N1cxSGR4cmExclJxMUI5cVJLNE1lRTY5dlFzRjJNblJnTDU0VmszZVJZSyJ9XSwia2V5QWdyZWVtZW50IjpbeyJpZCI6IiNrZXktMiIsInR5cGUiOiJYMjU1MTlLZXlBZ3JlZW1lbnRLZXkyMDE5IiwiY29udHJvbGxlciI6IiNpZCIsInB1YmxpY0tleUJhc2U1OCI6Ijk4ZE55eDJocm1SNUpuanNZajRqeUtEdkRTNFQ3YlN5akJhNFJLdTZpNldQIn1dfQ==",
                "jws": {
                    "protected": "eyJhbGciOiJFZERTQSIsImp3ayI6eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6IlBSa0hUM3FqVzJLVGNYR1E1bmJCZXNJUDdjRzRNSHFHYVpvWWp2eEowc0EifX0",
                    "signature": "EB0sccSGFsYsaXEKtOVSJ1SydsugAdE-SYq47xzl_0DSYm7id7YSe5QTgpEsgiu97wzBuF0L_yzCoDcvxBBDBg",
                    "header": {
                        "kid": "did:key:z6MkiZm3stDHuZLtwW1rWzGuCjn5yVgieuc97hEztmi4ZeKh"
                    }
                }
            }
        }
    },
    "error": {
        "name": "TimeoutError",
        "message": "Timeout has occurred",
        "info": {
            "meta": "MediationRecipientService.keylistUpdateAndAwait",
            "lastValue": null,
            "seen": 0
        }
    },
    "senderKey": "z6MkiZm3stDHuZLtwW1rWzGuCjn5yVgieuc97hEztmi4ZeKh",
    "recipientKey": "z6MkohvcgmP4JTtAoeYMogsBRtSVc5p63CLPAYg4qakRL2jV"
}

I have created a repro for the same here https://github.com/sairanjit/credo-askar-wallet-react-native/tree/connection-reuse

TimoGlastra commented 3 months ago

Does this also happen in Node.JS? If so, could you please provide the repro in Node? That makes it easier to test

sairanjit commented 3 months ago

Yes @TimoGlastra This is also happening in the Node.JS as well. I have created a repro for the same here https://github.com/sairanjit/credo-ts-examples/tree/connection-reuse

sairanjit commented 3 months ago

One observation is that after the timeout Error has occurred then we receive the keylist response message that it was waiting for

{
  "@type": "https://didcomm.org/coordinate-mediation/1.0/keylist-update-response",
  "@id": "311c73dd-df95-413b-9724-347f91f5e88b",
  "~thread": {
    "thid": "a8aee7d9-65e3-4049-a211-d23657cbf175"
  },
  "updated": [
    {
      "recipient_key": "FAMBvTH1PnvzaxPV42h9hXF46ruAiPdiQm8FFYMoxj4g",
      "action": "add",
      "result": "success"
    }
  ]
}
sairanjit commented 2 months ago

@TimoGlastra @genaris Changing the message receiving logic from concatMap to tap fixes this issue https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/agent/Agent.ts#L155

sairanjit commented 2 months ago

@TimoGlastra There is already a PR #1276 That addresses the required changes for this issue