diff --git a/packages/ui-did-keyring/src/KiltDid.ts b/packages/ui-did-keyring/src/KiltDid.ts index ea94188..0327162 100644 --- a/packages/ui-did-keyring/src/KiltDid.ts +++ b/packages/ui-did-keyring/src/KiltDid.ts @@ -20,16 +20,23 @@ export class KiltDid extends KiltDidSuper { this.#store = store ?? new BrowserStore(); } - public loadAll() { - this.#store.all((key, value) => { - if (kiltPairKeyRegex.test(key)) { - this.keyring.addFromJson(value as KeyringPair$Json); - } - }); - this.#store.all((key, value) => { - if (kiltDidRegex.test(key)) { - this.addDid(value as DidUri); - } + public loadAll(): Promise { + return new Promise((resolve) => { + this.#store.all((key, value) => { + const jsons: KeyringPair$Json[] = []; + const dids: DidUri[] = []; + + if (kiltPairKeyRegex.test(key)) { + jsons.push(value as KeyringPair$Json); + } else if (kiltDidRegex.test(key)) { + dids.push(value as DidUri); + } + + jsons.forEach((json) => this.keyring.addFromJson(json)); + dids.forEach((did) => super.addDid(did)); + + resolve(); + }); }); } diff --git a/packages/ui-did-keyring/src/ZkDid.ts b/packages/ui-did-keyring/src/ZkDid.ts index 672da3f..56f7943 100644 --- a/packages/ui-did-keyring/src/ZkDid.ts +++ b/packages/ui-did-keyring/src/ZkDid.ts @@ -20,20 +20,27 @@ export class ZkDid extends ZkDidSuper { this.#store = store ?? new BrowserStore(); } - loadAll() { - this.#store.all((key, val) => { - if (zkPairKeyRegex.test(key)) { - const json = val as KeyringPair$Json; - - this.keyring.addFromJson(json); - } - }); - this.#store.all((key, val) => { - if (zkDidRegex.test(key)) { - const did = helpers.fromDidDocument(val as DidDocument, this.keyring); - - this.dids.set(did.id, did); - } + public loadAll(): Promise { + return new Promise((resolve) => { + this.#store.all((key, val) => { + const jsons: KeyringPair$Json[] = []; + const documents: DidDocument[] = []; + + if (zkPairKeyRegex.test(key)) { + jsons.push(val as KeyringPair$Json); + } else if (zkDidRegex.test(key)) { + documents.push(val as DidDocument); + } + + jsons.forEach((json) => this.keyring.addFromJson(json)); + documents.forEach((document) => { + const did = helpers.fromDidDocument(document, this.keyring); + + this.dids.set(did.id, did); + }); + + resolve(); + }); }); }