Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: store recipient keys by default #1847

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,

// Calucate if we have a did document, otherwise use the already present recipient keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Calucate if we have a did document, otherwise use the already present recipient keys
// 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 @@ -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