Skip to content

Commit

Permalink
fix: workaround to not store dids twice
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Feb 10, 2024
1 parent f895a2c commit aa3b069
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packages/schemas/src/schemas/did/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ import { DIDStaticMethodTypes } from './types'

export const DIDStaticMethods: DIDStaticMethodTypes = {
async storePrismDID(did: SDK.Domain.DID, keyPathIndex: number, privateKey: SDK.Domain.PrivateKey, _privateKeyMetaId?: string | null | undefined, alias?: string | undefined): Promise<void> {
await this.db.collections.dids.insert({
did: did.toString(),
method: did.method,
methodId: did.methodId,
schema: did.schema,
alias
})
await this.storePrivateKeys(
privateKey,
did,
keyPathIndex,
)
const found = await this.db.collections.dids.findOne({
selector: {
did: {
$eq: did.toString(),
}
}
}).exec();
if (!found) {
await this.db.collections.dids.insert({
did: did.toString(),
method: did.method,
methodId: did.methodId,
schema: did.schema,
alias
})
await this.storePrivateKeys(
privateKey,
did,
keyPathIndex,
)
}
},
async getAllPrismDIDs(): Promise<SDK.Domain.PrismDIDInfo[]> {
const dids = await this.db.collections.dids.find({
Expand Down

0 comments on commit aa3b069

Please sign in to comment.