@aztec/wallet-sdk 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6
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 +228 -331
- package/dest/base-wallet/base_wallet.d.ts +74 -16
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +185 -33
- package/dest/base-wallet/index.d.ts +3 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +1 -0
- package/dest/base-wallet/utils.d.ts +49 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +131 -0
- package/dest/crypto.d.ts +192 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +394 -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 +158 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +258 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +174 -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 +63 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +22 -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 +132 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/extension/provider/extension_wallet.js +278 -0
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -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 +108 -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 +178 -29
- package/dest/types.d.ts +123 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +11 -0
- package/package.json +22 -13
- package/src/base-wallet/base_wallet.ts +242 -60
- package/src/base-wallet/index.ts +2 -1
- package/src/base-wallet/utils.ts +238 -0
- package/src/crypto.ts +499 -0
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +423 -0
- package/src/extension/handlers/content_script_connection_handler.ts +246 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +69 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/extension/provider/extension_wallet.ts +329 -0
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +3 -15
- package/src/manager/types.ts +112 -4
- package/src/manager/wallet_manager.ts +202 -31
- package/src/types.ts +132 -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,19 +1,21 @@
|
|
|
1
1
|
import type { Account } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
3
4
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
4
|
-
import type { Aliased,
|
|
5
|
+
import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, ExecuteUtilityOptions, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet, WalletCapabilities } from '@aztec/aztec.js/wallet';
|
|
5
6
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
6
7
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
7
|
-
import { Fr } from '@aztec/foundation/
|
|
8
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
9
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
10
|
+
import { type AccessScopes } from '@aztec/pxe/client/lazy';
|
|
9
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
10
12
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
11
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
12
|
-
import
|
|
13
|
-
import { type
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
+
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
16
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
15
17
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
16
|
-
import type
|
|
18
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
17
19
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
18
20
|
/**
|
|
19
21
|
* Options to configure fee payment for a transaction
|
|
@@ -29,6 +31,13 @@ export type FeeOptions = {
|
|
|
29
31
|
/** The gas settings to use for the transaction */
|
|
30
32
|
gasSettings: GasSettings;
|
|
31
33
|
};
|
|
34
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
35
|
+
export type SimulateViaEntrypointOptions = Pick<SimulateOptions, 'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'> & {
|
|
36
|
+
/** Fee options for the entrypoint */
|
|
37
|
+
feeOptions: FeeOptions;
|
|
38
|
+
/** Scopes to use for the simulation */
|
|
39
|
+
scopes: AccessScopes;
|
|
40
|
+
};
|
|
32
41
|
/**
|
|
33
42
|
* A base class for Wallet implementations
|
|
34
43
|
*/
|
|
@@ -36,9 +45,10 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
36
45
|
protected readonly pxe: PXE;
|
|
37
46
|
protected readonly aztecNode: AztecNode;
|
|
38
47
|
protected log: import("@aztec/foundation/log").Logger;
|
|
39
|
-
protected
|
|
48
|
+
protected minFeePadding: number;
|
|
40
49
|
protected cancellableTransactions: boolean;
|
|
41
|
-
protected constructor(pxe: PXE, aztecNode: AztecNode);
|
|
50
|
+
protected constructor(pxe: PXE, aztecNode: AztecNode, log?: import("@aztec/foundation/log").Logger);
|
|
51
|
+
protected scopesFrom(from: AztecAddress, additionalScopes?: AztecAddress[]): AztecAddress[];
|
|
42
52
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
43
53
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
44
54
|
/**
|
|
@@ -51,8 +61,22 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
51
61
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
52
62
|
getChainInfo(): Promise<ChainInfo>;
|
|
53
63
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
54
|
-
createAuthWit(from: AztecAddress, messageHashOrIntent:
|
|
55
|
-
|
|
64
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
65
|
+
/**
|
|
66
|
+
* Request capabilities from the wallet.
|
|
67
|
+
*
|
|
68
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
69
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
70
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
71
|
+
* friction by allowing apps to request permissions upfront.
|
|
72
|
+
*
|
|
73
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
74
|
+
* while the feature stabilizes.
|
|
75
|
+
*
|
|
76
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
77
|
+
*/
|
|
78
|
+
requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
79
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
56
80
|
/**
|
|
57
81
|
* Completes partial user-provided fee options with wallet defaults.
|
|
58
82
|
* @param from - The address where the transaction is being sent from
|
|
@@ -81,14 +105,48 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
81
105
|
}>;
|
|
82
106
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
83
107
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
108
|
+
/**
|
|
109
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
110
|
+
* @param executionPayload - The execution payload to simulate.
|
|
111
|
+
* @param opts - Simulation options.
|
|
112
|
+
*/
|
|
113
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions): Promise<TxSimulationResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
116
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
117
|
+
* Return values from both paths are merged back in original call order.
|
|
118
|
+
* @param executionPayload - The execution payload to simulate.
|
|
119
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
120
|
+
* @returns The merged simulation result.
|
|
121
|
+
*/
|
|
84
122
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
85
123
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
86
|
-
sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<
|
|
124
|
+
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
125
|
+
/**
|
|
126
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
127
|
+
* @param address - The contract address to resolve.
|
|
128
|
+
*/
|
|
129
|
+
protected getContractName(address: AztecAddress): Promise<string | undefined>;
|
|
87
130
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
131
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
|
|
132
|
+
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
135
|
+
*
|
|
136
|
+
* `isContractInitialized` requires the contract instance to be registered in the PXE (for `init_hash`). When the
|
|
137
|
+
* instance is not available, `isContractInitialized` is `undefined` since it cannot be determined.
|
|
138
|
+
* @param address - The contract address to query.
|
|
139
|
+
*/
|
|
140
|
+
getContractMetadata(address: AztecAddress): Promise<{
|
|
141
|
+
instance: ContractInstanceWithAddress | undefined;
|
|
142
|
+
isContractInitialized: boolean | undefined;
|
|
143
|
+
isContractPublished: boolean;
|
|
144
|
+
isContractUpdated: boolean;
|
|
145
|
+
updatedContractClassId: Fr | undefined;
|
|
146
|
+
}>;
|
|
147
|
+
getContractClassMetadata(id: Fr): Promise<{
|
|
148
|
+
isArtifactRegistered: boolean;
|
|
149
|
+
isContractClassPubliclyRegistered: boolean;
|
|
150
|
+
}>;
|
|
93
151
|
}
|
|
94
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
152
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDakYsT0FBTyxFQUNMLEtBQUssc0JBQXNCLEVBRTNCLEtBQUssVUFBVSxFQUVoQixNQUFNLDJCQUEyQixDQUFDO0FBQ25DLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFNUQsT0FBTyxLQUFLLEVBQ1YsT0FBTyxFQUNQLGVBQWUsRUFDZixZQUFZLEVBQ1osYUFBYSxFQUNiLHFCQUFxQixFQUNyQixZQUFZLEVBQ1osa0JBQWtCLEVBQ2xCLGNBQWMsRUFDZCxXQUFXLEVBQ1gsZUFBZSxFQUNmLE1BQU0sRUFDTixrQkFBa0IsRUFDbkIsTUFBTSx3QkFBd0IsQ0FBQztBQU9oQyxPQUFPLEVBQUUsOEJBQThCLEVBQXdDLE1BQU0sNEJBQTRCLENBQUM7QUFDbEgsT0FBTyxLQUFLLEVBQUUsU0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8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUMsQ0FPbEY7SUFFRCxTQUFTLENBQUMsa0JBQWtCLENBQUMsR0FBRyxFQUFFLEtBQUssRUFBRSxHQUFHLE9BQU8sRUFBRSxNQUFNLEVBQUUsR0FBRyxLQUFLLENBWXBFO0lBRUQsY0FBYyxDQUFDLElBQUksRUFBRSxZQUFZLEVBQUUsSUFBSSxFQUFFLHFCQUFxQixHQUFHLE9BQU8sQ0FBQyxzQkFBc0IsQ0FBQyxDQUUvRjtJQUVLLGdCQUFnQixDQUFDLENBQUMsRUFDdEIsUUFBUSxFQUFFLHVCQUF1QixFQUNqQyxXQUFXLEVBQUUsa0JBQWtCLEdBQzlCLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQWU1QjtJQUVEOzs7Ozs7T0FNRztJQUNHLG1CQUFtQixDQUFDLE9BQU8sRUFBRSxZQUFZOzs7Ozs7T0EyQjlDO0lBRUssd0JBQXdCLENBQUMsRUFBRSxFQUFFLEVBQUU7OztPQU1wQztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,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AAI,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA0CvG;IAEK,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAQlG;IAEY,MAAM,CAAC,CAAC,SAAS,sBAAsB,GAAG,SAAS,EAC9D,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAkCxB;IAED;;;OAGG;IACH,UAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAOlF;IAED,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,CAYpE;IAED,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAE/F;IAEK,gBAAgB,CAAC,CAAC,EACtB,QAAQ,EAAE,uBAAuB,EACjC,WAAW,EAAE,kBAAkB,GAC9B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAe5B;IAED;;;;;;OAMG;IACG,mBAAmB,CAAC,OAAO,EAAE,YAAY;;;;;;OA2B9C;IAEK,wBAAwB,CAAC,EAAE,EAAE,EAAE;;;OAMpC;CACF"}
|
|
@@ -1,29 +1,45 @@
|
|
|
1
|
+
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
1
3
|
import { GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
|
|
2
4
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
5
8
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
9
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
10
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
7
11
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
12
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
13
|
+
import { computeSiloedPrivateInitializationNullifier } from '@aztec/stdlib/hash';
|
|
9
14
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
10
15
|
import { inspect } from 'util';
|
|
16
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
11
17
|
/**
|
|
12
18
|
* A base class for Wallet implementations
|
|
13
19
|
*/ export class BaseWallet {
|
|
14
20
|
pxe;
|
|
15
21
|
aztecNode;
|
|
16
22
|
log;
|
|
17
|
-
|
|
23
|
+
minFeePadding;
|
|
18
24
|
cancellableTransactions;
|
|
19
25
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
20
|
-
constructor(pxe, aztecNode){
|
|
26
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
21
27
|
this.pxe = pxe;
|
|
22
28
|
this.aztecNode = aztecNode;
|
|
23
|
-
this.log =
|
|
24
|
-
this.
|
|
29
|
+
this.log = log;
|
|
30
|
+
this.minFeePadding = 0.5;
|
|
25
31
|
this.cancellableTransactions = false;
|
|
26
32
|
}
|
|
33
|
+
scopesFrom(from, additionalScopes = []) {
|
|
34
|
+
const allScopes = from.isZero() ? additionalScopes : [
|
|
35
|
+
from,
|
|
36
|
+
...additionalScopes
|
|
37
|
+
];
|
|
38
|
+
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
39
|
+
return [
|
|
40
|
+
...scopeSet
|
|
41
|
+
].map(AztecAddress.fromString);
|
|
42
|
+
}
|
|
27
43
|
/**
|
|
28
44
|
* Returns the list of aliased contacts associated with the wallet.
|
|
29
45
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -56,11 +72,28 @@ import { inspect } from 'util';
|
|
|
56
72
|
executionPayload
|
|
57
73
|
]) : executionPayload;
|
|
58
74
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
59
|
-
|
|
75
|
+
const chainInfo = await this.getChainInfo();
|
|
76
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
60
77
|
}
|
|
61
78
|
async createAuthWit(from, messageHashOrIntent) {
|
|
62
79
|
const account = await this.getAccountFromAddress(from);
|
|
63
|
-
|
|
80
|
+
const chainInfo = await this.getChainInfo();
|
|
81
|
+
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Request capabilities from the wallet.
|
|
85
|
+
*
|
|
86
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
87
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
88
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
89
|
+
* friction by allowing apps to request permissions upfront.
|
|
90
|
+
*
|
|
91
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
92
|
+
* while the feature stabilizes.
|
|
93
|
+
*
|
|
94
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
95
|
+
*/ requestCapabilities(_manifest) {
|
|
96
|
+
throw new Error('Not implemented');
|
|
64
97
|
}
|
|
65
98
|
async batch(methods) {
|
|
66
99
|
const results = [];
|
|
@@ -88,7 +121,7 @@ import { inspect } from 'util';
|
|
|
88
121
|
* @param gasSettings - User-provided partial gas settings
|
|
89
122
|
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
90
123
|
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
91
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.
|
|
124
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
92
125
|
let accountFeePaymentMethodOptions;
|
|
93
126
|
// The transaction does not include a fee payment method, so we set the flag
|
|
94
127
|
// for the account to use its fee juice balance
|
|
@@ -132,7 +165,7 @@ import { inspect } from 'util';
|
|
|
132
165
|
return this.pxe.registerSender(address);
|
|
133
166
|
}
|
|
134
167
|
async registerContract(instance, artifact, secretKey) {
|
|
135
|
-
const
|
|
168
|
+
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
136
169
|
if (existingInstance) {
|
|
137
170
|
// Instance already registered in the wallet
|
|
138
171
|
if (artifact) {
|
|
@@ -148,11 +181,10 @@ import { inspect } from 'util';
|
|
|
148
181
|
// Instance not registered yet
|
|
149
182
|
if (!artifact) {
|
|
150
183
|
// Try to get the artifact from the wallet's contract class storage
|
|
151
|
-
|
|
152
|
-
if (!
|
|
184
|
+
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
185
|
+
if (!artifact) {
|
|
153
186
|
throw new Error(`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()}`);
|
|
154
187
|
}
|
|
155
|
-
artifact = classMetadata.artifact;
|
|
156
188
|
}
|
|
157
189
|
await this.pxe.registerContract({
|
|
158
190
|
artifact,
|
|
@@ -164,20 +196,68 @@ import { inspect } from 'util';
|
|
|
164
196
|
}
|
|
165
197
|
return instance;
|
|
166
198
|
}
|
|
167
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
201
|
+
* @param executionPayload - The execution payload to simulate.
|
|
202
|
+
* @param opts - Simulation options.
|
|
203
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
204
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, opts.feeOptions);
|
|
205
|
+
return this.pxe.simulateTx(txRequest, {
|
|
206
|
+
simulatePublic: true,
|
|
207
|
+
skipTxValidation: opts.skipTxValidation,
|
|
208
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
209
|
+
scopes: opts.scopes
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
214
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
215
|
+
* Return values from both paths are merged back in original call order.
|
|
216
|
+
* @param executionPayload - The execution payload to simulate.
|
|
217
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
218
|
+
* @returns The merged simulation result.
|
|
219
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
168
220
|
const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
169
|
-
const
|
|
170
|
-
|
|
221
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
222
|
+
const remainingPayload = {
|
|
223
|
+
...executionPayload,
|
|
224
|
+
calls: remainingCalls
|
|
225
|
+
};
|
|
226
|
+
const chainInfo = await this.getChainInfo();
|
|
227
|
+
let blockHeader;
|
|
228
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
229
|
+
// To keep things consistent, we'll always try with PXE first
|
|
230
|
+
try {
|
|
231
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
232
|
+
} catch {
|
|
233
|
+
blockHeader = await this.aztecNode.getBlockHeader();
|
|
234
|
+
}
|
|
235
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
236
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, opts.from, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this)) : Promise.resolve([]),
|
|
237
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, {
|
|
238
|
+
from: opts.from,
|
|
239
|
+
feeOptions,
|
|
240
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
241
|
+
skipTxValidation: opts.skipTxValidation,
|
|
242
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true
|
|
243
|
+
}) : Promise.resolve(null)
|
|
244
|
+
]);
|
|
245
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
171
246
|
}
|
|
172
247
|
async profileTx(executionPayload, opts) {
|
|
173
248
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
174
249
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
175
|
-
return this.pxe.profileTx(txRequest,
|
|
250
|
+
return this.pxe.profileTx(txRequest, {
|
|
251
|
+
profileMode: opts.profileMode,
|
|
252
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
253
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
254
|
+
});
|
|
176
255
|
}
|
|
177
256
|
async sendTx(executionPayload, opts) {
|
|
178
257
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
179
258
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
180
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
259
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
260
|
+
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
181
261
|
const tx = await provenTx.toTx();
|
|
182
262
|
const txHash = tx.getTxHash();
|
|
183
263
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -188,7 +268,35 @@ import { inspect } from 'util';
|
|
|
188
268
|
throw this.contextualizeError(err, inspect(tx));
|
|
189
269
|
});
|
|
190
270
|
this.log.info(`Sent transaction ${txHash}`);
|
|
191
|
-
return txHash
|
|
271
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
272
|
+
if (opts.wait === NO_WAIT) {
|
|
273
|
+
return {
|
|
274
|
+
txHash,
|
|
275
|
+
...offchainOutput
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
279
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
280
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
281
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
282
|
+
if (receipt.debugLogs?.length) {
|
|
283
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
receipt,
|
|
287
|
+
...offchainOutput
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
292
|
+
* @param address - The contract address to resolve.
|
|
293
|
+
*/ async getContractName(address) {
|
|
294
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
295
|
+
if (!instance) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
299
|
+
return artifact?.name;
|
|
192
300
|
}
|
|
193
301
|
contextualizeError(err, ...context) {
|
|
194
302
|
let contextStr = '';
|
|
@@ -203,23 +311,67 @@ import { inspect } from 'util';
|
|
|
203
311
|
}
|
|
204
312
|
return err;
|
|
205
313
|
}
|
|
206
|
-
|
|
207
|
-
return this.pxe.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
314
|
+
executeUtility(call, opts) {
|
|
315
|
+
return this.pxe.executeUtility(call, {
|
|
316
|
+
authwits: opts.authWitnesses,
|
|
317
|
+
scopes: [
|
|
318
|
+
opts.scope
|
|
319
|
+
]
|
|
320
|
+
});
|
|
211
321
|
}
|
|
212
|
-
|
|
213
|
-
|
|
322
|
+
async getPrivateEvents(eventDef, eventFilter) {
|
|
323
|
+
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
324
|
+
const decodedEvents = pxeEvents.map((pxeEvent)=>{
|
|
325
|
+
return {
|
|
326
|
+
event: decodeFromAbi([
|
|
327
|
+
eventDef.abiType
|
|
328
|
+
], pxeEvent.packedEvent),
|
|
329
|
+
metadata: {
|
|
330
|
+
l2BlockNumber: pxeEvent.l2BlockNumber,
|
|
331
|
+
l2BlockHash: pxeEvent.l2BlockHash,
|
|
332
|
+
txHash: pxeEvent.txHash
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
return decodedEvents;
|
|
214
337
|
}
|
|
215
|
-
|
|
216
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
340
|
+
*
|
|
341
|
+
* `isContractInitialized` requires the contract instance to be registered in the PXE (for `init_hash`). When the
|
|
342
|
+
* instance is not available, `isContractInitialized` is `undefined` since it cannot be determined.
|
|
343
|
+
* @param address - The contract address to query.
|
|
344
|
+
*/ async getContractMetadata(address) {
|
|
345
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
346
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
347
|
+
// We check only the private initialization nullifier. It is emitted by both private and public initializers and
|
|
348
|
+
// includes init_hash, preventing observers from determining initialization status from the address alone. Without
|
|
349
|
+
// the instance (and thus init_hash), we can't compute it, so we return undefined.
|
|
350
|
+
//
|
|
351
|
+
// We skip the public initialization nullifier because it's not always emitted (contracts without public external
|
|
352
|
+
// functions that require initialization checks won't emit it). If the private one exists, the public one was
|
|
353
|
+
// created in the same tx and will also be present.
|
|
354
|
+
let isContractInitialized = undefined;
|
|
355
|
+
if (instance) {
|
|
356
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
357
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
358
|
+
isContractInitialized = !!witness;
|
|
359
|
+
}
|
|
360
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
361
|
+
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
362
|
+
return {
|
|
363
|
+
instance: instance ?? undefined,
|
|
364
|
+
isContractInitialized,
|
|
365
|
+
isContractPublished: !!publiclyRegisteredContract,
|
|
366
|
+
isContractUpdated: !!isContractUpdated,
|
|
367
|
+
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
368
|
+
};
|
|
217
369
|
}
|
|
218
|
-
async
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
370
|
+
async getContractClassMetadata(id) {
|
|
371
|
+
const publiclyRegisteredContractClass = await this.aztecNode.getContractClass(id);
|
|
372
|
+
return {
|
|
373
|
+
isArtifactRegistered: !!await this.pxe.getContractArtifact(id),
|
|
374
|
+
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass
|
|
375
|
+
};
|
|
224
376
|
}
|
|
225
377
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
2
|
-
|
|
1
|
+
export { BaseWallet, type FeeOptions, type SimulateViaEntrypointOptions } from './base_wallet.js';
|
|
2
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLEtBQUssVUFBVSxFQUFFLEtBQUssNEJBQTRCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNsRyxPQUFPLEVBQUUsZUFBZSxFQUFFLDJCQUEyQixFQUFFLG1DQUFtQyxFQUFFLE1BQU0sWUFBWSxDQUFDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
4
|
+
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
7
|
+
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
/**
|
|
9
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
10
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
11
|
+
*
|
|
12
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
13
|
+
* Any non-public-static call may enqueue public state mutations
|
|
14
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
15
|
+
* must go through the normal simulation path to see the correct state.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
19
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
20
|
+
optimizableCalls: FunctionCall[];
|
|
21
|
+
/** All remaining calls. */
|
|
22
|
+
remainingCalls: FunctionCall[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
26
|
+
* and sending each batch directly to the node.
|
|
27
|
+
*
|
|
28
|
+
* @param node - The Aztec node to simulate on.
|
|
29
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
30
|
+
* @param from - The account address making the calls.
|
|
31
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
32
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
33
|
+
* @param blockHeader - Block header to use as anchor.
|
|
34
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
35
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
36
|
+
*/
|
|
37
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver): Promise<TxSimulationResult[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
40
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
41
|
+
* concatenated: optimized first, then normal.
|
|
42
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
43
|
+
*
|
|
44
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
45
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
46
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResult | null): TxSimulationResult;
|
|
49
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUV0RCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBT3JCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lB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