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

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,7 +1,49 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
1
+ import { Fr } from '@aztec/foundation/fields';
3
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { GasSettings } from '@aztec/stdlib/gas';
4
4
  import { TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import type { AuthWitnessProvider, EntrypointInterface } from './interfaces.js';
6
+ import { ExecutionPayload } from './payload.js';
7
+ /**
8
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
9
+ */
10
+ export declare enum AccountFeePaymentMethodOptions {
11
+ /**
12
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
13
+ */
14
+ EXTERNAL = 0,
15
+ /**
16
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
17
+ * **which it must already have prior to this transaction**.
18
+ *
19
+ * The contract will set itself as the fee payer and end the setup phase.
20
+ */
21
+ PREEXISTING_FEE_JUICE = 1,
22
+ /**
23
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
24
+ * **which is being claimed in the same transaction**.
25
+ *
26
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
27
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
28
+ * to be executable during the setup phase.
29
+ */
30
+ FEE_JUICE_WITH_CLAIM = 2
31
+ }
32
+ /**
33
+ * General options for the tx execution.
34
+ */
35
+ export type DefaultAccountEntrypointOptions = {
36
+ /** Whether the transaction can be cancelled. */
37
+ cancellable?: boolean;
38
+ /**
39
+ * A nonce to inject into the app payload of the transaction. When used with cancellable=true, this nonce will be
40
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
41
+ * but higher fee. The nullifier ensures only one transaction can succeed.
42
+ */
43
+ txNonce?: Fr;
44
+ /** Options that configure how the account contract behaves depending on the fee payment method of the tx */
45
+ feePaymentMethodOptions: AccountFeePaymentMethodOptions;
46
+ };
5
47
  /**
6
48
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
49
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -12,7 +54,7 @@ export declare class DefaultAccountEntrypoint implements EntrypointInterface {
12
54
  private chainId;
13
55
  private version;
14
56
  constructor(address: AztecAddress, auth: AuthWitnessProvider, chainId?: number, version?: number);
15
- createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
57
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, options: DefaultAccountEntrypointOptions): Promise<TxExecutionRequest>;
16
58
  private getEntrypointAbi;
17
59
  }
18
60
  //# sourceMappingURL=account_entrypoint.d.ts.map
@@ -1 +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,O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AC,gBAAgB;CA2DzB"}
@@ -1,7 +1,30 @@
1
- import { EntrypointPayload, computeCombinedPayloadHash } from '@aztec/aztec.js/entrypoint';
1
+ import { Fr } from '@aztec/foundation/fields';
2
2
  import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
3
  import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
4
  import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
5
+ import { EncodedAppEntrypointCalls } from './encoding.js';
6
+ /**
7
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
8
+ */ export var AccountFeePaymentMethodOptions = /*#__PURE__*/ function(AccountFeePaymentMethodOptions) {
9
+ /**
10
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
11
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["EXTERNAL"] = 0] = "EXTERNAL";
12
+ /**
13
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
14
+ * **which it must already have prior to this transaction**.
15
+ *
16
+ * The contract will set itself as the fee payer and end the setup phase.
17
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["PREEXISTING_FEE_JUICE"] = 1] = "PREEXISTING_FEE_JUICE";
18
+ /**
19
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
20
+ * **which is being claimed in the same transaction**.
21
+ *
22
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
23
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
24
+ * to be executable during the setup phase.
25
+ */ AccountFeePaymentMethodOptions[AccountFeePaymentMethodOptions["FEE_JUICE_WITH_CLAIM"] = 2] = "FEE_JUICE_WITH_CLAIM";
26
+ return AccountFeePaymentMethodOptions;
27
+ }({});
5
28
  /**
6
29
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
30
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -16,31 +39,39 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
16
39
  this.chainId = chainId;
17
40
  this.version = version;
18
41
  }
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);
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
23
50
  const abi = this.getEntrypointAbi();
24
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
25
- appPayload,
26
- feePayload,
51
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
52
+ encodedCalls,
53
+ feePaymentMethodOptions,
27
54
  !!cancellable
28
55
  ]));
29
- const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload));
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
30
59
  const txRequest = TxExecutionRequest.from({
31
60
  firstCallArgsHash: entrypointHashedArgs.hash,
32
61
  origin: this.address,
33
62
  functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
63
+ txContext: new TxContext(this.chainId, this.version, gasSettings),
35
64
  argsOfCalls: [
36
- ...appPayload.hashedArguments,
37
- ...feePayload.hashedArguments,
38
- entrypointHashedArgs
65
+ ...encodedCalls.hashedArguments,
66
+ entrypointHashedArgs,
67
+ ...extraHashedArgs
39
68
  ],
40
69
  authWitnesses: [
41
- combinedPayloadAuthWitness
70
+ ...authWitnesses,
71
+ appPayloadAuthwitness
42
72
  ],
43
- capsules
73
+ capsules,
74
+ salt: Fr.random()
44
75
  });
45
76
  return txRequest;
46
77
  }
@@ -62,7 +93,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
62
93
  name: 'function_calls',
63
94
  type: {
64
95
  kind: 'array',
65
- length: 4,
96
+ length: 5,
66
97
  type: {
67
98
  kind: 'struct',
68
99
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -112,80 +143,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
112
143
  }
113
144
  },
114
145
  {
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',
146
+ name: 'hide_msg_sender',
189
147
  type: {
190
148
  kind: 'boolean'
191
149
  }
@@ -201,21 +159,23 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
201
159
  }
202
160
  },
203
161
  {
204
- name: 'nonce',
162
+ name: 'tx_nonce',
205
163
  type: {
206
164
  kind: 'field'
207
165
  }
208
- },
209
- {
210
- name: 'is_fee_payer',
211
- type: {
212
- kind: 'boolean'
213
- }
214
166
  }
215
167
  ]
216
168
  },
217
169
  visibility: 'public'
218
170
  },
171
+ {
172
+ name: 'fee_payment_method',
173
+ type: {
174
+ kind: 'integer',
175
+ sign: 'unsigned',
176
+ width: 8
177
+ }
178
+ },
219
179
  {
220
180
  name: 'cancellable',
221
181
  type: {
@@ -0,0 +1,14 @@
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';
5
+ /**
6
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
7
+ */
8
+ 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>;
13
+ }
14
+ //# sourceMappingURL=default_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,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"}
@@ -0,0 +1,32 @@
1
+ import { FunctionType } from '@aztec/stdlib/abi';
2
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ /**
4
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
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) {
13
+ // Initial request with calls, authWitnesses and capsules
14
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
15
+ if (calls.length > 1) {
16
+ throw new Error(`Expected a single call, got ${calls.length}`);
17
+ }
18
+ const call = calls[0];
19
+ // Hash the arguments for the function call
20
+ const hashedArguments = [
21
+ await HashedValues.fromArgs(call.args)
22
+ ];
23
+ if (call.type !== FunctionType.PRIVATE) {
24
+ throw new Error('Public entrypoints are not allowed');
25
+ }
26
+ // Assemble the tx request
27
+ return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(this.chainId, this.rollupVersion, gasSettings), [
28
+ ...hashedArguments,
29
+ ...extraHashedArgs
30
+ ], authWitnesses, capsules);
31
+ }
32
+ }
@@ -0,0 +1,17 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
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';
6
+ /**
7
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
8
+ */
9
+ export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
10
+ private chainId;
11
+ private version;
12
+ private address;
13
+ constructor(chainId: number, version: number, address?: AztecAddress);
14
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest>;
15
+ private getEntrypointAbi;
16
+ }
17
+ //# sourceMappingURL=default_multi_call_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_multi_call_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_multi_call_entrypoint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAElE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAFP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,YAA0D;IAGvE,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA0B7G,OAAO,CAAC,gBAAgB;CAyDzB"}
@@ -1,65 +1,45 @@
1
- import { Fr, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js';
2
- import { EntrypointPayload } from '@aztec/aztec.js/entrypoint';
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
3
  import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
4
  import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
- import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
5
+ import { EncodedAppEntrypointCalls } from './encoding.js';
6
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;
7
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
8
+ */ export class DefaultMultiCallEntrypoint {
13
9
  chainId;
14
10
  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;
11
+ address;
12
+ constructor(chainId, version, address = ProtocolContractAddress.MultiCallEntrypoint){
19
13
  this.chainId = chainId;
20
14
  this.version = version;
15
+ this.address = address;
21
16
  }
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);
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
28
23
  const abi = this.getEntrypointAbi();
29
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
30
- payload,
31
- this.userAddress
24
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
25
+ encodedCalls
32
26
  ]));
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);
27
+ // Assemble the tx request
48
28
  const txRequest = TxExecutionRequest.from({
49
29
  firstCallArgsHash: entrypointHashedArgs.hash,
50
- origin: this.dappEntrypointAddress,
51
- functionSelector,
52
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
30
+ origin: this.address,
31
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
32
+ txContext: new TxContext(this.chainId, this.version, gasSettings),
53
33
  argsOfCalls: [
54
- ...payload.hashedArguments,
55
- entrypointHashedArgs
56
- ],
57
- authWitnesses: [
58
- authWitness
34
+ ...encodedCalls.hashedArguments,
35
+ entrypointHashedArgs,
36
+ ...extraHashedArgs
59
37
  ],
60
- capsules
38
+ authWitnesses,
39
+ capsules,
40
+ salt: Fr.random()
61
41
  });
