@aztec/aztec.js 0.42.0 → 0.44.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 (56) hide show
  1. package/dest/account/interface.d.ts +5 -19
  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 +5 -2
  5. package/dest/account/wallet.d.ts.map +1 -1
  6. package/dest/account_manager/index.d.ts +1 -2
  7. package/dest/account_manager/index.d.ts.map +1 -1
  8. package/dest/account_manager/index.js +4 -11
  9. package/dest/api/abi.d.ts +1 -1
  10. package/dest/api/abi.d.ts.map +1 -1
  11. package/dest/api/abi.js +2 -2
  12. package/dest/contract/sent_tx.d.ts.map +1 -1
  13. package/dest/contract/sent_tx.js +6 -4
  14. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  15. package/dest/fee/private_fee_payment_method.js +12 -11
  16. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  17. package/dest/fee/public_fee_payment_method.js +15 -12
  18. package/dest/index.d.ts +4 -3
  19. package/dest/index.d.ts.map +1 -1
  20. package/dest/index.js +4 -3
  21. package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
  22. package/dest/rpc_clients/pxe_client.js +3 -1
  23. package/dest/utils/abi_types.d.ts +4 -2
  24. package/dest/utils/abi_types.d.ts.map +1 -1
  25. package/dest/utils/account.js +3 -3
  26. package/dest/utils/authwit.d.ts +45 -29
  27. package/dest/utils/authwit.d.ts.map +1 -1
  28. package/dest/utils/authwit.js +35 -17
  29. package/dest/utils/cheat_codes.d.ts.map +1 -1
  30. package/dest/utils/cheat_codes.js +6 -2
  31. package/dest/wallet/account_wallet.d.ts +27 -58
  32. package/dest/wallet/account_wallet.d.ts.map +1 -1
  33. package/dest/wallet/account_wallet.js +92 -79
  34. package/dest/wallet/base_wallet.d.ts +9 -14
  35. package/dest/wallet/base_wallet.d.ts.map +1 -1
  36. package/dest/wallet/base_wallet.js +15 -3
  37. package/dest/wallet/signerless_wallet.d.ts +3 -1
  38. package/dest/wallet/signerless_wallet.d.ts.map +1 -1
  39. package/dest/wallet/signerless_wallet.js +2 -2
  40. package/package.json +16 -9
  41. package/src/account/interface.ts +5 -24
  42. package/src/account/wallet.ts +7 -2
  43. package/src/account_manager/index.ts +7 -9
  44. package/src/api/abi.ts +1 -1
  45. package/src/contract/sent_tx.ts +5 -3
  46. package/src/fee/private_fee_payment_method.ts +4 -8
  47. package/src/fee/public_fee_payment_method.ts +17 -16
  48. package/src/index.ts +8 -3
  49. package/src/rpc_clients/pxe_client.ts +3 -1
  50. package/src/utils/abi_types.ts +11 -2
  51. package/src/utils/account.ts +2 -2
  52. package/src/utils/authwit.ts +66 -21
  53. package/src/utils/cheat_codes.ts +5 -1
  54. package/src/wallet/account_wallet.ts +112 -152
  55. package/src/wallet/base_wallet.ts +32 -21
  56. package/src/wallet/signerless_wallet.ts +2 -2
@@ -19,7 +19,7 @@ import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
19
19
  */
20
20
  export type DeployAccountOptions = Pick<
21
21
  DeployOptions,
22
- 'fee' | 'skipClassRegistration' | 'skipPublicDeployment' | 'estimateGas'
22
+ 'fee' | 'skipClassRegistration' | 'skipPublicDeployment' | 'estimateGas' | 'skipInitialization'
23
23
  >;
24
24
 
25
25
  /**
@@ -104,12 +104,13 @@ export class AccountManager {
104
104
  * @returns A Wallet instance.
105
105
  */
