From 17e48d12da10c2c74c626a98e7da20169ac5e4f8 Mon Sep 17 00:00:00 2001 From: Sasha Date: Tue, 30 Jan 2024 00:27:20 +0100 Subject: [PATCH] add keys operation to Keystore --- src/keystore/keystore.ts | 8 ++++++++ src/rln.ts | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/keystore/keystore.ts b/src/keystore/keystore.ts index 5be4712..51714d4 100644 --- a/src/keystore/keystore.ts +++ b/src/keystore/keystore.ts @@ -164,6 +164,14 @@ export class Keystore { return this.data; } + /** + * Read array of hashes of current credentials + * @returns array of keys of credentials in current Keystore + */ + public keys(): string[] { + return Object.keys(this.toObject().credentials || {}); + } + private static isValidNwakuStore(obj: unknown): boolean { if (!isKeystoreValid(obj)) { return false; diff --git a/src/rln.ts b/src/rln.ts index d3e99a1..314c48d 100644 --- a/src/rln.ts +++ b/src/rln.ts @@ -203,7 +203,7 @@ export class RLNInstance { private _contract: undefined | RLNContract; private _signer: undefined | ethers.Signer; - private _keystore = Keystore.create(); + private keystore = Keystore.create(); private _credentials: undefined | DecryptedCredentials; constructor( @@ -219,10 +219,6 @@ export class RLNInstance { return this._signer; } - public get keystore(): Keystore { - return this._keystore; - } - public async start(options: StartRLNOptions = {}): Promise { if (this.started || this.starting) { return; @@ -297,7 +293,7 @@ export class RLNInstance { throw Error("Failed to start RLN: cannot read Keystore provided."); } - this._keystore = keystore; + this.keystore = keystore; this._credentials = await keystore.readCredential( credentials.id, credentials.password