@aztec/cli-wallet 0.0.1-fake-ceab37513c → 0.0.2-commit.217f559981

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.
Files changed (106) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.d.ts +2 -1
  3. package/dest/bin/index.js +39 -23
  4. package/dest/cmds/authorize_action.d.ts +4 -3
  5. package/dest/cmds/authorize_action.d.ts.map +1 -1
  6. package/dest/cmds/authorize_action.js +8 -7
  7. package/dest/cmds/bridge_fee_juice.d.ts +4 -4
  8. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  9. package/dest/cmds/bridge_fee_juice.js +9 -7
  10. package/dest/cmds/check_tx.d.ts +5 -3
  11. package/dest/cmds/check_tx.d.ts.map +1 -1
  12. package/dest/cmds/check_tx.js +148 -6
  13. package/dest/cmds/create_account.d.ts +8 -6
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +56 -62
  16. package/dest/cmds/create_authwit.d.ts +4 -3
  17. package/dest/cmds/create_authwit.d.ts.map +1 -1
  18. package/dest/cmds/create_authwit.js +6 -6
  19. package/dest/cmds/deploy.d.ts +7 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +84 -50
  22. package/dest/cmds/deploy_account.d.ts +6 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +56 -65
  25. package/dest/cmds/import_test_accounts.d.ts +3 -3
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +6 -9
  28. package/dest/cmds/index.d.ts +3 -3
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +73 -112
  31. package/dest/cmds/profile.d.ts +7 -4
  32. package/dest/cmds/profile.d.ts.map +1 -1
  33. package/dest/cmds/profile.js +9 -4
  34. package/dest/cmds/register_contract.d.ts +7 -3
  35. package/dest/cmds/register_contract.d.ts.map +1 -1
  36. package/dest/cmds/register_contract.js +5 -6
  37. package/dest/cmds/register_sender.d.ts +4 -3
  38. package/dest/cmds/register_sender.d.ts.map +1 -1
  39. package/dest/cmds/send.d.ts +8 -9
  40. package/dest/cmds/send.d.ts.map +1 -1
  41. package/dest/cmds/send.js +46 -31
  42. package/dest/cmds/simulate.d.ts +7 -4
  43. package/dest/cmds/simulate.d.ts.map +1 -1
  44. package/dest/cmds/simulate.js +12 -7
  45. package/dest/storage/wallet_db.d.ts +6 -16
  46. package/dest/storage/wallet_db.d.ts.map +1 -1
  47. package/dest/storage/wallet_db.js +48 -54
  48. package/dest/utils/authorizations.d.ts +3 -2
  49. package/dest/utils/authorizations.d.ts.map +1 -1
  50. package/dest/utils/authorizations.js +1 -1
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  53. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  54. package/dest/utils/constants.d.ts +4 -0
  55. package/dest/utils/constants.d.ts.map +1 -0
  56. package/dest/utils/constants.js +7 -0
  57. package/dest/utils/ecdsa.d.ts +1 -1
  58. package/dest/utils/options/fees.d.ts +22 -28
  59. package/dest/utils/options/fees.d.ts.map +1 -1
  60. package/dest/utils/options/fees.js +66 -133
  61. package/dest/utils/options/index.d.ts +1 -1
  62. package/dest/utils/options/options.d.ts +3 -2
  63. package/dest/utils/options/options.d.ts.map +1 -1
  64. package/dest/utils/options/options.js +1 -1
  65. package/dest/utils/profiling.d.ts +1 -1
  66. package/dest/utils/profiling.d.ts.map +1 -1
  67. package/dest/utils/profiling.js +9 -1
  68. package/dest/utils/wallet.d.ts +40 -0
  69. package/dest/utils/wallet.d.ts.map +1 -0
  70. package/dest/utils/wallet.js +208 -0
  71. package/package.json +17 -14
  72. package/src/bin/index.ts +39 -31
  73. package/src/cmds/authorize_action.ts +14 -6
  74. package/src/cmds/bridge_fee_juice.ts +15 -11
  75. package/src/cmds/check_tx.ts +180 -5
  76. package/src/cmds/create_account.ts +63 -66
  77. package/src/cmds/create_authwit.ts +9 -5
  78. package/src/cmds/deploy.ts +82 -61
  79. package/src/cmds/deploy_account.ts +62 -64
  80. package/src/cmds/import_test_accounts.ts +7 -11
  81. package/src/cmds/index.ts +120 -206
  82. package/src/cmds/profile.ts +14 -6
  83. package/src/cmds/register_contract.ts +9 -11
  84. package/src/cmds/register_sender.ts +3 -2
  85. package/src/cmds/send.ts +42 -40
  86. package/src/cmds/simulate.ts +17 -12
  87. package/src/storage/wallet_db.ts +52 -67
  88. package/src/utils/authorizations.ts +3 -1
  89. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  90. package/src/utils/constants.ts +4 -0
  91. package/src/utils/options/fees.ts +88 -178
  92. package/src/utils/options/options.ts +3 -2
  93. package/src/utils/profiling.ts +15 -1
  94. package/src/utils/wallet.ts +290 -0
  95. package/dest/cmds/cancel_tx.d.ts +0 -11
  96. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  97. package/dest/cmds/cancel_tx.js +0 -43
  98. package/dest/utils/accounts.d.ts +0 -9
  99. package/dest/utils/accounts.d.ts.map +0 -1
  100. package/dest/utils/accounts.js +0 -61
  101. package/dest/utils/pxe_wrapper.d.ts +0 -12
  102. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  103. package/dest/utils/pxe_wrapper.js +0 -26
  104. package/src/cmds/cancel_tx.ts +0 -66
  105. package/src/utils/accounts.ts +0 -77
  106. package/src/utils/pxe_wrapper.ts +0 -32
