diff --git a/docs/docs/aztec/concepts/accounts/keys.md b/docs/docs/aztec/concepts/accounts/keys.md index 30f2e8610e1..602cea39f78 100644 --- a/docs/docs/aztec/concepts/accounts/keys.md +++ b/docs/docs/aztec/concepts/accounts/keys.md @@ -27,22 +27,13 @@ Instead it's up to the account contract developer to implement it. ## Public keys retrieval -The keys can be retrieved from the [Private eXecution Environment (PXE)](../pxe/index.md) using the following getter in Aztec.nr: +The keys for our accounts can be retrieved from the [Private eXecution Environment (PXE)](../pxe/index.md) using the following getter in Aztec.nr: ``` fn get_public_keys(account: AztecAddress) -> PublicKeys; ``` -It is necessary to first register the user as a recipient in our PXE, providing their public keys. - -First we need to get a hold of recipient's [complete address](#complete-address). -Below are some ways how we could instantiate it after getting the information in a string form from a recipient: - -#include_code instantiate-complete-address /yarn-project/circuits.js/src/structs/complete_address.test.ts rust - -Then to register the recipient's [complete address](#complete-address) in PXE we would call `registerRecipient` PXE endpoint using Aztec.js. - -#include_code register-recipient /yarn-project/aztec.js/src/wallet/create_recipient.ts rust +It is necessary to first register the user as an account in our PXE, by calling the `registerAccount` PXE endpoint using Aztec.js, providing the account's secret key and partial address. During private function execution these keys are obtained via an oracle call from PXE. diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/how_to_emit_event.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/how_to_emit_event.md index 0c0c7fc9d33..47440c4fd1c 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/how_to_emit_event.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/how_to_emit_event.md @@ -16,24 +16,6 @@ Unlike on Ethereum, there are 2 types of events supported by Aztec: [encrypted]( ## Encrypted Events -### Register a recipient - -Encrypted events can only be emitted by private functions and are encrypted using a public key of a recipient. -For this reason it is necessary to register a recipient in the Private Execution Environment (PXE) before encrypting the events for them. - -First we need to get a hold of recipient's complete address. -Below are some ways how we could instantiate it after getting the information in a string form from a recipient: - -#include_code instantiate-complete-address /yarn-project/circuits.js/src/structs/complete_address.test.ts rust - -Then to register the recipient's complete address in PXE we would call `registerRecipient` PXE endpoint using Aztec.js - -#include_code register-recipient /yarn-project/aztec.js/src/wallet/create_recipient.ts rust - -:::info -If a note recipient is one of the accounts inside the PXE, we don't need to register it as a recipient because we already have the public key available. You can register a recipient as shown [here](../how_to_deploy_contract.md) -::: - ### Call emit To emit encrypted logs you can import the `encode_and_encrypt` or `encode_and_encrypt_with_keys` functions and pass them into the `emit` function after inserting a note. An example can be seen in the reference token contract's transfer function: diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 2ec4fe257b8..2e1a43da978 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -81,21 +81,12 @@ export abstract class BaseWallet implements Wallet { registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise { return this.pxe.registerAccount(secretKey, partialAddress); } - registerRecipient(account: CompleteAddress): Promise { - return this.pxe.registerRecipient(account); - } getRegisteredAccounts(): Promise { return this.pxe.getRegisteredAccounts(); } getRegisteredAccount(address: AztecAddress): Promise { return this.pxe.getRegisteredAccount(address); } - getRecipients(): Promise { - return this.pxe.getRecipients(); - } - getRecipient(address: AztecAddress): Promise { - return this.pxe.getRecipient(address); - } registerContract(contract: { /** Instance */ instance: ContractInstanceWithAddress; /** Associated artifact */ artifact?: ContractArtifact; 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 { - 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 9b8da020962..f380cfec734 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -73,20 +73,6 @@ export interface PXE { */ registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise; - /** - * 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; - /** * Retrieves the user accounts registered on this PXE Service. * @returns An array of the accounts registered on this PXE Service. @@ -102,21 +88,6 @@ export interface PXE { */ getRegisteredAccount(address: AztecAddress): Promise; - /** - * Retrieves the recipients added to this PXE Service. - * @returns An array of recipients registered on this PXE Service. - */ - getRecipients(): Promise; - - /** - * Retrieves the complete address of the recipient corresponding to the provided aztec address. - * Complete addresses include the address, the partial address, and the encryption public key. - * - * @param address - The aztec address of the recipient. - * @returns The complete address of the requested recipient. - */ - getRecipient(address: AztecAddress): Promise; - /** * Registers a contract class in the PXE without registering any associated contract instance with it. * diff --git a/yarn-project/circuits.js/src/structs/complete_address.test.ts b/yarn-project/circuits.js/src/structs/complete_address.test.ts index d531e2e344a..a68d00e5c01 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.test.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.test.ts @@ -35,13 +35,10 @@ describe('CompleteAddress', () => { }); it('instantiates from string and individual components', () => { - // docs:start:instantiate-complete-address - // Typically a recipient would share their complete address with the sender const completeAddressFromString = CompleteAddress.fromString( '0x24e4646f58b9fbe7d38e317db8d5636c423fbbdfbe119fc190fe9c64747e0c6222f7fcddfa3ce3e8f0cc8e82d7b94cdd740afa3e77f8e4a63ea78a239432dcab0471657de2b6216ade6c506d28fbc22ba8b8ed95c871ad9f3e3984e90d9723a7111223493147f6785514b1c195bb37a2589f22a6596d30bb2bb145fdc9ca8f1e273bbffd678edce8fe30e0deafc4f66d58357c06fd4a820285294b9746c3be9509115c96e962322ffed6522f57194627136b8d03ac7469109707f5e44190c4840c49773308a13d740a7f0d4f0e6163b02c5a408b6f965856b6a491002d073d5b00d3d81beb009873eb7116327cf47c612d5758ef083d4fda78e9b63980b2a7622f567d22d2b02fe1f4ad42db9d58a36afd1983e7e2909d1cab61cafedad6193a0a7c585381b10f4666044266a02405bf6e01fa564c8517d4ad5823493abd31de', ); - // Alternatively, a recipient could share the individual components with the sender const address = Fr.fromString('0x24e4646f58b9fbe7d38e317db8d5636c423fbbdfbe119fc190fe9c64747e0c62'); const npkM = Point.fromString( '0x22f7fcddfa3ce3e8f0cc8e82d7b94cdd740afa3e77f8e4a63ea78a239432dcab0471657de2b6216ade6c506d28fbc22ba8b8ed95c871ad9f3e3984e90d9723a7', @@ -63,7 +60,6 @@ describe('CompleteAddress', () => { new PublicKeys(npkM, ivpkM, ovpkM, tpkM), partialAddress, ); - // docs:end:instantiate-complete-address expect(completeAddressFromComponents.equals(completeAddressFromString)).toBe(true); }); diff --git a/yarn-project/cli/src/cmds/pxe/get_recipient.ts b/yarn-project/cli/src/cmds/pxe/get_recipient.ts deleted file mode 100644 index 172ce3e1929..00000000000 --- a/yarn-project/cli/src/cmds/pxe/get_recipient.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { type AztecAddress } from '@aztec/aztec.js'; -import { createCompatibleClient } from '@aztec/aztec.js'; -import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; - -export async function getRecipient(aztecAddress: AztecAddress, rpcUrl: string, debugLogger: DebugLogger, log: LogFn) { - const client = await createCompatibleClient(rpcUrl, debugLogger); - const recipient = await client.getRecipient(aztecAddress); - - if (!recipient) { - log(`Unknown recipient ${aztecAddress.toString()}`); - } else { - log(recipient.toReadableString()); - } -} diff --git a/yarn-project/cli/src/cmds/pxe/get_recipients.ts b/yarn-project/cli/src/cmds/pxe/get_recipients.ts deleted file mode 100644 index 78109911e27..00000000000 --- a/yarn-project/cli/src/cmds/pxe/get_recipients.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createCompatibleClient } from '@aztec/aztec.js'; -import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; - -export async function getRecipients(rpcUrl: string, debugLogger: DebugLogger, log: LogFn) { - const client = await createCompatibleClient(rpcUrl, debugLogger); - const recipients = await client.getRecipients(); - if (!recipients.length) { - log('No recipients found.'); - } else { - log(`Recipients found: \n`); - for (const recipient of recipients) { - log(recipient.toReadableString()); - } - } -} diff --git a/yarn-project/cli/src/cmds/pxe/index.ts b/yarn-project/cli/src/cmds/pxe/index.ts index 4502505c9fe..bc3e4969a88 100644 --- a/yarn-project/cli/src/cmds/pxe/index.ts +++ b/yarn-project/cli/src/cmds/pxe/index.ts @@ -13,7 +13,6 @@ import { parseOptionalInteger, parseOptionalLogId, parseOptionalTxHash, - parsePartialAddress, parsePublicKey, pxeOption, } from '../../utils/commands.js'; @@ -91,22 +90,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 ', "The account's Aztec address.", parseAztecAddress) - .requiredOption('-p, --public-key ', 'The account public key.', parsePublicKey) - .requiredOption( - '-pa, --partial-address ', - '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.') @@ -127,25 +110,6 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL await getAccount(address, options.rpcUrl, debugLogger, log); }); - program - .command('get-recipients') - .description('Gets all the recipients stored in the PXE.') - .addOption(pxeOption) - .action(async (options: any) => { - const { getRecipients } = await import('./get_recipients.js'); - await getRecipients(options.rpcUrl, debugLogger, log); - }); - - program - .command('get-recipient') - .description('Gets a recipient given its Aztec address.') - .argument('
', 'The Aztec address to get recipient for', parseAztecAddress) - .addOption(pxeOption) - .action(async (address, options) => { - const { getRecipient } = await import('./get_recipient.js'); - await getRecipient(address, options.rpcUrl, debugLogger, log); - }); - program .command('block-number') .description('Gets the current Aztec L2 block number.') 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/end-to-end/src/composed/e2e_persistence.test.ts b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts index fabf8f8bae6..fbe36b3effc 100644 --- a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts +++ b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts @@ -200,10 +200,6 @@ describe('Aztec persistence', () => { await context.teardown(); }); - it('pxe does not have the owner account', async () => { - await expect(context.pxe.getRecipient(ownerAddress.address)).resolves.toBeUndefined(); - }); - it('the node has the contract', async () => { await expect(context.aztecNode.getContract(contractAddress)).resolves.toBeDefined(); }); diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index b32cbac2846..4504c8d4503 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -221,33 +221,6 @@ export class PXEService implements PXE { return Promise.resolve(account); } - public async registerRecipient(recipient: CompleteAddress): Promise { - 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 { - // 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 { - const result = await this.getRecipients(); - const recipient = result.find(r => r.address.equals(address)); - return Promise.resolve(recipient); - } - public async registerContractClass(artifact: ContractArtifact): Promise { 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..7a3161ab229 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 @@ -4,15 +4,7 @@ import { randomContractInstanceWithAddress, randomDeployedContract, } from '@aztec/circuit-types'; -import { - AztecAddress, - CompleteAddress, - Fr, - INITIAL_L2_BLOCK_NUM, - Point, - PublicKeys, - getContractClassFromArtifact, -} from '@aztec/circuits.js'; +import { AztecAddress, Fr, INITIAL_L2_BLOCK_NUM, getContractClassFromArtifact } from '@aztec/circuits.js'; export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => { describe(testName, () => { @@ -29,33 +21,11 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => // Check that the account is correctly registered using the getAccounts and getRecipients methods const accounts = await pxe.getRegisteredAccounts(); - const recipients = await pxe.getRecipients(); expect(accounts).toContainEqual(completeAddress); - expect(recipients).not.toContainEqual(completeAddress); // Check that the account 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).toEqual(completeAddress); - 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 () => { @@ -66,28 +36,6 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => 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;