@aztec/cli 0.16.4 → 0.16.6

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 (40) hide show
  1. package/dest/bin/index.js +0 -0
  2. package/package.json +8 -8
  3. package/src/bin/index.ts +0 -22
  4. package/src/client.ts +0 -68
  5. package/src/cmds/add_contract.ts +0 -27
  6. package/src/cmds/add_note.ts +0 -24
  7. package/src/cmds/block_number.ts +0 -12
  8. package/src/cmds/call.ts +0 -35
  9. package/src/cmds/check_deploy.ts +0 -17
  10. package/src/cmds/compute_selector.ts +0 -10
  11. package/src/cmds/create_account.ts +0 -39
  12. package/src/cmds/deploy.ts +0 -77
  13. package/src/cmds/deploy_l1_contracts.ts +0 -25
  14. package/src/cmds/example_contracts.ts +0 -12
  15. package/src/cmds/generate_p2p_private_key.ts +0 -13
  16. package/src/cmds/generate_private_key.ts +0 -23
  17. package/src/cmds/get_account.ts +0 -18
  18. package/src/cmds/get_accounts.ts +0 -19
  19. package/src/cmds/get_contract_data.ts +0 -39
  20. package/src/cmds/get_logs.ts +0 -71
  21. package/src/cmds/get_node_info.ts +0 -17
  22. package/src/cmds/get_recipient.ts +0 -18
  23. package/src/cmds/get_recipients.ts +0 -19
  24. package/src/cmds/get_tx_receipt.ts +0 -18
  25. package/src/cmds/inspect_contract.ts +0 -29
  26. package/src/cmds/parse_parameter_struct.ts +0 -30
  27. package/src/cmds/register_account.ts +0 -24
  28. package/src/cmds/register_recipient.ts +0 -21
  29. package/src/cmds/send.ts +0 -40
  30. package/src/cmds/unbox.ts +0 -11
  31. package/src/encoding.ts +0 -115
  32. package/src/github.ts +0 -3
  33. package/src/index.ts +0 -487
  34. package/src/test/mocks.ts +0 -65
  35. package/src/unbox.ts +0 -345
  36. package/src/update/common.ts +0 -16
  37. package/src/update/noir.ts +0 -79
  38. package/src/update/npm.ts +0 -134
  39. package/src/update/update.ts +0 -132
  40. package/src/utils.ts +0 -439