@@ -1,4 +1,7 @@
1
- import { type AccountWalletWithSecretKey, AuthWitness, type AztecAddress, Contract } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { Contract } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
5
  import { prepTx } from '@aztec/cli/utils';
3
6
  import type { LogFn } from '@aztec/foundation/log';
4
7
  import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
@@ -6,27 +9,32 @@ import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
6
9
  import { promises as fs } from 'fs';
7
10
  import path from 'path';
8
11
 
9
- import type { IFeeOpts } from '../utils/options/fees.js';
12
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
10
13
  import { printProfileResult } from '../utils/profiling.js';
14
+ import type { CLIWallet } from '../utils/wallet.js';
11
15
 
12
16
  export async function profile(
13
- wallet: AccountWalletWithSecretKey,
17
+ wallet: CLIWallet,
18
+ node: AztecNode,
19
+ from: AztecAddress,
14
20
  functionName: string,
15
21
  functionArgsIn: any[],
16
22
  contractArtifactPath: string,
17
23
  contractAddress: AztecAddress,
18
24
  debugOutputPath: string | undefined,
19
- feeOpts: IFeeOpts,
25
+ feeOpts: CLIFeeArgs,
20
26
  authWitnesses: AuthWitness[],
21
27
  log: LogFn,
22
28
  ) {
23
29
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
24
30
 
25
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
31
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
26
32
  const call = contract.methods[functionName](...functionArgs);
27
33
 
34
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
28
35
  const result = await call.profile({
29
- ...(await feeOpts.toSendOpts(wallet)),
36
+ fee: { gasSettings, paymentMethod },
37
+ from,
30
38
  profileMode: 'full',
31
39
  authWitnesses,
32
40
  skipProofGeneration: false,
@@ -1,17 +1,15 @@
1
- import {
2
- type AccountWalletWithSecretKey,
3
- type AztecAddress,
4
- type AztecNode,
5
- type Fr,
6
- PublicKeys,
7
- getContractInstanceFromInstantiationParams,
8
- } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
3
+ import { Fr } from '@aztec/aztec.js/fields';
4
+ import { PublicKeys } from '@aztec/aztec.js/keys';
5
+ import type { AztecNode } from '@aztec/aztec.js/node';
6
+ import type { Wallet } from '@aztec/aztec.js/wallet';
9
7
  import { getContractArtifact } from '@aztec/cli/cli-utils';
10
8
  import type { LogFn } from '@aztec/foundation/log';
11
9
  import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
12
10
 
13
11
  export async function registerContract(
14
- wallet: AccountWalletWithSecretKey,
12
+ wallet: Wallet,
15
13
  node: AztecNode,
16
14
  address: AztecAddress,
17
15
  artifactPath: string,
@@ -32,14 +30,14 @@ export async function registerContract(
32
30
  constructorArtifact,
33
31
  publicKeys: publicKeys ?? PublicKeys.default(),
34
32
  constructorArgs: rawArgs,
35
- salt,
33
+ salt: salt ?? Fr.ZERO,
36
34
  deployer,
37
35
  });
38
36
  }
39
37
  if (!contractInstance.address.equals(address)) {
40
38
  throw new Error(`Contract address mismatch: expected ${address}, got ${contractInstance.address}`);
41
39
  }
42
- await wallet.registerContract({ instance: contractInstance, artifact: contractArtifact });
40
+ await wallet.registerContract(contractInstance, contractArtifact);
43
41
  log(`Contract registered: at ${contractInstance.address}`);
44
42
  return contractInstance;
45
43
  }
@@ -1,7 +1,8 @@
1
- import type { AccountWalletWithSecretKey, AztecAddress } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
3
  import type { LogFn } from '@aztec/foundation/log';
3
4
 
4
- export async function registerSender(wallet: AccountWalletWithSecretKey, address: AztecAddress, log: LogFn) {
5
+ export async function registerSender(wallet: Wallet, address: AztecAddress, log: LogFn) {
5
6
  await wallet.registerSender(address);
6
7
  log(`Sender registered: ${address}`);
7
8
  }
package/src/cmds/send.ts CHANGED
@@ -1,86 +1,88 @@
1
- import {
2
- type AccountWalletWithSecretKey,
3
- AuthWitness,
4
- type AztecAddress,
5
- Contract,
6
- Fr,
7
- type SendMethodOptions,
8
- } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { Contract, NO_WAIT, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
9
5
  import { prepTx } from '@aztec/cli/utils';
10
6
  import type { LogFn } from '@aztec/foundation/log';
11
- import { GasSettings } from '@aztec/stdlib/gas';
12
7
 
13
- import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
8
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
9
+ import { CLIFeeArgs } from '../utils/options/fees.js';
14
10
  import { printProfileResult } from '../utils/profiling.js';
15
- import { DEFAULT_TX_TIMEOUT_S } from '../utils/pxe_wrapper.js';
11
+ import type { CLIWallet } from '../utils/wallet.js';
16
12
 
17
13
  export async function send(
18
- wallet: AccountWalletWithSecretKey,
14
+ wallet: CLIWallet,
15
+ node: AztecNode,
16
+ from: AztecAddress,
19
17
  functionName: string,
20
18
  functionArgsIn: any[],
21
19
  contractArtifactPath: string,
22
20
  contractAddress: AztecAddress,
23
21
  wait: boolean,
24
22
  cancellable: boolean,
25
- feeOpts: IFeeOpts,
23
+ feeOpts: CLIFeeArgs,
26
24
  authWitnesses: AuthWitness[],
27
25
  verbose: boolean,
28
26
  log: LogFn,
29
27
  ) {
30
28
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
31
29
 
32
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
30
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
33
31
  const call = contract.methods[functionName](...functionArgs);
34
32
 
35
- const txNonce = Fr.random();
36
-
37
- const sendOptions: SendMethodOptions = {
38
- ...(await feeOpts.toSendOpts(wallet)),
33
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
34
+ const sendOptions: SendInteractionOptions = {
35
+ fee: { paymentMethod, gasSettings },
36
+ from,
39
37
  authWitnesses,
40
- cancellable,
41
- txNonce,
42
38
  };
43
39
 
44
- const gasLimits = await call.estimateGas(sendOptions);
45
- printGasEstimates(feeOpts, gasLimits, log);
40
+ const { estimatedGas, stats } = await call.simulate({
41
+ ...sendOptions,
42
+ fee: { ...sendOptions.fee, estimateGas: true },
43
+ });
46
44
 
47
45
  if (feeOpts.estimateOnly) {
48
46
  return;
49
47
  }
50
48
 
51
- const provenTx = await call.prove(sendOptions);
52
49
  if (verbose) {
53
- printProfileResult(provenTx.stats!, log);
50
+ printProfileResult(stats!, log);
54
51
  }
55
52
 
56
- const tx = provenTx.send();
57
- const txHash = await tx.getTxHash();
58
- log(`\nTransaction hash: ${txHash.toString()}`);
59
53
  if (wait) {
60
54
  try {
61
- await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
55
+ const receipt = await call.send({
56
+ ...sendOptions,
57
+ fee: { ...sendOptions.fee, gasSettings: estimatedGas },
58
+ wait: { timeout: DEFAULT_TX_TIMEOUT_S },
59
+ });
62
60
 
61
+ const txHash = receipt.txHash;
62
+ log(`\nTransaction hash: ${txHash.toString()}`);
63
63
  log('Transaction has been mined');
64
-
65
- const receipt = await tx.getReceipt();
66
64
  log(` Tx fee: ${receipt.transactionFee}`);
67
65
  log(` Status: ${receipt.status}`);
68
66
  log(` Block number: ${receipt.blockNumber}`);
69
67
  log(` Block hash: ${receipt.blockHash?.toString()}`);
68
+
69
+ return {
70
+ txHash,
71
+ };
70
72
  } catch (err: any) {
71
73
  log(`Transaction failed\n ${err.message}`);
74
+ throw err;
72
75
  }
73
76
  } else {
77
+ const txHash = await call.send({
78
+ ...sendOptions,
79
+ fee: { ...sendOptions.fee, gasSettings: estimatedGas },
80
+ wait: NO_WAIT,
81
+ });
82
+ log(`\nTransaction hash: ${txHash.toString()}`);
74
83
  log('Transaction pending. Check status with check-tx');
84
+ return {
85
+ txHash,
86
+ };
75
87
  }
76
- const gasSettings = GasSettings.from({
77
- ...feeOpts.gasSettings,
78
- ...gasLimits,
79
- });
80
- return {
81
- txHash,
82
- txNonce,
83
- cancellable,
84
- gasSettings,
85
- };
86
88
  }
@@ -1,30 +1,38 @@
1
- import { type AccountWalletWithSecretKey, AuthWitness, type AztecAddress, Contract } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { Contract } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
5
  import { prepTx } from '@aztec/cli/utils';
3
6
  import type { LogFn } from '@aztec/foundation/log';
4
7
 
5
8
  import { format } from 'util';
6
9
 
7
10
  import { printAuthorizations } from '../utils/authorizations.js';
8
- import type { IFeeOpts } from '../utils/options/fees.js';
11
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
9
12
  import { printProfileResult } from '../utils/profiling.js';
13
+ import type { CLIWallet } from '../utils/wallet.js';
10
14
 
11
15
  export async function simulate(
12
- wallet: AccountWalletWithSecretKey,
16
+ wallet: CLIWallet,
17
+ node: AztecNode,
18
+ from: AztecAddress,
13
19
  functionName: string,
14
20
  functionArgsIn: any[],
15
21
  contractArtifactPath: string,
16
22
  contractAddress: AztecAddress,
17
- feeOpts: IFeeOpts,
23
+ feeOpts: CLIFeeArgs,
18
24
  authWitnesses: AuthWitness[],
19
25
  verbose: boolean,
20
26
  log: LogFn,
21
27
  ) {
22
28
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
23
29
 
24
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
30
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
25
31
  const call = contract.methods[functionName](...functionArgs);
32
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
26
33
  const simulationResult = await call.simulate({
27
- ...(await feeOpts.toSendOpts(wallet)),
34
+ fee: { paymentMethod, gasSettings },
35
+ from,
28
36
  authWitnesses,
29
37
  includeMetadata: true,
30
38
  });
@@ -33,14 +41,11 @@ export async function simulate(
33
41
  simulationResult.offchainEffects!,
34
42
  async (address: AztecAddress) => {
35
43
  const metadata = await wallet.getContractMetadata(address);
36
- if (!metadata.contractInstance) {
44
+ if (!metadata.instance) {
37
45
  return undefined;
38
46
  }
39
- const classMetadata = await wallet.getContractClassMetadata(
40
- metadata.contractInstance.currentContractClassId,
41
- true,
42
- );
43
- return classMetadata.artifact;
47
+ const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
48
+ return artifact;
44
49
  },
45
50
  log,
46
51
  );
@@ -1,22 +1,21 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { LogFn } from '@aztec/foundation/log';
3
3
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
4
4
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import { GasSettings } from '@aztec/stdlib/gas';
7
6
  import type { TxHash } from '@aztec/stdlib/tx';
8
7
 
9
- import type { AccountType } from '../utils/accounts.js';
8
+ import type { AccountType } from '../utils/constants.js';
10
9
  import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
11
10
 
12
11
  export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transactions', 'authwits'] as const;
13
12
  export type AliasType = (typeof Aliases)[number];
14
13
 
15
14
  export class WalletDB {
15
+ #store!: AztecAsyncKVStore;
16
16
  #accounts!: AztecAsyncMap<string, Buffer>;
17
17
  #aliases!: AztecAsyncMap<string, Buffer>;
18
18
  #bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
19
- #transactions!: AztecAsyncMap<string, Buffer>;
20
19
 
21
20
  private static instance: WalletDB;
22
21
 
@@ -31,10 +30,10 @@ export class WalletDB {
31
30
  }
32
31
 
33
32
  async init(store: AztecAsyncKVStore) {
33
+ this.#store = store;
34
34
  this.#accounts = store.openMap('accounts');
35
35
  this.#aliases = store.openMap('aliases');
36
36
  this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
37
- this.#transactions = store.openMap('transactions');
38
37
 
39
38
  await this.refreshAliasCache();
40
39
  }
@@ -44,14 +43,17 @@ export class WalletDB {
44
43
  }
45
44
 
46
45
  async pushBridgedFeeJuice(recipient: AztecAddress, secret: Fr, amount: bigint, leafIndex: bigint, log: LogFn) {
47
- let stackPointer = (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
48
- stackPointer++;
49
- await this.#bridgedFeeJuice.set(
50
- `${recipient.toString()}:${stackPointer}`,
51
- Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
52
- );
53
- await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
54
- log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
46
+ await this.#store.transactionAsync(async () => {
47
+ let stackPointer =
48
+ (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
49
+ stackPointer++;
50
+ await this.#bridgedFeeJuice.set(
51
+ `${recipient.toString()}:${stackPointer}`,
52
+ Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
53
+ );
54
+ await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
55
+ log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
56
+ });
55
57
  }
56
58
 
57
59
  async popBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
@@ -79,19 +81,24 @@ export class WalletDB {
79
81
  }: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
80
82
  log: LogFn,
81
83
  ) {
82
- if (alias) {
83
- await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
84
- }
85
- await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
86
- await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
87
- await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
84
+ let publicSigningKey: Buffer | undefined;
88
85
  if (type === 'ecdsasecp256r1ssh' && publicKey) {
89
- const publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
90
- await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
86
+ publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
91
87
  }
92
- await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
93
- log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
94
88
 
89
+ await this.#store.transactionAsync(async () => {
90
+ if (alias) {
91
+ await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
92
+ }
93
+ await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
94
+ await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
95
+ await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
96
+ if (publicSigningKey) {
97
+ await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
98
+ }
99
+ await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
100
+ });
101
+ log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
95
102
  await this.refreshAliasCache();
96
103
  }
97
104
 
@@ -103,63 +110,41 @@ export class WalletDB {
103
110
  }
104
111
 
105
112
  async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
106
- if (alias) {
107
- await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
108
- await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
109
- }
110
- await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
111
- await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
112
- await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
113
+ await this.#store.transactionAsync(async () => {
114
+ if (alias) {
115
+ await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
116
+ await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
117
+ }
118
+ await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
119
+ await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
120
+ await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
121
+ });
113
122
  log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
