@aztec/aztec.js 0.30.1 → 0.32.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.
Files changed (75) hide show
  1. package/README.md +1 -1
  2. package/dest/account/index.d.ts +1 -1
  3. package/dest/account/index.d.ts.map +1 -1
  4. package/dest/account/interface.d.ts +12 -21
  5. package/dest/account/interface.d.ts.map +1 -1
  6. package/dest/account/interface.js +1 -1
  7. package/dest/api/account.d.ts +1 -1
  8. package/dest/api/account.d.ts.map +1 -1
  9. package/dest/api/account.js +1 -1
  10. package/dest/api/entrypoint.d.ts +2 -0
  11. package/dest/api/entrypoint.d.ts.map +1 -0
  12. package/dest/api/entrypoint.js +2 -0
  13. package/dest/contract/base_contract_interaction.d.ts +1 -1
  14. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  15. package/dest/contract/checker.js +2 -2
  16. package/dest/contract/deploy_method.d.ts +2 -2
  17. package/dest/contract/deploy_method.d.ts.map +1 -1
  18. package/dest/contract/deploy_method.js +4 -9
  19. package/dest/contract/sent_tx.d.ts +2 -0
  20. package/dest/contract/sent_tx.d.ts.map +1 -1
  21. package/dest/contract/sent_tx.js +3 -3
  22. package/dest/deployment/broadcast_function.d.ts.map +1 -1
  23. package/dest/deployment/broadcast_function.js +16 -31
  24. package/dest/entrypoint/default_entrypoint.d.ts +12 -0
  25. package/dest/entrypoint/default_entrypoint.d.ts.map +1 -0
  26. package/dest/entrypoint/default_entrypoint.js +18 -0
  27. package/dest/entrypoint/entrypoint.d.ts +23 -0
  28. package/dest/entrypoint/entrypoint.d.ts.map +1 -0
  29. package/dest/entrypoint/entrypoint.js +2 -0
  30. package/dest/fee/native_fee_payment_method.d.ts.map +1 -1
  31. package/dest/fee/native_fee_payment_method.js +1 -6
  32. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  33. package/dest/fee/private_fee_payment_method.js +2 -2
  34. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  35. package/dest/fee/public_fee_payment_method.js +2 -2
  36. package/dest/index.d.ts +1 -1
  37. package/dest/index.d.ts.map +1 -1
  38. package/dest/index.js +2 -2
  39. package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
  40. package/dest/rpc_clients/pxe_client.js +3 -3
  41. package/dest/utils/authwit.d.ts +8 -4
  42. package/dest/utils/authwit.d.ts.map +1 -1
  43. package/dest/utils/authwit.js +12 -8
  44. package/dest/utils/cheat_codes.js +2 -2
  45. package/dest/wallet/account_wallet.d.ts +45 -7
  46. package/dest/wallet/account_wallet.d.ts.map +1 -1
  47. package/dest/wallet/account_wallet.js +75 -17
  48. package/dest/wallet/base_wallet.d.ts +8 -1
  49. package/dest/wallet/base_wallet.d.ts.map +1 -1
  50. package/dest/wallet/base_wallet.js +4 -1
  51. package/dest/wallet/signerless_wallet.d.ts +7 -2
  52. package/dest/wallet/signerless_wallet.d.ts.map +1 -1
  53. package/dest/wallet/signerless_wallet.js +18 -11
  54. package/package.json +8 -7
  55. package/src/account/index.ts +1 -1
  56. package/src/account/interface.ts +14 -23
  57. package/src/api/account.ts +1 -9
  58. package/src/api/entrypoint.ts +1 -0
  59. package/src/contract/base_contract_interaction.ts +1 -1
  60. package/src/contract/checker.ts +1 -1
  61. package/src/contract/deploy_method.ts +3 -9
  62. package/src/contract/sent_tx.ts +4 -2
  63. package/src/deployment/broadcast_function.ts +39 -47
  64. package/src/entrypoint/default_entrypoint.ts +27 -0
  65. package/src/entrypoint/entrypoint.ts +25 -0
  66. package/src/fee/native_fee_payment_method.ts +0 -5
  67. package/src/fee/private_fee_payment_method.ts +10 -5
  68. package/src/fee/public_fee_payment_method.ts +14 -8
  69. package/src/index.ts +2 -0
  70. package/src/rpc_clients/pxe_client.ts +3 -2
  71. package/src/utils/authwit.ts +12 -12
  72. package/src/utils/cheat_codes.ts +1 -1
  73. package/src/wallet/account_wallet.ts +123 -18
  74. package/src/wallet/base_wallet.ts +12 -1
  75. package/src/wallet/signerless_wallet.ts +23 -19
