@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 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/options/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './fees.js';
2
+ export * from './options.js';
@@ -0,0 +1,20 @@
1
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { Option } from 'commander';
4
+ import type { AliasType, WalletDB } from '../../storage/wallet_db.js';
5
+ export declare const ARTIFACT_DESCRIPTION = "Path to a compiled Aztec contract's artifact in JSON format. If executed inside a nargo workspace, a package and contract name can be specified as package@contract";
6
+ export declare function integerArgParser(value: string, argName: string, min?: number, max?: number): number;
7
+ export declare function aliasedTxHashParser(txHash: string, db?: WalletDB): import("@aztec/aztec.js").TxHash;
8
+ export declare function aliasedAuthWitParser(witness: string, db?: WalletDB): AuthWitness;
9
+ export declare function aliasedAddressParser(defaultPrefix: AliasType, address: string, db?: WalletDB): AztecAddress;
10
+ export declare function aliasedSecretKeyParser(sk: string, db?: WalletDB): import("@aztec/aztec.js").Fr;
11
+ export declare function createAliasOption(description: string, hide: boolean): Option;
12
+ export declare function createAccountOption(description: string, hide: boolean, db?: WalletDB): Option;
13
+ export declare function createTypeOption(mandatory: boolean): Option;
14
+ export declare function createArgsOption(isConstructor: boolean, db?: WalletDB): Option;
15
+ export declare function createContractAddressOption(db?: WalletDB): Option;
16
+ export declare function artifactPathParser(filePath: string, db?: WalletDB): Promise<string>;
17
+ export declare function artifactPathFromPromiseOrAlias(artifactPathPromise: Promise<string>, contractAddress: AztecAddress, db?: WalletDB): Promise<string>;
18
+ export declare function createArtifactOption(db?: WalletDB): Option;
19
+ export declare function createProfileOption(): Option;
20
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/utils/options/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAKtE,eAAO,MAAM,oBAAoB,wKACsI,CAAC;AAExK,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,GAAG,SAA0B,EAC7B,GAAG,SAA0B,UAU9B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,oCAQhE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,eAQlE;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,gBAQ5F;AAED,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,gCAQ/D;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,UAEnE;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,QAAQ,UAIpF;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,UAMlD;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,QAAQ,UAQrE;AAED,wBAAgB,2BAA2B,CAAC,EAAE,CAAC,EAAE,QAAQ,UAIxD;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,mBAajE;AAED,wBAAsB,8BAA8B,CAClD,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,EACpC,eAAe,EAAE,YAAY,EAC7B,EAAE,CAAC,EAAE,QAAQ,mBAWd;AAED,wBAAgB,oBAAoB,CAAC,EAAE,CAAC,EAAE,QAAQ,UAIjD;AAED,wBAAgB,mBAAmB,WAKlC"}
@@ -0,0 +1,122 @@
1
+ import { parseAztecAddress, parseSecretKey, parseTxHash } from '@aztec/cli/utils';
2
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
3
+ import { Option } from 'commander';
4
+ import { readdir, stat } from 'fs/promises';
5
+ import { AccountTypes } from '../accounts.js';
6
+ const TARGET_DIR = 'target';
7
+ export const ARTIFACT_DESCRIPTION = "Path to a compiled Aztec contract's artifact in JSON format. If executed inside a nargo workspace, a package and contract name can be specified as package@contract";
8
+ export function integerArgParser(value, argName, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
9
+ const parsed = parseInt(value, 10);
10
+ if (parsed < min) {
11
+ throw new Error(`${argName} must be greater than ${min}`);
12
+ }
13
+ if (parsed > max) {
14
+ throw new Error(`${argName} must be less than ${max}`);
15
+ }
16
+ return parsed;
17
+ }
18
+ export function aliasedTxHashParser(txHash, db) {
19
+ try {
20
+ return parseTxHash(txHash);
21
+ } catch (err) {
22
+ const prefixed = txHash.includes(':') ? txHash : `transactions:${txHash}`;
23
+ const rawTxHash = db ? db.tryRetrieveAlias(prefixed) : txHash;
24
+ return parseTxHash(rawTxHash);
25
+ }
26
+ }
27
+ export function aliasedAuthWitParser(witness, db) {
28
+ try {
29
+ return AuthWitness.fromString(witness);
30
+ } catch (err) {
31
+ const prefixed = witness.includes(':') ? witness : `authwits:${witness}`;
32
+ const rawAuthWitness = db ? db.tryRetrieveAlias(prefixed) : witness;
33
+ return AuthWitness.fromString(rawAuthWitness);
34
+ }
35
+ }
36
+ export function aliasedAddressParser(defaultPrefix, address, db) {
37
+ if (address.startsWith('0x')) {
38
+ return parseAztecAddress(address);
39
+ } else {
40
+ const prefixed = address.includes(':') ? address : `${defaultPrefix}:${address}`;
41
+ const rawAddress = db ? db.tryRetrieveAlias(prefixed) : address;
42
+ return parseAztecAddress(rawAddress);
43
+ }
44
+ }
45
+ export function aliasedSecretKeyParser(sk, db) {
46
+ if (sk.startsWith('0x')) {
47
+ return parseSecretKey(sk);
48
+ } else {
49
+ const prefixed = `${sk.startsWith('accounts') ? '' : 'accounts'}:${sk.endsWith(':sk') ? sk : `${sk}:sk`}`;
50
+ const rawSk = db ? db.tryRetrieveAlias(prefixed) : sk;
51
+ return parseSecretKey(rawSk);
52
+ }
53
+ }
54
+ export function createAliasOption(description, hide) {
55
+ return new Option(`-a, --alias <string>`, description).hideHelp(hide);
56
+ }
57
+ export function createAccountOption(description, hide, db) {
58
+ return new Option(`-f, --from <string>`, description).hideHelp(hide).argParser((address)=>aliasedAddressParser('accounts', address, db));
59
+ }
60
+ export function createTypeOption(mandatory) {
61
+ return new Option('-t, --type <string>', 'Type of account to create').choices(AccountTypes).default('schnorr').conflicts('account-or-address').makeOptionMandatory(mandatory);
62
+ }
63
+ export function createArgsOption(isConstructor, db) {
64
+ return new Option('--args [args...]', `${isConstructor ? 'Constructor' : 'Function'} arguments`).argParser((arg, prev)=>{
65
+ const next = db?.tryRetrieveAlias(arg) || arg;
66
+ prev.push(next);
67
+ return prev;
68
+ }).default([]);
69
+ }
70
+ export function createContractAddressOption(db) {
71
+ return new Option('-ca, --contract-address <address>', 'Aztec address of the contract.').argParser((address)=>aliasedAddressParser('contracts', address, db)).makeOptionMandatory(true);
72
+ }
73
+ export function artifactPathParser(filePath, db) {
74
+ if (filePath.includes('@')) {
75
+ const [pkg, contractName] = filePath.split('@');
76
+ return contractArtifactFromWorkspace(pkg, contractName);
77
+ } else if (!new RegExp(/^(\.|\/|[A-Z]:).*\.json$/).test(filePath)) {
78
+ filePath = db ? db.tryRetrieveAlias(`artifacts:${filePath}`) : filePath;
79
+ }
80
+ if (!filePath) {
81
+ throw new Error('This command has to be called from a nargo workspace or contract artifact path should be provided');
82
+ }
83
+ return Promise.resolve(filePath);
84
+ }
85
+ export async function artifactPathFromPromiseOrAlias(artifactPathPromise, contractAddress, db) {
86
+ let artifactPath = await artifactPathPromise;
87
+ if (db && !artifactPath) {
88
+ artifactPath = db.tryRetrieveAlias(`artifacts:${contractAddress.toString()}`);
89
+ if (!artifactPath) {
90
+ throw new Error(`No artifact found for contract address ${contractAddress}, please provide it via the -c option`);
91
+ }
92
+ }
93
+ return artifactPath;
94
+ }
95
+ export function createArtifactOption(db) {
96
+ return new Option('-c, --contract-artifact <fileLocation>', ARTIFACT_DESCRIPTION).argParser((filePath)=>artifactPathParser(filePath, db)).makeOptionMandatory(false);
97
+ }
98
+ export function createProfileOption() {
99
+ return new Option('-p, --profile', 'Run the real prover and get the gate count for each function in the transaction.').default(false);
100
+ }
101
+ async function contractArtifactFromWorkspace(pkg, contractName) {
102
+ const cwd = process.cwd();
103
+ try {
104
+ await stat(`${cwd}/Nargo.toml`);
105
+ } catch (e) {
106
+ throw new Error('Invalid contract artifact argument provided. To use this option, command should be called from a nargo workspace');
107
+ }
108
+ const filesInTarget = await readdir(`${cwd}/${TARGET_DIR}`);
109
+ const bestMatch = filesInTarget.filter((file)=>{
110
+ if (pkg && contractName) {
111
+ return file === `${pkg}-${contractName}.json`;
112
+ } else {
113
+ return file.endsWith('.json') && (file.includes(pkg || '') || file.includes(contractName || ''));
114
+ }
115
+ });
116
+ if (bestMatch.length === 0) {
117
+ throw new Error('No contract artifacts found in target directory with the specified criteria');
118
+ } else if (bestMatch.length > 1) {
119
+ throw new Error(`Multiple contract artifacts found in target directory with the specified criteria ${bestMatch.join(', ')}`);
120
+ }
121
+ return `${cwd}/${TARGET_DIR}/${bestMatch[0]}`;
122
+ }
@@ -0,0 +1,10 @@
1
+ import { type PXEServiceConfig } from '@aztec/pxe/server';
2
+ import { type AztecNode, type PXE } from '@aztec/stdlib/interfaces/client';
3
+ export declare class PXEWrapper {
4
+ private static pxe;
5
+ private static node;
6
+ getPXE(): PXE | undefined;
7
+ getNode(): AztecNode | undefined;
8
+ init(nodeUrl: string, dataDir: string, overridePXEServiceConfig?: Partial<PXEServiceConfig>): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=pxe_wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pxe_wrapper.d.ts","sourceRoot":"","sources":["../../src/utils/pxe_wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAyC,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAyB,MAAM,iCAAiC,CAAC;AAMlG,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAkB;IACpC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAwB;IAE3C,MAAM,IAAI,GAAG,GAAG,SAAS;IAIzB,OAAO,IAAI,SAAS,GAAG,SAAS;IAI1B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,wBAAwB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;CAMlG"}
@@ -0,0 +1,21 @@
1
+ import { createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
2
+ import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
3
+ /*
4
+ * Wrapper class for PXE service, avoids initialization issues due to
5
+ * closures when providing PXE service to injected commander.js commands
6
+ */ export class PXEWrapper {
7
+ static pxe;
8
+ static node;
9
+ getPXE() {
10
+ return PXEWrapper.pxe;
11
+ }
12
+ getNode() {
13
+ return PXEWrapper.node;
14
+ }
15
+ async init(nodeUrl, dataDir, overridePXEServiceConfig) {
16
+ PXEWrapper.node = createAztecNodeClient(nodeUrl);
17
+ const pxeConfig = Object.assign(getPXEServiceConfig(), overridePXEServiceConfig);
18
+ pxeConfig.dataDirectory = dataDir;
19
+ PXEWrapper.pxe = await createPXEService(PXEWrapper.node, pxeConfig);
20
+ }
21
+ }
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "@aztec/cli-wallet",
3
+ "version": "0.0.0-test.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./dest/cmds/index.js",
7
+ "./cli": "./dest/bin/index.js"
8
+ },
9
+ "typedocOptions": {
10
+ "entryPoints": [
11
+ "./src/cmds/index.ts"
12
+ ],
13
+ "name": "Aztec CLI wallet",
14
+ "tsconfig": "./tsconfig.json"
15
+ },
16
+ "bin": {
17
+ "aztec-wallet": "./dest/bin/index.js"
18
+ },
19
+ "scripts": {
20
+ "start": "node --no-warnings ./dest/bin",
21
+ "start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin",
22
+ "dev": "LOG_LEVEL=debug && node ./dest/bin",
23
+ "build": "yarn clean && tsc -b",
24
+ "build:dev": "tsc -b --watch",
25
+ "clean": "rm -rf ./dest .tsbuildinfo",
26
+ "formatting": "run -T prettier --check ./src && run -T eslint ./src",
27
+ "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
28
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
29
+ },
30
+ "inherits": [
31
+ "../package.common.json"
32
+ ],
33
+ "jest": {
34
+ "preset": "ts-jest/presets/default-esm",
35
+ "moduleNameMapper": {
36
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
37
+ },
38
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
39
+ "rootDir": "./src",
40
+ "extensionsToTreatAsEsm": [
41
+ ".ts"
42
+ ],
43
+ "transform": {
44
+ "^.+\\.tsx?$": [
45
+ "@swc/jest",
46
+ {
47
+ "jsc": {
48
+ "parser": {
49
+ "syntax": "typescript",
50
+ "decorators": true
51
+ },
52
+ "transform": {
53
+ "decoratorVersion": "2022-03"
54
+ }
55
+ }
56
+ }
57
+ ]
58
+ },
59
+ "reporters": [
60
+ "default"
61
+ ],
62
+ "testTimeout": 120000,
63
+ "setupFiles": [
64
+ "../../foundation/src/jest/setup.mjs"
65
+ ]
66
+ },
67
+ "dependencies": {
68
+ "@aztec/accounts": "0.0.0-test.0",
69
+ "@aztec/aztec.js": "0.0.0-test.0",
70
+ "@aztec/cli": "0.0.0-test.0",
71
+ "@aztec/ethereum": "0.0.0-test.0",
72
+ "@aztec/foundation": "0.0.0-test.0",
73
+ "@aztec/kv-store": "0.0.0-test.0",
74
+ "@aztec/noir-contracts.js": "0.0.0-test.0",
75
+ "@aztec/pxe": "0.0.0-test.0",
76
+ "@aztec/stdlib": "0.0.0-test.0",
77
+ "commander": "^12.1.0",
78
+ "inquirer": "^10.1.8",
79
+ "source-map-support": "^0.5.21",
80
+ "tslib": "^2.4.0"
81
+ },
82
+ "devDependencies": {
83
+ "@jest/globals": "^29.5.0",
84
+ "@types/jest": "^29.5.0",
85
+ "@types/node": "^18.7.23",
86
+ "@types/source-map-support": "^0.5.10",
87
+ "jest": "^29.5.0",
88
+ "jest-mock-extended": "^3.0.5",
89
+ "ts-jest": "^29.1.0",
90
+ "ts-node": "^10.9.1",
91
+ "typescript": "^5.0.4"
92
+ },
93
+ "files": [
94
+ "dest",
95
+ "src",
96
+ "!*.test.*"
97
+ ],
98
+ "types": "./dest/index.d.ts",
99
+ "engines": {
100
+ "node": ">=18"
101
+ }
102
+ }
@@ -0,0 +1,127 @@
1
+ import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js';
2
+ import { LOCALHOST } from '@aztec/cli/cli-utils';
3
+ import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
4
+ import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
5
+ import type { PXEServiceConfig } from '@aztec/pxe/config';
6
+
7
+ import { Argument, Command, Option } from 'commander';
8
+ import { mkdirSync, readFileSync } from 'fs';
9
+ import { homedir } from 'os';
10
+ import { dirname, join, resolve } from 'path';
11
+
12
+ import { injectCommands } from '../cmds/index.js';
13
+ import { Aliases, WalletDB } from '../storage/wallet_db.js';
14
+ import { createAliasOption } from '../utils/options/index.js';
15
+ import { PXEWrapper } from '../utils/pxe_wrapper.js';
16
+
17
+ const userLog = createConsoleLogger();
18
+ const debugLogger = createLogger('wallet');
19
+
20
+ const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet'), PXE_PROVER = 'none' } = process.env;
21
+
22
+ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
23
+ program
24
+ .command('alias')
25
+ .description('Aliases information for easy reference.')
26
+ .addArgument(new Argument('<type>', 'Type of alias to create').choices(Aliases))
27
+ .argument('<key>', 'Key to alias.')
28
+ .argument('<value>', 'Value to assign to the alias.')
29
+ .action(async (type, key, value) => {
30
+ value = db.tryRetrieveAlias(value) || value;
31
+ await db.storeAlias(type, key, value, log);
32
+ });
33
+
34
+ program
35
+ .command('get-alias')
36
+ .description('Shows stored aliases')
37
+ .addArgument(new Argument('[alias]', 'Alias to retrieve'))
38
+ .action(async alias => {
39
+ if (alias?.includes(':')) {
40
+ const value = await db.retrieveAlias(alias);
41
+ log(value);
42
+ } else {
43
+ const aliases = await db.listAliases(alias);
44
+ for (const { key, value } of aliases) {
45
+ log(`${key} -> ${value}`);
46
+ }
47
+ }
48
+ });
49
+
50
+ program
51
+ .command('create-secret')
52
+ .description('Creates an aliased secret to use in other commands')
53
+ .addOption(createAliasOption('Key to alias the secret with', false).makeOptionMandatory(true))
54
+ .action(async (_options, command) => {
55
+ const options = command.optsWithGlobals();
56
+ const { alias } = options;
57
+ const value = Fr.random();
58
+ const hash = computeSecretHash(value);
59
+
60
+ await db.storeAlias('secrets', alias, Buffer.from(value.toString()), log);
61
+ await db.storeAlias('secrets', `${alias}:hash`, Buffer.from(hash.toString()), log);
62
+ });
63
+
64
+ return program;
65
+ }
66
+
67
+ /** CLI wallet main entrypoint */
68
+ async function main() {
69
+ const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json');
70
+ const walletVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
71
+
72
+ const db = WalletDB.getInstance();
73
+ const pxeWrapper = new PXEWrapper();
74
+
75
+ const program = new Command('wallet');
76
+ program
77
+ .description('Aztec wallet')
78
+ .version(walletVersion)
79
+ .option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
80
+ .option('-p, --prover <string>', 'wasm|native|none', PXE_PROVER)
81
+ .addOption(
82
+ new Option('--remote-pxe', 'Connect to an external PXE RPC server, instead of the local one')
83
+ .env('REMOTE_PXE')
84
+ .default(false)
85
+ .conflicts('rpc-url'),
86
+ )
87
+ .addOption(
88
+ new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to')
89
+ .env('AZTEC_NODE_URL')
90
+ .default(`http://${LOCALHOST}:8080`),
91
+ )
92
+ .hook('preSubcommand', async command => {
93
+ const { dataDir, remotePxe, nodeUrl, prover } = command.optsWithGlobals();
94
+
95
+ if (!remotePxe) {
96
+ debugLogger.info('Using local PXE service');
97
+
98
+ const proverEnabled = prover !== 'none';
99
+
100
+ const bbBinaryPath =
101
+ prover === 'native'
102
+ ? resolve(dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/cpp/build/bin/bb')
103
+ : undefined;
104
+ const bbWorkingDirectory = dataDir + '/bb';
105
+ mkdirSync(bbWorkingDirectory, { recursive: true });
106
+
107
+ const overridePXEConfig: Partial<PXEServiceConfig> = {
108
+ proverEnabled,
109
+ bbBinaryPath: prover === 'native' ? bbBinaryPath : undefined,
110
+ bbWorkingDirectory: prover === 'native' ? bbWorkingDirectory : undefined,
111
+ };
112
+
113
+ await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
114
+ }
115
+ await db.init(await openStoreAt(dataDir));
116
+ });
117
+
118
+ injectCommands(program, userLog, debugLogger, db, pxeWrapper);
119
+ injectInternalCommands(program, userLog, db);
120
+ await program.parseAsync(process.argv);
121
+ }
122
+
123
+ main().catch(err => {
124
+ debugLogger.error(`Error in command execution`);
125
+ debugLogger.error(err + '\n' + err.stack);
126
+ process.exit(1);
127
+ });
@@ -0,0 +1,13 @@
1
+ import type { AccountWalletWithSecretKey, AuthWitness, AztecAddress } from '@aztec/aztec.js';
2
+ import type { LogFn } from '@aztec/foundation/log';
3
+
4
+ export async function addAuthwit(
5
+ wallet: AccountWalletWithSecretKey,
6
+ authwit: AuthWitness,
7
+ authorizer: AztecAddress,
8
+ log: LogFn,
9
+ ) {
10
+ await wallet.addAuthWitness(authwit);
11
+
12
+ log(`Added authorization witness from ${authorizer}`);
13
+ }
@@ -0,0 +1,36 @@
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 authorizeAction(
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 authorize private function. To allow a third party to call a private function, please create an authorization witness via the create-authwit command',
24
+ );
25
+ }
26
+
27
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
28
+ const action = contract.methods[functionName](...functionArgs);
29
+
30
+ const setAuthwitnessInteraction = await wallet.setPublicAuthWit({ caller, action }, true);
31
+ const witness = await setAuthwitnessInteraction.send().wait();
32
+
33
+ log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
34
+
35
+ return witness;
36
+ }
@@ -0,0 +1,88 @@
1
+ import { L1FeeJuicePortalManager, type PXE } from '@aztec/aztec.js';
2
+ import { prettyPrintJSON } from '@aztec/cli/utils';
3
+ import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ import type { LogFn, Logger } from '@aztec/foundation/log';
6
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+
8
+ export async function bridgeL1FeeJuice(
9
+ amount: bigint,
10
+ recipient: AztecAddress,
11
+ pxe: PXE,
12
+ l1RpcUrls: string[],
13
+ chainId: number,
14
+ privateKey: string | undefined,
15
+ mnemonic: string,
16
+ mint: boolean,
17
+ json: boolean,
18
+ wait: boolean,
19
+ interval = 60_000,
20
+ log: LogFn,
21
+ debugLogger: Logger,
22
+ ) {
23
+ // Prepare L1 client
24
+ const chain = createEthereumChain(l1RpcUrls, chainId);
25
+ const { publicClient, walletClient } = createL1Clients(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
26
+
27
+ const {
28
+ protocolContractAddresses: { feeJuice: feeJuiceAddress },
29
+ } = await pxe.getPXEInfo();
30
+
31
+ // Setup portal manager
32
+ const portal = await L1FeeJuicePortalManager.new(pxe, publicClient, walletClient, 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 pxe
70
+ .getL1ToL2MembershipWitness(feeJuiceAddress, Fr.fromHexString(messageHash), claimSecret)
71
+ .then(witness => resolve(witness))
72
+ .catch(err => reject(err));
73
+ }, delay);
74
+ });
75
+ };
76
+
77
+ let witness;
78
+
79
+ while (!witness) {
80
+ witness = await delayedCheck(interval);
81
+ if (!witness) {
82
+ log(`No L1 to L2 message found yet, checking again in ${interval / 1000}s`);
83
+ }
84
+ }
85
+ }
86
+
87
+ return [claimSecret, messageLeafIndex] as const;
88
+ }
@@ -0,0 +1,62 @@
1
+ import { type AccountWalletWithSecretKey, type FeePaymentMethod, SentTx, type TxHash, TxStatus } from '@aztec/aztec.js';
2
+ import type { FeeOptions } from '@aztec/aztec.js/entrypoint';
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import type { LogFn } from '@aztec/foundation/log';
5
+ import { GasFees, GasSettings } from '@aztec/stdlib/gas';
6
+
7
+ export async function cancelTx(
8
+ wallet: AccountWalletWithSecretKey,
9
+ {
10
+ txHash,
11
+ gasSettings: prevTxGasSettings,
12
+ nonce,
13
+ cancellable,
14
+ }: { txHash: TxHash; gasSettings: GasSettings; nonce: Fr; cancellable: boolean },
15
+ paymentMethod: FeePaymentMethod,
16
+ increasedFees: GasFees,
17
+ maxFeesPerGas: GasFees | undefined,
18
+ log: LogFn,
19
+ ) {
20
+ const receipt = await wallet.getTxReceipt(txHash);
21
+ if (receipt.status !== TxStatus.PENDING || !cancellable) {
22
+ log(`Transaction is in status ${receipt.status} and cannot be cancelled`);
23
+ return;
24
+ }
25
+
26
+ const maxPriorityFeesPerGas = new GasFees(
27
+ prevTxGasSettings.maxPriorityFeesPerGas.feePerDaGas.add(increasedFees.feePerDaGas),
28
+ prevTxGasSettings.maxPriorityFeesPerGas.feePerL2Gas.add(increasedFees.feePerL2Gas),
29
+ );
30
+
31
+ const fee: FeeOptions = {
32
+ paymentMethod,
33
+ gasSettings: GasSettings.from({
34
+ ...prevTxGasSettings,
35
+ maxPriorityFeesPerGas,
36
+ maxFeesPerGas: maxFeesPerGas ?? prevTxGasSettings.maxFeesPerGas,
37
+ }),
38
+ };
39
+
40
+ const txRequest = await wallet.createTxExecutionRequest({
41
+ calls: [],
42
+ fee,
43
+ nonce,
44
+ cancellable: true,
45
+ });
46
+ const txSimulationResult = await wallet.simulateTx(txRequest, true);
47
+ const txProvingResult = await wallet.proveTx(txRequest, txSimulationResult.privateExecutionResult);
48
+ const sentTx = new SentTx(wallet, wallet.sendTx(txProvingResult.toTx()));
49
+ try {
50
+ await sentTx.wait();
51
+
52
+ log('Transaction has been cancelled');
53
+
54
+ const cancelReceipt = await sentTx.getReceipt();
55
+ log(` Tx fee: ${cancelReceipt.transactionFee}`);
56
+ log(` Status: ${cancelReceipt.status}`);
57
+ log(` Block number: ${cancelReceipt.blockNumber}`);
58
+ log(` Block hash: ${cancelReceipt.blockHash?.toString()}`);
59
+ } catch (err: any) {
60
+ log(`Could not cancel transaction\n ${err.message}`);
61
+ }
62
+ }
@@ -0,0 +1,12 @@
1
+ import type { PXE, TxHash } from '@aztec/aztec.js';
2
+ import { inspectTx } from '@aztec/cli/inspect';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
+
5
+ export async function checkTx(client: PXE, txHash: TxHash, statusOnly: boolean, log: LogFn) {
6
+ if (statusOnly) {
7
+ const receipt = await client.getTxReceipt(txHash);
8
+ return receipt.status;
9
+ } else {
10
+ await inspectTx(client, txHash, log, { includeBlockInfo: true });
11
+ }
12
+ }