@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.0208eb9
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,204 @@
|
|
|
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 } from '@aztec/aztec.js/wallet';
|
|
8
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
+
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
10
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
12
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
13
|
+
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
14
|
+
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
15
|
+
import { printGasEstimates } from './options/fees.js';
|
|
16
|
+
export class CLIWallet extends BaseWallet {
|
|
17
|
+
userLog;
|
|
18
|
+
db;
|
|
19
|
+
accountCache;
|
|
20
|
+
constructor(pxe, node, userLog, db){
|
|
21
|
+
super(pxe, node), this.userLog = userLog, this.db = db, this.accountCache = new Map();
|
|
22
|
+
this.cancellableTransactions = true;
|
|
23
|
+
}
|
|
24
|
+
static async create(node, log, db, overridePXEConfig) {
|
|
25
|
+
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
26
|
+
const pxe = await createPXE(node, pxeConfig);
|
|
27
|
+
return new CLIWallet(pxe, node, log, db);
|
|
28
|
+
}
|
|
29
|
+
async getAccounts() {
|
|
30
|
+
const accounts = await this.db?.listAliases('accounts') ?? [];
|
|
31
|
+
return Promise.resolve(accounts.map(({ key, value })=>({
|
|
32
|
+
alias: value,
|
|
33
|
+
item: AztecAddress.fromString(key)
|
|
34
|
+
})));
|
|
35
|
+
}
|
|
36
|
+
async createCancellationTxExecutionRequest(from, txNonce, increasedFee) {
|
|
37
|
+
const executionPayload = ExecutionPayload.empty();
|
|
38
|
+
const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
|
|
39
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
40
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
41
|
+
const chainInfo = await this.getChainInfo();
|
|
42
|
+
const executionOptions = {
|
|
43
|
+
txNonce,
|
|
44
|
+
cancellable: this.cancellableTransactions,
|
|
45
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
46
|
+
};
|
|
47
|
+
return await fromAccount.createTxExecutionRequest(feeExecutionPayload ?? executionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
48
|
+
}
|
|
49
|
+
async proveCancellationTx(from, txNonce, increasedFee) {
|
|
50
|
+
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
51
|
+
return await this.pxe.proveTx(cancellationTxRequest);
|
|
52
|
+
}
|
|
53
|
+
async getAccountFromAddress(address) {
|
|
54
|
+
let account;
|
|
55
|
+
if (address.equals(AztecAddress.ZERO)) {
|
|
56
|
+
account = new SignerlessAccount();
|
|
57
|
+
} else if (this.accountCache.has(address.toString())) {
|
|
58
|
+
return this.accountCache.get(address.toString());
|
|
59
|
+
} else {
|
|
60
|
+
const accountManager = await this.createOrRetrieveAccount(address);
|
|
61
|
+
account = await accountManager.getAccount();
|
|
62
|
+
}
|
|
63
|
+
if (!account) {
|
|
64
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
65
|
+
}
|
|
66
|
+
return account;
|
|
67
|
+
}
|
|
68
|
+
async createAccount(secret, salt, contract) {
|
|
69
|
+
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
70
|
+
const instance = accountManager.getInstance();
|
|
71
|
+
const artifact = await contract.getContractArtifact();
|
|
72
|
+
await this.registerContract(instance, artifact, secret);
|
|
73
|
+
this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
74
|
+
return accountManager;
|
|
75
|
+
}
|
|
76
|
+
async createOrRetrieveAccount(address, secretKey, type = 'schnorr', salt, publicKey) {
|
|
77
|
+
let account;
|
|
78
|
+
salt ??= Fr.ZERO;
|
|
79
|
+
if (this.db && address) {
|
|
80
|
+
({ type, secretKey, salt } = await this.db.retrieveAccount(address));
|
|
81
|
+
}
|
|
82
|
+
if (!secretKey) {
|
|
83
|
+
throw new Error('Cannot retrieve/create wallet without secret key');
|
|
84
|
+
}
|
|
85
|
+
switch(type){
|
|
86
|
+
case 'schnorr':
|
|
87
|
+
{
|
|
88
|
+
account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'ecdsasecp256r1':
|
|
92
|
+
{
|
|
93
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()));
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'ecdsasecp256r1ssh':
|
|
97
|
+
{
|
|
98
|
+
let publicSigningKey;
|
|
99
|
+
if (this.db && address) {
|
|
100
|
+
publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
|
|
101
|
+
} else if (publicKey) {
|
|
102
|
+
const identities = await getIdentities();
|
|
103
|
+
const foundIdentity = identities.find((identity)=>identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey);
|
|
104
|
+
if (!foundIdentity) {
|
|
105
|
+
throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
|
|
106
|
+
}
|
|
107
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error('Public key must be provided for ECDSA SSH account');
|
|
110
|
+
}
|
|
111
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
default:
|
|
115
|
+
{
|
|
116
|
+
throw new Error(`Unsupported account type: ${type}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return account;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
123
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
124
|
+
* @param address - The address of the account to impersonate
|
|
125
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
126
|
+
*/ async getFakeAccountDataFor(address) {
|
|
127
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
128
|
+
// Account contracts can only be overridden if they have an associated address
|
|
129
|
+
// Overwriting SignerlessAccount is not supported, and does not really make sense
|
|
130
|
+
// since it has no authorization mechanism.
|
|
131
|
+
if (originalAccount instanceof SignerlessAccount) {
|
|
132
|
+
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
133
|
+
}
|
|
134
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
135
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
136
|
+
if (!contractInstance) {
|
|
137
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
138
|
+
}
|
|
139
|
+
const stubAccount = createStubAccount(originalAddress);
|
|
140
|
+
const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
141
|
+
salt: Fr.random()
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
account: stubAccount,
|
|
145
|
+
instance,
|
|
146
|
+
artifact: StubAccountContractArtifact
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async simulateTx(executionPayload, opts) {
|
|
150
|
+
let simulationResults;
|
|
151
|
+
const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
152
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
153
|
+
const chainInfo = await this.getChainInfo();
|
|
154
|
+
const executionOptions = {
|
|
155
|
+
txNonce: Fr.random(),
|
|
156
|
+
cancellable: this.cancellableTransactions,
|
|
157
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
158
|
+
};
|
|
159
|
+
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
160
|
+
feeExecutionPayload,
|
|
161
|
+
executionPayload
|
|
162
|
+
]) : executionPayload;
|
|
163
|
+
// Kernelless simulations using the multicall entrypoints are not currently supported,
|
|
164
|
+
// since we only override proper account contracts.
|
|
165
|
+
// TODO: allow disabling kernels even when no overrides are necessary
|
|
166
|
+
if (opts.from.equals(AztecAddress.ZERO)) {
|
|
167
|
+
const fromAccount = await this.getAccountFromAddress(opts.from);
|
|
168
|
+
const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
169
|
+
simulationResults = await this.pxe.simulateTx(txRequest, true, opts?.skipTxValidation, opts?.skipFeeEnforcement ?? true);
|
|
170
|
+
} else {
|
|
171
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
172
|
+
const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
173
|
+
const contractOverrides = {
|
|
174
|
+
[opts.from.toString()]: {
|
|
175
|
+
instance,
|
|
176
|
+
artifact
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
simulationResults = await this.pxe.simulateTx(txRequest, true, true, true, {
|
|
180
|
+
contracts: contractOverrides
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (opts.fee?.estimateGas) {
|
|
184
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
185
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
186
|
+
}
|
|
187
|
+
return simulationResults;
|
|
188
|
+
}
|
|
189
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
190
|
+
// this is just a CLI wallet.
|
|
191
|
+
getContracts() {
|
|
192
|
+
return this.pxe.getContracts();
|
|
193
|
+
}
|
|
194
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
195
|
+
// this is just a CLI wallet.
|
|
196
|
+
getNotes(filter) {
|
|
197
|
+
return this.pxe.debug.getNotes(filter);
|
|
198
|
+
}
|
|
199
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
200
|
+
// this is just a CLI wallet.
|
|
201
|
+
getContractArtifact(id) {
|
|
202
|
+
return this.pxe.getContractArtifact(id);
|
|
203
|
+
}
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli-wallet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.0208eb9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/cmds/index.js",
|
|
@@ -20,11 +20,9 @@
|
|
|
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
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
27
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
28
26
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
29
27
|
},
|
|
30
28
|
"inherits": [
|
|
@@ -62,33 +60,42 @@
|
|
|
62
60
|
"testTimeout": 120000,
|
|
63
61
|
"setupFiles": [
|
|
64
62
|
"../../foundation/src/jest/setup.mjs"
|
|
63
|
+
],
|
|
64
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
65
|
+
"setupFilesAfterEnv": [
|
|
66
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
65
67
|
]
|
|
66
68
|
},
|
|
67
69
|
"dependencies": {
|
|
68
|
-
"@aztec/accounts": "0.0.
|
|
69
|
-
"@aztec/aztec.js": "0.0.
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
76
|
-
"@aztec/
|
|
70
|
+
"@aztec/accounts": "0.0.1-commit.0208eb9",
|
|
71
|
+
"@aztec/aztec.js": "0.0.1-commit.0208eb9",
|
|
72
|
+
"@aztec/bb.js": "0.0.1-commit.0208eb9",
|
|
73
|
+
"@aztec/cli": "0.0.1-commit.0208eb9",
|
|
74
|
+
"@aztec/entrypoints": "0.0.1-commit.0208eb9",
|
|
75
|
+
"@aztec/ethereum": "0.0.1-commit.0208eb9",
|
|
76
|
+
"@aztec/foundation": "0.0.1-commit.0208eb9",
|
|
77
|
+
"@aztec/kv-store": "0.0.1-commit.0208eb9",
|
|
78
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.0208eb9",
|
|
79
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.0208eb9",
|
|
80
|
+
"@aztec/pxe": "0.0.1-commit.0208eb9",
|
|
81
|
+
"@aztec/stdlib": "0.0.1-commit.0208eb9",
|
|
82
|
+
"@aztec/wallet-sdk": "0.0.1-commit.0208eb9",
|
|
77
83
|
"commander": "^12.1.0",
|
|
78
84
|
"inquirer": "^10.1.8",
|
|
79
85
|
"source-map-support": "^0.5.21",
|
|
80
86
|
"tslib": "^2.4.0"
|
|
81
87
|
},
|
|
82
88
|
"devDependencies": {
|
|
83
|
-
"@jest/globals": "^
|
|
84
|
-
"@types/jest": "^
|
|
85
|
-
"@types/node": "^
|
|
89
|
+
"@jest/globals": "^30.0.0",
|
|
90
|
+
"@types/jest": "^30.0.0",
|
|
91
|
+
"@types/node": "^22.15.17",
|
|
86
92
|
"@types/source-map-support": "^0.5.10",
|
|
87
|
-
"
|
|
88
|
-
"jest
|
|
89
|
-
"
|
|
93
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
94
|
+
"jest": "^30.0.0",
|
|
95
|
+
"jest-mock-extended": "^4.0.0",
|
|
96
|
+
"ts-jest": "^29.4.0",
|
|
90
97
|
"ts-node": "^10.9.1",
|
|
91
|
-
"typescript": "^5.
|
|
98
|
+
"typescript": "^5.3.3"
|
|
92
99
|
},
|
|
93
100
|
"files": [
|
|
94
101
|
"dest",
|
|
@@ -97,6 +104,6 @@
|
|
|
97
104
|
],
|
|
98
105
|
"types": "./dest/index.d.ts",
|
|
99
106
|
"engines": {
|
|
100
|
-
"node": ">=
|
|
107
|
+
"node": ">=20.10"
|
|
101
108
|
}
|
|
102
109
|
}
|
package/src/bin/index.ts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { computeSecretHash } from '@aztec/aztec.js/crypto';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
5
|
+
import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
|
|
6
|
+
import { BackendType, Barretenberg } from '@aztec/bb.js';
|
|
2
7
|
import { LOCALHOST } from '@aztec/cli/cli-utils';
|
|
3
8
|
import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
4
9
|
import { openStoreAt } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
-
import type {
|
|
10
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
11
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
6
12
|
|
|
7
13
|
import { Argument, Command, Option } from 'commander';
|
|
8
|
-
import { mkdirSync, readFileSync } from 'fs';
|
|
9
14
|
import { homedir } from 'os';
|
|
10
|
-
import {
|
|
15
|
+
import { join } from 'path';
|
|
11
16
|
|
|
12
17
|
import { injectCommands } from '../cmds/index.js';
|
|
13
18
|
import { Aliases, WalletDB } from '../storage/wallet_db.js';
|
|
19
|
+
import { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
14
20
|
import { createAliasOption } from '../utils/options/index.js';
|
|
15
|
-
import {
|
|
21
|
+
import { CLIWallet } from '../utils/wallet.js';
|
|
16
22
|
|
|
17
23
|
const userLog = createConsoleLogger();
|
|
18
24
|
const debugLogger = createLogger('wallet');
|
|
19
25
|
|
|
20
|
-
const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet')
|
|
26
|
+
const { WALLET_DATA_DIRECTORY = join(homedir(), '.aztec/wallet') } = process.env;
|
|
21
27
|
|
|
28
|
+
// TODO: This function is only used in 1 place so we could just inline this
|
|
22
29
|
function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
23
30
|
program
|
|
24
31
|
.command('alias')
|
|
@@ -55,7 +62,7 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
|
55
62
|
const options = command.optsWithGlobals();
|
|
56
63
|
const { alias } = options;
|
|
57
64
|
const value = Fr.random();
|
|
58
|
-
const hash = computeSecretHash(value);
|
|
65
|
+
const hash = await computeSecretHash(value);
|
|
59
66
|
|
|
60
67
|
await db.storeAlias('secrets', alias, Buffer.from(value.toString()), log);
|
|
61
68
|
await db.storeAlias('secrets', `${alias}:hash`, Buffer.from(hash.toString()), log);
|
|
@@ -66,23 +73,21 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
|
|
|
66
73
|
|
|
67
74
|
/** CLI wallet main entrypoint */
|
|
68
75
|
async function main() {
|
|
69
|
-
const
|
|
70
|
-
const walletVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
|
|
76
|
+
const walletVersion = getPackageVersion() ?? '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
|
|
77
83
|
.description('Aztec wallet')
|
|
78
84
|
.version(walletVersion)
|
|
79
85
|
.option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
|
|
80
|
-
.option('-p, --prover <string>', 'wasm|native|none', PXE_PROVER)
|
|
81
86
|
.addOption(
|
|
82
|
-
new Option('--
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
87
|
+
new Option('-p, --prover <string>', 'The type of prover the wallet uses')
|
|
88
|
+
.choices(['wasm', 'native', 'none'])
|
|
89
|
+
.env('PXE_PROVER')
|
|
90
|
+
.default('native'),
|
|
86
91
|
)
|
|
87
92
|
.addOption(
|
|
88
93
|
new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to')
|
|
@@ -90,34 +95,59 @@ async function main() {
|
|
|
90
95
|
.default(`http://${LOCALHOST}:8080`),
|
|
91
96
|
)
|
|
92
97
|
.hook('preSubcommand', async command => {
|
|
93
|
-
|
|
98
|
+
// Skip initialization if user is just requesting help
|
|
99
|
+
if (command.args.includes('--help') || command.args.includes('-h')) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { dataDir, nodeUrl, prover } = command.optsWithGlobals();
|
|
94
104
|
|
|
95
|
-
|
|
96
|
-
debugLogger.info('Using local PXE service');
|
|
105
|
+
const proverEnabled = prover !== 'none';
|
|
97
106
|
|
|
98
|
-
|
|
107
|
+
switch (prover) {
|
|
108
|
+
case 'native':
|
|
109
|
+
await Barretenberg.initSingleton({ backend: BackendType.NativeUnixSocket });
|
|
110
|
+
break;
|
|
111
|
+
case 'wasm':
|
|
112
|
+
await Barretenberg.initSingleton({ backend: BackendType.Wasm });
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
99
115
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const bbWorkingDirectory = dataDir + '/bb';
|
|
105
|
-
mkdirSync(bbWorkingDirectory, { recursive: true });
|
|
116
|
+
const overridePXEConfig: Partial<PXEConfig> = {
|
|
117
|
+
proverEnabled,
|
|
118
|
+
dataDirectory: join(dataDir, 'pxe'),
|
|
119
|
+
};
|
|
106
120
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
121
|
+
const node = createAztecNodeClient(nodeUrl);
|
|
122
|
+
const wallet = await CLIWallet.create(node, userLog, db, overridePXEConfig);
|
|
123
|
+
|
|
124
|
+
walletAndNodeWrapper.setNodeAndWallet(node, wallet);
|
|
112
125
|
|
|
113
|
-
await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'), overridePXEConfig);
|
|
114
|
-
}
|
|
115
126
|
await db.init(await openStoreAt(dataDir));
|
|
127
|
+
let protocolContractsRegistered;
|
|
128
|
+
try {
|
|
129
|
+
protocolContractsRegistered = !!(await db.retrieveAlias('contracts:ContractClassRegistry'));
|
|
130
|
+
// eslint-disable-next-line no-empty
|
|
131
|
+
} catch {}
|
|
132
|
+
if (!protocolContractsRegistered) {
|
|
133
|
+
userLog('Registering protocol contract aliases...');
|
|
134
|
+
for (const [name, address] of Object.entries(ProtocolContractAddress)) {
|
|
135
|
+
await db.storeAlias('contracts', name, Buffer.from(address.toString()), userLog);
|
|
136
|
+
await db.storeAlias(
|
|
137
|
+
'artifacts',
|
|
138
|
+
address.toString(),
|
|
139
|
+
Buffer.from(`${name.slice(0, 1).toUpperCase()}${name.slice(1)}`),
|
|
140
|
+
userLog,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
116
144
|
});
|
|
117
145
|
|
|
118
|
-
injectCommands(program, userLog, debugLogger,
|
|
146
|
+
injectCommands(program, userLog, debugLogger, walletAndNodeWrapper, db);
|
|
119
147
|
injectInternalCommands(program, userLog, db);
|
|
120
148
|
await program.parseAsync(process.argv);
|
|
149
|
+
|
|
150
|
+
await Barretenberg.destroySingleton();
|
|
121
151
|
}
|
|
122
152
|
|
|
123
153
|
main().catch(err => {
|
|
@@ -1,9 +1,15 @@
|
|
|
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
|
|
|
8
|
+
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
9
|
+
|
|
5
10
|
export async function authorizeAction(
|
|
6
|
-
wallet:
|
|
11
|
+
wallet: Wallet,
|
|
12
|
+
from: AztecAddress,
|
|
7
13
|
functionName: string,
|
|
8
14
|
caller: AztecAddress,
|
|
9
15
|
functionArgsIn: any[],
|
|
@@ -24,11 +30,16 @@ export async function authorizeAction(
|
|
|
24
30
|
);
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
const contract =
|
|
33
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
28
34
|
const action = contract.methods[functionName](...functionArgs);
|
|
29
35
|
|
|
30
|
-
const setAuthwitnessInteraction = await
|
|
31
|
-
|
|
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 } });
|
|
32
43
|
|
|
33
44
|
log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
|
|
34
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,
|
|
@@ -22,14 +26,10 @@ export async function bridgeL1FeeJuice(
|
|
|
22
26
|
) {
|
|
23
27
|
// Prepare L1 client
|
|
24
28
|
const chain = createEthereumChain(l1RpcUrls, chainId);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const {
|
|
28
|
-
protocolContractAddresses: { feeJuice: feeJuiceAddress },
|
|
29
|
-
} = await pxe.getPXEInfo();
|
|
29
|
+
const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
|
|
30
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);
|