@aztec/entrypoints 0.0.1-commit.b655e406 → 0.0.1-commit.d1f2d6c

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,9 +1,8 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { GasSettings } from '@aztec/stdlib/gas';
4
- import { TxExecutionRequest } from '@aztec/stdlib/tx';
5
- import type { AuthWitnessProvider, EntrypointInterface } from './interfaces.js';
6
- import { ExecutionPayload } from './payload.js';
4
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
7
6
  /**
8
7
  * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
9
8
  */
@@ -49,12 +48,12 @@ export type DefaultAccountEntrypointOptions = {
49
48
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
50
49
  */
51
50
  export declare class DefaultAccountEntrypoint implements EntrypointInterface {
51
+ #private;
52
52
  private address;
53
53
  private auth;
54
- private chainId;
55
- private version;
56
- constructor(address: AztecAddress, auth: AuthWitnessProvider, chainId?: number, version?: number);
57
- createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, options: DefaultAccountEntrypointOptions): 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>;
58
57
  private getEntrypointAbi;
59
58
  }
60
- //# sourceMappingURL=account_entrypoint.d.ts.map
59
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJza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a,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,7 +1,6 @@
1
- import { Fr } from '@aztec/foundation/fields';
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';
5
4
  import { EncodedAppEntrypointCalls } from './encoding.js';
6
5
  /**
7
6
  * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
@@ -31,56 +30,81 @@ import { EncodedAppEntrypointCalls } from './encoding.js';
31
30
  */ export class DefaultAccountEntrypoint {
32
31
  address;
33
32
  auth;
34
- chainId;
35
- version;
36
- constructor(address, auth, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
33
+ constructor(address, auth){
37
34
  this.address = address;
38
35
  this.auth = auth;
39
- this.chainId = chainId;
40
- this.version = version;
41
36
  }
42
- async createTxExecutionRequest(exec, gasSettings, options) {
43
- // Initial request with calls, authWitnesses and capsules
44
- const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
45
- // Global tx options
46
- const { cancellable, txNonce, feePaymentMethodOptions } = options;
47
- // Encode the calls for the app
48
- const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
49
- // Obtain the entrypoint hashed args, built from the app encoded calls and global options
50
- const abi = this.getEntrypointAbi();
51
- const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
52
- encodedCalls,
53
- feePaymentMethodOptions,
54
- !!cancellable
55
- ]));
56
- // Generate the payload auth witness, by signing the hash of the payload
57
- const appPayloadAuthwitness = await this.auth.createAuthWit(await encodedCalls.hash());
58
- // Assemble the tx request
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);
59
41
  const txRequest = TxExecutionRequest.from({
60
42
  firstCallArgsHash: entrypointHashedArgs.hash,
61
43
  origin: this.address,
62
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
63
- txContext: new TxContext(this.chainId, this.version, gasSettings),
44
+ functionSelector: callData.functionSelector,
45
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
64
46
  argsOfCalls: [
65
- ...encodedCalls.hashedArguments,
47
+ ...callData.encodedCalls.hashedArguments,
66
48
  entrypointHashedArgs,
67
49
  ...extraHashedArgs
68
50
  ],
69
51
  authWitnesses: [
70
52
  ...authWitnesses,
71
- appPayloadAuthwitness
53
+ callData.payloadAuthWitness
72
54
  ],
73
55
  capsules,
74
56
  salt: Fr.random()
75
57
  });
76
58
  return txRequest;
