diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 3522de3feae..95dc8666cf2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -189,8 +189,6 @@ global NUM_BASE_PARITY_PER_ROOT_PARITY: u64 = 4; * | MID | 8 < n ≤ 16 | 32 < hash_index ≤ 40 | * | HIGH | 16 < n ≤ 48 | 40 < hash_index ≤ 48 | * +-----------+-------------------------------+----------------------+ - * - * Note: When modifying, modify `GeneratorIndexPacker` in packer.hpp accordingly. */ // Indices with size ≤ 8 global GENERATOR_INDEX__NOTE_HASH = 1; @@ -234,3 +232,8 @@ global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43; global GENERATOR_INDEX__FUNCTION_ARGS = 44; global GENERATOR_INDEX__AUTHWIT_INNER = 45; global GENERATOR_INDEX__AUTHWIT_OUTER = 46; +// Key related generators follow +global GENERATOR_INDEX__NSK_M = 47; +global GENERATOR_INDEX__IVSK_M = 48; +global GENERATOR_INDEX__OVSK_M = 49; +global GENERATOR_INDEX__TSK_M = 50; diff --git a/yarn-project/circuit-types/src/keys/index.ts b/yarn-project/circuit-types/src/keys/index.ts index f137b0d567a..c770f679814 100644 --- a/yarn-project/circuit-types/src/keys/index.ts +++ b/yarn-project/circuit-types/src/keys/index.ts @@ -1,2 +1,3 @@ export * from './key_pair.js'; export * from './key_store.js'; +export * from './new_key_store.js'; \ No newline at end of file diff --git a/yarn-project/circuit-types/src/keys/key_store.ts b/yarn-project/circuit-types/src/keys/key_store.ts index 4869503def4..3cf2c960d59 100644 --- a/yarn-project/circuit-types/src/keys/key_store.ts +++ b/yarn-project/circuit-types/src/keys/key_store.ts @@ -3,6 +3,7 @@ import { type AztecAddress, type GrumpkinPrivateKey, type PublicKey } from '@azt /** * Represents a secure storage for managing keys. * Provides functionality to create and retrieve accounts, private and public keys, + * TODO(#5627): 💣💣💣 */ export interface KeyStore { /** diff --git a/yarn-project/circuit-types/src/keys/new_key_store.ts b/yarn-project/circuit-types/src/keys/new_key_store.ts new file mode 100644 index 00000000000..861072b8147 --- /dev/null +++ b/yarn-project/circuit-types/src/keys/new_key_store.ts @@ -0,0 +1,36 @@ +import { AztecAddress, Fr, PartialAddress, type PublicKey } from '@aztec/circuits.js'; + +/** + * Represents a secure storage for managing keys. + */ +export interface NewKeyStore { + /** + * Retrieves the master nullifier public key. + * @returns A Promise that resolves to the master nullifier public key. + */ + getMasterNullifierPublicKey(): Promise; + + /** + * Retrieves the master incoming viewing key. + * @returns A Promise that resolves to the master incoming viewing key. + */ + getMasterIncomingViewingPublicKey(): Promise; + + /** + * Retrieves the master outgoing viewing key. + * @returns A Promise that resolves to the master outgoing viewing key. + */ + getMasterOutgoingViewingPublicKey(): Promise; + + /** + * Retrieves the master tagging key. + * @returns A Promise that resolves to the master tagging key. + */ + getMasterTaggingPublicKey(): Promise; + + /** + * Retrieves the hash of the public keys. + * @returns A Promise that resolves to the hash of the public keys. + */ + getPublicKeysHash(): Promise; +} diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 8879c01216c..2c0c6081456 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -148,4 +148,8 @@ export enum GeneratorIndex { FUNCTION_ARGS = 44, AUTHWIT_INNER = 45, AUTHWIT_OUTER = 46, + NSK_M = 47, + IVSK_M = 48, + OVSK_M = 49, + TSK_M = 50, } diff --git a/yarn-project/key-store/src/new_test_key_store.ts b/yarn-project/key-store/src/new_test_key_store.ts new file mode 100644 index 00000000000..14476d6084b --- /dev/null +++ b/yarn-project/key-store/src/new_test_key_store.ts @@ -0,0 +1,40 @@ +import { type NewKeyStore, type KeyPair, type KeyStore, type PublicKey } from '@aztec/circuit-types'; +import { + type AztecAddress, + type GrumpkinPrivateKey, + GrumpkinScalar, + Point, + computeNullifierSecretKey, + computeSiloedNullifierSecretKey, + derivePublicKey, + type Fr, + GeneratorIndex, + Fq, +} from '@aztec/circuits.js'; +import { type Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { type AztecKVStore, type AztecMap } from '@aztec/kv-store'; + +import { ConstantKeyPair } from './key_pair.js'; +import { poseidonHash } from '@aztec/foundation/crypto'; +/** + * TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment. + * It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized. + * TODO: Potentially rename to not include 'Test' in the name. + */ +export class NewTestKeyStore implements NewKeyStore { + #keys: AztecMap; + + constructor(private curve: Grumpkin, database: AztecKVStore) { + this.#keys = database.openMap('key_store'); + } + + public async addAccount(sk: Fr): Promise { + const masterNullifierSecretKey = poseidonHash([sk], GeneratorIndex.NSK_M); + // TODO: Is converting from Fr to Fq an issue? Fr.MODULUS is < Fq.MODULUS so it wont' throw but should we refactor this? + const masterNullifierPublicKey = this.curve.mul(this.curve.generator(), Fq.fromBuffer(masterNullifierSecretKey.toBuffer())) + } + + public async getMasterNullifierPublicKey(): Promise { + return poseidonHash() + } +} diff --git a/yarn-project/key-store/src/test_key_store.ts b/yarn-project/key-store/src/test_key_store.ts index a5bfe3144b3..4af7e2c2dfa 100644 --- a/yarn-project/key-store/src/test_key_store.ts +++ b/yarn-project/key-store/src/test_key_store.ts @@ -16,6 +16,7 @@ import { ConstantKeyPair } from './key_pair.js'; /** * TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment. * It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized. + * TODO(#5627): 💣💣💣 */ export class TestKeyStore implements KeyStore { #keys: AztecMap;