@@ -2,8 +2,9 @@ import { AuthWitness, FunctionCall, PXE, TxExecutionRequest } from '@aztec/circu
2
2
  import { AztecAddress, Fr } from '@aztec/circuits.js';
3
3
  import { ABIParameterVisibility, FunctionAbi, FunctionType } from '@aztec/foundation/abi';
4
4
 
5
- import { AccountInterface, FeeOptions } from '../account/interface.js';
5
+ import { AccountInterface } from '../account/interface.js';
6
6
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
7
+ import { FeeOptions } from '../entrypoint/entrypoint.js';
7
8
  import { computeAuthWitMessageHash } from '../utils/authwit.js';
8
9
  import { BaseWallet } from './base_wallet.js';
9
10
 
@@ -19,6 +20,14 @@ export class AccountWallet extends BaseWallet {
19
20
  return this.account.createTxExecutionRequest(execs, fee);
20
21
  }
21
22
 
23
+ getChainId(): Fr {
24
+ return this.account.getChainId();
25
+ }
26
+
27
+ getVersion(): Fr {
28
+ return this.account.getVersion();
29
+ }
30
+
22
31
  /**
23
32
  * Computes an authentication witness from either a message or a caller and an action.
24
33
  * If a message is provided, it will create a witness for the message directly.
@@ -35,6 +44,10 @@ export class AccountWallet extends BaseWallet {
35
44
  caller: AztecAddress;
36
45
  /** The action to approve */
37
46
  action: ContractFunctionInteraction | FunctionCall;
47
+ /** The chain id to approve */
48
+ chainId?: Fr;
49
+ /** The version to approve */
50
+ version?: Fr;
38
51
  },
39
52
  ): Promise<AuthWitness> {
40
53
  const messageHash = this.getMessageHash(messageHashOrIntent);
@@ -43,6 +56,37 @@ export class AccountWallet extends BaseWallet {
43
56
  return witness;
44
57
  }
45
58
 
59
+ /**
60
+ * Returns a function interaction to set a message hash as authorized or revoked in this account.
61
+ * Public calls can then consume this authorization.
62
+ * @param messageHashOrIntent - The message or the caller and action to authorize/revoke
63
+ * @param authorized - True to authorize, false to revoke authorization.
64
+ * @returns - A function interaction.
65
+ */
66
+ public setPublicAuthWit(
67
+ messageHashOrIntent:
68
+ | Fr
69
+ | Buffer
70
+ | {
71
+ /** The caller to approve */
72
+ caller: AztecAddress;
73
+ /** The action to approve */
74
+ action: ContractFunctionInteraction | FunctionCall;
75
+ /** The chain id to approve */
76
+ chainId?: Fr;
77
+ /** The version to approve */
78
+ version?: Fr;
79
+ },
80
+ authorized: boolean,
81
+ ): ContractFunctionInteraction {
82
+ const message = this.getMessageHash(messageHashOrIntent);
83
+ if (authorized) {
84
+ return new ContractFunctionInteraction(this, this.getAddress(), this.getApprovePublicAuthwitAbi(), [message]);
85
+ } else {
86
+ return this.cancelAuthWit(message);
87
+ }
88
+ }
89
+
46
90
  /**
47
91
  * Returns the message hash for the given message or authwit input.
48
92
  * @param messageHashOrIntent - The message hash or the caller and action to authorize
@@ -57,26 +101,37 @@ export class AccountWallet extends BaseWallet {
57
101
  caller: AztecAddress;
58
102
  /** The action to approve */
59
103
  action: ContractFunctionInteraction | FunctionCall;
104
+ /** The chain id to approve */
105
+ chainId?: Fr;
106
+ /** The version to approve */
107
+ version?: Fr;
60
108
  },
61
109
  ): Fr {
62
110
  if (Buffer.isBuffer(messageHashOrIntent)) {
63
111
  return Fr.fromBuffer(messageHashOrIntent);
64
112
  } else if (messageHashOrIntent instanceof Fr) {
65
113
  return messageHashOrIntent;
66
- } else if (messageHashOrIntent.action instanceof ContractFunctionInteraction) {
67
- return computeAuthWitMessageHash(messageHashOrIntent.caller, messageHashOrIntent.action.request());
114
+ } else {
115
+ return computeAuthWitMessageHash(
116
+ messageHashOrIntent.caller,
117
+ messageHashOrIntent.chainId || this.getChainId(),
118
+ messageHashOrIntent.version || this.getVersion(),
119
+ messageHashOrIntent.action instanceof ContractFunctionInteraction
120
+ ? messageHashOrIntent.action.request()
121
+ : messageHashOrIntent.action,
122
+ );
68
123
  }
69
- return computeAuthWitMessageHash(messageHashOrIntent.caller, messageHashOrIntent.action);
70
124
  }