77
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
+ }
78
102
  getEntrypointAbi() {
79
103
  return {
80
104
  name: 'entrypoint',
81
105
  isInitializer: false,
82
106
  functionType: 'private',
83
- isInternal: false,
107
+ isOnlySelf: false,
84
108
  isStatic: false,
85
109
  parameters: [
86
110
  {
@@ -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=
@@ -1,14 +1,11 @@
1
1
  import type { GasSettings } from '@aztec/stdlib/gas';
2
- import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
- import type { EntrypointInterface } from './interfaces.js';
4
- import type { ExecutionPayload } from './payload.js';
2
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { ChainInfo, EntrypointInterface } from './interfaces.js';
5
4
  /**
6
5
  * Default implementation of the entrypoint interface. It calls a function on a contract directly
7
6
  */
8
7
  export declare class DefaultEntrypoint implements EntrypointInterface {
9
- private chainId;
10
- private rollupVersion;
11
- constructor(chainId: number, rollupVersion: number);
12
- createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest>;
8
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo): Promise<TxExecutionRequest>;
9
+ wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload>;
13
10
  }
14
- //# sourceMappingURL=default_entrypoint.d.ts.map
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGVmYXVsdF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sRUFBRSxnQkFBZ0IsRUFBMkIsa0JBQWtCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUVqRyxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUV0RTs7R0FFRztBQUNILHFCQUFhLGlCQUFrQixZQUFXLG1CQUFtQjtJQUNyRCx3QkFBd0IsQ0FDNUIsSUFBSSxFQUFFLGdCQUFnQixFQUN0QixXQUFXLEVBQUUsV0FBVyxFQUN4QixTQUFTLEVBQUUsU0FBUyxHQUNuQixPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0EyQjdCO0lBRUssb0JBQW9CLENBQUMsSUFBSSxFQUFFLGdCQUFnQixFQUFFLFFBQVEsQ0FBQyxFQUFFLEdBQUcsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FnQjVGO0NBQ0YifQ==
@@ -1 +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,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,mBAAmB;IAEzD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,aAAa;gBADb,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM;IAGzB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA4B9G"}
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"}
@@ -1,15 +1,9 @@
1
1
  import { FunctionType } from '@aztec/stdlib/abi';
2
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
2
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
3
  /**
4
4
  * Default implementation of the entrypoint interface. It calls a function on a contract directly
5
5
  */ export class DefaultEntrypoint {
6
- chainId;
7
- rollupVersion;
8
- constructor(chainId, rollupVersion){
9
- this.chainId = chainId;
10
- this.rollupVersion = rollupVersion;
11
- }
12
- async createTxExecutionRequest(exec, gasSettings) {
6
+ async createTxExecutionRequest(exec, gasSettings, chainInfo) {
13
7
  // Initial request with calls, authWitnesses and capsules
14
8
  const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
15
9
  if (calls.length > 1) {
@@ -24,9 +18,22 @@ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
24
18
  throw new Error('Public entrypoints are not allowed');
25
19
  }
26
20
  // Assemble the tx request
27
- return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(this.chainId, this.rollupVersion, gasSettings), [
21
+ return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings), [
28
22
  ...hashedArguments,
29
23
  ...extraHashedArgs
30
24
  ], authWitnesses, capsules);
31
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
+ }
32
39
  }
@@ -1,17 +1,16 @@
1
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
2
  import type { GasSettings } from '@aztec/stdlib/gas';
3
- import { TxExecutionRequest } from '@aztec/stdlib/tx';
4
- import type { EntrypointInterface } from './interfaces.js';
5
- import type { ExecutionPayload } from './payload.js';
3
+ import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import type { ChainInfo, EntrypointInterface } from './interfaces.js';
6
5
  /**
7
6
  * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
8
7
  */
9
8
  export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
10
- private chainId;
11
- private version;
9
+ #private;
12
10
  private address;
13
- constructor(chainId: number, version: number, address?: AztecAddress);
14
- createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest>;
11
+ constructor(address?: AztecAddress);
12
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo): Promise<TxExecutionRequest>;
13
+ wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload>;
15
14
  private getEntrypointAbi;
16
15
  }
17
- //# sourceMappingURL=default_multi_call_entrypoint.d.ts.map
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9tdWx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AgB,CAAC,CAqB5F;IA0BD,OAAO,CAAC,gBAAgB;CAyDzB"}
@@ -1,37 +1,26 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import { FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
5
  import { EncodedAppEntrypointCalls } from './encoding.js';
6
6
  /**
7
7
  * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
8
8
  */ export class DefaultMultiCallEntrypoint {
9
- chainId;
10
- version;
11
9
  address;
12
- constructor(chainId, version, address = ProtocolContractAddress.MultiCallEntrypoint){
13
- this.chainId = chainId;
14
- this.version = version;
10
+ constructor(address = ProtocolContractAddress.MultiCallEntrypoint){
15
11
  this.address = address;
16
12
  }
17
- async createTxExecutionRequest(exec, gasSettings) {
18
- // Initial request with calls, authWitnesses and capsules
19
- const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
20
- // Encode the calls for the app
21
- const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
22
- // Obtain the entrypoint hashed args, built from the encoded calls
23
- const abi = this.getEntrypointAbi();
24
- const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
25
- encodedCalls
26
- ]));
27
- // Assemble the tx request
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);
28
17
  const txRequest = TxExecutionRequest.from({
29
18
  firstCallArgsHash: entrypointHashedArgs.hash,
30
19
  origin: this.address,
31
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
32
- txContext: new TxContext(this.chainId, this.version, gasSettings),
20
+ functionSelector: callData.functionSelector,
21
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
33
22
  argsOfCalls: [
34
- ...encodedCalls.hashedArguments,
23
+ ...callData.encodedCalls.hashedArguments,
35
24
  entrypointHashedArgs,
36
25
  ...extraHashedArgs
37
26
  ],
@@ -41,12 +30,43 @@ import { EncodedAppEntrypointCalls } from './encoding.js';
41
30
  });
42
31
  return Promise.resolve(txRequest);
43
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
+ }
44
64
  getEntrypointAbi() {
45
65
  return {
46
66
  name: 'entrypoint',
47
67
  isInitializer: false,
48
68
  functionType: 'private',
49
- isInternal: false,
69
+ isOnlySelf: false,
50
70
  isStatic: false,
51
71
  parameters: [
52
72
  {
@@ -1,8 +1,8 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { Tuple } from '@aztec/foundation/serialize';
3
3
  import { FunctionCall } from '@aztec/stdlib/abi';
4
4
  import { HashedValues } from '@aztec/stdlib/tx';
5
- declare const APP_MAX_CALLS = 5;
5
+ export declare const APP_MAX_CALLS = 5;
6
6
  /** Encoded function call for an Aztec entrypoint */
7
7
  export type EncodedFunctionCall = {
8
8
  /** Arguments hash for the call. */
@@ -85,5 +85,4 @@ export declare class EncodedAppEntrypointCalls implements EncodedCalls {
85
85
  }
86
86
  /** Encodes FunctionCalls for execution, following Noir's convention */
87
87
  export declare function encode(calls: FunctionCall[]): Promise<EncodedCalls>;
88
- export {};
89
- //# sourceMappingURL=encoding.d.ts.map
88
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW5jb2RpbmcuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9lbmNvZGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDekQsT0FBTyxFQUFFLFlBQVksRUFBZ0IsTUFBTSxtQkFBbUIsQ0FBQztBQUMvRCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFJaEQsZUFBTyxNQUFNLGFBQWEsSUFBSSxDQUFDO0FBRS9CLG9EQUFvRDtBQUNwRCxNQUFNLE1BQU0sbUJBQW1CLEdBQUc7SUFDaEMsbUNBQW1DO0lBQ25DLG9HQUFvRztJQUNwRyxTQUFTLEVBQUUsRUFBRSxDQUFDO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EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAwBzE"}
package/dest/encoding.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { GeneratorIndex } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
4
- import { Fr } from '@aztec/foundation/fields';
3
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { FunctionCall, FunctionType } from '@aztec/stdlib/abi';
6
6
  import { HashedValues } from '@aztec/stdlib/tx';
7
7
  // These must match the values defined in:
8
8
  // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr
9
- const APP_MAX_CALLS = 5;
9
+ export const APP_MAX_CALLS = 5;
10
10
  /**
11
11
  * Entrypoints derive their arguments from the calls that they'll ultimate make.
12
12
  * This utility class helps in creating the payload for the entrypoint by taking into
package/dest/index.d.ts CHANGED
@@ -10,4 +10,4 @@ export * from './interfaces.js';
10
10
  export * from './default_entrypoint.js';
11
11
  export * from './encoding.js';
12
12
  export * from './default_multi_call_entrypoint.js';
13
- //# sourceMappingURL=index.d.ts.map
13
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxjQUFjLHlCQUF5QixDQUFDO0FBQ3hDLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLG9DQUFvQyxDQUFDIn0=
@@ -1,8 +1,8 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
3
  import type { GasSettings } from '@aztec/stdlib/gas';
4
- import type { TxExecutionRequest } from '@aztec/stdlib/tx';
5
- import type { ExecutionPayload } from './payload.js';
4
+ import type { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import { z } from 'zod';
6
6
  /**
7
7
  * Information on the connected chain. Used by wallets when constructing transactions to protect against replay
8
8
  * attacks.
@@ -13,6 +13,19 @@ export type ChainInfo = {
13
13
  /** The version of the rollup */
14
14
  version: Fr;
15
15
  };
16
+ /**
17
+ * Zod schema for ChainInfo
18
+ */
19
+ export declare const ChainInfoSchema: z.ZodObject<{
20
+ chainId: z.ZodType<Fr, any, string>;
21
+ version: z.ZodType<Fr, any, string>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ chainId: Fr;
24
+ version: Fr;
25
+ }, {
26
+ chainId: string;
27
+ version: string;
28
+ }>;
16
29
  /**
17
30
  * Creates transaction execution requests out of a set of function calls, a fee payment method and
18
31
  * general options for the transaction
@@ -22,10 +35,23 @@ export interface EntrypointInterface {
22
35
  * Generates an execution request out of set of function calls.
23
36
  * @param exec - The execution intents to be run.
24
37
  * @param gasSettings - The gas settings for the transaction.
38
+ * @param chainInfo - Chain information (chainId and version) for replay protection.
25
39
  * @param options - Miscellaneous tx options that enable/disable features of the entrypoint
26
40
  * @returns The authenticated transaction execution request.
27
41
  */
28
- createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, options?: any): Promise<TxExecutionRequest>;
42
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo, options?: any): Promise<TxExecutionRequest>;
43
+ /**
44
+ * Wraps an execution payload such that it is executed *via* this entrypoint.
45
+ * This returns an ExecutionPayload with the entrypoint as the caller for the wrapped payload.
46
+ * Useful for account self-funding deployments and batching calls beyond the limit
47
+ * of a single entrypoint call.
48
+ *
49
+ * @param exec - The execution payload to wrap
50
+ * @param options - Implementation-specific options
51
+ * @returns A new execution payload with a single call to this entrypoint
52
+ * @throws Error if the payload cannot be wrapped (e.g., exceeds call limit)
53
+ */
54
+ wrapExecutionPayload(exec: ExecutionPayload, options?: any): Promise<ExecutionPayload>;
29
55
  }
30
56
  /** Creates authorization witnesses. */
31
57
  export interface AuthWitnessProvider {
@@ -36,4 +62,4 @@ export interface AuthWitnessProvider {
36
62
  */
37
63
  createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
38
64
  }
39
- //# sourceMappingURL=interfaces.d.ts.map
65
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFN0UsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4Qjs7O0dBR0c7QUFDSCxNQUFNLE1BQU0sU0FBUyxHQUFHO0lBQ3RCLHNCQUFzQjtJQUN0QixPQUFPLEVBQUUsRUFBRSxDQUFDO0lBQ1osaUNBQWlDO0lBQ2pDLE9BQU8sRUFBRSxFQUFFLENBQUM7Q0FDYixDQUFDO0FBRUY7O0dBRUc7QUFDSCxlQUFPLE1BQU0sZUFBZTs7Ozs7Ozs7O0VBRzFCLENBQUM7QUFFSDs7O0dBR0c7QUFDSCxNQUFNLFdBQVcsbUJBQW1C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,aAAa,CAAC,WAAW,EAAE,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/D"}
@@ -1 +1,8 @@
1
- /** Creates authorization witnesses. */ export { };
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { z } from 'zod';
3
+ /**
4
+ * Zod schema for ChainInfo
5
+ */ export const ChainInfoSchema = z.object({
6
+ chainId: Fr.schema,
7
+ version: Fr.schema
8
+ });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@aztec/entrypoints",
3
3
  "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/entrypoints",
4
4
  "description": "Implementation of sample contract entrypoints for the Aztec Network",
5
- "version": "0.0.1-commit.b655e406",
5
+ "version": "0.0.1-commit.d1f2d6c",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  "./account": "./dest/account_entrypoint.js",
@@ -20,9 +20,9 @@
20
20
  "tsconfig": "./tsconfig.json"
21
21
  },
22
22
  "scripts": {
23
- "build": "yarn clean && tsc -b",
24
- "build:dev": "tsc -b --watch",
25
- "build:ts": "tsc -b",
23
+ "build": "yarn clean && ../scripts/tsc.sh",
24
+ "build:dev": "../scripts/tsc.sh --watch",
25
+ "build:ts": "../scripts/tsc.sh",
26
26
  "clean": "rm -rf ./dest .tsbuildinfo",
27
27
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
28
28
  },
@@ -67,15 +67,17 @@
67
67
  ]
