@aztec/entrypoints 0.0.0-test.1 → 0.0.1-commit.017a351

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,59 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { GasSettings } from '@aztec/stdlib/gas';
4
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
6
+ /**
7
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
8
+ */
9
+ export declare enum AccountFeePaymentMethodOptions {
10
+ /**
11
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
12
+ */
13
+ EXTERNAL = 0,
14
+ /**
15
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
16
+ * **which it must already have prior to this transaction**.
17
+ *
18
+ * The contract will set itself as the fee payer and end the setup phase.
19
+ */
20
+ PREEXISTING_FEE_JUICE = 1,
21
+ /**
22
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
23
+ * **which is being claimed in the same transaction**.
24
+ *
25
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
26
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
27
+ * to be executable during the setup phase.
28
+ */
29
+ FEE_JUICE_WITH_CLAIM = 2
30
+ }
31
+ /**
32
+ * General options for the tx execution.
33
+ */
34
+ export type DefaultAccountEntrypointOptions = {
35
+ /** Whether the transaction can be cancelled. */
36
+ cancellable?: boolean;
37
+ /**
38
+ * A nonce to inject into the app payload of the transaction. When used with cancellable=true, this nonce will be
39
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
40
+ * but higher fee. The nullifier ensures only one transaction can succeed.
41
+ */
42
+ txNonce?: Fr;
43
+ /** Options that configure how the account contract behaves depending on the fee payment method of the tx */
44
+ feePaymentMethodOptions: AccountFeePaymentMethodOptions;
45
+ };
5
46
  /**
6
47
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
48
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
8
49
  */
9
50
  export declare class DefaultAccountEntrypoint implements EntrypointInterface {
51
+ #private;
10
52
  private address;
11
53
  private auth;
12
- private chainId;
13
- private version;
14
- constructor(address: AztecAddress, auth: AuthWitnessProvider, chainId?: number, version?: number);
15
- createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
54
+ constructor(address: AztecAddress, auth: AuthWitnessProvider);
55
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo, options: DefaultAccountEntrypointOptions): Promise<TxExecutionRequest>;
56
+ wrapExecutionPayload(exec: ExecutionPayload, chainInfo: ChainInfo, options: DefaultAccountEntrypointOptions): Promise<ExecutionPayload>;
16
57
  private getEntrypointAbi;
17
58
  }
18
- //# sourceMappingURL=account_entrypoint.d.ts.map
59
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWNjb3VudF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUdwRCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN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QUN2QyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0F1QjNCO0lBdUNELE9BQU8sQ0FBQyxnQkFBZ0I7Q0EyRHpCIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,oBAAoB,EAE1B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAHP,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2BvF,OAAO,CAAC,gBAAgB;CAqGzB"}
1
+ {"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3F;;GAEG;AACH,oBAAY,8BAA8B;IACxC;;OAEG;IACH,QAAQ,IAAI;IACZ;;;;;OAKG;IACH,qBAAqB,IAAI;IACzB;;;;;;;OAOG;IACH,oBAAoB,IAAI;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,gDAAgD;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC;IACb,4GAA4G;IAC5G,uBAAuB,EAAE,8BAA8B,CAAC;CACzD,CAAC;AAEF;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IAFd,YACU,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,mBAAmB,EAC/B;IAEE,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,kBAAkB,CAAC,CAgB7B;IAEK,oBAAoB,CACxB,IAAI,EAAE,gBAAgB,EACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;IAuCD,OAAO,CAAC,gBAAgB;CA2DzB"}
@@ -1,55 +1,123 @@
1
- import { EntrypointPayload, computeCombinedPayloadHash } from '@aztec/aztec.js/entrypoint';
2
- import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
- import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import { computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
4
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import { EncodedAppEntrypointCalls } from './encoding.js';
6
+ /**
7
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
8
+ */ export var AccountFeePaymentMethodOptions = /*#__PURE__*/ function(AccountFeePaymentMethodOptions) {
9
+ /**
10
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
11
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["EXTERNAL"] = 0] = "EXTERNAL";
12
+ /**
13
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
14
+ * **which it must already have prior to this transaction**.
15
+ *
16
+ * The contract will set itself as the fee payer and end the setup phase.
17
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["PREEXISTING_FEE_JUICE"] = 1] = "PREEXISTING_FEE_JUICE";
18
+ /**
19
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
20
+ * **which is being claimed in the same transaction**.
21
+ *
22
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
23
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
24
+ * to be executable during the setup phase.
25
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["FEE_JUICE_WITH_CLAIM"] = 2] = "FEE_JUICE_WITH_CLAIM";
26
+ return AccountFeePaymentMethodOptions;
27
+ }({});
5
28
  /**
6
29
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
30
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
8
31
  */ export class DefaultAccountEntrypoint {
9
32
  address;
10
33
  auth;
11
- chainId;
12
- version;
13
- constructor(address, auth, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
34
+ constructor(address, auth){
14
35
  this.address = address;
15
36
  this.auth = auth;
16
- this.chainId = chainId;
17
- this.version = version;
18
37
  }
19
- async createTxExecutionRequest(exec) {
20
- const { calls, fee, nonce, cancellable, capsules = [] } = exec;
21
- const appPayload = await EntrypointPayload.fromAppExecution(calls, nonce);
22
- const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee);
23
- const abi = this.getEntrypointAbi();
24
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
25
- appPayload,
26
- feePayload,
27
- !!cancellable
28
- ]));
29
- const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload));
38
+ async createTxExecutionRequest(exec, gasSettings, chainInfo, options) {
39
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
40
+ const callData = await this.#buildEntrypointCallData(exec, chainInfo, options);
41
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
30
42
  const txRequest = TxExecutionRequest.from({
31
43
  firstCallArgsHash: entrypointHashedArgs.hash,
32
44
  origin: this.address,
33
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
45
+ functionSelector: callData.functionSelector,
46
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
35
47
  argsOfCalls: [
36
- ...appPayload.hashedArguments,
37
- ...feePayload.hashedArguments,
38
- entrypointHashedArgs
48
+ ...callData.encodedCalls.hashedArguments,
49
+ entrypointHashedArgs,
50
+ ...extraHashedArgs
39
51
  ],
40
52
  authWitnesses: [
41
- combinedPayloadAuthWitness
53
+ ...authWitnesses,
54
+ callData.payloadAuthWitness
42
55
  ],
43
- capsules
56
+ capsules,
57
+ salt: Fr.random()
44
58
  });
45
59
  return txRequest;
46
60
  }
