From 91634354cda5c20f92a09ca3191abf3e88c165b4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 15 Apr 2024 14:23:38 +0000 Subject: [PATCH] fix --- yarn-project/key-store/src/test_key_store.ts | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/yarn-project/key-store/src/test_key_store.ts b/yarn-project/key-store/src/test_key_store.ts index c2d5036c5f5..022a01af9e0 100644 --- a/yarn-project/key-store/src/test_key_store.ts +++ b/yarn-project/key-store/src/test_key_store.ts @@ -255,15 +255,22 @@ export class NewTestKeyStore implements NewKeyStore { public getMasterIncomingViewingSecretKeyForPublicKey( masterIncomingViewingPublicKey: PublicKey, ): Promise { - const allMapValues = Array.from(this.#keys.values()); - const masterIncomingViewingSecretKeyBuffer = allMapValues.find(value => - value.equals(masterIncomingViewingPublicKey.toBuffer()), - ); - if (!masterIncomingViewingSecretKeyBuffer) { - throw new Error( - `Could not find master incoming viewing secret key for public key ${masterIncomingViewingPublicKey.toString()}`, - ); + // We iterate over the map keys to find the account address that corresponds to the provided public key + for (const [key, value] of this.#keys.entries()) { + if (value.equals(masterIncomingViewingPublicKey.toBuffer())) { + // We extract the account address from the map key + const accountAddress = key.split('-')[0]; + // We fetch the secret key and return it + const masterIncomingViewingSecretKeyBuffer = this.#keys.get(`${accountAddress.toString()}-ivsk_m`); + if (!masterIncomingViewingSecretKeyBuffer) { + throw new Error(`Could not find master incoming viewing secret key for account ${accountAddress.toString()}`); + } + return Promise.resolve(GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer)); + } } - return Promise.resolve(GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer)); + + throw new Error( + `Could not find master incoming viewing secret key for public key ${masterIncomingViewingPublicKey.toString()}`, + ); } }