Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 3, 2024
1 parent 18c66c0 commit aa6aa1b
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ contract Test {
address: AztecAddress,
public_nullifying_key: GrumpkinPoint,
) {
assert_eq(get_npk_m(&mut context, address), poseidon2_hash(public_nullifying_key.serialize()));
assert_eq(get_npk_m(&mut context, address), public_nullifying_key);
}

#[aztec(public)]
Expand Down
21 changes: 18 additions & 3 deletions yarn-project/circuits.js/src/keys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type Fr, type GrumpkinScalar } from '@aztec/foundation/fields';
import { Grumpkin } from '../barretenberg/crypto/grumpkin/index.js';
import { GeneratorIndex } from '../constants.gen.js';
import { type GrumpkinPrivateKey } from '../types/grumpkin_private_key.js';
import { type PublicKey } from '../types/public_key.js';

export function computeAppNullifierSecretKey(masterNullifierSecretKey: GrumpkinPrivateKey, app: AztecAddress): Fr {
return poseidon2Hash([masterNullifierSecretKey.high, masterNullifierSecretKey.low, app, GeneratorIndex.NSK_M]);
Expand All @@ -23,6 +24,21 @@ export function deriveSigningKey(secretKey: Fr): GrumpkinScalar {
return sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]);
}

export function computePublicKeysHash(
masterNullifierPublicKey: PublicKey,
masterIncomingViewingPublicKey: PublicKey,
masterOutgoingViewingPublicKey: PublicKey,
masterTaggingPublicKey: PublicKey,
): Fr {
return poseidon2Hash([
masterNullifierPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey,
masterTaggingPublicKey,
GeneratorIndex.PUBLIC_KEYS_HASH,
]);
}

/**
* Computes secret and public keys and public keys hash from a secret key.
* @param secretKey - The secret key to derive keys from.
Expand All @@ -44,13 +60,12 @@ export function deriveKeys(secretKey: Fr) {
const masterTaggingPublicKey = curve.mul(curve.generator(), masterTaggingSecretKey);

// We hash the public keys to get the public keys hash
const publicKeysHash = poseidon2Hash([
const publicKeysHash = computePublicKeysHash(
masterNullifierPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey,
masterTaggingPublicKey,
GeneratorIndex.PUBLIC_KEYS_HASH,
]);
);

return {
masterNullifierSecretKey,
Expand Down
Loading

0 comments on commit aa6aa1b

Please sign in to comment.