@aztec/aztec.js 0.40.0 → 0.41.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 (50) hide show
  1. package/dest/account/interface.d.ts +16 -1
  2. package/dest/account/interface.d.ts.map +1 -1
  3. package/dest/account/interface.js +1 -1
  4. package/dest/account/wallet.d.ts +2 -2
  5. package/dest/account/wallet.d.ts.map +1 -1
  6. package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
  7. package/dest/account_manager/deploy_account_method.js +2 -1
  8. package/dest/contract/contract_function_interaction.d.ts +2 -7
  9. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  10. package/dest/contract/contract_function_interaction.js +15 -33
  11. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
  12. package/dest/entrypoint/default_multi_call_entrypoint.js +4 -2
  13. package/dest/entrypoint/payload.d.ts +2 -0
  14. package/dest/entrypoint/payload.d.ts.map +1 -1
  15. package/dest/entrypoint/payload.js +3 -1
  16. package/dest/fee/native_fee_payment_method.d.ts.map +1 -1
  17. package/dest/fee/native_fee_payment_method.js +3 -2
  18. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  19. package/dest/fee/private_fee_payment_method.js +7 -3
  20. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  21. package/dest/fee/public_fee_payment_method.js +7 -3
  22. package/dest/index.d.ts +1 -1
  23. package/dest/index.d.ts.map +1 -1
  24. package/dest/index.js +2 -2
  25. package/dest/wallet/account_wallet.d.ts +12 -1
  26. package/dest/wallet/account_wallet.d.ts.map +1 -1
  27. package/dest/wallet/account_wallet.js +58 -4
  28. package/dest/wallet/base_wallet.d.ts +4 -2
  29. package/dest/wallet/base_wallet.d.ts.map +1 -1
  30. package/dest/wallet/base_wallet.js +6 -3
  31. package/dest/wallet/create_recipient.d.ts.map +1 -1
  32. package/dest/wallet/create_recipient.js +3 -1
  33. package/dest/wallet/signerless_wallet.d.ts +2 -1
  34. package/dest/wallet/signerless_wallet.d.ts.map +1 -1
  35. package/dest/wallet/signerless_wallet.js +4 -1
  36. package/package.json +7 -7
  37. package/src/account/interface.ts +17 -1
  38. package/src/account/wallet.ts +2 -2
  39. package/src/account_manager/deploy_account_method.ts +1 -0
  40. package/src/contract/contract_function_interaction.ts +18 -31
  41. package/src/entrypoint/default_multi_call_entrypoint.ts +3 -1
  42. package/src/entrypoint/payload.ts +4 -0
  43. package/src/fee/native_fee_payment_method.ts +2 -1
  44. package/src/fee/private_fee_payment_method.ts +7 -2
  45. package/src/fee/public_fee_payment_method.ts +4 -2
  46. package/src/index.ts +2 -1
  47. package/src/wallet/account_wallet.ts +65 -3
  48. package/src/wallet/base_wallet.ts +13 -3
  49. package/src/wallet/create_recipient.ts +2 -0
  50. package/src/wallet/signerless_wallet.ts +5 -1
@@ -1,5 +1,5 @@
1
1
  import { type AuthWitness, type FunctionCall, type PXE, type TxExecutionRequest } from '@aztec/circuit-types';
2
- import { type AztecAddress, Fr } from '@aztec/circuits.js';
2
+ import { AztecAddress, CANONICAL_KEY_REGISTRY_ADDRESS, Fq, Fr, derivePublicKeyFromSecretKey } from '@aztec/circuits.js';
3
3
  import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/foundation/abi';
4
4
 
5
5
  import { type AccountInterface } from '../account/interface.js';
@@ -165,6 +165,30 @@ export class AccountWallet extends BaseWallet {
165
165
  return { isValidInPrivate, isValidInPublic };
166
166
  }
167
167
 
