@aztec/wallets 0.0.1-commit.4d79d1f2d → 0.0.1-commit.4d9804df
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 +5 -3
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +12 -6
- package/dest/embedded/account-contract-providers/lazy.d.ts +5 -3
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +20 -6
- package/dest/embedded/account-contract-providers/types.d.ts +5 -3
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +66 -8
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +266 -61
- package/dest/embedded/entrypoints/browser.d.ts +8 -3
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +57 -20
- package/dest/embedded/entrypoints/node.d.ts +7 -11
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +49 -18
- 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 +21 -9
- package/src/embedded/account-contract-providers/bundle.ts +14 -6
- package/src/embedded/account-contract-providers/lazy.ts +22 -6
- package/src/embedded/account-contract-providers/types.ts +5 -2
- package/src/embedded/embedded_wallet.ts +345 -70
- package/src/embedded/entrypoints/browser.ts +67 -25
- package/src/embedded/entrypoints/node.ts +60 -40
- package/src/embedded/store_encryption.ts +146 -0
- package/src/embedded/wallet_db.ts +18 -12
- package/src/testing.ts +11 -16
- package/dest/embedded/embedded_wallet_browser.d.ts +0 -5
- package/dest/embedded/embedded_wallet_browser.d.ts.map +0 -1
- package/dest/embedded/embedded_wallet_browser.js +0 -31
- package/src/embedded/embedded_wallet_browser.ts +0 -40
|
@@ -1,21 +1,48 @@
|
|
|
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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
+
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
10
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
11
|
+
import { SimulationOverrides, TxStatus, collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
12
|
+
import { BaseWallet, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
|
|
13
|
+
/** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */ export function splitPxeOptions(pxe) {
|
|
14
|
+
if (!pxe) {
|
|
15
|
+
return {
|
|
16
|
+
config: {},
|
|
17
|
+
creation: {}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } = pxe;
|
|
21
|
+
return {
|
|
22
|
+
config,
|
|
23
|
+
creation: {
|
|
24
|
+
loggers,
|
|
25
|
+
loggerActorLabel,
|
|
26
|
+
proverOrOptions,
|
|
27
|
+
store,
|
|
28
|
+
simulator,
|
|
29
|
+
hooks,
|
|
30
|
+
preloadedContractsProvider
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
9
35
|
export class EmbeddedWallet extends BaseWallet {
|
|
10
36
|
walletDB;
|
|
11
37
|
accountContracts;
|
|
38
|
+
estimatedGasPadding;
|
|
39
|
+
// Stub class ids, populated on wallet startup
|
|
40
|
+
// to avoid redundant work per simulation
|
|
41
|
+
stubClassIds;
|
|
12
42
|
constructor(pxe, aztecNode, walletDB, accountContracts, log){
|
|
13
|
-
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts;
|
|
43
|
+
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING, this.stubClassIds = new Map();
|
|
14
44
|
}
|
|
15
45
|
async getAccountFromAddress(address) {
|
|
16
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
17
|
-
return new SignerlessAccount();
|
|
18
|
-
}
|
|
19
46
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
20
47
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
21
48
|
const account = await accountManager.getAccount();
|
|
@@ -29,80 +56,232 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
29
56
|
}
|
|
30
57
|
async registerSender(address, alias) {
|
|
31
58
|
await this.walletDB.storeSender(address, alias);
|
|
32
|
-
|
|
59
|
+
await this.pxe.registerTaggingSecretSource({
|
|
60
|
+
kind: 'address-derived',
|
|
61
|
+
sender: address
|
|
62
|
+
});
|
|
63
|
+
return address;
|
|
33
64
|
}
|
|
34
65
|
async getAddressBook() {
|
|
35
|
-
const
|
|
66
|
+
const sources = await this.pxe.getTaggingSecretSources({
|
|
67
|
+
kind: 'address-derived'
|
|
68
|
+
});
|
|
69
|
+
const senders = sources.map((source)=>source.sender);
|
|
36
70
|
const storedSenders = await this.walletDB.listSenders();
|
|
37
71
|
for (const storedSender of storedSenders){
|
|
38
72
|
if (senders.findIndex((sender)=>sender.equals(storedSender.item)) === -1) {
|
|
39
|
-
await this.pxe.
|
|
73
|
+
await this.pxe.registerTaggingSecretSource({
|
|
74
|
+
kind: 'address-derived',
|
|
75
|
+
sender: storedSender.item
|
|
76
|
+
});
|
|
40
77
|
}
|
|
41
78
|
}
|
|
42
79
|
return storedSenders;
|
|
43
80
|
}
|
|
44
81
|
/**
|
|
82
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
83
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
84
|
+
* the necessary authwitnesses.
|
|
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();
|
|
89
|
+
const feeOptions = await this.completeFeeOptions({
|
|
90
|
+
from: opts.from,
|
|
91
|
+
feePayer: executionPayload.feePayer,
|
|
92
|
+
gasSettings: opts.fee?.gasSettings,
|
|
93
|
+
forEstimation: true
|
|
94
|
+
});
|
|
95
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
96
|
+
// private authwitnesses based on offchain effects.
|
|
97
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
98
|
+
from: opts.from,
|
|
99
|
+
feeOptions,
|
|
100
|
+
additionalScopes: opts.additionalScopes,
|
|
101
|
+
skipTxValidation: true,
|
|
102
|
+
sendMessagesAs: opts.sendMessagesAs
|
|
103
|
+
});
|
|
104
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
105
|
+
const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
|
|
106
|
+
try {
|
|
107
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
108
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
109
|
+
consumer: effect.contractAddress,
|
|
110
|
+
innerHash: authRequest.innerHash
|
|
111
|
+
});
|
|
112
|
+
} catch {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
for (const authwit of authWitnesses){
|
|
117
|
+
if (authwit) {
|
|
118
|
+
executionPayload.authWitnesses.push(authwit);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
122
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
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}`);
|
|
124
|
+
const gasSettings = GasSettings.from({
|
|
125
|
+
...opts.fee?.gasSettings,
|
|
126
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
127
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
128
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
129
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
|
|
130
|
+
});
|
|
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
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return super.sendTx(executionPayload, {
|
|
147
|
+
...opts,
|
|
148
|
+
wait: wait,
|
|
149
|
+
fee: {
|
|
150
|
+
...opts.fee,
|
|
151
|
+
gasSettings
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
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
|
+
/**
|
|
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.
|
|
194
|
+
*/ async buildAccountOverrides(addresses) {
|
|
195
|
+
const accounts = await this.getAccounts();
|
|
196
|
+
const contracts = {};
|
|
197
|
+
const filtered = accounts.filter((acc)=>addresses.some((addr)=>addr.equals(acc.item)));
|
|
198
|
+
for (const account of filtered){
|
|
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
|
+
}
|
|
205
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
206
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
207
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
208
|
+
if (!contractInstance) {
|
|
209
|
+
throw new Error(`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`);
|
|
210
|
+
}
|
|
211
|
+
contracts[address.toString()] = {
|
|
212
|
+
instance: {
|
|
213
|
+
...contractInstance,
|
|
214
|
+
currentContractClassId: stubClassId
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return contracts;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
45
221
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
46
222
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
47
223
|
* private kernel circuit execution.
|
|
48
|
-
*/ async simulateViaEntrypoint(executionPayload,
|
|
49
|
-
const {
|
|
224
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
225
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
226
|
+
const scopes = this.scopesFrom(from, additionalScopes ?? [], sendMessagesAs);
|
|
50
227
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
51
|
-
const executionOptions = {
|
|
52
|
-
txNonce: Fr.random(),
|
|
53
|
-
cancellable: this.cancellableTransactions,
|
|
54
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
55
|
-
};
|
|
56
228
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
57
229
|
feeExecutionPayload,
|
|
58
230
|
executionPayload
|
|
59
231
|
]) : executionPayload;
|
|
60
232
|
const chainInfo = await this.getChainInfo();
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
skipFeeEnforcement: true,
|
|
65
|
-
skipTxValidation: true,
|
|
66
|
-
overrides: {
|
|
67
|
-
contracts: {
|
|
68
|
-
[from.toString()]: {
|
|
69
|
-
instance,
|
|
70
|
-
artifact
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
scopes
|
|
233
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
234
|
+
const overrides = new SimulationOverrides({
|
|
235
|
+
contracts: accountOverrides
|
|
75
236
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
237
|
+
let txRequest;
|
|
238
|
+
if (from === NO_FROM) {
|
|
239
|
+
const entrypoint = new DefaultEntrypoint();
|
|
240
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
241
|
+
} else {
|
|
242
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
243
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
244
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
245
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
246
|
+
const executionOptions = {
|
|
247
|
+
txNonce: Fr.random(),
|
|
248
|
+
cancellable: this.cancellableTransactions,
|
|
249
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
250
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
251
|
+
};
|
|
252
|
+
txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
86
253
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
254
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
255
|
+
simulatePublic: true,
|
|
256
|
+
skipFeeEnforcement,
|
|
257
|
+
skipTxValidation,
|
|
258
|
+
overrides,
|
|
259
|
+
scopes,
|
|
260
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
|
|
91
261
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
instance,
|
|
95
|
-
artifact: stubArtifact
|
|
96
|
-
};
|
|
262
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
263
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
97
264
|
}
|
|
98
265
|
async createAccountInternal(type, secret, salt, signingKey) {
|
|
99
266
|
let contract;
|
|
267
|
+
let immutablesHash;
|
|
268
|
+
let publicKey;
|
|
100
269
|
switch(type){
|
|
101
270
|
case 'schnorr':
|
|
102
271
|
{
|
|
103
272
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
104
273
|
break;
|
|
105
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
|
+
}
|
|
106
285
|
case 'ecdsasecp256k1':
|
|
107
286
|
{
|
|
108
287
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
@@ -118,10 +297,30 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
118
297
|
throw new Error(`Unknown account type ${type}`);
|
|
119
298
|
}
|
|
120
299
|
}
|
|
121
|
-
const accountManager = await AccountManager.create(this, secret, contract,
|
|
300
|
+
const accountManager = await AccountManager.create(this, secret, contract, {
|
|
301
|
+
salt,
|
|
302
|
+
immutablesHash
|
|
303
|
+
});
|
|
122
304
|
const instance = accountManager.getInstance();
|
|
123
|
-
const
|
|
124
|
-
|
|
305
|
+
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
306
|
+
if (!existingInstance) {
|
|
307
|
+
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
308
|
+
const artifact = existingArtifact ?? await accountManager.getAccountContract().getContractArtifact();
|
|
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
|
+
}
|
|
323
|
+
}
|
|
125
324
|
return accountManager;
|
|
126
325
|
}
|
|
127
326
|
async createAndStoreAccount(alias, type, secret, salt, signingKey) {
|
|
@@ -136,8 +335,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
136
335
|
return accountManager;
|
|
137
336
|
}
|
|
138
337
|
createSchnorrAccount(secret, salt, signingKey, alias) {
|
|
139
|
-
|
|
140
|
-
|
|
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());
|
|
141
342
|
}
|
|
142
343
|
createECDSARAccount(secret, salt, signingKey, alias) {
|
|
143
344
|
return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
|
|
@@ -148,7 +349,11 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
148
349
|
setMinFeePadding(value) {
|
|
149
350
|
this.minFeePadding = value ?? 0.5;
|
|
150
351
|
}
|
|
151
|
-
|
|
152
|
-
|
|
352
|
+
setEstimatedGasPadding(value) {
|
|
353
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
354
|
+
}
|
|
355
|
+
async stop() {
|
|
356
|
+
await this.pxe.stop();
|
|
357
|
+
await this.walletDB.close();
|
|
153
358
|
}
|
|
154
359
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { type AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { type PXE } from '@aztec/pxe/client/lazy';
|
|
4
|
+
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
1
5
|
import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
6
|
+
import { WalletDB } from '../wallet_db.js';
|
|
2
7
|
export declare class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
3
|
-
static create(
|
|
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>;
|
|
4
9
|
}
|
|
5
10
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
6
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
11
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
7
12
|
export { WalletDB } from '../wallet_db.js';
|
|
8
13
|
export type { AccountType } from '../wallet_db.js';
|
|
9
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL2Jyb3dzZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUF5QixNQUFNLHNCQUFzQixDQUFDO0FBQzdFLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUVsRSxPQUFPLEVBQUUsS0FBSyxHQUFHLEVBQXdELE1BQU0sd0JBQXdCLENBQUM7QUFPeEcsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx3Q0FBd0MsQ0FBQztBQUN2RixPQUFPLEVBQUUsY0FBYyxFQUFFLEtBQUsscUJBQXFCLEVBQW1CLE1BQU0sdUJBQXVCLENBQUM7QUFDcEcsT0FBTyxFQUE4QixRQUFRLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUV2RSxxQkFBYSxxQkFBc0IsU0FBUSxjQUFjO0lBQ3ZELE9BQWEsTUFBTSxDQUFDLENBQUMsU0FBUyxxQkFBcUIsR0FBRyxxQkFBcUIsRUFDekUsSUFBSSxFQUFFLEtBQ0osR0FBRyxFQUFFLEdBQUcsRUFDUixTQUFTLEVBQUUsU0FBUyxFQUNwQixRQUFRLEVBQUUsUUFBUSxFQUNsQixnQkFBZ0IsRUFBRSx3QkFBd0IsRUFDMUMsR0FBRyxDQUFDLEVBQUUsTUFBTSxLQUNULENBQUMsRUFDTixTQUFTLEVBQUUsTUFBTSxHQUFHLFNBQVMsRUFDN0IsT0FBTyxHQUFFLHFCQUEwQixHQUNsQyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBNERaO0NBQ0Y7QUFFRCxPQUFPLEVBQUUscUJBQXFCLElBQUksY0FBYyxFQUFFLENBQUM7QUFDbkQsWUFBWSxFQUFFLHFCQUFxQixFQUFFLHdCQUF3QixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDN0YsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQzNDLFlBQVksRUFBRSxXQUFXLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/browser.ts"],"names":[],"mappings":"
|
|
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,34 +1,71 @@
|
|
|
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
|
-
import { EmbeddedWallet } from '../embedded_wallet.js';
|
|
8
|
-
import { WalletDB } from '../wallet_db.js';
|
|
10
|
+
import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
|
|
11
|
+
import { WALLET_DATA_SCHEMA_VERSION, WalletDB } from '../wallet_db.js';
|
|
9
12
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
10
|
-
static async create(
|
|
13
|
+
static async create(nodeOrUrl, options = {}) {
|
|
11
14
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
12
|
-
const aztecNode = createAztecNodeClient(
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
16
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
17
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
18
|
+
const mergedConfigOverrides = {
|
|
19
|
+
...options.pxeConfig,
|
|
20
|
+
...pxeConfigFromPxe
|
|
21
|
+
};
|
|
22
|
+
const mergedCreationOverrides = {
|
|
23
|
+
...options.pxeOptions,
|
|
24
|
+
...pxeCreationFromPxe
|
|
25
|
+
};
|
|
26
|
+
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
27
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
28
|
+
// Unused in the browser: sqlite-opfs keys stores by name, not directory.
|
|
29
|
+
dataDirectory: 'pxe_data',
|
|
30
|
+
autoSync: false,
|
|
31
|
+
...mergedConfigOverrides
|
|
32
|
+
});
|
|
33
|
+
if (options.ephemeral) {
|
|
34
|
+
delete pxeConfig.dataDirectory;
|
|
18
35
|
}
|
|
19
|
-
const
|
|
36
|
+
const pxeOptions = {
|
|
37
|
+
...mergedCreationOverrides,
|
|
38
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
39
|
+
getPreloadedContracts: async ()=>[
|
|
40
|
+
await getStandardMultiCallEntrypoint(),
|
|
41
|
+
await getStandardAuthRegistry(),
|
|
42
|
+
await getStandardHandshakeRegistry()
|
|
43
|
+
]
|
|
44
|
+
},
|
|
20
45
|
loggers: {
|
|
21
46
|
store: rootLogger.createChild('pxe:data'),
|
|
22
47
|
pxe: rootLogger.createChild('pxe:service'),
|
|
23
|
-
prover: rootLogger.createChild('pxe:prover')
|
|
48
|
+
prover: rootLogger.createChild('pxe:prover'),
|
|
49
|
+
...mergedCreationOverrides.loggers
|
|
24
50
|
}
|
|
25
|
-
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
};
|
|
52
|
+
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
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;
|
|
32
69
|
}
|
|
33
70
|
}
|
|
34
71
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type
|
|
1
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { type PXE } from '@aztec/pxe/server';
|
|
3
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
4
5
|
import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
5
|
-
|
|
6
|
-
/** Override PXE configuration. */
|
|
7
|
-
pxeConfig?: Partial<PXEConfig>;
|
|
8
|
-
/** Advanced PXE creation options (custom store, prover, simulator). */
|
|
9
|
-
pxeOptions?: PXECreationOptions;
|
|
10
|
-
};
|
|
6
|
+
import { WalletDB } from '../wallet_db.js';
|
|
11
7
|
export declare class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
12
|
-
static create(nodeOrUrl: string | AztecNode, options?:
|
|
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>;
|
|
13
9
|
}
|
|
14
10
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
15
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
11
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
16
12
|
export { WalletDB } from '../wallet_db.js';
|
|
17
13
|
export type { AccountType } from '../wallet_db.js';
|
|
18
|
-
//# 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":"
|
|
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"}
|