Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 15, 2024
1 parent 1ed94b5 commit 8537cd2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion yarn-project/key-store/src/new_test_key_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('NewTestKeyStore', () => {
// Manages to find master nullifer secret key for pub key
const masterNullifierSecretKey = await keyStore.getMasterNullifierSecretKeyForPublicKey(masterNullifierPublicKey);
expect(masterNullifierSecretKey.toString()).toMatchInlineSnapshot(
`"0x2ef5d15dd65d29546680ab72846fb071f41cb9f2a0212215e6c560e29df4ff65"`,
`"0x0fde74d5e504c73b58aad420dd72590fc6004571411e7f77c45378714195a52b"`,
);
});
});
20 changes: 11 additions & 9 deletions yarn-project/key-store/src/new_test_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,17 @@ export class NewTestKeyStore implements NewKeyStore {
* @dev Used when feeding the master nullifier secret key to the kernel circuit for nullifier keys verification.
*/
public getMasterNullifierSecretKeyForPublicKey(masterNullifierPublicKey: PublicKey): Promise<GrumpkinPrivateKey> {
const allMapValues = Array.from(this.#keys.values());
const masterNullifierSecretKeyBuffer = allMapValues.find(value =>
value.equals(masterNullifierPublicKey.toBuffer()),
);
if (!masterNullifierSecretKeyBuffer) {
throw new Error(
`Could not find master nullifier secret key for public key ${masterNullifierPublicKey.toString()}`,
);
for (const [key, value] of this.#keys.entries()) {
if (value.equals(masterNullifierPublicKey.toBuffer())) {
const accountAddress = key.split('-')[0];
const masterNullifierSecretKeyBuffer = this.#keys.get(`${accountAddress.toString()}-nsk_m`);
if (!masterNullifierSecretKeyBuffer) {
throw new Error(`Could not find master nullifier secret key for account ${accountAddress.toString()}`);
}
return Promise.resolve(GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer));
}
}
return Promise.resolve(GrumpkinScalar.fromBuffer(masterNullifierSecretKeyBuffer));

throw new Error(`Could not find master nullifier secret key for public key ${masterNullifierPublicKey.toString()}`);
}
}

0 comments on commit 8537cd2

Please sign in to comment.