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