@@ -1,132 +0,0 @@
1
- /* eslint-disable jsdoc/require-jsdoc */
2
- import { DebugLogger, LogFn } from '@aztec/foundation/log';
3
-
4
- import { relative, resolve } from 'path';
5
- import { SemVer, coerce, gt, lt, parse } from 'semver';
6
-
7
- import { createCompatibleClient } from '../client.js';
8
- import { GITHUB_TAG_PREFIX } from '../github.js';
9
- import { DependencyChanges } from './common.js';
10
- import { updateAztecNr } from './noir.js';
11
- import { getNewestVersion as getLatestVersion, readPackageJson, updateAztecDeps, updateLockfile } from './npm.js';
12
-
13
- const SANDBOX_PACKAGE = '@aztec/aztec-sandbox';
14
-
15
- export async function update(
16
- projectPath: string,
17
- contracts: string[],
18
- pxeUrl: string,
19
- sandboxVersion: string,
20
- log: LogFn,
21
- debugLog: DebugLogger,
22
- ): Promise<void> {
23
- const targetSandboxVersion =
24
- sandboxVersion === 'latest' ? await getLatestVersion(SANDBOX_PACKAGE, 'latest') : parse(sandboxVersion);
25
-
26
- if (!targetSandboxVersion) {
27
- throw new Error(`Invalid aztec version ${sandboxVersion}`);
28
- }
29
-
30
- let currentSandboxVersion = await getNpmSandboxVersion(projectPath, log);
31
-
32
- if (!currentSandboxVersion) {
33
- currentSandboxVersion = await getRemoteSandboxVersion(pxeUrl, log, debugLog);
34
-
35
- if (currentSandboxVersion && lt(currentSandboxVersion, targetSandboxVersion)) {
36
- log(`
37
- Sandbox is older than version ${targetSandboxVersion}. If running via docker-compose, follow update instructions:
38
- https://docs.aztec.network/dev_docs/cli/updating
39
-
40
- Once the sandbox is updated, run the \`aztec-cli update\` command again`);
41
- return;
42
- }
43
- }
44
-
45
- if (!currentSandboxVersion) {
46
- throw new Error('Sandbox version could not be detected');
47
- }
48
-
49
- // sanity check
50
- if (gt(currentSandboxVersion, targetSandboxVersion)) {
51
- throw new Error('Local sandbox version is newer than latest version.');
52
- }
53
-
54
- const npmChanges = await updateAztecDeps(projectPath, targetSandboxVersion, log);
55
- if (npmChanges.dependencies.length > 0) {
56
- updateLockfile(projectPath, log);
57
- }
58
-
59
- const contractChanges: DependencyChanges[] = [];
60
- for (const contract of contracts) {
61
- try {
62
- contractChanges.push(
63
- await updateAztecNr(
64
- resolve(projectPath, contract),
65
- `${GITHUB_TAG_PREFIX}-v${targetSandboxVersion.version}`,
66
- log,
67
- ),
68
- );
69
- } catch (err) {
70
- if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
71
- log(`No Nargo.toml found in ${relative(process.cwd(), contract)}. Skipping...`);
72
- process.exit(1);
73
- }
74
-
75
- throw err;
76
- }
77
- }
78
-
79
- printChanges(npmChanges, log);
80
-
81
- contractChanges.forEach(changes => {
82
- printChanges(changes, log);
83
- });
84
- }
85
-
86
- function printChanges(changes: DependencyChanges, log: LogFn): void {
87
- log(`\nIn ${relative(process.cwd(), changes.file)}:`);
88
- if (changes.dependencies.length === 0) {
89
- log(' No changes');
90
- } else {
91
- changes.dependencies.forEach(({ name, from, to }) => {
92
- log(` Updated ${name} from ${from} to ${to}`);
93
- });
94
- }
95
- }
96
-
97
- async function getNpmSandboxVersion(projectPath: string, log: LogFn): Promise<SemVer | null> {
98
- try {
99
- const pkg = await readPackageJson(projectPath);
100
- // use coerce instead of parse because it eliminates semver operators like ~ and ^
101
- if (pkg.dependencies?.[SANDBOX_PACKAGE]) {
102
- return coerce(pkg.dependencies[SANDBOX_PACKAGE]);
103
- } else if (pkg.devDependencies?.[SANDBOX_PACKAGE]) {
104
- return coerce(pkg.devDependencies[SANDBOX_PACKAGE]);
105
- } else {
106
- return null;
107
- }
108
- } catch (err) {
109
- if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
110
- log(`No package.json found in ${projectPath}`);
111
- process.exit(1);
112
- }
113
-
114
- throw err;
115
- }
116
- }
117
-
118
- async function getRemoteSandboxVersion(pxeUrl: string, log: LogFn, debugLog: DebugLogger): Promise<SemVer | null> {
119
- try {
120
- const client = await createCompatibleClient(pxeUrl, debugLog);
121
- const nodeInfo = await client.getNodeInfo();
122
-
123
- return parse(nodeInfo.sandboxVersion);
124
- } catch (err) {
125
- if (err instanceof Error && err.message === 'fetch failed') {
126
- log(`Could not connect to Sandbox running on ${pxeUrl}`);
127
- process.exit(1);
128
- }
129
-
130
- throw err;
131
- }
132
- }
package/src/utils.ts DELETED
@@ -1,439 +0,0 @@
1
- import { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/aztec.js/abi';
2
- import { AztecAddress } from '@aztec/aztec.js/aztec_address';
3
- import { EthAddress } from '@aztec/aztec.js/eth_address';
4
- import { type L1ContractArtifactsForDeployment } from '@aztec/aztec.js/ethereum';
5
- import { Fr, GrumpkinScalar, Point } from '@aztec/aztec.js/fields';
6
- import { type PXE } from '@aztec/aztec.js/interfaces/pxe';
7
- import { LogId } from '@aztec/aztec.js/log_id';
8
- import { TxHash } from '@aztec/aztec.js/tx_hash';
9
- import { DebugLogger, LogFn } from '@aztec/foundation/log';
10
-
11
- import { CommanderError, InvalidArgumentError } from 'commander';
12
- import { readFile, rename, writeFile } from 'fs/promises';
13
-
14
- import { encodeArgs } from './encoding.js';
15
-
16
- /**
17
- * Helper type to dynamically import contracts.
18
- */
19
- interface ArtifactsType {
20
- [key: string]: ContractArtifact;
21
- }
22
-
23
- /**
24
- * Helper to get an ABI function or throw error if it doesn't exist.
25
- * @param artifact - Contract's build artifact in JSON format.
26
- * @param fnName - Function name to be found.
27
- * @returns The function's ABI.
28
- */
29
- export function getFunctionArtifact(artifact: ContractArtifact, fnName: string): FunctionArtifact {
30
- const fn = artifact.functions.find(({ name }) => name === fnName);
31
- if (!fn) {
32
- throw Error(`Function ${fnName} not found in contract ABI.`);
33
- }
34
- return fn;
35
- }
36
-
37
- /**
38
- * Function to execute the 'deployRollupContracts' command.
39
- * @param rpcUrl - The RPC URL of the ethereum node.
40
- * @param apiKey - The api key of the ethereum node endpoint.
41
- * @param privateKey - The private key to be used in contract deployment.
42
- * @param mnemonic - The mnemonic to be used in contract deployment.
43
- */
44
- export async function deployAztecContracts(
45
- rpcUrl: string,
46
- apiKey: string,
47
- privateKey: string,
48
- mnemonic: string,
49
- debugLogger: DebugLogger,
50
- ) {
51
- const {
52
- ContractDeploymentEmitterAbi,
53
- ContractDeploymentEmitterBytecode,
54
- InboxAbi,
55
- InboxBytecode,
56
- OutboxAbi,
57
- OutboxBytecode,
58
- RegistryAbi,
59
- RegistryBytecode,
60
- RollupAbi,
61
- RollupBytecode,
62
- } = await import('@aztec/l1-artifacts');
63
- const { createEthereumChain, deployL1Contracts } = await import('@aztec/ethereum');
64
- const { mnemonicToAccount, privateKeyToAccount } = await import('viem/accounts');
65
-
66
- const account = !privateKey ? mnemonicToAccount(mnemonic!) : privateKeyToAccount(`0x${privateKey}`);
67
- const chain = createEthereumChain(rpcUrl, apiKey);
68
- const l1Artifacts: L1ContractArtifactsForDeployment = {
69
- contractDeploymentEmitter: {
70
- contractAbi: ContractDeploymentEmitterAbi,
71
- contractBytecode: ContractDeploymentEmitterBytecode,
72
- },
73
- registry: {
74
- contractAbi: RegistryAbi,
75
- contractBytecode: RegistryBytecode,
76
- },
77
- inbox: {
78
- contractAbi: InboxAbi,
79
- contractBytecode: InboxBytecode,
80
- },
81
- outbox: {
82
- contractAbi: OutboxAbi,
83
- contractBytecode: OutboxBytecode,
84
- },
85
- rollup: {
86
- contractAbi: RollupAbi,
87
- contractBytecode: RollupBytecode,
88
- },
89
- };
90
- return await deployL1Contracts(chain.rpcUrl, account, chain.chainInfo, debugLogger, l1Artifacts);
91
- }
92
-
93
- /**
94
- * Gets all contracts available in \@aztec/noir-contracts.
95
- * @returns The contract ABIs.
96
- */
97
- export async function getExampleContractArtifacts() {
98
- const artifacts: ArtifactsType = await import('@aztec/noir-contracts/artifacts');
99
- return artifacts;
100
- }
101
-
102
- /**
103
- * Reads a file and converts it to an Aztec Contract ABI.
104
- * @param fileDir - The directory of the compiled contract ABI.
105
- * @returns The parsed contract artifact.
106
- */
107
- export async function getContractArtifact(fileDir: string, log: LogFn) {
108
- // first check if it's a noir-contracts example
109
- let contents: string;
110
- const artifacts = await getExampleContractArtifacts();
111
- if (artifacts[fileDir]) {
112
- return artifacts[fileDir] as ContractArtifact;
113
- }
114
-
115
- try {
116
- contents = await readFile(fileDir, 'utf8');
117
- } catch {
118
- throw Error(`Contract ${fileDir} not found`);
119
- }
120
-
121
- // if not found, try reading as path directly
122
- let contractArtifact: ContractArtifact;
123
- try {
124
- contractArtifact = JSON.parse(contents) as ContractArtifact;
125
- } catch (err) {
126
- log('Invalid file used. Please try again.');
127
- throw err;
128
- }
129
- return contractArtifact;
130
- }
131
-
132
- /**
133
- * Utility to select a TX sender either from user input
134
- * or from the first account that is found in a PXE instance.
135
- * @param pxe - The PXE instance that will be checked for an account.
136
- * @param _from - The user input.
137
- * @returns An Aztec address. Will throw if one can't be found in either options.
138
- */
139
- export async function getTxSender(pxe: PXE, _from?: string) {
140
- let from: AztecAddress;
141
- if (_from) {
142
- try {
143
- from = AztecAddress.fromString(_from);
144
- } catch {
145
- throw new InvalidArgumentError(`Invalid option 'from' passed: ${_from}`);
146
- }
147
- } else {
148
- const accounts = await pxe.getRegisteredAccounts();
149
- if (!accounts.length) {
150
- throw new Error('No accounts found in PXE instance.');
151
- }
152
- from = accounts[0].address;
153
- }
154
- return from;
155
- }
156
-
157
- /**
158
- * Performs necessary checks, conversions & operations to call a contract fn from the CLI.
159
- * @param contractFile - Directory of the compiled contract ABI.
160
- * @param functionName - Name of the function to be called.
161
- * @param _functionArgs - Arguments to call the function with.
162
- * @param log - Logger instance that will output to the CLI
163
- * @returns Formatted contract address, function arguments and caller's aztec address.
164
- */
165
- export async function prepTx(contractFile: string, functionName: string, _functionArgs: string[], log: LogFn) {
166
- const contractArtifact = await getContractArtifact(contractFile, log);
167
- const functionArtifact = getFunctionArtifact(contractArtifact, functionName);
168
- const functionArgs = encodeArgs(_functionArgs, functionArtifact.parameters);
169
-
170
- return { functionArgs, contractArtifact };
171
- }
172
-
173
- /**
174
- * Removes the leading 0x from a hex string. If no leading 0x is found the string is returned unchanged.
175
- * @param hex - A hex string
176
- * @returns A new string with leading 0x removed
177
- */
178
- export const stripLeadingHex = (hex: string) => {
179
- if (hex.length > 2 && hex.startsWith('0x')) {
180
- return hex.substring(2);
181
- }
182
- return hex;
183
- };
184
-
185
- /**
186
- * Parses a hex encoded string to an Fr integer to be used as salt
187
- * @param str - Hex encoded string
188
- * @returns A integer to be used as salt
189
- */
190
- export function parseSaltFromHexString(str: string): Fr {
191
- const hex = stripLeadingHex(str);
192
-
193
- // ensure it's a hex string
194
- if (!hex.match(/^[0-9a-f]+$/i)) {
195
- throw new InvalidArgumentError('Invalid hex string');
196
- }
197
-
198
- // pad it so that we may read it as a buffer.
199
- // Buffer needs _exactly_ two hex characters per byte
200
- const padded = hex.length % 2 === 1 ? '0' + hex : hex;
201
-
202
- // finally, turn it into an integer
203
- return Fr.fromBuffer(Buffer.from(padded, 'hex'));
204
- }
205
-
206
- /**
207
- * Parses an AztecAddress from a string.
208
- * @param address - A serialized Aztec address
209
- * @returns An Aztec address
210
- * @throws InvalidArgumentError if the input string is not valid.
211
- */
212
- export function parseAztecAddress(address: string): AztecAddress {
213
- try {
214
- return AztecAddress.fromString(address);
215
- } catch {
216
- throw new InvalidArgumentError(`Invalid address: ${address}`);
217
- }
218
- }
219
-
220
- /**
221
- * Parses an Ethereum address from a string.
222
- * @param address - A serialized Ethereum address
223
- * @returns An Ethereum address
224
- * @throws InvalidArgumentError if the input string is not valid.
225
- */
226
- export function parseEthereumAddress(address: string): EthAddress {
227
- try {
228
- return EthAddress.fromString(address);
229
- } catch {
230
- throw new InvalidArgumentError(`Invalid address: ${address}`);
231
- }
232
- }
233
-
234
- /**
235
- * Parses an AztecAddress from a string.
236
- * @param address - A serialized Aztec address
237
- * @returns An Aztec address
238
- * @throws InvalidArgumentError if the input string is not valid.
239
- */
240
- export function parseOptionalAztecAddress(address: string): AztecAddress | undefined {
241
- if (!address) {
242
- return undefined;
243
- }
244
- return parseAztecAddress(address);
245
- }
246
-
247
- /**
248
- * Parses an optional log ID string into a LogId object.
249
- *
250
- * @param logId - The log ID string to parse.
251
- * @returns The parsed LogId object, or undefined if the log ID is missing or empty.
252
- */
253
- export function parseOptionalLogId(logId: string): LogId | undefined {
254
- if (!logId) {
255
- return undefined;
256
- }
257
- return LogId.fromString(logId);
258
- }
259
-
260
- /**
261
- * Parses a selector from a string.
262
- * @param selector - A serialized selector.
263
- * @returns A selector.
264
- * @throws InvalidArgumentError if the input string is not valid.
265
- */
266
- export function parseOptionalSelector(selector: string): FunctionSelector | undefined {
267
- if (!selector) {
268
- return undefined;
269
- }
270
- try {
271
- return FunctionSelector.fromString(selector);
272
- } catch {
273
- throw new InvalidArgumentError(`Invalid selector: ${selector}`);
274
- }
275
- }
276
-
277
- /**
278
- * Parses a string into an integer or returns undefined if the input is falsy.
279
- *
280
- * @param value - The string to parse into an integer.
281
- * @returns The parsed integer, or undefined if the input string is falsy.
282
- * @throws If the input is not a valid integer.
283
- */
284
- export function parseOptionalInteger(value: string): number | undefined {
285
- if (!value) {
286
- return undefined;
287
- }
288
- const parsed = Number(value);
289
- if (!Number.isInteger(parsed)) {
290
- throw new InvalidArgumentError('Invalid integer.');
291
- }
292
- return parsed;
293
- }
294
-
295
- /**
296
- * Parses a TxHash from a string.
297
- * @param txHash - A transaction hash
298
- * @returns A TxHash instance
299
- * @throws InvalidArgumentError if the input string is not valid.
300
- */
301
- export function parseTxHash(txHash: string): TxHash {
302
- try {
303
- return TxHash.fromString(txHash);
304
- } catch {
305
- throw new InvalidArgumentError(`Invalid transaction hash: ${txHash}`);
306
- }
307
- }
308
-
309
- /**
310
- * Parses an optional TxHash from a string.
311
- * Calls parseTxHash internally.
312
- * @param txHash - A transaction hash
313
- * @returns A TxHash instance, or undefined if the input string is falsy.
314
- * @throws InvalidArgumentError if the input string is not valid.
315
- */
316
- export function parseOptionalTxHash(txHash: string): TxHash | undefined {
317
- if (!txHash) {
318
- return undefined;
319
- }
320
- return parseTxHash(txHash);
321
- }
322
-
323
- /**
324
- * Parses a public key from a string.
325
- * @param publicKey - A public key
326
- * @returns A Point instance
327
- * @throws InvalidArgumentError if the input string is not valid.
328
- */
329
- export function parsePublicKey(publicKey: string): Point {
330
- try {
331
- return Point.fromString(publicKey);
332
- } catch (err) {
333
- throw new InvalidArgumentError(`Invalid public key: ${publicKey}`);
334
- }
335
- }
336
-
337
- /**
338
- * Parses a partial address from a string.
339
- * @param address - A partial address
340
- * @returns A Fr instance
341
- * @throws InvalidArgumentError if the input string is not valid.
342
- */
343
- export function parsePartialAddress(address: string): Fr {
344
- try {
345
- return Fr.fromString(address);
346
- } catch (err) {
347
- throw new InvalidArgumentError(`Invalid partial address: ${address}`);
348
- }
349
- }
350
-
351
- /**
352
- * Parses a private key from a string.
353
- * @param privateKey - A string
354
- * @returns A private key
355
- * @throws InvalidArgumentError if the input string is not valid.
356
- */
357
- export function parsePrivateKey(privateKey: string): GrumpkinScalar {
358
- try {
359
- const value = GrumpkinScalar.fromString(privateKey);
360
- // most likely a badly formatted key was passed
361
- if (value.isZero()) {
362
- throw new Error('Private key must not be zero');
363
- }
364
-
365
- return value;
366
- } catch (err) {
367
- throw new InvalidArgumentError(`Invalid private key: ${privateKey}`);
368
- }
369
- }
370
-
371
- /**
372
- * Parses a field from a string.
373
- * @param field - A string representing the field.
374
- * @returns A field.
375
- * @throws InvalidArgumentError if the input string is not valid.
376
- */
377
- export function parseField(field: string): Fr {
378
- try {
379
- const isHex = field.startsWith('0x') || field.match(new RegExp(`^[0-9a-f]{${Fr.SIZE_IN_BYTES * 2}}$`, 'i'));
380
- if (isHex) {
381
- return Fr.fromString(field);
382
- }
383
-
384
- if (['true', 'false'].includes(field)) {
385
- return new Fr(field === 'true');
386
- }
387
-
388
- const isNumber = +field || field === '0';
389
- if (isNumber) {
390
- return new Fr(BigInt(field));
391
- }
392
-
393
- const isBigInt = field.endsWith('n');
394
- if (isBigInt) {
395
- return new Fr(BigInt(field.replace(/n$/, '')));
396
- }
397
-
398
- return new Fr(BigInt(field));
399
- } catch (err) {
400
- throw new InvalidArgumentError(`Invalid field: ${field}`);
401
- }
402
- }
403
-
404
- /**
405
- * Parses an array of strings to Frs.
406
- * @param fields - An array of strings representing the fields.
407
- * @returns An array of Frs.
408
- */
409
- export function parseFields(fields: string[]): Fr[] {
410
- return fields.map(parseField);
411
- }
412
-
413
- /**
414
- * Updates a file in place atomically.
415
- * @param filePath - Path to file
416
- * @param contents - New contents to write
417
- */
418
- export async function atomicUpdateFile(filePath: string, contents: string) {
419
- const tmpFilepath = filePath + '.tmp';
420
- try {
421
- await writeFile(tmpFilepath, contents, {
422
- // let's crash if the tmp file already exists
423
- flag: 'wx',
424
- });
425
- await rename(tmpFilepath, filePath);
426
- } catch (e) {
427
- if (e instanceof Error && 'code' in e && e.code === 'EEXIST') {
428
- const commanderError = new CommanderError(
429
- 1,
430
- e.code,
431
- `Temporary file already exists: ${tmpFilepath}. Delete this file and try again.`,
432
- );
433
- commanderError.nestedError = e.message;
434
- throw commanderError;
435
- } else {
436
- throw e;
437
- }
438
- }
439
- }