Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Mar 18, 2024
1 parent cfad8dd commit 29de2ac
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions yarn-project/aztec.js/src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
| {
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec.js/src/utils/authwit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]),
);
};
Expand Down
42 changes: 21 additions & 21 deletions yarn-project/aztec.js/src/wallet/account_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
| {
Expand All @@ -37,19 +37,19 @@ export class AccountWallet extends BaseWallet {
action: ContractFunctionInteraction | FunctionCall;
},
): Promise<AuthWitness> {
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
| {
Expand All @@ -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
| {
Expand All @@ -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 {
Expand All @@ -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
| {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export abstract class BaseWallet implements Wallet {
abstract createTxExecutionRequest(execs: FunctionCall[], fee?: FeeOptions): Promise<TxExecutionRequest>;

abstract createAuthWit(
messageOrAuthWitInput:
messageHashOrIntent:
| Fr
| Buffer
| {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 29de2ac

Please sign in to comment.