Skip to content

Commit 0e24724

Browse files
committed
added a localcaching for didDocument
1 parent 605b415 commit 0e24724

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/credential/services/credential.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
} from '../dto/register-credential.dto';
2424
import { getAppVault, getAppMenemonic } from '../../utils/app-vault-service';
2525
import { TxSendModuleService } from 'src/tx-send-module/tx-send-module.service';
26-
26+
import * as NodeCache from 'node-cache';
27+
const myCache = new NodeCache();
2728
@Injectable()
2829
export class CredentialService {
2930
constructor(
@@ -112,7 +113,16 @@ export class CredentialService {
112113
);
113114
const seed = await this.hidWallet.getSeedFromMnemonic(issuerMnemonic);
114115
const hypersignDid = new HypersignDID();
115-
const { didDocument } = await hypersignDid.resolve({ did: issuerDid });
116+
let didDocument;
117+
if (myCache.has(issuerDid)) {
118+
didDocument = myCache.get(issuerDid);
119+
console.log('Getting from Cache');
120+
} else {
121+
const resp = await hypersignDid.resolve({ did: issuerDid });
122+
didDocument = resp.didDocument;
123+
myCache.set(issuerDid, didDocument);
124+
Logger.log('Setting Cache');
125+
}
116126
const verificationMethod = didDocument.verificationMethod.find(
117127
(vm) => vm.id === verificationMethodId,
118128
);
@@ -192,6 +202,7 @@ export class CredentialService {
192202
} = await hypersignVC.issue({
193203
credential,
194204
issuerDid,
205+
issuerDidDoc: didDocument,
195206
verificationMethodId,
196207
privateKeyMultibase,
197208
registerCredential: false,

0 commit comments

Comments
 (0)