71
125
 
72
126
  /**
73
- * Returns a function interaction to set a message hash as authorized or revoked in this account.
74
- * Public calls can then consume this authorization.
75
- * @param messageHashOrIntent - The message or the caller and action to authorize/revoke
76
- * @param authorized - True to authorize, false to revoke authorization.
77
- * @returns - A function interaction.
127
+ * Lookup the validity of an authwit in private and public contexts.
128
+ * If the authwit have been consumed already (nullifier spent), will return false in both contexts.
129
+ * @param target - The target contract address
130
+ * @param messageHashOrIntent - The message hash or the caller and action to authorize/revoke
131
+ * @returns - A struct containing the validity of the authwit in private and public contexts.
78
132
  */
79
- public setPublicAuthWit(
133
+ async lookupValidity(
134
+ target: AztecAddress,
80
135
  messageHashOrIntent:
81
136
  | Fr
82
137
  | Buffer
@@ -85,15 +140,29 @@ export class AccountWallet extends BaseWallet {
85
140
  caller: AztecAddress;
86
141
  /** The action to approve */
87
142
  action: ContractFunctionInteraction | FunctionCall;
143
+ /** The chain id to approve */
144
+ chainId?: Fr;
145
+ /** The version to approve */
146
+ version?: Fr;
88
147
  },
89
- authorized: boolean,
90
- ): ContractFunctionInteraction {
91
- const message = this.getMessageHash(messageHashOrIntent);
92
- if (authorized) {
93
- return new ContractFunctionInteraction(this, this.getAddress(), this.getApprovePublicAuthwitAbi(), [message]);
94
- } else {
95
- return this.cancelAuthWit(message);
96
- }
148
+ ): Promise<{
149
+ /** boolean flag indicating if the authwit is valid in private context */
150
+ isValidInPrivate: boolean;
151
+ /** boolean flag indicating if the authwit is valid in public context */
152
+ isValidInPublic: boolean;
153
+ }> {
154
+ const messageHash = this.getMessageHash(messageHashOrIntent);
155
+ const witness = await this.getAuthWitness(messageHash);
156
+ const blockNumber = await this.getBlockNumber();
157
+ const interaction = new ContractFunctionInteraction(this, target, this.getLookupValidityAbi(), [
158
+ target,
159
+ blockNumber,
160
+ witness != undefined,
161
+ messageHash,
162
+ ]);
163
+
164
+ const [isValidInPrivate, isValidInPublic] = await interaction.view();
165
+ return { isValidInPrivate, isValidInPublic };
97
166
  }
98
167
 
99
168
  /**
@@ -110,6 +179,10 @@ export class AccountWallet extends BaseWallet {
110
179
  caller: AztecAddress;
111
180
  /** The action to approve */
112
181
  action: ContractFunctionInteraction | FunctionCall;
182
+ /** The chain id to approve */
183
+ chainId?: Fr;
184
+ /** The version to approve */
185
+ version?: Fr;
113
186
  },
114
187
  ): ContractFunctionInteraction {
115
188
  const message = this.getMessageHash(messageHashOrIntent);
@@ -160,4 +233,36 @@ export class AccountWallet extends BaseWallet {
160
233
  returnTypes: [],
161
234
  };
162
235
  }
236
+
237
+ private getLookupValidityAbi(): FunctionAbi {
238
+ return {
239
+ name: 'lookup_validity',
240
+ isInitializer: false,
241
+ functionType: FunctionType.UNCONSTRAINED,
242
+ isInternal: false,
243
+ parameters: [
244
+ {
245
+ name: 'myself',
246
+ type: {
247
+ kind: 'struct',
248
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
249
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
250
+ },
251
+ visibility: 'private' as ABIParameterVisibility,
252
+ },
253
+ {
254
+ name: 'block_number',
255
+ type: { kind: 'integer', sign: 'unsigned', width: 32 },
256
+ visibility: 'private' as ABIParameterVisibility,
257
+ },
258
+ {
259
+ name: 'check_private',
260
+ type: { kind: 'boolean' },
261
+ visibility: 'private' as ABIParameterVisibility,
262
+ },
263
+ { name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
264
+ ],
265
+ returnTypes: [{ kind: 'array', length: 2, type: { kind: 'boolean' } }],
266
+ };
267
+ }
163
268
  }
