@aztec/wallet-sdk 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e
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 +217 -294
- package/dest/base-wallet/base_wallet.d.ts +61 -16
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +172 -38
- 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 +59 -50
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +202 -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 +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/{providers/extension → extension/provider}/extension_wallet.js +57 -97
- 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/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 +91 -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 +174 -44
- package/dest/types.d.ts +43 -12
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -2
- package/package.json +17 -10
- package/src/base-wallet/base_wallet.ts +245 -76
- package/src/base-wallet/index.ts +2 -1
- package/src/base-wallet/utils.ts +238 -0
- package/src/crypto.ts +237 -113
- 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/{providers/extension → extension/provider}/extension_wallet.ts +61 -111
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +2 -10
- package/src/manager/types.ts +94 -8
- package/src/manager/wallet_manager.ts +190 -46
- package/src/types.ts +44 -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
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACpC,uCAAuC;IACvC,kBAAkB,oCAAoC;IACtD,sEAAsE;IACtE,oBAAoB,sCAAsC;IAC1D,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACpC,uCAAuC;IACvC,kBAAkB,oCAAoC;IACtD,sEAAsE;IACtE,UAAU,4BAA4B;IACtC,oDAAoD;IACpD,oBAAoB,sCAAsC;IAC1D,qDAAqD;IACrD,qBAAqB,uCAAuC;CAC7D;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,gEAAgE;IAChE,SAAS,EAAE,iBAAiB,CAAC;IAC7B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,wBAAwB;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC;IAClC,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,IAAI,EAAE,iBAAiB,CAAC,kBAAkB,CAAC;IAC3C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mBAAmB;IACnB,IAAI,EAAE,iBAAiB,CAAC,oBAAoB,CAAC;IAC7C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mBAAmB;IACnB,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC;IAC9C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,SAAS,EAAE,iBAAiB,CAAC;CAC9B"}
|
package/dest/types.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/ export var WalletMessageType = /*#__PURE__*/ function(WalletMessageType) {
|
|
5
5
|
/** Discovery request to find installed wallets */ WalletMessageType["DISCOVERY"] = "aztec-wallet-discovery";
|
|
6
6
|
/** Discovery response from a wallet */ WalletMessageType["DISCOVERY_RESPONSE"] = "aztec-wallet-discovery-response";
|
|
7
|
-
/**
|
|
8
|
-
/**
|
|
7
|
+
/** Disconnect message (unencrypted control message, bidirectional) */ WalletMessageType["DISCONNECT"] = "aztec-wallet-disconnect";
|
|
8
|
+
/** Key exchange request sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_REQUEST"] = "aztec-wallet-key-exchange-request";
|
|
9
|
+
/** Key exchange response sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_RESPONSE"] = "aztec-wallet-key-exchange-response";
|
|
9
10
|
return WalletMessageType;
|
|
10
11
|
}({});
|
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallet-sdk",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
|
|
4
|
-
"version": "0.0.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.35158ae7e",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
8
|
-
"./
|
|
8
|
+
"./extension/handlers": "./dest/extension/handlers/index.js",
|
|
9
|
+
"./extension/provider": "./dest/extension/provider/index.js",
|
|
9
10
|
"./crypto": "./dest/crypto.js",
|
|
10
11
|
"./types": "./dest/types.js",
|
|
11
12
|
"./manager": "./dest/manager/index.js"
|
|
12
13
|
},
|
|
13
14
|
"typedocOptions": {
|
|
14
15
|
"entryPoints": [
|
|
15
|
-
"./src/index.ts"
|
|
16
|
+
"./src/base-wallet/index.ts",
|
|
17
|
+
"./src/extension/handlers/index.ts",
|
|
18
|
+
"./src/extension/provider/index.ts",
|
|
19
|
+
"./src/crypto.ts",
|
|
20
|
+
"./src/types.ts",
|
|
21
|
+
"./src/manager/index.ts"
|
|
16
22
|
],
|
|
23
|
+
"name": "Wallet SDK",
|
|
17
24
|
"tsconfig": "./tsconfig.json"
|
|
18
25
|
},
|
|
19
26
|
"scripts": {
|
|
@@ -64,15 +71,15 @@
|
|
|
64
71
|
]
|
|
65
72
|
},
|
|
66
73
|
"dependencies": {
|
|
67
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
68
|
-
"@aztec/constants": "0.0.1-commit.
|
|
69
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
70
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
71
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
72
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
74
|
+
"@aztec/aztec.js": "0.0.1-commit.35158ae7e",
|
|
75
|
+
"@aztec/constants": "0.0.1-commit.35158ae7e",
|
|
76
|
+
"@aztec/entrypoints": "0.0.1-commit.35158ae7e",
|
|
77
|
+
"@aztec/foundation": "0.0.1-commit.35158ae7e",
|
|
78
|
+
"@aztec/pxe": "0.0.1-commit.35158ae7e",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.35158ae7e"
|
|
73
80
|
},
|
|
74
81
|
"devDependencies": {
|
|
75
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
82
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.35158ae7e",
|
|
76
83
|
"@jest/globals": "^30.0.0",
|
|
77
84
|
"@types/jest": "^30.0.0",
|
|
78
85
|
"@types/node": "^22.15.17",
|
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import type { Account } from '@aztec/aztec.js/account';
|
|
1
|
+
import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
3
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
12
|
+
import {
|
|
13
|
+
type Aliased,
|
|
14
|
+
type AppCapabilities,
|
|
15
|
+
type BatchResults,
|
|
16
|
+
type BatchedMethod,
|
|
17
|
+
ContractInitializationStatus,
|
|
18
|
+
type ExecuteUtilityOptions,
|
|
19
|
+
type PrivateEvent,
|
|
20
|
+
type PrivateEventFilter,
|
|
21
|
+
type ProfileOptions,
|
|
22
|
+
type SendOptions,
|
|
23
|
+
type SimulateOptions,
|
|
24
|
+
type Wallet,
|
|
25
|
+
type WalletCapabilities,
|
|
14
26
|
} from '@aztec/aztec.js/wallet';
|
|
15
27
|
import {
|
|
16
28
|
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
@@ -19,10 +31,12 @@ import {
|
|
|
19
31
|
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
|
|
20
32
|
} from '@aztec/constants';
|
|
21
33
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
34
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
22
35
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
23
36
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
24
37
|
import { createLogger } from '@aztec/foundation/log';
|
|
25
38
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
39
|
+
import { type AccessScopes, displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
26
40
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
27
41
|
import {
|
|
28
42
|
type ContractArtifact,
|
|
@@ -31,7 +45,7 @@ import {
|
|
|
31
45
|
decodeFromAbi,
|
|
32
46
|
} from '@aztec/stdlib/abi';
|
|
33
47
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
34
|
-
import
|
|
48
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
35
49
|
import {
|
|
36
50
|
type ContractInstanceWithAddress,
|
|
37
51
|
computePartialAddress,
|
|
@@ -39,20 +53,24 @@ import {
|
|
|
39
53
|
} from '@aztec/stdlib/contract';
|
|
40
54
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
41
55
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
42
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
computeSiloedPrivateInitializationNullifier,
|
|
58
|
+
computeSiloedPublicInitializationNullifier,
|
|
59
|
+
} from '@aztec/stdlib/hash';
|
|
43
60
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
44
|
-
import
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
TxProfileResult,
|
|
48
|
-
TxReceipt,
|
|
61
|
+
import {
|
|
62
|
+
BlockHeader,
|
|
63
|
+
type TxExecutionRequest,
|
|
64
|
+
type TxProfileResult,
|
|
49
65
|
TxSimulationResult,
|
|
50
|
-
|
|
66
|
+
type UtilityExecutionResult,
|
|
51
67
|
} from '@aztec/stdlib/tx';
|
|
52
68
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
53
69
|
|
|
54
70
|
import { inspect } from 'util';
|
|
55
71
|
|
|
72
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
73
|
+
|
|
56
74
|
/**
|
|
57
75
|
* Options to configure fee payment for a transaction
|
|
58
76
|
*/
|
|
@@ -63,17 +81,25 @@ export type FeeOptions = {
|
|
|
63
81
|
*/
|
|
64
82
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
65
83
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
66
|
-
accountFeePaymentMethodOptions
|
|
84
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
67
85
|
/** The gas settings to use for the transaction */
|
|
68
86
|
gasSettings: GasSettings;
|
|
69
87
|
};
|
|
70
88
|
|
|
89
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
90
|
+
export type SimulateViaEntrypointOptions = Pick<
|
|
91
|
+
SimulateOptions,
|
|
92
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
93
|
+
> & {
|
|
94
|
+
/** Fee options for the entrypoint */
|
|
95
|
+
feeOptions: FeeOptions;
|
|
96
|
+
/** Scopes to use for the simulation */
|
|
97
|
+
scopes: AccessScopes;
|
|
98
|
+
};
|
|
71
99
|
/**
|
|
72
100
|
* A base class for Wallet implementations
|
|
73
101
|
*/
|
|
74
102
|
export abstract class BaseWallet implements Wallet {
|
|
75
|
-
protected log = createLogger('wallet-sdk:base_wallet');
|
|
76
|
-
|
|
77
103
|
protected minFeePadding = 0.5;
|
|
78
104
|
protected cancellableTransactions = false;
|
|
79
105
|
|
|
@@ -81,8 +107,15 @@ export abstract class BaseWallet implements Wallet {
|
|
|
81
107
|
protected constructor(
|
|
82
108
|
protected readonly pxe: PXE,
|
|
83
109
|
protected readonly aztecNode: AztecNode,
|
|
110
|
+
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
84
111
|
) {}
|
|
85
112
|
|
|
113
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
114
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
115
|
+
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
116
|
+
return [...scopeSet].map(AztecAddress.fromString);
|
|
117
|
+
}
|
|
118
|
+
|
|
86
119
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
87
120
|
|
|
88
121
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -106,26 +139,33 @@ export abstract class BaseWallet implements Wallet {
|
|
|
106
139
|
|
|
107
140
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
108
141
|
executionPayload: ExecutionPayload,
|
|
109
|
-
from: AztecAddress,
|
|
142
|
+
from: AztecAddress | NoFrom,
|
|
110
143
|
feeOptions: FeeOptions,
|
|
111
144
|
): Promise<TxExecutionRequest> {
|
|
112
145
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
113
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
114
|
-
txNonce: Fr.random(),
|
|
115
|
-
cancellable: this.cancellableTransactions,
|
|
116
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
117
|
-
};
|
|
118
146
|
const finalExecutionPayload = feeExecutionPayload
|
|
119
147
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
120
148
|
: executionPayload;
|
|
121
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
122
149
|
const chainInfo = await this.getChainInfo();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
chainInfo
|
|
127
|
-
|
|
128
|
-
|
|
150
|
+
|
|
151
|
+
if (from === NO_FROM) {
|
|
152
|
+
const entrypoint = new DefaultEntrypoint();
|
|
153
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
154
|
+
} else {
|
|
155
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
156
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
157
|
+
txNonce: Fr.random(),
|
|
158
|
+
cancellable: this.cancellableTransactions,
|
|
159
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
160
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
161
|
+
};
|
|
162
|
+
return fromAccount.createTxExecutionRequest(
|
|
163
|
+
finalExecutionPayload,
|
|
164
|
+
feeOptions.gasSettings,
|
|
165
|
+
chainInfo,
|
|
166
|
+
executionOptions,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
129
169
|
}
|
|
130
170
|
|
|
131
171
|
public async createAuthWit(
|
|
@@ -137,6 +177,23 @@ export abstract class BaseWallet implements Wallet {
|
|
|
137
177
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
138
178
|
}
|
|
139
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Request capabilities from the wallet.
|
|
182
|
+
*
|
|
183
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
184
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
185
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
186
|
+
* friction by allowing apps to request permissions upfront.
|
|
187
|
+
*
|
|
188
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
189
|
+
* while the feature stabilizes.
|
|
190
|
+
*
|
|
191
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
192
|
+
*/
|
|
193
|
+
public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
194
|
+
throw new Error('Not implemented');
|
|
195
|
+
}
|
|
196
|
+
|
|
140
197
|
public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
141
198
|
const results: any[] = [];
|
|
142
199
|
for (const method of methods) {
|
|
@@ -163,23 +220,27 @@ export abstract class BaseWallet implements Wallet {
|
|
|
163
220
|
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
164
221
|
*/
|
|
165
222
|
protected async completeFeeOptions(
|
|
166
|
-
from: AztecAddress,
|
|
223
|
+
from: AztecAddress | NoFrom,
|
|
167
224
|
feePayer?: AztecAddress,
|
|
168
225
|
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
169
226
|
): Promise<FeeOptions> {
|
|
170
227
|
const maxFeesPerGas =
|
|
171
228
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
172
229
|
let accountFeePaymentMethodOptions;
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
230
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
231
|
+
// account contract entrypoint to use
|
|
232
|
+
if (from !== NO_FROM) {
|
|
233
|
+
if (!feePayer) {
|
|
234
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
235
|
+
// for the account to use its fee juice balance
|
|
236
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
237
|
+
} else {
|
|
238
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
239
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
240
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
241
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
242
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
243
|
+
}
|
|
183
244
|
}
|
|
184
245
|
const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
|
|
185
246
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
@@ -199,7 +260,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
199
260
|
* @param gasSettings - User-provided partial gas settings
|
|
200
261
|
*/
|
|
201
262
|
protected async completeFeeOptionsForEstimation(
|
|
202
|
-
from: AztecAddress,
|
|
263
|
+
from: AztecAddress | NoFrom,
|
|
203
264
|
feePayer?: AztecAddress,
|
|
204
265
|
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
205
266
|
) {
|
|
@@ -263,29 +324,99 @@ export abstract class BaseWallet implements Wallet {
|
|
|
263
324
|
return instance;
|
|
264
325
|
}
|
|
265
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
329
|
+
* @param executionPayload - The execution payload to simulate.
|
|
330
|
+
* @param opts - Simulation options.
|
|
331
|
+
*/
|
|
332
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
333
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
334
|
+
executionPayload,
|
|
335
|
+
opts.from,
|
|
336
|
+
opts.feeOptions,
|
|
337
|
+
);
|
|
338
|
+
return this.pxe.simulateTx(txRequest, {
|
|
339
|
+
simulatePublic: true,
|
|
340
|
+
skipTxValidation: opts.skipTxValidation,
|
|
341
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
342
|
+
scopes: opts.scopes,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
348
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
349
|
+
* Return values from both paths are merged back in original call order.
|
|
350
|
+
* @param executionPayload - The execution payload to simulate.
|
|
351
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
352
|
+
* @returns The merged simulation result.
|
|
353
|
+
*/
|
|
266
354
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
267
355
|
const feeOptions = opts.fee?.estimateGas
|
|
268
356
|
? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
|
|
269
357
|
: await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
358
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
359
|
+
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
360
|
+
|
|
361
|
+
const chainInfo = await this.getChainInfo();
|
|
362
|
+
let blockHeader: BlockHeader;
|
|
363
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
364
|
+
// To keep things consistent, we'll always try with PXE first
|
|
365
|
+
try {
|
|
366
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
367
|
+
} catch {
|
|
368
|
+
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
372
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
373
|
+
optimizableCalls.length > 0
|
|
374
|
+
? simulateViaNode(
|
|
375
|
+
this.aztecNode,
|
|
376
|
+
optimizableCalls,
|
|
377
|
+
simulationOrigin,
|
|
378
|
+
chainInfo,
|
|
379
|
+
feeOptions.gasSettings,
|
|
380
|
+
blockHeader,
|
|
381
|
+
opts.skipFeeEnforcement ?? true,
|
|
382
|
+
this.getContractName.bind(this),
|
|
383
|
+
)
|
|
384
|
+
: Promise.resolve([]),
|
|
385
|
+
remainingCalls.length > 0
|
|
386
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
387
|
+
from: opts.from,
|
|
388
|
+
feeOptions,
|
|
389
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
390
|
+
skipTxValidation: opts.skipTxValidation,
|
|
391
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
392
|
+
})
|
|
393
|
+
: Promise.resolve(null),
|
|
394
|
+
]);
|
|
395
|
+
|
|
396
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
277
397
|
}
|
|
278
398
|
|
|
279
399
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
280
400
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
281
401
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
282
|
-
return this.pxe.profileTx(txRequest,
|
|
402
|
+
return this.pxe.profileTx(txRequest, {
|
|
403
|
+
profileMode: opts.profileMode,
|
|
404
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
405
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
406
|
+
});
|
|
283
407
|
}
|
|
284
408
|
|
|
285
|
-
async sendTx
|
|
409
|
+
public async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
410
|
+
executionPayload: ExecutionPayload,
|
|
411
|
+
opts: SendOptions<W>,
|
|
412
|
+
): Promise<SendReturn<W>> {
|
|
286
413
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
287
414
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
288
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
415
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
416
|
+
const offchainOutput = extractOffchainOutput(
|
|
417
|
+
provenTx.getOffchainEffects(),
|
|
418
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
419
|
+
);
|
|
289
420
|
const tx = await provenTx.toTx();
|
|
290
421
|
const txHash = tx.getTxHash();
|
|
291
422
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -296,7 +427,35 @@ export abstract class BaseWallet implements Wallet {
|
|
|
296
427
|
throw this.contextualizeError(err, inspect(tx));
|
|
297
428
|
});
|
|
298
429
|
this.log.info(`Sent transaction ${txHash}`);
|
|
299
|
-
|
|
430
|
+
|
|
431
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
432
|
+
if (opts.wait === NO_WAIT) {
|
|
433
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
437
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
438
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
439
|
+
|
|
440
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
441
|
+
if (receipt.debugLogs?.length) {
|
|
442
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
450
|
+
* @param address - The contract address to resolve.
|
|
451
|
+
*/
|
|
452
|
+
protected async getContractName(address: AztecAddress): Promise<string | undefined> {
|
|
453
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
454
|
+
if (!instance) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
458
|
+
return artifact?.name;
|
|
300
459
|
}
|
|
301
460
|
|
|
302
461
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -313,12 +472,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
313
472
|
return err;
|
|
314
473
|
}
|
|
315
474
|
|
|
316
|
-
|
|
317
|
-
return this.pxe.
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
321
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
475
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
476
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
322
477
|
}
|
|
323
478
|
|
|
324
479
|
async getPrivateEvents<T>(
|
|
@@ -341,26 +496,40 @@ export abstract class BaseWallet implements Wallet {
|
|
|
341
496
|
return decodedEvents;
|
|
342
497
|
}
|
|
343
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
501
|
+
* @param address - The contract address to query.
|
|
502
|
+
*/
|
|
344
503
|
async getContractMetadata(address: AztecAddress) {
|
|
345
504
|
const instance = await this.pxe.getContractInstance(address);
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
505
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
506
|
+
|
|
507
|
+
let initializationStatus: ContractInitializationStatus;
|
|
508
|
+
if (instance) {
|
|
509
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
510
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
511
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
512
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
513
|
+
initializationStatus = witness
|
|
514
|
+
? ContractInitializationStatus.INITIALIZED
|
|
515
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
516
|
+
} else {
|
|
517
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
518
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
519
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
520
|
+
// uninitialized.
|
|
521
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
522
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
523
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
524
|
+
}
|
|
525
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
356
526
|
const isContractUpdated =
|
|
357
527
|
publiclyRegisteredContract &&
|
|
358
528
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
359
529
|
return {
|
|
360
530
|
instance: instance ?? undefined,
|
|
361
|
-
|
|
531
|
+
initializationStatus,
|
|
362
532
|
isContractPublished: !!publiclyRegisteredContract,
|
|
363
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
364
533
|
isContractUpdated: !!isContractUpdated,
|
|
365
534
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
|
366
535
|
};
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
1
|
+
export { BaseWallet, type FeeOptions, type SimulateViaEntrypointOptions } from './base_wallet.js';
|
|
2
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|