61
+ async wrapExecutionPayload(exec, chainInfo, options) {
62
+ const { authWitnesses, capsules, extraHashedArgs, feePayer } = exec;
63
+ const callData = await this.#buildEntrypointCallData(exec, chainInfo, options);
64
+ // Build the entrypoint function call
65
+ const entrypointCall = FunctionCall.from({
66
+ name: callData.abi.name,
67
+ to: this.address,
68
+ selector: callData.functionSelector,
69
+ type: callData.abi.functionType,
70
+ hideMsgSender: false,
71
+ isStatic: callData.abi.isStatic,
72
+ args: callData.encodedArgs,
73
+ returnTypes: callData.abi.returnTypes
74
+ });
75
+ return new ExecutionPayload([
76
+ entrypointCall
77
+ ], [
78
+ callData.payloadAuthWitness,
79
+ ...authWitnesses
80
+ ], capsules, [
81
+ ...callData.encodedCalls.hashedArguments,
82
+ ...extraHashedArgs
83
+ ], feePayer ?? this.address);
84
+ }
85
+ /**
86
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
87
+ * This includes encoding calls, building entrypoint arguments, and creating the authwitness.
88
+ * @param exec - The execution payload containing calls to encode
89
+ * @param chainInfo - Chain information (chainId and version) for replay protection
90
+ * @param options - Account entrypoint options including tx nonce and fee payment method
91
+ * @returns Encoded call data, ABI, function selector, and auth witness
92
+ */ async #buildEntrypointCallData(exec, chainInfo, options) {
93
+ const { calls } = exec;
94
+ const { cancellable, txNonce, feePaymentMethodOptions } = options;
95
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
96
+ const abi = this.getEntrypointAbi();
97
+ const args = [
98
+ encodedCalls,
99
+ feePaymentMethodOptions,
100
+ !!cancellable
101
+ ];
102
+ const encodedArgs = encodeArguments(abi, args);
103
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
104
+ const payloadHash = await encodedCalls.hash();
105
+ const messageHash = await computeOuterAuthWitHash(this.address, chainInfo.chainId, chainInfo.version, payloadHash);
106
+ const payloadAuthWitness = await this.auth.createAuthWit(messageHash);
107
+ return {
108
+ encodedCalls,
109
+ abi,
110
+ encodedArgs,
111
+ functionSelector,
112
+ payloadAuthWitness
113
+ };
114
+ }
47
115
  getEntrypointAbi() {
48
116
  return {
49
117
  name: 'entrypoint',
50
118
  isInitializer: false,
51
119
  functionType: 'private',
52
- isInternal: false,
120
+ isOnlySelf: false,
53
121
  isStatic: false,
54
122
  parameters: [
55
123
  {
@@ -62,7 +130,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
62
130
  name: 'function_calls',
63
131
  type: {
64
132
  kind: 'array',
65
- length: 4,
133
+ length: 5,
66
134
  type: {
67
135
  kind: 'struct',
68
136
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -112,80 +180,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
112
180
  }
113
181
  },
114
182
  {
115
- name: 'is_static',
116
- type: {
117
- kind: 'boolean'
118
- }
119
- }
120
- ]
121
- }
122
- }
123
- },
124
- {
125
- name: 'nonce',
126
- type: {
127
- kind: 'field'
128
- }
129
- }
130
- ]
131
- },
132
- visibility: 'public'
133
- },
134
- {
135
- name: 'fee_payload',
136
- type: {
137
- kind: 'struct',
138
- path: 'authwit::entrypoint::fee::FeePayload',
139
- fields: [
140
- {
141
- name: 'function_calls',
142
- type: {
143
- kind: 'array',
144
- length: 2,
145
- type: {
146
- kind: 'struct',
147
- path: 'authwit::entrypoint::function_call::FunctionCall',
148
- fields: [
149
- {
150
- name: 'args_hash',
151
- type: {
152
- kind: 'field'
153
- }
154
- },
155
- {
156
- name: 'function_selector',
157
- type: {
158
- kind: 'struct',
159
- path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
160
- fields: [
161
- {
162
- name: 'inner',
163
- type: {
164
- kind: 'integer',
165
- sign: 'unsigned',
166
- width: 32
167
- }
168
- }
169
- ]
170
- }
171
- },
172
- {
173
- name: 'target_address',
174
- type: {
175
- kind: 'struct',
176
- path: 'authwit::aztec::protocol_types::address::AztecAddress',
177
- fields: [
178
- {
179
- name: 'inner',
180
- type: {
181
- kind: 'field'
182
- }
183
- }
184
- ]
185
- }
186
- },
187
- {
188
- name: 'is_public',
183
+ name: 'hide_msg_sender',
189
184
  type: {
190
185
  kind: 'boolean'
191
186
  }
@@ -201,21 +196,23 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
201
196
  }
202
197
  },
203
198
  {
204
- name: 'nonce',
199
+ name: 'tx_nonce',
205
200
  type: {
206
201
  kind: 'field'
207
202
  }
208
- },
209
- {
210
- name: 'is_fee_payer',
211
- type: {
212
- kind: 'boolean'
213
- }
214
203
  }
215
204
  ]
216
205
  },
217
206
  visibility: 'public'
218
207
  },
208
+ {
209
+ name: 'fee_payment_method',
210
+ type: {
211
+ kind: 'integer',
212
+ sign: 'unsigned',
213
+ width: 8
214
+ }
215
+ },
219
216
  {
220
217
  name: 'cancellable',
221
218
  type: {
@@ -2,4 +2,4 @@
2
2
  export declare const DEFAULT_CHAIN_ID = 31337;
3
3
  /** Default protocol version to use. */
4
4
  export declare const DEFAULT_VERSION = 1;
5
- //# sourceMappingURL=constants.d.ts.map
5
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uc3RhbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDhGQUE4RjtBQUM5RixlQUFPLE1BQU0sZ0JBQWdCLFFBQVEsQ0FBQztBQUN0Qyx1Q0FBdUM7QUFDdkMsZUFBTyxNQUFNLGVBQWUsSUFBSSxDQUFDIn0=
@@ -0,0 +1,11 @@
1
+ import type { GasSettings } from '@aztec/stdlib/gas';
2
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { ChainInfo, EntrypointInterface } from './interfaces.js';
4
+ /**
5
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
6
+ */
7
+ export declare class DefaultEntrypoint implements EntrypointInterface {
8
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo): Promise<TxExecutionRequest>;
9
+ wrapExecutionPayload(exec: ExecutionPayload, _chainInfo: ChainInfo, _options?: any): Promise<ExecutionPayload>;
10
+ }
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9lbnRyeXBvaW50Lm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AAW,EACxB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CA2B7B;IAEK,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgBnH;CACF"}
@@ -0,0 +1,39 @@
1
+ import { FunctionType } from '@aztec/stdlib/abi';
2
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ /**
4
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
5
+ */ export class DefaultEntrypoint {
6
+ async createTxExecutionRequest(exec, gasSettings, chainInfo) {
7
+ // Initial request with calls, authWitnesses and capsules
8
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
9
+ if (calls.length > 1) {
10
+ throw new Error(`Expected a single call, got ${calls.length}`);
11
+ }
12
+ const call = calls[0];
13
+ // Hash the arguments for the function call
14
+ const hashedArguments = [
15
+ await HashedValues.fromArgs(call.args)
16
+ ];
17
+ if (call.type !== FunctionType.PRIVATE) {
18
+ throw new Error('Public entrypoints are not allowed');
19
+ }
20
+ // Assemble the tx request
21
+ return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings), [
22
+ ...hashedArguments,
23
+ ...extraHashedArgs
24
+ ], authWitnesses, capsules);
25
+ }
26
+ async wrapExecutionPayload(exec, _chainInfo, _options) {
27
+ if (exec.calls.length !== 1) {
28
+ throw new Error(`DefaultEntrypoint can only wrap a single call, got ${exec.calls.length}`);
29
+ }
30
+ const call = exec.calls[0];
31
+ const hashedArguments = await HashedValues.fromArgs(call.args);
32
+ return new ExecutionPayload([
33
+ call
34
+ ], exec.authWitnesses, exec.capsules, [
35
+ hashedArguments,
36
+ ...exec.extraHashedArgs
37
+ ], exec.feePayer);
38
+ }
39
+ }
@@ -0,0 +1,16 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { GasSettings } from '@aztec/stdlib/gas';
3
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import type { ChainInfo, EntrypointInterface } from './interfaces.js';
5
+ /**
6
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
7
+ */
8
+ export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
9
+ #private;
10
+ private address;
11
+ constructor(address?: AztecAddress);
12
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo): Promise<TxExecutionRequest>;
13
+ wrapExecutionPayload(exec: ExecutionPayload, _chainInfo: ChainInfo, _options?: any): Promise<ExecutionPayload>;
14
+ private getEntrypointAbi;
15
+ }
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9tdWx0aV9jYWxsX2VudHJ5cG9pbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9kZWZhdWx0X211bHRpX2NhbGxfZW50cnlwb2ludC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNyRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQTJCLGtCQUFrQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFHakcsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLG1CQUFtQixFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFdEU7O0dBRUc7QUFDSCxxQkFBYSwwQkFBMkIsWUFBVyxtQkFBbUI7O0lBQ3hELE9BQU8sQ0FBQyxPQUFPO0lBQTNCLFlBQW9CLE9BQU8sR0FBRSxZQUFxRCxFQUFJ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, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js';
2
- import { EntrypointPayload } from '@aztec/aztec.js/entrypoint';
3
- import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
- import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint/constants';
3
+ import { FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import { EncodedAppEntrypointCalls } from './encoding.js';
6
6
  /**
7
- * Implementation for an entrypoint interface that follows the default entrypoint signature
8
- * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
9
- */ export class DefaultDappEntrypoint {
10
- userAddress;
11
- userAuthWitnessProvider;
12
- dappEntrypointAddress;
13
- chainId;
14
- version;
15
- constructor(userAddress, userAuthWitnessProvider, dappEntrypointAddress, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
16
- this.userAddress = userAddress;
17
- this.userAuthWitnessProvider = userAuthWitnessProvider;
18
- this.dappEntrypointAddress = dappEntrypointAddress;
19
- this.chainId = chainId;
20
- this.version = version;
7
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
8
+ */ export class DefaultMultiCallEntrypoint {
9
+ address;
10
+ constructor(address = STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS){
11
+ this.address = address;
21
12
  }
22
- async createTxExecutionRequest(exec) {
23
- const { calls, fee, capsules = [] } = exec;
24
- if (calls.length !== 1) {
25
- throw new Error(`Expected exactly 1 function call, got ${calls.length}`);
26
- }
27
- const payload = await EntrypointPayload.fromFunctionCalls(calls);
28
- const abi = this.getEntrypointAbi();
29
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
30
- payload,
31
- this.userAddress
32
- ]));
33
- const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
34
- // Default msg_sender for entrypoints is now Fr.max_value rather than 0 addr (see #7190 & #7404)
35
- const innerHash = await computeInnerAuthWitHash([
36
- Fr.MAX_FIELD_VALUE,
37
- functionSelector.toField(),
38
- entrypointHashedArgs.hash
39
- ]);
40
- const outerHash = await computeAuthWitMessageHash({
41
- consumer: this.dappEntrypointAddress,
42
- innerHash
43
- }, {
44
- chainId: new Fr(this.chainId),
45
- version: new Fr(this.version)
46
- });
47
- const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash);
13
+ async createTxExecutionRequest(exec, gasSettings, chainInfo) {
14
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
15
+ const callData = await this.#buildEntrypointCallData(exec);
16
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
48
17
  const txRequest = TxExecutionRequest.from({
49
18
  firstCallArgsHash: entrypointHashedArgs.hash,
50
- origin: this.dappEntrypointAddress,
51
- functionSelector,
52
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
19
+ origin: this.address,
20
+ functionSelector: callData.functionSelector,
21
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
53
22
  argsOfCalls: [
54
- ...payload.hashedArguments,
55
- entrypointHashedArgs
23
+ ...callData.encodedCalls.hashedArguments,
24
+ entrypointHashedArgs,
25
+ ...extraHashedArgs
56
26
  ],
57
- authWitnesses: [
58
- authWitness
59
- ],
60
- capsules
27
+ authWitnesses,
28
+ capsules,
29
+ salt: Fr.random()
30
+ });
31
+ return Promise.resolve(txRequest);
32
+ }
33
+ async wrapExecutionPayload(exec, _chainInfo, _options) {
34
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
35
+ const callData = await this.#buildEntrypointCallData(exec);
36
+ const entrypointCall = FunctionCall.from({
37
+ name: callData.abi.name,
38
+ to: this.address,
39
+ selector: callData.functionSelector,
40
+ type: callData.abi.functionType,
41
+ hideMsgSender: false,
42
+ isStatic: callData.abi.isStatic,
43
+ args: callData.encodedArgs,
44
+ returnTypes: callData.abi.returnTypes
61
45
  });
62
- return txRequest;
46
+ return new ExecutionPayload([
47
+ entrypointCall
48
+ ], authWitnesses, capsules, [
49
+ ...callData.encodedCalls.hashedArguments,
50
+ ...extraHashedArgs
51
+ ], exec.feePayer);
52
+ }
53
+ /**
54
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
55
+ * This includes encoding calls and building entrypoint arguments.
56
+ * @param exec - The execution payload containing calls to encode
57
+ * @returns Encoded call data, ABI, encoded arguments, and function selector
58
+ */ async #buildEntrypointCallData(exec) {
59
+ const { calls } = exec;
60
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
61
+ const abi = this.getEntrypointAbi();
62
+ const encodedArgs = encodeArguments(abi, [
63
+ encodedCalls
64
+ ]);
65
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
66
+ return {
67
+ encodedCalls,
68
+ abi,
69
+ encodedArgs,
70
+ functionSelector
71
+ };
63
72
  }
