@aztec/aztec.js 0.16.4 → 0.16.5
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/dest/artifacts/ecdsa_account_contract.json +2 -2
- package/dest/artifacts/schnorr_account_contract.json +2 -2
- package/dest/artifacts/schnorr_single_key_account_contract.json +2 -2
- package/dest/index.d.ts +8 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +7 -6
- package/package.json +5 -5
- package/src/account/contract/base_account_contract.ts +0 -25
- package/src/account/contract/ecdsa_account_contract.ts +0 -38
- package/src/account/contract/index.ts +0 -37
- package/src/account/contract/schnorr_account_contract.ts +0 -38
- package/src/account/contract/single_key_account_contract.ts +0 -45
- package/src/account/defaults/default_entrypoint.ts +0 -102
- package/src/account/defaults/default_interface.ts +0 -38
- package/src/account/defaults/entrypoint_payload.ts +0 -89
- package/src/account/defaults/index.ts +0 -3
- package/src/account/index.ts +0 -124
- package/src/account/interface.ts +0 -35
- package/src/account/manager/deploy_account_sent_tx.ts +0 -42
- package/src/account/manager/index.ts +0 -156
- package/src/account/manager/util.ts +0 -29
- package/src/account/utils.ts +0 -47
- package/src/api/README.md +0 -7
- package/src/api/abi.ts +0 -1
- package/src/api/aztec_address.ts +0 -1
- package/src/api/eth_address.ts +0 -1
- package/src/api/ethereum.ts +0 -6
- package/src/api/fields.ts +0 -1
- package/src/api/init.ts +0 -1
- package/src/api/interfaces/pxe.ts +0 -1
- package/src/api/log_id.ts +0 -1
- package/src/api/tx_hash.ts +0 -1
- package/src/artifacts/ecdsa_account_contract.json +0 -699
- package/src/artifacts/schnorr_account_contract.json +0 -687
- package/src/artifacts/schnorr_single_key_account_contract.json +0 -622
- package/src/contract/base_contract_interaction.ts +0 -61
- package/src/contract/batch_call.ts +0 -23
- package/src/contract/checker.ts +0 -117
- package/src/contract/contract.ts +0 -59
- package/src/contract/contract_base.ts +0 -70
- package/src/contract/contract_function_interaction.ts +0 -80
- package/src/contract/index.ts +0 -42
- package/src/contract/sent_tx.ts +0 -137
- package/src/contract_deployer/contract_deployer.ts +0 -26
- package/src/contract_deployer/deploy_method.ts +0 -139
- package/src/contract_deployer/deploy_sent_tx.ts +0 -71
- package/src/contract_deployer/index.ts +0 -3
- package/src/index.ts +0 -137
- package/src/pxe_client.ts +0 -63
- package/src/sandbox/index.ts +0 -85
- package/src/utils/abi_types.ts +0 -10
- package/src/utils/authwit.ts +0 -24
- package/src/utils/cheat_codes.ts +0 -300
- package/src/utils/defaults.ts +0 -4
- package/src/utils/index.ts +0 -7
- package/src/utils/l1_contracts.ts +0 -21
- package/src/utils/l2_contracts.ts +0 -12
- package/src/utils/pub_key.ts +0 -12
- package/src/utils/secrets.ts +0 -11
- package/src/wallet/account_wallet.ts +0 -86
- package/src/wallet/base_wallet.ts +0 -120
- package/src/wallet/index.ts +0 -12
- package/src/wallet/signerless_wallet.ts +0 -38
package/src/account/index.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `account` module provides utilities for managing accounts. The most common methods to use
|
|
3
|
-
* are {@link getEcdsaAccount} and {@link getSchnorrAccount}, which return {@link AccountManager} instances
|
|
4
|
-
* using the default ECDSA or Schnorr account implementation respectively. The {@link AccountManager} class then
|
|
5
|
-
* allows to deploy and register a fresh account, or to obtain a `Wallet` instance out of an account already deployed.
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* const encryptionPrivateKey = GrumpkinScalar.random();
|
|
9
|
-
* const signingPrivateKey = GrumpkinScalar.random();
|
|
10
|
-
* const wallet = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy();
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* For testing purposes, consider using the {@link createAccount} and {@link createAccounts} methods,
|
|
14
|
-
* which create, register, and deploy random accounts, and return their associated `Wallet`s.
|
|
15
|
-
*
|
|
16
|
-
* For implementing your own account contract, the recommended way is to extend from the base
|
|
17
|
-
* {@link BaseAccountContract} class.
|
|
18
|
-
* Read more in {@link https://docs.aztec.network/dev_docs/wallets/writing_an_account_contract | Writing an account contract}.
|
|
19
|
-
*
|
|
20
|
-
* @packageDocumentation
|
|
21
|
-
*/
|
|
22
|
-
import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types';
|
|
23
|
-
|
|
24
|
-
import { AccountContract, AccountWallet, AztecAddress, Fr } from '../index.js';
|
|
25
|
-
import { EcdsaAccountContract } from './contract/ecdsa_account_contract.js';
|
|
26
|
-
import { SchnorrAccountContract } from './contract/schnorr_account_contract.js';
|
|
27
|
-
import { SingleKeyAccountContract } from './contract/single_key_account_contract.js';
|
|
28
|
-
import { AccountManager } from './manager/index.js';
|
|
29
|
-
|
|
30
|
-
export * from './contract/index.js';
|
|
31
|
-
export * from './defaults/index.js';
|
|
32
|
-
export * from './utils.js';
|
|
33
|
-
export { AccountInterface, AuthWitnessProvider } from './interface.js';
|
|
34
|
-
export { AccountManager, CompleteAddress };
|
|
35
|
-
|
|
36
|
-
/** A contract deployment salt. */
|
|
37
|
-
export type Salt = Fr | number | bigint;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates an Account that relies on an ECDSA signing key for authentication.
|
|
41
|
-
* @param pxe - An PXE server instance.
|
|
42
|
-
* @param encryptionPrivateKey - Grumpkin key used for note encryption.
|
|
43
|
-
* @param signingPrivateKey - Secp256k1 key used for signing transactions.
|
|
44
|
-
* @param saltOrAddress - Deployment salt or complete address if account contract is already deployed.
|
|
45
|
-
*/
|
|
46
|
-
export function getEcdsaAccount(
|
|
47
|
-
pxe: PXE,
|
|
48
|
-
encryptionPrivateKey: GrumpkinPrivateKey,
|
|
49
|
-
signingPrivateKey: Buffer,
|
|
50
|
-
saltOrAddress?: Salt | CompleteAddress,
|
|
51
|
-
): AccountManager {
|
|
52
|
-
return new AccountManager(pxe, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Creates an Account that relies on a Grumpkin signing key for authentication.
|
|
57
|
-
* @param pxe - An PXE server instance.
|
|
58
|
-
* @param encryptionPrivateKey - Grumpkin key used for note encryption.
|
|
59
|
-
* @param signingPrivateKey - Grumpkin key used for signing transactions.
|
|
60
|
-
* @param saltOrAddress - Deployment salt or complete address if account contract is already deployed.
|
|
61
|
-
*/
|
|
62
|
-
export function getSchnorrAccount(
|
|
63
|
-
pxe: PXE,
|
|
64
|
-
encryptionPrivateKey: GrumpkinPrivateKey,
|
|
65
|
-
signingPrivateKey: GrumpkinPrivateKey,
|
|
66
|
-
saltOrAddress?: Salt | CompleteAddress,
|
|
67
|
-
): AccountManager {
|
|
68
|
-
return new AccountManager(pxe, encryptionPrivateKey, new SchnorrAccountContract(signingPrivateKey), saltOrAddress);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Creates an Account that uses the same Grumpkin key for encryption and authentication.
|
|
73
|
-
* @param pxe - An PXE server instance.
|
|
74
|
-
* @param encryptionAndSigningPrivateKey - Grumpkin key used for note encryption and signing transactions.
|
|
75
|
-
* @param saltOrAddress - Deployment salt or complete address if account contract is already deployed.
|
|
76
|
-
*/
|
|
77
|
-
export function getUnsafeSchnorrAccount(
|
|
78
|
-
pxe: PXE,
|
|
79
|
-
encryptionAndSigningPrivateKey: GrumpkinPrivateKey,
|
|
80
|
-
saltOrAddress?: Salt | CompleteAddress,
|
|
81
|
-
): AccountManager {
|
|
82
|
-
return new AccountManager(
|
|
83
|
-
pxe,
|
|
84
|
-
encryptionAndSigningPrivateKey,
|
|
85
|
-
new SingleKeyAccountContract(encryptionAndSigningPrivateKey),
|
|
86
|
-
saltOrAddress,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication.
|
|
92
|
-
* @param pxe - An PXE server instance.
|
|
93
|
-
* @param address - Address for the account.
|
|
94
|
-
* @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions.
|
|
95
|
-
* @returns A wallet for this account that can be used to interact with a contract instance.
|
|
96
|
-
*/
|
|
97
|
-
export function getUnsafeSchnorrWallet(
|
|
98
|
-
pxe: PXE,
|
|
99
|
-
address: AztecAddress,
|
|
100
|
-
signingKey: GrumpkinPrivateKey,
|
|
101
|
-
): Promise<AccountWallet> {
|
|
102
|
-
return getWallet(pxe, address, new SingleKeyAccountContract(signingKey));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Gets a wallet for an already registered account.
|
|
107
|
-
* @param pxe - PXE Service instance.
|
|
108
|
-
* @param address - Address for the account.
|
|
109
|
-
* @param accountContract - Account contract implementation.
|
|
110
|
-
* @returns A wallet for this account that can be used to interact with a contract instance.
|
|
111
|
-
*/
|
|
112
|
-
export async function getWallet(
|
|
113
|
-
pxe: PXE,
|
|
114
|
-
address: AztecAddress,
|
|
115
|
-
accountContract: AccountContract,
|
|
116
|
-
): Promise<AccountWallet> {
|
|
117
|
-
const completeAddress = await pxe.getRegisteredAccount(address);
|
|
118
|
-
if (!completeAddress) {
|
|
119
|
-
throw new Error(`Account ${address} not found`);
|
|
120
|
-
}
|
|
121
|
-
const nodeInfo = await pxe.getNodeInfo();
|
|
122
|
-
const entrypoint = accountContract.getInterface(completeAddress, nodeInfo);
|
|
123
|
-
return new AccountWallet(pxe, entrypoint);
|
|
124
|
-
}
|
package/src/account/interface.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { AuthWitness, CompleteAddress, FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
3
|
-
|
|
4
|
-
// docs:start:account-interface
|
|
5
|
-
/** Creates authorization witnesses. */
|
|
6
|
-
export interface AuthWitnessProvider {
|
|
7
|
-
/**
|
|
8
|
-
* Create an authorization witness for the given message.
|
|
9
|
-
* @param message - Message to authorize.
|
|
10
|
-
*/
|
|
11
|
-
createAuthWitness(message: Fr): Promise<AuthWitness>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Creates transaction execution requests out of a set of function calls. */
|
|
15
|
-
export interface EntrypointInterface {
|
|
16
|
-
/**
|
|
17
|
-
* Generates an authenticated request out of set of function calls.
|
|
18
|
-
* @param executions - The execution intents to be run.
|
|
19
|
-
* @param opts - Options.
|
|
20
|
-
* @returns The authenticated transaction execution request.
|
|
21
|
-
*/
|
|
22
|
-
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Handler for interfacing with an account. Knows how to create transaction execution
|
|
27
|
-
* requests and authorize actions for its corresponding account.
|
|
28
|
-
*/
|
|
29
|
-
export interface AccountInterface extends AuthWitnessProvider, EntrypointInterface {
|
|
30
|
-
/**
|
|
31
|
-
* Returns the complete address for this account.
|
|
32
|
-
*/
|
|
33
|
-
getCompleteAddress(): CompleteAddress;
|
|
34
|
-
}
|
|
35
|
-
// docs:end:account-interface
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { FieldsOf } from '@aztec/circuits.js';
|
|
2
|
-
import { TxHash, TxReceipt } from '@aztec/types';
|
|
3
|
-
|
|
4
|
-
import { DefaultWaitOpts, SentTx, WaitOpts } from '../../contract/sent_tx.js';
|
|
5
|
-
import { Wallet } from '../../wallet/index.js';
|
|
6
|
-
import { waitForAccountSynch } from './util.js';
|
|
7
|
-
|
|
8
|
-
/** Extends a transaction receipt with a wallet instance for the newly deployed contract. */
|
|
9
|
-
export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
|
|
10
|
-
/** Wallet that corresponds to the newly deployed account contract. */
|
|
11
|
-
wallet: Wallet;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A deployment transaction for an account contract sent to the network, extending SentTx with methods to get the resulting wallet.
|
|
16
|
-
*/
|
|
17
|
-
export class DeployAccountSentTx extends SentTx {
|
|
18
|
-
constructor(private wallet: Wallet, txHashPromise: Promise<TxHash>) {
|
|
19
|
-
super(wallet, txHashPromise);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Awaits for the tx to be mined and returns the contract instance. Throws if tx is not mined.
|
|
24
|
-
* @param opts - Options for configuring the waiting for the tx to be mined.
|
|
25
|
-
* @returns The deployed contract instance.
|
|
26
|
-
*/
|
|
27
|
-
public async getWallet(opts?: WaitOpts): Promise<Wallet> {
|
|
28
|
-
const receipt = await this.wait(opts);
|
|
29
|
-
return receipt.wallet;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Awaits for the tx to be mined and returns the receipt along with a wallet instance. Throws if tx is not mined.
|
|
34
|
-
* @param opts - Options for configuring the waiting for the tx to be mined.
|
|
35
|
-
* @returns The transaction receipt with the wallet for the deployed account contract.
|
|
36
|
-
*/
|
|
37
|
-
public async wait(opts: WaitOpts = DefaultWaitOpts): Promise<DeployAccountTxReceipt> {
|
|
38
|
-
const receipt = await super.wait(opts);
|
|
39
|
-
await waitForAccountSynch(this.pxe, this.wallet.getCompleteAddress(), opts);
|
|
40
|
-
return { ...receipt, wallet: this.wallet };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { PublicKey, getContractDeploymentInfo } from '@aztec/circuits.js';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import { DefaultWaitOpts } from '../../contract/sent_tx.js';
|
|
6
|
-
import {
|
|
7
|
-
AccountWalletWithPrivateKey,
|
|
8
|
-
ContractDeployer,
|
|
9
|
-
DeployMethod,
|
|
10
|
-
WaitOpts,
|
|
11
|
-
generatePublicKey,
|
|
12
|
-
} from '../../index.js';
|
|
13
|
-
import { AccountContract, Salt } from '../index.js';
|
|
14
|
-
import { AccountInterface } from '../interface.js';
|
|
15
|
-
import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
|
|
16
|
-
import { waitForAccountSynch } from './util.js';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
|
|
20
|
-
* and creating and registering the user wallet in the PXE Service.
|
|
21
|
-
*/
|
|
22
|
-
export class AccountManager {
|
|
23
|
-
/** Deployment salt for the account contract. */
|
|
24
|
-
public readonly salt?: Fr;
|
|
25
|
-
|
|
26
|
-
private completeAddress?: CompleteAddress;
|
|
27
|
-
private encryptionPublicKey?: PublicKey;
|
|
28
|
-
private deployMethod?: DeployMethod;
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
private pxe: PXE,
|
|
32
|
-
private encryptionPrivateKey: GrumpkinPrivateKey,
|
|
33
|
-
private accountContract: AccountContract,
|
|
34
|
-
saltOrAddress?: Salt | CompleteAddress,
|
|
35
|
-
) {
|
|
36
|
-
if (saltOrAddress instanceof CompleteAddress) {
|
|
37
|
-
this.completeAddress = saltOrAddress;
|
|
38
|
-
} else {
|
|
39
|
-
this.salt = saltOrAddress ? new Fr(saltOrAddress) : Fr.random();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
protected getEncryptionPublicKey() {
|
|
44
|
-
if (!this.encryptionPublicKey) {
|
|
45
|
-
this.encryptionPublicKey = generatePublicKey(this.encryptionPrivateKey);
|
|
46
|
-
}
|
|
47
|
-
return this.encryptionPublicKey;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Returns the entrypoint for this account as defined by its account contract.
|
|
52
|
-
* @returns An entrypoint.
|
|
53
|
-
*/
|
|
54
|
-
public async getAccount(): Promise<AccountInterface> {
|
|
55
|
-
const nodeInfo = await this.pxe.getNodeInfo();
|
|
56
|
-
const completeAddress = this.getCompleteAddress();
|
|
57
|
-
return this.accountContract.getInterface(completeAddress, nodeInfo);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Gets the calculated complete address associated with this account.
|
|
62
|
-
* Does not require the account to be deployed or registered.
|
|
63
|
-
* @returns The address, partial address, and encryption public key.
|
|
64
|
-
*/
|
|
65
|
-
public getCompleteAddress(): CompleteAddress {
|
|
66
|
-
if (!this.completeAddress) {
|
|
67
|
-
const encryptionPublicKey = generatePublicKey(this.encryptionPrivateKey);
|
|
68
|
-
const contractDeploymentInfo = getContractDeploymentInfo(
|
|
69
|
-
this.accountContract.getContractArtifact(),
|
|
70
|
-
this.accountContract.getDeploymentArgs(),
|
|
71
|
-
this.salt!,
|
|
72
|
-
encryptionPublicKey,
|
|
73
|
-
);
|
|
74
|
-
this.completeAddress = contractDeploymentInfo.completeAddress;
|
|
75
|
-
}
|
|
76
|
-
return this.completeAddress;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Returns a Wallet instance associated with this account. Use it to create Contract
|
|
81
|
-
* instances to be interacted with from this account.
|
|
82
|
-
* @returns A Wallet instance.
|
|
83
|
-
*/
|
|
84
|
-
public async getWallet(): Promise<AccountWalletWithPrivateKey> {
|
|
85
|
-
const entrypoint = await this.getAccount();
|
|
86
|
-
return new AccountWalletWithPrivateKey(this.pxe, entrypoint, this.encryptionPrivateKey);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Registers this account in the PXE Service and returns the associated wallet. Registering
|
|
91
|
-
* the account on the PXE Service is required for managing private state associated with it.
|
|
92
|
-
* Use the returned wallet to create Contract instances to be interacted with from this account.
|
|
93
|
-
* @param opts - Options to wait for the account to be synched.
|
|
94
|
-
* @returns A Wallet instance.
|
|
95
|
-
*/
|
|
96
|
-
public async register(opts: WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithPrivateKey> {
|
|
97
|
-
const address = await this.#register();
|
|
98
|
-
await waitForAccountSynch(this.pxe, address, opts);
|
|
99
|
-
return this.getWallet();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Returns the pre-populated deployment method to deploy the account contract that backs this account.
|
|
104
|
-
* Typically you will not need this method and can call `deploy` directly. Use this for having finer
|
|
105
|
-
* grained control on when to create, simulate, and send the deployment tx.
|
|
106
|
-
* @returns A DeployMethod instance that deploys this account contract.
|
|
107
|
-
*/
|
|
108
|
-
public async getDeployMethod() {
|
|
109
|
-
if (!this.deployMethod) {
|
|
110
|
-
if (!this.salt) {
|
|
111
|
-
throw new Error(`Cannot deploy account contract without known salt.`);
|
|
112
|
-
}
|
|
113
|
-
await this.#register();
|
|
114
|
-
const encryptionPublicKey = this.getEncryptionPublicKey();
|
|
115
|
-
const deployer = new ContractDeployer(this.accountContract.getContractArtifact(), this.pxe, encryptionPublicKey);
|
|
116
|
-
const args = this.accountContract.getDeploymentArgs();
|
|
117
|
-
this.deployMethod = deployer.deploy(...args);
|
|
118
|
-
}
|
|
119
|
-
return this.deployMethod;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Deploys the account contract that backs this account.
|
|
124
|
-
* Uses the salt provided in the constructor or a randomly generated one.
|
|
125
|
-
* Note that if the Account is constructed with an explicit complete address
|
|
126
|
-
* it is assumed that the account contract has already been deployed and this method will throw.
|
|
127
|
-
* Registers the account in the PXE Service before deploying the contract.
|
|
128
|
-
* @returns A SentTx object that can be waited to get the associated Wallet.
|
|
129
|
-
*/
|
|
130
|
-
public async deploy(): Promise<DeployAccountSentTx> {
|
|
131
|
-
const deployMethod = await this.getDeployMethod();
|
|
132
|
-
const wallet = await this.getWallet();
|
|
133
|
-
const sentTx = deployMethod.send({ contractAddressSalt: this.salt });
|
|
134
|
-
return new DeployAccountSentTx(wallet, sentTx.getTxHash());
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Deploys the account contract that backs this account and awaits the tx to be mined.
|
|
139
|
-
* Uses the salt provided in the constructor or a randomly generated one.
|
|
140
|
-
* Note that if the Account is constructed with an explicit complete address
|
|
141
|
-
* it is assumed that the account contract has already been deployed and this method will throw.
|
|
142
|
-
* Registers the account in the PXE Service before deploying the contract.
|
|
143
|
-
* @param opts - Options to wait for the tx to be mined.
|
|
144
|
-
* @returns A Wallet instance.
|
|
145
|
-
*/
|
|
146
|
-
public async waitDeploy(opts: WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithPrivateKey> {
|
|
147
|
-
await this.deploy().then(tx => tx.wait(opts));
|
|
148
|
-
return this.getWallet();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async #register(): Promise<CompleteAddress> {
|
|
152
|
-
const completeAddress = this.getCompleteAddress();
|
|
153
|
-
await this.pxe.registerAccount(this.encryptionPrivateKey, completeAddress.partialAddress);
|
|
154
|
-
return completeAddress;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { CompleteAddress, PXE, WaitOpts, retryUntil } from '../../index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Waits for the account to finish synchronizing with the PXE Service.
|
|
5
|
-
* @param pxe - PXE instance
|
|
6
|
-
* @param address - Address to wait for synch
|
|
7
|
-
* @param opts - Wait options
|
|
8
|
-
*/
|
|
9
|
-
export async function waitForAccountSynch(
|
|
10
|
-
pxe: PXE,
|
|
11
|
-
address: CompleteAddress,
|
|
12
|
-
{ interval, timeout }: WaitOpts,
|
|
13
|
-
): Promise<void> {
|
|
14
|
-
const publicKey = address.publicKey.toString();
|
|
15
|
-
await retryUntil(
|
|
16
|
-
async () => {
|
|
17
|
-
const status = await pxe.getSyncStatus();
|
|
18
|
-
const accountSynchedToBlock = status.notes[publicKey];
|
|
19
|
-
if (typeof accountSynchedToBlock === 'undefined') {
|
|
20
|
-
return false;
|
|
21
|
-
} else {
|
|
22
|
-
return accountSynchedToBlock >= status.blocks;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
'waitForAccountSynch',
|
|
26
|
-
timeout,
|
|
27
|
-
interval,
|
|
28
|
-
);
|
|
29
|
-
}
|
package/src/account/utils.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { CompleteAddress, GrumpkinScalar } from '@aztec/circuits.js';
|
|
2
|
-
import { PXE } from '@aztec/types';
|
|
3
|
-
|
|
4
|
-
import { getSchnorrAccount } from '../index.js';
|
|
5
|
-
import { AccountWalletWithPrivateKey } from '../wallet/account_wallet.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Deploys and registers a new account using random private keys and returns the associated Schnorr account wallet. Useful for testing.
|
|
9
|
-
* @param pxe - PXE.
|
|
10
|
-
* @returns - A wallet for a fresh account.
|
|
11
|
-
*/
|
|
12
|
-
export function createAccount(pxe: PXE): Promise<AccountWalletWithPrivateKey> {
|
|
13
|
-
return getSchnorrAccount(pxe, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates a random address and registers it as a recipient on the pxe server. Useful for testing.
|
|
18
|
-
* @param pxe - PXE.
|
|
19
|
-
* @returns Complete address of the registered recipient.
|
|
20
|
-
*/
|
|
21
|
-
export async function createRecipient(pxe: PXE): Promise<CompleteAddress> {
|
|
22
|
-
const completeAddress = CompleteAddress.random();
|
|
23
|
-
await pxe.registerRecipient(completeAddress);
|
|
24
|
-
return completeAddress;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Creates a given number of random accounts using the Schnorr account wallet.
|
|
29
|
-
* @param pxe - PXE.
|
|
30
|
-
* @param numberOfAccounts - How many accounts to create.
|
|
31
|
-
* @returns The created account wallets.
|
|
32
|
-
*/
|
|
33
|
-
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<AccountWalletWithPrivateKey[]> {
|
|
34
|
-
const accounts = [];
|
|
35
|
-
|
|
36
|
-
// Prepare deployments
|
|
37
|
-
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
38
|
-
const account = getSchnorrAccount(pxe, GrumpkinScalar.random(), GrumpkinScalar.random());
|
|
39
|
-
await account.getDeployMethod().then(d => d.simulate({ contractAddressSalt: account.salt }));
|
|
40
|
-
accounts.push(account);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Send them and await them to be mined
|
|
44
|
-
const txs = await Promise.all(accounts.map(account => account.deploy()));
|
|
45
|
-
await Promise.all(txs.map(tx => tx.wait({ interval: 0.1 })));
|
|
46
|
-
return Promise.all(accounts.map(account => account.getWallet()));
|
|
47
|
-
}
|
package/src/api/README.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# API
|
|
2
|
-
|
|
3
|
-
This provides a more modular api for importing parts of the library as needed.
|
|
4
|
-
The root `index.js` just exposes everything, which can have consequences for startup times and optimizations.
|
|
5
|
-
Here we can gradually build up a much more granular api to allow importing precisely what's needed.
|
|
6
|
-
This should adopt the opposite philosophy to "export all my child exports".
|
|
7
|
-
Every file should (usually) export one thing, and the file/directory structure should be reflected in package.json exports.
|
package/src/api/abi.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ContractArtifact, FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
package/src/api/aztec_address.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { AztecAddress } from '@aztec/foundation/aztec-address';
|
package/src/api/eth_address.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { EthAddress } from '@aztec/foundation/eth-address';
|
package/src/api/ethereum.ts
DELETED
package/src/api/fields.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Point, Fr, Fq, GrumpkinScalar } from '@aztec/foundation/fields';
|
package/src/api/init.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { init as initAztecJs } from '@aztec/foundation/crypto';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PXE } from '@aztec/types/interfaces';
|
package/src/api/log_id.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { LogId } from '@aztec/types/log_id';
|
package/src/api/tx_hash.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { TxHash } from '@aztec/types/tx_hash';
|