@aztec/aztec 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2

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/README.md +57 -0
  2. package/dest/bin/index.js +46 -0
  3. package/dest/cli/aztec_start_action.js +110 -0
  4. package/dest/cli/aztec_start_options.js +341 -0
  5. package/dest/cli/cli.js +33 -0
  6. package/dest/cli/cmds/start_archiver.js +35 -0
  7. package/dest/cli/cmds/start_bot.js +31 -0
  8. package/dest/cli/cmds/start_faucet.js +20 -0
  9. package/dest/cli/cmds/start_node.js +109 -0
  10. package/dest/cli/cmds/start_p2p_bootstrap.js +20 -0
  11. package/dest/cli/cmds/start_proof_verifier.js +12 -0
  12. package/dest/cli/cmds/start_prover_agent.js +32 -0
  13. package/dest/cli/cmds/start_prover_broker.js +22 -0
  14. package/dest/cli/cmds/start_prover_node.js +81 -0
  15. package/dest/cli/cmds/start_pxe.js +90 -0
  16. package/dest/cli/cmds/start_txe.js +11 -0
  17. package/dest/cli/index.js +1 -0
  18. package/dest/cli/util.js +154 -0
  19. package/dest/cli/validation.js +25 -0
  20. package/dest/examples/token.js +53 -0
  21. package/dest/examples/util.js +31 -0
  22. package/dest/index.js +1 -0
  23. package/dest/mnemonic.js +1 -0
  24. package/dest/sandbox.js +116 -0
  25. package/dest/splash.js +2 -0
  26. package/package.json +119 -0
  27. package/src/bin/index.ts +54 -0
  28. package/src/cli/aztec_start_action.ts +115 -0
  29. package/src/cli/aztec_start_options.ts +366 -0
  30. package/src/cli/cli.ts +48 -0
  31. package/src/cli/cmds/start_archiver.ts +47 -0
  32. package/src/cli/cmds/start_bot.ts +49 -0
  33. package/src/cli/cmds/start_faucet.ts +34 -0
  34. package/src/cli/cmds/start_node.ts +123 -0
  35. package/src/cli/cmds/start_p2p_bootstrap.ts +25 -0
  36. package/src/cli/cmds/start_proof_verifier.ts +18 -0
  37. package/src/cli/cmds/start_prover_agent.ts +65 -0
  38. package/src/cli/cmds/start_prover_broker.ts +37 -0
  39. package/src/cli/cmds/start_prover_node.ts +100 -0
  40. package/src/cli/cmds/start_pxe.ts +124 -0
  41. package/src/cli/cmds/start_txe.ts +15 -0
  42. package/src/cli/index.ts +1 -0
  43. package/src/cli/util.ts +216 -0
  44. package/src/cli/validation.ts +38 -0
  45. package/src/examples/token.ts +74 -0
  46. package/src/examples/util.ts +44 -0
  47. package/src/index.ts +1 -0
  48. package/src/mnemonic.ts +1 -0
  49. package/src/sandbox.ts +165 -0
  50. package/src/splash.ts +10 -0
@@ -0,0 +1,109 @@
1
+ import { aztecNodeConfigMappings, getConfigEnvVars as getNodeConfigEnvVars } from '@aztec/aztec-node';
2
+ import { AztecNodeApiSchema, P2PApiSchema } from '@aztec/circuit-types';
3
+ import { NULL_KEY } from '@aztec/ethereum';
4
+ import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';
5
+ import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
6
+ import { createAztecNode, deployContractsToL1 } from '../../sandbox.js';
7
+ import { extractNamespacedOptions, extractRelevantOptions } from '../util.js';
8
+ import { validateL1Config } from '../validation.js';
9
+ export async function startNode(options, signalHandlers, services, userLog) {
10
+ // options specifically namespaced with --node.<option>
11
+ const nodeSpecificOptions = extractNamespacedOptions(options, 'node');
12
+ // All options that are relevant to the Aztec Node
13
+ const nodeConfig = {
14
+ ...extractRelevantOptions(options, aztecNodeConfigMappings, 'node')
15
+ };
16
+ if (options.proverNode) {
17
+ userLog(`Running a Prover Node within a Node is not yet supported`);
18
+ process.exit(1);
19
+ }
20
+ // Deploy contracts if needed
21
+ if (nodeSpecificOptions.deployAztecContracts || nodeSpecificOptions.deployAztecContractsSalt) {
22
+ let account;
23
+ if (nodeSpecificOptions.publisherPrivateKey) {
24
+ account = privateKeyToAccount(nodeSpecificOptions.publisherPrivateKey);
25
+ } else if (options.l1Mnemonic) {
26
+ account = mnemonicToAccount(options.l1Mnemonic);
27
+ } else {
28
+ throw new Error('--node.publisherPrivateKey or --l1-mnemonic is required to deploy L1 contracts');
29
+ }
30
+ // REFACTOR: We should not be calling a method from sandbox on the prod start flow
31
+ await deployContractsToL1(nodeConfig, account, undefined, {
32
+ assumeProvenThroughBlockNumber: nodeSpecificOptions.assumeProvenThroughBlockNumber,
33
+ salt: nodeSpecificOptions.deployAztecContractsSalt
34
+ });
35
+ } else {
36
+ await validateL1Config({
37
+ ...getNodeConfigEnvVars(),
38
+ ...nodeConfig
39
+ });
40
+ }
41
+ // if no publisher private key, then use l1Mnemonic
42
+ if (!options.archiver) {
43
+ // expect archiver url in node config
44
+ const archiverUrl = nodeConfig.archiverUrl;
45
+ if (!archiverUrl) {
46
+ userLog('Archiver Service URL is required to start Aztec Node without --archiver option');
47
+ throw new Error('Archiver Service URL is required to start Aztec Node without --archiver option');
48
+ }
49
+ nodeConfig.archiverUrl = archiverUrl;
50
+ }
51
+ if (!options.sequencer) {
52
+ nodeConfig.disableValidator = true;
53
+ } else {
54
+ const sequencerConfig = extractNamespacedOptions(options, 'sequencer');
55
+ let account;
56
+ if (!sequencerConfig.publisherPrivateKey || sequencerConfig.publisherPrivateKey === NULL_KEY) {
57
+ if (!options.l1Mnemonic) {
58
+ userLog('--sequencer.publisherPrivateKey or --l1-mnemonic is required to start Aztec Node with --sequencer option');
59
+ throw new Error('Private key or Mnemonic is required to start Aztec Node with --sequencer option');
60
+ } else {
61
+ account = mnemonicToAccount(options.l1Mnemonic);
62
+ const privKey = account.getHdKey().privateKey;
63
+ nodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey).toString('hex')}`;
64
+ }
65
+ } else {
66
+ nodeConfig.publisherPrivateKey = sequencerConfig.publisherPrivateKey;
67
+ }
68
+ }
69
+ if (nodeConfig.p2pEnabled) {
70
+ // ensure bootstrapNodes is an array
71
+ if (nodeConfig.bootstrapNodes && typeof nodeConfig.bootstrapNodes === 'string') {
72
+ nodeConfig.bootstrapNodes = nodeConfig.bootstrapNodes.split(',');
73
+ }
74
+ }
75
+ const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel');
76
+ const telemetry = initTelemetryClient(telemetryConfig);
77
+ // Create and start Aztec Node
78
+ const node = await createAztecNode(nodeConfig, {
79
+ telemetry
80
+ });
81
+ // Add node and p2p to services list
82
+ services.node = [
83
+ node,
84
+ AztecNodeApiSchema
85
+ ];
86
+ services.p2p = [
87
+ node.getP2P(),
88
+ P2PApiSchema
89
+ ];
90
+ // Add node stop function to signal handlers
91
+ signalHandlers.push(node.stop.bind(node));
92
+ // Add a PXE client that connects to this node if requested
93
+ let pxe;
94
+ if (options.pxe) {
95
+ const { addPXE } = await import('./start_pxe.js');
96
+ pxe = await addPXE(options, signalHandlers, services, userLog, {
97
+ node
98
+ });
99
+ }
100
+ // Add a txs bot if requested
101
+ if (options.bot) {
102
+ const { addBot } = await import('./start_bot.js');
103
+ await addBot(options, signalHandlers, services, {
104
+ pxe,
105
+ node,
106
+ telemetry
107
+ });
108
+ }
109
+ }
@@ -0,0 +1,20 @@
1
+ import { P2PBootstrapApiSchema } from '@aztec/circuit-types';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { createStore } from '@aztec/kv-store/lmdb-v2';
4
+ import { BootstrapNode, bootnodeConfigMappings } from '@aztec/p2p';
5
+ import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
6
+ import { extractRelevantOptions } from '../util.js';
7
+ export async function startP2PBootstrap(options, signalHandlers, services, userLog) {
8
+ // Start a P2P bootstrap node.
9
+ const config = extractRelevantOptions(options, bootnodeConfigMappings, 'p2p');
10
+ const telemetryClient = initTelemetryClient(getTelemetryClientConfig());
11
+ const store = await createStore('p2p-bootstrap', config, createLogger('p2p:bootstrap:store'));
12
+ const node = new BootstrapNode(store, telemetryClient);
13
+ await node.start(config);
14
+ signalHandlers.push(()=>node.stop());
15
+ services.bootstrap = [
16
+ node,
17
+ P2PBootstrapApiSchema
18
+ ];
19
+ userLog(`P2P bootstrap node started on ${config.udpListenAddress}`);
20
+ }
@@ -0,0 +1,12 @@
1
+ import { ProofVerifier, proofVerifierConfigMappings } from '@aztec/proof-verifier';
2
+ import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';
3
+ import { extractRelevantOptions } from '../util.js';
4
+ export async function startProofVerifier(options, signalHandlers, userLog) {
5
+ const config = extractRelevantOptions(options, proofVerifierConfigMappings, 'proofVerifier');
6
+ const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel');
7
+ const telemetry = initTelemetryClient(telemetryConfig);
8
+ const proofVerifier = await ProofVerifier.new(config, telemetry);
9
+ userLog('Starting proof verifier');
10
+ proofVerifier.start();
11
+ signalHandlers.push(()=>proofVerifier.stop());
12
+ }
@@ -0,0 +1,32 @@
1
+ import { times } from '@aztec/foundation/collection';
2
+ import { buildServerCircuitProver } from '@aztec/prover-client';
3
+ import { InlineProofStore, ProvingAgent, createProvingJobBrokerClient, proverAgentConfigMappings } from '@aztec/prover-client/broker';
4
+ import { getProverNodeAgentConfigFromEnv } from '@aztec/prover-node';
5
+ import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';
6
+ import { extractRelevantOptions } from '../util.js';
7
+ export async function startProverAgent(options, signalHandlers, services, userLog) {
8
+ if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
9
+ userLog(`Starting a prover agent with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
10
+ process.exit(1);
11
+ }
12
+ const config = {
13
+ ...getProverNodeAgentConfigFromEnv(),
14
+ ...extractRelevantOptions(options, proverAgentConfigMappings, 'proverAgent')
15
+ };
16
+ if (config.realProofs && (!config.bbBinaryPath || !config.acvmBinaryPath)) {
17
+ process.exit(1);
18
+ }
19
+ if (!config.proverBrokerUrl) {
20
+ process.exit(1);
21
+ }
22
+ const broker = createProvingJobBrokerClient(config.proverBrokerUrl);
23
+ const telemetry = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
24
+ const prover = await buildServerCircuitProver(config, telemetry);
25
+ const proofStore = new InlineProofStore();
26
+ const agents = times(config.proverAgentCount, ()=>new ProvingAgent(broker, proofStore, prover, config.proverAgentProofTypes, config.proverAgentPollIntervalMs, telemetry));
27
+ await Promise.all(agents.map((agent)=>agent.start()));
28
+ signalHandlers.push(async ()=>{
29
+ await Promise.all(agents.map((agent)=>agent.stop()));
30
+ await telemetry.stop();
31
+ });
32
+ }
@@ -0,0 +1,22 @@
1
+ import { ProvingJobBrokerSchema, createAndStartProvingBroker, proverBrokerConfigMappings } from '@aztec/prover-client/broker';
2
+ import { getProverNodeBrokerConfigFromEnv } from '@aztec/prover-node';
3
+ import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
4
+ import { extractRelevantOptions } from '../util.js';
5
+ export async function startProverBroker(options, signalHandlers, services, userLog) {
6
+ if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
7
+ userLog(`Starting a prover broker with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
8
+ process.exit(1);
9
+ }
10
+ const config = {
11
+ ...getProverNodeBrokerConfigFromEnv(),
12
+ ...extractRelevantOptions(options, proverBrokerConfigMappings, 'proverBroker')
13
+ };
14
+ const client = initTelemetryClient(getTelemetryClientConfig());
15
+ const broker = await createAndStartProvingBroker(config, client);
16
+ services.proverBroker = [
17
+ broker,
18
+ ProvingJobBrokerSchema
19
+ ];
20
+ signalHandlers.push(()=>broker.stop());
21
+ return broker;
22
+ }
@@ -0,0 +1,81 @@
1
+ import { P2PApiSchema, ProverNodeApiSchema, createAztecNodeClient } from '@aztec/circuit-types';
2
+ import { NULL_KEY } from '@aztec/ethereum';
3
+ import { ProvingJobConsumerSchema, createProvingJobBrokerClient } from '@aztec/prover-client/broker';
4
+ import { createProverNode, getProverNodeConfigFromEnv, proverNodeConfigMappings } from '@aztec/prover-node';
5
+ import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client';
6
+ import { mnemonicToAccount } from 'viem/accounts';
7
+ import { extractRelevantOptions } from '../util.js';
8
+ import { validateL1Config } from '../validation.js';
9
+ import { startProverBroker } from './start_prover_broker.js';
10
+ export async function startProverNode(options, signalHandlers, services, userLog) {
11
+ if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
12
+ userLog(`Starting a prover-node with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
13
+ process.exit(1);
14
+ }
15
+ const proverConfig = {
16
+ ...getProverNodeConfigFromEnv(),
17
+ ...extractRelevantOptions(options, proverNodeConfigMappings, 'proverNode')
18
+ };
19
+ if (!options.archiver && !proverConfig.archiverUrl) {
20
+ userLog('--archiver.archiverUrl is required to start a Prover Node without --archiver option');
21
+ process.exit(1);
22
+ }
23
+ if (!proverConfig.publisherPrivateKey || proverConfig.publisherPrivateKey === NULL_KEY) {
24
+ if (!options.l1Mnemonic) {
25
+ userLog(`--l1-mnemonic is required to start a Prover Node without --node.publisherPrivateKey`);
26
+ process.exit(1);
27
+ }
28
+ const hdAccount = mnemonicToAccount(options.l1Mnemonic);
29
+ const privKey = hdAccount.getHdKey().privateKey;
30
+ proverConfig.publisherPrivateKey = `0x${Buffer.from(privKey).toString('hex')}`;
31
+ }
32
+ // TODO(palla/prover-node) L1 contract addresses should not silently default to zero,
33
+ // they should be undefined if not set and fail loudly.
34
+ // Load l1 contract addresses from aztec node if not set.
35
+ const isRollupAddressSet = proverConfig.l1Contracts?.rollupAddress && !proverConfig.l1Contracts.rollupAddress.isZero();
36
+ const nodeUrl = proverConfig.nodeUrl ?? proverConfig.proverCoordinationNodeUrl;
37
+ if (nodeUrl && !isRollupAddressSet) {
38
+ userLog(`Loading L1 contract addresses from aztec node at ${nodeUrl}`);
39
+ proverConfig.l1Contracts = await createAztecNodeClient(nodeUrl).getL1ContractAddresses();
40
+ }
41
+ // If we create an archiver here, validate the L1 config
42
+ if (options.archiver) {
43
+ await validateL1Config(proverConfig);
44
+ }
45
+ const telemetry = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
46
+ let broker;
47
+ if (proverConfig.proverBrokerUrl) {
48
+ broker = createProvingJobBrokerClient(proverConfig.proverBrokerUrl);
49
+ } else if (options.proverBroker) {
50
+ broker = await startProverBroker(options, signalHandlers, services, userLog);
51
+ } else {
52
+ userLog(`--prover-broker-url or --prover-broker is required to start a Prover Node`);
53
+ process.exit(1);
54
+ }
55
+ if (proverConfig.proverAgentCount === 0) {
56
+ userLog(`Running prover node without local prover agent. Connect one or more prover agents to this node or pass --proverAgent.proverAgentCount`);
57
+ }
58
+ const proverNode = await createProverNode(proverConfig, {
59
+ telemetry,
60
+ broker
61
+ });
62
+ services.proverNode = [
63
+ proverNode,
64
+ ProverNodeApiSchema
65
+ ];
66
+ const p2p = proverNode.getP2P();
67
+ if (p2p) {
68
+ services.p2p = [
69
+ proverNode.getP2P(),
70
+ P2PApiSchema
71
+ ];
72
+ }
73
+ if (!proverConfig.proverBrokerUrl) {
74
+ services.provingJobSource = [
75
+ proverNode.getProver().getProvingJobSource(),
76
+ ProvingJobConsumerSchema
77
+ ];
78
+ }
79
+ signalHandlers.push(proverNode.stop.bind(proverNode));
80
+ await proverNode.start();
81
+ }
@@ -0,0 +1,90 @@
1
+ import { Fr, PublicKeys, getContractClassFromArtifact } from '@aztec/aztec.js';
2
+ import { PXESchema, createAztecNodeClient } from '@aztec/circuit-types';
3
+ import { getContractArtifact } from '@aztec/cli/cli-utils';
4
+ import { AztecAddress, allPxeConfigMappings, createPXEService } from '@aztec/pxe';
5
+ import { makeTracedFetch } from '@aztec/telemetry-client';
6
+ import { L2BasicContractsMap, Network } from '@aztec/types/network';
7
+ import { extractRelevantOptions } from '../util.js';
8
+ const contractAddressesUrl = 'http://static.aztec.network';
9
+ export async function startPXE(options, signalHandlers, services, userLog) {
10
+ await addPXE(options, signalHandlers, services, userLog, {});
11
+ return services;
12
+ }
13
+ function isValidNetwork(value) {
14
+ return Object.values(Network).includes(value);
15
+ }
16
+ async function fetchBasicContractAddresses(url) {
17
+ const response = await fetch(url);
18
+ if (!response.ok) {
19
+ throw new Error(`Failed to fetch basic contract addresses from ${url}`);
20
+ }
21
+ return response.json();
22
+ }
23
+ export async function addPXE(options, signalHandlers, services, userLog, deps = {}) {
24
+ const pxeConfig = extractRelevantOptions(options, allPxeConfigMappings, 'pxe');
25
+ let nodeUrl;
26
+ if (pxeConfig.network) {
27
+ if (isValidNetwork(pxeConfig.network)) {
28
+ if (!pxeConfig.apiKey && !pxeConfig.nodeUrl) {
29
+ userLog(`API Key or Aztec Node URL is required to connect to ${pxeConfig.network}`);
30
+ process.exit(1);
31
+ } else if (pxeConfig.apiKey) {
32
+ nodeUrl = `https://api.aztec.network/${pxeConfig.network}/aztec-node-1/${pxeConfig.apiKey}`;
33
+ } else if (pxeConfig.nodeUrl) {
34
+ nodeUrl = pxeConfig.nodeUrl;
35
+ }
36
+ } else {
37
+ userLog(`Network ${pxeConfig.network} is not supported`);
38
+ process.exit(1);
39
+ }
40
+ } else {
41
+ nodeUrl = pxeConfig.nodeUrl;
42
+ }
43
+ if (!nodeUrl && !deps.node && !pxeConfig.network) {
44
+ userLog('Aztec Node URL (nodeUrl | AZTEC_NODE_URL) option is required to start PXE without --node option');
45
+ process.exit(1);
46
+ }
47
+ const node = deps.node ?? createAztecNodeClient(nodeUrl, makeTracedFetch([
48
+ 1,
49
+ 2,
50
+ 3
51
+ ], true));
52
+ const pxe = await createPXEService(node, pxeConfig);
53
+ // register basic contracts
54
+ if (pxeConfig.network) {
55
+ userLog(`Registering basic contracts for ${pxeConfig.network}`);
56
+ const basicContractsInfo = await fetchBasicContractAddresses(`${contractAddressesUrl}/${pxeConfig.network}/basic_contracts.json`);
57
+ const l2Contracts = {};
58
+ for (const [key, artifactName] of Object.entries(L2BasicContractsMap[pxeConfig.network])){
59
+ l2Contracts[key] = {
60
+ name: key,
61
+ address: AztecAddress.fromString(basicContractsInfo[key].address),
62
+ initHash: Fr.fromHexString(basicContractsInfo[key].initHash),
63
+ salt: Fr.fromHexString(basicContractsInfo[key].salt),
64
+ artifact: await getContractArtifact(artifactName, userLog)
65
+ };
66
+ }
67
+ await Promise.all(Object.values(l2Contracts).map(async ({ name, address, artifact, initHash, salt })=>{
68
+ const instance = {
69
+ version: 1,
70
+ salt,
71
+ initializationHash: initHash,
72
+ address,
73
+ deployer: AztecAddress.ZERO,
74
+ contractClassId: (await getContractClassFromArtifact(artifact)).id,
75
+ publicKeys: PublicKeys.default()
76
+ };
77
+ userLog(`Registering ${name} at ${address.toString()}`);
78
+ await pxe.registerContract({
79
+ artifact,
80
+ instance
81
+ });
82
+ }));
83
+ }
84
+ // Add PXE to services list
85
+ services.pxe = [
86
+ pxe,
87
+ PXESchema
88
+ ];
89
+ return pxe;
90
+ }
@@ -0,0 +1,11 @@
1
+ import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
2
+ import { createTXERpcServer } from '@aztec/txe';
3
+ export async function startTXE(options, debugLogger) {
4
+ debugLogger.info(`Setting up TXE...`);
5
+ const txeServer = createTXERpcServer(debugLogger);
6
+ const { port } = await startHttpRpcServer(txeServer, {
7
+ port: options.port,
8
+ timeoutMs: 1e3 * 60 * 5
9
+ });
10
+ debugLogger.info(`TXE listening on port ${port}`);
11
+ }
@@ -0,0 +1 @@
1
+ export * from './cli.js';
@@ -0,0 +1,154 @@
1
+ import chalk from 'chalk';
2
+ import { aztecStartOptions } from './aztec_start_options.js';
3
+ export const installSignalHandlers = (logFn, cb)=>{
4
+ const shutdown = async ()=>{
5
+ logFn('Shutting down...');
6
+ if (cb) {
7
+ await Promise.all(cb);
8
+ }
9
+ process.exit(0);
10
+ };
11
+ process.removeAllListeners('SIGINT');
12
+ process.removeAllListeners('SIGTERM');
13
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
14
+ process.once('SIGINT', shutdown);
15
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
16
+ process.once('SIGTERM', shutdown);
17
+ };
18
+ /**
19
+ * Creates logs for the initial accounts
20
+ * @param accounts - The initial accounts
21
+ * @param pxe - A PXE instance to get the registered accounts
22
+ * @returns A string array containing the initial accounts details
23
+ */ export async function createAccountLogs(accountsWithSecretKeys, pxe) {
24
+ const registeredAccounts = await pxe.getRegisteredAccounts();
25
+ const accountLogStrings = [
26
+ `Initial Accounts:\n\n`
27
+ ];
28
+ for (const accountWithSecretKey of accountsWithSecretKeys){
29
+ const completeAddress = await accountWithSecretKey.account.getCompleteAddress();
30
+ if (registeredAccounts.find((a)=>a.equals(completeAddress))) {
31
+ accountLogStrings.push(` Address: ${completeAddress.address.toString()}\n`);
32
+ accountLogStrings.push(` Partial Address: ${completeAddress.partialAddress.toString()}\n`);
33
+ accountLogStrings.push(` Secret Key: ${accountWithSecretKey.secretKey.toString()}\n`);
34
+ accountLogStrings.push(` Master nullifier public key: ${completeAddress.publicKeys.masterNullifierPublicKey.toString()}\n`);
35
+ accountLogStrings.push(` Master incoming viewing public key: ${completeAddress.publicKeys.masterIncomingViewingPublicKey.toString()}\n\n`);
36
+ accountLogStrings.push(` Master outgoing viewing public key: ${completeAddress.publicKeys.masterOutgoingViewingPublicKey.toString()}\n\n`);
37
+ accountLogStrings.push(` Master tagging public key: ${completeAddress.publicKeys.masterTaggingPublicKey.toString()}\n\n`);
38
+ }
39
+ }
40
+ return accountLogStrings;
41
+ }
42
+ export function getMaxLengths(sections) {
43
+ let maxFlagLength = 0;
44
+ let maxDefaultLength = 0;
45
+ Object.values(sections).forEach((options)=>{
46
+ options.forEach((option)=>{
47
+ if (option.flag.length > maxFlagLength) {
48
+ maxFlagLength = option.flag.length;
49
+ }
50
+ const defaultLength = option.defaultValue ? option.defaultValue.length : 0;
51
+ if (defaultLength > maxDefaultLength) {
52
+ maxDefaultLength = defaultLength;
53
+ }
54
+ });
55
+ });
56
+ return [
57
+ maxFlagLength + 1,
58
+ maxDefaultLength + 1
59
+ ];
60
+ }
61
+ export function formatHelpLine(option, defaultValue, envVar, maxOptionLength, maxDefaultLength) {
62
+ const paddedOption = option.padEnd(maxOptionLength + 2, ' ');
63
+ const paddedDefault = defaultValue.padEnd(maxDefaultLength + 2, ' ');
64
+ return `${chalk.cyan(paddedOption)}${chalk.yellow(paddedDefault)}${chalk.green(envVar)}`;
65
+ }
66
+ const getDefaultOrEnvValue = (opt)=>{
67
+ let val;
68
+ // if the option is set in the environment, use that & parse it
69
+ if (opt.envVar && process.env[opt.envVar]) {
70
+ val = process.env[opt.envVar];
71
+ if (val && opt.parseVal) {
72
+ return opt.parseVal(val);
73
+ }
74
+ // if no env variable, use the default value
75
+ } else if (opt.defaultValue) {
76
+ val = opt.defaultValue;
77
+ }
78
+ return val;
79
+ };
80
+ // Function to add options dynamically
81
+ export const addOptions = (cmd, options)=>{
82
+ options.forEach((opt)=>{
83
+ cmd.option(opt.flag, `${opt.description} (default: ${opt.defaultValue}) ($${opt.envVar})`, opt.parseVal ? opt.parseVal : (val)=>val, getDefaultOrEnvValue(opt));
84
+ });
85
+ };
86
+ export const printAztecStartHelpText = ()=>{
87
+ const helpTextLines = [
88
+ ''
89
+ ];
90
+ const [maxFlagLength, maxDefaultLength] = getMaxLengths(aztecStartOptions);
91
+ Object.keys(aztecStartOptions).forEach((category)=>{
92
+ helpTextLines.push(chalk.bold.blue(` ${category}`));
93
+ helpTextLines.push('');
94
+ aztecStartOptions[category].forEach((opt)=>{
95
+ const defaultValueText = opt.defaultValue ? `(default: ${opt.printDefault ? opt.printDefault(opt.defaultValue) : opt.defaultValue})` : '';
96
+ const envVarText = opt.envVar ? `($${opt.envVar})` : '';
97
+ const flagText = `${opt.flag}`;
98
+ const paddedText = formatHelpLine(flagText, defaultValueText, envVarText, maxFlagLength, maxDefaultLength);
99
+ helpTextLines.push(` ${paddedText}`);
100
+ helpTextLines.push(` ${chalk.white(opt.description)}`);
101
+ helpTextLines.push('');
102
+ });
103
+ });
104
+ return helpTextLines.join('\n');
105
+ };
106
+ /**
107
+ * Extracts namespaced options from a key-value map.
108
+ * @param options - Key-value map of options.
109
+ * @param namespace - The namespace to extract.
110
+ * @returns Key-value map of namespaced options.
111
+ */ export const extractNamespacedOptions = (options, namespace)=>{
112
+ const extract = `${namespace}.`;
113
+ const namespacedOptions = {};
114
+ for(const key in options){
115
+ if (key.startsWith(extract)) {
116
+ namespacedOptions[key.replace(extract, '')] = options[key];
117
+ }
118
+ }
119
+ return namespacedOptions;
120
+ };
121
+ /**
122
+ * Extracts relevant options from a key-value map.
123
+ * @template T - The type of the relevant options.
124
+ * @param options - Key-value map of options.
125
+ * @param mappings - The mappings to extract.
126
+ * @param namespace - The namespace to extract for.
127
+ * @returns Key-value map of relevant options.
128
+ */ export const extractRelevantOptions = (options, mappings, namespace)=>{
129
+ const relevantOptions = {};
130
+ // Iterate over each key in the options
131
+ Object.keys(options).forEach((optionKey)=>{
132
+ const keyParts = optionKey.split('.');
133
+ const optionNamespace = keyParts.length > 1 ? keyParts[0] : '';
134
+ const mainKey = keyParts.length > 1 ? keyParts[1] : keyParts[0];
135
+ // Check if the key exists in the mappings
136
+ if (mainKey in mappings) {
137
+ // Check for duplicates in the options
138
+ const duplicates = Object.keys(options).filter((optKey)=>{
139
+ const optKeyParts = optKey.split('.');
140
+ return optKeyParts[1] === mainKey || optKeyParts[0] === mainKey;
141
+ });
142
+ // If duplicates are found, use the namespace to differentiate
143
+ if (duplicates.length > 1) {
144
+ if (namespace === optionNamespace) {
145
+ relevantOptions[mainKey] = options[optionKey];
146
+ }
147
+ } else {
148
+ // If no duplicates, extract the value without considering the namespace
149
+ relevantOptions[mainKey] = options[optionKey];
150
+ }
151
+ }
152
+ });
153
+ return relevantOptions;
154
+ };
@@ -0,0 +1,25 @@
1
+ import { getL1ContractsAddresses, getL1ContractsConfig, getPublicClient } from '@aztec/ethereum';
2
+ /**
3
+ * Connects to L1 using the provided L1 RPC URL and reads all addresses and settings from the governance
4
+ * contract. For each key, compares it against the provided config (if it is not empty) and throws on mismatches.
5
+ */ export async function validateL1Config(config) {
6
+ const publicClient = getPublicClient(config);
7
+ const actualAddresses = await getL1ContractsAddresses(publicClient, config.l1Contracts.governanceAddress);
8
+ for(const keyStr in actualAddresses){
9
+ const key = keyStr;
10
+ const actual = actualAddresses[key];
11
+ const expected = config.l1Contracts[key];
12
+ if (expected !== undefined && !expected.isZero() && !actual.equals(expected)) {
13
+ throw new Error(`Expected L1 contract address ${key} to be ${expected} but found ${actual}`);
14
+ }
15
+ }
16
+ const actualConfig = await getL1ContractsConfig(publicClient, actualAddresses);
17
+ for(const keyStr in actualConfig){
18
+ const key = keyStr;
19
+ const actual = actualConfig[key];
20
+ const expected = config[key];
21
+ if (expected !== undefined && actual !== expected) {
22
+ throw new Error(`Expected L1 setting ${key} to be ${expected} but found ${actual}`);
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,53 @@
1
+ import { getSingleKeyAccount } from '@aztec/accounts/single_key';
2
+ import { Fr, createPXEClient } from '@aztec/aztec.js';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { TokenContract } from '@aztec/noir-contracts.js/Token';
5
+ const logger = createLogger('example:token');
6
+ export const alicePrivateKey = Fr.random();
7
+ export const bobPrivateKey = Fr.random();
8
+ const url = 'http://localhost:8080';
9
+ const pxe = createPXEClient(url);
10
+ let aliceWallet;
11
+ let bobWallet;
12
+ const ALICE_MINT_BALANCE = 333n;
13
+ const TRANSFER_AMOUNT = 33n;
14
+ /**
15
+ * Main function.
16
+ */ async function main() {
17
+ logger.info('Running token contract test on HTTP interface.');
18
+ const aliceAccount = await getSingleKeyAccount(pxe, alicePrivateKey);
19
+ aliceWallet = await aliceAccount.waitSetup();
20
+ const bobAccount = await getSingleKeyAccount(pxe, bobPrivateKey);
21
+ bobWallet = await bobAccount.waitSetup();
22
+ const alice = aliceWallet.getCompleteAddress();
23
+ const bob = bobWallet.getCompleteAddress();
24
+ logger.info(`Created Alice and Bob accounts: ${alice.address.toString()}, ${bob.address.toString()}`);
25
+ logger.info('Deploying Token...');
26
+ const token = await TokenContract.deploy(aliceWallet, alice, 'TokenName', 'TokenSymbol', 18).send().deployed();
27
+ logger.info('Token deployed');
28
+ // Create the contract abstraction and link it to Alice's and Bob's wallet for future signing
29
+ const tokenAlice = await TokenContract.at(token.address, aliceWallet);
30
+ const tokenBob = await TokenContract.at(token.address, bobWallet);
31
+ // Mint tokens to Alice
32
+ logger.info(`Minting ${ALICE_MINT_BALANCE} more coins to Alice...`);
33
+ const from = aliceWallet.getAddress(); // we are setting from to Alice here because of TODO(#9887)
34
+ await tokenAlice.methods.mint_to_private(from, aliceWallet.getAddress(), ALICE_MINT_BALANCE).send().wait();
35
+ logger.info(`${ALICE_MINT_BALANCE} tokens were successfully minted by Alice and transferred to private`);
36
+ const balanceAfterMint = await tokenAlice.methods.balance_of_private(alice).simulate();
37
+ logger.info(`Tokens successfully minted. New Alice's balance: ${balanceAfterMint}`);
38
+ // We will now transfer tokens from Alice to Bob
39
+ logger.info(`Transferring ${TRANSFER_AMOUNT} tokens from Alice to Bob...`);
40
+ await tokenAlice.methods.transfer(bob, TRANSFER_AMOUNT).send().wait();
41
+ // Check the new balances
42
+ const aliceBalance = await tokenAlice.methods.balance_of_private(alice).simulate();
43
+ logger.info(`Alice's balance ${aliceBalance}`);
44
+ const bobBalance = await tokenBob.methods.balance_of_private(bob).simulate();
45
+ logger.info(`Bob's balance ${bobBalance}`);
46
+ }
47
+ main().then(()=>{
48
+ logger.info('Finished running successfully.');
49
+ process.exit(0);
50
+ }).catch((err)=>{
51
+ logger.error('Error in main fn: ', err);
52
+ process.exit(1);
53
+ });
@@ -0,0 +1,31 @@
1
+ import { EthAddress } from '@aztec/aztec.js';
2
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
3
+ /**
4
+ * Helper function to deploy ETH contracts.
5
+ * @param walletClient - A viem WalletClient.
6
+ * @param publicClient - A viem PublicClient.
7
+ * @param abi - The ETH contract's ABI (as abitype's Abi).
8
+ * @param bytecode - The ETH contract's bytecode.
9
+ * @param args - Constructor arguments for the contract.
10
+ * @returns The ETH address the contract was deployed to.
11
+ */ export async function deployL1Contract(walletClient, publicClient, abi, bytecode, args = []) {
12
+ const hash = await walletClient.deployContract({
13
+ abi,
14
+ bytecode,
15
+ args
16
+ });
17
+ const receipt = await publicClient.waitForTransactionReceipt({
18
+ hash
19
+ });
20
+ const contractAddress = receipt.contractAddress;
21
+ if (!contractAddress) {
22
+ throw new Error(`No contract address found in receipt: ${jsonStringify(receipt)}`);
23
+ }
24
+ return EthAddress.fromString(receipt.contractAddress);
25
+ }
26
+ /**
27
+ * Sleep for a given number of milliseconds.
28
+ * @param ms - the number of milliseconds to sleep for
29
+ */ export function delay(ms) {
30
+ return new Promise((resolve)=>setTimeout(resolve, ms));
31
+ }
package/dest/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createSandbox } from './sandbox.js';
@@ -0,0 +1 @@
1
+ export const DefaultMnemonic = 'test test test test test test test test test test test junk';