@aztec/cli-wallet 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.
- package/README.md +2 -0
- package/dest/bin/index.js +75 -0
- package/dest/cmds/add_authwit.js +4 -0
- package/dest/cmds/add_note.js +14 -0
- package/dest/cmds/authorize_action.js +17 -0
- package/dest/cmds/bridge_fee_juice.js +52 -0
- package/dest/cmds/cancel_tx.js +38 -0
- package/dest/cmds/check_tx.js +11 -0
- package/dest/cmds/create_account.js +98 -0
- package/dest/cmds/create_authwit.js +16 -0
- package/dest/cmds/deploy.js +83 -0
- package/dest/cmds/deploy_account.js +84 -0
- package/dest/cmds/index.js +227 -0
- package/dest/cmds/register_contract.js +14 -0
- package/dest/cmds/register_sender.js +4 -0
- package/dest/cmds/send.js +49 -0
- package/dest/cmds/simulate.js +26 -0
- package/dest/storage/wallet_db.js +180 -0
- package/dest/utils/accounts.js +87 -0
- package/dest/utils/ecdsa.js +13 -0
- package/dest/utils/options/fees.js +189 -0
- package/dest/utils/options/index.js +2 -0
- package/dest/utils/options/options.js +122 -0
- package/dest/utils/pxe_wrapper.js +21 -0
- package/package.json +103 -0
- package/src/bin/index.ts +121 -0
- package/src/cmds/add_authwit.ts +13 -0
- package/src/cmds/add_note.ts +30 -0
- package/src/cmds/authorize_action.ts +36 -0
- package/src/cmds/bridge_fee_juice.ts +88 -0
- package/src/cmds/cancel_tx.ts +61 -0
- package/src/cmds/check_tx.ts +12 -0
- package/src/cmds/create_account.ts +120 -0
- package/src/cmds/create_authwit.ts +35 -0
- package/src/cmds/deploy.ts +113 -0
- package/src/cmds/deploy_account.ts +92 -0
- package/src/cmds/index.ts +674 -0
- package/src/cmds/register_contract.ts +20 -0
- package/src/cmds/register_sender.ts +7 -0
- package/src/cmds/send.ts +62 -0
- package/src/cmds/simulate.ts +42 -0
- package/src/storage/wallet_db.ts +205 -0
- package/src/utils/accounts.ts +102 -0
- package/src/utils/ecdsa.ts +15 -0
- package/src/utils/options/fees.ts +234 -0
- package/src/utils/options/index.ts +2 -0
- package/src/utils/options/options.ts +175 -0
- package/src/utils/pxe_wrapper.ts +26 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { AuthWitness } from '@aztec/circuit-types';
|
|
2
|
+
import { type AztecAddress } from '@aztec/circuits.js';
|
|
3
|
+
import { parseAztecAddress, parseSecretKey, parseTxHash } from '@aztec/cli/utils';
|
|
4
|
+
|
|
5
|
+
import { Option } from 'commander';
|
|
6
|
+
import { readdir, stat } from 'fs/promises';
|
|
7
|
+
|
|
8
|
+
import { type AliasType, type WalletDB } from '../../storage/wallet_db.js';
|
|
9
|
+
import { AccountTypes } from '../accounts.js';
|
|
10
|
+
|
|
11
|
+
const TARGET_DIR = 'target';
|
|
12
|
+
|
|
13
|
+
export const ARTIFACT_DESCRIPTION =
|
|
14
|
+
"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";
|
|
15
|
+
|
|
16
|
+
export function integerArgParser(
|
|
17
|
+
value: string,
|
|
18
|
+
argName: string,
|
|
19
|
+
min = Number.MIN_SAFE_INTEGER,
|
|
20
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
21
|
+
) {
|
|
22
|
+
const parsed = parseInt(value, 10);
|
|
23
|
+
if (parsed < min) {
|
|
24
|
+
throw new Error(`${argName} must be greater than ${min}`);
|
|
25
|
+
}
|
|
26
|
+
if (parsed > max) {
|
|
27
|
+
throw new Error(`${argName} must be less than ${max}`);
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function aliasedTxHashParser(txHash: string, db?: WalletDB) {
|
|
33
|
+
try {
|
|
34
|
+
return parseTxHash(txHash);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
const prefixed = txHash.includes(':') ? txHash : `transactions:${txHash}`;
|
|
37
|
+
const rawTxHash = db ? db.tryRetrieveAlias(prefixed) : txHash;
|
|
38
|
+
return parseTxHash(rawTxHash);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function aliasedAuthWitParser(witness: string, db?: WalletDB) {
|
|
43
|
+
try {
|
|
44
|
+
return AuthWitness.fromString(witness);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
const prefixed = witness.includes(':') ? witness : `authwits:${witness}`;
|
|
47
|
+
const rawAuthWitness = db ? db.tryRetrieveAlias(prefixed) : witness;
|
|
48
|
+
return AuthWitness.fromString(rawAuthWitness);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function aliasedAddressParser(defaultPrefix: AliasType, address: string, db?: WalletDB) {
|
|
53
|
+
if (address.startsWith('0x')) {
|
|
54
|
+
return parseAztecAddress(address);
|
|
55
|
+
} else {
|
|
56
|
+
const prefixed = address.includes(':') ? address : `${defaultPrefix}:${address}`;
|
|
57
|
+
const rawAddress = db ? db.tryRetrieveAlias(prefixed) : address;
|
|
58
|
+
return parseAztecAddress(rawAddress);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function aliasedSecretKeyParser(sk: string, db?: WalletDB) {
|
|
63
|
+
if (sk.startsWith('0x')) {
|
|
64
|
+
return parseSecretKey(sk);
|
|
65
|
+
} else {
|
|
66
|
+
const prefixed = `${sk.startsWith('accounts') ? '' : 'accounts'}:${sk.endsWith(':sk') ? sk : `${sk}:sk`}`;
|
|
67
|
+
const rawSk = db ? db.tryRetrieveAlias(prefixed) : sk;
|
|
68
|
+
return parseSecretKey(rawSk);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createAliasOption(description: string, hide: boolean) {
|
|
73
|
+
return new Option(`-a, --alias <string>`, description).hideHelp(hide);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function createAccountOption(description: string, hide: boolean, db?: WalletDB) {
|
|
77
|
+
return new Option(`-f, --from <string>`, description)
|
|
78
|
+
.hideHelp(hide)
|
|
79
|
+
.argParser(address => aliasedAddressParser('accounts', address, db));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createTypeOption(mandatory: boolean) {
|
|
83
|
+
return new Option('-t, --type <string>', 'Type of account to create')
|
|
84
|
+
.choices(AccountTypes)
|
|
85
|
+
.default('schnorr')
|
|
86
|
+
.conflicts('account-or-address')
|
|
87
|
+
.makeOptionMandatory(mandatory);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createArgsOption(isConstructor: boolean, db?: WalletDB) {
|
|
91
|
+
return new Option('--args [args...]', `${isConstructor ? 'Constructor' : 'Function'} arguments`)
|
|
92
|
+
.argParser((arg, prev: string[]) => {
|
|
93
|
+
const next = db?.tryRetrieveAlias(arg) || arg;
|
|
94
|
+
prev.push(next);
|
|
95
|
+
return prev;
|
|
96
|
+
})
|
|
97
|
+
.default([]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function createContractAddressOption(db?: WalletDB) {
|
|
101
|
+
return new Option('-ca, --contract-address <address>', 'Aztec address of the contract.')
|
|
102
|
+
.argParser(address => aliasedAddressParser('contracts', address, db))
|
|
103
|
+
.makeOptionMandatory(true);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function artifactPathParser(filePath: string, db?: WalletDB) {
|
|
107
|
+
if (filePath.includes('@')) {
|
|
108
|
+
const [pkg, contractName] = filePath.split('@');
|
|
109
|
+
return contractArtifactFromWorkspace(pkg, contractName);
|
|
110
|
+
} else if (!new RegExp(/^(\.|\/|[A-Z]:).*\.json$/).test(filePath)) {
|
|
111
|
+
filePath = db ? db.tryRetrieveAlias(`artifacts:${filePath}`) : filePath;
|
|
112
|
+
}
|
|
113
|
+
if (!filePath) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
'This command has to be called from a nargo workspace or contract artifact path should be provided',
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return Promise.resolve(filePath);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function artifactPathFromPromiseOrAlias(
|
|
122
|
+
artifactPathPromise: Promise<string>,
|
|
123
|
+
contractAddress: AztecAddress,
|
|
124
|
+
db?: WalletDB,
|
|
125
|
+
) {
|
|
126
|
+
let artifactPath = await artifactPathPromise;
|
|
127
|
+
|
|
128
|
+
if (db && !artifactPath) {
|
|
129
|
+
artifactPath = db.tryRetrieveAlias(`artifacts:${contractAddress.toString()}`);
|
|
130
|
+
if (!artifactPath) {
|
|
131
|
+
throw new Error(`No artifact found for contract address ${contractAddress}, please provide it via the -c option`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return artifactPath;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function createArtifactOption(db?: WalletDB) {
|
|
138
|
+
return new Option('-c, --contract-artifact <fileLocation>', ARTIFACT_DESCRIPTION)
|
|
139
|
+
.argParser(filePath => artifactPathParser(filePath, db))
|
|
140
|
+
.makeOptionMandatory(false);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function createProfileOption() {
|
|
144
|
+
return new Option(
|
|
145
|
+
'-p, --profile',
|
|
146
|
+
'Run the real prover and get the gate count for each function in the transaction.',
|
|
147
|
+
).default(false);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function contractArtifactFromWorkspace(pkg?: string, contractName?: string) {
|
|
151
|
+
const cwd = process.cwd();
|
|
152
|
+
try {
|
|
153
|
+
await stat(`${cwd}/Nargo.toml`);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
'Invalid contract artifact argument provided. To use this option, command should be called from a nargo workspace',
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const filesInTarget = await readdir(`${cwd}/${TARGET_DIR}`);
|
|
160
|
+
const bestMatch = filesInTarget.filter(file => {
|
|
161
|
+
if (pkg && contractName) {
|
|
162
|
+
return file === `${pkg}-${contractName}.json`;
|
|
163
|
+
} else {
|
|
164
|
+
return file.endsWith('.json') && (file.includes(pkg || '') || file.includes(contractName || ''));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if (bestMatch.length === 0) {
|
|
168
|
+
throw new Error('No contract artifacts found in target directory with the specified criteria');
|
|
169
|
+
} else if (bestMatch.length > 1) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Multiple contract artifacts found in target directory with the specified criteria ${bestMatch.join(', ')}`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return `${cwd}/${TARGET_DIR}/${bestMatch[0]}`;
|
|
175
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type AztecNode, type PXE, createAztecNodeClient } from '@aztec/circuit-types';
|
|
2
|
+
import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Wrapper class for PXE service, avoids initialization issues due to
|
|
6
|
+
* closures when providing PXE service to injected commander.js commands
|
|
7
|
+
*/
|
|
8
|
+
export class PXEWrapper {
|
|
9
|
+
private static pxe: PXE | undefined;
|
|
10
|
+
private static node: AztecNode | undefined;
|
|
11
|
+
|
|
12
|
+
getPXE(): PXE | undefined {
|
|
13
|
+
return PXEWrapper.pxe;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getNode(): AztecNode | undefined {
|
|
17
|
+
return PXEWrapper.node;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async init(nodeUrl: string, dataDir: string, overridePXEServiceConfig?: Partial<PXEServiceConfig>) {
|
|
21
|
+
PXEWrapper.node = createAztecNodeClient(nodeUrl);
|
|
22
|
+
const pxeConfig = Object.assign(getPXEServiceConfig(), overridePXEServiceConfig);
|
|
23
|
+
pxeConfig.dataDirectory = dataDir;
|
|
24
|
+
PXEWrapper.pxe = await createPXEService(PXEWrapper.node, pxeConfig);
|
|
25
|
+
}
|
|
26
|
+
}
|