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