@@ -19,9 +19,9 @@ import { ContractArtifact } from '@aztec/foundation/abi';
19
19
  import { ContractClassWithId, ContractInstanceWithAddress } from '@aztec/types/contracts';
20
20
  import { NodeInfo } from '@aztec/types/interfaces';
21
21
 
22
- import { FeeOptions } from '../account/interface.js';
23
22
  import { Wallet } from '../account/wallet.js';
24
23
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
24
+ import { FeeOptions } from '../entrypoint/entrypoint.js';
25
25
 
26
26
  /**
27
27
  * A base class for Wallet implementations
@@ -31,6 +31,10 @@ export abstract class BaseWallet implements Wallet {
31
31
 
32
32
  abstract getCompleteAddress(): CompleteAddress;
33
33
 
34
+ abstract getChainId(): Fr;
35
+
36
+ abstract getVersion(): Fr;
37
+
34
38
  abstract createTxExecutionRequest(execs: FunctionCall[], fee?: FeeOptions): Promise<TxExecutionRequest>;
35
39
 
36
40
  abstract createAuthWit(
@@ -42,6 +46,10 @@ export abstract class BaseWallet implements Wallet {
42
46
  caller: AztecAddress;
43
47
  /** The action to approve */
44
48
  action: ContractFunctionInteraction | FunctionCall;
49
+ /** The chain id to approve */
50
+ chainId?: Fr;
51
+ /** The version to approve */
52
+ version?: Fr;
45
53
  },
46
54
  ): Promise<AuthWitness>;
47
55
 
@@ -139,6 +147,9 @@ export abstract class BaseWallet implements Wallet {
139
147
  addAuthWitness(authWitness: AuthWitness) {
140
148
  return this.pxe.addAuthWitness(authWitness);
141
149
  }
150
+ getAuthWitness(messageHash: Fr) {
151
+ return this.pxe.getAuthWitness(messageHash);
152
+ }
142
153
  isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
143
154
  return this.pxe.isContractClassPubliclyRegistered(id);
144
155
  }
@@ -1,37 +1,41 @@
1
- import { AuthWitness, FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/circuit-types';
2
- import { CompleteAddress, Fr, TxContext } from '@aztec/circuits.js';
1
+ import { AuthWitness, FunctionCall, PXE, TxExecutionRequest } from '@aztec/circuit-types';
2
+ import { CompleteAddress, Fr } from '@aztec/circuits.js';
3
3
 
4
+ import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js';
5
+ import { EntrypointInterface } from '../entrypoint/entrypoint.js';
4
6
  import { BaseWallet } from './base_wallet.js';
5
7
 
6
8
  /**
7
9
  * Wallet implementation which creates a transaction request directly to the requested contract without any signing.
8
10
  */
9
11
  export class SignerlessWallet extends BaseWallet {
12
+ constructor(pxe: PXE, private entrypoint?: EntrypointInterface) {
13
+ super(pxe);
14
+ }
15
+
10
16
  async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
11
- if (executions.length !== 1) {
12
- throw new Error(`Unexpected number of executions. Expected 1 but received ${executions.length}.`);
17
+ let entrypoint = this.entrypoint;
18
+ if (!entrypoint) {
19
+ const { chainId, protocolVersion } = await this.pxe.getNodeInfo();
20
+ entrypoint = new DefaultEntrypoint(chainId, protocolVersion);
13
21
  }
14
- const [execution] = executions;
15
- const packedArguments = PackedArguments.fromArgs(execution.args);
16
- const { chainId, protocolVersion } = await this.pxe.getNodeInfo();
17
- const txContext = TxContext.empty(chainId, protocolVersion);
18
- return Promise.resolve(
19
- new TxExecutionRequest(
20
- execution.to,
21
- execution.functionData,
22
- packedArguments.hash,
23
- txContext,
24
- [packedArguments],
25
- [],
26
- ),
27
- );
22
+
23
+ return entrypoint.createTxExecutionRequest(executions);
24
+ }
25
+
26
+ getChainId(): Fr {
27
+ throw new Error('Method not implemented.');
28
+ }
29
+
30
+ getVersion(): Fr {
31
+ throw new Error('Method not implemented.');
28
32
  }
29
33
 
30
34
  getCompleteAddress(): CompleteAddress {
31
35
  throw new Error('Method not implemented.');
32
36
  }
33
37
 
34
- createAuthWit(_message: Fr): Promise<AuthWitness> {
38
+ createAuthWit(_messageHash: Fr): Promise<AuthWitness> {
35
39
  throw new Error('Method not implemented.');
36
40
  }
37
41
  }