Skip to content

Commit

Permalink
Add to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed May 17, 2024
1 parent 7853a03 commit c9e0a05
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
22 changes: 21 additions & 1 deletion yarn-project/aztec.js/src/account/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type AuthWitness, type CompleteAddress, type FunctionCall } from '@aztec/circuit-types';
import { type AztecAddress } from '@aztec/circuits.js';
import { type Fr } from '@aztec/foundation/fields';
import { type Fq, type Fr, type Point } from '@aztec/foundation/fields';

import { type ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import { type EntrypointInterface } from '../entrypoint/entrypoint.js';
Expand Down Expand Up @@ -51,4 +51,24 @@ export interface AccountInterface extends AuthWitnessProvider, EntrypointInterfa
/** Returns the rollup version for this account */
getVersion(): Fr;
}

/**
* Handler for interfacing with an account's ability to rotate its keys.
*/
export interface AccountKeyRotationInterface {
/**
* Returns a function interaction to rotate our master nullifer public key in the canonical key registry.
* @param newNpkM - The new master nullifier public key we want to use.
* @remarks - This does not hinder our ability to spend notes tied to a previous master nullifier public key.
* @returns - A function interaction.
*/
rotateNpkM(newNpkM: Point): ContractFunctionInteraction;

/**
* Rotates master nullifier keys.
* @param newNskM - The new master nullifier secret key we want to use.
* @remarks - This does not hinder our ability to spend notes tied to a previous master nullifier public key.
*/
rotateNskM(newNskM: Fq): Promise<void>;
}
// docs:end:account-interface
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/account/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type PXE } from '@aztec/circuit-types';

import { type AccountInterface } from './interface.js';
import { type AccountInterface, type AccountKeyRotationInterface } from './interface.js';

/**
* The wallet interface.
*/
export type Wallet = AccountInterface & PXE;
export type Wallet = AccountInterface & PXE & AccountKeyRotationInterface;
13 changes: 12 additions & 1 deletion yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ import {
type TxHash,
type TxReceipt,
} from '@aztec/circuit-types';
import { type AztecAddress, type CompleteAddress, type Fq, type Fr, type PartialAddress } from '@aztec/circuits.js';
import {
type AztecAddress,
type CompleteAddress,
type Fq,
type Fr,
type PartialAddress,
type Point,
} from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';
import { type ContractClassWithId, type ContractInstanceWithAddress } from '@aztec/types/contracts';
import { type NodeInfo } from '@aztec/types/interfaces';
Expand All @@ -38,6 +45,10 @@ export abstract class BaseWallet implements Wallet {

abstract createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;

abstract rotateNpkM(newNpkM: Point): ContractFunctionInteraction;

abstract rotateNskM(newNskM: Fq): Promise<void>;

abstract createAuthWit(
messageHashOrIntent:
| Fr
Expand Down
11 changes: 10 additions & 1 deletion yarn-project/aztec.js/src/wallet/signerless_wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type AuthWitness, type PXE, type TxExecutionRequest } from '@aztec/circuit-types';
import { type CompleteAddress, type Fr } from '@aztec/circuits.js';
import { type CompleteAddress, type Fq, type Fr, type Point } from '@aztec/circuits.js';

import { type ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js';
import { type EntrypointInterface, type ExecutionRequestInit } from '../entrypoint/entrypoint.js';
import { BaseWallet } from './base_wallet.js';
Expand Down Expand Up @@ -42,4 +43,12 @@ export class SignerlessWallet extends BaseWallet {
createAuthWit(_messageHash: Fr): Promise<AuthWitness> {
throw new Error('Method not implemented.');
}

rotateNpkM(_newNpkM: Point): ContractFunctionInteraction {
throw new Error('Method not implemented.');
}

rotateNskM(_newNskM: Fq): Promise<void> {
throw new Error('Method not implemented.');
}
}
5 changes: 2 additions & 3 deletions yarn-project/end-to-end/src/e2e_key_rotation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createAccounts } from '@aztec/accounts/testing';
import {
type AccountWallet,
type AztecAddress,
type AztecNode,
type DebugLogger,
Expand Down Expand Up @@ -31,8 +30,8 @@ describe('e2e_key_rotation', () => {
let aztecNode: AztecNode;
let pxeA: PXE;
let pxeB: PXE;
let walletA: AccountWallet;
let walletB: AccountWallet;
let walletA: Wallet;
let walletB: Wallet;
let logger: DebugLogger;
let teardownA: () => Promise<void>;
let teardownB: () => Promise<void>;
Expand Down

0 comments on commit c9e0a05

Please sign in to comment.