@aztec/entrypoints 0.0.0-test.1 → 0.0.1-fake-ceab37513c

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,7 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
3
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
2
  import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
4
+ import { ExecutionPayload } from './payload.js';
5
5
  /**
6
6
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
7
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -12,7 +12,7 @@ export declare class DefaultAccountEntrypoint implements EntrypointInterface {
12
12
  private chainId;
13
13
  private version;
14
14
  constructor(address: AztecAddress, auth: AuthWitnessProvider, chainId?: number, version?: number);
15
- createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
15
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
16
16
  private getEntrypointAbi;
17
17
  }
18
18
  //# 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,OAAO,CAAC,kBAAkB,CAAC;IA2BvF,OAAO,CAAC,gBAAgB;CAqGzB"}
1
+ {"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;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,CAC5B,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC;IA+C9B,OAAO,CAAC,gBAAgB;CAqGzB"}
@@ -1,7 +1,8 @@
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 { EncodedCallsForEntrypoint, computeCombinedPayloadHash } from './encoding.js';
5
6
  /**
6
7
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
8
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -16,31 +17,47 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
16
17
  this.chainId = chainId;
17
18
  this.version = version;
18
19
  }
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);
20
+ async createTxExecutionRequest(exec, fee, options) {
21
+ // Initial request with calls, authWitnesses and capsules
22
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
23
+ // Global tx options
24
+ const { cancellable, txNonce } = options;
25
+ // Encode the calls for the app
26
+ const appEncodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls, txNonce);
27
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
28
+ const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
29
+ // Encode the calls for the fee
30
+ const feePayer = await fee.paymentMethod.getFeePayer(fee.gasSettings);
31
+ const isFeePayer = feePayer.equals(this.address);
32
+ const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
33
+ // Obtain the entrypoint hashed args, built from the app and fee encoded calls
23
34
  const abi = this.getEntrypointAbi();
24
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
25
- appPayload,
26
- feePayload,
35
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
36
+ appEncodedCalls,
37
+ feeEncodedCalls,
27
38
  !!cancellable
28
39
  ]));
29
- const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload));
40
+ // Generate the combined payload auth witness, by signing the hash of the combined payload
41
+ const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appEncodedCalls, feeEncodedCalls));
42
+ // Assemble the tx request
30
43
  const txRequest = TxExecutionRequest.from({
31
44
  firstCallArgsHash: entrypointHashedArgs.hash,
32
45
  origin: this.address,
33
46
  functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
47
  txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
35
48
  argsOfCalls: [
36
- ...appPayload.hashedArguments,
37
- ...feePayload.hashedArguments,
38
- entrypointHashedArgs
49
+ ...appEncodedCalls.hashedArguments,
50
+ ...feeEncodedCalls.hashedArguments,
51
+ entrypointHashedArgs,
52
+ ...extraHashedArgs
39
53
  ],
40
54
  authWitnesses: [
55
+ ...authWitnesses,
56
+ ...feeAuthwitnesses,
41
57
  combinedPayloadAuthWitness
42
58
  ],
43
- capsules
59
+ capsules,
60
+ salt: Fr.random()
44
61
  });
45
62
  return txRequest;
46
63
  }
@@ -122,7 +139,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
122
139
  }
123
140
  },
124
141
  {
125
- name: 'nonce',
142
+ name: 'tx_nonce',
126
143
  type: {
127
144
  kind: 'field'
128
145
  }
@@ -201,7 +218,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
201
218
  }
202
219
  },
203
220
  {
204
- name: 'nonce',
221
+ name: 'tx_nonce',
205
222
  type: {
206
223
  kind: 'field'
207
224
  }
@@ -0,0 +1,13 @@
1
+ import { TxExecutionRequest } from '@aztec/stdlib/tx';
2
+ import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
3
+ import type { ExecutionPayload } from './payload.js';
4
+ /**
5
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
6
+ */
7
+ export declare class DefaultEntrypoint implements EntrypointInterface {
8
+ private chainId;
9
+ private rollupVersion;
10
+ constructor(chainId: number, rollupVersion: number);
11
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
12
+ }
13
+ //# 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,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,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,CAC5B,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC;CA+B/B"}
@@ -0,0 +1,35 @@
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, fee, options) {
13
+ if (options.txNonce || options.cancellable !== undefined) {
14
+ throw new Error('TxExecutionOptions are not supported in DefaultEntrypoint');
15
+ }
16
+ // Initial request with calls, authWitnesses and capsules
17
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
18
+ if (calls.length > 1) {
19
+ throw new Error(`Expected a single call, got ${calls.length}`);
20
+ }
21
+ const call = calls[0];
22
+ // Hash the arguments for the function call
23
+ const hashedArguments = [
24
+ await HashedValues.fromArgs(call.args)
25
+ ];
26
+ if (call.type !== FunctionType.PRIVATE) {
27
+ throw new Error('Public entrypoints are not allowed');
28
+ }
29
+ // Assemble the tx request
30
+ return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(this.chainId, this.rollupVersion, fee.gasSettings), [
31
+ ...hashedArguments,
32
+ ...extraHashedArgs
33
+ ], authWitnesses, capsules);
34
+ }
35
+ }
@@ -0,0 +1,16 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { EntrypointInterface, FeeOptions } from './interfaces.js';
4
+ import type { ExecutionPayload } from './payload.js';
5
+ /**
6
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
7
+ */
8
+ export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
9
+ private chainId;
10
+ private version;
11
+ private address;
12
+ constructor(chainId: number, version: number, address?: AztecAddress);
13
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise<TxExecutionRequest>;
14
+ private getEntrypointAbi;
15
+ }
16
+ //# 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,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACvE,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,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAkCpG,OAAO,CAAC,gBAAgB;CAwDzB"}
@@ -1,65 +1,52 @@
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 { EncodedCallsForEntrypoint } 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, fee) {
18
+ // Initial request with calls, authWitnesses and capsules
19
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
20
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
21
+ const { calls: feeCalls, authWitnesses: feeAuthwitnesses, extraHashedArgs: feeExtraHashedArgs } = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
22
+ // Encode the calls, including the fee calls
23
+ // (since this entrypoint does not distinguish between app and fee calls)
24
+ const encodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls.concat(feeCalls));
25
+ // Obtain the entrypoint hashed args, built from the encoded calls
28
26
  const abi = this.getEntrypointAbi();
