@hsuite/native-connect-angular 2.1.3 → 2.1.4
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.
|
@@ -13,7 +13,8 @@ import { WalletConnectModal } from '@walletconnect/modal';
|
|
|
13
13
|
import SignClient from '@walletconnect/sign-client';
|
|
14
14
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
15
15
|
import * as QRCode from 'qrcode';
|
|
16
|
-
import { Subscription } from 'rxjs';
|
|
16
|
+
import { Subscription, firstValueFrom, catchError, from, switchMap, throwError } from 'rxjs';
|
|
17
|
+
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
|
17
18
|
import { PublicKey, KeyList, TransferTransaction, AccountId, Hbar, TokenId, NftId, TokenAssociateTransaction, TokenDissociateTransaction, ScheduleCreateTransaction, TokenCreateTransaction, TokenType, TokenSupplyType, TokenMintTransaction, TokenBurnTransaction, TopicCreateTransaction, TopicMessageSubmitTransaction, AccountCreateTransaction, PrivateKey, AccountUpdateTransaction, TransactionId, BatchTransaction, Client } from '@hashgraph/sdk';
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -1427,7 +1428,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
1427
1428
|
* Each event is available as both an Angular EventEmitter (for template bindings)
|
|
1428
1429
|
* and an RxJS Observable (for advanced composition with operators).
|
|
1429
1430
|
*/
|
|
1430
|
-
const logger$
|
|
1431
|
+
const logger$k = getLogger().scoped?.('WalletEventBus') ?? getLogger();
|
|
1431
1432
|
/**
|
|
1432
1433
|
* Centralized event bus for wallet events.
|
|
1433
1434
|
*
|
|
@@ -1539,7 +1540,7 @@ class WalletEventBus {
|
|
|
1539
1540
|
*
|
|
1540
1541
|
*/
|
|
1541
1542
|
constructor() {
|
|
1542
|
-
logger$
|
|
1543
|
+
logger$k.debug('Event bus initialized');
|
|
1543
1544
|
}
|
|
1544
1545
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: WalletEventBus, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1545
1546
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: WalletEventBus, providedIn: 'root' });
|
|
@@ -1726,7 +1727,7 @@ class BaseWalletProvider {
|
|
|
1726
1727
|
* }
|
|
1727
1728
|
* ```
|
|
1728
1729
|
*/
|
|
1729
|
-
const logger$
|
|
1730
|
+
const logger$j = getLogger().scoped?.('ChannelClientService') ?? getLogger();
|
|
1730
1731
|
/**
|
|
1731
1732
|
* ChannelClientService
|
|
1732
1733
|
*
|
|
@@ -1776,6 +1777,7 @@ class ChannelClientService {
|
|
|
1776
1777
|
return {
|
|
1777
1778
|
id: `channel-${account.address}`,
|
|
1778
1779
|
address: account.address,
|
|
1780
|
+
publicKey: account.publicKey,
|
|
1779
1781
|
label: account.alias ?? `Account ${index + 1}`,
|
|
1780
1782
|
ledgerId: account.ledgerId,
|
|
1781
1783
|
networkId: account.networkId,
|
|
@@ -1814,7 +1816,7 @@ class ChannelClientService {
|
|
|
1814
1816
|
*/
|
|
1815
1817
|
async connect(config) {
|
|
1816
1818
|
if (this._state() === 'connecting' || this._state() === 'pending') {
|
|
1817
|
-
logger$
|
|
1819
|
+
logger$j.warn('Connection already in progress');
|
|
1818
1820
|
const existing = this._currentInvite();
|
|
1819
1821
|
if (existing)
|
|
1820
1822
|
return existing;
|
|
@@ -1856,7 +1858,7 @@ class ChannelClientService {
|
|
|
1856
1858
|
this.runInZone(() => {
|
|
1857
1859
|
const previousState = this._state();
|
|
1858
1860
|
if (state !== previousState) {
|
|
1859
|
-
logger$
|
|
1861
|
+
logger$j.debug('State change via callback', { from: previousState, to: state });
|
|
1860
1862
|
this._state.set(state);
|
|
1861
1863
|
// Handle error state - this is triggered on rejection
|
|
1862
1864
|
if (state === 'error') {
|
|
@@ -1881,7 +1883,7 @@ class ChannelClientService {
|
|
|
1881
1883
|
},
|
|
1882
1884
|
onAccountsChange: (accounts) => {
|
|
1883
1885
|
this.runInZone(() => {
|
|
1884
|
-
logger$
|
|
1886
|
+
logger$j.debug('Accounts change via callback', { count: accounts.length });
|
|
1885
1887
|
this._accounts.set(accounts);
|
|
1886
1888
|
// Re-persist when accounts change
|
|
1887
1889
|
if (this._state() === 'active') {
|
|
@@ -1892,7 +1894,7 @@ class ChannelClientService {
|
|
|
1892
1894
|
onTransportChange: (transport) => {
|
|
1893
1895
|
this.runInZone(() => {
|
|
1894
1896
|
if (transport !== this._transportState()) {
|
|
1895
|
-
logger$
|
|
1897
|
+
logger$j.debug('Transport change via callback', { state: transport });
|
|
1896
1898
|
this._transportState.set(transport);
|
|
1897
1899
|
}
|
|
1898
1900
|
});
|
|
@@ -1927,7 +1929,7 @@ class ChannelClientService {
|
|
|
1927
1929
|
});
|
|
1928
1930
|
// Store invite for reconnection
|
|
1929
1931
|
this.storeInvite(invite);
|
|
1930
|
-
logger$
|
|
1932
|
+
logger$j.info('Channel connection initiated', {
|
|
1931
1933
|
channelId: invite.id.slice(0, 8),
|
|
1932
1934
|
type: invite.type,
|
|
1933
1935
|
});
|
|
@@ -1935,7 +1937,7 @@ class ChannelClientService {
|
|
|
1935
1937
|
}
|
|
1936
1938
|
catch (error) {
|
|
1937
1939
|
const message = error instanceof Error ? error.message : String(error);
|
|
1938
|
-
logger$
|
|
1940
|
+
logger$j.error('Connection failed', { error: message });
|
|
1939
1941
|
// Reset connecting flag on error
|
|
1940
1942
|
this.connectingNewSession = false;
|
|
1941
1943
|
this.runInZone(() => {
|
|
@@ -1976,7 +1978,7 @@ class ChannelClientService {
|
|
|
1976
1978
|
if (state !== 'active' && state !== 'approved') {
|
|
1977
1979
|
throw new Error(`Not connected - channel state is '${state}'. Please reconnect to the wallet.`);
|
|
1978
1980
|
}
|
|
1979
|
-
logger$
|
|
1981
|
+
logger$j.debug('Sending RPC request', { method, state });
|
|
1980
1982
|
return this.client.request(method, params, timeoutMs);
|
|
1981
1983
|
}
|
|
1982
1984
|
/**
|
|
@@ -2053,7 +2055,7 @@ class ChannelClientService {
|
|
|
2053
2055
|
await this.client.disconnect();
|
|
2054
2056
|
}
|
|
2055
2057
|
catch (error) {
|
|
2056
|
-
logger$
|
|
2058
|
+
logger$j.warn('Disconnect error', { error });
|
|
2057
2059
|
}
|
|
2058
2060
|
this.client = null;
|
|
2059
2061
|
}
|
|
@@ -2065,7 +2067,7 @@ class ChannelClientService {
|
|
|
2065
2067
|
this._currentInvite.set(null);
|
|
2066
2068
|
this._error.set(null);
|
|
2067
2069
|
});
|
|
2068
|
-
logger$
|
|
2070
|
+
logger$j.info('Disconnected from channel');
|
|
2069
2071
|
}
|
|
2070
2072
|
/**
|
|
2071
2073
|
* Attempt to restore a previous session.
|
|
@@ -2078,7 +2080,7 @@ class ChannelClientService {
|
|
|
2078
2080
|
async attemptRestore() {
|
|
2079
2081
|
// Skip restore if a new connection is being initiated
|
|
2080
2082
|
if (this.connectingNewSession) {
|
|
2081
|
-
logger$
|
|
2083
|
+
logger$j.debug('Skipping restore - new connection in progress');
|
|
2082
2084
|
return false;
|
|
2083
2085
|
}
|
|
2084
2086
|
const stored = this.getStoredChannel();
|
|
@@ -2094,11 +2096,11 @@ class ChannelClientService {
|
|
|
2094
2096
|
// Safe to do unconditionally at this point in the project's lifecycle:
|
|
2095
2097
|
// no dApp sessions are live in production yet.
|
|
2096
2098
|
if (stored.localContext === undefined) {
|
|
2097
|
-
logger$
|
|
2099
|
+
logger$j.warn('Clearing legacy persisted channel without localContext — user must re-approve the dApp connection (§21.1)', { channelId: stored.id.slice(0, 8) });
|
|
2098
2100
|
this.clearStoredChannel();
|
|
2099
2101
|
return false;
|
|
2100
2102
|
}
|
|
2101
|
-
logger$
|
|
2103
|
+
logger$j.info('Attempting session restore', {
|
|
2102
2104
|
channelId: stored.id.slice(0, 8),
|
|
2103
2105
|
});
|
|
2104
2106
|
this.runInZone(() => {
|
|
@@ -2111,7 +2113,7 @@ class ChannelClientService {
|
|
|
2111
2113
|
this.runInZone(() => {
|
|
2112
2114
|
const previousState = this._state();
|
|
2113
2115
|
if (state !== previousState) {
|
|
2114
|
-
logger$
|
|
2116
|
+
logger$j.debug('State change via callback (reconnect)', {
|
|
2115
2117
|
from: previousState,
|
|
2116
2118
|
to: state,
|
|
2117
2119
|
});
|
|
@@ -2131,7 +2133,7 @@ class ChannelClientService {
|
|
|
2131
2133
|
},
|
|
2132
2134
|
onAccountsChange: (accounts) => {
|
|
2133
2135
|
this.runInZone(() => {
|
|
2134
|
-
logger$
|
|
2136
|
+
logger$j.debug('Accounts change via callback (reconnect)', { count: accounts.length });
|
|
2135
2137
|
this._accounts.set(accounts);
|
|
2136
2138
|
if (this._state() === 'active') {
|
|
2137
2139
|
this.persistCurrentState();
|
|
@@ -2141,7 +2143,7 @@ class ChannelClientService {
|
|
|
2141
2143
|
onTransportChange: (transport) => {
|
|
2142
2144
|
this.runInZone(() => {
|
|
2143
2145
|
if (transport !== this._transportState()) {
|
|
2144
|
-
logger$
|
|
2146
|
+
logger$j.debug('Transport change via callback (reconnect)', { state: transport });
|
|
2145
2147
|
this._transportState.set(transport);
|
|
2146
2148
|
}
|
|
2147
2149
|
});
|
|
@@ -2164,14 +2166,14 @@ class ChannelClientService {
|
|
|
2164
2166
|
}
|
|
2165
2167
|
this._state.set('active');
|
|
2166
2168
|
});
|
|
2167
|
-
logger$
|
|
2169
|
+
logger$j.info('Session restored successfully', {
|
|
2168
2170
|
channelId: stored.id.slice(0, 8),
|
|
2169
2171
|
accounts: restoredAccounts.length,
|
|
2170
2172
|
});
|
|
2171
2173
|
return true;
|
|
2172
2174
|
}
|
|
2173
2175
|
catch (error) {
|
|
2174
|
-
logger$
|
|
2176
|
+
logger$j.warn('Session restore failed', {
|
|
2175
2177
|
error: error instanceof Error ? error.message : String(error),
|
|
2176
2178
|
});
|
|
2177
2179
|
// Clean up the partially initialized client
|
|
@@ -2247,7 +2249,7 @@ class ChannelClientService {
|
|
|
2247
2249
|
}
|
|
2248
2250
|
if (clientTransport !== this._transportState()) {
|
|
2249
2251
|
this._transportState.set(clientTransport);
|
|
2250
|
-
logger$
|
|
2252
|
+
logger$j.debug('Transport state updated', { state: clientTransport });
|
|
2251
2253
|
}
|
|
2252
2254
|
});
|
|
2253
2255
|
// Continue polling as long as client exists
|
|
@@ -2290,14 +2292,14 @@ class ChannelClientService {
|
|
|
2290
2292
|
const persisted = this.client.exportState();
|
|
2291
2293
|
if (persisted) {
|
|
2292
2294
|
localStorage.setItem(ChannelClientService.STORAGE_KEY, JSON.stringify(persisted));
|
|
2293
|
-
logger$
|
|
2295
|
+
logger$j.debug('Channel state persisted', {
|
|
2294
2296
|
channelId: persisted.id.slice(0, 8),
|
|
2295
2297
|
accounts: persisted.accounts?.length ?? 0,
|
|
2296
2298
|
});
|
|
2297
2299
|
}
|
|
2298
2300
|
}
|
|
2299
2301
|
catch (error) {
|
|
2300
|
-
logger$
|
|
2302
|
+
logger$j.warn('Failed to persist channel state', { error });
|
|
2301
2303
|
}
|
|
2302
2304
|
}
|
|
2303
2305
|
/**
|
|
@@ -2338,7 +2340,7 @@ class ChannelClientService {
|
|
|
2338
2340
|
}
|
|
2339
2341
|
}
|
|
2340
2342
|
catch {
|
|
2341
|
-
logger$
|
|
2343
|
+
logger$j.warn('Failed to store channel');
|
|
2342
2344
|
}
|
|
2343
2345
|
}
|
|
2344
2346
|
/**
|
|
@@ -2352,7 +2354,7 @@ class ChannelClientService {
|
|
|
2352
2354
|
}
|
|
2353
2355
|
}
|
|
2354
2356
|
catch {
|
|
2355
|
-
logger$
|
|
2357
|
+
logger$j.warn('Failed to retrieve stored channel');
|
|
2356
2358
|
}
|
|
2357
2359
|
return null;
|
|
2358
2360
|
}
|
|
@@ -2404,7 +2406,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
2404
2406
|
* 8. P2P upgrade happens automatically in background
|
|
2405
2407
|
* ```
|
|
2406
2408
|
*/
|
|
2407
|
-
const logger$
|
|
2409
|
+
const logger$i = getLogger().scoped?.('HsuiteNativeProvider') ?? getLogger();
|
|
2408
2410
|
/**
|
|
2409
2411
|
* HSuite Native Connect Provider.
|
|
2410
2412
|
*
|
|
@@ -2490,7 +2492,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2490
2492
|
const isConnected = this.channelService.isConnected();
|
|
2491
2493
|
// If we were connected but now disconnected, emit disconnect event
|
|
2492
2494
|
if (this.previouslyConnected && !isConnected && status === 'disconnected') {
|
|
2493
|
-
logger$
|
|
2495
|
+
logger$i.info('[HsuiteNativeProvider] Channel terminated');
|
|
2494
2496
|
this.eventBus.disconnected.emit({
|
|
2495
2497
|
providerId: this.id,
|
|
2496
2498
|
providerType: 'hsuite-native',
|
|
@@ -2503,7 +2505,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2503
2505
|
});
|
|
2504
2506
|
// Attempt automatic reconnect when session exists after reload
|
|
2505
2507
|
void this.attemptReconnect().catch((error) => {
|
|
2506
|
-
logger$
|
|
2508
|
+
logger$i.debug('[HsuiteNativeProvider] Auto-reconnect skipped', { error });
|
|
2507
2509
|
});
|
|
2508
2510
|
}
|
|
2509
2511
|
/**
|
|
@@ -2597,10 +2599,10 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2597
2599
|
// Guard: Don't start a new connection if already connecting
|
|
2598
2600
|
const currentStatus = this.status();
|
|
2599
2601
|
if (currentStatus === 'connecting') {
|
|
2600
|
-
logger$
|
|
2602
|
+
logger$i.warn('Connection already in progress, ignoring duplicate request');
|
|
2601
2603
|
return;
|
|
2602
2604
|
}
|
|
2603
|
-
logger$
|
|
2605
|
+
logger$i.info('Connecting to HSuite Wallet via unified channel protocol', { config });
|
|
2604
2606
|
try {
|
|
2605
2607
|
const invite = await this.channelService.connect({
|
|
2606
2608
|
type: 'session',
|
|
@@ -2626,14 +2628,14 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2626
2628
|
accounts,
|
|
2627
2629
|
timestamp: Date.now(),
|
|
2628
2630
|
});
|
|
2629
|
-
logger$
|
|
2631
|
+
logger$i.info('Connected successfully via unified channel', {
|
|
2630
2632
|
channelId: invite.id.slice(0, 8),
|
|
2631
2633
|
accountCount: accounts.length,
|
|
2632
2634
|
});
|
|
2633
2635
|
});
|
|
2634
2636
|
}
|
|
2635
2637
|
catch (error) {
|
|
2636
|
-
logger$
|
|
2638
|
+
logger$i.error('Connection failed', { error });
|
|
2637
2639
|
throw error;
|
|
2638
2640
|
}
|
|
2639
2641
|
}
|
|
@@ -2666,7 +2668,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2666
2668
|
if (wallet) {
|
|
2667
2669
|
// Send invite directly via BroadcastChannel - instant, no network!
|
|
2668
2670
|
this.localDiscoveryService.sendInvite(wallet.fingerprint, inviteUrl, config?.appId, config?.appName);
|
|
2669
|
-
logger$
|
|
2671
|
+
logger$i.info('[HsuiteNativeProvider] Sent invite via local discovery', {
|
|
2670
2672
|
wallet: wallet.fingerprint.slice(0, 8),
|
|
2671
2673
|
});
|
|
2672
2674
|
return;
|
|
@@ -2758,7 +2760,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2758
2760
|
* @throws {Error} If disconnection fails (event still emitted)
|
|
2759
2761
|
*/
|
|
2760
2762
|
async disconnect() {
|
|
2761
|
-
logger$
|
|
2763
|
+
logger$i.info('Disconnecting from HSuite Wallet');
|
|
2762
2764
|
try {
|
|
2763
2765
|
await this.channelService.disconnect();
|
|
2764
2766
|
// Emit disconnection event
|
|
@@ -2768,10 +2770,10 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2768
2770
|
reason: 'user_initiated',
|
|
2769
2771
|
timestamp: Date.now(),
|
|
2770
2772
|
});
|
|
2771
|
-
logger$
|
|
2773
|
+
logger$i.info('Disconnected successfully');
|
|
2772
2774
|
}
|
|
2773
2775
|
catch (error) {
|
|
2774
|
-
logger$
|
|
2776
|
+
logger$i.error('Disconnection failed', { error });
|
|
2775
2777
|
// Still emit event even if disconnect fails
|
|
2776
2778
|
this.eventBus.disconnected.emit({
|
|
2777
2779
|
providerId: this.id,
|
|
@@ -2799,7 +2801,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2799
2801
|
* @throws {Error} If channel communication fails
|
|
2800
2802
|
*/
|
|
2801
2803
|
async signTransaction(options) {
|
|
2802
|
-
logger$
|
|
2804
|
+
logger$i.info('Signing transaction', { options });
|
|
2803
2805
|
try {
|
|
2804
2806
|
const response = await this.channelService.signTransaction({
|
|
2805
2807
|
accountAddress: options.accountAddress,
|
|
@@ -2807,7 +2809,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2807
2809
|
ledgerId: options.ledgerId,
|
|
2808
2810
|
networkId: options.networkId,
|
|
2809
2811
|
});
|
|
2810
|
-
logger$
|
|
2812
|
+
logger$i.info('Transaction signed');
|
|
2811
2813
|
return {
|
|
2812
2814
|
signedPayload: response.signedPayload || '',
|
|
2813
2815
|
signature: response.signature,
|
|
@@ -2815,7 +2817,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2815
2817
|
};
|
|
2816
2818
|
}
|
|
2817
2819
|
catch (error) {
|
|
2818
|
-
logger$
|
|
2820
|
+
logger$i.error('Transaction signing failed', { error });
|
|
2819
2821
|
throw error;
|
|
2820
2822
|
}
|
|
2821
2823
|
}
|
|
@@ -2839,7 +2841,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2839
2841
|
* @throws {Error} If transaction submission fails
|
|
2840
2842
|
*/
|
|
2841
2843
|
async signAndExecuteTransaction(options) {
|
|
2842
|
-
logger$
|
|
2844
|
+
logger$i.info('signAndExecuteTransaction called (single prompt)', {
|
|
2843
2845
|
accountAddress: options.accountAddress,
|
|
2844
2846
|
ledgerId: options.ledgerId,
|
|
2845
2847
|
networkId: options.networkId,
|
|
@@ -2876,7 +2878,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2876
2878
|
* @param options
|
|
2877
2879
|
*/
|
|
2878
2880
|
async submitTransactionInternal(options) {
|
|
2879
|
-
logger$
|
|
2881
|
+
logger$i.info('Signing and submitting transaction (single prompt)', {
|
|
2880
2882
|
accountAddress: options.accountAddress,
|
|
2881
2883
|
ledgerId: options.ledgerId,
|
|
2882
2884
|
networkId: options.networkId,
|
|
@@ -2894,7 +2896,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2894
2896
|
innerTransactions: options.innerTransactions,
|
|
2895
2897
|
}),
|
|
2896
2898
|
});
|
|
2897
|
-
logger$
|
|
2899
|
+
logger$i.info('Transaction signed and submitted successfully', {
|
|
2898
2900
|
transactionId: response.transactionId,
|
|
2899
2901
|
transactionHash: response.transactionHash?.substring(0, 16),
|
|
2900
2902
|
});
|
|
@@ -2905,7 +2907,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2905
2907
|
};
|
|
2906
2908
|
}
|
|
2907
2909
|
catch (error) {
|
|
2908
|
-
logger$
|
|
2910
|
+
logger$i.error('Transaction sign+submit failed', { error });
|
|
2909
2911
|
throw error;
|
|
2910
2912
|
}
|
|
2911
2913
|
}
|
|
@@ -2927,7 +2929,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2927
2929
|
* @throws {Error} If wallet is not connected
|
|
2928
2930
|
*/
|
|
2929
2931
|
async signMessage(options) {
|
|
2930
|
-
logger$
|
|
2932
|
+
logger$i.info('Signing message', {
|
|
2931
2933
|
accountAddress: options.accountAddress,
|
|
2932
2934
|
encoding: options.encoding,
|
|
2933
2935
|
messageLength: options.message?.length,
|
|
@@ -2940,7 +2942,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2940
2942
|
ledgerId: options.ledgerId,
|
|
2941
2943
|
networkId: options.networkId,
|
|
2942
2944
|
});
|
|
2943
|
-
logger$
|
|
2945
|
+
logger$i.info('Message signed successfully', {
|
|
2944
2946
|
algorithm: response.algorithm,
|
|
2945
2947
|
caipChainId: response.caipChainId,
|
|
2946
2948
|
});
|
|
@@ -2957,7 +2959,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2957
2959
|
};
|
|
2958
2960
|
}
|
|
2959
2961
|
catch (error) {
|
|
2960
|
-
logger$
|
|
2962
|
+
logger$i.error('Message signing failed', { error });
|
|
2961
2963
|
throw error;
|
|
2962
2964
|
}
|
|
2963
2965
|
}
|
|
@@ -2989,7 +2991,7 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
2989
2991
|
* @returns Promise resolving to true if reconnection succeeded, false otherwise
|
|
2990
2992
|
*/
|
|
2991
2993
|
async attemptReconnect() {
|
|
2992
|
-
logger$
|
|
2994
|
+
logger$i.info('Attempting reconnect via unified channel');
|
|
2993
2995
|
try {
|
|
2994
2996
|
const success = await this.channelService.attemptRestore();
|
|
2995
2997
|
if (success) {
|
|
@@ -3002,15 +3004,15 @@ class HsuiteNativeProvider extends BaseWalletProvider {
|
|
|
3002
3004
|
metadata: { autoReconnected: true },
|
|
3003
3005
|
timestamp: Date.now(),
|
|
3004
3006
|
});
|
|
3005
|
-
logger$
|
|
3007
|
+
logger$i.info('Reconnect successful');
|
|
3006
3008
|
}
|
|
3007
3009
|
else {
|
|
3008
|
-
logger$
|
|
3010
|
+
logger$i.warn('Reconnect failed - no session or unable to connect');
|
|
3009
3011
|
}
|
|
3010
3012
|
return success;
|
|
3011
3013
|
}
|
|
3012
3014
|
catch (error) {
|
|
3013
|
-
logger$
|
|
3015
|
+
logger$i.error('Reconnect failed', { error });
|
|
3014
3016
|
return false;
|
|
3015
3017
|
}
|
|
3016
3018
|
}
|
|
@@ -3045,7 +3047,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
3045
3047
|
* Implements the IWalletConnectSigner interface for Hedera ledger.
|
|
3046
3048
|
* Handles Hedera-specific JSON-RPC methods and transaction formats.
|
|
3047
3049
|
*/
|
|
3048
|
-
const logger$
|
|
3050
|
+
const logger$h = getLogger().scoped?.('HederaSigner') ?? getLogger();
|
|
3049
3051
|
/**
|
|
3050
3052
|
* Extract a meaningful error message from various error shapes.
|
|
3051
3053
|
* WalletConnect SDK throws errors that are not standard Error instances.
|
|
@@ -3063,7 +3065,7 @@ const logger$g = getLogger().scoped?.('HederaSigner') ?? getLogger();
|
|
|
3063
3065
|
*/
|
|
3064
3066
|
function extractErrorMessage$1(error) {
|
|
3065
3067
|
// Log the raw error for debugging
|
|
3066
|
-
logger$
|
|
3068
|
+
logger$h.debug('Extracting error message', {
|
|
3067
3069
|
errorType: typeof error,
|
|
3068
3070
|
isError: error instanceof Error,
|
|
3069
3071
|
constructorName: error?.constructor?.name,
|
|
@@ -3101,7 +3103,7 @@ function extractErrorMessage$1(error) {
|
|
|
3101
3103
|
propDebug[prop] = '[err]';
|
|
3102
3104
|
}
|
|
3103
3105
|
}
|
|
3104
|
-
logger$
|
|
3106
|
+
logger$h.error('WC Error object dump', propDebug);
|
|
3105
3107
|
// Check for code property first (common in SDK errors like PIN_REQUIRED)
|
|
3106
3108
|
if (typeof errorObj['code'] === 'string') {
|
|
3107
3109
|
const codeMsg = errorObj['message']
|
|
@@ -3182,7 +3184,7 @@ function extractErrorMessage$1(error) {
|
|
|
3182
3184
|
}
|
|
3183
3185
|
// Try getting own property names (includes non-enumerable)
|
|
3184
3186
|
const ownProps = Object.getOwnPropertyNames(errorObj);
|
|
3185
|
-
logger$
|
|
3187
|
+
logger$h.debug('Error object properties', { props: ownProps });
|
|
3186
3188
|
if (ownProps.length > 0) {
|
|
3187
3189
|
// Try to read ALL properties for better debugging
|
|
3188
3190
|
const propValues = [];
|
|
@@ -3203,7 +3205,7 @@ function extractErrorMessage$1(error) {
|
|
|
3203
3205
|
propValues.push(k);
|
|
3204
3206
|
}
|
|
3205
3207
|
}
|
|
3206
|
-
logger$
|
|
3208
|
+
logger$h.debug('Error property values', { values: propValues });
|
|
3207
3209
|
// Return a more informative error
|
|
3208
3210
|
return `Error with properties: ${propValues.slice(0, 5).join(', ')}`;
|
|
3209
3211
|
}
|
|
@@ -3216,7 +3218,7 @@ function extractErrorMessage$1(error) {
|
|
|
3216
3218
|
}
|
|
3217
3219
|
}
|
|
3218
3220
|
// Last resort - log what we know about the object
|
|
3219
|
-
logger$
|
|
3221
|
+
logger$h.warn('Could not extract error message', {
|
|
3220
3222
|
constructor: error?.constructor?.name,
|
|
3221
3223
|
prototype: Object.getPrototypeOf(error)?.constructor?.name,
|
|
3222
3224
|
});
|
|
@@ -3301,9 +3303,15 @@ class HederaSigner {
|
|
|
3301
3303
|
},
|
|
3302
3304
|
expiry: 300, // 5 minutes in seconds
|
|
3303
3305
|
});
|
|
3306
|
+
// #482: prefer the full signed transaction. When the wallet returns a
|
|
3307
|
+
// `signedTransaction` (base64 proto.TransactionList), `signedPayload` carries a
|
|
3308
|
+
// complete signed protobuf the consuming dApp can relay directly (server-side
|
|
3309
|
+
// broadcast) instead of reassembling one from a bare SignatureMap with
|
|
3310
|
+
// @hashgraph/sdk. Fall back to `signatureMap` for HIP-820 wallets that only
|
|
3311
|
+
// return the sign-only shape (back-compat). Raw `result` stays under `metadata.result`.
|
|
3304
3312
|
return {
|
|
3305
|
-
signedPayload: String(result.
|
|
3306
|
-
result.
|
|
3313
|
+
signedPayload: String(result.signedTransaction ||
|
|
3314
|
+
result.signatureMap ||
|
|
3307
3315
|
JSON.stringify(result)),
|
|
3308
3316
|
metadata: { result },
|
|
3309
3317
|
};
|
|
@@ -3315,13 +3323,13 @@ class HederaSigner {
|
|
|
3315
3323
|
Object.keys(error).length === 0 &&
|
|
3316
3324
|
!(error instanceof Error);
|
|
3317
3325
|
if (isEmptyError) {
|
|
3318
|
-
logger$
|
|
3326
|
+
logger$h.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
3319
3327
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3320
3328
|
});
|
|
3321
3329
|
throw new Error('WalletConnect connection issue - please try again');
|
|
3322
3330
|
}
|
|
3323
3331
|
const errorMsg = extractErrorMessage$1(error);
|
|
3324
|
-
logger$
|
|
3332
|
+
logger$h.error('Sign failed', { error: errorMsg });
|
|
3325
3333
|
throw new Error(`Hedera sign failed: ${errorMsg}`);
|
|
3326
3334
|
}
|
|
3327
3335
|
}
|
|
@@ -3337,7 +3345,7 @@ class HederaSigner {
|
|
|
3337
3345
|
const network = params.networkId.includes('mainnet') ? 'mainnet' : 'testnet';
|
|
3338
3346
|
// Format account ID in HIP-30 format
|
|
3339
3347
|
const signerAccountId = `hedera:${network}:${params.accountAddress}`;
|
|
3340
|
-
logger$
|
|
3348
|
+
logger$h.debug('Sending hedera_signAndExecuteTransaction request', {
|
|
3341
3349
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3342
3350
|
chainId: `hedera:${network}`,
|
|
3343
3351
|
signerAccountId,
|
|
@@ -3365,7 +3373,7 @@ class HederaSigner {
|
|
|
3365
3373
|
try {
|
|
3366
3374
|
// Race between the request and our timeout
|
|
3367
3375
|
const result = await Promise.race([requestPromise, timeoutPromise]);
|
|
3368
|
-
logger$
|
|
3376
|
+
logger$h.debug('Received hedera_signAndExecuteTransaction response', {
|
|
3369
3377
|
hasResult: !!result,
|
|
3370
3378
|
resultKeys: result ? Object.keys(result) : [],
|
|
3371
3379
|
});
|
|
@@ -3398,7 +3406,7 @@ class HederaSigner {
|
|
|
3398
3406
|
// Get all own property names
|
|
3399
3407
|
ownProps: error && typeof error === 'object' ? Object.getOwnPropertyNames(error) : [],
|
|
3400
3408
|
};
|
|
3401
|
-
logger$
|
|
3409
|
+
logger$h.error('Submit failed - full error analysis', errorInfo);
|
|
3402
3410
|
// Check if this is an empty error object (WalletConnect SDK bug)
|
|
3403
3411
|
// This typically happens when relay subscription is stale
|
|
3404
3412
|
const isEmptyError = typeof error === 'object' &&
|
|
@@ -3410,7 +3418,7 @@ class HederaSigner {
|
|
|
3410
3418
|
// It usually means the relay subscription was stale
|
|
3411
3419
|
// The SessionHealthManager should have pinged before the request,
|
|
3412
3420
|
// but if we still get this error, the subscription dropped after the ping
|
|
3413
|
-
logger$
|
|
3421
|
+
logger$h.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
3414
3422
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3415
3423
|
hint: 'This can happen when the relay WebSocket connection drops',
|
|
3416
3424
|
});
|
|
@@ -3420,7 +3428,7 @@ class HederaSigner {
|
|
|
3420
3428
|
'please check your transaction history as it may have been executed successfully.');
|
|
3421
3429
|
}
|
|
3422
3430
|
const errorMsg = extractErrorMessage$1(error);
|
|
3423
|
-
logger$
|
|
3431
|
+
logger$h.error('Submit failed', { error: errorMsg });
|
|
3424
3432
|
throw new Error(`Hedera submit failed: ${errorMsg}`);
|
|
3425
3433
|
}
|
|
3426
3434
|
}
|
|
@@ -3477,13 +3485,13 @@ class HederaSigner {
|
|
|
3477
3485
|
Object.keys(error).length === 0 &&
|
|
3478
3486
|
!(error instanceof Error);
|
|
3479
3487
|
if (isEmptyError) {
|
|
3480
|
-
logger$
|
|
3488
|
+
logger$h.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
3481
3489
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3482
3490
|
});
|
|
3483
3491
|
throw new Error('WalletConnect connection issue - please try again');
|
|
3484
3492
|
}
|
|
3485
3493
|
const errorMsg = extractErrorMessage$1(error);
|
|
3486
|
-
logger$
|
|
3494
|
+
logger$h.error('Sign message failed', { error: errorMsg });
|
|
3487
3495
|
throw new Error(`Hedera sign message failed: ${errorMsg}`);
|
|
3488
3496
|
}
|
|
3489
3497
|
}
|
|
@@ -3501,15 +3509,15 @@ class HederaSigner {
|
|
|
3501
3509
|
*/
|
|
3502
3510
|
parseAccounts(namespace, targetNetworkId) {
|
|
3503
3511
|
if (!namespace) {
|
|
3504
|
-
logger$
|
|
3512
|
+
logger$h.warn('Namespace is null or undefined');
|
|
3505
3513
|
return [];
|
|
3506
3514
|
}
|
|
3507
3515
|
if (!namespace.accounts) {
|
|
3508
|
-
logger$
|
|
3516
|
+
logger$h.warn('Namespace has no accounts property');
|
|
3509
3517
|
return [];
|
|
3510
3518
|
}
|
|
3511
3519
|
if (!Array.isArray(namespace.accounts)) {
|
|
3512
|
-
logger$
|
|
3520
|
+
logger$h.warn('Namespace accounts is not an array', {
|
|
3513
3521
|
type: typeof namespace.accounts,
|
|
3514
3522
|
});
|
|
3515
3523
|
return [];
|
|
@@ -3519,7 +3527,7 @@ class HederaSigner {
|
|
|
3519
3527
|
// HIP-30 format: hedera:testnet:0.0.12345
|
|
3520
3528
|
const parts = account.split(':');
|
|
3521
3529
|
if (parts.length < 3) {
|
|
3522
|
-
logger$
|
|
3530
|
+
logger$h.warn('Invalid account format', { account, partsLength: parts.length });
|
|
3523
3531
|
return { address: account, chainId: 'hedera:testnet' };
|
|
3524
3532
|
}
|
|
3525
3533
|
return {
|
|
@@ -3532,7 +3540,7 @@ class HederaSigner {
|
|
|
3532
3540
|
const targetNetwork = targetNetworkId.split(':')[1]?.toLowerCase(); // e.g., 'mainnet'
|
|
3533
3541
|
if (targetNetwork) {
|
|
3534
3542
|
const filteredAccounts = allAccounts.filter((acc) => acc.chainId.toLowerCase().includes(targetNetwork));
|
|
3535
|
-
logger$
|
|
3543
|
+
logger$h.debug('Filtered accounts by target network', {
|
|
3536
3544
|
targetNetworkId,
|
|
3537
3545
|
targetNetwork,
|
|
3538
3546
|
totalAccounts: allAccounts.length,
|
|
@@ -3540,7 +3548,7 @@ class HederaSigner {
|
|
|
3540
3548
|
});
|
|
3541
3549
|
// If no accounts match the target network, log a warning
|
|
3542
3550
|
if (filteredAccounts.length === 0 && allAccounts.length > 0) {
|
|
3543
|
-
logger$
|
|
3551
|
+
logger$h.warn('No accounts found for target network', {
|
|
3544
3552
|
targetNetwork,
|
|
3545
3553
|
availableNetworks: [...new Set(allAccounts.map((a) => a.chainId))],
|
|
3546
3554
|
});
|
|
@@ -3568,7 +3576,7 @@ class HederaSigner {
|
|
|
3568
3576
|
* Implements the IWalletConnectSigner interface for XRPL ledger.
|
|
3569
3577
|
* Handles XRPL-specific JSON-RPC methods and transaction formats.
|
|
3570
3578
|
*/
|
|
3571
|
-
const logger$
|
|
3579
|
+
const logger$g = getLogger().scoped?.('XrplSigner') ?? getLogger();
|
|
3572
3580
|
/**
|
|
3573
3581
|
* Extract a meaningful error message from various error shapes.
|
|
3574
3582
|
* WalletConnect SDK throws errors that are not standard Error instances.
|
|
@@ -3586,7 +3594,7 @@ const logger$f = getLogger().scoped?.('XrplSigner') ?? getLogger();
|
|
|
3586
3594
|
*/
|
|
3587
3595
|
function extractErrorMessage(error) {
|
|
3588
3596
|
// Log raw error for debugging
|
|
3589
|
-
logger$
|
|
3597
|
+
logger$g.debug('Raw error object', {
|
|
3590
3598
|
errorType: typeof error,
|
|
3591
3599
|
isError: error instanceof Error,
|
|
3592
3600
|
errorKeys: typeof error === 'object' && error !== null ? Object.keys(error) : [],
|
|
@@ -3722,7 +3730,7 @@ class XrplSigner {
|
|
|
3722
3730
|
*/
|
|
3723
3731
|
async signTransaction(params) {
|
|
3724
3732
|
// Decode base64 payload to JSON transaction
|
|
3725
|
-
logger$
|
|
3733
|
+
logger$g.debug('Decoding XRPL transaction payload', {
|
|
3726
3734
|
payloadLength: params.payload?.length,
|
|
3727
3735
|
networkId: params.networkId,
|
|
3728
3736
|
topic: params.topic?.substring(0, 16) + '...',
|
|
@@ -3730,19 +3738,19 @@ class XrplSigner {
|
|
|
3730
3738
|
let transaction;
|
|
3731
3739
|
try {
|
|
3732
3740
|
transaction = XrplTransactionEncoder.decodeTransaction(params.payload);
|
|
3733
|
-
logger$
|
|
3741
|
+
logger$g.debug('Transaction decoded successfully', {
|
|
3734
3742
|
transactionType: transaction?.TransactionType,
|
|
3735
3743
|
account: transaction?.Account,
|
|
3736
3744
|
});
|
|
3737
3745
|
}
|
|
3738
3746
|
catch (decodeError) {
|
|
3739
|
-
logger$
|
|
3747
|
+
logger$g.error('Failed to decode transaction payload', {
|
|
3740
3748
|
error: decodeError instanceof Error ? decodeError.message : String(decodeError),
|
|
3741
3749
|
});
|
|
3742
3750
|
throw decodeError;
|
|
3743
3751
|
}
|
|
3744
3752
|
try {
|
|
3745
|
-
logger$
|
|
3753
|
+
logger$g.debug('Sending xrpl_signTransaction request to wallet', {
|
|
3746
3754
|
method: 'xrpl_signTransaction',
|
|
3747
3755
|
chainId: params.networkId,
|
|
3748
3756
|
topic: params.topic?.substring(0, 16) + '...',
|
|
@@ -3759,7 +3767,7 @@ class XrplSigner {
|
|
|
3759
3767
|
},
|
|
3760
3768
|
expiry: 300, // 5 minutes in seconds
|
|
3761
3769
|
});
|
|
3762
|
-
logger$
|
|
3770
|
+
logger$g.debug('Received response from wallet', {
|
|
3763
3771
|
hasResult: !!result,
|
|
3764
3772
|
resultKeys: result ? Object.keys(result) : [],
|
|
3765
3773
|
});
|
|
@@ -3775,13 +3783,13 @@ class XrplSigner {
|
|
|
3775
3783
|
Object.keys(error).length === 0 &&
|
|
3776
3784
|
!(error instanceof Error);
|
|
3777
3785
|
if (isEmptyError) {
|
|
3778
|
-
logger$
|
|
3786
|
+
logger$g.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
3779
3787
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3780
3788
|
});
|
|
3781
3789
|
throw new Error('WalletConnect connection issue - please try again');
|
|
3782
3790
|
}
|
|
3783
3791
|
const errorMsg = extractErrorMessage(error);
|
|
3784
|
-
logger$
|
|
3792
|
+
logger$g.error('Sign failed', { error: errorMsg });
|
|
3785
3793
|
throw new Error(`XRPL sign failed: ${errorMsg}`);
|
|
3786
3794
|
}
|
|
3787
3795
|
}
|
|
@@ -3796,7 +3804,7 @@ class XrplSigner {
|
|
|
3796
3804
|
// Decode base64 payload to JSON transaction
|
|
3797
3805
|
const transaction = XrplTransactionEncoder.decodeTransaction(params.payload);
|
|
3798
3806
|
try {
|
|
3799
|
-
logger$
|
|
3807
|
+
logger$g.debug('Sending xrpl_signAndSubmit request to wallet', {
|
|
3800
3808
|
method: 'xrpl_signAndSubmit',
|
|
3801
3809
|
chainId: params.networkId,
|
|
3802
3810
|
topic: params.topic?.substring(0, 16) + '...',
|
|
@@ -3813,7 +3821,7 @@ class XrplSigner {
|
|
|
3813
3821
|
},
|
|
3814
3822
|
expiry: 300, // 5 minutes in seconds
|
|
3815
3823
|
});
|
|
3816
|
-
logger$
|
|
3824
|
+
logger$g.debug('Received xrpl_signAndSubmit response', {
|
|
3817
3825
|
hasResult: !!result,
|
|
3818
3826
|
resultKeys: result ? Object.keys(result) : [],
|
|
3819
3827
|
});
|
|
@@ -3835,14 +3843,14 @@ class XrplSigner {
|
|
|
3835
3843
|
if (isEmptyError) {
|
|
3836
3844
|
// Empty error object is a known WalletConnect SDK issue
|
|
3837
3845
|
// It usually means the relay subscription was stale
|
|
3838
|
-
logger$
|
|
3846
|
+
logger$g.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
3839
3847
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3840
3848
|
hint: 'This can happen when the relay WebSocket connection drops',
|
|
3841
3849
|
});
|
|
3842
3850
|
throw new Error('WalletConnect connection issue - please try again');
|
|
3843
3851
|
}
|
|
3844
3852
|
const errorMsg = extractErrorMessage(error);
|
|
3845
|
-
logger$
|
|
3853
|
+
logger$g.error('Submit failed', { error: errorMsg });
|
|
3846
3854
|
throw new Error(`XRPL submit failed: ${errorMsg}`);
|
|
3847
3855
|
}
|
|
3848
3856
|
}
|
|
@@ -3892,13 +3900,13 @@ class XrplSigner {
|
|
|
3892
3900
|
Object.keys(error).length === 0 &&
|
|
3893
3901
|
!(error instanceof Error);
|
|
3894
3902
|
if (isEmptyError) {
|
|
3895
|
-
logger$
|
|
3903
|
+
logger$g.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
3896
3904
|
topic: params.topic?.substring(0, 16) + '...',
|
|
3897
3905
|
});
|
|
3898
3906
|
throw new Error('WalletConnect connection issue - please try again');
|
|
3899
3907
|
}
|
|
3900
3908
|
const errorMsg = extractErrorMessage(error);
|
|
3901
|
-
logger$
|
|
3909
|
+
logger$g.error('Sign message failed', { error: errorMsg });
|
|
3902
3910
|
throw new Error(`XRPL sign message failed: ${errorMsg}`);
|
|
3903
3911
|
}
|
|
3904
3912
|
}
|
|
@@ -3923,7 +3931,7 @@ class XrplSigner {
|
|
|
3923
3931
|
// XRPL format: xrpl:testnet:rN7n7otQDd6FczFgLdlqtyMVrn3WnFBrDB
|
|
3924
3932
|
const parts = account.split(':');
|
|
3925
3933
|
if (parts.length < 3) {
|
|
3926
|
-
logger$
|
|
3934
|
+
logger$g.warn('Invalid account format', { account });
|
|
3927
3935
|
return { address: account, chainId: 'xrpl:testnet' };
|
|
3928
3936
|
}
|
|
3929
3937
|
return {
|
|
@@ -3936,7 +3944,7 @@ class XrplSigner {
|
|
|
3936
3944
|
const targetNetwork = targetNetworkId.split(':')[1]?.toLowerCase(); // e.g., 'mainnet'
|
|
3937
3945
|
if (targetNetwork) {
|
|
3938
3946
|
const filteredAccounts = allAccounts.filter((acc) => acc.chainId.toLowerCase().includes(targetNetwork));
|
|
3939
|
-
logger$
|
|
3947
|
+
logger$g.debug('Filtered accounts by target network', {
|
|
3940
3948
|
targetNetworkId,
|
|
3941
3949
|
targetNetwork,
|
|
3942
3950
|
totalAccounts: allAccounts.length,
|
|
@@ -3944,7 +3952,7 @@ class XrplSigner {
|
|
|
3944
3952
|
});
|
|
3945
3953
|
// If no accounts match the target network, log a warning
|
|
3946
3954
|
if (filteredAccounts.length === 0 && allAccounts.length > 0) {
|
|
3947
|
-
logger$
|
|
3955
|
+
logger$g.warn('No accounts found for target network', {
|
|
3948
3956
|
targetNetwork,
|
|
3949
3957
|
availableNetworks: [...new Set(allAccounts.map((a) => a.chainId))],
|
|
3950
3958
|
});
|
|
@@ -3976,7 +3984,7 @@ class XrplSigner {
|
|
|
3976
3984
|
* 1. Implementing IWalletConnectSigner interface
|
|
3977
3985
|
* 2. Registering the signer with SignerFactory
|
|
3978
3986
|
*/
|
|
3979
|
-
const logger$
|
|
3987
|
+
const logger$f = getLogger().scoped?.('SignerFactory') ?? getLogger();
|
|
3980
3988
|
/**
|
|
3981
3989
|
* Factory class for creating and managing WalletConnect signers.
|
|
3982
3990
|
*
|
|
@@ -4018,13 +4026,13 @@ class SignerFactory {
|
|
|
4018
4026
|
*/
|
|
4019
4027
|
static registerSigner(ledgerId, signer) {
|
|
4020
4028
|
if (signer.ledgerId !== ledgerId) {
|
|
4021
|
-
logger$
|
|
4029
|
+
logger$f.warn('Signer ledgerId does not match registration key', {
|
|
4022
4030
|
signerLedgerId: signer.ledgerId,
|
|
4023
4031
|
registrationKey: ledgerId,
|
|
4024
4032
|
});
|
|
4025
4033
|
}
|
|
4026
4034
|
this.signers.set(ledgerId, signer);
|
|
4027
|
-
logger$
|
|
4035
|
+
logger$f.debug('Registered signer for ledger', { ledgerId });
|
|
4028
4036
|
}
|
|
4029
4037
|
/**
|
|
4030
4038
|
* Check if a signer is registered for a ledger.
|
|
@@ -4053,7 +4061,7 @@ class SignerFactory {
|
|
|
4053
4061
|
static unregisterSigner(ledgerId) {
|
|
4054
4062
|
const removed = this.signers.delete(ledgerId);
|
|
4055
4063
|
if (removed) {
|
|
4056
|
-
logger$
|
|
4064
|
+
logger$f.debug('Unregistered signer for ledger', { ledgerId });
|
|
4057
4065
|
}
|
|
4058
4066
|
return removed;
|
|
4059
4067
|
}
|
|
@@ -4082,7 +4090,7 @@ class SignerFactory {
|
|
|
4082
4090
|
* - Automatic ping cache management
|
|
4083
4091
|
* - Subscription refresh capability
|
|
4084
4092
|
*/
|
|
4085
|
-
const logger$
|
|
4093
|
+
const logger$e = getLogger().scoped?.('WCSessionHealth') ?? getLogger();
|
|
4086
4094
|
/**
|
|
4087
4095
|
* Manages WalletConnect session health to prevent stale relay subscription issues.
|
|
4088
4096
|
*
|
|
@@ -4113,7 +4121,7 @@ class SessionHealthManager {
|
|
|
4113
4121
|
constructor(client) {
|
|
4114
4122
|
this.client = client;
|
|
4115
4123
|
this.setupRelayMonitoring();
|
|
4116
|
-
logger$
|
|
4124
|
+
logger$e.info('SessionHealthManager initialized');
|
|
4117
4125
|
}
|
|
4118
4126
|
/**
|
|
4119
4127
|
* Ensure session is healthy before making a request.
|
|
@@ -4131,14 +4139,14 @@ class SessionHealthManager {
|
|
|
4131
4139
|
const now = Date.now();
|
|
4132
4140
|
// Skip if we pinged recently
|
|
4133
4141
|
if (now - lastPing <= this.PING_INTERVAL_MS) {
|
|
4134
|
-
logger$
|
|
4142
|
+
logger$e.debug('Skipping ping - recent ping exists', {
|
|
4135
4143
|
topic: topic.substring(0, 16) + '...',
|
|
4136
4144
|
lastPingAge: now - lastPing,
|
|
4137
4145
|
});
|
|
4138
4146
|
return;
|
|
4139
4147
|
}
|
|
4140
4148
|
try {
|
|
4141
|
-
logger$
|
|
4149
|
+
logger$e.debug('Pinging session to ensure relay subscription', {
|
|
4142
4150
|
topic: topic.substring(0, 16) + '...',
|
|
4143
4151
|
});
|
|
4144
4152
|
// Race ping against timeout
|
|
@@ -4147,14 +4155,14 @@ class SessionHealthManager {
|
|
|
4147
4155
|
new Promise((_, reject) => setTimeout(() => reject(new Error('Ping timeout')), this.PING_TIMEOUT_MS)),
|
|
4148
4156
|
]);
|
|
4149
4157
|
this.lastPingTime.set(topic, now);
|
|
4150
|
-
logger$
|
|
4158
|
+
logger$e.debug('Session ping successful', {
|
|
4151
4159
|
topic: topic.substring(0, 16) + '...',
|
|
4152
4160
|
});
|
|
4153
4161
|
}
|
|
4154
4162
|
catch (err) {
|
|
4155
4163
|
// Log warning but don't throw - let the request attempt proceed
|
|
4156
4164
|
// The request might still succeed if the subscription is actually active
|
|
4157
|
-
logger$
|
|
4165
|
+
logger$e.warn('Session ping failed - relay subscription may be stale', {
|
|
4158
4166
|
topic: topic.substring(0, 16) + '...',
|
|
4159
4167
|
error: err instanceof Error ? err.message : String(err),
|
|
4160
4168
|
});
|
|
@@ -4176,16 +4184,16 @@ class SessionHealthManager {
|
|
|
4176
4184
|
await relayer.subscribe(topic);
|
|
4177
4185
|
// Clear ping cache so next ensureSessionHealth will ping
|
|
4178
4186
|
this.lastPingTime.delete(topic);
|
|
4179
|
-
logger$
|
|
4187
|
+
logger$e.info('Refreshed relay subscription', {
|
|
4180
4188
|
topic: topic.substring(0, 16) + '...',
|
|
4181
4189
|
});
|
|
4182
4190
|
}
|
|
4183
4191
|
else {
|
|
4184
|
-
logger$
|
|
4192
|
+
logger$e.warn('Relayer.subscribe not available');
|
|
4185
4193
|
}
|
|
4186
4194
|
}
|
|
4187
4195
|
catch (err) {
|
|
4188
|
-
logger$
|
|
4196
|
+
logger$e.warn('Failed to refresh subscription', {
|
|
4189
4197
|
topic: topic.substring(0, 16) + '...',
|
|
4190
4198
|
error: err instanceof Error ? err.message : String(err),
|
|
4191
4199
|
});
|
|
@@ -4218,22 +4226,22 @@ class SessionHealthManager {
|
|
|
4218
4226
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- WalletConnect internal API not typed
|
|
4219
4227
|
const relayer = this.client.core?.relayer;
|
|
4220
4228
|
if (!relayer) {
|
|
4221
|
-
logger$
|
|
4229
|
+
logger$e.warn('Could not access relayer for monitoring');
|
|
4222
4230
|
return;
|
|
4223
4231
|
}
|
|
4224
4232
|
relayer.on('connect', () => {
|
|
4225
|
-
logger$
|
|
4233
|
+
logger$e.info('Relay WebSocket connected');
|
|
4226
4234
|
});
|
|
4227
4235
|
relayer.on('disconnect', () => {
|
|
4228
|
-
logger$
|
|
4236
|
+
logger$e.warn('Relay WebSocket disconnected - clearing ping cache');
|
|
4229
4237
|
this.lastPingTime.clear();
|
|
4230
4238
|
});
|
|
4231
4239
|
relayer.on('error', (err) => {
|
|
4232
|
-
logger$
|
|
4240
|
+
logger$e.error('Relay error', {
|
|
4233
4241
|
error: err?.message || String(err),
|
|
4234
4242
|
});
|
|
4235
4243
|
});
|
|
4236
|
-
logger$
|
|
4244
|
+
logger$e.debug('Relay monitoring setup complete');
|
|
4237
4245
|
}
|
|
4238
4246
|
}
|
|
4239
4247
|
|
|
@@ -4258,7 +4266,7 @@ class SessionHealthManager {
|
|
|
4258
4266
|
*
|
|
4259
4267
|
* Extracted from WalletConnectV2Provider to reduce file size.
|
|
4260
4268
|
*/
|
|
4261
|
-
const logger$
|
|
4269
|
+
const logger$d = getLogger().scoped?.('WCClientManager') ?? getLogger();
|
|
4262
4270
|
/**
|
|
4263
4271
|
* Storage key for persisted projectId
|
|
4264
4272
|
*/
|
|
@@ -4285,7 +4293,7 @@ class WalletConnectClientManager {
|
|
|
4285
4293
|
if (this.client && this.projectId === projectId) {
|
|
4286
4294
|
return this.client;
|
|
4287
4295
|
}
|
|
4288
|
-
logger$
|
|
4296
|
+
logger$d.debug('Initializing SignClient', { projectId: projectId.substring(0, 8) });
|
|
4289
4297
|
// Store projectId for session restoration
|
|
4290
4298
|
this.projectId = projectId;
|
|
4291
4299
|
this.persistProjectId(projectId);
|
|
@@ -4297,7 +4305,7 @@ class WalletConnectClientManager {
|
|
|
4297
4305
|
});
|
|
4298
4306
|
// Initialize session health manager for relay subscription management
|
|
4299
4307
|
this.sessionHealth = new SessionHealthManager(this.client);
|
|
4300
|
-
logger$
|
|
4308
|
+
logger$d.info('SignClient initialized with session health manager');
|
|
4301
4309
|
return this.client;
|
|
4302
4310
|
}
|
|
4303
4311
|
/**
|
|
@@ -4326,14 +4334,14 @@ class WalletConnectClientManager {
|
|
|
4326
4334
|
async restoreClient(metadata) {
|
|
4327
4335
|
const storedProjectId = this.getStoredProjectId();
|
|
4328
4336
|
if (!storedProjectId) {
|
|
4329
|
-
logger$
|
|
4337
|
+
logger$d.debug('No stored projectId, skipping client restoration');
|
|
4330
4338
|
return undefined;
|
|
4331
4339
|
}
|
|
4332
4340
|
try {
|
|
4333
4341
|
return await this.initialize(storedProjectId, metadata);
|
|
4334
4342
|
}
|
|
4335
4343
|
catch (error) {
|
|
4336
|
-
logger$
|
|
4344
|
+
logger$d.error('Failed to restore client', {
|
|
4337
4345
|
error: error instanceof Error ? error.message : String(error),
|
|
4338
4346
|
});
|
|
4339
4347
|
return undefined;
|
|
@@ -4400,7 +4408,7 @@ class WalletConnectClientManager {
|
|
|
4400
4408
|
if (sessionProperties) {
|
|
4401
4409
|
connectParams.sessionProperties = sessionProperties;
|
|
4402
4410
|
}
|
|
4403
|
-
logger$
|
|
4411
|
+
logger$d.debug('Connecting with params', {
|
|
4404
4412
|
namespaces: Object.keys(optionalNamespaces),
|
|
4405
4413
|
hasSessionProperties: !!sessionProperties,
|
|
4406
4414
|
});
|
|
@@ -4466,7 +4474,7 @@ class WalletConnectClientManager {
|
|
|
4466
4474
|
const startKeepAlive = () => {
|
|
4467
4475
|
keepAliveInterval = setInterval(async () => {
|
|
4468
4476
|
try {
|
|
4469
|
-
logger$
|
|
4477
|
+
logger$d.debug('Keep-alive ping during request', {
|
|
4470
4478
|
topic: params.topic?.substring(0, 16) + '...',
|
|
4471
4479
|
method: params.request.method,
|
|
4472
4480
|
});
|
|
@@ -4479,7 +4487,7 @@ class WalletConnectClientManager {
|
|
|
4479
4487
|
}
|
|
4480
4488
|
catch (err) {
|
|
4481
4489
|
// Log but don't throw - ping failure during wait is not critical
|
|
4482
|
-
logger$
|
|
4490
|
+
logger$d.debug('Keep-alive ping failed (non-critical)', {
|
|
4483
4491
|
error: err instanceof Error ? err.message : String(err),
|
|
4484
4492
|
});
|
|
4485
4493
|
}
|
|
@@ -4521,7 +4529,7 @@ class WalletConnectClientManager {
|
|
|
4521
4529
|
window.localStorage?.setItem(STORAGE_KEY_PROJECT_ID, projectId);
|
|
4522
4530
|
}
|
|
4523
4531
|
catch {
|
|
4524
|
-
logger$
|
|
4532
|
+
logger$d.warn('Failed to persist projectId');
|
|
4525
4533
|
}
|
|
4526
4534
|
}
|
|
4527
4535
|
getStoredProjectId() {
|
|
@@ -4566,7 +4574,7 @@ class WalletConnectClientManager {
|
|
|
4566
4574
|
* - Aggregate accounts across sessions
|
|
4567
4575
|
* - Find sessions by account address
|
|
4568
4576
|
*/
|
|
4569
|
-
const logger$
|
|
4577
|
+
const logger$c = getLogger().scoped?.('WCSessionStore') ?? getLogger();
|
|
4570
4578
|
/**
|
|
4571
4579
|
* WalletConnect Session Store
|
|
4572
4580
|
*
|
|
@@ -4604,7 +4612,7 @@ class WalletConnectSessionStore {
|
|
|
4604
4612
|
*/
|
|
4605
4613
|
setSession(sessionKey, data) {
|
|
4606
4614
|
this.sessions.set(sessionKey, data);
|
|
4607
|
-
logger$
|
|
4615
|
+
logger$c.debug('Session stored', { sessionKey, accountCount: data.accounts.length });
|
|
4608
4616
|
}
|
|
4609
4617
|
/**
|
|
4610
4618
|
* Delete a session by key.
|
|
@@ -4615,7 +4623,7 @@ class WalletConnectSessionStore {
|
|
|
4615
4623
|
deleteSession(sessionKey) {
|
|
4616
4624
|
const deleted = this.sessions.delete(sessionKey);
|
|
4617
4625
|
if (deleted) {
|
|
4618
|
-
logger$
|
|
4626
|
+
logger$c.debug('Session deleted', { sessionKey });
|
|
4619
4627
|
}
|
|
4620
4628
|
return deleted;
|
|
4621
4629
|
}
|
|
@@ -4639,7 +4647,7 @@ class WalletConnectSessionStore {
|
|
|
4639
4647
|
clear() {
|
|
4640
4648
|
this.sessions.clear();
|
|
4641
4649
|
this._accounts.set([]);
|
|
4642
|
-
logger$
|
|
4650
|
+
logger$c.debug('All sessions cleared');
|
|
4643
4651
|
}
|
|
4644
4652
|
/**
|
|
4645
4653
|
* Get all session entries.
|
|
@@ -4680,7 +4688,7 @@ class WalletConnectSessionStore {
|
|
|
4680
4688
|
for (const sessionData of this.sessions.values()) {
|
|
4681
4689
|
allAccounts.push(...sessionData.accounts);
|
|
4682
4690
|
}
|
|
4683
|
-
logger$
|
|
4691
|
+
logger$c.debug('Aggregated accounts', {
|
|
4684
4692
|
sessionCount: this.sessions.size,
|
|
4685
4693
|
totalAccounts: allAccounts.length,
|
|
4686
4694
|
});
|
|
@@ -4716,7 +4724,7 @@ class WalletConnectSessionStore {
|
|
|
4716
4724
|
for (const [sessionKey, sessionData] of this.sessions.entries()) {
|
|
4717
4725
|
if (sessionData.session.topic === topic) {
|
|
4718
4726
|
this.sessions.delete(sessionKey);
|
|
4719
|
-
logger$
|
|
4727
|
+
logger$c.info('Session removed by topic', { sessionKey, topic: topic.substring(0, 16) });
|
|
4720
4728
|
return { sessionKey, data: sessionData };
|
|
4721
4729
|
}
|
|
4722
4730
|
}
|
|
@@ -4764,7 +4772,7 @@ class WalletConnectSessionStore {
|
|
|
4764
4772
|
*
|
|
4765
4773
|
* Extracted from WalletConnectV2Provider to reduce file size.
|
|
4766
4774
|
*/
|
|
4767
|
-
const logger$
|
|
4775
|
+
const logger$b = getLogger().scoped?.('WCSigningOrchestrator') ?? getLogger();
|
|
4768
4776
|
/**
|
|
4769
4777
|
* Signing Orchestrator
|
|
4770
4778
|
*
|
|
@@ -4795,7 +4803,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4795
4803
|
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'signTransaction');
|
|
4796
4804
|
// Use user's selected network from session, with fallback to options.networkId
|
|
4797
4805
|
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
4798
|
-
logger$
|
|
4806
|
+
logger$b.debug('Routing sign to signer', {
|
|
4799
4807
|
ledgerId: sessionInfo.signer.ledgerId,
|
|
4800
4808
|
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
4801
4809
|
networkId,
|
|
@@ -4818,7 +4826,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4818
4826
|
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'submitTransaction');
|
|
4819
4827
|
// Use user's selected network from session, with fallback to options.networkId
|
|
4820
4828
|
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
4821
|
-
logger$
|
|
4829
|
+
logger$b.debug('Routing submit to signer', {
|
|
4822
4830
|
ledgerId: sessionInfo.signer.ledgerId,
|
|
4823
4831
|
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
4824
4832
|
networkId,
|
|
@@ -4841,7 +4849,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4841
4849
|
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'signAndExecuteTransaction');
|
|
4842
4850
|
// Use user's selected network from session, with fallback to options.networkId
|
|
4843
4851
|
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
4844
|
-
logger$
|
|
4852
|
+
logger$b.debug('Routing signAndExecute to signer', {
|
|
4845
4853
|
ledgerId: sessionInfo.signer.ledgerId,
|
|
4846
4854
|
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
4847
4855
|
networkId,
|
|
@@ -4882,7 +4890,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4882
4890
|
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'signMessage');
|
|
4883
4891
|
// Use user's selected network from session, with fallback to options.networkId
|
|
4884
4892
|
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
4885
|
-
logger$
|
|
4893
|
+
logger$b.debug('Routing signMessage to signer', {
|
|
4886
4894
|
ledgerId: sessionInfo.signer.ledgerId,
|
|
4887
4895
|
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
4888
4896
|
networkId,
|
|
@@ -4923,7 +4931,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4923
4931
|
if (optionsNetworkId &&
|
|
4924
4932
|
sessionInfo.userSelectedNetwork &&
|
|
4925
4933
|
optionsNetworkId !== sessionInfo.userSelectedNetwork) {
|
|
4926
|
-
logger$
|
|
4934
|
+
logger$b.warn('Network mismatch: using session network over caller-provided network', {
|
|
4927
4935
|
callerNetwork: optionsNetworkId,
|
|
4928
4936
|
sessionNetwork: sessionInfo.userSelectedNetwork,
|
|
4929
4937
|
using: resolvedNetwork,
|
|
@@ -4943,7 +4951,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4943
4951
|
}
|
|
4944
4952
|
// Validate session exists in WC SDK
|
|
4945
4953
|
if (!this.validateSessionInSdk(sessionInfo.session.topic)) {
|
|
4946
|
-
logger$
|
|
4954
|
+
logger$b.error('Session not found in WC SDK', {
|
|
4947
4955
|
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
4948
4956
|
account: accountAddress,
|
|
4949
4957
|
});
|
|
@@ -4970,7 +4978,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
4970
4978
|
return !!session;
|
|
4971
4979
|
}
|
|
4972
4980
|
catch (error) {
|
|
4973
|
-
logger$
|
|
4981
|
+
logger$b.warn('Session validation failed', {
|
|
4974
4982
|
topic: topic.substring(0, 16) + '...',
|
|
4975
4983
|
error: error instanceof Error ? error.message : String(error),
|
|
4976
4984
|
});
|
|
@@ -5006,7 +5014,7 @@ class WalletConnectSigningOrchestrator {
|
|
|
5006
5014
|
* - Testable (mock signers for unit tests)
|
|
5007
5015
|
* - Maintainable (ledger logic is isolated)
|
|
5008
5016
|
*/
|
|
5009
|
-
const logger$
|
|
5017
|
+
const logger$a = getLogger().scoped?.('WalletConnectV2Provider') ?? getLogger();
|
|
5010
5018
|
/**
|
|
5011
5019
|
* Storage key prefix for persisting user's network selection per session topic.
|
|
5012
5020
|
* This is critical for proper session restoration after page reload.
|
|
@@ -5070,7 +5078,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5070
5078
|
clientManager: this.clientManager,
|
|
5071
5079
|
eventBus: this.eventBus,
|
|
5072
5080
|
});
|
|
5073
|
-
logger$
|
|
5081
|
+
logger$a.info('Initializing - will attempt session restoration');
|
|
5074
5082
|
void this.restoreSession();
|
|
5075
5083
|
}
|
|
5076
5084
|
/**
|
|
@@ -5097,7 +5105,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5097
5105
|
*/
|
|
5098
5106
|
async restoreSession() {
|
|
5099
5107
|
try {
|
|
5100
|
-
logger$
|
|
5108
|
+
logger$a.debug('Attempting to restore sessions...');
|
|
5101
5109
|
// Restore client from stored projectId
|
|
5102
5110
|
const client = await this.clientManager.restoreClient({
|
|
5103
5111
|
name: 'HSuite Demo',
|
|
@@ -5112,7 +5120,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5112
5120
|
this.registerSessionDeleteListener();
|
|
5113
5121
|
// Get all active sessions
|
|
5114
5122
|
const activeSessions = this.clientManager.getActiveSessions();
|
|
5115
|
-
logger$
|
|
5123
|
+
logger$a.info('Found active sessions', { count: activeSessions.length });
|
|
5116
5124
|
if (activeSessions.length === 0) {
|
|
5117
5125
|
return;
|
|
5118
5126
|
}
|
|
@@ -5122,7 +5130,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5122
5130
|
await this.restoreSingleSession(session);
|
|
5123
5131
|
}
|
|
5124
5132
|
catch (error) {
|
|
5125
|
-
logger$
|
|
5133
|
+
logger$a.error('Failed to restore session', {
|
|
5126
5134
|
topic: session.topic,
|
|
5127
5135
|
error: error instanceof Error ? error.message : String(error),
|
|
5128
5136
|
});
|
|
@@ -5132,11 +5140,11 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5132
5140
|
this.sessionStore.updateAggregatedAccounts();
|
|
5133
5141
|
if (this.sessionStore.size > 0) {
|
|
5134
5142
|
this._status.set('connected');
|
|
5135
|
-
logger$
|
|
5143
|
+
logger$a.info('Restored sessions', { count: this.sessionStore.size });
|
|
5136
5144
|
}
|
|
5137
5145
|
}
|
|
5138
5146
|
catch (error) {
|
|
5139
|
-
logger$
|
|
5147
|
+
logger$a.error('Failed to restore sessions', {
|
|
5140
5148
|
error: error instanceof Error ? error.message : String(error),
|
|
5141
5149
|
});
|
|
5142
5150
|
}
|
|
@@ -5151,23 +5159,23 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5151
5159
|
* @param session - WalletConnect session object from IndexedDB
|
|
5152
5160
|
*/
|
|
5153
5161
|
async restoreSingleSession(session) {
|
|
5154
|
-
logger$
|
|
5155
|
-
logger$
|
|
5162
|
+
logger$a.debug('Restoring session', { topic: session.topic });
|
|
5163
|
+
logger$a.debug('Session namespaces', { namespaces: Object.keys(session.namespaces) });
|
|
5156
5164
|
// Determine ledger from session namespaces
|
|
5157
5165
|
let ledgerId;
|
|
5158
5166
|
let walletReportedNetwork;
|
|
5159
5167
|
if (session.namespaces.hedera) {
|
|
5160
5168
|
ledgerId = 'hedera';
|
|
5161
5169
|
walletReportedNetwork = session.namespaces.hedera.chains?.[0] || 'hedera:testnet';
|
|
5162
|
-
logger$
|
|
5170
|
+
logger$a.debug('Found Hedera namespace', { chains: session.namespaces.hedera.chains });
|
|
5163
5171
|
}
|
|
5164
5172
|
else if (session.namespaces.xrpl) {
|
|
5165
5173
|
ledgerId = 'xrpl';
|
|
5166
5174
|
walletReportedNetwork = session.namespaces.xrpl.chains?.[0] || 'xrpl:testnet';
|
|
5167
|
-
logger$
|
|
5175
|
+
logger$a.debug('Found XRPL namespace', { chains: session.namespaces.xrpl.chains });
|
|
5168
5176
|
}
|
|
5169
5177
|
if (!ledgerId || !walletReportedNetwork) {
|
|
5170
|
-
logger$
|
|
5178
|
+
logger$a.warn('Could not determine ledger for session', {
|
|
5171
5179
|
topic: session.topic,
|
|
5172
5180
|
availableNamespaces: Object.keys(session.namespaces),
|
|
5173
5181
|
});
|
|
@@ -5178,14 +5186,14 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5178
5186
|
const userSelectedNetwork = this.getUserNetworkSelection(session.topic);
|
|
5179
5187
|
const networkId = userSelectedNetwork || walletReportedNetwork;
|
|
5180
5188
|
if (userSelectedNetwork) {
|
|
5181
|
-
logger$
|
|
5189
|
+
logger$a.debug('Restored user network selection', {
|
|
5182
5190
|
userSelectedNetwork,
|
|
5183
5191
|
walletReportedNetwork,
|
|
5184
5192
|
topic: session.topic.substring(0, 16),
|
|
5185
5193
|
});
|
|
5186
5194
|
}
|
|
5187
5195
|
else {
|
|
5188
|
-
logger$
|
|
5196
|
+
logger$a.warn('No stored network selection found, using wallet-reported network', {
|
|
5189
5197
|
walletReportedNetwork,
|
|
5190
5198
|
topic: session.topic.substring(0, 16),
|
|
5191
5199
|
});
|
|
@@ -5196,18 +5204,18 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5196
5204
|
const sessionKey = this.sessionStore.generateSessionKey(ledgerId, networkId, session.topic);
|
|
5197
5205
|
// Parse accounts from session, filtering by user's selected network
|
|
5198
5206
|
const namespace = session.namespaces[ledgerId];
|
|
5199
|
-
logger$
|
|
5207
|
+
logger$a.debug('Namespace for restoration', {
|
|
5200
5208
|
ledgerId,
|
|
5201
5209
|
accountCount: namespace?.accounts?.length || 0,
|
|
5202
5210
|
});
|
|
5203
5211
|
// Pass the user's selected network to filter accounts appropriately
|
|
5204
5212
|
const parsedAccounts = signer.parseAccounts(namespace, userSelectedNetwork);
|
|
5205
|
-
logger$
|
|
5213
|
+
logger$a.debug('Parsed accounts from restored session', {
|
|
5206
5214
|
count: parsedAccounts.length,
|
|
5207
5215
|
userSelectedNetwork,
|
|
5208
5216
|
});
|
|
5209
5217
|
if (parsedAccounts.length === 0) {
|
|
5210
|
-
logger$
|
|
5218
|
+
logger$a.warn('Restored session has no accounts for selected network', {
|
|
5211
5219
|
userSelectedNetwork,
|
|
5212
5220
|
walletReportedNetwork,
|
|
5213
5221
|
});
|
|
@@ -5239,7 +5247,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5239
5247
|
signer,
|
|
5240
5248
|
accounts,
|
|
5241
5249
|
});
|
|
5242
|
-
logger$
|
|
5250
|
+
logger$a.info('Restored session', {
|
|
5243
5251
|
sessionKey,
|
|
5244
5252
|
ledgerId,
|
|
5245
5253
|
networkId,
|
|
@@ -5266,13 +5274,13 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5266
5274
|
storeUserNetworkSelection(sessionTopic, networkId) {
|
|
5267
5275
|
try {
|
|
5268
5276
|
localStorage.setItem(`${NETWORK_SELECTION_STORAGE_KEY}${sessionTopic}`, networkId);
|
|
5269
|
-
logger$
|
|
5277
|
+
logger$a.debug('Stored user network selection', {
|
|
5270
5278
|
topic: sessionTopic.substring(0, 16),
|
|
5271
5279
|
networkId,
|
|
5272
5280
|
});
|
|
5273
5281
|
}
|
|
5274
5282
|
catch (e) {
|
|
5275
|
-
logger$
|
|
5283
|
+
logger$a.warn('Failed to store network selection', { error: e.message });
|
|
5276
5284
|
}
|
|
5277
5285
|
}
|
|
5278
5286
|
/**
|
|
@@ -5286,7 +5294,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5286
5294
|
return localStorage.getItem(`${NETWORK_SELECTION_STORAGE_KEY}${sessionTopic}`) || undefined;
|
|
5287
5295
|
}
|
|
5288
5296
|
catch (e) {
|
|
5289
|
-
logger$
|
|
5297
|
+
logger$a.warn('Failed to retrieve network selection', { error: e.message });
|
|
5290
5298
|
return undefined;
|
|
5291
5299
|
}
|
|
5292
5300
|
}
|
|
@@ -5332,7 +5340,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5332
5340
|
}
|
|
5333
5341
|
// Get the appropriate signer for this ledger (Strategy Pattern)
|
|
5334
5342
|
const signer = SignerFactory.getSigner(wcConfig.ledgerId);
|
|
5335
|
-
logger$
|
|
5343
|
+
logger$a.debug('Using signer for ledger', { ledgerId: wcConfig.ledgerId });
|
|
5336
5344
|
// Initialize client via manager
|
|
5337
5345
|
await this.clientManager.initialize(projectId, {
|
|
5338
5346
|
name: wcConfig.appName || 'HSuite Demo',
|
|
@@ -5346,14 +5354,14 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5346
5354
|
// Build namespace configuration using signer
|
|
5347
5355
|
const namespaceConfig = signer.buildNamespace(wcConfig.networkId);
|
|
5348
5356
|
const optionalNamespaces = { [wcConfig.ledgerId]: namespaceConfig };
|
|
5349
|
-
logger$
|
|
5357
|
+
logger$a.debug('Namespace config', { ledgerId: wcConfig.ledgerId });
|
|
5350
5358
|
// Build session properties to pass user's preferred network to wallet
|
|
5351
5359
|
// This tells the wallet which network accounts to show in the picker
|
|
5352
5360
|
const sessionProperties = {
|
|
5353
5361
|
preferredNetwork: wcConfig.networkId,
|
|
5354
5362
|
preferredLedger: wcConfig.ledgerId,
|
|
5355
5363
|
};
|
|
5356
|
-
logger$
|
|
5364
|
+
logger$a.info('Connecting with preferred network', {
|
|
5357
5365
|
preferredNetwork: wcConfig.networkId,
|
|
5358
5366
|
preferredLedger: wcConfig.ledgerId,
|
|
5359
5367
|
});
|
|
@@ -5363,10 +5371,10 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5363
5371
|
await modal.openModal({ uri });
|
|
5364
5372
|
}
|
|
5365
5373
|
// Wait for wallet approval
|
|
5366
|
-
logger$
|
|
5374
|
+
logger$a.info('Waiting for wallet approval...');
|
|
5367
5375
|
const session = await approval();
|
|
5368
5376
|
this.clientManager.closeModal();
|
|
5369
|
-
logger$
|
|
5377
|
+
logger$a.info('[WC:DAPP:APPROVED] Session approved by wallet', {
|
|
5370
5378
|
topic: session.topic.substring(0, 16) + '...',
|
|
5371
5379
|
fullTopic: session.topic,
|
|
5372
5380
|
namespaces: Object.keys(session.namespaces),
|
|
@@ -5376,12 +5384,12 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5376
5384
|
const sessionKey = this.sessionStore.generateSessionKey(wcConfig.ledgerId, wcConfig.networkId, session.topic);
|
|
5377
5385
|
// Parse accounts from session
|
|
5378
5386
|
const sessionNamespace = session.namespaces[wcConfig.ledgerId];
|
|
5379
|
-
logger$
|
|
5387
|
+
logger$a.debug('Session namespace for ledger', {
|
|
5380
5388
|
ledgerId: wcConfig.ledgerId,
|
|
5381
5389
|
accountCount: sessionNamespace?.accounts?.length || 0,
|
|
5382
5390
|
});
|
|
5383
5391
|
if (!sessionNamespace) {
|
|
5384
|
-
logger$
|
|
5392
|
+
logger$a.error('No namespace found for ledger', {
|
|
5385
5393
|
ledgerId: wcConfig.ledgerId,
|
|
5386
5394
|
availableNamespaces: Object.keys(session.namespaces),
|
|
5387
5395
|
});
|
|
@@ -5390,12 +5398,12 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5390
5398
|
// Parse accounts from session namespace, filtering by user's selected network
|
|
5391
5399
|
// This ensures we only show accounts that match the network the user selected
|
|
5392
5400
|
const parsedAccounts = signer.parseAccounts(sessionNamespace, wcConfig.networkId);
|
|
5393
|
-
logger$
|
|
5401
|
+
logger$a.debug('Parsed accounts', {
|
|
5394
5402
|
count: parsedAccounts.length,
|
|
5395
5403
|
userSelectedNetwork: wcConfig.networkId,
|
|
5396
5404
|
});
|
|
5397
5405
|
if (parsedAccounts.length === 0) {
|
|
5398
|
-
logger$
|
|
5406
|
+
logger$a.warn('No accounts returned from wallet - possible causes:', {
|
|
5399
5407
|
reason1: 'Wallet has no accounts for the requested network',
|
|
5400
5408
|
reason2: 'Wallet denied account sharing',
|
|
5401
5409
|
reason3: 'Wallet returned accounts in unexpected format',
|
|
@@ -5434,7 +5442,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5434
5442
|
this.storeUserNetworkSelection(session.topic, wcConfig.networkId);
|
|
5435
5443
|
// Verify session exists in WC SDK after storing
|
|
5436
5444
|
const sdkSession = this.clientManager.getSession(session.topic);
|
|
5437
|
-
logger$
|
|
5445
|
+
logger$a.info('[WC:DAPP:STORED] Session stored locally', {
|
|
5438
5446
|
sessionKey,
|
|
5439
5447
|
topic: session.topic.substring(0, 16) + '...',
|
|
5440
5448
|
fullTopic: session.topic,
|
|
@@ -5463,7 +5471,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5463
5471
|
catch (error) {
|
|
5464
5472
|
this._status.set('error');
|
|
5465
5473
|
this._error.set(error instanceof Error ? error.message : 'Connection failed');
|
|
5466
|
-
logger$
|
|
5474
|
+
logger$a.error('Connection failed', {
|
|
5467
5475
|
error: error instanceof Error ? error.message : String(error),
|
|
5468
5476
|
});
|
|
5469
5477
|
// Emit provider error event
|
|
@@ -5528,14 +5536,14 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5528
5536
|
// WalletConnect events arrive outside Angular's zone
|
|
5529
5537
|
this.clientManager.on('session_delete', (event) => {
|
|
5530
5538
|
this.zone.run(() => {
|
|
5531
|
-
logger$
|
|
5539
|
+
logger$a.info('� Session deleted by wallet (session_delete event)', {
|
|
5532
5540
|
topic: event.topic,
|
|
5533
5541
|
});
|
|
5534
5542
|
this.removeSessionByTopic(event.topic);
|
|
5535
5543
|
});
|
|
5536
5544
|
});
|
|
5537
5545
|
this.sessionDeleteListenerRegistered = true;
|
|
5538
|
-
logger$
|
|
5546
|
+
logger$a.debug('session_delete listener registered');
|
|
5539
5547
|
}
|
|
5540
5548
|
/**
|
|
5541
5549
|
* Disconnect from WalletConnect sessions.
|
|
@@ -5545,7 +5553,7 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5545
5553
|
*/
|
|
5546
5554
|
async disconnect(sessionKey) {
|
|
5547
5555
|
if (!this.clientManager.isInitialized()) {
|
|
5548
|
-
logger$
|
|
5556
|
+
logger$a.warn('No client to disconnect');
|
|
5549
5557
|
return;
|
|
5550
5558
|
}
|
|
5551
5559
|
if (sessionKey) {
|
|
@@ -5557,10 +5565,10 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5557
5565
|
code: 6000,
|
|
5558
5566
|
message: 'User disconnected session',
|
|
5559
5567
|
});
|
|
5560
|
-
logger$
|
|
5568
|
+
logger$a.info('Disconnected session', { sessionKey });
|
|
5561
5569
|
}
|
|
5562
5570
|
catch (e) {
|
|
5563
|
-
logger$
|
|
5571
|
+
logger$a.error('Disconnect error for session', {
|
|
5564
5572
|
sessionKey,
|
|
5565
5573
|
error: e instanceof Error ? e.message : String(e),
|
|
5566
5574
|
});
|
|
@@ -5585,14 +5593,14 @@ class WalletConnectV2Provider extends BaseWalletProvider {
|
|
|
5585
5593
|
code: 6000,
|
|
5586
5594
|
message: 'User disconnected all sessions',
|
|
5587
5595
|
})
|
|
5588
|
-
.catch((err) => logger$
|
|
5596
|
+
.catch((err) => logger$a.error('Disconnect error', {
|
|
5589
5597
|
error: err.message,
|
|
5590
5598
|
})));
|
|
5591
5599
|
}
|
|
5592
5600
|
await Promise.all(disconnectPromises);
|
|
5593
5601
|
this.sessionStore.clear();
|
|
5594
5602
|
this._status.set('disconnected');
|
|
5595
|
-
logger$
|
|
5603
|
+
logger$a.info('Disconnected all sessions');
|
|
5596
5604
|
}
|
|
5597
5605
|
this.clientManager.closeModal();
|
|
5598
5606
|
}
|
|
@@ -5695,7 +5703,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
5695
5703
|
* - RPC communication over best available transport
|
|
5696
5704
|
* - Session ownership remains with the wallet
|
|
5697
5705
|
*/
|
|
5698
|
-
const logger$
|
|
5706
|
+
const logger$9 = getLogger().scoped?.('P2PSessionManager') ?? getLogger();
|
|
5699
5707
|
/**
|
|
5700
5708
|
* Mobile Native Session Manager
|
|
5701
5709
|
*
|
|
@@ -5764,7 +5772,7 @@ class P2PSessionManager {
|
|
|
5764
5772
|
* @returns Promise resolving to offer result with QR data
|
|
5765
5773
|
*/
|
|
5766
5774
|
async createPairingOffer(options) {
|
|
5767
|
-
logger$
|
|
5775
|
+
logger$9.info('Creating pairing offer (Nostr-first)', { options });
|
|
5768
5776
|
try {
|
|
5769
5777
|
this.runInZone(() => this._connectionState.set('creating_offer'));
|
|
5770
5778
|
// Clean up any existing client
|
|
@@ -5777,12 +5785,12 @@ class P2PSessionManager {
|
|
|
5777
5785
|
this.client = new ChannelClient({
|
|
5778
5786
|
p2p: { enabled: true },
|
|
5779
5787
|
onStateChange: (state) => {
|
|
5780
|
-
logger$
|
|
5788
|
+
logger$9.debug('ChannelClient state callback', { state });
|
|
5781
5789
|
const accounts = this.client?.accounts ?? [];
|
|
5782
5790
|
this.handleStateChange(state, accounts);
|
|
5783
5791
|
},
|
|
5784
5792
|
onAccountsChange: (accounts) => {
|
|
5785
|
-
logger$
|
|
5793
|
+
logger$9.debug('ChannelClient accounts callback', { count: accounts.length });
|
|
5786
5794
|
const state = this.client?.state ?? 'idle';
|
|
5787
5795
|
this.handleStateChange(state, accounts);
|
|
5788
5796
|
},
|
|
@@ -5807,7 +5815,7 @@ class P2PSessionManager {
|
|
|
5807
5815
|
// Encode invite for QR code
|
|
5808
5816
|
const qrData = encodeChannelInvite(invite);
|
|
5809
5817
|
this.runInZone(() => this._connectionState.set('awaiting_connection'));
|
|
5810
|
-
logger$
|
|
5818
|
+
logger$9.info('Pairing offer created', {
|
|
5811
5819
|
sessionId: invite.id.slice(0, 8),
|
|
5812
5820
|
qrDataLength: qrData.length,
|
|
5813
5821
|
});
|
|
@@ -5816,7 +5824,7 @@ class P2PSessionManager {
|
|
|
5816
5824
|
return { qrData, sessionId: invite.id };
|
|
5817
5825
|
}
|
|
5818
5826
|
catch (error) {
|
|
5819
|
-
logger$
|
|
5827
|
+
logger$9.error('Failed to create pairing offer', { error });
|
|
5820
5828
|
this.runInZone(() => this._connectionState.set('error'));
|
|
5821
5829
|
this.notifyError(error instanceof Error ? error : new Error('Failed to create offer'));
|
|
5822
5830
|
throw error;
|
|
@@ -5834,7 +5842,7 @@ class P2PSessionManager {
|
|
|
5834
5842
|
if (!this.client || !this.currentInvite) {
|
|
5835
5843
|
throw new Error('No active pairing offer - call createPairingOffer first');
|
|
5836
5844
|
}
|
|
5837
|
-
logger$
|
|
5845
|
+
logger$9.info('Waiting for wallet to connect and approve session...');
|
|
5838
5846
|
return new Promise((resolve, reject) => {
|
|
5839
5847
|
this.sessionApprovalPromise = { resolve, reject };
|
|
5840
5848
|
});
|
|
@@ -5845,7 +5853,7 @@ class P2PSessionManager {
|
|
|
5845
5853
|
* Cleans up the transport without fully disconnecting.
|
|
5846
5854
|
*/
|
|
5847
5855
|
async cancelPairingOffer() {
|
|
5848
|
-
logger$
|
|
5856
|
+
logger$9.debug('Cancelling pairing offer');
|
|
5849
5857
|
if (this.sessionApprovalPromise) {
|
|
5850
5858
|
this.sessionApprovalPromise.reject(new Error('Pairing cancelled'));
|
|
5851
5859
|
this.sessionApprovalPromise = undefined;
|
|
@@ -5887,7 +5895,7 @@ class P2PSessionManager {
|
|
|
5887
5895
|
*/
|
|
5888
5896
|
async signTransaction(options) {
|
|
5889
5897
|
this.requireSession();
|
|
5890
|
-
logger$
|
|
5898
|
+
logger$9.info('Signing transaction', { account: options.accountAddress });
|
|
5891
5899
|
if (!this.client) {
|
|
5892
5900
|
throw new Error('Not connected');
|
|
5893
5901
|
}
|
|
@@ -5909,7 +5917,7 @@ class P2PSessionManager {
|
|
|
5909
5917
|
*/
|
|
5910
5918
|
async submitTransaction(options) {
|
|
5911
5919
|
this.requireSession();
|
|
5912
|
-
logger$
|
|
5920
|
+
logger$9.info('Submitting transaction', { account: options.accountAddress });
|
|
5913
5921
|
if (!this.client) {
|
|
5914
5922
|
throw new Error('Not connected');
|
|
5915
5923
|
}
|
|
@@ -5934,7 +5942,7 @@ class P2PSessionManager {
|
|
|
5934
5942
|
*/
|
|
5935
5943
|
async signMessage(options) {
|
|
5936
5944
|
this.requireSession();
|
|
5937
|
-
logger$
|
|
5945
|
+
logger$9.info('Signing message', { account: options.accountAddress });
|
|
5938
5946
|
if (!this.client) {
|
|
5939
5947
|
throw new Error('Not connected');
|
|
5940
5948
|
}
|
|
@@ -5959,7 +5967,7 @@ class P2PSessionManager {
|
|
|
5959
5967
|
* Terminate the current session
|
|
5960
5968
|
*/
|
|
5961
5969
|
async terminateSession() {
|
|
5962
|
-
logger$
|
|
5970
|
+
logger$9.info('Terminating session');
|
|
5963
5971
|
if (this.client) {
|
|
5964
5972
|
await this.client.disconnect();
|
|
5965
5973
|
}
|
|
@@ -6060,6 +6068,7 @@ class P2PSessionManager {
|
|
|
6060
6068
|
accounts: accounts.map((acc, index) => ({
|
|
6061
6069
|
id: `p2p-${acc.address}`,
|
|
6062
6070
|
address: acc.address,
|
|
6071
|
+
publicKey: acc.publicKey,
|
|
6063
6072
|
label: acc.alias || `Account ${index + 1}`,
|
|
6064
6073
|
ledgerId: acc.ledgerId,
|
|
6065
6074
|
networkId: acc.networkId,
|
|
@@ -6078,7 +6087,7 @@ class P2PSessionManager {
|
|
|
6078
6087
|
* @param reason
|
|
6079
6088
|
*/
|
|
6080
6089
|
handleDisconnection(reason) {
|
|
6081
|
-
logger$
|
|
6090
|
+
logger$9.info('Handling disconnection', { reason });
|
|
6082
6091
|
this.cleanup();
|
|
6083
6092
|
this.runInZone(() => {
|
|
6084
6093
|
this._currentSession.set(null);
|
|
@@ -6130,7 +6139,7 @@ class P2PSessionManager {
|
|
|
6130
6139
|
callback(session);
|
|
6131
6140
|
}
|
|
6132
6141
|
catch (error) {
|
|
6133
|
-
logger$
|
|
6142
|
+
logger$9.error('Connected callback error', { error });
|
|
6134
6143
|
}
|
|
6135
6144
|
}
|
|
6136
6145
|
}
|
|
@@ -6143,7 +6152,7 @@ class P2PSessionManager {
|
|
|
6143
6152
|
callback();
|
|
6144
6153
|
}
|
|
6145
6154
|
catch (error) {
|
|
6146
|
-
logger$
|
|
6155
|
+
logger$9.error('Disconnected callback error', { error });
|
|
6147
6156
|
}
|
|
6148
6157
|
}
|
|
6149
6158
|
}
|
|
@@ -6157,7 +6166,7 @@ class P2PSessionManager {
|
|
|
6157
6166
|
callback(error);
|
|
6158
6167
|
}
|
|
6159
6168
|
catch (err) {
|
|
6160
|
-
logger$
|
|
6169
|
+
logger$9.error('Error callback error', { err });
|
|
6161
6170
|
}
|
|
6162
6171
|
}
|
|
6163
6172
|
}
|
|
@@ -6199,7 +6208,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
6199
6208
|
* 4. User approves session in wallet
|
|
6200
6209
|
* 5. P2P upgrade happens automatically in background
|
|
6201
6210
|
*/
|
|
6202
|
-
const logger$
|
|
6211
|
+
const logger$8 = getLogger().scoped?.('P2PNativeProvider') ?? getLogger();
|
|
6203
6212
|
/**
|
|
6204
6213
|
* Storage key for mobile session metadata (separate from hsuite-native)
|
|
6205
6214
|
*/
|
|
@@ -6224,10 +6233,10 @@ class P2PSessionPersistence {
|
|
|
6224
6233
|
timestamp: Date.now(),
|
|
6225
6234
|
};
|
|
6226
6235
|
window.localStorage.setItem(P2P_SESSION_STORAGE_KEY, JSON.stringify(payload));
|
|
6227
|
-
logger$
|
|
6236
|
+
logger$8.debug('Mobile session persisted', { sessionId: session.sessionId });
|
|
6228
6237
|
}
|
|
6229
6238
|
catch (error) {
|
|
6230
|
-
logger$
|
|
6239
|
+
logger$8.warn('Failed to persist mobile session', { error });
|
|
6231
6240
|
}
|
|
6232
6241
|
}
|
|
6233
6242
|
/**
|
|
@@ -6245,11 +6254,11 @@ class P2PSessionPersistence {
|
|
|
6245
6254
|
this.clear();
|
|
6246
6255
|
return null;
|
|
6247
6256
|
}
|
|
6248
|
-
logger$
|
|
6257
|
+
logger$8.info('Restored mobile session metadata', { sessionId: stored.sessionId });
|
|
6249
6258
|
return stored;
|
|
6250
6259
|
}
|
|
6251
6260
|
catch (error) {
|
|
6252
|
-
logger$
|
|
6261
|
+
logger$8.warn('Failed to restore mobile session', { error });
|
|
6253
6262
|
return null;
|
|
6254
6263
|
}
|
|
6255
6264
|
}
|
|
@@ -6261,10 +6270,10 @@ class P2PSessionPersistence {
|
|
|
6261
6270
|
if (typeof window === 'undefined')
|
|
6262
6271
|
return;
|
|
6263
6272
|
window.localStorage.removeItem(P2P_SESSION_STORAGE_KEY);
|
|
6264
|
-
logger$
|
|
6273
|
+
logger$8.debug('Mobile session cleared');
|
|
6265
6274
|
}
|
|
6266
6275
|
catch (error) {
|
|
6267
|
-
logger$
|
|
6276
|
+
logger$8.warn('Failed to clear mobile session', { error });
|
|
6268
6277
|
}
|
|
6269
6278
|
}
|
|
6270
6279
|
/**
|
|
@@ -6384,7 +6393,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6384
6393
|
restorePersistedSession() {
|
|
6385
6394
|
const stored = this.sessionPersistence.restore();
|
|
6386
6395
|
if (stored) {
|
|
6387
|
-
logger$
|
|
6396
|
+
logger$8.info('Restoring persisted mobile session', {
|
|
6388
6397
|
sessionId: stored.sessionId,
|
|
6389
6398
|
accountCount: stored.accounts?.length ?? 0,
|
|
6390
6399
|
});
|
|
@@ -6395,7 +6404,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6395
6404
|
}
|
|
6396
6405
|
// Note: We don't set connected status because WebRTC needs re-pairing
|
|
6397
6406
|
// The persisted data is for account info only
|
|
6398
|
-
logger$
|
|
6407
|
+
logger$8.debug('Mobile session metadata restored (requires re-pairing for connection)');
|
|
6399
6408
|
}
|
|
6400
6409
|
}
|
|
6401
6410
|
/**
|
|
@@ -6418,7 +6427,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6418
6427
|
* @throws {Error} If offer generation fails
|
|
6419
6428
|
*/
|
|
6420
6429
|
async createPairingOffer(config) {
|
|
6421
|
-
logger$
|
|
6430
|
+
logger$8.info('Creating pairing offer', { config });
|
|
6422
6431
|
try {
|
|
6423
6432
|
this._connectionState.set('generating_offer');
|
|
6424
6433
|
this._error.set(null);
|
|
@@ -6441,14 +6450,14 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6441
6450
|
this._pairingOffer.set(offerResult);
|
|
6442
6451
|
this._connectionState.set('awaiting_scan');
|
|
6443
6452
|
this._status.set('connecting');
|
|
6444
|
-
logger$
|
|
6453
|
+
logger$8.info('Pairing offer created', {
|
|
6445
6454
|
qrDataLength: result.qrData.length,
|
|
6446
6455
|
expiresAt: offerResult.expiresAt,
|
|
6447
6456
|
});
|
|
6448
6457
|
return offerResult;
|
|
6449
6458
|
}
|
|
6450
6459
|
catch (error) {
|
|
6451
|
-
logger$
|
|
6460
|
+
logger$8.error('Failed to create pairing offer', { error });
|
|
6452
6461
|
this._connectionState.set('error');
|
|
6453
6462
|
this._status.set('error');
|
|
6454
6463
|
this._error.set(error instanceof Error ? error.message : 'Failed to create pairing offer');
|
|
@@ -6462,7 +6471,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6462
6471
|
* @returns Promise resolving to new pairing offer
|
|
6463
6472
|
*/
|
|
6464
6473
|
async refreshPairingOffer(config) {
|
|
6465
|
-
logger$
|
|
6474
|
+
logger$8.debug('Refreshing pairing offer');
|
|
6466
6475
|
// Cancel any existing offer
|
|
6467
6476
|
await this.sessionManager.cancelPairingOffer();
|
|
6468
6477
|
return this.createPairingOffer(config);
|
|
@@ -6498,7 +6507,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6498
6507
|
* @throws {Error} If no pairing offer was created
|
|
6499
6508
|
*/
|
|
6500
6509
|
async waitForSessionApproval() {
|
|
6501
|
-
logger$
|
|
6510
|
+
logger$8.info('Waiting for wallet to connect and approve session');
|
|
6502
6511
|
this._connectionState.set('pending_approval');
|
|
6503
6512
|
try {
|
|
6504
6513
|
// This blocks until wallet connects via Nostr and user approves
|
|
@@ -6516,7 +6525,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6516
6525
|
return session;
|
|
6517
6526
|
}
|
|
6518
6527
|
catch (error) {
|
|
6519
|
-
logger$
|
|
6528
|
+
logger$8.error('Session approval failed', { error });
|
|
6520
6529
|
this._connectionState.set('error');
|
|
6521
6530
|
throw error;
|
|
6522
6531
|
}
|
|
@@ -6541,10 +6550,10 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6541
6550
|
* @throws {Error} If connection times out (2 minutes)
|
|
6542
6551
|
*/
|
|
6543
6552
|
async connect(config) {
|
|
6544
|
-
logger$
|
|
6553
|
+
logger$8.info('Connect called', { config });
|
|
6545
6554
|
// If already connected, no-op
|
|
6546
6555
|
if (this._status() === 'connected') {
|
|
6547
|
-
logger$
|
|
6556
|
+
logger$8.debug('Already connected');
|
|
6548
6557
|
return;
|
|
6549
6558
|
}
|
|
6550
6559
|
// Create pairing offer and wait for connection
|
|
@@ -6572,7 +6581,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6572
6581
|
* persisted session data. The wallet is notified of the disconnection.
|
|
6573
6582
|
*/
|
|
6574
6583
|
async disconnect() {
|
|
6575
|
-
logger$
|
|
6584
|
+
logger$8.info('Disconnecting');
|
|
6576
6585
|
try {
|
|
6577
6586
|
await this.sessionManager.terminateSession();
|
|
6578
6587
|
}
|
|
@@ -6604,7 +6613,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6604
6613
|
if (this._status() !== 'connected') {
|
|
6605
6614
|
throw new Error('Not connected to wallet');
|
|
6606
6615
|
}
|
|
6607
|
-
logger$
|
|
6616
|
+
logger$8.info('Signing transaction', { account: options.accountAddress });
|
|
6608
6617
|
const result = await this.sessionManager.signTransaction({
|
|
6609
6618
|
accountAddress: options.accountAddress,
|
|
6610
6619
|
payload: options.payload,
|
|
@@ -6635,7 +6644,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6635
6644
|
if (this._status() !== 'connected') {
|
|
6636
6645
|
throw new Error('Not connected to wallet');
|
|
6637
6646
|
}
|
|
6638
|
-
logger$
|
|
6647
|
+
logger$8.info('Submitting transaction', { account: options.accountAddress });
|
|
6639
6648
|
const result = await this.sessionManager.submitTransaction({
|
|
6640
6649
|
accountAddress: options.accountAddress,
|
|
6641
6650
|
payload: options.payload,
|
|
@@ -6687,7 +6696,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6687
6696
|
if (this._status() !== 'connected') {
|
|
6688
6697
|
throw new Error('Not connected to wallet');
|
|
6689
6698
|
}
|
|
6690
|
-
logger$
|
|
6699
|
+
logger$8.info('Signing message', { account: options.accountAddress });
|
|
6691
6700
|
const result = await this.sessionManager.signMessage({
|
|
6692
6701
|
accountAddress: options.accountAddress,
|
|
6693
6702
|
message: options.message,
|
|
@@ -6722,7 +6731,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6722
6731
|
// Connection established — wrap in NgZone to ensure Angular change
|
|
6723
6732
|
// detection picks up signal updates from Nostr/WebSocket callbacks
|
|
6724
6733
|
this.sessionManager.onConnected((session) => {
|
|
6725
|
-
logger$
|
|
6734
|
+
logger$8.info('Session connected', { sessionId: session?.id });
|
|
6726
6735
|
this.ngZone.run(() => {
|
|
6727
6736
|
this._connectionState.set('connected');
|
|
6728
6737
|
this._status.set('connected');
|
|
@@ -6740,7 +6749,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6740
6749
|
});
|
|
6741
6750
|
// Session terminated
|
|
6742
6751
|
this.sessionManager.onDisconnected(() => {
|
|
6743
|
-
logger$
|
|
6752
|
+
logger$8.info('Session disconnected');
|
|
6744
6753
|
this.ngZone.run(() => {
|
|
6745
6754
|
this._connectionState.set('disconnected');
|
|
6746
6755
|
this._status.set('disconnected');
|
|
@@ -6751,7 +6760,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6751
6760
|
});
|
|
6752
6761
|
// Error occurred
|
|
6753
6762
|
this.sessionManager.onError((error) => {
|
|
6754
|
-
logger$
|
|
6763
|
+
logger$8.error('Session error', { error });
|
|
6755
6764
|
this.ngZone.run(() => {
|
|
6756
6765
|
this._connectionState.set('error');
|
|
6757
6766
|
this._status.set('error');
|
|
@@ -6760,7 +6769,7 @@ class P2PNativeProvider extends BaseWalletProvider {
|
|
|
6760
6769
|
});
|
|
6761
6770
|
// Accounts updated
|
|
6762
6771
|
this.sessionManager.onAccountsChanged((accounts) => {
|
|
6763
|
-
logger$
|
|
6772
|
+
logger$8.debug('Accounts updated', { count: accounts.length });
|
|
6764
6773
|
this.ngZone.run(() => {
|
|
6765
6774
|
const accountsWithProvider = this.ensureProviderIdOnAccounts(accounts);
|
|
6766
6775
|
this._accounts.set(accountsWithProvider);
|
|
@@ -6830,7 +6839,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
6830
6839
|
* +-------------------------------------------------------------------+
|
|
6831
6840
|
* ```
|
|
6832
6841
|
*/
|
|
6833
|
-
const logger$
|
|
6842
|
+
const logger$7 = getLogger().scoped?.('UnifiedWalletService') ?? getLogger();
|
|
6834
6843
|
/**
|
|
6835
6844
|
* Central service for managing wallet connections across multiple protocols.
|
|
6836
6845
|
*
|
|
@@ -6968,7 +6977,7 @@ class UnifiedWalletService {
|
|
|
6968
6977
|
return await reconnect.call(provider);
|
|
6969
6978
|
}
|
|
6970
6979
|
catch (error) {
|
|
6971
|
-
logger$
|
|
6980
|
+
logger$7.warn('Provider reconnect failed', { providerId, error });
|
|
6972
6981
|
return false;
|
|
6973
6982
|
}
|
|
6974
6983
|
}
|
|
@@ -7032,7 +7041,7 @@ class UnifiedWalletService {
|
|
|
7032
7041
|
*/
|
|
7033
7042
|
registerProvider(provider) {
|
|
7034
7043
|
if (this.providers.has(provider.id)) {
|
|
7035
|
-
logger$
|
|
7044
|
+
logger$7.warn('Provider already registered', { providerId: provider.id });
|
|
7036
7045
|
return;
|
|
7037
7046
|
}
|
|
7038
7047
|
this.providers.set(provider.id, provider);
|
|
@@ -7487,7 +7496,7 @@ class UnifiedWalletService {
|
|
|
7487
7496
|
switchAccount(accountId) {
|
|
7488
7497
|
const account = this.getAccountById(accountId);
|
|
7489
7498
|
if (!account) {
|
|
7490
|
-
logger$
|
|
7499
|
+
logger$7.warn('Account not found', { accountId });
|
|
7491
7500
|
return false;
|
|
7492
7501
|
}
|
|
7493
7502
|
this.setActiveAccount(account);
|
|
@@ -7542,7 +7551,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
7542
7551
|
* - Keyboard navigation support
|
|
7543
7552
|
* - Toast/alert integration
|
|
7544
7553
|
*/
|
|
7545
|
-
const logger$
|
|
7554
|
+
const logger$6 = getLogger().scoped?.('AccountSelectorService') ?? getLogger();
|
|
7546
7555
|
/**
|
|
7547
7556
|
* @service AccountSelectorService
|
|
7548
7557
|
* Business logic service for account selector component.
|
|
@@ -7631,7 +7640,7 @@ class AccountSelectorService {
|
|
|
7631
7640
|
return null;
|
|
7632
7641
|
}
|
|
7633
7642
|
catch (error) {
|
|
7634
|
-
logger$
|
|
7643
|
+
logger$6.error('Error getting currently connected account', { error });
|
|
7635
7644
|
return null;
|
|
7636
7645
|
}
|
|
7637
7646
|
}, ...(ngDevMode ? [{ debugName: "currentlyConnectedAccount" }] : []));
|
|
@@ -7659,7 +7668,7 @@ class AccountSelectorService {
|
|
|
7659
7668
|
return others;
|
|
7660
7669
|
}
|
|
7661
7670
|
catch (error) {
|
|
7662
|
-
logger$
|
|
7671
|
+
logger$6.error('Error getting other accounts', { error });
|
|
7663
7672
|
return [];
|
|
7664
7673
|
}
|
|
7665
7674
|
}, ...(ngDevMode ? [{ debugName: "otherAccounts" }] : []));
|
|
@@ -7688,10 +7697,10 @@ class AccountSelectorService {
|
|
|
7688
7697
|
// Modal mode: show toast and dismiss
|
|
7689
7698
|
if (mode === 'modal') {
|
|
7690
7699
|
await this.showSuccessToast(`Switched to ${account.label || 'Account'}`);
|
|
7691
|
-
logger$
|
|
7700
|
+
logger$6.info('[Modal] Account changed and modal dismissed', { ...accountData });
|
|
7692
7701
|
}
|
|
7693
7702
|
else {
|
|
7694
|
-
logger$
|
|
7703
|
+
logger$6.info('[Inline] Account changed', { ...accountData });
|
|
7695
7704
|
}
|
|
7696
7705
|
return accountData;
|
|
7697
7706
|
}
|
|
@@ -7743,7 +7752,7 @@ class AccountSelectorService {
|
|
|
7743
7752
|
*/
|
|
7744
7753
|
async disconnectAll(_mode) {
|
|
7745
7754
|
if (!this.alertController) {
|
|
7746
|
-
logger$
|
|
7755
|
+
logger$6.warn('AlertController not available for disconnect confirmation');
|
|
7747
7756
|
return false;
|
|
7748
7757
|
}
|
|
7749
7758
|
return new Promise((resolve) => {
|
|
@@ -7768,7 +7777,7 @@ class AccountSelectorService {
|
|
|
7768
7777
|
await this.wallet.disconnectSession(session.providerId, session.metadata?.sessionKey);
|
|
7769
7778
|
}
|
|
7770
7779
|
catch (error) {
|
|
7771
|
-
logger$
|
|
7780
|
+
logger$6.error('Failed to disconnect session', {
|
|
7772
7781
|
providerId: session.providerId,
|
|
7773
7782
|
error,
|
|
7774
7783
|
});
|
|
@@ -7778,7 +7787,7 @@ class AccountSelectorService {
|
|
|
7778
7787
|
resolve(true);
|
|
7779
7788
|
}
|
|
7780
7789
|
catch (error) {
|
|
7781
|
-
logger$
|
|
7790
|
+
logger$6.error('Failed to disconnect all sessions', { error });
|
|
7782
7791
|
this.error.set('Failed to disconnect all wallets');
|
|
7783
7792
|
resolve(false);
|
|
7784
7793
|
}
|
|
@@ -7863,11 +7872,11 @@ class AccountSelectorService {
|
|
|
7863
7872
|
if (mode === 'modal') {
|
|
7864
7873
|
await this.showSuccessToast('Wallet disconnected successfully');
|
|
7865
7874
|
}
|
|
7866
|
-
logger$
|
|
7875
|
+
logger$6.info('Session disconnected', { providerId, sessionKey, mode });
|
|
7867
7876
|
return true;
|
|
7868
7877
|
}
|
|
7869
7878
|
catch (error) {
|
|
7870
|
-
logger$
|
|
7879
|
+
logger$6.error('Failed to disconnect session', { providerId, error });
|
|
7871
7880
|
if (mode === 'modal') {
|
|
7872
7881
|
await this.showErrorToast('Failed to disconnect wallet. Please try again.');
|
|
7873
7882
|
}
|
|
@@ -9492,7 +9501,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
9492
9501
|
* - HSuite Native + Mobile QR: Network → Protocol → Method → QR Pairing (4 steps)
|
|
9493
9502
|
* - WalletConnect: Network → Protocol → Ledger → Connect (4 steps)
|
|
9494
9503
|
*/
|
|
9495
|
-
const logger$
|
|
9504
|
+
const logger$5 = getLogger().scoped?.('WalletConnectionModal') ?? getLogger();
|
|
9496
9505
|
/**
|
|
9497
9506
|
* Connection step enumeration for the wizard flow
|
|
9498
9507
|
*/
|
|
@@ -10017,7 +10026,7 @@ class WalletConnectionModalComponent {
|
|
|
10017
10026
|
await this.modalController.dismiss({ connected: true });
|
|
10018
10027
|
}
|
|
10019
10028
|
catch (error) {
|
|
10020
|
-
logger$
|
|
10029
|
+
logger$5.error('Connection failed', {
|
|
10021
10030
|
error: error instanceof Error ? error.message : String(error),
|
|
10022
10031
|
});
|
|
10023
10032
|
this.connectionError.set(error instanceof Error ? error.message : 'Connection failed. Please try again.');
|
|
@@ -10062,7 +10071,7 @@ class WalletConnectionModalComponent {
|
|
|
10062
10071
|
this.waitForWalletApproval();
|
|
10063
10072
|
}
|
|
10064
10073
|
catch (error) {
|
|
10065
|
-
logger$
|
|
10074
|
+
logger$5.error('Failed to create pairing offer', { error });
|
|
10066
10075
|
this.connectionError.set(error instanceof Error ? error.message : 'Failed to generate QR code');
|
|
10067
10076
|
this.isGeneratingOffer.set(false);
|
|
10068
10077
|
}
|
|
@@ -10075,7 +10084,7 @@ class WalletConnectionModalComponent {
|
|
|
10075
10084
|
try {
|
|
10076
10085
|
// This blocks until wallet scans QR, connects via Nostr, and user approves
|
|
10077
10086
|
const session = await this.p2pNativeProvider.waitForSessionApproval();
|
|
10078
|
-
logger$
|
|
10087
|
+
logger$5.info('Session approved by wallet', {
|
|
10079
10088
|
sessionId: session?.sessionId,
|
|
10080
10089
|
accounts: session?.accounts?.length,
|
|
10081
10090
|
});
|
|
@@ -10084,7 +10093,7 @@ class WalletConnectionModalComponent {
|
|
|
10084
10093
|
catch (error) {
|
|
10085
10094
|
// Only show error if we're still on the QR pairing step (not cancelled)
|
|
10086
10095
|
if (this.currentStep() === ConnectionStep.QrPairing) {
|
|
10087
|
-
logger$
|
|
10096
|
+
logger$5.error('Session approval failed', { error });
|
|
10088
10097
|
this.connectionError.set(error instanceof Error ? error.message : 'Session approval failed or rejected');
|
|
10089
10098
|
}
|
|
10090
10099
|
this.isWaitingForWallet.set(false);
|
|
@@ -10095,7 +10104,7 @@ class WalletConnectionModalComponent {
|
|
|
10095
10104
|
* Handle QR code expiry
|
|
10096
10105
|
*/
|
|
10097
10106
|
onQrExpired() {
|
|
10098
|
-
logger$
|
|
10107
|
+
logger$5.debug('QR code expired');
|
|
10099
10108
|
this.pairingOffer.set('');
|
|
10100
10109
|
this.isWaitingForWallet.set(false);
|
|
10101
10110
|
}
|
|
@@ -10111,7 +10120,7 @@ class WalletConnectionModalComponent {
|
|
|
10111
10120
|
* Handle successful mobile connection
|
|
10112
10121
|
*/
|
|
10113
10122
|
onMobileConnected() {
|
|
10114
|
-
logger$
|
|
10123
|
+
logger$5.info('Mobile wallet connected');
|
|
10115
10124
|
this.connected.emit({ protocol: 'mobile-native', method: 'qr' });
|
|
10116
10125
|
void this.modalController.dismiss({ connected: true });
|
|
10117
10126
|
}
|
|
@@ -10162,7 +10171,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
10162
10171
|
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
10163
10172
|
* visit https://hsuite.finance/licensing
|
|
10164
10173
|
*/
|
|
10165
|
-
const logger$
|
|
10174
|
+
const logger$4 = getLogger().scoped?.('WalletConnectButton') ?? getLogger();
|
|
10166
10175
|
/**
|
|
10167
10176
|
* @component WalletConnectButtonComponent
|
|
10168
10177
|
* Ready-to-use wallet connection button for dApps with multi-protocol support.
|
|
@@ -10267,7 +10276,7 @@ class WalletConnectButtonComponent {
|
|
|
10267
10276
|
catch (err) {
|
|
10268
10277
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
10269
10278
|
this.error.emit(error);
|
|
10270
|
-
logger$
|
|
10279
|
+
logger$4.error('Connection failed', { error: error.message });
|
|
10271
10280
|
}
|
|
10272
10281
|
finally {
|
|
10273
10282
|
this.isConnecting = false;
|
|
@@ -10313,7 +10322,7 @@ class WalletConnectButtonComponent {
|
|
|
10313
10322
|
catch (err) {
|
|
10314
10323
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
10315
10324
|
this.error.emit(error);
|
|
10316
|
-
logger$
|
|
10325
|
+
logger$4.error('Disconnect failed', { error: error.message });
|
|
10317
10326
|
}
|
|
10318
10327
|
}
|
|
10319
10328
|
/**
|
|
@@ -11708,7 +11717,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
11708
11717
|
* }
|
|
11709
11718
|
* ```
|
|
11710
11719
|
*/
|
|
11711
|
-
const logger$
|
|
11720
|
+
const logger$3 = getLogger().scoped?.('TransactionService') ?? getLogger();
|
|
11712
11721
|
/**
|
|
11713
11722
|
* High-level transaction service with automatic state management.
|
|
11714
11723
|
*
|
|
@@ -11760,7 +11769,7 @@ class TransactionService {
|
|
|
11760
11769
|
async signTransaction(payload) {
|
|
11761
11770
|
return this.executeTransaction(async () => {
|
|
11762
11771
|
const result = (await this.walletService.signTransaction(payload));
|
|
11763
|
-
logger$
|
|
11772
|
+
logger$3.info('Transaction signed', {
|
|
11764
11773
|
hasSignature: !!result.signedTransaction,
|
|
11765
11774
|
});
|
|
11766
11775
|
await this.showSuccessToast('Transaction Signed', 'Your transaction has been signed successfully.');
|
|
@@ -11781,7 +11790,7 @@ class TransactionService {
|
|
|
11781
11790
|
async submitTransaction(payload) {
|
|
11782
11791
|
return this.executeTransaction(async () => {
|
|
11783
11792
|
const result = (await this.walletService.submitTransaction(payload));
|
|
11784
|
-
logger$
|
|
11793
|
+
logger$3.info('Transaction submitted', { transactionId: result.transactionId });
|
|
11785
11794
|
await this.showSuccessToast('Transaction Submitted', `Transaction ID: ${result.transactionId || 'Success'}`);
|
|
11786
11795
|
return result;
|
|
11787
11796
|
});
|
|
@@ -11800,7 +11809,7 @@ class TransactionService {
|
|
|
11800
11809
|
// Use the wallet's signAndExecuteTransaction method directly
|
|
11801
11810
|
// This uses hedera_signAndExecuteTransaction for WalletConnect (one prompt!)
|
|
11802
11811
|
const result = (await this.walletService.signAndExecuteTransaction(payload));
|
|
11803
|
-
logger$
|
|
11812
|
+
logger$3.info('Transaction signed and submitted', { transactionId: result.transactionId });
|
|
11804
11813
|
await this.showSuccessToast('Transaction Complete', `Transaction ID: ${result.transactionId || 'Success'}`);
|
|
11805
11814
|
return result;
|
|
11806
11815
|
});
|
|
@@ -11824,7 +11833,7 @@ class TransactionService {
|
|
|
11824
11833
|
batchKey: options.batchKey,
|
|
11825
11834
|
innerTransactions: options.innerTransactions,
|
|
11826
11835
|
}));
|
|
11827
|
-
logger$
|
|
11836
|
+
logger$3.info('Batch transaction submitted', { transactionId: result.transactionId });
|
|
11828
11837
|
await this.showSuccessToast('Batch Transaction Complete', `Transaction ID: ${result.transactionId || 'Success'}`);
|
|
11829
11838
|
return result;
|
|
11830
11839
|
});
|
|
@@ -11837,8 +11846,8 @@ class TransactionService {
|
|
|
11837
11846
|
*/
|
|
11838
11847
|
async signMessage(message) {
|
|
11839
11848
|
return this.executeTransaction(async () => {
|
|
11840
|
-
const result =
|
|
11841
|
-
logger$
|
|
11849
|
+
const result = await this.walletService.signMessage(message);
|
|
11850
|
+
logger$3.info('Message signed', { hasSignature: !!result.signature });
|
|
11842
11851
|
await this.showSuccessToast('Message Signed', 'Your message has been signed successfully.');
|
|
11843
11852
|
return result;
|
|
11844
11853
|
});
|
|
@@ -11961,6 +11970,378 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
11961
11970
|
args: [{ providedIn: 'root' }]
|
|
11962
11971
|
}] });
|
|
11963
11972
|
|
|
11973
|
+
/**
|
|
11974
|
+
* HSuite Native Connect
|
|
11975
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
11976
|
+
*
|
|
11977
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
11978
|
+
*
|
|
11979
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
11980
|
+
* visit https://hsuite.finance/licensing
|
|
11981
|
+
*/
|
|
11982
|
+
/**
|
|
11983
|
+
* @file Smart-host customer session helper.
|
|
11984
|
+
*
|
|
11985
|
+
* @module services/smart-session
|
|
11986
|
+
*
|
|
11987
|
+
* @description
|
|
11988
|
+
* SmartSessionService automates the smart-host authentication handshake for
|
|
11989
|
+
* HSuite dApps. It discovers the host's `appId`, requests a challenge, signs it
|
|
11990
|
+
* with the active wallet account, and exchanges the signed challenge for a
|
|
11991
|
+
* short-lived bearer token.
|
|
11992
|
+
*
|
|
11993
|
+
* **Typical flow:**
|
|
11994
|
+
* ```typescript
|
|
11995
|
+
* const session = inject(SmartSessionService);
|
|
11996
|
+
* await session.login();
|
|
11997
|
+
* const bearer = session.getBearer();
|
|
11998
|
+
* ```
|
|
11999
|
+
*
|
|
12000
|
+
* The service also exposes {@link withSession} for automatic 401 recovery:
|
|
12001
|
+
* operations that fail with HTTP 401 are retried once after a fresh login.
|
|
12002
|
+
*/
|
|
12003
|
+
const logger$2 = getLogger().scoped?.('SmartSessionService') ?? getLogger();
|
|
12004
|
+
/**
|
|
12005
|
+
* Configuration token for {@link SmartSessionService}.
|
|
12006
|
+
*/
|
|
12007
|
+
const SMART_SESSION_CONFIG = new InjectionToken('SMART_SESSION_CONFIG', {
|
|
12008
|
+
factory: () => ({}),
|
|
12009
|
+
});
|
|
12010
|
+
/**
|
|
12011
|
+
* Smart-host customer session helper.
|
|
12012
|
+
*
|
|
12013
|
+
* @service SmartSessionService
|
|
12014
|
+
*
|
|
12015
|
+
* @description
|
|
12016
|
+
* Encapsulates the full challenge → sign → verify → store JWT flow required by
|
|
12017
|
+
* HSuite smart hosts. The service is intentionally thin: it delegates signing to
|
|
12018
|
+
* {@link TransactionService} and relies on standard Angular `HttpClient` for the
|
|
12019
|
+
* host HTTP calls.
|
|
12020
|
+
*
|
|
12021
|
+
* @providedIn root
|
|
12022
|
+
*/
|
|
12023
|
+
class SmartSessionService {
|
|
12024
|
+
http = inject(HttpClient);
|
|
12025
|
+
walletService = inject(UnifiedWalletService);
|
|
12026
|
+
transactionService = inject(TransactionService);
|
|
12027
|
+
config = inject(SMART_SESSION_CONFIG);
|
|
12028
|
+
get baseUrl() {
|
|
12029
|
+
return this.config.baseUrl ?? '';
|
|
12030
|
+
}
|
|
12031
|
+
get healthEndpoint() {
|
|
12032
|
+
return this.config.healthEndpoint ?? '/api/health';
|
|
12033
|
+
}
|
|
12034
|
+
get challengeEndpoint() {
|
|
12035
|
+
return this.config.challengeEndpoint ?? '/api/auth/challenge';
|
|
12036
|
+
}
|
|
12037
|
+
get verifyEndpoint() {
|
|
12038
|
+
return this.config.verifyEndpoint ?? '/api/auth/verify';
|
|
12039
|
+
}
|
|
12040
|
+
get storageKey() {
|
|
12041
|
+
return this.config.storageKey ?? 'hsuite.smart-session';
|
|
12042
|
+
}
|
|
12043
|
+
/**
|
|
12044
|
+
* Returns the currently stored bearer token, or `null` if there is no session.
|
|
12045
|
+
*
|
|
12046
|
+
* @returns Bearer token string or null
|
|
12047
|
+
*/
|
|
12048
|
+
getBearer() {
|
|
12049
|
+
const stored = this.readStoredSession();
|
|
12050
|
+
return stored && stored.expiresAt > Date.now() ? stored.bearer : null;
|
|
12051
|
+
}
|
|
12052
|
+
/**
|
|
12053
|
+
* Checks whether a non-expired session is available.
|
|
12054
|
+
*
|
|
12055
|
+
* @returns true if logged in and the bearer has not expired
|
|
12056
|
+
*/
|
|
12057
|
+
isLoggedIn() {
|
|
12058
|
+
return this.getBearer() !== null;
|
|
12059
|
+
}
|
|
12060
|
+
/**
|
|
12061
|
+
* Performs the full smart-host login handshake.
|
|
12062
|
+
*
|
|
12063
|
+
* @description
|
|
12064
|
+
* 1. Discovers `appId` from the health endpoint.
|
|
12065
|
+
* 2. Fetches a challenge from the challenge endpoint.
|
|
12066
|
+
* 3. Signs the challenge with the active wallet account.
|
|
12067
|
+
* 4. Exchanges the signed challenge for a bearer token.
|
|
12068
|
+
* 5. Stores the bearer and expiry in `sessionStorage`.
|
|
12069
|
+
*
|
|
12070
|
+
* @returns The verify response from the host
|
|
12071
|
+
*
|
|
12072
|
+
* @throws {Error} If no active account is available
|
|
12073
|
+
* @throws {Error} If the health endpoint does not return an `appId`
|
|
12074
|
+
* @throws {Error} If the challenge endpoint does not return a `challenge`
|
|
12075
|
+
* @throws {Error} If the verify call fails
|
|
12076
|
+
*/
|
|
12077
|
+
async login() {
|
|
12078
|
+
const account = this.walletService.activeAccount();
|
|
12079
|
+
if (!account) {
|
|
12080
|
+
throw new Error('No active account');
|
|
12081
|
+
}
|
|
12082
|
+
logger$2.info('Starting smart-host login handshake', {
|
|
12083
|
+
accountAddress: account.address,
|
|
12084
|
+
});
|
|
12085
|
+
const health = await this.fetchHealth();
|
|
12086
|
+
if (!health.appId) {
|
|
12087
|
+
throw new Error('Smart host health endpoint did not return appId');
|
|
12088
|
+
}
|
|
12089
|
+
const challengeResponse = await this.fetchChallenge(health.appId);
|
|
12090
|
+
if (!challengeResponse.challenge) {
|
|
12091
|
+
throw new Error('Smart host challenge endpoint did not return challenge');
|
|
12092
|
+
}
|
|
12093
|
+
const signResult = await this.transactionService.signMessage(challengeResponse.challenge);
|
|
12094
|
+
const verifyResponse = await this.verifyChallenge(health.appId, account, challengeResponse.challenge, signResult);
|
|
12095
|
+
if (!verifyResponse.bearer) {
|
|
12096
|
+
throw new Error('Smart host verify endpoint did not return bearer');
|
|
12097
|
+
}
|
|
12098
|
+
const expiresAt = this.resolveExpiry(verifyResponse);
|
|
12099
|
+
this.storeSession({ bearer: verifyResponse.bearer, expiresAt });
|
|
12100
|
+
logger$2.info('Smart-host login successful', {
|
|
12101
|
+
appId: health.appId,
|
|
12102
|
+
expiresAt,
|
|
12103
|
+
});
|
|
12104
|
+
return verifyResponse;
|
|
12105
|
+
}
|
|
12106
|
+
/**
|
|
12107
|
+
* Clears the stored session.
|
|
12108
|
+
*/
|
|
12109
|
+
logout() {
|
|
12110
|
+
this.clearStoredSession();
|
|
12111
|
+
logger$2.info('Smart-host session cleared');
|
|
12112
|
+
}
|
|
12113
|
+
/**
|
|
12114
|
+
* Runs an HTTP operation with automatic 401 recovery.
|
|
12115
|
+
*
|
|
12116
|
+
* @description
|
|
12117
|
+
* Executes the provided operation. If it rejects with an HTTP 401 error,
|
|
12118
|
+
* the service clears the current bearer, performs a fresh login, and retries
|
|
12119
|
+
* the operation once. Any other error is propagated immediately.
|
|
12120
|
+
*
|
|
12121
|
+
* @param operation - Async operation that needs a valid session
|
|
12122
|
+
* @returns The result of the operation
|
|
12123
|
+
*
|
|
12124
|
+
* @throws {Error} The original error if retry is not possible or fails
|
|
12125
|
+
*/
|
|
12126
|
+
async withSession(operation) {
|
|
12127
|
+
try {
|
|
12128
|
+
return await operation();
|
|
12129
|
+
}
|
|
12130
|
+
catch (error) {
|
|
12131
|
+
if (this.isUnauthorizedError(error)) {
|
|
12132
|
+
logger$2.warn('Operation received 401; attempting single session refresh');
|
|
12133
|
+
this.logout();
|
|
12134
|
+
await this.login();
|
|
12135
|
+
return await operation();
|
|
12136
|
+
}
|
|
12137
|
+
throw error;
|
|
12138
|
+
}
|
|
12139
|
+
}
|
|
12140
|
+
async fetchHealth() {
|
|
12141
|
+
return firstValueFrom(this.http.get(`${this.baseUrl}${this.healthEndpoint}`));
|
|
12142
|
+
}
|
|
12143
|
+
async fetchChallenge(appId) {
|
|
12144
|
+
return firstValueFrom(this.http.post(`${this.baseUrl}${this.challengeEndpoint}`, { appId }));
|
|
12145
|
+
}
|
|
12146
|
+
async verifyChallenge(appId, account, challenge, signResult) {
|
|
12147
|
+
const payload = {
|
|
12148
|
+
appId,
|
|
12149
|
+
accountAddress: account.address,
|
|
12150
|
+
publicKey: signResult.publicKey ?? account.publicKey,
|
|
12151
|
+
signature: signResult.signature,
|
|
12152
|
+
algorithm: signResult.algorithm,
|
|
12153
|
+
message: challenge,
|
|
12154
|
+
caipChainId: signResult.caipChainId,
|
|
12155
|
+
ledgerId: account.ledgerId,
|
|
12156
|
+
networkId: account.networkId,
|
|
12157
|
+
};
|
|
12158
|
+
return firstValueFrom(this.http.post(`${this.baseUrl}${this.verifyEndpoint}`, payload));
|
|
12159
|
+
}
|
|
12160
|
+
resolveExpiry(response) {
|
|
12161
|
+
if (response.expiresAt) {
|
|
12162
|
+
return response.expiresAt;
|
|
12163
|
+
}
|
|
12164
|
+
if (response.expiresIn) {
|
|
12165
|
+
return Date.now() + response.expiresIn * 1000;
|
|
12166
|
+
}
|
|
12167
|
+
// Default to 5 minutes if no expiry is provided
|
|
12168
|
+
return Date.now() + 5 * 60 * 1000;
|
|
12169
|
+
}
|
|
12170
|
+
readStoredSession() {
|
|
12171
|
+
try {
|
|
12172
|
+
const raw = sessionStorage.getItem(this.storageKey);
|
|
12173
|
+
if (!raw) {
|
|
12174
|
+
return null;
|
|
12175
|
+
}
|
|
12176
|
+
const parsed = JSON.parse(raw);
|
|
12177
|
+
if (!parsed.bearer || typeof parsed.expiresAt !== 'number') {
|
|
12178
|
+
return null;
|
|
12179
|
+
}
|
|
12180
|
+
return parsed;
|
|
12181
|
+
}
|
|
12182
|
+
catch {
|
|
12183
|
+
return null;
|
|
12184
|
+
}
|
|
12185
|
+
}
|
|
12186
|
+
storeSession(session) {
|
|
12187
|
+
try {
|
|
12188
|
+
sessionStorage.setItem(this.storageKey, JSON.stringify(session));
|
|
12189
|
+
}
|
|
12190
|
+
catch (error) {
|
|
12191
|
+
logger$2.warn('Failed to store smart session', { error });
|
|
12192
|
+
}
|
|
12193
|
+
}
|
|
12194
|
+
clearStoredSession() {
|
|
12195
|
+
try {
|
|
12196
|
+
sessionStorage.removeItem(this.storageKey);
|
|
12197
|
+
}
|
|
12198
|
+
catch (error) {
|
|
12199
|
+
logger$2.warn('Failed to clear smart session', { error });
|
|
12200
|
+
}
|
|
12201
|
+
}
|
|
12202
|
+
isUnauthorizedError(error) {
|
|
12203
|
+
if (!error || typeof error !== 'object') {
|
|
12204
|
+
return false;
|
|
12205
|
+
}
|
|
12206
|
+
const status = error.status;
|
|
12207
|
+
if (typeof status === 'number') {
|
|
12208
|
+
return status === 401;
|
|
12209
|
+
}
|
|
12210
|
+
const message = String(error.message ?? '');
|
|
12211
|
+
return /\b401\b|unauthorized/i.test(message);
|
|
12212
|
+
}
|
|
12213
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: SmartSessionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
12214
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: SmartSessionService, providedIn: 'root' });
|
|
12215
|
+
}
|
|
12216
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: SmartSessionService, decorators: [{
|
|
12217
|
+
type: Injectable,
|
|
12218
|
+
args: [{ providedIn: 'root' }]
|
|
12219
|
+
}] });
|
|
12220
|
+
|
|
12221
|
+
/**
|
|
12222
|
+
* HSuite Native Connect
|
|
12223
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
12224
|
+
*
|
|
12225
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
12226
|
+
*
|
|
12227
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
12228
|
+
* visit https://hsuite.finance/licensing
|
|
12229
|
+
*/
|
|
12230
|
+
/**
|
|
12231
|
+
* @file HTTP interceptor that attaches wallet-attributed auth headers.
|
|
12232
|
+
*
|
|
12233
|
+
* @module services/hsuite-auth-interceptor
|
|
12234
|
+
*
|
|
12235
|
+
* @description
|
|
12236
|
+
* `HsuiteAuthInterceptor` automatically adds the active smart-host bearer token
|
|
12237
|
+
* and wallet ledger identifier to outgoing HTTP requests. When a request fails
|
|
12238
|
+
* with HTTP 401, it delegates recovery to {@link SmartSessionService} for a
|
|
12239
|
+
* single re-login and retry.
|
|
12240
|
+
*
|
|
12241
|
+
* **Registration (standalone apps):**
|
|
12242
|
+
* ```typescript
|
|
12243
|
+
* provideHttpClient(withInterceptors([provideHsuiteAuthInterceptor()]))
|
|
12244
|
+
* ```
|
|
12245
|
+
*
|
|
12246
|
+
* **Registration (module-based apps):**
|
|
12247
|
+
* ```typescript
|
|
12248
|
+
* { provide: HTTP_INTERCEPTORS, useClass: HsuiteAuthInterceptor, multi: true }
|
|
12249
|
+
* ```
|
|
12250
|
+
*/
|
|
12251
|
+
/**
|
|
12252
|
+
* Headers injected by the interceptor.
|
|
12253
|
+
*/
|
|
12254
|
+
const HSUITE_AUTH_HEADER = 'Authorization';
|
|
12255
|
+
const HSUITE_LEDGER_HEADER = 'X-Ledger-Id';
|
|
12256
|
+
/**
|
|
12257
|
+
* Functional HTTP interceptor that attaches wallet-attributed auth headers.
|
|
12258
|
+
*
|
|
12259
|
+
* @description
|
|
12260
|
+
* Adds:
|
|
12261
|
+
* - `Authorization: Bearer <token>` when {@link SmartSessionService.getBearer} returns a token
|
|
12262
|
+
* - `X-Ledger-Id: <ledgerId>` when a wallet account is active
|
|
12263
|
+
*
|
|
12264
|
+
* On 401 responses, clears the stale bearer and retries once after re-login.
|
|
12265
|
+
*
|
|
12266
|
+
* @param req - The outgoing HTTP request
|
|
12267
|
+
* @param next - The downstream request handler
|
|
12268
|
+
* @returns Observable of HTTP events
|
|
12269
|
+
*/
|
|
12270
|
+
const hsuiteAuthInterceptor = (req, next) => {
|
|
12271
|
+
const session = inject(SmartSessionService);
|
|
12272
|
+
const wallet = inject(UnifiedWalletService);
|
|
12273
|
+
const authenticated = appendAuthHeaders(req, session, wallet);
|
|
12274
|
+
return next(authenticated).pipe(catchError((error) => {
|
|
12275
|
+
if (error instanceof HttpErrorResponse && error.status === 401) {
|
|
12276
|
+
session.logout();
|
|
12277
|
+
return from(session.login()).pipe(switchMap(() => next(appendAuthHeaders(req, session, wallet))), catchError((loginError) => throwError(() => loginError)));
|
|
12278
|
+
}
|
|
12279
|
+
return throwError(() => error);
|
|
12280
|
+
}));
|
|
12281
|
+
};
|
|
12282
|
+
/**
|
|
12283
|
+
* Class-based HTTP interceptor for module-based Angular apps.
|
|
12284
|
+
*
|
|
12285
|
+
* @description
|
|
12286
|
+
* Provides the same behavior as {@link hsuiteAuthInterceptor} in a class form
|
|
12287
|
+
* suitable for registration via `HTTP_INTERCEPTORS`.
|
|
12288
|
+
*/
|
|
12289
|
+
class HsuiteAuthInterceptor {
|
|
12290
|
+
session = inject(SmartSessionService);
|
|
12291
|
+
wallet = inject(UnifiedWalletService);
|
|
12292
|
+
/**
|
|
12293
|
+
* Intercepts outgoing HTTP requests to attach wallet-attributed auth headers.
|
|
12294
|
+
*
|
|
12295
|
+
* @param req - The outgoing HTTP request
|
|
12296
|
+
* @param next - The downstream request handler
|
|
12297
|
+
* @returns Observable of HTTP events
|
|
12298
|
+
*/
|
|
12299
|
+
intercept(req, next) {
|
|
12300
|
+
const authenticated = appendAuthHeaders(req, this.session, this.wallet);
|
|
12301
|
+
return next.handle(authenticated).pipe(catchError((error) => {
|
|
12302
|
+
if (error instanceof HttpErrorResponse && error.status === 401) {
|
|
12303
|
+
this.session.logout();
|
|
12304
|
+
return from(this.session.login()).pipe(switchMap(() => next.handle(appendAuthHeaders(req, this.session, this.wallet))), catchError((loginError) => throwError(() => loginError)));
|
|
12305
|
+
}
|
|
12306
|
+
return throwError(() => error);
|
|
12307
|
+
}));
|
|
12308
|
+
}
|
|
12309
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: HsuiteAuthInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
12310
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: HsuiteAuthInterceptor, providedIn: 'root' });
|
|
12311
|
+
}
|
|
12312
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: HsuiteAuthInterceptor, decorators: [{
|
|
12313
|
+
type: Injectable,
|
|
12314
|
+
args: [{ providedIn: 'root' }]
|
|
12315
|
+
}] });
|
|
12316
|
+
/**
|
|
12317
|
+
* Helper that clones a request with the active auth headers attached.
|
|
12318
|
+
*
|
|
12319
|
+
* @param req - The outgoing HTTP request
|
|
12320
|
+
* @param session - Smart session service for bearer lookup
|
|
12321
|
+
* @param wallet - Unified wallet service for ledger ID lookup
|
|
12322
|
+
* @returns The request cloned with Authorization and/or X-Ledger-Id headers
|
|
12323
|
+
*/
|
|
12324
|
+
function appendAuthHeaders(req, session, wallet) {
|
|
12325
|
+
const bearer = session.getBearer();
|
|
12326
|
+
const activeAccount = wallet.activeAccount();
|
|
12327
|
+
const ledgerId = activeAccount?.ledgerId;
|
|
12328
|
+
// Avoid mutating requests that already carry an Authorization header
|
|
12329
|
+
if (!bearer && !ledgerId) {
|
|
12330
|
+
return req;
|
|
12331
|
+
}
|
|
12332
|
+
const headers = {};
|
|
12333
|
+
if (bearer && !req.headers.has(HSUITE_AUTH_HEADER)) {
|
|
12334
|
+
headers[HSUITE_AUTH_HEADER] = `Bearer ${bearer}`;
|
|
12335
|
+
}
|
|
12336
|
+
if (ledgerId && !req.headers.has(HSUITE_LEDGER_HEADER)) {
|
|
12337
|
+
headers[HSUITE_LEDGER_HEADER] = ledgerId;
|
|
12338
|
+
}
|
|
12339
|
+
if (Object.keys(headers).length === 0) {
|
|
12340
|
+
return req;
|
|
12341
|
+
}
|
|
12342
|
+
return req.clone({ setHeaders: headers });
|
|
12343
|
+
}
|
|
12344
|
+
|
|
11964
12345
|
/**
|
|
11965
12346
|
* HSuite Native Connect
|
|
11966
12347
|
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
@@ -14901,5 +15282,5 @@ function provideWalletErrorHandler(config) {
|
|
|
14901
15282
|
* Generated bundle index. Do not edit.
|
|
14902
15283
|
*/
|
|
14903
15284
|
|
|
14904
|
-
export { ACTIVE_ACCOUNT_SOURCE, AccountActionsComponent, AccountFilterComponent, AccountFormattingService, AccountGroupingService, AccountListComponent, AccountSelectorComponent, AccountSelectorService, BaseWalletProvider, ChannelClientService, ChromeExtensionTransport, DEFAULT_LEDGER_ICONS, DEFAULT_WALLET_URL, HederaSigner, HederaTransactionBuilderService, HsuiteNativeProvider, HsuiteWalletModule, LEDGER_COLORS, LEDGER_ICON_NAMES, LEDGER_NAMES, LedgerUIRegistry, LoggerService, P2PNativeProvider, P2PSessionManager, SignerFactory, TransactionService, UnifiedWalletService, WalletAccountDisplayComponent, WalletConnectButtonComponent, WalletConnectClientManager, WalletConnectPromptComponent, WalletConnectSessionStore, WalletConnectSigningOrchestrator, WalletConnectV2Provider, WalletConnectedDirective, WalletConnectedGuardComponent, WalletConnectionModalComponent, WalletContextDirective, WalletContextService, WalletErrorHandler, WalletEventBus, WalletEventsDirective, WalletSessionDisplayComponent, WalletTransactionStatusComponent, XrplSigner, XrplTransactionBuilderService, getExtensionVersion, getLedgerColor, getLedgerIcon, getLedgerName, getTokenIcon, isExtensionInstalled, isHsuiteNativeConfig, isWalletConnectV2Config, provideWalletErrorHandler, registerLedgerIcons, scaleHederaAmountToBaseUnits };
|
|
15285
|
+
export { ACTIVE_ACCOUNT_SOURCE, AccountActionsComponent, AccountFilterComponent, AccountFormattingService, AccountGroupingService, AccountListComponent, AccountSelectorComponent, AccountSelectorService, BaseWalletProvider, ChannelClientService, ChromeExtensionTransport, DEFAULT_LEDGER_ICONS, DEFAULT_WALLET_URL, HSUITE_AUTH_HEADER, HSUITE_LEDGER_HEADER, HederaSigner, HederaTransactionBuilderService, HsuiteAuthInterceptor, HsuiteNativeProvider, HsuiteWalletModule, LEDGER_COLORS, LEDGER_ICON_NAMES, LEDGER_NAMES, LedgerUIRegistry, LoggerService, P2PNativeProvider, P2PSessionManager, SMART_SESSION_CONFIG, SignerFactory, SmartSessionService, TransactionService, UnifiedWalletService, WalletAccountDisplayComponent, WalletConnectButtonComponent, WalletConnectClientManager, WalletConnectPromptComponent, WalletConnectSessionStore, WalletConnectSigningOrchestrator, WalletConnectV2Provider, WalletConnectedDirective, WalletConnectedGuardComponent, WalletConnectionModalComponent, WalletContextDirective, WalletContextService, WalletErrorHandler, WalletEventBus, WalletEventsDirective, WalletSessionDisplayComponent, WalletTransactionStatusComponent, XrplSigner, XrplTransactionBuilderService, getExtensionVersion, getLedgerColor, getLedgerIcon, getLedgerName, getTokenIcon, hsuiteAuthInterceptor, isExtensionInstalled, isHsuiteNativeConfig, isWalletConnectV2Config, provideWalletErrorHandler, registerLedgerIcons, scaleHederaAmountToBaseUnits };
|
|
14905
15286
|
//# sourceMappingURL=hsuite-native-connect-angular.mjs.map
|