@aztec/wallet-sdk 0.0.1-commit.ec5f612 → 0.0.1-commit.ec7ac5448
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/base-wallet/base_wallet.d.ts +40 -39
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +123 -73
- package/dest/base-wallet/index.d.ts +2 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/utils.d.ts +3 -2
- package/dest/base-wallet/utils.d.ts.map +1 -1
- package/dest/base-wallet/utils.js +3 -1
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/provider/extension_wallet.d.ts +2 -5
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/index.d.ts +2 -2
- package/dest/extension/provider/index.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +118 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +228 -0
- package/dest/iframe/handlers/index.d.ts +2 -0
- package/dest/iframe/handlers/index.d.ts.map +1 -0
- package/dest/iframe/handlers/index.js +1 -0
- package/dest/iframe/provider/iframe_discovery.d.ts +25 -0
- package/dest/iframe/provider/iframe_discovery.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_discovery.js +167 -0
- package/dest/iframe/provider/iframe_provider.d.ts +65 -0
- package/dest/iframe/provider/iframe_provider.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_provider.js +257 -0
- package/dest/iframe/provider/iframe_wallet.d.ts +68 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +200 -0
- package/dest/iframe/provider/index.d.ts +4 -0
- package/dest/iframe/provider/index.d.ts.map +1 -0
- package/dest/iframe/provider/index.js +3 -0
- package/dest/manager/types.d.ts +3 -2
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +46 -16
- package/dest/types.d.ts +14 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +192 -128
- package/src/base-wallet/index.ts +6 -1
- package/src/base-wallet/utils.ts +6 -4
- package/src/crypto.ts +104 -0
- package/src/extension/provider/extension_wallet.ts +1 -6
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +328 -0
- package/src/iframe/handlers/index.ts +7 -0
- package/src/iframe/provider/iframe_discovery.ts +185 -0
- package/src/iframe/provider/iframe_provider.ts +331 -0
- package/src/iframe/provider/iframe_wallet.ts +229 -0
- package/src/iframe/provider/index.ts +3 -0
- package/src/manager/types.ts +2 -1
- package/src/manager/wallet_manager.ts +48 -14
- package/src/types.ts +13 -0
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import type { Account } from '@aztec/aztec.js/account';
|
|
1
|
+
import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
3
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type InteractionWaitOptions,
|
|
6
|
+
NO_WAIT,
|
|
7
|
+
type SendReturn,
|
|
8
|
+
extractOffchainOutput,
|
|
9
|
+
} from '@aztec/aztec.js/contracts';
|
|
4
10
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
5
11
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
6
|
-
import type {
|
|
7
|
-
Aliased,
|
|
8
|
-
AppCapabilities,
|
|
9
|
-
BatchResults,
|
|
10
|
-
BatchedMethod,
|
|
11
|
-
ExecuteUtilityOptions,
|
|
12
|
-
PrivateEvent,
|
|
13
|
-
PrivateEventFilter,
|
|
14
|
-
ProfileOptions,
|
|
15
|
-
SendOptions,
|
|
16
|
-
SimulateOptions,
|
|
17
|
-
Wallet,
|
|
18
|
-
WalletCapabilities,
|
|
19
|
-
} from '@aztec/aztec.js/wallet';
|
|
20
12
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
type Aliased,
|
|
14
|
+
type AppCapabilities,
|
|
15
|
+
type BatchResults,
|
|
16
|
+
type BatchedMethod,
|
|
17
|
+
ContractInitializationStatus,
|
|
18
|
+
type ExecuteUtilityOptions,
|
|
19
|
+
type PrivateEvent,
|
|
20
|
+
type PrivateEventFilter,
|
|
21
|
+
type ProfileOptions,
|
|
22
|
+
type SendOptions,
|
|
23
|
+
type SimulateOptions,
|
|
24
|
+
TxSimulationResultWithAppOffset,
|
|
25
|
+
type Wallet,
|
|
26
|
+
type WalletCapabilities,
|
|
27
|
+
} from '@aztec/aztec.js/wallet';
|
|
26
28
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
29
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
27
30
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
28
31
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
29
32
|
import { createLogger } from '@aztec/foundation/log';
|
|
30
33
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
31
|
-
import {
|
|
34
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
32
35
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
33
36
|
import {
|
|
34
37
|
type ContractArtifact,
|
|
@@ -44,14 +47,16 @@ import {
|
|
|
44
47
|
getContractClassFromArtifact,
|
|
45
48
|
} from '@aztec/stdlib/contract';
|
|
46
49
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
47
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
48
|
-
import {
|
|
50
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
51
|
+
import {
|
|
52
|
+
computeSiloedPrivateInitializationNullifier,
|
|
53
|
+
computeSiloedPublicInitializationNullifier,
|
|
54
|
+
} from '@aztec/stdlib/hash';
|
|
49
55
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
50
56
|
import {
|
|
51
57
|
BlockHeader,
|
|
52
58
|
type TxExecutionRequest,
|
|
53
59
|
type TxProfileResult,
|
|
54
|
-
TxSimulationResult,
|
|
55
60
|
type UtilityExecutionResult,
|
|
56
61
|
} from '@aztec/stdlib/tx';
|
|
57
62
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
@@ -70,11 +75,32 @@ export type FeeOptions = {
|
|
|
70
75
|
*/
|
|
71
76
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
72
77
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
73
|
-
accountFeePaymentMethodOptions
|
|
78
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
74
79
|
/** The gas settings to use for the transaction */
|
|
75
80
|
gasSettings: GasSettings;
|
|
76
81
|
};
|
|
77
82
|
|
|
83
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
84
|
+
export type SimulateViaEntrypointOptions = Pick<
|
|
85
|
+
SimulateOptions,
|
|
86
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
87
|
+
> & {
|
|
88
|
+
/** Fee options for the entrypoint */
|
|
89
|
+
feeOptions: FeeOptions;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Options for `completeFeeOptions`. */
|
|
93
|
+
export type CompleteFeeOptionsConfig = {
|
|
94
|
+
/** The address where the transaction is being sent from. */
|
|
95
|
+
from: AztecAddress | NoFrom;
|
|
96
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
97
|
+
feePayer?: AztecAddress;
|
|
98
|
+
/** User-provided partial gas settings. */
|
|
99
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
100
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
101
|
+
forEstimation?: boolean;
|
|
102
|
+
};
|
|
103
|
+
|
|
78
104
|
/**
|
|
79
105
|
* A base class for Wallet implementations
|
|
80
106
|
*/
|
|
@@ -89,8 +115,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
89
115
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
90
116
|
) {}
|
|
91
117
|
|
|
92
|
-
protected scopesFrom(from: AztecAddress, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
93
|
-
const allScopes = from
|
|
118
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
119
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
94
120
|
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
95
121
|
return [...scopeSet].map(AztecAddress.fromString);
|
|
96
122
|
}
|
|
@@ -118,26 +144,33 @@ export abstract class BaseWallet implements Wallet {
|
|
|
118
144
|
|
|
119
145
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
120
146
|
executionPayload: ExecutionPayload,
|
|
121
|
-
from: AztecAddress,
|
|
147
|
+
from: AztecAddress | NoFrom,
|
|
122
148
|
feeOptions: FeeOptions,
|
|
123
149
|
): Promise<TxExecutionRequest> {
|
|
124
150
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
125
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
126
|
-
txNonce: Fr.random(),
|
|
127
|
-
cancellable: this.cancellableTransactions,
|
|
128
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
129
|
-
};
|
|
130
151
|
const finalExecutionPayload = feeExecutionPayload
|
|
131
152
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
132
153
|
: executionPayload;
|
|
133
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
134
154
|
const chainInfo = await this.getChainInfo();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
chainInfo
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
|
|
156
|
+
if (from === NO_FROM) {
|
|
157
|
+
const entrypoint = new DefaultEntrypoint();
|
|
158
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
159
|
+
} else {
|
|
160
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
161
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
162
|
+
txNonce: Fr.random(),
|
|
163
|
+
cancellable: this.cancellableTransactions,
|
|
164
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
165
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
166
|
+
};
|
|
167
|
+
return fromAccount.createTxExecutionRequest(
|
|
168
|
+
finalExecutionPayload,
|
|
169
|
+
feeOptions.gasSettings,
|
|
170
|
+
chainInfo,
|
|
171
|
+
executionOptions,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
141
174
|
}
|
|
142
175
|
|
|
143
176
|
public async createAuthWit(
|
|
@@ -186,31 +219,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
186
219
|
|
|
187
220
|
/**
|
|
188
221
|
* Completes partial user-provided fee options with wallet defaults.
|
|
189
|
-
* @param
|
|
190
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
191
|
-
* @param gasSettings - User-provided partial gas settings
|
|
192
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
222
|
+
* @param config - Fee completion config.
|
|
193
223
|
*/
|
|
194
|
-
protected async completeFeeOptions(
|
|
195
|
-
from
|
|
196
|
-
feePayer?: AztecAddress,
|
|
197
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
198
|
-
): Promise<FeeOptions> {
|
|
224
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
225
|
+
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
199
226
|
const maxFeesPerGas =
|
|
200
227
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
201
228
|
let accountFeePaymentMethodOptions;
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
229
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
230
|
+
// account contract entrypoint to use
|
|
231
|
+
if (from !== NO_FROM) {
|
|
232
|
+
if (!feePayer) {
|
|
233
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
234
|
+
// for the account to use its fee juice balance
|
|
235
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
236
|
+
} else {
|
|
237
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
238
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
239
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
240
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
241
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
242
|
+
}
|
|
212
243
|
}
|
|
213
|
-
const
|
|
244
|
+
const gasSettingsOverrides = {
|
|
245
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
246
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
247
|
+
maxFeesPerGas,
|
|
248
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
249
|
+
};
|
|
250
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
251
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
252
|
+
const fullGasSettings = forEstimation
|
|
253
|
+
? GasSettings.forEstimation(gasSettingsOverrides)
|
|
254
|
+
: GasSettings.fallback(gasSettingsOverrides);
|
|
214
255
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
215
256
|
return {
|
|
216
257
|
gasSettings: fullGasSettings,
|
|
@@ -219,37 +260,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
219
260
|
};
|
|
220
261
|
}
|
|
221
262
|
|
|
222
|
-
/**
|
|
223
|
-
* Completes partial user-provided fee options with unreasonably high gas limits
|
|
224
|
-
* for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
|
|
225
|
-
* to avoid running out of gas during estimation.
|
|
226
|
-
* @param from - The address where the transaction is being sent from
|
|
227
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
228
|
-
* @param gasSettings - User-provided partial gas settings
|
|
229
|
-
*/
|
|
230
|
-
protected async completeFeeOptionsForEstimation(
|
|
231
|
-
from: AztecAddress,
|
|
232
|
-
feePayer?: AztecAddress,
|
|
233
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
234
|
-
) {
|
|
235
|
-
const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
|
|
236
|
-
const {
|
|
237
|
-
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
238
|
-
} = defaultFeeOptions;
|
|
239
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
240
|
-
// They will be tuned down after the simulation.
|
|
241
|
-
const gasSettingsForEstimation = new GasSettings(
|
|
242
|
-
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
243
|
-
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
244
|
-
maxFeesPerGas,
|
|
245
|
-
maxPriorityFeesPerGas,
|
|
246
|
-
);
|
|
247
|
-
return {
|
|
248
|
-
...defaultFeeOptions,
|
|
249
|
-
gasSettings: gasSettingsForEstimation,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
263
|
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
254
264
|
return this.pxe.registerSender(address);
|
|
255
265
|
}
|
|
@@ -295,22 +305,36 @@ export abstract class BaseWallet implements Wallet {
|
|
|
295
305
|
/**
|
|
296
306
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
297
307
|
* @param executionPayload - The execution payload to simulate.
|
|
298
|
-
* @param
|
|
299
|
-
* @param feeOptions - Fee options for the transaction.
|
|
300
|
-
* @param skipTxValidation - Whether to skip tx validation.
|
|
301
|
-
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
302
|
-
* @param scopes - The scopes to use for the simulation.
|
|
308
|
+
* @param opts - Simulation options.
|
|
303
309
|
*/
|
|
304
|
-
protected async simulateViaEntrypoint(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
310
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
311
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
312
|
+
executionPayload,
|
|
313
|
+
opts.from,
|
|
314
|
+
opts.feeOptions,
|
|
315
|
+
);
|
|
316
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
317
|
+
simulatePublic: true,
|
|
318
|
+
skipTxValidation: opts.skipTxValidation,
|
|
319
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
320
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
321
|
+
});
|
|
322
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
323
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
328
|
+
* calls, N+1 = app).
|
|
329
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
330
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
331
|
+
*/
|
|
332
|
+
protected async computeAppCallOffset(from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<number> {
|
|
333
|
+
if (from === NO_FROM) {
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
337
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
314
338
|
}
|
|
315
339
|
|
|
316
340
|
/**
|
|
@@ -321,10 +345,16 @@ export abstract class BaseWallet implements Wallet {
|
|
|
321
345
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
322
346
|
* @returns The merged simulation result.
|
|
323
347
|
*/
|
|
324
|
-
async simulateTx(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
348
|
+
async simulateTx(
|
|
349
|
+
executionPayload: ExecutionPayload,
|
|
350
|
+
opts: SimulateOptions,
|
|
351
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
352
|
+
const feeOptions = await this.completeFeeOptions({
|
|
353
|
+
from: opts.from,
|
|
354
|
+
feePayer: executionPayload.feePayer,
|
|
355
|
+
gasSettings: opts.fee?.gasSettings,
|
|
356
|
+
forEstimation: true,
|
|
357
|
+
});
|
|
328
358
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
329
359
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
330
360
|
|
|
@@ -338,12 +368,13 @@ export abstract class BaseWallet implements Wallet {
|
|
|
338
368
|
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
339
369
|
}
|
|
340
370
|
|
|
371
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
341
372
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
342
373
|
optimizableCalls.length > 0
|
|
343
374
|
? simulateViaNode(
|
|
344
375
|
this.aztecNode,
|
|
345
376
|
optimizableCalls,
|
|
346
|
-
|
|
377
|
+
simulationOrigin,
|
|
347
378
|
chainInfo,
|
|
348
379
|
feeOptions.gasSettings,
|
|
349
380
|
blockHeader,
|
|
@@ -352,14 +383,13 @@ export abstract class BaseWallet implements Wallet {
|
|
|
352
383
|
)
|
|
353
384
|
: Promise.resolve([]),
|
|
354
385
|
remainingCalls.length > 0
|
|
355
|
-
? this.simulateViaEntrypoint(
|
|
356
|
-
|
|
357
|
-
opts.from,
|
|
386
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
387
|
+
from: opts.from,
|
|
358
388
|
feeOptions,
|
|
359
|
-
|
|
360
|
-
opts.skipTxValidation,
|
|
361
|
-
opts.skipFeeEnforcement ?? true,
|
|
362
|
-
)
|
|
389
|
+
additionalScopes: opts.additionalScopes,
|
|
390
|
+
skipTxValidation: opts.skipTxValidation,
|
|
391
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
392
|
+
})
|
|
363
393
|
: Promise.resolve(null),
|
|
364
394
|
]);
|
|
365
395
|
|
|
@@ -367,7 +397,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
367
397
|
}
|
|
368
398
|
|
|
369
399
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
370
|
-
const feeOptions = await this.completeFeeOptions(
|
|
400
|
+
const feeOptions = await this.completeFeeOptions({
|
|
401
|
+
from: opts.from,
|
|
402
|
+
feePayer: executionPayload.feePayer,
|
|
403
|
+
gasSettings: opts.fee?.gasSettings,
|
|
404
|
+
});
|
|
371
405
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
372
406
|
return this.pxe.profileTx(txRequest, {
|
|
373
407
|
profileMode: opts.profileMode,
|
|
@@ -380,9 +414,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
380
414
|
executionPayload: ExecutionPayload,
|
|
381
415
|
opts: SendOptions<W>,
|
|
382
416
|
): Promise<SendReturn<W>> {
|
|
383
|
-
const feeOptions = await this.completeFeeOptions(
|
|
417
|
+
const feeOptions = await this.completeFeeOptions({
|
|
418
|
+
from: opts.from,
|
|
419
|
+
feePayer: executionPayload.feePayer,
|
|
420
|
+
gasSettings: opts.fee?.gasSettings,
|
|
421
|
+
});
|
|
384
422
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
385
423
|
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
424
|
+
const offchainOutput = extractOffchainOutput(
|
|
425
|
+
provenTx.getOffchainEffects(),
|
|
426
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
427
|
+
);
|
|
386
428
|
const tx = await provenTx.toTx();
|
|
387
429
|
const txHash = tx.getTxHash();
|
|
388
430
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -396,7 +438,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
396
438
|
|
|
397
439
|
// If wait is NO_WAIT, return txHash immediately
|
|
398
440
|
if (opts.wait === NO_WAIT) {
|
|
399
|
-
return txHash as SendReturn<W>;
|
|
441
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
400
442
|
}
|
|
401
443
|
|
|
402
444
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
@@ -408,7 +450,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
408
450
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
409
451
|
}
|
|
410
452
|
|
|
411
|
-
return receipt as SendReturn<W>;
|
|
453
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
412
454
|
}
|
|
413
455
|
|
|
414
456
|
/**
|
|
@@ -439,7 +481,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
439
481
|
}
|
|
440
482
|
|
|
441
483
|
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
442
|
-
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes:
|
|
484
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
443
485
|
}
|
|
444
486
|
|
|
445
487
|
async getPrivateEvents<T>(
|
|
@@ -462,17 +504,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
462
504
|
return decodedEvents;
|
|
463
505
|
}
|
|
464
506
|
|
|
507
|
+
/**
|
|
508
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
509
|
+
* @param address - The contract address to query.
|
|
510
|
+
*/
|
|
465
511
|
async getContractMetadata(address: AztecAddress) {
|
|
466
512
|
const instance = await this.pxe.getContractInstance(address);
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
513
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
514
|
+
|
|
515
|
+
let initializationStatus: ContractInitializationStatus;
|
|
516
|
+
if (instance) {
|
|
517
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
518
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
519
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
520
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
521
|
+
initializationStatus = witness
|
|
522
|
+
? ContractInitializationStatus.INITIALIZED
|
|
523
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
524
|
+
} else {
|
|
525
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
526
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
527
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
528
|
+
// uninitialized.
|
|
529
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
530
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
531
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
532
|
+
}
|
|
533
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
470
534
|
const isContractUpdated =
|
|
471
535
|
publiclyRegisteredContract &&
|
|
472
536
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
473
537
|
return {
|
|
474
538
|
instance: instance ?? undefined,
|
|
475
|
-
|
|
539
|
+
initializationStatus,
|
|
476
540
|
isContractPublished: !!publiclyRegisteredContract,
|
|
477
541
|
isContractUpdated: !!isContractUpdated,
|
|
478
542
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
BaseWallet,
|
|
3
|
+
type CompleteFeeOptionsConfig,
|
|
4
|
+
type FeeOptions,
|
|
5
|
+
type SimulateViaEntrypointOptions,
|
|
6
|
+
} from './base_wallet.js';
|
|
2
7
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
package/src/base-wallet/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
2
3
|
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
3
4
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
4
5
|
import { makeTuple } from '@aztec/foundation/array';
|
|
@@ -214,13 +215,13 @@ export async function simulateViaNode(
|
|
|
214
215
|
*/
|
|
215
216
|
export function buildMergedSimulationResult(
|
|
216
217
|
optimizedResults: TxSimulationResult[],
|
|
217
|
-
normalResult:
|
|
218
|
-
):
|
|
218
|
+
normalResult: TxSimulationResultWithAppOffset | null,
|
|
219
|
+
): TxSimulationResultWithAppOffset {
|
|
219
220
|
const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
|
|
220
221
|
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
221
222
|
const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
|
|
222
223
|
|
|
223
|
-
const baseResult = normalResult ?? optimizedResults[0];
|
|
224
|
+
const baseResult: TxSimulationResult = normalResult ?? optimizedResults[0];
|
|
224
225
|
|
|
225
226
|
const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
|
|
226
227
|
? {
|
|
@@ -229,10 +230,11 @@ export function buildMergedSimulationResult(
|
|
|
229
230
|
}
|
|
230
231
|
: undefined;
|
|
231
232
|
|
|
232
|
-
|
|
233
|
+
const merged = new TxSimulationResult(
|
|
233
234
|
baseResult.privateExecutionResult,
|
|
234
235
|
baseResult.publicInputs,
|
|
235
236
|
mergedPublicOutput,
|
|
236
237
|
normalResult?.stats,
|
|
237
238
|
);
|
|
239
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(merged, normalResult?.appCallOffset ?? 0);
|
|
238
240
|
}
|
package/src/crypto.ts
CHANGED
|
@@ -497,3 +497,107 @@ export function hashToEmoji(hash: string, count: number = DEFAULT_EMOJI_GRID_SIZ
|
|
|
497
497
|
}
|
|
498
498
|
return emojis.join('');
|
|
499
499
|
}
|
|
500
|
+
|
|
501
|
+
// ─── Passphrase-based encryption (PBKDF2 + AES-256-GCM) ───────────────────
|
|
502
|
+
|
|
503
|
+
/** Default PBKDF2 iteration count. High to compensate for short PINs (~1-2s on modern hardware). */
|
|
504
|
+
const DEFAULT_PBKDF2_ITERATIONS = 2_000_000;
|
|
505
|
+
const PBKDF2_SALT_BYTES = 16;
|
|
506
|
+
const PBKDF2_IV_BYTES = 12;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Derives an AES-256-GCM key from a passphrase using PBKDF2-SHA256.
|
|
510
|
+
*
|
|
511
|
+
* @param passphrase - The user-provided passphrase or PIN
|
|
512
|
+
* @param salt - Random salt bytes
|
|
513
|
+
* @param iterations - PBKDF2 iteration count (default: 2,000,000)
|
|
514
|
+
* @returns An AES-256-GCM CryptoKey
|
|
515
|
+
*/
|
|
516
|
+
export async function deriveKeyFromPassphrase(
|
|
517
|
+
passphrase: string,
|
|
518
|
+
salt: Uint8Array,
|
|
519
|
+
iterations: number = DEFAULT_PBKDF2_ITERATIONS,
|
|
520
|
+
): Promise<CryptoKey> {
|
|
521
|
+
const keyMaterial = await crypto.subtle.importKey('raw', new TextEncoder().encode(passphrase), 'PBKDF2', false, [
|
|
522
|
+
'deriveKey',
|
|
523
|
+
]);
|
|
524
|
+
return crypto.subtle.deriveKey(
|
|
525
|
+
{ name: 'PBKDF2', salt: salt as BufferSource, iterations, hash: 'SHA-256' },
|
|
526
|
+
keyMaterial,
|
|
527
|
+
{ name: 'AES-GCM', length: 256 },
|
|
528
|
+
false,
|
|
529
|
+
['encrypt', 'decrypt'],
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Encrypts arbitrary bytes with a passphrase using PBKDF2 + AES-256-GCM.
|
|
535
|
+
*
|
|
536
|
+
* Output layout: `[salt (16)] [iv (12)] [ciphertext (...)]`
|
|
537
|
+
*
|
|
538
|
+
* @param plaintext - Data to encrypt
|
|
539
|
+
* @param passphrase - User passphrase or PIN
|
|
540
|
+
* @param iterations - PBKDF2 iteration count (default: 2,000,000)
|
|
541
|
+
* @returns A Uint8Array containing salt + iv + ciphertext
|
|
542
|
+
*/
|
|
543
|
+
export async function encryptWithPassphrase(
|
|
544
|
+
plaintext: Uint8Array,
|
|
545
|
+
passphrase: string,
|
|
546
|
+
iterations: number = DEFAULT_PBKDF2_ITERATIONS,
|
|
547
|
+
): Promise<Uint8Array> {
|
|
548
|
+
const salt = crypto.getRandomValues(new Uint8Array(PBKDF2_SALT_BYTES));
|
|
549
|
+
const iv = crypto.getRandomValues(new Uint8Array(PBKDF2_IV_BYTES));
|
|
550
|
+
const key = await deriveKeyFromPassphrase(passphrase, salt, iterations);
|
|
551
|
+
const ciphertext = new Uint8Array(
|
|
552
|
+
await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, plaintext as BufferSource),
|
|
553
|
+
);
|
|
554
|
+
const result = new Uint8Array(PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES + ciphertext.length);
|
|
555
|
+
result.set(salt, 0);
|
|
556
|
+
result.set(iv, PBKDF2_SALT_BYTES);
|
|
557
|
+
result.set(ciphertext, PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Decrypts data produced by {@link encryptWithPassphrase}.
|
|
563
|
+
*
|
|
564
|
+
* @param data - The encrypted blob (salt + iv + ciphertext)
|
|
565
|
+
* @param passphrase - The passphrase used during encryption
|
|
566
|
+
* @param iterations - PBKDF2 iteration count (must match encryption)
|
|
567
|
+
* @returns The decrypted plaintext bytes
|
|
568
|
+
* @throws On wrong passphrase (AES-GCM auth tag mismatch)
|
|
569
|
+
*/
|
|
570
|
+
export async function decryptWithPassphrase(
|
|
571
|
+
data: Uint8Array,
|
|
572
|
+
passphrase: string,
|
|
573
|
+
iterations: number = DEFAULT_PBKDF2_ITERATIONS,
|
|
574
|
+
): Promise<Uint8Array> {
|
|
575
|
+
const salt = data.slice(0, PBKDF2_SALT_BYTES);
|
|
576
|
+
const iv = data.slice(PBKDF2_SALT_BYTES, PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
|
|
577
|
+
const ciphertext = data.slice(PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
|
|
578
|
+
const key = await deriveKeyFromPassphrase(passphrase, salt, iterations);
|
|
579
|
+
return new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext as BufferSource));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Converts a Uint8Array to a base64 string.
|
|
584
|
+
*/
|
|
585
|
+
export function uint8ToBase64(bytes: Uint8Array): string {
|
|
586
|
+
let binary = '';
|
|
587
|
+
for (const b of bytes) {
|
|
588
|
+
binary += String.fromCharCode(b);
|
|
589
|
+
}
|
|
590
|
+
return btoa(binary);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Converts a base64 string to a Uint8Array.
|
|
595
|
+
*/
|
|
596
|
+
export function base64ToUint8(b64: string): Uint8Array {
|
|
597
|
+
const binary = atob(b64);
|
|
598
|
+
const bytes = new Uint8Array(binary.length);
|
|
599
|
+
for (let i = 0; i < binary.length; i++) {
|
|
600
|
+
bytes[i] = binary.charCodeAt(i);
|
|
601
|
+
}
|
|
602
|
+
return bytes;
|
|
603
|
+
}
|
|
@@ -6,7 +6,7 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
6
6
|
import type { FunctionsOf } from '@aztec/foundation/types';
|
|
7
7
|
|
|
8
8
|
import { type EncryptedPayload, decrypt, encrypt } from '../../crypto.js';
|
|
9
|
-
import { type WalletMessage, WalletMessageType, type WalletResponse } from '../../types.js';
|
|
9
|
+
import { type DisconnectCallback, type WalletMessage, WalletMessageType, type WalletResponse } from '../../types.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Internal type representing a wallet method call before encryption.
|
|
@@ -19,11 +19,6 @@ type WalletMethodCall = {
|
|
|
19
19
|
args: unknown[];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Callback type for wallet disconnect events.
|
|
24
|
-
*/
|
|
25
|
-
export type DisconnectCallback = () => void;
|
|
26
|
-
|
|
27
22
|
/**
|
|
28
23
|
* A wallet implementation that communicates with browser extension wallets
|
|
29
24
|
* using an encrypted MessageChannel.
|