@aztec/cli-wallet 3.0.0-canary.a9708bd → 3.0.0-devnet.3
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.js +28 -22
- package/dest/cmds/authorize_action.d.ts +3 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +5 -6
- package/dest/cmds/bridge_fee_juice.d.ts +2 -2
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +6 -5
- package/dest/cmds/check_tx.d.ts +4 -2
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +145 -6
- package/dest/cmds/create_account.d.ts +5 -4
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +35 -47
- package/dest/cmds/create_authwit.d.ts +3 -2
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/create_authwit.js +5 -5
- package/dest/cmds/deploy.d.ts +6 -3
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +57 -46
- package/dest/cmds/deploy_account.d.ts +5 -7
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +36 -51
- package/dest/cmds/import_test_accounts.d.ts +2 -2
- 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 +2 -2
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +73 -112
- package/dest/cmds/profile.d.ts +6 -3
- package/dest/cmds/profile.d.ts.map +1 -1
- package/dest/cmds/profile.js +8 -3
- package/dest/cmds/register_contract.d.ts +6 -2
- 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 +3 -2
- package/dest/cmds/register_sender.d.ts.map +1 -1
- package/dest/cmds/send.d.ts +7 -8
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +26 -23
- package/dest/cmds/simulate.d.ts +6 -3
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +8 -3
- package/dest/storage/wallet_db.d.ts +2 -12
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +1 -22
- package/dest/utils/authorizations.d.ts +2 -1
- 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/options/fees.d.ts +20 -27
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +65 -132
- package/dest/utils/options/options.d.ts +2 -1
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/wallet.d.ts +35 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +193 -0
- package/package.json +12 -12
- package/src/bin/index.ts +30 -29
- package/src/cmds/authorize_action.ts +13 -5
- package/src/cmds/bridge_fee_juice.ts +12 -9
- package/src/cmds/check_tx.ts +182 -5
- package/src/cmds/create_account.ts +42 -52
- package/src/cmds/create_authwit.ts +8 -4
- package/src/cmds/deploy.ts +58 -56
- package/src/cmds/deploy_account.ts +43 -51
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +120 -206
- package/src/cmds/profile.ts +13 -5
- package/src/cmds/register_contract.ts +9 -11
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +21 -31
- package/src/cmds/simulate.ts +13 -5
- package/src/storage/wallet_db.ts +2 -30
- package/src/utils/authorizations.ts +3 -1
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/options/fees.ts +86 -177
- package/src/utils/options/options.ts +3 -2
- package/src/utils/wallet.ts +264 -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
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
|
+
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
|
+
import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
|
|
4
|
+
import { getIdentities } from '@aztec/accounts/utils';
|
|
5
|
+
import { SignerlessAccount } from '@aztec/aztec.js/account';
|
|
6
|
+
import { getContractInstanceFromInstantiationParams, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
7
|
+
import { AccountManager, BaseWallet } from '@aztec/aztec.js/wallet';
|
|
8
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
|
|
9
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
10
|
+
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
13
|
+
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
14
|
+
import { printGasEstimates } from './options/fees.js';
|
|
15
|
+
export const AccountTypes = [
|
|
16
|
+
'schnorr',
|
|
17
|
+
'ecdsasecp256r1',
|
|
18
|
+
'ecdsasecp256r1ssh',
|
|
19
|
+
'ecdsasecp256k1'
|
|
20
|
+
];
|
|
21
|
+
export const BASE_FEE_PADDING = 0.5;
|
|
22
|
+
export class CLIWallet extends BaseWallet {
|
|
23
|
+
userLog;
|
|
24
|
+
db;
|
|
25
|
+
accountCache;
|
|
26
|
+
constructor(pxe, node, userLog, db){
|
|
27
|
+
super(pxe, node), this.userLog = userLog, this.db = db, this.accountCache = new Map();
|
|
28
|
+
this.cancellableTransactions = true;
|
|
29
|
+
}
|
|
30
|
+
static async create(node, log, db, overridePXEConfig) {
|
|
31
|
+
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
32
|
+
const pxe = await createPXE(node, pxeConfig);
|
|
33
|
+
return new CLIWallet(pxe, node, log, db);
|
|
34
|
+
}
|
|
35
|
+
async getAccounts() {
|
|
36
|
+
const accounts = await this.db?.listAliases('accounts') ?? [];
|
|
37
|
+
return Promise.resolve(accounts.map(({ key, value })=>({
|
|
38
|
+
alias: value,
|
|
39
|
+
item: AztecAddress.fromString(key)
|
|
40
|
+
})));
|
|
41
|
+
}
|
|
42
|
+
async createCancellationTxExecutionRequest(from, txNonce, increasedFee) {
|
|
43
|
+
const feeOptions = await this.getDefaultFeeOptions(from, increasedFee);
|
|
44
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
45
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
46
|
+
const executionOptions = {
|
|
47
|
+
txNonce,
|
|
48
|
+
cancellable: this.cancellableTransactions,
|
|
49
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
50
|
+
};
|
|
51
|
+
return await fromAccount.createTxExecutionRequest(feeExecutionPayload ?? ExecutionPayload.empty(), feeOptions.gasSettings, executionOptions);
|
|
52
|
+
}
|
|
53
|
+
async proveCancellationTx(from, txNonce, increasedFee) {
|
|
54
|
+
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
55
|
+
return await this.pxe.proveTx(cancellationTxRequest);
|
|
56
|
+
}
|
|
57
|
+
async getAccountFromAddress(address) {
|
|
58
|
+
let account;
|
|
59
|
+
if (address.equals(AztecAddress.ZERO)) {
|
|
60
|
+
const chainInfo = await this.getChainInfo();
|
|
61
|
+
account = new SignerlessAccount(chainInfo);
|
|
62
|
+
} else if (this.accountCache.has(address.toString())) {
|
|
63
|
+
return this.accountCache.get(address.toString());
|
|
64
|
+
} else {
|
|
65
|
+
const accountManager = await this.createOrRetrieveAccount(address);
|
|
66
|
+
account = await accountManager.getAccount();
|
|
67
|
+
}
|
|
68
|
+
if (!account) {
|
|
69
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
70
|
+
}
|
|
71
|
+
return account;
|
|
72
|
+
}
|
|
73
|
+
async createAccount(secret, salt, contract) {
|
|
74
|
+
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
75
|
+
const instance = accountManager.getInstance();
|
|
76
|
+
const artifact = await contract.getContractArtifact();
|
|
77
|
+
await this.registerContract(instance, artifact, secret);
|
|
78
|
+
this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
79
|
+
return accountManager;
|
|
80
|
+
}
|
|
81
|
+
async createOrRetrieveAccount(address, secretKey, type = 'schnorr', salt, publicKey) {
|
|
82
|
+
let account;
|
|
83
|
+
salt ??= Fr.ZERO;
|
|
84
|
+
if (this.db && address) {
|
|
85
|
+
({ type, secretKey, salt } = await this.db.retrieveAccount(address));
|
|
86
|
+
}
|
|
87
|
+
if (!secretKey) {
|
|
88
|
+
throw new Error('Cannot retrieve/create wallet without secret key');
|
|
89
|
+
}
|
|
90
|
+
switch(type){
|
|
91
|
+
case 'schnorr':
|
|
92
|
+
{
|
|
93
|
+
account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'ecdsasecp256r1':
|
|
97
|
+
{
|
|
98
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()));
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'ecdsasecp256r1ssh':
|
|
102
|
+
{
|
|
103
|
+
let publicSigningKey;
|
|
104
|
+
if (this.db && address) {
|
|
105
|
+
publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
|
|
106
|
+
} else if (publicKey) {
|
|
107
|
+
const identities = await getIdentities();
|
|
108
|
+
const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
|
|
109
|
+
if (!foundIdentity) {
|
|
110
|
+
throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
|
|
111
|
+
}
|
|
112
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
|
|
113
|
+
} else {
|
|
114
|
+
throw new Error('Public key must be provided for ECDSA SSH account');
|
|
115
|
+
}
|
|
116
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
{
|
|
121
|
+
throw new Error(`Unsupported account type: ${type}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return account;
|
|
125
|
+
}
|
|
126
|
+
async getFakeAccountDataFor(address) {
|
|
127
|
+
const chainInfo = await this.getChainInfo();
|
|
128
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
129
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
130
|
+
const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
|
|
131
|
+
if (!contractInstance) {
|
|
132
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
133
|
+
}
|
|
134
|
+
const stubAccount = createStubAccount(originalAddress, chainInfo);
|
|
135
|
+
const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
136
|
+
salt: Fr.random()
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
account: stubAccount,
|
|
140
|
+
instance,
|
|
141
|
+
artifact: StubAccountContractArtifact
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async simulateTx(executionPayload, opts) {
|
|
145
|
+
let simulationResults;
|
|
146
|
+
const feeOptions = opts.fee?.estimateGas ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee) : await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
147
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
148
|
+
const executionOptions = {
|
|
149
|
+
txNonce: Fr.random(),
|
|
150
|
+
cancellable: this.cancellableTransactions,
|
|
151
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
152
|
+
};
|
|
153
|
+
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
154
|
+
feeExecutionPayload,
|
|
155
|
+
executionPayload
|
|
156
|
+
]) : executionPayload;
|
|
157
|
+
// Kernelless simulations using the multicall entrypoints are not currently supported,
|
|
158
|
+
// since we only override proper account contracts.
|
|
159
|
+
// TODO: allow disabling kernels even when no overrides are necessary
|
|
160
|
+
if (opts.from.equals(AztecAddress.ZERO)) {
|
|
161
|
+
const fromAccount = await this.getAccountFromAddress(opts.from);
|
|
162
|
+
const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
|
|
163
|
+
simulationResults = await this.pxe.simulateTx(txRequest, true, opts?.skipTxValidation, opts?.skipFeeEnforcement ?? true);
|
|
164
|
+
} else {
|
|
165
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
166
|
+
const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
|
|
167
|
+
const contractOverrides = {
|
|
168
|
+
[opts.from.toString()]: {
|
|
169
|
+
instance,
|
|
170
|
+
artifact
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
simulationResults = await this.pxe.simulateTx(txRequest, true, true, true, {
|
|
174
|
+
contracts: contractOverrides
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (opts.fee?.estimateGas) {
|
|
178
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
179
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
180
|
+
}
|
|
181
|
+
return simulationResults;
|
|
182
|
+
}
|
|
183
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
184
|
+
// this is just a CLI wallet.
|
|
185
|
+
getContracts() {
|
|
186
|
+
return this.pxe.getContracts();
|
|
187
|
+
}
|
|
188
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
189
|
+
// this is just a CLI wallet.
|
|
190
|
+
getNotes(filter) {
|
|
191
|
+
return this.pxe.getNotes(filter);
|
|
192
|
+
}
|
|
193
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli-wallet",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-devnet.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/cmds/index.js",
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/accounts": "3.0.0-
|
|
71
|
-
"@aztec/aztec.js": "3.0.0-
|
|
72
|
-
"@aztec/cli": "3.0.0-
|
|
73
|
-
"@aztec/entrypoints": "3.0.0-
|
|
74
|
-
"@aztec/ethereum": "3.0.0-
|
|
75
|
-
"@aztec/foundation": "3.0.0-
|
|
76
|
-
"@aztec/kv-store": "3.0.0-
|
|
77
|
-
"@aztec/noir-contracts.js": "3.0.0-
|
|
78
|
-
"@aztec/noir-noirc_abi": "3.0.0-
|
|
79
|
-
"@aztec/pxe": "3.0.0-
|
|
80
|
-
"@aztec/stdlib": "3.0.0-
|
|
70
|
+
"@aztec/accounts": "3.0.0-devnet.3",
|
|
71
|
+
"@aztec/aztec.js": "3.0.0-devnet.3",
|
|
72
|
+
"@aztec/cli": "3.0.0-devnet.3",
|
|
73
|
+
"@aztec/entrypoints": "3.0.0-devnet.3",
|
|
74
|
+
"@aztec/ethereum": "3.0.0-devnet.3",
|
|
75
|
+
"@aztec/foundation": "3.0.0-devnet.3",
|
|
76
|
+
"@aztec/kv-store": "3.0.0-devnet.3",
|
|
77
|
+
"@aztec/noir-contracts.js": "3.0.0-devnet.3",
|
|
78
|
+
"@aztec/noir-noirc_abi": "3.0.0-devnet.3",
|
|
79
|
+
"@aztec/pxe": "3.0.0-devnet.3",
|
|
80
|
+
"@aztec/stdlib": "3.0.0-devnet.3",
|
|
81
81
|
"commander": "^12.1.0",
|
|
82
82
|
"inquirer": "^10.1.8",
|
|
83
83
|
"source-map-support": "^0.5.21",
|
package/src/bin/index.ts
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computeSecretHash } from '@aztec/aztec.js/crypto';
|
|
2
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
+
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
4
|
+
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
2
5
|
import { LOCALHOST } from '@aztec/cli/cli-utils';
|
|
3
6
|
import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
4
7
|
import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
-
import type {
|
|
8
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
6
9
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
7
10
|
|
|
8
11
|
import { Argument, Command, Option } from 'commander';
|
|
9
12
|
import { mkdirSync } from 'fs';
|
|
10
13
|
import { homedir } from 'os';
|
|
11
14
|
import { dirname, join, resolve } from 'path';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
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,40 @@ 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
|
-
const { dataDir,
|
|
98
|
+
const { dataDir, nodeUrl, prover } = command.optsWithGlobals();
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
debugLogger.info('Using local PXE service');
|
|
100
|
+
const proverEnabled = prover !== 'none';
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
const bbBinaryPath =
|
|
103
|
+
prover === 'native'
|
|
104
|
+
? resolve(dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/cpp/build/bin/bb')
|
|
105
|
+
: undefined;
|
|
106
|
+
const bbWorkingDirectory = dataDir + '/bb';
|
|
107
|
+
mkdirSync(bbWorkingDirectory, { recursive: true });
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
const overridePXEConfig: Partial<PXEConfig> = {
|
|
110
|
+
proverEnabled,
|
|
111
|
+
bbBinaryPath: prover === 'native' ? bbBinaryPath : undefined,
|
|
112
|
+
bbWorkingDirectory: prover === 'native' ? bbWorkingDirectory : undefined,
|
|
113
|
+
dataDirectory: join(dataDir, 'pxe'),
|
|
114
|
+
};
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
116
|
+
const node = createAztecNodeClient(nodeUrl);
|
|
117
|
+
const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
|
|
118
|
+
|
|
119
|
+
walletAndNodeWrapper.setNodeAndWallet(node, wallet);
|
|
117
120
|
|
|
118
|
-
pxeWrapper.prepare(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
|
|
119
|
-
}
|
|
120
121
|
await db.init(await openStoreAt(dataDir));
|
|
121
122
|
let protocolContractsRegistered;
|
|
122
123
|
try {
|
|
@@ -137,7 +138,7 @@ async function main() {
|
|
|
137
138
|
}
|
|
138
139
|
});
|
|
139
140
|
|
|
140
|
-
injectCommands(program, userLog, debugLogger,
|
|
141
|
+
injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
|
|
141
142
|
injectInternalCommands(program, userLog, db);
|
|
142
143
|
await program.parseAsync(process.argv);
|
|
143
144
|
}
|
|
@@ -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,
|
|
@@ -30,8 +33,13 @@ export async function authorizeAction(
|
|
|
30
33
|
const contract = await 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,17 @@
|
|
|
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
5
|
import { createEthereumChain, createExtendedL1Client } from '@aztec/ethereum';
|
|
4
6
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
7
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
6
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
+
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
7
10
|
|
|
8
11
|
export async function bridgeL1FeeJuice(
|
|
9
12
|
amount: bigint,
|
|
10
13
|
recipient: AztecAddress,
|
|
11
|
-
|
|
14
|
+
node: AztecNode,
|
|
12
15
|
l1RpcUrls: string[],
|
|
13
16
|
chainId: number,
|
|
14
17
|
privateKey: string | undefined,
|
|
@@ -24,12 +27,8 @@ export async function bridgeL1FeeJuice(
|
|
|
24
27
|
const chain = createEthereumChain(l1RpcUrls, chainId);
|
|
25
28
|
const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
|
|
26
29
|
|
|
27
|
-
const {
|
|
28
|
-
protocolContractAddresses: { feeJuice: feeJuiceAddress },
|
|
29
|
-
} = await pxe.getPXEInfo();
|
|
30
|
-
|
|
31
30
|
// Setup portal manager
|
|
32
|
-
const portal = await L1FeeJuicePortalManager.new(
|
|
31
|
+
const portal = await L1FeeJuicePortalManager.new(node, client, debugLogger);
|
|
33
32
|
const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(
|
|
34
33
|
recipient,
|
|
35
34
|
amount,
|
|
@@ -66,8 +65,12 @@ export async function bridgeL1FeeJuice(
|
|
|
66
65
|
const delayedCheck = (delay: number) => {
|
|
67
66
|
return new Promise((resolve, reject) => {
|
|
68
67
|
setTimeout(() => {
|
|
69
|
-
void
|
|
70
|
-
|
|
68
|
+
void getNonNullifiedL1ToL2MessageWitness(
|
|
69
|
+
node,
|
|
70
|
+
ProtocolContractAddress.FeeJuice,
|
|
71
|
+
Fr.fromHexString(messageHash),
|
|
72
|
+
claimSecret,
|
|
73
|
+
)
|
|
71
74
|
.then(witness => resolve(witness))
|
|
72
75
|
.catch(err => reject(err));
|
|
73
76
|
}, delay);
|
package/src/cmds/check_tx.ts
CHANGED
|
@@ -1,12 +1,189 @@
|
|
|
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 { UniqueNote } 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} ${effectsInBlock ? `(${effectsInBlock.data.revertCode.getDescription()})` : ''}`);
|
|
36
|
+
if (receipt.error) {
|
|
37
|
+
log(` Error: ${receipt.error}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!effectsInBlock) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const effects = effectsInBlock.data;
|
|
45
|
+
const artifactMap = await getKnownArtifacts(wallet);
|
|
46
|
+
|
|
47
|
+
log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
|
|
48
|
+
if (receipt.transactionFee) {
|
|
49
|
+
log(` Fee: ${receipt.transactionFee.toString()}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Public logs
|
|
53
|
+
const publicLogs = effects.publicLogs;
|
|
54
|
+
if (publicLogs.length > 0) {
|
|
55
|
+
log(' Logs:');
|
|
56
|
+
for (const publicLog of publicLogs) {
|
|
57
|
+
log(` ${publicLog.toHumanReadable()}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Public data writes
|
|
62
|
+
const writes = effects.publicDataWrites;
|
|
63
|
+
if (writes.length > 0) {
|
|
64
|
+
log(' Public data writes:');
|
|
65
|
+
for (const write of writes) {
|
|
66
|
+
log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Created notes
|
|
71
|
+
const notes = effects.noteHashes;
|
|
72
|
+
if (notes.length > 0) {
|
|
73
|
+
log(' Created notes:');
|
|
74
|
+
log(` Total: ${notes.length}`);
|
|
75
|
+
for (const note of notes) {
|
|
76
|
+
log(` Note hash: ${note.toShortString()}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Nullifiers
|
|
81
|
+
const nullifierCount = effects.nullifiers.length;
|
|
82
|
+
const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
|
|
83
|
+
if (nullifierCount > 0) {
|
|
84
|
+
log(' Nullifiers:');
|
|
85
|
+
for (const nullifier of effects.nullifiers) {
|
|
86
|
+
const deployed = deployNullifiers[nullifier.toString()];
|
|
87
|
+
const note = deployed
|
|
88
|
+
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed }))[0]
|
|
89
|
+
: undefined;
|
|
90
|
+
const initialized = initNullifiers[nullifier.toString()];
|
|
91
|
+
const registered = classNullifiers[nullifier.toString()];
|
|
92
|
+
if (nullifier.toBuffer().equals(txHash.toBuffer())) {
|
|
93
|
+
log(` Transaction hash nullifier ${nullifier.toShortString()}`);
|
|
94
|
+
} else if (note) {
|
|
95
|
+
inspectNote(note, artifactMap, log, `Nullifier ${nullifier.toShortString()} for note`);
|
|
96
|
+
} else if (deployed) {
|
|
97
|
+
log(
|
|
98
|
+
` Contract ${toFriendlyAddress(deployed, artifactMap)} deployed via nullifier ${nullifier.toShortString()}`,
|
|
99
|
+
);
|
|
100
|
+
} else if (initialized) {
|
|
101
|
+
log(
|
|
102
|
+
` Contract ${toFriendlyAddress(
|
|
103
|
+
initialized,
|
|
104
|
+
artifactMap,
|
|
105
|
+
)} initialized via nullifier ${nullifier.toShortString()}`,
|
|
106
|
+
);
|
|
107
|
+
} else if (registered) {
|
|
108
|
+
log(` Class ${registered} registered via nullifier ${nullifier.toShortString()}`);
|
|
109
|
+
} else {
|
|
110
|
+
log(` Unknown nullifier ${nullifier.toString()}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// L2 to L1 messages
|
|
116
|
+
if (effects.l2ToL1Msgs.length > 0) {
|
|
117
|
+
log(` L2 to L1 messages:`);
|
|
118
|
+
for (const msg of effects.l2ToL1Msgs) {
|
|
119
|
+
log(` ${msg.toString()}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function inspectNote(note: UniqueNote, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
|
|
125
|
+
const artifact = artifactMap[note.contractAddress.toString()];
|
|
126
|
+
const contract = artifact?.name ?? note.contractAddress.toString();
|
|
127
|
+
log(` ${text} at ${contract}`);
|
|
128
|
+
log(` Recipient: ${toFriendlyAddress(note.recipient, artifactMap)}`);
|
|
129
|
+
for (const field of note.note.items) {
|
|
130
|
+
log(` ${field.toString()}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
|
|
135
|
+
const artifact = artifactMap[address.toString()];
|
|
136
|
+
if (!artifact) {
|
|
137
|
+
return address.toString();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return `${artifact.name}<${address.toString()}>`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
|
|
144
|
+
const knownContracts = await wallet.getContracts();
|
|
145
|
+
const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
|
|
146
|
+
const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
|
|
147
|
+
const initNullifiers: Record<string, AztecAddress> = {};
|
|
148
|
+
const deployNullifiers: Record<string, AztecAddress> = {};
|
|
149
|
+
const classNullifiers: Record<string, string> = {};
|
|
150
|
+
for (const contract of knownContracts) {
|
|
151
|
+
initNullifiers[(await siloNullifier(contract, contract.toField())).toString()] = contract;
|
|
152
|
+
deployNullifiers[(await siloNullifier(deployerAddress, contract.toField())).toString()] = contract;
|
|
153
|
+
}
|
|
154
|
+
for (const artifact of Object.values(artifactMap)) {
|
|
155
|
+
classNullifiers[(await siloNullifier(classRegistryAddress, artifact.classId)).toString()] =
|
|
156
|
+
`${artifact.name}Class<${artifact.classId}>`;
|
|
157
|
+
}
|
|
158
|
+
return { initNullifiers, deployNullifiers, classNullifiers };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type ArtifactMap = Record<string, ContractArtifactWithClassId>;
|
|
162
|
+
type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
|
|
163
|
+
|
|
164
|
+
async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
|
|
165
|
+
const knownContractAddresses = await wallet.getContracts();
|
|
166
|
+
const knownContracts = (
|
|
167
|
+
await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
|
|
168
|
+
).map(contractMetadata => contractMetadata.contractInstance);
|
|
169
|
+
const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
|
|
170
|
+
const knownArtifacts = (
|
|
171
|
+
await Promise.all(classIds.map(classId => (classId ? wallet.getContractClassMetadata(classId) : undefined)))
|
|
172
|
+
).map(contractClassMetadata =>
|
|
173
|
+
contractClassMetadata
|
|
174
|
+
? { ...contractClassMetadata.artifact, classId: contractClassMetadata.contractClass?.id }
|
|
175
|
+
: undefined,
|
|
176
|
+
);
|
|
177
|
+
const map: Record<string, ContractArtifactWithClassId> = {};
|
|
178
|
+
for (const instance of knownContracts) {
|
|
179
|
+
if (instance) {
|
|
180
|
+
const artifact = knownArtifacts.find(a =>
|
|
181
|
+
a?.classId?.equals(instance.currentContractClassId),
|
|
182
|
+
) as ContractArtifactWithClassId;
|
|
183
|
+
if (artifact) {
|
|
184
|
+
map[instance.address.toString()] = artifact;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
11
187
|
}
|
|
188
|
+
return map;
|
|
12
189
|
}
|