Skip to content

Commit

Permalink
generalizing key store test
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jun 5, 2024
1 parent 34fe73f commit 58df708
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
8 changes: 7 additions & 1 deletion yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { type GrumpkinPrivateKey, type AztecAddress, type CompleteAddress, type Fq, type Fr, type PartialAddress } from '@aztec/circuits.js';
import {
type AztecAddress,
type CompleteAddress,
type Fr,
type GrumpkinPrivateKey,
type PartialAddress,
} from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';
import {
type ContractClassWithId,
Expand Down
12 changes: 12 additions & 0 deletions yarn-project/key-store/src/__snapshots__/key_store.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

exports[`KeyStore key rotation tests 1`] = `"0x1a8a9a1d91cbb353d8df4f1bbfd0283f7fc63766f671edd9443a1270a7b2a954"`;

exports[`KeyStore key rotation tests 2`] = `"0x296e42f1039b62290372d608fcab55b00a3f96c1c8aa347b2a830639c5a12757"`;

exports[`KeyStore key rotation tests 3`] = `"0x019f2a705b68683f1d86da639a543411fa779af41896c3920d0c2d5226c686dd"`;

exports[`KeyStore key rotation tests 4`] = `"0x117445c8819c06b9a0889e5cce1f550e32ec6993c23f57bc9fc5cda05df520ae"`;

exports[`KeyStore key rotation tests 5`] = `"0x1a8a9a1d91cbb353d8df4f1bbfd0283f7fc63766f671edd9443a1270a7b2a954"`;

exports[`KeyStore key rotation tests 6`] = `"0x21e3ca4bc7ae2b5e9fe343f4eec5c0aa7391857333821a4b0a1c7d4cb0055bf0"`;

exports[`KeyStore key rotation tests 7`] = `"0x0900aea4825d057e5bc916063a535520a7c6283740eaf218cd6961b10cba46fd"`;

exports[`KeyStore key rotation tests 8`] = `"0x27ccbe41ff5f33fa78348533da9d4a79e8fea8805771e61748ea42be4202f168"`;
22 changes: 7 additions & 15 deletions yarn-project/key-store/src/key_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {
AztecAddress,
Fq,
Fr,
KeyPrefix,
type KeyPrefix,
computeAppSecretKey,
deriveKeys,
derivePublicKeyFromSecretKey
derivePublicKeyFromSecretKey,
} from '@aztec/circuits.js';
import { openTmpStore } from '@aztec/kv-store/utils';

Expand Down Expand Up @@ -90,17 +90,15 @@ describe('KeyStore', () => {
);
});

it.each(['n', 'iv'])('key rotation tests', async keyPrefix => {
it.each(['n' as KeyPrefix, 'iv' as KeyPrefix])('key rotation tests', async keyPrefix => {
const keyStore = new KeyStore(openTmpStore());

// Arbitrary fixed values
const sk = new Fr(8923n);
const partialAddress = new Fr(243523n);

const { address: accountAddress } = await keyStore.addAccount(sk, partialAddress);
expect(accountAddress.toString()).toMatchInlineSnapshot(
`"0x1a8a9a1d91cbb353d8df4f1bbfd0283f7fc63766f671edd9443a1270a7b2a954"`,
);
expect(accountAddress.toString()).toMatchSnapshot();

// Arbitrary fixed values
const newMasterSecretKeys = [new Fq(420n), new Fq(69n), new Fq(42069n)];
Expand Down Expand Up @@ -146,23 +144,17 @@ describe('KeyStore', () => {
newComputedMasterPublicKeyHashes[0],
appAddress,
);
expect(appSecretKey0.toString()).toMatchInlineSnapshot(
`"0x296e42f1039b62290372d608fcab55b00a3f96c1c8aa347b2a830639c5a12757"`,
);
expect(appSecretKey0.toString()).toMatchSnapshot();
const { skApp: appSecretKey1 } = await keyStore.getKeyValidationRequest(
newComputedMasterPublicKeyHashes[1],
appAddress,
);
expect(appSecretKey1.toString()).toMatchInlineSnapshot(
`"0x019f2a705b68683f1d86da639a543411fa779af41896c3920d0c2d5226c686dd"`,
);
expect(appSecretKey1.toString()).toMatchSnapshot();
const { skApp: appSecretKey2 } = await keyStore.getKeyValidationRequest(
newComputedMasterPublicKeyHashes[2],
appAddress,
);
expect(appSecretKey2.toString()).toMatchInlineSnapshot(
`"0x117445c8819c06b9a0889e5cce1f550e32ec6993c23f57bc9fc5cda05df520ae"`,
);
expect(appSecretKey2.toString()).toMatchSnapshot();

expect(appSecretKey0).toEqual(computeAppSecretKey(newMasterSecretKeys[0], appAddress, keyPrefix));
expect(appSecretKey1).toEqual(computeAppSecretKey(newMasterSecretKeys[1], appAddress, keyPrefix));
Expand Down

0 comments on commit 58df708

Please sign in to comment.