From 8cb26e929b9b9dc6822a56cc9b951d68547e20f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Thu, 19 Dec 2024 12:37:20 -0600 Subject: [PATCH] refactor: `contact` --> `sender` in PXE API (#10861) --- docs/docs/migration_notes.md | 15 +++++++++++- .../aztec.js/src/wallet/base_wallet.ts | 12 +++++----- .../circuit-types/src/interfaces/pxe.test.ts | 18 +++++++------- .../circuit-types/src/interfaces/pxe.ts | 18 +++++++------- yarn-project/cli-wallet/src/cmds/index.ts | 14 +++++------ .../cli-wallet/src/cmds/register_contact.ts | 7 ------ .../cli-wallet/src/cmds/register_sender.ts | 7 ++++++ .../cli-wallet/src/storage/wallet_db.ts | 4 ++-- .../end-to-end/src/e2e_2_pxes.test.ts | 8 +++---- .../src/e2e_crowdfunding_and_claim.test.ts | 2 +- .../pxe/src/database/kv_pxe_database.ts | 6 ++--- yarn-project/pxe/src/database/pxe_database.ts | 12 +++++----- .../pxe/src/pxe_service/pxe_service.ts | 24 +++++++++---------- .../pxe/src/simulator_oracle/index.ts | 15 ++++++------ .../simulator_oracle/simulator_oracle.test.ts | 2 +- 15 files changed, 89 insertions(+), 75 deletions(-) delete mode 100644 yarn-project/cli-wallet/src/cmds/register_contact.ts create mode 100644 yarn-project/cli-wallet/src/cmds/register_sender.ts diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index 7232ee8cb1e..2181a6c6785 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -6,7 +6,7 @@ keywords: [sandbox, aztec, notes, migration, updating, upgrading] Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. ## 0.68.0 -### [archiver, node, pxe] Remove contract artifacts in node and archiver and store function names instead +### [archiver, node, pxe] Remove contract artifacts in node and archiver and store function names instead Contract artifacts were only in the archiver for debugging purposes. Instead function names are now (optionally) emitted when registering contract classes @@ -54,6 +54,19 @@ Also created a public function `pull_funds()` for admin to clawback any money in Expect more changes in FPC in the coming releases! +### Name change from `contact` to `sender` in PXE API +`contact` has been deemed confusing because the name is too similar to `contract`. +For this reason we've decided to rename it: + +```diff +- await pxe.registerContact(address); ++ await pxe.registerSender(address); +- await pxe.getContacts(); ++ await pxe.getSenders(); +- await pxe.removeContact(address); ++ await pxe.removeSender(address); +``` + ## 0.67.1 ### Noir contracts package no longer exposes artifacts as default export diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index e279c66e05f..bd1e5fd6e59 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -86,14 +86,14 @@ export abstract class BaseWallet implements Wallet { getRegisteredAccount(address: AztecAddress): Promise { return this.pxe.getRegisteredAccount(address); } - registerContact(address: AztecAddress): Promise { - return this.pxe.registerContact(address); + registerSender(address: AztecAddress): Promise { + return this.pxe.registerSender(address); } - getContacts(): Promise { - return this.pxe.getContacts(); + getSenders(): Promise { + return this.pxe.getSenders(); } - async removeContact(address: AztecAddress): Promise { - await this.pxe.removeContact(address); + async removeSender(address: AztecAddress): Promise { + await this.pxe.removeSender(address); } registerContract(contract: { /** Instance */ instance: ContractInstanceWithAddress; diff --git a/yarn-project/circuit-types/src/interfaces/pxe.test.ts b/yarn-project/circuit-types/src/interfaces/pxe.test.ts index 902e5d538b5..35ca91421a2 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.test.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.test.ts @@ -118,18 +118,18 @@ describe('PXESchema', () => { expect(result).toBeInstanceOf(CompleteAddress); }); - it('registerContact', async () => { - const result = await context.client.registerContact(address); + it('registerSender', async () => { + const result = await context.client.registerSender(address); expect(result).toEqual(address); }); - it('getContacts', async () => { - const result = await context.client.getContacts(); + it('getSenders', async () => { + const result = await context.client.getSenders(); expect(result).toEqual([address]); }); - it('removeContact', async () => { - await context.client.removeContact(address); + it('removeSender', async () => { + await context.client.removeSender(address); }); it('registerContractClass', async () => { @@ -344,14 +344,14 @@ class MockPXE implements PXE { expect(address).toBeInstanceOf(AztecAddress); return Promise.resolve(CompleteAddress.random()); } - registerContact(address: AztecAddress): Promise { + registerSender(address: AztecAddress): Promise { expect(address).toBeInstanceOf(AztecAddress); return Promise.resolve(this.address); } - getContacts(): Promise { + getSenders(): Promise { return Promise.resolve([this.address]); } - removeContact(address: AztecAddress): Promise { + removeSender(address: AztecAddress): Promise { expect(address).toBeInstanceOf(AztecAddress); return Promise.resolve(); } diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index b47fb693449..7aaa954f7df 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -123,18 +123,18 @@ export interface PXE { * @param address - Address of the user to add to the address book * @returns The address address of the account. */ - registerContact(address: AztecAddress): Promise; + registerSender(address: AztecAddress): Promise; /** - * Retrieves the addresses stored as contacts on this PXE Service. - * @returns An array of the contacts on this PXE Service. + * Retrieves the addresses stored as senders on this PXE Service. + * @returns An array of the senders on this PXE Service. */ - getContacts(): Promise; + getSenders(): Promise; /** - * Removes a contact in the address book. + * Removes a sender in the address book. */ - removeContact(address: AztecAddress): Promise; + removeSender(address: AztecAddress): Promise; /** * Registers a contract class in the PXE without registering any associated contract instance with it. @@ -467,9 +467,9 @@ export const PXESchema: ApiSchemaFor = { .function() .args(schemas.AztecAddress) .returns(z.union([CompleteAddress.schema, z.undefined()])), - registerContact: z.function().args(schemas.AztecAddress).returns(schemas.AztecAddress), - getContacts: z.function().returns(z.array(schemas.AztecAddress)), - removeContact: z.function().args(schemas.AztecAddress).returns(z.void()), + registerSender: z.function().args(schemas.AztecAddress).returns(schemas.AztecAddress), + getSenders: z.function().returns(z.array(schemas.AztecAddress)), + removeSender: z.function().args(schemas.AztecAddress).returns(z.void()), registerContractClass: z.function().args(ContractArtifactSchema).returns(z.void()), registerContract: z .function() diff --git a/yarn-project/cli-wallet/src/cmds/index.ts b/yarn-project/cli-wallet/src/cmds/index.ts index 1915e080af7..14fe32668c1 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -617,27 +617,27 @@ export function injectCommands( }); program - .command('register-contact') + .command('register-sender') .description( - "Registers a contact's address in the wallet, so the note synching process will look for notes sent by them", + "Registers a sender's address in the wallet, so the note synching process will look for notes sent by them", ) - .argument('[address]', 'The address of the contact to register', address => + .argument('[address]', 'The address of the sender to register', address => aliasedAddressParser('accounts', address, db), ) .addOption(pxeOption) .addOption(createAccountOption('Alias or address of the account to simulate from', !db, db)) - .addOption(createAliasOption('Alias for the contact. Used for easy reference in subsequent commands.', !db)) + .addOption(createAliasOption('Alias for the sender. Used for easy reference in subsequent commands.', !db)) .action(async (address, options) => { - const { registerContact } = await import('./register_contact.js'); + const { registerSender } = await import('./register_sender.js'); const { from: parsedFromAddress, rpcUrl, secretKey, alias } = options; const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger)); const account = await createOrRetrieveAccount(client, parsedFromAddress, db, secretKey); const wallet = await getWalletWithScopes(account, db); - await registerContact(wallet, address, log); + await registerSender(wallet, address, log); if (db && alias) { - await db.storeContact(address, alias, log); + await db.storeSender(address, alias, log); } }); diff --git a/yarn-project/cli-wallet/src/cmds/register_contact.ts b/yarn-project/cli-wallet/src/cmds/register_contact.ts deleted file mode 100644 index 8a3c9ea9d6f..00000000000 --- a/yarn-project/cli-wallet/src/cmds/register_contact.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { type AccountWalletWithSecretKey, type AztecAddress } from '@aztec/aztec.js'; -import { type LogFn } from '@aztec/foundation/log'; - -export async function registerContact(wallet: AccountWalletWithSecretKey, address: AztecAddress, log: LogFn) { - await wallet.registerContact(address); - log(`Contact registered: ${address}`); -} diff --git a/yarn-project/cli-wallet/src/cmds/register_sender.ts b/yarn-project/cli-wallet/src/cmds/register_sender.ts new file mode 100644 index 00000000000..0d84f637c49 --- /dev/null +++ b/yarn-project/cli-wallet/src/cmds/register_sender.ts @@ -0,0 +1,7 @@ +import { type AccountWalletWithSecretKey, type AztecAddress } from '@aztec/aztec.js'; +import { type LogFn } from '@aztec/foundation/log'; + +export async function registerSender(wallet: AccountWalletWithSecretKey, address: AztecAddress, log: LogFn) { + await wallet.registerSender(address); + log(`Sender registered: ${address}`); +} diff --git a/yarn-project/cli-wallet/src/storage/wallet_db.ts b/yarn-project/cli-wallet/src/storage/wallet_db.ts index 3bef8ed0153..1c491ae17cb 100644 --- a/yarn-project/cli-wallet/src/storage/wallet_db.ts +++ b/yarn-project/cli-wallet/src/storage/wallet_db.ts @@ -82,9 +82,9 @@ export class WalletDB { log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`); } - async storeContact(address: AztecAddress, alias: string, log: LogFn) { + async storeSender(address: AztecAddress, alias: string, log: LogFn) { await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString())); - log(`Account stored in database with alias ${alias} as a contact`); + log(`Account stored in database with alias ${alias} as a sender`); } async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) { diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index d52f3494ecd..c5f7b3134d9 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -49,8 +49,8 @@ describe('e2e_2_pxes', () => { What is a more robust solution? */ await sleep(5000); - await walletA.registerContact(walletB.getAddress()); - await walletB.registerContact(walletA.getAddress()); + await walletA.registerSender(walletB.getAddress()); + await walletB.registerSender(walletA.getAddress()); }); afterEach(async () => { @@ -182,13 +182,13 @@ describe('e2e_2_pxes', () => { const sharedAccountAddress = sharedAccountOnA.getCompleteAddress(); const sharedWalletOnA = await sharedAccountOnA.waitSetup(); - await sharedWalletOnA.registerContact(walletA.getAddress()); + await sharedWalletOnA.registerSender(walletA.getAddress()); const sharedAccountOnB = getUnsafeSchnorrAccount(pxeB, sharedSecretKey, sharedAccountOnA.salt); await sharedAccountOnB.register(); const sharedWalletOnB = await sharedAccountOnB.getWallet(); - await sharedWalletOnB.registerContact(sharedWalletOnA.getAddress()); + await sharedWalletOnB.registerSender(sharedWalletOnA.getAddress()); // deploy the contract on PXE A const token = await deployToken(walletA, initialBalance, logger); diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 0ac2e55f332..8918c3eb74a 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -116,7 +116,7 @@ describe('e2e_crowdfunding_and_claim', () => { // as a contact to all donor wallets, so they can receive notes await Promise.all( donorWallets.map(async wallet => { - await wallet.registerContact(operatorWallet.getAddress()); + await wallet.registerSender(operatorWallet.getAddress()); }), ); // Now we mint DNT to donors diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index 7ff1f19062b..ebf1c07991c 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -538,7 +538,7 @@ export class KVPxeDatabase implements PxeDatabase { return (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)); } - async addContactAddress(address: AztecAddress): Promise { + async addSenderAddress(address: AztecAddress): Promise { if (await this.#addressBook.hasAsync(address.toString())) { return false; } @@ -548,11 +548,11 @@ export class KVPxeDatabase implements PxeDatabase { return true; } - async getContactAddresses(): Promise { + async getSenderAddresses(): Promise { return (await toArray(this.#addressBook.entriesAsync())).map(AztecAddress.fromString); } - async removeContactAddress(address: AztecAddress): Promise { + async removeSenderAddress(address: AztecAddress): Promise { if (!this.#addressBook.hasAsync(address.toString())) { return false; } diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 4f2fd1557f2..6926b2c02af 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -119,24 +119,24 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD setHeader(header: BlockHeader): Promise; /** - * Adds contact address to the database. + * Adds sender address to the database. * @param address - The address to add to the address book. * @returns A promise resolving to true if the address was added, false if it already exists. */ - addContactAddress(address: AztecAddress): Promise; + addSenderAddress(address: AztecAddress): Promise; /** - * Retrieves the list of contact addresses in the address book. + * Retrieves the list of sender addresses in the address book. * @returns An array of Aztec addresses. */ - getContactAddresses(): Promise; + getSenderAddresses(): Promise; /** - * Removes a contact address from the database. + * Removes a sender address from the database. * @param address - The address to remove from the address book. * @returns A promise resolving to true if the address was removed, false if it does not exist. */ - removeContactAddress(address: AztecAddress): Promise; + removeSenderAddress(address: AztecAddress): Promise; /** * Adds complete address to the database. diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 3a0e982c10d..02375e72ff5 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -164,37 +164,37 @@ export class PXEService implements PXE { return accountCompleteAddress; } - public async registerContact(address: AztecAddress): Promise { + public async registerSender(address: AztecAddress): Promise { const accounts = await this.keyStore.getAccounts(); if (accounts.includes(address)) { - this.log.info(`Account:\n "${address.toString()}"\n already registered.`); + this.log.info(`Sender:\n "${address.toString()}"\n already registered.`); return address; } - const wasAdded = await this.db.addContactAddress(address); + const wasAdded = await this.db.addSenderAddress(address); if (wasAdded) { - this.log.info(`Added contact:\n ${address.toString()}`); + this.log.info(`Added sender:\n ${address.toString()}`); } else { - this.log.info(`Contact:\n "${address.toString()}"\n already registered.`); + this.log.info(`Sender:\n "${address.toString()}"\n already registered.`); } return address; } - public getContacts(): Promise { - const contacts = this.db.getContactAddresses(); + public getSenders(): Promise { + const senders = this.db.getSenderAddresses(); - return Promise.resolve(contacts); + return Promise.resolve(senders); } - public async removeContact(address: AztecAddress): Promise { - const wasRemoved = await this.db.removeContactAddress(address); + public async removeSender(address: AztecAddress): Promise { + const wasRemoved = await this.db.removeSenderAddress(address); if (wasRemoved) { - this.log.info(`Removed contact:\n ${address.toString()}`); + this.log.info(`Removed sender:\n ${address.toString()}`); } else { - this.log.info(`Contact:\n "${address.toString()}"\n not in address book.`); + this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`); } return Promise.resolve(); diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index bb3885695a4..f19f840a343 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -253,8 +253,8 @@ export class SimulatorOracle implements DBOracle { * finally the index specified tag. We will then query the node with this tag for each address in the address book. * @returns The full list of the users contact addresses. */ - public getContacts(): Promise { - return this.db.getContactAddresses(); + public getSenders(): Promise { + return this.db.getSenderAddresses(); } /** @@ -321,18 +321,19 @@ export class SimulatorOracle implements DBOracle { * @param recipient - The address receiving the notes * @returns A list of indexed tagging secrets */ - async #getIndexedTaggingSecretsForContacts( + async #getIndexedTaggingSecretsForSenders( contractAddress: AztecAddress, recipient: AztecAddress, ): Promise { const recipientCompleteAddress = await this.getCompleteAddress(recipient); const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient); - // We implicitly add all PXE accounts as contacts, this helps us decrypt tags on notes that we send to ourselves (recipient = us, sender = us) - const contacts = [...(await this.db.getContactAddresses()), ...(await this.keyStore.getAccounts())].filter( + // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves + // (recipient = us, sender = us) + const senders = [...(await this.db.getSenderAddresses()), ...(await this.keyStore.getAccounts())].filter( (address, index, self) => index === self.findIndex(otherAddress => otherAddress.equals(address)), ); - const appTaggingSecrets = contacts.map(contact => { + const appTaggingSecrets = senders.map(contact => { const sharedSecret = computeTaggingSecretPoint(recipientCompleteAddress, recipientIvsk, contact); return poseidon2Hash([sharedSecret.x, sharedSecret.y, contractAddress]); }); @@ -434,7 +435,7 @@ export class SimulatorOracle implements DBOracle { const logsForRecipient: TxScopedL2Log[] = []; // Get all the secrets for the recipient and sender pairs (#9365) - const secrets = await this.#getIndexedTaggingSecretsForContacts(contractAddress, recipient); + const secrets = await this.#getIndexedTaggingSecretsForSenders(contractAddress, recipient); // We fetch logs for a window of indexes in a range: // . diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index 0db352f96a6..e7007268753 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -226,7 +226,7 @@ describe('Simulator oracle', () => { return { completeAddress, ivsk: keys.masterIncomingViewingSecretKey, secretKey: new Fr(index) }; }); for (const sender of senders) { - await database.addContactAddress(sender.completeAddress.address); + await database.addSenderAddress(sender.completeAddress.address); } aztecNode.getLogsByTags.mockReset(); });