@aztec/wallets 5.0.0-private.20260318 → 5.0.0-rc.1
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 -8
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +10 -10
- package/dest/embedded/account-contract-providers/lazy.d.ts +6 -8
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +20 -10
- package/dest/embedded/account-contract-providers/types.d.ts +6 -8
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +65 -10
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +252 -59
- 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 +39 -10
- 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 +33 -10
- package/dest/embedded/store_encryption.d.ts +67 -0
- package/dest/embedded/store_encryption.d.ts.map +1 -0
- package/dest/embedded/store_encryption.js +71 -0
- package/dest/embedded/wallet_db.d.ts +7 -6
- package/dest/embedded/wallet_db.d.ts.map +1 -1
- package/dest/embedded/wallet_db.js +10 -9
- package/dest/testing.d.ts +8 -4
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +8 -14
- package/package.json +12 -10
- package/src/embedded/account-contract-providers/bundle.ts +13 -12
- package/src/embedded/account-contract-providers/lazy.ts +23 -12
- package/src/embedded/account-contract-providers/types.ts +6 -4
- package/src/embedded/embedded_wallet.ts +331 -67
- package/src/embedded/entrypoints/browser.ts +47 -20
- package/src/embedded/entrypoints/node.ts +46 -26
- package/src/embedded/store_encryption.ts +107 -0
- package/src/embedded/wallet_db.ts +13 -10
- package/src/testing.ts +11 -16
|
@@ -1,21 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { ContractFunctionInteraction, NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
6
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
7
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
3
8
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
9
|
+
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
10
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
6
11
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
7
|
-
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
8
|
-
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
12
|
+
import { SimulationOverrides, TxStatus, collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
13
|
+
import { BaseWallet, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
|
|
14
|
+
/** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */ export function splitPxeOptions(pxe) {
|
|
15
|
+
if (!pxe) {
|
|
16
|
+
return {
|
|
17
|
+
config: {},
|
|
18
|
+
creation: {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } = pxe;
|
|
22
|
+
return {
|
|
23
|
+
config,
|
|
24
|
+
creation: {
|
|
25
|
+
loggers,
|
|
26
|
+
loggerActorLabel,
|
|
27
|
+
proverOrOptions,
|
|
28
|
+
store,
|
|
29
|
+
simulator,
|
|
30
|
+
hooks,
|
|
31
|
+
preloadedContractsProvider
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
9
36
|
export class EmbeddedWallet extends BaseWallet {
|
|
10
37
|
walletDB;
|
|
11
38
|
accountContracts;
|
|
39
|
+
estimatedGasPadding;
|
|
40
|
+
// Stub class ids, populated on wallet startup
|
|
41
|
+
// to avoid redundant work per simulation
|
|
42
|
+
stubClassIds;
|
|
12
43
|
constructor(pxe, aztecNode, walletDB, accountContracts, log){
|
|
13
|
-
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts;
|
|
44
|
+
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING, this.stubClassIds = new Map();
|
|
14
45
|
}
|
|
15
46
|
async getAccountFromAddress(address) {
|
|
16
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
17
|
-
return new SignerlessAccount();
|
|
18
|
-
}
|
|
19
47
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
20
48
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
21
49
|
const account = await accountManager.getAccount();
|
|
@@ -42,75 +70,215 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
42
70
|
return storedSenders;
|
|
43
71
|
}
|
|
44
72
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*/ async
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
74
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
75
|
+
* the necessary authwitnesses.
|
|
76
|
+
*/ async sendTx(executionPayload, opts) {
|
|
77
|
+
// PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
|
|
78
|
+
// both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
|
|
79
|
+
await this.pxe.sync();
|
|
80
|
+
const feeOptions = await this.completeFeeOptions({
|
|
81
|
+
from: opts.from,
|
|
82
|
+
feePayer: executionPayload.feePayer,
|
|
83
|
+
gasSettings: opts.fee?.gasSettings,
|
|
84
|
+
forEstimation: true
|
|
85
|
+
});
|
|
86
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
87
|
+
// private authwitnesses based on offchain effects.
|
|
88
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
89
|
+
from: opts.from,
|
|
90
|
+
feeOptions,
|
|
91
|
+
additionalScopes: opts.additionalScopes,
|
|
92
|
+
skipTxValidation: true,
|
|
93
|
+
sendMessagesAs: opts.sendMessagesAs
|
|
94
|
+
});
|
|
95
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
96
|
+
const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
|
|
97
|
+
try {
|
|
98
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
99
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
100
|
+
consumer: effect.contractAddress,
|
|
101
|
+
innerHash: authRequest.innerHash
|
|
102
|
+
});
|
|
103
|
+
} catch {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
for (const authwit of authWitnesses){
|
|
108
|
+
if (authwit) {
|
|
109
|
+
executionPayload.authWitnesses.push(authwit);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
113
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
114
|
+
this.log.verbose(`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`);
|
|
115
|
+
const gasSettings = GasSettings.from({
|
|
116
|
+
...opts.fee?.gasSettings,
|
|
117
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
118
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
119
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
120
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
|
|
121
|
+
});
|
|
122
|
+
let wait = opts.wait;
|
|
123
|
+
if (wait !== NO_WAIT) {
|
|
124
|
+
const callerWaitOpts = typeof wait === 'object' ? wait : {};
|
|
125
|
+
wait = {
|
|
126
|
+
...callerWaitOpts,
|
|
127
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
128
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
129
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
130
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
131
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
132
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
133
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
134
|
+
waitForStatus: callerWaitOpts.waitForStatus ?? TxStatus.PROPOSED
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return super.sendTx(executionPayload, {
|
|
138
|
+
...opts,
|
|
139
|
+
wait: wait,
|
|
140
|
+
fee: {
|
|
141
|
+
...opts.fee,
|
|
142
|
+
gasSettings
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
|
|
148
|
+
* wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
|
|
149
|
+
* standalone simulations we still need a fresh anchor block, which we provide here.
|
|
150
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
151
|
+
await this.pxe.sync();
|
|
152
|
+
return super.simulateTx(executionPayload, opts);
|
|
153
|
+
}
|
|
154
|
+
async profileTx(executionPayload, opts) {
|
|
155
|
+
await this.pxe.sync();
|
|
156
|
+
return super.profileTx(executionPayload, opts);
|
|
157
|
+
}
|
|
158
|
+
async executeUtility(call, opts) {
|
|
159
|
+
await this.pxe.sync();
|
|
160
|
+
return super.executeUtility(call, opts);
|
|
161
|
+
}
|
|
162
|
+
async getPrivateEvents(eventDef, eventFilter) {
|
|
163
|
+
await this.pxe.sync();
|
|
164
|
+
return super.getPrivateEvents(eventDef, eventFilter);
|
|
165
|
+
}
|
|
166
|
+
async registerContract(instance, artifact, secretKey) {
|
|
167
|
+
// registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
|
|
168
|
+
// block to verify the current class id from the node.
|
|
169
|
+
await this.pxe.sync();
|
|
170
|
+
return super.registerContract(instance, artifact, secretKey);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
174
|
+
* stubClassIds. Called on wallet initialization.
|
|
175
|
+
*/ async initStubClasses() {
|
|
176
|
+
const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
|
|
177
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
|
|
178
|
+
await this.pxe.registerContractClass(schnorrArtifact);
|
|
179
|
+
// ecdsa stubs share the same class id
|
|
180
|
+
const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
|
|
181
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
|
|
182
|
+
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
183
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
184
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
185
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
186
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
190
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
191
|
+
*/ async buildAccountOverrides(addresses) {
|
|
192
|
+
const accounts = await this.getAccounts();
|
|
193
|
+
const contracts = {};
|
|
194
|
+
const filtered = accounts.filter((acc)=>addresses.some((addr)=>addr.equals(acc.item)));
|
|
195
|
+
for (const account of filtered){
|
|
196
|
+
const address = account.item;
|
|
197
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
198
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
199
|
+
if (!stubClassId) {
|
|
200
|
+
throw new Error(`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`);
|
|
201
|
+
}
|
|
202
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
203
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
204
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
205
|
+
if (!contractInstance) {
|
|
206
|
+
throw new Error(`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`);
|
|
207
|
+
}
|
|
208
|
+
contracts[address.toString()] = {
|
|
209
|
+
instance: {
|
|
210
|
+
...contractInstance,
|
|
211
|
+
currentContractClassId: stubClassId
|
|
60
212
|
}
|
|
61
213
|
};
|
|
62
|
-
} else {
|
|
63
|
-
fromAccount = await this.getAccountFromAddress(from);
|
|
64
214
|
}
|
|
215
|
+
return contracts;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
219
|
+
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
220
|
+
* private kernel circuit execution.
|
|
221
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
222
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
223
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
65
224
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
66
|
-
const executionOptions = {
|
|
67
|
-
txNonce: Fr.random(),
|
|
68
|
-
cancellable: this.cancellableTransactions,
|
|
69
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
70
|
-
};
|
|
71
225
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
72
226
|
feeExecutionPayload,
|
|
73
227
|
executionPayload
|
|
74
228
|
]) : executionPayload;
|
|
75
229
|
const chainInfo = await this.getChainInfo();
|
|
76
|
-
const
|
|
77
|
-
|
|
230
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
231
|
+
const overrides = new SimulationOverrides({
|
|
232
|
+
contracts: accountOverrides
|
|
233
|
+
});
|
|
234
|
+
let txRequest;
|
|
235
|
+
if (from === NO_FROM) {
|
|
236
|
+
const entrypoint = new DefaultEntrypoint();
|
|
237
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
238
|
+
} else {
|
|
239
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
240
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
241
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
242
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
243
|
+
const executionOptions = {
|
|
244
|
+
txNonce: Fr.random(),
|
|
245
|
+
cancellable: this.cancellableTransactions,
|
|
246
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
247
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
248
|
+
};
|
|
249
|
+
txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
250
|
+
}
|
|
251
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
78
252
|
simulatePublic: true,
|
|
79
253
|
skipFeeEnforcement,
|
|
80
254
|
skipTxValidation,
|
|
81
255
|
overrides,
|
|
82
|
-
scopes
|
|
256
|
+
scopes,
|
|
257
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
|
|
83
258
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
87
|
-
if (originalAccount instanceof SignerlessAccount) {
|
|
88
|
-
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
89
|
-
}
|
|
90
|
-
const originalAddress = originalAccount.getCompleteAddress();
|
|
91
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
92
|
-
if (!contractInstance) {
|
|
93
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
94
|
-
}
|
|
95
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
96
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
97
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
98
|
-
salt: Fr.random()
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
account: stubAccount,
|
|
102
|
-
instance,
|
|
103
|
-
artifact: stubArtifact
|
|
104
|
-
};
|
|
259
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
260
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
105
261
|
}
|
|
106
262
|
async createAccountInternal(type, secret, salt, signingKey) {
|
|
107
263
|
let contract;
|
|
264
|
+
let immutablesHash;
|
|
265
|
+
let publicKey;
|
|
108
266
|
switch(type){
|
|
109
267
|
case 'schnorr':
|
|
110
268
|
{
|
|
111
269
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
112
270
|
break;
|
|
113
271
|
}
|
|
272
|
+
case 'schnorr_initializerless':
|
|
273
|
+
{
|
|
274
|
+
contract = await this.accountContracts.getSchnorrInitializerlessAccountContract(Fq.fromBuffer(signingKey));
|
|
275
|
+
publicKey = await new Schnorr().computePublicKey(Fq.fromBuffer(signingKey));
|
|
276
|
+
immutablesHash = await poseidon2Hash([
|
|
277
|
+
publicKey.x,
|
|
278
|
+
publicKey.y
|
|
279
|
+
]);
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
114
282
|
case 'ecdsasecp256k1':
|
|
115
283
|
{
|
|
116
284
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
@@ -126,12 +294,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
126
294
|
throw new Error(`Unknown account type ${type}`);
|
|
127
295
|
}
|
|
128
296
|
}
|
|
129
|
-
const accountManager = await AccountManager.create(this, secret, contract,
|
|
297
|
+
const accountManager = await AccountManager.create(this, secret, contract, {
|
|
298
|
+
salt,
|
|
299
|
+
immutablesHash
|
|
300
|
+
});
|
|
130
301
|
const instance = accountManager.getInstance();
|
|
131
302
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
132
303
|
if (!existingInstance) {
|
|
133
304
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
305
|
+
const artifact = existingArtifact ?? await accountManager.getAccountContract().getContractArtifact();
|
|
134
306
|
await this.registerContract(instance, !existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined, accountManager.getSecretKey());
|
|
307
|
+
if (type === 'schnorr_initializerless') {
|
|
308
|
+
const constructor = artifact.functions.find((f)=>f.name === 'constructor');
|
|
309
|
+
if (!constructor) {
|
|
310
|
+
throw new Error('Could not create SchnorrInitializerlessAccountContract: constructor ABI not found');
|
|
311
|
+
}
|
|
312
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructor, [
|
|
313
|
+
publicKey.x,
|
|
314
|
+
publicKey.y
|
|
315
|
+
]);
|
|
316
|
+
await storeCall.simulate({
|
|
317
|
+
from: instance.address
|
|
318
|
+
});
|
|
319
|
+
}
|
|
135
320
|
}
|
|
136
321
|
return accountManager;
|
|
137
322
|
}
|
|
@@ -150,6 +335,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
150
335
|
const sk = signingKey ?? deriveSigningKey(secret);
|
|
151
336
|
return this.createAndStoreAccount(alias ?? '', 'schnorr', secret, salt, sk.toBuffer());
|
|
152
337
|
}
|
|
338
|
+
createSchnorrInitializerlessAccount(secret, salt, signingKey, alias) {
|
|
339
|
+
const sk = signingKey ?? deriveSigningKey(secret);
|
|
340
|
+
return this.createAndStoreAccount(alias ?? '', 'schnorr_initializerless', secret, salt, sk.toBuffer());
|
|
341
|
+
}
|
|
153
342
|
createECDSARAccount(secret, salt, signingKey, alias) {
|
|
154
343
|
return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
|
|
155
344
|
}
|
|
@@ -159,7 +348,11 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
159
348
|
setMinFeePadding(value) {
|
|
160
349
|
this.minFeePadding = value ?? 0.5;
|
|
161
350
|
}
|
|
162
|
-
|
|
163
|
-
|
|
351
|
+
setEstimatedGasPadding(value) {
|
|
352
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
353
|
+
}
|
|
354
|
+
async stop() {
|
|
355
|
+
await this.pxe.stop();
|
|
356
|
+
await this.walletDB.close();
|
|
164
357
|
}
|
|
165
358
|
}
|
|
@@ -8,7 +8,7 @@ export declare class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
8
8
|
static create<T extends BrowserEmbeddedWallet = BrowserEmbeddedWallet>(this: new (pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger) => T, nodeOrUrl: string | AztecNode, options?: EmbeddedWalletOptions): Promise<T>;
|
|
9
9
|
}
|
|
10
10
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
11
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
11
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
12
12
|
export { WalletDB } from '../wallet_db.js';
|
|
13
13
|
export type { AccountType } from '../wallet_db.js';
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL2Jyb3dzZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUF5QixNQUFNLHNCQUFzQixDQUFDO0FBQzdFLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUVsRSxPQUFPLEVBQUUsS0FBSyxHQUFHLEVBQXNDLE1BQU0sd0JBQXdCLENBQUM7QUFPdEYsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx3Q0FBd0MsQ0FBQztBQUN2RixPQUFPLEVBQUUsY0FBYyxFQUFFLEtBQUsscUJBQXFCLEVBQW1CLE1BQU0sdUJBQXVCLENBQUM7QUFDcEcsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBRTNDLHFCQUFhLHFCQUFzQixTQUFRLGNBQWM7SUFDdkQsT0FBYSxNQUFNLENBQUMsQ0FBQyxTQUFTLHFCQUFxQixHQUFHLHFCQUFxQixFQUN6RSxJQUFJLEVBQUUsS0FDSixHQUFHLEVBQUUsR0FBRyxFQUNSLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFFBQVEsRUFBRSxRQUFRLEVBQ2xCLGdCQUFnQixFQUFFLHdCQUF3QixFQUMxQyxHQUFHLENBQUMsRUFBRSxNQUFNLEtBQ1QsQ0FBQyxFQUNOLFNBQVMsRUFBRSxNQUFNLEdBQUcsU0FBUyxFQUM3QixPQUFPLEdBQUUscUJBQTBCLEdBQ2xDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0E0RFo7Q0FDRjtBQUVELE9BQU8sRUFBRSxxQkFBcUIsSUFBSSxjQUFjLEVBQUUsQ0FBQztBQUNuRCxZQUFZLEVBQUUscUJBQXFCLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUM3RixPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFDM0MsWUFBWSxFQUFFLFdBQVcsRUFBRSxNQUFNLGlCQUFpQixDQUFDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,wBAAwB,CAAC;AAOtF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,OAAa,MAAM,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB,EACzE,IAAI,EAAE,KACJ,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,wBAAwB,EAC1C,GAAG,CAAC,EAAE,MAAM,KACT,CAAC,EACN,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC,CA4DZ;CACF;AAED,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,CAAC;AACnD,YAAY,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -3,40 +3,69 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { createStore, openTmpStore } from '@aztec/kv-store/indexeddb';
|
|
4
4
|
import { createPXE } from '@aztec/pxe/client/lazy';
|
|
5
5
|
import { getPXEConfig } from '@aztec/pxe/config';
|
|
6
|
+
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry/lazy';
|
|
7
|
+
import { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry/lazy';
|
|
8
|
+
import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint/lazy';
|
|
6
9
|
import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
|
|
7
|
-
import { EmbeddedWallet } from '../embedded_wallet.js';
|
|
10
|
+
import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
|
|
8
11
|
import { WalletDB } from '../wallet_db.js';
|
|
9
12
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
10
13
|
static async create(nodeOrUrl, options = {}) {
|
|
11
14
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
12
15
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
13
16
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
17
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
18
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
19
|
+
const mergedConfigOverrides = {
|
|
20
|
+
...options.pxeConfig,
|
|
21
|
+
...pxeConfigFromPxe
|
|
22
|
+
};
|
|
23
|
+
const mergedCreationOverrides = {
|
|
24
|
+
...options.pxeOptions,
|
|
25
|
+
...pxeCreationFromPxe
|
|
26
|
+
};
|
|
14
27
|
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
15
|
-
proverEnabled:
|
|
28
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
16
29
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
17
|
-
|
|
30
|
+
autoSync: false,
|
|
31
|
+
...mergedConfigOverrides
|
|
18
32
|
});
|
|
19
33
|
if (options.ephemeral) {
|
|
20
34
|
delete pxeConfig.dataDirectory;
|
|
21
35
|
}
|
|
22
36
|
const pxeOptions = {
|
|
23
|
-
...
|
|
37
|
+
...mergedCreationOverrides,
|
|
38
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
39
|
+
getPreloadedContracts: async ()=>[
|
|
40
|
+
await getStandardMultiCallEntrypoint(),
|
|
41
|
+
await getStandardAuthRegistry(),
|
|
42
|
+
await getStandardHandshakeRegistry()
|
|
43
|
+
]
|
|
44
|
+
},
|
|
24
45
|
loggers: {
|
|
25
46
|
store: rootLogger.createChild('pxe:data'),
|
|
26
47
|
pxe: rootLogger.createChild('pxe:service'),
|
|
27
48
|
prover: rootLogger.createChild('pxe:prover'),
|
|
28
|
-
...
|
|
49
|
+
...mergedCreationOverrides.loggers
|
|
29
50
|
}
|
|
30
51
|
};
|
|
31
52
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
32
|
-
const walletDBStore = options.ephemeral ? await openTmpStore(true) : await createStore('wallet_data', {
|
|
53
|
+
const walletDBStore = options.walletDb?.store ?? (options.ephemeral ? await openTmpStore(true) : await createStore('wallet_data', {
|
|
33
54
|
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
34
55
|
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
35
|
-
l1Contracts
|
|
36
|
-
}, 1, rootLogger.createChild('wallet:data'));
|
|
37
|
-
const walletDB = WalletDB
|
|
38
|
-
|
|
56
|
+
rollupAddress: l1Contracts.rollupAddress
|
|
57
|
+
}, 1, rootLogger.createChild('wallet:data')));
|
|
58
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
59
|
+
const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger);
|
|
60
|
+
await wallet.initStubClasses();
|
|
61
|
+
return wallet;
|
|
39
62
|
}
|
|
40
63
|
}
|
|
41
64
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
42
65
|
export { WalletDB } from '../wallet_db.js';
|
|
66
|
+
// At-rest encryption helpers are intentionally NOT re-exported here. They live
|
|
67
|
+
// on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
|
|
68
|
+
// (and bundlers) of this entrypoint don't transitively pull in
|
|
69
|
+
// `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
|
|
70
|
+
// chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
|
|
71
|
+
// (e.g. the playground) should never see sqlite-opfs in their bundle.
|
|
@@ -8,7 +8,7 @@ export declare class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
8
8
|
static create<T extends NodeEmbeddedWallet = NodeEmbeddedWallet>(this: new (pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger) => T, nodeOrUrl: string | AztecNode, options?: EmbeddedWalletOptions): Promise<T>;
|
|
9
9
|
}
|
|
10
10
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
11
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
11
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
12
12
|
export { WalletDB } from '../wallet_db.js';
|
|
13
13
|
export type { AccountType } from '../wallet_db.js';
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL25vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBR2xFLE9BQU8sRUFBRSxLQUFLLEdBQUcsRUFBc0MsTUFBTSxtQkFBbUIsQ0FBQztBQUlqRixPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUdqRSxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHdDQUF3QyxDQUFDO0FBQ3ZGLE9BQU8sRUFBRSxjQUFjLEVBQUUsS0FBSyxxQkFBcUIsRUFBbUIsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRyxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFM0MscUJBQWEsa0JBQW1CLFNBQVEsY0FBYztJQUNwRCxPQUFhLE1BQU0sQ0FBQyxDQUFDLFNBQVMsa0JBQWtCLEdBQUcsa0JBQWtCLEVBQ25FLElBQUksRUFBRSxLQUNKLEdBQUcsRUFBRSxHQUFHLEVBQ1IsU0FBUyxFQUFFLFNBQVMsRUFDcEIsUUFBUSxFQUFFLFFBQVEsRUFDbEIsZ0JBQWdCLEVBQUUsd0JBQXdCLEVBQzFDLEdBQUcsQ0FBQyxFQUFFLE1BQU0sS0FDVCxDQUFDLEVBQ04sU0FBUyxFQUFFLE1BQU0sR0FBRyxTQUFTLEVBQzdCLE9BQU8sR0FBRSxxQkFBMEIsR0FDbEMsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQWtFWjtDQUNGO0FBRUQsT0FBTyxFQUFFLGtCQUFrQixJQUFJLGNBQWMsRUFBRSxDQUFDO0FBQ2hELFlBQVksRUFBRSxxQkFBcUIsRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzdGLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUMzQyxZQUFZLEVBQUUsV0FBVyxFQUFFLE1BQU0saUJBQWlCLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,mBAAmB,CAAC;AAIjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAa,MAAM,CAAC,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,EACnE,IAAI,EAAE,KACJ,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,wBAAwB,EAC1C,GAAG,CAAC,EAAE,MAAM,KACT,CAAC,EACN,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC,CAkEZ;CACF;AAED,OAAO,EAAE,kBAAkB,IAAI,cAAc,EAAE,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -3,39 +3,62 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
3
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
|
+
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
|
|
7
|
+
import { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry';
|
|
8
|
+
import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
6
9
|
import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
|
|
7
|
-
import { EmbeddedWallet } from '../embedded_wallet.js';
|
|
10
|
+
import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
|
|
8
11
|
import { WalletDB } from '../wallet_db.js';
|
|
9
12
|
export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
10
13
|
static async create(nodeOrUrl, options = {}) {
|
|
11
14
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
12
15
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
13
16
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
17
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
18
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
19
|
+
const mergedConfigOverrides = {
|
|
20
|
+
...options.pxeConfig,
|
|
21
|
+
...pxeConfigFromPxe
|
|
22
|
+
};
|
|
23
|
+
const mergedCreationOverrides = {
|
|
24
|
+
...options.pxeOptions,
|
|
25
|
+
...pxeCreationFromPxe
|
|
26
|
+
};
|
|
14
27
|
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
15
|
-
proverEnabled:
|
|
28
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
16
29
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
17
|
-
|
|
30
|
+
autoSync: false,
|
|
31
|
+
...mergedConfigOverrides
|
|
18
32
|
});
|
|
19
33
|
if (options.ephemeral) {
|
|
20
34
|
delete pxeConfig.dataDirectory;
|
|
21
35
|
}
|
|
22
36
|
const pxeOptions = {
|
|
23
|
-
...
|
|
37
|
+
...mergedCreationOverrides,
|
|
38
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
39
|
+
getPreloadedContracts: async ()=>[
|
|
40
|
+
await getStandardMultiCallEntrypoint(),
|
|
41
|
+
await getStandardAuthRegistry(),
|
|
42
|
+
await getStandardHandshakeRegistry()
|
|
43
|
+
]
|
|
44
|
+
},
|
|
24
45
|
loggers: {
|
|
25
46
|
store: rootLogger.createChild('pxe:data'),
|
|
26
47
|
pxe: rootLogger.createChild('pxe:service'),
|
|
27
48
|
prover: rootLogger.createChild('pxe:prover'),
|
|
28
|
-
...
|
|
49
|
+
...mergedCreationOverrides.loggers
|
|
29
50
|
}
|
|
30
51
|
};
|
|
31
52
|
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, {
|
|
53
|
+
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
54
|
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
34
55
|
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
35
|
-
l1Contracts
|
|
36
|
-
}, rootLogger.createChild('wallet:data').getBindings());
|
|
37
|
-
const walletDB = WalletDB
|
|
38
|
-
|
|
56
|
+
rollupAddress: l1Contracts.rollupAddress
|
|
57
|
+
}, rootLogger.createChild('wallet:data').getBindings()));
|
|
58
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
59
|
+
const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
|
|
60
|
+
await wallet.initStubClasses();
|
|
61
|
+
return wallet;
|
|
39
62
|
}
|
|
40
63
|
}
|
|
41
64
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet-layer helpers for opening the embedded wallet's two encrypted stores (PXE + walletDB) as a cohesive unit.
|
|
3
|
+
*
|
|
4
|
+
* Sits on top of `@aztec/kv-store/sqlite-opfs`'s typed `SqliteEncryptionError` and adds:
|
|
5
|
+
*
|
|
6
|
+
* - `storeName: 'pxe' | 'wallet'`, telling callers WHICH store failed.
|
|
7
|
+
* - Cleanup: when the wallet store fails to open, ensures the already-opened PXE store is closed before the error
|
|
8
|
+
* surfaces, so callers don't leak the SAH Pool's OPFS lock.
|
|
9
|
+
*/
|
|
10
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
11
|
+
import { AztecSQLiteOPFSStore, SqliteEncryptionError } from '@aztec/kv-store/sqlite-opfs';
|
|
12
|
+
/** Which of the embedded wallet's two stores failed to open. */
|
|
13
|
+
export type EmbeddedStoreName = 'pxe' | 'wallet';
|
|
14
|
+
/**
|
|
15
|
+
* Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
|
|
16
|
+
* key. The original {@link SqliteEncryptionError} is preserved as `cause`.
|
|
17
|
+
*/
|
|
18
|
+
export declare class EmbeddedWalletEncryptionError extends Error {
|
|
19
|
+
readonly storeName: EmbeddedStoreName;
|
|
20
|
+
constructor(storeName: EmbeddedStoreName, opts: {
|
|
21
|
+
cause: SqliteEncryptionError;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** Configuration for {@link openEncryptedEmbeddedStores}. */
|
|
25
|
+
export interface OpenEncryptedEmbeddedStoresOptions {
|
|
26
|
+
pxe: {
|
|
27
|
+
name: string;
|
|
28
|
+
poolDirectory?: string;
|
|
29
|
+
};
|
|
30
|
+
wallet: {
|
|
31
|
+
name: string;
|
|
32
|
+
poolDirectory?: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Internal seam for tests to inject a fake store opener. Defaults to `AztecSQLiteOPFSStore.open`. Not part of the
|
|
37
|
+
* public API.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export type OpenSqliteEncryptedStoreFn = (log: Logger, name: string, poolDirectory: string | undefined, encryptionKey: Uint8Array) => Promise<AztecSQLiteOPFSStore>;
|
|
42
|
+
/**
|
|
43
|
+
* Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
|
|
44
|
+
*
|
|
45
|
+
* The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
|
|
46
|
+
* the key buffer to its worker. A single buffer would detach between the two opens.
|
|
47
|
+
*
|
|
48
|
+
* Failure modes:
|
|
49
|
+
*
|
|
50
|
+
* - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
|
|
51
|
+
* needed (nothing was opened).
|
|
52
|
+
* - Wallet store fails to decrypt → closes the already-opened PXE store then throws
|
|
53
|
+
* `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
|
|
54
|
+
* - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
|
|
55
|
+
* (preserves callers' existing untyped error handling for non-encryption faults).
|
|
56
|
+
*
|
|
57
|
+
* @param config - Per-store name/poolDirectory.
|
|
58
|
+
* @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
|
|
59
|
+
* detaches on transfer, so each call must allocate).
|
|
60
|
+
* @param log - Logger for both stores.
|
|
61
|
+
* @param openStore - Internal test seam. Do not pass in production code.
|
|
62
|
+
*/
|
|
63
|
+
export declare function openEncryptedEmbeddedStores(config: OpenEncryptedEmbeddedStoresOptions, getEncryptionKey: () => Promise<Uint8Array>, log: Logger, openStore?: OpenSqliteEncryptedStoreFn): Promise<{
|
|
64
|
+
pxeStore: AztecSQLiteOPFSStore;
|
|
65
|
+
walletStore: AztecSQLiteOPFSStore;
|
|
66
|
+
}>;
|
|
67
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUscUJBQXFCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUUxRixnRUFBZ0U7QUFDaEUsTUFBTSxNQUFNLGlCQUFpQixHQUFHLEtBQUssR0FBRyxRQUFRLENBQUM7QUFFakQ7OztHQUdHO0FBQ0gscUJBQWEsNkJBQThCLFNBQVEsS0FBSztJQUN0RCxRQUFRLENBQUMsU0FBUyxFQUFFLGlCQUFpQixDQUFDO0lBRXRDLFlBQVksU0FBUyxFQUFFLGlCQUFpQixFQUFFLElBQUksRUFBRTtRQUFFLEtBQUssRUFBRSxxQkFBcUIsQ0FBQTtLQUFFLEVBSS9FO0NBQ0Y7QUFFRCw2REFBNkQ7QUFDN0QsTUFBTSxXQUFXLGtDQUFrQztJQUNqRCxHQUFHLEVBQUU7UUFBRSxJQUFJLEVBQUUsTUFBTSxDQUFDO1FBQUMsYUFBYSxDQUFDLEVBQUUsTUFBTSxDQUFBO0tBQUUsQ0FBQztJQUM5QyxNQUFNLEVBQUU7UUFBRSxJQUFJLEVBQUUsTUFBTSxDQUFDO1FBQUMsYUFBYSxDQUFDLEVBQUUsTUFBTSxDQUFBO0tBQUUsQ0FBQztDQUNsRDtBQUVEOzs7OztHQUtHO0FBQ0gsTUFBTSxNQUFNLDBCQUEwQixHQUFHLENBQ3ZDLEdBQUcsRUFBRSxNQUFNLEVBQ1gsSUFBSSxFQUFFLE1BQU0sRUFDWixhQUFhLEVBQUUsTUFBTSxHQUFHLFNBQVMsRUFDakMsYUFBYSxFQUFFLFVBQVUsS0FDdEIsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBQUM7QUFLbkM7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBb0JHO0FBQ0gsd0JBQXNCLDJCQUEyQixDQUMvQyxNQUFNLEVBQUUsa0NBQWtDLEVBQzFDLGdCQUFnQixFQUFFLE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxFQUMzQyxHQUFHLEVBQUUsTUFBTSxFQUNYLFNBQVMsR0FBRSwwQkFBNkMsR0FDdkQsT0FBTyxDQUFDO0lBQUUsUUFBUSxFQUFFLG9CQUFvQixDQUFDO0lBQUMsV0FBVyxFQUFFLG9CQUFvQixDQUFBO0NBQUUsQ0FBQyxDQVdoRiJ9
|