@aztec/entrypoints 0.0.0-test.1 → 0.0.1-commit.001888fc

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
+ domainSeparator: 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
+ domainSeparator: 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 { DomainSeparator } 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
+ domainSeparator;
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 */ domainSeparator, /**
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.domainSeparator = domainSeparator;
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.domainSeparator);
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, DomainSeparator.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,66 @@
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 chainInfo - Chain information (chainId and version) for replay protection
51
+ * @param options - Implementation-specific options
52
+ * @returns A new execution payload with a single call to this entrypoint
53
+ * @throws Error if the payload cannot be wrapped (e.g., exceeds call limit)
54
+ */
55
+ wrapExecutionPayload(exec: ExecutionPayload, chainInfo: ChainInfo, options?: any): Promise<ExecutionPayload>;
56
+ }
57
+ /** Creates authorization witnesses. */
58
+ export interface AuthWitnessProvider {
59
+ /**
60
+ * Computes an authentication witness from either a message hash
61
+ * @param messageHash - The message hash to approve
62
+ * @returns The authentication witness
63
+ */
64
+ createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
65
+ }
66
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFN0UsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4Qjs7O0dBR0c7QUFDSCxNQUFNLE1BQU0sU0FBUyxHQUFHO0lBQ3RCLHNCQUFzQjtJQUN0QixPQUFPLEVBQUUsRUFBRSxDQ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CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,sBAAsB;IACtB,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;;;;;;;;;;;OAWG;IACH,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9G;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.001888fc",
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.001888fc",
71
+ "@aztec/foundation": "0.0.1-commit.001888fc",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.001888fc",
73
+ "@aztec/stdlib": "0.0.1-commit.001888fc",
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,54 @@
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';
3
+ import { computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
9
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import type { GasSettings } from '@aztec/stdlib/gas';
6
+ import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
11
7
 
12
- import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
8
+ import { EncodedAppEntrypointCalls } from './encoding.js';
9
+ import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
10
+
11
+ /**
12
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
13
+ */
14
+ export enum AccountFeePaymentMethodOptions {
15
+ /**
16
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
17
+ */
18
+ EXTERNAL = 0,
19
+ /**
20
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
21
+ * **which it must already have prior to this transaction**.
22
+ *
23
+ * The contract will set itself as the fee payer and end the setup phase.
24
+ */
25
+ PREEXISTING_FEE_JUICE = 1,
26
+ /**
27
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
28
+ * **which is being claimed in the same transaction**.
29
+ *
30
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
31
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
32
+ * to be executable during the setup phase.
33
+ */
34
+ FEE_JUICE_WITH_CLAIM = 2,
35
+ }
36
+
37
+ /**
38
+ * General options for the tx execution.
39
+ */
40
+ export type DefaultAccountEntrypointOptions = {
41
+ /** Whether the transaction can be cancelled. */
42
+ cancellable?: boolean;
43
+ /**
44
+ * A nonce to inject into the app payload of the transaction. When used with cancellable=true, this nonce will be
45
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
46
+ * but higher fee. The nullifier ensures only one transaction can succeed.
47
+ */
48
+ txNonce?: Fr;
49
+ /** Options that configure how the account contract behaves depending on the fee payment method of the tx */
50
+ feePaymentMethodOptions: AccountFeePaymentMethodOptions;
51
+ };
13
52
 
14
53
  /**
15
54
  * Implementation for an entrypoint interface that follows the default entrypoint signature
@@ -19,43 +58,103 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
19
58
  constructor(
20
59
  private address: AztecAddress,
21
60
  private auth: AuthWitnessProvider,
22
- private chainId: number = DEFAULT_CHAIN_ID,
23
- private version: number = DEFAULT_VERSION,
24
61
  ) {}
25
62
 
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
-
63
+ async createTxExecutionRequest(
64
+ exec: ExecutionPayload,
65
+ gasSettings: GasSettings,
66
+ chainInfo: ChainInfo,
67
+ options: DefaultAccountEntrypointOptions,
68
+ ): Promise<TxExecutionRequest> {
69
+ const { authWitnesses, capsules, extraHashedArgs } = exec;
70
+ const callData = await this.#buildEntrypointCallData(exec, chainInfo, options);
71
+ const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
40
72
  const txRequest = TxExecutionRequest.from({
41
73
  firstCallArgsHash: entrypointHashedArgs.hash,
42
74
  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],
75
+ functionSelector: callData.functionSelector,
76
+ txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
77
+ argsOfCalls: [...callData.encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
78
+ authWitnesses: [...authWitnesses, callData.payloadAuthWitness],
47
79
  capsules,
80
+ salt: Fr.random(),
48
81
  });
49
82
 
50
83
  return txRequest;
51
84
  }
52
85
 
86
+ async wrapExecutionPayload(
87
+ exec: ExecutionPayload,
88
+ chainInfo: ChainInfo,
89
+ options: DefaultAccountEntrypointOptions,
90
+ ): Promise<ExecutionPayload> {
91
+ const { authWitnesses, capsules, extraHashedArgs, feePayer } = exec;
92
+ const callData = await this.#buildEntrypointCallData(exec, chainInfo, options);
93
+
94
+ // Build the entrypoint function call
95
+ const entrypointCall = FunctionCall.from({
96
+ name: callData.abi.name,
97
+ to: this.address,
98
+ selector: callData.functionSelector,
99
+ type: callData.abi.functionType,
100
+ hideMsgSender: false,
101
+ isStatic: callData.abi.isStatic,
102
+ args: callData.encodedArgs,
103
+ returnTypes: callData.abi.returnTypes,
104
+ });
105
+
106
+ return new ExecutionPayload(
107
+ [entrypointCall],
108
+ [callData.payloadAuthWitness, ...authWitnesses],
109
+ capsules,
110
+ [...callData.encodedCalls.hashedArguments, ...extraHashedArgs],
111
+ feePayer ?? this.address,
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
117
+ * This includes encoding calls, building entrypoint arguments, and creating the authwitness.
118
+ * @param exec - The execution payload containing calls to encode
119
+ * @param chainInfo - Chain information (chainId and version) for replay protection
120
+ * @param options - Account entrypoint options including tx nonce and fee payment method
121
+ * @returns Encoded call data, ABI, function selector, and auth witness
122
+ */
123
+ async #buildEntrypointCallData(
124
+ exec: ExecutionPayload,
125
+ chainInfo: ChainInfo,
126
+ options: DefaultAccountEntrypointOptions,
127
+ ) {
128
+ const { calls } = exec;
129
+ const { cancellable, txNonce, feePaymentMethodOptions } = options;
130
+
131
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
132
+
133
+ const abi = this.getEntrypointAbi();
134
+ const args = [encodedCalls, feePaymentMethodOptions, !!cancellable];
135
+ const encodedArgs = encodeArguments(abi, args);
136
+
137
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
138
+
139
+ const payloadHash = await encodedCalls.hash();
140
+ const messageHash = await computeOuterAuthWitHash(this.address, chainInfo.chainId, chainInfo.version, payloadHash);
141
+ const payloadAuthWitness = await this.auth.createAuthWit(messageHash);
142
+
143
+ return {
144
+ encodedCalls,
145
+ abi,
146
+ encodedArgs,
147
+ functionSelector,
148
+ payloadAuthWitness,
149
+ };
150
+ }
151
+
53
152
  private getEntrypointAbi() {
54
153
  return {
55
154
  name: 'entrypoint',
56
155
  isInitializer: false,
57
156
  functionType: 'private',
58
- isInternal: false,
157
+ isOnlySelf: false,
59
158
  isStatic: false,
60
159
  parameters: [
61
160
  {
@@ -68,50 +167,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
68
167
  name: 'function_calls',
69
168
  type: {
70
169
  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,
170
+ length: 5,
115
171
  type: {
116
172
  kind: 'struct',
117
173
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -134,17 +190,18 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
134
190
  },
135
191
  },
136
192
  { name: 'is_public', type: { kind: 'boolean' } },
193
+ { name: 'hide_msg_sender', type: { kind: 'boolean' } },
137
194
  { name: 'is_static', type: { kind: 'boolean' } },
138
195
  ],
139
196
  },
140
197
  },
141
198
  },
142
- { name: 'nonce', type: { kind: 'field' } },
143
- { name: 'is_fee_payer', type: { kind: 'boolean' } },
199
+ { name: 'tx_nonce', type: { kind: 'field' } },
144
200
  ],
145
201
  },
146
202
  visibility: 'public',
147
203
  },
204
+ { name: 'fee_payment_method', type: { kind: 'integer', sign: 'unsigned', width: 8 } },
148
205
  { name: 'cancellable', type: { kind: 'boolean' } },
149
206
  ],
150
207
  returnTypes: [],