@aztec/entrypoints 0.0.0-test.1 → 0.0.1-commit.0208eb9

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, options: DefaultAccountEntrypointOptions): Promise<ExecutionPayload>;
16
57
  private getEntrypointAbi;
17
58
  }
18
- //# sourceMappingURL=account_entrypoint.d.ts.map
59
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWNjb3VudF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNyRCxPQUFPLE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1QjNCO0lBZ0NELE9BQU8sQ0FBQyxnQkFBZ0I7Q0EyRHpCIn0=
@@ -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;AAEpD,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,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;IAgCD,OAAO,CAAC,gBAAgB;CA2DzB"}
@@ -1,55 +1,110 @@
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 { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import { EncodedAppEntrypointCalls } from './encoding.js';
5
+ /**
6
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
7
+ */ export var AccountFeePaymentMethodOptions = /*#__PURE__*/ function(AccountFeePaymentMethodOptions) {
8
+ /**
9
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
10
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["EXTERNAL"] = 0] = "EXTERNAL";
11
+ /**
12
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
13
+ * **which it must already have prior to this transaction**.
14
+ *
15
+ * The contract will set itself as the fee payer and end the setup phase.
16
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["PREEXISTING_FEE_JUICE"] = 1] = "PREEXISTING_FEE_JUICE";
17
+ /**
18
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
19
+ * **which is being claimed in the same transaction**.
20
+ *
21
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
22
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
23
+ * to be executable during the setup phase.
24
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["FEE_JUICE_WITH_CLAIM"] = 2] = "FEE_JUICE_WITH_CLAIM";
25
+ return AccountFeePaymentMethodOptions;
26
+ }({});
5
27
  /**
6
28
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
29
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
8
30
  */ export class DefaultAccountEntrypoint {
9
31
  address;
10
32
  auth;
11
- chainId;
12
- version;
13
- constructor(address, auth, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
33
+ constructor(address, auth){
14
34
  this.address = address;
15
35
  this.auth = auth;
16
- this.chainId = chainId;
17
- this.version = version;
18
36
  }
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));
37
+ async createTxExecutionRequest(exec, gasSettings, chainInfo, options) {
38
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
39
+ const callData = await this.#buildEntrypointCallData(exec, options);
40
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
30
41
  const txRequest = TxExecutionRequest.from({
31
42
  firstCallArgsHash: entrypointHashedArgs.hash,
32
43
  origin: this.address,
33
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
44
+ functionSelector: callData.functionSelector,
45
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
35
46
  argsOfCalls: [
36
- ...appPayload.hashedArguments,
37
- ...feePayload.hashedArguments,
38
- entrypointHashedArgs
47
+ ...callData.encodedCalls.hashedArguments,
48
+ entrypointHashedArgs,
49
+ ...extraHashedArgs
39
50
  ],
40
51
  authWitnesses: [
41
- combinedPayloadAuthWitness
52
+ ...authWitnesses,
53
+ callData.payloadAuthWitness
42
54
  ],
43
- capsules
55
+ capsules,
56
+ salt: Fr.random()
44
57
  });
45
58
  return txRequest;
46
59
  }
60
+ async wrapExecutionPayload(exec, options) {
61
+ const { authWitnesses, capsules, extraHashedArgs, feePayer } = exec;
62
+ const callData = await this.#buildEntrypointCallData(exec, options);
63
+ // Build the entrypoint function call
64
+ const entrypointCall = new FunctionCall(callData.abi.name, this.address, callData.functionSelector, callData.abi.functionType, false, callData.abi.isStatic, callData.encodedArgs, callData.abi.returnTypes);
65
+ return new ExecutionPayload([
66
+ entrypointCall
67
+ ], [
68
+ callData.payloadAuthWitness,
69
+ ...authWitnesses
70
+ ], capsules, [
71
+ ...callData.encodedCalls.hashedArguments,
72
+ ...extraHashedArgs
73
+ ], feePayer ?? this.address);
74
+ }
75
+ /**
76
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
77
+ * This includes encoding calls, building entrypoint arguments, and creating the authwitness.
78
+ * @param exec - The execution payload containing calls to encode
79
+ * @param options - Account entrypoint options including tx nonce and fee payment method
80
+ * @returns Encoded call data, ABI, function selector, and auth witness
81
+ */ async #buildEntrypointCallData(exec, options) {
82
+ const { calls } = exec;
83
+ const { cancellable, txNonce, feePaymentMethodOptions } = options;
84
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
85
+ const abi = this.getEntrypointAbi();
86
+ const args = [
87
+ encodedCalls,
88
+ feePaymentMethodOptions,
89
+ !!cancellable
90
+ ];
91
+ const encodedArgs = encodeArguments(abi, args);
92
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
93
+ const payloadAuthWitness = await this.auth.createAuthWit(await encodedCalls.hash());
94
+ return {
95
+ encodedCalls,
96
+ abi,
97
+ encodedArgs,
98
+ functionSelector,
99
+ payloadAuthWitness
100
+ };
101
+ }
47
102
  getEntrypointAbi() {
48
103
  return {
49
104
  name: 'entrypoint',
50
105
  isInitializer: false,
51
106
  functionType: 'private',
52
- isInternal: false,
107
+ isOnlySelf: false,
53
108
  isStatic: false,
54
109
  parameters: [
55
110
  {
@@ -62,7 +117,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
62
117
  name: 'function_calls',
63
118
  type: {
64
119
  kind: 'array',
65
- length: 4,
120
+ length: 5,
66
121
  type: {
67
122
  kind: 'struct',
68
123
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -112,80 +167,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
112
167
  }
113
168
  },
114
169
  {
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',
170
+ name: 'hide_msg_sender',
189
171
  type: {
190
172
  kind: 'boolean'
191
173
  }
@@ -201,21 +183,23 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
201
183
  }
202
184
  },
203
185
  {
204
- name: 'nonce',
186
+ name: 'tx_nonce',
205
187
  type: {
206
188
  kind: 'field'
207
189
  }
208
- },
209
- {
210
- name: 'is_fee_payer',
211
- type: {
212
- kind: 'boolean'
213
- }
214
190
  }
215
191
  ]
216
192
  },
217
193
  visibility: 'public'
218
194
  },
195
+ {
196
+ name: 'fee_payment_method',
197
+ type: {
198
+ kind: 'integer',
199
+ sign: 'unsigned',
200
+ width: 8
201
+ }
202
+ },
219
203
  {
220
204
  name: 'cancellable',
221
205
  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, _options?: any): Promise<ExecutionPayload>;
10
+ }
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGVmYXVsdF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sRUFBRSxnQkFBZ0IsRUFBMkIsa0JBQWtCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUVqRyxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUV0RTs7R0FFRztBQUNILHFCQUFhLGlCQUFrQixZQUFXLG1CQUFtQjtJQUNyRCx3QkFBd0IsQ0FDNUIsSUFBSSxFQUFFLGdCQUFnQixFQUN0QixXQUFXLEVBQUUsV0FBVyxFQUN4QixTQUFTLEVBQUUsU0FBUyxHQUNuQixPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0EyQjdCO0lBRUssb0JBQW9CLENBQUMsSUFBSSxFQUFFLGdCQUFnQixFQUFFLFFBQVEsQ0FBQyxFQUFFLEdBQUcsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FnQjVGO0NBQ0YifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEjG,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,qBAAa,iBAAkB,YAAW,mBAAmB;IACrD,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CA2B7B;IAEK,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgB5F;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, _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, _options?: any): Promise<ExecutionPayload>;
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":"","sources":["../src/default_multi_call_entrypoint.ts"],"names":[],"mappings":"AAGA,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,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;;IACxD,OAAO,CAAC,OAAO;IAA3B,YAAoB,OAAO,GAAE,YAA0D,EAAI;IAErF,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAiB7B;IAEK,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqB5F;IA0BD,OAAO,CAAC,gBAAgB;CAyDzB"}
@@ -1,85 +1,85 @@
1
- import { Fr, 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 { ProtocolContractAddress } from '@aztec/protocol-contracts';
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 = ProtocolContractAddress.MultiCallEntrypoint){
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()
61
30
  });
