@aztec/cli 0.1.0-alpha26 → 0.1.0-alpha28

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.
package/src/index.ts CHANGED
@@ -7,15 +7,14 @@ import {
7
7
  Point,
8
8
  createAccounts,
9
9
  createAztecRpcClient,
10
+ generatePublicKey,
10
11
  getAccountWallet,
11
12
  } from '@aztec/aztec.js';
12
13
  import { StructType } from '@aztec/foundation/abi';
13
- import { randomBytes } from '@aztec/foundation/crypto';
14
14
  import { JsonStringify } from '@aztec/foundation/json-rpc';
15
- import { createConsoleLogger } from '@aztec/foundation/log';
16
- import { createDebugLogger } from '@aztec/foundation/log';
15
+ import { createConsoleLogger, createDebugLogger } from '@aztec/foundation/log';
17
16
  import { SchnorrSingleKeyAccountContractAbi } from '@aztec/noir-contracts/artifacts';
18
- import { ContractData, L2BlockL2Logs, TxHash } from '@aztec/types';
17
+ import { ContractData, L2BlockL2Logs, PrivateKey, TxHash } from '@aztec/types';
19
18
 
20
19
  import { Command } from 'commander';
21
20
  import { mnemonicToAccount } from 'viem/accounts';
@@ -27,10 +26,16 @@ const accountCreationSalt = Fr.ZERO;
27
26
 
28
27
  const debugLogger = createDebugLogger('aztec:cli');
29
28
  const log = createConsoleLogger();
29
+ const stripLeadingHex = (hex: string) => {
30
+ if (hex.length > 2 && hex.startsWith('0x')) {
31
+ return hex.substring(2);
32
+ }
33
+ return hex;
34
+ };
30
35
 
31
36
  const program = new Command();
32
37
 
33
- program.name('azti').description('CLI for interacting with Aztec.').version('0.1.0');
38
+ program.name('aztec-cli').description('CLI for interacting with Aztec.').version('0.1.0');
34
39
 
35
40
  const { ETHEREUM_HOST, AZTEC_RPC_HOST, PRIVATE_KEY, PUBLIC_KEY, API_KEY } = process.env;
36
41
 
@@ -66,18 +71,23 @@ async function main() {
66
71
  });
67
72
 
68
73
  program
69
- .command('create-private-key')
74
+ .command('generate-private-key')
70
75
  .description('Generates a 32-byte private key.')
71
76
  .option('-m, --mnemonic', 'A mnemonic string that can be used for the private key generation.')
