@aztec/entrypoints 0.0.0-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Account Entrypoints
2
+
3
+ This package contains different transaction entrypoints for the Aztec Network.
4
+
5
+ ## Available entrypoints
6
+
7
+ - **Account entrypoint**: this entrypoint encodes the payload to start an interaction through an Account Contract. It is meant to be used with accounts implementing the interface defined by `@aztec/accounts`.
8
+ - **DApp entrypoint**: this encodes the payload so that it may run a dapp directly, instead of going through an account contract.
@@ -0,0 +1,18 @@
1
+ import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
+ import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ /**
6
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
7
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
8
+ */
9
+ export declare class DefaultAccountEntrypoint implements EntrypointInterface {
10
+ private address;
11
+ private auth;
12
+ private chainId;
13
+ private version;
14
+ constructor(address: AztecAddress, auth: AuthWitnessProvider, chainId?: number, version?: number);
15
+ createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
16
+ private getEntrypointAbi;
17
+ }
18
+ //# sourceMappingURL=account_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,oBAAoB,EAE1B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAHP,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2BvF,OAAO,CAAC,gBAAgB;CAqGzB"}
@@ -0,0 +1,230 @@
1
+ import { EntrypointPayload, computeCombinedPayloadHash } from '@aztec/aztec.js/entrypoint';
2
+ import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
5
+ /**
6
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
7
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
8
+ */ export class DefaultAccountEntrypoint {
9
+ address;
10
+ auth;
11
+ chainId;
12
+ version;
13
+ constructor(address, auth, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
14
+ this.address = address;
15
+ this.auth = auth;
16
+ this.chainId = chainId;
17
+ this.version = version;
18
+ }
19
+ async createTxExecutionRequest(exec) {
20
+ const { calls, fee, nonce, cancellable, capsules = [] } = exec;
21
+ const appPayload = await EntrypointPayload.fromAppExecution(calls, nonce);
22
+ const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee);
23
+ const abi = this.getEntrypointAbi();
24
+ const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
25
+ appPayload,
26
+ feePayload,
27
+ !!cancellable
28
+ ]));
29
+ const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload));
30
+ const txRequest = TxExecutionRequest.from({
31
+ firstCallArgsHash: entrypointHashedArgs.hash,
32
+ origin: this.address,
33
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
+ txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
35
+ argsOfCalls: [
36
+ ...appPayload.hashedArguments,
37
+ ...feePayload.hashedArguments,
38
+ entrypointHashedArgs
39
+ ],
40
+ authWitnesses: [
41
+ combinedPayloadAuthWitness
42
+ ],
43
+ capsules
44
+ });
45
+ return txRequest;
46
+ }
47
+ getEntrypointAbi() {
48
+ return {
49
+ name: 'entrypoint',
50
+ isInitializer: false,
51
+ functionType: 'private',
52
+ isInternal: false,
53
+ isStatic: false,
54
+ parameters: [
55
+ {
56
+ name: 'app_payload',
57
+ type: {
58
+ kind: 'struct',
59
+ path: 'authwit::entrypoint::app::AppPayload',
60
+ fields: [
61
+ {
62
+ name: 'function_calls',
63
+ type: {
64
+ kind: 'array',
65
+ length: 4,
66
+ type: {
67
+ kind: 'struct',
68
+ path: 'authwit::entrypoint::function_call::FunctionCall',
69
+ fields: [
70
+ {
71
+ name: 'args_hash',
72
+ type: {
73
+ kind: 'field'
74
+ }
75
+ },
76
+ {
77
+ name: 'function_selector',
78
+ type: {
79
+ kind: 'struct',
80
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
81
+ fields: [
82
+ {
83
+ name: 'inner',
84
+ type: {
85
+ kind: 'integer',
86
+ sign: 'unsigned',
87
+ width: 32
88
+ }
89
+ }
90
+ ]
91
+ }
92
+ },
93
+ {
94
+ name: 'target_address',
95
+ type: {
96
+ kind: 'struct',
97
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
98
+ fields: [
99
+ {
100
+ name: 'inner',
101
+ type: {
102
+ kind: 'field'
103
+ }
104
+ }
105
+ ]
106
+ }
107
+ },
108
+ {
109
+ name: 'is_public',
110
+ type: {
111
+ kind: 'boolean'
112
+ }
113
+ },
114
+ {
115
+ name: 'is_static',
116
+ type: {
117
+ kind: 'boolean'
118
+ }
119
+ }
120
+ ]
121
+ }
122
+ }
123
+ },
124
+ {
125
+ name: 'nonce',
126
+ type: {
127
+ kind: 'field'
128
+ }
129
+ }
130
+ ]
131
+ },
132
+ visibility: 'public'
133
+ },
134
+ {
135
+ name: 'fee_payload',
136
+ type: {
137
+ kind: 'struct',
138
+ path: 'authwit::entrypoint::fee::FeePayload',
139
+ fields: [
140
+ {
141
+ name: 'function_calls',
142
+ type: {
143
+ kind: 'array',
144
+ length: 2,
145
+ type: {
146
+ kind: 'struct',
147
+ path: 'authwit::entrypoint::function_call::FunctionCall',
148
+ fields: [
149
+ {
150
+ name: 'args_hash',
151
+ type: {
152
+ kind: 'field'
153
+ }
154
+ },
155
+ {
156
+ name: 'function_selector',
157
+ type: {
158
+ kind: 'struct',
159
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
160
+ fields: [
161
+ {
162
+ name: 'inner',
163
+ type: {
164
+ kind: 'integer',
165
+ sign: 'unsigned',
166
+ width: 32
167
+ }
168
+ }
169
+ ]
170
+ }
171
+ },
172
+ {
173
+ name: 'target_address',
174
+ type: {
175
+ kind: 'struct',
176
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
177
+ fields: [
178
+ {
179
+ name: 'inner',
180
+ type: {
181
+ kind: 'field'
182
+ }
183
+ }
184
+ ]
185
+ }
186
+ },
187
+ {
188
+ name: 'is_public',
189
+ type: {
190
+ kind: 'boolean'
191
+ }
192
+ },
193
+ {
194
+ name: 'is_static',
195
+ type: {
196
+ kind: 'boolean'
197
+ }
198
+ }
199
+ ]
200
+ }
201
+ }
202
+ },
203
+ {
204
+ name: 'nonce',
205
+ type: {
206
+ kind: 'field'
207
+ }
208
+ },
209
+ {
210
+ name: 'is_fee_payer',
211
+ type: {
212
+ kind: 'boolean'
213
+ }
214
+ }
215
+ ]
216
+ },
217
+ visibility: 'public'
218
+ },
219
+ {
220
+ name: 'cancellable',
221
+ type: {
222
+ kind: 'boolean'
223
+ }
224
+ }
225
+ ],
226
+ returnTypes: [],
227
+ errorTypes: {}
228
+ };
229
+ }
230
+ }
@@ -0,0 +1,5 @@
1
+ /** Default L1 chain ID to use when constructing txs (matches hardhat and anvil's default). */
2
+ export declare const DEFAULT_CHAIN_ID = 31337;
3
+ /** Default protocol version to use. */
4
+ export declare const DEFAULT_VERSION = 1;
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AACtC,uCAAuC;AACvC,eAAO,MAAM,eAAe,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** Default L1 chain ID to use when constructing txs (matches hardhat and anvil's default). */ export const DEFAULT_CHAIN_ID = 31337;
2
+ /** Default protocol version to use. */ export const DEFAULT_VERSION = 1;
@@ -0,0 +1,19 @@
1
+ import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
+ import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ /**
6
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
7
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
8
+ */
9
+ export declare class DefaultDappEntrypoint implements EntrypointInterface {
10
+ private userAddress;
11
+ private userAuthWitnessProvider;
12
+ private dappEntrypointAddress;
13
+ private chainId;
14
+ private version;
15
+ constructor(userAddress: AztecAddress, userAuthWitnessProvider: AuthWitnessProvider, dappEntrypointAddress: AztecAddress, chainId?: number, version?: number);
16
+ createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
17
+ private getEntrypointAbi;
18
+ }
19
+ //# sourceMappingURL=dapp_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dapp_entrypoint.d.ts","sourceRoot":"","sources":["../src/dapp_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,KAAK,mBAAmB,EAAqB,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEpH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,mBAAmB;IAE7D,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,uBAAuB;IAC/B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAJP,WAAW,EAAE,YAAY,EACzB,uBAAuB,EAAE,mBAAmB,EAC5C,qBAAqB,EAAE,YAAY,EACnC,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqCvF,OAAO,CAAC,gBAAgB;CAiEzB"}
@@ -0,0 +1,172 @@
1
+ import { Fr, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js';
2
+ import { EntrypointPayload } from '@aztec/aztec.js/entrypoint';
3
+ import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
6
+ /**
7
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
8
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
9
+ */ export class DefaultDappEntrypoint {
10
+ userAddress;
11
+ userAuthWitnessProvider;
12
+ dappEntrypointAddress;
13
+ chainId;
14
+ version;
15
+ constructor(userAddress, userAuthWitnessProvider, dappEntrypointAddress, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
16
+ this.userAddress = userAddress;
17
+ this.userAuthWitnessProvider = userAuthWitnessProvider;
18
+ this.dappEntrypointAddress = dappEntrypointAddress;
19
+ this.chainId = chainId;
20
+ this.version = version;
21
+ }
22
+ async createTxExecutionRequest(exec) {
23
+ const { calls, fee, capsules = [] } = exec;
24
+ if (calls.length !== 1) {
25
+ throw new Error(`Expected exactly 1 function call, got ${calls.length}`);
26
+ }
27
+ const payload = await EntrypointPayload.fromFunctionCalls(calls);
28
+ const abi = this.getEntrypointAbi();
29
+ const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
30
+ payload,
31
+ this.userAddress
32
+ ]));
33
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
34
+ // Default msg_sender for entrypoints is now Fr.max_value rather than 0 addr (see #7190 & #7404)
35
+ const innerHash = await computeInnerAuthWitHash([
36
+ Fr.MAX_FIELD_VALUE,
37
+ functionSelector.toField(),
38
+ entrypointHashedArgs.hash
39
+ ]);
40
+ const outerHash = await computeAuthWitMessageHash({
41
+ consumer: this.dappEntrypointAddress,
42
+ innerHash
43
+ }, {
44
+ chainId: new Fr(this.chainId),
45
+ version: new Fr(this.version)
46
+ });
47
+ const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash);
48
+ const txRequest = TxExecutionRequest.from({
49
+ firstCallArgsHash: entrypointHashedArgs.hash,
50
+ origin: this.dappEntrypointAddress,
51
+ functionSelector,
52
+ txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
53
+ argsOfCalls: [
54
+ ...payload.hashedArguments,
55
+ entrypointHashedArgs
56
+ ],
57
+ authWitnesses: [
58
+ authWitness
59
+ ],
60
+ capsules
61
+ });
62
+ return txRequest;
63
+ }
64
+ getEntrypointAbi() {
65
+ return {
66
+ name: 'entrypoint',
67
+ isInitializer: false,
68
+ functionType: 'private',
69
+ isInternal: false,
70
+ isStatic: false,
71
+ parameters: [
72
+ {
73
+ name: 'payload',
74
+ type: {
75
+ kind: 'struct',
76
+ path: 'dapp_payload::DAppPayload',
77
+ fields: [
78
+ {
79
+ name: 'function_calls',
80
+ type: {
81
+ kind: 'array',
82
+ length: 1,
83
+ type: {
84
+ kind: 'struct',
85
+ path: 'authwit::entrypoint::function_call::FunctionCall',
86
+ fields: [
87
+ {
88
+ name: 'args_hash',
89
+ type: {
90
+ kind: 'field'
91
+ }
92
+ },
93
+ {
94
+ name: 'function_selector',
95
+ type: {
96
+ kind: 'struct',
97
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
98
+ fields: [
99
+ {
100
+ name: 'inner',
101
+ type: {
102
+ kind: 'integer',
103
+ sign: 'unsigned',
104
+ width: 32
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ },
110
+ {
111
+ name: 'target_address',
112
+ type: {
113
+ kind: 'struct',
114
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
115
+ fields: [
116
+ {
117
+ name: 'inner',
118
+ type: {
119
+ kind: 'field'
120
+ }
121
+ }
122
+ ]
123
+ }
124
+ },
125
+ {
126
+ name: 'is_public',
127
+ type: {
128
+ kind: 'boolean'
129
+ }
130
+ },
131
+ {
132
+ name: 'is_static',
133
+ type: {
134
+ kind: 'boolean'
135
+ }
136
+ }
137
+ ]
138
+ }
139
+ }
140
+ },
141
+ {
142
+ name: 'nonce',
143
+ type: {
144
+ kind: 'field'
145
+ }
146
+ }
147
+ ]
148
+ },
149
+ visibility: 'public'
150
+ },
151
+ {
152
+ name: 'user_address',
153
+ type: {
154
+ kind: 'struct',
155
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
156
+ fields: [
157
+ {
158
+ name: 'inner',
159
+ type: {
160
+ kind: 'field'
161
+ }
162
+ }
163
+ ]
164
+ },
165
+ visibility: 'public'
166
+ }
167
+ ],
168
+ returnTypes: [],
169
+ errorTypes: {}
170
+ };
171
+ }
172
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The `@aztec/accounts/defaults` export provides the base class {@link DefaultAccountContract} for implementing account contracts that use the default entrypoint payload module.
3
+ *
4
+ * Read more in {@link https://docs.aztec.network/developers/tutorials/codealong/contract_tutorials/write_accounts_contract | Writing an account contract}.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from './account_entrypoint.js';
9
+ export * from './dapp_entrypoint.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dest/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The `@aztec/accounts/defaults` export provides the base class {@link DefaultAccountContract} for implementing account contracts that use the default entrypoint payload module.
3
+ *
4
+ * Read more in {@link https://docs.aztec.network/developers/tutorials/codealong/contract_tutorials/write_accounts_contract | Writing an account contract}.
5
+ *
6
+ * @packageDocumentation
7
+ */ export * from './account_entrypoint.js';
8
+ export * from './dapp_entrypoint.js';
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@aztec/entrypoints",
3
+ "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/entrypoints",
4
+ "description": "Implementation of sample contract entrypoints for the Aztec Network",
5
+ "version": "0.0.0-test.0",
6
+ "type": "module",
7
+ "exports": {
8
+ "./dapp": "./dest/dapp_entrypoint.js",
9
+ "./account": "./dest/account_entrypoint.js"
10
+ },
11
+ "typedocOptions": {
12
+ "entryPoints": [
13
+ "./src/index.ts"
14
+ ],
15
+ "name": "Entrypoints",
16
+ "tsconfig": "./tsconfig.json"
17
+ },
18
+ "scripts": {
19
+ "build": "yarn clean && tsc -b",
20
+ "build:dev": "tsc -b --watch",
21
+ "build:ts": "tsc -b",
22
+ "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
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
26
+ },
27
+ "inherits": [
28
+ "../package.common.json"
29
+ ],
30
+ "jest": {
31
+ "moduleNameMapper": {
32
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
33
+ },
34
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
35
+ "rootDir": "./src",
36
+ "transform": {
37
+ "^.+\\.tsx?$": [
38
+ "@swc/jest",
39
+ {
40
+ "jsc": {
41
+ "parser": {
42
+ "syntax": "typescript",
43
+ "decorators": true
44
+ },
45
+ "transform": {
46
+ "decoratorVersion": "2022-03"
47
+ }
48
+ }
49
+ }
50
+ ]
51
+ },
52
+ "extensionsToTreatAsEsm": [
53
+ ".ts"
54
+ ],
55
+ "reporters": [
56
+ "default"
57
+ ],
58
+ "testTimeout": 120000,
59
+ "setupFiles": [
60
+ "../../foundation/src/jest/setup.mjs"
61
+ ]
62
+ },
63
+ "dependencies": {
64
+ "@aztec/aztec.js": "0.0.0-test.0",
65
+ "@aztec/foundation": "0.0.0-test.0",
66
+ "@aztec/protocol-contracts": "0.0.0-test.0",
67
+ "@aztec/stdlib": "0.0.0-test.0",
68
+ "tslib": "^2.4.0"
69
+ },
70
+ "devDependencies": {
71
+ "@jest/globals": "^29.5.0",
72
+ "@types/jest": "^29.5.0",
73
+ "jest": "^29.5.0",
74
+ "ts-node": "^10.9.1",
75
+ "typescript": "^5.0.4"
76
+ },
77
+ "files": [
78
+ "dest",
79
+ "src",
80
+ "!*.test.*"
81
+ ],
82
+ "engines": {
83
+ "node": ">=18"
84
+ }
85
+ }
@@ -0,0 +1,154 @@
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';
9
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
11
+
12
+ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
13
+
14
+ /**
15
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
16
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
17
+ */
18
+ export class DefaultAccountEntrypoint implements EntrypointInterface {
19
+ constructor(
20
+ private address: AztecAddress,
21
+ private auth: AuthWitnessProvider,
22
+ private chainId: number = DEFAULT_CHAIN_ID,
23
+ private version: number = DEFAULT_VERSION,
24
+ ) {}
25
+
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
+
40
+ const txRequest = TxExecutionRequest.from({
41
+ firstCallArgsHash: entrypointHashedArgs.hash,
42
+ 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],
47
+ capsules,
48
+ });
49
+
50
+ return txRequest;
51
+ }
52
+
53
+ private getEntrypointAbi() {
54
+ return {
55
+ name: 'entrypoint',
56
+ isInitializer: false,
57
+ functionType: 'private',
58
+ isInternal: false,
59
+ isStatic: false,
60
+ parameters: [
61
+ {
62
+ name: 'app_payload',
63
+ type: {
64
+ kind: 'struct',
65
+ path: 'authwit::entrypoint::app::AppPayload',
66
+ fields: [
67
+ {
68
+ name: 'function_calls',
69
+ type: {
70
+ 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,
115
+ type: {
116
+ kind: 'struct',
117
+ path: 'authwit::entrypoint::function_call::FunctionCall',
118
+ fields: [
119
+ { name: 'args_hash', type: { kind: 'field' } },
120
+ {
121
+ name: 'function_selector',
122
+ type: {
123
+ kind: 'struct',
124
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
125
+ fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
126
+ },
127
+ },
128
+ {
129
+ name: 'target_address',
130
+ type: {
131
+ kind: 'struct',
132
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
133
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
134
+ },
135
+ },
136
+ { name: 'is_public', type: { kind: 'boolean' } },
137
+ { name: 'is_static', type: { kind: 'boolean' } },
138
+ ],
139
+ },
140
+ },
141
+ },
142
+ { name: 'nonce', type: { kind: 'field' } },
143
+ { name: 'is_fee_payer', type: { kind: 'boolean' } },
144
+ ],
145
+ },
146
+ visibility: 'public',
147
+ },
148
+ { name: 'cancellable', type: { kind: 'boolean' } },
149
+ ],
150
+ returnTypes: [],
151
+ errorTypes: {},
152
+ } as FunctionAbi;
153
+ }
154
+ }
@@ -0,0 +1,4 @@
1
+ /** Default L1 chain ID to use when constructing txs (matches hardhat and anvil's default). */
2
+ export const DEFAULT_CHAIN_ID = 31337;
3
+ /** Default protocol version to use. */
4
+ export const DEFAULT_VERSION = 1;
@@ -0,0 +1,125 @@
1
+ import { Fr, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js';
2
+ import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
3
+ import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
4
+ import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
5
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
7
+
8
+ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
9
+
10
+ /**
11
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
12
+ * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
13
+ */
14
+ export class DefaultDappEntrypoint implements EntrypointInterface {
15
+ constructor(
16
+ private userAddress: AztecAddress,
17
+ private userAuthWitnessProvider: AuthWitnessProvider,
18
+ private dappEntrypointAddress: AztecAddress,
19
+ private chainId: number = DEFAULT_CHAIN_ID,
20
+ private version: number = DEFAULT_VERSION,
21
+ ) {}
22
+
23
+ async createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
24
+ const { calls, fee, capsules = [] } = exec;
25
+ if (calls.length !== 1) {
26
+ throw new Error(`Expected exactly 1 function call, got ${calls.length}`);
27
+ }
28
+
29
+ const payload = await EntrypointPayload.fromFunctionCalls(calls);
30
+
31
+ const abi = this.getEntrypointAbi();
32
+ const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload, this.userAddress]));
33
+ const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
34
+ // Default msg_sender for entrypoints is now Fr.max_value rather than 0 addr (see #7190 & #7404)
35
+ const innerHash = await computeInnerAuthWitHash([
36
+ Fr.MAX_FIELD_VALUE,
37
+ functionSelector.toField(),
38
+ entrypointHashedArgs.hash,
39
+ ]);
40
+ const outerHash = await computeAuthWitMessageHash(
41
+ { consumer: this.dappEntrypointAddress, innerHash },
42
+ { chainId: new Fr(this.chainId), version: new Fr(this.version) },
43
+ );
44
+
45
+ const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash);
46
+
47
+ const txRequest = TxExecutionRequest.from({
48
+ firstCallArgsHash: entrypointHashedArgs.hash,
49
+ origin: this.dappEntrypointAddress,
50
+ functionSelector,
51
+ txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
52
+ argsOfCalls: [...payload.hashedArguments, entrypointHashedArgs],
53
+ authWitnesses: [authWitness],
54
+ capsules,
55
+ });
56
+
57
+ return txRequest;
58
+ }
59
+
60
+ private getEntrypointAbi() {
61
+ return {
62
+ name: 'entrypoint',
63
+ isInitializer: false,
64
+ functionType: 'private',
65
+ isInternal: false,
66
+ isStatic: false,
67
+ parameters: [
68
+ {
69
+ name: 'payload',
70
+ type: {
71
+ kind: 'struct',
72
+ path: 'dapp_payload::DAppPayload',
73
+ fields: [
74
+ {
75
+ name: 'function_calls',
76
+ type: {
77
+ kind: 'array',
78
+ length: 1,
79
+ type: {
80
+ kind: 'struct',
81
+ path: 'authwit::entrypoint::function_call::FunctionCall',
82
+ fields: [
83
+ { name: 'args_hash', type: { kind: 'field' } },
84
+ {
85
+ name: 'function_selector',
86
+ type: {
87
+ kind: 'struct',
88
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
89
+ fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
90
+ },
91
+ },
92
+ {
93
+ name: 'target_address',
94
+ type: {
95
+ kind: 'struct',
96
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
97
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
98
+ },
99
+ },
100
+ { name: 'is_public', type: { kind: 'boolean' } },
101
+ { name: 'is_static', type: { kind: 'boolean' } },
102
+ ],
103
+ },
104
+ },
105
+ },
106
+ { name: 'nonce', type: { kind: 'field' } },
107
+ ],
108
+ },
109
+ visibility: 'public',
110
+ },
111
+ {
112
+ name: 'user_address',
113
+ type: {
114
+ kind: 'struct',
115
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
116
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
117
+ },
118
+ visibility: 'public',
119
+ },
120
+ ],
121
+ returnTypes: [],
122
+ errorTypes: {},
123
+ } as FunctionAbi;
124
+ }
125
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The `@aztec/accounts/defaults` export provides the base class {@link DefaultAccountContract} for implementing account contracts that use the default entrypoint payload module.
3
+ *
4
+ * Read more in {@link https://docs.aztec.network/developers/tutorials/codealong/contract_tutorials/write_accounts_contract | Writing an account contract}.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ export * from './account_entrypoint.js';
10
+ export * from './dapp_entrypoint.js';