@aztec/wallet-sdk 0.0.1-commit.e0f15ab9b → 0.0.1-commit.e304674f1
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/dest/base-wallet/base_wallet.d.ts +15 -26
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +29 -32
- package/dest/base-wallet/index.d.ts +2 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/provider/extension_wallet.d.ts +2 -5
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/index.d.ts +2 -2
- package/dest/extension/provider/index.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +118 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +228 -0
- package/dest/iframe/handlers/index.d.ts +2 -0
- package/dest/iframe/handlers/index.d.ts.map +1 -0
- package/dest/iframe/handlers/index.js +1 -0
- package/dest/iframe/provider/iframe_discovery.d.ts +25 -0
- package/dest/iframe/provider/iframe_discovery.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_discovery.js +167 -0
- package/dest/iframe/provider/iframe_provider.d.ts +65 -0
- package/dest/iframe/provider/iframe_provider.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_provider.js +257 -0
- package/dest/iframe/provider/iframe_wallet.d.ts +68 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +200 -0
- package/dest/iframe/provider/index.d.ts +4 -0
- package/dest/iframe/provider/index.d.ts.map +1 -0
- package/dest/iframe/provider/index.js +3 -0
- package/dest/manager/types.d.ts +3 -2
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +46 -16
- package/dest/types.d.ts +14 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +46 -55
- package/src/base-wallet/index.ts +6 -1
- package/src/crypto.ts +104 -0
- package/src/extension/provider/extension_wallet.ts +1 -6
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +328 -0
- package/src/iframe/handlers/index.ts +7 -0
- package/src/iframe/provider/iframe_discovery.ts +185 -0
- package/src/iframe/provider/iframe_provider.ts +331 -0
- package/src/iframe/provider/iframe_wallet.ts +229 -0
- package/src/iframe/provider/index.ts +3 -0
- package/src/manager/types.ts +2 -1
- package/src/manager/wallet_manager.ts +48 -14
- package/src/types.ts +13 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
2
2
|
import { ExtensionProvider, ExtensionWallet } from '../extension/provider/index.js';
|
|
3
|
+
import { discoverWebWallets } from '../iframe/provider/iframe_discovery.js';
|
|
3
4
|
import { WalletMessageType } from '../types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Manager for wallet discovery, configuration, and connection.
|
|
@@ -75,6 +76,20 @@ import { WalletMessageType } from '../types.js';
|
|
|
75
76
|
let pendingResolve = null;
|
|
76
77
|
let completed = false;
|
|
77
78
|
const { promise: donePromise, resolve: resolveDone } = promiseWithResolvers();
|
|
79
|
+
const pendingSources = new Set();
|
|
80
|
+
const emit = (provider)=>{
|
|
81
|
+
options.onWalletDiscovered?.(provider);
|
|
82
|
+
if (pendingResolve) {
|
|
83
|
+
const resolve = pendingResolve;
|
|
84
|
+
pendingResolve = null;
|
|
85
|
+
resolve({
|
|
86
|
+
value: provider,
|
|
87
|
+
done: false
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
pendingProviders.push(provider);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
78
93
|
const markComplete = ()=>{
|
|
79
94
|
completed = true;
|
|
80
95
|
resolveDone();
|
|
@@ -87,7 +102,14 @@ import { WalletMessageType } from '../types.js';
|
|
|
87
102
|
});
|
|
88
103
|
}
|
|
89
104
|
};
|
|
105
|
+
const sourceComplete = (source)=>{
|
|
106
|
+
pendingSources.delete(source);
|
|
107
|
+
if (pendingSources.size === 0) {
|
|
108
|
+
markComplete();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
90
111
|
if (this.config.extensions?.enabled) {
|
|
112
|
+
pendingSources.add('extensions');
|
|
91
113
|
const extensionConfig = this.config.extensions;
|
|
92
114
|
void ExtensionProvider.discoverWallets(chainInfo, {
|
|
93
115
|
appId,
|
|
@@ -95,25 +117,33 @@ import { WalletMessageType } from '../types.js';
|
|
|
95
117
|
signal: abortController.signal,
|
|
96
118
|
onWalletDiscovered: (discoveredWallet)=>{
|
|
97
119
|
const provider = this.createProviderFromDiscoveredWallet(discoveredWallet, chainInfo, extensionConfig);
|
|
98
|
-
if (
|
|
99
|
-
|
|
120
|
+
if (provider) {
|
|
121
|
+
emit(provider);
|
|
100
122
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
}
|
|
124
|
+
}).then(()=>sourceComplete('extensions'));
|
|
125
|
+
}
|
|
126
|
+
if (this.config.webWallets?.urls && this.config.webWallets.urls.length > 0) {
|
|
127
|
+
pendingSources.add('webWallets');
|
|
128
|
+
const webSession = discoverWebWallets(this.config.webWallets.urls, chainInfo);
|
|
129
|
+
// Forward discovered web wallets into the shared iterator
|
|
130
|
+
void (async ()=>{
|
|
131
|
+
try {
|
|
132
|
+
for await (const provider of webSession.wallets){
|
|
133
|
+
if (abortController.signal.aborted) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
emit(provider);
|
|
113
137
|
}
|
|
138
|
+
} finally{
|
|
139
|
+
sourceComplete('webWallets');
|
|
114
140
|
}
|
|
115
|
-
})
|
|
116
|
-
|
|
141
|
+
})();
|
|
142
|
+
abortController.signal.addEventListener('abort', ()=>webSession.cancel(), {
|
|
143
|
+
once: true
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (pendingSources.size === 0) {
|
|
117
147
|
markComplete();
|
|
118
148
|
}
|
|
119
149
|
const wallets = {
|
package/dest/types.d.ts
CHANGED
|
@@ -14,7 +14,15 @@ export declare enum WalletMessageType {
|
|
|
14
14
|
/** Key exchange request sent over MessageChannel */
|
|
15
15
|
KEY_EXCHANGE_REQUEST = "aztec-wallet-key-exchange-request",
|
|
16
16
|
/** Key exchange response sent over MessageChannel */
|
|
17
|
-
KEY_EXCHANGE_RESPONSE = "aztec-wallet-key-exchange-response"
|
|
17
|
+
KEY_EXCHANGE_RESPONSE = "aztec-wallet-key-exchange-response",
|
|
18
|
+
/** Wallet ready signal */
|
|
19
|
+
WALLET_READY = "aztec-wallet-ready",
|
|
20
|
+
/** Encrypted wallet message wrapper */
|
|
21
|
+
SECURE_MESSAGE = "aztec-wallet-secure-message",
|
|
22
|
+
/** Encrypted wallet response wrapper */
|
|
23
|
+
SECURE_RESPONSE = "aztec-wallet-secure-response",
|
|
24
|
+
/** Session disconnected notification */
|
|
25
|
+
SESSION_DISCONNECTED = "aztec-wallet-session-disconnected"
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
28
|
* Information about an installed Aztec wallet.
|
|
@@ -120,4 +128,8 @@ export interface KeyExchangeResponse {
|
|
|
120
128
|
/** Wallet's ECDH public key for deriving shared secret */
|
|
121
129
|
publicKey: ExportedPublicKey;
|
|
122
130
|
}
|
|
123
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Callback invoked when a wallet connection is disconnected.
|
|
133
|
+
*/
|
|
134
|
+
export type DisconnectCallback = () => void;
|
|
135
|
+
//# sourceMappingURL=data:application/json;base64,eyJ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IAAI,CAAC"}
|
package/dest/types.js
CHANGED
|
@@ -7,5 +7,9 @@
|
|
|
7
7
|
/** Disconnect message (unencrypted control message, bidirectional) */ WalletMessageType["DISCONNECT"] = "aztec-wallet-disconnect";
|
|
8
8
|
/** Key exchange request sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_REQUEST"] = "aztec-wallet-key-exchange-request";
|
|
9
9
|
/** Key exchange response sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_RESPONSE"] = "aztec-wallet-key-exchange-response";
|
|
10
|
+
/** Wallet ready signal */ WalletMessageType["WALLET_READY"] = "aztec-wallet-ready";
|
|
11
|
+
/** Encrypted wallet message wrapper */ WalletMessageType["SECURE_MESSAGE"] = "aztec-wallet-secure-message";
|
|
12
|
+
/** Encrypted wallet response wrapper */ WalletMessageType["SECURE_RESPONSE"] = "aztec-wallet-secure-response";
|
|
13
|
+
/** Session disconnected notification */ WalletMessageType["SESSION_DISCONNECTED"] = "aztec-wallet-session-disconnected";
|
|
10
14
|
return WalletMessageType;
|
|
11
15
|
}({});
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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.e304674f1",
|
|
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
9
|
"./extension/provider": "./dest/extension/provider/index.js",
|
|
10
|
+
"./iframe/handlers": "./dest/iframe/handlers/index.js",
|
|
11
|
+
"./iframe/provider": "./dest/iframe/provider/index.js",
|
|
10
12
|
"./crypto": "./dest/crypto.js",
|
|
11
13
|
"./types": "./dest/types.js",
|
|
12
14
|
"./manager": "./dest/manager/index.js"
|
|
@@ -16,6 +18,8 @@
|
|
|
16
18
|
"./src/base-wallet/index.ts",
|
|
17
19
|
"./src/extension/handlers/index.ts",
|
|
18
20
|
"./src/extension/provider/index.ts",
|
|
21
|
+
"./src/iframe/handlers/index.ts",
|
|
22
|
+
"./src/iframe/provider/index.ts",
|
|
19
23
|
"./src/crypto.ts",
|
|
20
24
|
"./src/types.ts",
|
|
21
25
|
"./src/manager/index.ts"
|
|
@@ -71,15 +75,15 @@
|
|
|
71
75
|
]
|
|
72
76
|
},
|
|
73
77
|
"dependencies": {
|
|
74
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
75
|
-
"@aztec/constants": "0.0.1-commit.
|
|
76
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
77
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
78
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
79
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
78
|
+
"@aztec/aztec.js": "0.0.1-commit.e304674f1",
|
|
79
|
+
"@aztec/constants": "0.0.1-commit.e304674f1",
|
|
80
|
+
"@aztec/entrypoints": "0.0.1-commit.e304674f1",
|
|
81
|
+
"@aztec/foundation": "0.0.1-commit.e304674f1",
|
|
82
|
+
"@aztec/pxe": "0.0.1-commit.e304674f1",
|
|
83
|
+
"@aztec/stdlib": "0.0.1-commit.e304674f1"
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
82
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
86
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.e304674f1",
|
|
83
87
|
"@jest/globals": "^30.0.0",
|
|
84
88
|
"@types/jest": "^30.0.0",
|
|
85
89
|
"@types/node": "^22.15.17",
|
|
@@ -24,19 +24,13 @@ import {
|
|
|
24
24
|
type Wallet,
|
|
25
25
|
type WalletCapabilities,
|
|
26
26
|
} from '@aztec/aztec.js/wallet';
|
|
27
|
-
import {
|
|
28
|
-
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
29
|
-
GAS_ESTIMATION_L2_GAS_LIMIT,
|
|
30
|
-
GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT,
|
|
31
|
-
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
|
|
32
|
-
} from '@aztec/constants';
|
|
33
27
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
34
28
|
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
35
29
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
36
30
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
37
31
|
import { createLogger } from '@aztec/foundation/log';
|
|
38
32
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
39
|
-
import {
|
|
33
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
40
34
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
41
35
|
import {
|
|
42
36
|
type ContractArtifact,
|
|
@@ -52,7 +46,7 @@ import {
|
|
|
52
46
|
getContractClassFromArtifact,
|
|
53
47
|
} from '@aztec/stdlib/contract';
|
|
54
48
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
55
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
49
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
56
50
|
import {
|
|
57
51
|
computeSiloedPrivateInitializationNullifier,
|
|
58
52
|
computeSiloedPublicInitializationNullifier,
|
|
@@ -94,8 +88,21 @@ export type SimulateViaEntrypointOptions = Pick<
|
|
|
94
88
|
/** Fee options for the entrypoint */
|
|
95
89
|
feeOptions: FeeOptions;
|
|
96
90
|
/** Scopes to use for the simulation */
|
|
97
|
-
scopes:
|
|
91
|
+
scopes: AztecAddress[];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Options for `completeFeeOptions`. */
|
|
95
|
+
export type CompleteFeeOptionsConfig = {
|
|
96
|
+
/** The address where the transaction is being sent from. */
|
|
97
|
+
from: AztecAddress | NoFrom;
|
|
98
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
99
|
+
feePayer?: AztecAddress;
|
|
100
|
+
/** User-provided partial gas settings. */
|
|
101
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
102
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
103
|
+
forEstimation?: boolean;
|
|
98
104
|
};
|
|
105
|
+
|
|
99
106
|
/**
|
|
100
107
|
* A base class for Wallet implementations
|
|
101
108
|
*/
|
|
@@ -214,16 +221,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
214
221
|
|
|
215
222
|
/**
|
|
216
223
|
* Completes partial user-provided fee options with wallet defaults.
|
|
217
|
-
* @param
|
|
218
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
219
|
-
* @param gasSettings - User-provided partial gas settings
|
|
220
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
224
|
+
* @param config - Fee completion config.
|
|
221
225
|
*/
|
|
222
|
-
protected async completeFeeOptions(
|
|
223
|
-
from
|
|
224
|
-
feePayer?: AztecAddress,
|
|
225
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
226
|
-
): Promise<FeeOptions> {
|
|
226
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
227
|
+
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
227
228
|
const maxFeesPerGas =
|
|
228
229
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
229
230
|
let accountFeePaymentMethodOptions;
|
|
@@ -242,7 +243,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
242
243
|
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
|
-
const
|
|
246
|
+
const gasSettingsOverrides = {
|
|
247
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
248
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
249
|
+
maxFeesPerGas,
|
|
250
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
251
|
+
};
|
|
252
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
253
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
254
|
+
const fullGasSettings = forEstimation
|
|
255
|
+
? GasSettings.forEstimation(gasSettingsOverrides)
|
|
256
|
+
: GasSettings.fallback(gasSettingsOverrides);
|
|
246
257
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
247
258
|
return {
|
|
248
259
|
gasSettings: fullGasSettings,
|
|
@@ -251,37 +262,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
251
262
|
};
|
|
252
263
|
}
|
|
253
264
|
|
|
254
|
-
/**
|
|
255
|
-
* Completes partial user-provided fee options with unreasonably high gas limits
|
|
256
|
-
* for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
|
|
257
|
-
* to avoid running out of gas during estimation.
|
|
258
|
-
* @param from - The address where the transaction is being sent from
|
|
259
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
260
|
-
* @param gasSettings - User-provided partial gas settings
|
|
261
|
-
*/
|
|
262
|
-
protected async completeFeeOptionsForEstimation(
|
|
263
|
-
from: AztecAddress | NoFrom,
|
|
264
|
-
feePayer?: AztecAddress,
|
|
265
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
266
|
-
) {
|
|
267
|
-
const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
|
|
268
|
-
const {
|
|
269
|
-
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
270
|
-
} = defaultFeeOptions;
|
|
271
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
272
|
-
// They will be tuned down after the simulation.
|
|
273
|
-
const gasSettingsForEstimation = new GasSettings(
|
|
274
|
-
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
275
|
-
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
276
|
-
maxFeesPerGas,
|
|
277
|
-
maxPriorityFeesPerGas,
|
|
278
|
-
);
|
|
279
|
-
return {
|
|
280
|
-
...defaultFeeOptions,
|
|
281
|
-
gasSettings: gasSettingsForEstimation,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
265
|
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
286
266
|
return this.pxe.registerSender(address);
|
|
287
267
|
}
|
|
@@ -352,9 +332,12 @@ export abstract class BaseWallet implements Wallet {
|
|
|
352
332
|
* @returns The merged simulation result.
|
|
353
333
|
*/
|
|
354
334
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
355
|
-
const feeOptions =
|
|
356
|
-
|
|
357
|
-
:
|
|
335
|
+
const feeOptions = await this.completeFeeOptions({
|
|
336
|
+
from: opts.from,
|
|
337
|
+
feePayer: executionPayload.feePayer,
|
|
338
|
+
gasSettings: opts.fee?.gasSettings,
|
|
339
|
+
forEstimation: true,
|
|
340
|
+
});
|
|
358
341
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
359
342
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
360
343
|
|
|
@@ -397,7 +380,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
397
380
|
}
|
|
398
381
|
|
|
399
382
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
400
|
-
const feeOptions = await this.completeFeeOptions(
|
|
383
|
+
const feeOptions = await this.completeFeeOptions({
|
|
384
|
+
from: opts.from,
|
|
385
|
+
feePayer: executionPayload.feePayer,
|
|
386
|
+
gasSettings: opts.fee?.gasSettings,
|
|
387
|
+
});
|
|
401
388
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
402
389
|
return this.pxe.profileTx(txRequest, {
|
|
403
390
|
profileMode: opts.profileMode,
|
|
@@ -410,7 +397,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
410
397
|
executionPayload: ExecutionPayload,
|
|
411
398
|
opts: SendOptions<W>,
|
|
412
399
|
): Promise<SendReturn<W>> {
|
|
413
|
-
const feeOptions = await this.completeFeeOptions(
|
|
400
|
+
const feeOptions = await this.completeFeeOptions({
|
|
401
|
+
from: opts.from,
|
|
402
|
+
feePayer: executionPayload.feePayer,
|
|
403
|
+
gasSettings: opts.fee?.gasSettings,
|
|
404
|
+
});
|
|
414
405
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
415
406
|
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
416
407
|
const offchainOutput = extractOffchainOutput(
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
BaseWallet,
|
|
3
|
+
type CompleteFeeOptionsConfig,
|
|
4
|
+
type FeeOptions,
|
|
5
|
+
type SimulateViaEntrypointOptions,
|
|
6
|
+
} from './base_wallet.js';
|
|
2
7
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
package/src/crypto.ts
CHANGED
|
@@ -497,3 +497,107 @@ export function hashToEmoji(hash: string, count: number = DEFAULT_EMOJI_GRID_SIZ
|
|
|
497
497
|
}
|
|
498
498
|
return emojis.join('');
|
|
499
499
|
}
|
|
500
|
+
|
|
501
|
+
// ─── Passphrase-based encryption (PBKDF2 + AES-256-GCM) ───────────────────
|
|
502
|
+
|
|
503
|
+
/** Default PBKDF2 iteration count. High to compensate for short PINs (~1-2s on modern hardware). */
|
|
504
|
+
const DEFAULT_PBKDF2_ITERATIONS = 2_000_000;
|
|
505
|
+
const PBKDF2_SALT_BYTES = 16;
|
|
506
|
+
const PBKDF2_IV_BYTES = 12;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Derives an AES-256-GCM key from a passphrase using PBKDF2-SHA256.
|
|
510
|
+
*
|
|
511
|
+
* @param passphrase - The user-provided passphrase or PIN
|
|
512
|
+
* @param salt - Random salt bytes
|
|
513
|
+
* @param iterations - PBKDF2 iteration count (default: 2,000,000)
|
|
514
|
+
* @returns An AES-256-GCM CryptoKey
|
|
515
|
+
*/
|
|
516
|
+
export async function deriveKeyFromPassphrase(
|
|
517
|
+
passphrase: string,
|
|
518
|
+
salt: Uint8Array,
|
|
519
|
+
iterations: number = DEFAULT_PBKDF2_ITERATIONS,
|
|
520
|
+
): Promise<CryptoKey> {
|
|
521
|
+
const keyMaterial = await crypto.subtle.importKey('raw', new TextEncoder().encode(passphrase), 'PBKDF2', false, [
|
|
522
|
+
'deriveKey',
|
|
523
|
+
]);
|
|
524
|
+
return crypto.subtle.deriveKey(
|
|
525
|
+
{ name: 'PBKDF2', salt: salt as BufferSource, iterations, hash: 'SHA-256' },
|
|
526
|
+
keyMaterial,
|
|
527
|
+
{ name: 'AES-GCM', length: 256 },
|
|
528
|
+
false,
|
|
529
|
+
['encrypt', 'decrypt'],
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Encrypts arbitrary bytes with a passphrase using PBKDF2 + AES-256-GCM.
|
|
535
|
+
*
|
|
536
|
+
* Output layout: `[salt (16)] [iv (12)] [ciphertext (...)]`
|
|
537
|
+
*
|
|
538
|
+
* @param plaintext - Data to encrypt
|
|
539
|
+
* @param passphrase - User passphrase or PIN
|
|
540
|
+
* @param iterations - PBKDF2 iteration count (default: 2,000,000)
|
|
541
|
+
* @returns A Uint8Array containing salt + iv + ciphertext
|
|
542
|
+
*/
|
|
543
|
+
export async function encryptWithPassphrase(
|
|
544
|
+
plaintext: Uint8Array,
|
|
545
|
+
passphrase: string,
|
|
546
|
+
iterations: number = DEFAULT_PBKDF2_ITERATIONS,
|
|
547
|
+
): Promise<Uint8Array> {
|
|
548
|
+
const salt = crypto.getRandomValues(new Uint8Array(PBKDF2_SALT_BYTES));
|
|
549
|
+
const iv = crypto.getRandomValues(new Uint8Array(PBKDF2_IV_BYTES));
|
|
550
|
+
const key = await deriveKeyFromPassphrase(passphrase, salt, iterations);
|
|
551
|
+
const ciphertext = new Uint8Array(
|
|
552
|
+
await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, plaintext as BufferSource),
|
|
553
|
+
);
|
|
554
|
+
const result = new Uint8Array(PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES + ciphertext.length);
|
|
555
|
+
result.set(salt, 0);
|
|
556
|
+
result.set(iv, PBKDF2_SALT_BYTES);
|
|
557
|
+
result.set(ciphertext, PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Decrypts data produced by {@link encryptWithPassphrase}.
|
|
563
|
+
*
|
|
564
|
+
* @param data - The encrypted blob (salt + iv + ciphertext)
|
|
565
|
+
* @param passphrase - The passphrase used during encryption
|
|
566
|
+
* @param iterations - PBKDF2 iteration count (must match encryption)
|
|
567
|
+
* @returns The decrypted plaintext bytes
|
|
568
|
+
* @throws On wrong passphrase (AES-GCM auth tag mismatch)
|
|
569
|
+
*/
|
|
570
|
+
export async function decryptWithPassphrase(
|
|
571
|
+
data: Uint8Array,
|
|
572
|
+
passphrase: string,
|
|
573
|
+
iterations: number = DEFAULT_PBKDF2_ITERATIONS,
|
|
574
|
+
): Promise<Uint8Array> {
|
|
575
|
+
const salt = data.slice(0, PBKDF2_SALT_BYTES);
|
|
576
|
+
const iv = data.slice(PBKDF2_SALT_BYTES, PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
|
|
577
|
+
const ciphertext = data.slice(PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
|
|
578
|
+
const key = await deriveKeyFromPassphrase(passphrase, salt, iterations);
|
|
579
|
+
return new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext as BufferSource));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Converts a Uint8Array to a base64 string.
|
|
584
|
+
*/
|
|
585
|
+
export function uint8ToBase64(bytes: Uint8Array): string {
|
|
586
|
+
let binary = '';
|
|
587
|
+
for (const b of bytes) {
|
|
588
|
+
binary += String.fromCharCode(b);
|
|
589
|
+
}
|
|
590
|
+
return btoa(binary);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Converts a base64 string to a Uint8Array.
|
|
595
|
+
*/
|
|
596
|
+
export function base64ToUint8(b64: string): Uint8Array {
|
|
597
|
+
const binary = atob(b64);
|
|
598
|
+
const bytes = new Uint8Array(binary.length);
|
|
599
|
+
for (let i = 0; i < binary.length; i++) {
|
|
600
|
+
bytes[i] = binary.charCodeAt(i);
|
|
601
|
+
}
|
|
602
|
+
return bytes;
|
|
603
|
+
}
|
|
@@ -6,7 +6,7 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
6
6
|
import type { FunctionsOf } from '@aztec/foundation/types';
|
|
7
7
|
|
|
8
8
|
import { type EncryptedPayload, decrypt, encrypt } from '../../crypto.js';
|
|
9
|
-
import { type WalletMessage, WalletMessageType, type WalletResponse } from '../../types.js';
|
|
9
|
+
import { type DisconnectCallback, type WalletMessage, WalletMessageType, type WalletResponse } from '../../types.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Internal type representing a wallet method call before encryption.
|
|
@@ -19,11 +19,6 @@ type WalletMethodCall = {
|
|
|
19
19
|
args: unknown[];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Callback type for wallet disconnect events.
|
|
24
|
-
*/
|
|
25
|
-
export type DisconnectCallback = () => void;
|
|
26
|
-
|
|
27
22
|
/**
|
|
28
23
|
* A wallet implementation that communicates with browser extension wallets
|
|
29
24
|
* using an encrypted MessageChannel.
|