64
73
  getEntrypointAbi() {
65
74
  return {
66
75
  name: 'entrypoint',
67
76
  isInitializer: false,
68
77
  functionType: 'private',
69
- isInternal: false,
78
+ isOnlySelf: false,
70
79
  isStatic: false,
71
80
  parameters: [
72
81
  {
73
- name: 'payload',
82
+ name: 'app_payload',
74
83
  type: {
75
84
  kind: 'struct',
76
- path: 'dapp_payload::DAppPayload',
85
+ path: 'authwit::entrypoint::app::AppPayload',
77
86
  fields: [
78
87
  {
79
88
  name: 'function_calls',
80
89
  type: {
81
90
  kind: 'array',
82
- length: 1,
91
+ length: 5,
83
92
  type: {
84
93
  kind: 'struct',
85
94
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -111,7 +120,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
111
120
  name: 'target_address',
112
121
  type: {
113
122
  kind: 'struct',
114
- path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
123
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
115
124
  fields: [
116
125
  {
117
126
  name: 'inner',
@@ -128,6 +137,12 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
128
137
  kind: 'boolean'
129
138
  }
130
139
  },
140
+ {
141
+ name: 'hide_msg_sender',
142
+ type: {
143
+ kind: 'boolean'
144
+ }
145
+ },
131
146
  {
132
147
  name: 'is_static',
133
148
  type: {
@@ -139,23 +154,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
139
154
  }
140
155
  },
141
156
  {
142
- name: 'nonce',
143
- type: {
144
- kind: 'field'
145
- }
146
- }
147
- ]
148
- },
149
- visibility: 'public'
150
- },
151
- {
152
- name: 'user_address',
153
- type: {
154
- kind: 'struct',
155
- path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
156
- fields: [
157
- {
158
- name: 'inner',
157
+ name: 'tx_nonce',
159
158
  type: {
160
159
  kind: 'field'
161
160
  }