Skip to content

Commit

Permalink
refactor: nuking KeyStore and KeyPair interfaces (#6553)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored May 21, 2024
1 parent 8bbbbb6 commit 23e0518
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 177 deletions.
1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './function_call.js';
export * from './keys/index.js';
export * from './notes/index.js';
export * from './messaging/index.js';
export * from './l2_block.js';
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/circuit-types/src/keys/index.ts

This file was deleted.

20 changes: 0 additions & 20 deletions yarn-project/circuit-types/src/keys/key_pair.ts

This file was deleted.

120 changes: 0 additions & 120 deletions yarn-project/circuit-types/src/keys/key_store.ts

This file was deleted.

2 changes: 1 addition & 1 deletion yarn-project/key-store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './test_key_store.js';
export * from './key_store.js';
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
} from '@aztec/circuits.js';
import { openTmpStore } from '@aztec/kv-store/utils';

import { TestKeyStore } from './test_key_store.js';
import { KeyStore } from './key_store.js';

describe('TestKeyStore', () => {
describe('KeyStore', () => {
it('Adds account and returns keys', async () => {
const keyStore = new TestKeyStore(openTmpStore());
const keyStore = new KeyStore(openTmpStore());

// Arbitrary fixed values
const sk = new Fr(8923n);
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('TestKeyStore', () => {
});

it('nullifier key rotation tests', async () => {
const keyStore = new TestKeyStore(openTmpStore());
const keyStore = new KeyStore(openTmpStore());

// Arbitrary fixed values
const sk = new Fr(8923n);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type KeyStore, type PublicKey } from '@aztec/circuit-types';
import { type PublicKey } from '@aztec/circuit-types';
import {
AztecAddress,
CompleteAddress,
Expand All @@ -24,10 +24,9 @@ import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize'
import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';

/**
* 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.
* Used for managing keys. Can hold keys of multiple accounts and allows for key rotation.
*/
export class TestKeyStore implements KeyStore {
export class KeyStore {
#keys: AztecMap<string, Buffer>;

constructor(database: AztecKVStore) {
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/pxe/src/kernel_oracle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AztecNode, type KeyStore } from '@aztec/circuit-types';
import { type AztecNode } from '@aztec/circuit-types';
import {
type AztecAddress,
type Fr,
Expand All @@ -13,6 +13,7 @@ import {
} from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';
import { type Tuple } from '@aztec/foundation/serialize';
import { type KeyStore } from '@aztec/key-store';

import { type ContractDataOracle } from '../contract_data_oracle/index.js';
import { type ProvingDataOracle } from './../kernel_prover/proving_data_oracle.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/note_processor/note_processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EncryptedL2BlockL2Logs,
EncryptedL2Log,
EncryptedTxL2Logs,
type KeyStore,
type L1NotePayload,
L2Block,
TaggedNote,
Expand All @@ -20,6 +19,7 @@ import {
} from '@aztec/circuits.js';
import { pedersenHash } from '@aztec/foundation/crypto';
import { GrumpkinScalar, Point } from '@aztec/foundation/fields';
import { type KeyStore } from '@aztec/key-store';
import { openTmpStore } from '@aztec/kv-store/utils';
import { type AcirSimulator } from '@aztec/simulator';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type AztecNode,
type EncryptedL2BlockL2Logs,
type KeyStore,
L1NotePayload,
type L2Block,
TaggedNote,
Expand All @@ -11,6 +10,7 @@ import { INITIAL_L2_BLOCK_NUM, MAX_NEW_NOTE_HASHES_PER_TX, type PublicKey } from
import { type Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { Timer } from '@aztec/foundation/timer';
import { type KeyStore } from '@aztec/key-store';
import { ContractNotFoundError } from '@aztec/simulator';

import { DeferredNoteDao } from '../database/deferred_note_dao.js';
Expand Down
8 changes: 3 additions & 5 deletions yarn-project/pxe/src/pxe_service/create_pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BBNativeProofCreator } from '@aztec/bb-prover';
import { type AztecNode, type ProofCreator } from '@aztec/circuit-types';
import { randomBytes } from '@aztec/foundation/crypto';
import { createDebugLogger } from '@aztec/foundation/log';
import { TestKeyStore } from '@aztec/key-store';
import { KeyStore } from '@aztec/key-store';
import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
import { initStoreForRollup } from '@aztec/kv-store/utils';
import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer';
Expand All @@ -20,7 +20,7 @@ import { PXEService } from './pxe_service.js';

/**
* Create and start an PXEService instance with the given AztecNode.
* If no keyStore or database is provided, it will use TestKeyStore and MemoryDB as default values.
* If no keyStore or database is provided, it will use KeyStore and MemoryDB as default values.
* Returns a Promise that resolves to the started PXEService instance.
*
* @param aztecNode - The AztecNode instance to be used by the server.
Expand All @@ -42,9 +42,7 @@ export async function createPXEService(
const keyStorePath = config.dataDirectory ? join(config.dataDirectory, 'pxe_key_store') : undefined;
const l1Contracts = await aztecNode.getL1ContractAddresses();

const keyStore = new TestKeyStore(
await initStoreForRollup(AztecLmdbStore.open(keyStorePath), l1Contracts.rollupAddress),
);
const keyStore = new KeyStore(await initStoreForRollup(AztecLmdbStore.open(keyStorePath), l1Contracts.rollupAddress));
const db = new KVPxeDatabase(await initStoreForRollup(AztecLmdbStore.open(pxeDbPath), l1Contracts.rollupAddress));

// (@PhilWindle) Temporary validation until WASM is implemented
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ExtendedNote,
type FunctionCall,
type GetUnencryptedLogsResponse,
type KeyStore,
type L2Block,
type LogFilter,
MerkleTreeId,
Expand Down Expand Up @@ -42,6 +41,7 @@ import { Fq, Fr } from '@aztec/foundation/fields';
import { SerialQueue } from '@aztec/foundation/fifo';
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { Timer } from '@aztec/foundation/timer';
import { type KeyStore } from '@aztec/key-store';
import {
type AcirSimulator,
type ExecutionResult,
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type AztecNode, type PXE, TxEffect, mockTx } from '@aztec/circuit-types
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { type L1ContractAddresses } from '@aztec/ethereum';
import { EthAddress } from '@aztec/foundation/eth-address';
import { TestKeyStore } from '@aztec/key-store';
import { KeyStore } from '@aztec/key-store';
import { openTmpStore } from '@aztec/kv-store/utils';

import { type MockProxy, mock } from 'jest-mock-extended';
Expand All @@ -16,7 +16,7 @@ import { pxeTestSuite } from './pxe_test_suite.js';

function createPXEService(): Promise<PXE> {
const kvStore = openTmpStore();
const keyStore = new TestKeyStore(kvStore);
const keyStore = new KeyStore(kvStore);
const node = mock<AztecNode>();
const db = new KVPxeDatabase(kvStore);
const config: PXEServiceConfig = { l2BlockPollingIntervalMS: 100, l2StartingBlock: INITIAL_L2_BLOCK_NUM };
Expand All @@ -42,14 +42,14 @@ function createPXEService(): Promise<PXE> {
pxeTestSuite('PXEService', createPXEService);

describe('PXEService', () => {
let keyStore: TestKeyStore;
let keyStore: KeyStore;
let node: MockProxy<AztecNode>;
let db: PxeDatabase;
let config: PXEServiceConfig;

beforeEach(() => {
const kvStore = openTmpStore();
keyStore = new TestKeyStore(kvStore);
keyStore = new KeyStore(kvStore);
node = mock<AztecNode>();
db = new KVPxeDatabase(kvStore);
config = { l2BlockPollingIntervalMS: 100, l2StartingBlock: INITIAL_L2_BLOCK_NUM, proverEnabled: false };
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/pxe/src/simulator/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type AztecNode, type KeyStore } from '@aztec/circuit-types';
import { type AztecNode } from '@aztec/circuit-types';
import { type KeyStore } from '@aztec/key-store';
import { AcirSimulator } from '@aztec/simulator';

import { ContractDataOracle } from '../contract_data_oracle/index.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type AztecNode,
type KeyStore,
type L2Block,
MerkleTreeId,
type NoteStatus,
Expand All @@ -20,6 +19,7 @@ import {
import { computeL1ToL2MessageNullifier } from '@aztec/circuits.js/hash';
import { type FunctionArtifact, getFunctionArtifact } from '@aztec/foundation/abi';
import { createDebugLogger } from '@aztec/foundation/log';
import { type KeyStore } from '@aztec/key-store';
import { type DBOracle, MessageLoadOracleInputs } from '@aztec/simulator';
import { type ContractInstance } from '@aztec/types/contracts';

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/synchronizer/synchronizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Fr, type Header, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
import { makeHeader } from '@aztec/circuits.js/testing';
import { randomInt } from '@aztec/foundation/crypto';
import { SerialQueue } from '@aztec/foundation/fifo';
import { TestKeyStore } from '@aztec/key-store';
import { KeyStore } from '@aztec/key-store';
import { openTmpStore } from '@aztec/kv-store/utils';

import { type MockProxy, mock } from 'jest-mock-extended';
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('Synchronizer', () => {
expect(await synchronizer.isGlobalStateSynchronized()).toBe(true);

// Manually adding account to database so that we can call synchronizer.isAccountStateSynchronized
const keyStore = new TestKeyStore(openTmpStore());
const keyStore = new KeyStore(openTmpStore());
const addAddress = async (startingBlockNum: number) => {
const secretKey = Fr.random();
const partialAddress = Fr.random();
Expand Down
10 changes: 2 additions & 8 deletions yarn-project/pxe/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import {
type AztecNode,
type KeyStore,
type L2Block,
L2BlockL2Logs,
MerkleTreeId,
type TxHash,
} from '@aztec/circuit-types';
import { type AztecNode, type L2Block, L2BlockL2Logs, MerkleTreeId, type TxHash } from '@aztec/circuit-types';
import { type NoteProcessorCaughtUpStats } from '@aztec/circuit-types/stats';
import { type AztecAddress, type Fr, INITIAL_L2_BLOCK_NUM, type PublicKey } from '@aztec/circuits.js';
import { type SerialQueue } from '@aztec/foundation/fifo';
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import { type KeyStore } from '@aztec/key-store';

import { type DeferredNoteDao } from '../database/deferred_note_dao.js';
import { type PxeDatabase } from '../database/index.js';
Expand Down

0 comments on commit 23e0518

Please sign in to comment.