Skip to content

Commit

Permalink
fix: store recipient keys by default (#1847)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Apr 30, 2024
1 parent 5d986f0 commit e9238cf
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ export class InMemoryDidRegistry implements DidRegistrar, DidResolver {
did: didDocument.id,
role: DidDocumentRole.Created,
didDocument,
tags: {
// We need to save the recipientKeys, so we can find the associated did
// of a key when we receive a message from another connection.
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
},
})
const didRepository = agentContext.dependencyManager.resolve(DidRepository)
await didRepository.save(agentContext, didRecord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,6 @@ export class ConnectionService {
did: peerDid,
role,
didDocument,
tags: {
// We need to save the recipientKeys, so we can find the associated did
// of a key when we receive a message from another connection.
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
},
})

// Store the unqualified did with the legacy did document in the metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ export class DidRotateService {
did: didDocument.id,
didDocument,
tags: {
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),

// For did:peer, store any alternative dids (like short form did:peer:4),
// it may have in order to relate any message referencing it
alternativeDids: isValidPeerDid(didDocument.id) ? getAlternativeDidsForPeerDid(didDocument.id) : undefined,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/modules/dids/DidsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export class DidsApi {
if (existingDidRecord) {
existingDidRecord.didDocument = didDocument
existingDidRecord.setTags({
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
alternativeDids: isValidPeerDid(didDocument.id) ? getAlternativeDidsForPeerDid(did) : undefined,
})

Expand All @@ -170,7 +169,6 @@ export class DidsApi {
did,
didDocument,
tags: {
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
alternativeDids: isValidPeerDid(didDocument.id) ? getAlternativeDidsForPeerDid(did) : undefined,
},
})
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/modules/dids/__tests__/peer-did.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ describe('peer dids', () => {
// It is important to take the did document from the PeerDid class
// as it will have the id property
didDocument: didDocument,
tags: {
// We need to save the recipientKeys, so we can find the associated did
// of a key when we receive a message from another connection.
recipientKeyFingerprints: didDocument.recipientKeys.map((key) => key.fingerprint),
},
})

await didRepository.save(agentContext, didDocumentRecord)
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/modules/dids/repository/DidRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export interface CustomDidTags extends TagsBase {
}

type DefaultDidTags = {
// We set the recipientKeyFingeprints as a default tag, if the did record has a did document
// If the did record does not have a did document, we can't calculate it, and it needs to be
// handled by the creator of the did record
recipientKeyFingerprints?: string[]

role: DidDocumentRole
method: string
legacyUnqualifiedDid?: string
Expand Down Expand Up @@ -75,6 +80,11 @@ export class DidRecord extends BaseRecord<DefaultDidTags, CustomDidTags, DidReco
legacyUnqualifiedDid: legacyDid?.unqualifiedDid,
did: this.did,
methodSpecificIdentifier: did.id,

// Calculate if we have a did document, otherwise use the already present recipient keys
recipientKeyFingerprints: this.didDocument
? this.didDocument.recipientKeys.map((recipientKey) => recipientKey.fingerprint)
: this._tags.recipientKeyFingerprints,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1462,11 +1462,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MktCZAQNGvWb4WHAjwBqPtXhZdDYorbSJkGW9vj1uhw1HD",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.608Z",
"did": "did:peer:1zQmP96nW6vbNjzwPt19z1NYqhnAfgnAFqfLHcktkmdUFzhT",
"didDocument": {
Expand Down Expand Up @@ -1536,11 +1532,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6Mko31DNE3gqMRZj1JNhv2BHb1caQshcd9njgKkEQXsgFRp",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.646Z",
"did": "did:peer:1zQmPbGa8KDwyjcw9UgwCCgJMV7jU5kKCyvBuwFVc88WxA56",
"didDocument": {
Expand Down Expand Up @@ -1610,11 +1602,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6Mkw81EsWQioXYC9YJ7uKHCRh6LTN7sfD9sJbSPBGXmUpzC",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.577Z",
"did": "did:peer:1zQmRAfQ6J5qk4qcbHyoStFVkhusazLT9xQcFhdC9dhhQ1cJ",
"didDocument": {
Expand Down Expand Up @@ -1684,11 +1672,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6Mkt1tsp15cnDD7wBCFgehiR2SxHX1aPxt4sueE24twH9Bd",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.628Z",
"did": "did:peer:1zQmSMBVNMDrh7fyE8bkAmk1ZatshjinpsEqPA3nx8JYjuKb",
"didDocument": {
Expand Down Expand Up @@ -1758,11 +1742,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6Mkwc6efk75y4Y1agRx4NGpvtrpKxtKvMfgBEdQkHBwU8Xu",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.608Z",
"did": "did:peer:1zQmXYj3nNwsF37WXXdb8XkCAtsTCBpJJbsLKPPGfi2PWCTU",
"didDocument": {
Expand Down Expand Up @@ -1832,11 +1812,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkvW9GxjjUdL9qpaj2qQW6YBhCjZY7Zkzrks3cgpJaRjxR",
],
},
"_tags": {},
"createdAt": "2022-04-20T13:02:21.646Z",
"did": "did:peer:1zQmZ2tdw35SaLncSHhf9zBv3e9QmJmLErZRSLsDdYowPHXy",
"didDocument": {
Expand Down Expand Up @@ -1906,11 +1882,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MktpVtPC5j91aycGPT5pceiu8EGKDzM5RLwqAZBuCgxw4V",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.641Z",
"did": "did:peer:1zQma8LpnJ22GxQdyASV5jP6psacAGtJ6ytk4pVayYp4erRf",
"didDocument": {
Expand Down Expand Up @@ -1980,11 +1952,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkwXNXTehVH7YijDmN1PtaXaSaCniTyaVepmY1EJgS15xq",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.646Z",
"did": "did:peer:1zQmadmBfngrYSWhYYxZ24fpW29iwhKhQ6CB6euLabbSK6ga",
"didDocument": {
Expand Down Expand Up @@ -2054,11 +2022,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkjmCrDWJVf8H2pCHcu11UDs4jb6FVu8nn5yQW24rrgez6",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.628Z",
"did": "did:peer:1zQmc3BZoTinpVaG3oZ4PmRVN4JMdNZGCmPkS6smmTNLnvEZ",
"didDocument": {
Expand Down Expand Up @@ -2128,11 +2092,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkjDJL4X7YGoH6gjamhZR2NzowPZqtJfX5kPuNuWiVdjMr",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.641Z",
"did": "did:peer:1zQmcXZepLE55VGCMELEFjMd4nKrzp3GGyRR3r3MYermagui",
"didDocument": {
Expand Down Expand Up @@ -2202,11 +2162,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkvcgxQSsX5WA8vcBokLZ46znnhRBH6aKAGYnonEUfUnQV",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.635Z",
"did": "did:peer:1zQmduuYkxRKJuVyvDqttdd9eDfBwDnF1DAU5FFQo4whx7Uw",
"didDocument": {
Expand Down Expand Up @@ -2276,11 +2232,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkfiPMPxCQeSDZGMkCvm1Y2rBoPsmw4ZHMv71jXtcWRRiM",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.577Z",
"did": "did:peer:1zQmeHpGaZ48DnAP2k3KntXB1vmd8MgLEdcb4EQzqWJDHcbX",
"didDocument": {
Expand Down Expand Up @@ -2350,11 +2302,7 @@ exports[`UpdateAssistant | v0.1 - v0.2 should correctly update the connection re
},
"type": "DidRecord",
"value": {
"_tags": {
"recipientKeyFingerprints": [
"z6MkuWTEmH1mUo6W96zSWyH612hFHowRzNEscPYBL2CCMyC2",
],
},
"_tags": {},
"createdAt": "2022-04-30T13:02:21.653Z",
"did": "did:peer:1zQmfDAtfDZcK4trJBsvVTXrBx9uaLCHSUZH9X2LFaAd3JKv",
"didDocument": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ describe('0.1-0.2 | Connection', () => {
didDocumentString: JSON.stringify(legacyDidPeerR1xKJw17sUoXhejEpugMYJ),
},
},
_tags: {
recipientKeyFingerprints: [
'z6MksYU4MHtfmNhNm1uGMvANr9j4CBv2FymjiJtRgA36bSVH',
'z6MksYU4MHtfmNhNm1uGMvANr9j4CBv2FymjiJtRgA36bSVH',
],
},
})
expect(didRecord.getTags()).toMatchObject({
recipientKeyFingerprints: [
'z6MksYU4MHtfmNhNm1uGMvANr9j4CBv2FymjiJtRgA36bSVH',
'z6MksYU4MHtfmNhNm1uGMvANr9j4CBv2FymjiJtRgA36bSVH',
],
})

expect(theirDidRecord.toJSON()).toMatchObject({
Expand All @@ -253,12 +253,12 @@ describe('0.1-0.2 | Connection', () => {
didDocumentString: JSON.stringify(legacyDidPeer4kgVt6CidfKgo1MoWMqsQX),
},
},
_tags: {
recipientKeyFingerprints: [
'z6MkjKUBV9DDUj7cgW8UbDJZhPcHCH8up26Lrr8YqkAS4wcb',
'z6MkjKUBV9DDUj7cgW8UbDJZhPcHCH8up26Lrr8YqkAS4wcb',
],
},
})
expect(theirDidRecord.getTags()).toMatchObject({
recipientKeyFingerprints: [
'z6MkjKUBV9DDUj7cgW8UbDJZhPcHCH8up26Lrr8YqkAS4wcb',
'z6MkjKUBV9DDUj7cgW8UbDJZhPcHCH8up26Lrr8YqkAS4wcb',
],
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ export async function extractDidDocument<Agent extends BaseAgent>(agent: Agent,
role: DidDocumentRole.Created,
didDocument: newOurDidDocument,
createdAt: connectionRecord.createdAt,
tags: {
recipientKeyFingerprints: newOurDidDocument.recipientKeys.map((key) => key.fingerprint),
},
})

ourDidRecord.metadata.set(DidRecordMetadataKeys.LegacyDid, {
Expand Down Expand Up @@ -231,9 +228,6 @@ export async function extractDidDocument<Agent extends BaseAgent>(agent: Agent,
role: DidDocumentRole.Received,
didDocument: newTheirDidDocument,
createdAt: connectionRecord.createdAt,
tags: {
recipientKeyFingerprints: newTheirDidDocument.recipientKeys.map((key) => key.fingerprint),
},
})

theirDidRecord.metadata.set(DidRecordMetadataKeys.LegacyDid, {
Expand Down
4 changes: 1 addition & 3 deletions packages/indy-vdr/src/dids/IndyVdrIndyDidRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ export class IndyVdrIndyDidRegistrar implements DidRegistrar {
const didRecord = new DidRecord({
did,
role: DidDocumentRole.Created,
tags: {
recipientKeyFingerprints: didDocument.recipientKeys.map((key: Key) => key.fingerprint),
},
didDocument,
})

const didRepository = agentContext.dependencyManager.resolve(DidRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,13 @@ describe('IndyVdrIndyDidRegistrar', () => {
expect(saveCalled).toHaveBeenCalledTimes(1)
const [saveEvent] = saveCalled.mock.calls[0]

expect(saveEvent.payload.record.getTags()).toMatchObject({
recipientKeyFingerprints: ['z6LSrH6AdsQeZuKKmG6Ehx7abEQZsVg2psR2VU536gigUoAe'],
})
expect(saveEvent.payload.record).toMatchObject({
did: 'did:indy:pool1:B6xaJg1c2xU3D9ppCtt1CZ',
role: DidDocumentRole.Created,
_tags: {
recipientKeyFingerprints: ['z6LSrH6AdsQeZuKKmG6Ehx7abEQZsVg2psR2VU536gigUoAe'],
},
didDocument: undefined,
didDocument: expect.any(DidDocument),
})
})

Expand Down

0 comments on commit e9238cf

Please sign in to comment.