11import type { FeeOptions , TxExecutionOptions } from '@aztec/entrypoints/interfaces' ;
22import type { ExecutionPayload } from '@aztec/entrypoints/payload' ;
33import { Fr } from '@aztec/foundation/fields' ;
4- import { ProtocolContractAddress } from '@aztec/protocol-contracts' ;
5- import { ABIParameterVisibility , type FunctionAbi , FunctionType } from '@aztec/stdlib/abi' ;
64import { AuthWitness } from '@aztec/stdlib/auth-witness' ;
7- import type { AztecAddress } from '@aztec/stdlib/aztec-address' ;
85import type { TxExecutionRequest } from '@aztec/stdlib/tx' ;
96
10- import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js' ;
11- import {
12- type IntentAction ,
13- type IntentInnerHash ,
14- computeAuthWitMessageHash ,
15- computeInnerAuthWitHashFromAction ,
16- } from '../utils/authwit.js' ;
17- import type { Wallet } from '../wallet/wallet.js' ;
7+ import { type CallIntent , type IntentInnerHash , computeAuthWitMessageHash } from '../utils/authwit.js' ;
188import type { AccountInterface } from './interface.js' ;
199
2010/**
@@ -27,18 +17,7 @@ interface AuthwitnessIntentProvider {
2717 * during function execution
2818 * @param intent - The action (or inner hash) to authorize
2919 */
30- createAuthWit ( intent : IntentInnerHash | IntentAction | Buffer | Fr ) : Promise < AuthWitness > ;
31- /**
32- * Sets a public authwit for an intent or inner hash
33- * @param wallet - The wallet to send the transaction authorizing the action from
34- * @param messageHashOrIntent - The action (or inner hash) to authorize/deny
35- * @param authorized - Whether to authorize or deny the action
36- */
37- setPublicAuthWit (
38- wallet : Wallet ,
39- messageHashOrIntent : Fr | Buffer | IntentInnerHash | IntentAction ,
40- authorized : boolean ,
41- ) : Promise < ContractFunctionInteraction > ;
20+ createAuthWit ( intent : IntentInnerHash | CallIntent | Buffer | Fr ) : Promise < AuthWitness > ;
4221}
4322
4423/**
@@ -90,7 +69,7 @@ export class BaseAccount implements Account {
9069 * @param messageHashOrIntent - The message hash of the intent to approve
9170 * @returns The authentication witness
9271 */
93- async createAuthWit ( messageHashOrIntent : Fr | Buffer | IntentAction | IntentInnerHash ) : Promise < AuthWitness > {
72+ async createAuthWit ( messageHashOrIntent : Fr | Buffer | CallIntent | IntentInnerHash ) : Promise < AuthWitness > {
9473 let messageHash : Fr ;
9574 if ( Buffer . isBuffer ( messageHashOrIntent ) ) {
9675 messageHash = Fr . fromBuffer ( messageHashOrIntent ) ;
@@ -103,175 +82,15 @@ export class BaseAccount implements Account {
10382 return this . account . createAuthWit ( messageHash ) ;
10483 }
10584
106- /**
107- * Returns a function interaction to set a message hash as authorized or revoked in this account.
108- *
109- * Public calls can then consume this authorization.
110- *
111- * @param wallet - The wallet to send the transaction authorizing the action from
112- * @param messageHashOrIntent - The message hash or intent to authorize/revoke
113- * @param authorized - True to authorize, false to revoke authorization.
114- * @returns - A function interaction.
115- */
116- public async setPublicAuthWit (
117- wallet : Wallet ,
118- messageHashOrIntent : Fr | Buffer | IntentInnerHash | IntentAction ,
119- authorized : boolean ,
120- ) : Promise < ContractFunctionInteraction > {
121- let messageHash : Fr ;
122- if ( Buffer . isBuffer ( messageHashOrIntent ) ) {
123- messageHash = Fr . fromBuffer ( messageHashOrIntent ) ;
124- } else if ( messageHashOrIntent instanceof Fr ) {
125- messageHash = messageHashOrIntent ;
126- } else {
127- messageHash = await this . getMessageHash ( messageHashOrIntent ) ;
128- }
129-
130- return new ContractFunctionInteraction ( wallet , ProtocolContractAddress . AuthRegistry , this . getSetAuthorizedAbi ( ) , [
131- messageHash ,
132- authorized ,
133- ] ) ;
134- }
135-
136- private async getInnerHashAndConsumer ( intent : IntentInnerHash | IntentAction ) : Promise < {
137- /** The inner hash */
138- innerHash : Fr ;
139- /** The consumer of the authwit */
140- consumer : AztecAddress ;
141- } > {
142- if ( 'caller' in intent && 'action' in intent ) {
143- const action =
144- intent . action instanceof ContractFunctionInteraction ? ( await intent . action . request ( ) ) . calls [ 0 ] : intent . action ;
145- return {
146- innerHash : await computeInnerAuthWitHashFromAction ( intent . caller , action ) ,
147- consumer : action . to ,
148- } ;
149- } else if ( Buffer . isBuffer ( intent . innerHash ) ) {
150- return { innerHash : Fr . fromBuffer ( intent . innerHash ) , consumer : intent . consumer } ;
151- }
152- return { innerHash : intent . innerHash , consumer : intent . consumer } ;
153- }
154-
15585 /**
15686 * Returns the message hash for the given intent
15787 *
15888 * @param intent - A tuple of (consumer and inner hash) or (caller and action)
15989 * @returns The message hash
16090 */
161- private getMessageHash ( intent : IntentInnerHash | IntentAction ) : Promise < Fr > {
91+ private getMessageHash ( intent : IntentInnerHash | CallIntent ) : Promise < Fr > {
16292 const chainId = this . getChainId ( ) ;
16393 const version = this . getVersion ( ) ;
16494 return computeAuthWitMessageHash ( intent , { chainId, version } ) ;
16595 }
166-
167- /**
168- * Lookup the validity of an authwit in private and public contexts.
169- *
170- * Uses the chain id and version of the wallet.
171- *
172- * @param wallet - The wallet use to simulate and read the public data
173- * @param onBehalfOf - The address of the "approver"
174- * @param intent - The consumer and inner hash or the caller and action to lookup
175- * @param witness - The computed authentication witness to check
176- * @returns - A struct containing the validity of the authwit in private and public contexts.
177- */
178- async lookupValidity (
179- wallet : Wallet ,
180- onBehalfOf : AztecAddress ,
181- intent : IntentInnerHash | IntentAction ,
182- witness : AuthWitness ,
183- ) : Promise < {
184- /** boolean flag indicating if the authwit is valid in private context */
185- isValidInPrivate : boolean ;
186- /** boolean flag indicating if the authwit is valid in public context */
187- isValidInPublic : boolean ;
188- } > {
189- const { innerHash, consumer } = await this . getInnerHashAndConsumer ( intent ) ;
190-
191- const messageHash = await this . getMessageHash ( intent ) ;
192- const results = { isValidInPrivate : false , isValidInPublic : false } ;
193-
194- // Check private
195- try {
196- results . isValidInPrivate = ( await new ContractFunctionInteraction (
197- wallet ,
198- onBehalfOf ,
199- this . getLookupValidityAbi ( ) ,
200- [ consumer , innerHash ] ,
201- ) . simulate ( { from : this . getAddress ( ) , authWitnesses : [ witness ] } ) ) as boolean ;
202- // TODO: Narrow down the error to make sure simulation failed due to an invalid authwit
203- // eslint-disable-next-line no-empty
204- } catch { }
205-
206- // check public
207- results . isValidInPublic = ( await new ContractFunctionInteraction (
208- wallet ,
209- ProtocolContractAddress . AuthRegistry ,
210- this . getIsConsumableAbi ( ) ,
211- [ onBehalfOf , messageHash ] ,
212- ) . simulate ( { from : this . getAddress ( ) } ) ) as boolean ;
213-
214- return results ;
215- }
216-
217- private getSetAuthorizedAbi ( ) : FunctionAbi {
218- return {
219- name : 'set_authorized' ,
220- isInitializer : false ,
221- functionType : FunctionType . PUBLIC ,
222- isInternal : true ,
223- isStatic : false ,
224- parameters : [
225- {
226- name : 'message_hash' ,
227- type : { kind : 'field' } ,
228- visibility : 'private' as ABIParameterVisibility ,
229- } ,
230- {
231- name : 'authorize' ,
232- type : { kind : 'boolean' } ,
233- visibility : 'private' as ABIParameterVisibility ,
234- } ,
235- ] ,
236- returnTypes : [ ] ,
237- errorTypes : { } ,
238- } ;
239- }
240-
241- private getLookupValidityAbi ( ) : FunctionAbi {
242- return {
243- name : 'lookup_validity' ,
244- isInitializer : false ,
245- functionType : FunctionType . UTILITY ,
246- isInternal : false ,
247- isStatic : false ,
248- parameters : [ { name : 'message_hash' , type : { kind : 'field' } , visibility : 'private' as ABIParameterVisibility } ] ,
249- returnTypes : [ { kind : 'boolean' } ] ,
250- errorTypes : { } ,
251- } ;
252- }
253-
254- private getIsConsumableAbi ( ) : FunctionAbi {
255- return {
256- name : 'utility_is_consumable' ,
257- isInitializer : false ,
258- functionType : FunctionType . UTILITY ,
259- isInternal : false ,
260- isStatic : false ,
261- parameters : [
262- {
263- name : 'address' ,
264- type : {
265- fields : [ { name : 'inner' , type : { kind : 'field' } } ] ,
266- kind : 'struct' ,
267- path : 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress' ,
268- } ,
269- visibility : 'private' as ABIParameterVisibility ,
270- } ,
271- { name : 'message_hash' , type : { kind : 'field' } , visibility : 'private' as ABIParameterVisibility } ,
272- ] ,
273- returnTypes : [ { kind : 'boolean' } ] ,
274- errorTypes : { } ,
275- } ;
276- }
27796}
0 commit comments