diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 2a1f5235b4e..48e259aeca1 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -80,9 +80,6 @@ export abstract class BaseWallet implements Wallet { addNote(note: ExtendedNote): Promise { return this.pxe.addNote(note); } - getNoteNonces(note: ExtendedNote): Promise { - return this.pxe.getNoteNonces(note); - } getBlock(number: number): Promise { return this.pxe.getBlock(number); } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 8d8a9b69156..44fa8db2e41 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -221,45 +221,53 @@ export class PXEService implements PXE { throw new Error('Unknown account.'); } - const [nonce] = await this.getNoteNonces(note); - if (!nonce) { + const nonces = await this.getNoteNonces(note); + if (nonces.length === 0) { throw new Error(`Cannot find the note in tx: ${note.txHash}.`); } - const { innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } = - await this.simulator.computeNoteHashAndNullifier(note.contractAddress, nonce, note.storageSlot, note.note); + for (const nonce of nonces) { + const { innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } = + await this.simulator.computeNoteHashAndNullifier(note.contractAddress, nonce, note.storageSlot, note.note); - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) - // This can always be `uniqueSiloedNoteHash` once notes added from public also include nonces. - const noteHashToLookUp = nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; - const index = await this.node.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, noteHashToLookUp); - if (index === undefined) { - throw new Error('Note does not exist.'); - } + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) + // This can always be `uniqueSiloedNoteHash` once notes added from public also include nonces. + const noteHashToLookUp = nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; + const index = await this.node.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, noteHashToLookUp); + if (index === undefined) { + throw new Error('Note does not exist.'); + } - const wasm = await CircuitsWasm.get(); - const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!); - const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); - if (nullifierIndex !== undefined) { - throw new Error('The note has been destroyed.'); - } + const wasm = await CircuitsWasm.get(); + const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!); + const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); + if (nullifierIndex !== undefined) { + throw new Error('The note has been destroyed.'); + } - await this.db.addNote( - new NoteDao( - note.note, - note.contractAddress, - note.storageSlot, - note.txHash, - nonce, - innerNoteHash, - siloedNullifier, - index, - publicKey, - ), - ); + await this.db.addNote( + new NoteDao( + note.note, + note.contractAddress, + note.storageSlot, + note.txHash, + nonce, + innerNoteHash, + siloedNullifier, + index, + publicKey, + ), + ); + } } - public async getNoteNonces(note: ExtendedNote): Promise { + /** + * Finds the nonce(s) for a given note. + * @param note - The note to find the nonces for. + * @returns The nonces of the note. + * @remarks More than a single nonce may be returned since there might be more than one nonce for a given note. + */ + private async getNoteNonces(note: ExtendedNote): Promise { const tx = await this.node.getTx(note.txHash); if (!tx) { throw new Error(`Unknown tx: ${note.txHash}`); diff --git a/yarn-project/types/src/interfaces/pxe.ts b/yarn-project/types/src/interfaces/pxe.ts index 5efef5b63ae..c7dd53a76b0 100644 --- a/yarn-project/types/src/interfaces/pxe.ts +++ b/yarn-project/types/src/interfaces/pxe.ts @@ -177,14 +177,6 @@ export interface PXE { */ addNote(note: ExtendedNote): Promise; - /** - * Finds the nonce(s) for a given note. - * @param note - The note to find the nonces for. - * @returns The nonces of the note. - * @remarks More than a single nonce may be returned since there might be more than one nonce for a given note. - */ - getNoteNonces(note: ExtendedNote): Promise; - /** * Get the given block. * @param number - The block number being requested.