106
106
  public async register(opts: WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithSecretKey> {
107
- await this.#register();
108
107
  await this.pxe.registerContract({
109
108
  artifact: this.accountContract.getContractArtifact(),
110
109
  instance: this.getInstance(),
111
110
  });
112
111
 
112
+ await this.pxe.registerAccount(this.secretKey, this.getCompleteAddress().partialAddress);
113
+
113
114
  await waitForAccountSynch(this.pxe, this.getCompleteAddress(), opts);
114
115
  return this.getWallet();
115
116
  }
@@ -127,7 +128,9 @@ export class AccountManager {
127
128
  `Account contract ${this.accountContract.getContractArtifact().name} does not require deployment.`,
128
129
  );
129
130
  }
130
- await this.#register();
131
+
132
+ await this.pxe.registerAccount(this.secretKey, this.getCompleteAddress().partialAddress);
133
+
131
134
  const { chainId, protocolVersion } = await this.pxe.getNodeInfo();
132
135
  const deployWallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));
133
136
 
@@ -163,7 +166,7 @@ export class AccountManager {
163
166
  contractAddressSalt: this.salt,
164
167
  skipClassRegistration: opts?.skipClassRegistration ?? true,
165
168
  skipPublicDeployment: opts?.skipPublicDeployment ?? true,
166
- skipInitialization: false,
169
+ skipInitialization: opts?.skipInitialization ?? false,
167
170
  universalDeploy: true,
168
171
  fee: opts?.fee,
169
172
  estimateGas: opts?.estimateGas,
@@ -191,9 +194,4 @@ export class AccountManager {
191
194
  public isDeployable() {
192
195
  return this.accountContract.getDeploymentArgs() !== undefined;
193
196
  }
194
-
195
- async #register(): Promise<void> {
196
- const completeAddress = this.getCompleteAddress();
197
- await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress);
198
- }
199
197
  }
package/src/api/abi.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
1
+ export { type ContractArtifact, type FunctionArtifact, EventSelector, FunctionSelector } from '@aztec/foundation/abi';
2
2
  export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi';
3
3
  export { type NoirCompiledContract } from '@aztec/types/noir';