72
- .action(options => {
77
+ .action(async options => {
73
78
  let privKey;
79
+ let publicKey;
74
80
  if (options.mnemonic) {
75
81
  const acc = mnemonicToAccount(options.mnemonic);
76
- privKey = Buffer.from(acc.getHdKey().privateKey!).toString('hex');
82
+ const key = Buffer.from(acc.getHdKey().privateKey!);
83
+ privKey = key.toString('hex');
84
+ publicKey = await generatePublicKey(new PrivateKey(key));
77
85
  } else {
78
- privKey = randomBytes(32).toString('hex');
86
+ const key = PrivateKey.random();
87
+ privKey = PrivateKey.random().toString();
88
+ publicKey = await generatePublicKey(key);
79
89
  }
80
- log(`\n${privKey}\n`);
90
+ log(`\nPrivate Key: ${privKey}\nPublic Key: ${publicKey.toString()}\n`);
81
91
  });
82
92
 
83
93
  program
@@ -91,11 +101,11 @@ async function main() {
91
101
  .option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
92
102
  .action(async options => {
93
103
  const client = createAztecRpcClient(options.rpcUrl);
94
- const privateKey = options.privateKey && Buffer.from(options.privateKey.replace(/^0x/i, ''), 'hex');
104
+ const privateKey = options.privateKey && Buffer.from(stripLeadingHex(options.privateKey), 'hex');
95
105
  const wallet = await createAccounts(
96
106
  client,
97
107
  SchnorrSingleKeyAccountContractAbi,
98
- privateKey,
108
+ new PrivateKey(privateKey),
99
109
  accountCreationSalt,
100
110
  1,
101
111
  );
@@ -206,22 +216,22 @@ async function main() {
206
216
  .command('get-logs')
207
217
  .description('Gets all the unencrypted logs from L2 blocks in the range specified.')
208
218
  .argument('<from>', 'Block num start for getting logs.')
209
- .argument('<take>', 'How many block logs to fetch.')
219
+ .argument('<limit>', 'How many block logs to fetch.')
210
220
  .option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
211
221
  .action(async (_from, _take, options) => {
212
222
  let from: number;
213
- let take: number;
223
+ let limit: number;
214
224
  try {
215
225
  from = parseInt(_from);
216
- take = parseInt(_take);
226
+ limit = parseInt(_take);
217
227
  } catch {
218
228
  log(`Invalid integer value(s) passed: ${_from}, ${_take}`);
219
229
  return;
220
230
  }
221
231
  const client = createAztecRpcClient(options.rpcUrl);
222
- const logs = await client.getUnencryptedLogs(from, take);
232
+ const logs = await client.getUnencryptedLogs(from, limit);
223
233
  if (!logs.length) {
224
- log(`No logs found in blocks ${from} to ${from + take}`);
234
+ log(`No logs found in blocks ${from} to ${from + limit}`);
225
235
  } else {
226
236
  log('Logs found: \n');
227
237
  L2BlockL2Logs.unrollLogs(logs).forEach(fnLog => log(`${fnLog.toString('ascii')}\n`));
@@ -238,7 +248,12 @@ async function main() {
238
248
  log('No accounts found.');
239
249
  } else {
240
250
  log(`Accounts found: \n`);
241
- accounts.forEach(async acc => log(`Address: ${acc}\nPublic Key: ${await client.getPublicKey(acc)}\n`));
251
+ for (const address of accounts) {
252
+ const [pk, partialAddress] = await client.getPublicKeyAndPartialAddress(address);
253
+ log(
254
+ `Address: ${address}\nPublic Key: ${pk.toString()}\nPartial Contract Address: ${partialAddress.toString()}\n`,
255
+ );
256
+ }
242
257
  }
243
258
  });
244
259
 
@@ -250,16 +265,17 @@ async function main() {
250
265
  .action(async (_address, options) => {
251
266
  const client = createAztecRpcClient(options.rpcUrl);
252
267
  const address = AztecAddress.fromString(_address);
253
- const pk = await client.getPublicKey(address);
268
+ const [pk, partialAddress] = await client.getPublicKeyAndPartialAddress(address);
269
+
254
270
  if (!pk) {
255
271
  log(`Unkown account ${_address}`);
256
272
  } else {
257
- log(`Public Key: \n ${pk.toString()}`);
273
+ log(`Public Key: \n ${pk.toString()}\nPartial Contract Address: ${partialAddress.toString()}\n`);
258
274
  }
259
275
  });
260
276
 
261
277
  program
262
- .command('call-fn')
278
+ .command('send')
263
279
  .description('Calls a function on an Aztec contract.')
264
280
  .argument('<contractAbi>', "The compiled contract's ABI in JSON format", undefined)
265
281
  .argument('<contractAddress>', 'Address of the contract')
@@ -281,10 +297,10 @@ async function main() {
281
297
  const wallet = await getAccountWallet(
282
298
  client,
283
299
  SchnorrSingleKeyAccountContractAbi,
284
- Buffer.from(options.privateKey, 'hex'),
300
+ PrivateKey.fromString(options.privateKey),
285
301
  accountCreationSalt,
286
302
  );
287
- const contract = new Contract(contractAddress, contractAbi, wallet);
303
+ const contract = await Contract.create(contractAddress, contractAbi, wallet);
288
304
  const origin = (await wallet.getAccounts()).find(addr => addr.equals(wallet.getAddress()));
289
305
  const tx = contract.methods[functionName](...functionArgs).send({
290
306
  origin,
@@ -299,7 +315,7 @@ async function main() {
299
315
  });
300
316
 
301
317
  program
302
- .command('view-fn')
318
+ .command('call')
303
319
  .description(
304
320
  'Simulates the execution of a view (read-only) function on a deployed contract, without modifying state.',
305
321
  )
@@ -345,8 +361,8 @@ async function main() {
345
361
  });
346
362
 
347
363
  program
348
- .command('block-num')
349
- .description('Gets the current Aztec L2 number.')
364
+ .command('block-number')
365
+ .description('Gets the current Aztec L2 block number.')
350
366
  .option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
351
367
  .action(async (options: any) => {
352
368
  const client = createAztecRpcClient(options.rpcUrl);
package/tsconfig.json CHANGED
@@ -17,6 +17,9 @@
17
17
  },
18
18
  {
19
19
  "path": "../noir-contracts"
20
+ },
21
+ {
22
+ "path": "../types"
20
23
  }
21
24
  ],
22
25
  "include": ["src"],