@aztec/wallets 0.0.1-commit.d1da697d6 → 0.0.1-commit.d58ff9d0
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 +12 -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 +32 -6
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +146 -41
- package/dest/embedded/entrypoints/browser.d.ts +1 -1
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +33 -13
- package/dest/embedded/entrypoints/node.d.ts +1 -1
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +36 -13
- package/dest/embedded/store_encryption.d.ts +74 -0
- package/dest/embedded/store_encryption.d.ts.map +1 -0
- package/dest/embedded/store_encryption.js +93 -0
- package/dest/embedded/wallet_db.d.ts +9 -6
- package/dest/embedded/wallet_db.d.ts.map +1 -1
- package/dest/embedded/wallet_db.js +13 -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 +15 -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 +175 -45
- package/src/embedded/entrypoints/browser.ts +32 -17
- package/src/embedded/entrypoints/node.ts +37 -21
- package/src/embedded/store_encryption.ts +146 -0
- package/src/embedded/wallet_db.ts +18 -12
- package/src/testing.ts +11 -17
|
@@ -1,14 +1,15 @@
|
|
|
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
|
-
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
10
11
|
import { SimulationOverrides, TxStatus, collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
11
|
-
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
12
|
+
import { BaseWallet, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
|
|
12
13
|
/** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */ export function splitPxeOptions(pxe) {
|
|
13
14
|
if (!pxe) {
|
|
14
15
|
return {
|
|
@@ -16,7 +17,7 @@ import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
|
16
17
|
creation: {}
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
|
-
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, ...config } = pxe;
|
|
20
|
+
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } = pxe;
|
|
20
21
|
return {
|
|
21
22
|
config,
|
|
22
23
|
creation: {
|
|
@@ -24,7 +25,9 @@ import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
|
24
25
|
loggerActorLabel,
|
|
25
26
|
proverOrOptions,
|
|
26
27
|
store,
|
|
27
|
-
simulator
|
|
28
|
+
simulator,
|
|
29
|
+
hooks,
|
|
30
|
+
preloadedContractsProvider
|
|
28
31
|
}
|
|
29
32
|
};
|
|
30
33
|
}
|
|
@@ -33,8 +36,11 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
33
36
|
walletDB;
|
|
34
37
|
accountContracts;
|
|
35
38
|
estimatedGasPadding;
|
|
39
|
+
// Stub class ids, populated on wallet startup
|
|
40
|
+
// to avoid redundant work per simulation
|
|
41
|
+
stubClassIds;
|
|
36
42
|
constructor(pxe, aztecNode, walletDB, accountContracts, log){
|
|
37
|
-
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
43
|
+
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING, this.stubClassIds = new Map();
|
|
38
44
|
}
|
|
39
45
|
async getAccountFromAddress(address) {
|
|
40
46
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
@@ -50,14 +56,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
50
56
|
}
|
|
51
57
|
async registerSender(address, alias) {
|
|
52
58
|
await this.walletDB.storeSender(address, alias);
|
|
53
|
-
|
|
59
|
+
await this.pxe.registerTaggingSecretSource({
|
|
60
|
+
kind: 'address-derived',
|
|
61
|
+
sender: address
|
|
62
|
+
});
|
|
63
|
+
return address;
|
|
54
64
|
}
|
|
55
65
|
async getAddressBook() {
|
|
56
|
-
const
|
|
66
|
+
const sources = await this.pxe.getTaggingSecretSources({
|
|
67
|
+
kind: 'address-derived'
|
|
68
|
+
});
|
|
69
|
+
const senders = sources.map((source)=>source.sender);
|
|
57
70
|
const storedSenders = await this.walletDB.listSenders();
|
|
58
71
|
for (const storedSender of storedSenders){
|
|
59
72
|
if (senders.findIndex((sender)=>sender.equals(storedSender.item)) === -1) {
|
|
60
|
-
await this.pxe.
|
|
73
|
+
await this.pxe.registerTaggingSecretSource({
|
|
74
|
+
kind: 'address-derived',
|
|
75
|
+
sender: storedSender.item
|
|
76
|
+
});
|
|
61
77
|
}
|
|
62
78
|
}
|
|
63
79
|
return storedSenders;
|
|
@@ -67,6 +83,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
67
83
|
* estimates actual gas usage and captures call authorization requests to generate
|
|
68
84
|
* the necessary authwitnesses.
|
|
69
85
|
*/ async sendTx(executionPayload, opts) {
|
|
86
|
+
// PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
|
|
87
|
+
// both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
|
|
88
|
+
await this.pxe.sync();
|
|
70
89
|
const feeOptions = await this.completeFeeOptions({
|
|
71
90
|
from: opts.from,
|
|
72
91
|
feePayer: executionPayload.feePayer,
|
|
@@ -78,8 +97,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
78
97
|
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
79
98
|
from: opts.from,
|
|
80
99
|
feeOptions,
|
|
81
|
-
|
|
82
|
-
skipTxValidation: true
|
|
100
|
+
additionalScopes: opts.additionalScopes,
|
|
101
|
+
skipTxValidation: true,
|
|
102
|
+
sendMessagesAs: opts.sendMessagesAs
|
|
83
103
|
});
|
|
84
104
|
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
85
105
|
const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
|
|
@@ -98,7 +118,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
98
118
|
executionPayload.authWitnesses.push(authwit);
|
|
99
119
|
}
|
|
100
120
|
}
|
|
101
|
-
const
|
|
121
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
122
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
102
123
|
this.log.verbose(`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`);
|
|
103
124
|
const gasSettings = GasSettings.from({
|
|
104
125
|
...opts.fee?.gasSettings,
|
|
@@ -107,19 +128,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
107
128
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
108
129
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
|
|
109
130
|
});
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
let wait = opts.wait;
|
|
132
|
+
if (wait !== NO_WAIT) {
|
|
133
|
+
const callerWaitOpts = typeof wait === 'object' ? wait : {};
|
|
134
|
+
wait = {
|
|
135
|
+
...callerWaitOpts,
|
|
136
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
137
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
138
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
139
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
140
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
141
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
142
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
143
|
+
waitForStatus: callerWaitOpts.waitForStatus ?? TxStatus.PROPOSED
|
|
144
|
+
};
|
|
120
145
|
}
|
|
121
146
|
return super.sendTx(executionPayload, {
|
|
122
147
|
...opts,
|
|
148
|
+
wait: wait,
|
|
123
149
|
fee: {
|
|
124
150
|
...opts.fee,
|
|
125
151
|
gasSettings
|
|
@@ -127,26 +153,66 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
127
153
|
});
|
|
128
154
|
}
|
|
129
155
|
/**
|
|
156
|
+
* Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
|
|
157
|
+
* wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
|
|
158
|
+
* standalone simulations we still need a fresh anchor block, which we provide here.
|
|
159
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
160
|
+
await this.pxe.sync();
|
|
161
|
+
return super.simulateTx(executionPayload, opts);
|
|
162
|
+
}
|
|
163
|
+
async profileTx(executionPayload, opts) {
|
|
164
|
+
await this.pxe.sync();
|
|
165
|
+
return super.profileTx(executionPayload, opts);
|
|
166
|
+
}
|
|
167
|
+
async executeUtility(call, opts) {
|
|
168
|
+
await this.pxe.sync();
|
|
169
|
+
return super.executeUtility(call, opts);
|
|
170
|
+
}
|
|
171
|
+
async getPrivateEvents(eventDef, eventFilter) {
|
|
172
|
+
await this.pxe.sync();
|
|
173
|
+
return super.getPrivateEvents(eventDef, eventFilter);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
177
|
+
* stubClassIds. Called on wallet initialization.
|
|
178
|
+
*/ async initStubClasses() {
|
|
179
|
+
const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
|
|
180
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
|
|
181
|
+
await this.pxe.registerContractClass(schnorrArtifact);
|
|
182
|
+
// ecdsa stubs share the same class id
|
|
183
|
+
const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
|
|
184
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
|
|
185
|
+
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
186
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
187
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
188
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
189
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
130
192
|
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
193
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
131
194
|
*/ async buildAccountOverrides(addresses) {
|
|
132
195
|
const accounts = await this.getAccounts();
|
|
133
196
|
const contracts = {};
|
|
134
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
135
197
|
const filtered = accounts.filter((acc)=>addresses.some((addr)=>addr.equals(acc.item)));
|
|
136
198
|
for (const account of filtered){
|
|
137
199
|
const address = account.item;
|
|
200
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
201
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
202
|
+
if (!stubClassId) {
|
|
203
|
+
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.`);
|
|
204
|
+
}
|
|
138
205
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
139
206
|
const completeAddress = originalAccount.getCompleteAddress();
|
|
140
207
|
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
141
208
|
if (!contractInstance) {
|
|
142
209
|
throw new Error(`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`);
|
|
143
210
|
}
|
|
144
|
-
const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
145
|
-
salt: Fr.random()
|
|
146
|
-
});
|
|
147
211
|
contracts[address.toString()] = {
|
|
148
|
-
instance:
|
|
149
|
-
|
|
212
|
+
instance: {
|
|
213
|
+
...contractInstance,
|
|
214
|
+
currentContractClassId: stubClassId
|
|
215
|
+
}
|
|
150
216
|
};
|
|
151
217
|
}
|
|
152
218
|
return contracts;
|
|
@@ -156,23 +222,27 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
156
222
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
157
223
|
* private kernel circuit execution.
|
|
158
224
|
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
159
|
-
const { from, feeOptions,
|
|
225
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
226
|
+
const scopes = this.scopesFrom(from, additionalScopes ?? [], sendMessagesAs);
|
|
160
227
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
161
228
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
162
229
|
feeExecutionPayload,
|
|
163
230
|
executionPayload
|
|
164
231
|
]) : executionPayload;
|
|
165
232
|
const chainInfo = await this.getChainInfo();
|
|
166
|
-
const accountOverrides = await this.buildAccountOverrides(
|
|
167
|
-
const overrides = new SimulationOverrides(
|
|
233
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
234
|
+
const overrides = new SimulationOverrides({
|
|
235
|
+
contracts: accountOverrides
|
|
236
|
+
});
|
|
168
237
|
let txRequest;
|
|
169
238
|
if (from === NO_FROM) {
|
|
170
239
|
const entrypoint = new DefaultEntrypoint();
|
|
171
240
|
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
172
241
|
} else {
|
|
242
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
173
243
|
const originalAccount = await this.getAccountFromAddress(from);
|
|
174
244
|
const completeAddress = originalAccount.getCompleteAddress();
|
|
175
|
-
const account = await this.accountContracts.createStubAccount(completeAddress);
|
|
245
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
176
246
|
const executionOptions = {
|
|
177
247
|
txNonce: Fr.random(),
|
|
178
248
|
cancellable: this.cancellableTransactions,
|
|
@@ -181,22 +251,37 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
181
251
|
};
|
|
182
252
|
txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
183
253
|
}
|
|
184
|
-
|
|
254
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
185
255
|
simulatePublic: true,
|
|
186
256
|
skipFeeEnforcement,
|
|
187
257
|
skipTxValidation,
|
|
188
258
|
overrides,
|
|
189
|
-
scopes
|
|
259
|
+
scopes,
|
|
260
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
|
|
190
261
|
});
|
|
262
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
263
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
191
264
|
}
|
|
192
265
|
async createAccountInternal(type, secret, salt, signingKey) {
|
|
193
266
|
let contract;
|
|
267
|
+
let immutablesHash;
|
|
268
|
+
let publicKey;
|
|
194
269
|
switch(type){
|
|
195
270
|
case 'schnorr':
|
|
196
271
|
{
|
|
197
272
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
198
273
|
break;
|
|
199
274
|
}
|
|
275
|
+
case 'schnorr_initializerless':
|
|
276
|
+
{
|
|
277
|
+
contract = await this.accountContracts.getSchnorrInitializerlessAccountContract(Fq.fromBuffer(signingKey));
|
|
278
|
+
publicKey = await new Schnorr().computePublicKey(Fq.fromBuffer(signingKey));
|
|
279
|
+
immutablesHash = await poseidon2Hash([
|
|
280
|
+
publicKey.x,
|
|
281
|
+
publicKey.y
|
|
282
|
+
]);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
200
285
|
case 'ecdsasecp256k1':
|
|
201
286
|
{
|
|
202
287
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
@@ -212,12 +297,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
212
297
|
throw new Error(`Unknown account type ${type}`);
|
|
213
298
|
}
|
|
214
299
|
}
|
|
215
|
-
const accountManager = await AccountManager.create(this, secret, contract,
|
|
300
|
+
const accountManager = await AccountManager.create(this, secret, contract, {
|
|
301
|
+
salt,
|
|
302
|
+
immutablesHash
|
|
303
|
+
});
|
|
216
304
|
const instance = accountManager.getInstance();
|
|
217
305
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
218
306
|
if (!existingInstance) {
|
|
219
307
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
308
|
+
const artifact = existingArtifact ?? await accountManager.getAccountContract().getContractArtifact();
|
|
220
309
|
await this.registerContract(instance, !existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined, accountManager.getSecretKey());
|
|
310
|
+
if (type === 'schnorr_initializerless') {
|
|
311
|
+
const constructor = artifact.functions.find((f)=>f.name === 'constructor');
|
|
312
|
+
if (!constructor) {
|
|
313
|
+
throw new Error('Could not create SchnorrInitializerlessAccountContract: constructor ABI not found');
|
|
314
|
+
}
|
|
315
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructor, [
|
|
316
|
+
publicKey.x,
|
|
317
|
+
publicKey.y
|
|
318
|
+
]);
|
|
319
|
+
await storeCall.simulate({
|
|
320
|
+
from: instance.address
|
|
321
|
+
});
|
|
322
|
+
}
|
|
221
323
|
}
|
|
222
324
|
return accountManager;
|
|
223
325
|
}
|
|
@@ -233,8 +335,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
233
335
|
return accountManager;
|
|
234
336
|
}
|
|
235
337
|
createSchnorrAccount(secret, salt, signingKey, alias) {
|
|
236
|
-
|
|
237
|
-
|
|
338
|
+
return this.createAndStoreAccount(alias ?? '', 'schnorr', secret, salt, signingKey.toBuffer());
|
|
339
|
+
}
|
|
340
|
+
createSchnorrInitializerlessAccount(secret, salt, signingKey, alias) {
|
|
341
|
+
return this.createAndStoreAccount(alias ?? '', 'schnorr_initializerless', secret, salt, signingKey.toBuffer());
|
|
238
342
|
}
|
|
239
343
|
createECDSARAccount(secret, salt, signingKey, alias) {
|
|
240
344
|
return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
|
|
@@ -248,7 +352,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
248
352
|
setEstimatedGasPadding(value) {
|
|
249
353
|
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
250
354
|
}
|
|
251
|
-
stop() {
|
|
252
|
-
|
|
355
|
+
async stop() {
|
|
356
|
+
await this.pxe.stop();
|
|
357
|
+
await this.walletDB.close();
|
|
253
358
|
}
|
|
254
359
|
}
|
|
@@ -11,4 +11,4 @@ export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
|
11
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL2Jyb3dzZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUF5QixNQUFNLHNCQUFzQixDQUFDO0FBQzdFLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUVsRSxPQUFPLEVBQUUsS0FBSyxHQUFHLEVBQXdELE1BQU0sd0JBQXdCLENBQUM7QUFPeEcsT0FBTyx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ElE,OAAO,EAAE,KAAK,GAAG,
|
|
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,EAAwD,MAAM,wBAAwB,CAAC;AAOxG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAA8B,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEvE,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,16 +1,18 @@
|
|
|
1
1
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
4
|
-
import { createPXE } from '@aztec/pxe/client/lazy';
|
|
3
|
+
import { openTmpStore } from '@aztec/kv-store/sqlite-opfs';
|
|
4
|
+
import { createPXE, openBrowserStore } 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
10
|
import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
|
|
8
|
-
import { WalletDB } from '../wallet_db.js';
|
|
11
|
+
import { WALLET_DATA_SCHEMA_VERSION, 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
|
-
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
14
16
|
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
15
17
|
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
16
18
|
const mergedConfigOverrides = {
|
|
@@ -22,8 +24,10 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
22
24
|
...pxeCreationFromPxe
|
|
23
25
|
};
|
|
24
26
|
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
25
|
-
proverEnabled: mergedConfigOverrides.proverEnabled
|
|
26
|
-
|
|
27
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
28
|
+
// Unused in the browser: sqlite-opfs keys stores by name, not directory.
|
|
29
|
+
dataDirectory: 'pxe_data',
|
|
30
|
+
autoSync: false,
|
|
27
31
|
...mergedConfigOverrides
|
|
28
32
|
});
|
|
29
33
|
if (options.ephemeral) {
|
|
@@ -31,6 +35,13 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
31
35
|
}
|
|
32
36
|
const pxeOptions = {
|
|
33
37
|
...mergedCreationOverrides,
|
|
38
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
39
|
+
getPreloadedContracts: async ()=>[
|
|
40
|
+
await getStandardMultiCallEntrypoint(),
|
|
41
|
+
await getStandardAuthRegistry(),
|
|
42
|
+
await getStandardHandshakeRegistry()
|
|
43
|
+
]
|
|
44
|
+
},
|
|
34
45
|
loggers: {
|
|
35
46
|
store: rootLogger.createChild('pxe:data'),
|
|
36
47
|
pxe: rootLogger.createChild('pxe:service'),
|
|
@@ -39,13 +50,22 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
39
50
|
}
|
|
40
51
|
};
|
|
41
52
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
let walletDBStore = options.walletDb?.store;
|
|
54
|
+
if (!walletDBStore) {
|
|
55
|
+
if (options.ephemeral) {
|
|
56
|
+
walletDBStore = await openTmpStore(true);
|
|
57
|
+
} else {
|
|
58
|
+
const { l1ChainId, l1ContractAddresses } = await aztecNode.getNodeInfo();
|
|
59
|
+
walletDBStore = await openBrowserStore('wallet_data', WALLET_DATA_SCHEMA_VERSION, {
|
|
60
|
+
l1ChainId,
|
|
61
|
+
rollupAddress: l1ContractAddresses.rollupAddress
|
|
62
|
+
}, rootLogger.createChild('wallet:data'));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
66
|
+
const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger);
|
|
67
|
+
await wallet.initStubClasses();
|
|
68
|
+
return wallet;
|
|
49
69
|
}
|
|
50
70
|
}
|
|
51
71
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
@@ -11,4 +11,4 @@ export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
|
11
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL25vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBR2xFLE9BQU8sRUFBRSxLQUFLLEdBQUcsRUFBaUQsTUFBTSxtQkFBbUIsQ0FBQztBQUk1RixPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUdqRSxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHdDQUF3QyxDQUFDO0FBQ3ZGLE9BQU8sRUFBRSxjQUFjLEVBQUUsS0FBSyxxQkFBcUIsRUFBbUIsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRyxPQUFPLEVBQThCLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBSXZFLHFCQUFhLGtCQUFtQixTQUFRLGNBQWM7SUFDcEQsT0FBYSxNQUFNLENBQUMsQ0FBQyxTQUFTLGtCQUFrQixHQUFHLGtCQUFrQixFQUNuRSxJQUFJLEVBQUUsS0FDSixHQUFHLEVBQUUsR0FBRyxFQUNSLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFFBQVEsRUFBRSxRQUFRLEVBQ2xCLGdCQUFnQixFQUFFLHdCQUF3QixFQUMxQyxHQUFHLENBQUMsRUFBRSxNQUFNLEtBQ1QsQ0FBQyxFQUNOLFNBQVMsRUFBRSxNQUFNLEdBQUcsU0FBUyxFQUM3QixPQUFPLEdBQUUscUJBQTBCLEdBQ2xDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FpRVo7Q0FDRjtBQUVELE9BQU8sRUFBRSxrQkFBa0IsSUFBSSxjQUFjLEVBQUUsQ0FBQztBQUNoRCxZQUFZLEVBQUUscUJBQXFCLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUM3RixPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFDM0MsWUFBWSxFQUFFLFdBQVcsRUFBRSxNQUFNLGlCQUFpQixDQUFDIn0=
|
|
@@ -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,
|
|
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,EAAiD,MAAM,mBAAmB,CAAC;AAI5F,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,EAA8B,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIvE,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,CAiEZ;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"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
3
|
+
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
4
4
|
import { getPXEConfig } from '@aztec/pxe/config';
|
|
5
|
-
import { createPXE } from '@aztec/pxe/server';
|
|
5
|
+
import { createPXE, openStore } 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
10
|
import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
|
|
8
|
-
import { WalletDB } from '../wallet_db.js';
|
|
11
|
+
import { WALLET_DATA_SCHEMA_VERSION, WalletDB } from '../wallet_db.js';
|
|
12
|
+
const DEFAULT_WALLET_DATA_DIRECTORY = 'aztec-wallet-data';
|
|
9
13
|
export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
10
14
|
static async create(nodeOrUrl, options = {}) {
|
|
11
15
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
12
16
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
13
|
-
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
14
17
|
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
15
18
|
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
16
19
|
const mergedConfigOverrides = {
|
|
@@ -22,8 +25,9 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
22
25
|
...pxeCreationFromPxe
|
|
23
26
|
};
|
|
24
27
|
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
25
|
-
proverEnabled: mergedConfigOverrides.proverEnabled
|
|
26
|
-
dataDirectory:
|
|
28
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
29
|
+
dataDirectory: DEFAULT_WALLET_DATA_DIRECTORY,
|
|
30
|
+
autoSync: false,
|
|
27
31
|
...mergedConfigOverrides
|
|
28
32
|
});
|
|
29
33
|
if (options.ephemeral) {
|
|
@@ -31,6 +35,13 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
31
35
|
}
|
|
32
36
|
const pxeOptions = {
|
|
33
37
|
...mergedCreationOverrides,
|
|
38
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
39
|
+
getPreloadedContracts: async ()=>[
|
|
40
|
+
await getStandardMultiCallEntrypoint(),
|
|
41
|
+
await getStandardAuthRegistry(),
|
|
42
|
+
await getStandardHandshakeRegistry()
|
|
43
|
+
]
|
|
44
|
+
},
|
|
34
45
|
loggers: {
|
|
35
46
|
store: rootLogger.createChild('pxe:data'),
|
|
36
47
|
pxe: rootLogger.createChild('pxe:service'),
|
|
@@ -39,13 +50,25 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
39
50
|
}
|
|
40
51
|
};
|
|
41
52
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
let walletDBStore = options.walletDb?.store;
|
|
54
|
+
if (!walletDBStore) {
|
|
55
|
+
const bindings = rootLogger.createChild('wallet:data').getBindings();
|
|
56
|
+
if (options.ephemeral) {
|
|
57
|
+
walletDBStore = await openTmpStore('wallet_data', true, undefined, undefined, bindings);
|
|
58
|
+
} else {
|
|
59
|
+
const { l1ChainId, l1ContractAddresses } = await aztecNode.getNodeInfo();
|
|
60
|
+
walletDBStore = await openStore('wallet_data', WALLET_DATA_SCHEMA_VERSION, {
|
|
61
|
+
dataDirectory: pxeConfig.dataDirectory ?? DEFAULT_WALLET_DATA_DIRECTORY,
|
|
62
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
63
|
+
l1ChainId,
|
|
64
|
+
rollupAddress: l1ContractAddresses.rollupAddress
|
|
65
|
+
}, bindings);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
69
|
+
const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
|
|
70
|
+
await wallet.initStubClasses();
|
|
71
|
+
return wallet;
|
|
49
72
|
}
|
|
50
73
|
}
|
|
51
74
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
* Internal seam for tests to inject a fake store wiper. Defaults to removing the store's OPFS pool directory
|
|
44
|
+
* outright. Not part of the public API.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export type WipeSqliteStoreFn = (poolDirectory: string | undefined) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
|
|
51
|
+
*
|
|
52
|
+
* The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
|
|
53
|
+
* the key buffer to its worker. A single buffer would detach between the two opens.
|
|
54
|
+
*
|
|
55
|
+
* Failure modes:
|
|
56
|
+
*
|
|
57
|
+
* - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
|
|
58
|
+
* needed (nothing was opened).
|
|
59
|
+
* - Wallet store fails to decrypt → closes the already-opened PXE store then throws
|
|
60
|
+
* `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
|
|
61
|
+
* - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
|
|
62
|
+
* (preserves callers' existing untyped error handling for non-encryption faults).
|
|
63
|
+
*
|
|
64
|
+
* @param config - Per-store name/poolDirectory.
|
|
65
|
+
* @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
|
|
66
|
+
* detaches on transfer, so each call must allocate).
|
|
67
|
+
* @param log - Logger for both stores.
|
|
68
|
+
* @param openStore - Internal test seam. Do not pass in production code.
|
|
69
|
+
*/
|
|
70
|
+
export declare function openEncryptedEmbeddedStores(config: OpenEncryptedEmbeddedStoresOptions, getEncryptionKey: () => Promise<Uint8Array>, log: Logger, openStore?: OpenSqliteEncryptedStoreFn, wipeStore?: WipeSqliteStoreFn): Promise<{
|
|
71
|
+
pxeStore: AztecSQLiteOPFSStore;
|
|
72
|
+
walletStore: AztecSQLiteOPFSStore;
|
|
73
|
+
}>;
|
|
74
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQ0wsb0JBQW9CLEVBRXBCLHFCQUFxQixFQUV0QixNQUFNLDZCQUE2QixDQUFDO0FBRXJDLGdFQUFnRTtBQUNoRSxNQUFNLE1BQU0saUJBQWlCLEdBQUcsS0FBSyxHQUFHLFFBQVEsQ0FBQztBQUVqRDs7O0dBR0c7QUFDSCxxQkFBYSw2QkFBOEIsU0FBUSxLQUFLO0lBQ3RELFFBQVEsQ0FBQyxTQUFTLEVBQUUsaUJBQWlCLENBQUM7SUFFdEMsWUFBWSxTQUFTLEVBQUUsaUJBQWlCLEVBQUUsSUFBSSxFQUFFO1FBQUUsS0FBSyxFQUFFLHFCQUFxQixDQUFBO0tBQUUsRUFJL0U7Q0FDRjtBQUVELDZEQUE2RDtBQUM3RCxNQUFNLFdBQVcsa0NBQWtDO0lBQ2pELEdBQUcsRUFBRTtRQUFFLElBQUksRUFBRSxNQUFNLENBQUM7UUFBQyxhQUFhLENBQUMsRUFBRSxNQUFNLENBQUE7S0FBRSxDQUFDO0lBQzlDLE1BQU0sRUFBRTtRQUFFLElBQUksRUFBRSxNQUFNLENBQUM7UUFBQyxhQUFhLENBQUMsRUFBRSxNQUF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