Skip to content

Commit

Permalink
Merge pull request #77 from TheTechmage/feat/interopathon
Browse files Browse the repository at this point in the history
Feat: Interopathon Support (did:peer:4 & Empty Messages)
  • Loading branch information
TheTechmage authored Oct 28, 2024
2 parents f5383e1 + 5abc403 commit afc6f27
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 16 deletions.
32 changes: 30 additions & 2 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
},
"dependencies": {
"@noble/curves": "^1.2.0",
"bs58": "^5.0.0",
"didcomm": "^0.4.1",
"lit-code": "^0.1.12",
"mithril": "^2.2.2",
"multibase": "^4.0.6",
"multicodec": "^3.2.1",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"varint": "^6.0.0"
},
"devDependencies": {
"@fortawesome/fontawesome-free": "^6.4.2",
Expand All @@ -44,6 +46,7 @@
"@types/mithril": "^2.0.14",
"@types/prismjs": "^1.26.0",
"@types/uuid": "^9.0.3",
"@types/varint": "^6.0.3",
"bulma": "^0.9.4",
"css-loader": "^6.8.1",
"html-loader": "^4.2.0",
Expand Down
30 changes: 29 additions & 1 deletion src/lib/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ export class Agent {
case "didGenerated":
this.onDidGenerated(e.data.payload)
break
case "didRotated":
let contacts = ContactService.getContacts()
const {oldDid, newDid, jwt} = e.data.payload
if(this.profile.did == oldDid)
this.profile.did = newDid

for (let contact of contacts) {
const message = {
type: "https://didcomm.org/empty/1.0/empty",
body: {},
from_prior: jwt,
}
logger.log("Sending new did to contact:", contact?.label || contact.did)
console.log("Sending new did to contact:", contact, message)
this.sendMessage(contact, message as IMessage)
}
break
case "messageReceived":
this.onMessageReceived(e.data.payload)
break
Expand Down Expand Up @@ -143,6 +160,10 @@ export class Agent {
}

private onMessageReceived(message: IMessage) {
if (message?.prior) {
const oldContact = ContactService.getContact(message.prior.iss)
oldContact && ContactService.rotateContact(oldContact, message.prior.sub)
}
const from =
message.from == this.profile.did
? (this.profile as Contact)
Expand All @@ -159,7 +180,7 @@ export class Agent {
}
ContactService.addMessage(message.from, {
sender: fromName,
receiver: to.label || to.did,
receiver: to?.label || to.did,
timestamp: new Date(),
content: message.body.content,
type: message.type,
Expand Down Expand Up @@ -202,6 +223,13 @@ export class Agent {
ContactService.addMessage(contact.did, internalMessage)
}

public async rotateDid() {
this.worker.postMessage({
type: "rotateDid",
payload: {},
})
}

public async refreshMessages() {
this.postMessage({
type: "pickupStatus",
Expand Down
9 changes: 9 additions & 0 deletions src/lib/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ export class EphemeralContactService extends ContactService {
this.contacts[contact.did] = contact
}

rotateContact(contact: Contact, newDid: string): void {
const old_did = contact.did
delete this.contacts[contact.did]
contact.did = newDid
this.contacts[contact.did] = contact
this.messages[newDid] = this.messages[old_did]
delete this.messages[old_did]
}

saveMessageHistory(did: string, messages: Message[]): void {
this.messages[did] = messages
}
Expand Down
Loading

0 comments on commit afc6f27

Please sign in to comment.