@aztec/entrypoints 0.0.0-test.1 → 0.0.1-commit.0b941701

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.
@@ -0,0 +1,88 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { Tuple } from '@aztec/foundation/serialize';
3
+ import { FunctionCall } from '@aztec/stdlib/abi';
4
+ import { HashedValues } from '@aztec/stdlib/tx';
5
+ export declare const APP_MAX_CALLS = 5;
6
+ /** Encoded function call for an Aztec entrypoint */
7
+ export type EncodedFunctionCall = {
8
+ /** Arguments hash for the call. */
9
+ /** This should be the calldata hash `hash([function_selector, ...args])` if `is_public` is true. */
10
+ args_hash: Fr;
11
+ /** Selector of the function to call */
12
+ function_selector: Fr;
13
+ /** Address of the contract to call */
14
+ target_address: Fr;
15
+ /** Whether the function is public or private */
16
+ is_public: boolean;
17
+ /** Only applicable for enqueued public function calls. Whether the msg_sender will be set to "null". */
18
+ hide_msg_sender: boolean;
19
+ /** Whether the function can alter state */
20
+ is_static: boolean;
21
+ };
22
+ /** Type that represents function calls ready to be sent to a circuit for execution */
23
+ export type EncodedCalls = {
24
+ /** Function calls in the expected format (Noir's convention) */
25
+ encodedFunctionCalls: EncodedFunctionCall[];
26
+ /** The hashed args for the call, ready to be injected in the execution cache */
27
+ hashedArguments: HashedValues[];
28
+ };
29
+ /**
30
+ * Entrypoints derive their arguments from the calls that they'll ultimate make.
31
+ * This utility class helps in creating the payload for the entrypoint by taking into
32
+ * account how the calls are encoded and hashed.
33
+ * */
34
+ export declare class EncodedAppEntrypointCalls implements EncodedCalls {
35
+ /** Function calls in the expected format (Noir's convention) */
36
+ encodedFunctionCalls: EncodedFunctionCall[];
37
+ /** The hashed args for the call, ready to be injected in the execution cache */
38
+ hashedArguments: HashedValues[];
39
+ /** The index of the generator to use for hashing */
40
+ generatorIndex: number;
41
+ /**
42
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
43
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
44
+ * but higher fee. The nullifier ensures only one transaction can succeed.
45
+ */
46
+ tx_nonce: Fr;
47
+ constructor(
48
+ /** Function calls in the expected format (Noir's convention) */
49
+ encodedFunctionCalls: EncodedFunctionCall[],
50
+ /** The hashed args for the call, ready to be injected in the execution cache */
51
+ hashedArguments: HashedValues[],
52
+ /** The index of the generator to use for hashing */
53
+ generatorIndex: number,
54
+ /**
55
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
56
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
57
+ * but higher fee. The nullifier ensures only one transaction can succeed.
58
+ */
59
+ tx_nonce: Fr);
60
+ /**
61
+ * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding
62
+ * @internal
63
+ */
64
+ get function_calls(): EncodedFunctionCall[];
65
+ /**
66
+ * Serializes the payload to an array of fields
67
+ * @returns The fields of the payload
68
+ */
69
+ toFields(): Fr[];
70
+ /**
71
+ * Hashes the payload
72
+ * @returns The hash of the payload
73
+ */
74
+ hash(): Promise<Fr>;
75
+ /** Serializes the function calls to an array of fields. */
76
+ protected functionCallsToFields(): Fr[];
77
+ /**
78
+ * Encodes the functions for the app-portion of a transaction from a set of function calls and a nonce
79
+ * @param functionCalls - The function calls to execute
80
+ * @param txNonce - A nonce used to enable transaction cancellation when cancellable=true. Transactions with the same
81
+ * nonce can be replaced by submitting a new one with a higher fee.
82
+ * @returns The encoded calls
83
+ */
84
+ static create(functionCalls: FunctionCall[] | Tuple<FunctionCall, typeof APP_MAX_CALLS>, txNonce?: Fr): Promise<EncodedAppEntrypointCalls>;
85
+ }
86
+ /** Encodes FunctionCalls for execution, following Noir's convention */
87
+ export declare function encode(calls: FunctionCall[]): Promise<EncodedCalls>;
88
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW5jb2RpbmcuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJz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a,MAAM,CACjB,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,OAAO,aAAa,CAAC,EACzE,OAAO,KAAc,sCAatB;CACF;AAED,uEAAuE;AACvE,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAwBzE"}
@@ -0,0 +1,97 @@
1
+ import { GeneratorIndex } from '@aztec/constants';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
3
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { FunctionCall, FunctionType } from '@aztec/stdlib/abi';
6
+ import { HashedValues } from '@aztec/stdlib/tx';
7
+ // These must match the values defined in:
8
+ // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr
9
+ export const APP_MAX_CALLS = 5;
10
+ /**
11
+ * Entrypoints derive their arguments from the calls that they'll ultimate make.
12
+ * This utility class helps in creating the payload for the entrypoint by taking into
13
+ * account how the calls are encoded and hashed.
14
+ * */ export class EncodedAppEntrypointCalls {
15
+ encodedFunctionCalls;
16
+ hashedArguments;
17
+ generatorIndex;
18
+ tx_nonce;
19
+ constructor(/** Function calls in the expected format (Noir's convention) */ encodedFunctionCalls, /** The hashed args for the call, ready to be injected in the execution cache */ hashedArguments, /** The index of the generator to use for hashing */ generatorIndex, /**
20
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
21
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
22
+ * but higher fee. The nullifier ensures only one transaction can succeed.
23
+ */ // eslint-disable-next-line camelcase
24
+ tx_nonce){
25
+ this.encodedFunctionCalls = encodedFunctionCalls;
26
+ this.hashedArguments = hashedArguments;
27
+ this.generatorIndex = generatorIndex;
28
+ this.tx_nonce = tx_nonce;
29
+ }
30
+ /* eslint-disable camelcase */ /**
31
+ * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding
32
+ * @internal
33
+ */ get function_calls() {
34
+ return this.encodedFunctionCalls;
35
+ }
36
+ /* eslint-enable camelcase */ /**
37
+ * Serializes the payload to an array of fields
38
+ * @returns The fields of the payload
39
+ */ toFields() {
40
+ return [
41
+ ...this.functionCallsToFields(),
42
+ this.tx_nonce
43
+ ];
44
+ }
45
+ /**
46
+ * Hashes the payload
47
+ * @returns The hash of the payload
48
+ */ hash() {
49
+ return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex);
50
+ }
51
+ /** Serializes the function calls to an array of fields. */ functionCallsToFields() {
52
+ return this.encodedFunctionCalls.flatMap((call)=>[
53
+ call.args_hash,
54
+ call.function_selector,
55
+ call.target_address,
56
+ new Fr(call.is_public),
57
+ new Fr(call.hide_msg_sender),
58
+ new Fr(call.is_static)
59
+ ]);
60
+ }
61
+ /**
62
+ * Encodes the functions for the app-portion of a transaction from a set of function calls and a nonce
63
+ * @param functionCalls - The function calls to execute
64
+ * @param txNonce - A nonce used to enable transaction cancellation when cancellable=true. Transactions with the same
65
+ * nonce can be replaced by submitting a new one with a higher fee.
66
+ * @returns The encoded calls
67
+ */ static async create(functionCalls, txNonce = Fr.random()) {
68
+ if (functionCalls.length > APP_MAX_CALLS) {
69
+ throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`);
70
+ }
71
+ const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS);
72
+ const encoded = await encode(paddedCalls);
73
+ return new EncodedAppEntrypointCalls(encoded.encodedFunctionCalls, encoded.hashedArguments, GeneratorIndex.SIGNATURE_PAYLOAD, txNonce);
74
+ }
75
+ }
76
+ /** Encodes FunctionCalls for execution, following Noir's convention */ export async function encode(calls) {
77
+ const hashedArguments = [];
78
+ for (const call of calls){
79
+ const hashed = call.type === FunctionType.PUBLIC ? await HashedValues.fromCalldata([
80
+ call.selector.toField(),
81
+ ...call.args
82
+ ]) : await HashedValues.fromArgs(call.args);
83
+ hashedArguments.push(hashed);
84
+ }
85
+ /* eslint-disable camelcase */ const encodedFunctionCalls = calls.map((call, index)=>({
86
+ args_hash: hashedArguments[index].hash,
87
+ function_selector: call.selector.toField(),
88
+ target_address: call.to.toField(),
89
+ is_public: call.type == FunctionType.PUBLIC,
90
+ hide_msg_sender: call.hideMsgSender,
91
+ is_static: call.isStatic
92
+ }));
93
+ return {
94
+ encodedFunctionCalls,
95
+ hashedArguments
96
+ };
97
+ }
package/dest/index.d.ts CHANGED
@@ -6,5 +6,8 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  export * from './account_entrypoint.js';
9
- export * from './dapp_entrypoint.js';
10
- //# sourceMappingURL=index.d.ts.map
9
+ export * from './interfaces.js';
10
+ export * from './default_entrypoint.js';
11
+ export * from './encoding.js';
12
+ export * from './default_multi_call_entrypoint.js';
13
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxjQUFjLHlCQUF5QixDQUFDO0FBQ3hDLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLG9DQUFvQyxDQUFDIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,oCAAoC,CAAC"}
package/dest/index.js CHANGED
@@ -5,4 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */ export * from './account_entrypoint.js';
8
- export * from './dapp_entrypoint.js';
8
+ export * from './interfaces.js';
9
+ export * from './default_entrypoint.js';
10
+ export * from './encoding.js';
11
+ export * from './default_multi_call_entrypoint.js';
@@ -0,0 +1,65 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
+ import type { GasSettings } from '@aztec/stdlib/gas';
4
+ import type { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import { z } from 'zod';
6
+ /**
7
+ * Information on the connected chain. Used by wallets when constructing transactions to protect against replay
8
+ * attacks.
9
+ */
10
+ export type ChainInfo = {
11
+ /** The L1 chain id */
12
+ chainId: Fr;
13
+ /** The version of the rollup */
14
+ version: Fr;
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
+ }>;
29
+ /**
30
+ * Creates transaction execution requests out of a set of function calls, a fee payment method and
31
+ * general options for the transaction
32
+ */
33
+ export interface EntrypointInterface {
34
+ /**
35
+ * Generates an execution request out of set of function calls.
36
+ * @param exec - The execution intents to be run.
37
+ * @param gasSettings - The gas settings for the transaction.
38
+ * @param chainInfo - Chain information (chainId and version) for replay protection.
39
+ * @param options - Miscellaneous tx options that enable/disable features of the entrypoint
40
+ * @returns The authenticated transaction execution request.
41
+ */
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>;
55
+ }
56
+ /** Creates authorization witnesses. */
57
+ export interface AuthWitnessProvider {
58
+ /**
59
+ * Computes an authentication witness from either a message hash
60
+ * @param messageHash - The message hash to approve
61
+ * @returns The authentication witness
62
+ */
63
+ createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
64
+ }
65
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFN0UsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4Qjs7O0dBR0c7QUFDSCxNQUFNLE1BQU0sU0FBUyxHQUFHO0lBQ3RCLHNCQUFzQjtJQUN0QixPQUFPLEVBQUUsRUFBRSxDQUFDO0lBQ1osaUNBQWlDO0lBQ2pDLE9BQU8sRUFBR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ACtB,OAAO,EAAE,EAAE,CAAC;IACZ,iCAAiC;IACjC,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;EAG1B,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,wBAAwB,CACtB,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAE/B;;;;;;;;;;OAUG;IACH,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACxF;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,8 @@
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,11 +2,15 @@
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.0-test.1",
5
+ "version": "0.0.1-commit.0b941701",
6
6
  "type": "module",
7
7
  "exports": {
8
- "./dapp": "./dest/dapp_entrypoint.js",
9
- "./account": "./dest/account_entrypoint.js"
8
+ "./account": "./dest/account_entrypoint.js",
9
+ "./default": "./dest/default_entrypoint.js",
10
+ "./multicall": "./dest/default_multi_call_entrypoint.js",
11
+ "./interfaces": "./dest/interfaces.js",
12
+ "./payload": "./dest/payload.js",
13
+ "./encoding": "./dest/encoding.js"
10
14
  },
11
15
  "typedocOptions": {
12
16
  "entryPoints": [
@@ -16,12 +20,10 @@
16
20
  "tsconfig": "./tsconfig.json"
17
21
  },
18
22
  "scripts": {
19
- "build": "yarn clean && tsc -b",
20
- "build:dev": "tsc -b --watch",
21
- "build:ts": "tsc -b",
23
+ "build": "yarn clean && ../scripts/tsc.sh",
24
+ "build:dev": "../scripts/tsc.sh --watch",
25
+ "build:ts": "../scripts/tsc.sh",
22
26
  "clean": "rm -rf ./dest .tsbuildinfo",
23
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
24
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
25
27
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
26
28
  },
27
29
  "inherits": [
@@ -58,21 +60,27 @@
58
60
  "testTimeout": 120000,
59
61
  "setupFiles": [
60
62
  "../../foundation/src/jest/setup.mjs"
63
+ ],
64
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
65
+ "setupFilesAfterEnv": [
66
+ "../../foundation/src/jest/setupAfterEnv.mjs"
61
67
  ]
62
68
  },
63
69
  "dependencies": {
64
- "@aztec/aztec.js": "0.0.0-test.1",
65
- "@aztec/foundation": "0.0.0-test.1",
66
- "@aztec/protocol-contracts": "0.0.0-test.1",
67
- "@aztec/stdlib": "0.0.0-test.1",
68
- "tslib": "^2.4.0"
70
+ "@aztec/constants": "0.0.1-commit.0b941701",
71
+ "@aztec/foundation": "0.0.1-commit.0b941701",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.0b941701",
73
+ "@aztec/stdlib": "0.0.1-commit.0b941701",
74
+ "tslib": "^2.4.0",
75
+ "zod": "^3.23.8"
69
76
  },
70
77
  "devDependencies": {
71
- "@jest/globals": "^29.5.0",
72
- "@types/jest": "^29.5.0",
73
- "jest": "^29.5.0",
78
+ "@jest/globals": "^30.0.0",
79
+ "@types/jest": "^30.0.0",
80
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
81
+ "jest": "^30.0.0",
74
82
  "ts-node": "^10.9.1",
75
- "typescript": "^5.0.4"
83
+ "typescript": "^5.3.3"
76
84
  },
77
85
  "files": [
78
86
  "dest",
@@ -80,6 +88,6 @@
80
88
  "!*.test.*"
81
89
  ],
82
90
  "engines": {
83
- "node": ">=18"
91
+ "node": ">=20.10"
84
92
  }
85
93
  }
@@ -1,15 +1,53 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import {
3
- type EntrypointInterface,
4
- EntrypointPayload,
5
- type ExecutionRequestInit,
6
- computeCombinedPayloadHash,
7
- } from '@aztec/aztec.js/entrypoint';
8
- 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';
9
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import type { GasSettings } from '@aztec/stdlib/gas';
5
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
11
6
 
12
- import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
7
+ import { EncodedAppEntrypointCalls } from './encoding.js';
8
+ import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
9
+
10
+ /**
11
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
12
+ */
13
+ export enum AccountFeePaymentMethodOptions {
14
+ /**
15
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
16
+ */
17
+ EXTERNAL = 0,
18
+ /**
19
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
20
+ * **which it must already have prior to this transaction**.
21
+ *
22
+ * The contract will set itself as the fee payer and end the setup phase.
23
+ */
24
+ PREEXISTING_FEE_JUICE = 1,
25
+ /**
26
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
27
+ * **which is being claimed in the same transaction**.
28
+ *
29
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
30
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
31
+ * to be executable during the setup phase.
32
+ */
33
+ FEE_JUICE_WITH_CLAIM = 2,
34
+ }
35
+
36
+ /**
37
+ * General options for the tx execution.
38
+ */
39
+ export type DefaultAccountEntrypointOptions = {
40
+ /** Whether the transaction can be cancelled. */
41
+ cancellable?: boolean;
42
+ /**
43
+ * A nonce to inject into the app payload of the transaction. When used with cancellable=true, this nonce will be
44
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
45
+ * but higher fee. The nullifier ensures only one transaction can succeed.
46
+ */
47
+ txNonce?: Fr;
48
+ /** Options that configure how the account contract behaves depending on the fee payment method of the tx */
49
+ feePaymentMethodOptions: AccountFeePaymentMethodOptions;
50
+ };
13
51
 
14
52
  /**
15
53
  * Implementation for an entrypoint interface that follows the default entrypoint signature
@@ -19,43 +57,95 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
19
57
  constructor(
20
58
  private address: AztecAddress,
21
59
  private auth: AuthWitnessProvider,
22
- private chainId: number = DEFAULT_CHAIN_ID,
23
- private version: number = DEFAULT_VERSION,
24
60
  ) {}
25
61
 
26
- async createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
27
- const { calls, fee, nonce, cancellable, capsules = [] } = exec;
28
- const appPayload = await EntrypointPayload.fromAppExecution(calls, nonce);
29
- const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee);
30
-
31
- const abi = this.getEntrypointAbi();
32
- const entrypointHashedArgs = await HashedValues.fromValues(
33
- encodeArguments(abi, [appPayload, feePayload, !!cancellable]),
34
- );
35
-
36
- const combinedPayloadAuthWitness = await this.auth.createAuthWit(
37
- await computeCombinedPayloadHash(appPayload, feePayload),
38
- );
39
-
62
+ async createTxExecutionRequest(
63
+ exec: ExecutionPayload,
64
+ gasSettings: GasSettings,
65
+ chainInfo: ChainInfo,
66
+ options: DefaultAccountEntrypointOptions,
67
+ ): Promise<TxExecutionRequest> {
68
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
69
+ const callData = await this.#buildEntrypointCallData(exec, options);
70
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
40
71
  const txRequest = TxExecutionRequest.from({
41
72
  firstCallArgsHash: entrypointHashedArgs.hash,
42
73
  origin: this.address,
43
- functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
44
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
45
- argsOfCalls: [...appPayload.hashedArguments, ...feePayload.hashedArguments, entrypointHashedArgs],
46
- authWitnesses: [combinedPayloadAuthWitness],
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],
47
78
  capsules,
79
+ salt: Fr.random(),
48
80
  });
49
81
 
50
82
  return txRequest;
51
83
  }
52
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
+
53
143
  private getEntrypointAbi() {
54
144
  return {
55
145
  name: 'entrypoint',
56
146
  isInitializer: false,
57
147
  functionType: 'private',
58
- isInternal: false,
148
+ isOnlySelf: false,
59
149
  isStatic: false,
60
150
  parameters: [
61
151
  {
@@ -68,50 +158,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
68
158
  name: 'function_calls',
69
159
  type: {
70
160
  kind: 'array',
71
- length: 4,
72
- type: {
73
- kind: 'struct',
74
- path: 'authwit::entrypoint::function_call::FunctionCall',
75
- fields: [
76
- { name: 'args_hash', type: { kind: 'field' } },
77
- {
78
- name: 'function_selector',
79
- type: {
80
- kind: 'struct',
81
- path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
82
- fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
83
- },
84
- },
85
- {
86
- name: 'target_address',
87
- type: {
88
- kind: 'struct',
89
- path: 'authwit::aztec::protocol_types::address::AztecAddress',
90
- fields: [{ name: 'inner', type: { kind: 'field' } }],
91
- },
92
- },
93
- { name: 'is_public', type: { kind: 'boolean' } },
94
- { name: 'is_static', type: { kind: 'boolean' } },
95
- ],
96
- },
97
- },
98
- },
99
- { name: 'nonce', type: { kind: 'field' } },
100
- ],
101
- },
102
- visibility: 'public',
103
- },
104
- {
105
- name: 'fee_payload',
106
- type: {
107
- kind: 'struct',
108
- path: 'authwit::entrypoint::fee::FeePayload',
109
- fields: [
110
- {
111
- name: 'function_calls',
112
- type: {
113
- kind: 'array',
114
- length: 2,
161
+ length: 5,
115
162
  type: {
116
163
  kind: 'struct',
117
164
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -134,17 +181,18 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
134
181
  },
135
182
  },
136
183
  { name: 'is_public', type: { kind: 'boolean' } },
184
+ { name: 'hide_msg_sender', type: { kind: 'boolean' } },
137
185
  { name: 'is_static', type: { kind: 'boolean' } },
138
186
  ],
139
187
  },
140
188
  },
141
189
  },
142
- { name: 'nonce', type: { kind: 'field' } },
143
- { name: 'is_fee_payer', type: { kind: 'boolean' } },
190
+ { name: 'tx_nonce', type: { kind: 'field' } },
144
191
  ],
145
192
  },
146
193
  visibility: 'public',
147
194
  },
195
+ { name: 'fee_payment_method', type: { kind: 'integer', sign: 'unsigned', width: 8 } },
148
196
  { name: 'cancellable', type: { kind: 'boolean' } },
149
197
  ],
150
198
  returnTypes: [],