@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.017a351
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 +30 -0
- package/dest/bin/index.d.ts +2 -1
- package/dest/bin/index.js +58 -26
- package/dest/cmds/authorize_action.d.ts +4 -3
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +11 -5
- package/dest/cmds/bridge_fee_juice.d.ts +4 -4
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +10 -8
- package/dest/cmds/check_tx.d.ts +5 -3
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +174 -6
- package/dest/cmds/create_account.d.ts +10 -7
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +74 -38
- package/dest/cmds/create_authwit.d.ts +4 -3
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/create_authwit.js +6 -6
- package/dest/cmds/deploy.d.ts +8 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +108 -59
- package/dest/cmds/deploy_account.d.ts +7 -8
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +70 -36
- package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
- package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
- package/dest/cmds/get_fee_juice_balance.js +27 -0
- package/dest/cmds/import_test_accounts.d.ts +3 -3
- package/dest/cmds/import_test_accounts.d.ts.map +1 -1
- package/dest/cmds/import_test_accounts.js +6 -9
- package/dest/cmds/index.d.ts +3 -3
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +99 -115
- package/dest/cmds/profile.d.ts +8 -0
- package/dest/cmds/profile.d.ts.map +1 -0
- package/dest/cmds/profile.js +28 -0
- package/dest/cmds/register_contract.d.ts +7 -3
- package/dest/cmds/register_contract.d.ts.map +1 -1
- package/dest/cmds/register_contract.js +20 -7
- package/dest/cmds/register_sender.d.ts +4 -3
- package/dest/cmds/register_sender.d.ts.map +1 -1
- package/dest/cmds/send.d.ts +9 -9
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +54 -27
- package/dest/cmds/simulate.d.ts +7 -3
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +26 -20
- package/dest/storage/wallet_db.d.ts +12 -19
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +63 -55
- package/dest/utils/authorizations.d.ts +6 -0
- package/dest/utils/authorizations.d.ts.map +1 -0
- package/dest/utils/authorizations.js +28 -0
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
- package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
- package/dest/utils/constants.d.ts +4 -0
- package/dest/utils/constants.d.ts.map +1 -0
- package/dest/utils/constants.js +7 -0
- package/dest/utils/ecdsa.d.ts +1 -3
- package/dest/utils/ecdsa.d.ts.map +1 -1
- package/dest/utils/options/fees.d.ts +23 -28
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +112 -148
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +9 -5
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +26 -14
- package/dest/utils/profiling.d.ts +5 -0
- package/dest/utils/profiling.d.ts.map +1 -0
- package/dest/utils/profiling.js +68 -0
- package/dest/utils/wallet.d.ts +44 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +263 -0
- package/package.json +31 -23
- package/src/bin/index.ts +63 -33
- package/src/cmds/authorize_action.ts +16 -5
- package/src/cmds/bridge_fee_juice.ts +16 -12
- package/src/cmds/check_tx.ts +212 -5
- package/src/cmds/create_account.ts +89 -45
- package/src/cmds/create_authwit.ts +9 -5
- package/src/cmds/deploy.ts +115 -71
- package/src/cmds/deploy_account.ts +84 -36
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +312 -222
- package/src/cmds/profile.ts +48 -0
- package/src/cmds/register_contract.ts +28 -5
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +59 -25
- package/src/cmds/simulate.ts +37 -24
- package/src/storage/wallet_db.ts +67 -68
- package/src/utils/authorizations.ts +51 -0
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +169 -210
- package/src/utils/options/options.ts +41 -19
- package/src/utils/profiling.ts +172 -0
- package/src/utils/wallet.ts +330 -0
- package/dest/cmds/add_authwit.d.ts +0 -4
- package/dest/cmds/add_authwit.d.ts.map +0 -1
- package/dest/cmds/add_authwit.js +0 -4
- package/dest/cmds/cancel_tx.d.ts +0 -11
- package/dest/cmds/cancel_tx.d.ts.map +0 -1
- package/dest/cmds/cancel_tx.js +0 -38
- package/dest/utils/accounts.d.ts +0 -11
- package/dest/utils/accounts.d.ts.map +0 -1
- package/dest/utils/accounts.js +0 -87
- package/dest/utils/pxe_wrapper.d.ts +0 -10
- package/dest/utils/pxe_wrapper.d.ts.map +0 -1
- package/dest/utils/pxe_wrapper.js +0 -21
- package/src/cmds/add_authwit.ts +0 -13
- package/src/cmds/cancel_tx.ts +0 -62
- package/src/utils/accounts.ts +0 -102
- package/src/utils/pxe_wrapper.ts +0 -26
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { format } from 'util';
|
|
2
|
+
const FN_NAME_PADDING = 60;
|
|
3
|
+
const COLUMN_MIN_WIDTH = 13;
|
|
4
|
+
const COLUMN_MAX_WIDTH = 15;
|
|
5
|
+
const ORACLE_NAME_PADDING = 50;
|
|
6
|
+
export function printProfileResult(stats, log, printOracles = false, executionSteps) {
|
|
7
|
+
log(format('\nPer circuit breakdown:\n'));
|
|
8
|
+
log(format(' ', 'Function name'.padEnd(FN_NAME_PADDING), 'Time'.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), executionSteps ? 'Gates'.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH) : '', executionSteps ? 'Subtotal'.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH) : ''));
|
|
9
|
+
log(format(''.padEnd(FN_NAME_PADDING + COLUMN_MAX_WIDTH + COLUMN_MAX_WIDTH + (executionSteps ? COLUMN_MAX_WIDTH + COLUMN_MAX_WIDTH : 0), '-')));
|
|
10
|
+
let acc = 0;
|
|
11
|
+
let biggest = executionSteps?.[0];
|
|
12
|
+
const timings = stats.timings;
|
|
13
|
+
timings.perFunction.forEach((fn, i)=>{
|
|
14
|
+
const currentExecutionStep = executionSteps?.[i];
|
|
15
|
+
if (currentExecutionStep && biggest && currentExecutionStep.gateCount > biggest.gateCount) {
|
|
16
|
+
biggest = currentExecutionStep;
|
|
17
|
+
}
|
|
18
|
+
acc += currentExecutionStep ? currentExecutionStep.gateCount : 0;
|
|
19
|
+
log(format(' - ', fn.functionName.padEnd(FN_NAME_PADDING), `${fn.time.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), currentExecutionStep ? currentExecutionStep.gateCount.toLocaleString().padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH) : '', currentExecutionStep ? acc.toLocaleString().padStart(COLUMN_MAX_WIDTH) : ''));
|
|
20
|
+
if (printOracles && fn.oracles) {
|
|
21
|
+
log('');
|
|
22
|
+
for (const [oracleName, { times }] of Object.entries(fn.oracles)){
|
|
23
|
+
const calls = times.length;
|
|
24
|
+
const min = Math.min(...times);
|
|
25
|
+
const max = Math.max(...times);
|
|
26
|
+
const total = times.reduce((acc, time)=>acc + time, 0);
|
|
27
|
+
const avg = total / calls;
|
|
28
|
+
log(format(' ', oracleName.padEnd(ORACLE_NAME_PADDING), `${calls} calls`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `${total.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `min: ${min.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `avg: ${avg.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `max: ${max.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH)));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
log('');
|
|
32
|
+
});
|
|
33
|
+
if (biggest) {
|
|
34
|
+
log(format('\nTotal gates:', acc.toLocaleString(), `(Biggest circuit: ${biggest.functionName} -> ${biggest.gateCount.toLocaleString()})`));
|
|
35
|
+
}
|
|
36
|
+
if (stats.nodeRPCCalls) {
|
|
37
|
+
log(format('\nRPC calls:\n'));
|
|
38
|
+
for (const [method, { times }] of Object.entries(stats.nodeRPCCalls.perMethod)){
|
|
39
|
+
const calls = times.length;
|
|
40
|
+
const total = times.reduce((acc, time)=>acc + time, 0);
|
|
41
|
+
const avg = total / calls;
|
|
42
|
+
const min = Math.min(...times);
|
|
43
|
+
const max = Math.max(...times);
|
|
44
|
+
log(format(method.padEnd(ORACLE_NAME_PADDING), `${calls} calls`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `${total.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `min: ${min.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `avg: ${avg.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH), `max: ${max.toFixed(2)}ms`.padStart(COLUMN_MIN_WIDTH).padEnd(COLUMN_MAX_WIDTH)));
|
|
45
|
+
}
|
|
46
|
+
const { roundTrips } = stats.nodeRPCCalls;
|
|
47
|
+
log(format('\nRound trips (actual blocking waits):\n'));
|
|
48
|
+
log(format('Round trips:'.padEnd(25), `${roundTrips.roundTrips}`.padStart(COLUMN_MAX_WIDTH)));
|
|
49
|
+
log(format('Total blocking time:'.padEnd(25), `${roundTrips.totalBlockingTime.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
50
|
+
if (roundTrips.roundTrips > 0) {
|
|
51
|
+
const avgRoundTrip = roundTrips.totalBlockingTime / roundTrips.roundTrips;
|
|
52
|
+
log(format('Avg round trip:'.padEnd(25), `${avgRoundTrip.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
log(format('\nSync time:'.padEnd(25), `${timings.sync?.toFixed(2)}ms`.padStart(16)));
|
|
56
|
+
log(format('Private simulation time:'.padEnd(25), `${timings.perFunction.reduce((acc, { time })=>acc + time, 0).toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
57
|
+
if (timings.proving) {
|
|
58
|
+
log(format('Proving time:'.padEnd(25), `${timings.proving?.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
59
|
+
}
|
|
60
|
+
if (timings.publicSimulation) {
|
|
61
|
+
log(format('Public simulation time:'.padEnd(25), `${timings.publicSimulation?.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
62
|
+
}
|
|
63
|
+
if (timings.validation) {
|
|
64
|
+
log(format('Validation time:'.padEnd(25), `${timings.validation?.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
65
|
+
}
|
|
66
|
+
log(format('Total time:'.padEnd(25), `${timings.total.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH), `(${timings.unaccounted.toFixed(2)}ms unaccounted)`));
|
|
67
|
+
log('\n');
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Account } from '@aztec/aztec.js/account';
|
|
2
|
+
import { type InteractionFeeOptions } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
4
|
+
import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
8
|
+
import type { NotesFilter } from '@aztec/pxe/client/lazy';
|
|
9
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
10
|
+
import type { PXE } from '@aztec/pxe/server';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
13
|
+
import type { TxProvingResult } from '@aztec/stdlib/tx';
|
|
14
|
+
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
15
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
16
|
+
import type { WalletDB } from '../storage/wallet_db.js';
|
|
17
|
+
import type { AccountType } from './constants.js';
|
|
18
|
+
export declare class CLIWallet extends BaseWallet {
|
|
19
|
+
private userLog;
|
|
20
|
+
private db?;
|
|
21
|
+
private accountCache;
|
|
22
|
+
private stubClassIds;
|
|
23
|
+
constructor(pxe: PXE, node: AztecNode, userLog: LogFn, db?: WalletDB | undefined);
|
|
24
|
+
static create(node: AztecNode, log: LogFn, db?: WalletDB, overridePXEConfig?: Partial<PXEConfig>): Promise<CLIWallet>;
|
|
25
|
+
private registerAuthRegistry;
|
|
26
|
+
private initStubClasses;
|
|
27
|
+
getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
28
|
+
private createCancellationTxExecutionRequest;
|
|
29
|
+
proveCancellationTx(from: AztecAddress, txNonce: Fr, increasedFee: InteractionFeeOptions): Promise<TxProvingResult>;
|
|
30
|
+
getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
31
|
+
private createAccount;
|
|
32
|
+
createOrRetrieveAccount(address?: AztecAddress, secretKey?: Fr, type?: AccountType, salt?: Fr, publicKey?: string): Promise<AccountManager>;
|
|
33
|
+
private getFakeAccountDataFor;
|
|
34
|
+
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResultWithAppOffset>;
|
|
35
|
+
/**
|
|
36
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
37
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
38
|
+
*/
|
|
39
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions): Promise<TxSimulationResultWithAppOffset>;
|
|
40
|
+
getContracts(): Promise<AztecAddress[]>;
|
|
41
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]>;
|
|
42
|
+
getContractArtifact(id: Fr): Promise<import("@aztec/stdlib/abi").ContractArtifact | undefined>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvd2FsbGV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUtBLE9BQU8sRUFBRSxLQUFLLE9BQU8sRUFBaUMsTUFBTSx5QkFBeUIsQ0FBQztBQUN0RixPQUFPLEVBQUUsS0FBSyxxQkFBcUIsRUFBOEMsTUFBTSwyQkFBMkIsQ0FBQztBQUNuSCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsY0FBYyxFQUFFLEtBQUssT0FBTyxFQUFFLEtBQUssZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUY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BAAgB,EAClC,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,+BAA+B,CAAC,CAa1C;IAED;;;OAGG;IACH,UAAyB,qBAAqB,CAC5C,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,4BAA4B,GACjC,OAAO,CAAC,+BAA+B,CAAC,CA2C1C;IAID,YAAY,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAEtC;IAID,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAEhD;IAID,mBAAmB,CAAC,EAAE,EAAE,EAAE,qEAEzB;CACF"}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
|
+
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
|
+
import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa';
|
|
4
|
+
import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
|
|
5
|
+
import { getIdentities } from '@aztec/accounts/utils';
|
|
6
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
7
|
+
import { getContractClassFromArtifact, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
8
|
+
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
9
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
10
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
|
+
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
13
|
+
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
16
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
17
|
+
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
18
|
+
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
19
|
+
import { printGasEstimates } from './options/fees.js';
|
|
20
|
+
export class CLIWallet extends BaseWallet {
|
|
21
|
+
userLog;
|
|
22
|
+
db;
|
|
23
|
+
accountCache;
|
|
24
|
+
// Stub class ids, populated on wallet startup
|
|
25
|
+
// to avoid redundant work per simulation
|
|
26
|
+
stubClassIds;
|
|
27
|
+
constructor(pxe, node, userLog, db){
|
|
28
|
+
super(pxe, node), this.userLog = userLog, this.db = db, this.accountCache = new Map(), this.stubClassIds = new Map();
|
|
29
|
+
this.cancellableTransactions = true;
|
|
30
|
+
}
|
|
31
|
+
static async create(node, log, db, overridePXEConfig) {
|
|
32
|
+
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
33
|
+
const pxe = await createPXE(node, pxeConfig);
|
|
34
|
+
const wallet = new CLIWallet(pxe, node, log, db);
|
|
35
|
+
await wallet.initStubClasses();
|
|
36
|
+
await wallet.registerAuthRegistry();
|
|
37
|
+
return wallet;
|
|
38
|
+
}
|
|
39
|
+
async registerAuthRegistry() {
|
|
40
|
+
const { instance, artifact } = await getStandardAuthRegistry();
|
|
41
|
+
await this.pxe.registerContract({
|
|
42
|
+
instance,
|
|
43
|
+
artifact
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
48
|
+
* stubClassIds. Called on wallet initialization.
|
|
49
|
+
*/ async initStubClasses() {
|
|
50
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
|
|
51
|
+
await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
|
|
52
|
+
// ecdsa stubs share the same class id
|
|
53
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
|
|
54
|
+
await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
|
|
55
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
56
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
57
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
58
|
+
this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
|
|
59
|
+
}
|
|
60
|
+
async getAccounts() {
|
|
61
|
+
const accounts = await this.db?.listAliases('accounts') ?? [];
|
|
62
|
+
return Promise.resolve(accounts.map(({ key, value })=>{
|
|
63
|
+
const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
|
|
64
|
+
return {
|
|
65
|
+
alias,
|
|
66
|
+
item: AztecAddress.fromString(value)
|
|
67
|
+
};
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
async createCancellationTxExecutionRequest(from, txNonce, increasedFee) {
|
|
71
|
+
const executionPayload = ExecutionPayload.empty();
|
|
72
|
+
const feeOptions = await this.completeFeeOptions({
|
|
73
|
+
from,
|
|
74
|
+
feePayer: executionPayload.feePayer,
|
|
75
|
+
gasSettings: increasedFee.gasSettings
|
|
76
|
+
});
|
|
77
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
78
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
79
|
+
const chainInfo = await this.getChainInfo();
|
|
80
|
+
const executionOptions = {
|
|
81
|
+
txNonce,
|
|
82
|
+
cancellable: this.cancellableTransactions,
|
|
83
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
84
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
85
|
+
};
|
|
86
|
+
return await fromAccount.createTxExecutionRequest(feeExecutionPayload ?? executionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
87
|
+
}
|
|
88
|
+
async proveCancellationTx(from, txNonce, increasedFee) {
|
|
89
|
+
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
90
|
+
return await this.pxe.proveTx(cancellationTxRequest, {
|
|
91
|
+
scopes: this.scopesFrom(from),
|
|
92
|
+
senderForTags: from
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async getAccountFromAddress(address) {
|
|
96
|
+
let account;
|
|
97
|
+
if (this.accountCache.has(address.toString())) {
|
|
98
|
+
return this.accountCache.get(address.toString());
|
|
99
|
+
} else {
|
|
100
|
+
const accountManager = await this.createOrRetrieveAccount(address);
|
|
101
|
+
account = await accountManager.getAccount();
|
|
102
|
+
}
|
|
103
|
+
if (!account) {
|
|
104
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
105
|
+
}
|
|
106
|
+
return account;
|
|
107
|
+
}
|
|
108
|
+
async createAccount(secret, salt, contract) {
|
|
109
|
+
const accountManager = await AccountManager.create(this, secret, contract, {
|
|
110
|
+
salt
|
|
111
|
+
});
|
|
112
|
+
const instance = accountManager.getInstance();
|
|
113
|
+
const artifact = await contract.getContractArtifact();
|
|
114
|
+
await this.registerContract(instance, artifact, secret);
|
|
115
|
+
this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
116
|
+
return accountManager;
|
|
117
|
+
}
|
|
118
|
+
async createOrRetrieveAccount(address, secretKey, type = 'schnorr', salt, publicKey) {
|
|
119
|
+
let account;
|
|
120
|
+
salt ??= Fr.ZERO;
|
|
121
|
+
if (this.db && address) {
|
|
122
|
+
({ type, secretKey, salt } = await this.db.retrieveAccount(address));
|
|
123
|
+
}
|
|
124
|
+
if (!secretKey) {
|
|
125
|
+
throw new Error('Cannot retrieve/create wallet without secret key');
|
|
126
|
+
}
|
|
127
|
+
switch(type){
|
|
128
|
+
case 'schnorr':
|
|
129
|
+
{
|
|
130
|
+
account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case 'ecdsasecp256r1':
|
|
134
|
+
{
|
|
135
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()));
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case 'ecdsasecp256r1ssh':
|
|
139
|
+
{
|
|
140
|
+
let publicSigningKey;
|
|
141
|
+
if (this.db && address) {
|
|
142
|
+
publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
|
|
143
|
+
} else if (publicKey) {
|
|
144
|
+
const identities = await getIdentities();
|
|
145
|
+
const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
|
|
146
|
+
if (!foundIdentity) {
|
|
147
|
+
throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
|
|
148
|
+
}
|
|
149
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
|
|
150
|
+
} else {
|
|
151
|
+
throw new Error('Public key must be provided for ECDSA SSH account');
|
|
152
|
+
}
|
|
153
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default:
|
|
157
|
+
{
|
|
158
|
+
throw new Error(`Unsupported account type: ${type}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return account;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
165
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
166
|
+
* @param address - The address of the account to impersonate
|
|
167
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
168
|
+
*/ async getFakeAccountDataFor(address) {
|
|
169
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
170
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
171
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
172
|
+
if (!contractInstance) {
|
|
173
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
174
|
+
}
|
|
175
|
+
const { type } = await this.db.retrieveAccount(address);
|
|
176
|
+
const stubAccount = type === 'schnorr' ? createStubSchnorrAccount(originalAddress) : createStubEcdsaAccount(originalAddress);
|
|
177
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
178
|
+
if (!stubClassId) {
|
|
179
|
+
throw new Error(`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`);
|
|
180
|
+
}
|
|
181
|
+
const instance = {
|
|
182
|
+
...contractInstance,
|
|
183
|
+
currentContractClassId: stubClassId
|
|
184
|
+
};
|
|
185
|
+
return {
|
|
186
|
+
account: stubAccount,
|
|
187
|
+
instance
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async simulateTx(executionPayload, opts) {
|
|
191
|
+
const simulationResults = await super.simulateTx(executionPayload, opts);
|
|
192
|
+
if (opts.fee?.estimateGas) {
|
|
193
|
+
const feeOptions = await this.completeFeeOptions({
|
|
194
|
+
from: opts.from,
|
|
195
|
+
feePayer: executionPayload.feePayer,
|
|
196
|
+
gasSettings: opts.fee?.gasSettings
|
|
197
|
+
});
|
|
198
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
199
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
200
|
+
}
|
|
201
|
+
return simulationResults;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
205
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
206
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
207
|
+
const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
|
|
208
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
209
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
210
|
+
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
211
|
+
feeExecutionPayload,
|
|
212
|
+
executionPayload
|
|
213
|
+
]) : executionPayload;
|
|
214
|
+
const chainInfo = await this.getChainInfo();
|
|
215
|
+
let overrides;
|
|
216
|
+
let txRequest;
|
|
217
|
+
if (from === NO_FROM) {
|
|
218
|
+
const entrypoint = new DefaultEntrypoint();
|
|
219
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
220
|
+
} else {
|
|
221
|
+
const { account, instance } = await this.getFakeAccountDataFor(from);
|
|
222
|
+
overrides = {
|
|
223
|
+
contracts: {
|
|
224
|
+
[from.toString()]: {
|
|
225
|
+
instance
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const executionOptions = {
|
|
230
|
+
txNonce: Fr.random(),
|
|
231
|
+
cancellable: this.cancellableTransactions,
|
|
232
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
233
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
234
|
+
};
|
|
235
|
+
txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
236
|
+
}
|
|
237
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
238
|
+
simulatePublic: true,
|
|
239
|
+
skipFeeEnforcement: true,
|
|
240
|
+
skipTxValidation: true,
|
|
241
|
+
overrides,
|
|
242
|
+
scopes,
|
|
243
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
|
|
244
|
+
});
|
|
245
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
246
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
247
|
+
}
|
|
248
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
249
|
+
// this is just a CLI wallet.
|
|
250
|
+
getContracts() {
|
|
251
|
+
return this.pxe.getContracts();
|
|
252
|
+
}
|
|
253
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
254
|
+
// this is just a CLI wallet.
|
|
255
|
+
getNotes(filter) {
|
|
256
|
+
return this.pxe.debug.getNotes(filter);
|
|
257
|
+
}
|
|
258
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
259
|
+
// this is just a CLI wallet.
|
|
260
|
+
getContractArtifact(id) {
|
|
261
|
+
return this.pxe.getContractArtifact(id);
|
|
262
|
+
}
|
|
263
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli-wallet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.017a351",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/cmds/index.js",
|
|
@@ -19,12 +19,10 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"start": "node --no-warnings ./dest/bin",
|
|
21
21
|
"start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin",
|
|
22
|
-
"dev": "LOG_LEVEL
|
|
23
|
-
"build": "yarn clean && tsc
|
|
24
|
-
"build:dev": "tsc
|
|
22
|
+
"dev": "LOG_LEVEL=\"debug; info: json-rpc, simulator\" node ./dest/bin",
|
|
23
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
24
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
25
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
26
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
29
27
|
},
|
|
30
28
|
"inherits": [
|
|
@@ -62,33 +60,43 @@
|
|
|
62
60
|
"testTimeout": 120000,
|
|
63
61
|
"setupFiles": [
|
|
64
62
|
"../../foundation/src/jest/setup.mjs"
|
|
63
|
+
],
|
|
64
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
65
|
+
"setupFilesAfterEnv": [
|
|
66
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
65
67
|
]
|
|
66
68
|
},
|
|
67
69
|
"dependencies": {
|
|
68
|
-
"@aztec/accounts": "0.0.
|
|
69
|
-
"@aztec/aztec.js": "0.0.
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
76
|
-
"@aztec/
|
|
70
|
+
"@aztec/accounts": "0.0.1-commit.017a351",
|
|
71
|
+
"@aztec/aztec.js": "0.0.1-commit.017a351",
|
|
72
|
+
"@aztec/bb.js": "0.0.1-commit.017a351",
|
|
73
|
+
"@aztec/cli": "0.0.1-commit.017a351",
|
|
74
|
+
"@aztec/entrypoints": "0.0.1-commit.017a351",
|
|
75
|
+
"@aztec/ethereum": "0.0.1-commit.017a351",
|
|
76
|
+
"@aztec/foundation": "0.0.1-commit.017a351",
|
|
77
|
+
"@aztec/kv-store": "0.0.1-commit.017a351",
|
|
78
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.017a351",
|
|
79
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.017a351",
|
|
80
|
+
"@aztec/pxe": "0.0.1-commit.017a351",
|
|
81
|
+
"@aztec/standard-contracts": "0.0.1-commit.017a351",
|
|
82
|
+
"@aztec/stdlib": "0.0.1-commit.017a351",
|
|
83
|
+
"@aztec/wallet-sdk": "0.0.1-commit.017a351",
|
|
77
84
|
"commander": "^12.1.0",
|
|
78
85
|
"inquirer": "^10.1.8",
|
|
79
86
|
"source-map-support": "^0.5.21",
|
|
80
87
|
"tslib": "^2.4.0"
|
|
81
88
|
},
|
|
82
89
|
"devDependencies": {
|
|
83
|
-
"@jest/globals": "^
|
|
84
|
-
"@types/jest": "^
|
|
85
|
-
"@types/node": "^
|
|
90
|
+
"@jest/globals": "^30.0.0",
|
|
91
|
+
"@types/jest": "^30.0.0",
|
|
92
|
+
"@types/node": "^22.15.17",
|
|
86
93
|
"@types/source-map-support": "^0.5.10",
|
|
87
|
-
"
|
|
88
|
-
"jest
|
|
89
|
-
"
|
|
94
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
95
|
+
"jest": "^30.0.0",
|
|
96
|
+
"jest-mock-extended": "^4.0.0",
|
|
97
|
+
"ts-jest": "^29.4.0",
|
|
90
98
|
"ts-node": "^10.9.1",
|
|
91
|
-
"typescript": "^5.
|
|
99
|
+
"typescript": "^5.3.3"
|
|
92
100
|
},
|
|
93
101
|
"files": [
|
|
94
102
|
"dest",
|
|
@@ -97,6 +105,6 @@
|
|
|
97
105
|
],
|
|
98
106
|
"types": "./dest/index.d.ts",
|
|
99
107
|
"engines": {
|
|
100
|
-
"node": ">=
|
|
108
|
+
"node": ">=20.10"
|
|
101
109
|
}
|
|
102
110
|
}
|
package/src/bin/index.ts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { computeSecretHash } from '@aztec/aztec.js/crypto';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
5
|
+
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
6
|
+
import { BackendType, Barretenberg } from '@aztec/bb.js';
|
|
2
7
|
import { LOCALHOST } from '@aztec/cli/cli-utils';
|
|
3
8
|
import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
4
9
|
import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
-
import type {
|
|
10
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
11
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
6
12
|
|
|
7
13
|
import { Argument, Command, Option } from 'commander';
|
|
8
|
-
import { mkdirSync, readFileSync } from 'fs';
|
|
9
14
|
import { homedir } from 'os';
|
|
10
|
-
import {
|
|
15
|
+
import { join } from 'path';
|
|
11
16
|
|
|
12
17
|
import { injectCommands } from '../cmds/index.js';
|
|
13
18
|
import { Aliases, WalletDB } from '../storage/wallet_db.js';
|
|
19
|
+
import { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
14
20
|
import { createAliasOption } from '../utils/options/index.js';
|
|
15
|
-
import {
|
|
21
|
+
import { CLIWallet } from '../utils/wallet.js';
|
|
16
22
|
|
|
17
23
|
const userLog = createConsoleLogger();
|
|
18
24
|
const debugLogger = createLogger('wallet');
|
|
19
25
|
|
|
20
|
-
const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet')
|
|
26
|
+
const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet') } = process.env;
|
|
21
27
|
|
|
28
|
+
// TODO: This function is only used in 1 place so we could just inline this
|
|
22
29
|
function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
23
30
|
program
|
|
24
31
|
.command('alias')
|
|
@@ -55,7 +62,7 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
|
55
62
|
const options = command.optsWithGlobals();
|
|
56
63
|
const { alias } = options;
|
|
57
64
|
const value = Fr.random();
|
|
58
|
-
const hash = computeSecretHash(value);
|
|
65
|
+
const hash = await computeSecretHash(value);
|
|
59
66
|
|
|
60
67
|
await db.storeAlias('secrets', alias, Buffer.from(value.toString()), log);
|
|
61
68
|
await db.storeAlias('secrets', `${alias}:hash`, Buffer.from(hash.toString()), log);
|
|
@@ -66,23 +73,21 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
|
66
73
|
|
|
67
74
|
/** CLI wallet main entrypoint */
|
|
68
75
|
async function main() {
|
|
69
|
-
const
|
|
70
|
-
const walletVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
|
|
76
|
+
const walletVersion = getPackageVersion();
|
|
71
77
|
|
|
72
78
|
const db = WalletDB.getInstance();
|
|
73
|
-
const
|
|
79
|
+
const walletAndNodeWrapper = new CliWalletAndNodeWrapper();
|
|
74
80
|
|
|
75
81
|
const program = new Command('wallet');
|
|
76
82
|
program
|
|
77
83
|
.description('Aztec wallet')
|
|
78
84
|
.version(walletVersion)
|
|
79
85
|
.option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
|
|
80
|
-
.option('-p, --prover <string>', 'wasm|native|none', PXE_PROVER)
|
|
81
86
|
.addOption(
|
|
82
|
-
new Option('--
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
87
|
+
new Option('-p, --prover <string>', 'The type of prover the wallet uses')
|
|
88
|
+
.choices(['wasm', 'native', 'none'])
|
|
89
|
+
.env('PXE_PROVER')
|
|
90
|
+
.default('native'),
|
|
86
91
|
)
|
|
87
92
|
.addOption(
|
|
88
93
|
new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to')
|
|
@@ -90,34 +95,59 @@ async function main() {
|
|
|
90
95
|
.default(`http://${LOCALHOST}:8080`),
|
|
91
96
|
)
|
|
92
97
|
.hook('preSubcommand', async command => {
|
|
93
|
-
|
|
98
|
+
// Skip initialization if user is just requesting help
|
|
99
|
+
if (command.args.includes('--help') || command.args.includes('-h')) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { dataDir, nodeUrl, prover } = command.optsWithGlobals();
|
|
94
104
|
|
|
95
|
-
|
|
96
|
-
debugLogger.info('Using local PXE service');
|
|
105
|
+
const proverEnabled = prover !== 'none';
|
|
97
106
|
|
|
98
|
-
|
|
107
|
+
switch (prover) {
|
|
108
|
+
case 'native':
|
|
109
|
+
await Barretenberg.initSingleton({ backend: BackendType.NativeUnixSocket });
|
|
110
|
+
break;
|
|
111
|
+
case 'wasm':
|
|
112
|
+
await Barretenberg.initSingleton({ backend: BackendType.Wasm });
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
99
115
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const bbWorkingDirectory = dataDir + '/bb';
|
|
105
|
-
mkdirSync(bbWorkingDirectory, { recursive: true });
|
|
116
|
+
const overridePXEConfig: Partial<PXEConfig> = {
|
|
117
|
+
proverEnabled,
|
|
118
|
+
dataDirectory: join(dataDir, 'pxe'),
|
|
119
|
+
};
|
|
106
120
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
121
|
+
const node = createAztecNodeClient(nodeUrl);
|
|
122
|
+
const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
|
|
123
|
+
|
|
124
|
+
walletAndNodeWrapper.setNodeAndWallet(node, wallet);
|
|
112
125
|
|
|
113
|
-
await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
|
|
114
|
-
}
|
|
115
126
|
await db.init(await openStoreAt(dataDir));
|
|
127
|
+
let protocolContractsRegistered;
|
|
128
|
+
try {
|
|
129
|
+
protocolContractsRegistered = !!(await db.retrieveAlias('contracts:ContractClassRegistry'));
|
|
130
|
+
// eslint-disable-next-line no-empty
|
|
131
|
+
} catch {}
|
|
132
|
+
if (!protocolContractsRegistered) {
|
|
133
|
+
userLog('Registering protocol contract aliases...');
|
|
134
|
+
for (const [name, address] of Object.entries(ProtocolContractAddress)) {
|
|
135
|
+
await db.storeAlias('contracts', name, Buffer.from(address.toString()), userLog);
|
|
136
|
+
await db.storeAlias(
|
|
137
|
+
'artifacts',
|
|
138
|
+
address.toString(),
|
|
139
|
+
Buffer.from(`${name.slice(0, 1).toUpperCase()}${name.slice(1)}`),
|
|
140
|
+
userLog,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
116
144
|
});
|
|
117
145
|
|
|
118
|
-
injectCommands(program, userLog, debugLogger,
|
|
146
|
+
injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
|
|
119
147
|
injectInternalCommands(program, userLog, db);
|
|
120
148
|
await program.parseAsync(process.argv);
|
|
149
|
+
|
|
150
|
+
await Barretenberg.destroySingleton();
|
|
121
151
|
}
|
|
122
152
|
|
|
123
153
|
main().catch(err => {
|