-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './key_pair.js'; | ||
export * from './key_store.js'; | ||
export * from './new_key_store.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PublicKey>; | ||
|
||
/** | ||
* Retrieves the master incoming viewing key. | ||
* @returns A Promise that resolves to the master incoming viewing key. | ||
*/ | ||
getMasterIncomingViewingPublicKey(): Promise<PublicKey>; | ||
|
||
/** | ||
* Retrieves the master outgoing viewing key. | ||
* @returns A Promise that resolves to the master outgoing viewing key. | ||
*/ | ||
getMasterOutgoingViewingPublicKey(): Promise<PublicKey>; | ||
|
||
/** | ||
* Retrieves the master tagging key. | ||
* @returns A Promise that resolves to the master tagging key. | ||
*/ | ||
getMasterTaggingPublicKey(): Promise<PublicKey>; | ||
|
||
/** | ||
* Retrieves the hash of the public keys. | ||
* @returns A Promise that resolves to the hash of the public keys. | ||
*/ | ||
getPublicKeysHash(): Promise<PublicKey>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, Buffer>; | ||
|
||
constructor(private curve: Grumpkin, database: AztecKVStore) { | ||
this.#keys = database.openMap('key_store'); | ||
} | ||
|
||
public async addAccount(sk: Fr): Promise<PublicKey> { | ||
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<PublicKey> { | ||
return poseidonHash() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters