@aztec/cli-wallet 0.0.0-test.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 (94) hide show
  1. package/README.md +2 -0
  2. package/dest/bin/index.d.ts +2 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +75 -0
  5. package/dest/cmds/add_authwit.d.ts +4 -0
  6. package/dest/cmds/add_authwit.d.ts.map +1 -0
  7. package/dest/cmds/add_authwit.js +4 -0
  8. package/dest/cmds/authorize_action.d.ts +4 -0
  9. package/dest/cmds/authorize_action.d.ts.map +1 -0
  10. package/dest/cmds/authorize_action.js +17 -0
  11. package/dest/cmds/bridge_fee_juice.d.ts +6 -0
  12. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -0
  13. package/dest/cmds/bridge_fee_juice.js +52 -0
  14. package/dest/cmds/cancel_tx.d.ts +11 -0
  15. package/dest/cmds/cancel_tx.d.ts.map +1 -0
  16. package/dest/cmds/cancel_tx.js +38 -0
  17. package/dest/cmds/check_tx.d.ts +4 -0
  18. package/dest/cmds/check_tx.d.ts.map +1 -0
  19. package/dest/cmds/check_tx.js +11 -0
  20. package/dest/cmds/create_account.d.ts +12 -0
  21. package/dest/cmds/create_account.d.ts.map +1 -0
  22. package/dest/cmds/create_account.js +94 -0
  23. package/dest/cmds/create_authwit.d.ts +4 -0
  24. package/dest/cmds/create_authwit.d.ts.map +1 -0
  25. package/dest/cmds/create_authwit.js +16 -0
  26. package/dest/cmds/deploy.d.ts +6 -0
  27. package/dest/cmds/deploy.d.ts.map +1 -0
  28. package/dest/cmds/deploy.js +83 -0
  29. package/dest/cmds/deploy_account.d.ts +9 -0
  30. package/dest/cmds/deploy_account.d.ts.map +1 -0
  31. package/dest/cmds/deploy_account.js +80 -0
  32. package/dest/cmds/import_test_accounts.d.ts +5 -0
  33. package/dest/cmds/import_test_accounts.d.ts.map +1 -0
  34. package/dest/cmds/import_test_accounts.js +42 -0
  35. package/dest/cmds/index.d.ts +6 -0
  36. package/dest/cmds/index.d.ts.map +1 -0
  37. package/dest/cmds/index.js +223 -0
  38. package/dest/cmds/register_contract.d.ts +4 -0
  39. package/dest/cmds/register_contract.d.ts.map +1 -0
  40. package/dest/cmds/register_contract.js +14 -0
  41. package/dest/cmds/register_sender.d.ts +4 -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 +49 -0
  47. package/dest/cmds/simulate.d.ts +4 -0
  48. package/dest/cmds/simulate.d.ts.map +1 -0
  49. package/dest/cmds/simulate.js +26 -0
  50. package/dest/storage/wallet_db.d.ts +65 -0
  51. package/dest/storage/wallet_db.d.ts.map +1 -0
  52. package/dest/storage/wallet_db.js +209 -0
  53. package/dest/utils/accounts.d.ts +11 -0
  54. package/dest/utils/accounts.d.ts.map +1 -0
  55. package/dest/utils/accounts.js +87 -0
  56. package/dest/utils/ecdsa.d.ts +4 -0
  57. package/dest/utils/ecdsa.d.ts.map +1 -0
  58. package/dest/utils/ecdsa.js +13 -0
  59. package/dest/utils/options/fees.d.ts +41 -0
  60. package/dest/utils/options/fees.d.ts.map +1 -0
  61. package/dest/utils/options/fees.js +283 -0
  62. package/dest/utils/options/index.d.ts +3 -0
  63. package/dest/utils/options/index.d.ts.map +1 -0
  64. package/dest/utils/options/index.js +2 -0
  65. package/dest/utils/options/options.d.ts +20 -0
  66. package/dest/utils/options/options.d.ts.map +1 -0
  67. package/dest/utils/options/options.js +122 -0
  68. package/dest/utils/pxe_wrapper.d.ts +10 -0
  69. package/dest/utils/pxe_wrapper.d.ts.map +1 -0
  70. package/dest/utils/pxe_wrapper.js +21 -0
  71. package/package.json +102 -0
  72. package/src/bin/index.ts +127 -0
  73. package/src/cmds/add_authwit.ts +13 -0
  74. package/src/cmds/authorize_action.ts +36 -0
  75. package/src/cmds/bridge_fee_juice.ts +88 -0
  76. package/src/cmds/cancel_tx.ts +62 -0
  77. package/src/cmds/check_tx.ts +12 -0
  78. package/src/cmds/create_account.ts +120 -0
  79. package/src/cmds/create_authwit.ts +35 -0
  80. package/src/cmds/deploy.ts +113 -0
  81. package/src/cmds/deploy_account.ts +92 -0
  82. package/src/cmds/import_test_accounts.ts +47 -0
  83. package/src/cmds/index.ts +641 -0
  84. package/src/cmds/register_contract.ts +20 -0
  85. package/src/cmds/register_sender.ts +7 -0
  86. package/src/cmds/send.ts +62 -0
  87. package/src/cmds/simulate.ts +42 -0
  88. package/src/storage/wallet_db.ts +243 -0
  89. package/src/utils/accounts.ts +102 -0
  90. package/src/utils/ecdsa.ts +15 -0
  91. package/src/utils/options/fees.ts +365 -0
  92. package/src/utils/options/index.ts +2 -0
  93. package/src/utils/options/options.ts +175 -0
  94. package/src/utils/pxe_wrapper.ts +26 -0
