Skip to content

Commit

Permalink
feat: save returned brainshare credential (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickreynolds authored Oct 5, 2023
1 parent 8493d54 commit b2d51d1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/agent-explore/src/context/web3/saveMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
29 changes: 26 additions & 3 deletions packages/plugin/src/components/MarkDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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! })
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2d51d1

Please sign in to comment.