@aztec/wallet-sdk 3.0.0-nightly.20251122
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 +424 -0
- package/dest/base-wallet/base_wallet.d.ts +94 -0
- package/dest/base-wallet/base_wallet.d.ts.map +1 -0
- package/dest/base-wallet/base_wallet.js +225 -0
- package/dest/base-wallet/index.d.ts +2 -0
- package/dest/base-wallet/index.d.ts.map +1 -0
- package/dest/base-wallet/index.js +1 -0
- package/dest/manager/index.d.ts +8 -0
- package/dest/manager/index.d.ts.map +1 -0
- package/dest/manager/index.js +5 -0
- package/dest/manager/types.d.ts +64 -0
- package/dest/manager/types.d.ts.map +1 -0
- package/dest/manager/types.js +3 -0
- package/dest/manager/wallet_manager.d.ts +27 -0
- package/dest/manager/wallet_manager.d.ts.map +1 -0
- package/dest/manager/wallet_manager.js +77 -0
- package/dest/providers/extension/extension_provider.d.ts +17 -0
- package/dest/providers/extension/extension_provider.d.ts.map +1 -0
- package/dest/providers/extension/extension_provider.js +56 -0
- package/dest/providers/extension/extension_wallet.d.ts +23 -0
- package/dest/providers/extension/extension_wallet.d.ts.map +1 -0
- package/dest/providers/extension/extension_wallet.js +96 -0
- package/dest/providers/extension/index.d.ts +4 -0
- package/dest/providers/extension/index.d.ts.map +1 -0
- package/dest/providers/extension/index.js +2 -0
- package/dest/providers/types.d.ts +67 -0
- package/dest/providers/types.d.ts.map +1 -0
- package/dest/providers/types.js +3 -0
- package/package.json +95 -0
- package/src/base-wallet/base_wallet.ts +342 -0
- package/src/base-wallet/index.ts +1 -0
- package/src/manager/index.ts +24 -0
- package/src/manager/types.ts +69 -0
- package/src/manager/wallet_manager.ts +86 -0
- package/src/providers/extension/extension_provider.ts +72 -0
- package/src/providers/extension/extension_wallet.ts +124 -0
- package/src/providers/extension/index.ts +3 -0
- package/src/providers/types.ts +71 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
|
+
/**
|
|
3
|
+
* Information about an installed Aztec wallet wallet
|
|
4
|
+
*/
|
|
5
|
+
export interface WalletInfo {
|
|
6
|
+
/** Unique identifier for the wallet */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Display name of the wallet */
|
|
9
|
+
name: string;
|
|
10
|
+
/** URL to the wallet's icon */
|
|
11
|
+
icon?: string;
|
|
12
|
+
/** Wallet version */
|
|
13
|
+
version: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Message format for wallet communication
|
|
17
|
+
*/
|
|
18
|
+
export interface WalletMessage {
|
|
19
|
+
/** Unique message ID for tracking responses */
|
|
20
|
+
messageId: string;
|
|
21
|
+
/** The wallet method to call */
|
|
22
|
+
type: string;
|
|
23
|
+
/** Arguments for the method */
|
|
24
|
+
args: unknown[];
|
|
25
|
+
/** Chain information */
|
|
26
|
+
chainInfo: ChainInfo;
|
|
27
|
+
/** Application ID making the request */
|
|
28
|
+
appId: string;
|
|
29
|
+
/** Wallet ID to target a specific wallet */
|
|
30
|
+
walletId: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Response message from wallet
|
|
34
|
+
*/
|
|
35
|
+
export interface WalletResponse {
|
|
36
|
+
/** Message ID matching the request */
|
|
37
|
+
messageId: string;
|
|
38
|
+
/** Result data (if successful) */
|
|
39
|
+
result?: unknown;
|
|
40
|
+
/** Error data (if failed) */
|
|
41
|
+
error?: unknown;
|
|
42
|
+
/** Wallet ID that sent the response */
|
|
43
|
+
walletId: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Discovery message for finding installed wallets
|
|
47
|
+
*/
|
|
48
|
+
export interface DiscoveryRequest {
|
|
49
|
+
/** Message type for discovery */
|
|
50
|
+
type: 'aztec-wallet-discovery';
|
|
51
|
+
/** Request ID */
|
|
52
|
+
requestId: string;
|
|
53
|
+
/** Chain information to check if wallet supports this network */
|
|
54
|
+
chainInfo: ChainInfo;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Discovery response from an wallet
|
|
58
|
+
*/
|
|
59
|
+
export interface DiscoveryResponse {
|
|
60
|
+
/** Message type for discovery response */
|
|
61
|
+
type: 'aztec-wallet-discovery-response';
|
|
62
|
+
/** Request ID matching the discovery request */
|
|
63
|
+
requestId: string;
|
|
64
|
+
/** Wallet information */
|
|
65
|
+
walletInfo: WalletInfo;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;GAEG;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;;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,wBAAwB,CAAC;IAC/B,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,IAAI,EAAE,iCAAiC,CAAC;IACxC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/wallet-sdk",
|
|
3
|
+
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
|
|
4
|
+
"version": "3.0.0-nightly.20251122",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./base-wallet": "./dest/base-wallet/index.js",
|
|
8
|
+
"./providers/extension": "./dest/providers/extension/index.js",
|
|
9
|
+
"./manager": "./dest/manager/index.js"
|
|
10
|
+
},
|
|
11
|
+
"typedocOptions": {
|
|
12
|
+
"entryPoints": [
|
|
13
|
+
"./src/index.ts"
|
|
14
|
+
],
|
|
15
|
+
"tsconfig": "./tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "yarn clean && tsc -b",
|
|
19
|
+
"build:dev": "tsc -b --watch",
|
|
20
|
+
"build:ts": "tsc -b",
|
|
21
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
22
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
23
|
+
},
|
|
24
|
+
"inherits": [
|
|
25
|
+
"../package.common.json"
|
|
26
|
+
],
|
|
27
|
+
"jest": {
|
|
28
|
+
"moduleNameMapper": {
|
|
29
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
30
|
+
},
|
|
31
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
32
|
+
"rootDir": "./src",
|
|
33
|
+
"transform": {
|
|
34
|
+
"^.+\\.tsx?$": [
|
|
35
|
+
"@swc/jest",
|
|
36
|
+
{
|
|
37
|
+
"jsc": {
|
|
38
|
+
"parser": {
|
|
39
|
+
"syntax": "typescript",
|
|
40
|
+
"decorators": true
|
|
41
|
+
},
|
|
42
|
+
"transform": {
|
|
43
|
+
"decoratorVersion": "2022-03"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"extensionsToTreatAsEsm": [
|
|
50
|
+
".ts"
|
|
51
|
+
],
|
|
52
|
+
"reporters": [
|
|
53
|
+
"default"
|
|
54
|
+
],
|
|
55
|
+
"testTimeout": 120000,
|
|
56
|
+
"setupFiles": [
|
|
57
|
+
"../../foundation/src/jest/setup.mjs"
|
|
58
|
+
],
|
|
59
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
60
|
+
"setupFilesAfterEnv": [
|
|
61
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@aztec/aztec.js": "3.0.0-nightly.20251122",
|
|
66
|
+
"@aztec/constants": "3.0.0-nightly.20251122",
|
|
67
|
+
"@aztec/entrypoints": "3.0.0-nightly.20251122",
|
|
68
|
+
"@aztec/foundation": "3.0.0-nightly.20251122",
|
|
69
|
+
"@aztec/pxe": "3.0.0-nightly.20251122",
|
|
70
|
+
"@aztec/stdlib": "3.0.0-nightly.20251122"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@aztec/noir-contracts.js": "3.0.0-nightly.20251122",
|
|
74
|
+
"@jest/globals": "^30.0.0",
|
|
75
|
+
"@types/jest": "^30.0.0",
|
|
76
|
+
"@types/node": "^22.15.17",
|
|
77
|
+
"jest": "^30.0.0",
|
|
78
|
+
"jest-mock-extended": "^4.0.0",
|
|
79
|
+
"resolve-typescript-plugin": "^2.0.1",
|
|
80
|
+
"ts-loader": "^9.5.4",
|
|
81
|
+
"ts-node": "^10.9.1",
|
|
82
|
+
"typescript": "^5.3.3",
|
|
83
|
+
"util": "^0.12.5"
|
|
84
|
+
},
|
|
85
|
+
"files": [
|
|
86
|
+
"dest",
|
|
87
|
+
"src",
|
|
88
|
+
"!*.test.*",
|
|
89
|
+
"artifacts"
|
|
90
|
+
],
|
|
91
|
+
"types": "./dest/index.d.ts",
|
|
92
|
+
"engines": {
|
|
93
|
+
"node": ">=20.10"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import type { Account } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
4
|
+
import type {
|
|
5
|
+
Aliased,
|
|
6
|
+
BatchResults,
|
|
7
|
+
BatchableMethods,
|
|
8
|
+
BatchedMethod,
|
|
9
|
+
ProfileOptions,
|
|
10
|
+
SendOptions,
|
|
11
|
+
SimulateOptions,
|
|
12
|
+
Wallet,
|
|
13
|
+
} from '@aztec/aztec.js/wallet';
|
|
14
|
+
import {
|
|
15
|
+
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
16
|
+
GAS_ESTIMATION_L2_GAS_LIMIT,
|
|
17
|
+
GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT,
|
|
18
|
+
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
|
|
19
|
+
} from '@aztec/constants';
|
|
20
|
+
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
21
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
22
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
23
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
24
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
25
|
+
import type { PXE } from '@aztec/pxe/server';
|
|
26
|
+
import {
|
|
27
|
+
type ContractArtifact,
|
|
28
|
+
type EventMetadataDefinition,
|
|
29
|
+
type FunctionCall,
|
|
30
|
+
decodeFromAbi,
|
|
31
|
+
} from '@aztec/stdlib/abi';
|
|
32
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
33
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
34
|
+
import {
|
|
35
|
+
type ContractClassMetadata,
|
|
36
|
+
type ContractInstanceWithAddress,
|
|
37
|
+
type ContractMetadata,
|
|
38
|
+
computePartialAddress,
|
|
39
|
+
getContractClassFromArtifact,
|
|
40
|
+
} from '@aztec/stdlib/contract';
|
|
41
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
42
|
+
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
43
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
44
|
+
import type {
|
|
45
|
+
TxExecutionRequest,
|
|
46
|
+
TxHash,
|
|
47
|
+
TxProfileResult,
|
|
48
|
+
TxReceipt,
|
|
49
|
+
TxSimulationResult,
|
|
50
|
+
UtilitySimulationResult,
|
|
51
|
+
} from '@aztec/stdlib/tx';
|
|
52
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
53
|
+
|
|
54
|
+
import { inspect } from 'util';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Options to configure fee payment for a transaction
|
|
58
|
+
*/
|
|
59
|
+
export type FeeOptions = {
|
|
60
|
+
/**
|
|
61
|
+
* A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
|
|
62
|
+
* doesn't already include one
|
|
63
|
+
*/
|
|
64
|
+
walletFeePaymentMethod?: FeePaymentMethod;
|
|
65
|
+
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
66
|
+
accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
|
|
67
|
+
/** The gas settings to use for the transaction */
|
|
68
|
+
gasSettings: GasSettings;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A base class for Wallet implementations
|
|
73
|
+
*/
|
|
74
|
+
export abstract class BaseWallet implements Wallet {
|
|
75
|
+
protected log = createLogger('wallet-sdk:base_wallet');
|
|
76
|
+
|
|
77
|
+
protected baseFeePadding = 0.5;
|
|
78
|
+
protected cancellableTransactions = false;
|
|
79
|
+
|
|
80
|
+
// Protected because we want to force wallets to instantiate their own PXE.
|
|
81
|
+
protected constructor(
|
|
82
|
+
protected readonly pxe: PXE,
|
|
83
|
+
protected readonly aztecNode: AztecNode,
|
|
84
|
+
) {}
|
|
85
|
+
|
|
86
|
+
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
87
|
+
|
|
88
|
+
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns the list of aliased contacts associated with the wallet.
|
|
92
|
+
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
93
|
+
* - Senders: Addresses we check during synching in case they sent us notes,
|
|
94
|
+
* - Contacts: more general concept akin to a phone's contact list.
|
|
95
|
+
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
96
|
+
*/
|
|
97
|
+
async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
98
|
+
const senders: AztecAddress[] = await this.pxe.getSenders();
|
|
99
|
+
return senders.map(sender => ({ item: sender, alias: '' }));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getChainInfo(): Promise<ChainInfo> {
|
|
103
|
+
const { l1ChainId, rollupVersion } = await this.aztecNode.getNodeInfo();
|
|
104
|
+
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
108
|
+
executionPayload: ExecutionPayload,
|
|
109
|
+
from: AztecAddress,
|
|
110
|
+
feeOptions: FeeOptions,
|
|
111
|
+
): Promise<TxExecutionRequest> {
|
|
112
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
113
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
114
|
+
txNonce: Fr.random(),
|
|
115
|
+
cancellable: this.cancellableTransactions,
|
|
116
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
117
|
+
};
|
|
118
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
119
|
+
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
120
|
+
: executionPayload;
|
|
121
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
122
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public async createAuthWit(
|
|
126
|
+
from: AztecAddress,
|
|
127
|
+
messageHashOrIntent: Fr | IntentInnerHash | CallIntent,
|
|
128
|
+
): Promise<AuthWitness> {
|
|
129
|
+
const account = await this.getAccountFromAddress(from);
|
|
130
|
+
return account.createAuthWit(messageHashOrIntent);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public async batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(
|
|
134
|
+
methods: T,
|
|
135
|
+
): Promise<BatchResults<T>> {
|
|
136
|
+
const results: any[] = [];
|
|
137
|
+
for (const method of methods) {
|
|
138
|
+
const { name, args } = method;
|
|
139
|
+
// Type safety is guaranteed by the BatchedMethod type, which ensures that:
|
|
140
|
+
// 1. `name` is a valid batchable method name
|
|
141
|
+
// 2. `args` matches the parameter types of that specific method
|
|
142
|
+
// 3. The return type is correctly mapped in BatchResults<T>
|
|
143
|
+
// We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
|
|
144
|
+
|
|
145
|
+
const fn = this[name] as (...args: any[]) => Promise<any>;
|
|
146
|
+
const result = await fn.apply(this, args);
|
|
147
|
+
// Wrap result with method name for discriminated union deserialization
|
|
148
|
+
results.push({ name, result });
|
|
149
|
+
}
|
|
150
|
+
return results as BatchResults<T>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Completes partial user-provided fee options with wallet defaults.
|
|
155
|
+
* @param from - The address where the transaction is being sent from
|
|
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
|
|
159
|
+
*/
|
|
160
|
+
protected async completeFeeOptions(
|
|
161
|
+
from: AztecAddress,
|
|
162
|
+
feePayer?: AztecAddress,
|
|
163
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
164
|
+
): Promise<FeeOptions> {
|
|
165
|
+
const maxFeesPerGas =
|
|
166
|
+
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentBaseFees()).mul(1 + this.baseFeePadding);
|
|
167
|
+
let accountFeePaymentMethodOptions;
|
|
168
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
169
|
+
// for the account to use its fee juice balance
|
|
170
|
+
if (!feePayer) {
|
|
171
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
172
|
+
} else {
|
|
173
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
174
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
175
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
176
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
177
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
178
|
+
}
|
|
179
|
+
const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
|
|
180
|
+
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
181
|
+
return {
|
|
182
|
+
gasSettings: fullGasSettings,
|
|
183
|
+
walletFeePaymentMethod: undefined,
|
|
184
|
+
accountFeePaymentMethodOptions,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Completes partial user-provided fee options with unreasonably high gas limits
|
|
190
|
+
* for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
|
|
191
|
+
* to avoid running out of gas during estimation.
|
|
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
|
|
195
|
+
*/
|
|
196
|
+
protected async completeFeeOptionsForEstimation(
|
|
197
|
+
from: AztecAddress,
|
|
198
|
+
feePayer?: AztecAddress,
|
|
199
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
200
|
+
) {
|
|
201
|
+
const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
|
|
202
|
+
const {
|
|
203
|
+
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
204
|
+
} = defaultFeeOptions;
|
|
205
|
+
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
206
|
+
// They will be tuned down after the simulation.
|
|
207
|
+
const gasSettingsForEstimation = new GasSettings(
|
|
208
|
+
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
209
|
+
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
210
|
+
maxFeesPerGas,
|
|
211
|
+
maxPriorityFeesPerGas,
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
214
|
+
...defaultFeeOptions,
|
|
215
|
+
gasSettings: gasSettingsForEstimation,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
220
|
+
return this.pxe.registerSender(address);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async registerContract(
|
|
224
|
+
instance: ContractInstanceWithAddress,
|
|
225
|
+
artifact?: ContractArtifact,
|
|
226
|
+
secretKey?: Fr,
|
|
227
|
+
): Promise<ContractInstanceWithAddress> {
|
|
228
|
+
const { contractInstance: existingInstance } = await this.pxe.getContractMetadata(instance.address);
|
|
229
|
+
|
|
230
|
+
if (existingInstance) {
|
|
231
|
+
// Instance already registered in the wallet
|
|
232
|
+
if (artifact) {
|
|
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 });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (secretKey) {
|
|
257
|
+
await this.pxe.registerAccount(secretKey, await computePartialAddress(instance));
|
|
258
|
+
}
|
|
259
|
+
return instance;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
263
|
+
const feeOptions = opts.fee?.estimateGas
|
|
264
|
+
? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
|
|
265
|
+
: await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
266
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
267
|
+
return this.pxe.simulateTx(
|
|
268
|
+
txRequest,
|
|
269
|
+
true /* simulatePublic */,
|
|
270
|
+
opts?.skipTxValidation,
|
|
271
|
+
opts?.skipFeeEnforcement ?? true,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
276
|
+
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
277
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
278
|
+
return this.pxe.profileTx(txRequest, opts.profileMode, opts.skipProofGeneration ?? true);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<TxHash> {
|
|
282
|
+
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
283
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
284
|
+
const provenTx = await this.pxe.proveTx(txRequest);
|
|
285
|
+
const tx = await provenTx.toTx();
|
|
286
|
+
const txHash = tx.getTxHash();
|
|
287
|
+
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
288
|
+
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
289
|
+
}
|
|
290
|
+
this.log.debug(`Sending transaction ${txHash}`);
|
|
291
|
+
await this.aztecNode.sendTx(tx).catch(err => {
|
|
292
|
+
throw this.contextualizeError(err, inspect(tx));
|
|
293
|
+
});
|
|
294
|
+
this.log.info(`Sent transaction ${txHash}`);
|
|
295
|
+
return txHash;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
299
|
+
let contextStr = '';
|
|
300
|
+
if (context.length > 0) {
|
|
301
|
+
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
302
|
+
}
|
|
303
|
+
if (err instanceof SimulationError) {
|
|
304
|
+
err.setAztecContext(contextStr);
|
|
305
|
+
} else {
|
|
306
|
+
this.log.error(err.name, err);
|
|
307
|
+
this.log.debug(contextStr);
|
|
308
|
+
}
|
|
309
|
+
return err;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
simulateUtility(call: FunctionCall, authwits?: AuthWitness[]): Promise<UtilitySimulationResult> {
|
|
313
|
+
return this.pxe.simulateUtility(call, authwits);
|
|
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);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async getPrivateEvents<T>(
|
|
328
|
+
contractAddress: AztecAddress,
|
|
329
|
+
eventDef: EventMetadataDefinition,
|
|
330
|
+
from: number,
|
|
331
|
+
limit: number,
|
|
332
|
+
recipients: AztecAddress[] = [],
|
|
333
|
+
): Promise<T[]> {
|
|
334
|
+
const events = await this.pxe.getPrivateEvents(contractAddress, eventDef.eventSelector, from, limit, recipients);
|
|
335
|
+
|
|
336
|
+
const decodedEvents = events.map(
|
|
337
|
+
(event: any /** PrivateEvent */): T => decodeFromAbi([eventDef.abiType], event.packedEvent) as T,
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
return decodedEvents;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { WalletManager } from './wallet_manager.js';
|
|
2
|
+
export type {
|
|
3
|
+
WalletManagerConfig,
|
|
4
|
+
ExtensionWalletConfig,
|
|
5
|
+
WebWalletConfig,
|
|
6
|
+
WalletProviderType,
|
|
7
|
+
WalletProvider,
|
|
8
|
+
DiscoverWalletsOptions,
|
|
9
|
+
} from './types.js';
|
|
10
|
+
|
|
11
|
+
// Re-export types from providers for convenience
|
|
12
|
+
export type {
|
|
13
|
+
WalletInfo,
|
|
14
|
+
WalletMessage,
|
|
15
|
+
WalletResponse,
|
|
16
|
+
DiscoveryRequest,
|
|
17
|
+
DiscoveryResponse,
|
|
18
|
+
} from '../providers/types.js';
|
|
19
|
+
|
|
20
|
+
// Re-export commonly needed utilities for wallet integration
|
|
21
|
+
export { ChainInfoSchema } from '@aztec/aztec.js/account';
|
|
22
|
+
export type { ChainInfo } from '@aztec/aztec.js/account';
|
|
23
|
+
export { WalletSchema } from '@aztec/aztec.js/wallet';
|
|
24
|
+
export { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for extension wallets
|
|
6
|
+
*/
|
|
7
|
+
export interface ExtensionWalletConfig {
|
|
8
|
+
/** Whether extension wallets are enabled */
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
/** Optional list of allowed extension IDs (whitelist) */
|
|
11
|
+
allowList?: string[];
|
|
12
|
+
/** Optional list of blocked extension IDs (blacklist) */
|
|
13
|
+
blockList?: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for web wallets
|
|
18
|
+
*/
|
|
19
|
+
export interface WebWalletConfig {
|
|
20
|
+
/** URLs of web wallet services */
|
|
21
|
+
urls: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for the WalletManager
|
|
26
|
+
*/
|
|
27
|
+
export interface WalletManagerConfig {
|
|
28
|
+
/** Extension wallet configuration */
|
|
29
|
+
extensions?: ExtensionWalletConfig;
|
|
30
|
+
/** Web wallet configuration */
|
|
31
|
+
webWallets?: WebWalletConfig;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Type of wallet provider
|
|
36
|
+
*/
|
|
37
|
+
export type WalletProviderType = 'extension' | 'web' | 'embedded';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A wallet provider that can connect to create a wallet instance.
|
|
41
|
+
* Chain information is already baked in from the discovery process.
|
|
42
|
+
*/
|
|
43
|
+
export interface WalletProvider {
|
|
44
|
+
/** Unique identifier for the provider */
|
|
45
|
+
id: string;
|
|
46
|
+
/** Type of wallet provider */
|
|
47
|
+
type: WalletProviderType;
|
|
48
|
+
/** Display name */
|
|
49
|
+
name: string;
|
|
50
|
+
/** Icon URL */
|
|
51
|
+
icon?: string;
|
|
52
|
+
/** Additional metadata */
|
|
53
|
+
metadata?: Record<string, unknown>;
|
|
54
|
+
/**
|
|
55
|
+
* Connect to this wallet provider with an application ID
|
|
56
|
+
* @param appId - Application identifier for the requesting dapp
|
|
57
|
+
*/
|
|
58
|
+
connect(appId: string): Promise<Wallet>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Options for discovering wallets
|
|
63
|
+
*/
|
|
64
|
+
export interface DiscoverWalletsOptions {
|
|
65
|
+
/** Chain information to filter by */
|
|
66
|
+
chainInfo: ChainInfo;
|
|
67
|
+
/** Discovery timeout in milliseconds */
|
|
68
|
+
timeout?: number;
|
|
69
|
+
}
|