From f18e38aac5ad358c294978cfad0b6bb555032268 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 18 Dec 2024 18:52:03 +0000 Subject: [PATCH] WIP --- docs/docs/migration_notes.md | 8 +++++-- .../aztec.js/src/wallet/base_wallet.ts | 8 +++---- .../circuit-types/src/interfaces/pxe.test.ts | 12 +++++----- .../circuit-types/src/interfaces/pxe.ts | 14 ++++++------ yarn-project/cli-wallet/src/cmds/index.ts | 12 +++++----- ...register_contact.ts => register_sender.ts} | 2 +- .../cli-wallet/src/storage/wallet_db.ts | 4 ++-- .../pxe/src/database/kv_pxe_database.ts | 6 ++--- yarn-project/pxe/src/database/pxe_database.ts | 12 +++++----- .../pxe/src/pxe_service/pxe_service.ts | 22 +++++++++---------- .../pxe/src/simulator_oracle/index.ts | 15 +++++++------ .../simulator_oracle/simulator_oracle.test.ts | 2 +- 12 files changed, 61 insertions(+), 56 deletions(-) rename yarn-project/cli-wallet/src/cmds/{register_contact.ts => register_sender.ts} (87%) diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index 52f7122d806..2d6c9e256f6 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -8,13 +8,17 @@ Aztec is in full-speed development. Literally every version breaks compatibility ## TBD -### PXE.registerContact --> PXE.registerSender -`registerContact` has been deemed confusing because the name is too similar to `registerContract`. +### 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 diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index ff59ba0cee3..2ede1886e86 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -89,11 +89,11 @@ export abstract class BaseWallet implements Wallet { 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 562601f082a..81f262f9317 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.test.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.test.ts @@ -123,13 +123,13 @@ describe('PXESchema', () => { 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 () => { @@ -347,10 +347,10 @@ class MockPXE implements PXE { 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 42dfcd2b99f..32cddd41fb5 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -126,15 +126,15 @@ export interface PXE { 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,8 +467,8 @@ export const PXESchema: ApiSchemaFor = { .args(schemas.AztecAddress) .returns(z.union([CompleteAddress.schema, z.undefined()])), registerSender: 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()), + 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 e8ded3a0c28..14fe32668c1 100644 --- a/yarn-project/cli-wallet/src/cmds/index.ts +++ b/yarn-project/cli-wallet/src/cmds/index.ts @@ -617,18 +617,18 @@ 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 { registerSender } = 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); @@ -637,7 +637,7 @@ export function injectCommands( 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_sender.ts similarity index 87% rename from yarn-project/cli-wallet/src/cmds/register_contact.ts rename to yarn-project/cli-wallet/src/cmds/register_sender.ts index 91247257df8..0d84f637c49 100644 --- a/yarn-project/cli-wallet/src/cmds/register_contact.ts +++ b/yarn-project/cli-wallet/src/cmds/register_sender.ts @@ -3,5 +3,5 @@ import { type LogFn } from '@aztec/foundation/log'; export async function registerSender(wallet: AccountWalletWithSecretKey, address: AztecAddress, log: LogFn) { await wallet.registerSender(address); - log(`Contact registered: ${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/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 0160a8cff62..9dbcff61604 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -167,34 +167,34 @@ export class PXEService implements PXE { 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(); });