Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 16, 2024
1 parent 4591484 commit 9163435
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions yarn-project/key-store/src/test_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,22 @@ export class NewTestKeyStore implements NewKeyStore {
public getMasterIncomingViewingSecretKeyForPublicKey(
masterIncomingViewingPublicKey: PublicKey,
): Promise<GrumpkinPrivateKey> {
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()}`,
);
}
}

0 comments on commit 9163435

Please sign in to comment.