@aztec/wallets 0.0.1-commit.88e6f9396 → 0.0.1-commit.8cb2d04d8
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/embedded/account-contract-providers/bundle.d.ts +4 -3
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +6 -5
- package/dest/embedded/account-contract-providers/lazy.d.ts +4 -3
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +16 -6
- package/dest/embedded/account-contract-providers/types.d.ts +4 -3
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +34 -7
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +101 -55
- package/dest/embedded/entrypoints/browser.d.ts +2 -2
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +17 -7
- package/dest/embedded/entrypoints/node.d.ts +2 -2
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +17 -7
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +2 -2
- package/package.json +10 -10
- package/src/embedded/account-contract-providers/bundle.ts +7 -5
- package/src/embedded/account-contract-providers/lazy.ts +17 -6
- package/src/embedded/account-contract-providers/types.ts +4 -2
- package/src/embedded/embedded_wallet.ts +133 -65
- package/src/embedded/entrypoints/browser.ts +25 -18
- package/src/embedded/entrypoints/node.ts +31 -24
- package/src/testing.ts +2 -1
|
@@ -4,36 +4,46 @@ import { createStore, openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
|
4
4
|
import { getPXEConfig } from '@aztec/pxe/config';
|
|
5
5
|
import { createPXE } from '@aztec/pxe/server';
|
|
6
6
|
import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
|
|
7
|
-
import { EmbeddedWallet } from '../embedded_wallet.js';
|
|
7
|
+
import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
|
|
8
8
|
import { WalletDB } from '../wallet_db.js';
|
|
9
9
|
export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
10
10
|
static async create(nodeOrUrl, options = {}) {
|
|
11
11
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
12
12
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
13
13
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
14
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
15
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
16
|
+
const mergedConfigOverrides = {
|
|
17
|
+
...options.pxeConfig,
|
|
18
|
+
...pxeConfigFromPxe
|
|
19
|
+
};
|
|
20
|
+
const mergedCreationOverrides = {
|
|
21
|
+
...options.pxeOptions,
|
|
22
|
+
...pxeCreationFromPxe
|
|
23
|
+
};
|
|
14
24
|
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
15
|
-
proverEnabled:
|
|
25
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
16
26
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
17
|
-
...
|
|
27
|
+
...mergedConfigOverrides
|
|
18
28
|
});
|
|
19
29
|
if (options.ephemeral) {
|
|
20
30
|
delete pxeConfig.dataDirectory;
|
|
21
31
|
}
|
|
22
32
|
const pxeOptions = {
|
|
23
|
-
...
|
|
33
|
+
...mergedCreationOverrides,
|
|
24
34
|
loggers: {
|
|
25
35
|
store: rootLogger.createChild('pxe:data'),
|
|
26
36
|
pxe: rootLogger.createChild('pxe:service'),
|
|
27
37
|
prover: rootLogger.createChild('pxe:prover'),
|
|
28
|
-
...
|
|
38
|
+
...mergedCreationOverrides.loggers
|
|
29
39
|
}
|
|
30
40
|
};
|
|
31
41
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
32
|
-
const walletDBStore = options.ephemeral ? await openTmpStore(`wallet_data_${l1Contracts.rollupAddress}`, true, undefined, undefined, rootLogger.createChild('wallet:data').getBindings()) : await createStore('wallet_data', 1, {
|
|
42
|
+
const walletDBStore = options.walletDb?.store ?? (options.ephemeral ? await openTmpStore(`wallet_data_${l1Contracts.rollupAddress}`, true, undefined, undefined, rootLogger.createChild('wallet:data').getBindings()) : await createStore('wallet_data', 1, {
|
|
33
43
|
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
34
44
|
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
35
45
|
l1Contracts
|
|
36
|
-
}, rootLogger.createChild('wallet:data').getBindings());
|
|
46
|
+
}, rootLogger.createChild('wallet:data').getBindings()));
|
|
37
47
|
const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
38
48
|
return new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
|
|
39
49
|
}
|
package/dest/testing.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ interface WalletWithSchnorrAccounts {
|
|
|
9
9
|
export declare function deployFundedSchnorrAccounts(wallet: WalletWithSchnorrAccounts, accountsData: InitialAccountData[], waitOptions?: WaitOpts): Promise<AccountManager[]>;
|
|
10
10
|
export declare function registerInitialLocalNetworkAccountsInWallet(wallet: WalletWithSchnorrAccounts): Promise<AztecAddress[]>;
|
|
11
11
|
export {};
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUdsRSxPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUMxRCxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUM3RCxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDN0QsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRTNELFVBQVUseUJBQXlCO0lBQ2pDLG9CQUFvQixDQUFDLE1BQU0sRUFBRSxFQUFFLEVBQUUsSUFBSSxFQUFFLEVBQUUsRUFBRSxVQUFVLENBQUMsRUFBRSxFQUFFLEVBQUUsS0FBSyxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FBQztDQUN0RztBQUVELHdCQUFzQiwyQkFBMkIsQ0FDL0MsTUFBTSxFQUFFLHlCQUF5QixFQUNqQyxZQUFZLEVBQUUsa0JBQWtCLEVBQUUsRUFDbEMsV0FBVyxDQUFDLEVBQUUsUUFBUSw2QkFnQnZCO0FBRUQsd0JBQXNCLDJDQUEyQyxDQUMvRCxNQUFNLEVBQUUseUJBQXlCLEdBQ2hDLE9BQU8sQ0FBQyxZQUFZLEVBQUUsQ0FBQyxDQU96QiJ9
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,UAAU,yBAAyB;IACjC,oBAAoB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACtG;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,kBAAkB,EAAE,EAClC,WAAW,CAAC,EAAE,QAAQ,6BAgBvB;AAED,wBAAsB,2CAA2C,CAC/D,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,YAAY,EAAE,CAAC,CAOzB"}
|
package/dest/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
|
|
2
|
-
import {
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
3
3
|
export async function deployFundedSchnorrAccounts(wallet, accountsData, waitOptions) {
|
|
4
4
|
const accountManagers = [];
|
|
5
5
|
// Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
|
|
@@ -8,7 +8,7 @@ export async function deployFundedSchnorrAccounts(wallet, accountsData, waitOpti
|
|
|
8
8
|
const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
9
9
|
const deployMethod = await accountManager.getDeployMethod();
|
|
10
10
|
await deployMethod.send({
|
|
11
|
-
from:
|
|
11
|
+
from: NO_FROM,
|
|
12
12
|
skipClassPublication: i !== 0,
|
|
13
13
|
wait: waitOptions
|
|
14
14
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallets",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallets",
|
|
4
|
-
"version": "0.0.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.8cb2d04d8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./embedded": {
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"../package.common.json"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
31
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
32
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
33
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
34
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
35
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
36
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
37
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
38
|
-
"@aztec/wallet-sdk": "0.0.1-commit.
|
|
30
|
+
"@aztec/accounts": "0.0.1-commit.8cb2d04d8",
|
|
31
|
+
"@aztec/aztec.js": "0.0.1-commit.8cb2d04d8",
|
|
32
|
+
"@aztec/entrypoints": "0.0.1-commit.8cb2d04d8",
|
|
33
|
+
"@aztec/foundation": "0.0.1-commit.8cb2d04d8",
|
|
34
|
+
"@aztec/kv-store": "0.0.1-commit.8cb2d04d8",
|
|
35
|
+
"@aztec/protocol-contracts": "0.0.1-commit.8cb2d04d8",
|
|
36
|
+
"@aztec/pxe": "0.0.1-commit.8cb2d04d8",
|
|
37
|
+
"@aztec/stdlib": "0.0.1-commit.8cb2d04d8",
|
|
38
|
+
"@aztec/wallet-sdk": "0.0.1-commit.8cb2d04d8"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@jest/globals": "^30.0.0",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
2
|
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
|
-
import {
|
|
3
|
+
import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa';
|
|
4
|
+
import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
|
|
4
5
|
import type { Account, AccountContract } from '@aztec/aztec.js/account';
|
|
5
6
|
import type { Fq } from '@aztec/foundation/curves/bn254';
|
|
6
7
|
import { getCanonicalMultiCallEntrypoint } from '@aztec/protocol-contracts/multi-call-entrypoint';
|
|
7
8
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
8
9
|
import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
9
10
|
|
|
11
|
+
import type { AccountType } from '../wallet_db.js';
|
|
10
12
|
import type { AccountContractsProvider } from './types.js';
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -26,12 +28,12 @@ export class BundleAccountContractsProvider implements AccountContractsProvider
|
|
|
26
28
|
return Promise.resolve(new EcdsaKAccountContract(signingKey));
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
getStubAccountContractArtifact(): Promise<ContractArtifact> {
|
|
30
|
-
return Promise.resolve(
|
|
31
|
+
getStubAccountContractArtifact(type: AccountType): Promise<ContractArtifact> {
|
|
32
|
+
return Promise.resolve(type === 'schnorr' ? StubSchnorrAccountContractArtifact : StubEcdsaAccountContractArtifact);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
createStubAccount(address: CompleteAddress): Promise<Account> {
|
|
34
|
-
return Promise.resolve(
|
|
35
|
+
createStubAccount(address: CompleteAddress, type: AccountType): Promise<Account> {
|
|
36
|
+
return Promise.resolve(type === 'schnorr' ? createStubSchnorrAccount(address) : createStubEcdsaAccount(address));
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }> {
|
|
@@ -4,6 +4,7 @@ import { getCanonicalMultiCallEntrypoint } from '@aztec/protocol-contracts/multi
|
|
|
4
4
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
6
6
|
|
|
7
|
+
import type { AccountType } from '../wallet_db.js';
|
|
7
8
|
import type { AccountContractsProvider } from './types.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -26,14 +27,24 @@ export class LazyAccountContractsProvider implements AccountContractsProvider {
|
|
|
26
27
|
return new EcdsaKAccountContract(signingKey);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
async getStubAccountContractArtifact(): Promise<ContractArtifact> {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
async getStubAccountContractArtifact(type: AccountType): Promise<ContractArtifact> {
|
|
31
|
+
if (type === 'schnorr') {
|
|
32
|
+
const { getStubSchnorrAccountContractArtifact } = await import('@aztec/accounts/stub/schnorr/lazy');
|
|
33
|
+
return getStubSchnorrAccountContractArtifact();
|
|
34
|
+
} else {
|
|
35
|
+
const { getStubEcdsaAccountContractArtifact } = await import('@aztec/accounts/stub/ecdsa/lazy');
|
|
36
|
+
return getStubEcdsaAccountContractArtifact();
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
async createStubAccount(address: CompleteAddress): Promise<Account> {
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
async createStubAccount(address: CompleteAddress, type: AccountType): Promise<Account> {
|
|
41
|
+
if (type === 'schnorr') {
|
|
42
|
+
const { createStubSchnorrAccount } = await import('@aztec/accounts/stub/schnorr/lazy');
|
|
43
|
+
return createStubSchnorrAccount(address);
|
|
44
|
+
} else {
|
|
45
|
+
const { createStubEcdsaAccount } = await import('@aztec/accounts/stub/ecdsa/lazy');
|
|
46
|
+
return createStubEcdsaAccount(address);
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }> {
|
|
@@ -3,6 +3,8 @@ import type { Fq } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
5
|
|
|
6
|
+
import type { AccountType } from '../wallet_db.js';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Provides account contract implementations and stub accounts for the EmbeddedWallet.
|
|
8
10
|
* Two implementations exist:
|
|
@@ -13,7 +15,7 @@ export interface AccountContractsProvider {
|
|
|
13
15
|
getSchnorrAccountContract(signingKey: Fq): Promise<AccountContract>;
|
|
14
16
|
getEcdsaRAccountContract(signingKey: Buffer): Promise<AccountContract>;
|
|
15
17
|
getEcdsaKAccountContract(signingKey: Buffer): Promise<AccountContract>;
|
|
16
|
-
getStubAccountContractArtifact(): Promise<ContractArtifact>;
|
|
18
|
+
getStubAccountContractArtifact(type: AccountType): Promise<ContractArtifact>;
|
|
17
19
|
getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }>;
|
|
18
|
-
createStubAccount(address: CompleteAddress): Promise<Account>;
|
|
20
|
+
createStubAccount(address: CompleteAddress, type: AccountType): Promise<Account>;
|
|
19
21
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { type Account,
|
|
1
|
+
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import { type InteractionWaitOptions, type SendReturn, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn, type WaitOpts, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
|
|
5
|
-
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
6
6
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
7
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
7
8
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
8
9
|
import type { Logger } from '@aztec/foundation/log';
|
|
10
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
11
|
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
10
12
|
import type { PXE } from '@aztec/pxe/server';
|
|
11
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -14,9 +16,11 @@ import { GasSettings } from '@aztec/stdlib/gas';
|
|
|
14
16
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
15
17
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
16
18
|
import {
|
|
19
|
+
type ContractOverrides,
|
|
17
20
|
ExecutionPayload,
|
|
18
21
|
SimulationOverrides,
|
|
19
|
-
type
|
|
22
|
+
type TxExecutionRequest,
|
|
23
|
+
TxStatus,
|
|
20
24
|
collectOffchainEffects,
|
|
21
25
|
mergeExecutionPayloads,
|
|
22
26
|
} from '@aztec/stdlib/tx';
|
|
@@ -25,14 +29,45 @@ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk
|
|
|
25
29
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
26
30
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
27
31
|
|
|
32
|
+
/** Options for the PXE instance created by the EmbeddedWallet. */
|
|
33
|
+
export type EmbeddedWalletPXEOptions = Partial<PXEConfig> & PXECreationOptions;
|
|
34
|
+
|
|
35
|
+
/** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */
|
|
36
|
+
export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
|
|
37
|
+
config: Partial<PXEConfig>;
|
|
38
|
+
creation: PXECreationOptions;
|
|
39
|
+
} {
|
|
40
|
+
if (!pxe) {
|
|
41
|
+
return { config: {}, creation: {} };
|
|
42
|
+
}
|
|
43
|
+
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, ...config } = pxe;
|
|
44
|
+
return { config, creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator } };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Options for the EmbeddedWallet's own DB (accounts, senders — distinct from PXE state). */
|
|
48
|
+
export type EmbeddedWalletDBOptions = {
|
|
49
|
+
/** Override the wallet DB backend. If omitted, an IndexedDB (browser) / LMDB (node) store is created. */
|
|
50
|
+
store?: AztecAsyncKVStore;
|
|
51
|
+
};
|
|
52
|
+
|
|
28
53
|
export type EmbeddedWalletOptions = {
|
|
29
54
|
/** Parent logger. Child loggers are derived via createChild() for each subsystem. */
|
|
30
55
|
logger?: Logger;
|
|
31
56
|
/** Use ephemeral (in-memory) stores. Data will not persist across sessions. */
|
|
32
57
|
ephemeral?: boolean;
|
|
33
|
-
/**
|
|
58
|
+
/** PXE configuration and dependency overrides (custom store, prover, simulator). */
|
|
59
|
+
pxe?: EmbeddedWalletPXEOptions;
|
|
60
|
+
/** Wallet DB dependency overrides (custom store). */
|
|
61
|
+
walletDb?: EmbeddedWalletDBOptions;
|
|
62
|
+
/**
|
|
63
|
+
* Override PXE configuration.
|
|
64
|
+
* @deprecated Use `pxe` instead.
|
|
65
|
+
*/
|
|
34
66
|
pxeConfig?: Partial<PXEConfig>;
|
|
35
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Advanced PXE creation options (custom store, prover, simulator).
|
|
69
|
+
* @deprecated Use `pxe` instead.
|
|
70
|
+
*/
|
|
36
71
|
pxeOptions?: PXECreationOptions;
|
|
37
72
|
};
|
|
38
73
|
|
|
@@ -52,10 +87,6 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
52
87
|
}
|
|
53
88
|
|
|
54
89
|
protected async getAccountFromAddress(address: AztecAddress): Promise<Account> {
|
|
55
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
56
|
-
return new SignerlessAccount();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
90
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
60
91
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
61
92
|
const account = await accountManager.getAccount();
|
|
@@ -96,18 +127,19 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
96
127
|
executionPayload: ExecutionPayload,
|
|
97
128
|
opts: SendOptions<W>,
|
|
98
129
|
): Promise<SendReturn<W>> {
|
|
99
|
-
const feeOptions = await this.
|
|
100
|
-
opts.from,
|
|
101
|
-
executionPayload.feePayer,
|
|
102
|
-
opts.fee?.gasSettings,
|
|
103
|
-
|
|
130
|
+
const feeOptions = await this.completeFeeOptions({
|
|
131
|
+
from: opts.from,
|
|
132
|
+
feePayer: executionPayload.feePayer,
|
|
133
|
+
gasSettings: opts.fee?.gasSettings,
|
|
134
|
+
forEstimation: true,
|
|
135
|
+
});
|
|
104
136
|
|
|
105
137
|
// Simulate the transaction first to estimate gas and capture required
|
|
106
138
|
// private authwitnesses based on offchain effects.
|
|
107
139
|
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
108
140
|
from: opts.from,
|
|
109
141
|
feeOptions,
|
|
110
|
-
|
|
142
|
+
additionalScopes: opts.additionalScopes,
|
|
111
143
|
skipTxValidation: true,
|
|
112
144
|
});
|
|
113
145
|
|
|
@@ -116,7 +148,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
116
148
|
offchainEffects.map(async effect => {
|
|
117
149
|
try {
|
|
118
150
|
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
119
|
-
return this.createAuthWit(
|
|
151
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
120
152
|
consumer: effect.contractAddress,
|
|
121
153
|
innerHash: authRequest.innerHash,
|
|
122
154
|
});
|
|
@@ -141,12 +173,63 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
141
173
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
142
174
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
143
175
|
});
|
|
176
|
+
const waitOpts: WaitOpts = typeof opts.wait === 'object' ? opts.wait : {};
|
|
177
|
+
|
|
178
|
+
if (!waitOpts?.waitForStatus) {
|
|
179
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
180
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
181
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
182
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
183
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
184
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
185
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
186
|
+
waitOpts!.waitForStatus = TxStatus.PROPOSED;
|
|
187
|
+
}
|
|
144
188
|
return super.sendTx(executionPayload, {
|
|
145
189
|
...opts,
|
|
146
190
|
fee: { ...opts.fee, gasSettings },
|
|
147
191
|
});
|
|
148
192
|
}
|
|
149
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
196
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
197
|
+
*/
|
|
198
|
+
protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
|
|
199
|
+
const accounts = await this.getAccounts();
|
|
200
|
+
const contracts: ContractOverrides = {};
|
|
201
|
+
|
|
202
|
+
const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
|
|
203
|
+
|
|
204
|
+
for (const account of filtered) {
|
|
205
|
+
const address = account.item;
|
|
206
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
207
|
+
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact(type);
|
|
208
|
+
|
|
209
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
210
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
211
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
212
|
+
if (!contractInstance) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const stubConstructorArgs = type === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
|
|
219
|
+
const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
220
|
+
salt: Fr.random(),
|
|
221
|
+
constructorArgs: stubConstructorArgs,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
contracts[address.toString()] = {
|
|
225
|
+
instance: stubInstance,
|
|
226
|
+
artifact: stubArtifact,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return contracts;
|
|
231
|
+
}
|
|
232
|
+
|
|
150
233
|
/**
|
|
151
234
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
152
235
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -155,66 +238,51 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
155
238
|
protected override async simulateViaEntrypoint(
|
|
156
239
|
executionPayload: ExecutionPayload,
|
|
157
240
|
opts: SimulateViaEntrypointOptions,
|
|
158
|
-
): Promise<
|
|
159
|
-
const { from, feeOptions,
|
|
160
|
-
|
|
161
|
-
let overrides: SimulationOverrides | undefined;
|
|
162
|
-
let fromAccount: Account;
|
|
163
|
-
if (!from.equals(AztecAddress.ZERO)) {
|
|
164
|
-
const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
165
|
-
fromAccount = account;
|
|
166
|
-
overrides = {
|
|
167
|
-
contracts: { [from.toString()]: { instance, artifact } },
|
|
168
|
-
};
|
|
169
|
-
} else {
|
|
170
|
-
fromAccount = await this.getAccountFromAddress(from);
|
|
171
|
-
}
|
|
241
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
242
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
243
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
172
244
|
|
|
173
245
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
174
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
175
|
-
txNonce: Fr.random(),
|
|
176
|
-
cancellable: this.cancellableTransactions,
|
|
177
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
178
|
-
};
|
|
179
246
|
const finalExecutionPayload = feeExecutionPayload
|
|
180
247
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
181
248
|
: executionPayload;
|
|
182
249
|
const chainInfo = await this.getChainInfo();
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
189
|
-
|
|
250
|
+
|
|
251
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
252
|
+
const overrides = new SimulationOverrides(accountOverrides);
|
|
253
|
+
|
|
254
|
+
let txRequest: TxExecutionRequest;
|
|
255
|
+
if (from === NO_FROM) {
|
|
256
|
+
const entrypoint = new DefaultEntrypoint();
|
|
257
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
258
|
+
} else {
|
|
259
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
260
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
261
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
262
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
263
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
264
|
+
txNonce: Fr.random(),
|
|
265
|
+
cancellable: this.cancellableTransactions,
|
|
266
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
267
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
268
|
+
};
|
|
269
|
+
txRequest = await account.createTxExecutionRequest(
|
|
270
|
+
finalExecutionPayload,
|
|
271
|
+
feeOptions.gasSettings,
|
|
272
|
+
chainInfo,
|
|
273
|
+
executionOptions,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
190
278
|
simulatePublic: true,
|
|
191
279
|
skipFeeEnforcement,
|
|
192
280
|
skipTxValidation,
|
|
193
281
|
overrides,
|
|
194
282
|
scopes,
|
|
195
283
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
199
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
200
|
-
if (originalAccount instanceof SignerlessAccount) {
|
|
201
|
-
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
202
|
-
}
|
|
203
|
-
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
204
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
205
|
-
if (!contractInstance) {
|
|
206
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
207
|
-
}
|
|
208
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
209
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
210
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
211
|
-
salt: Fr.random(),
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
account: stubAccount,
|
|
215
|
-
instance,
|
|
216
|
-
artifact: stubArtifact,
|
|
217
|
-
};
|
|
284
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
285
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
218
286
|
}
|
|
219
287
|
|
|
220
288
|
protected async createAccountInternal(
|
|
@@ -6,7 +6,7 @@ import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
|
6
6
|
|
|
7
7
|
import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
|
|
8
8
|
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
9
|
-
import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
9
|
+
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
10
10
|
import { WalletDB } from '../wallet_db.js';
|
|
11
11
|
|
|
12
12
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
@@ -26,10 +26,15 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
26
26
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
27
27
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
28
28
|
|
|
29
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
30
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
31
|
+
const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
|
|
32
|
+
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
33
|
+
|
|
29
34
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
30
|
-
proverEnabled:
|
|
35
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
31
36
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
32
|
-
...
|
|
37
|
+
...mergedConfigOverrides,
|
|
33
38
|
});
|
|
34
39
|
|
|
35
40
|
if (options.ephemeral) {
|
|
@@ -37,29 +42,31 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
const pxeOptions: PXECreationOptions = {
|
|
40
|
-
...
|
|
45
|
+
...mergedCreationOverrides,
|
|
41
46
|
loggers: {
|
|
42
47
|
store: rootLogger.createChild('pxe:data'),
|
|
43
48
|
pxe: rootLogger.createChild('pxe:service'),
|
|
44
49
|
prover: rootLogger.createChild('pxe:prover'),
|
|
45
|
-
...
|
|
50
|
+
...mergedCreationOverrides.loggers,
|
|
46
51
|
},
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
50
55
|
|
|
51
|
-
const walletDBStore =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
const walletDBStore =
|
|
57
|
+
options.walletDb?.store ??
|
|
58
|
+
(options.ephemeral
|
|
59
|
+
? await openTmpStore(true)
|
|
60
|
+
: await createStore(
|
|
61
|
+
'wallet_data',
|
|
62
|
+
{
|
|
63
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
64
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
65
|
+
l1Contracts,
|
|
66
|
+
},
|
|
67
|
+
1,
|
|
68
|
+
rootLogger.createChild('wallet:data'),
|
|
69
|
+
));
|
|
63
70
|
const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
64
71
|
|
|
65
72
|
return new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
|
|
@@ -67,6 +74,6 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
70
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
77
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
71
78
|
export { WalletDB } from '../wallet_db.js';
|
|
72
79
|
export type { AccountType } from '../wallet_db.js';
|