114
-
115
123
  await this.refreshAliasCache();
116
124
  }
117
125
 
118
126
  async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
119
- if (alias) {
120
- await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
121
- }
122
- await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
127
+ await this.#store.transactionAsync(async () => {
128
+ if (alias) {
129
+ await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
130
+ }
131
+ await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
132
+ });
123
133
  log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
124
-
125
134
  await this.refreshAliasCache();
126
135
  }
127
136
 
128
- async storeTx(
129
- {
130
- txHash,
131
- txNonce,
132
- cancellable,
133
- gasSettings,
134
- }: { txHash: TxHash; txNonce: Fr; cancellable: boolean; gasSettings: GasSettings },
135
- log: LogFn,
136
- alias?: string,
137
- ) {
138
- if (alias) {
139
- await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
140
- }
141
- await this.#transactions.set(`${txHash.toString()}:txNonce`, txNonce.toBuffer());
142
- await this.#transactions.set(`${txHash.toString()}:cancellable`, Buffer.from(cancellable ? 'true' : 'false'));
143
- await this.#transactions.set(`${txHash.toString()}:gasSettings`, gasSettings.toBuffer());
144
- await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
137
+ async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
138
+ await this.#store.transactionAsync(async () => {
139
+ if (alias) {
140
+ await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
141
+ }
142
+ await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
143
+ });
145
144
  log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
