@aztec/wallets 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
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 +6 -2
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +4 -0
- package/dest/embedded/account-contract-providers/lazy.d.ts +6 -2
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +4 -0
- package/dest/embedded/account-contract-providers/types.d.ts +6 -2
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +38 -6
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +148 -48
- package/dest/embedded/entrypoints/browser.d.ts +8 -3
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +32 -15
- package/dest/embedded/entrypoints/node.d.ts +7 -11
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +22 -14
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +2 -2
- package/package.json +19 -9
- package/src/embedded/account-contract-providers/bundle.ts +6 -1
- package/src/embedded/account-contract-providers/lazy.ts +6 -1
- package/src/embedded/account-contract-providers/types.ts +2 -1
- package/src/embedded/embedded_wallet.ts +201 -56
- package/src/embedded/entrypoints/browser.ts +46 -19
- package/src/embedded/entrypoints/node.ts +34 -30
- package/src/testing.ts +2 -1
- package/dest/embedded/embedded_wallet_browser.d.ts +0 -5
- package/dest/embedded/embedded_wallet_browser.d.ts.map +0 -1
- package/dest/embedded/embedded_wallet_browser.js +0 -31
- package/src/embedded/embedded_wallet_browser.ts +0 -40
|
@@ -1,43 +1,51 @@
|
|
|
1
1
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { createStore
|
|
3
|
+
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
|
+
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
|
+
};
|
|
13
24
|
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
14
|
-
proverEnabled:
|
|
15
|
-
|
|
25
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
26
|
+
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
27
|
+
...mergedConfigOverrides
|
|
16
28
|
});
|
|
17
29
|
if (options.ephemeral) {
|
|
18
30
|
delete pxeConfig.dataDirectory;
|
|
19
31
|
}
|
|
20
32
|
const pxeOptions = {
|
|
21
|
-
...
|
|
33
|
+
...mergedCreationOverrides,
|
|
22
34
|
loggers: {
|
|
23
35
|
store: rootLogger.createChild('pxe:data'),
|
|
24
36
|
pxe: rootLogger.createChild('pxe:service'),
|
|
25
37
|
prover: rootLogger.createChild('pxe:prover'),
|
|
26
|
-
...
|
|
38
|
+
...mergedCreationOverrides.loggers
|
|
27
39
|
}
|
|
28
40
|
};
|
|
29
41
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const walletDBStore = options.ephemeral ? await openTmpStore('wallet_data', true, undefined, undefined, rootLogger.createChild('wallet:data').getBindings()) : await createWalletStore('wallet_data', 1, {
|
|
33
|
-
dataDirectory: pxeConfig.dataDirectory,
|
|
42
|
+
const walletDBStore = options.ephemeral ? await openTmpStore(`wallet_data_${l1Contracts.rollupAddress}`, true, undefined, undefined, rootLogger.createChild('wallet:data').getBindings()) : await createStore('wallet_data', 1, {
|
|
43
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
34
44
|
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
35
|
-
l1Contracts
|
|
36
|
-
rollupAddress
|
|
37
|
-
}
|
|
45
|
+
l1Contracts
|
|
38
46
|
}, rootLogger.createChild('wallet:data').getBindings());
|
|
39
47
|
const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
40
|
-
return new
|
|
48
|
+
return new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
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.e304674f1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./embedded": {
|
|
@@ -27,14 +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/
|
|
36
|
-
"@aztec/
|
|
37
|
-
"@aztec/
|
|
30
|
+
"@aztec/accounts": "0.0.1-commit.e304674f1",
|
|
31
|
+
"@aztec/aztec.js": "0.0.1-commit.e304674f1",
|
|
32
|
+
"@aztec/entrypoints": "0.0.1-commit.e304674f1",
|
|
33
|
+
"@aztec/foundation": "0.0.1-commit.e304674f1",
|
|
34
|
+
"@aztec/kv-store": "0.0.1-commit.e304674f1",
|
|
35
|
+
"@aztec/protocol-contracts": "0.0.1-commit.e304674f1",
|
|
36
|
+
"@aztec/pxe": "0.0.1-commit.e304674f1",
|
|
37
|
+
"@aztec/stdlib": "0.0.1-commit.e304674f1",
|
|
38
|
+
"@aztec/wallet-sdk": "0.0.1-commit.e304674f1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@jest/globals": "^30.0.0",
|
|
@@ -43,6 +44,15 @@
|
|
|
43
44
|
"ts-node": "^10.9.1",
|
|
44
45
|
"typescript": "^5.3.3"
|
|
45
46
|
},
|
|
47
|
+
"typedocOptions": {
|
|
48
|
+
"entryPoints": [
|
|
49
|
+
"./src/embedded/entrypoints/browser.ts",
|
|
50
|
+
"./src/embedded/entrypoints/node.ts",
|
|
51
|
+
"./src/testing.ts"
|
|
52
|
+
],
|
|
53
|
+
"name": "Wallets",
|
|
54
|
+
"tsconfig": "./tsconfig.json"
|
|
55
|
+
},
|
|
46
56
|
"files": [
|
|
47
57
|
"dest",
|
|
48
58
|
"src",
|
|
@@ -3,8 +3,9 @@ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
|
3
3
|
import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
|
|
4
4
|
import type { Account, AccountContract } from '@aztec/aztec.js/account';
|
|
5
5
|
import type { Fq } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { getCanonicalMultiCallEntrypoint } from '@aztec/protocol-contracts/multi-call-entrypoint';
|
|
6
7
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
7
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
8
|
+
import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
8
9
|
|
|
9
10
|
import type { AccountContractsProvider } from './types.js';
|
|
10
11
|
|
|
@@ -32,4 +33,8 @@ export class BundleAccountContractsProvider implements AccountContractsProvider
|
|
|
32
33
|
createStubAccount(address: CompleteAddress): Promise<Account> {
|
|
33
34
|
return Promise.resolve(createStubAccount(address));
|
|
34
35
|
}
|
|
36
|
+
|
|
37
|
+
getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }> {
|
|
38
|
+
return getCanonicalMultiCallEntrypoint();
|
|
39
|
+
}
|
|
35
40
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Account, AccountContract } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { Fq } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { getCanonicalMultiCallEntrypoint } from '@aztec/protocol-contracts/multi-call-entrypoint/lazy';
|
|
3
4
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
4
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
6
|
|
|
6
7
|
import type { AccountContractsProvider } from './types.js';
|
|
7
8
|
|
|
@@ -34,4 +35,8 @@ export class LazyAccountContractsProvider implements AccountContractsProvider {
|
|
|
34
35
|
const { createStubAccount } = await import('@aztec/accounts/stub/lazy');
|
|
35
36
|
return createStubAccount(address);
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }> {
|
|
40
|
+
return getCanonicalMultiCallEntrypoint();
|
|
41
|
+
}
|
|
37
42
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Account, AccountContract } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { Fq } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
4
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
4
|
+
import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Provides account contract implementations and stub accounts for the EmbeddedWallet.
|
|
@@ -14,5 +14,6 @@ export interface AccountContractsProvider {
|
|
|
14
14
|
getEcdsaRAccountContract(signingKey: Buffer): Promise<AccountContract>;
|
|
15
15
|
getEcdsaKAccountContract(signingKey: Buffer): Promise<AccountContract>;
|
|
16
16
|
getStubAccountContractArtifact(): Promise<ContractArtifact>;
|
|
17
|
+
getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }>;
|
|
17
18
|
createStubAccount(address: CompleteAddress): Promise<Account>;
|
|
18
19
|
}
|
|
@@ -1,28 +1,73 @@
|
|
|
1
|
-
import { type Account,
|
|
2
|
-
import
|
|
1
|
+
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn, type WaitOpts, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
|
|
3
5
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
4
6
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
7
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
5
8
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
6
9
|
import type { Logger } from '@aztec/foundation/log';
|
|
10
|
+
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
7
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
8
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
13
|
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
14
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
10
15
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
11
16
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
12
|
-
import {
|
|
13
|
-
|
|
17
|
+
import {
|
|
18
|
+
type ContractOverrides,
|
|
19
|
+
ExecutionPayload,
|
|
20
|
+
SimulationOverrides,
|
|
21
|
+
type TxExecutionRequest,
|
|
22
|
+
type TxSimulationResult,
|
|
23
|
+
TxStatus,
|
|
24
|
+
collectOffchainEffects,
|
|
25
|
+
mergeExecutionPayloads,
|
|
26
|
+
} from '@aztec/stdlib/tx';
|
|
27
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
14
28
|
|
|
15
29
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
16
30
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
17
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
|
+
|
|
18
47
|
export type EmbeddedWalletOptions = {
|
|
19
48
|
/** Parent logger. Child loggers are derived via createChild() for each subsystem. */
|
|
20
49
|
logger?: Logger;
|
|
21
50
|
/** Use ephemeral (in-memory) stores. Data will not persist across sessions. */
|
|
22
51
|
ephemeral?: boolean;
|
|
52
|
+
/** PXE configuration and dependency overrides (custom store, prover, simulator). */
|
|
53
|
+
pxe?: EmbeddedWalletPXEOptions;
|
|
54
|
+
/**
|
|
55
|
+
* Override PXE configuration.
|
|
56
|
+
* @deprecated Use `pxe` instead.
|
|
57
|
+
*/
|
|
58
|
+
pxeConfig?: Partial<PXEConfig>;
|
|
59
|
+
/**
|
|
60
|
+
* Advanced PXE creation options (custom store, prover, simulator).
|
|
61
|
+
* @deprecated Use `pxe` instead.
|
|
62
|
+
*/
|
|
63
|
+
pxeOptions?: PXECreationOptions;
|
|
23
64
|
};
|
|
24
65
|
|
|
66
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
67
|
+
|
|
25
68
|
export class EmbeddedWallet extends BaseWallet {
|
|
69
|
+
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
70
|
+
|
|
26
71
|
constructor(
|
|
27
72
|
pxe: PXE,
|
|
28
73
|
aztecNode: AztecNode,
|
|
@@ -34,10 +79,6 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
34
79
|
}
|
|
35
80
|
|
|
36
81
|
protected async getAccountFromAddress(address: AztecAddress): Promise<Account> {
|
|
37
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
38
|
-
return new SignerlessAccount();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
82
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
42
83
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
43
84
|
const account = await accountManager.getAccount();
|
|
@@ -69,6 +110,114 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
69
110
|
return storedSenders;
|
|
70
111
|
}
|
|
71
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
115
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
116
|
+
* the necessary authwitnesses.
|
|
117
|
+
*/
|
|
118
|
+
public override async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
119
|
+
executionPayload: ExecutionPayload,
|
|
120
|
+
opts: SendOptions<W>,
|
|
121
|
+
): Promise<SendReturn<W>> {
|
|
122
|
+
const feeOptions = await this.completeFeeOptions({
|
|
123
|
+
from: opts.from,
|
|
124
|
+
feePayer: executionPayload.feePayer,
|
|
125
|
+
gasSettings: opts.fee?.gasSettings,
|
|
126
|
+
forEstimation: true,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
130
|
+
// private authwitnesses based on offchain effects.
|
|
131
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
132
|
+
from: opts.from,
|
|
133
|
+
feeOptions,
|
|
134
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
135
|
+
skipTxValidation: true,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
139
|
+
const authWitnesses = await Promise.all(
|
|
140
|
+
offchainEffects.map(async effect => {
|
|
141
|
+
try {
|
|
142
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
143
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
144
|
+
consumer: effect.contractAddress,
|
|
145
|
+
innerHash: authRequest.innerHash,
|
|
146
|
+
});
|
|
147
|
+
} catch {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
for (const authwit of authWitnesses) {
|
|
153
|
+
if (authwit) {
|
|
154
|
+
executionPayload.authWitnesses.push(authwit);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
|
|
158
|
+
this.log.verbose(
|
|
159
|
+
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
160
|
+
);
|
|
161
|
+
const gasSettings = GasSettings.from({
|
|
162
|
+
...opts.fee?.gasSettings,
|
|
163
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
164
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
165
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
166
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
167
|
+
});
|
|
168
|
+
const waitOpts: WaitOpts = typeof opts.wait === 'object' ? opts.wait : {};
|
|
169
|
+
|
|
170
|
+
if (!waitOpts?.waitForStatus) {
|
|
171
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
172
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
173
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
174
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
175
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
176
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
177
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
178
|
+
waitOpts!.waitForStatus = TxStatus.PROPOSED;
|
|
179
|
+
}
|
|
180
|
+
return super.sendTx(executionPayload, {
|
|
181
|
+
...opts,
|
|
182
|
+
fee: { ...opts.fee, gasSettings },
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
188
|
+
*/
|
|
189
|
+
protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
|
|
190
|
+
const accounts = await this.getAccounts();
|
|
191
|
+
const contracts: ContractOverrides = {};
|
|
192
|
+
|
|
193
|
+
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
194
|
+
|
|
195
|
+
const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
|
|
196
|
+
|
|
197
|
+
for (const account of filtered) {
|
|
198
|
+
const address = account.item;
|
|
199
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
200
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
201
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
202
|
+
if (!contractInstance) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
209
|
+
salt: Fr.random(),
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
contracts[address.toString()] = {
|
|
213
|
+
instance: stubInstance,
|
|
214
|
+
artifact: stubArtifact,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return contracts;
|
|
219
|
+
}
|
|
220
|
+
|
|
72
221
|
/**
|
|
73
222
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
74
223
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -76,63 +225,50 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
76
225
|
*/
|
|
77
226
|
protected override async simulateViaEntrypoint(
|
|
78
227
|
executionPayload: ExecutionPayload,
|
|
79
|
-
|
|
80
|
-
feeOptions: FeeOptions,
|
|
81
|
-
_skipTxValidation?: boolean,
|
|
82
|
-
_skipFeeEnforcement?: boolean,
|
|
83
|
-
scopes?: AztecAddress[],
|
|
228
|
+
opts: SimulateViaEntrypointOptions,
|
|
84
229
|
): Promise<TxSimulationResult> {
|
|
85
|
-
const {
|
|
230
|
+
const { from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
86
231
|
|
|
87
232
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
88
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
89
|
-
txNonce: Fr.random(),
|
|
90
|
-
cancellable: this.cancellableTransactions,
|
|
91
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
92
|
-
};
|
|
93
233
|
const finalExecutionPayload = feeExecutionPayload
|
|
94
234
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
95
235
|
: executionPayload;
|
|
96
236
|
const chainInfo = await this.getChainInfo();
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
)
|
|
237
|
+
|
|
238
|
+
const accountOverrides = await this.buildAccountOverrides(this.scopesFrom(from, opts.additionalScopes));
|
|
239
|
+
const overrides = new SimulationOverrides(accountOverrides);
|
|
240
|
+
|
|
241
|
+
let txRequest: TxExecutionRequest;
|
|
242
|
+
if (from === NO_FROM) {
|
|
243
|
+
const entrypoint = new DefaultEntrypoint();
|
|
244
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
245
|
+
} else {
|
|
246
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
247
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
248
|
+
const account = await this.accountContracts.createStubAccount(completeAddress);
|
|
249
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
250
|
+
txNonce: Fr.random(),
|
|
251
|
+
cancellable: this.cancellableTransactions,
|
|
252
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
253
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
254
|
+
};
|
|
255
|
+
txRequest = await account.createTxExecutionRequest(
|
|
256
|
+
finalExecutionPayload,
|
|
257
|
+
feeOptions.gasSettings,
|
|
258
|
+
chainInfo,
|
|
259
|
+
executionOptions,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
103
263
|
return this.pxe.simulateTx(txRequest, {
|
|
104
264
|
simulatePublic: true,
|
|
105
|
-
skipFeeEnforcement
|
|
106
|
-
skipTxValidation
|
|
107
|
-
overrides
|
|
108
|
-
contracts: { [from.toString()]: { instance, artifact } },
|
|
109
|
-
},
|
|
265
|
+
skipFeeEnforcement,
|
|
266
|
+
skipTxValidation,
|
|
267
|
+
overrides,
|
|
110
268
|
scopes,
|
|
111
269
|
});
|
|
112
270
|
}
|
|
113
271
|
|
|
114
|
-
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
115
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
116
|
-
if (originalAccount instanceof SignerlessAccount) {
|
|
117
|
-
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
118
|
-
}
|
|
119
|
-
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
120
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
121
|
-
if (!contractInstance) {
|
|
122
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
123
|
-
}
|
|
124
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
125
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
126
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
127
|
-
salt: Fr.random(),
|
|
128
|
-
});
|
|
129
|
-
return {
|
|
130
|
-
account: stubAccount,
|
|
131
|
-
instance,
|
|
132
|
-
artifact: stubArtifact,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
272
|
protected async createAccountInternal(
|
|
137
273
|
type: AccountType,
|
|
138
274
|
secret: Fr,
|
|
@@ -161,10 +297,15 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
161
297
|
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
162
298
|
|
|
163
299
|
const instance = accountManager.getInstance();
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
300
|
+
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
301
|
+
if (!existingInstance) {
|
|
302
|
+
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
303
|
+
await this.registerContract(
|
|
304
|
+
instance,
|
|
305
|
+
!existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
|
|
306
|
+
accountManager.getSecretKey(),
|
|
307
|
+
);
|
|
308
|
+
}
|
|
168
309
|
return accountManager;
|
|
169
310
|
}
|
|
170
311
|
|
|
@@ -197,6 +338,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
197
338
|
this.minFeePadding = value ?? 0.5;
|
|
198
339
|
}
|
|
199
340
|
|
|
341
|
+
setEstimatedGasPadding(value?: number) {
|
|
342
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
343
|
+
}
|
|
344
|
+
|
|
200
345
|
stop() {
|
|
201
346
|
return this.pxe.stop();
|
|
202
347
|
}
|
|
@@ -1,50 +1,77 @@
|
|
|
1
|
-
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type AztecNode, createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { createStore, openTmpStore } from '@aztec/kv-store/indexeddb';
|
|
4
|
-
import { createPXE } from '@aztec/pxe/client/lazy';
|
|
5
|
-
import { getPXEConfig } from '@aztec/pxe/config';
|
|
4
|
+
import { type PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/client/lazy';
|
|
5
|
+
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
6
6
|
|
|
7
7
|
import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
|
|
8
|
-
import {
|
|
8
|
+
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
9
|
+
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
9
10
|
import { WalletDB } from '../wallet_db.js';
|
|
10
11
|
|
|
11
12
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
12
|
-
static async create
|
|
13
|
+
static async create<T extends BrowserEmbeddedWallet = BrowserEmbeddedWallet>(
|
|
14
|
+
this: new (
|
|
15
|
+
pxe: PXE,
|
|
16
|
+
aztecNode: AztecNode,
|
|
17
|
+
walletDB: WalletDB,
|
|
18
|
+
accountContracts: AccountContractsProvider,
|
|
19
|
+
log?: Logger,
|
|
20
|
+
) => T,
|
|
21
|
+
nodeOrUrl: string | AztecNode,
|
|
22
|
+
options: EmbeddedWalletOptions = {},
|
|
23
|
+
): Promise<T> {
|
|
13
24
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
14
25
|
|
|
15
|
-
const aztecNode = createAztecNodeClient(
|
|
16
|
-
|
|
26
|
+
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
17
27
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
18
|
-
const rollupAddress = l1Contracts.rollupAddress;
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
|
|
34
|
+
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
35
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
36
|
+
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
37
|
+
...mergedConfigOverrides,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (options.ephemeral) {
|
|
41
|
+
delete pxeConfig.dataDirectory;
|
|
23
42
|
}
|
|
24
43
|
|
|
25
|
-
const
|
|
44
|
+
const pxeOptions: PXECreationOptions = {
|
|
45
|
+
...mergedCreationOverrides,
|
|
26
46
|
loggers: {
|
|
27
47
|
store: rootLogger.createChild('pxe:data'),
|
|
28
48
|
pxe: rootLogger.createChild('pxe:service'),
|
|
29
49
|
prover: rootLogger.createChild('pxe:prover'),
|
|
50
|
+
...mergedCreationOverrides.loggers,
|
|
30
51
|
},
|
|
31
|
-
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
32
55
|
|
|
33
56
|
const walletDBStore = options.ephemeral
|
|
34
57
|
? await openTmpStore(true)
|
|
35
58
|
: await createStore(
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
|
|
59
|
+
'wallet_data',
|
|
60
|
+
{
|
|
61
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
62
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
63
|
+
l1Contracts,
|
|
64
|
+
},
|
|
65
|
+
1,
|
|
39
66
|
rootLogger.createChild('wallet:data'),
|
|
40
67
|
);
|
|
41
68
|
const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
42
69
|
|
|
43
|
-
return new
|
|
70
|
+
return new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
|
|
44
71
|
}
|
|
45
72
|
}
|
|
46
73
|
|
|
47
74
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
48
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
75
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
49
76
|
export { WalletDB } from '../wallet_db.js';
|
|
50
77
|
export type { AccountType } from '../wallet_db.js';
|