Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 29, 2024
1 parent 0425254 commit 79d6a4e
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 134 deletions.
3 changes: 0 additions & 3 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 0 additions & 15 deletions yarn-project/aztec.js/src/wallet/create_recipient.ts

This file was deleted.

14 changes: 0 additions & 14 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions yarn-project/cli/src/cmds/pxe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
18 changes: 0 additions & 18 deletions yarn-project/cli/src/cmds/pxe/register_recipient.ts

This file was deleted.

27 changes: 0 additions & 27 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 0 additions & 40 deletions yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 79d6a4e

Please sign in to comment.