@hsuite/native-connect-angular 3.0.2 → 3.0.3
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.
|
@@ -1847,6 +1847,26 @@ class ConnectionInProgressError extends Error {
|
|
|
1847
1847
|
}
|
|
1848
1848
|
}
|
|
1849
1849
|
|
|
1850
|
+
/**
|
|
1851
|
+
* HSuite Native Connect
|
|
1852
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
1853
|
+
*
|
|
1854
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
1855
|
+
*
|
|
1856
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
1857
|
+
* visit https://hsuite.finance/licensing
|
|
1858
|
+
*/
|
|
1859
|
+
const MOBILE_USER_AGENT = /iPhone|iPad|iPod|Android/i;
|
|
1860
|
+
/**
|
|
1861
|
+
* Whether a user agent string names a phone or tablet OS. An iPad that asks for
|
|
1862
|
+
* desktop sites reports a Mac user agent and is NOT matched here.
|
|
1863
|
+
* @param userAgent - `navigator.userAgent`
|
|
1864
|
+
* @returns true for iPhone, iPad, iPod and Android user agents
|
|
1865
|
+
*/
|
|
1866
|
+
function isMobileUserAgent(userAgent) {
|
|
1867
|
+
return MOBILE_USER_AGENT.test(userAgent);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1850
1870
|
/**
|
|
1851
1871
|
* HSuite Native Connect
|
|
1852
1872
|
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
@@ -3533,7 +3553,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
3533
3553
|
* @param config - Connection configuration with app metadata
|
|
3534
3554
|
*/
|
|
3535
3555
|
async openWalletWindow(inviteUrl, walletBaseUrl, config) {
|
|
3536
|
-
const isMobile =
|
|
3556
|
+
const isMobile = isMobileUserAgent(navigator.userAgent);
|
|
3537
3557
|
// LOCAL-FIRST DISCOVERY
|
|
3538
3558
|
// Wait briefly for wallet heartbeat before opening new tab
|
|
3539
3559
|
if (this.localDiscoveryService?.active) {
|
|
@@ -5019,6 +5039,346 @@ class SignerFactory {
|
|
|
5019
5039
|
}
|
|
5020
5040
|
}
|
|
5021
5041
|
|
|
5042
|
+
/**
|
|
5043
|
+
* HSuite Native Connect
|
|
5044
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
5045
|
+
*
|
|
5046
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
5047
|
+
*
|
|
5048
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
5049
|
+
* visit https://hsuite.finance/licensing
|
|
5050
|
+
*/
|
|
5051
|
+
/**
|
|
5052
|
+
* @file hedera-host-wallet.ts
|
|
5053
|
+
* @description Pair through the Hedera wallet that is HOSTING this page
|
|
5054
|
+
*
|
|
5055
|
+
* WHY: opened inside a wallet's own dApp browser on a phone, WalletConnect's
|
|
5056
|
+
* modal hands the pairing link over by deep link, and a deep link into the app
|
|
5057
|
+
* the page already runs in goes nowhere, so the connection never completes.
|
|
5058
|
+
*
|
|
5059
|
+
* THE PROTOCOL is Hedera's own, from `@hashgraph/hedera-wallet-connect`
|
|
5060
|
+
* (`extensionController`, `DAppConnector.connectExtension`, `DAppSigner.request`),
|
|
5061
|
+
* which wallet extensions and in-app browsers answer:
|
|
5062
|
+
*
|
|
5063
|
+
* page → `hedera-extension-query` (and `hedera-iframe-query` to a parent frame)
|
|
5064
|
+
* wallet → `hedera-extension-response` {metadata: {id, name, …}}
|
|
5065
|
+
* (`hedera-iframe-response` from a parent frame)
|
|
5066
|
+
* page → `hedera-extension-connect-<id>` {pairingString: <wc: uri>}
|
|
5067
|
+
* (`hedera-iframe-connect` to a parent frame)
|
|
5068
|
+
* page → `hedera-extension-open-<id>` before every request, so the wallet
|
|
5069
|
+
* brings up its approval sheet
|
|
5070
|
+
*
|
|
5071
|
+
* WHEN IT APPLIES: a wallet that frames the page, only when the dApp listed
|
|
5072
|
+
* that wallet's origin ({@link HEDERA_HOST_WALLET_PARENT_ORIGINS}); a
|
|
5073
|
+
* same-window answer only on a phone or tablet. A framing page gets the
|
|
5074
|
+
* pairing link, and with it the power to answer the connection with its own
|
|
5075
|
+
* wallet, so one the dApp did not name is never asked and never answered. On desktop the same answer comes from a browser
|
|
5076
|
+
* EXTENSION (HashPack, Kabila), and those users keep the modal and its choice of
|
|
5077
|
+
* wallet. A phone has no Hedera wallet extensions, so an answer there means the
|
|
5078
|
+
* page runs inside that wallet's own browser.
|
|
5079
|
+
*
|
|
5080
|
+
* NOTHING IS POSTED UNTIL IT IS NEEDED: the wallet is asked for on the first
|
|
5081
|
+
* Hedera pairing, or on the first request of a session remembered as paired
|
|
5082
|
+
* through a wallet (after a reload). A page that never uses Hedera, or runs on a
|
|
5083
|
+
* desktop outside a frame, posts no message at all.
|
|
5084
|
+
*
|
|
5085
|
+
* Nothing here signs anything: it routes the pairing link WalletConnect already
|
|
5086
|
+
* produced, and remembers which session was paired this way so the approval
|
|
5087
|
+
* sheet ping goes only to that session.
|
|
5088
|
+
*/
|
|
5089
|
+
const HOST_WALLET_EVENTS = {
|
|
5090
|
+
query: 'hedera-extension-query',
|
|
5091
|
+
response: 'hedera-extension-response',
|
|
5092
|
+
connectPrefix: 'hedera-extension-connect-',
|
|
5093
|
+
openPrefix: 'hedera-extension-open-',
|
|
5094
|
+
iframeQuery: 'hedera-iframe-query',
|
|
5095
|
+
iframeResponse: 'hedera-iframe-response',
|
|
5096
|
+
iframeConnect: 'hedera-iframe-connect',
|
|
5097
|
+
};
|
|
5098
|
+
/** A pairing link or a request is due and no wallet has answered yet: how long to wait for an answer. */
|
|
5099
|
+
const HOST_WALLET_REQUERY_WAIT_MS = 600;
|
|
5100
|
+
/** How long a hosting wallet has to approve a handed-over pairing before the modal opens after all. */
|
|
5101
|
+
const HOST_WALLET_HANDOFF_TIMEOUT_MS = 20_000;
|
|
5102
|
+
/** Storage key prefix: the host wallet a session (by WalletConnect topic) was paired through. */
|
|
5103
|
+
const HOST_WALLET_PAIRED_KEY_PREFIX = 'hsuite.walletconnect.hostWallet.';
|
|
5104
|
+
/** Wallet ids are short tokens; anything else is not an answer to act on. */
|
|
5105
|
+
const WALLET_ID = /^[A-Za-z0-9._:-]{1,100}$/;
|
|
5106
|
+
const REAL_CLOCK = {
|
|
5107
|
+
schedule: (fn, ms) => setTimeout(fn, ms),
|
|
5108
|
+
cancel: (timer) => clearTimeout(timer),
|
|
5109
|
+
};
|
|
5110
|
+
/**
|
|
5111
|
+
* A wallet's answer to the query, or null for anything else (malformed, or another message).
|
|
5112
|
+
* @param data - The message payload
|
|
5113
|
+
* @param viaParent - Whether it came from a parent frame
|
|
5114
|
+
* @param origin - The sending window's origin
|
|
5115
|
+
*/
|
|
5116
|
+
function parseHostWalletMessage(data, viaParent, origin) {
|
|
5117
|
+
if (!data || typeof data !== 'object')
|
|
5118
|
+
return null;
|
|
5119
|
+
const msg = data;
|
|
5120
|
+
const expected = viaParent ? HOST_WALLET_EVENTS.iframeResponse : HOST_WALLET_EVENTS.response;
|
|
5121
|
+
if (msg.type !== expected || !msg.metadata || typeof msg.metadata !== 'object')
|
|
5122
|
+
return null;
|
|
5123
|
+
const meta = msg.metadata;
|
|
5124
|
+
if (typeof meta.id !== 'string' || !WALLET_ID.test(meta.id))
|
|
5125
|
+
return null;
|
|
5126
|
+
const name = typeof meta.name === 'string' && meta.name.trim() ? meta.name.trim().slice(0, 60) : meta.id;
|
|
5127
|
+
return { id: meta.id, name, viaParent, origin };
|
|
5128
|
+
}
|
|
5129
|
+
/**
|
|
5130
|
+
* A phone or tablet: a mobile UA, or an iPad that asks for desktop sites (Mac UA with touch).
|
|
5131
|
+
* @param device - User agent and touch points
|
|
5132
|
+
*/
|
|
5133
|
+
function isTouchDevice(device) {
|
|
5134
|
+
return (isMobileUserAgent(device.userAgent) ||
|
|
5135
|
+
(/Macintosh/.test(device.userAgent) && device.maxTouchPoints > 1));
|
|
5136
|
+
}
|
|
5137
|
+
/**
|
|
5138
|
+
* Whether to route through `wallet`: always when it frames the page, otherwise only on a phone or tablet.
|
|
5139
|
+
* @param wallet - The wallet that answered, if any
|
|
5140
|
+
* @param device - User agent and touch points
|
|
5141
|
+
*/
|
|
5142
|
+
function shouldUseHostWallet(wallet, device) {
|
|
5143
|
+
if (!wallet)
|
|
5144
|
+
return false;
|
|
5145
|
+
return wallet.viaParent || isTouchDevice(device);
|
|
5146
|
+
}
|
|
5147
|
+
/**
|
|
5148
|
+
* Finds a hosting Hedera wallet and routes pairing links and approval pings to it.
|
|
5149
|
+
*/
|
|
5150
|
+
class HederaHostWalletLink {
|
|
5151
|
+
win;
|
|
5152
|
+
device;
|
|
5153
|
+
store;
|
|
5154
|
+
clock;
|
|
5155
|
+
trustedParentOrigins;
|
|
5156
|
+
found = null;
|
|
5157
|
+
stop = null;
|
|
5158
|
+
waiters = [];
|
|
5159
|
+
/**
|
|
5160
|
+
* @param win - The page's window
|
|
5161
|
+
* @param device - User agent and touch points
|
|
5162
|
+
* @param store - Where paired sessions are remembered, or null
|
|
5163
|
+
* @param clock - Timers
|
|
5164
|
+
* @param trustedParentOrigins - Origins of wallets allowed to frame this
|
|
5165
|
+
* page and take its pairing link. Empty: no framing page is trusted.
|
|
5166
|
+
*/
|
|
5167
|
+
constructor(win, device, store, clock = REAL_CLOCK, trustedParentOrigins = []) {
|
|
5168
|
+
this.win = win;
|
|
5169
|
+
this.device = device;
|
|
5170
|
+
this.store = store;
|
|
5171
|
+
this.clock = clock;
|
|
5172
|
+
this.trustedParentOrigins = trustedParentOrigins;
|
|
5173
|
+
}
|
|
5174
|
+
/**
|
|
5175
|
+
* Listen for a hosting wallet's answer. Posts nothing. `handOff` and `ping`
|
|
5176
|
+
* call this themselves; calling it again is a no-op. Returns the disposer.
|
|
5177
|
+
*/
|
|
5178
|
+
start() {
|
|
5179
|
+
if (!this.stop) {
|
|
5180
|
+
const listener = (event) => this.onMessage(event);
|
|
5181
|
+
this.win.addEventListener('message', listener);
|
|
5182
|
+
this.stop = () => {
|
|
5183
|
+
this.win.removeEventListener('message', listener);
|
|
5184
|
+
this.stop = null;
|
|
5185
|
+
this.release();
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
return this.stop;
|
|
5189
|
+
}
|
|
5190
|
+
/** The hosting wallet, when this page should connect through it. */
|
|
5191
|
+
active() {
|
|
5192
|
+
return shouldUseHostWallet(this.found, this.device) ? this.found : null;
|
|
5193
|
+
}
|
|
5194
|
+
/**
|
|
5195
|
+
* Hand a Hedera pairing link to the hosting wallet. Resolves null, with
|
|
5196
|
+
* nothing sent, when there is none: the caller opens the modal as before.
|
|
5197
|
+
* Otherwise resolves the wallet that took the link, and the modal still opens
|
|
5198
|
+
* if that wallet has not approved within HOST_WALLET_HANDOFF_TIMEOUT_MS, so a
|
|
5199
|
+
* wallet that ignores the link never leaves the user waiting on nothing.
|
|
5200
|
+
* @param pairing - The link, the modal fallback and the approval promise
|
|
5201
|
+
*/
|
|
5202
|
+
async handOff(pairing) {
|
|
5203
|
+
if (!pairing.uri.startsWith('wc:'))
|
|
5204
|
+
return null;
|
|
5205
|
+
this.start();
|
|
5206
|
+
if (!this.found && this.mayBeHosted()) {
|
|
5207
|
+
this.query();
|
|
5208
|
+
await this.answer(HOST_WALLET_REQUERY_WAIT_MS);
|
|
5209
|
+
}
|
|
5210
|
+
const wallet = this.active();
|
|
5211
|
+
if (!wallet)
|
|
5212
|
+
return null;
|
|
5213
|
+
this.post(wallet, pairing.uri);
|
|
5214
|
+
let pending = true;
|
|
5215
|
+
const fallback = this.clock.schedule(() => {
|
|
5216
|
+
if (!pending)
|
|
5217
|
+
return;
|
|
5218
|
+
pending = false;
|
|
5219
|
+
// The modal is best effort here: the connection itself still waits on `settled`.
|
|
5220
|
+
Promise.resolve()
|
|
5221
|
+
.then(() => pairing.openModal())
|
|
5222
|
+
.catch(() => undefined);
|
|
5223
|
+
}, HOST_WALLET_HANDOFF_TIMEOUT_MS);
|
|
5224
|
+
const settle = () => {
|
|
5225
|
+
pending = false;
|
|
5226
|
+
this.clock.cancel(fallback);
|
|
5227
|
+
};
|
|
5228
|
+
pairing.settled.then(settle, settle);
|
|
5229
|
+
return wallet;
|
|
5230
|
+
}
|
|
5231
|
+
/**
|
|
5232
|
+
* Remember that the session on `topic` was paired through `wallet`. Call once
|
|
5233
|
+
* the wallet has approved, not when the link is handed over.
|
|
5234
|
+
* @param topic - WalletConnect session topic
|
|
5235
|
+
* @param wallet - The wallet `handOff` resolved
|
|
5236
|
+
*/
|
|
5237
|
+
markPaired(topic, wallet) {
|
|
5238
|
+
try {
|
|
5239
|
+
this.store?.setItem(HOST_WALLET_PAIRED_KEY_PREFIX + topic, wallet.id);
|
|
5240
|
+
}
|
|
5241
|
+
catch {
|
|
5242
|
+
// Storage blocked: no ping for this session, nothing else changes.
|
|
5243
|
+
}
|
|
5244
|
+
}
|
|
5245
|
+
/**
|
|
5246
|
+
* Forget a session, when it is disconnected or deleted.
|
|
5247
|
+
* @param topic - WalletConnect session topic
|
|
5248
|
+
*/
|
|
5249
|
+
forget(topic) {
|
|
5250
|
+
try {
|
|
5251
|
+
this.store?.removeItem(HOST_WALLET_PAIRED_KEY_PREFIX + topic);
|
|
5252
|
+
}
|
|
5253
|
+
catch {
|
|
5254
|
+
// Storage blocked: there was nothing to forget.
|
|
5255
|
+
}
|
|
5256
|
+
}
|
|
5257
|
+
/**
|
|
5258
|
+
* Before a Hedera request on `topic`: ask the hosting wallet to show its
|
|
5259
|
+
* approval sheet, as `DAppSigner.request` does. Only for a session that was
|
|
5260
|
+
* paired through that wallet, and never to a parent frame (the reference
|
|
5261
|
+
* library has no such message). After a reload the wallet has not been asked
|
|
5262
|
+
* for yet: it is asked now, and pinged as soon as it answers.
|
|
5263
|
+
* @param topic - WalletConnect session topic
|
|
5264
|
+
*/
|
|
5265
|
+
ping(topic) {
|
|
5266
|
+
const pairedId = this.pairedWith(topic);
|
|
5267
|
+
if (!pairedId)
|
|
5268
|
+
return;
|
|
5269
|
+
const open = () => {
|
|
5270
|
+
const wallet = this.active();
|
|
5271
|
+
if (!wallet || wallet.viaParent || wallet.id !== pairedId)
|
|
5272
|
+
return;
|
|
5273
|
+
this.win.postMessage({ type: HOST_WALLET_EVENTS.openPrefix + wallet.id }, this.win.location.origin);
|
|
5274
|
+
};
|
|
5275
|
+
this.start();
|
|
5276
|
+
if (this.found || !this.mayBeHosted()) {
|
|
5277
|
+
open();
|
|
5278
|
+
return;
|
|
5279
|
+
}
|
|
5280
|
+
this.query();
|
|
5281
|
+
void this.answer(HOST_WALLET_REQUERY_WAIT_MS).then(open);
|
|
5282
|
+
}
|
|
5283
|
+
mayBeHosted() {
|
|
5284
|
+
return this.isFramedByTrusted() || isTouchDevice(this.device);
|
|
5285
|
+
}
|
|
5286
|
+
isFramed() {
|
|
5287
|
+
return !!this.win.parent && this.win.parent !== this.win;
|
|
5288
|
+
}
|
|
5289
|
+
/** Framed, and the dApp named at least one wallet origin that may frame it. */
|
|
5290
|
+
isFramedByTrusted() {
|
|
5291
|
+
return this.isFramed() && this.trustedParentOrigins.length > 0;
|
|
5292
|
+
}
|
|
5293
|
+
post(wallet, uri) {
|
|
5294
|
+
if (wallet.viaParent) {
|
|
5295
|
+
this.win.parent.postMessage({ type: HOST_WALLET_EVENTS.iframeConnect, pairingString: uri }, wallet.origin);
|
|
5296
|
+
}
|
|
5297
|
+
else {
|
|
5298
|
+
this.win.postMessage({ type: HOST_WALLET_EVENTS.connectPrefix + wallet.id, pairingString: uri }, this.win.location.origin);
|
|
5299
|
+
}
|
|
5300
|
+
}
|
|
5301
|
+
pairedWith(topic) {
|
|
5302
|
+
try {
|
|
5303
|
+
return this.store?.getItem(HOST_WALLET_PAIRED_KEY_PREFIX + topic) ?? null;
|
|
5304
|
+
}
|
|
5305
|
+
catch {
|
|
5306
|
+
return null;
|
|
5307
|
+
}
|
|
5308
|
+
}
|
|
5309
|
+
query() {
|
|
5310
|
+
this.win.postMessage({ type: HOST_WALLET_EVENTS.query }, this.win.location.origin);
|
|
5311
|
+
if (this.isFramedByTrusted()) {
|
|
5312
|
+
// Only to the wallets the dApp named: any other parent never hears of it.
|
|
5313
|
+
for (const origin of this.trustedParentOrigins) {
|
|
5314
|
+
this.win.parent.postMessage({ type: HOST_WALLET_EVENTS.iframeQuery }, origin);
|
|
5315
|
+
}
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
/**
|
|
5319
|
+
* Resolves when a wallet answers, or after `ms`.
|
|
5320
|
+
* @param ms - The longest to wait
|
|
5321
|
+
*/
|
|
5322
|
+
answer(ms) {
|
|
5323
|
+
return new Promise((resolve) => {
|
|
5324
|
+
const timer = this.clock.schedule(() => resolve(), ms);
|
|
5325
|
+
this.waiters = [
|
|
5326
|
+
...this.waiters,
|
|
5327
|
+
() => {
|
|
5328
|
+
this.clock.cancel(timer);
|
|
5329
|
+
resolve();
|
|
5330
|
+
},
|
|
5331
|
+
];
|
|
5332
|
+
});
|
|
5333
|
+
}
|
|
5334
|
+
release() {
|
|
5335
|
+
const waiters = this.waiters;
|
|
5336
|
+
this.waiters = [];
|
|
5337
|
+
waiters.forEach((w) => w());
|
|
5338
|
+
}
|
|
5339
|
+
onMessage(event) {
|
|
5340
|
+
if (this.found)
|
|
5341
|
+
return;
|
|
5342
|
+
const fromParent = this.isFramed() &&
|
|
5343
|
+
event.source === this.win.parent &&
|
|
5344
|
+
this.trustedParentOrigins.includes(event.origin);
|
|
5345
|
+
const fromSelf = event.source === this.win;
|
|
5346
|
+
if (!fromParent && !fromSelf)
|
|
5347
|
+
return;
|
|
5348
|
+
this.found = parseHostWalletMessage(event.data, fromParent, event.origin);
|
|
5349
|
+
if (this.found)
|
|
5350
|
+
this.release();
|
|
5351
|
+
}
|
|
5352
|
+
}
|
|
5353
|
+
/**
|
|
5354
|
+
* Origins of the Hedera wallets allowed to frame this dApp and take its
|
|
5355
|
+
* pairing link (`https://wallet.example`, exact match). Empty by default: a
|
|
5356
|
+
* page that frames the dApp is not trusted, and the WalletConnect modal opens
|
|
5357
|
+
* as it always did. Provide the list to pair inside a wallet that embeds dApps
|
|
5358
|
+
* in a frame.
|
|
5359
|
+
*/
|
|
5360
|
+
const HEDERA_HOST_WALLET_PARENT_ORIGINS = new InjectionToken('HEDERA_HOST_WALLET_PARENT_ORIGINS', { providedIn: 'root', factory: () => [] });
|
|
5361
|
+
/**
|
|
5362
|
+
* The page's link to a hosting Hedera wallet. Creating it posts nothing and
|
|
5363
|
+
* listens to nothing (see the file header). Null outside a browser. Override in tests, or provide null to
|
|
5364
|
+
* always use the WalletConnect modal.
|
|
5365
|
+
*/
|
|
5366
|
+
const HEDERA_HOST_WALLET_LINK = new InjectionToken('HEDERA_HOST_WALLET_LINK', {
|
|
5367
|
+
providedIn: 'root',
|
|
5368
|
+
factory: () => {
|
|
5369
|
+
if (typeof window === 'undefined' || typeof navigator === 'undefined')
|
|
5370
|
+
return null;
|
|
5371
|
+
let store = null;
|
|
5372
|
+
try {
|
|
5373
|
+
store = window.localStorage;
|
|
5374
|
+
}
|
|
5375
|
+
catch {
|
|
5376
|
+
store = null;
|
|
5377
|
+
}
|
|
5378
|
+
return new HederaHostWalletLink(window, { userAgent: navigator.userAgent, maxTouchPoints: navigator.maxTouchPoints ?? 0 }, store, undefined, inject(HEDERA_HOST_WALLET_PARENT_ORIGINS));
|
|
5379
|
+
},
|
|
5380
|
+
});
|
|
5381
|
+
|
|
5022
5382
|
/**
|
|
5023
5383
|
* HSuite Native Connect
|
|
5024
5384
|
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
@@ -5736,6 +6096,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5736
6096
|
sessionStore;
|
|
5737
6097
|
clientManager;
|
|
5738
6098
|
eventBus;
|
|
6099
|
+
beforeRequest;
|
|
5739
6100
|
/**
|
|
5740
6101
|
*
|
|
5741
6102
|
* @param config
|
|
@@ -5745,6 +6106,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5745
6106
|
this.sessionStore = config.sessionStore;
|
|
5746
6107
|
this.clientManager = config.clientManager;
|
|
5747
6108
|
this.eventBus = config.eventBus;
|
|
6109
|
+
this.beforeRequest = config.beforeRequest;
|
|
5748
6110
|
}
|
|
5749
6111
|
/**
|
|
5750
6112
|
* Sign a transaction without submitting.
|
|
@@ -5761,6 +6123,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5761
6123
|
networkId,
|
|
5762
6124
|
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
5763
6125
|
});
|
|
6126
|
+
this.announceRequest(sessionInfo);
|
|
5764
6127
|
return sessionInfo.signer.signTransaction({
|
|
5765
6128
|
client: this.clientManager.getClient(),
|
|
5766
6129
|
topic: sessionInfo.session.topic,
|
|
@@ -5784,6 +6147,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5784
6147
|
networkId,
|
|
5785
6148
|
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
5786
6149
|
});
|
|
6150
|
+
this.announceRequest(sessionInfo);
|
|
5787
6151
|
return sessionInfo.signer.submitTransaction({
|
|
5788
6152
|
client: this.clientManager.getClient(),
|
|
5789
6153
|
topic: sessionInfo.session.topic,
|
|
@@ -5807,6 +6171,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5807
6171
|
networkId,
|
|
5808
6172
|
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
5809
6173
|
});
|
|
6174
|
+
this.announceRequest(sessionInfo);
|
|
5810
6175
|
// Check if signer supports native signAndExecute
|
|
5811
6176
|
if (typeof sessionInfo.signer.signAndExecuteTransaction === 'function') {
|
|
5812
6177
|
return sessionInfo.signer.signAndExecuteTransaction({
|
|
@@ -5848,6 +6213,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5848
6213
|
networkId,
|
|
5849
6214
|
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
5850
6215
|
});
|
|
6216
|
+
this.announceRequest(sessionInfo);
|
|
5851
6217
|
return sessionInfo.signer.signMessage({
|
|
5852
6218
|
client: this.clientManager.getClient(),
|
|
5853
6219
|
topic: sessionInfo.session.topic,
|
|
@@ -5858,6 +6224,27 @@ class WalletConnectSigningOrchestrator {
|
|
|
5858
6224
|
encoding: options.encoding,
|
|
5859
6225
|
});
|
|
5860
6226
|
}
|
|
6227
|
+
/**
|
|
6228
|
+
* Tell the provider a wallet request is about to go out on this session.
|
|
6229
|
+
* @param sessionInfo - The session the request goes to
|
|
6230
|
+
* @param sessionInfo.signer
|
|
6231
|
+
* @param sessionInfo.signer.ledgerId
|
|
6232
|
+
* @param sessionInfo.session
|
|
6233
|
+
* @param sessionInfo.session.topic
|
|
6234
|
+
*/
|
|
6235
|
+
announceRequest(sessionInfo) {
|
|
6236
|
+
try {
|
|
6237
|
+
this.beforeRequest?.({
|
|
6238
|
+
ledgerId: sessionInfo.signer.ledgerId,
|
|
6239
|
+
topic: sessionInfo.session.topic,
|
|
6240
|
+
});
|
|
6241
|
+
}
|
|
6242
|
+
catch (error) {
|
|
6243
|
+
logger$8.warn('beforeRequest hook failed', {
|
|
6244
|
+
error: error instanceof Error ? error.message : String(error),
|
|
6245
|
+
});
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
5861
6248
|
/**
|
|
5862
6249
|
* Resolve the network ID to use for signing.
|
|
5863
6250
|
*
|
|
@@ -6018,6 +6405,8 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6018
6405
|
eventBus = inject(WalletEventBus);
|
|
6019
6406
|
// NgZone for ensuring change detection runs after WalletConnect events
|
|
6020
6407
|
zone = inject(NgZone);
|
|
6408
|
+
// The Hedera wallet hosting this page (its in-app browser or frame), if any
|
|
6409
|
+
hostWalletLink = inject(HEDERA_HOST_WALLET_LINK, { optional: true });
|
|
6021
6410
|
/**
|
|
6022
6411
|
*
|
|
6023
6412
|
*/
|
|
@@ -6029,6 +6418,11 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6029
6418
|
sessionStore: this.sessionStore,
|
|
6030
6419
|
clientManager: this.clientManager,
|
|
6031
6420
|
eventBus: this.eventBus,
|
|
6421
|
+
// Hedera only: have the hosting wallet bring up its approval sheet.
|
|
6422
|
+
beforeRequest: ({ ledgerId, topic }) => {
|
|
6423
|
+
if (ledgerId === 'hedera')
|
|
6424
|
+
this.hostWalletLink?.ping(topic);
|
|
6425
|
+
},
|
|
6032
6426
|
});
|
|
6033
6427
|
logger$7.info('Initializing - will attempt session restoration');
|
|
6034
6428
|
void this.restoreSession();
|
|
@@ -6263,6 +6657,16 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6263
6657
|
// Ignore cleanup errors
|
|
6264
6658
|
}
|
|
6265
6659
|
}
|
|
6660
|
+
/**
|
|
6661
|
+
* Forget everything stored per session topic. Every per-topic key is cleared
|
|
6662
|
+
* here, so a session that ends cannot leave one behind.
|
|
6663
|
+
*
|
|
6664
|
+
* @param sessionTopic - WalletConnect session topic
|
|
6665
|
+
*/
|
|
6666
|
+
forgetSessionState(sessionTopic) {
|
|
6667
|
+
this.clearUserNetworkSelection(sessionTopic);
|
|
6668
|
+
this.hostWalletLink?.forget(sessionTopic);
|
|
6669
|
+
}
|
|
6266
6670
|
/**
|
|
6267
6671
|
* Connect to a wallet via WalletConnect QR code.
|
|
6268
6672
|
*
|
|
@@ -6321,12 +6725,29 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6321
6725
|
});
|
|
6322
6726
|
// Connect and show QR code
|
|
6323
6727
|
const { uri, approval } = await this.clientManager.connect(optionalNamespaces, sessionProperties);
|
|
6728
|
+
// approval() makes a NEW promise per call and drops the previous one's
|
|
6729
|
+
// resolver: call it exactly once and share the promise.
|
|
6730
|
+
const approved = approval();
|
|
6731
|
+
// Awaited below; this only keeps an early rejection from going unhandled.
|
|
6732
|
+
approved.catch(() => undefined);
|
|
6733
|
+
// Inside a Hedera wallet's own browser or frame, hand the pairing link to
|
|
6734
|
+
// that wallet: the modal's deep link cannot open the app the page runs in.
|
|
6735
|
+
// The modal still opens if the wallet has not approved in time.
|
|
6736
|
+
let hostWallet = null;
|
|
6324
6737
|
if (uri) {
|
|
6325
|
-
|
|
6738
|
+
const openModal = () => modal.openModal({ uri });
|
|
6739
|
+
if (wcConfig.ledgerId === 'hedera' && this.hostWalletLink) {
|
|
6740
|
+
hostWallet = await this.hostWalletLink
|
|
6741
|
+
.handOff({ uri, openModal, settled: approved })
|
|
6742
|
+
.catch(() => null);
|
|
6743
|
+
}
|
|
6744
|
+
if (!hostWallet) {
|
|
6745
|
+
await openModal();
|
|
6746
|
+
}
|
|
6326
6747
|
}
|
|
6327
6748
|
// Wait for wallet approval
|
|
6328
|
-
logger$7.info('Waiting for wallet approval...');
|
|
6329
|
-
const session = await
|
|
6749
|
+
logger$7.info('Waiting for wallet approval...', { viaHostWallet: !!hostWallet });
|
|
6750
|
+
const session = await approved;
|
|
6330
6751
|
this.clientManager.closeModal();
|
|
6331
6752
|
logger$7.info('[WC:DAPP:APPROVED] Session approved by wallet', {
|
|
6332
6753
|
topic: session.topic.substring(0, 16) + '...',
|
|
@@ -6405,6 +6826,11 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6405
6826
|
});
|
|
6406
6827
|
// Persist user's network selection for session restoration after page reload
|
|
6407
6828
|
this.storeUserNetworkSelection(session.topic, wcConfig.networkId);
|
|
6829
|
+
// Approved through the hosting wallet: its approval sheet is pinged before
|
|
6830
|
+
// each request on this session.
|
|
6831
|
+
if (hostWallet) {
|
|
6832
|
+
this.hostWalletLink?.markPaired(session.topic, hostWallet);
|
|
6833
|
+
}
|
|
6408
6834
|
// Verify session exists in WC SDK after storing
|
|
6409
6835
|
const sdkSession = this.clientManager.getSession(session.topic);
|
|
6410
6836
|
logger$7.info('[WC:DAPP:STORED] Session stored locally', {
|
|
@@ -6461,8 +6887,8 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6461
6887
|
removeSessionByTopic(topic) {
|
|
6462
6888
|
// Find and remove the session using session store
|
|
6463
6889
|
const removed = this.sessionStore.removeSessionByTopic(topic);
|
|
6464
|
-
// Clean up stored
|
|
6465
|
-
this.
|
|
6890
|
+
// Clean up what was stored for this session
|
|
6891
|
+
this.forgetSessionState(topic);
|
|
6466
6892
|
// Update aggregated accounts
|
|
6467
6893
|
this.sessionStore.updateAggregatedAccounts();
|
|
6468
6894
|
// Update status
|
|
@@ -6540,8 +6966,8 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6540
6966
|
error: e instanceof Error ? e.message : String(e),
|
|
6541
6967
|
});
|
|
6542
6968
|
}
|
|
6543
|
-
// Clean up stored
|
|
6544
|
-
this.
|
|
6969
|
+
// Clean up what was stored for this session
|
|
6970
|
+
this.forgetSessionState(sessionData.session.topic);
|
|
6545
6971
|
this.sessionStore.deleteSession(sessionKey);
|
|
6546
6972
|
this.sessionStore.updateAggregatedAccounts();
|
|
6547
6973
|
if (this.sessionStore.size === 0) {
|
|
@@ -6553,8 +6979,8 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
6553
6979
|
// Disconnect all sessions
|
|
6554
6980
|
const disconnectPromises = [];
|
|
6555
6981
|
for (const [_key, sessionData] of this.sessionStore.entries()) {
|
|
6556
|
-
// Clean up
|
|
6557
|
-
this.
|
|
6982
|
+
// Clean up what was stored for each session
|
|
6983
|
+
this.forgetSessionState(sessionData.session.topic);
|
|
6558
6984
|
disconnectPromises.push(this.clientManager
|
|
6559
6985
|
.disconnect(sessionData.session.topic, {
|
|
6560
6986
|
code: 6000,
|
|
@@ -7700,28 +8126,24 @@ function networkName(networkId) {
|
|
|
7700
8126
|
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
7701
8127
|
* visit https://hsuite.finance/licensing
|
|
7702
8128
|
*/
|
|
7703
|
-
/** `shard.realm.num` — short enough to show whole
|
|
8129
|
+
/** `shard.realm.num` — short enough to show whole, in a phone header too. */
|
|
7704
8130
|
const HEDERA_ID = /^\d+\.\d+\.\d+$/;
|
|
7705
8131
|
/**
|
|
7706
8132
|
* Display form of an account address for the account UI (canvas page "Conta").
|
|
7707
|
-
* Hedera ids are shown whole (`0.0.4821937`)
|
|
7708
|
-
*
|
|
8133
|
+
* Hedera ids are shown whole (`0.0.4821937`) at every width: shortening one
|
|
8134
|
+
* saves a character or two and hides the digits the user reads to tell their
|
|
8135
|
+
* accounts apart. Longer addresses (XRPL, EVM) become `rN7f…k2Qp`. Screens that
|
|
7709
8136
|
* shorten an address also expose the full one (accessible name / title).
|
|
7710
8137
|
*
|
|
7711
8138
|
* `AccountFormattingService.truncateAddress` is not used: it keeps a 11-char
|
|
7712
8139
|
* id whole at any length and joins with three dots.
|
|
7713
8140
|
* @param address
|
|
7714
|
-
* @param opts
|
|
7715
|
-
* @param opts.compact - phone header chip (A07)
|
|
7716
8141
|
*/
|
|
7717
|
-
function shortAddress$1(address
|
|
8142
|
+
function shortAddress$1(address) {
|
|
7718
8143
|
if (!address)
|
|
7719
8144
|
return '';
|
|
7720
|
-
if (HEDERA_ID.test(address))
|
|
7721
|
-
return
|
|
7722
|
-
? `${address.slice(0, 6)}…${address.slice(-3)}`
|
|
7723
|
-
: address;
|
|
7724
|
-
}
|
|
8145
|
+
if (HEDERA_ID.test(address))
|
|
8146
|
+
return address;
|
|
7725
8147
|
return address.length > 12 ? `${address.slice(0, 4)}…${address.slice(-4)}` : address;
|
|
7726
8148
|
}
|
|
7727
8149
|
|
|
@@ -7850,7 +8272,7 @@ class AccountSelectorService {
|
|
|
7850
8272
|
for (const s of sessions)
|
|
7851
8273
|
counts.set(s.name, (counts.get(s.name) ?? 0) + 1);
|
|
7852
8274
|
return sessions.map((s) => (counts.get(s.name) ?? 0) > 1 && s.accounts[0]
|
|
7853
|
-
? { ...s, name: `${s.name} · ${shortAddress$1(s.accounts[0].address
|
|
8275
|
+
? { ...s, name: `${s.name} · ${shortAddress$1(s.accounts[0].address)}` }
|
|
7854
8276
|
: s);
|
|
7855
8277
|
}, ...(ngDevMode ? [{ debugName: "sessionsVm" }] : []));
|
|
7856
8278
|
/**
|
|
@@ -18718,7 +19140,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.26", ngImpo
|
|
|
18718
19140
|
class AccountChipComponent {
|
|
18719
19141
|
// Decorator inputs (not signal inputs): this package's Vitest setup has no
|
|
18720
19142
|
// Angular compiler plugin, and JIT cannot see `input()` initializers.
|
|
18721
|
-
/** Phone header (A07):
|
|
19143
|
+
/** Phone header (A07): tighter chip, no caret. */
|
|
18722
19144
|
compact = false;
|
|
18723
19145
|
/** Whether the account menu this chip opens is showing (`aria-expanded`). */
|
|
18724
19146
|
expanded = false;
|
|
@@ -18729,9 +19151,9 @@ class AccountChipComponent {
|
|
|
18729
19151
|
wallet = inject(UnifiedWalletService);
|
|
18730
19152
|
account = computed(() => this.wallet.activeAccount(), ...(ngDevMode ? [{ debugName: "account" }] : []));
|
|
18731
19153
|
avatar = computed(() => avatarColor(this.account()?.address ?? ''), ...(ngDevMode ? [{ debugName: "avatar" }] : []));
|
|
18732
|
-
/** Address as shown
|
|
19154
|
+
/** Address as shown: a Hedera id whole, in the compact chip too. */
|
|
18733
19155
|
displayAddress() {
|
|
18734
|
-
return shortAddress$1(this.account()?.address ?? ''
|
|
19156
|
+
return shortAddress$1(this.account()?.address ?? '');
|
|
18735
19157
|
}
|
|
18736
19158
|
/** Full address (the visible one may be shortened) and the account count. */
|
|
18737
19159
|
accessibleName() {
|
|
@@ -19367,5 +19789,5 @@ function provideWalletErrorHandler(config) {
|
|
|
19367
19789
|
* Generated bundle index. Do not edit.
|
|
19368
19790
|
*/
|
|
19369
19791
|
|
|
19370
|
-
export { ACTIVE_ACCOUNT_SOURCE, AccountActionsComponent, AccountChipComponent, AccountFilterComponent, AccountFormattingService, AccountGroupingService, AccountListComponent, AccountMenuComponent, AccountSelectorComponent, AccountSelectorService, BaseWalletProvider, ChannelClientService, ChromeExtensionTransport, ConnectionInProgressError, DEFAULT_LEDGER_ICONS, DEFAULT_WALLET_URL, HSUITE_AUTH_HEADER, HSUITE_LEDGER_HEADER, HederaSigner, HederaTransactionBuilderService, HsuiteAuthInterceptor, HsuiteNativeProvider, HsuiteWalletModule, LEDGER_COLORS, LEDGER_ICON_NAMES, LEDGER_NAMES$1 as LEDGER_NAMES, LedgerUIRegistry, LoggerService, MAX_NATIVE_SESSIONS, NATIVE_SESSION_KEY_PREFIX, NativeSessionLimitError, NoAccountsForNetworkError, SMART_SESSION_CONFIG, SessionNoticeService, SignerFactory, SmartSessionService, TransactionService, UnifiedWalletService, WALLET_UI_CONFIG, WalletAccountDisplayComponent, WalletButtonComponent, WalletConnectButtonComponent, WalletConnectClientManager, WalletConnectPromptComponent, WalletConnectSessionStore, WalletConnectSigningOrchestrator, WalletConnectV2Provider, WalletConnectedDirective, WalletConnectedGuardComponent, WalletConnectionModalComponent, WalletContextDirective, WalletContextService, WalletErrorHandler, WalletEventBus, WalletEventsDirective, WalletSessionDisplayComponent, WalletTransactionStatusComponent, WalletUiService, XrplSigner, XrplTransactionBuilderService, channelIdFromSessionKey, getExtensionVersion, getLedgerColor, getLedgerIcon, getLedgerName, getTokenIcon, hsuiteAuthInterceptor, isExtensionInstalled, isHsuiteNativeConfig, isWalletConnectV2Config, nativeSessionKeyFor, parseNativeSessionKey, provideWalletErrorHandler, provideWalletUi, registerLedgerIcons, scaleHederaAmountToBaseUnits, supportsSessionManagement };
|
|
19792
|
+
export { ACTIVE_ACCOUNT_SOURCE, AccountActionsComponent, AccountChipComponent, AccountFilterComponent, AccountFormattingService, AccountGroupingService, AccountListComponent, AccountMenuComponent, AccountSelectorComponent, AccountSelectorService, BaseWalletProvider, ChannelClientService, ChromeExtensionTransport, ConnectionInProgressError, DEFAULT_LEDGER_ICONS, DEFAULT_WALLET_URL, HEDERA_HOST_WALLET_LINK, HEDERA_HOST_WALLET_PARENT_ORIGINS, HOST_WALLET_EVENTS, HOST_WALLET_HANDOFF_TIMEOUT_MS, HOST_WALLET_PAIRED_KEY_PREFIX, HOST_WALLET_REQUERY_WAIT_MS, HSUITE_AUTH_HEADER, HSUITE_LEDGER_HEADER, HederaHostWalletLink, HederaSigner, HederaTransactionBuilderService, HsuiteAuthInterceptor, HsuiteNativeProvider, HsuiteWalletModule, LEDGER_COLORS, LEDGER_ICON_NAMES, LEDGER_NAMES$1 as LEDGER_NAMES, LedgerUIRegistry, LoggerService, MAX_NATIVE_SESSIONS, NATIVE_SESSION_KEY_PREFIX, NativeSessionLimitError, NoAccountsForNetworkError, SMART_SESSION_CONFIG, SessionNoticeService, SignerFactory, SmartSessionService, TransactionService, UnifiedWalletService, WALLET_UI_CONFIG, WalletAccountDisplayComponent, WalletButtonComponent, WalletConnectButtonComponent, WalletConnectClientManager, WalletConnectPromptComponent, WalletConnectSessionStore, WalletConnectSigningOrchestrator, WalletConnectV2Provider, WalletConnectedDirective, WalletConnectedGuardComponent, WalletConnectionModalComponent, WalletContextDirective, WalletContextService, WalletErrorHandler, WalletEventBus, WalletEventsDirective, WalletSessionDisplayComponent, WalletTransactionStatusComponent, WalletUiService, XrplSigner, XrplTransactionBuilderService, channelIdFromSessionKey, getExtensionVersion, getLedgerColor, getLedgerIcon, getLedgerName, getTokenIcon, hsuiteAuthInterceptor, isExtensionInstalled, isHsuiteNativeConfig, isTouchDevice, isWalletConnectV2Config, nativeSessionKeyFor, parseHostWalletMessage, parseNativeSessionKey, provideWalletErrorHandler, provideWalletUi, registerLedgerIcons, scaleHederaAmountToBaseUnits, shouldUseHostWallet, supportsSessionManagement };
|
|
19371
19793
|
//# sourceMappingURL=hsuite-native-connect-angular.mjs.map
|