diff --git a/packages/agent-explore/src/context/web3/saveMessageHandler.ts b/packages/agent-explore/src/context/web3/saveMessageHandler.ts index d773021..eb98a12 100644 --- a/packages/agent-explore/src/context/web3/saveMessageHandler.ts +++ b/packages/agent-explore/src/context/web3/saveMessageHandler.ts @@ -20,6 +20,8 @@ export class SaveMessageHandler extends AbstractMessageHandler { // console.log('message received: ', message) if (message.type === 'veramo.io-chat-v1') { await context.agent.dataStoreSaveMessage({ message }) + } else if (message.type === 'https://veramo.io/didcomm/brainshare/1.0/return-index' || message.type === 'https://veramo.io/didcomm/brainshare/1.0/return-credential') { + await context.agent.dataStoreSaveVerifiableCredential({ verifiableCredential: message.data.credential }) } return super.handle(message, context) } diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 84a0881..eae39d5 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -46,11 +46,13 @@ "react-query": "^3.39.3", "react-router-dom": "^6.11.2", "typescript": "4.9.5", - "url-parse": "^1.5.10" + "url-parse": "^1.5.10", + "uuid": "^9.0.1" }, "devDependencies": { "@types/markdown-it": "^13.0.2", "@types/react": "^18.2.23", - "@types/react-dom": "^18.2.8" + "@types/react-dom": "^18.2.8", + "@types/uuid": "^9.0.4" } } diff --git a/packages/plugin/src/components/MarkDown.tsx b/packages/plugin/src/components/MarkDown.tsx index abacbda..7895955 100644 --- a/packages/plugin/src/components/MarkDown.tsx +++ b/packages/plugin/src/components/MarkDown.tsx @@ -7,6 +7,7 @@ import { IDataStore, UniqueVerifiableCredential } from '@veramo/core-types'; import { useVeramo } from '@veramo-community/veramo-react'; import { Spin } from 'antd'; import { usePlugins } from '../PluginProvider.js'; +import { v4 } from 'uuid' const md = new MarkdownIt({ html: true, @@ -74,14 +75,36 @@ export const CredentialLoader: React.FC<{ hash: string, did?: string}> = ({ hash useEffect(() => { const load = async () => { - const verifiableCredential = await agent?.dataStoreGetVerifiableCredential({ - hash, - }); + let verifiableCredential + try { + verifiableCredential = await agent?.dataStoreGetVerifiableCredential({ + hash, + }); + } catch (ex) { + console.log("credential not found locally") + } if (verifiableCredential) { setCredential({hash, verifiableCredential}) } else { // TRY IPFS or DIDComm + const senders = await agent?.didManagerFind({ provider: "did:peer"}) + if (senders && senders.length > 0) { + const requestCredMessage = { + type: 'https://veramo.io/didcomm/brainshare/1.0/request-credential', + from: senders[0].did, + to: did, + id: v4(), + body: { + hash + }, + return_route: 'all' + } + const packedMessage = await agent?.packDIDCommMessage({ message: requestCredMessage, packing: 'authcrypt' }) + await agent?.sendDIDCommMessage({ packedMessage: packedMessage!, messageId: requestCredMessage.id, recipientDidUrl: did! }) + const localCred = await agent?.dataStoreGetVerifiableCredential({ hash }) + setCredential({ hash, verifiableCredential: localCred! }) + } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9aa8bfd..46dab5b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -369,6 +369,9 @@ importers: url-parse: specifier: ^1.5.10 version: 1.5.10 + uuid: + specifier: ^9.0.1 + version: 9.0.1 devDependencies: '@types/markdown-it': specifier: ^13.0.2 @@ -379,6 +382,9 @@ importers: '@types/react-dom': specifier: ^18.2.8 version: 18.2.8 + '@types/uuid': + specifier: ^9.0.4 + version: 9.0.4 packages: