@aztec/wallet-sdk 0.0.1-commit.b64cb54f6 → 0.0.1-commit.b9865e97
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/README.md +125 -0
- package/dest/base-wallet/base_wallet.d.ts +60 -39
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +167 -75
- 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 +7 -4
- package/dest/base-wallet/utils.d.ts.map +1 -1
- package/dest/base-wallet/utils.js +11 -5
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +12 -2
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -1
- package/dest/extension/handlers/background_connection_handler.js +44 -8
- package/dest/extension/handlers/content_script_connection_handler.d.ts +2 -1
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -1
- package/dest/extension/handlers/content_script_connection_handler.js +19 -0
- package/dest/extension/handlers/internal_message_types.d.ts +3 -1
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -1
- package/dest/extension/handlers/internal_message_types.js +3 -1
- package/dest/extension/provider/extension_wallet.d.ts +26 -6
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +80 -9
- 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 +122 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +239 -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 +85 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +269 -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 +64 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +29 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +245 -128
- package/src/base-wallet/index.ts +6 -1
- package/src/base-wallet/utils.ts +15 -5
- package/src/crypto.ts +104 -0
- package/src/extension/handlers/background_connection_handler.ts +42 -9
- package/src/extension/handlers/content_script_connection_handler.ts +18 -0
- package/src/extension/handlers/internal_message_types.ts +2 -0
- package/src/extension/provider/extension_wallet.ts +94 -13
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +341 -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 +323 -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 +72 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
1
2
|
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
3
|
-
import {
|
|
4
|
+
import { ContractInitializationStatus, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
6
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
5
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
9
|
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
@@ -9,8 +11,8 @@ import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
|
9
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
12
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
11
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
12
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
13
|
-
import {
|
|
14
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
15
|
+
import { computeSiloedPrivateInitializationNullifier, computeSiloedPublicInitializationNullifier } from '@aztec/stdlib/hash';
|
|
14
16
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
15
17
|
import { inspect } from 'util';
|
|
16
18
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
@@ -22,6 +24,9 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
22
24
|
log;
|
|
23
25
|
minFeePadding;
|
|
24
26
|
cancellableTransactions;
|
|
27
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
28
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
29
|
+
nodeInfoPromise;
|
|
25
30
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
26
31
|
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
27
32
|
this.pxe = pxe;
|
|
@@ -31,7 +36,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
31
36
|
this.cancellableTransactions = false;
|
|
32
37
|
}
|
|
33
38
|
scopesFrom(from, additionalScopes = []) {
|
|
34
|
-
const allScopes = from
|
|
39
|
+
const allScopes = from === NO_FROM ? additionalScopes : [
|
|
35
40
|
from,
|
|
36
41
|
...additionalScopes
|
|
37
42
|
];
|
|
@@ -41,6 +46,15 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
41
46
|
].map(AztecAddress.fromString);
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
49
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
50
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
51
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
52
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
53
|
+
* @param sendMessagesAs - Explicit override.
|
|
54
|
+
*/ senderForTagsFrom(from, sendMessagesAs) {
|
|
55
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
44
58
|
* Returns the list of aliased contacts associated with the wallet.
|
|
45
59
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
46
60
|
* - Senders: Addresses we check during synching in case they sent us notes,
|
|
@@ -54,7 +68,10 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
54
68
|
}));
|
|
55
69
|
}
|
|
56
70
|
async getChainInfo() {
|
|
57
|
-
|
|
71
|
+
if (!this.nodeInfoPromise) {
|
|
72
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo();
|
|
73
|
+
}
|
|
74
|
+
const { l1ChainId, rollupVersion } = await this.nodeInfoPromise;
|
|
58
75
|
return {
|
|
59
76
|
chainId: new Fr(l1ChainId),
|
|
60
77
|
version: new Fr(rollupVersion)
|
|
@@ -62,18 +79,24 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
62
79
|
}
|
|
63
80
|
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
64
81
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
65
|
-
const executionOptions = {
|
|
66
|
-
txNonce: Fr.random(),
|
|
67
|
-
cancellable: this.cancellableTransactions,
|
|
68
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
69
|
-
};
|
|
70
82
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
71
83
|
feeExecutionPayload,
|
|
72
84
|
executionPayload
|
|
73
85
|
]) : executionPayload;
|
|
74
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
75
86
|
const chainInfo = await this.getChainInfo();
|
|
76
|
-
|
|
87
|
+
if (from === NO_FROM) {
|
|
88
|
+
const entrypoint = new DefaultEntrypoint();
|
|
89
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
90
|
+
} else {
|
|
91
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
92
|
+
const executionOptions = {
|
|
93
|
+
txNonce: Fr.random(),
|
|
94
|
+
cancellable: this.cancellableTransactions,
|
|
95
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
96
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
97
|
+
};
|
|
98
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
99
|
+
}
|
|
77
100
|
}
|
|
78
101
|
async createAuthWit(from, messageHashOrIntent) {
|
|
79
102
|
const account = await this.getAccountFromAddress(from);
|
|
@@ -116,26 +139,33 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
116
139
|
}
|
|
117
140
|
/**
|
|
118
141
|
* Completes partial user-provided fee options with wallet defaults.
|
|
119
|
-
* @param
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
124
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
142
|
+
* @param config - Fee completion config.
|
|
143
|
+
*/ async completeFeeOptions(config) {
|
|
144
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
145
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
125
146
|
let accountFeePaymentMethodOptions;
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
148
|
+
// account contract entrypoint to use
|
|
149
|
+
if (from !== NO_FROM) {
|
|
150
|
+
if (!feePayer) {
|
|
151
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
152
|
+
// for the account to use its fee juice balance
|
|
153
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
154
|
+
} else {
|
|
155
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
156
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
157
|
+
accountFeePaymentMethodOptions = from.equals(feePayer) ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM : AccountFeePaymentMethodOptions.EXTERNAL;
|
|
158
|
+
}
|
|
134
159
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
160
|
+
const gasSettingsOverrides = {
|
|
161
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
162
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
163
|
+
maxFeesPerGas,
|
|
164
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
165
|
+
};
|
|
166
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
167
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
168
|
+
const fullGasSettings = forEstimation ? GasSettings.forEstimation(gasSettingsOverrides) : GasSettings.fallback(gasSettingsOverrides);
|
|
139
169
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
140
170
|
return {
|
|
141
171
|
gasSettings: fullGasSettings,
|
|
@@ -144,22 +174,24 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
144
174
|
};
|
|
145
175
|
}
|
|
146
176
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* to
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
178
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
179
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
180
|
+
*/ async getMinFees(estimate = ManaUsageEstimate.Limit) {
|
|
181
|
+
try {
|
|
182
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
183
|
+
if (predicted.length === 0) {
|
|
184
|
+
return this.aztecNode.getCurrentMinFees();
|
|
185
|
+
}
|
|
186
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
189
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
190
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
191
|
+
return this.aztecNode.getCurrentMinFees();
|
|
192
|
+
}
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
163
195
|
}
|
|
164
196
|
registerSender(address, _alias = '') {
|
|
165
197
|
return this.pxe.registerSender(address);
|
|
@@ -196,22 +228,37 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
196
228
|
}
|
|
197
229
|
return instance;
|
|
198
230
|
}
|
|
231
|
+
registerContractClass(artifact) {
|
|
232
|
+
return this.pxe.registerContractClass(artifact);
|
|
233
|
+
}
|
|
199
234
|
/**
|
|
200
235
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
201
236
|
* @param executionPayload - The execution payload to simulate.
|
|
202
|
-
* @param
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
* @param scopes - The scopes to use for the simulation.
|
|
207
|
-
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement) {
|
|
208
|
-
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
209
|
-
return this.pxe.simulateTx(txRequest, {
|
|
237
|
+
* @param opts - Simulation options.
|
|
238
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
239
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, opts.feeOptions);
|
|
240
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
210
241
|
simulatePublic: true,
|
|
211
|
-
skipTxValidation,
|
|
212
|
-
skipFeeEnforcement,
|
|
213
|
-
scopes
|
|
242
|
+
skipTxValidation: opts.skipTxValidation,
|
|
243
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
244
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
245
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
246
|
+
overrides: opts.overrides
|
|
214
247
|
});
|
|
248
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
249
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
253
|
+
* calls, N+1 = app).
|
|
254
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
255
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
256
|
+
*/ async computeAppCallOffset(from, feeOptions) {
|
|
257
|
+
if (from === NO_FROM) {
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
261
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
215
262
|
}
|
|
216
263
|
/**
|
|
217
264
|
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
@@ -221,7 +268,13 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
221
268
|
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
222
269
|
* @returns The merged simulation result.
|
|
223
270
|
*/ async simulateTx(executionPayload, opts) {
|
|
224
|
-
const feeOptions =
|
|
271
|
+
const feeOptions = await this.completeFeeOptions({
|
|
272
|
+
from: opts.from,
|
|
273
|
+
feePayer: executionPayload.feePayer,
|
|
274
|
+
gasSettings: opts.fee?.gasSettings,
|
|
275
|
+
forEstimation: true,
|
|
276
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
277
|
+
});
|
|
225
278
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
226
279
|
const remainingPayload = {
|
|
227
280
|
...executionPayload,
|
|
@@ -234,31 +287,54 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
234
287
|
try {
|
|
235
288
|
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
236
289
|
} catch {
|
|
237
|
-
blockHeader = await this.aztecNode.
|
|
290
|
+
blockHeader = (await this.aztecNode.getBlockData('latest')).header;
|
|
238
291
|
}
|
|
292
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
239
293
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
240
|
-
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls,
|
|
241
|
-
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload,
|
|
294
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this), opts.overrides) : Promise.resolve([]),
|
|
295
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, {
|
|
296
|
+
from: opts.from,
|
|
297
|
+
feeOptions,
|
|
298
|
+
additionalScopes: opts.additionalScopes,
|
|
299
|
+
skipTxValidation: opts.skipTxValidation,
|
|
300
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
301
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
302
|
+
overrides: opts.overrides
|
|
303
|
+
}) : Promise.resolve(null)
|
|
242
304
|
]);
|
|
243
305
|
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
244
306
|
}
|
|
245
307
|
async profileTx(executionPayload, opts) {
|
|
246
|
-
const feeOptions = await this.completeFeeOptions(
|
|
308
|
+
const feeOptions = await this.completeFeeOptions({
|
|
309
|
+
from: opts.from,
|
|
310
|
+
feePayer: executionPayload.feePayer,
|
|
311
|
+
gasSettings: opts.fee?.gasSettings,
|
|
312
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
313
|
+
});
|
|
247
314
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
248
315
|
return this.pxe.profileTx(txRequest, {
|
|
249
316
|
profileMode: opts.profileMode,
|
|
250
317
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
251
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
318
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
319
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
252
320
|
});
|
|
253
321
|
}
|
|
254
322
|
async sendTx(executionPayload, opts) {
|
|
255
|
-
const feeOptions = await this.completeFeeOptions(
|
|
323
|
+
const feeOptions = await this.completeFeeOptions({
|
|
324
|
+
from: opts.from,
|
|
325
|
+
feePayer: executionPayload.feePayer,
|
|
326
|
+
gasSettings: opts.fee?.gasSettings,
|
|
327
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
328
|
+
});
|
|
256
329
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
257
|
-
const provenTx = await this.pxe.proveTx(txRequest,
|
|
330
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
331
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
332
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
333
|
+
});
|
|
258
334
|
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
259
335
|
const tx = await provenTx.toTx();
|
|
260
336
|
const txHash = tx.getTxHash();
|
|
261
|
-
if (await this.aztecNode.
|
|
337
|
+
if ((await this.aztecNode.getTxReceipt(txHash)).isMined()) {
|
|
262
338
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
263
339
|
}
|
|
264
340
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
@@ -277,7 +353,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
277
353
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
278
354
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
279
355
|
// Display debug logs from public execution if present (served in test mode only)
|
|
280
|
-
if (receipt.debugLogs?.length) {
|
|
356
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
281
357
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
282
358
|
}
|
|
283
359
|
return {
|
|
@@ -312,9 +388,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
312
388
|
executeUtility(call, opts) {
|
|
313
389
|
return this.pxe.executeUtility(call, {
|
|
314
390
|
authwits: opts.authWitnesses,
|
|
315
|
-
scopes:
|
|
316
|
-
opts.scope
|
|
317
|
-
]
|
|
391
|
+
scopes: opts.scopes
|
|
318
392
|
});
|
|
319
393
|
}
|
|
320
394
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
@@ -333,15 +407,33 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
333
407
|
});
|
|
334
408
|
return decodedEvents;
|
|
335
409
|
}
|
|
336
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
412
|
+
* @param address - The contract address to query.
|
|
413
|
+
*/ async getContractMetadata(address) {
|
|
337
414
|
const instance = await this.pxe.getContractInstance(address);
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
415
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
416
|
+
let initializationStatus;
|
|
417
|
+
if (instance) {
|
|
418
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
419
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
420
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
421
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
422
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNINITIALIZED;
|
|
423
|
+
} else {
|
|
424
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
425
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
426
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
427
|
+
// uninitialized.
|
|
428
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
429
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
430
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
431
|
+
}
|
|
432
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
341
433
|
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
342
434
|
return {
|
|
343
435
|
instance: instance ?? undefined,
|
|
344
|
-
|
|
436
|
+
initializationStatus,
|
|
345
437
|
isContractPublished: !!publiclyRegisteredContract,
|
|
346
438
|
isContractUpdated: !!isContractUpdated,
|
|
347
439
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
1
|
+
export { BaseWallet, type CompleteFeeOptionsConfig, type FeeOptions, type SimulateViaEntrypointOptions, } from './base_wallet.js';
|
|
2
2
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsVUFBVSxFQUNWLEtBQUssd0JBQXdCLEVBQzdCLEtBQUssVUFBVSxFQUNmLEtBQUssNEJBQTRCLEdBQ2xDLE1BQU0sa0JBQWtCLENBQUM7QUFDMUIsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
2
3
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
4
|
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
4
5
|
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
5
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
7
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
7
|
-
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
import { type BlockHeader, type ExecutionPayload, type SimulationOverrides, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
9
|
/**
|
|
9
10
|
* Splits an execution payload into a leading prefix of public static calls
|
|
10
11
|
* (eligible for direct node simulation) and the remaining calls.
|
|
@@ -32,9 +33,11 @@ export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPa
|
|
|
32
33
|
* @param gasSettings - Gas settings for the transaction.
|
|
33
34
|
* @param blockHeader - Block header to use as anchor.
|
|
34
35
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
36
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
37
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
35
38
|
* @returns Array of TxSimulationResult, one per batch.
|
|
36
39
|
*/
|
|
37
|
-
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver): Promise<TxSimulationResult[]>;
|
|
40
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver, overrides?: SimulationOverrides): Promise<TxSimulationResult[]>;
|
|
38
41
|
/**
|
|
39
42
|
* Merges simulation results from the optimized (public static) and normal paths.
|
|
40
43
|
* Since optimized calls are always a leading prefix, return values are simply
|
|
@@ -45,5 +48,5 @@ export declare function simulateViaNode(node: AztecNode, publicStaticCalls: Func
|
|
|
45
48
|
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
46
49
|
* @returns A single TxSimulationResult with return values in original call order.
|
|
47
50
|
*/
|
|
48
|
-
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult:
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResultWithAppOffset | null): TxSimulationResultWithAppOffset;
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsK0JBQStCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUV6RSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBS3JCLEtBQUssbUJBQW1CLEVBR3hCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lBQ3ZFLGdCQUFnQixFQUFFLFlBQVksRUFBRSxDQUFDO0lBQ2pDLDJCQUEyQjtJQUMzQixjQUFjLEVBQUUsWUFBWSxFQUFFLENBQUM7Q0FDaEMsQ0FPQTtBQTBHRDs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILHdCQUFzQixlQUFlLENBQ25DLElBQUksRUFBRSxTQUFTLEVBQ2YsaUJBQWlCLEVBQUUsWUFBWSxFQUFFLEVBQ2pDLElBQUksRUFBRSxZQUFZLEVBQ2xCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLGtCQUFrQixxQkFBZ0IsRUFDbEMsZUFBZSxFQUFFLG9CQUFvQixFQUNyQyxTQUFTLENBQUMsRUFBRSxtQkFBbUIsR0FDOUIsT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUMsQ0F5Qi9CO0FBRUQ7Ozs7Ozs7OztHQVNHO0FBQ0gsd0JBQWdCLDJCQUEyQixDQUN6QyxnQkFBZ0IsRUFBRSxrQkFBa0IsRUFBRSxFQUN0QyxZQUFZLEVBQUUsK0JBQStCLEdBQUcsSUFBSSxHQUNuRCwrQkFBK0IsQ0FxQmpDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base-wallet/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base-wallet/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQrD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAKrB,KAAK,mBAAmB,EAGxB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,gBAAgB,GAAG;IAC9E,uEAAuE;IACvE,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,2BAA2B;IAC3B,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAOA;AA0GD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,SAAS,EACf,iBAAiB,EAAE,YAAY,EAAE,EACjC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,kBAAkB,qBAAgB,EAClC,eAAe,EAAE,oBAAoB,EACrC,SAAS,CAAC,EAAE,mBAAmB,GAC9B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAyB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,+BAA+B,GAAG,IAAI,GACnD,+BAA+B,CAqBjC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
1
2
|
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
2
3
|
import { makeTuple } from '@aztec/foundation/array';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -34,8 +35,10 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
34
35
|
* @param gasSettings - Gas settings for the transaction.
|
|
35
36
|
* @param blockHeader - Block header to use as anchor.
|
|
36
37
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
38
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
39
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
37
40
|
* @returns TxSimulationResult with public return values.
|
|
38
|
-
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName) {
|
|
41
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName, overrides) {
|
|
39
42
|
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
40
43
|
const publicFunctionCalldata = [];
|
|
41
44
|
for (const call of publicStaticCalls){
|
|
@@ -74,7 +77,7 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
74
77
|
contractClassLogFields: [],
|
|
75
78
|
publicFunctionCalldata: publicFunctionCalldata
|
|
76
79
|
});
|
|
77
|
-
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
80
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
|
|
78
81
|
if (publicOutput.revertReason) {
|
|
79
82
|
throw publicOutput.revertReason;
|
|
80
83
|
}
|
|
@@ -93,15 +96,17 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
93
96
|
* @param gasSettings - Gas settings for the transaction.
|
|
94
97
|
* @param blockHeader - Block header to use as anchor.
|
|
95
98
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
99
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
100
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
96
101
|
* @returns Array of TxSimulationResult, one per batch.
|
|
97
|
-
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true, getContractName) {
|
|
102
|
+
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true, getContractName, overrides) {
|
|
98
103
|
const batches = [];
|
|
99
104
|
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
100
105
|
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
101
106
|
}
|
|
102
107
|
const results = [];
|
|
103
108
|
for (const batch of batches){
|
|
104
|
-
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName);
|
|
109
|
+
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName, overrides);
|
|
105
110
|
results.push(result);
|
|
106
111
|
}
|
|
107
112
|
return results;
|
|
@@ -127,5 +132,6 @@ import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, T
|
|
|
127
132
|
...baseResult.publicOutput,
|
|
128
133
|
publicReturnValues: allReturnValues
|
|
129
134
|
} : undefined;
|
|
130
|
-
|
|
135
|
+
const merged = new TxSimulationResult(baseResult.privateExecutionResult, baseResult.publicInputs, mergedPublicOutput, normalResult?.stats);
|
|
136
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(merged, normalResult?.appCallOffset ?? 0);
|
|
131
137
|
}
|
package/dest/crypto.d.ts
CHANGED
|
@@ -189,4 +189,42 @@ export declare const DEFAULT_EMOJI_GRID_SIZE = 9;
|
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
191
|
export declare function hashToEmoji(hash: string, count?: number): string;
|
|
192
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Derives an AES-256-GCM key from a passphrase using PBKDF2-SHA256.
|
|
194
|
+
*
|
|
195
|
+
* @param passphrase - The user-provided passphrase or PIN
|
|
196
|
+
* @param salt - Random salt bytes
|
|
197
|
+
* @param iterations - PBKDF2 iteration count (default: 2,000,000)
|
|
198
|
+
* @returns An AES-256-GCM CryptoKey
|
|
199
|
+
*/
|
|
200
|
+
export declare function deriveKeyFromPassphrase(passphrase: string, salt: Uint8Array, iterations?: number): Promise<CryptoKey>;
|
|
201
|
+
/**
|
|
202
|
+
* Encrypts arbitrary bytes with a passphrase using PBKDF2 + AES-256-GCM.
|
|
203
|
+
*
|
|
204
|
+
* Output layout: `[salt (16)] [iv (12)] [ciphertext (...)]`
|
|
205
|
+
*
|
|
206
|
+
* @param plaintext - Data to encrypt
|
|
207
|
+
* @param passphrase - User passphrase or PIN
|
|
208
|
+
* @param iterations - PBKDF2 iteration count (default: 2,000,000)
|
|
209
|
+
* @returns A Uint8Array containing salt + iv + ciphertext
|
|
210
|
+
*/
|
|
211
|
+
export declare function encryptWithPassphrase(plaintext: Uint8Array, passphrase: string, iterations?: number): Promise<Uint8Array>;
|
|
212
|
+
/**
|
|
213
|
+
* Decrypts data produced by {@link encryptWithPassphrase}.
|
|
214
|
+
*
|
|
215
|
+
* @param data - The encrypted blob (salt + iv + ciphertext)
|
|
216
|
+
* @param passphrase - The passphrase used during encryption
|
|
217
|
+
* @param iterations - PBKDF2 iteration count (must match encryption)
|
|
218
|
+
* @returns The decrypted plaintext bytes
|
|
219
|
+
* @throws On wrong passphrase (AES-GCM auth tag mismatch)
|
|
220
|
+
*/
|
|
221
|
+
export declare function decryptWithPassphrase(data: Uint8Array, passphrase: string, iterations?: number): Promise<Uint8Array>;
|
|
222
|
+
/**
|
|
223
|
+
* Converts a Uint8Array to a base64 string.
|
|
224
|
+
*/
|
|
225
|
+
export declare function uint8ToBase64(bytes: Uint8Array): string;
|
|
226
|
+
/**
|
|
227
|
+
* Converts a base64 string to a Uint8Array.
|
|
228
|
+
*/
|
|
229
|
+
export declare function base64ToUint8(b64: string): Uint8Array;
|
|
230
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3J5cHRvLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cm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