@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.023c3e5
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 +147 -6
- package/dest/cmds/create_account.d.ts +9 -7
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +61 -36
- 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 +7 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +98 -58
- package/dest/cmds/deploy_account.d.ts +6 -8
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +60 -37
- 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 +83 -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 +8 -9
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +51 -28
- 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 +7 -19
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +49 -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 +22 -28
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +86 -145
- 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 +35 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +204 -0
- package/package.json +29 -22
- 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 +180 -5
- package/src/cmds/create_account.ts +72 -42
- package/src/cmds/create_authwit.ts +9 -5
- package/src/cmds/deploy.ts +103 -67
- package/src/cmds/deploy_account.ts +72 -37
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +256 -220
- 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 +51 -25
- package/src/cmds/simulate.ts +37 -24
- package/src/storage/wallet_db.ts +53 -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 +136 -207
- package/src/utils/options/options.ts +41 -19
- package/src/utils/profiling.ts +172 -0
- package/src/utils/wallet.ts +283 -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,48 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { Contract } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
|
+
import { prepTx } from '@aztec/cli/utils';
|
|
6
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
7
|
+
import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
|
|
8
|
+
|
|
9
|
+
import { promises as fs } from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
|
|
12
|
+
import type { CLIFeeArgs } from '../utils/options/fees.js';
|
|
13
|
+
import { printProfileResult } from '../utils/profiling.js';
|
|
14
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
15
|
+
|
|
16
|
+
export async function profile(
|
|
17
|
+
wallet: CLIWallet,
|
|
18
|
+
node: AztecNode,
|
|
19
|
+
from: AztecAddress,
|
|
20
|
+
functionName: string,
|
|
21
|
+
functionArgsIn: any[],
|
|
22
|
+
contractArtifactPath: string,
|
|
23
|
+
contractAddress: AztecAddress,
|
|
24
|
+
debugOutputPath: string | undefined,
|
|
25
|
+
feeOpts: CLIFeeArgs,
|
|
26
|
+
authWitnesses: AuthWitness[],
|
|
27
|
+
log: LogFn,
|
|
28
|
+
) {
|
|
29
|
+
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
30
|
+
|
|
31
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
32
|
+
const call = contract.methods[functionName](...functionArgs);
|
|
33
|
+
|
|
34
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
35
|
+
const result = await call.profile({
|
|
36
|
+
fee: { gasSettings, paymentMethod },
|
|
37
|
+
from,
|
|
38
|
+
profileMode: 'full',
|
|
39
|
+
authWitnesses,
|
|
40
|
+
skipProofGeneration: false,
|
|
41
|
+
});
|
|
42
|
+
printProfileResult(result.stats, log, true, result.executionSteps);
|
|
43
|
+
if (debugOutputPath) {
|
|
44
|
+
const ivcInputsPath = path.join(debugOutputPath, 'ivc-inputs.msgpack');
|
|
45
|
+
log(`Debug output written to ${ivcInputsPath}.`);
|
|
46
|
+
await fs.writeFile(ivcInputsPath, serializePrivateExecutionSteps(result.executionSteps));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,20 +1,43 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { PublicKeys } from '@aztec/aztec.js/keys';
|
|
5
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
6
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
2
7
|
import { getContractArtifact } from '@aztec/cli/cli-utils';
|
|
3
8
|
import type { LogFn } from '@aztec/foundation/log';
|
|
9
|
+
import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
|
|
4
10
|
|
|
5
11
|
export async function registerContract(
|
|
6
|
-
wallet:
|
|
12
|
+
wallet: Wallet,
|
|
7
13
|
node: AztecNode,
|
|
8
14
|
address: AztecAddress,
|
|
9
15
|
artifactPath: string,
|
|
10
16
|
log: LogFn,
|
|
17
|
+
initializer?: string,
|
|
18
|
+
publicKeys?: PublicKeys,
|
|
19
|
+
rawArgs?: any[],
|
|
20
|
+
salt?: Fr,
|
|
21
|
+
deployer?: AztecAddress,
|
|
11
22
|
) {
|
|
12
23
|
const contractArtifact = await getContractArtifact(artifactPath, log);
|
|
13
|
-
const
|
|
24
|
+
const hasInitializer = getAllFunctionAbis(contractArtifact).some(fn => fn.isInitializer);
|
|
25
|
+
const constructorArtifact = hasInitializer ? getInitializer(contractArtifact, initializer) : undefined;
|
|
26
|
+
let contractInstance = await node.getContract(address);
|
|
14
27
|
if (!contractInstance) {
|
|
15
|
-
|
|
28
|
+
log(`Contract not found in the node at ${address}. Computing instance locally...`);
|
|
29
|
+
contractInstance = await getContractInstanceFromInstantiationParams(contractArtifact, {
|
|
30
|
+
constructorArtifact,
|
|
31
|
+
publicKeys: publicKeys ?? PublicKeys.default(),
|
|
32
|
+
constructorArgs: rawArgs,
|
|
33
|
+
salt: salt ?? Fr.ZERO,
|
|
34
|
+
deployer,
|
|
35
|
+
});
|
|
16
36
|
}
|
|
17
|
-
|
|
37
|
+
if (!contractInstance.address.equals(address)) {
|
|
38
|
+
throw new Error(`Contract address mismatch: expected ${address}, got ${contractInstance.address}`);
|
|
39
|
+
}
|
|
40
|
+
await wallet.registerContract(contractInstance, contractArtifact);
|
|
18
41
|
log(`Contract registered: at ${contractInstance.address}`);
|
|
19
42
|
return contractInstance;
|
|
20
43
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
2
3
|
import type { LogFn } from '@aztec/foundation/log';
|
|
3
4
|
|
|
4
|
-
export async function registerSender(wallet:
|
|
5
|
+
export async function registerSender(wallet: Wallet, address: AztecAddress, log: LogFn) {
|
|
5
6
|
await wallet.registerSender(address);
|
|
6
7
|
log(`Sender registered: ${address}`);
|
|
7
8
|
}
|
package/src/cmds/send.ts
CHANGED
|
@@ -1,62 +1,88 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { Contract, NO_WAIT, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
5
|
import { prepTx } from '@aztec/cli/utils';
|
|
3
6
|
import type { LogFn } from '@aztec/foundation/log';
|
|
4
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
5
7
|
|
|
6
|
-
import {
|
|
8
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
9
|
+
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
10
|
+
import { printProfileResult } from '../utils/profiling.js';
|
|
11
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
7
12
|
|
|
8
13
|
export async function send(
|
|
9
|
-
wallet:
|
|
14
|
+
wallet: CLIWallet,
|
|
15
|
+
node: AztecNode,
|
|
16
|
+
from: AztecAddress,
|
|
10
17
|
functionName: string,
|
|
11
18
|
functionArgsIn: any[],
|
|
12
19
|
contractArtifactPath: string,
|
|
13
20
|
contractAddress: AztecAddress,
|
|
14
21
|
wait: boolean,
|
|
15
22
|
cancellable: boolean,
|
|
16
|
-
feeOpts:
|
|
23
|
+
feeOpts: CLIFeeArgs,
|
|
24
|
+
authWitnesses: AuthWitness[],
|
|
25
|
+
verbose: boolean,
|
|
17
26
|
log: LogFn,
|
|
18
27
|
) {
|
|
19
28
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
20
29
|
|
|
21
|
-
const contract =
|
|
30
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
22
31
|
const call = contract.methods[functionName](...functionArgs);
|
|
23
32
|
|
|
24
|
-
const
|
|
25
|
-
|
|
33
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
34
|
+
const sendOptions: SendInteractionOptions = {
|
|
35
|
+
fee: { paymentMethod, gasSettings },
|
|
36
|
+
from,
|
|
37
|
+
authWitnesses,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const { estimatedGas, stats } = await call.simulate({
|
|
41
|
+
...sendOptions,
|
|
42
|
+
fee: { ...sendOptions.fee, estimateGas: true },
|
|
43
|
+
});
|
|
26
44
|
|
|
27
45
|
if (feeOpts.estimateOnly) {
|
|
28
46
|
return;
|
|
29
47
|
}
|
|
30
48
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
if (verbose) {
|
|
50
|
+
printProfileResult(stats!, log);
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
if (wait) {
|
|
36
54
|
try {
|
|
37
|
-
await
|
|
55
|
+
const receipt = await call.send({
|
|
56
|
+
...sendOptions,
|
|
57
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
58
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S },
|
|
59
|
+
});
|
|
38
60
|
|
|
61
|
+
const txHash = receipt.txHash;
|
|
62
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
39
63
|
log('Transaction has been mined');
|
|
40
|
-
|
|
41
|
-
const receipt = await tx.getReceipt();
|
|
42
64
|
log(` Tx fee: ${receipt.transactionFee}`);
|
|
43
65
|
log(` Status: ${receipt.status}`);
|
|
44
66
|
log(` Block number: ${receipt.blockNumber}`);
|
|
45
67
|
log(` Block hash: ${receipt.blockHash?.toString()}`);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
txHash,
|
|
71
|
+
};
|
|
46
72
|
} catch (err: any) {
|
|
47
73
|
log(`Transaction failed\n ${err.message}`);
|
|
74
|
+
throw err;
|
|
48
75
|
}
|
|
49
76
|
} else {
|
|
77
|
+
const txHash = await call.send({
|
|
78
|
+
...sendOptions,
|
|
79
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
80
|
+
wait: NO_WAIT,
|
|
81
|
+
});
|
|
82
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
50
83
|
log('Transaction pending. Check status with check-tx');
|
|
84
|
+
return {
|
|
85
|
+
txHash,
|
|
86
|
+
};
|
|
51
87
|
}
|
|
52
|
-
const gasSettings = GasSettings.from({
|
|
53
|
-
...feeOpts.gasSettings,
|
|
54
|
-
...gasLimits,
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
txHash,
|
|
58
|
-
nonce,
|
|
59
|
-
cancellable,
|
|
60
|
-
gasSettings,
|
|
61
|
-
};
|
|
62
88
|
}
|
package/src/cmds/simulate.ts
CHANGED
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { Contract } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
5
|
import { prepTx } from '@aztec/cli/utils';
|
|
3
6
|
import type { LogFn } from '@aztec/foundation/log';
|
|
4
7
|
|
|
5
8
|
import { format } from 'util';
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
log(format('\nGate count per circuit:'));
|
|
12
|
-
let acc = 0;
|
|
13
|
-
result.gateCounts.forEach(r => {
|
|
14
|
-
acc += r.gateCount;
|
|
15
|
-
log(format(' ', r.circuitName.padEnd(50), 'Gates:', r.gateCount.toLocaleString(), '\tAcc:', acc.toLocaleString()));
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
log(format('\nTotal gates:', acc.toLocaleString()));
|
|
19
|
-
}
|
|
10
|
+
import { printAuthorizations } from '../utils/authorizations.js';
|
|
11
|
+
import type { CLIFeeArgs } from '../utils/options/fees.js';
|
|
12
|
+
import { printProfileResult } from '../utils/profiling.js';
|
|
13
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
20
14
|
|
|
21
15
|
export async function simulate(
|
|
22
|
-
wallet:
|
|
16
|
+
wallet: CLIWallet,
|
|
17
|
+
node: AztecNode,
|
|
18
|
+
from: AztecAddress,
|
|
23
19
|
functionName: string,
|
|
24
20
|
functionArgsIn: any[],
|
|
25
21
|
contractArtifactPath: string,
|
|
26
22
|
contractAddress: AztecAddress,
|
|
27
|
-
|
|
23
|
+
feeOpts: CLIFeeArgs,
|
|
24
|
+
authWitnesses: AuthWitness[],
|
|
25
|
+
verbose: boolean,
|
|
28
26
|
log: LogFn,
|
|
29
27
|
) {
|
|
30
28
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
31
29
|
|
|
32
|
-
const contract =
|
|
30
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
33
31
|
const call = contract.methods[functionName](...functionArgs);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
33
|
+
const simulationResult = await call.simulate({
|
|
34
|
+
fee: { paymentMethod, gasSettings },
|
|
35
|
+
from,
|
|
36
|
+
authWitnesses,
|
|
37
|
+
includeMetadata: true,
|
|
38
|
+
});
|
|
39
|
+
if (verbose) {
|
|
40
|
+
await printAuthorizations(
|
|
41
|
+
simulationResult.offchainEffects!,
|
|
42
|
+
async (address: AztecAddress) => {
|
|
43
|
+
const metadata = await wallet.getContractMetadata(address);
|
|
44
|
+
if (!metadata.instance) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
|
|
48
|
+
return artifact;
|
|
49
|
+
},
|
|
50
|
+
log,
|
|
51
|
+
);
|
|
52
|
+
printProfileResult(simulationResult.stats!, log);
|
|
41
53
|
}
|
|
54
|
+
log(format('\nSimulation result: ', simulationResult.result, '\n'));
|
|
42
55
|
}
|
package/src/storage/wallet_db.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { LogFn } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
4
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
7
6
|
import type { TxHash } from '@aztec/stdlib/tx';
|
|
8
7
|
|
|
9
|
-
import type { AccountType } from '../utils/
|
|
8
|
+
import type { AccountType } from '../utils/constants.js';
|
|
10
9
|
import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
|
|
11
10
|
|
|
12
11
|
export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transactions', 'authwits'] as const;
|
|
13
12
|
export type AliasType = (typeof Aliases)[number];
|
|
14
13
|
|
|
15
14
|
export class WalletDB {
|
|
15
|
+
#store!: AztecAsyncKVStore;
|
|
16
16
|
#accounts!: AztecAsyncMap<string, Buffer>;
|
|
17
17
|
#aliases!: AztecAsyncMap<string, Buffer>;
|
|
18
18
|
#bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
|
|
19
|
-
#transactions!: AztecAsyncMap<string, Buffer>;
|
|
20
19
|
|
|
21
20
|
private static instance: WalletDB;
|
|
22
21
|
|
|
@@ -31,10 +30,10 @@ export class WalletDB {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
async init(store: AztecAsyncKVStore) {
|
|
33
|
+
this.#store = store;
|
|
34
34
|
this.#accounts = store.openMap('accounts');
|
|
35
35
|
this.#aliases = store.openMap('aliases');
|
|
36
36
|
this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
|
|
37
|
-
this.#transactions = store.openMap('transactions');
|
|
38
37
|
|
|
39
38
|
await this.refreshAliasCache();
|
|
40
39
|
}
|
|
@@ -44,14 +43,17 @@ export class WalletDB {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
async pushBridgedFeeJuice(recipient: AztecAddress, secret: Fr, amount: bigint, leafIndex: bigint, log: LogFn) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
await this.#store.transactionAsync(async () => {
|
|
47
|
+
let stackPointer =
|
|
48
|
+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
49
|
+
stackPointer++;
|
|
50
|
+
await this.#bridgedFeeJuice.set(
|
|
51
|
+
`${recipient.toString()}:${stackPointer}`,
|
|
52
|
+
Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
|
|
53
|
+
);
|
|
54
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
|
|
55
|
+
log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
56
|
+
});
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
async popBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
|
|
@@ -79,19 +81,24 @@ export class WalletDB {
|
|
|
79
81
|
}: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
|
|
80
82
|
log: LogFn,
|
|
81
83
|
) {
|
|
82
|
-
|
|
83
|
-
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
84
|
-
}
|
|
85
|
-
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
86
|
-
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
87
|
-
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
84
|
+
let publicSigningKey: Buffer | undefined;
|
|
88
85
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
89
|
-
|
|
90
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
86
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
91
87
|
}
|
|
92
|
-
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
93
|
-
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
94
88
|
|
|
89
|
+
await this.#store.transactionAsync(async () => {
|
|
90
|
+
if (alias) {
|
|
91
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
92
|
+
}
|
|
93
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
94
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
95
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
96
|
+
if (publicSigningKey) {
|
|
97
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
98
|
+
}
|
|
99
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
100
|
+
});
|
|
101
|
+
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
95
102
|
await this.refreshAliasCache();
|
|
96
103
|
}
|
|
97
104
|
|
|
@@ -103,67 +110,45 @@ export class WalletDB {
|
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
await this.#store.transactionAsync(async () => {
|
|
114
|
+
if (alias) {
|
|
115
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
116
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
117
|
+
}
|
|
118
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
119
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
120
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
121
|
+
});
|
|
113
122
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
114
|
-
|
|
115
123
|
await this.refreshAliasCache();
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
await this.#store.transactionAsync(async () => {
|
|
128
|
+
if (alias) {
|
|
129
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
130
|
+
}
|
|
131
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
132
|
+
});
|
|
123
133
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
124
|
-
|
|
125
134
|
await this.refreshAliasCache();
|
|
126
135
|
}
|
|
127
136
|
|
|
128
|
-
async storeTx(
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
log: LogFn,
|
|
136
|
-
alias?: string,
|
|
137
|
-
) {
|
|
138
|
-
if (alias) {
|
|
139
|
-
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
140
|
-
}
|
|
141
|
-
await this.#transactions.set(`${txHash.toString()}:nonce`, nonce.toBuffer());
|
|
142
|
-
await this.#transactions.set(`${txHash.toString()}:cancellable`, Buffer.from(cancellable ? 'true' : 'false'));
|
|
143
|
-
await this.#transactions.set(`${txHash.toString()}:gasSettings`, gasSettings.toBuffer());
|
|
144
|
-
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
137
|
+
async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
|
|
138
|
+
await this.#store.transactionAsync(async () => {
|
|
139
|
+
if (alias) {
|
|
140
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
141
|
+
}
|
|
142
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
143
|
+
});
|
|
145
144
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
146
|
-
|
|
147
145
|
await this.refreshAliasCache();
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
async retrieveTxData(txHash: TxHash) {
|
|
151
|
-
const nonceBuffer = await this.#transactions.getAsync(`${txHash.toString()}:nonce`);
|
|
152
|
-
if (!nonceBuffer) {
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Could not find ${txHash.toString()}:nonce. Transaction with hash "${txHash.toString()}" does not exist on this wallet.`,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
const nonce = Fr.fromBuffer(nonceBuffer);
|
|
158
|
-
const cancellable = (await this.#transactions.getAsync(`${txHash.toString()}:cancellable`))!.toString() === 'true';
|
|
159
|
-
const gasBuffer = (await this.#transactions.getAsync(`${txHash.toString()}:gasSettings`))!;
|
|
160
|
-
return { txHash, nonce, cancellable, gasSettings: GasSettings.fromBuffer(gasBuffer) };
|
|
161
|
-
}
|
|
162
|
-
|
|
163
148
|
tryRetrieveAlias(arg: string) {
|
|
164
149
|
try {
|
|
165
150
|
return this.retrieveAliasFromCache(arg);
|
|
166
|
-
} catch
|
|
151
|
+
} catch {
|
|
167
152
|
return arg;
|
|
168
153
|
}
|
|
169
154
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
4
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
5
|
+
import { type AbiDecoded, decodeFromAbi, getFunctionArtifact } from '@aztec/stdlib/abi';
|
|
6
|
+
import type { OffchainEffect } from '@aztec/stdlib/tx';
|
|
7
|
+
|
|
8
|
+
import { format } from 'util';
|
|
9
|
+
|
|
10
|
+
export async function printAuthorizations(
|
|
11
|
+
offchainEffects: OffchainEffect[],
|
|
12
|
+
artifactRetriever: (address: AztecAddress) => Promise<ContractArtifact | undefined>,
|
|
13
|
+
log: LogFn,
|
|
14
|
+
) {
|
|
15
|
+
log(format('\nAuthorizations requested by the tx:\n'));
|
|
16
|
+
const callAuthorizationSelector = await CallAuthorizationRequest.getSelector();
|
|
17
|
+
const callAuthorizationEffects = offchainEffects.filter(effect =>
|
|
18
|
+
effect.data[0].equals(callAuthorizationSelector.toField()),
|
|
19
|
+
);
|
|
20
|
+
for (const callAuthorizationEffect of callAuthorizationEffects) {
|
|
21
|
+
const callAuthorizationRequest = await CallAuthorizationRequest.fromFields(callAuthorizationEffect.data);
|
|
22
|
+
const artifact = await artifactRetriever(callAuthorizationEffect.contractAddress);
|
|
23
|
+
if (!artifact) {
|
|
24
|
+
log(format(' -', `Call authorization. Inner hash: ${callAuthorizationRequest.innerHash.toString()}\n`));
|
|
25
|
+
log(format(' ', `Contract: unknown@${callAuthorizationEffect.contractAddress}`));
|
|
26
|
+
log(
|
|
27
|
+
format(
|
|
28
|
+
' ',
|
|
29
|
+
`${callAuthorizationRequest.functionSelector.toString()}(\n${callAuthorizationRequest.args.map(arg => ` ${arg.toString()}`).join(',\n')}\n )`,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
} else {
|
|
33
|
+
const functionAbi = await getFunctionArtifact(artifact, callAuthorizationRequest.functionSelector);
|
|
34
|
+
const callData = decodeFromAbi(
|
|
35
|
+
functionAbi.parameters.map(param => param.type),
|
|
36
|
+
callAuthorizationRequest.args,
|
|
37
|
+
) as AbiDecoded[];
|
|
38
|
+
const parameters = functionAbi.parameters.map((param, i) => ({ name: param.name, value: callData[i] }));
|
|
39
|
+
log(format(' -', `Call authorization. Inner hash: ${callAuthorizationRequest.innerHash.toString()}`));
|
|
40
|
+
log(format(' ', `Contract: ${artifact.name}@${callAuthorizationEffect.contractAddress}`));
|
|
41
|
+
log(
|
|
42
|
+
format(
|
|
43
|
+
' ',
|
|
44
|
+
/* eslint-disable-next-line @typescript-eslint/no-base-to-string */
|
|
45
|
+
`${functionAbi.name}(\n${parameters.map(p => ` ${p.name}: ${p.value}`).join(',\n')}\n )`,
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
log(`\n`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
2
|
+
|
|
3
|
+
import { CLIWallet } from './wallet.js';
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_TX_TIMEOUT_S = 180;
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Wrapper class for CLIWallet and AztecNode, avoids initialization issues due to closures when providing CLIWallet
|
|
9
|
+
* and AztecNode to injected commander.js commands
|
|
10
|
+
*/
|
|
11
|
+
export class CliWalletAndNodeWrapper {
|
|
12
|
+
private _wallet: CLIWallet | undefined;
|
|
13
|
+
private _node: AztecNode | undefined;
|
|
14
|
+
|
|
15
|
+
constructor() {}
|
|
16
|
+
|
|
17
|
+
get wallet() {
|
|
18
|
+
if (!this._wallet) {
|
|
19
|
+
throw new Error('Wallet not initialized while it should have been initialized in preSubcommand');
|
|
20
|
+
}
|
|
21
|
+
return this._wallet;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get node(): AztecNode {
|
|
25
|
+
if (!this._node) {
|
|
26
|
+
throw new Error('Node not initialized while it should have been initialized in preSubcommand');
|
|
27
|
+
}
|
|
28
|
+
return this._node;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setNodeAndWallet(node: AztecNode, wallet: CLIWallet) {
|
|
32
|
+
this._node = node;
|
|
33
|
+
this._wallet = wallet;
|
|
34
|
+
}
|
|
35
|
+
}
|