Skip to content

Commit

Permalink
feat(DID): remove did document creation upon initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Harasz committed Nov 17, 2021
1 parent 9414600 commit b2feede
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Expand Up @@ -15,6 +15,7 @@

### Methods

- [createDocument](modules_didRegistry_didRegistry_service.DidRegistry.md#createdocument)
- [createPublicClaim](modules_didRegistry_didRegistry_service.DidRegistry.md#createpublicclaim)
- [decodeJWTToken](modules_didRegistry_didRegistry_service.DidRegistry.md#decodejwttoken)
- [getDidDocument](modules_didRegistry_didRegistry_service.DidRegistry.md#getdiddocument)
Expand Down Expand Up @@ -62,6 +63,20 @@ ___

## Methods

### createDocument

**createDocument**(): `Promise`<`boolean`\>

**`description`** create did document if not exists

#### Returns

`Promise`<`boolean`\>

true if document is created successfully

___

### createPublicClaim

**createPublicClaim**(`__namedParameters`): `Promise`<`string`\>
Expand Down
23 changes: 16 additions & 7 deletions src/modules/didRegistry/didRegistry.service.ts
Expand Up @@ -194,6 +194,22 @@ export class DidRegistry {
}
}

/**
* @description create did document if not exists
* @returns true if document is created successfully
*/
async createDocument(): Promise<boolean> {
if (this._cacheClient) {
const cachedDoc = await this._cacheClient.getDidDocument(this._did);
const pubKey = cachedDoc.publicKey.find((pk) => pk.id.endsWith(KeyTags.OWNER));
if (!pubKey) {
return this._document.create();
}
return true;
}
return this._document.create();
}

/**
* revokeDidDocument
*
Expand Down Expand Up @@ -237,13 +253,6 @@ export class DidRegistry {

private async _setDocument() {
this._document = new DIDDocumentFull(this._did, this._operator);
if (this._cacheClient) {
const cachedDoc = await this._cacheClient.getDidDocument(this._did);
const pubKey = cachedDoc.publicKey.find((pk) => pk.id.endsWith(KeyTags.OWNER));
if (!pubKey) {
await this._document.create();
}
}
}

private _setClaims() {
Expand Down

0 comments on commit b2feede

Please sign in to comment.