From 79d6a4ed58a863e3d3eead8d84035c49da65c58a Mon Sep 17 00:00:00 2001
From: sklppy88 <esau@aztecprotocol.com>
Date: Tue, 29 Oct 2024 14:45:29 +0000
Subject: [PATCH] init

---
 .../aztec.js/src/wallet/base_wallet.ts        |  3 --
 .../aztec.js/src/wallet/create_recipient.ts   | 15 -------
 .../circuit-types/src/interfaces/pxe.ts       | 14 -------
 yarn-project/cli/src/cmds/pxe/index.ts        | 16 --------
 .../cli/src/cmds/pxe/register_recipient.ts    | 18 ---------
 .../pxe/src/pxe_service/pxe_service.ts        | 27 -------------
 .../src/pxe_service/test/pxe_test_suite.ts    | 40 -------------------
 .../pxe/src/simulator_oracle/index.ts         |  2 +-
 8 files changed, 1 insertion(+), 134 deletions(-)
 delete mode 100644 yarn-project/aztec.js/src/wallet/create_recipient.ts
 delete mode 100644 yarn-project/cli/src/cmds/pxe/register_recipient.ts

diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts
index e64396187a7..b0090d5fa96 100644
--- a/yarn-project/aztec.js/src/wallet/base_wallet.ts
+++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts
@@ -82,9 +82,6 @@ export abstract class BaseWallet implements Wallet {
   registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
     return this.pxe.registerAccount(secretKey, partialAddress);
   }
-  registerRecipient(account: CompleteAddress): Promise<void> {
-    return this.pxe.registerRecipient(account);
-  }
   getRegisteredAccounts(): Promise<CompleteAddress[]> {
     return this.pxe.getRegisteredAccounts();
   }
