diff --git a/yarn-project/aztec.js/src/account/interface.ts b/yarn-project/aztec.js/src/account/interface.ts index 96247ab97cd..7da5226b749 100644 --- a/yarn-project/aztec.js/src/account/interface.ts +++ b/yarn-project/aztec.js/src/account/interface.ts @@ -19,14 +19,14 @@ export type FeeOptions = { /** Creates authorization witnesses. */ export interface AuthWitnessProvider { /** - * Computes an authentication witness from either a message or a caller and an action. - * If a message is provided, it will create a witness for the message directly. - * Otherwise, it will compute the message using the caller and the action. - * @param messageOrAuthWitInput - The message or the caller and action to approve + * Computes an authentication witness from either a message hash or an intent (caller and an action). + * If a message hash is provided, it will create a witness for that directly. + * Otherwise, it will compute the message hash using the caller and the action of the intent. + * @param messageHashOrIntent - The message hash or the intent (caller and action) to approve * @returns The authentication witness */ createAuthWit( - messageOrAuthWitInput: + messageHashOrIntent: | Fr | Buffer | { diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index 865f278dfa5..2087730ca81 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -12,16 +12,16 @@ import { pedersenHash } from '@aztec/foundation/crypto'; * `bob` then signs the message hash and gives it to `alice` who can then perform the * action. * @param caller - The caller approved to make the call - * @param request - The request to be made (function call) + * @param action - The request to be made (function call) * @returns The message hash for the witness */ -export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => { +export const computeAuthWitMessageHash = (caller: AztecAddress, action: FunctionCall) => { return computeOuterAuthWitHash( - request.to.toField(), + action.to.toField(), computeInnerAuthWitHash([ caller.toField(), - request.functionData.selector.toField(), - PackedArguments.fromArgs(request.args).hash, + action.functionData.selector.toField(), + PackedArguments.fromArgs(action.args).hash, ]), ); }; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 7d1404794bb..10383dcea4c 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -23,11 +23,11 @@ export class AccountWallet extends BaseWallet { * Computes an authentication witness from either a message or a caller and an action. * If a message is provided, it will create a witness for the message directly. * Otherwise, it will compute the message using the caller and the action. - * @param messageOrAuthWitInput - The message or the caller and action to approve + * @param messageHashOrIntent - The message or the caller and action to approve * @returns The authentication witness */ async createAuthWit( - messageOrAuthWitInput: + messageHashOrIntent: | Fr | Buffer | { @@ -37,19 +37,19 @@ export class AccountWallet extends BaseWallet { action: ContractFunctionInteraction | FunctionCall; }, ): Promise { - const message = this.getMessage(messageOrAuthWitInput); - const witness = await this.account.createAuthWit(message); + const messageHash = this.getMessageHash(messageHashOrIntent); + const witness = await this.account.createAuthWit(messageHash); await this.pxe.addAuthWitness(witness); return witness; } /** * Returns the message hash for the given message or authwit input. - * @param messageOrAuthWitInput - The message or the caller and action to authorize - * @returns Message hash + * @param messageHashOrIntent - The message hash or the caller and action to authorize + * @returns The message hash */ - private getMessage( - messageOrAuthWitInput: + private getMessageHash( + messageHashOrIntent: | Fr | Buffer | { @@ -59,25 +59,25 @@ export class AccountWallet extends BaseWallet { action: ContractFunctionInteraction | FunctionCall; }, ): Fr { - if (Buffer.isBuffer(messageOrAuthWitInput)) { - return Fr.fromBuffer(messageOrAuthWitInput); - } else if (messageOrAuthWitInput instanceof Fr) { - return messageOrAuthWitInput; - } else if (messageOrAuthWitInput.action instanceof ContractFunctionInteraction) { - return computeAuthWitMessageHash(messageOrAuthWitInput.caller, messageOrAuthWitInput.action.request()); + if (Buffer.isBuffer(messageHashOrIntent)) { + return Fr.fromBuffer(messageHashOrIntent); + } else if (messageHashOrIntent instanceof Fr) { + return messageHashOrIntent; + } else if (messageHashOrIntent.action instanceof ContractFunctionInteraction) { + return computeAuthWitMessageHash(messageHashOrIntent.caller, messageHashOrIntent.action.request()); } - return computeAuthWitMessageHash(messageOrAuthWitInput.caller, messageOrAuthWitInput.action); + return computeAuthWitMessageHash(messageHashOrIntent.caller, messageHashOrIntent.action); } /** * Returns a function interaction to set a message hash as authorized or revoked in this account. * Public calls can then consume this authorization. - * @param messageOrAuthWitInput - The message or the caller and action to authorize/revoke + * @param messageHashOrIntent - The message or the caller and action to authorize/revoke * @param authorized - True to authorize, false to revoke authorization. * @returns - A function interaction. */ public setPublicAuthWit( - messageOrAuthWitInput: + messageHashOrIntent: | Fr | Buffer | { @@ -88,7 +88,7 @@ export class AccountWallet extends BaseWallet { }, authorized: boolean, ): ContractFunctionInteraction { - const message = this.getMessage(messageOrAuthWitInput); + const message = this.getMessageHash(messageHashOrIntent); if (authorized) { return new ContractFunctionInteraction(this, this.getAddress(), this.getApprovePublicAuthwitAbi(), [message]); } else { @@ -98,11 +98,11 @@ export class AccountWallet extends BaseWallet { /** * Returns a function interaction to cancel a message hash as authorized in this account. - * @param messageOrAuthWitInput - The message or the caller and action to authorize/revoke + * @param messageHashOrIntent - The message or the caller and action to authorize/revoke * @returns - A function interaction. */ public cancelAuthWit( - messageOrAuthWitInput: + messageHashOrIntent: | Fr | Buffer | { @@ -112,7 +112,7 @@ export class AccountWallet extends BaseWallet { action: ContractFunctionInteraction | FunctionCall; }, ): ContractFunctionInteraction { - const message = this.getMessage(messageOrAuthWitInput); + const message = this.getMessageHash(messageHashOrIntent); const args = [message]; return new ContractFunctionInteraction(this, this.getAddress(), this.getCancelAuthwitAbi(), args); } diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 529d5c23ced..d6f88da973e 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -34,7 +34,7 @@ export abstract class BaseWallet implements Wallet { abstract createTxExecutionRequest(execs: FunctionCall[], fee?: FeeOptions): Promise; abstract createAuthWit( - messageOrAuthWitInput: + messageHashOrIntent: | Fr | Buffer | { diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index deae7eb5f36..3f979ac6bc2 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -493,7 +493,7 @@ describe('e2e_token_contract', () => { await wallets[0].cancelAuthWit({ caller: accounts[1].address, action }).send().wait(); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. + // Check that the authwit is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txCancelledAuthwit = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) @@ -515,7 +515,7 @@ describe('e2e_token_contract', () => { await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, false).send().wait(); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. + // Check that the authwit is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txCancelledAuthwit = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)