29
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
30
- payload,
31
- this.userAddress
27
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
28
+ encodedCalls
32
29
  ]));
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);
30
+ // Assemble the tx request
48
31
  const txRequest = TxExecutionRequest.from({
49
32
  firstCallArgsHash: entrypointHashedArgs.hash,
50
- origin: this.dappEntrypointAddress,
51
- functionSelector,
33
+ origin: this.address,
34
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
52
35
  txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
53
36
  argsOfCalls: [
54
- ...payload.hashedArguments,
55
- entrypointHashedArgs
37
+ ...encodedCalls.hashedArguments,
38
+ entrypointHashedArgs,
39
+ ...extraHashedArgs,
40
+ ...feeExtraHashedArgs
56
41
  ],
57
42
  authWitnesses: [
58
- authWitness
43
+ ...feeAuthwitnesses,
44
+ ...authWitnesses
59
45
  ],
60
- capsules
46
+ capsules,
47
+ salt: Fr.random()
61
48
  });
62
- return txRequest;
49
+ return Promise.resolve(txRequest);
63
50
  }
64
51
  getEntrypointAbi() {
65
52
  return {
@@ -70,16 +57,16 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
70
57
  isStatic: false,
71
58
  parameters: [
72
59
  {
73
- name: 'payload',
60
+ name: 'app_payload',
74
61
  type: {
75
62
  kind: 'struct',
76
- path: 'dapp_payload::DAppPayload',
63
+ path: 'authwit::entrypoint::app::AppPayload',
77
64
  fields: [
78
65
  {
79
66
  name: 'function_calls',
80
67
  type: {
81
68
  kind: 'array',
82
- length: 1,
69
+ length: 4,
83
70
  type: {
84
71
  kind: 'struct',
85
72
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -111,7 +98,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
111
98
  name: 'target_address',
112
99
  type: {
113
100
  kind: 'struct',
114
- path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
101
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
115
102
  fields: [
116
103
  {
117
104
  name: 'inner',
@@ -139,23 +126,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
139
126
  }
140
127
  },
141
128
  {
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',
129
+ name: 'tx_nonce',
159
130
  type: {
160
131
  kind: 'field'
161
132
  }
@@ -0,0 +1,121 @@
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 = 4;
6
+ declare const FEE_MAX_CALLS = 2;
7
+ /** Encoded function call for an Aztec entrypoint */
8
+ export type EncodedFunctionCall = {
9
+ /** Arguments hash for the call. */
10
+ /** This should be the calldata hash `hash([function_selector, ...args])` if `is_public` is true. */
11
+ args_hash: Fr;
12
+ /** Selector of the function to call */
13
+ function_selector: Fr;
14
+ /** Address of the contract to call */
15
+ target_address: Fr;
16
+ /** Whether the function is public or private */
17
+ is_public: boolean;
18
+ /** Whether the function can alter state */
19
+ is_static: boolean;
20
+ };
21
+ /** Type that represents function calls ready to be sent to a circuit for execution */
22
+ export type EncodedCalls = {
23
+ /** Function calls in the expected format (Noir's convention) */
24
+ encodedFunctionCalls: EncodedFunctionCall[];
25
+ /** The hashed args for the call, ready to be injected in the execution cache */
26
+ hashedArguments: HashedValues[];
27
+ };
28
+ /**
29
+ * Entrypoints derive their arguments from the calls that they'll ultimate make.
30
+ * This utility class helps in creating the payload for the entrypoint by taking into
31
+ * account how the calls are encoded and hashed.
32
+ * */
33
+ export declare abstract class EncodedCallsForEntrypoint implements EncodedCalls {
34
+ /** Function calls in the expected format (Noir's convention) */
35
+ encodedFunctionCalls: EncodedFunctionCall[];
36
+ /** The hashed args for the call, ready to be injected in the execution cache */
37
+ hashedArguments: HashedValues[];
38
+ /** The index of the generator to use for hashing */
39
+ generatorIndex: number;
40
+ /**
41
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
42
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
43
+ * but higher fee. The nullifier ensures only one transaction can succeed.
44
+ */
45
+ tx_nonce: Fr;
46
+ constructor(
47
+ /** Function calls in the expected format (Noir's convention) */
48
+ encodedFunctionCalls: EncodedFunctionCall[],
49
+ /** The hashed args for the call, ready to be injected in the execution cache */
50
+ hashedArguments: HashedValues[],
51
+ /** The index of the generator to use for hashing */
52
+ generatorIndex: number,
53
+ /**
54
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
55
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
56
+ * but higher fee. The nullifier ensures only one transaction can succeed.
57
+ */
58
+ tx_nonce: Fr);
59
+ /**
60
+ * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding
61
+ * @internal
62
+ */
63
+ get function_calls(): EncodedFunctionCall[];
64
+ /**
65
+ * Serializes the payload to an array of fields
66
+ * @returns The fields of the payload
67
+ */
68
+ abstract toFields(): Fr[];
69
+ /**
70
+ * Hashes the payload
71
+ * @returns The hash of the payload
72
+ */
73
+ hash(): Promise<Fr>;
74
+ /** Serializes the function calls to an array of fields. */
75
+ protected functionCallsToFields(): Fr[];
76
+ /**
77
+ * Encodes a set of function calls for a dapp entrypoint
78
+ * @param functionCalls - The function calls to execute
79
+ * @returns The encoded calls
80
+ */
81
+ static fromFunctionCalls(functionCalls: FunctionCall[]): Promise<EncodedAppEntrypointCalls>;
82
+ /**
83
+ * Encodes the functions for the app-portion of a transaction from a set of function calls and a nonce
84
+ * @param functionCalls - The function calls to execute
85
+ * @param txNonce - A nonce used to enable transaction cancellation when cancellable=true. Transactions with the same
86
+ * nonce can be replaced by submitting a new one with a higher fee.
87
+ * @returns The encoded calls
88
+ */
89
+ static fromAppExecution(functionCalls: FunctionCall[] | Tuple<FunctionCall, typeof APP_MAX_CALLS>, txNonce?: Fr): Promise<EncodedAppEntrypointCalls>;
90
+ /**
91
+ * Creates an encoded set of functions to pay the fee for a transaction
92
+ * @param functionCalls - The calls generated by the payment method
93
+ * @param isFeePayer - Whether the sender should be appointed as fee payer
94
+ * @returns The encoded calls
95
+ */
96
+ static fromFeeCalls(functionCalls: FunctionCall[] | Tuple<FunctionCall, typeof FEE_MAX_CALLS>, isFeePayer: boolean): Promise<EncodedFeeEntrypointCalls>;
97
+ }
98
+ /** Encoded calls for app phase execution. */
99
+ export declare class EncodedAppEntrypointCalls extends EncodedCallsForEntrypoint {
100
+ constructor(encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], generatorIndex: number, txNonce: Fr);
101
+ toFields(): Fr[];
102
+ }
103
+ /** Encoded calls for fee payment */
104
+ export declare class EncodedFeeEntrypointCalls extends EncodedCallsForEntrypoint {
105
+ #private;
106
+ constructor(encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], generatorIndex: number, txNonce: Fr, isFeePayer: boolean);
107
+ toFields(): Fr[];
108
+ /** Whether the sender should be appointed as fee payer. */
109
+ get is_fee_payer(): boolean;
110
+ }
111
+ /**
112
+ * Computes a hash of a combined set of app and fee calls.
113
+ * @param appCalls - A set of app calls.
114
+ * @param feeCalls - A set of calls used to pay fees.
115
+ * @returns A hash of a combined call set.
116
+ */
117
+ export declare function computeCombinedPayloadHash(appPayload: EncodedAppEntrypointCalls, feePayload: EncodedFeeEntrypointCalls): Promise<Fr>;
118
+ /** Encodes FunctionCalls for execution, following Noir's convention */
119
+ export declare function encode(calls: FunctionCall[]): Promise<EncodedCalls>;
120
+ export {};
121
+ //# 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,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,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,YAAY,GAAG;IACzB,gEAAgE;IAChE,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;IAC5C,gFAAgF;IAChF,eAAe,EAAE,YAAY,EAAE,CAAC;CACjC,CAAC;AAEF;;;;KAIK;AACL,8BAAsB,yBAA0B,YAAW,YAAY;IAEnE,gEAAgE;IACzD,oBAAoB,EAAE,mBAAmB,EAAE;IAClD,gFAAgF;IACzE,eAAe,EAAE,YAAY,EAAE;IACtC,oDAAoD;IAC7C,cAAc,EAAE,MAAM;IAC7B;;;;OAIG;IAEI,QAAQ,EAAE,EAAE;;IAZnB,gEAAgE;IACzD,oBAAoB,EAAE,mBAAmB,EAAE;IAClD,gFAAgF;IACzE,eAAe,EAAE,YAAY,EAAE;IACtC,oDAAoD;IAC7C,cAAc,EAAE,MAAM;IAC7B;;;;OAIG;IAEI,QAAQ,EAAE,EAAE;IAIrB;;;OAGG;IACH,IAAI,cAAc,0BAEjB;IAGD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,IAAI,EAAE,EAAE;IAEzB;;;OAGG;IACH,IAAI;IAIJ,2DAA2D;IAC3D,SAAS,CAAC,qBAAqB;IAU/B;;;;OAIG;WACU,iBAAiB,CAAC,aAAa,EAAE,YAAY,EAAE;IAK5D;;;;;;OAMG;WACU,gBAAgB,CAC3B,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,OAAO,aAAa,CAAC,EACzE,OAAO,KAAc;IAevB;;;;;OAKG;WACU,YAAY,CACvB,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,OAAO,aAAa,CAAC,EACzE,UAAU,EAAE,OAAO;CAYtB;AAED,6CAA6C;AAC7C,qBAAa,yBAA0B,SAAQ,yBAAyB;gBAEpE,oBAAoB,EAAE,mBAAmB,EAAE,EAC3C,eAAe,EAAE,YAAY,EAAE,EAC/B,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,EAAE;IAKJ,QAAQ,IAAI,EAAE,EAAE;CAG1B;AAED,oCAAoC;AACpC,qBAAa,yBAA0B,SAAQ,yBAAyB;;gBAIpE,oBAAoB,EAAE,mBAAmB,EAAE,EAC3C,eAAe,EAAE,YAAY,EAAE,EAC/B,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,EAAE,EACX,UAAU,EAAE,OAAO;IAMZ,QAAQ,IAAI,EAAE,EAAE;IAKzB,2DAA2D;IAC3D,IAAI,YAAY,YAEf;CAEF;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,yBAAyB,EACrC,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,EAAE,CAAC,CAKb;AAED,uEAAuE;AACvE,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAuBzE"}
@@ -0,0 +1,145 @@
1
+ import { GeneratorIndex } from '@aztec/constants';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
3
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
4
+ import { Fr } from '@aztec/foundation/fields';
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
+ const APP_MAX_CALLS = 4;
10
+ // - and noir-projects/aztec-nr/aztec/src/entrypoint/fee.nr
11
+ const FEE_MAX_CALLS = 2;
12
+ /**
13
+ * Entrypoints derive their arguments from the calls that they'll ultimate make.
14
+ * This utility class helps in creating the payload for the entrypoint by taking into
15
+ * account how the calls are encoded and hashed.
16
+ * */ export class EncodedCallsForEntrypoint {
17
+ encodedFunctionCalls;
18
+ hashedArguments;
19
+ generatorIndex;
20
+ tx_nonce;
21
+ 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, /**
22
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
23
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
24
+ * but higher fee. The nullifier ensures only one transaction can succeed.
25
+ */ // eslint-disable-next-line camelcase
26
+ tx_nonce){
27
+ this.encodedFunctionCalls = encodedFunctionCalls;
28
+ this.hashedArguments = hashedArguments;
29
+ this.generatorIndex = generatorIndex;
30
+ this.tx_nonce = tx_nonce;
31
+ }
32
+ /* eslint-disable camelcase */ /**
33
+ * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding
34
+ * @internal
35
+ */ get function_calls() {
36
+ return this.encodedFunctionCalls;
37
+ }
38
+ /**
39
+ * Hashes the payload
40
+ * @returns The hash of the payload
41
+ */ hash() {
42
+ return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex);
43
+ }
44
+ /** Serializes the function calls to an array of fields. */ functionCallsToFields() {
45
+ return this.encodedFunctionCalls.flatMap((call)=>[
46
+ call.args_hash,
47
+ call.function_selector,
48
+ call.target_address,
49
+ new Fr(call.is_public),
50
+ new Fr(call.is_static)
51
+ ]);
52
+ }
53
+ /**
54
+ * Encodes a set of function calls for a dapp entrypoint
55
+ * @param functionCalls - The function calls to execute
56
+ * @returns The encoded calls
57
+ */ static async fromFunctionCalls(functionCalls) {
58
+ const encoded = await encode(functionCalls);
59
+ return new EncodedAppEntrypointCalls(encoded.encodedFunctionCalls, encoded.hashedArguments, 0, Fr.random());
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 fromAppExecution(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
+ * Creates an encoded set of functions to pay the fee for a transaction
77
+ * @param functionCalls - The calls generated by the payment method
78
+ * @param isFeePayer - Whether the sender should be appointed as fee payer
79
+ * @returns The encoded calls
80
+ */ static async fromFeeCalls(functionCalls, isFeePayer) {
81
+ const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), FEE_MAX_CALLS);
82
+ const encoded = await encode(paddedCalls);
83
+ return new EncodedFeeEntrypointCalls(encoded.encodedFunctionCalls, encoded.hashedArguments, GeneratorIndex.FEE_PAYLOAD, Fr.random(), isFeePayer);
84
+ }
85
+ }
86
+ /** Encoded calls for app phase execution. */ export class EncodedAppEntrypointCalls extends EncodedCallsForEntrypoint {
87
+ constructor(encodedFunctionCalls, hashedArguments, generatorIndex, txNonce){
88
+ super(encodedFunctionCalls, hashedArguments, generatorIndex, txNonce);
89
+ }
90
+ toFields() {
91
+ return [
92
+ ...this.functionCallsToFields(),
93
+ this.tx_nonce
94
+ ];
95
+ }
96
+ }
97
+ /** Encoded calls for fee payment */ export class EncodedFeeEntrypointCalls extends EncodedCallsForEntrypoint {
98
+ #isFeePayer;
99
+ constructor(encodedFunctionCalls, hashedArguments, generatorIndex, txNonce, isFeePayer){
100
+ super(encodedFunctionCalls, hashedArguments, generatorIndex, txNonce);
101
+ this.#isFeePayer = isFeePayer;
102
+ }
103
+ toFields() {
104
+ return [
105
+ ...this.functionCallsToFields(),
106
+ this.tx_nonce,
107
+ new Fr(this.#isFeePayer)
108
+ ];
109
+ }
110
+ /* eslint-disable camelcase */ /** Whether the sender should be appointed as fee payer. */ get is_fee_payer() {
111
+ return this.#isFeePayer;
112
+ }
113
+ }
114
+ /**
115
+ * Computes a hash of a combined set of app and fee calls.
116
+ * @param appCalls - A set of app calls.
117
+ * @param feeCalls - A set of calls used to pay fees.
118
+ * @returns A hash of a combined call set.
119
+ */ export async function computeCombinedPayloadHash(appPayload, feePayload) {
120
+ return poseidon2HashWithSeparator([
121
+ await appPayload.hash(),
122
+ await feePayload.hash()
123
+ ], GeneratorIndex.COMBINED_PAYLOAD);
124
+ }
125
+ /** Encodes FunctionCalls for execution, following Noir's convention */ export async function encode(calls) {
126
+ const hashedArguments = [];
127
+ for (const call of calls){
128
+ const hashed = call.type === FunctionType.PUBLIC ? await HashedValues.fromCalldata([
129
+ call.selector.toField(),
130
+ ...call.args
131
+ ]) : await HashedValues.fromArgs(call.args);
132
+ hashedArguments.push(hashed);
133
+ }
134
+ /* eslint-disable camelcase */ const encodedFunctionCalls = calls.map((call, index)=>({
135
+ args_hash: hashedArguments[index].hash,
136
+ function_selector: call.selector.toField(),
137
+ target_address: call.to.toField(),
138
+ is_public: call.type == FunctionType.PUBLIC,
139
+ is_static: call.isStatic
140
+ }));
141
+ return {
142
+ encodedFunctionCalls,
143
+ hashedArguments
144
+ };
145
+ }
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';
9
+ export * from './interfaces.js';
10
+ export * from './default_entrypoint.js';
11
+ export * from './encoding.js';
12
+ export * from './default_multi_call_entrypoint.js';
10
13
  //# sourceMappingURL=index.d.ts.map
@@ -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';