62
- return txRequest;
31
+ return Promise.resolve(txRequest);
32
+ }
33
+ async wrapExecutionPayload(exec, _options) {
34
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
35
+ const callData = await this.#buildEntrypointCallData(exec);
36
+ const entrypointCall = new FunctionCall(callData.abi.name, this.address, callData.functionSelector, callData.abi.functionType, false, callData.abi.isStatic, callData.encodedArgs, callData.abi.returnTypes);
37
+ return new ExecutionPayload([
38
+ entrypointCall
39
+ ], authWitnesses, capsules, [
40
+ ...callData.encodedCalls.hashedArguments,
41
+ ...extraHashedArgs
42
+ ], exec.feePayer);
43
+ }
44
+ /**
45
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
46
+ * This includes encoding calls and building entrypoint arguments.
47
+ * @param exec - The execution payload containing calls to encode
48
+ * @returns Encoded call data, ABI, encoded arguments, and function selector
49
+ */ async #buildEntrypointCallData(exec) {
50
+ const { calls } = exec;
51
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
52
+ const abi = this.getEntrypointAbi();
53
+ const encodedArgs = encodeArguments(abi, [
54
+ encodedCalls
55
+ ]);
56
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
57
+ return {
58
+ encodedCalls,
59
+ abi,
60
+ encodedArgs,
61
+ functionSelector
62
+ };
63
63
  }
64
64
  getEntrypointAbi() {
65
65
  return {
66
66
  name: 'entrypoint',
67
67
  isInitializer: false,
68
68
  functionType: 'private',
69
- isInternal: false,
69
+ isOnlySelf: false,
70
70
  isStatic: false,
71
71
  parameters: [
72
72
  {
73
- name: 'payload',
73
+ name: 'app_payload',
74
74
  type: {
75
75
  kind: 'struct',
76
- path: 'dapp_payload::DAppPayload',
76
+ path: 'authwit::entrypoint::app::AppPayload',
77
77
  fields: [
78
78
  {
79
79
  name: 'function_calls',
80
80
  type: {
81
81
  kind: 'array',
82
- length: 1,
82
+ length: 5,
83
83
  type: {
84
84
  kind: 'struct',
85
85
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -111,7 +111,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
111
111
  name: 'target_address',
112
112
  type: {
113
113
  kind: 'struct',
114
- path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
114
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
115
115
  fields: [
116
116
  {
117
117
  name: 'inner',
@@ -128,6 +128,12 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
128
128
  kind: 'boolean'
129
129
  }
130
130
  },
131
+ {
132
+ name: 'hide_msg_sender',
133
+ type: {
134
+ kind: 'boolean'
135
+ }
136
+ },
131
137
  {
132
138
  name: 'is_static',
133
139
  type: {
@@ -139,23 +145,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
139
145
  }
140
146
  },
141
147
  {
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',
148
+ name: 'tx_nonce',
159
149
  type: {
160
150
  kind: 'field'
161
151
  }