@aztec-labs/cli-wallet 6.0.0-nightly.20260829

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 (110) hide show
  1. package/README.md +32 -0
  2. package/dest/bin/index.d.ts +3 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +96 -0
  5. package/dest/cmds/authorize_action.d.ts +5 -0
  6. package/dest/cmds/authorize_action.d.ts.map +1 -0
  7. package/dest/cmds/authorize_action.js +23 -0
  8. package/dest/cmds/bridge_fee_juice.d.ts +6 -0
  9. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -0
  10. package/dest/cmds/bridge_fee_juice.js +54 -0
  11. package/dest/cmds/check_tx.d.ts +6 -0
  12. package/dest/cmds/check_tx.d.ts.map +1 -0
  13. package/dest/cmds/check_tx.js +181 -0
  14. package/dest/cmds/create_account.d.ts +17 -0
  15. package/dest/cmds/create_account.d.ts.map +1 -0
  16. package/dest/cmds/create_account.js +146 -0
  17. package/dest/cmds/create_authwit.d.ts +5 -0
  18. package/dest/cmds/create_authwit.d.ts.map +1 -0
  19. package/dest/cmds/create_authwit.js +16 -0
  20. package/dest/cmds/deploy.d.ts +10 -0
  21. package/dest/cmds/deploy.d.ts.map +1 -0
  22. package/dest/cmds/deploy.js +129 -0
  23. package/dest/cmds/deploy_account.d.ts +8 -0
  24. package/dest/cmds/deploy_account.d.ts.map +1 -0
  25. package/dest/cmds/deploy_account.js +111 -0
  26. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  27. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  28. package/dest/cmds/get_fee_juice_balance.js +27 -0
  29. package/dest/cmds/import_test_accounts.d.ts +5 -0
  30. package/dest/cmds/import_test_accounts.d.ts.map +1 -0
  31. package/dest/cmds/import_test_accounts.js +40 -0
  32. package/dest/cmds/index.d.ts +6 -0
  33. package/dest/cmds/index.d.ts.map +1 -0
  34. package/dest/cmds/index.js +208 -0
  35. package/dest/cmds/profile.d.ts +8 -0
  36. package/dest/cmds/profile.d.ts.map +1 -0
  37. package/dest/cmds/profile.js +28 -0
  38. package/dest/cmds/register_contract.d.ts +8 -0
  39. package/dest/cmds/register_contract.d.ts.map +1 -0
  40. package/dest/cmds/register_contract.js +27 -0
  41. package/dest/cmds/register_sender.d.ts +5 -0
  42. package/dest/cmds/register_sender.d.ts.map +1 -0
  43. package/dest/cmds/register_sender.js +4 -0
  44. package/dest/cmds/send.d.ts +11 -0
  45. package/dest/cmds/send.d.ts.map +1 -0
  46. package/dest/cmds/send.js +73 -0
  47. package/dest/cmds/simulate.d.ts +8 -0
  48. package/dest/cmds/simulate.d.ts.map +1 -0
  49. package/dest/cmds/simulate.js +33 -0
  50. package/dest/storage/wallet_db.d.ts +61 -0
  51. package/dest/storage/wallet_db.d.ts.map +1 -0
  52. package/dest/storage/wallet_db.js +231 -0
  53. package/dest/utils/authorizations.d.ts +6 -0
  54. package/dest/utils/authorizations.d.ts.map +1 -0
  55. package/dest/utils/authorizations.js +28 -0
  56. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  57. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  58. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  59. package/dest/utils/constants.d.ts +4 -0
  60. package/dest/utils/constants.d.ts.map +1 -0
  61. package/dest/utils/constants.js +8 -0
  62. package/dest/utils/ecdsa.d.ts +2 -0
  63. package/dest/utils/ecdsa.d.ts.map +1 -0
  64. package/dest/utils/ecdsa.js +13 -0
  65. package/dest/utils/options/fees.d.ts +36 -0
  66. package/dest/utils/options/fees.d.ts.map +1 -0
  67. package/dest/utils/options/fees.js +250 -0
  68. package/dest/utils/options/index.d.ts +3 -0
  69. package/dest/utils/options/index.d.ts.map +1 -0
  70. package/dest/utils/options/index.js +2 -0
  71. package/dest/utils/options/options.d.ts +24 -0
  72. package/dest/utils/options/options.d.ts.map +1 -0
  73. package/dest/utils/options/options.js +134 -0
  74. package/dest/utils/profiling.d.ts +5 -0
  75. package/dest/utils/profiling.d.ts.map +1 -0
  76. package/dest/utils/profiling.js +68 -0
  77. package/dest/utils/wallet.d.ts +64 -0
  78. package/dest/utils/wallet.d.ts.map +1 -0
  79. package/dest/utils/wallet.js +285 -0
  80. package/dest/utils/well_known_contracts.d.ts +8 -0
  81. package/dest/utils/well_known_contracts.d.ts.map +1 -0
  82. package/dest/utils/well_known_contracts.js +38 -0
  83. package/package.json +108 -0
  84. package/src/bin/index.ts +141 -0
  85. package/src/cmds/authorize_action.ts +47 -0
  86. package/src/cmds/bridge_fee_juice.ts +92 -0
  87. package/src/cmds/check_tx.ts +220 -0
  88. package/src/cmds/create_account.ts +176 -0
  89. package/src/cmds/create_authwit.ts +39 -0
  90. package/src/cmds/deploy.ts +157 -0
  91. package/src/cmds/deploy_account.ts +140 -0
  92. package/src/cmds/get_fee_juice_balance.ts +37 -0
  93. package/src/cmds/import_test_accounts.ts +54 -0
  94. package/src/cmds/index.ts +732 -0
  95. package/src/cmds/profile.ts +47 -0
  96. package/src/cmds/register_contract.ts +43 -0
  97. package/src/cmds/register_sender.ts +8 -0
  98. package/src/cmds/send.ts +96 -0
  99. package/src/cmds/simulate.ts +55 -0
  100. package/src/storage/wallet_db.ts +264 -0
  101. package/src/utils/authorizations.ts +50 -0
  102. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  103. package/src/utils/constants.ts +10 -0
  104. package/src/utils/ecdsa.ts +15 -0
  105. package/src/utils/options/fees.ts +325 -0
  106. package/src/utils/options/index.ts +2 -0
  107. package/src/utils/options/options.ts +196 -0
  108. package/src/utils/profiling.ts +171 -0
  109. package/src/utils/wallet.ts +377 -0
  110. package/src/utils/well_known_contracts.ts +46 -0