62
- return txRequest;
42
+ return Promise.resolve(txRequest);
63
43
  }
64
44
  getEntrypointAbi() {
65
45
  return {
@@ -70,16 +50,16 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
70
50
  isStatic: false,
71
51
  parameters: [
72
52
  {
73
- name: 'payload',
53
+ name: 'app_payload',
74
54
  type: {
75
55
  kind: 'struct',
76
- path: 'dapp_payload::DAppPayload',
56
+ path: 'authwit::entrypoint::app::AppPayload',
77
57
  fields: [
78
58
  {
79
59
  name: 'function_calls',
80
60
  type: {
81
61
  kind: 'array',
82
- length: 1,
62
+ length: 5,
83
63
  type: {
84
64
  kind: 'struct',
85
65
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -111,7 +91,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
111
91
  name: 'target_address',
112
92
  type: {
113
93
  kind: 'struct',
114
- path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
94
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
115
95
  fields: [
116
96
  {
117
97
  name: 'inner',
@@ -128,6 +108,12 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
128
108
  kind: 'boolean'
129
109
  }
130
110
  },
111
+ {
112
+ name: 'hide_msg_sender',
113
+ type: {
114
+ kind: 'boolean'
115
+ }
116
+ },
131
117
  {
132
118
  name: 'is_static',
133
119
  type: {
@@ -139,23 +125,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
139
125
  }
140
126
  },
141
127
  {
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',
128
+ name: 'tx_nonce',
159
129
  type: {
160
130
  kind: 'field'
161
131
  }
@@ -0,0 +1,89 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { Tuple } from '@aztec/foundation/serialize';
3
+ import { FunctionCall } from '@aztec/stdlib/abi';
4
+ import { HashedValues } from '@aztec/stdlib/tx';
5
+ 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
+ export {};
89
+ //# sourceMappingURL=encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,QAAA,MAAM,aAAa,IAAI,CAAC;AAExB,oDAAoD;AACpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,mCAAmC;IACnC,oGAAoG;IACpG,SAAS,EAAE,EAAE,CAAC;IACd,uCAAuC;IACvC,iBAAiB,EAAE,EAAE,CAAC;IACtB,sCAAsC;IACtC,cAAc,EAAE,EAAE,CAAC;IACnB,gDAAgD;IAChD,SAAS,EAAE,OAAO,CAAC;IACnB,wGAAwG;IACxG,eAAe,EAAE,OAAO,CAAC;IACzB,2CAA2C;IAC3C,SAAS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