add keys operation to Keystore

This commit is contained in:
Sasha 2024-01-30 00:27:20 +01:00
parent eb119aa763
commit 17e48d12da
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View File

@ -164,6 +164,14 @@ export class Keystore {
return this.data; 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 { private static isValidNwakuStore(obj: unknown): boolean {
if (!isKeystoreValid(obj)) { if (!isKeystoreValid(obj)) {
return false; return false;

View File

@ -203,7 +203,7 @@ export class RLNInstance {
private _contract: undefined | RLNContract; private _contract: undefined | RLNContract;
private _signer: undefined | ethers.Signer; private _signer: undefined | ethers.Signer;
private _keystore = Keystore.create(); private keystore = Keystore.create();
private _credentials: undefined | DecryptedCredentials; private _credentials: undefined | DecryptedCredentials;
constructor( constructor(
@ -219,10 +219,6 @@ export class RLNInstance {
return this._signer; return this._signer;
} }
public get keystore(): Keystore {
return this._keystore;
}
public async start(options: StartRLNOptions = {}): Promise<void> { public async start(options: StartRLNOptions = {}): Promise<void> {
if (this.started || this.starting) { if (this.started || this.starting) {
return; return;
@ -297,7 +293,7 @@ export class RLNInstance {
throw Error("Failed to start RLN: cannot read Keystore provided."); throw Error("Failed to start RLN: cannot read Keystore provided.");
} }
this._keystore = keystore; this.keystore = keystore;
this._credentials = await keystore.readCredential( this._credentials = await keystore.readCredential(
credentials.id, credentials.id,
credentials.password credentials.password