@aztec/test-wallet 3.0.0-devnet.2

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.
@@ -0,0 +1,174 @@
1
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
2
+ import { SignerlessAccount } from '@aztec/aztec.js/account';
3
+ import { SetPublicAuthwitContractInteraction, getMessageHashFromIntent, lookupValidity } from '@aztec/aztec.js/authorization';
4
+ import { BaseWallet } from '@aztec/aztec.js/wallet';
5
+ import { AccountManager } from '@aztec/aztec.js/wallet';
6
+ import { mergeExecutionPayloads } from '@aztec/entrypoints/payload';
7
+ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
8
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
9
+ import { ProvenTx } from '../utils.js';
10
+ /**
11
+ * Wallet implementation that stores accounts in memory and allows allows their creation
12
+ * from the outside (which is something actual wallets shouldn't allow!)
13
+ * It is intended to be used in e2e tests.
14
+ */ export class BaseTestWallet extends BaseWallet {
15
+ accounts = new Map();
16
+ /**
17
+ * Toggle for running "simulated simulations" when calling simulateTx.
18
+ *
19
+ * Terminology:
20
+ * - "simulation": run private circuits normally and then run the kernel in a simulated (brillig) mode on ACVM.
21
+ * No kernel witnesses are generated, but protocol rules are checked.
22
+ * - "simulated simulation": skip running kernels in ACVM altogether and emulate their behavior in TypeScript
23
+ * (akin to generateSimulatedProvingResult). We mutate public inputs like the kernels would and can swap in
24
+ * fake/private bytecode or accounts for tests. This is much faster but is not usable in situations where we
25
+ * need kernel witnesses.
26
+ *
27
+ * When this flag is true, simulateTx constructs a request using a fake account (and accepts contract overrides
28
+ * on the input) and the PXE emulates kernel effects without generating kernel witnesses. When false, simulateTx
29
+ * defers to the standard simulation path.
30
+ */ simulatedSimulations = false;
31
+ /** Enable the "simulated simulation" path for simulateTx. */ enableSimulatedSimulations() {
32
+ this.simulatedSimulations = true;
33
+ }
34
+ /** Disable the "simulated simulation" path for simulateTx. */ disableSimulatedSimulations() {
35
+ this.simulatedSimulations = false;
36
+ }
37
+ setBaseFeePadding(value) {
38
+ this.baseFeePadding = value ?? 0.5;
39
+ }
40
+ async getAccountFromAddress(address) {
41
+ let account;
42
+ if (address.equals(AztecAddress.ZERO)) {
43
+ const chainInfo = await this.getChainInfo();
44
+ account = new SignerlessAccount(chainInfo);
45
+ } else {
46
+ account = this.accounts.get(address?.toString() ?? '');
47
+ }
48
+ if (!account) {
49
+ throw new Error(`Account not found in wallet for address: ${address}`);
50
+ }
51
+ return account;
52
+ }
53
+ getAccounts() {
54
+ return Promise.resolve(Array.from(this.accounts.values()).map((acc)=>({
55
+ alias: '',
56
+ item: acc.getAddress()
57
+ })));
58
+ }
59
+ /**
60
+ * Creates a new account with the provided account data or generates random values and uses SchnorrAccountContract
61
+ * if not provided.
62
+ *
63
+ * @param accountData - Optional account configuration containing secret, salt and account contract.
64
+ * @returns A new AccountManager instance for the created account
65
+ */ async createAccount(accountData) {
66
+ // Generate random values if not provided
67
+ const secret = accountData?.secret ?? Fr.random();
68
+ const salt = accountData?.salt ?? Fr.random();
69
+ // Use SchnorrAccountContract if not provided
70
+ const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
71
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
72
+ const instance = accountManager.getInstance();
73
+ const artifact = await contract.getContractArtifact();
74
+ await this.registerContract(instance, artifact, secret);
75
+ this.accounts.set(accountManager.address.toString(), await accountManager.getAccount());
76
+ return accountManager;
77
+ }
78
+ /**
79
+ * Lookup the validity of an authwit in private and public contexts.
80
+ *
81
+ * Uses the chain id and version of the wallet.
82
+ *
83
+ * @param wallet - The wallet use to simulate and read the public data
84
+ * @param onBehalfOf - The address of the "approver"
85
+ * @param intent - The consumer and inner hash or the caller and action to lookup
86
+ * @param witness - The computed authentication witness to check
87
+ * @returns - A struct containing the validity of the authwit in private and public contexts.
88
+ */ lookupValidity(onBehalfOf, intent, witness) {
89
+ return lookupValidity(this, onBehalfOf, intent, witness);
90
+ }
91
+ /**
92
+ * Returns an interaction that can be used to set the authorization status
93
+ * of an intent
94
+ * @param from - The address authorizing/revoking the action
95
+ * @param messageHashOrIntent - The action to authorize/revoke
96
+ * @param authorized - Whether the action can be performed or not
97
+ */ setPublicAuthWit(from, messageHashOrIntent, authorized) {
98
+ return SetPublicAuthwitContractInteraction.create(this, from, messageHashOrIntent, authorized);
99
+ }
100
+ /**
101
+ * Creates and returns an authwit according the the rules
102
+ * of the provided account. This authwit can be verified
103
+ * by the account contract
104
+ * @param from - The address authorizing the action
105
+ * @param messageHashOrIntent - The action to authorize
106
+ */ async createAuthWit(from, messageHashOrIntent) {
107
+ const account = await this.getAccountFromAddress(from);
108
+ const chainInfo = await this.getChainInfo();
109
+ const messageHash = await getMessageHashFromIntent(messageHashOrIntent, chainInfo);
110
+ return account.createAuthWit(messageHash);
111
+ }
112
+ async simulateTx(executionPayload, opts) {
113
+ if (!this.simulatedSimulations) {
114
+ return super.simulateTx(executionPayload, opts);
115
+ } else {
116
+ const feeOptions = opts.fee?.estimateGas ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee) : await this.getDefaultFeeOptions(opts.from, opts.fee);
117
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
118
+ const executionOptions = {
119
+ txNonce: Fr.random(),
120
+ cancellable: this.cancellableTransactions,
121
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
122
+ };
123
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
124
+ feeExecutionPayload,
125
+ executionPayload
126
+ ]) : executionPayload;
127
+ const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
128
+ const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
129
+ const contractOverrides = {
130
+ [opts.from.toString()]: {
131
+ instance,
132
+ artifact
133
+ }
134
+ };
135
+ return this.pxe.simulateTx(txRequest, true, true, true, {
136
+ contracts: contractOverrides
137
+ });
138
+ }
139
+ }
140
+ /**
141
+ * A utility to prove a transaction using this wallet and return it to be sent by a different entity on their own accord
142
+ *
143
+ * Note that this should not be used in production code since a proven transaction could be sent to a malicious
144
+ * node to index and track. It also makes it very difficult for the wallet to keep track of the interaction.
145
+ * @param exec - The execution payload to prove.
146
+ * @param opts - The options to configure the interaction
147
+ * @returns - A proven tx ready to be sent to the network
148
+ */ async proveTx(exec, opts) {
149
+ const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
150
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
151
+ const txProvingResult = await this.pxe.proveTx(txRequest);
152
+ return new ProvenTx(this.aztecNode, await txProvingResult.toTx(), txProvingResult.getOffchainEffects(), txProvingResult.stats);
153
+ }
154
+ /**
155
+ * A debugging utility to get notes based on the provided filter.
156
+ *
157
+ * Note that this should not be used in production code because the structure of notes is considered to be
158
+ * an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
159
+ * note-related information in production code, please implement a custom utility function on your contract and call
160
+ * that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
161
+ *
162
+ * @param filter - The filter to apply to the notes.
163
+ * @returns The requested notes.
164
+ */ getNotes(filter) {
165
+ return this.pxe.getNotes(filter);
166
+ }
167
+ /**
168
+ * Stops the internal job queue.
169
+ *
170
+ * This function is typically used when tearing down tests.
171
+ */ stop() {
172
+ return this.pxe.stop();
173
+ }
174
+ }
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@aztec/test-wallet",
3
+ "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/test-wallet",
4
+ "version": "3.0.0-devnet.2",
5
+ "type": "module",
6
+ "exports": {
7
+ "./client/bundle": "./dest/bundle.js",
8
+ "./client/lazy": "./dest/lazy.js",
9
+ "./server": "./dest/server.js"
10
+ },
11
+ "typedocOptions": {
12
+ "entryPoints": [
13
+ "./src/index.ts"
14
+ ],
15
+ "tsconfig": "./tsconfig.json"
16
+ },
17
+ "scripts": {
18
+ "build": "yarn clean && tsc -b",
19
+ "build:dev": "tsc -b --watch",
20
+ "build:ts": "tsc -b",
21
+ "clean": "rm -rf ./dest .tsbuildinfo",
22
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
23
+ },
24
+ "inherits": [
25
+ "../package.common.json"
26
+ ],
27
+ "jest": {
28
+ "moduleNameMapper": {
29
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
30
+ },
31
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
32
+ "rootDir": "./src",
33
+ "transform": {
34
+ "^.+\\.tsx?$": [
35
+ "@swc/jest",
36
+ {
37
+ "jsc": {
38
+ "parser": {
39
+ "syntax": "typescript",
40
+ "decorators": true
41
+ },
42
+ "transform": {
43
+ "decoratorVersion": "2022-03"
44
+ }
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ "extensionsToTreatAsEsm": [
50
+ ".ts"
51
+ ],
52
+ "reporters": [
53
+ "default"
54
+ ],
55
+ "testTimeout": 120000,
56
+ "setupFiles": [
57
+ "../../foundation/src/jest/setup.mjs"
58
+ ],
59
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
60
+ "setupFilesAfterEnv": [
61
+ "../../foundation/src/jest/setupAfterEnv.mjs"
62
+ ]
63
+ },
64
+ "dependencies": {
65
+ "@aztec/accounts": "3.0.0-devnet.2",
66
+ "@aztec/aztec.js": "3.0.0-devnet.2",
67
+ "@aztec/entrypoints": "3.0.0-devnet.2",
68
+ "@aztec/foundation": "3.0.0-devnet.2",
69
+ "@aztec/noir-contracts.js": "3.0.0-devnet.2",
70
+ "@aztec/pxe": "3.0.0-devnet.2",
71
+ "@aztec/stdlib": "3.0.0-devnet.2"
72
+ },
73
+ "devDependencies": {
74
+ "@jest/globals": "^30.0.0",
75
+ "@types/jest": "^30.0.0",
76
+ "@types/node": "^22.15.17",
77
+ "jest": "^30.0.0",
78
+ "resolve-typescript-plugin": "^2.0.1",
79
+ "ts-loader": "^9.5.4",
80
+ "ts-node": "^10.9.1",
81
+ "typescript": "^5.3.3",
82
+ "util": "^0.12.5"
83
+ },
84
+ "files": [
85
+ "dest",
86
+ "src",
87
+ "!*.test.*",
88
+ "artifacts"
89
+ ],
90
+ "types": "./dest/index.d.ts",
91
+ "engines": {
92
+ "node": ">=20.10"
93
+ }
94
+ }
package/src/bundle.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { TestWallet } from './wallet/bundle.js';
2
+ export { type AccountData } from './wallet/test_wallet.js';
3
+ export {
4
+ deployFundedSchnorrAccounts,
5
+ registerInitialSandboxAccountsInWallet,
6
+ ProvenTx,
7
+ proveInteraction,
8
+ } from './utils.js';
package/src/lazy.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { TestWallet } from './wallet/lazy.js';
2
+ export { type AccountData } from './wallet/test_wallet.js';
3
+ export {
4
+ deployFundedSchnorrAccounts,
5
+ registerInitialSandboxAccountsInWallet,
6
+ ProvenTx,
7
+ proveInteraction,
8
+ } from './utils.js';
package/src/server.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { TestWallet } from './wallet/server.js';
2
+ export { type AccountData } from './wallet/test_wallet.js';
3
+ export {
4
+ deployFundedSchnorrAccounts,
5
+ registerInitialSandboxAccountsInWallet,
6
+ ProvenTx,
7
+ proveInteraction,
8
+ } from './utils.js';
package/src/utils.ts ADDED
@@ -0,0 +1,101 @@
1
+ import type { InitialAccountData } from '@aztec/accounts/testing';
2
+ import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
3
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
4
+ import {
5
+ ContractFunctionInteraction,
6
+ DeployMethod,
7
+ type DeployOptions,
8
+ type SendInteractionOptions,
9
+ SentTx,
10
+ type WaitOpts,
11
+ toSendOptions,
12
+ } from '@aztec/aztec.js/contracts';
13
+ import type { AztecNode } from '@aztec/aztec.js/node';
14
+ import { type OffchainEffect, type ProvingStats, Tx } from '@aztec/stdlib/tx';
15
+
16
+ import type { BaseTestWallet } from './wallet/test_wallet.js';
17
+
18
+ /**
19
+ * Deploys the SchnorrAccount contracts backed by prefunded addresses
20
+ * at genesis. This can be directly used to pay for transactions in FeeJuice.
21
+ */
22
+ export async function deployFundedSchnorrAccounts(
23
+ wallet: BaseTestWallet,
24
+ aztecNode: AztecNode,
25
+ accountsData: InitialAccountData[],
26
+ waitOptions?: WaitOpts,
27
+ ) {
28
+ const accountManagers = [];
29
+ // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
30
+ for (let i = 0; i < accountsData.length; i++) {
31
+ const { secret, salt, signingKey } = accountsData[i];
32
+ const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
33
+ const deployMethod = await accountManager.getDeployMethod();
34
+ await deployMethod
35
+ .send({
36
+ from: AztecAddress.ZERO,
37
+ skipClassPublication: i !== 0, // Publish the contract class at most once.
38
+ })
39
+ .wait(waitOptions);
40
+ accountManagers.push(accountManager);
41
+ }
42
+ return accountManagers;
43
+ }
44
+
45
+ /**
46
+ * Registers the initial sandbox accounts in the wallet.
47
+ * @param wallet - Test wallet to use to register the accounts.
48
+ * @returns Addresses of the registered accounts.
49
+ */
50
+ export async function registerInitialSandboxAccountsInWallet(wallet: BaseTestWallet): Promise<AztecAddress[]> {
51
+ const testAccounts = await getInitialTestAccountsData();
52
+ return Promise.all(
53
+ testAccounts.map(async account => {
54
+ return (await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey)).address;
55
+ }),
56
+ );
57
+ }
58
+ /**
59
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of the test wallet
60
+ */
61
+ export class ProvenTx extends Tx {
62
+ constructor(
63
+ private node: AztecNode,
64
+ tx: Tx,
65
+ /** The offchain effects emitted during the execution of the transaction. */
66
+ public offchainEffects: OffchainEffect[],
67
+ // eslint-disable-next-line jsdoc/require-jsdoc
68
+ public stats?: ProvingStats,
69
+ ) {
70
+ super(tx.getTxHash(), tx.data, tx.clientIvcProof, tx.contractClassLogFields, tx.publicFunctionCalldata);
71
+ }
72
+
73
+ send() {
74
+ const sendTx = async () => {
75
+ await this.node.sendTx(this);
76
+ return this.getTxHash();
77
+ };
78
+ return new SentTx(this.node, sendTx);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Helper function to prove an interaction via a TestWallet
84
+ * @param wallet - The TestWallet to use
85
+ * @param interaction - The interaction to prove
86
+ * @param options - Either SendInteractionOptions (for ContractFunctionInteraction) or DeployOptions (for DeployMethod)
87
+ * @returns - A proven transaction ready do be sent to the network
88
+ */
89
+ export async function proveInteraction(
90
+ wallet: BaseTestWallet,
91
+ interaction: ContractFunctionInteraction | DeployMethod,
92
+ options: SendInteractionOptions | DeployOptions,
93
+ ) {
94
+ let execPayload;
95
+ if (interaction instanceof DeployMethod) {
96
+ execPayload = await interaction.request(interaction.convertDeployOptionsToRequestOptions(options));
97
+ } else {
98
+ execPayload = await interaction.request(options);
99
+ }
100
+ return wallet.proveTx(execPayload, await toSendOptions(options));
101
+ }
@@ -0,0 +1,79 @@
1
+ import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
+ import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
4
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
5
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
6
+ import { Fq, Fr } from '@aztec/aztec.js/fields';
7
+ import type { AztecNode } from '@aztec/aztec.js/node';
8
+ import { AccountManager } from '@aztec/aztec.js/wallet';
9
+ import { type PXEConfig, type PXECreationOptions, createPXE, getPXEConfig } from '@aztec/pxe/client/bundle';
10
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
11
+
12
+ import { BaseTestWallet } from './test_wallet.js';
13
+
14
+ /**
15
+ * A TestWallet implementation that loads the account contract artifacts eagerly
16
+ * Note that the only difference from `lazy` and `server` test wallets is that it uses the `createPXE` function
17
+ * from the `pxe/client/bundle` package.
18
+ */
19
+ export class TestWallet extends BaseTestWallet {
20
+ static async create(
21
+ node: AztecNode,
22
+ overridePXEConfig?: Partial<PXEConfig>,
23
+ options: PXECreationOptions = { loggers: {} },
24
+ ): Promise<TestWallet> {
25
+ const pxeConfig = Object.assign(getPXEConfig(), {
26
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
27
+ ...overridePXEConfig,
28
+ });
29
+ const pxe = await createPXE(node, pxeConfig, options);
30
+ return new TestWallet(pxe, node);
31
+ }
32
+
33
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
34
+ signingKey = signingKey ?? deriveSigningKey(secret);
35
+ const accountData = {
36
+ secret,
37
+ salt,
38
+ contract: new SchnorrAccountContract(signingKey),
39
+ };
40
+ return this.createAccount(accountData);
41
+ }
42
+
43
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
44
+ const accountData = {
45
+ secret,
46
+ salt,
47
+ contract: new EcdsaRAccountContract(signingKey),
48
+ };
49
+ return this.createAccount(accountData);
50
+ }
51
+
52
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
53
+ const accountData = {
54
+ secret,
55
+ salt,
56
+ contract: new EcdsaKAccountContract(signingKey),
57
+ };
58
+ return this.createAccount(accountData);
59
+ }
60
+
61
+ async getFakeAccountDataFor(address: AztecAddress) {
62
+ const chainInfo = await this.getChainInfo();
63
+ const originalAccount = await this.getAccountFromAddress(address);
64
+ const originalAddress = originalAccount.getCompleteAddress();
65
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
66
+ if (!contractInstance) {
67
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
68
+ }
69
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
70
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
71
+ salt: Fr.random(),
72
+ });
73
+ return {
74
+ account: stubAccount,
75
+ instance,
76
+ artifact: StubAccountContractArtifact,
77
+ };
78
+ }
79
+ }
@@ -0,0 +1,80 @@
1
+ import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa/lazy';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr/lazy';
3
+ import { createStubAccount, getStubAccountContractArtifact } from '@aztec/accounts/stub/lazy';
4
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
5
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
6
+ import { Fq, Fr } from '@aztec/aztec.js/fields';
7
+ import type { AztecNode } from '@aztec/aztec.js/node';
8
+ import { AccountManager } from '@aztec/aztec.js/wallet';
9
+ import { type PXEConfig, type PXECreationOptions, createPXE, getPXEConfig } from '@aztec/pxe/client/lazy';
10
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
11
+
12
+ import { BaseTestWallet } from './test_wallet.js';
13
+
14
+ /**
15
+ * A TestWallet implementation that loads the account contract artifacts lazily
16
+ * Note that the only difference from `server` and `bundle` test wallets is that it uses the `createPXE` function
17
+ * from the `pxe/client/lazy` package.
18
+ */
19
+ export class TestWallet extends BaseTestWallet {
20
+ static async create(
21
+ node: AztecNode,
22
+ overridePXEConfig?: Partial<PXEConfig>,
23
+ options: PXECreationOptions = { loggers: {} },
24
+ ): Promise<TestWallet> {
25
+ const pxeConfig = Object.assign(getPXEConfig(), {
26
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
27
+ ...overridePXEConfig,
28
+ });
29
+ const pxe = await createPXE(node, pxeConfig, options);
30
+ return new TestWallet(pxe, node);
31
+ }
32
+
33
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
34
+ signingKey = signingKey ?? deriveSigningKey(secret);
35
+ const accountData = {
36
+ secret,
37
+ salt,
38
+ contract: new SchnorrAccountContract(signingKey),
39
+ };
40
+ return this.createAccount(accountData);
41
+ }
42
+
43
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
44
+ const accountData = {
45
+ secret,
46
+ salt,
47
+ contract: new EcdsaRAccountContract(signingKey),
48
+ };
49
+ return this.createAccount(accountData);
50
+ }
51
+
52
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
53
+ const accountData = {
54
+ secret,
55
+ salt,
56
+ contract: new EcdsaKAccountContract(signingKey),
57
+ };
58
+ return this.createAccount(accountData);
59
+ }
60
+
61
+ async getFakeAccountDataFor(address: AztecAddress) {
62
+ const chainInfo = await this.getChainInfo();
63
+ const originalAccount = await this.getAccountFromAddress(address);
64
+ const originalAddress = originalAccount.getCompleteAddress();
65
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
66
+ if (!contractInstance) {
67
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
68
+ }
69
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
70
+ const StubAccountContractArtifact = await getStubAccountContractArtifact();
71
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
72
+ salt: Fr.random(),
73
+ });
74
+ return {
75
+ account: stubAccount,
76
+ instance,
77
+ artifact: StubAccountContractArtifact,
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,79 @@
1
+ import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
+ import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
4
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
5
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
6
+ import { Fq, Fr } from '@aztec/aztec.js/fields';
7
+ import type { AztecNode } from '@aztec/aztec.js/node';
8
+ import { AccountManager } from '@aztec/aztec.js/wallet';
9
+ import { type PXEConfig, type PXECreationOptions, createPXE, getPXEConfig } from '@aztec/pxe/server';
10
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
11
+
12
+ import { BaseTestWallet } from './test_wallet.js';
13
+
14
+ /**
15
+ * A TestWallet implementation to be used in server settings (e.g. e2e tests).
16
+ * Note that the only difference from `lazy` and `bundle` test wallets is that it uses the `createPXE` function
17
+ * from the `pxe/server` package.
18
+ */
19
+ export class TestWallet extends BaseTestWallet {
20
+ static async create(
21
+ node: AztecNode,
22
+ overridePXEConfig?: Partial<PXEConfig>,
23
+ options: PXECreationOptions = { loggers: {} },
24
+ ): Promise<TestWallet> {
25
+ const pxeConfig = Object.assign(getPXEConfig(), {
26
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
27
+ ...overridePXEConfig,
28
+ });
29
+ const pxe = await createPXE(node, pxeConfig, options);
30
+ return new TestWallet(pxe, node);
31
+ }
32
+
33
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
34
+ signingKey = signingKey ?? deriveSigningKey(secret);
35
+ const accountData = {
36
+ secret,
37
+ salt,
38
+ contract: new SchnorrAccountContract(signingKey),
39
+ };
40
+ return this.createAccount(accountData);
41
+ }
42
+
43
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
44
+ const accountData = {
45
+ secret,
46
+ salt,
47
+ contract: new EcdsaRAccountContract(signingKey),
48
+ };
49
+ return this.createAccount(accountData);
50
+ }
51
+
52
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
53
+ const accountData = {
54
+ secret,
55
+ salt,
56
+ contract: new EcdsaKAccountContract(signingKey),
57
+ };
58
+ return this.createAccount(accountData);
59
+ }
60
+
61
+ async getFakeAccountDataFor(address: AztecAddress) {
62
+ const chainInfo = await this.getChainInfo();
63
+ const originalAccount = await this.getAccountFromAddress(address);
64
+ const originalAddress = originalAccount.getCompleteAddress();
65
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
66
+ if (!contractInstance) {
67
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
68
+ }
69
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
70
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
71
+ salt: Fr.random(),
72
+ });
73
+ return {
74
+ account: stubAccount,
75
+ instance,
76
+ artifact: StubAccountContractArtifact,
77
+ };
78
+ }
79
+ }