@@ -80,13 +80,15 @@ export class SentTx {
80
80
  if (opts?.debug) {
81
81
  const txHash = await this.getTxHash();
82
82
  const tx = (await this.pxe.getTxEffect(txHash))!;
83
- const visibleNotes = await this.pxe.getNotes({ txHash });
83
+ const visibleIncomingNotes = await this.pxe.getIncomingNotes({ txHash });
84
+ const visibleOutgoingNotes = await this.pxe.getOutgoingNotes({ txHash });
84
85
  receipt.debugInfo = {
85
86
  noteHashes: tx.noteHashes,
86
87
  nullifiers: tx.nullifiers,
87
88
  publicDataWrites: tx.publicDataWrites,
88
89
  l2ToL1Msgs: tx.l2ToL1Msgs,
89
- visibleNotes,
90
+ visibleIncomingNotes,
91
+ visibleOutgoingNotes,
90
92
  };
91
93
  }
92
94
  return receipt;
@@ -109,7 +111,7 @@ export class SentTx {
109
111
  */
110
112
  public async getVisibleNotes(): Promise<ExtendedNote[]> {
111
113
  await this.wait();
112
- return this.pxe.getNotes({ txHash: await this.getTxHash() });
114
+ return this.pxe.getIncomingNotes({ txHash: await this.getTxHash() });
113
115
  }
114
116
 
115
117
  protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
@@ -6,7 +6,6 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
6
6
  import { Fr } from '@aztec/foundation/fields';
7
7
 
8
8
  import { type Wallet } from '../account/wallet.js';
9
- import { computeAuthWitMessageHash } from '../utils/authwit.js';
10
9
  import { type FeePaymentMethod } from './fee_payment_method.js';
11
10
 
12
11
  /**
@@ -55,11 +54,9 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
55
54
  async getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
56
55
  const nonce = Fr.random();
57
56
  const maxFee = gasSettings.getFeeLimit();
58
- const messageHash = computeAuthWitMessageHash(
59
- this.paymentContract,
60
- this.wallet.getChainId(),
61
- this.wallet.getVersion(),
62
- {
57
+ await this.wallet.createAuthWit({
58
+ caller: this.paymentContract,
59
+ action: {
63
60
  name: 'unshield',
64
61
  args: [this.wallet.getCompleteAddress().address, this.paymentContract, maxFee, nonce],
65
62
  selector: FunctionSelector.fromSignature('unshield((Field),(Field),Field,Field)'),
@@ -68,8 +65,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
68
65
  to: this.asset,
69
66
  returnTypes: [],
70
67
  },
71
- );
72
- await this.wallet.createAuthWit(messageHash);
68
+ });
73
69
 
74
70
  const secretHashForRebate = computeSecretHash(this.rebateSecret);
75
71
 
@@ -4,7 +4,6 @@ import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
4
4
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
5
5
  import { Fr } from '@aztec/foundation/fields';
6
6
 
7
- import { computeAuthWitMessageHash } from '../utils/authwit.js';
8
7
  import { type AccountWallet } from '../wallet/account_wallet.js';
9
8
  import { type FeePaymentMethod } from './fee_payment_method.js';
10
9
 
@@ -47,23 +46,25 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
47
46
  getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
48
47
  const nonce = Fr.random();
49
48
  const maxFee = gasSettings.getFeeLimit();
50
- const messageHash = computeAuthWitMessageHash(
51
- this.paymentContract,
52
- this.wallet.getChainId(),
53
- this.wallet.getVersion(),
54
- {
55
- name: 'transfer_public',
56
- args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
57
- selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
58
- type: FunctionType.PUBLIC,
59
- isStatic: false,
60
- to: this.asset,
61
- returnTypes: [],
62
- },
63
- );
64
49
 
65
50
  return Promise.resolve([
66
- this.wallet.setPublicAuthWit(messageHash, true).request(),
51
+ this.wallet
52
+ .setPublicAuthWit(
53
+ {
54
+ caller: this.paymentContract,
55
+ action: {
56
+ name: 'transfer_public',
57
+ args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
58
+ selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
59
+ type: FunctionType.PUBLIC,
60
+ isStatic: false,
61
+ to: this.asset,
62
+ returnTypes: [],
63
+ },
64
+ },
65
+ true,
66
+ )
67
+ .request(),
67
68
  {
68
69
  name: 'fee_entrypoint_public',
69
70
  to: this.paymentContract,
package/src/index.ts CHANGED
@@ -41,23 +41,25 @@ export {
41
41
  CheatCodes,
42
42
  EthAddressLike,
43
43
  EthCheatCodes,
44
+ EventSelectorLike,
44
45
  FieldLike,
45
46
  FunctionSelectorLike,
46
47
  WrappedFieldLike,
47
48
  computeAuthWitMessageHash,
49
+ computeInnerAuthWitHashFromAction,
48
50
  computeInnerAuthWitHash,
49
- computeOuterAuthWitHash,
50
51
  generatePublicKey,
51
52
  waitForAccountSynch,
52
53
  waitForPXE,
53
54
  } from './utils/index.js';
55
+ export { NoteSelector } from '@aztec/foundation/abi';
54
56
 
55
57
  export { createPXEClient } from './rpc_clients/index.js';
56
58
 
57
59
  export { AuthWitnessProvider } from './account/index.js';
58
60
 
59
61
  export { AccountContract } from './account/index.js';
60
- export { AccountManager } from './account_manager/index.js';
62
+ export { AccountManager, DeployAccountOptions } from './account_manager/index.js';
61
63
 
62
64
  export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, Wallet } from './wallet/index.js';
63
65
 
@@ -95,7 +97,7 @@ export {
95
97
  CompleteAddress,
96
98
  EncryptedL2BlockL2Logs,
97
99
  EncryptedLogHeader,
98
- EncryptedLogIncomingBody,
100
+ EncryptedNoteLogIncomingBody,
99
101
  EncryptedLogOutgoingBody,
100
102
  ExtendedNote,
101
103
  FunctionCall,
@@ -127,6 +129,9 @@ export {
127
129
  createAztecNodeClient,
128
130
  merkleTreeIds,
129
131
  mockTx,
132
+ TaggedLog,
133
+ L1NotePayload,
134
+ L1EventPayload,
130
135
  } from '@aztec/circuit-types';
131
136
  export { NodeInfo } from '@aztec/types/interfaces';
132
137
 
@@ -25,6 +25,7 @@ import {
25
25
  GrumpkinScalar,
26
26
  Point,
27
27
  } from '@aztec/circuits.js';
28
+ import { NoteSelector } from '@aztec/foundation/abi';
28
29
  import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
29
30
 
30
31
  /**
@@ -53,9 +54,10 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)
53
54
  Point,
54
55
  TxExecutionRequest,
55
56
  TxHash,
57
+ NoteSelector,
56
58
  },
57
59
  { Tx, SimulatedTx, TxReceipt, EncryptedNoteL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness },
58
60
  false,
59
61
  'pxe',
60
62
  fetch,
61
- );
63
+ ) as PXE;
@@ -1,4 +1,10 @@
1
- import { type AztecAddress, type EthAddress, type Fr, type FunctionSelector } from '@aztec/circuits.js';
1
+ import {
2
+ type AztecAddress,
3
+ type EthAddress,
4
+ type EventSelector,
5
+ type Fr,
6
+ type FunctionSelector,
7
+ } from '@aztec/circuits.js';
2
8
 
3
9
  /** Any type that can be converted into a field for a contract call. */
4
10
  export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
@@ -9,8 +15,11 @@ export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | Eth
9
15
  /** Any type that can be converted into an AztecAddress Aztec.nr struct. */
10
16
  export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;
11
17
 
12
- /** Any type that can be converted into an FunctionSelector Aztec.nr struct. */
18
+ /** Any type that can be converted into a FunctionSelector Aztec.nr struct. */
13
19
  export type FunctionSelectorLike = FieldLike | FunctionSelector;
14
20
 
21
+ /** Any type that can be converted into an EventSelector Aztec.nr struct. */
22
+ export type EventSelectorLike = FieldLike | EventSelector;
23
+
15
24
  /** Any type that can be converted into a struct with a single `inner` field. */
16
25
  export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
@@ -14,11 +14,11 @@ export async function waitForAccountSynch(
14
14
  address: CompleteAddress,
15
15
  { interval, timeout }: WaitOpts = DefaultWaitOpts,
16
16
  ): Promise<void> {
17
- const publicKey = address.publicKeys.masterIncomingViewingPublicKey.toString();
17
+ const accountAddress = address.address.toString();
18
18
  await retryUntil(
19
19
  async () => {
20
20
  const status = await pxe.getSyncStatus();
21
- const accountSynchedToBlock = status.notes[publicKey];
21
+ const accountSynchedToBlock = status.notes[accountAddress];
22
22
  if (typeof accountSynchedToBlock === 'undefined') {
23
23
  return false;
24
24
  } else {
@@ -1,32 +1,77 @@
1
1
  import { type FunctionCall, PackedValues } from '@aztec/circuit-types';
2
- import { type AztecAddress, type Fr, GeneratorIndex } from '@aztec/circuits.js';
2
+ import { type AztecAddress, Fr, GeneratorIndex } from '@aztec/circuits.js';
3
3
  import { pedersenHash } from '@aztec/foundation/crypto';
4
4
 
5
+ import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
6
+
7
+ /** Metadata for the intent */
8
+ export type IntentMetadata = {
9
+ /** The chain id to approve */
10
+ chainId: Fr;
11
+ /** The version to approve */
12
+ version: Fr;
13
+ };
14
+
15
+ /** Intent with an inner hash */
16
+ export type IntentInnerHash = {
17
+ /** The consumer */
18
+ consumer: AztecAddress;
19
+ /** The action to approve */
20
+ innerHash: Buffer | Fr;
21
+ };
22
+
23
+ /** Intent with an action */
24
+ export type IntentAction = {
25
+ /** The caller to approve */
26
+ caller: AztecAddress;
27
+ /** The action to approve */
28
+ action: ContractFunctionInteraction | FunctionCall;
29
+ };
30
+
5
31
  // docs:start:authwit_computeAuthWitMessageHash
6
32
  /**
7
- * Compute an authentication witness message hash from a caller and a request
8
- * H(target: AztecAddress, chainId: Field, version: Field, H(caller: AztecAddress, selector: Field, args_hash: Field))
9
- * Example usage would be `bob` authenticating `alice` to perform a transfer of `10`
10
- * tokens from his account to herself:
11
- * H(token, 1, 1, H(alice, transfer_selector, H(bob, alice, 10, nonce)))
12
- * `bob` then signs the message hash and gives it to `alice` who can then perform the
13
- * action.
14
- * @param caller - The caller approved to make the call
15
- * @param chainId - The chain id for the message
16
- * @param version - The version for the message
17
- * @param action - The request to be made (function call)
18
- * @returns The message hash for the witness
33
+ * Compute an authentication witness message hash from an intent and metadata
34
+ *
35
+ * If using the `IntentInnerHash`, the consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
36
+ * The `innerHash` itself will be the message that a contract is allowed to execute.
37
+ * At the point of "approval checking", the validating contract (account for private and registry for public) will be computing the message hash
38
+ * (`H(consumer, chainid, version, inner_hash)`) where the all but the `inner_hash` is injected from the context (consumer = msg_sender),
39
+ * and use it for the authentication check.
40
+ * Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
41
+ *
42
+ * If using the `IntentAction`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
43
+ * The action is then used along with the `caller` to compute the `innerHash` and the consumer.
44
+ *
45
+ *
46
+ * @param intent - The intent to approve (consumer and innerHash or caller and action)
47
+ * The consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
48
+ * The caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
49
+ * The caller becomes part of the `inner_hash` and is dealt with entirely in application logic.
50
+ * @param metadata - The metadata for the intent (chainId, version)
51
+ * @returns The message hash for the action
19
52
  */
20
- export const computeAuthWitMessageHash = (caller: AztecAddress, chainId: Fr, version: Fr, action: FunctionCall) => {
21
- return computeOuterAuthWitHash(
22
- action.to.toField(),
23
- chainId,
24
- version,
25
- computeInnerAuthWitHash([caller.toField(), action.selector.toField(), PackedValues.fromValues(action.args).hash]),
26
- );
53
+ export const computeAuthWitMessageHash = (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => {
54
+ const chainId = metadata.chainId;
55
+ const version = metadata.version;
56
+
57
+ if ('caller' in intent) {
58
+ const action = intent.action instanceof ContractFunctionInteraction ? intent.action.request() : intent.action;
59
+ return computeOuterAuthWitHash(
60
+ action.to.toField(),
61
+ chainId,
62
+ version,
63
+ computeInnerAuthWitHashFromAction(intent.caller, action),
64
+ );
65
+ } else {
66
+ const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
67
+ return computeOuterAuthWitHash(intent.consumer, chainId, version, inner);
68
+ }
27
69
  };
28
70
  // docs:end:authwit_computeAuthWitMessageHash
29
71
 
72
+ export const computeInnerAuthWitHashFromAction = (caller: AztecAddress, action: FunctionCall) =>
73
+ computeInnerAuthWitHash([caller.toField(), action.selector.toField(), PackedValues.fromValues(action.args).hash]);
74
+
30
75
  /**
31
76
  * Compute the inner hash for an authentication witness.
32
77
  * This is the "intent" of the message, before siloed with the consumer.
@@ -53,6 +98,6 @@ export const computeInnerAuthWitHash = (args: Fr[]) => {
53
98
  * @param innerHash - The inner hash for the witness
54
99
  * @returns The outer hash for the witness
55
100
  */
56
- export const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => {
101
+ const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => {
57
102
  return pedersenHash([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER);
58
103
  };
@@ -291,7 +291,11 @@ export class AztecCheatCodes {
291
291
  * @returns The notes stored at the given slot
292
292
  */
293
293
  public async loadPrivate(owner: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise<Note[]> {
294
- const extendedNotes = await this.pxe.getNotes({ owner, contractAddress: contract, storageSlot: new Fr(slot) });
294
+ const extendedNotes = await this.pxe.getIncomingNotes({
295
+ owner,
296
+ contractAddress: contract,
297
+ storageSlot: new Fr(slot),
298
+ });
295
299
  return extendedNotes.map(extendedNote => extendedNote.note);
296
300
  }
297
301
  }