How to Rotate Nullifier Keys
This guide explains how to rotate nullifer secret and public keys using Aztec.js. To learn more about key rotation, read the concepts section.
Prerequisites
You should have a wallet whose keys you want to rotate. You can learn how to create wallets from this guide.
You should also have a PXE initialized.
Relevant imports
You will need to import these from Aztec.js:
imports
import { type PublicKey, derivePublicKeyFromSecretKey } from '@aztec/circuits.js';
import { TestContract, TokenContract } from '@aztec/noir-contracts.js';
Source code: yarn-project/end-to-end/src/e2e_key_rotation.test.ts#L16-L20
Create nullifier secret and public key
newNskM
= new master nullifier secret key
newNpkM
= new master nullifier public key (type PublicKey
)
create_keys
const newNskM = Fq.random();
newNpkM = derivePublicKeyFromSecretKey(newNskM);
Source code: yarn-project/end-to-end/src/e2e_key_rotation.test.ts#L175-L178
Rotate nullifier secret and public key
Call rotateNullifierKeys
on the AccountWallet to rotate the secret key in the PXE and call the key registry with the new derived public key.
rotateNullifierKeys
// This function saves the new nullifier secret key for the account in our PXE,
// and calls the key registry with the derived nullifier public key.
await walletB.rotateNullifierKeys(newNskM);
Source code: yarn-project/end-to-end/src/e2e_key_rotation.test.ts#L180-L184