@aztec-labs/entrypoints 6.0.0-nightly.20260829

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.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Account Entrypoints
2
+
3
+ This package contains different transaction entrypoints for the Aztec Network.
4
+
5
+ ## Available entrypoints
6
+
7
+ - **Account entrypoint**: this entrypoint encodes the payload to start an interaction through an Account Contract. It is meant to be used with accounts implementing the interface defined by `@aztec-labs/accounts`.
8
+ - **DApp entrypoint**: this encodes the payload so that it may run a dapp directly, instead of going through an account contract.
@@ -0,0 +1,59 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
3
+ import type { GasSettings } from '@aztec-labs/stdlib/gas';
4
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec-labs/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
+ };
46
+ /**
47
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
48
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
49
+ */
50
+ export declare class DefaultAccountEntrypoint implements EntrypointInterface {
51
+ #private;
52
+ private address;
53
+ private auth;
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>;
57
+ private getEntrypointAbi;
58
+ }
59
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWNjb3VudF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxxQ0FBcUMsQ0FBQztBQVN6RCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSxrQ0FBa0MsQ0FBQztBQUNyRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUMxRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQTJC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AO,EAAE,+BAA+B,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;IAuCD,OAAO,CAAC,gBAAgB;CA0DzB"}
@@ -0,0 +1,226 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { FunctionCall, FunctionSelector, encodeArguments, getFunctionReturnType } from '@aztec-labs/stdlib/abi';
3
+ import { computeOuterAuthWitHash } from '@aztec-labs/stdlib/auth-witness';
4
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec-labs/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
+ }({});
28
+ /**
29
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
30
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
31
+ */ export class DefaultAccountEntrypoint {
32
+ address;
33
+ auth;
34
+ constructor(address, auth){
35
+ this.address = address;
36
+ this.auth = auth;
37
+ }
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);
42
+ const txRequest = TxExecutionRequest.from({
43
+ firstCallArgsHash: entrypointHashedArgs.hash,
44
+ origin: this.address,
45
+ functionSelector: callData.functionSelector,
46
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
47
+ argsOfCalls: [
48
+ ...callData.encodedCalls.hashedArguments,
49
+ entrypointHashedArgs,
50
+ ...extraHashedArgs
51
+ ],
52
+ authWitnesses: [
53
+ ...authWitnesses,
54
+ callData.payloadAuthWitness
55
+ ],
56
+ capsules,
57
+ salt: Fr.random()
58
+ });
59
+ return txRequest;
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
+ returnType: getFunctionReturnType(callData.abi)
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
+ }
115
+ getEntrypointAbi() {
116
+ return {
117
+ name: 'entrypoint',
118
+ isInitializer: false,
119
+ functionType: 'private',
120
+ isOnlySelf: false,
121
+ isStatic: false,
122
+ parameters: [
123
+ {
124
+ name: 'app_payload',
125
+ type: {
126
+ kind: 'struct',
127
+ path: 'authwit::entrypoint::app::AppPayload',
128
+ fields: [
129
+ {
130
+ name: 'function_calls',
131
+ type: {
132
+ kind: 'array',
133
+ length: 5,
134
+ type: {
135
+ kind: 'struct',
136
+ path: 'authwit::entrypoint::function_call::FunctionCall',
137
+ fields: [
138
+ {
139
+ name: 'args_hash',
140
+ type: {
141
+ kind: 'field'
142
+ }
143
+ },
144
+ {
145
+ name: 'function_selector',
146
+ type: {
147
+ kind: 'struct',
148
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
149
+ fields: [
150
+ {
151
+ name: 'inner',
152
+ type: {
153
+ kind: 'integer',
154
+ sign: 'unsigned',
155
+ width: 32
156
+ }
157
+ }
158
+ ]
159
+ }
160
+ },
161
+ {
162
+ name: 'target_address',
163
+ type: {
164
+ kind: 'struct',
165
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
166
+ fields: [
167
+ {
168
+ name: 'inner',
169
+ type: {
170
+ kind: 'field'
171
+ }
172
+ }
173
+ ]
174
+ }
175
+ },
176
+ {
177
+ name: 'is_public',
178
+ type: {
179
+ kind: 'boolean'
180
+ }
181
+ },
182
+ {
183
+ name: 'hide_msg_sender',
184
+ type: {
185
+ kind: 'boolean'
186
+ }
187
+ },
188
+ {
189
+ name: 'is_static',
190
+ type: {
191
+ kind: 'boolean'
192
+ }
193
+ }
194
+ ]
195
+ }
196
+ }
197
+ },
198
+ {
199
+ name: 'tx_nonce',
200
+ type: {
201
+ kind: 'field'
202
+ }
203
+ }
204
+ ]
205
+ },
206
+ visibility: 'public'
207
+ },
208
+ {
209
+ name: 'fee_payment_method',
210
+ type: {
211
+ kind: 'integer',
212
+ sign: 'unsigned',
213
+ width: 8
214
+ }
215
+ },
216
+ {
217
+ name: 'cancellable',
218
+ type: {
219
+ kind: 'boolean'
220
+ }
221
+ }
222
+ ],
223
+ errorTypes: {}
224
+ };
225
+ }
226
+ }
@@ -0,0 +1,5 @@
1
+ /** Default L1 chain ID to use when constructing txs (matches hardhat and anvil's default). */
2
+ export declare const DEFAULT_CHAIN_ID = 31337;
3
+ /** Default protocol version to use. */
4
+ export declare const DEFAULT_VERSION = 1;
5
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uc3RhbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDhGQUE4RjtBQUM5RixlQUFPLE1BQU0sZ0JBQWdCLFFBQVEsQ0FBQztBQUN0Qyx1Q0FBdUM7QUFDdkMsZUFBTyxNQUFNLGVBQWUsSUFBSSxDQUFDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AACtC,uCAAuC;AACvC,eAAO,MAAM,eAAe,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Default L1 chain ID to use when constructing txs (matches hardhat and anvil's default). */ export const DEFAULT_CHAIN_ID = 31337;
2
+ /** Default protocol version to use. */ export const DEFAULT_VERSION = 1;
@@ -0,0 +1,11 @@
1
+ import type { GasSettings } from '@aztec-labs/stdlib/gas';
2
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec-labs/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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGVmYXVsdF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzFELE9BQU8sRUFBRSxnQkFBZ0IsRUFBMkIsa0JBQWtCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUV0RyxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUV0RTs7R0FFRztBQUNILHFCQUFhLGlCQUFrQixZQUFXLG1CQUFtQjtJQUNyRCx3QkFBd0IsQ0FDNUIsSUFBSSxFQUFFLGdCQUFnQixFQUN0QixXQUFXLEVBQUUsV0FBVyxFQUN4QixTQUFTLEVBQUUsU0FBUyxHQUNuQixPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0EyQjdCO0lBRUssb0JBQW9CLENBQUMsSUFBSSxFQUFFLGdCQUFnQixFQUFFLFVBQVUsRUFBRSxTQUFTLEVBQUUsUUFBUSxDQUFDLEVBQUUsR0FBRyxHQUFHLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxDQWdCbkg7Q0FDRiJ9
@@ -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,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEtG,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,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgBnH;CACF"}
@@ -0,0 +1,39 @@
1
+ import { FunctionType } from '@aztec-labs/stdlib/abi';
2
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec-labs/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-labs/stdlib/aztec-address';
2
+ import type { GasSettings } from '@aztec-labs/stdlib/gas';
3
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec-labs/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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9tdWx0aV9jYWxsX2VudHJ5cG9pbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9kZWZhdWx0X211bHRpX2NhbGxfZW50cnlwb2ludC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFTQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSxrQ0FBa0MsQ0FBQztBQUNyRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUMxRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQTJCLGtCQUFrQixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFHdEcsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLG1CQUFtQixFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFdEU7O0dBRUc7QUFDSCxxQkFBYSwwQkFBMkIsWUFBVyxtQkFBbUI7O0lBQ3hELE9BQU8sQ0FBQyxPQUFPO0lBQTNCLFlBQW9CLE9BQU8sR0FBRSxZQUFxRCxFQUFJO0lBRWhGLHdCQUF3QixDQUM1QixJQUFJLEVBQUUsZ0JBQWdCLEVBQ3RCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLFNBQVMsRUFBRSxTQUFTLEdBQ25CLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQWlCN0I7SUFFSyxvQkFBb0IsQ0FBQyxJQUFJLEVBQUUsZ0JBQWdCLEVBQUUsVUFBVSxFQUFFLFNBQVMsRUFBRSxRQUFRLENBQUMsRUFBRSxHQUFHLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBcUJuSDtJQTBCRCxPQUFPLENBQUMsZ0JBQWdCO0NBd0R6QiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_multi_call_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_multi_call_entrypoint.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAGtG,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,YAAqD,EAAI;IAEhF,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,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqBnH;IA0BD,OAAO,CAAC,gBAAgB;CAwDzB"}
@@ -0,0 +1,170 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec-labs/standard-contracts/multi-call-entrypoint/constants';
3
+ import { FunctionCall, FunctionSelector, encodeArguments, getFunctionReturnType } from '@aztec-labs/stdlib/abi';
4
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec-labs/stdlib/tx';
5
+ import { EncodedAppEntrypointCalls } from './encoding.js';
6
+ /**
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;
12
+ }
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);
17
+ const txRequest = TxExecutionRequest.from({
18
+ firstCallArgsHash: entrypointHashedArgs.hash,
19
+ origin: this.address,
20
+ functionSelector: callData.functionSelector,
21
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
22
+ argsOfCalls: [
23
+ ...callData.encodedCalls.hashedArguments,
24
+ entrypointHashedArgs,
25
+ ...extraHashedArgs
26
+ ],
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
+ returnType: getFunctionReturnType(callData.abi)
45
+ });
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
+ };
72
+ }
73
+ getEntrypointAbi() {
74
+ return {
75
+ name: 'entrypoint',
76
+ isInitializer: false,
77
+ functionType: 'private',
78
+ isOnlySelf: false,
79
+ isStatic: false,
80
+ parameters: [
81
+ {
82
+ name: 'app_payload',
83
+ type: {
84
+ kind: 'struct',
85
+ path: 'authwit::entrypoint::app::AppPayload',
86
+ fields: [
87
+ {
88
+ name: 'function_calls',
89
+ type: {
90
+ kind: 'array',
91
+ length: 5,
92
+ type: {
93
+ kind: 'struct',
94
+ path: 'authwit::entrypoint::function_call::FunctionCall',
95
+ fields: [
96
+ {
97
+ name: 'args_hash',
98
+ type: {
99
+ kind: 'field'
100
+ }
101
+ },
102
+ {
103
+ name: 'function_selector',
104
+ type: {
105
+ kind: 'struct',
106
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
107
+ fields: [
108
+ {
109
+ name: 'inner',
110
+ type: {
111
+ kind: 'integer',
112
+ sign: 'unsigned',
113
+ width: 32
114
+ }
115
+ }
116
+ ]
117
+ }
118
+ },
119
+ {
120
+ name: 'target_address',
121
+ type: {
122
+ kind: 'struct',
123
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
124
+ fields: [
125
+ {
126
+ name: 'inner',
127
+ type: {
128
+ kind: 'field'
129
+ }
130
+ }
131
+ ]
132
+ }
133
+ },
134
+ {
135
+ name: 'is_public',
136
+ type: {
137
+ kind: 'boolean'
138
+ }
139
+ },
140
+ {
141
+ name: 'hide_msg_sender',
142
+ type: {
143
+ kind: 'boolean'
144
+ }
145
+ },
146
+ {
147
+ name: 'is_static',
148
+ type: {
149
+ kind: 'boolean'
150
+ }
151
+ }
152
+ ]
153
+ }
154
+ }
155
+ },
156
+ {
157
+ name: 'tx_nonce',
158
+ type: {
159
+ kind: 'field'
160
+ }
161
+ }
162
+ ]
163
+ },
164
+ visibility: 'public'
165
+ }
166
+ ],
167
+ errorTypes: {}
168
+ };
169
+ }
170
+ }