@aztec/cli-wallet 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9
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 +39 -23
- 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 +8 -7
- 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 +9 -7
- 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 +148 -6
- package/dest/cmds/create_account.d.ts +8 -6
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +56 -62
- 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 +84 -50
- 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 +56 -65
- 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 +73 -112
- package/dest/cmds/profile.d.ts +7 -4
- package/dest/cmds/profile.d.ts.map +1 -1
- package/dest/cmds/profile.js +9 -4
- 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 +5 -6
- 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 +46 -31
- package/dest/cmds/simulate.d.ts +7 -4
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +12 -7
- package/dest/storage/wallet_db.d.ts +6 -16
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +48 -54
- package/dest/utils/authorizations.d.ts +3 -2
- package/dest/utils/authorizations.d.ts.map +1 -1
- package/dest/utils/authorizations.js +1 -1
- 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 -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 +66 -133
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +3 -2
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/profiling.d.ts +1 -1
- package/dest/utils/profiling.d.ts.map +1 -1
- package/dest/utils/profiling.js +9 -1
- package/dest/utils/wallet.d.ts +40 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +208 -0
- package/package.json +17 -14
- package/src/bin/index.ts +39 -31
- package/src/cmds/authorize_action.ts +14 -6
- package/src/cmds/bridge_fee_juice.ts +15 -11
- package/src/cmds/check_tx.ts +180 -5
- package/src/cmds/create_account.ts +63 -66
- package/src/cmds/create_authwit.ts +9 -5
- package/src/cmds/deploy.ts +82 -61
- package/src/cmds/deploy_account.ts +62 -64
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +120 -206
- package/src/cmds/profile.ts +14 -6
- package/src/cmds/register_contract.ts +9 -11
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +42 -40
- package/src/cmds/simulate.ts +17 -12
- package/src/storage/wallet_db.ts +52 -67
- package/src/utils/authorizations.ts +3 -1
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +88 -178
- package/src/utils/options/options.ts +3 -2
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +290 -0
- 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 -43
- package/dest/utils/accounts.d.ts +0 -9
- package/dest/utils/accounts.d.ts.map +0 -1
- package/dest/utils/accounts.js +0 -61
- package/dest/utils/pxe_wrapper.d.ts +0 -12
- package/dest/utils/pxe_wrapper.d.ts.map +0 -1
- package/dest/utils/pxe_wrapper.js +0 -26
- package/src/cmds/cancel_tx.ts +0 -66
- package/src/utils/accounts.ts +0 -77
- package/src/utils/pxe_wrapper.ts +0 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli-wallet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6-commit.a2d1860fe9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/cmds/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"start": "node --no-warnings ./dest/bin",
|
|
21
21
|
"start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin",
|
|
22
22
|
"dev": "LOG_LEVEL=debug && node ./dest/bin",
|
|
23
|
-
"build": "yarn clean && tsc
|
|
24
|
-
"build:dev": "tsc
|
|
23
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
24
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
25
25
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
26
26
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
27
|
},
|
|
@@ -67,17 +67,19 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/accounts": "0.0.
|
|
71
|
-
"@aztec/aztec.js": "0.0.
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
76
|
-
"@aztec/
|
|
77
|
-
"@aztec/
|
|
78
|
-
"@aztec/noir-
|
|
79
|
-
"@aztec/
|
|
80
|
-
"@aztec/
|
|
70
|
+
"@aztec/accounts": "0.0.6-commit.a2d1860fe9",
|
|
71
|
+
"@aztec/aztec.js": "0.0.6-commit.a2d1860fe9",
|
|
72
|
+
"@aztec/bb.js": "0.0.6-commit.a2d1860fe9",
|
|
73
|
+
"@aztec/cli": "0.0.6-commit.a2d1860fe9",
|
|
74
|
+
"@aztec/entrypoints": "0.0.6-commit.a2d1860fe9",
|
|
75
|
+
"@aztec/ethereum": "0.0.6-commit.a2d1860fe9",
|
|
76
|
+
"@aztec/foundation": "0.0.6-commit.a2d1860fe9",
|
|
77
|
+
"@aztec/kv-store": "0.0.6-commit.a2d1860fe9",
|
|
78
|
+
"@aztec/noir-contracts.js": "0.0.6-commit.a2d1860fe9",
|
|
79
|
+
"@aztec/noir-noirc_abi": "0.0.6-commit.a2d1860fe9",
|
|
80
|
+
"@aztec/pxe": "0.0.6-commit.a2d1860fe9",
|
|
81
|
+
"@aztec/stdlib": "0.0.6-commit.a2d1860fe9",
|
|
82
|
+
"@aztec/wallet-sdk": "0.0.6-commit.a2d1860fe9",
|
|
81
83
|
"commander": "^12.1.0",
|
|
82
84
|
"inquirer": "^10.1.8",
|
|
83
85
|
"source-map-support": "^0.5.21",
|
|
@@ -88,6 +90,7 @@
|
|
|
88
90
|
"@types/jest": "^30.0.0",
|
|
89
91
|
"@types/node": "^22.15.17",
|
|
90
92
|
"@types/source-map-support": "^0.5.10",
|
|
93
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
91
94
|
"jest": "^30.0.0",
|
|
92
95
|
"jest-mock-extended": "^4.0.0",
|
|
93
96
|
"ts-jest": "^29.4.0",
|
package/src/bin/index.ts
CHANGED
|
@@ -1,25 +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';
|
|
6
11
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
7
12
|
|
|
8
13
|
import { Argument, Command, Option } from 'commander';
|
|
9
|
-
import { mkdirSync } from 'fs';
|
|
10
14
|
import { homedir } from 'os';
|
|
11
|
-
import {
|
|
15
|
+
import { join } from 'path';
|
|
12
16
|
|
|
13
17
|
import { injectCommands } from '../cmds/index.js';
|
|
14
18
|
import { Aliases, WalletDB } from '../storage/wallet_db.js';
|
|
19
|
+
import { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
15
20
|
import { createAliasOption } from '../utils/options/index.js';
|
|
16
|
-
import {
|
|
21
|
+
import { CLIWallet } from '../utils/wallet.js';
|
|
17
22
|
|
|
18
23
|
const userLog = createConsoleLogger();
|
|
19
24
|
const debugLogger = createLogger('wallet');
|
|
20
25
|
|
|
21
26
|
const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet') } = process.env;
|
|
22
27
|
|
|
28
|
+
// TODO: This function is only used in 1 place so we could just inline this
|
|
23
29
|
function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
24
30
|
program
|
|
25
31
|
.command('alias')
|
|
@@ -70,7 +76,7 @@ async function main() {
|
|
|
70
76
|
const walletVersion = getPackageVersion() ?? '0.0.0';
|
|
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
|
|
@@ -78,45 +84,45 @@ async function main() {
|
|
|
78
84
|
.version(walletVersion)
|
|
79
85
|
.option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
|
|
80
86
|
.addOption(
|
|
81
|
-
new Option('-p, --prover <string>', 'The type of prover the wallet uses
|
|
87
|
+
new Option('-p, --prover <string>', 'The type of prover the wallet uses')
|
|
82
88
|
.choices(['wasm', 'native', 'none'])
|
|
83
89
|
.env('PXE_PROVER')
|
|
84
90
|
.default('native'),
|
|
85
91
|
)
|
|
86
|
-
.addOption(
|
|
87
|
-
new Option('--remote-pxe', 'Connect to an external PXE RPC server instead of the local one')
|
|
88
|
-
.env('REMOTE_PXE')
|
|
89
|
-
.default(false)
|
|
90
|
-
.conflicts('rpc-url'),
|
|
91
|
-
)
|
|
92
92
|
.addOption(
|
|
93
93
|
new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to')
|
|
94
94
|
.env('AZTEC_NODE_URL')
|
|
95
95
|
.default(`http://${LOCALHOST}:8080`),
|
|
96
96
|
)
|
|
97
97
|
.hook('preSubcommand', async command => {
|
|
98
|
-
|
|
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();
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
debugLogger.info('Using local PXE service');
|
|
105
|
+
const proverEnabled = prover !== 'none';
|
|
102
106
|
|
|
103
|
-
|
|
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
|
+
}
|
|
104
115
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const bbWorkingDirectory = dataDir + '/bb';
|
|
110
|
-
mkdirSync(bbWorkingDirectory, { recursive: true });
|
|
116
|
+
const overridePXEConfig: Partial<PXEConfig> = {
|
|
117
|
+
proverEnabled,
|
|
118
|
+
dataDirectory: join(dataDir, 'pxe'),
|
|
119
|
+
};
|
|
111
120
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
121
|
+
const node = createAztecNodeClient(nodeUrl);
|
|
122
|
+
const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
|
|
123
|
+
|
|
124
|
+
walletAndNodeWrapper.setNodeAndWallet(node, wallet);
|
|
117
125
|
|
|
118
|
-
pxeWrapper.prepare(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
|
|
119
|
-
}
|
|
120
126
|
await db.init(await openStoreAt(dataDir));
|
|
121
127
|
let protocolContractsRegistered;
|
|
122
128
|
try {
|
|
@@ -137,9 +143,11 @@ async function main() {
|
|
|
137
143
|
}
|
|
138
144
|
});
|
|
139
145
|
|
|
140
|
-
injectCommands(program, userLog, debugLogger,
|
|
146
|
+
injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
|
|
141
147
|
injectInternalCommands(program, userLog, db);
|
|
142
148
|
await program.parseAsync(process.argv);
|
|
149
|
+
|
|
150
|
+
await Barretenberg.destroySingleton();
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
main().catch(err => {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { SetPublicAuthwitContractInteraction } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { Contract } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
2
5
|
import { prepTx } from '@aztec/cli/utils';
|
|
3
6
|
import type { LogFn } from '@aztec/foundation/log';
|
|
4
7
|
|
|
5
|
-
import { DEFAULT_TX_TIMEOUT_S } from '../utils/
|
|
8
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
6
9
|
|
|
7
10
|
export async function authorizeAction(
|
|
8
|
-
wallet:
|
|
11
|
+
wallet: Wallet,
|
|
9
12
|
from: AztecAddress,
|
|
10
13
|
functionName: string,
|
|
11
14
|
caller: AztecAddress,
|
|
@@ -27,11 +30,16 @@ export async function authorizeAction(
|
|
|
27
30
|
);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
const contract =
|
|
33
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
31
34
|
const action = contract.methods[functionName](...functionArgs);
|
|
32
35
|
|
|
33
|
-
const setAuthwitnessInteraction = await
|
|
34
|
-
|
|
36
|
+
const setAuthwitnessInteraction = await SetPublicAuthwitContractInteraction.create(
|
|
37
|
+
wallet,
|
|
38
|
+
from,
|
|
39
|
+
{ caller, action },
|
|
40
|
+
true,
|
|
41
|
+
);
|
|
42
|
+
const witness = await setAuthwitnessInteraction.send({ wait: { timeout: DEFAULT_TX_TIMEOUT_S } });
|
|
35
43
|
|
|
36
44
|
log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
|
|
37
45
|
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { L1FeeJuicePortalManager
|
|
1
|
+
import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
2
4
|
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
3
|
-
import { createEthereumChain
|
|
4
|
-
import {
|
|
5
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
6
|
+
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
8
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
6
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
+
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
7
11
|
|
|
8
12
|
export async function bridgeL1FeeJuice(
|
|
9
13
|
amount: bigint,
|
|
10
14
|
recipient: AztecAddress,
|
|
11
|
-
|
|
15
|
+
node: AztecNode,
|
|
12
16
|
l1RpcUrls: string[],
|
|
13
17
|
chainId: number,
|
|
14
18
|
privateKey: string | undefined,
|
|
@@ -24,12 +28,8 @@ export async function bridgeL1FeeJuice(
|
|
|
24
28
|
const chain = createEthereumChain(l1RpcUrls, chainId);
|
|
25
29
|
const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
|
|
26
30
|
|
|
27
|
-
const {
|
|
28
|
-
protocolContractAddresses: { feeJuice: feeJuiceAddress },
|
|
29
|
-
} = await pxe.getPXEInfo();
|
|
30
|
-
|
|
31
31
|
// Setup portal manager
|
|
32
|
-
const portal = await L1FeeJuicePortalManager.new(
|
|
32
|
+
const portal = await L1FeeJuicePortalManager.new(node, client, debugLogger);
|
|
33
33
|
const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(
|
|
34
34
|
recipient,
|
|
35
35
|
amount,
|
|
@@ -66,8 +66,12 @@ export async function bridgeL1FeeJuice(
|
|
|
66
66
|
const delayedCheck = (delay: number) => {
|
|
67
67
|
return new Promise((resolve, reject) => {
|
|
68
68
|
setTimeout(() => {
|
|
69
|
-
void
|
|
70
|
-
|
|
69
|
+
void getNonNullifiedL1ToL2MessageWitness(
|
|
70
|
+
node,
|
|
71
|
+
ProtocolContractAddress.FeeJuice,
|
|
72
|
+
Fr.fromHexString(messageHash),
|
|
73
|
+
claimSecret,
|
|
74
|
+
)
|
|
71
75
|
.then(witness => resolve(witness))
|
|
72
76
|
.catch(err => reject(err));
|
|
73
77
|
}, delay);
|
package/src/cmds/check_tx.ts
CHANGED
|
@@ -1,12 +1,187 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
|
+
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
6
|
+
import type { TxHash } from '@aztec/aztec.js/tx';
|
|
3
7
|
import type { LogFn } from '@aztec/foundation/log';
|
|
8
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
9
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
import type { CLIWallet } from '../utils/wallet.js';
|
|
12
|
+
|
|
13
|
+
export async function checkTx(
|
|
14
|
+
wallet: CLIWallet,
|
|
15
|
+
aztecNode: AztecNode,
|
|
16
|
+
txHash: TxHash,
|
|
17
|
+
statusOnly: boolean,
|
|
18
|
+
log: LogFn,
|
|
19
|
+
) {
|
|
6
20
|
if (statusOnly) {
|
|
7
|
-
const receipt = await
|
|
21
|
+
const receipt = await aztecNode.getTxReceipt(txHash);
|
|
8
22
|
return receipt.status;
|
|
9
23
|
} else {
|
|
10
|
-
await inspectTx(
|
|
24
|
+
await inspectTx(wallet, aztecNode, txHash, log);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// The rest of the code here was copied over here from CLI because in CLI I needed to prune the inspect function of the PXE
|
|
29
|
+
// dependency when dropping PXE JSON RPC Server.
|
|
30
|
+
|
|
31
|
+
async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
|
|
32
|
+
const [receipt, effectsInBlock] = await Promise.all([aztecNode.getTxReceipt(txHash), aztecNode.getTxEffect(txHash)]);
|
|
33
|
+
// Base tx data
|
|
34
|
+
log(`Tx ${txHash.toString()}`);
|
|
35
|
+
log(` Status: ${receipt.status}`);
|
|
36
|
+
if (receipt.executionResult) {
|
|
37
|
+
log(` Execution result: ${receipt.executionResult}`);
|
|
38
|
+
}
|
|
39
|
+
if (receipt.error) {
|
|
40
|
+
log(` Error: ${receipt.error}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!effectsInBlock) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const effects = effectsInBlock.data;
|
|
48
|
+
const artifactMap = await getKnownArtifacts(wallet);
|
|
49
|
+
|
|
50
|
+
log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
|
|
51
|
+
if (receipt.transactionFee) {
|
|
52
|
+
log(` Fee: ${receipt.transactionFee.toString()}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Public logs
|
|
56
|
+
const publicLogs = effects.publicLogs;
|
|
57
|
+
if (publicLogs.length > 0) {
|
|
58
|
+
log(' Logs:');
|
|
59
|
+
for (const publicLog of publicLogs) {
|
|
60
|
+
log(` ${publicLog.toHumanReadable()}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Public data writes
|
|
65
|
+
const writes = effects.publicDataWrites;
|
|
66
|
+
if (writes.length > 0) {
|
|
67
|
+
log(' Public data writes:');
|
|
68
|
+
for (const write of writes) {
|
|
69
|
+
log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Created notes
|
|
74
|
+
const notes = effects.noteHashes;
|
|
75
|
+
if (notes.length > 0) {
|
|
76
|
+
log(' Created notes:');
|
|
77
|
+
log(` Total: ${notes.length}`);
|
|
78
|
+
for (const note of notes) {
|
|
79
|
+
log(` Note hash: ${note.toShortString()}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Nullifiers
|
|
84
|
+
const nullifierCount = effects.nullifiers.length;
|
|
85
|
+
const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
|
|
86
|
+
if (nullifierCount > 0) {
|
|
87
|
+
log(' Nullifiers:');
|
|
88
|
+
for (const nullifier of effects.nullifiers) {
|
|
89
|
+
const deployed = deployNullifiers[nullifier.toString()];
|
|
90
|
+
const note = deployed
|
|
91
|
+
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed, scopes: 'ALL_SCOPES' }))[0]
|
|
92
|
+
: undefined;
|
|
93
|
+
const initialized = initNullifiers[nullifier.toString()];
|
|
94
|
+
const registered = classNullifiers[nullifier.toString()];
|
|
95
|
+
if (nullifier.toBuffer().equals(txHash.toBuffer())) {
|
|
96
|
+
log(` Transaction hash nullifier ${nullifier.toShortString()}`);
|
|
97
|
+
} else if (note) {
|
|
98
|
+
inspectNote(note, artifactMap, log, `Nullifier ${nullifier.toShortString()} for note`);
|
|
99
|
+
} else if (deployed) {
|
|
100
|
+
log(
|
|
101
|
+
` Contract ${toFriendlyAddress(deployed, artifactMap)} deployed via nullifier ${nullifier.toShortString()}`,
|
|
102
|
+
);
|
|
103
|
+
} else if (initialized) {
|
|
104
|
+
log(
|
|
105
|
+
` Contract ${toFriendlyAddress(
|
|
106
|
+
initialized,
|
|
107
|
+
artifactMap,
|
|
108
|
+
)} initialized via nullifier ${nullifier.toShortString()}`,
|
|
109
|
+
);
|
|
110
|
+
} else if (registered) {
|
|
111
|
+
log(` Class ${registered} registered via nullifier ${nullifier.toShortString()}`);
|
|
112
|
+
} else {
|
|
113
|
+
log(` Unknown nullifier ${nullifier.toString()}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// L2 to L1 messages
|
|
119
|
+
if (effects.l2ToL1Msgs.length > 0) {
|
|
120
|
+
log(` L2 to L1 messages:`);
|
|
121
|
+
for (const msg of effects.l2ToL1Msgs) {
|
|
122
|
+
log(` ${msg.toString()}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function inspectNote(note: NoteDao, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
|
|
128
|
+
const artifact = artifactMap[note.contractAddress.toString()];
|
|
129
|
+
const contract = artifact?.name ?? note.contractAddress.toString();
|
|
130
|
+
log(` ${text} at ${contract}`);
|
|
131
|
+
for (const field of note.note.items) {
|
|
132
|
+
log(` ${field.toString()}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
|
|
137
|
+
const artifact = artifactMap[address.toString()];
|
|
138
|
+
if (!artifact) {
|
|
139
|
+
return address.toString();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return `${artifact.name}<${address.toString()}>`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
|
|
146
|
+
const knownContracts = await wallet.getContracts();
|
|
147
|
+
const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
|
|
148
|
+
const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
|
|
149
|
+
const initNullifiers: Record<string, AztecAddress> = {};
|
|
150
|
+
const deployNullifiers: Record<string, AztecAddress> = {};
|
|
151
|
+
const classNullifiers: Record<string, string> = {};
|
|
152
|
+
for (const contract of knownContracts) {
|
|
153
|
+
initNullifiers[(await siloNullifier(contract, contract.toField())).toString()] = contract;
|
|
154
|
+
deployNullifiers[(await siloNullifier(deployerAddress, contract.toField())).toString()] = contract;
|
|
155
|
+
}
|
|
156
|
+
for (const artifact of Object.values(artifactMap)) {
|
|
157
|
+
classNullifiers[(await siloNullifier(classRegistryAddress, artifact.classId)).toString()] =
|
|
158
|
+
`${artifact.name}Class<${artifact.classId}>`;
|
|
159
|
+
}
|
|
160
|
+
return { initNullifiers, deployNullifiers, classNullifiers };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
type ArtifactMap = Record<string, ContractArtifactWithClassId>;
|
|
164
|
+
type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
|
|
165
|
+
|
|
166
|
+
async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
|
|
167
|
+
const knownContractAddresses = await wallet.getContracts();
|
|
168
|
+
const knownContracts = (
|
|
169
|
+
await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
|
|
170
|
+
).map(contractMetadata => contractMetadata.instance);
|
|
171
|
+
const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
|
|
172
|
+
const knownArtifacts = (
|
|
173
|
+
await Promise.all(classIds.map(classId => (classId ? wallet.getContractArtifact(classId) : undefined)))
|
|
174
|
+
).map((artifact, index) => (artifact ? { ...artifact, classId: classIds[index] } : undefined));
|
|
175
|
+
const map: Record<string, ContractArtifactWithClassId> = {};
|
|
176
|
+
for (const instance of knownContracts) {
|
|
177
|
+
if (instance) {
|
|
178
|
+
const artifact = knownArtifacts.find(a =>
|
|
179
|
+
a?.classId?.equals(instance.currentContractClassId),
|
|
180
|
+
) as ContractArtifactWithClassId;
|
|
181
|
+
if (artifact) {
|
|
182
|
+
map[instance.address.toString()] = artifact;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
11
185
|
}
|
|
186
|
+
return map;
|
|
12
187
|
}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
import { AztecAddress
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
4
|
+
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
2
5
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
7
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
8
|
+
import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
5
9
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
10
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
11
|
+
import type { AccountType } from '../utils/constants.js';
|
|
12
|
+
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
8
13
|
import { printProfileResult } from '../utils/profiling.js';
|
|
9
|
-
import {
|
|
14
|
+
import { CLIWallet } from '../utils/wallet.js';
|
|
10
15
|
|
|
11
16
|
export async function createAccount(
|
|
12
|
-
|
|
17
|
+
wallet: CLIWallet,
|
|
18
|
+
aztecNode: AztecNode,
|
|
13
19
|
accountType: AccountType,
|
|
14
20
|
secretKey: Fr | undefined,
|
|
15
21
|
publicKey: string | undefined,
|
|
16
22
|
alias: string | undefined,
|
|
23
|
+
deployer: AztecAddress | undefined,
|
|
17
24
|
registerOnly: boolean,
|
|
18
|
-
publicDeploy: boolean,
|
|
19
25
|
skipInitialization: boolean,
|
|
26
|
+
publicDeploy: boolean,
|
|
27
|
+
registerClass: boolean,
|
|
20
28
|
wait: boolean,
|
|
21
|
-
feeOpts:
|
|
29
|
+
feeOpts: CLIFeeArgs,
|
|
22
30
|
json: boolean,
|
|
23
31
|
verbose: boolean,
|
|
24
32
|
debugLogger: Logger,
|
|
@@ -26,10 +34,8 @@ export async function createAccount(
|
|
|
26
34
|
) {
|
|
27
35
|
secretKey ??= Fr.random();
|
|
28
36
|
|
|
29
|
-
const account = await createOrRetrieveAccount(
|
|
30
|
-
client,
|
|
37
|
+
const account = await wallet.createOrRetrieveAccount(
|
|
31
38
|
undefined /* address, we don't have it yet */,
|
|
32
|
-
undefined /* db, as we want to create from scratch */,
|
|
33
39
|
secretKey,
|
|
34
40
|
accountType,
|
|
35
41
|
Fr.ZERO,
|
|
@@ -48,7 +54,6 @@ export async function createAccount(
|
|
|
48
54
|
out.partialAddress = partialAddress;
|
|
49
55
|
out.salt = salt;
|
|
50
56
|
out.initHash = account.getInstance().initializationHash;
|
|
51
|
-
out.deployer = account.getInstance().deployer;
|
|
52
57
|
} else {
|
|
53
58
|
log(`\nNew account:\n`);
|
|
54
59
|
log(`Address: ${address.toString()}`);
|
|
@@ -59,90 +64,82 @@ export async function createAccount(
|
|
|
59
64
|
log(`Partial address: ${partialAddress.toString()}`);
|
|
60
65
|
log(`Salt: ${salt.toString()}`);
|
|
61
66
|
log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
|
|
62
|
-
log(`Deployer: ${account.getInstance().deployer.toString()}`);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
let
|
|
66
|
-
let txReceipt;
|
|
67
|
-
if (registerOnly) {
|
|
68
|
-
await
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
69
|
+
let txHash: TxHash | undefined;
|
|
70
|
+
let txReceipt: TxReceipt | undefined;
|
|
71
|
+
if (!registerOnly) {
|
|
72
|
+
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
73
|
+
|
|
74
|
+
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
75
|
+
const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
|
|
76
|
+
|
|
77
|
+
const deployAccountOpts: DeployAccountOptions = {
|
|
78
|
+
skipClassPublication: !registerClass,
|
|
73
79
|
skipInstancePublication: !publicDeploy,
|
|
74
|
-
skipInitialization
|
|
75
|
-
|
|
80
|
+
skipInitialization,
|
|
81
|
+
from,
|
|
82
|
+
fee: { paymentMethod, gasSettings },
|
|
76
83
|
};
|
|
77
|
-
/*
|
|
78
|
-
* This is usually handled by accountManager.create(), but we're accessing the lower
|
|
79
|
-
* level method to get gas and timings. That means we have to replicate some of the logic here.
|
|
80
|
-
* In case we're initializing and/or publishing our own account, we need to hijack the payment method for the fee,
|
|
81
|
-
* wrapping it in the one that will make use of the freshly deployed account's
|
|
82
|
-
* entrypoint. For reference, see aztec.js/src/account_manager.ts:sendAccountContractSetupTx()
|
|
83
|
-
* Also, salt and universalDeploy have to be explicitly provided
|
|
84
|
-
*/
|
|
85
|
-
deployOpts.fee =
|
|
86
|
-
!deployOpts?.deployWallet && deployOpts?.fee
|
|
87
|
-
? { ...deployOpts.fee, paymentMethod: await account.getSelfPaymentMethod(deployOpts.fee.paymentMethod) }
|
|
88
|
-
: deployOpts?.fee;
|
|
89
84
|
|
|
90
|
-
const deployMethod = await account.getDeployMethod(
|
|
85
|
+
const deployMethod = await account.getDeployMethod();
|
|
86
|
+
const { estimatedGas, stats } = await deployMethod.simulate({
|
|
87
|
+
...deployAccountOpts,
|
|
88
|
+
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
89
|
+
});
|
|
91
90
|
|
|
92
91
|
if (feeOpts.estimateOnly) {
|
|
93
|
-
const gas = await deployMethod.estimateGas({
|
|
94
|
-
...deployOpts,
|
|
95
|
-
from: AztecAddress.ZERO,
|
|
96
|
-
universalDeploy: true,
|
|
97
|
-
contractAddressSalt: salt,
|
|
98
|
-
});
|
|
99
92
|
if (json) {
|
|
100
93
|
out.fee = {
|
|
101
94
|
gasLimits: {
|
|
102
|
-
da:
|
|
103
|
-
l2:
|
|
95
|
+
da: estimatedGas.gasLimits.daGas,
|
|
96
|
+
l2: estimatedGas.gasLimits.l2Gas,
|
|
104
97
|
},
|
|
105
98
|
teardownGasLimits: {
|
|
106
|
-
da:
|
|
107
|
-
l2:
|
|
99
|
+
da: estimatedGas.teardownGasLimits.daGas,
|
|
100
|
+
l2: estimatedGas.teardownGasLimits,
|
|
108
101
|
},
|
|
109
102
|
};
|
|
110
|
-
} else {
|
|
111
|
-
printGasEstimates(feeOpts, gas, log);
|
|
112
103
|
}
|
|
113
104
|
} else {
|
|
114
|
-
const provenTx = await deployMethod.prove({
|
|
115
|
-
...deployOpts,
|
|
116
|
-
from: AztecAddress.ZERO,
|
|
117
|
-
universalDeploy: true,
|
|
118
|
-
contractAddressSalt: salt,
|
|
119
|
-
});
|
|
120
105
|
if (verbose) {
|
|
121
|
-
printProfileResult(
|
|
106
|
+
printProfileResult(stats, log);
|
|
122
107
|
}
|
|
123
|
-
tx = provenTx.send();
|
|
124
108
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
109
|
+
if (!json) {
|
|
110
|
+
log(`\nWaiting for account contract deployment...`);
|
|
111
|
+
}
|
|
112
|
+
const result = await deployMethod.send({
|
|
113
|
+
...deployAccountOpts,
|
|
114
|
+
fee: deployAccountOpts.fee
|
|
115
|
+
? {
|
|
116
|
+
...deployAccountOpts.fee,
|
|
117
|
+
gasSettings: estimatedGas,
|
|
118
|
+
}
|
|
119
|
+
: undefined,
|
|
120
|
+
wait: wait ? { timeout: DEFAULT_TX_TIMEOUT_S, returnReceipt: true } : NO_WAIT,
|
|
121
|
+
});
|
|
122
|
+
const isReceipt = (data: TxReceipt | TxHash): data is TxReceipt => 'txHash' in data;
|
|
123
|
+
if (isReceipt(result)) {
|
|
124
|
+
txReceipt = result;
|
|
125
|
+
txHash = result.txHash;
|
|
133
126
|
out.txReceipt = {
|
|
134
127
|
status: txReceipt.status,
|
|
135
128
|
transactionFee: txReceipt.transactionFee,
|
|
136
129
|
};
|
|
130
|
+
} else {
|
|
131
|
+
txHash = result;
|
|
137
132
|
}
|
|
133
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
134
|
+
out.txHash = txHash;
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
if (json) {
|
|
142
139
|
log(prettyPrintJSON(out));
|
|
143
140
|
} else {
|
|
144
|
-
if (
|
|
145
|
-
log(`Deploy tx hash: ${
|
|
141
|
+
if (txHash) {
|
|
142
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
146
143
|
}
|
|
147
144
|
if (txReceipt) {
|
|
148
145
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|