Skip to main content

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.


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:

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)

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.

// 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