@aztec/wallet-sdk 0.0.1-commit.3469e52 → 0.0.1-commit.350e0a4d
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 +318 -270
- package/dest/base-wallet/base_wallet.d.ts +115 -40
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +345 -105
- package/dest/base-wallet/get_gas_limits.d.ts +36 -0
- package/dest/base-wallet/get_gas_limits.d.ts.map +1 -0
- package/dest/base-wallet/get_gas_limits.js +55 -0
- package/dest/base-wallet/index.d.ts +4 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +2 -0
- package/dest/base-wallet/utils.d.ts +52 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +137 -0
- package/dest/crypto.d.ts +97 -50
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +290 -108
- package/dest/emoji_alphabet.d.ts +35 -0
- package/dest/emoji_alphabet.d.ts.map +1 -0
- package/dest/emoji_alphabet.js +299 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +168 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +294 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +57 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +193 -0
- package/dest/extension/handlers/index.d.ts +12 -0
- package/dest/extension/handlers/index.d.ts.map +1 -0
- package/dest/extension/handlers/index.js +10 -0
- package/dest/extension/handlers/internal_message_types.d.ts +65 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +24 -0
- package/dest/extension/provider/extension_provider.d.ts +107 -0
- package/dest/extension/provider/extension_provider.d.ts.map +1 -0
- package/dest/extension/provider/extension_provider.js +160 -0
- package/dest/extension/provider/extension_wallet.d.ts +152 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/extension_wallet.js +134 -103
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/index.js +0 -2
- 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/index.d.ts +2 -8
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +0 -6
- package/dest/manager/types.d.ts +92 -9
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/types.js +17 -1
- package/dest/manager/wallet_manager.d.ts +50 -7
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +203 -43
- package/dest/types.d.ts +104 -11
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +32 -2
- package/package.json +21 -10
- package/src/base-wallet/base_wallet.ts +449 -167
- package/src/base-wallet/get_gas_limits.ts +88 -0
- package/src/base-wallet/index.ts +8 -1
- package/src/base-wallet/utils.ts +248 -0
- package/src/crypto.ts +341 -113
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +456 -0
- package/src/extension/handlers/content_script_connection_handler.ts +264 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +71 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/{providers/extension → extension/provider}/extension_wallet.ts +151 -120
- package/src/extension/provider/index.ts +7 -0
- 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/index.ts +2 -10
- package/src/manager/types.ts +95 -8
- package/src/manager/wallet_manager.ts +223 -45
- package/src/types.ts +116 -10
- package/dest/providers/extension/extension_provider.d.ts +0 -63
- package/dest/providers/extension/extension_provider.d.ts.map +0 -1
- package/dest/providers/extension/extension_provider.js +0 -124
- package/dest/providers/extension/extension_wallet.d.ts +0 -155
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/index.d.ts +0 -6
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/src/providers/extension/extension_provider.ts +0 -167
- package/src/providers/extension/index.ts +0 -5
|
@@ -1,28 +1,37 @@
|
|
|
1
|
-
import type { Account } from '@aztec/aztec.js/account';
|
|
1
|
+
import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
3
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
4
|
+
import {
|
|
5
|
+
type InteractionWaitOptions,
|
|
6
|
+
NO_WAIT,
|
|
7
|
+
type SendReturn,
|
|
8
|
+
extractOffchainOutput,
|
|
9
|
+
} from '@aztec/aztec.js/contracts';
|
|
3
10
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
4
|
-
import
|
|
5
|
-
Aliased,
|
|
6
|
-
BatchResults,
|
|
7
|
-
BatchedMethod,
|
|
8
|
-
PrivateEvent,
|
|
9
|
-
PrivateEventFilter,
|
|
10
|
-
ProfileOptions,
|
|
11
|
-
SendOptions,
|
|
12
|
-
SimulateOptions,
|
|
13
|
-
Wallet,
|
|
14
|
-
} from '@aztec/aztec.js/wallet';
|
|
11
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
15
12
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
type Aliased,
|
|
14
|
+
type AppCapabilities,
|
|
15
|
+
type BatchResults,
|
|
16
|
+
type BatchedMethod,
|
|
17
|
+
ContractInitializationStatus,
|
|
18
|
+
type ExecuteUtilityOptions,
|
|
19
|
+
type PrivateEvent,
|
|
20
|
+
type PrivateEventFilter,
|
|
21
|
+
type ProfileOptions,
|
|
22
|
+
type SendOptions,
|
|
23
|
+
type SimulateOptions,
|
|
24
|
+
TxSimulationResultWithAppOffset,
|
|
25
|
+
type Wallet,
|
|
26
|
+
type WalletCapabilities,
|
|
27
|
+
} from '@aztec/aztec.js/wallet';
|
|
21
28
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
29
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
22
30
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
23
31
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
24
32
|
import { createLogger } from '@aztec/foundation/log';
|
|
25
33
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
34
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
26
35
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
27
36
|
import {
|
|
28
37
|
type ContractArtifact,
|
|
@@ -31,28 +40,30 @@ import {
|
|
|
31
40
|
decodeFromAbi,
|
|
32
41
|
} from '@aztec/stdlib/abi';
|
|
33
42
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
34
|
-
import
|
|
35
|
-
import {
|
|
36
|
-
type ContractInstanceWithAddress,
|
|
37
|
-
computePartialAddress,
|
|
38
|
-
getContractClassFromArtifact,
|
|
39
|
-
} from '@aztec/stdlib/contract';
|
|
43
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
|
+
import { type ContractInstancePreimage, type NodeInfo, computePartialAddress } from '@aztec/stdlib/contract';
|
|
40
45
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
41
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
42
|
-
import {
|
|
46
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
47
|
+
import {
|
|
48
|
+
computeSiloedPrivateInitializationNullifier,
|
|
49
|
+
computeSiloedPublicInitializationNullifier,
|
|
50
|
+
} from '@aztec/stdlib/hash';
|
|
43
51
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
44
|
-
import type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
import { type MasterSecretKeys, deriveKeys, deriveKeysFromMasterSecretKeys } from '@aztec/stdlib/keys';
|
|
53
|
+
import {
|
|
54
|
+
BlockHeader,
|
|
55
|
+
ExecutionPayload,
|
|
56
|
+
type TxExecutionRequest,
|
|
57
|
+
type TxProfileResult,
|
|
58
|
+
type UtilityExecutionResult,
|
|
59
|
+
mergeExecutionPayloads,
|
|
51
60
|
} from '@aztec/stdlib/tx';
|
|
52
|
-
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
53
61
|
|
|
54
62
|
import { inspect } from 'util';
|
|
55
63
|
|
|
64
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
65
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
66
|
+
|
|
56
67
|
/**
|
|
57
68
|
* Options to configure fee payment for a transaction
|
|
58
69
|
*/
|
|
@@ -63,26 +74,74 @@ export type FeeOptions = {
|
|
|
63
74
|
*/
|
|
64
75
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
65
76
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
66
|
-
accountFeePaymentMethodOptions
|
|
77
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
67
78
|
/** The gas settings to use for the transaction */
|
|
68
79
|
gasSettings: GasSettings;
|
|
69
80
|
};
|
|
70
81
|
|
|
82
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
83
|
+
export type SimulateViaEntrypointOptions = Pick<
|
|
84
|
+
SimulateOptions,
|
|
85
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement' | 'sendMessagesAs' | 'overrides'
|
|
86
|
+
> & {
|
|
87
|
+
/** Fee options for the entrypoint */
|
|
88
|
+
feeOptions: FeeOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** Options for `completeFeeOptions`. */
|
|
92
|
+
export type CompleteFeeOptionsConfig = {
|
|
93
|
+
/** The address where the transaction is being sent from. */
|
|
94
|
+
from: AztecAddress | NoFrom;
|
|
95
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
96
|
+
feePayer?: AztecAddress;
|
|
97
|
+
/** User-provided partial gas settings. */
|
|
98
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
99
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
100
|
+
forEstimation?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Assumed network congestion level for fee prediction. Controls how aggressively the wallet
|
|
103
|
+
* estimates future fees. Defaults to Limit (worst case) when not specified.
|
|
104
|
+
*/
|
|
105
|
+
congestionEstimate?: ManaUsageEstimate;
|
|
106
|
+
};
|
|
107
|
+
|
|
71
108
|
/**
|
|
72
109
|
* A base class for Wallet implementations
|
|
73
110
|
*/
|
|
74
111
|
export abstract class BaseWallet implements Wallet {
|
|
75
|
-
protected log = createLogger('wallet-sdk:base_wallet');
|
|
76
|
-
|
|
77
112
|
protected minFeePadding = 0.5;
|
|
78
113
|
protected cancellableTransactions = false;
|
|
114
|
+
// Poll interval (in seconds) injected into sendTx waits when the caller does not specify one. Left undefined on
|
|
115
|
+
// production wallets so the DefaultWaitOpts 1s cadence stands; test wallets talking to in-process nodes lower it.
|
|
116
|
+
protected defaultWaitInterval?: number;
|
|
117
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
118
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
119
|
+
private nodeInfoPromise: Promise<NodeInfo> | undefined;
|
|
79
120
|
|
|
80
121
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
81
122
|
protected constructor(
|
|
82
123
|
protected readonly pxe: PXE,
|
|
83
124
|
protected readonly aztecNode: AztecNode,
|
|
125
|
+
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
84
126
|
) {}
|
|
85
127
|
|
|
128
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
129
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
130
|
+
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
131
|
+
return [...scopeSet].map(AztecAddress.fromStringUnsafe);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
136
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
137
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
138
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
139
|
+
* @param sendMessagesAs - Explicit override.
|
|
140
|
+
*/
|
|
141
|
+
protected senderForTagsFrom(from: AztecAddress | NoFrom, sendMessagesAs?: AztecAddress): AztecAddress | undefined {
|
|
142
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
143
|
+
}
|
|
144
|
+
|
|
86
145
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
87
146
|
|
|
88
147
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -95,37 +154,71 @@ export abstract class BaseWallet implements Wallet {
|
|
|
95
154
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
96
155
|
*/
|
|
97
156
|
async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
98
|
-
const
|
|
99
|
-
return
|
|
157
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
158
|
+
return sources.map(source => ({ item: source.sender, alias: '' }));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
163
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
164
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
165
|
+
* depend on it.
|
|
166
|
+
*/
|
|
167
|
+
private getNodeInfo(): Promise<NodeInfo> {
|
|
168
|
+
if (!this.nodeInfoPromise) {
|
|
169
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch(err => {
|
|
170
|
+
this.nodeInfoPromise = undefined;
|
|
171
|
+
throw err;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return this.nodeInfoPromise;
|
|
100
175
|
}
|
|
101
176
|
|
|
102
177
|
async getChainInfo(): Promise<ChainInfo> {
|
|
103
|
-
const { l1ChainId, rollupVersion } = await this.
|
|
178
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
104
179
|
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
105
180
|
}
|
|
106
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
184
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
185
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
186
|
+
* the cached node info, since a wallet talks to a single network.
|
|
187
|
+
*/
|
|
188
|
+
protected async getMaxTxGasLimits(): Promise<Gas> {
|
|
189
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
190
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
191
|
+
}
|
|
192
|
+
|
|
107
193
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
108
194
|
executionPayload: ExecutionPayload,
|
|
109
|
-
from: AztecAddress,
|
|
195
|
+
from: AztecAddress | NoFrom,
|
|
110
196
|
feeOptions: FeeOptions,
|
|
111
197
|
): Promise<TxExecutionRequest> {
|
|
112
198
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
113
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
114
|
-
txNonce: Fr.random(),
|
|
115
|
-
cancellable: this.cancellableTransactions,
|
|
116
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
117
|
-
};
|
|
118
199
|
const finalExecutionPayload = feeExecutionPayload
|
|
119
200
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
120
201
|
: executionPayload;
|
|
121
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
122
202
|
const chainInfo = await this.getChainInfo();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
chainInfo
|
|
127
|
-
|
|
128
|
-
|
|
203
|
+
|
|
204
|
+
if (from === NO_FROM) {
|
|
205
|
+
const entrypoint = new DefaultEntrypoint();
|
|
206
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
207
|
+
} else {
|
|
208
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
209
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
210
|
+
txNonce: Fr.random(),
|
|
211
|
+
cancellable: this.cancellableTransactions,
|
|
212
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
213
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
214
|
+
};
|
|
215
|
+
return fromAccount.createTxExecutionRequest(
|
|
216
|
+
finalExecutionPayload,
|
|
217
|
+
feeOptions.gasSettings,
|
|
218
|
+
chainInfo,
|
|
219
|
+
executionOptions,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
129
222
|
}
|
|
130
223
|
|
|
131
224
|
public async createAuthWit(
|
|
@@ -137,6 +230,23 @@ export abstract class BaseWallet implements Wallet {
|
|
|
137
230
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
138
231
|
}
|
|
139
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Request capabilities from the wallet.
|
|
235
|
+
*
|
|
236
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
237
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
238
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
239
|
+
* friction by allowing apps to request permissions upfront.
|
|
240
|
+
*
|
|
241
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
242
|
+
* while the feature stabilizes.
|
|
243
|
+
*
|
|
244
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
245
|
+
*/
|
|
246
|
+
public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
247
|
+
throw new Error('Not implemented');
|
|
248
|
+
}
|
|
249
|
+
|
|
140
250
|
public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
141
251
|
const results: any[] = [];
|
|
142
252
|
for (const method of methods) {
|
|
@@ -157,31 +267,54 @@ export abstract class BaseWallet implements Wallet {
|
|
|
157
267
|
|
|
158
268
|
/**
|
|
159
269
|
* Completes partial user-provided fee options with wallet defaults.
|
|
160
|
-
* @param
|
|
161
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
162
|
-
* @param gasSettings - User-provided partial gas settings
|
|
163
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
270
|
+
* @param config - Fee completion config.
|
|
164
271
|
*/
|
|
165
|
-
protected async completeFeeOptions(
|
|
166
|
-
from
|
|
167
|
-
feePayer?: AztecAddress,
|
|
168
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
169
|
-
): Promise<FeeOptions> {
|
|
272
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
273
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
170
274
|
const maxFeesPerGas =
|
|
171
|
-
gasSettings?.maxFeesPerGas ?? (await this.
|
|
275
|
+
gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
172
276
|
let accountFeePaymentMethodOptions;
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
if (
|
|
176
|
-
|
|
277
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
278
|
+
// account contract entrypoint to use
|
|
279
|
+
if (from !== NO_FROM) {
|
|
280
|
+
if (!feePayer) {
|
|
281
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
282
|
+
// for the account to use its fee juice balance
|
|
283
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
284
|
+
} else {
|
|
285
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
286
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
287
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
288
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
289
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const gasSettingsOverrides = {
|
|
293
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
294
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
295
|
+
maxFeesPerGas,
|
|
296
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
297
|
+
};
|
|
298
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
299
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
300
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
301
|
+
let fullGasSettings;
|
|
302
|
+
if (forEstimation) {
|
|
303
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
304
|
+
// validate against the network admission limit here.
|
|
305
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
177
306
|
} else {
|
|
178
|
-
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
307
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
308
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
309
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
310
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
311
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
312
|
+
}
|
|
313
|
+
fullGasSettings = GasSettings.fallback({
|
|
314
|
+
...gasSettingsOverrides,
|
|
315
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits,
|
|
316
|
+
});
|
|
183
317
|
}
|
|
184
|
-
const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
|
|
185
318
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
186
319
|
return {
|
|
187
320
|
gasSettings: fullGasSettings,
|
|
@@ -191,104 +324,207 @@ export abstract class BaseWallet implements Wallet {
|
|
|
191
324
|
}
|
|
192
325
|
|
|
193
326
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* to
|
|
197
|
-
* @param from - The address where the transaction is being sent from
|
|
198
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
199
|
-
* @param gasSettings - User-provided partial gas settings
|
|
327
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
328
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
329
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
200
330
|
*/
|
|
201
|
-
protected async
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
maxPriorityFeesPerGas,
|
|
217
|
-
);
|
|
218
|
-
return {
|
|
219
|
-
...defaultFeeOptions,
|
|
220
|
-
gasSettings: gasSettingsForEstimation,
|
|
221
|
-
};
|
|
331
|
+
protected async getMinFees(estimate: ManaUsageEstimate = ManaUsageEstimate.Limit): Promise<GasFees> {
|
|
332
|
+
try {
|
|
333
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
334
|
+
if (predicted.length === 0) {
|
|
335
|
+
return this.aztecNode.getCurrentMinFees();
|
|
336
|
+
}
|
|
337
|
+
return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
|
|
338
|
+
} catch (err: any) {
|
|
339
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
340
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
341
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
342
|
+
return this.aztecNode.getCurrentMinFees();
|
|
343
|
+
}
|
|
344
|
+
throw err;
|
|
345
|
+
}
|
|
222
346
|
}
|
|
223
347
|
|
|
224
|
-
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
225
|
-
|
|
348
|
+
async registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
349
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
350
|
+
return address;
|
|
226
351
|
}
|
|
227
352
|
|
|
228
353
|
async registerContract(
|
|
229
|
-
instance:
|
|
354
|
+
instance: ContractInstancePreimage,
|
|
230
355
|
artifact?: ContractArtifact,
|
|
231
|
-
|
|
232
|
-
): Promise<
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const thisContractClass = await getContractClassFromArtifact(artifact);
|
|
239
|
-
if (!thisContractClass.id.equals(existingInstance.currentContractClassId)) {
|
|
240
|
-
// wallet holds an outdated version of this contract
|
|
241
|
-
await this.pxe.updateContract(instance.address, artifact);
|
|
242
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
// If no artifact provided, we just use the existing registration
|
|
246
|
-
} else {
|
|
247
|
-
// Instance not registered yet
|
|
248
|
-
if (!artifact) {
|
|
249
|
-
// Try to get the artifact from the wallet's contract class storage
|
|
250
|
-
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
251
|
-
if (!artifact) {
|
|
252
|
-
throw new Error(
|
|
253
|
-
`Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`,
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
await this.pxe.registerContract({ artifact, instance });
|
|
356
|
+
secretKeyOrKeys?: Fr | MasterSecretKeys,
|
|
357
|
+
): Promise<void> {
|
|
358
|
+
// Classes and instances are registered independently: register the artifact (if provided) then the instance.
|
|
359
|
+
// Neither call validates that the artifact matches the class the instance runs, a missing artifact only surfaces
|
|
360
|
+
// when the contract is later simulated.
|
|
361
|
+
if (artifact) {
|
|
362
|
+
await this.pxe.registerContractClass(artifact);
|
|
258
363
|
}
|
|
364
|
+
const contractAddress = await this.pxe.registerContract(instance);
|
|
259
365
|
|
|
260
|
-
if (
|
|
261
|
-
|
|
366
|
+
if (secretKeyOrKeys) {
|
|
367
|
+
// PXE never receives the account seed (from which the message-signing/fallback secret keys could be re-derived):
|
|
368
|
+
// the wallet derives the keys here. Of these, PXE only reads and stores the four privacy secret keys and the
|
|
369
|
+
// message-signing and fallback *public* keys — it never touches the message-signing or fallback secret keys.
|
|
370
|
+
//
|
|
371
|
+
// Since PXE recomputes the address from those keys, we assert it matches the instance's address: a mismatch means
|
|
372
|
+
// the provided keys don't correspond to this account.
|
|
373
|
+
const derivedKeys =
|
|
374
|
+
secretKeyOrKeys instanceof Fr
|
|
375
|
+
? await deriveKeys(secretKeyOrKeys)
|
|
376
|
+
: await deriveKeysFromMasterSecretKeys(secretKeyOrKeys);
|
|
377
|
+
const { address } = await this.pxe.registerAccount(derivedKeys, await computePartialAddress(instance));
|
|
378
|
+
if (!address.equals(contractAddress)) {
|
|
379
|
+
throw new Error(
|
|
380
|
+
`Registered account address ${address.toString()} does not match contract instance address ${contractAddress.toString()}: the provided keys do not correspond to this account.`,
|
|
381
|
+
);
|
|
382
|
+
}
|
|
262
383
|
}
|
|
263
|
-
return instance;
|
|
264
384
|
}
|
|
265
385
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
386
|
+
registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
387
|
+
return this.pxe.registerContractClass(artifact);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
392
|
+
* @param executionPayload - The execution payload to simulate.
|
|
393
|
+
* @param opts - Simulation options.
|
|
394
|
+
*/
|
|
395
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
396
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
397
|
+
executionPayload,
|
|
398
|
+
opts.from,
|
|
399
|
+
opts.feeOptions,
|
|
276
400
|
);
|
|
401
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
402
|
+
simulatePublic: true,
|
|
403
|
+
skipTxValidation: opts.skipTxValidation,
|
|
404
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
405
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
406
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
407
|
+
overrides: opts.overrides,
|
|
408
|
+
});
|
|
409
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
410
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
415
|
+
* calls, N+1 = app).
|
|
416
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
417
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
418
|
+
*/
|
|
419
|
+
protected async computeAppCallOffset(from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<number> {
|
|
420
|
+
if (from === NO_FROM) {
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
424
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
429
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
430
|
+
* Return values from both paths are merged back in original call order.
|
|
431
|
+
* @param executionPayload - The execution payload to simulate.
|
|
432
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
433
|
+
* @returns The merged simulation result.
|
|
434
|
+
*/
|
|
435
|
+
async simulateTx(
|
|
436
|
+
executionPayload: ExecutionPayload,
|
|
437
|
+
opts: SimulateOptions,
|
|
438
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
439
|
+
const feeOptions = await this.completeFeeOptions({
|
|
440
|
+
from: opts.from,
|
|
441
|
+
feePayer: executionPayload.feePayer,
|
|
442
|
+
gasSettings: opts.fee?.gasSettings,
|
|
443
|
+
forEstimation: true,
|
|
444
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
445
|
+
});
|
|
446
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
447
|
+
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
448
|
+
|
|
449
|
+
const chainInfo = await this.getChainInfo();
|
|
450
|
+
let blockHeader: BlockHeader;
|
|
451
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
452
|
+
// To keep things consistent, we'll always try with PXE first
|
|
453
|
+
try {
|
|
454
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
455
|
+
} catch {
|
|
456
|
+
blockHeader = (await this.aztecNode.getBlockData('latest'))!.header;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
460
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
461
|
+
optimizableCalls.length > 0
|
|
462
|
+
? simulateViaNode(
|
|
463
|
+
this.aztecNode,
|
|
464
|
+
optimizableCalls,
|
|
465
|
+
simulationOrigin,
|
|
466
|
+
chainInfo,
|
|
467
|
+
feeOptions.gasSettings,
|
|
468
|
+
blockHeader,
|
|
469
|
+
opts.skipFeeEnforcement ?? true,
|
|
470
|
+
this.getContractName.bind(this),
|
|
471
|
+
opts.overrides,
|
|
472
|
+
)
|
|
473
|
+
: Promise.resolve([]),
|
|
474
|
+
remainingCalls.length > 0
|
|
475
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
476
|
+
from: opts.from,
|
|
477
|
+
feeOptions,
|
|
478
|
+
additionalScopes: opts.additionalScopes,
|
|
479
|
+
skipTxValidation: opts.skipTxValidation,
|
|
480
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
481
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
482
|
+
overrides: opts.overrides,
|
|
483
|
+
})
|
|
484
|
+
: Promise.resolve(null),
|
|
485
|
+
]);
|
|
486
|
+
|
|
487
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
277
488
|
}
|
|
278
489
|
|
|
279
490
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
280
|
-
const feeOptions = await this.completeFeeOptions(
|
|
491
|
+
const feeOptions = await this.completeFeeOptions({
|
|
492
|
+
from: opts.from,
|
|
493
|
+
feePayer: executionPayload.feePayer,
|
|
494
|
+
gasSettings: opts.fee?.gasSettings,
|
|
495
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
496
|
+
});
|
|
281
497
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
282
|
-
return this.pxe.profileTx(txRequest,
|
|
498
|
+
return this.pxe.profileTx(txRequest, {
|
|
499
|
+
profileMode: opts.profileMode,
|
|
500
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
501
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
502
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
503
|
+
});
|
|
283
504
|
}
|
|
284
505
|
|
|
285
|
-
async sendTx
|
|
286
|
-
|
|
506
|
+
public async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
507
|
+
executionPayload: ExecutionPayload,
|
|
508
|
+
opts: SendOptions<W>,
|
|
509
|
+
): Promise<SendReturn<W>> {
|
|
510
|
+
const feeOptions = await this.completeFeeOptions({
|
|
511
|
+
from: opts.from,
|
|
512
|
+
feePayer: executionPayload.feePayer,
|
|
513
|
+
gasSettings: opts.fee?.gasSettings,
|
|
514
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
515
|
+
});
|
|
287
516
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
288
|
-
const provenTx = await this.pxe.proveTx(txRequest
|
|
517
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
518
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
519
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
520
|
+
});
|
|
521
|
+
const offchainOutput = extractOffchainOutput(
|
|
522
|
+
provenTx.getOffchainEffects(),
|
|
523
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
524
|
+
);
|
|
289
525
|
const tx = await provenTx.toTx();
|
|
290
526
|
const txHash = tx.getTxHash();
|
|
291
|
-
if (await this.aztecNode.
|
|
527
|
+
if ((await this.aztecNode.getTxReceipt(txHash)).isMined()) {
|
|
292
528
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
293
529
|
}
|
|
294
530
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
@@ -296,7 +532,43 @@ export abstract class BaseWallet implements Wallet {
|
|
|
296
532
|
throw this.contextualizeError(err, inspect(tx));
|
|
297
533
|
});
|
|
298
534
|
this.log.info(`Sent transaction ${txHash}`);
|
|
299
|
-
|
|
535
|
+
|
|
536
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
537
|
+
if (opts.wait === NO_WAIT) {
|
|
538
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
542
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
543
|
+
const waitOpts =
|
|
544
|
+
this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined
|
|
545
|
+
? { ...callerWaitOpts, interval: this.defaultWaitInterval }
|
|
546
|
+
: callerWaitOpts;
|
|
547
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
548
|
+
|
|
549
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
550
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
551
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
559
|
+
* @param address - The contract address to resolve.
|
|
560
|
+
*/
|
|
561
|
+
protected async getContractName(address: AztecAddress): Promise<string | undefined> {
|
|
562
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
563
|
+
if (!instance) {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
567
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
568
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
569
|
+
// want to fallback to the current class.
|
|
570
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
571
|
+
return artifact?.name;
|
|
300
572
|
}
|
|
301
573
|
|
|
302
574
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -313,12 +585,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
313
585
|
return err;
|
|
314
586
|
}
|
|
315
587
|
|
|
316
|
-
|
|
317
|
-
return this.pxe.
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
321
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
588
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
589
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
322
590
|
}
|
|
323
591
|
|
|
324
592
|
async getPrivateEvents<T>(
|
|
@@ -341,26 +609,40 @@ export abstract class BaseWallet implements Wallet {
|
|
|
341
609
|
return decodedEvents;
|
|
342
610
|
}
|
|
343
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
614
|
+
* @param address - The contract address to query.
|
|
615
|
+
*/
|
|
344
616
|
async getContractMetadata(address: AztecAddress) {
|
|
345
617
|
const instance = await this.pxe.getContractInstance(address);
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
618
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
619
|
+
|
|
620
|
+
let initializationStatus: ContractInitializationStatus;
|
|
621
|
+
if (instance) {
|
|
622
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
623
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
624
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
625
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
626
|
+
initializationStatus = witness
|
|
627
|
+
? ContractInitializationStatus.INITIALIZED
|
|
628
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
629
|
+
} else {
|
|
630
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
631
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
632
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
633
|
+
// uninitialized.
|
|
634
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
635
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
636
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
637
|
+
}
|
|
638
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
356
639
|
const isContractUpdated =
|
|
357
640
|
publiclyRegisteredContract &&
|
|
358
641
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
359
642
|
return {
|
|
360
643
|
instance: instance ?? undefined,
|
|
361
|
-
|
|
644
|
+
initializationStatus,
|
|
362
645
|
isContractPublished: !!publiclyRegisteredContract,
|
|
363
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
364
646
|
isContractUpdated: !!isContractUpdated,
|
|
365
647
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
|
366
648
|
};
|