@@ -0,0 +1,120 @@
1
+ import type { DeployAccountOptions, PXE } from '@aztec/aztec.js';
2
+ import { prettyPrintJSON } from '@aztec/cli/cli-utils';
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import type { LogFn, Logger } from '@aztec/foundation/log';
5
+
6
+ import { type AccountType, createOrRetrieveAccount } from '../utils/accounts.js';
7
+ import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
8
+
9
+ export async function createAccount(
10
+ client: PXE,
11
+ accountType: AccountType,
12
+ secretKey: Fr | undefined,
13
+ publicKey: string | undefined,
14
+ alias: string | undefined,
15
+ registerOnly: boolean,
16
+ publicDeploy: boolean,
17
+ skipInitialization: boolean,
18
+ wait: boolean,
19
+ feeOpts: IFeeOpts,
20
+ json: boolean,
21
+ debugLogger: Logger,
22
+ log: LogFn,
23
+ ) {
24
+ secretKey ??= Fr.random();
25
+
26
+ const account = await createOrRetrieveAccount(
27
+ client,
28
+ undefined /* address, we don't have it yet */,
29
+ undefined /* db, as we want to create from scratch */,
30
+ secretKey,
31
+ accountType,
32
+ Fr.ZERO,
33
+ publicKey,
34
+ );
35
+ const salt = account.getInstance().salt;
36
+ const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
37
+
38
+ const out: Record<string, any> = {};
39
+ if (json) {
40
+ out.address = address;
41
+ out.publicKey = publicKeys;
42
+ if (secretKey) {
43
+ out.secretKey = secretKey;
44
+ }
45
+ out.partialAddress = partialAddress;
46
+ out.salt = salt;
47
+ out.initHash = account.getInstance().initializationHash;
48
+ out.deployer = account.getInstance().deployer;
49
+ } else {
50
+ log(`\nNew account:\n`);
51
+ log(`Address: ${address.toString()}`);
52
+ log(`Public key: ${publicKeys.toString()}`);
53
+ if (secretKey) {
54
+ log(`Secret key: ${secretKey.toString()}`);
55
+ }
56
+ log(`Partial address: ${partialAddress.toString()}`);
57
+ log(`Salt: ${salt.toString()}`);
58
+ log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
59
+ log(`Deployer: ${account.getInstance().deployer.toString()}`);
60
+ }
61
+
62
+ let tx;
63
+ let txReceipt;
64
+ if (registerOnly) {
65
+ await account.register();
66
+ } else {
67
+ const wallet = await account.getWallet();
68
+ const deployOpts: DeployAccountOptions = {
69
+ skipClassRegistration: !publicDeploy,
70
+ skipPublicDeployment: !publicDeploy,
71
+ skipInitialization: skipInitialization,
72
+ ...(await feeOpts.toDeployAccountOpts(wallet)),
73
+ };
74
+ if (feeOpts.estimateOnly) {
75
+ const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
76
+ if (json) {
77
+ out.fee = {
78
+ gasLimits: {
79
+ da: gas.gasLimits.daGas,
80
+ l2: gas.gasLimits.l2Gas,
81
+ },
82
+ teardownGasLimits: {
83
+ da: gas.teardownGasLimits.daGas,
84
+ l2: gas.teardownGasLimits,
85
+ },
86
+ };
87
+ } else {
88
+ printGasEstimates(feeOpts, gas, log);
89
+ }
90
+ } else {
91
+ tx = account.deploy(deployOpts);
92
+ const txHash = await tx.getTxHash();
93
+ debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
94
+ out.txHash = txHash;
95
+ if (wait) {
96
+ if (!json) {
97
+ log(`\nWaiting for account contract deployment...`);
98
+ }
99
+ txReceipt = await tx.wait();
100
+ out.txReceipt = {
101
+ status: txReceipt.status,
102
+ transactionFee: txReceipt.transactionFee,
103
+ };
104
+ }
105
+ }
106
+ }
107
+
108
+ if (json) {
109
+ log(prettyPrintJSON(out));
110
+ } else {
111
+ if (tx) {
112
+ log(`Deploy tx hash: ${await tx.getTxHash()}`);
113
+ }
114
+ if (txReceipt) {
115
+ log(`Deploy tx fee: ${txReceipt.transactionFee}`);
116
+ }
117
+ }
118
+
119
+ return { alias, address, secretKey, salt };
120
+ }
@@ -0,0 +1,35 @@
1
+ import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js';
2
+ import { prepTx } from '@aztec/cli/utils';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
+
5
+ export async function createAuthwit(
6
+ wallet: AccountWalletWithSecretKey,
7
+ functionName: string,
8
+ caller: AztecAddress,
9
+ functionArgsIn: any[],
10
+ contractArtifactPath: string,
11
+ contractAddress: AztecAddress,
12
+ log: LogFn,
13
+ ) {
14
+ const { functionArgs, contractArtifact, isPrivate } = await prepTx(
15
+ contractArtifactPath,
16
+ functionName,
17
+ functionArgsIn,
18
+ log,
19
+ );
20
+
21
+ if (!isPrivate) {
22
+ throw new Error(
23
+ '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',
24
+ );
25
+ }
26
+
27
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
28
+ const action = contract.methods[functionName](...functionArgs);
29
+
30
+ const witness = await wallet.createAuthWit({ caller, action });
31
+
32
+ log(`Created authorization witness for action ${functionName} on contract ${contractAddress} for caller ${caller}`);
33
+
34
+ return witness;
35
+ }
@@ -0,0 +1,113 @@
1
+ import { type AccountWalletWithSecretKey, ContractDeployer, type DeployMethod, Fr, type PXE } from '@aztec/aztec.js';
2
+ import { GITHUB_TAG_PREFIX, encodeArgs, getContractArtifact } from '@aztec/cli/utils';
3
+ import type { LogFn, Logger } from '@aztec/foundation/log';
4
+ import { getInitializer } from '@aztec/stdlib/abi';
5
+ import { PublicKeys } from '@aztec/stdlib/keys';
6
+
7
+ import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
8
+
9
+ export async function deploy(
10
+ client: PXE,
11
+ wallet: AccountWalletWithSecretKey,
12
+ artifactPath: string,
13
+ json: boolean,
14
+ publicKeys: PublicKeys | undefined,
15
+ rawArgs: any[],
16
+ salt: Fr | undefined,
17
+ initializer: string | undefined,
18
+ skipPublicDeployment: boolean,
19
+ skipClassRegistration: boolean,
20
+ skipInitialization: boolean | undefined,
21
+ universalDeploy: boolean | undefined,
22
+ wait: boolean,
23
+ feeOpts: IFeeOpts,
24
+ debugLogger: Logger,
25
+ log: LogFn,
26
+ logJson: (output: any) => void,
27
+ ) {
28
+ salt ??= Fr.random();
29
+ const contractArtifact = await getContractArtifact(artifactPath, log);
30
+ const constructorArtifact = getInitializer(contractArtifact, initializer);
31
+
32
+ const nodeInfo = await client.getNodeInfo();
33
+ const expectedAztecNrVersion = `${GITHUB_TAG_PREFIX}-v${nodeInfo.nodeVersion}`;
34
+ if (contractArtifact.aztecNrVersion && contractArtifact.aztecNrVersion !== expectedAztecNrVersion) {
35
+ log(
36
+ `\nWarning: Contract was compiled with a different version of Aztec.nr: ${contractArtifact.aztecNrVersion}. Consider updating Aztec.nr to ${expectedAztecNrVersion}\n`,
37
+ );
38
+ }
39
+
40
+ const deployer = new ContractDeployer(contractArtifact, wallet, publicKeys ?? PublicKeys.default(), initializer);
41
+
42
+ let args = [];
43
+ if (rawArgs.length > 0) {
44
+ if (!constructorArtifact) {
45
+ throw new Error(`Cannot process constructor arguments as no constructor was found`);
46
+ }
47
+ debugLogger.debug(`Input arguments: ${rawArgs.map((x: any) => `"${x}"`).join(', ')}`);
48
+ args = encodeArgs(rawArgs, constructorArtifact!.parameters);
49
+ debugLogger.debug(`Encoded arguments: ${args.join(', ')}`);
50
+ }
51
+
52
+ const deploy = deployer.deploy(...args);
53
+ const deployOpts: Parameters<DeployMethod['send']>[0] = {
54
+ ...(await feeOpts.toSendOpts(wallet)),
55
+ contractAddressSalt: salt,
56
+ universalDeploy,
57
+ skipClassRegistration,
58
+ skipInitialization,
59
+ skipPublicDeployment,
60
+ };
61
+
62
+ if (feeOpts.estimateOnly) {
63
+ const gas = await deploy.estimateGas(deployOpts);
64
+ printGasEstimates(feeOpts, gas, log);
65
+ return;
66
+ }
67
+
68
+ const tx = deploy.send(deployOpts);
69
+
70
+ const txHash = await tx.getTxHash();
71
+ debugLogger.debug(`Deploy tx sent with hash ${txHash}`);
72
+ if (wait) {
73
+ const deployed = await tx.wait();
74
+ const { address, partialAddress, instance } = deployed.contract;
75
+ if (json) {
76
+ logJson({
77
+ address: address.toString(),
78
+ partialAddress: (await partialAddress).toString(),
79
+ initializationHash: instance.initializationHash.toString(),
80
+ salt: salt.toString(),
81
+ transactionFee: deployed.transactionFee?.toString(),
82
+ });
83
+ } else {
84
+ log(`Contract deployed at ${address.toString()}`);
85
+ log(`Contract partial address ${(await partialAddress).toString()}`);
86
+ log(`Contract init hash ${instance.initializationHash.toString()}`);
87
+ log(`Deployment tx hash: ${txHash.toString()}`);
88
+ log(`Deployment salt: ${salt.toString()}`);
89
+ log(`Deployment fee: ${deployed.transactionFee}`);
90
+ }
91
+ } else {
92
+ const { address, partialAddress } = deploy;
93
+ const instance = await deploy.getInstance();
94
+ if (json) {
95
+ logJson({
96
+ address: address?.toString() ?? 'N/A',
97
+ partialAddress: (await partialAddress)?.toString() ?? 'N/A',
98
+ txHash: txHash.toString(),
99
+ initializationHash: instance.initializationHash.toString(),
100
+ salt: salt.toString(),
101
+ deployer: instance.deployer.toString(),
102
+ });
103
+ } else {
104
+ log(`Contract deployed at ${address?.toString()}`);
105
+ log(`Contract partial address ${(await partialAddress)?.toString()}`);
106
+ log(`Contract init hash ${instance.initializationHash.toString()}`);
107
+ log(`Deployment tx hash: ${txHash.toString()}`);
108
+ log(`Deployment salt: ${salt.toString()}`);
109
+ log(`Deployer: ${instance.deployer.toString()}`);
110
+ }
111
+ }
112
+ return deploy.address;
113
+ }
@@ -0,0 +1,92 @@
1
+ import type { AccountManager, DeployAccountOptions } from '@aztec/aztec.js';
2
+ import { prettyPrintJSON } from '@aztec/cli/cli-utils';
3
+ import type { LogFn, Logger } from '@aztec/foundation/log';
4
+
5
+ import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
6
+
7
+ export async function deployAccount(
8
+ account: AccountManager,
9
+ wait: boolean,
10
+ feeOpts: IFeeOpts,
11
+ json: boolean,
12
+ debugLogger: Logger,
13
+ log: LogFn,
14
+ ) {
15
+ const out: Record<string, any> = {};
16
+ const { address, partialAddress, publicKeys } = await account.getCompleteAddress();
17
+ const { initializationHash, deployer, salt } = account.getInstance();
18
+ const wallet = await account.getWallet();
19
+ const secretKey = wallet.getSecretKey();
20
+
21
+ if (json) {
22
+ out.address = address;
23
+ out.partialAddress = partialAddress;
24
+ out.salt = salt;
25
+ out.initHash = initializationHash;
26
+ out.deployer = deployer;
27
+ } else {
28
+ log(`\nNew account:\n`);
29
+ log(`Address: ${address.toString()}`);
30
+ log(`Public key: ${publicKeys.toString()}`);
31
+ if (secretKey) {
32
+ log(`Secret key: ${secretKey.toString()}`);
33
+ }
34
+ log(`Partial address: ${partialAddress.toString()}`);
35
+ log(`Salt: ${salt.toString()}`);
36
+ log(`Init hash: ${initializationHash.toString()}`);
37
+ log(`Deployer: ${deployer.toString()}`);
38
+ }
39
+
40
+ let tx;
41
+ let txReceipt;
42
+
43
+ const deployOpts: DeployAccountOptions = {
44
+ ...(await feeOpts.toDeployAccountOpts(wallet)),
45
+ skipInitialization: false,
46
+ };
47
+ if (feeOpts.estimateOnly) {
48
+ const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
49
+ if (json) {
50
+ out.fee = {
51
+ gasLimits: {
52
+ da: gas.gasLimits.daGas,
53
+ l2: gas.gasLimits.l2Gas,
54
+ },
55
+ teardownGasLimits: {
56
+ da: gas.teardownGasLimits.daGas,
57
+ l2: gas.teardownGasLimits,
58
+ },
59
+ };
60
+ } else {
61
+ printGasEstimates(feeOpts, gas, log);
62
+ }
63
+ } else {
64
+ tx = account.deploy(deployOpts);
65
+ const txHash = await tx.getTxHash();
66
+ debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
67
+ out.txHash = txHash;
68
+ if (wait) {
69
+ if (!json) {
70
+ log(`\nWaiting for account contract deployment...`);
71
+ }
72
+ txReceipt = await tx.wait();
73
+ out.txReceipt = {
74
+ status: txReceipt.status,
75
+ transactionFee: txReceipt.transactionFee,
76
+ };
77
+ }
78
+ }
79
+
80
+ if (json) {
81
+ log(prettyPrintJSON(out));
82
+ } else {
83
+ if (tx) {
84
+ log(`Deploy tx hash: ${await tx.getTxHash()}`);
85
+ }
86
+ if (txReceipt) {
87
+ log(`Deploy tx fee: ${txReceipt.transactionFee}`);
88
+ }
89
+ }
90
+
91
+ return { address, secretKey, salt };
92
+ }
@@ -0,0 +1,47 @@
1
+ import { getSchnorrAccount } from '@aztec/accounts/schnorr';
2
+ import { getInitialTestAccounts } from '@aztec/accounts/testing';
3
+ import { Fr, type PXE } from '@aztec/aztec.js';
4
+ import { prettyPrintJSON } from '@aztec/cli/cli-utils';
5
+ import type { LogFn } from '@aztec/foundation/log';
6
+
7
+ import type { WalletDB } from '../storage/wallet_db.js';
8
+
9
+ export async function importTestAccounts(client: PXE, db: WalletDB, json: boolean, log: LogFn) {
10
+ const testAccounts = await getInitialTestAccounts();
11
+ const accounts = await Promise.all(
12
+ testAccounts.map(({ secret, signingKey, salt }) => getSchnorrAccount(client, secret, signingKey, salt)),
13
+ );
14
+
15
+ const out: Record<string, any> = {};
16
+ await Promise.all(
17
+ accounts.map(async (account, i) => {
18
+ const alias = `test${i}`;
19
+ const secret = testAccounts[i].secret;
20
+ const salt = new Fr(account.salt);
21
+ const address = account.getAddress();
22
+ await account.register();
23
+ await db.storeAccount(address, { type: 'schnorr', secretKey: secret, salt, alias, publicKey: undefined }, log);
24
+
25
+ if (json) {
26
+ out[alias] = {
27
+ alias,
28
+ address,
29
+ secret,
30
+ salt,
31
+ };
32
+ } else {
33
+ log(`\nTest account:`);
34
+ log(`Alias: ${alias}`);
35
+ log(`Address: ${address}`);
36
+ log(`Secret key: ${secret}`);
37
+ log(`Salt: ${salt}`);
38
+ }
39
+ }),
40
+ );
41
+
42
+ if (json) {
43
+ log(prettyPrintJSON(out));
44
+ } else {
45
+ log(`\n${testAccounts.length} test accounts imported to wallet db.\n`);
46
+ }
47
+ }