@aztec/wallet-sdk 4.0.0-devnet.2-patch.4 → 4.0.0-devnet.3-patch.1
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 +31 -20
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +108 -48
- 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 +6 -3
- 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 +159 -82
- package/src/base-wallet/index.ts +1 -1
- package/src/base-wallet/utils.ts +8 -0
- 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,21 +1,28 @@
|
|
|
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
|
|
7
|
-
Aliased,
|
|
8
|
-
AppCapabilities,
|
|
9
|
-
BatchResults,
|
|
10
|
-
BatchedMethod,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
import {
|
|
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,
|
|
19
26
|
} from '@aztec/aztec.js/wallet';
|
|
20
27
|
import {
|
|
21
28
|
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
@@ -24,11 +31,12 @@ import {
|
|
|
24
31
|
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
|
|
25
32
|
} from '@aztec/constants';
|
|
26
33
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
34
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
27
35
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
28
36
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
29
37
|
import { createLogger } from '@aztec/foundation/log';
|
|
30
38
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
31
|
-
import
|
|
39
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
32
40
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
33
41
|
import {
|
|
34
42
|
type ContractArtifact,
|
|
@@ -37,7 +45,7 @@ import {
|
|
|
37
45
|
decodeFromAbi,
|
|
38
46
|
} from '@aztec/stdlib/abi';
|
|
39
47
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
40
|
-
import
|
|
48
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
41
49
|
import {
|
|
42
50
|
type ContractInstanceWithAddress,
|
|
43
51
|
computePartialAddress,
|
|
@@ -45,14 +53,17 @@ import {
|
|
|
45
53
|
} from '@aztec/stdlib/contract';
|
|
46
54
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
47
55
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
48
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
computeSiloedPrivateInitializationNullifier,
|
|
58
|
+
computeSiloedPublicInitializationNullifier,
|
|
59
|
+
} from '@aztec/stdlib/hash';
|
|
49
60
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
50
61
|
import {
|
|
51
62
|
BlockHeader,
|
|
52
63
|
type TxExecutionRequest,
|
|
53
64
|
type TxProfileResult,
|
|
54
65
|
TxSimulationResult,
|
|
55
|
-
type
|
|
66
|
+
type UtilityExecutionResult,
|
|
56
67
|
} from '@aztec/stdlib/tx';
|
|
57
68
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
58
69
|
|
|
@@ -70,11 +81,21 @@ export type FeeOptions = {
|
|
|
70
81
|
*/
|
|
71
82
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
72
83
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
73
|
-
accountFeePaymentMethodOptions
|
|
84
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
74
85
|
/** The gas settings to use for the transaction */
|
|
75
86
|
gasSettings: GasSettings;
|
|
76
87
|
};
|
|
77
88
|
|
|
89
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
90
|
+
export type SimulateViaEntrypointOptions = Pick<
|
|
91
|
+
SimulateOptions,
|
|
92
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
93
|
+
> & {
|
|
94
|
+
/** Fee options for the entrypoint */
|
|
95
|
+
feeOptions: FeeOptions;
|
|
96
|
+
/** Scopes to use for the simulation */
|
|
97
|
+
scopes: AztecAddress[];
|
|
98
|
+
};
|
|
78
99
|
/**
|
|
79
100
|
* A base class for Wallet implementations
|
|
80
101
|
*/
|
|
@@ -89,10 +110,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
89
110
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
90
111
|
) {}
|
|
91
112
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
113
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
114
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
115
|
+
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
116
|
+
return [...scopeSet].map(AztecAddress.fromString);
|
|
96
117
|
}
|
|
97
118
|
|
|
98
119
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
@@ -118,26 +139,33 @@ export abstract class BaseWallet implements Wallet {
|
|
|
118
139
|
|
|
119
140
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
120
141
|
executionPayload: ExecutionPayload,
|
|
121
|
-
from: AztecAddress,
|
|
142
|
+
from: AztecAddress | NoFrom,
|
|
122
143
|
feeOptions: FeeOptions,
|
|
123
144
|
): Promise<TxExecutionRequest> {
|
|
124
145
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
125
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
126
|
-
txNonce: Fr.random(),
|
|
127
|
-
cancellable: this.cancellableTransactions,
|
|
128
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
129
|
-
};
|
|
130
146
|
const finalExecutionPayload = feeExecutionPayload
|
|
131
147
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
132
148
|
: executionPayload;
|
|
133
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
134
149
|
const chainInfo = await this.getChainInfo();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
chainInfo
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
|
|
151
|
+
if (from === NO_FROM) {
|
|
152
|
+
const entrypoint = new DefaultEntrypoint();
|
|
153
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
154
|
+
} else {
|
|
155
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
156
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
157
|
+
txNonce: Fr.random(),
|
|
158
|
+
cancellable: this.cancellableTransactions,
|
|
159
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
160
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
161
|
+
};
|
|
162
|
+
return fromAccount.createTxExecutionRequest(
|
|
163
|
+
finalExecutionPayload,
|
|
164
|
+
feeOptions.gasSettings,
|
|
165
|
+
chainInfo,
|
|
166
|
+
executionOptions,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
141
169
|
}
|
|
142
170
|
|
|
143
171
|
public async createAuthWit(
|
|
@@ -192,23 +220,27 @@ export abstract class BaseWallet implements Wallet {
|
|
|
192
220
|
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
193
221
|
*/
|
|
194
222
|
protected async completeFeeOptions(
|
|
195
|
-
from: AztecAddress,
|
|
223
|
+
from: AztecAddress | NoFrom,
|
|
196
224
|
feePayer?: AztecAddress,
|
|
197
225
|
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
198
226
|
): Promise<FeeOptions> {
|
|
199
227
|
const maxFeesPerGas =
|
|
200
228
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
201
229
|
let accountFeePaymentMethodOptions;
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
230
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
231
|
+
// account contract entrypoint to use
|
|
232
|
+
if (from !== NO_FROM) {
|
|
233
|
+
if (!feePayer) {
|
|
234
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
235
|
+
// for the account to use its fee juice balance
|
|
236
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
237
|
+
} else {
|
|
238
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
239
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
240
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
241
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
242
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
243
|
+
}
|
|
212
244
|
}
|
|
213
245
|
const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
|
|
214
246
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
@@ -228,7 +260,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
228
260
|
* @param gasSettings - User-provided partial gas settings
|
|
229
261
|
*/
|
|
230
262
|
protected async completeFeeOptionsForEstimation(
|
|
231
|
-
from: AztecAddress,
|
|
263
|
+
from: AztecAddress | NoFrom,
|
|
232
264
|
feePayer?: AztecAddress,
|
|
233
265
|
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
234
266
|
) {
|
|
@@ -295,22 +327,20 @@ export abstract class BaseWallet implements Wallet {
|
|
|
295
327
|
/**
|
|
296
328
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
297
329
|
* @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.
|
|
330
|
+
* @param opts - Simulation options.
|
|
303
331
|
*/
|
|
304
|
-
protected async simulateViaEntrypoint(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
332
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
333
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
334
|
+
executionPayload,
|
|
335
|
+
opts.from,
|
|
336
|
+
opts.feeOptions,
|
|
337
|
+
);
|
|
338
|
+
return this.pxe.simulateTx(txRequest, {
|
|
339
|
+
simulatePublic: true,
|
|
340
|
+
skipTxValidation: opts.skipTxValidation,
|
|
341
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
342
|
+
scopes: opts.scopes,
|
|
343
|
+
});
|
|
314
344
|
}
|
|
315
345
|
|
|
316
346
|
/**
|
|
@@ -338,27 +368,28 @@ 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,
|
|
350
381
|
opts.skipFeeEnforcement ?? true,
|
|
382
|
+
this.getContractName.bind(this),
|
|
351
383
|
)
|
|
352
384
|
: Promise.resolve([]),
|
|
353
385
|
remainingCalls.length > 0
|
|
354
|
-
? this.simulateViaEntrypoint(
|
|
355
|
-
|
|
356
|
-
opts.from,
|
|
386
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
387
|
+
from: opts.from,
|
|
357
388
|
feeOptions,
|
|
358
|
-
this.
|
|
359
|
-
opts.skipTxValidation,
|
|
360
|
-
opts.skipFeeEnforcement ?? true,
|
|
361
|
-
)
|
|
389
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
390
|
+
skipTxValidation: opts.skipTxValidation,
|
|
391
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
392
|
+
})
|
|
362
393
|
: Promise.resolve(null),
|
|
363
394
|
]);
|
|
364
395
|
|
|
@@ -371,7 +402,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
371
402
|
return this.pxe.profileTx(txRequest, {
|
|
372
403
|
profileMode: opts.profileMode,
|
|
373
404
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
374
|
-
scopes: this.
|
|
405
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
375
406
|
});
|
|
376
407
|
}
|
|
377
408
|
|
|
@@ -381,7 +412,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
381
412
|
): Promise<SendReturn<W>> {
|
|
382
413
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
383
414
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
384
|
-
const provenTx = await this.pxe.proveTx(txRequest, this.
|
|
415
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
416
|
+
const offchainOutput = extractOffchainOutput(
|
|
417
|
+
provenTx.getOffchainEffects(),
|
|
418
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
419
|
+
);
|
|
385
420
|
const tx = await provenTx.toTx();
|
|
386
421
|
const txHash = tx.getTxHash();
|
|
387
422
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -395,12 +430,32 @@ export abstract class BaseWallet implements Wallet {
|
|
|
395
430
|
|
|
396
431
|
// If wait is NO_WAIT, return txHash immediately
|
|
397
432
|
if (opts.wait === NO_WAIT) {
|
|
398
|
-
return txHash as SendReturn<W>;
|
|
433
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
399
434
|
}
|
|
400
435
|
|
|
401
436
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
402
437
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
403
|
-
|
|
438
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
439
|
+
|
|
440
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
441
|
+
if (receipt.debugLogs?.length) {
|
|
442
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
450
|
+
* @param address - The contract address to resolve.
|
|
451
|
+
*/
|
|
452
|
+
protected async getContractName(address: AztecAddress): Promise<string | undefined> {
|
|
453
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
454
|
+
if (!instance) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
458
|
+
return artifact?.name;
|
|
404
459
|
}
|
|
405
460
|
|
|
406
461
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -417,8 +472,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
417
472
|
return err;
|
|
418
473
|
}
|
|
419
474
|
|
|
420
|
-
|
|
421
|
-
return this.pxe.
|
|
475
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
476
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
422
477
|
}
|
|
423
478
|
|
|
424
479
|
async getPrivateEvents<T>(
|
|
@@ -441,17 +496,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
441
496
|
return decodedEvents;
|
|
442
497
|
}
|
|
443
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
501
|
+
* @param address - The contract address to query.
|
|
502
|
+
*/
|
|
444
503
|
async getContractMetadata(address: AztecAddress) {
|
|
445
504
|
const instance = await this.pxe.getContractInstance(address);
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
505
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
506
|
+
|
|
507
|
+
let initializationStatus: ContractInitializationStatus;
|
|
508
|
+
if (instance) {
|
|
509
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
510
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
511
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
512
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
513
|
+
initializationStatus = witness
|
|
514
|
+
? ContractInitializationStatus.INITIALIZED
|
|
515
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
516
|
+
} else {
|
|
517
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
518
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
519
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
520
|
+
// uninitialized.
|
|
521
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
522
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
523
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
524
|
+
}
|
|
525
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
449
526
|
const isContractUpdated =
|
|
450
527
|
publiclyRegisteredContract &&
|
|
451
528
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
452
529
|
return {
|
|
453
530
|
instance: instance ?? undefined,
|
|
454
|
-
|
|
531
|
+
initializationStatus,
|
|
455
532
|
isContractPublished: !!publiclyRegisteredContract,
|
|
456
533
|
isContractUpdated: !!isContractUpdated,
|
|
457
534
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
1
|
+
export { BaseWallet, type FeeOptions, type SimulateViaEntrypointOptions } from './base_wallet.js';
|
|
2
2
|
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
|
|
|
@@ -145,6 +148,9 @@ async function simulateBatchViaNode(
|
|
|
145
148
|
throw publicOutput.revertReason;
|
|
146
149
|
}
|
|
147
150
|
|
|
151
|
+
// Display debug logs from the public simulation.
|
|
152
|
+
await displayDebugLogs(publicOutput.debugLogs, getContractName);
|
|
153
|
+
|
|
148
154
|
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
149
155
|
}
|
|
150
156
|
|
|
@@ -169,6 +175,7 @@ export async function simulateViaNode(
|
|
|
169
175
|
gasSettings: GasSettings,
|
|
170
176
|
blockHeader: BlockHeader,
|
|
171
177
|
skipFeeEnforcement: boolean = true,
|
|
178
|
+
getContractName: ContractNameResolver,
|
|
172
179
|
): Promise<TxSimulationResult[]> {
|
|
173
180
|
const batches: FunctionCall[][] = [];
|
|
174
181
|
|
|
@@ -187,6 +194,7 @@ export async function simulateViaNode(
|
|
|
187
194
|
gasSettings,
|
|
188
195
|
blockHeader,
|
|
189
196
|
skipFeeEnforcement,
|
|
197
|
+
getContractName,
|
|
190
198
|
);
|
|
191
199
|
results.push(result);
|
|
192
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
|
+
}
|
|
@@ -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.
|