@aztec/wallet-sdk 4.1.2 → 4.2.0-aztecnr-rc.2
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 +23 -17
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +70 -45
- 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 +122 -78
- package/src/base-wallet/index.ts +1 -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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IframeConnectionHandler — wallet-side of the cross-origin iframe protocol.
|
|
3
|
+
*
|
|
4
|
+
* This mirrors {@link BackgroundConnectionHandler} from `@aztec/wallet-sdk/extension/handlers`
|
|
5
|
+
* but uses `window.postMessage` instead of browser.runtime messaging.
|
|
6
|
+
*
|
|
7
|
+
* Message flow (wallet receives):
|
|
8
|
+
* parent → DISCOVERY → show approval UI → send DISCOVERY_RESPONSE
|
|
9
|
+
* parent → KEY_EXCHANGE_REQUEST → ECDH → send KEY_EXCHANGE_RESPONSE
|
|
10
|
+
* parent → SECURE_MESSAGE → decrypt → Wallet → encrypt → SECURE_RESPONSE
|
|
11
|
+
* parent → DISCONNECT → terminate session
|
|
12
|
+
*
|
|
13
|
+
* The wallet announces itself by posting WALLET_READY as soon as the handler starts,
|
|
14
|
+
* so the dApp knows it can send a discovery request.
|
|
15
|
+
*/
|
|
16
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
17
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
18
|
+
/**
|
|
19
|
+
* A pending discovery request from a dApp (before user approval).
|
|
20
|
+
*/
|
|
21
|
+
export interface PendingSession {
|
|
22
|
+
/** Unique request identifier */
|
|
23
|
+
requestId: string;
|
|
24
|
+
/** Application identifier */
|
|
25
|
+
appId: string;
|
|
26
|
+
/** Origin URL of the requesting page */
|
|
27
|
+
origin: string;
|
|
28
|
+
/** Approval status */
|
|
29
|
+
status: 'pending' | 'approved';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* An active session (after key exchange).
|
|
33
|
+
*/
|
|
34
|
+
export interface ActiveSession {
|
|
35
|
+
/** Session identifier (same as the discovery requestId) */
|
|
36
|
+
sessionId: string;
|
|
37
|
+
/** AES-256-GCM shared key for this session */
|
|
38
|
+
sharedKey: CryptoKey;
|
|
39
|
+
/** Verification hash for emoji display */
|
|
40
|
+
verificationHash: string;
|
|
41
|
+
/** Origin URL of the connected dApp */
|
|
42
|
+
origin: string;
|
|
43
|
+
/** Application identifier */
|
|
44
|
+
appId: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for the iframe connection handler.
|
|
48
|
+
*/
|
|
49
|
+
export interface IframeConnectionConfig {
|
|
50
|
+
/** Unique wallet identifier */
|
|
51
|
+
walletId: string;
|
|
52
|
+
/** Display name for the wallet */
|
|
53
|
+
walletName: string;
|
|
54
|
+
/** Wallet version string */
|
|
55
|
+
walletVersion: string;
|
|
56
|
+
/** Optional wallet icon URL */
|
|
57
|
+
walletIcon?: string;
|
|
58
|
+
/** Origins allowed to connect. If empty or undefined, all origins are allowed (dev mode). */
|
|
59
|
+
allowedOrigins?: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Event callbacks for the iframe connection handler.
|
|
63
|
+
*/
|
|
64
|
+
export interface IframeConnectionCallbacks {
|
|
65
|
+
/** Called when a new discovery request arrives — wallet can show approval UI */
|
|
66
|
+
onPendingDiscovery?: (session: PendingSession) => void;
|
|
67
|
+
/** Called when a session is established (key exchange complete) */
|
|
68
|
+
onSessionEstablished?: (session: ActiveSession) => void;
|
|
69
|
+
/** Called when a session is terminated */
|
|
70
|
+
onSessionTerminated?: (sessionId: string) => void;
|
|
71
|
+
/** Called when a key exchange completes — show verificationHash as emojis to the user */
|
|
72
|
+
onVerificationHash?: (verificationHash: string) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Resolves the Wallet instance to use for a given dApp and chain.
|
|
75
|
+
* Called when an encrypted message arrives and needs to be dispatched.
|
|
76
|
+
*/
|
|
77
|
+
getWallet: (appId: string, chainInfo: ChainInfo) => Promise<Wallet>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Handles the wallet side of the cross-origin iframe protocol.
|
|
81
|
+
*
|
|
82
|
+
* Manages the full lifecycle: discovery, ECDH key exchange, encrypted message
|
|
83
|
+
* dispatch to a {@link Wallet} instance, and session termination.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const handler = new IframeConnectionHandler(
|
|
88
|
+
* { walletId: 'my-wallet', walletName: 'My Wallet', walletVersion: '1.0.0' },
|
|
89
|
+
* {
|
|
90
|
+
* onPendingDiscovery: (session) => showApprovalUI(session),
|
|
91
|
+
* getWallet: (appId, chainInfo) => createWalletForApp(appId, chainInfo),
|
|
92
|
+
* },
|
|
93
|
+
* );
|
|
94
|
+
* handler.start();
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare class IframeConnectionHandler {
|
|
98
|
+
private config;
|
|
99
|
+
private callbacks;
|
|
100
|
+
private pendingSessions;
|
|
101
|
+
private activeSessions;
|
|
102
|
+
private log;
|
|
103
|
+
constructor(config: IframeConnectionConfig, callbacks: IframeConnectionCallbacks);
|
|
104
|
+
start(): void;
|
|
105
|
+
stop(): void;
|
|
106
|
+
approveDiscovery(requestId: string): void;
|
|
107
|
+
rejectDiscovery(requestId: string): void;
|
|
108
|
+
terminateSession(sessionId: string): void;
|
|
109
|
+
getPendingSessions(): PendingSession[];
|
|
110
|
+
private handleMessage;
|
|
111
|
+
private handleMessageAsync;
|
|
112
|
+
private handleDiscoveryRequest;
|
|
113
|
+
private handleKeyExchangeRequest;
|
|
114
|
+
private handleSecureMessage;
|
|
115
|
+
private postToParent;
|
|
116
|
+
private postToOrigin;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWZyYW1lX2Nvbm5lY3Rpb25faGFuZGxlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2lmcmFtZS9oYW5kbGVycy9pZnJhbWVfY29ubmVjdGlvbl9oYW5kbGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7Ozs7OztHQWNHO0FBQ0gsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFekQsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFnQnJEOztHQUVHO0FBQ0gsTUFBTSxXQUFXLGNBQWM7SUFDN0IsZ0NBQWdDO0lBQ2hDLFNBQVMsRUFBRSxNQUFNLENBQUM7SUFDbEIsNkJBQTZCO0lBQzdCLEtBQUssRUFBRSxNQUFNLENBQUM7SUFDZCx3Q0FBd0M7SUFDeEMsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUNmLHNCQUFzQjtJQUN0QixNQUFNLEVBQUUsU0FBUyxHQUFHLFVBQVUsQ0FBQztDQUNoQztBQUVEOztHQUVHO0FBQ0gsTUFBTSxXQUFXLGFBQWE7SUFDNUIsMkRBQTJEO0lBQzNELFNBQVMsRUFBRSxNQUFNLENBQUM7SUFDbEIsOENBQThDO0lBQzlDLFNBQVMsRUFBRSxTQUFTLENBQUM7SUFDckIsMENBQTBDO0lBQzFDLGdCQUFnQixFQUFFLE1BQU0sQ0FBQztJQUN6Qix1Q0FBdUM7SUFDdkMsTUF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UI7SUFNaEMsT0FBTyxDQUFDLE1BQU07SUFDZCxPQUFPLENBQUMsU0FBUztJQU5uQixPQUFPLENBQUMsZUFBZSxDQUFxQztJQUM1RCxPQUFPLENBQUMsY0FBYyxDQUFvQztJQUMxRCxPQUFPLENBQUMsR0FBRyxDQUF5QztJQUVwRCxZQUNVLE1BQU0sRUFBRSxzQkFBc0IsRUFDOUIsU0FBUyxFQUFFLHlCQUF5QixFQUMxQztJQUVKLEtBQUssSUFBSSxJQUFJLENBSVo7SUFFRCxJQUFJLElBQUksSUFBSSxDQUVYO0lBRUQsZ0JBQWdCLENBQUMsU0FBUyxFQUFFLE1BQU0sR0FBRyxJQUFJLENBa0J4QztJQUVELGVBQWUsQ0FBQyxTQUFTLEVBQUUsTUFBTSxHQUFHLElBQUksQ0FFdkM7SUFFRCxnQkFBZ0IsQ0FBQyxTQUFTLEVBQUUsTUFBTSxHQUFHLElBQUksQ0FVeEM7SUFFRCxrQkFBa0IsSUFBSSxjQUFjLEVBQUUsQ0FFckM7SUFFRCxPQUFPLENBQUMsYUFBYSxDQUVuQjtZQUVZLGtCQUFrQjtJQTRCaEMsT0FBTyxDQUFDLHNCQUFzQjtZQVNoQix3QkFBd0I7WUE2Q3hCLG1CQUFtQjtJQXNEakMsT0FBTyxDQUFDLFlBQVk7SUFNcEIsT0FBTyxDQUFDLFlBQVk7Q0FLckIifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframe_connection_handler.d.ts","sourceRoot":"","sources":["../../../src/iframe/handlers/iframe_connection_handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAgBrD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KA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;IAMhC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IANnB,OAAO,CAAC,eAAe,CAAqC;IAC5D,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,GAAG,CAAyC;IAEpD,YACU,MAAM,EAAE,sBAAsB,EAC9B,SAAS,EAAE,yBAAyB,EAC1C;IAEJ,KAAK,IAAI,IAAI,CAIZ;IAED,IAAI,IAAI,IAAI,CAEX;IAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAkBxC;IAED,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEvC;IAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAUxC;IAED,kBAAkB,IAAI,cAAc,EAAE,CAErC;IAED,OAAO,CAAC,aAAa,CAEnB;YAEY,kBAAkB;IA4BhC,OAAO,CAAC,sBAAsB;YAShB,wBAAwB;YA6CxB,mBAAmB;IAsDjC,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,YAAY;CAKrB"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IframeConnectionHandler — wallet-side of the cross-origin iframe protocol.
|
|
3
|
+
*
|
|
4
|
+
* This mirrors {@link BackgroundConnectionHandler} from `@aztec/wallet-sdk/extension/handlers`
|
|
5
|
+
* but uses `window.postMessage` instead of browser.runtime messaging.
|
|
6
|
+
*
|
|
7
|
+
* Message flow (wallet receives):
|
|
8
|
+
* parent → DISCOVERY → show approval UI → send DISCOVERY_RESPONSE
|
|
9
|
+
* parent → KEY_EXCHANGE_REQUEST → ECDH → send KEY_EXCHANGE_RESPONSE
|
|
10
|
+
* parent → SECURE_MESSAGE → decrypt → Wallet → encrypt → SECURE_RESPONSE
|
|
11
|
+
* parent → DISCONNECT → terminate session
|
|
12
|
+
*
|
|
13
|
+
* The wallet announces itself by posting WALLET_READY as soon as the handler starts,
|
|
14
|
+
* so the dApp knows it can send a discovery request.
|
|
15
|
+
*/ import { createLogger } from '@aztec/aztec.js/log';
|
|
16
|
+
import { WalletSchema } from '@aztec/aztec.js/wallet';
|
|
17
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
18
|
+
import { parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
|
|
19
|
+
import { decrypt, deriveSessionKeys, encrypt, exportPublicKey, generateKeyPair, importPublicKey } from '../../crypto.js';
|
|
20
|
+
import { WalletMessageType } from '../../types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Handles the wallet side of the cross-origin iframe protocol.
|
|
23
|
+
*
|
|
24
|
+
* Manages the full lifecycle: discovery, ECDH key exchange, encrypted message
|
|
25
|
+
* dispatch to a {@link Wallet} instance, and session termination.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const handler = new IframeConnectionHandler(
|
|
30
|
+
* { walletId: 'my-wallet', walletName: 'My Wallet', walletVersion: '1.0.0' },
|
|
31
|
+
* {
|
|
32
|
+
* onPendingDiscovery: (session) => showApprovalUI(session),
|
|
33
|
+
* getWallet: (appId, chainInfo) => createWalletForApp(appId, chainInfo),
|
|
34
|
+
* },
|
|
35
|
+
* );
|
|
36
|
+
* handler.start();
|
|
37
|
+
* ```
|
|
38
|
+
*/ export class IframeConnectionHandler {
|
|
39
|
+
config;
|
|
40
|
+
callbacks;
|
|
41
|
+
pendingSessions;
|
|
42
|
+
activeSessions;
|
|
43
|
+
log;
|
|
44
|
+
constructor(config, callbacks){
|
|
45
|
+
this.config = config;
|
|
46
|
+
this.callbacks = callbacks;
|
|
47
|
+
this.pendingSessions = new Map();
|
|
48
|
+
this.activeSessions = new Map();
|
|
49
|
+
this.log = createLogger('wallet:iframe-handler');
|
|
50
|
+
this.handleMessage = (event)=>{
|
|
51
|
+
void this.handleMessageAsync(event);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
start() {
|
|
55
|
+
window.addEventListener('message', this.handleMessage);
|
|
56
|
+
this.postToParent({
|
|
57
|
+
type: WalletMessageType.WALLET_READY
|
|
58
|
+
});
|
|
59
|
+
this.log.info('IframeConnectionHandler started, posted WALLET_READY');
|
|
60
|
+
}
|
|
61
|
+
stop() {
|
|
62
|
+
window.removeEventListener('message', this.handleMessage);
|
|
63
|
+
}
|
|
64
|
+
approveDiscovery(requestId) {
|
|
65
|
+
const pending = this.pendingSessions.get(requestId);
|
|
66
|
+
if (!pending || pending.status !== 'pending') {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
pending.status = 'approved';
|
|
70
|
+
this.postToOrigin(pending.origin, {
|
|
71
|
+
type: WalletMessageType.DISCOVERY_RESPONSE,
|
|
72
|
+
requestId,
|
|
73
|
+
walletInfo: {
|
|
74
|
+
id: this.config.walletId,
|
|
75
|
+
name: this.config.walletName,
|
|
76
|
+
version: this.config.walletVersion,
|
|
77
|
+
icon: this.config.walletIcon
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.log.info(`Discovery approved for requestId=${requestId}`);
|
|
81
|
+
}
|
|
82
|
+
rejectDiscovery(requestId) {
|
|
83
|
+
this.pendingSessions.delete(requestId);
|
|
84
|
+
}
|
|
85
|
+
terminateSession(sessionId) {
|
|
86
|
+
const session = this.activeSessions.get(sessionId);
|
|
87
|
+
if (session) {
|
|
88
|
+
this.postToOrigin(session.origin, {
|
|
89
|
+
type: WalletMessageType.SESSION_DISCONNECTED,
|
|
90
|
+
sessionId
|
|
91
|
+
});
|
|
92
|
+
this.activeSessions.delete(sessionId);
|
|
93
|
+
this.callbacks.onSessionTerminated?.(sessionId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
getPendingSessions() {
|
|
97
|
+
return Array.from(this.pendingSessions.values()).filter((s)=>s.status === 'pending');
|
|
98
|
+
}
|
|
99
|
+
handleMessage;
|
|
100
|
+
async handleMessageAsync(event) {
|
|
101
|
+
if (this.config.allowedOrigins && this.config.allowedOrigins.length > 0) {
|
|
102
|
+
if (!this.config.allowedOrigins.includes(event.origin)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const msg = event.data;
|
|
107
|
+
if (!msg || typeof msg !== 'object' || !msg.type) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
switch(msg.type){
|
|
111
|
+
case WalletMessageType.DISCOVERY:
|
|
112
|
+
this.handleDiscoveryRequest(msg, event.origin);
|
|
113
|
+
break;
|
|
114
|
+
case WalletMessageType.KEY_EXCHANGE_REQUEST:
|
|
115
|
+
await this.handleKeyExchangeRequest(msg, event.origin);
|
|
116
|
+
break;
|
|
117
|
+
case WalletMessageType.SECURE_MESSAGE:
|
|
118
|
+
await this.handleSecureMessage(msg);
|
|
119
|
+
break;
|
|
120
|
+
case WalletMessageType.DISCONNECT:
|
|
121
|
+
this.terminateSession(msg.sessionId);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
handleDiscoveryRequest(msg, origin) {
|
|
126
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
127
|
+
const { requestId, appId } = msg;
|
|
128
|
+
const pending = {
|
|
129
|
+
requestId,
|
|
130
|
+
appId,
|
|
131
|
+
origin,
|
|
132
|
+
status: 'pending'
|
|
133
|
+
};
|
|
134
|
+
this.pendingSessions.set(requestId, pending);
|
|
135
|
+
this.log.info(`Discovery request from appId=${appId} origin=${origin}`);
|
|
136
|
+
this.callbacks.onPendingDiscovery?.(pending);
|
|
137
|
+
}
|
|
138
|
+
async handleKeyExchangeRequest(msg, origin) {
|
|
139
|
+
const { requestId, publicKey: appPublicKeyRaw } = msg;
|
|
140
|
+
const pending = this.pendingSessions.get(requestId);
|
|
141
|
+
if (!pending || pending.status !== 'approved') {
|
|
142
|
+
this.log.warn(`Key exchange for unknown/unapproved requestId=${requestId}`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const keyPair = await generateKeyPair();
|
|
147
|
+
const walletPublicKey = await exportPublicKey(keyPair.publicKey);
|
|
148
|
+
const appPublicKey = await importPublicKey(appPublicKeyRaw);
|
|
149
|
+
const sessionKeys = await deriveSessionKeys(keyPair, appPublicKey, false);
|
|
150
|
+
const session = {
|
|
151
|
+
sessionId: requestId,
|
|
152
|
+
sharedKey: sessionKeys.encryptionKey,
|
|
153
|
+
verificationHash: sessionKeys.verificationHash,
|
|
154
|
+
origin: pending.origin,
|
|
155
|
+
appId: pending.appId
|
|
156
|
+
};
|
|
157
|
+
this.activeSessions.set(requestId, session);
|
|
158
|
+
this.pendingSessions.delete(requestId);
|
|
159
|
+
this.postToOrigin(origin, {
|
|
160
|
+
type: WalletMessageType.KEY_EXCHANGE_RESPONSE,
|
|
161
|
+
requestId,
|
|
162
|
+
publicKey: walletPublicKey,
|
|
163
|
+
verificationHash: sessionKeys.verificationHash
|
|
164
|
+
});
|
|
165
|
+
this.callbacks.onVerificationHash?.(sessionKeys.verificationHash);
|
|
166
|
+
this.callbacks.onSessionEstablished?.(session);
|
|
167
|
+
this.log.info(`Key exchange complete, sessionId=${requestId}`);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
this.log.error(`Key exchange failed: ${err}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async handleSecureMessage(msg) {
|
|
173
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
174
|
+
const { sessionId, encrypted } = msg;
|
|
175
|
+
const session = this.activeSessions.get(sessionId);
|
|
176
|
+
if (!session) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
let walletMessage;
|
|
180
|
+
try {
|
|
181
|
+
walletMessage = await decrypt(session.sharedKey, encrypted);
|
|
182
|
+
} catch {
|
|
183
|
+
this.log.warn(`Decryption failed for sessionId=${sessionId}`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const { messageId, type, args, chainInfo, appId } = walletMessage;
|
|
187
|
+
let result;
|
|
188
|
+
let error;
|
|
189
|
+
try {
|
|
190
|
+
const wallet = await this.callbacks.getWallet(appId, chainInfo);
|
|
191
|
+
if (!schemaHasMethod(WalletSchema, type)) {
|
|
192
|
+
throw new Error(`Unknown wallet method: ${type}`);
|
|
193
|
+
}
|
|
194
|
+
// Zod's AnyZodTuple rejects optional tuple items typed as `T | undefined`
|
|
195
|
+
const sanitizedArgs = await parseWithOptionals(args, WalletSchema[type].parameters());
|
|
196
|
+
result = await wallet[type](...sanitizedArgs);
|
|
197
|
+
} catch (err) {
|
|
198
|
+
error = err instanceof Error ? err.message : String(err);
|
|
199
|
+
this.log.error(`Error handling ${type}: ${error}`);
|
|
200
|
+
}
|
|
201
|
+
const response = {
|
|
202
|
+
messageId,
|
|
203
|
+
walletId: this.config.walletId,
|
|
204
|
+
result,
|
|
205
|
+
error
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
const encryptedResponse = await encrypt(session.sharedKey, jsonStringify(response));
|
|
209
|
+
this.postToOrigin(session.origin, {
|
|
210
|
+
type: WalletMessageType.SECURE_RESPONSE,
|
|
211
|
+
sessionId,
|
|
212
|
+
encrypted: encryptedResponse
|
|
213
|
+
});
|
|
214
|
+
} catch (err) {
|
|
215
|
+
this.log.error(`Encryption of response failed: ${err}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
postToParent(msg) {
|
|
219
|
+
if (window.parent !== window) {
|
|
220
|
+
window.parent.postMessage(msg, '*');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
postToOrigin(origin, msg) {
|
|
224
|
+
if (window.parent !== window) {
|
|
225
|
+
window.parent.postMessage(msg, origin);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { IframeConnectionHandler, type IframeConnectionConfig, type IframeConnectionCallbacks, type PendingSession, type ActiveSession, } from './iframe_connection_handler.js';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9pZnJhbWUvaGFuZGxlcnMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUNMLHVCQUF1QixFQUN2QixLQUFLLHNCQUFzQixFQUMzQixLQUFLLHlCQUF5QixFQUM5QixLQUFLLGNBQWMsRUFDbkIsS0FBSyxhQUFhLEdBQ25CLE1BQU0sZ0NBQWdDLENBQUMifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/iframe/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IframeConnectionHandler } from './iframe_connection_handler.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web wallet discovery — creates {@link IframeWalletProvider} instances from a list of URLs.
|
|
3
|
+
*
|
|
4
|
+
* For each configured URL we probe the wallet by loading a tiny invisible iframe,
|
|
5
|
+
* waiting for WALLET_READY, then sending a DISCOVERY request. On a successful
|
|
6
|
+
* DISCOVERY_RESPONSE we emit an IframeWalletProvider to the caller.
|
|
7
|
+
*
|
|
8
|
+
* This is intentionally lightweight (no key exchange yet) — key exchange happens
|
|
9
|
+
* later when the user selects the wallet and calls `provider.establishSecureChannel()`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
12
|
+
import type { DiscoverySession } from '../../manager/types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Probes a list of web wallet URLs and returns a {@link DiscoverySession} compatible
|
|
15
|
+
* with WalletManager's `getAvailableWallets()` interface.
|
|
16
|
+
*
|
|
17
|
+
* Discovered {@link IframeWalletProvider} instances are yielded asynchronously as each
|
|
18
|
+
* wallet responds to the probe.
|
|
19
|
+
*
|
|
20
|
+
* @param walletUrls - URLs of web wallets to probe
|
|
21
|
+
* @param chainInfo - Network information to pass during discovery
|
|
22
|
+
* @returns A cancellable discovery session
|
|
23
|
+
*/
|
|
24
|
+
export declare function discoverWebWallets(walletUrls: string[], chainInfo: ChainInfo): DiscoverySession;
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWZyYW1lX2Rpc2NvdmVyeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2lmcmFtZS9wcm92aWRlci9pZnJhbWVfZGlzY292ZXJ5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7R0FTRztBQUNILE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBR3pELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFrQixNQUFNLHdCQUF3QixDQUFDO0FBTS9FOzs7Ozs7Ozs7O0dBVUc7QUFDSCx3QkFBZ0Isa0JBQWtCLENBQUMsVUFBVSxFQUFFLE1BQU0sRUFBRSxFQUFFLFNBQVMsRUFBRSxTQUFTLEdBQUcsZ0JBQWdCLENBdUYvRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframe_discovery.d.ts","sourceRoot":"","sources":["../../../src/iframe/provider/iframe_discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,wBAAwB,CAAC;AAM/E;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,GAAG,gBAAgB,CAuF/F"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web wallet discovery — creates {@link IframeWalletProvider} instances from a list of URLs.
|
|
3
|
+
*
|
|
4
|
+
* For each configured URL we probe the wallet by loading a tiny invisible iframe,
|
|
5
|
+
* waiting for WALLET_READY, then sending a DISCOVERY request. On a successful
|
|
6
|
+
* DISCOVERY_RESPONSE we emit an IframeWalletProvider to the caller.
|
|
7
|
+
*
|
|
8
|
+
* This is intentionally lightweight (no key exchange yet) — key exchange happens
|
|
9
|
+
* later when the user selects the wallet and calls `provider.establishSecureChannel()`.
|
|
10
|
+
*/ import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
11
|
+
import { WalletMessageType } from '../../types.js';
|
|
12
|
+
import { IframeWalletProvider } from './iframe_provider.js';
|
|
13
|
+
const PROBE_TIMEOUT_MS = 10_000;
|
|
14
|
+
/**
|
|
15
|
+
* Probes a list of web wallet URLs and returns a {@link DiscoverySession} compatible
|
|
16
|
+
* with WalletManager's `getAvailableWallets()` interface.
|
|
17
|
+
*
|
|
18
|
+
* Discovered {@link IframeWalletProvider} instances are yielded asynchronously as each
|
|
19
|
+
* wallet responds to the probe.
|
|
20
|
+
*
|
|
21
|
+
* @param walletUrls - URLs of web wallets to probe
|
|
22
|
+
* @param chainInfo - Network information to pass during discovery
|
|
23
|
+
* @returns A cancellable discovery session
|
|
24
|
+
*/ export function discoverWebWallets(walletUrls, chainInfo) {
|
|
25
|
+
const { promise: donePromise, resolve: resolveDone } = promiseWithResolvers();
|
|
26
|
+
/* eslint-enable jsdoc/require-jsdoc */ let state = {
|
|
27
|
+
status: 'discovering',
|
|
28
|
+
resolve: null
|
|
29
|
+
};
|
|
30
|
+
const pendingProviders = [];
|
|
31
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
32
|
+
function emit(provider) {
|
|
33
|
+
if (state.status !== 'discovering') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (state.resolve) {
|
|
37
|
+
const resolve = state.resolve;
|
|
38
|
+
state.resolve = null;
|
|
39
|
+
resolve({
|
|
40
|
+
value: provider,
|
|
41
|
+
done: false
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
pendingProviders.push(provider);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
48
|
+
function markComplete() {
|
|
49
|
+
if (state.status !== 'discovering') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const pendingResolve = state.resolve;
|
|
53
|
+
state = {
|
|
54
|
+
status: 'done'
|
|
55
|
+
};
|
|
56
|
+
resolveDone();
|
|
57
|
+
if (pendingResolve) {
|
|
58
|
+
pendingResolve({
|
|
59
|
+
value: undefined,
|
|
60
|
+
done: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Probe all URLs in parallel
|
|
65
|
+
const probes = walletUrls.map((url)=>probeWallet(url, chainInfo, PROBE_TIMEOUT_MS).then((provider)=>{
|
|
66
|
+
if (provider) {
|
|
67
|
+
emit(provider);
|
|
68
|
+
}
|
|
69
|
+
}, ()=>{
|
|
70
|
+
// ignore probe errors
|
|
71
|
+
}));
|
|
72
|
+
void Promise.all(probes).then(markComplete);
|
|
73
|
+
const wallets = {
|
|
74
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
75
|
+
[Symbol.asyncIterator] () {
|
|
76
|
+
return {
|
|
77
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
78
|
+
next () {
|
|
79
|
+
if (pendingProviders.length > 0) {
|
|
80
|
+
return Promise.resolve({
|
|
81
|
+
value: pendingProviders.shift(),
|
|
82
|
+
done: false
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (state.status === 'done') {
|
|
86
|
+
return Promise.resolve({
|
|
87
|
+
value: undefined,
|
|
88
|
+
done: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve)=>{
|
|
92
|
+
if (state.status === 'discovering') {
|
|
93
|
+
state.resolve = resolve;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
98
|
+
return () {
|
|
99
|
+
markComplete();
|
|
100
|
+
return Promise.resolve({
|
|
101
|
+
value: undefined,
|
|
102
|
+
done: true
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
wallets,
|
|
110
|
+
done: donePromise,
|
|
111
|
+
cancel: markComplete
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Probes a single web wallet URL.
|
|
116
|
+
* Creates a temporary hidden iframe, waits for WALLET_READY, sends DISCOVERY_REQUEST.
|
|
117
|
+
* Returns an IframeWalletProvider on success, null on timeout/failure.
|
|
118
|
+
* @internal
|
|
119
|
+
*/ function probeWallet(walletUrl, chainInfo, timeoutMs) {
|
|
120
|
+
const walletOrigin = new URL(walletUrl).origin;
|
|
121
|
+
const iframe = document.createElement('iframe');
|
|
122
|
+
iframe.src = walletUrl;
|
|
123
|
+
iframe.style.cssText = 'display:none;width:0;height:0;border:none;position:absolute;top:-9999px;';
|
|
124
|
+
iframe.allow = 'storage-access; cross-origin-isolated';
|
|
125
|
+
let timer;
|
|
126
|
+
// Register listener BEFORE appending to DOM to avoid race with WALLET_READY
|
|
127
|
+
const result = new Promise((resolve)=>{
|
|
128
|
+
const cleanup = ()=>{
|
|
129
|
+
if (iframe.parentNode) {
|
|
130
|
+
iframe.parentNode.removeChild(iframe);
|
|
131
|
+
}
|
|
132
|
+
window.removeEventListener('message', handler);
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
};
|
|
135
|
+
timer = setTimeout(()=>{
|
|
136
|
+
cleanup();
|
|
137
|
+
resolve(null);
|
|
138
|
+
}, timeoutMs);
|
|
139
|
+
let step = 'waiting-ready';
|
|
140
|
+
const requestId = globalThis.crypto.randomUUID();
|
|
141
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
142
|
+
function handler(event) {
|
|
143
|
+
if (event.origin !== walletOrigin) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const msg = event.data;
|
|
147
|
+
if (!msg || typeof msg !== 'object') {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (step === 'waiting-ready' && msg.type === WalletMessageType.WALLET_READY) {
|
|
151
|
+
step = 'waiting-discovery';
|
|
152
|
+
iframe.contentWindow?.postMessage({
|
|
153
|
+
type: WalletMessageType.DISCOVERY,
|
|
154
|
+
requestId,
|
|
155
|
+
appId: 'discovery-probe'
|
|
156
|
+
}, walletOrigin);
|
|
157
|
+
} else if (step === 'waiting-discovery' && msg.type === WalletMessageType.DISCOVERY_RESPONSE && msg.requestId === requestId) {
|
|
158
|
+
const info = msg.walletInfo;
|
|
159
|
+
cleanup();
|
|
160
|
+
resolve(new IframeWalletProvider(info.id, info.name, info.icon, walletUrl, chainInfo));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
window.addEventListener('message', handler);
|
|
164
|
+
});
|
|
165
|
+
document.body.appendChild(iframe);
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IframeWalletProvider — implements {@link WalletProvider} for web wallets loaded in iframes.
|
|
3
|
+
*
|
|
4
|
+
* Flow (mirrors ExtensionProvider):
|
|
5
|
+
* 1. Creates an `<iframe src="walletUrl">` (in app-provided container or floating panel)
|
|
6
|
+
* 2. Waits for WALLET_READY message from the iframe
|
|
7
|
+
* 3. Sends DISCOVERY → waits for DISCOVERY_RESPONSE
|
|
8
|
+
* 4. Sends KEY_EXCHANGE_REQUEST (ECDH public key) → waits for KEY_EXCHANGE_RESPONSE
|
|
9
|
+
* 5. Derives shared session keys, exposes verificationHash
|
|
10
|
+
* 6. On confirm(): returns IframeWallet backed by the established session
|
|
11
|
+
*/
|
|
12
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
13
|
+
import type { PendingConnection, ProviderDisconnectionCallback, WalletProvider } from '../../manager/types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Options for {@link IframeWalletProvider.establishSecureChannel}.
|
|
16
|
+
*/
|
|
17
|
+
export interface IframeConnectionOptions {
|
|
18
|
+
/** Container element to inject the iframe into. If omitted, a floating panel is created. */
|
|
19
|
+
container?: HTMLElement;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A {@link WalletProvider} that connects to a web wallet loaded in a cross-origin iframe.
|
|
23
|
+
*
|
|
24
|
+
* Discovered via {@link discoverWebWallets} and used through the standard
|
|
25
|
+
* `WalletProvider.establishSecureChannel()` flow.
|
|
26
|
+
*/
|
|
27
|
+
export declare class IframeWalletProvider implements WalletProvider {
|
|
28
|
+
/** Unique wallet identifier. */
|
|
29
|
+
readonly id: string;
|
|
30
|
+
/** Display name for the wallet. */
|
|
31
|
+
readonly name: string;
|
|
32
|
+
/** Optional wallet icon URL. */
|
|
33
|
+
readonly icon: string | undefined;
|
|
34
|
+
private readonly walletUrl;
|
|
35
|
+
private readonly chainInfo;
|
|
36
|
+
readonly type: "web";
|
|
37
|
+
private iframe;
|
|
38
|
+
private _container;
|
|
39
|
+
private _appOwnsContainer;
|
|
40
|
+
private _dragCleanup;
|
|
41
|
+
private wallet;
|
|
42
|
+
private _disconnected;
|
|
43
|
+
private disconnectCallbacks;
|
|
44
|
+
constructor(
|
|
45
|
+
/** Unique wallet identifier. */
|
|
46
|
+
id: string,
|
|
47
|
+
/** Display name for the wallet. */
|
|
48
|
+
name: string,
|
|
49
|
+
/** Optional wallet icon URL. */
|
|
50
|
+
icon: string | undefined, walletUrl: string, chainInfo: ChainInfo);
|
|
51
|
+
/**
|
|
52
|
+
* Establishes a secure encrypted channel with the iframe wallet.
|
|
53
|
+
*
|
|
54
|
+
* @param appId - Application identifier for the requesting dApp
|
|
55
|
+
* @param options - Optional container element for the iframe
|
|
56
|
+
* @returns A {@link PendingConnection} with verification hash and confirm/cancel
|
|
57
|
+
*/
|
|
58
|
+
establishSecureChannel(appId: string, options?: IframeConnectionOptions): Promise<PendingConnection>;
|
|
59
|
+
disconnect(): Promise<void>;
|
|
60
|
+
onDisconnect(callback: ProviderDisconnectionCallback): () => void;
|
|
61
|
+
isDisconnected(): boolean;
|
|
62
|
+
private createFloatingPanel;
|
|
63
|
+
private cleanup;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWZyYW1lX3Byb3ZpZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaWZyYW1lL3Byb3ZpZGVyL2lmcmFtZV9wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7Ozs7OztHQVVHO0FBQ0gsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFVekQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsNkJBQTZCLEVBQUUsY0FBYyxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFTL0c7O0dBRUc7QUFDSCxNQUFNLFdBQVcsdUJBQXVCO0lBQ3RDLDRGQUE0RjtJQUM1RixTQUFTLENBQUMsRUFBRSxXQUFXLENBQUM7Q0FDekI7QUFFRDs7Ozs7R0FLRztBQUNILHFCQUFhLG9CQUFxQixZQUFXLGNBQWM7SUFZdkQsZ0NBQWdDO2FBQ2hCLEVBQUUsRUFBRSxNQUFNO0lBQzFCLG1DQUFtQzthQUNuQixJQUFJLEVBQUUsTUFBTTtJQUM1QixnQ0FBZ0M7YUFDaEIsSUFBSSxFQUFFLE1BQU0sR0FBRyxTQUFTO0lBQ3hDLE9BQU8sQ0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