@hsuite/native-connect-angular 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/USAGE_EXAMPLES.md +476 -0
- package/assets/wallets/extension.svg +7 -0
- package/assets/wallets/hashpack.svg +6 -0
- package/assets/wallets/hsuite.svg +11 -0
- package/assets/wallets/kabila.svg +11 -0
- package/assets/wallets/walletconnect.svg +13 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-summary.json +50 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +476 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +476 -0
- package/coverage/lcov-report/lib/components/account-selector/account-actions/account-actions.component.ts.html +868 -0
- package/coverage/lcov-report/lib/components/account-selector/account-actions/index.html +116 -0
- package/coverage/lcov-report/lib/components/account-selector/account-filter/account-filter.component.ts.html +1288 -0
- package/coverage/lcov-report/lib/components/account-selector/account-filter/index.html +116 -0
- package/coverage/lcov-report/lib/components/account-selector/account-formatting.service.ts.html +685 -0
- package/coverage/lcov-report/lib/components/account-selector/account-grouping.service.ts.html +766 -0
- package/coverage/lcov-report/lib/components/account-selector/account-list/account-list.component.ts.html +1495 -0
- package/coverage/lcov-report/lib/components/account-selector/account-list/index.html +116 -0
- package/coverage/lcov-report/lib/components/account-selector/account-selector.component.ts.html +1495 -0
- package/coverage/lcov-report/lib/components/account-selector/account-selector.service.ts.html +1588 -0
- package/coverage/lcov-report/lib/components/account-selector/index.html +161 -0
- package/coverage/lcov-report/lib/components/wallet-account-display/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-account-display/wallet-account-display.component.ts.html +505 -0
- package/coverage/lcov-report/lib/components/wallet-connect-button/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +805 -0
- package/coverage/lcov-report/lib/components/wallet-connect-prompt/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +409 -0
- package/coverage/lcov-report/lib/components/wallet-connected-guard/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +304 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +436 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +2287 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +2275 -0
- package/coverage/lcov-report/lib/components/wallet-session-display/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-session-display/wallet-session-display.component.ts.html +676 -0
- package/coverage/lcov-report/lib/components/wallet-transaction-status/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +703 -0
- package/coverage/lcov-report/lib/directives/index.html +146 -0
- package/coverage/lcov-report/lib/directives/wallet-connected.directive.ts.html +670 -0
- package/coverage/lcov-report/lib/directives/wallet-context.directive.ts.html +547 -0
- package/coverage/lcov-report/lib/directives/wallet-events.directive.ts.html +781 -0
- package/coverage/lcov-report/lib/hsuite-wallet.module.ts.html +715 -0
- package/coverage/lcov-report/lib/index.html +116 -0
- package/coverage/lcov-report/lib/models/connection-config.model.ts.html +280 -0
- package/coverage/lcov-report/lib/models/index.html +131 -0
- package/coverage/lcov-report/lib/models/provider-types.ts.html +577 -0
- package/coverage/lcov-report/lib/providers/base-wallet-provider.ts.html +1138 -0
- package/coverage/lcov-report/lib/providers/hsuite-native/channel-client.service.ts.html +2671 -0
- package/coverage/lcov-report/lib/providers/hsuite-native/index.html +116 -0
- package/coverage/lcov-report/lib/providers/hsuite-native-provider.ts.html +2347 -0
- package/coverage/lcov-report/lib/providers/index.html +146 -0
- package/coverage/lcov-report/lib/providers/p2p-native/index.html +131 -0
- package/coverage/lcov-report/lib/providers/p2p-native/p2p-native.provider.ts.html +2254 -0
- package/coverage/lcov-report/lib/providers/p2p-native/p2p-session-manager.ts.html +2170 -0
- package/coverage/lcov-report/lib/providers/wallet-error-handler.ts.html +1132 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/index.html +176 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/session-health.ts.html +673 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +1177 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-provider.ts.html +2563 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +904 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +982 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/hedera-signer.ts.html +1915 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/index.html +146 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/signer-factory.ts.html +445 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/xrpl-signer.ts.html +1519 -0
- package/coverage/lcov-report/lib/services/index.html +191 -0
- package/coverage/lcov-report/lib/services/logger.service.ts.html +463 -0
- package/coverage/lcov-report/lib/services/transaction-builders/base-transaction-builder.service.ts.html +1840 -0
- package/coverage/lcov-report/lib/services/transaction-builders/hedera-amount-utils.ts.html +337 -0
- package/coverage/lcov-report/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +3940 -0
- package/coverage/lcov-report/lib/services/transaction-builders/index.html +161 -0
- package/coverage/lcov-report/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +2581 -0
- package/coverage/lcov-report/lib/services/transaction.service.ts.html +1123 -0
- package/coverage/lcov-report/lib/services/unified-wallet.service.ts.html +2641 -0
- package/coverage/lcov-report/lib/services/wallet-context.service.ts.html +637 -0
- package/coverage/lcov-report/lib/services/wallet-event-bus.service.ts.html +643 -0
- package/coverage/lcov-report/lib/services/wallet-providers.service.ts.html +496 -0
- package/coverage/lcov-report/lib/transports/chrome-extension-transport.ts.html +823 -0
- package/coverage/lcov-report/lib/transports/index.html +116 -0
- package/coverage/lcov-report/lib/utils/index.html +116 -0
- package/coverage/lcov-report/lib/utils/ledger-icons.util.ts.html +319 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +19252 -0
- package/coverage/lib/components/account-selector/account-actions/account-actions.component.ts.html +868 -0
- package/coverage/lib/components/account-selector/account-actions/index.html +116 -0
- package/coverage/lib/components/account-selector/account-filter/account-filter.component.ts.html +1288 -0
- package/coverage/lib/components/account-selector/account-filter/index.html +116 -0
- package/coverage/lib/components/account-selector/account-formatting.service.ts.html +685 -0
- package/coverage/lib/components/account-selector/account-grouping.service.ts.html +766 -0
- package/coverage/lib/components/account-selector/account-list/account-list.component.ts.html +1495 -0
- package/coverage/lib/components/account-selector/account-list/index.html +116 -0
- package/coverage/lib/components/account-selector/account-selector.component.ts.html +1495 -0
- package/coverage/lib/components/account-selector/account-selector.service.ts.html +1588 -0
- package/coverage/lib/components/account-selector/index.html +161 -0
- package/coverage/lib/components/wallet-account-display/index.html +116 -0
- package/coverage/lib/components/wallet-account-display/wallet-account-display.component.ts.html +505 -0
- package/coverage/lib/components/wallet-connect-button/index.html +116 -0
- package/coverage/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +805 -0
- package/coverage/lib/components/wallet-connect-prompt/index.html +116 -0
- package/coverage/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +409 -0
- package/coverage/lib/components/wallet-connected-guard/index.html +116 -0
- package/coverage/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +304 -0
- package/coverage/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +436 -0
- package/coverage/lib/components/wallet-connection-modal/connection-method-step/index.html +116 -0
- package/coverage/lib/components/wallet-connection-modal/index.html +116 -0
- package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/index.html +116 -0
- package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +2287 -0
- package/coverage/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +2275 -0
- package/coverage/lib/components/wallet-session-display/index.html +116 -0
- package/coverage/lib/components/wallet-session-display/wallet-session-display.component.ts.html +676 -0
- package/coverage/lib/components/wallet-transaction-status/index.html +116 -0
- package/coverage/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +703 -0
- package/coverage/lib/directives/index.html +146 -0
- package/coverage/lib/directives/wallet-connected.directive.ts.html +670 -0
- package/coverage/lib/directives/wallet-context.directive.ts.html +547 -0
- package/coverage/lib/directives/wallet-events.directive.ts.html +781 -0
- package/coverage/lib/hsuite-wallet.module.ts.html +715 -0
- package/coverage/lib/index.html +116 -0
- package/coverage/lib/models/connection-config.model.ts.html +280 -0
- package/coverage/lib/models/index.html +131 -0
- package/coverage/lib/models/provider-types.ts.html +577 -0
- package/coverage/lib/providers/base-wallet-provider.ts.html +1138 -0
- package/coverage/lib/providers/hsuite-native/channel-client.service.ts.html +2671 -0
- package/coverage/lib/providers/hsuite-native/index.html +116 -0
- package/coverage/lib/providers/hsuite-native-provider.ts.html +2347 -0
- package/coverage/lib/providers/index.html +146 -0
- package/coverage/lib/providers/p2p-native/index.html +131 -0
- package/coverage/lib/providers/p2p-native/p2p-native.provider.ts.html +2254 -0
- package/coverage/lib/providers/p2p-native/p2p-session-manager.ts.html +2170 -0
- package/coverage/lib/providers/wallet-error-handler.ts.html +1132 -0
- package/coverage/lib/providers/walletconnect/core/index.html +176 -0
- package/coverage/lib/providers/walletconnect/core/session-health.ts.html +673 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +1177 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-provider.ts.html +2563 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +904 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +982 -0
- package/coverage/lib/providers/walletconnect/signers/hedera-signer.ts.html +1915 -0
- package/coverage/lib/providers/walletconnect/signers/index.html +146 -0
- package/coverage/lib/providers/walletconnect/signers/signer-factory.ts.html +445 -0
- package/coverage/lib/providers/walletconnect/signers/xrpl-signer.ts.html +1519 -0
- package/coverage/lib/services/index.html +191 -0
- package/coverage/lib/services/logger.service.ts.html +463 -0
- package/coverage/lib/services/transaction-builders/base-transaction-builder.service.ts.html +1840 -0
- package/coverage/lib/services/transaction-builders/hedera-amount-utils.ts.html +337 -0
- package/coverage/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +3940 -0
- package/coverage/lib/services/transaction-builders/index.html +161 -0
- package/coverage/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +2581 -0
- package/coverage/lib/services/transaction.service.ts.html +1123 -0
- package/coverage/lib/services/unified-wallet.service.ts.html +2641 -0
- package/coverage/lib/services/wallet-context.service.ts.html +637 -0
- package/coverage/lib/services/wallet-event-bus.service.ts.html +643 -0
- package/coverage/lib/services/wallet-providers.service.ts.html +496 -0
- package/coverage/lib/transports/chrome-extension-transport.ts.html +823 -0
- package/coverage/lib/transports/index.html +116 -0
- package/coverage/lib/utils/index.html +116 -0
- package/coverage/lib/utils/ledger-icons.util.ts.html +319 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/README.md +48 -0
- package/dist/fesm2022/hsuite-native-connect-angular.mjs +14592 -0
- package/dist/fesm2022/hsuite-native-connect-angular.mjs.map +1 -0
- package/dist/index.d.ts +6949 -0
- package/examples/minimal-connect.ts +178 -0
- package/examples/multi-protocol.ts +495 -0
- package/examples/transaction-signing.ts +361 -0
- package/jest.config.json +45 -0
- package/karma.conf.js +42 -0
- package/ng-package.json +20 -0
- package/package.json +60 -0
- package/src/index.ts +203 -0
- package/src/lib/components/account-selector/account-actions/account-actions.component.ts +261 -0
- package/src/lib/components/account-selector/account-filter/account-filter.component.ts +401 -0
- package/src/lib/components/account-selector/account-formatting.service.ts +200 -0
- package/src/lib/components/account-selector/account-grouping.service.ts +227 -0
- package/src/lib/components/account-selector/account-list/account-list.component.ts +470 -0
- package/src/lib/components/account-selector/account-selector.component.html +135 -0
- package/src/lib/components/account-selector/account-selector.component.scss +2039 -0
- package/src/lib/components/account-selector/account-selector.component.ts +470 -0
- package/src/lib/components/account-selector/account-selector.service.ts +501 -0
- package/src/lib/components/wallet-account-display/wallet-account-display.component.html +34 -0
- package/src/lib/components/wallet-account-display/wallet-account-display.component.scss +99 -0
- package/src/lib/components/wallet-account-display/wallet-account-display.component.ts +140 -0
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.html +14 -0
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.scss +272 -0
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.ts +240 -0
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.html +24 -0
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.scss +50 -0
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts +108 -0
- package/src/lib/components/wallet-connected-guard/wallet-connected-guard.component.html +24 -0
- package/src/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts +73 -0
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.html +56 -0
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.scss +218 -0
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts +117 -0
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.html +94 -0
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.scss +272 -0
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts +734 -0
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.html +197 -0
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.scss +678 -0
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts +730 -0
- package/src/lib/components/wallet-session-display/wallet-session-display.component.html +110 -0
- package/src/lib/components/wallet-session-display/wallet-session-display.component.scss +179 -0
- package/src/lib/components/wallet-session-display/wallet-session-display.component.ts +197 -0
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.html +65 -0
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.scss +254 -0
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts +206 -0
- package/src/lib/directives/wallet-connected.directive.ts +195 -0
- package/src/lib/directives/wallet-context.directive.ts +154 -0
- package/src/lib/directives/wallet-events.directive.ts +232 -0
- package/src/lib/hsuite-wallet.module.ts +210 -0
- package/src/lib/models/connection-config.model.ts +65 -0
- package/src/lib/models/provider-types.ts +164 -0
- package/src/lib/models/unified-account.model.ts +76 -0
- package/src/lib/models/wallet-context.model.ts +121 -0
- package/src/lib/models/wallet-events.model.ts +158 -0
- package/src/lib/providers/base-wallet-provider.ts +351 -0
- package/src/lib/providers/hsuite-native/channel-client.service.spec.ts +73 -0
- package/src/lib/providers/hsuite-native/channel-client.service.ts +862 -0
- package/src/lib/providers/hsuite-native/index.ts +8 -0
- package/src/lib/providers/hsuite-native-provider.ts +754 -0
- package/src/lib/providers/mobile-native/mobile-native.provider.spec.ts +19 -0
- package/src/lib/providers/p2p-native/index.ts +30 -0
- package/src/lib/providers/p2p-native/p2p-native.provider.spec.ts +523 -0
- package/src/lib/providers/p2p-native/p2p-native.provider.ts +723 -0
- package/src/lib/providers/p2p-native/p2p-session-manager.ts +695 -0
- package/src/lib/providers/wallet-error-handler.ts +349 -0
- package/src/lib/providers/walletconnect/core/base-signer.interface.ts +122 -0
- package/src/lib/providers/walletconnect/core/session-health.ts +196 -0
- package/src/lib/providers/walletconnect/core/walletconnect-client-manager.ts +364 -0
- package/src/lib/providers/walletconnect/core/walletconnect-provider.integration.spec.ts +348 -0
- package/src/lib/providers/walletconnect/core/walletconnect-provider.ts +826 -0
- package/src/lib/providers/walletconnect/core/walletconnect-session-store.ts +273 -0
- package/src/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts +299 -0
- package/src/lib/providers/walletconnect/core/walletconnect-types.ts +48 -0
- package/src/lib/providers/walletconnect/index.ts +33 -0
- package/src/lib/providers/walletconnect/signers/hedera-signer.spec.ts +367 -0
- package/src/lib/providers/walletconnect/signers/hedera-signer.ts +610 -0
- package/src/lib/providers/walletconnect/signers/signer-factory.spec.ts +62 -0
- package/src/lib/providers/walletconnect/signers/signer-factory.ts +120 -0
- package/src/lib/providers/walletconnect/signers/xrpl-signer.spec.ts +296 -0
- package/src/lib/providers/walletconnect/signers/xrpl-signer.ts +478 -0
- package/src/lib/services/logger.service.ts +126 -0
- package/src/lib/services/transaction-builders/base-transaction-builder.service.ts +585 -0
- package/src/lib/services/transaction-builders/hedera-amount-utils.ts +84 -0
- package/src/lib/services/transaction-builders/hedera-transaction-builder.service.spec.ts +741 -0
- package/src/lib/services/transaction-builders/hedera-transaction-builder.service.ts +1285 -0
- package/src/lib/services/transaction-builders/index.ts +54 -0
- package/src/lib/services/transaction-builders/xrpl-transaction-builder.service.spec.ts +937 -0
- package/src/lib/services/transaction-builders/xrpl-transaction-builder.service.ts +832 -0
- package/src/lib/services/transaction.service.ts +346 -0
- package/src/lib/services/unified-wallet.service.spec.ts +1382 -0
- package/src/lib/services/unified-wallet.service.ts +852 -0
- package/src/lib/services/wallet-context.service.ts +184 -0
- package/src/lib/services/wallet-event-bus.service.ts +186 -0
- package/src/lib/services/wallet-providers.service.ts +137 -0
- package/src/lib/transports/chrome-extension-transport.ts +246 -0
- package/src/lib/utils/index.ts +14 -0
- package/src/lib/utils/ledger-icons.util.ts +78 -0
- package/test/test-setup.ts +21 -0
- package/test-setup.ts +63 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +29 -0
- package/tsconfig.spec.json +15 -0
- package/vitest.config.ts +48 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HSuite Native Connect
|
|
3
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
6
|
+
*
|
|
7
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
8
|
+
* visit https://hsuite.finance/licensing
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file walletconnect-session-store.ts
|
|
13
|
+
* @description Session storage and management for WalletConnect provider
|
|
14
|
+
*
|
|
15
|
+
* Extracted from WalletConnectV2Provider to reduce file size and improve maintainability.
|
|
16
|
+
*
|
|
17
|
+
* Responsibilities:
|
|
18
|
+
* - Store and retrieve WalletConnect sessions
|
|
19
|
+
* - Generate unique session keys
|
|
20
|
+
* - Aggregate accounts across sessions
|
|
21
|
+
* - Find sessions by account address
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { signal } from '@angular/core';
|
|
25
|
+
import { getLogger } from '@hsuite/native-connect-sdk';
|
|
26
|
+
|
|
27
|
+
import type { UnifiedAccount } from '../../../models/unified-account.model';
|
|
28
|
+
|
|
29
|
+
import type { IWalletConnectSigner } from './base-signer.interface';
|
|
30
|
+
|
|
31
|
+
const logger = getLogger().scoped?.('WCSessionStore') ?? getLogger();
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Session data structure stored in the session store.
|
|
35
|
+
*/
|
|
36
|
+
export interface StoredSessionData {
|
|
37
|
+
/** Raw WalletConnect session object */
|
|
38
|
+
session: any;
|
|
39
|
+
/** Ledger identifier (hedera, xrpl) */
|
|
40
|
+
ledgerId: string;
|
|
41
|
+
/** Network identifier (hedera:testnet, xrpl:mainnet) */
|
|
42
|
+
networkId: string;
|
|
43
|
+
/**
|
|
44
|
+
* User's selected network from the connection modal.
|
|
45
|
+
* This is critical for respecting user intent - wallets may return accounts
|
|
46
|
+
* from multiple networks, but we should use the network the user selected.
|
|
47
|
+
*
|
|
48
|
+
* This value is set when connecting and persisted for session restoration.
|
|
49
|
+
* It takes precedence over the wallet-reported networkId for signing operations.
|
|
50
|
+
*/
|
|
51
|
+
userSelectedNetwork: string;
|
|
52
|
+
/** Signer instance for this ledger */
|
|
53
|
+
signer: IWalletConnectSigner;
|
|
54
|
+
/** Unified accounts parsed from session */
|
|
55
|
+
accounts: UnifiedAccount[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* WalletConnect Session Store
|
|
60
|
+
*
|
|
61
|
+
* Manages the in-memory storage of WalletConnect sessions.
|
|
62
|
+
* Provides utility methods for session lookup and aggregation.
|
|
63
|
+
*/
|
|
64
|
+
export class WalletConnectSessionStore {
|
|
65
|
+
/**
|
|
66
|
+
* Map of session key to session data.
|
|
67
|
+
* Session key format: wc-{ledger}-{network}-{topicPrefix}
|
|
68
|
+
*/
|
|
69
|
+
private readonly sessions = new Map<string, StoredSessionData>();
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Aggregated accounts signal for reactive UI binding.
|
|
73
|
+
*/
|
|
74
|
+
private readonly _accounts = signal<UnifiedAccount[]>([]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Read-only accounts signal.
|
|
78
|
+
*/
|
|
79
|
+
readonly accounts = this._accounts.asReadonly();
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get a session by key.
|
|
83
|
+
*
|
|
84
|
+
* @param sessionKey - Unique session key
|
|
85
|
+
* @returns Session data or undefined
|
|
86
|
+
*/
|
|
87
|
+
getSession(sessionKey: string): StoredSessionData | undefined {
|
|
88
|
+
return this.sessions.get(sessionKey);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Store a session.
|
|
93
|
+
*
|
|
94
|
+
* @param sessionKey - Unique session key
|
|
95
|
+
* @param data - Session data to store
|
|
96
|
+
*/
|
|
97
|
+
setSession(sessionKey: string, data: StoredSessionData): void {
|
|
98
|
+
this.sessions.set(sessionKey, data);
|
|
99
|
+
logger.debug('Session stored', { sessionKey, accountCount: data.accounts.length });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Delete a session by key.
|
|
104
|
+
*
|
|
105
|
+
* @param sessionKey - Session key to delete
|
|
106
|
+
* @returns true if session was deleted
|
|
107
|
+
*/
|
|
108
|
+
deleteSession(sessionKey: string): boolean {
|
|
109
|
+
const deleted = this.sessions.delete(sessionKey);
|
|
110
|
+
if (deleted) {
|
|
111
|
+
logger.debug('Session deleted', { sessionKey });
|
|
112
|
+
}
|
|
113
|
+
return deleted;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if a session exists.
|
|
118
|
+
*
|
|
119
|
+
* @param sessionKey - Session key to check
|
|
120
|
+
*/
|
|
121
|
+
hasSession(sessionKey: string): boolean {
|
|
122
|
+
return this.sessions.has(sessionKey);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the number of stored sessions.
|
|
127
|
+
*/
|
|
128
|
+
get size(): number {
|
|
129
|
+
return this.sessions.size;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Clear all sessions.
|
|
134
|
+
*/
|
|
135
|
+
clear(): void {
|
|
136
|
+
this.sessions.clear();
|
|
137
|
+
this._accounts.set([]);
|
|
138
|
+
logger.debug('All sessions cleared');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get all session entries.
|
|
143
|
+
*
|
|
144
|
+
* @returns Iterator of [sessionKey, sessionData] pairs
|
|
145
|
+
*/
|
|
146
|
+
entries(): IterableIterator<[string, StoredSessionData]> {
|
|
147
|
+
return this.sessions.entries();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get all session values.
|
|
152
|
+
*
|
|
153
|
+
* @returns Iterator of session data
|
|
154
|
+
*/
|
|
155
|
+
values(): IterableIterator<StoredSessionData> {
|
|
156
|
+
return this.sessions.values();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Generate a unique session key for tracking multiple sessions.
|
|
161
|
+
* Format: wc-{ledger}-{network}-{topicPrefix}
|
|
162
|
+
*
|
|
163
|
+
* @param ledgerId - Ledger identifier (hedera, xrpl)
|
|
164
|
+
* @param networkId - Network identifier (hedera:testnet, xrpl:mainnet)
|
|
165
|
+
* @param topic - WalletConnect session topic (optional)
|
|
166
|
+
* @returns Unique session key
|
|
167
|
+
*/
|
|
168
|
+
generateSessionKey(ledgerId: string, networkId: string, topic?: string): string {
|
|
169
|
+
const topicPrefix = topic ? topic.substring(0, 8) : Date.now().toString();
|
|
170
|
+
const networkPart = networkId.split(':')[1] || 'unknown';
|
|
171
|
+
return `wc-${ledgerId}-${networkPart}-${topicPrefix}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Update the aggregated accounts signal from all sessions.
|
|
176
|
+
* Call this after session changes to keep accounts in sync.
|
|
177
|
+
*/
|
|
178
|
+
updateAggregatedAccounts(): void {
|
|
179
|
+
const allAccounts: UnifiedAccount[] = [];
|
|
180
|
+
|
|
181
|
+
for (const sessionData of this.sessions.values()) {
|
|
182
|
+
allAccounts.push(...sessionData.accounts);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
logger.debug('Aggregated accounts', {
|
|
186
|
+
sessionCount: this.sessions.size,
|
|
187
|
+
totalAccounts: allAccounts.length,
|
|
188
|
+
});
|
|
189
|
+
this._accounts.set(allAccounts);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Find the session containing a specific account address.
|
|
194
|
+
*
|
|
195
|
+
* @param accountAddress - Account address to find
|
|
196
|
+
* @returns Session, signer, and network info, or undefined if not found
|
|
197
|
+
*/
|
|
198
|
+
findSessionByAccount(accountAddress: string):
|
|
199
|
+
| {
|
|
200
|
+
session: any;
|
|
201
|
+
signer: IWalletConnectSigner;
|
|
202
|
+
networkId: string;
|
|
203
|
+
userSelectedNetwork: string;
|
|
204
|
+
}
|
|
205
|
+
| undefined {
|
|
206
|
+
for (const sessionData of this.sessions.values()) {
|
|
207
|
+
const accountExists = sessionData.accounts.some((acc) => acc.address === accountAddress);
|
|
208
|
+
if (accountExists) {
|
|
209
|
+
return {
|
|
210
|
+
session: sessionData.session,
|
|
211
|
+
signer: sessionData.signer,
|
|
212
|
+
networkId: sessionData.networkId,
|
|
213
|
+
userSelectedNetwork: sessionData.userSelectedNetwork,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Find and remove a session by its WalletConnect topic.
|
|
222
|
+
*
|
|
223
|
+
* @param topic - WalletConnect session topic
|
|
224
|
+
* @returns Removed session data, or undefined if not found
|
|
225
|
+
*/
|
|
226
|
+
removeSessionByTopic(topic: string): { sessionKey: string; data: StoredSessionData } | undefined {
|
|
227
|
+
for (const [sessionKey, sessionData] of this.sessions.entries()) {
|
|
228
|
+
if (sessionData.session.topic === topic) {
|
|
229
|
+
this.sessions.delete(sessionKey);
|
|
230
|
+
logger.info('Session removed by topic', { sessionKey, topic: topic.substring(0, 16) });
|
|
231
|
+
return { sessionKey, data: sessionData };
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get all active sessions as an array.
|
|
239
|
+
* Useful for UI display.
|
|
240
|
+
*
|
|
241
|
+
* @returns Array of session information
|
|
242
|
+
*/
|
|
243
|
+
getActiveSessions(): Array<{
|
|
244
|
+
sessionKey: string;
|
|
245
|
+
ledgerId: string;
|
|
246
|
+
networkId: string;
|
|
247
|
+
userSelectedNetwork: string;
|
|
248
|
+
accounts: UnifiedAccount[];
|
|
249
|
+
topic: string;
|
|
250
|
+
}> {
|
|
251
|
+
const sessions: Array<{
|
|
252
|
+
sessionKey: string;
|
|
253
|
+
ledgerId: string;
|
|
254
|
+
networkId: string;
|
|
255
|
+
userSelectedNetwork: string;
|
|
256
|
+
accounts: UnifiedAccount[];
|
|
257
|
+
topic: string;
|
|
258
|
+
}> = [];
|
|
259
|
+
|
|
260
|
+
for (const [sessionKey, sessionData] of this.sessions.entries()) {
|
|
261
|
+
sessions.push({
|
|
262
|
+
sessionKey,
|
|
263
|
+
ledgerId: sessionData.ledgerId,
|
|
264
|
+
networkId: sessionData.networkId,
|
|
265
|
+
userSelectedNetwork: sessionData.userSelectedNetwork,
|
|
266
|
+
accounts: sessionData.accounts,
|
|
267
|
+
topic: sessionData.session.topic,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return sessions;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HSuite Native Connect
|
|
3
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
6
|
+
*
|
|
7
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
8
|
+
* visit https://hsuite.finance/licensing
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file walletconnect-signing-orchestrator.ts
|
|
13
|
+
* @description Signing orchestration for WalletConnect provider
|
|
14
|
+
*
|
|
15
|
+
* Handles:
|
|
16
|
+
* - Finding sessions for accounts
|
|
17
|
+
* - Session validation in WC SDK
|
|
18
|
+
* - Routing sign/submit requests to appropriate signers
|
|
19
|
+
*
|
|
20
|
+
* Extracted from WalletConnectV2Provider to reduce file size.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { getLogger } from '@hsuite/native-connect-sdk';
|
|
24
|
+
|
|
25
|
+
import type { WalletEventBus } from '../../../services/wallet-event-bus.service';
|
|
26
|
+
import type {
|
|
27
|
+
SignTransactionOptions,
|
|
28
|
+
SubmitTransactionOptions,
|
|
29
|
+
SignResult,
|
|
30
|
+
SubmitResult,
|
|
31
|
+
SignMessageOptions,
|
|
32
|
+
SignMessageResult,
|
|
33
|
+
} from '../../base-wallet-provider';
|
|
34
|
+
|
|
35
|
+
import type { WalletConnectClientManager } from './walletconnect-client-manager';
|
|
36
|
+
import type { WalletConnectSessionStore } from './walletconnect-session-store';
|
|
37
|
+
|
|
38
|
+
const logger = getLogger().scoped?.('WCSigningOrchestrator') ?? getLogger();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Signing orchestration configuration
|
|
42
|
+
*/
|
|
43
|
+
export interface SigningOrchestratorConfig {
|
|
44
|
+
providerId: string;
|
|
45
|
+
sessionStore: WalletConnectSessionStore;
|
|
46
|
+
clientManager: WalletConnectClientManager;
|
|
47
|
+
eventBus: WalletEventBus;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Signing Orchestrator
|
|
52
|
+
*
|
|
53
|
+
* Routes signing requests to the appropriate session and signer.
|
|
54
|
+
* Handles session validation and error emission.
|
|
55
|
+
*/
|
|
56
|
+
export class WalletConnectSigningOrchestrator {
|
|
57
|
+
private readonly providerId: string;
|
|
58
|
+
private readonly sessionStore: WalletConnectSessionStore;
|
|
59
|
+
private readonly clientManager: WalletConnectClientManager;
|
|
60
|
+
private readonly eventBus: WalletEventBus;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param config
|
|
65
|
+
*/
|
|
66
|
+
constructor(config: SigningOrchestratorConfig) {
|
|
67
|
+
this.providerId = config.providerId;
|
|
68
|
+
this.sessionStore = config.sessionStore;
|
|
69
|
+
this.clientManager = config.clientManager;
|
|
70
|
+
this.eventBus = config.eventBus;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Sign a transaction without submitting.
|
|
75
|
+
* Uses the user's selected network from the session for the signing request.
|
|
76
|
+
* @param options
|
|
77
|
+
*/
|
|
78
|
+
async signTransaction(options: SignTransactionOptions): Promise<SignResult> {
|
|
79
|
+
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'signTransaction');
|
|
80
|
+
|
|
81
|
+
// Use user's selected network from session, with fallback to options.networkId
|
|
82
|
+
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
83
|
+
|
|
84
|
+
logger.debug('Routing sign to signer', {
|
|
85
|
+
ledgerId: sessionInfo.signer.ledgerId,
|
|
86
|
+
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
87
|
+
networkId,
|
|
88
|
+
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return sessionInfo.signer.signTransaction({
|
|
92
|
+
client: this.clientManager.getClient(),
|
|
93
|
+
topic: sessionInfo.session.topic,
|
|
94
|
+
accountAddress: options.accountAddress,
|
|
95
|
+
payload: options.payload,
|
|
96
|
+
networkId,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Sign and submit a transaction.
|
|
102
|
+
* Uses the user's selected network from the session for the signing request.
|
|
103
|
+
* @param options
|
|
104
|
+
*/
|
|
105
|
+
async submitTransaction(options: SubmitTransactionOptions): Promise<SubmitResult> {
|
|
106
|
+
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'submitTransaction');
|
|
107
|
+
|
|
108
|
+
// Use user's selected network from session, with fallback to options.networkId
|
|
109
|
+
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
110
|
+
|
|
111
|
+
logger.debug('Routing submit to signer', {
|
|
112
|
+
ledgerId: sessionInfo.signer.ledgerId,
|
|
113
|
+
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
114
|
+
networkId,
|
|
115
|
+
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return sessionInfo.signer.submitTransaction({
|
|
119
|
+
client: this.clientManager.getClient(),
|
|
120
|
+
topic: sessionInfo.session.topic,
|
|
121
|
+
accountAddress: options.accountAddress,
|
|
122
|
+
payload: options.payload,
|
|
123
|
+
networkId,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sign and execute a transaction (single wallet prompt).
|
|
129
|
+
* Uses the user's selected network from the session for the signing request.
|
|
130
|
+
* @param options
|
|
131
|
+
*/
|
|
132
|
+
async signAndExecuteTransaction(options: SubmitTransactionOptions): Promise<SubmitResult> {
|
|
133
|
+
const sessionInfo = this.findAndValidateSession(
|
|
134
|
+
options.accountAddress,
|
|
135
|
+
'signAndExecuteTransaction',
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// Use user's selected network from session, with fallback to options.networkId
|
|
139
|
+
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
140
|
+
|
|
141
|
+
logger.debug('Routing signAndExecute to signer', {
|
|
142
|
+
ledgerId: sessionInfo.signer.ledgerId,
|
|
143
|
+
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
144
|
+
networkId,
|
|
145
|
+
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Check if signer supports native signAndExecute
|
|
149
|
+
if (typeof sessionInfo.signer.signAndExecuteTransaction === 'function') {
|
|
150
|
+
return sessionInfo.signer.signAndExecuteTransaction({
|
|
151
|
+
client: this.clientManager.getClient(),
|
|
152
|
+
topic: sessionInfo.session.topic,
|
|
153
|
+
accountAddress: options.accountAddress,
|
|
154
|
+
payload: options.payload,
|
|
155
|
+
networkId,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Fallback: sign then submit
|
|
160
|
+
const signResult = await sessionInfo.signer.signTransaction({
|
|
161
|
+
client: this.clientManager.getClient(),
|
|
162
|
+
topic: sessionInfo.session.topic,
|
|
163
|
+
accountAddress: options.accountAddress,
|
|
164
|
+
payload: options.payload,
|
|
165
|
+
networkId,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return sessionInfo.signer.submitTransaction({
|
|
169
|
+
client: this.clientManager.getClient(),
|
|
170
|
+
topic: sessionInfo.session.topic,
|
|
171
|
+
accountAddress: options.accountAddress,
|
|
172
|
+
payload: signResult.signedPayload || options.payload,
|
|
173
|
+
networkId,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Sign a message.
|
|
179
|
+
* Uses the user's selected network from the session for the signing request.
|
|
180
|
+
* @param options
|
|
181
|
+
*/
|
|
182
|
+
async signMessage(options: SignMessageOptions): Promise<SignMessageResult> {
|
|
183
|
+
const sessionInfo = this.findAndValidateSession(options.accountAddress, 'signMessage');
|
|
184
|
+
|
|
185
|
+
// Use user's selected network from session, with fallback to options.networkId
|
|
186
|
+
const networkId = this.resolveNetworkId(sessionInfo, options.networkId);
|
|
187
|
+
|
|
188
|
+
logger.debug('Routing signMessage to signer', {
|
|
189
|
+
ledgerId: sessionInfo.signer.ledgerId,
|
|
190
|
+
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
191
|
+
networkId,
|
|
192
|
+
userSelectedNetwork: sessionInfo.userSelectedNetwork,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return sessionInfo.signer.signMessage({
|
|
196
|
+
client: this.clientManager.getClient(),
|
|
197
|
+
topic: sessionInfo.session.topic,
|
|
198
|
+
accountAddress: options.accountAddress,
|
|
199
|
+
payload: '',
|
|
200
|
+
networkId,
|
|
201
|
+
message: options.message,
|
|
202
|
+
encoding: options.encoding,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Resolve the network ID to use for signing.
|
|
208
|
+
*
|
|
209
|
+
* Priority:
|
|
210
|
+
* 1. User's selected network from session (userSelectedNetwork)
|
|
211
|
+
* 2. Session's networkId
|
|
212
|
+
* 3. options.networkId from the caller
|
|
213
|
+
* 4. Empty string (let signer handle default)
|
|
214
|
+
*
|
|
215
|
+
* This ensures we always use the network the user selected when connecting,
|
|
216
|
+
* regardless of what the caller passes in.
|
|
217
|
+
*
|
|
218
|
+
* @param sessionInfo - Session info containing network selections
|
|
219
|
+
* @param sessionInfo.userSelectedNetwork
|
|
220
|
+
* @param optionsNetworkId - Network ID from caller options
|
|
221
|
+
* @param sessionInfo.networkId
|
|
222
|
+
* @returns Resolved network ID to use
|
|
223
|
+
*/
|
|
224
|
+
private resolveNetworkId(
|
|
225
|
+
sessionInfo: { userSelectedNetwork: string; networkId: string },
|
|
226
|
+
optionsNetworkId?: string,
|
|
227
|
+
): string {
|
|
228
|
+
// Prefer user's selected network, then session network, then options
|
|
229
|
+
const resolvedNetwork =
|
|
230
|
+
sessionInfo.userSelectedNetwork || sessionInfo.networkId || optionsNetworkId || '';
|
|
231
|
+
|
|
232
|
+
// Log if there's a mismatch between options and session network
|
|
233
|
+
if (
|
|
234
|
+
optionsNetworkId &&
|
|
235
|
+
sessionInfo.userSelectedNetwork &&
|
|
236
|
+
optionsNetworkId !== sessionInfo.userSelectedNetwork
|
|
237
|
+
) {
|
|
238
|
+
logger.warn('Network mismatch: using session network over caller-provided network', {
|
|
239
|
+
callerNetwork: optionsNetworkId,
|
|
240
|
+
sessionNetwork: sessionInfo.userSelectedNetwork,
|
|
241
|
+
using: resolvedNetwork,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return resolvedNetwork;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Find session for account and validate it exists in SDK.
|
|
250
|
+
* @param accountAddress
|
|
251
|
+
* @param context
|
|
252
|
+
*/
|
|
253
|
+
private findAndValidateSession(accountAddress: string, context: string) {
|
|
254
|
+
const sessionInfo = this.sessionStore.findSessionByAccount(accountAddress);
|
|
255
|
+
if (!sessionInfo) {
|
|
256
|
+
throw new Error(`No WalletConnect session found for account: ${accountAddress}`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Validate session exists in WC SDK
|
|
260
|
+
if (!this.validateSessionInSdk(sessionInfo.session.topic)) {
|
|
261
|
+
logger.error('Session not found in WC SDK', {
|
|
262
|
+
topic: sessionInfo.session.topic.substring(0, 16) + '...',
|
|
263
|
+
account: accountAddress,
|
|
264
|
+
});
|
|
265
|
+
this.eventBus.providerError.emit({
|
|
266
|
+
providerId: this.providerId,
|
|
267
|
+
error: new Error('WalletConnect session expired or disconnected. Please reconnect.'),
|
|
268
|
+
context,
|
|
269
|
+
timestamp: Date.now(),
|
|
270
|
+
});
|
|
271
|
+
throw new Error(
|
|
272
|
+
'WalletConnect session expired or disconnected. Please reconnect your wallet.',
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return sessionInfo;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Validate session exists in WC SDK storage.
|
|
281
|
+
* @param topic
|
|
282
|
+
*/
|
|
283
|
+
private validateSessionInSdk(topic: string): boolean {
|
|
284
|
+
if (!this.clientManager.isInitialized()) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const session = this.clientManager.getSession(topic);
|
|
290
|
+
return !!session;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
logger.warn('Session validation failed', {
|
|
293
|
+
topic: topic.substring(0, 16) + '...',
|
|
294
|
+
error: error instanceof Error ? error.message : String(error),
|
|
295
|
+
});
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HSuite Native Connect
|
|
3
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
6
|
+
*
|
|
7
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
8
|
+
* visit https://hsuite.finance/licensing
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file walletconnect-types.ts
|
|
13
|
+
* @description Shared types for WalletConnect integration
|
|
14
|
+
*
|
|
15
|
+
* Common types used across the WalletConnect provider and signers
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { ISignClient } from '@walletconnect/types';
|
|
19
|
+
import type { WalletConnectModal } from '@walletconnect/modal';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents an active WalletConnect session
|
|
23
|
+
*/
|
|
24
|
+
export interface WalletConnectSession {
|
|
25
|
+
topic: string;
|
|
26
|
+
namespaces: Record<string, unknown>;
|
|
27
|
+
ledgerId: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Context object containing all necessary WalletConnect instances
|
|
32
|
+
*/
|
|
33
|
+
export interface SignerContext {
|
|
34
|
+
client: ISignClient;
|
|
35
|
+
session: WalletConnectSession;
|
|
36
|
+
modal?: WalletConnectModal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Metadata about a WalletConnect session for storage/restoration
|
|
41
|
+
*/
|
|
42
|
+
export interface SessionMetadata {
|
|
43
|
+
projectId: string;
|
|
44
|
+
ledgerId: string;
|
|
45
|
+
networkId: string;
|
|
46
|
+
topic: string;
|
|
47
|
+
connectedAt: number;
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HSuite Native Connect
|
|
3
|
+
* Copyright 2024-2025 HSuite (https://hsuite.finance)
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
6
|
+
*
|
|
7
|
+
* This file is part of HSuite Native Connect. For commercial licensing,
|
|
8
|
+
* visit https://hsuite.finance/licensing
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file index.ts
|
|
13
|
+
* @description Barrel export for WalletConnect module
|
|
14
|
+
*
|
|
15
|
+
* Provides a clean public API for the WalletConnect integration.
|
|
16
|
+
* Exports all necessary types, classes, and utilities.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Core
|
|
20
|
+
export * from './core/walletconnect-provider';
|
|
21
|
+
export * from './core/walletconnect-session-store';
|
|
22
|
+
export * from './core/walletconnect-client-manager';
|
|
23
|
+
export * from './core/walletconnect-signing-orchestrator';
|
|
24
|
+
export * from './core/base-signer.interface';
|
|
25
|
+
export * from './core/walletconnect-types';
|
|
26
|
+
|
|
27
|
+
// Signers
|
|
28
|
+
export * from './signers/hedera-signer';
|
|
29
|
+
export * from './signers/xrpl-signer';
|
|
30
|
+
export * from './signers/signer-factory';
|
|
31
|
+
|
|
32
|
+
// Encoders - re-export from native-wallet-sdk for convenience
|
|
33
|
+
export { HederaTransactionEncoder, XrplTransactionEncoder } from '@hsuite/native-connect-sdk';
|