68
68
  },
69
69
  "dependencies": {
70
- "@aztec/constants": "0.0.1-commit.b655e406",
71
- "@aztec/foundation": "0.0.1-commit.b655e406",
72
- "@aztec/protocol-contracts": "0.0.1-commit.b655e406",
73
- "@aztec/stdlib": "0.0.1-commit.b655e406",
74
- "tslib": "^2.4.0"
70
+ "@aztec/constants": "0.0.1-commit.d1f2d6c",
71
+ "@aztec/foundation": "0.0.1-commit.d1f2d6c",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.d1f2d6c",
73
+ "@aztec/stdlib": "0.0.1-commit.d1f2d6c",
74
+ "tslib": "^2.4.0",
75
+ "zod": "^3.23.8"
75
76
  },
76
77
  "devDependencies": {
77
78
  "@jest/globals": "^30.0.0",
78
79
  "@types/jest": "^30.0.0",
80
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
79
81
  "jest": "^30.0.0",
80
82
  "ts-node": "^10.9.1",
81
83
  "typescript": "^5.3.3"
@@ -1,13 +1,11 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type FunctionAbi, FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { GasSettings } from '@aztec/stdlib/gas';
5
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
6
6
 
7
- import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
8
7
  import { EncodedAppEntrypointCalls } from './encoding.js';
9
- import type { AuthWitnessProvider, EntrypointInterface } from './interfaces.js';
10
- import { ExecutionPayload } from './payload.js';
8
+ import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
11
9
 
12
10
  /**
13
11
  * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
@@ -59,39 +57,24 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
59
57
  constructor(
60
58
  private address: AztecAddress,
61
59
  private auth: AuthWitnessProvider,
62
- private chainId: number = DEFAULT_CHAIN_ID,
63
- private version: number = DEFAULT_VERSION,
64
60
  ) {}
65
61
 
66
62
  async createTxExecutionRequest(
67
63
  exec: ExecutionPayload,
68
64
  gasSettings: GasSettings,
65
+ chainInfo: ChainInfo,
69
66
  options: DefaultAccountEntrypointOptions,
70
67
  ): Promise<TxExecutionRequest> {
71
- // Initial request with calls, authWitnesses and capsules
72
- const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
73
- // Global tx options
74
- const { cancellable, txNonce, feePaymentMethodOptions } = options;
75
- // Encode the calls for the app
76
- const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
77
-
78
- // Obtain the entrypoint hashed args, built from the app encoded calls and global options
79
- const abi = this.getEntrypointAbi();
80
- const entrypointHashedArgs = await HashedValues.fromArgs(
81
- encodeArguments(abi, [encodedCalls, feePaymentMethodOptions, !!cancellable]),
82
- );
83
-
84
- // Generate the payload auth witness, by signing the hash of the payload
85
- const appPayloadAuthwitness = await this.auth.createAuthWit(await encodedCalls.hash());
86
-
87
- // Assemble the tx request
68
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
69
+ const callData = await this.#buildEntrypointCallData(exec, options);
70
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
88
71
  const txRequest = TxExecutionRequest.from({
89
72
  firstCallArgsHash: entrypointHashedArgs.hash,
90
73
  origin: this.address,
91
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
92
- txContext: new TxContext(this.chainId, this.version, gasSettings),
93
- argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
94
- authWitnesses: [...authWitnesses, appPayloadAuthwitness],
74
+ functionSelector: callData.functionSelector,
75
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
76
+ argsOfCalls: [...callData.encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
77
+ authWitnesses: [...authWitnesses, callData.payloadAuthWitness],
95
78
  capsules,
96
79
  salt: Fr.random(),
97
80
  });
@@ -99,12 +82,70 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
99
82
  return txRequest;
100
83
  }
101
84
 
85
+ async wrapExecutionPayload(
86
+ exec: ExecutionPayload,
87
+ options: DefaultAccountEntrypointOptions,
88
+ ): Promise<ExecutionPayload> {
89
+ const { authWitnesses, capsules, extraHashedArgs, feePayer } = exec;
90
+ const callData = await this.#buildEntrypointCallData(exec, options);
91
+
92
+ // Build the entrypoint function call
93
+ const entrypointCall = new FunctionCall(
94
+ callData.abi.name,
95
+ this.address,
96
+ callData.functionSelector,
97
+ callData.abi.functionType,
98
+ false,
99
+ callData.abi.isStatic,
100
+ callData.encodedArgs,
101
+ callData.abi.returnTypes,
102
+ );
103
+
104
+ return new ExecutionPayload(
105
+ [entrypointCall],
106
+ [callData.payloadAuthWitness, ...authWitnesses],
107
+ capsules,
108
+ [...callData.encodedCalls.hashedArguments, ...extraHashedArgs],
109
+ feePayer ?? this.address,
110
+ );
111
+ }
112
+
113
+ /**
114
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
115
+ * This includes encoding calls, building entrypoint arguments, and creating the authwitness.
116
+ * @param exec - The execution payload containing calls to encode
117
+ * @param options - Account entrypoint options including tx nonce and fee payment method
118
+ * @returns Encoded call data, ABI, function selector, and auth witness
119
+ */
120
+ async #buildEntrypointCallData(exec: ExecutionPayload, options: DefaultAccountEntrypointOptions) {
121
+ const { calls } = exec;
122
+ const { cancellable, txNonce, feePaymentMethodOptions } = options;
123
+
124
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
125
+
126
+ const abi = this.getEntrypointAbi();
127
+ const args = [encodedCalls, feePaymentMethodOptions, !!cancellable];
128
+ const encodedArgs = encodeArguments(abi, args);
129
+
130
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
131
+
132
+ const payloadAuthWitness = await this.auth.createAuthWit(await encodedCalls.hash());
133
+
134
+ return {
135
+ encodedCalls,
136
+ abi,
137
+ encodedArgs,
138
+ functionSelector,
139
+ payloadAuthWitness,
140
+ };
141
+ }
142
+
102
143
  private getEntrypointAbi() {
103
144
  return {
104
145
  name: 'entrypoint',
105
146
  isInitializer: false,
106
147
  functionType: 'private',
107
- isInternal: false,
148
+ isOnlySelf: false,
108
149
  isStatic: false,
109
150
  parameters: [
110
151
  {
@@ -1,20 +1,18 @@
1
1
  import { FunctionType } from '@aztec/stdlib/abi';
2
2
  import type { GasSettings } from '@aztec/stdlib/gas';
3
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
4
 
5
- import type { EntrypointInterface } from './interfaces.js';
6
- import type { ExecutionPayload } from './payload.js';
5
+ import type { ChainInfo, EntrypointInterface } from './interfaces.js';
7
6
 
8
7
  /**
9
8
  * Default implementation of the entrypoint interface. It calls a function on a contract directly
10
9
  */
11
10
  export class DefaultEntrypoint implements EntrypointInterface {
12
- constructor(
13
- private chainId: number,
14
- private rollupVersion: number,
15
- ) {}
16
-
17
- async createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest> {
11
+ async createTxExecutionRequest(
12
+ exec: ExecutionPayload,
13
+ gasSettings: GasSettings,
14
+ chainInfo: ChainInfo,
15
+ ): Promise<TxExecutionRequest> {
18
16
  // Initial request with calls, authWitnesses and capsules
19
17
  const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
20
18
 
@@ -36,10 +34,28 @@ export class DefaultEntrypoint implements EntrypointInterface {
36
34
  call.to,
37
35
  call.selector,
38
36
  hashedArguments[0].hash,
39
- new TxContext(this.chainId, this.rollupVersion, gasSettings),
37
+ new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
40
38
  [...hashedArguments, ...extraHashedArgs],
41
39
  authWitnesses,
42
40
  capsules,
43
41
  );
44
42
  }
43
+
44
+ async wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload> {
45
+ if (exec.calls.length !== 1) {
46
+ throw new Error(`DefaultEntrypoint can only wrap a single call, got ${exec.calls.length}`);
47
+ }
48
+
49
+ const call = exec.calls[0];
50
+
51
+ const hashedArguments = await HashedValues.fromArgs(call.args);
52
+
53
+ return new ExecutionPayload(
54
+ [call],
55
+ exec.authWitnesses,
56
+ exec.capsules,
57
+ [hashedArguments, ...exec.extraHashedArgs],
58
+ exec.feePayer,
59
+ );
60
+ }
45
61
  }
@@ -1,42 +1,34 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import { type FunctionAbi, FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { GasSettings } from '@aztec/stdlib/gas';
6
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
6
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
7
7
 
8
8
  import { EncodedAppEntrypointCalls } from './encoding.js';
9
- import type { EntrypointInterface } from './interfaces.js';
10
- import type { ExecutionPayload } from './payload.js';
9
+ import type { ChainInfo, EntrypointInterface } from './interfaces.js';
11
10
 
12
11
  /**
13
12
  * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
14
13
  */
15
14
  export class DefaultMultiCallEntrypoint implements EntrypointInterface {
16
- constructor(
17
- private chainId: number,
18
- private version: number,
19
- private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
20
- ) {}
15
+ constructor(private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint) {}
21
16
 
22
- async createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest> {
23
- // Initial request with calls, authWitnesses and capsules
24
- const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
17
+ async createTxExecutionRequest(
18
+ exec: ExecutionPayload,
19
+ gasSettings: GasSettings,
20
+ chainInfo: ChainInfo,
21
+ ): Promise<TxExecutionRequest> {
22
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
23
+ const callData = await this.#buildEntrypointCallData(exec);
25
24
 
26
- // Encode the calls for the app
27
- const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
28
-
29
- // Obtain the entrypoint hashed args, built from the encoded calls
30
- const abi = this.getEntrypointAbi();
31
- const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [encodedCalls]));
32
-
33
- // Assemble the tx request
25
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
34
26
  const txRequest = TxExecutionRequest.from({
35
27
  firstCallArgsHash: entrypointHashedArgs.hash,
36
28
  origin: this.address,
37
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
38
- txContext: new TxContext(this.chainId, this.version, gasSettings),
39
- argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
29
+ functionSelector: callData.functionSelector,
30
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
31
+ argsOfCalls: [...callData.encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
40
32
  authWitnesses,
41
33
  capsules,
42
34
  salt: Fr.random(),
@@ -45,12 +37,59 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
45
37
  return Promise.resolve(txRequest);
46
38
  }
47
39
 
40
+ async wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload> {
41
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
42
+ const callData = await this.#buildEntrypointCallData(exec);
43
+ const entrypointCall = new FunctionCall(
44
+ callData.abi.name,
45
+ this.address,
46
+ callData.functionSelector,
47
+ callData.abi.functionType,
48
+ false,
49
+ callData.abi.isStatic,
50
+ callData.encodedArgs,
51
+ callData.abi.returnTypes,
52
+ );
53
+
54
+ return new ExecutionPayload(
55
+ [entrypointCall],
56
+ authWitnesses,
57
+ capsules,
58
+ [...callData.encodedCalls.hashedArguments, ...extraHashedArgs],
59
+ exec.feePayer,
60
+ );
61
+ }
62
+
63
+ /**
64
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
65
+ * This includes encoding calls and building entrypoint arguments.
66
+ * @param exec - The execution payload containing calls to encode
67
+ * @returns Encoded call data, ABI, encoded arguments, and function selector
68
+ */
69
+ async #buildEntrypointCallData(exec: ExecutionPayload) {
70
+ const { calls } = exec;
71
+
72
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
73
+
74
+ const abi = this.getEntrypointAbi();
75
+ const encodedArgs = encodeArguments(abi, [encodedCalls]);
76
+
77
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
78
+
79
+ return {
80
+ encodedCalls,
81
+ abi,
82
+ encodedArgs,
83
+ functionSelector,
84
+ };
85
+ }
86
+
48
87
  private getEntrypointAbi() {
49
88
  return {
50
89
  name: 'entrypoint',
51
90
  isInitializer: false,
52
91
  functionType: 'private',
53
- isInternal: false,
92
+ isOnlySelf: false,
54
93
  isStatic: false,
55
94
  parameters: [
56
95
  {
package/src/encoding.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { GeneratorIndex } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
4
- import { Fr } from '@aztec/foundation/fields';
3
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import type { Tuple } from '@aztec/foundation/serialize';
6
6
  import { FunctionCall, FunctionType } from '@aztec/stdlib/abi';
7
7
  import { HashedValues } from '@aztec/stdlib/tx';
8
8
 
9
9
  // These must match the values defined in:
10
10
  // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr
11
- const APP_MAX_CALLS = 5;
11
+ export const APP_MAX_CALLS = 5;
12
12
 
13
13
  /** Encoded function call for an Aztec entrypoint */
14
14
  export type EncodedFunctionCall = {
package/src/interfaces.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
3
  import type { GasSettings } from '@aztec/stdlib/gas';
4
- import type { TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import type { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
5
5
 
6
- import type { ExecutionPayload } from './payload.js';
6
+ import { z } from 'zod';
7
7
 
8
8
  /**
9
9
  * Information on the connected chain. Used by wallets when constructing transactions to protect against replay
@@ -16,6 +16,14 @@ export type ChainInfo = {
16
16
  version: Fr;
17
17
  };
18
18
 
19
+ /**
20
+ * Zod schema for ChainInfo
21
+ */
22
+ export const ChainInfoSchema = z.object({
23
+ chainId: Fr.schema,
24
+ version: Fr.schema,
25
+ });
26
+
19
27
  /**
20
28
  * Creates transaction execution requests out of a set of function calls, a fee payment method and
21
29
  * general options for the transaction
@@ -25,14 +33,29 @@ export interface EntrypointInterface {
25
33
  * Generates an execution request out of set of function calls.
26
34
  * @param exec - The execution intents to be run.
27
35
  * @param gasSettings - The gas settings for the transaction.
36
+ * @param chainInfo - Chain information (chainId and version) for replay protection.
28
37
  * @param options - Miscellaneous tx options that enable/disable features of the entrypoint
29
38
  * @returns The authenticated transaction execution request.
30
39
  */
31
40
  createTxExecutionRequest(
32
41
  exec: ExecutionPayload,
33
42
  gasSettings: GasSettings,
43
+ chainInfo: ChainInfo,
34
44
  options?: any,
35
45
  ): Promise<TxExecutionRequest>;
46
+
47
+ /**
48
+ * Wraps an execution payload such that it is executed *via* this entrypoint.
49
+ * This returns an ExecutionPayload with the entrypoint as the caller for the wrapped payload.
50
+ * Useful for account self-funding deployments and batching calls beyond the limit
51
+ * of a single entrypoint call.
52
+ *
53
+ * @param exec - The execution payload to wrap
54
+ * @param options - Implementation-specific options
55
+ * @returns A new execution payload with a single call to this entrypoint
56
+ * @throws Error if the payload cannot be wrapped (e.g., exceeds call limit)
57
+ */
58
+ wrapExecutionPayload(exec: ExecutionPayload, options?: any): Promise<ExecutionPayload>;
36
59
  }
37
60
 
38
61
  /** Creates authorization witnesses. */
package/dest/payload.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { FunctionCall } from '@aztec/stdlib/abi';
2
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
- import { Capsule, HashedValues } from '@aztec/stdlib/tx';
4
- /**
5
- * Represents data necessary to perform an action in the network successfully.
6
- * This class can be considered Aztec's "minimal execution unit".
7
- * */
8
- export declare class ExecutionPayload {
9
- /** The function calls to be executed. */
10
- calls: FunctionCall[];
11
- /** Any transient auth witnesses needed for this execution */
12
- authWitnesses: AuthWitness[];
13
- /** Data passed through an oracle for this execution. */
14
- capsules: Capsule[];
15
- /** Extra hashed values to be injected in the execution cache */
16
- extraHashedArgs: HashedValues[];
17
- constructor(
18
- /** The function calls to be executed. */
19
- calls: FunctionCall[],
20
- /** Any transient auth witnesses needed for this execution */
21
- authWitnesses: AuthWitness[],
22
- /** Data passed through an oracle for this execution. */
23
- capsules: Capsule[],
24
- /** Extra hashed values to be injected in the execution cache */
25
- extraHashedArgs?: HashedValues[]);
26
- static empty(): ExecutionPayload;
27
- }
28
- /**
29
- * Merges an array ExecutionPayloads combining their calls, authWitnesses, capsules and extraArgHashes.
30
- */
31
- export declare function mergeExecutionPayloads(requests: ExecutionPayload[]): ExecutionPayload;
32
- //# sourceMappingURL=payload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../src/payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;KAGK;AACL,qBAAa,gBAAgB;IAEzB,yCAAyC;IAClC,KAAK,EAAE,YAAY,EAAE;IAC5B,6DAA6D;IACtD,aAAa,EAAE,WAAW,EAAE;IACnC,wDAAwD;IACjD,QAAQ,EAAE,OAAO,EAAE;IAC1B,gEAAgE;IACzD,eAAe,EAAE,YAAY,EAAE;;IAPtC,yCAAyC;IAClC,KAAK,EAAE,YAAY,EAAE;IAC5B,6DAA6D;IACtD,aAAa,EAAE,WAAW,EAAE;IACnC,wDAAwD;IACjD,QAAQ,EAAE,OAAO,EAAE;IAC1B,gEAAgE;IACzD,eAAe,GAAE,YAAY,EAAO;IAG7C,MAAM,CAAC,KAAK;CAGb;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAMrF"}
package/dest/payload.js DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * Represents data necessary to perform an action in the network successfully.
3
- * This class can be considered Aztec's "minimal execution unit".
4
- * */ export class ExecutionPayload {
5
- calls;
6
- authWitnesses;
7
- capsules;
8
- extraHashedArgs;
9
- constructor(/** The function calls to be executed. */ calls, /** Any transient auth witnesses needed for this execution */ authWitnesses, /** Data passed through an oracle for this execution. */ capsules, /** Extra hashed values to be injected in the execution cache */ extraHashedArgs = []){
10
- this.calls = calls;
11
- this.authWitnesses = authWitnesses;
12
- this.capsules = capsules;
13
- this.extraHashedArgs = extraHashedArgs;
14
- }
15
- static empty() {
16
- return new ExecutionPayload([], [], []);
17
- }
18
- }
19
- /**
20
- * Merges an array ExecutionPayloads combining their calls, authWitnesses, capsules and extraArgHashes.
21
- */ export function mergeExecutionPayloads(requests) {
22
- const calls = requests.map((r)=>r.calls).flat();
23
- const combinedAuthWitnesses = requests.map((r)=>r.authWitnesses ?? []).flat();
24
- const combinedCapsules = requests.map((r)=>r.capsules ?? []).flat();
25
- const combinedextraHashedArgs = requests.map((r)=>r.extraHashedArgs ?? []).flat();
26
- return new ExecutionPayload(calls, combinedAuthWitnesses, combinedCapsules, combinedextraHashedArgs);
27
- }
package/src/payload.ts DELETED
@@ -1,35 +0,0 @@
1
- import { FunctionCall } from '@aztec/stdlib/abi';
2
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
- import { Capsule, HashedValues } from '@aztec/stdlib/tx';
4
-
5
- /**
6
- * Represents data necessary to perform an action in the network successfully.
7
- * This class can be considered Aztec's "minimal execution unit".
8
- * */
9
- export class ExecutionPayload {
10
- public constructor(
11
- /** The function calls to be executed. */
12
- public calls: FunctionCall[],
13
- /** Any transient auth witnesses needed for this execution */
14
- public authWitnesses: AuthWitness[],
15
- /** Data passed through an oracle for this execution. */
16
- public capsules: Capsule[],
17
- /** Extra hashed values to be injected in the execution cache */
18
- public extraHashedArgs: HashedValues[] = [],
19
- ) {}
20
-
21
- static empty() {
22
- return new ExecutionPayload([], [], []);
23
- }
24
- }
25
-
26
- /**
27
- * Merges an array ExecutionPayloads combining their calls, authWitnesses, capsules and extraArgHashes.
28
- */
29
- export function mergeExecutionPayloads(requests: ExecutionPayload[]): ExecutionPayload {
30
- const calls = requests.map(r => r.calls).flat();
31
- const combinedAuthWitnesses = requests.map(r => r.authWitnesses ?? []).flat();
32
- const combinedCapsules = requests.map(r => r.capsules ?? []).flat();
33
- const combinedextraHashedArgs = requests.map(r => r.extraHashedArgs ?? []).flat();
34
- return new ExecutionPayload(calls, combinedAuthWitnesses, combinedCapsules, combinedextraHashedArgs);
35
- }