@aztec/wallets 0.0.1-commit.9ef841308 → 0.0.1-commit.a4600f49
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 +52 -8
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +192 -47
- 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 +34 -11
- 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 +12 -11
- 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 +236 -48
- package/src/embedded/entrypoints/browser.ts +41 -21
- package/src/embedded/entrypoints/node.ts +46 -26
- package/src/embedded/store_encryption.ts +107 -0
- package/src/embedded/wallet_db.ts +15 -12
- package/src/testing.ts +11 -17
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
4
|
-
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
3
|
+
import { ContractFunctionInteraction, NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
5
5
|
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
6
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
7
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
6
8
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
7
|
-
import {
|
|
9
|
+
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
8
10
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
9
11
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
10
|
-
import { collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
11
|
-
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
|
+
}
|
|
12
35
|
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
13
36
|
export class EmbeddedWallet extends BaseWallet {
|
|
14
37
|
walletDB;
|
|
15
38
|
accountContracts;
|
|
16
39
|
estimatedGasPadding;
|
|
40
|
+
// Stub class ids, populated on wallet startup
|
|
41
|
+
// to avoid redundant work per simulation
|
|
42
|
+
stubClassIds;
|
|
17
43
|
constructor(pxe, aztecNode, walletDB, accountContracts, log){
|
|
18
|
-
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
44
|
+
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING, this.stubClassIds = new Map();
|
|
19
45
|
}
|
|
20
46
|
async getAccountFromAddress(address) {
|
|
21
47
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
@@ -31,14 +57,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
31
57
|
}
|
|
32
58
|
async registerSender(address, alias) {
|
|
33
59
|
await this.walletDB.storeSender(address, alias);
|
|
34
|
-
|
|
60
|
+
await this.pxe.registerTaggingSecretSource({
|
|
61
|
+
kind: 'address-derived',
|
|
62
|
+
sender: address
|
|
63
|
+
});
|
|
64
|
+
return address;
|
|
35
65
|
}
|
|
36
66
|
async getAddressBook() {
|
|
37
|
-
const
|
|
67
|
+
const sources = await this.pxe.getTaggingSecretSources({
|
|
68
|
+
kind: 'address-derived'
|
|
69
|
+
});
|
|
70
|
+
const senders = sources.map((source)=>source.sender);
|
|
38
71
|
const storedSenders = await this.walletDB.listSenders();
|
|
39
72
|
for (const storedSender of storedSenders){
|
|
40
73
|
if (senders.findIndex((sender)=>sender.equals(storedSender.item)) === -1) {
|
|
41
|
-
await this.pxe.
|
|
74
|
+
await this.pxe.registerTaggingSecretSource({
|
|
75
|
+
kind: 'address-derived',
|
|
76
|
+
sender: storedSender.item
|
|
77
|
+
});
|
|
42
78
|
}
|
|
43
79
|
}
|
|
44
80
|
return storedSenders;
|
|
@@ -48,14 +84,23 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
48
84
|
* estimates actual gas usage and captures call authorization requests to generate
|
|
49
85
|
* the necessary authwitnesses.
|
|
50
86
|
*/ async sendTx(executionPayload, opts) {
|
|
51
|
-
|
|
87
|
+
// PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
|
|
88
|
+
// both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
|
|
89
|
+
await this.pxe.sync();
|
|
90
|
+
const feeOptions = await this.completeFeeOptions({
|
|
91
|
+
from: opts.from,
|
|
92
|
+
feePayer: executionPayload.feePayer,
|
|
93
|
+
gasSettings: opts.fee?.gasSettings,
|
|
94
|
+
forEstimation: true
|
|
95
|
+
});
|
|
52
96
|
// Simulate the transaction first to estimate gas and capture required
|
|
53
97
|
// private authwitnesses based on offchain effects.
|
|
54
98
|
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
55
99
|
from: opts.from,
|
|
56
100
|
feeOptions,
|
|
57
|
-
|
|
58
|
-
skipTxValidation: true
|
|
101
|
+
additionalScopes: opts.additionalScopes,
|
|
102
|
+
skipTxValidation: true,
|
|
103
|
+
sendMessagesAs: opts.sendMessagesAs
|
|
59
104
|
});
|
|
60
105
|
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
61
106
|
const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
|
|
@@ -74,7 +119,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
74
119
|
executionPayload.authWitnesses.push(authwit);
|
|
75
120
|
}
|
|
76
121
|
}
|
|
77
|
-
const
|
|
122
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
123
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
78
124
|
this.log.verbose(`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`);
|
|
79
125
|
const gasSettings = GasSettings.from({
|
|
80
126
|
...opts.fee?.gasSettings,
|
|
@@ -83,8 +129,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
83
129
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
84
130
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
|
|
85
131
|
});
|
|
132
|
+
let wait = opts.wait;
|
|
133
|
+
if (wait !== NO_WAIT) {
|
|
134
|
+
const callerWaitOpts = typeof wait === 'object' ? wait : {};
|
|
135
|
+
wait = {
|
|
136
|
+
...callerWaitOpts,
|
|
137
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
138
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
139
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
140
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
141
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
142
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
143
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
144
|
+
waitForStatus: callerWaitOpts.waitForStatus ?? TxStatus.PROPOSED
|
|
145
|
+
};
|
|
146
|
+
}
|
|
86
147
|
return super.sendTx(executionPayload, {
|
|
87
148
|
...opts,
|
|
149
|
+
wait: wait,
|
|
88
150
|
fee: {
|
|
89
151
|
...opts.fee,
|
|
90
152
|
gasSettings
|
|
@@ -92,32 +154,96 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
92
154
|
});
|
|
93
155
|
}
|
|
94
156
|
/**
|
|
157
|
+
* Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
|
|
158
|
+
* wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
|
|
159
|
+
* standalone simulations we still need a fresh anchor block, which we provide here.
|
|
160
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
161
|
+
await this.pxe.sync();
|
|
162
|
+
return super.simulateTx(executionPayload, opts);
|
|
163
|
+
}
|
|
164
|
+
async profileTx(executionPayload, opts) {
|
|
165
|
+
await this.pxe.sync();
|
|
166
|
+
return super.profileTx(executionPayload, opts);
|
|
167
|
+
}
|
|
168
|
+
async executeUtility(call, opts) {
|
|
169
|
+
await this.pxe.sync();
|
|
170
|
+
return super.executeUtility(call, opts);
|
|
171
|
+
}
|
|
172
|
+
async getPrivateEvents(eventDef, eventFilter) {
|
|
173
|
+
await this.pxe.sync();
|
|
174
|
+
return super.getPrivateEvents(eventDef, eventFilter);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
178
|
+
* stubClassIds. Called on wallet initialization.
|
|
179
|
+
*/ async initStubClasses() {
|
|
180
|
+
const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
|
|
181
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
|
|
182
|
+
await this.pxe.registerContractClass(schnorrArtifact);
|
|
183
|
+
// ecdsa stubs share the same class id
|
|
184
|
+
const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
|
|
185
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
|
|
186
|
+
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
187
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
188
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
189
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
190
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
194
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
195
|
+
*/ async buildAccountOverrides(addresses) {
|
|
196
|
+
const accounts = await this.getAccounts();
|
|
197
|
+
const contracts = {};
|
|
198
|
+
const filtered = accounts.filter((acc)=>addresses.some((addr)=>addr.equals(acc.item)));
|
|
199
|
+
for (const account of filtered){
|
|
200
|
+
const address = account.item;
|
|
201
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
202
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
203
|
+
if (!stubClassId) {
|
|
204
|
+
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.`);
|
|
205
|
+
}
|
|
206
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
207
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
208
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
209
|
+
if (!contractInstance) {
|
|
210
|
+
throw new Error(`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`);
|
|
211
|
+
}
|
|
212
|
+
contracts[address.toString()] = {
|
|
213
|
+
instance: {
|
|
214
|
+
...contractInstance,
|
|
215
|
+
currentContractClassId: stubClassId
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return contracts;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
95
222
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
96
223
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
97
224
|
* private kernel circuit execution.
|
|
98
225
|
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
99
|
-
const { from, feeOptions,
|
|
226
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
227
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
100
228
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
101
229
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
102
230
|
feeExecutionPayload,
|
|
103
231
|
executionPayload
|
|
104
232
|
]) : executionPayload;
|
|
105
233
|
const chainInfo = await this.getChainInfo();
|
|
106
|
-
|
|
234
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
235
|
+
const overrides = new SimulationOverrides({
|
|
236
|
+
contracts: accountOverrides
|
|
237
|
+
});
|
|
107
238
|
let txRequest;
|
|
108
239
|
if (from === NO_FROM) {
|
|
109
240
|
const entrypoint = new DefaultEntrypoint();
|
|
110
241
|
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
111
242
|
} else {
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
instance,
|
|
117
|
-
artifact
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
243
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
244
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
245
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
246
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
121
247
|
const executionOptions = {
|
|
122
248
|
txNonce: Fr.random(),
|
|
123
249
|
cancellable: this.cancellableTransactions,
|
|
@@ -126,40 +252,37 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
126
252
|
};
|
|
127
253
|
txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
128
254
|
}
|
|
129
|
-
|
|
255
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
130
256
|
simulatePublic: true,
|
|
131
257
|
skipFeeEnforcement,
|
|
132
258
|
skipTxValidation,
|
|
133
259
|
overrides,
|
|
134
|
-
scopes
|
|
260
|
+
scopes,
|
|
261
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
|
|
135
262
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
139
|
-
const originalAddress = originalAccount.getCompleteAddress();
|
|
140
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
141
|
-
if (!contractInstance) {
|
|
142
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
143
|
-
}
|
|
144
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
145
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
146
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
147
|
-
salt: Fr.random()
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
account: stubAccount,
|
|
151
|
-
instance,
|
|
152
|
-
artifact: stubArtifact
|
|
153
|
-
};
|
|
263
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
264
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
154
265
|
}
|
|
155
266
|
async createAccountInternal(type, secret, salt, signingKey) {
|
|
156
267
|
let contract;
|
|
268
|
+
let immutablesHash;
|
|
269
|
+
let publicKey;
|
|
157
270
|
switch(type){
|
|
158
271
|
case 'schnorr':
|
|
159
272
|
{
|
|
160
273
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
161
274
|
break;
|
|
162
275
|
}
|
|
276
|
+
case 'schnorr_initializerless':
|
|
277
|
+
{
|
|
278
|
+
contract = await this.accountContracts.getSchnorrInitializerlessAccountContract(Fq.fromBuffer(signingKey));
|
|
279
|
+
publicKey = await new Schnorr().computePublicKey(Fq.fromBuffer(signingKey));
|
|
280
|
+
immutablesHash = await poseidon2Hash([
|
|
281
|
+
publicKey.x,
|
|
282
|
+
publicKey.y
|
|
283
|
+
]);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
163
286
|
case 'ecdsasecp256k1':
|
|
164
287
|
{
|
|
165
288
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
@@ -175,12 +298,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
175
298
|
throw new Error(`Unknown account type ${type}`);
|
|
176
299
|
}
|
|
177
300
|
}
|
|
178
|
-
const accountManager = await AccountManager.create(this, secret, contract,
|
|
301
|
+
const accountManager = await AccountManager.create(this, secret, contract, {
|
|
302
|
+
salt,
|
|
303
|
+
immutablesHash
|
|
304
|
+
});
|
|
179
305
|
const instance = accountManager.getInstance();
|
|
180
306
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
181
307
|
if (!existingInstance) {
|
|
182
308
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
309
|
+
const artifact = existingArtifact ?? await accountManager.getAccountContract().getContractArtifact();
|
|
183
310
|
await this.registerContract(instance, !existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined, accountManager.getSecretKey());
|
|
311
|
+
if (type === 'schnorr_initializerless') {
|
|
312
|
+
const constructor = artifact.functions.find((f)=>f.name === 'constructor');
|
|
313
|
+
if (!constructor) {
|
|
314
|
+
throw new Error('Could not create SchnorrInitializerlessAccountContract: constructor ABI not found');
|
|
315
|
+
}
|
|
316
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructor, [
|
|
317
|
+
publicKey.x,
|
|
318
|
+
publicKey.y
|
|
319
|
+
]);
|
|
320
|
+
await storeCall.simulate({
|
|
321
|
+
from: instance.address
|
|
322
|
+
});
|
|
323
|
+
}
|
|
184
324
|
}
|
|
185
325
|
return accountManager;
|
|
186
326
|
}
|
|
@@ -199,6 +339,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
199
339
|
const sk = signingKey ?? deriveSigningKey(secret);
|
|
200
340
|
return this.createAndStoreAccount(alias ?? '', 'schnorr', secret, salt, sk.toBuffer());
|
|
201
341
|
}
|
|
342
|
+
createSchnorrInitializerlessAccount(secret, salt, signingKey, alias) {
|
|
343
|
+
const sk = signingKey ?? deriveSigningKey(secret);
|
|
344
|
+
return this.createAndStoreAccount(alias ?? '', 'schnorr_initializerless', secret, salt, sk.toBuffer());
|
|
345
|
+
}
|
|
202
346
|
createECDSARAccount(secret, salt, signingKey, alias) {
|
|
203
347
|
return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
|
|
204
348
|
}
|
|
@@ -211,7 +355,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
211
355
|
setEstimatedGasPadding(value) {
|
|
212
356
|
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
213
357
|
}
|
|
214
|
-
stop() {
|
|
215
|
-
|
|
358
|
+
async stop() {
|
|
359
|
+
await this.pxe.stop();
|
|
360
|
+
await this.walletDB.close();
|
|
216
361
|
}
|
|
217
362
|
}
|
|
@@ -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"}
|
|
@@ -1,41 +1,64 @@
|
|
|
1
1
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { createStore, openTmpStore } from '@aztec/kv-store/
|
|
3
|
+
import { createStore, openTmpStore } from '@aztec/kv-store/sqlite-opfs';
|
|
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,
|
|
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 };
|
|
@@ -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,
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JQUFJLGNBQWMsRUFBRSxDQUFDO0FBQ2hELFlBQVksRUFBRSxxQkFBcUIsRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzdGLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUMzQyxZQUFZLEVBQUUsV0FBVyxFQUFFLE1BQU0saUJBQWlCLENBQUMifQ==
|
|
@@ -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,
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUscUJBQXFCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUUxRixnRUFBZ0U7QUFDaEUsTUFBTSxNQUFNLGlCQUFpQixHQUFHLEtBQUssR0FBRyxRQUFRLENBQUM7QUFFakQ7OztHQUdHO0FBQ0gscUJBQWEsNkJBQThCLFNBQVEsS0FBSztJQUN0RCxRQUFRLENBQUMsU0FBUyxFQUFFLGlCQUFpQixDQUFDO0lBRXRDLFlBQVksU0FBUyxFQUFFLGl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