168
+ /**
169
+ * Rotates the account master nullifier key pair.
170
+ * @param newNskM - The new master nullifier secret key we want to use.
171
+ * @remarks - This function also calls the canonical key registry with the account's new derived master nullifier public key.
172
+ * We are doing it this way to avoid user error, in the case that a user rotates their keys in the key registry,
173
+ * but fails to do so in the key store. This leads to unspendable notes.
174
+ *
175
+ * This does not hinder our ability to spend notes tied to a previous master nullifier public key, provided we have the master nullifier secret key for it.
176
+ */
177
+ public async rotateNullifierKeys(newNskM: Fq = Fq.random()): Promise<void> {
178
+ // We rotate our secret key in the keystore first, because if the subsequent interaction fails, there are no bad side-effects.
179
+ // If vice versa (the key registry is called first), but the call to the PXE fails, we will end up in a situation with unspendable notes, as we have not committed our
180
+ // nullifier secret key to our wallet.
181
+ await this.pxe.rotateNskM(this.getAddress(), newNskM);
182
+ const interaction = new ContractFunctionInteraction(
183
+ this,
184
+ AztecAddress.fromBigInt(CANONICAL_KEY_REGISTRY_ADDRESS),
185
+ this.getRotateNpkMAbi(),
186
+ [this.getAddress(), derivePublicKeyFromSecretKey(newNskM), Fr.ZERO],
187
+ );
188
+
189
+ await interaction.send().wait();
190
+ }
191
+
168
192
  /**
169
193
  * Returns a function interaction to cancel a message hash as authorized in this account.
170
194
  * @param messageHashOrIntent - The message or the caller and action to authorize/revoke
@@ -204,8 +228,9 @@ export class AccountWallet extends BaseWallet {
204
228
  return {
205
229
  name: 'approve_public_authwit',
206
230
  isInitializer: false,
207
- functionType: FunctionType.OPEN,
231
+ functionType: FunctionType.PUBLIC,
208
232
  isInternal: true,
233
+ isStatic: false,
209
234
  parameters: [
210
235
  {
211
236
  name: 'message_hash',
@@ -221,8 +246,9 @@ export class AccountWallet extends BaseWallet {
221
246
  return {
222
247
  name: 'cancel_authwit',
223
248
  isInitializer: false,
224
- functionType: FunctionType.SECRET,
249
+ functionType: FunctionType.PRIVATE,
225
250
  isInternal: true,
251
+ isStatic: false,
226
252
  parameters: [
227
253
  {
228
254
  name: 'message_hash',
@@ -240,6 +266,7 @@ export class AccountWallet extends BaseWallet {
240
266
  isInitializer: false,
241
267
  functionType: FunctionType.UNCONSTRAINED,
242
268
  isInternal: false,
269
+ isStatic: false,
243
270
  parameters: [
244
271
  {
245
272
  name: 'myself',
@@ -265,4 +292,39 @@ export class AccountWallet extends BaseWallet {
265
292
  returnTypes: [{ kind: 'array', length: 2, type: { kind: 'boolean' } }],
266
293
  };
267
294
  }
295
+
296
+ private getRotateNpkMAbi(): FunctionAbi {
297
+ return {
298
+ name: 'rotate_npk_m',
299
+ isInitializer: false,
300
+ functionType: FunctionType.PUBLIC,
301
+ isInternal: false,
302
+ isStatic: false,
303
+ parameters: [
304
+ {
305
+ name: 'address',
306
+ type: {
307
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
308
+ kind: 'struct',
309
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
310
+ },
311
+ visibility: 'private' as ABIParameterVisibility,
312
+ },
313
+ {
314
+ name: 'new_npk_m',
315
+ type: {
316
+ fields: [
317
+ { name: 'x', type: { kind: 'field' } },
318
+ { name: 'y', type: { kind: 'field' } },
319
+ ],
320
+ kind: 'struct',
321
+ path: 'authwit::aztec::protocol_types::grumpkin_point::GrumpkinPoint',
322
+ },
323
+ visibility: 'private' as ABIParameterVisibility,
324
+ },
325
+ { name: 'nonce', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
326
+ ],
327
+ returnTypes: [],
328
+ };
329
+ }
268
330
  }
@@ -15,7 +15,7 @@ import {
15
15
  type TxHash,
16
16
  type TxReceipt,
17
17
  } from '@aztec/circuit-types';
18
- import { type AztecAddress, type CompleteAddress, type Fr, type PartialAddress } from '@aztec/circuits.js';
18
+ import { type AztecAddress, type CompleteAddress, type Fq, type Fr, type PartialAddress } from '@aztec/circuits.js';
19
19
  import { type ContractArtifact } from '@aztec/foundation/abi';
20
20
  import { type ContractClassWithId, type ContractInstanceWithAddress } from '@aztec/types/contracts';
21
21
  import { type NodeInfo } from '@aztec/types/interfaces';
@@ -54,6 +54,8 @@ export abstract class BaseWallet implements Wallet {
54
54
  },
55
55
  ): Promise<AuthWitness>;
56
56
 
57
+ abstract rotateNullifierKeys(newNskM: Fq): Promise<void>;
58
+
57
59
  getAddress() {
58
60
  return this.getCompleteAddress().address;
59
61
  }
@@ -69,6 +71,9 @@ export abstract class BaseWallet implements Wallet {
69
71
  registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
70
72
  return this.pxe.registerAccount(secretKey, partialAddress);
71
73
  }
74
+ rotateNskM(address: AztecAddress, secretKey: Fq) {
75
+ return this.pxe.rotateNskM(address, secretKey);
76
+ }
72
77
  registerRecipient(account: CompleteAddress): Promise<void> {
73
78
  return this.pxe.registerRecipient(account);
74
79
  }
@@ -127,8 +132,13 @@ export abstract class BaseWallet implements Wallet {
127
132
  getBlock(number: number): Promise<L2Block | undefined> {
128
133
  return this.pxe.getBlock(number);
129
134
  }
130
- viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress | undefined): Promise<any> {
131
- return this.pxe.viewTx(functionName, args, to, from);
135
+ simulateUnconstrained(
136
+ functionName: string,
137
+ args: any[],
138
+ to: AztecAddress,
139
+ from?: AztecAddress | undefined,
140
+ ): Promise<any> {
141
+ return this.pxe.simulateUnconstrained(functionName, args, to, from);
132
142
  }
133
143
  getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
134
144
  return this.pxe.getUnencryptedLogs(filter);
@@ -8,6 +8,8 @@ import { CompleteAddress } from '@aztec/circuits.js';
8
8
  */
9
9
  export async function createRecipient(pxe: PXE): Promise<CompleteAddress> {
10
10
  const completeAddress = CompleteAddress.random();
11
+ // docs:start:register-recipient
11
12
  await pxe.registerRecipient(completeAddress);
13
+ // docs:end:register-recipient
12
14
  return completeAddress;
13
15
  }
@@ -1,5 +1,5 @@
1
1
  import { type AuthWitness, type PXE, type TxExecutionRequest } from '@aztec/circuit-types';
2
- import { type CompleteAddress, type Fr } from '@aztec/circuits.js';
2
+ import { type CompleteAddress, type Fq, type Fr } from '@aztec/circuits.js';
3
3
 
4
4
  import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js';
5
5
  import { type EntrypointInterface, type ExecutionRequestInit } from '../entrypoint/entrypoint.js';
@@ -42,4 +42,8 @@ export class SignerlessWallet extends BaseWallet {
42
42
  createAuthWit(_messageHash: Fr): Promise<AuthWitness> {
43
43
  throw new Error('Method not implemented.');
44
44
  }
45
+
46
+ rotateNullifierKeys(_newNskM: Fq): Promise<void> {
47
+ throw new Error('Method not implemented.');
48
+ }
45
49
  }