Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Dec 18, 2024
1 parent 68aab05 commit f18e38a
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 56 deletions.
8 changes: 6 additions & 2 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ export abstract class BaseWallet implements Wallet {
registerSender(address: AztecAddress): Promise<AztecAddress> {
return this.pxe.registerSender(address);
}
getContacts(): Promise<AztecAddress[]> {
return this.pxe.getContacts();
getSenders(): Promise<AztecAddress[]> {
return this.pxe.getSenders();
}
async removeContact(address: AztecAddress): Promise<void> {
await this.pxe.removeContact(address);
async removeSender(address: AztecAddress): Promise<void> {
await this.pxe.removeSender(address);
}
registerContract(contract: {
/** Instance */ instance: ContractInstanceWithAddress;
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -347,10 +347,10 @@ class MockPXE implements PXE {
expect(address).toBeInstanceOf(AztecAddress);
return Promise.resolve(this.address);
}
getContacts(): Promise<AztecAddress[]> {
getSenders(): Promise<AztecAddress[]> {
return Promise.resolve([this.address]);
}
removeContact(address: AztecAddress): Promise<void> {
removeSender(address: AztecAddress): Promise<void> {
expect(address).toBeInstanceOf(AztecAddress);
return Promise.resolve();
}
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export interface PXE {
registerSender(address: AztecAddress): Promise<AztecAddress>;

/**
* 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<AztecAddress[]>;
getSenders(): Promise<AztecAddress[]>;

/**
* Removes a contact in the address book.
* Removes a sender in the address book.
*/
removeContact(address: AztecAddress): Promise<void>;
removeSender(address: AztecAddress): Promise<void>;

/**
* Registers a contract class in the PXE without registering any associated contract instance with it.
Expand Down Expand Up @@ -467,8 +467,8 @@ export const PXESchema: ApiSchemaFor<PXE> = {
.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()
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/cli-wallet/src/cmds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
4 changes: 2 additions & 2 deletions yarn-project/cli-wallet/src/storage/wallet_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
async addSenderAddress(address: AztecAddress): Promise<boolean> {
if (await this.#addressBook.hasAsync(address.toString())) {
return false;
}
Expand All @@ -548,11 +548,11 @@ export class KVPxeDatabase implements PxeDatabase {
return true;
}

async getContactAddresses(): Promise<AztecAddress[]> {
async getSenderAddresses(): Promise<AztecAddress[]> {
return (await toArray(this.#addressBook.entriesAsync())).map(AztecAddress.fromString);
}

async removeContactAddress(address: AztecAddress): Promise<boolean> {
async removeSenderAddress(address: AztecAddress): Promise<boolean> {
if (!this.#addressBook.hasAsync(address.toString())) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/pxe/src/database/pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,24 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
setHeader(header: BlockHeader): Promise<void>;

/**
* 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<boolean>;
addSenderAddress(address: AztecAddress): Promise<boolean>;

/**
* 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<AztecAddress[]>;
getSenderAddresses(): Promise<AztecAddress[]>;

/**
* 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<boolean>;
removeSenderAddress(address: AztecAddress): Promise<boolean>;

/**
* Adds complete address to the database.
Expand Down
22 changes: 11 additions & 11 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,34 +167,34 @@ export class PXEService implements PXE {
public async registerSender(address: AztecAddress): Promise<AztecAddress> {
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<AztecAddress[]> {
const contacts = this.db.getContactAddresses();
public getSenders(): Promise<AztecAddress[]> {
const senders = this.db.getSenderAddresses();

return Promise.resolve(contacts);
return Promise.resolve(senders);
}

public async removeContact(address: AztecAddress): Promise<void> {
const wasRemoved = await this.db.removeContactAddress(address);
public async removeSender(address: AztecAddress): Promise<void> {
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();
Expand Down
15 changes: 8 additions & 7 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AztecAddress[]> {
return this.db.getContactAddresses();
public getSenders(): Promise<AztecAddress[]> {
return this.db.getSenderAddresses();
}

/**
Expand Down Expand Up @@ -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<IndexedTaggingSecret[]> {
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]);
});
Expand Down Expand Up @@ -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:
// <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit f18e38a

Please sign in to comment.