146
-
147
145
  await this.refreshAliasCache();
148
146
  }
149
147
 
150
- async retrieveTxData(txHash: TxHash) {
151
- const txNonceBuffer = await this.#transactions.getAsync(`${txHash.toString()}:txNonce`);
152
- if (!txNonceBuffer) {
153
- throw new Error(
154
- `Could not find ${txHash.toString()}:txNonce. Transaction with hash "${txHash.toString()}" does not exist on this wallet.`,
155
- );
156
- }
157
- const txNonce = Fr.fromBuffer(txNonceBuffer);
158
- const cancellable = (await this.#transactions.getAsync(`${txHash.toString()}:cancellable`))!.toString() === 'true';
159
- const gasBuffer = (await this.#transactions.getAsync(`${txHash.toString()}:gasSettings`))!;
160
- return { txHash, txNonce, cancellable, gasSettings: GasSettings.fromBuffer(gasBuffer) };
161
- }
162
-
163
148
  tryRetrieveAlias(arg: string) {
164
149
  try {
165
150
  return this.retrieveAliasFromCache(arg);
@@ -1,4 +1,6 @@
1
- import { type AztecAddress, CallAuthorizationRequest, type ContractArtifact } from '@aztec/aztec.js';
1
+ import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
2
4
  import type { LogFn } from '@aztec/foundation/log';
3
5
  import { type AbiDecoded, decodeFromAbi, getFunctionArtifact } from '@aztec/stdlib/abi';
4
6
  import type { OffchainEffect } from '@aztec/stdlib/tx';
@@ -0,0 +1,35 @@
1
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
2
+
3
+ import { CLIWallet } from './wallet.js';
4
+
5
+ export const DEFAULT_TX_TIMEOUT_S = 180;
6
+
7
+ /*
8
+ * Wrapper class for CLIWallet and AztecNode, avoids initialization issues due to closures when providing CLIWallet
9
+ * and AztecNode to injected commander.js commands
10
+ */
11
+ export class CliWalletAndNodeWrapper {
12
+ private _wallet: CLIWallet | undefined;
13
+ private _node: AztecNode | undefined;
14
+
15
+ constructor() {}
16
+
17
+ get wallet() {
18
+ if (!this._wallet) {
19
+ throw new Error('Wallet not initialized while it should have been initialized in preSubcommand');
20
+ }
21
+ return this._wallet;
22
+ }
23
+
24
+ get node(): AztecNode {
25
+ if (!this._node) {
26
+ throw new Error('Node not initialized while it should have been initialized in preSubcommand');
27
+ }
28
+ return this._node;
29
+ }
30
+
31
+ setNodeAndWallet(node: AztecNode, wallet: CLIWallet) {
32
+ this._node = node;
33
+ this._wallet = wallet;
34
+ }
35
+ }
@@ -0,0 +1,4 @@
1
+ export const MIN_FEE_PADDING = 0.5;
2
+
3
+ export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
4
+ export type AccountType = (typeof AccountTypes)[number];