@aztec/wallet-sdk 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
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 +41 -39
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +137 -80
- 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 +7 -4
- 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 +4 -6
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +9 -2
- 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 +6 -5
- 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 +48 -18
- 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 +201 -132
- package/src/base-wallet/index.ts +6 -1
- package/src/base-wallet/utils.ts +9 -0
- package/src/crypto.ts +104 -0
- package/src/extension/provider/extension_wallet.ts +13 -10
- 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 +5 -4
- package/src/manager/wallet_manager.ts +55 -23
- package/src/types.ts +13 -0
|
@@ -1,33 +1,36 @@
|
|
|
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
|
-
PrivateEvent,
|
|
12
|
-
PrivateEventFilter,
|
|
13
|
-
ProfileOptions,
|
|
14
|
-
SendOptions,
|
|
15
|
-
SimulateOptions,
|
|
16
|
-
SimulateUtilityOptions,
|
|
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
|
+
type Wallet,
|
|
25
|
+
type WalletCapabilities,
|
|
26
|
+
} from '@aztec/aztec.js/wallet';
|
|
26
27
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
28
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
27
29
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
28
30
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
29
31
|
import { createLogger } from '@aztec/foundation/log';
|
|
30
32
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
33
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
31
34
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
32
35
|
import {
|
|
33
36
|
type ContractArtifact,
|
|
@@ -36,22 +39,25 @@ import {
|
|
|
36
39
|
decodeFromAbi,
|
|
37
40
|
} from '@aztec/stdlib/abi';
|
|
38
41
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
39
|
-
import
|
|
42
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
40
43
|
import {
|
|
41
44
|
type ContractInstanceWithAddress,
|
|
42
45
|
computePartialAddress,
|
|
43
46
|
getContractClassFromArtifact,
|
|
44
47
|
} from '@aztec/stdlib/contract';
|
|
45
48
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
46
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
47
|
-
import {
|
|
49
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
50
|
+
import {
|
|
51
|
+
computeSiloedPrivateInitializationNullifier,
|
|
52
|
+
computeSiloedPublicInitializationNullifier,
|
|
53
|
+
} from '@aztec/stdlib/hash';
|
|
48
54
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
49
55
|
import {
|
|
50
56
|
BlockHeader,
|
|
51
57
|
type TxExecutionRequest,
|
|
52
58
|
type TxProfileResult,
|
|
53
59
|
TxSimulationResult,
|
|
54
|
-
type
|
|
60
|
+
type UtilityExecutionResult,
|
|
55
61
|
} from '@aztec/stdlib/tx';
|
|
56
62
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
57
63
|
|
|
@@ -69,11 +75,34 @@ export type FeeOptions = {
|
|
|
69
75
|
*/
|
|
70
76
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
71
77
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
72
|
-
accountFeePaymentMethodOptions
|
|
78
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
73
79
|
/** The gas settings to use for the transaction */
|
|
74
80
|
gasSettings: GasSettings;
|
|
75
81
|
};
|
|
76
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
|
+
/** Scopes to use for the simulation */
|
|
91
|
+
scopes: AztecAddress[];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Options for `completeFeeOptions`. */
|
|
95
|
+
export type CompleteFeeOptionsConfig = {
|
|
96
|
+
/** The address where the transaction is being sent from. */
|
|
97
|
+
from: AztecAddress | NoFrom;
|
|
98
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
99
|
+
feePayer?: AztecAddress;
|
|
100
|
+
/** User-provided partial gas settings. */
|
|
101
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
102
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
103
|
+
forEstimation?: boolean;
|
|
104
|
+
};
|
|
105
|
+
|
|
77
106
|
/**
|
|
78
107
|
* A base class for Wallet implementations
|
|
79
108
|
*/
|
|
@@ -88,10 +117,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
88
117
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
89
118
|
) {}
|
|
90
119
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
120
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
121
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
122
|
+
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
123
|
+
return [...scopeSet].map(AztecAddress.fromString);
|
|
95
124
|
}
|
|
96
125
|
|
|
97
126
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
@@ -117,26 +146,33 @@ export abstract class BaseWallet implements Wallet {
|
|
|
117
146
|
|
|
118
147
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
119
148
|
executionPayload: ExecutionPayload,
|
|
120
|
-
from: AztecAddress,
|
|
149
|
+
from: AztecAddress | NoFrom,
|
|
121
150
|
feeOptions: FeeOptions,
|
|
122
151
|
): Promise<TxExecutionRequest> {
|
|
123
152
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
124
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
125
|
-
txNonce: Fr.random(),
|
|
126
|
-
cancellable: this.cancellableTransactions,
|
|
127
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
128
|
-
};
|
|
129
153
|
const finalExecutionPayload = feeExecutionPayload
|
|
130
154
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
131
155
|
: executionPayload;
|
|
132
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
133
156
|
const chainInfo = await this.getChainInfo();
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
chainInfo
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
|
|
158
|
+
if (from === NO_FROM) {
|
|
159
|
+
const entrypoint = new DefaultEntrypoint();
|
|
160
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
161
|
+
} else {
|
|
162
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
163
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
164
|
+
txNonce: Fr.random(),
|
|
165
|
+
cancellable: this.cancellableTransactions,
|
|
166
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
167
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
168
|
+
};
|
|
169
|
+
return fromAccount.createTxExecutionRequest(
|
|
170
|
+
finalExecutionPayload,
|
|
171
|
+
feeOptions.gasSettings,
|
|
172
|
+
chainInfo,
|
|
173
|
+
executionOptions,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
140
176
|
}
|
|
141
177
|
|
|
142
178
|
public async createAuthWit(
|
|
@@ -185,31 +221,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
185
221
|
|
|
186
222
|
/**
|
|
187
223
|
* Completes partial user-provided fee options with wallet defaults.
|
|
188
|
-
* @param
|
|
189
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
190
|
-
* @param gasSettings - User-provided partial gas settings
|
|
191
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
224
|
+
* @param config - Fee completion config.
|
|
192
225
|
*/
|
|
193
|
-
protected async completeFeeOptions(
|
|
194
|
-
from
|
|
195
|
-
feePayer?: AztecAddress,
|
|
196
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
197
|
-
): Promise<FeeOptions> {
|
|
226
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
227
|
+
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
198
228
|
const maxFeesPerGas =
|
|
199
229
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
200
230
|
let accountFeePaymentMethodOptions;
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
231
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
232
|
+
// account contract entrypoint to use
|
|
233
|
+
if (from !== NO_FROM) {
|
|
234
|
+
if (!feePayer) {
|
|
235
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
236
|
+
// for the account to use its fee juice balance
|
|
237
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
238
|
+
} else {
|
|
239
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
240
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
241
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
242
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
243
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
244
|
+
}
|
|
211
245
|
}
|
|
212
|
-
const
|
|
246
|
+
const gasSettingsOverrides = {
|
|
247
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
248
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
249
|
+
maxFeesPerGas,
|
|
250
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
251
|
+
};
|
|
252
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
253
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
254
|
+
const fullGasSettings = forEstimation
|
|
255
|
+
? GasSettings.forEstimation(gasSettingsOverrides)
|
|
256
|
+
: GasSettings.fallback(gasSettingsOverrides);
|
|
213
257
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
214
258
|
return {
|
|
215
259
|
gasSettings: fullGasSettings,
|
|
@@ -218,37 +262,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
218
262
|
};
|
|
219
263
|
}
|
|
220
264
|
|
|
221
|
-
/**
|
|
222
|
-
* Completes partial user-provided fee options with unreasonably high gas limits
|
|
223
|
-
* for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
|
|
224
|
-
* to avoid running out of gas during estimation.
|
|
225
|
-
* @param from - The address where the transaction is being sent from
|
|
226
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
227
|
-
* @param gasSettings - User-provided partial gas settings
|
|
228
|
-
*/
|
|
229
|
-
protected async completeFeeOptionsForEstimation(
|
|
230
|
-
from: AztecAddress,
|
|
231
|
-
feePayer?: AztecAddress,
|
|
232
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
233
|
-
) {
|
|
234
|
-
const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
|
|
235
|
-
const {
|
|
236
|
-
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
237
|
-
} = defaultFeeOptions;
|
|
238
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
239
|
-
// They will be tuned down after the simulation.
|
|
240
|
-
const gasSettingsForEstimation = new GasSettings(
|
|
241
|
-
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
242
|
-
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
243
|
-
maxFeesPerGas,
|
|
244
|
-
maxPriorityFeesPerGas,
|
|
245
|
-
);
|
|
246
|
-
return {
|
|
247
|
-
...defaultFeeOptions,
|
|
248
|
-
gasSettings: gasSettingsForEstimation,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
265
|
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
253
266
|
return this.pxe.registerSender(address);
|
|
254
267
|
}
|
|
@@ -294,22 +307,20 @@ export abstract class BaseWallet implements Wallet {
|
|
|
294
307
|
/**
|
|
295
308
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
296
309
|
* @param executionPayload - The execution payload to simulate.
|
|
297
|
-
* @param
|
|
298
|
-
* @param feeOptions - Fee options for the transaction.
|
|
299
|
-
* @param skipTxValidation - Whether to skip tx validation.
|
|
300
|
-
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
301
|
-
* @param scopes - The scopes to use for the simulation.
|
|
310
|
+
* @param opts - Simulation options.
|
|
302
311
|
*/
|
|
303
|
-
protected async simulateViaEntrypoint(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
312
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
313
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
314
|
+
executionPayload,
|
|
315
|
+
opts.from,
|
|
316
|
+
opts.feeOptions,
|
|
317
|
+
);
|
|
318
|
+
return this.pxe.simulateTx(txRequest, {
|
|
319
|
+
simulatePublic: true,
|
|
320
|
+
skipTxValidation: opts.skipTxValidation,
|
|
321
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
322
|
+
scopes: opts.scopes,
|
|
323
|
+
});
|
|
313
324
|
}
|
|
314
325
|
|
|
315
326
|
/**
|
|
@@ -321,9 +332,12 @@ export abstract class BaseWallet implements Wallet {
|
|
|
321
332
|
* @returns The merged simulation result.
|
|
322
333
|
*/
|
|
323
334
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
324
|
-
const feeOptions =
|
|
325
|
-
|
|
326
|
-
:
|
|
335
|
+
const feeOptions = await this.completeFeeOptions({
|
|
336
|
+
from: opts.from,
|
|
337
|
+
feePayer: executionPayload.feePayer,
|
|
338
|
+
gasSettings: opts.fee?.gasSettings,
|
|
339
|
+
forEstimation: true,
|
|
340
|
+
});
|
|
327
341
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
328
342
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
329
343
|
|
|
@@ -337,27 +351,28 @@ export abstract class BaseWallet implements Wallet {
|
|
|
337
351
|
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
338
352
|
}
|
|
339
353
|
|
|
354
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
340
355
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
341
356
|
optimizableCalls.length > 0
|
|
342
357
|
? simulateViaNode(
|
|
343
358
|
this.aztecNode,
|
|
344
359
|
optimizableCalls,
|
|
345
|
-
|
|
360
|
+
simulationOrigin,
|
|
346
361
|
chainInfo,
|
|
347
362
|
feeOptions.gasSettings,
|
|
348
363
|
blockHeader,
|
|
349
364
|
opts.skipFeeEnforcement ?? true,
|
|
365
|
+
this.getContractName.bind(this),
|
|
350
366
|
)
|
|
351
367
|
: Promise.resolve([]),
|
|
352
368
|
remainingCalls.length > 0
|
|
353
|
-
? this.simulateViaEntrypoint(
|
|
354
|
-
|
|
355
|
-
opts.from,
|
|
369
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
370
|
+
from: opts.from,
|
|
356
371
|
feeOptions,
|
|
357
|
-
opts.
|
|
358
|
-
opts.
|
|
359
|
-
|
|
360
|
-
)
|
|
372
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
373
|
+
skipTxValidation: opts.skipTxValidation,
|
|
374
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
375
|
+
})
|
|
361
376
|
: Promise.resolve(null),
|
|
362
377
|
]);
|
|
363
378
|
|
|
@@ -365,12 +380,16 @@ export abstract class BaseWallet implements Wallet {
|
|
|
365
380
|
}
|
|
366
381
|
|
|
367
382
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
368
|
-
const feeOptions = await this.completeFeeOptions(
|
|
383
|
+
const feeOptions = await this.completeFeeOptions({
|
|
384
|
+
from: opts.from,
|
|
385
|
+
feePayer: executionPayload.feePayer,
|
|
386
|
+
gasSettings: opts.fee?.gasSettings,
|
|
387
|
+
});
|
|
369
388
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
370
389
|
return this.pxe.profileTx(txRequest, {
|
|
371
390
|
profileMode: opts.profileMode,
|
|
372
391
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
373
|
-
scopes: this.
|
|
392
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
374
393
|
});
|
|
375
394
|
}
|
|
376
395
|
|
|
@@ -378,9 +397,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
378
397
|
executionPayload: ExecutionPayload,
|
|
379
398
|
opts: SendOptions<W>,
|
|
380
399
|
): Promise<SendReturn<W>> {
|
|
381
|
-
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
|
+
});
|
|
382
405
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
383
|
-
const provenTx = await this.pxe.proveTx(txRequest, this.
|
|
406
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
407
|
+
const offchainOutput = extractOffchainOutput(
|
|
408
|
+
provenTx.getOffchainEffects(),
|
|
409
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
410
|
+
);
|
|
384
411
|
const tx = await provenTx.toTx();
|
|
385
412
|
const txHash = tx.getTxHash();
|
|
386
413
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -394,12 +421,32 @@ export abstract class BaseWallet implements Wallet {
|
|
|
394
421
|
|
|
395
422
|
// If wait is NO_WAIT, return txHash immediately
|
|
396
423
|
if (opts.wait === NO_WAIT) {
|
|
397
|
-
return txHash as SendReturn<W>;
|
|
424
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
398
425
|
}
|
|
399
426
|
|
|
400
427
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
401
428
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
402
|
-
|
|
429
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
430
|
+
|
|
431
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
432
|
+
if (receipt.debugLogs?.length) {
|
|
433
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
441
|
+
* @param address - The contract address to resolve.
|
|
442
|
+
*/
|
|
443
|
+
protected async getContractName(address: AztecAddress): Promise<string | undefined> {
|
|
444
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
445
|
+
if (!instance) {
|
|
446
|
+
return undefined;
|
|
447
|
+
}
|
|
448
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
449
|
+
return artifact?.name;
|
|
403
450
|
}
|
|
404
451
|
|
|
405
452
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -416,8 +463,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
416
463
|
return err;
|
|
417
464
|
}
|
|
418
465
|
|
|
419
|
-
|
|
420
|
-
return this.pxe.
|
|
466
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
467
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
421
468
|
}
|
|
422
469
|
|
|
423
470
|
async getPrivateEvents<T>(
|
|
@@ -440,17 +487,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
440
487
|
return decodedEvents;
|
|
441
488
|
}
|
|
442
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
492
|
+
* @param address - The contract address to query.
|
|
493
|
+
*/
|
|
443
494
|
async getContractMetadata(address: AztecAddress) {
|
|
444
495
|
const instance = await this.pxe.getContractInstance(address);
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
496
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
497
|
+
|
|
498
|
+
let initializationStatus: ContractInitializationStatus;
|
|
499
|
+
if (instance) {
|
|
500
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
501
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
502
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
503
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
504
|
+
initializationStatus = witness
|
|
505
|
+
? ContractInitializationStatus.INITIALIZED
|
|
506
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
507
|
+
} else {
|
|
508
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
509
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
510
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
511
|
+
// uninitialized.
|
|
512
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
513
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
514
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
515
|
+
}
|
|
516
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
448
517
|
const isContractUpdated =
|
|
449
518
|
publiclyRegisteredContract &&
|
|
450
519
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
451
520
|
return {
|
|
452
521
|
instance: instance ?? undefined,
|
|
453
|
-
|
|
522
|
+
initializationStatus,
|
|
454
523
|
isContractPublished: !!publiclyRegisteredContract,
|
|
455
524
|
isContractUpdated: !!isContractUpdated,
|
|
456
525
|
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
|
@@ -4,6 +4,8 @@ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
|
4
4
|
import { makeTuple } from '@aztec/foundation/array';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
7
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
8
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
7
9
|
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
8
10
|
import { type FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
11
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -72,6 +74,7 @@ async function simulateBatchViaNode(
|
|
|
72
74
|
gasSettings: GasSettings,
|
|
73
75
|
blockHeader: BlockHeader,
|
|
74
76
|
skipFeeEnforcement: boolean,
|
|
77
|
+
getContractName: ContractNameResolver,
|
|
75
78
|
): Promise<TxSimulationResult> {
|
|
76
79
|
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
77
80
|
|
|
@@ -126,6 +129,7 @@ async function simulateBatchViaNode(
|
|
|
126
129
|
const provingResult = await generateSimulatedProvingResult(
|
|
127
130
|
privateResult,
|
|
128
131
|
(_contractAddress: AztecAddress, _functionSelector: FunctionSelector) => Promise.resolve(''),
|
|
132
|
+
node,
|
|
129
133
|
1, // minRevertibleSideEffectCounter
|
|
130
134
|
);
|
|
131
135
|
|
|
@@ -144,6 +148,9 @@ async function simulateBatchViaNode(
|
|
|
144
148
|
throw publicOutput.revertReason;
|
|
145
149
|
}
|
|
146
150
|
|
|
151
|
+
// Display debug logs from the public simulation.
|
|
152
|
+
await displayDebugLogs(publicOutput.debugLogs, getContractName);
|
|
153
|
+
|
|
147
154
|
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
148
155
|
}
|
|
149
156
|
|
|
@@ -168,6 +175,7 @@ export async function simulateViaNode(
|
|
|
168
175
|
gasSettings: GasSettings,
|
|
169
176
|
blockHeader: BlockHeader,
|
|
170
177
|
skipFeeEnforcement: boolean = true,
|
|
178
|
+
getContractName: ContractNameResolver,
|
|
171
179
|
): Promise<TxSimulationResult[]> {
|
|
172
180
|
const batches: FunctionCall[][] = [];
|
|
173
181
|
|
|
@@ -186,6 +194,7 @@ export async function simulateViaNode(
|
|
|
186
194
|
gasSettings,
|
|
187
195
|
blockHeader,
|
|
188
196
|
skipFeeEnforcement,
|
|
197
|
+
getContractName,
|
|
189
198
|
);
|
|
190
199
|
results.push(result);
|
|
191
200
|
}
|
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
|
+
}
|