diff --git a/yarn-project/aztec.js/src/wallet/create_recipient.ts b/yarn-project/aztec.js/src/wallet/create_recipient.ts
deleted file mode 100644
index 1ec56fb6954..00000000000
--- a/yarn-project/aztec.js/src/wallet/create_recipient.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { type PXE } from '@aztec/circuit-types';
-import { CompleteAddress } from '@aztec/circuits.js';
-
-/**
- * Creates a random address and registers it as a recipient on the pxe server. Useful for testing.
- * @param pxe - PXE.
- * @returns Complete address of the registered recipient.
- */
-export async function createRecipient(pxe: PXE): Promise<CompleteAddress> {
-  const completeAddress = CompleteAddress.random();
-  // docs:start:register-recipient
-  await pxe.registerRecipient(completeAddress);
-  // docs:end:register-recipient
-  return completeAddress;
-}
diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts
index 26721aee915..dd28b7c032f 100644
--- a/yarn-project/circuit-types/src/interfaces/pxe.ts
+++ b/yarn-project/circuit-types/src/interfaces/pxe.ts
@@ -78,20 +78,6 @@ export interface PXE {
    */
   registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress>;
 
-  /**
-   * Registers a recipient in PXE. This is required when sending encrypted notes to
-   * a user who hasn't deployed their account contract yet. Since their account is not deployed, their
-   * encryption public key has not been broadcasted, so we need to manually register it on the PXE Service
-   * in order to be able to encrypt data for this recipient.
-   *
-   * @param recipient - The complete address of the recipient
-   * @remarks Called recipient because we can only send notes to this account and not receive them via this PXE Service.
-   * This is because we don't have the associated private key and for this reason we can't decrypt
-   * the recipient's notes. We can send notes to this account because we can encrypt them with the recipient's
-   * public key.
-   */
-  registerRecipient(recipient: CompleteAddress): Promise<void>;
-
   /**
    * Retrieves the user accounts registered on this PXE Service.
    * @returns An array of the accounts registered on this PXE Service.
diff --git a/yarn-project/cli/src/cmds/pxe/index.ts b/yarn-project/cli/src/cmds/pxe/index.ts
index 4502505c9fe..6af4d0bbef4 100644
--- a/yarn-project/cli/src/cmds/pxe/index.ts
+++ b/yarn-project/cli/src/cmds/pxe/index.ts
@@ -91,22 +91,6 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
       await getLogs(txHash, fromBlock, toBlock, afterLog, contractAddress, rpcUrl, follow, debugLogger, log);
     });
 
-  program
-    .command('register-recipient')
-    .description('Register a recipient in the PXE.')
-    .requiredOption('-a, --address <aztecAddress>', "The account's Aztec address.", parseAztecAddress)
-    .requiredOption('-p, --public-key <publicKey>', 'The account public key.', parsePublicKey)
-    .requiredOption(
-      '-pa, --partial-address <partialAddress>',
-      'The partially computed address of the account contract.',
-      parsePartialAddress,
-    )
-    .addOption(pxeOption)
-    .action(async ({ address, publicKey, partialAddress, rpcUrl }) => {
-      const { registerRecipient } = await import('./register_recipient.js');
-      await registerRecipient(address, publicKey, partialAddress, rpcUrl, debugLogger, log);
-    });
-
   program
     .command('get-accounts')
     .description('Gets all the Aztec accounts stored in the PXE.')
diff --git a/yarn-project/cli/src/cmds/pxe/register_recipient.ts b/yarn-project/cli/src/cmds/pxe/register_recipient.ts
deleted file mode 100644
index d16987d3eed..00000000000
--- a/yarn-project/cli/src/cmds/pxe/register_recipient.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { type AztecAddress, type Fr } from '@aztec/aztec.js';
-import { createCompatibleClient } from '@aztec/aztec.js';
-import { CompleteAddress } from '@aztec/circuit-types';
-import { type PublicKeys } from '@aztec/circuits.js';
-import { type DebugLogger, type LogFn } from '@aztec/foundation/log';
-
-export async function registerRecipient(
-  aztecAddress: AztecAddress,
-  publicKeys: PublicKeys,
-  partialAddress: Fr,
-  rpcUrl: string,
-  debugLogger: DebugLogger,
-  log: LogFn,
-) {
-  const client = await createCompatibleClient(rpcUrl, debugLogger);
-  await client.registerRecipient(new CompleteAddress(aztecAddress, publicKeys, partialAddress));
-  log(`\nRegistered details for account with address: ${aztecAddress}\n`);
-}
diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts
index 31b82f878b3..a06217d6104 100644
--- a/yarn-project/pxe/src/pxe_service/pxe_service.ts
+++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts
@@ -220,33 +220,6 @@ export class PXEService implements PXE {
     return Promise.resolve(account);
   }
 
-  public async registerRecipient(recipient: CompleteAddress): Promise<void> {
-    const wasAdded = await this.db.addCompleteAddress(recipient);
-
-    if (wasAdded) {
-      this.log.info(`Added recipient:\n ${recipient.toReadableString()}`);
-    } else {
-      this.log.info(`Recipient:\n "${recipient.toReadableString()}"\n already registered.`);
-    }
-  }
-
-  public async getRecipients(): Promise<CompleteAddress[]> {
-    // Get complete addresses of both the recipients and the accounts
-    const completeAddresses = await this.db.getCompleteAddresses();
-    // Filter out the addresses corresponding to accounts
-    const accounts = await this.keyStore.getAccounts();
-    const recipients = completeAddresses.filter(
-      completeAddress => !accounts.find(account => account.equals(completeAddress.address)),
-    );
-    return recipients;
-  }
-
-  public async getRecipient(address: AztecAddress): Promise<CompleteAddress | undefined> {
-    const result = await this.getRecipients();
-    const recipient = result.find(r => r.address.equals(address));
-    return Promise.resolve(recipient);
-  }
-
   public async registerContractClass(artifact: ContractArtifact): Promise<void> {
     const contractClassId = computeContractClassId(getContractClassFromArtifact(artifact));
     await this.db.addContractArtifact(contractClassId, artifact);
diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts
index c54cc97e274..490b9d015ae 100644
--- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts
+++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts
@@ -40,24 +40,6 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
       expect(recipient).toBeUndefined();
     });
 
-    it('registers a recipient and returns it as a recipient only and not as an account', async () => {
-      const completeAddress = CompleteAddress.random();
-
-      await pxe.registerRecipient(completeAddress);
-
-      // Check that the recipient is correctly registered using the getAccounts and getRecipients methods
-      const accounts = await pxe.getRegisteredAccounts();
-      const recipients = await pxe.getRecipients();
-      expect(accounts).not.toContainEqual(completeAddress);
-      expect(recipients).toContainEqual(completeAddress);
-
-      // Check that the recipient is correctly registered using the getAccount and getRecipient methods
-      const account = await pxe.getRegisteredAccount(completeAddress.address);
-      const recipient = await pxe.getRecipient(completeAddress.address);
-      expect(account).toBeUndefined();
-      expect(recipient).toEqual(completeAddress);
-    });
-
     it('does not throw when registering the same account twice (just ignores the second attempt)', async () => {
       const randomSecretKey = Fr.random();
       const randomPartialAddress = Fr.random();
@@ -66,28 +48,6 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
       await pxe.registerAccount(randomSecretKey, randomPartialAddress);
     });
 
-    // Disabled as CompleteAddress constructor now performs preimage validation.
-    it.skip('cannot register a recipient with the same aztec address but different pub key or partial address', async () => {
-      const recipient1 = CompleteAddress.random();
-      const recipient2 = new CompleteAddress(
-        recipient1.address,
-        new PublicKeys(Point.random(), Point.random(), Point.random(), Point.random()),
-        Fr.random(),
-      );
-
-      await pxe.registerRecipient(recipient1);
-      await expect(() => pxe.registerRecipient(recipient2)).rejects.toThrow(
-        `Complete address with aztec address ${recipient1.address}`,
-      );
-    });
-
-    it('does not throw when registering the same recipient twice (just ignores the second attempt)', async () => {
-      const completeAddress = CompleteAddress.random();
-
-      await pxe.registerRecipient(completeAddress);
-      await pxe.registerRecipient(completeAddress);
-    });
-
     it('successfully adds a contract', async () => {
       const contracts = [randomDeployedContract(), randomDeployedContract()];
       for (const contract of contracts) {
diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts
index 50570db1ae5..4295bc1e555 100644
--- a/yarn-project/pxe/src/simulator_oracle/index.ts
+++ b/yarn-project/pxe/src/simulator_oracle/index.ts
@@ -49,7 +49,7 @@ export class SimulatorOracle implements DBOracle {
     if (!completeAddress) {
       throw new Error(
         `No public key registered for address ${account}.
-        Register it by calling pxe.registerRecipient(...) or pxe.registerAccount(...).\nSee docs for context: https://docs.aztec.network/reference/common_errors/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
+        Register it by calling pxe.registerAccount(...).\nSee docs for context: https://docs.aztec.network/reference/common_errors/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
       );
     }
     return completeAddress;