@@ -0,0 +1,47 @@
1
+ import type { AztecAddress } from '@aztec-labs/aztec.js/addresses';
2
+ import { SetPublicAuthwitContractInteraction } from '@aztec-labs/aztec.js/authorization';
3
+ import { Contract } from '@aztec-labs/aztec.js/contracts';
4
+ import type { Wallet } from '@aztec-labs/aztec.js/wallet';
5
+ import { prepTx } from '@aztec-labs/cli/utils';
6
+ import type { LogFn } from '@aztec-labs/foundation/log';
7
+
8
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
9
+
10
+ export async function authorizeAction(
11
+ wallet: Wallet,
12
+ from: AztecAddress,
13
+ functionName: string,
14
+ caller: AztecAddress,
15
+ functionArgsIn: any[],
16
+ contractArtifactPath: string,
17
+ contractAddress: AztecAddress,
18
+ log: LogFn,
19
+ ) {
20
+ const { functionArgs, contractArtifact, isPrivate } = await prepTx(
21
+ contractArtifactPath,
22
+ functionName,
23
+ functionArgsIn,
24
+ log,
25
+ );
26
+
27
+ if (isPrivate) {
28
+ throw new Error(
29
+ 'Cannot authorize private function. To allow a third party to call a private function, please create an authorization witness via the create-authwit command',
30
+ );
31
+ }
32
+
33
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
34
+ const action = contract.methods[functionName](...functionArgs);
35
+
36
+ const setAuthwitnessInteraction = await SetPublicAuthwitContractInteraction.create(
37
+ wallet,
38
+ from,
39
+ { caller, action },
40
+ true,
41
+ );
42
+ const witness = await setAuthwitnessInteraction.send({ wait: { timeout: DEFAULT_TX_TIMEOUT_S } });
43
+
44
+ log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
45
+
46
+ return witness;
47
+ }
@@ -0,0 +1,92 @@
1
+ import { L1FeeJuicePortalManager } from '@aztec-labs/aztec.js/ethereum';
2
+ import type { AztecNode } from '@aztec-labs/aztec.js/node';
3
+ import { ProtocolContractAddress } from '@aztec-labs/aztec.js/protocol';
4
+ import { prettyPrintJSON } from '@aztec-labs/cli/utils';
5
+ import { createEthereumChain } from '@aztec-labs/ethereum/chain';
6
+ import { createExtendedL1Client } from '@aztec-labs/ethereum/client';
7
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
8
+ import type { LogFn, Logger } from '@aztec-labs/foundation/log';
9
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
10
+ import { getNonNullifiedL1ToL2MessageWitness } from '@aztec-labs/stdlib/messaging';
11
+
12
+ export async function bridgeL1FeeJuice(
13
+ amount: bigint,
14
+ recipient: AztecAddress,
15
+ node: AztecNode,
16
+ l1RpcUrls: string[],
17
+ chainId: number,
18
+ privateKey: string | undefined,
19
+ mnemonic: string,
20
+ mint: boolean,
21
+ json: boolean,
22
+ wait: boolean,
23
+ interval = 60_000,
24
+ log: LogFn,
25
+ debugLogger: Logger,
26
+ ) {
27
+ // Prepare L1 client
28
+ const chain = createEthereumChain(l1RpcUrls, chainId);
29
+ const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
30
+
31
+ // Setup portal manager
32
+ const portal = await L1FeeJuicePortalManager.new(node, client, debugLogger);
33
+ const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(
34
+ recipient,
35
+ amount,
36
+ mint,
37
+ );
38
+
39
+ if (json) {
40
+ const out = {
41
+ claimAmount,
42
+ claimSecret,
43
+ messageLeafIndex,
44
+ };
45
+ log(prettyPrintJSON(out));
46
+ } else {
47
+ if (mint) {
48
+ log(`Minted ${claimAmount} fee juice on L1 and pushed to L2 portal`);
49
+ } else {
50
+ log(`Bridged ${claimAmount} fee juice to L2 portal`);
51
+ }
52
+ log(
53
+ `claimAmount=${claimAmount},claimSecret=${claimSecret},messageHash=${messageHash},messageLeafIndex=${messageLeafIndex}\n`,
54
+ );
55
+ log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
56
+ if (wait) {
57
+ log(
58
+ `This command will now continually poll every ${
59
+ interval / 1000
60
+ }s for the inclusion of the newly created L1 to L2 message`,
61
+ );
62
+ }
63
+ }
64
+
65
+ if (wait) {
66
+ const delayedCheck = (delay: number) => {
67
+ return new Promise((resolve, reject) => {
68
+ setTimeout(() => {
69
+ void getNonNullifiedL1ToL2MessageWitness(
70
+ node,
71
+ ProtocolContractAddress.FeeJuice,
72
+ Fr.fromHexString(messageHash),
73
+ claimSecret,
74
+ )
75
+ .then(witness => resolve(witness))
76
+ .catch(err => reject(err));
77
+ }, delay);
78
+ });
79
+ };
80
+
81
+ let witness;
82
+
83
+ while (!witness) {
84
+ witness = await delayedCheck(interval);
85
+ if (!witness) {
86
+ log(`No L1 to L2 message found yet, checking again in ${interval / 1000}s`);
87
+ }
88
+ }
89
+ }
90
+
91
+ return [claimSecret, messageLeafIndex] as const;
92
+ }
@@ -0,0 +1,220 @@
1
+ import type { ContractArtifact } from '@aztec-labs/aztec.js/abi';
2
+ import { AztecAddress } from '@aztec-labs/aztec.js/addresses';
3
+ import { Fr } from '@aztec-labs/aztec.js/fields';
4
+ import type { AztecNode } from '@aztec-labs/aztec.js/node';
5
+ import { ProtocolContractAddress } from '@aztec-labs/aztec.js/protocol';
6
+ import type { TxHash } from '@aztec-labs/aztec.js/tx';
7
+ import type { LogFn } from '@aztec-labs/foundation/log';
8
+ import {
9
+ computeSiloedPrivateInitializationNullifier,
10
+ computeSiloedPublicInitializationNullifier,
11
+ siloNullifier,
12
+ } from '@aztec-labs/stdlib/hash';
13
+ import { NoteDao } from '@aztec-labs/stdlib/note';
14
+
15
+ import type { CLIWallet } from '../utils/wallet.js';
16
+
17
+ export async function checkTx(
18
+ wallet: CLIWallet,
19
+ aztecNode: AztecNode,
20
+ txHash: TxHash,
21
+ statusOnly: boolean,
22
+ log: LogFn,
23
+ ) {
24
+ if (statusOnly) {
25
+ const receipt = await aztecNode.getTxReceipt(txHash);
26
+ return receipt.status;
27
+ } else {
28
+ await inspectTx(wallet, aztecNode, txHash, log);
29
+ }
30
+ }
31
+
32
+ // The rest of the code here was copied over here from CLI because in CLI I needed to prune the inspect function of the PXE
33
+ // dependency when dropping PXE JSON RPC Server.
34
+
35
+ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
36
+ const receipt = await aztecNode.getTxReceipt(txHash, { includeTxEffect: true });
37
+ // Base tx data
38
+ log(`Tx ${txHash.toString()}`);
39
+ log(` Status: ${receipt.status}`);
40
+ if (receipt.executionResult) {
41
+ log(` Execution result: ${receipt.executionResult}`);
42
+ }
43
+ if (receipt.error) {
44
+ log(` Error: ${receipt.error}`);
45
+ }
46
+
47
+ if (!receipt.isMined() || !receipt.txEffect) {
48
+ return;
49
+ }
50
+
51
+ const effects = receipt.txEffect;
52
+ const artifactMap = await getKnownArtifacts(wallet);
53
+
54
+ log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
55
+ if (receipt.transactionFee) {
56
+ log(` Fee: ${receipt.transactionFee.toString()}`);
57
+ }
58
+
59
+ // Public logs
60
+ const publicLogs = effects.publicLogs;
61
+ if (publicLogs.length > 0) {
62
+ log(' Logs:');
63
+ for (const publicLog of publicLogs) {
64
+ log(` ${publicLog.toHumanReadable()}`);
65
+ }
66
+ }
67
+
68
+ // Public data writes
69
+ const writes = effects.publicDataWrites;
70
+ if (writes.length > 0) {
71
+ log(' Public data writes:');
72
+ for (const write of writes) {
73
+ log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
74
+ }
75
+ }
76
+
77
+ // Created notes
78
+ const notes = effects.noteHashes;
79
+ if (notes.length > 0) {
80
+ log(' Created notes:');
81
+ log(` Total: ${notes.length}`);
82
+ for (const note of notes) {
83
+ log(` Note hash: ${note.toShortString()}`);
84
+ }
85
+ }
86
+
87
+ // Nullifiers
88
+ const nullifierCount = effects.nullifiers.length;
89
+ const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
90
+ const accounts = (await wallet.getAccounts()).map(a => a.item);
91
+ if (nullifierCount > 0) {
92
+ log(' Nullifiers:');
93
+ for (const nullifier of effects.nullifiers) {
94
+ const deployed = deployNullifiers[nullifier.toString()];
95
+ const note = deployed
96
+ ? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed, scopes: accounts }))[0]
97
+ : undefined;
98
+ const initialized = initNullifiers[nullifier.toString()];
99
+ const registered = classNullifiers[nullifier.toString()];
100
+ if (nullifier.toBuffer().equals(txHash.toBuffer())) {
101
+ log(` Transaction hash nullifier ${nullifier.toShortString()}`);
102
+ } else if (note) {
103
+ inspectNote(note, artifactMap, log, `Nullifier ${nullifier.toShortString()} for note`);
104
+ } else if (deployed) {
105
+ log(
106
+ ` Contract ${toFriendlyAddress(deployed, artifactMap)} deployed via nullifier ${nullifier.toShortString()}`,
107
+ );
108
+ } else if (initialized) {
109
+ log(
110
+ ` Contract ${toFriendlyAddress(
111
+ initialized,
112
+ artifactMap,
113
+ )} initialized via nullifier ${nullifier.toShortString()}`,
114
+ );
115
+ } else if (registered) {
116
+ log(` Class ${registered} registered via nullifier ${nullifier.toShortString()}`);
117
+ } else {
118
+ log(` Unknown nullifier ${nullifier.toString()}`);
119
+ }
120
+ }
121
+ }
122
+
123
+ // L2 to L1 messages
124
+ if (effects.l2ToL1Msgs.length > 0) {
125
+ log(` L2 to L1 messages:`);
126
+ for (const msg of effects.l2ToL1Msgs) {
127
+ log(` ${msg.toString()}`);
128
+ }
129
+ }
130
+ }
131
+
132
+ function inspectNote(note: NoteDao, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
133
+ const artifact = artifactMap[note.contractAddress.toString()];
134
+ const contract = artifact?.name ?? note.contractAddress.toString();
135
+ log(` ${text} at ${contract}`);
136
+ for (const field of note.note.items) {
137
+ log(` ${field.toString()}`);
138
+ }
139
+ }
140
+
141
+ function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
142
+ const artifact = artifactMap[address.toString()];
143
+ if (!artifact) {
144
+ return address.toString();
145
+ }
146
+
147
+ return `${artifact.name}<${address.toString()}>`;
148
+ }
149
+
150
+ async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
151
+ const knownContracts = await wallet.getContracts();
152
+
153
+ const [contractResults, classResults] = await Promise.all([
154
+ Promise.all(knownContracts.map(contract => getContractNullifiers(wallet, contract))),
155
+ Promise.all(Object.values(artifactMap).map(artifact => getClassNullifier(artifact))),
156
+ ]);
157
+
158
+ const initNullifiers: Record<string, AztecAddress> = {};
159
+ const deployNullifiers: Record<string, AztecAddress> = {};
160
+ const classNullifiers: Record<string, string> = {};
161
+
162
+ for (const { contract, deployNullifier, privateInitNullifier, publicInitNullifier } of contractResults) {
163
+ deployNullifiers[deployNullifier.toString()] = contract;
164
+ if (privateInitNullifier) {
165
+ initNullifiers[privateInitNullifier.toString()] = contract;
166
+ }
167
+ initNullifiers[publicInitNullifier.toString()] = contract;
168
+ }
169
+ for (const { nullifier, label } of classResults) {
170
+ classNullifiers[nullifier.toString()] = label;
171
+ }
172
+
173
+ return { initNullifiers, deployNullifiers, classNullifiers };
174
+ }
175
+
176
+ async function getContractNullifiers(wallet: CLIWallet, contract: AztecAddress) {
177
+ const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
178
+ const deployNullifier = await siloNullifier(deployerAddress, contract.toField());
179
+
180
+ const metadata = await wallet.getContractMetadata(contract);
181
+ const privateInitNullifier = metadata.instance
182
+ ? await computeSiloedPrivateInitializationNullifier(contract, metadata.instance.initializationHash)
183
+ : undefined;
184
+ const publicInitNullifier = await computeSiloedPublicInitializationNullifier(contract);
185
+
186
+ return { contract, deployNullifier, privateInitNullifier, publicInitNullifier };
187
+ }
188
+
189
+ async function getClassNullifier(artifact: ContractArtifactWithClassId) {
190
+ const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
191
+ const nullifier = await siloNullifier(classRegistryAddress, artifact.classId);
192
+ return { nullifier, label: `${artifact.name}Class<${artifact.classId}>` };
193
+ }
194
+
195
+ type ArtifactMap = Record<string, ContractArtifactWithClassId>;
196
+ type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
197
+
198
+ async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
199
+ const knownContractAddresses = await wallet.getContracts();
200
+ const knownContracts = await Promise.all(
201
+ knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)),
202
+ );
203
+ const classIdFor = (metadata: (typeof knownContracts)[number]): Fr | undefined =>
204
+ metadata.updatedContractClassId ?? metadata.instance?.originalContractClassId;
205
+ const classIds = [...new Set(knownContracts.map(classIdFor))];
206
+ const knownArtifacts = (
207
+ await Promise.all(classIds.map(classId => (classId ? wallet.getContractArtifact(classId) : undefined)))
208
+ ).map((artifact, index) => (artifact ? { ...artifact, classId: classIds[index] } : undefined));
209
+ const map: Record<string, ContractArtifactWithClassId> = {};
210
+ for (const metadata of knownContracts) {
211
+ const classId = classIdFor(metadata);
212
+ if (metadata.instance && classId) {
213
+ const artifact = knownArtifacts.find(a => a?.classId?.equals(classId)) as ContractArtifactWithClassId;
214
+ if (artifact) {
215
+ map[metadata.instance.address.toString()] = artifact;
216
+ }
217
+ }
218
+ }
219
+ return map;
220
+ }
@@ -0,0 +1,176 @@
1
+ import { deriveSecretKeyFromSigningKey } from '@aztec-labs/accounts/utils';
2
+ import { NO_FROM } from '@aztec-labs/aztec.js/account';
3
+ import { AztecAddress } from '@aztec-labs/aztec.js/addresses';
4
+ import { NO_WAIT } from '@aztec-labs/aztec.js/contracts';
5
+ import { type AztecNode, waitForTx } from '@aztec-labs/aztec.js/node';
6
+ import type { DeployAccountOptions } from '@aztec-labs/aztec.js/wallet';
7
+ import { prettyPrintJSON } from '@aztec-labs/cli/cli-utils';
8
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
9
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
10
+ import type { LogFn, Logger } from '@aztec-labs/foundation/log';
11
+ import { type TxHash, type TxReceipt, TxStatus } from '@aztec-labs/stdlib/tx';
12
+
13
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
14
+ import type { AccountType } from '../utils/constants.js';
15
+ import { CLIFeeArgs } from '../utils/options/fees.js';
16
+ import { printProfileResult } from '../utils/profiling.js';
17
+ import { CLIWallet } from '../utils/wallet.js';
18
+
19
+ export async function createAccount(
20
+ wallet: CLIWallet,
21
+ aztecNode: AztecNode,
22
+ accountType: AccountType,
23
+ signingKey: GrumpkinScalar | undefined,
24
+ salt: Fr | undefined,
25
+ publicKey: string | undefined,
26
+ alias: string | undefined,
27
+ deployer: AztecAddress | undefined,
28
+ registerOnly: boolean,
29
+ skipInitialization: boolean,
30
+ publicDeploy: boolean,
31
+ registerClass: boolean,
32
+ wait: boolean,
33
+ feeOpts: CLIFeeArgs,
34
+ waitForStatus: TxStatus,
35
+ json: boolean,
36
+ verbose: boolean,
37
+ debugLogger: Logger,
38
+ log: LogFn,
39
+ ) {
40
+ let secretKey: Fr;
41
+ if (accountType === 'ecdsasecp256r1ssh') {
42
+ // SSH accounts sign with a key held in the agent, and so we cannot derive their privacy secret key from it. Instead
43
+ // we pick a random value.
44
+ secretKey = Fr.random();
45
+ } else {
46
+ signingKey ??= GrumpkinScalar.random();
47
+ secretKey = await deriveSecretKeyFromSigningKey(signingKey);
48
+ }
49
+
50
+ const account = await wallet.createAccount(accountType, signingKey, secretKey, salt, publicKey);
51
+ const instanceSalt = account.getInstance().salt;
52
+ const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
53
+
54
+ const out: Record<string, any> = {};
55
+ if (json) {
56
+ out.address = address;
57
+ out.publicKey = publicKeys;
58
+ if (signingKey) {
59
+ out.signingKey = signingKey;
60
+ }
61
+ if (secretKey) {
62
+ out.secretKey = secretKey;
63
+ }
64
+ out.partialAddress = partialAddress;
65
+ out.salt = instanceSalt;
66
+ out.initHash = account.getInstance().initializationHash;
67
+ } else {
68
+ log(`\nNew account:\n`);
69
+ log(`Address: ${address.toString()}`);
70
+ log(`Public key: ${publicKeys.toString()}`);
71
+ if (signingKey) {
72
+ log(`Signing key: ${signingKey.toString()}`);
73
+ }
74
+ if (secretKey) {
75
+ log(`Secret key: ${secretKey.toString()}`);
76
+ }
77
+ log(`Partial address: ${partialAddress.toString()}`);
78
+ log(`Salt: ${instanceSalt.toString()}`);
79
+ log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
80
+ }
81
+
82
+ let txHash: TxHash | undefined;
83
+ let txReceipt: TxReceipt | undefined;
84
+ // Initializerless accounts have no deployment tx — creating one only registers it locally — so there is
85
+ // nothing to deploy on-chain.
86
+ if (!registerOnly && accountType !== 'schnorr_initializerless') {
87
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
88
+
89
+ const delegatedDeployment = deployer && !account.address.equals(deployer);
90
+ const from = delegatedDeployment ? deployer : NO_FROM;
91
+
92
+ const deployAccountOpts: DeployAccountOptions = {
93
+ skipClassPublication: !registerClass,
94
+ skipInstancePublication: !publicDeploy,
95
+ skipInitialization,
96
+ from,
97
+ fee: { paymentMethod, gasSettings },
98
+ };
99
+
100
+ const localStart = performance.now();
101
+ const deployMethod = await account.getDeployMethod();
102
+ const sim = await deployMethod.simulate({
103
+ ...deployAccountOpts,
104
+ includeMetadata: true,
105
+ });
106
+ // includeMetadata: true guarantees these fields are present
107
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
108
+ const stats = sim.stats!;
109
+
110
+ if (feeOpts.estimateOnly) {
111
+ if (json) {
112
+ out.fee = {
113
+ gasLimits: {
114
+ da: estimatedGas.gasLimits.daGas,
115
+ l2: estimatedGas.gasLimits.l2Gas,
116
+ },
117
+ teardownGasLimits: {
118
+ da: estimatedGas.teardownGasLimits.daGas,
119
+ l2: estimatedGas.teardownGasLimits,
120
+ },
121
+ };
122
+ }
123
+ } else {
124
+ if (verbose) {
125
+ printProfileResult(stats, log);
126
+ }
127
+
128
+ if (!json) {
129
+ log(`\nWaiting for account contract deployment...`);
130
+ }
131
+ const sendOpts = {
132
+ ...deployAccountOpts,
133
+ fee: deployAccountOpts.fee
134
+ ? {
135
+ ...deployAccountOpts.fee,
136
+ gasSettings: estimatedGas,
137
+ }
138
+ : undefined,
139
+ };
140
+
141
+ ({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
142
+ const localTimeMs = performance.now() - localStart;
143
+
144
+ if (wait) {
145
+ const nodeStart = performance.now();
146
+ txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
147
+ const nodeTimeMs = performance.now() - nodeStart;
148
+
149
+ out.txReceipt = {
150
+ status: txReceipt.status,
151
+ transactionFee: txReceipt.transactionFee,
152
+ };
153
+
154
+ if (!json) {
155
+ log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
156
+ log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
157
+ }
158
+ }
159
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
160
+ out.txHash = txHash;
161
+ }
162
+ }
163
+
164
+ if (json) {
165
+ log(prettyPrintJSON(out));
166
+ } else {
167
+ if (txHash) {
168
+ log(`Deploy tx hash: ${txHash.toString()}`);
169
+ }
170
+ if (txReceipt) {
171
+ log(`Deploy tx fee: ${txReceipt.transactionFee}`);
172
+ }
173
+ }
174
+
175
+ return { alias, address, signingKey, secretKey, salt: instanceSalt };
176
+ }
@@ -0,0 +1,39 @@
1
+ import type { AztecAddress } from '@aztec-labs/aztec.js/addresses';
2
+ import { Contract } from '@aztec-labs/aztec.js/contracts';
3
+ import { prepTx } from '@aztec-labs/cli/utils';
4
+ import type { LogFn } from '@aztec-labs/foundation/log';
5
+
6
+ import type { CLIWallet } from '../utils/wallet.js';
7
+
8
+ export async function createAuthwit(
9
+ wallet: CLIWallet,
10
+ from: AztecAddress,
11
+ functionName: string,
12
+ caller: AztecAddress,
13
+ functionArgsIn: any[],
14
+ contractArtifactPath: string,
15
+ contractAddress: AztecAddress,
16
+ log: LogFn,
17
+ ) {
18
+ const { functionArgs, contractArtifact, isPrivate } = await prepTx(
19
+ contractArtifactPath,
20
+ functionName,
21
+ functionArgsIn,
22
+ log,
23
+ );
24
+
25
+ if (!isPrivate) {
26
+ throw new Error(
27
+ 'Cannot create an authwit for a public function. To allow a third party to call a public function, please authorize the action via the authorize-action command',
28
+ );
29
+ }
30
+
31
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
32
+ const call = await contract.methods[functionName](...functionArgs).getFunctionCall();
33
+
34
+ const witness = await wallet.createAuthWit(from, { caller, call });
35
+
36
+ log(`Created authorization witness for action ${functionName} on contract ${contractAddress} for caller ${caller}`);
37
+
38
+ return witness;
39
+ }