@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,4 @@
1
+ export { TestWallet } from './wallet/bundle.js';
2
+ export { type AccountData } from './wallet/test_wallet.js';
3
+ export { deployFundedSchnorrAccounts, registerInitialSandboxAccountsInWallet, ProvenTx, proveInteraction, } from './utils.js';
4
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,2BAA2B,EAC3B,sCAAsC,EACtC,QAAQ,EACR,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
package/dest/bundle.js ADDED
@@ -0,0 +1,2 @@
1
+ export { TestWallet } from './wallet/bundle.js';
2
+ export { deployFundedSchnorrAccounts, registerInitialSandboxAccountsInWallet, ProvenTx, proveInteraction } from './utils.js';
package/dest/lazy.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { TestWallet } from './wallet/lazy.js';
2
+ export { type AccountData } from './wallet/test_wallet.js';
3
+ export { deployFundedSchnorrAccounts, registerInitialSandboxAccountsInWallet, ProvenTx, proveInteraction, } from './utils.js';
4
+ //# sourceMappingURL=lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,2BAA2B,EAC3B,sCAAsC,EACtC,QAAQ,EACR,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
package/dest/lazy.js ADDED
@@ -0,0 +1,2 @@
1
+ export { TestWallet } from './wallet/lazy.js';
2
+ export { deployFundedSchnorrAccounts, registerInitialSandboxAccountsInWallet, ProvenTx, proveInteraction } from './utils.js';
@@ -0,0 +1,4 @@
1
+ export { TestWallet } from './wallet/server.js';
2
+ export { type AccountData } from './wallet/test_wallet.js';
3
+ export { deployFundedSchnorrAccounts, registerInitialSandboxAccountsInWallet, ProvenTx, proveInteraction, } from './utils.js';
4
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,2BAA2B,EAC3B,sCAAsC,EACtC,QAAQ,EACR,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
package/dest/server.js ADDED
@@ -0,0 +1,2 @@
1
+ export { TestWallet } from './wallet/server.js';
2
+ export { deployFundedSchnorrAccounts, registerInitialSandboxAccountsInWallet, ProvenTx, proveInteraction } from './utils.js';
@@ -0,0 +1,39 @@
1
+ import type { InitialAccountData } from '@aztec/accounts/testing';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { ContractFunctionInteraction, DeployMethod, type DeployOptions, type SendInteractionOptions, SentTx, type WaitOpts } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
5
+ import { type OffchainEffect, type ProvingStats, Tx } from '@aztec/stdlib/tx';
6
+ import type { BaseTestWallet } from './wallet/test_wallet.js';
7
+ /**
8
+ * Deploys the SchnorrAccount contracts backed by prefunded addresses
9
+ * at genesis. This can be directly used to pay for transactions in FeeJuice.
10
+ */
11
+ export declare function deployFundedSchnorrAccounts(wallet: BaseTestWallet, aztecNode: AztecNode, accountsData: InitialAccountData[], waitOptions?: WaitOpts): Promise<import("@aztec/aztec.js/wallet").AccountManager[]>;
12
+ /**
13
+ * Registers the initial sandbox accounts in the wallet.
14
+ * @param wallet - Test wallet to use to register the accounts.
15
+ * @returns Addresses of the registered accounts.
16
+ */
17
+ export declare function registerInitialSandboxAccountsInWallet(wallet: BaseTestWallet): Promise<AztecAddress[]>;
18
+ /**
19
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of the test wallet
20
+ */
21
+ export declare class ProvenTx extends Tx {
22
+ private node;
23
+ /** The offchain effects emitted during the execution of the transaction. */
24
+ offchainEffects: OffchainEffect[];
25
+ stats?: ProvingStats | undefined;
26
+ constructor(node: AztecNode, tx: Tx,
27
+ /** The offchain effects emitted during the execution of the transaction. */
28
+ offchainEffects: OffchainEffect[], stats?: ProvingStats | undefined);
29
+ send(): SentTx;
30
+ }
31
+ /**
32
+ * Helper function to prove an interaction via a TestWallet
33
+ * @param wallet - The TestWallet to use
34
+ * @param interaction - The interaction to prove
35
+ * @param options - Either SendInteractionOptions (for ContractFunctionInteraction) or DeployOptions (for DeployMethod)
36
+ * @returns - A proven transaction ready do be sent to the network
37
+ */
38
+ export declare function proveInteraction(wallet: BaseTestWallet, interaction: ContractFunctionInteraction | DeployMethod, options: SendInteractionOptions | DeployOptions): Promise<ProvenTx>;
39
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,MAAM,EACN,KAAK,QAAQ,EAEd,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D;;;GAGG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAAE,EAClC,WAAW,CAAC,EAAE,QAAQ,8DAiBvB;AAED;;;;GAIG;AACH,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAO5G;AACD;;GAEG;AACH,qBAAa,QAAS,SAAQ,EAAE;IAE5B,OAAO,CAAC,IAAI;IAEZ,4EAA4E;IACrE,eAAe,EAAE,cAAc,EAAE;IAEjC,KAAK,CAAC,EAAE,YAAY;gBALnB,IAAI,EAAE,SAAS,EACvB,EAAE,EAAE,EAAE;IACN,4EAA4E;IACrE,eAAe,EAAE,cAAc,EAAE,EAEjC,KAAK,CAAC,EAAE,YAAY,YAAA;IAK7B,IAAI;CAOL;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,WAAW,EAAE,2BAA2B,GAAG,YAAY,EACvD,OAAO,EAAE,sBAAsB,GAAG,aAAa,qBAShD"}
package/dest/utils.js ADDED
@@ -0,0 +1,65 @@
1
+ import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { DeployMethod, SentTx, toSendOptions } from '@aztec/aztec.js/contracts';
4
+ import { Tx } from '@aztec/stdlib/tx';
5
+ /**
6
+ * Deploys the SchnorrAccount contracts backed by prefunded addresses
7
+ * at genesis. This can be directly used to pay for transactions in FeeJuice.
8
+ */ export async function deployFundedSchnorrAccounts(wallet, aztecNode, accountsData, waitOptions) {
9
+ const accountManagers = [];
10
+ // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
11
+ for(let i = 0; i < accountsData.length; i++){
12
+ const { secret, salt, signingKey } = accountsData[i];
13
+ const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
14
+ const deployMethod = await accountManager.getDeployMethod();
15
+ await deployMethod.send({
16
+ from: AztecAddress.ZERO,
17
+ skipClassPublication: i !== 0
18
+ }).wait(waitOptions);
19
+ accountManagers.push(accountManager);
20
+ }
21
+ return accountManagers;
22
+ }
23
+ /**
24
+ * Registers the initial sandbox accounts in the wallet.
25
+ * @param wallet - Test wallet to use to register the accounts.
26
+ * @returns Addresses of the registered accounts.
27
+ */ export async function registerInitialSandboxAccountsInWallet(wallet) {
28
+ const testAccounts = await getInitialTestAccountsData();
29
+ return Promise.all(testAccounts.map(async (account)=>{
30
+ return (await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey)).address;
31
+ }));
32
+ }
33
+ /**
34
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of the test wallet
35
+ */ export class ProvenTx extends Tx {
36
+ node;
37
+ offchainEffects;
38
+ stats;
39
+ constructor(node, tx, /** The offchain effects emitted during the execution of the transaction. */ offchainEffects, // eslint-disable-next-line jsdoc/require-jsdoc
40
+ stats){
41
+ super(tx.getTxHash(), tx.data, tx.clientIvcProof, tx.contractClassLogFields, tx.publicFunctionCalldata), this.node = node, this.offchainEffects = offchainEffects, this.stats = stats;
42
+ }
43
+ send() {
44
+ const sendTx = async ()=>{
45
+ await this.node.sendTx(this);
46
+ return this.getTxHash();
47
+ };
48
+ return new SentTx(this.node, sendTx);
49
+ }
50
+ }
51
+ /**
52
+ * Helper function to prove an interaction via a TestWallet
53
+ * @param wallet - The TestWallet to use
54
+ * @param interaction - The interaction to prove
55
+ * @param options - Either SendInteractionOptions (for ContractFunctionInteraction) or DeployOptions (for DeployMethod)
56
+ * @returns - A proven transaction ready do be sent to the network
57
+ */ export async function proveInteraction(wallet, interaction, options) {
58
+ let execPayload;
59
+ if (interaction instanceof DeployMethod) {
60
+ execPayload = await interaction.request(interaction.convertDeployOptionsToRequestOptions(options));
61
+ } else {
62
+ execPayload = await interaction.request(options);
63
+ }
64
+ return wallet.proveTx(execPayload, await toSendOptions(options));
65
+ }
@@ -0,0 +1,23 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { Fq, Fr } from '@aztec/aztec.js/fields';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import { AccountManager } from '@aztec/aztec.js/wallet';
5
+ import { type PXEConfig, type PXECreationOptions } from '@aztec/pxe/client/bundle';
6
+ import { BaseTestWallet } from './test_wallet.js';
7
+ /**
8
+ * A TestWallet implementation that loads the account contract artifacts eagerly
9
+ * Note that the only difference from `lazy` and `server` test wallets is that it uses the `createPXE` function
10
+ * from the `pxe/client/bundle` package.
11
+ */
12
+ export declare class TestWallet extends BaseTestWallet {
13
+ static create(node: AztecNode, overridePXEConfig?: Partial<PXEConfig>, options?: PXECreationOptions): Promise<TestWallet>;
14
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager>;
15
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
16
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
17
+ getFakeAccountDataFor(address: AztecAddress): Promise<{
18
+ account: import("@aztec/aztec.js/account").BaseAccount;
19
+ instance: import("@aztec/aztec.js/contracts").ContractInstanceWithAddress;
20
+ artifact: import("@aztec/aztec.js/abi").ContractArtifact;
21
+ }>;
22
+ }
23
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/wallet/bundle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAA2B,MAAM,0BAA0B,CAAC;AAG5G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc;WAC/B,MAAM,CACjB,IAAI,EAAE,SAAS,EACf,iBAAiB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EACtC,OAAO,GAAE,kBAAoC,GAC5C,OAAO,CAAC,UAAU,CAAC;IAStB,oBAAoB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAUpF,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAStF,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAShF,qBAAqB,CAAC,OAAO,EAAE,YAAY;;;;;CAkBlD"}
@@ -0,0 +1,67 @@
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 { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
5
+ import { Fr } from '@aztec/aztec.js/fields';
6
+ import { createPXE, getPXEConfig } from '@aztec/pxe/client/bundle';
7
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
8
+ import { BaseTestWallet } from './test_wallet.js';
9
+ /**
10
+ * A TestWallet implementation that loads the account contract artifacts eagerly
11
+ * Note that the only difference from `lazy` and `server` test wallets is that it uses the `createPXE` function
12
+ * from the `pxe/client/bundle` package.
13
+ */ export class TestWallet extends BaseTestWallet {
14
+ static async create(node, overridePXEConfig, options = {
15
+ loggers: {}
16
+ }) {
17
+ const pxeConfig = Object.assign(getPXEConfig(), {
18
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
19
+ ...overridePXEConfig
20
+ });
21
+ const pxe = await createPXE(node, pxeConfig, options);
22
+ return new TestWallet(pxe, node);
23
+ }
24
+ createSchnorrAccount(secret, salt, signingKey) {
25
+ signingKey = signingKey ?? deriveSigningKey(secret);
26
+ const accountData = {
27
+ secret,
28
+ salt,
29
+ contract: new SchnorrAccountContract(signingKey)
30
+ };
31
+ return this.createAccount(accountData);
32
+ }
33
+ createECDSARAccount(secret, salt, signingKey) {
34
+ const accountData = {
35
+ secret,
36
+ salt,
37
+ contract: new EcdsaRAccountContract(signingKey)
38
+ };
39
+ return this.createAccount(accountData);
40
+ }
41
+ createECDSAKAccount(secret, salt, signingKey) {
42
+ const accountData = {
43
+ secret,
44
+ salt,
45
+ contract: new EcdsaKAccountContract(signingKey)
46
+ };
47
+ return this.createAccount(accountData);
48
+ }
49
+ async getFakeAccountDataFor(address) {
50
+ const chainInfo = await this.getChainInfo();
51
+ const originalAccount = await this.getAccountFromAddress(address);
52
+ const originalAddress = originalAccount.getCompleteAddress();
53
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
54
+ if (!contractInstance) {
55
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
56
+ }
57
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
58
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
59
+ salt: Fr.random()
60
+ });
61
+ return {
62
+ account: stubAccount,
63
+ instance,
64
+ artifact: StubAccountContractArtifact
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,23 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { Fq, Fr } from '@aztec/aztec.js/fields';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import { AccountManager } from '@aztec/aztec.js/wallet';
5
+ import { type PXEConfig, type PXECreationOptions } from '@aztec/pxe/client/lazy';
6
+ import { BaseTestWallet } from './test_wallet.js';
7
+ /**
8
+ * A TestWallet implementation that loads the account contract artifacts lazily
9
+ * Note that the only difference from `server` and `bundle` test wallets is that it uses the `createPXE` function
10
+ * from the `pxe/client/lazy` package.
11
+ */
12
+ export declare class TestWallet extends BaseTestWallet {
13
+ static create(node: AztecNode, overridePXEConfig?: Partial<PXEConfig>, options?: PXECreationOptions): Promise<TestWallet>;
14
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager>;
15
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
16
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
17
+ getFakeAccountDataFor(address: AztecAddress): Promise<{
18
+ account: import("@aztec/aztec.js/account").BaseAccount;
19
+ instance: import("@aztec/aztec.js/contracts").ContractInstanceWithAddress;
20
+ artifact: import("@aztec/aztec.js/abi").ContractArtifact;
21
+ }>;
22
+ }
23
+ //# sourceMappingURL=lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/wallet/lazy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAA2B,MAAM,wBAAwB,CAAC;AAG1G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc;WAC/B,MAAM,CACjB,IAAI,EAAE,SAAS,EACf,iBAAiB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EACtC,OAAO,GAAE,kBAAoC,GAC5C,OAAO,CAAC,UAAU,CAAC;IAStB,oBAAoB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAUpF,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAStF,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAShF,qBAAqB,CAAC,OAAO,EAAE,YAAY;;;;;CAmBlD"}
@@ -0,0 +1,68 @@
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 { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
5
+ import { Fr } from '@aztec/aztec.js/fields';
6
+ import { createPXE, getPXEConfig } from '@aztec/pxe/client/lazy';
7
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
8
+ import { BaseTestWallet } from './test_wallet.js';
9
+ /**
10
+ * A TestWallet implementation that loads the account contract artifacts lazily
11
+ * Note that the only difference from `server` and `bundle` test wallets is that it uses the `createPXE` function
12
+ * from the `pxe/client/lazy` package.
13
+ */ export class TestWallet extends BaseTestWallet {
14
+ static async create(node, overridePXEConfig, options = {
15
+ loggers: {}
16
+ }) {
17
+ const pxeConfig = Object.assign(getPXEConfig(), {
18
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
19
+ ...overridePXEConfig
20
+ });
21
+ const pxe = await createPXE(node, pxeConfig, options);
22
+ return new TestWallet(pxe, node);
23
+ }
24
+ createSchnorrAccount(secret, salt, signingKey) {
25
+ signingKey = signingKey ?? deriveSigningKey(secret);
26
+ const accountData = {
27
+ secret,
28
+ salt,
29
+ contract: new SchnorrAccountContract(signingKey)
30
+ };
31
+ return this.createAccount(accountData);
32
+ }
33
+ createECDSARAccount(secret, salt, signingKey) {
34
+ const accountData = {
35
+ secret,
36
+ salt,
37
+ contract: new EcdsaRAccountContract(signingKey)
38
+ };
39
+ return this.createAccount(accountData);
40
+ }
41
+ createECDSAKAccount(secret, salt, signingKey) {
42
+ const accountData = {
43
+ secret,
44
+ salt,
45
+ contract: new EcdsaKAccountContract(signingKey)
46
+ };
47
+ return this.createAccount(accountData);
48
+ }
49
+ async getFakeAccountDataFor(address) {
50
+ const chainInfo = await this.getChainInfo();
51
+ const originalAccount = await this.getAccountFromAddress(address);
52
+ const originalAddress = originalAccount.getCompleteAddress();
53
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
54
+ if (!contractInstance) {
55
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
56
+ }
57
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
58
+ const StubAccountContractArtifact = await getStubAccountContractArtifact();
59
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
60
+ salt: Fr.random()
61
+ });
62
+ return {
63
+ account: stubAccount,
64
+ instance,
65
+ artifact: StubAccountContractArtifact
66
+ };
67
+ }
68
+ }
@@ -0,0 +1,23 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { Fq, Fr } from '@aztec/aztec.js/fields';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import { AccountManager } from '@aztec/aztec.js/wallet';
5
+ import { type PXEConfig, type PXECreationOptions } from '@aztec/pxe/server';
6
+ import { BaseTestWallet } from './test_wallet.js';
7
+ /**
8
+ * A TestWallet implementation to be used in server settings (e.g. e2e tests).
9
+ * Note that the only difference from `lazy` and `bundle` test wallets is that it uses the `createPXE` function
10
+ * from the `pxe/server` package.
11
+ */
12
+ export declare class TestWallet extends BaseTestWallet {
13
+ static create(node: AztecNode, overridePXEConfig?: Partial<PXEConfig>, options?: PXECreationOptions): Promise<TestWallet>;
14
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager>;
15
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
16
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
17
+ getFakeAccountDataFor(address: AztecAddress): Promise<{
18
+ account: import("@aztec/aztec.js/account").BaseAccount;
19
+ instance: import("@aztec/aztec.js/contracts").ContractInstanceWithAddress;
20
+ artifact: import("@aztec/aztec.js/abi").ContractArtifact;
21
+ }>;
22
+ }
23
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/wallet/server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAA2B,MAAM,mBAAmB,CAAC;AAGrG,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc;WAC/B,MAAM,CACjB,IAAI,EAAE,SAAS,EACf,iBAAiB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EACtC,OAAO,GAAE,kBAAoC,GAC5C,OAAO,CAAC,UAAU,CAAC;IAStB,oBAAoB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAUpF,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAStF,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAShF,qBAAqB,CAAC,OAAO,EAAE,YAAY;;;;;CAkBlD"}
@@ -0,0 +1,67 @@
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 { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
5
+ import { Fr } from '@aztec/aztec.js/fields';
6
+ import { createPXE, getPXEConfig } from '@aztec/pxe/server';
7
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
8
+ import { BaseTestWallet } from './test_wallet.js';
9
+ /**
10
+ * A TestWallet implementation to be used in server settings (e.g. e2e tests).
11
+ * Note that the only difference from `lazy` and `bundle` test wallets is that it uses the `createPXE` function
12
+ * from the `pxe/server` package.
13
+ */ export class TestWallet extends BaseTestWallet {
14
+ static async create(node, overridePXEConfig, options = {
15
+ loggers: {}
16
+ }) {
17
+ const pxeConfig = Object.assign(getPXEConfig(), {
18
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
19
+ ...overridePXEConfig
20
+ });
21
+ const pxe = await createPXE(node, pxeConfig, options);
22
+ return new TestWallet(pxe, node);
23
+ }
24
+ createSchnorrAccount(secret, salt, signingKey) {
25
+ signingKey = signingKey ?? deriveSigningKey(secret);
26
+ const accountData = {
27
+ secret,
28
+ salt,
29
+ contract: new SchnorrAccountContract(signingKey)
30
+ };
31
+ return this.createAccount(accountData);
32
+ }
33
+ createECDSARAccount(secret, salt, signingKey) {
34
+ const accountData = {
35
+ secret,
36
+ salt,
37
+ contract: new EcdsaRAccountContract(signingKey)
38
+ };
39
+ return this.createAccount(accountData);
40
+ }
41
+ createECDSAKAccount(secret, salt, signingKey) {
42
+ const accountData = {
43
+ secret,
44
+ salt,
45
+ contract: new EcdsaKAccountContract(signingKey)
46
+ };
47
+ return this.createAccount(accountData);
48
+ }
49
+ async getFakeAccountDataFor(address) {
50
+ const chainInfo = await this.getChainInfo();
51
+ const originalAccount = await this.getAccountFromAddress(address);
52
+ const originalAddress = originalAccount.getCompleteAddress();
53
+ const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
54
+ if (!contractInstance) {
55
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
56
+ }
57
+ const stubAccount = createStubAccount(originalAddress, chainInfo);
58
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
59
+ salt: Fr.random()
60
+ });
61
+ return {
62
+ account: stubAccount,
63
+ instance,
64
+ artifact: StubAccountContractArtifact
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,143 @@
1
+ import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
+ import { type Account, type AccountContract } from '@aztec/aztec.js/account';
3
+ import { type CallIntent, type ContractFunctionInteractionCallIntent, type IntentInnerHash, SetPublicAuthwitContractInteraction } from '@aztec/aztec.js/authorization';
4
+ import { BaseWallet, type SendOptions, type SimulateOptions } from '@aztec/aztec.js/wallet';
5
+ import { AccountManager } from '@aztec/aztec.js/wallet';
6
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
7
+ import { Fq, Fr } from '@aztec/foundation/fields';
8
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
9
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
11
+ import type { NotesFilter, UniqueNote } from '@aztec/stdlib/note';
12
+ import type { TxSimulationResult } from '@aztec/stdlib/tx';
13
+ import { ProvenTx } from '../utils.js';
14
+ /**
15
+ * Data for generating an account.
16
+ */
17
+ export interface AccountData {
18
+ /**
19
+ * Secret to derive the keys for the account.
20
+ */
21
+ secret: Fr;
22
+ /**
23
+ * Contract address salt.
24
+ */
25
+ salt: Fr;
26
+ /**
27
+ * Contract that backs the account.
28
+ */
29
+ contract: AccountContract;
30
+ }
31
+ /**
32
+ * Wallet implementation that stores accounts in memory and allows allows their creation
33
+ * from the outside (which is something actual wallets shouldn't allow!)
34
+ * It is intended to be used in e2e tests.
35
+ */
36
+ export declare abstract class BaseTestWallet extends BaseWallet {
37
+ protected accounts: Map<string, Account>;
38
+ /**
39
+ * Toggle for running "simulated simulations" when calling simulateTx.
40
+ *
41
+ * Terminology:
42
+ * - "simulation": run private circuits normally and then run the kernel in a simulated (brillig) mode on ACVM.
43
+ * No kernel witnesses are generated, but protocol rules are checked.
44
+ * - "simulated simulation": skip running kernels in ACVM altogether and emulate their behavior in TypeScript
45
+ * (akin to generateSimulatedProvingResult). We mutate public inputs like the kernels would and can swap in
46
+ * fake/private bytecode or accounts for tests. This is much faster but is not usable in situations where we
47
+ * need kernel witnesses.
48
+ *
49
+ * When this flag is true, simulateTx constructs a request using a fake account (and accepts contract overrides
50
+ * on the input) and the PXE emulates kernel effects without generating kernel witnesses. When false, simulateTx
51
+ * defers to the standard simulation path.
52
+ */
53
+ private simulatedSimulations;
54
+ /** Enable the "simulated simulation" path for simulateTx. */
55
+ enableSimulatedSimulations(): void;
56
+ /** Disable the "simulated simulation" path for simulateTx. */
57
+ disableSimulatedSimulations(): void;
58
+ setBaseFeePadding(value?: number): void;
59
+ protected getAccountFromAddress(address: AztecAddress): Promise<Account>;
60
+ getAccounts(): Promise<{
61
+ alias: string;
62
+ item: AztecAddress;
63
+ }[]>;
64
+ /**
65
+ * Creates a new account with the provided account data or generates random values and uses SchnorrAccountContract
66
+ * if not provided.
67
+ *
68
+ * @param accountData - Optional account configuration containing secret, salt and account contract.
69
+ * @returns A new AccountManager instance for the created account
70
+ */
71
+ createAccount(accountData?: AccountData): Promise<AccountManager>;
72
+ abstract createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager>;
73
+ abstract createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
74
+ abstract createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
75
+ /**
76
+ * Lookup the validity of an authwit in private and public contexts.
77
+ *
78
+ * Uses the chain id and version of the wallet.
79
+ *
80
+ * @param wallet - The wallet use to simulate and read the public data
81
+ * @param onBehalfOf - The address of the "approver"
82
+ * @param intent - The consumer and inner hash or the caller and action to lookup
83
+ * @param witness - The computed authentication witness to check
84
+ * @returns - A struct containing the validity of the authwit in private and public contexts.
85
+ */
86
+ lookupValidity(onBehalfOf: AztecAddress, intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, witness: AuthWitness): Promise<{
87
+ /** boolean flag indicating if the authwit is valid in private context */
88
+ isValidInPrivate: boolean;
89
+ /** boolean flag indicating if the authwit is valid in public context */
90
+ isValidInPublic: boolean;
91
+ }>;
92
+ /**
93
+ * Returns an interaction that can be used to set the authorization status
94
+ * of an intent
95
+ * @param from - The address authorizing/revoking the action
96
+ * @param messageHashOrIntent - The action to authorize/revoke
97
+ * @param authorized - Whether the action can be performed or not
98
+ */
99
+ setPublicAuthWit(from: AztecAddress, messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, authorized: boolean): Promise<SetPublicAuthwitContractInteraction>;
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
+ */
107
+ createAuthWit(from: AztecAddress, messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent): Promise<AuthWitness>;
108
+ abstract getFakeAccountDataFor(address: AztecAddress): Promise<{
109
+ account: Account;
110
+ instance: ContractInstanceWithAddress;
111
+ artifact: ContractArtifact;
112
+ }>;
113
+ simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
114
+ /**
115
+ * A utility to prove a transaction using this wallet and return it to be sent by a different entity on their own accord
116
+ *
117
+ * Note that this should not be used in production code since a proven transaction could be sent to a malicious
118
+ * node to index and track. It also makes it very difficult for the wallet to keep track of the interaction.
119
+ * @param exec - The execution payload to prove.
120
+ * @param opts - The options to configure the interaction
121
+ * @returns - A proven tx ready to be sent to the network
122
+ */
123
+ proveTx(exec: ExecutionPayload, opts: SendOptions): Promise<ProvenTx>;
124
+ /**
125
+ * A debugging utility to get notes based on the provided filter.
126
+ *
127
+ * Note that this should not be used in production code because the structure of notes is considered to be
128
+ * an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
129
+ * note-related information in production code, please implement a custom utility function on your contract and call
130
+ * that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
131
+ *
132
+ * @param filter - The filter to apply to the notes.
133
+ * @returns The requested notes.
134
+ */
135
+ getNotes(filter: NotesFilter): Promise<UniqueNote[]>;
136
+ /**
137
+ * Stops the internal job queue.
138
+ *
139
+ * This function is typically used when tearing down tests.
140
+ */
141
+ stop(): Promise<void>;
142
+ }
143
+ //# sourceMappingURL=test_wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/test_wallet.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAqB,MAAM,yBAAyB,CAAC;AAChG,OAAO,EACL,KAAK,UAAU,EACf,KAAK,qCAAqC,EAC1C,KAAK,eAAe,EACpB,mCAAmC,EAGpC,MA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