@hsuite/native-connect-angular 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +146 -0
- package/package.json +30 -13
- package/USAGE_EXAMPLES.md +0 -476
- package/assets/wallets/extension.svg +0 -7
- package/assets/wallets/hashpack.svg +0 -6
- package/assets/wallets/hsuite.svg +0 -11
- package/assets/wallets/kabila.svg +0 -11
- package/assets/wallets/walletconnect.svg +0 -13
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/coverage-summary.json +0 -54
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -476
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -476
- package/coverage/lcov-report/lib/components/account-selector/account-actions/account-actions.component.ts.html +0 -868
- package/coverage/lcov-report/lib/components/account-selector/account-actions/index.html +0 -116
- package/coverage/lcov-report/lib/components/account-selector/account-filter/account-filter.component.ts.html +0 -1288
- package/coverage/lcov-report/lib/components/account-selector/account-filter/index.html +0 -116
- package/coverage/lcov-report/lib/components/account-selector/account-formatting.service.ts.html +0 -679
- package/coverage/lcov-report/lib/components/account-selector/account-grouping.service.ts.html +0 -766
- package/coverage/lcov-report/lib/components/account-selector/account-list/account-list.component.ts.html +0 -1495
- package/coverage/lcov-report/lib/components/account-selector/account-list/index.html +0 -116
- package/coverage/lcov-report/lib/components/account-selector/account-selector.component.ts.html +0 -1495
- package/coverage/lcov-report/lib/components/account-selector/account-selector.service.ts.html +0 -1588
- package/coverage/lcov-report/lib/components/account-selector/index.html +0 -161
- package/coverage/lcov-report/lib/components/wallet-account-display/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-account-display/wallet-account-display.component.ts.html +0 -505
- package/coverage/lcov-report/lib/components/wallet-connect-button/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +0 -829
- package/coverage/lcov-report/lib/components/wallet-connect-prompt/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +0 -409
- package/coverage/lcov-report/lib/components/wallet-connected-guard/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +0 -304
- package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +0 -436
- package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-connection-modal/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +0 -2287
- package/coverage/lcov-report/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +0 -2518
- package/coverage/lcov-report/lib/components/wallet-session-display/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-session-display/wallet-session-display.component.ts.html +0 -676
- package/coverage/lcov-report/lib/components/wallet-transaction-status/index.html +0 -116
- package/coverage/lcov-report/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +0 -703
- package/coverage/lcov-report/lib/directives/index.html +0 -146
- package/coverage/lcov-report/lib/directives/wallet-connected.directive.ts.html +0 -670
- package/coverage/lcov-report/lib/directives/wallet-context.directive.ts.html +0 -547
- package/coverage/lcov-report/lib/directives/wallet-events.directive.ts.html +0 -781
- package/coverage/lcov-report/lib/hsuite-wallet.module.ts.html +0 -715
- package/coverage/lcov-report/lib/index.html +0 -116
- package/coverage/lcov-report/lib/models/connection-config.model.ts.html +0 -280
- package/coverage/lcov-report/lib/models/index.html +0 -131
- package/coverage/lcov-report/lib/models/provider-types.ts.html +0 -583
- package/coverage/lcov-report/lib/providers/base-wallet-provider.ts.html +0 -1138
- package/coverage/lcov-report/lib/providers/hsuite-native/channel-client.service.ts.html +0 -2674
- package/coverage/lcov-report/lib/providers/hsuite-native/index.html +0 -116
- package/coverage/lcov-report/lib/providers/hsuite-native-provider.ts.html +0 -2347
- package/coverage/lcov-report/lib/providers/index.html +0 -146
- package/coverage/lcov-report/lib/providers/p2p-native/index.html +0 -131
- package/coverage/lcov-report/lib/providers/p2p-native/p2p-native.provider.ts.html +0 -2254
- package/coverage/lcov-report/lib/providers/p2p-native/p2p-session-manager.ts.html +0 -2173
- package/coverage/lcov-report/lib/providers/wallet-error-handler.ts.html +0 -1132
- package/coverage/lcov-report/lib/providers/walletconnect/core/index.html +0 -176
- package/coverage/lcov-report/lib/providers/walletconnect/core/session-health.ts.html +0 -673
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +0 -1177
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-provider.ts.html +0 -2566
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +0 -904
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +0 -982
- package/coverage/lcov-report/lib/providers/walletconnect/signers/hedera-signer.ts.html +0 -1915
- package/coverage/lcov-report/lib/providers/walletconnect/signers/index.html +0 -146
- package/coverage/lcov-report/lib/providers/walletconnect/signers/signer-factory.ts.html +0 -445
- package/coverage/lcov-report/lib/providers/walletconnect/signers/xrpl-signer.ts.html +0 -1519
- package/coverage/lcov-report/lib/services/hsuite-auth.interceptor.ts.html +0 -568
- package/coverage/lcov-report/lib/services/index.html +0 -221
- package/coverage/lcov-report/lib/services/logger.service.ts.html +0 -463
- package/coverage/lcov-report/lib/services/smart-session.service.ts.html +0 -1264
- package/coverage/lcov-report/lib/services/transaction-builders/active-account-source.ts.html +0 -250
- package/coverage/lcov-report/lib/services/transaction-builders/base-transaction-builder.service.ts.html +0 -1840
- package/coverage/lcov-report/lib/services/transaction-builders/hedera-amount-utils.ts.html +0 -337
- package/coverage/lcov-report/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +0 -3940
- package/coverage/lcov-report/lib/services/transaction-builders/index.html +0 -176
- package/coverage/lcov-report/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +0 -2581
- package/coverage/lcov-report/lib/services/transaction.service.ts.html +0 -1120
- package/coverage/lcov-report/lib/services/unified-wallet.service.ts.html +0 -2638
- package/coverage/lcov-report/lib/services/wallet-context.service.ts.html +0 -637
- package/coverage/lcov-report/lib/services/wallet-event-bus.service.ts.html +0 -643
- package/coverage/lcov-report/lib/services/wallet-providers.service.ts.html +0 -493
- package/coverage/lcov-report/lib/transports/chrome-extension-transport.ts.html +0 -823
- package/coverage/lcov-report/lib/transports/index.html +0 -116
- package/coverage/lcov-report/lib/utils/index.html +0 -131
- package/coverage/lcov-report/lib/utils/ledger-icons.util.ts.html +0 -412
- package/coverage/lcov-report/lib/utils/ledger-ui-registry.ts.html +0 -676
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov.info +0 -20366
- package/coverage/lib/components/account-selector/account-actions/account-actions.component.ts.html +0 -868
- package/coverage/lib/components/account-selector/account-actions/index.html +0 -116
- package/coverage/lib/components/account-selector/account-filter/account-filter.component.ts.html +0 -1288
- package/coverage/lib/components/account-selector/account-filter/index.html +0 -116
- package/coverage/lib/components/account-selector/account-formatting.service.ts.html +0 -679
- package/coverage/lib/components/account-selector/account-grouping.service.ts.html +0 -766
- package/coverage/lib/components/account-selector/account-list/account-list.component.ts.html +0 -1495
- package/coverage/lib/components/account-selector/account-list/index.html +0 -116
- package/coverage/lib/components/account-selector/account-selector.component.ts.html +0 -1495
- package/coverage/lib/components/account-selector/account-selector.service.ts.html +0 -1588
- package/coverage/lib/components/account-selector/index.html +0 -161
- package/coverage/lib/components/wallet-account-display/index.html +0 -116
- package/coverage/lib/components/wallet-account-display/wallet-account-display.component.ts.html +0 -505
- package/coverage/lib/components/wallet-connect-button/index.html +0 -116
- package/coverage/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +0 -829
- package/coverage/lib/components/wallet-connect-prompt/index.html +0 -116
- package/coverage/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +0 -409
- package/coverage/lib/components/wallet-connected-guard/index.html +0 -116
- package/coverage/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +0 -304
- package/coverage/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +0 -436
- package/coverage/lib/components/wallet-connection-modal/connection-method-step/index.html +0 -116
- package/coverage/lib/components/wallet-connection-modal/index.html +0 -116
- package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/index.html +0 -116
- package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +0 -2287
- package/coverage/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +0 -2518
- package/coverage/lib/components/wallet-session-display/index.html +0 -116
- package/coverage/lib/components/wallet-session-display/wallet-session-display.component.ts.html +0 -676
- package/coverage/lib/components/wallet-transaction-status/index.html +0 -116
- package/coverage/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +0 -703
- package/coverage/lib/directives/index.html +0 -146
- package/coverage/lib/directives/wallet-connected.directive.ts.html +0 -670
- package/coverage/lib/directives/wallet-context.directive.ts.html +0 -547
- package/coverage/lib/directives/wallet-events.directive.ts.html +0 -781
- package/coverage/lib/hsuite-wallet.module.ts.html +0 -715
- package/coverage/lib/index.html +0 -116
- package/coverage/lib/models/connection-config.model.ts.html +0 -280
- package/coverage/lib/models/index.html +0 -131
- package/coverage/lib/models/provider-types.ts.html +0 -583
- package/coverage/lib/providers/base-wallet-provider.ts.html +0 -1138
- package/coverage/lib/providers/hsuite-native/channel-client.service.ts.html +0 -2674
- package/coverage/lib/providers/hsuite-native/index.html +0 -116
- package/coverage/lib/providers/hsuite-native-provider.ts.html +0 -2347
- package/coverage/lib/providers/index.html +0 -146
- package/coverage/lib/providers/p2p-native/index.html +0 -131
- package/coverage/lib/providers/p2p-native/p2p-native.provider.ts.html +0 -2254
- package/coverage/lib/providers/p2p-native/p2p-session-manager.ts.html +0 -2173
- package/coverage/lib/providers/wallet-error-handler.ts.html +0 -1132
- package/coverage/lib/providers/walletconnect/core/index.html +0 -176
- package/coverage/lib/providers/walletconnect/core/session-health.ts.html +0 -673
- package/coverage/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +0 -1177
- package/coverage/lib/providers/walletconnect/core/walletconnect-provider.ts.html +0 -2566
- package/coverage/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +0 -904
- package/coverage/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +0 -982
- package/coverage/lib/providers/walletconnect/signers/hedera-signer.ts.html +0 -1915
- package/coverage/lib/providers/walletconnect/signers/index.html +0 -146
- package/coverage/lib/providers/walletconnect/signers/signer-factory.ts.html +0 -445
- package/coverage/lib/providers/walletconnect/signers/xrpl-signer.ts.html +0 -1519
- package/coverage/lib/services/hsuite-auth.interceptor.ts.html +0 -568
- package/coverage/lib/services/index.html +0 -221
- package/coverage/lib/services/logger.service.ts.html +0 -463
- package/coverage/lib/services/smart-session.service.ts.html +0 -1264
- package/coverage/lib/services/transaction-builders/active-account-source.ts.html +0 -250
- package/coverage/lib/services/transaction-builders/base-transaction-builder.service.ts.html +0 -1840
- package/coverage/lib/services/transaction-builders/hedera-amount-utils.ts.html +0 -337
- package/coverage/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +0 -3940
- package/coverage/lib/services/transaction-builders/index.html +0 -176
- package/coverage/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +0 -2581
- package/coverage/lib/services/transaction.service.ts.html +0 -1120
- package/coverage/lib/services/unified-wallet.service.ts.html +0 -2638
- package/coverage/lib/services/wallet-context.service.ts.html +0 -637
- package/coverage/lib/services/wallet-event-bus.service.ts.html +0 -643
- package/coverage/lib/services/wallet-providers.service.ts.html +0 -493
- package/coverage/lib/transports/chrome-extension-transport.ts.html +0 -823
- package/coverage/lib/transports/index.html +0 -116
- package/coverage/lib/utils/index.html +0 -131
- package/coverage/lib/utils/ledger-icons.util.ts.html +0 -412
- package/coverage/lib/utils/ledger-ui-registry.ts.html +0 -676
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/examples/minimal-connect.ts +0 -178
- package/examples/multi-protocol.ts +0 -495
- package/examples/transaction-signing.ts +0 -361
- package/jest.config.json +0 -45
- package/karma.conf.js +0 -42
- package/ng-package.json +0 -20
- package/src/index.ts +0 -229
- package/src/lib/components/account-selector/account-actions/account-actions.component.ts +0 -261
- package/src/lib/components/account-selector/account-filter/account-filter.component.ts +0 -401
- package/src/lib/components/account-selector/account-formatting.service.ts +0 -198
- package/src/lib/components/account-selector/account-grouping.service.ts +0 -227
- package/src/lib/components/account-selector/account-list/account-list.component.ts +0 -470
- package/src/lib/components/account-selector/account-selector.component.html +0 -135
- package/src/lib/components/account-selector/account-selector.component.scss +0 -2039
- package/src/lib/components/account-selector/account-selector.component.ts +0 -470
- package/src/lib/components/account-selector/account-selector.service.ts +0 -501
- package/src/lib/components/wallet-account-display/wallet-account-display.component.html +0 -34
- package/src/lib/components/wallet-account-display/wallet-account-display.component.scss +0 -99
- package/src/lib/components/wallet-account-display/wallet-account-display.component.ts +0 -140
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.html +0 -14
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.scss +0 -272
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.spec.ts +0 -89
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.ts +0 -248
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.html +0 -24
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.scss +0 -50
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts +0 -108
- package/src/lib/components/wallet-connected-guard/wallet-connected-guard.component.html +0 -24
- package/src/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts +0 -73
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.html +0 -56
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.scss +0 -218
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts +0 -117
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.html +0 -94
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.scss +0 -272
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts +0 -734
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.html +0 -192
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.scss +0 -678
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.spec.ts +0 -173
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts +0 -811
- package/src/lib/components/wallet-session-display/wallet-session-display.component.html +0 -110
- package/src/lib/components/wallet-session-display/wallet-session-display.component.scss +0 -179
- package/src/lib/components/wallet-session-display/wallet-session-display.component.ts +0 -197
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.html +0 -65
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.scss +0 -254
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts +0 -206
- package/src/lib/directives/wallet-connected.directive.ts +0 -195
- package/src/lib/directives/wallet-context.directive.ts +0 -154
- package/src/lib/directives/wallet-events.directive.ts +0 -232
- package/src/lib/hsuite-wallet.module.ts +0 -210
- package/src/lib/models/connection-config.model.ts +0 -65
- package/src/lib/models/provider-types.ts +0 -166
- package/src/lib/models/unified-account.model.ts +0 -79
- package/src/lib/models/wallet-context.model.ts +0 -121
- package/src/lib/models/wallet-events.model.ts +0 -158
- package/src/lib/providers/base-wallet-provider.ts +0 -351
- package/src/lib/providers/hsuite-native/channel-client.service.spec.ts +0 -73
- package/src/lib/providers/hsuite-native/channel-client.service.ts +0 -863
- package/src/lib/providers/hsuite-native/index.ts +0 -8
- package/src/lib/providers/hsuite-native-provider.ts +0 -754
- package/src/lib/providers/mobile-native/mobile-native.provider.spec.ts +0 -19
- package/src/lib/providers/p2p-native/index.ts +0 -30
- package/src/lib/providers/p2p-native/p2p-native.provider.spec.ts +0 -523
- package/src/lib/providers/p2p-native/p2p-native.provider.ts +0 -723
- package/src/lib/providers/p2p-native/p2p-session-manager.ts +0 -696
- package/src/lib/providers/wallet-error-handler.ts +0 -349
- package/src/lib/providers/walletconnect/core/base-signer.interface.ts +0 -122
- package/src/lib/providers/walletconnect/core/session-health.ts +0 -196
- package/src/lib/providers/walletconnect/core/walletconnect-client-manager.ts +0 -364
- package/src/lib/providers/walletconnect/core/walletconnect-provider.integration.spec.ts +0 -348
- package/src/lib/providers/walletconnect/core/walletconnect-provider.ts +0 -827
- package/src/lib/providers/walletconnect/core/walletconnect-session-store.ts +0 -273
- package/src/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts +0 -299
- package/src/lib/providers/walletconnect/core/walletconnect-types.ts +0 -48
- package/src/lib/providers/walletconnect/index.ts +0 -33
- package/src/lib/providers/walletconnect/signers/hedera-signer.spec.ts +0 -367
- package/src/lib/providers/walletconnect/signers/hedera-signer.ts +0 -610
- package/src/lib/providers/walletconnect/signers/signer-factory.spec.ts +0 -62
- package/src/lib/providers/walletconnect/signers/signer-factory.ts +0 -120
- package/src/lib/providers/walletconnect/signers/xrpl-signer.spec.ts +0 -296
- package/src/lib/providers/walletconnect/signers/xrpl-signer.ts +0 -478
- package/src/lib/services/hsuite-auth.interceptor.ts +0 -159
- package/src/lib/services/logger.service.ts +0 -126
- package/src/lib/services/smart-session.service.ts +0 -378
- package/src/lib/services/transaction-builders/active-account-source.spec.ts +0 -75
- package/src/lib/services/transaction-builders/active-account-source.ts +0 -55
- package/src/lib/services/transaction-builders/base-transaction-builder.service.ts +0 -585
- package/src/lib/services/transaction-builders/hedera-amount-utils.ts +0 -84
- package/src/lib/services/transaction-builders/hedera-transaction-builder.service.spec.ts +0 -741
- package/src/lib/services/transaction-builders/hedera-transaction-builder.service.ts +0 -1285
- package/src/lib/services/transaction-builders/index.ts +0 -55
- package/src/lib/services/transaction-builders/xrpl-transaction-builder.service.spec.ts +0 -937
- package/src/lib/services/transaction-builders/xrpl-transaction-builder.service.ts +0 -832
- package/src/lib/services/transaction.service.ts +0 -349
- package/src/lib/services/unified-wallet.service.spec.ts +0 -1382
- package/src/lib/services/unified-wallet.service.ts +0 -851
- package/src/lib/services/wallet-context.service.ts +0 -184
- package/src/lib/services/wallet-event-bus.service.ts +0 -186
- package/src/lib/services/wallet-providers.service.ts +0 -136
- package/src/lib/transports/chrome-extension-transport.ts +0 -246
- package/src/lib/utils/index.ts +0 -15
- package/src/lib/utils/ledger-icons.util.ts +0 -109
- package/src/lib/utils/ledger-ui-registry.ts +0 -197
- package/test/test-setup.ts +0 -21
- package/test-setup.ts +0 -63
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -29
- package/tsconfig.spec.json +0 -15
- package/vitest.config.ts +0 -48
|
@@ -1,126 +0,0 @@
|
|
|
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 Angular Logger Service for dependency injection.
|
|
13
|
-
*
|
|
14
|
-
* @module services/logger
|
|
15
|
-
*
|
|
16
|
-
* @description
|
|
17
|
-
* LoggerService wraps the SDK's logger for Angular dependency injection, providing
|
|
18
|
-
* a consistent logging interface throughout Angular applications. It enables
|
|
19
|
-
* scoped logging with component/service names, production mode filtering, and
|
|
20
|
-
* consistent log formatting.
|
|
21
|
-
*
|
|
22
|
-
* **Key Features:**
|
|
23
|
-
* - Scoped loggers for easy filtering and tracing
|
|
24
|
-
* - Production-aware log level filtering
|
|
25
|
-
* - Consistent formatting across all components
|
|
26
|
-
* - Context objects for structured logging
|
|
27
|
-
*
|
|
28
|
-
* **Log Levels:**
|
|
29
|
-
* - `debug` - Detailed debugging information (filtered in production)
|
|
30
|
-
* - `info` - General informational messages
|
|
31
|
-
* - `warn` - Warning conditions that may need attention
|
|
32
|
-
* - `error` - Error conditions requiring action
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
import { Injectable } from '@angular/core';
|
|
36
|
-
import { getLogger, Logger } from '@hsuite/native-connect-sdk';
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Angular Logger Service that wraps the SDK's logger for dependency injection.
|
|
40
|
-
*
|
|
41
|
-
* @service LoggerService
|
|
42
|
-
*
|
|
43
|
-
* @description
|
|
44
|
-
* Provides scoped logger instances for components and services. All logs go through
|
|
45
|
-
* the SDK's configurable logging infrastructure, which supports production mode
|
|
46
|
-
* filtering and scope-based log levels.
|
|
47
|
-
*
|
|
48
|
-
* **Best Practices:**
|
|
49
|
-
* - Create scoped loggers at the class level for consistent scope names
|
|
50
|
-
* - Use structured context objects for machine-readable logs
|
|
51
|
-
* - Use appropriate log levels (debug for dev, info for operations, error for failures)
|
|
52
|
-
*
|
|
53
|
-
* @providedIn root
|
|
54
|
-
*/
|
|
55
|
-
@Injectable({ providedIn: 'root' })
|
|
56
|
-
export class LoggerService {
|
|
57
|
-
private readonly rootLogger: Logger = getLogger();
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Returns a scoped logger instance.
|
|
61
|
-
*
|
|
62
|
-
* Scoped loggers prefix all messages with the scope name,
|
|
63
|
-
* making it easier to filter and trace logs.
|
|
64
|
-
*
|
|
65
|
-
* @param scope The scope for the logger (e.g., 'AppComponent', 'WalletService').
|
|
66
|
-
* @returns A scoped Logger instance
|
|
67
|
-
*/
|
|
68
|
-
scoped(scope: string): Logger {
|
|
69
|
-
return this.rootLogger.scoped?.(scope) ?? this.rootLogger;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the root logger instance.
|
|
74
|
-
*
|
|
75
|
-
* Use sparingly - prefer scoped() for component/service logging.
|
|
76
|
-
*
|
|
77
|
-
* @returns The root Logger instance
|
|
78
|
-
*/
|
|
79
|
-
getRootLogger(): Logger {
|
|
80
|
-
return this.rootLogger;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Log a debug message using the root logger.
|
|
85
|
-
* Convenience method for one-off logs.
|
|
86
|
-
*
|
|
87
|
-
* @param message Log message
|
|
88
|
-
* @param context Optional context object
|
|
89
|
-
*/
|
|
90
|
-
debug(message: string, context?: Record<string, unknown>): void {
|
|
91
|
-
this.rootLogger.debug(message, context);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Log an info message using the root logger.
|
|
96
|
-
* Convenience method for one-off logs.
|
|
97
|
-
*
|
|
98
|
-
* @param message Log message
|
|
99
|
-
* @param context Optional context object
|
|
100
|
-
*/
|
|
101
|
-
info(message: string, context?: Record<string, unknown>): void {
|
|
102
|
-
this.rootLogger.info(message, context);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Log a warning message using the root logger.
|
|
107
|
-
* Convenience method for one-off logs.
|
|
108
|
-
*
|
|
109
|
-
* @param message Log message
|
|
110
|
-
* @param context Optional context object
|
|
111
|
-
*/
|
|
112
|
-
warn(message: string, context?: Record<string, unknown>): void {
|
|
113
|
-
this.rootLogger.warn(message, context);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Log an error message using the root logger.
|
|
118
|
-
* Convenience method for one-off logs.
|
|
119
|
-
*
|
|
120
|
-
* @param message Log message
|
|
121
|
-
* @param context Optional context object
|
|
122
|
-
*/
|
|
123
|
-
error(message: string, context?: Record<string, unknown>): void {
|
|
124
|
-
this.rootLogger.error(message, context);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,378 +0,0 @@
|
|
|
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 Smart-host customer session helper.
|
|
13
|
-
*
|
|
14
|
-
* @module services/smart-session
|
|
15
|
-
*
|
|
16
|
-
* @description
|
|
17
|
-
* SmartSessionService automates the smart-host authentication handshake for
|
|
18
|
-
* HSuite dApps. It discovers the host's `appId`, requests a challenge, signs it
|
|
19
|
-
* with the active wallet account, and exchanges the signed challenge for a
|
|
20
|
-
* short-lived bearer token.
|
|
21
|
-
*
|
|
22
|
-
* **Typical flow:**
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const session = inject(SmartSessionService);
|
|
25
|
-
* await session.login();
|
|
26
|
-
* const bearer = session.getBearer();
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* The service also exposes {@link withSession} for automatic 401 recovery:
|
|
30
|
-
* operations that fail with HTTP 401 are retried once after a fresh login.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import { HttpClient } from '@angular/common/http';
|
|
34
|
-
import { Injectable, inject, InjectionToken } from '@angular/core';
|
|
35
|
-
import { getLogger } from '@hsuite/native-connect-sdk';
|
|
36
|
-
import { firstValueFrom } from 'rxjs';
|
|
37
|
-
|
|
38
|
-
import type { SignMessageResult } from '../providers/base-wallet-provider';
|
|
39
|
-
|
|
40
|
-
import { TransactionService } from './transaction.service';
|
|
41
|
-
import { UnifiedWalletService } from './unified-wallet.service';
|
|
42
|
-
|
|
43
|
-
const logger = getLogger().scoped?.('SmartSessionService') ?? getLogger();
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Configuration token for {@link SmartSessionService}.
|
|
47
|
-
*/
|
|
48
|
-
export const SMART_SESSION_CONFIG = new InjectionToken<SmartSessionConfig>('SMART_SESSION_CONFIG', {
|
|
49
|
-
factory: () => ({}),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Configuration for the smart-host session handshake.
|
|
54
|
-
*/
|
|
55
|
-
export interface SmartSessionConfig {
|
|
56
|
-
/**
|
|
57
|
-
* Base URL for the smart-host API.
|
|
58
|
-
* @default '' (relative to the current origin)
|
|
59
|
-
*/
|
|
60
|
-
baseUrl?: string;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Health endpoint used to discover the host `appId`.
|
|
64
|
-
* @default '/api/health'
|
|
65
|
-
*/
|
|
66
|
-
healthEndpoint?: string;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Challenge endpoint used to obtain a message to sign.
|
|
70
|
-
* @default '/api/auth/challenge'
|
|
71
|
-
*/
|
|
72
|
-
challengeEndpoint?: string;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Verify endpoint used to exchange the signed challenge for a bearer token.
|
|
76
|
-
* @default '/api/auth/verify'
|
|
77
|
-
*/
|
|
78
|
-
verifyEndpoint?: string;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* sessionStorage key used to persist the session token and expiry.
|
|
82
|
-
* @default 'hsuite.smart-session'
|
|
83
|
-
*/
|
|
84
|
-
storageKey?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Health response shape expected from the smart host.
|
|
89
|
-
*/
|
|
90
|
-
export interface SmartHostHealth {
|
|
91
|
-
appId: string;
|
|
92
|
-
[key: string]: unknown;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Challenge response shape expected from the smart host.
|
|
97
|
-
*/
|
|
98
|
-
export interface SmartHostChallenge {
|
|
99
|
-
challenge: string;
|
|
100
|
-
[key: string]: unknown;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Verify request payload sent to the smart host.
|
|
105
|
-
*/
|
|
106
|
-
export interface SmartHostVerifyRequest {
|
|
107
|
-
appId: string;
|
|
108
|
-
accountAddress: string;
|
|
109
|
-
publicKey?: string;
|
|
110
|
-
signature: string;
|
|
111
|
-
algorithm?: string;
|
|
112
|
-
message: string;
|
|
113
|
-
caipChainId?: string;
|
|
114
|
-
ledgerId?: string;
|
|
115
|
-
networkId?: string;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Verify response shape expected from the smart host.
|
|
120
|
-
*/
|
|
121
|
-
export interface SmartHostVerifyResponse {
|
|
122
|
-
bearer: string;
|
|
123
|
-
expiresAt?: number;
|
|
124
|
-
expiresIn?: number;
|
|
125
|
-
[key: string]: unknown;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Persisted smart session.
|
|
130
|
-
*/
|
|
131
|
-
interface StoredSession {
|
|
132
|
-
bearer: string;
|
|
133
|
-
expiresAt: number;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Smart-host customer session helper.
|
|
138
|
-
*
|
|
139
|
-
* @service SmartSessionService
|
|
140
|
-
*
|
|
141
|
-
* @description
|
|
142
|
-
* Encapsulates the full challenge → sign → verify → store JWT flow required by
|
|
143
|
-
* HSuite smart hosts. The service is intentionally thin: it delegates signing to
|
|
144
|
-
* {@link TransactionService} and relies on standard Angular `HttpClient` for the
|
|
145
|
-
* host HTTP calls.
|
|
146
|
-
*
|
|
147
|
-
* @providedIn root
|
|
148
|
-
*/
|
|
149
|
-
@Injectable({ providedIn: 'root' })
|
|
150
|
-
export class SmartSessionService {
|
|
151
|
-
private readonly http = inject(HttpClient);
|
|
152
|
-
private readonly walletService = inject(UnifiedWalletService);
|
|
153
|
-
private readonly transactionService = inject(TransactionService);
|
|
154
|
-
private readonly config = inject(SMART_SESSION_CONFIG);
|
|
155
|
-
|
|
156
|
-
private get baseUrl(): string {
|
|
157
|
-
return this.config.baseUrl ?? '';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private get healthEndpoint(): string {
|
|
161
|
-
return this.config.healthEndpoint ?? '/api/health';
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private get challengeEndpoint(): string {
|
|
165
|
-
return this.config.challengeEndpoint ?? '/api/auth/challenge';
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
private get verifyEndpoint(): string {
|
|
169
|
-
return this.config.verifyEndpoint ?? '/api/auth/verify';
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private get storageKey(): string {
|
|
173
|
-
return this.config.storageKey ?? 'hsuite.smart-session';
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Returns the currently stored bearer token, or `null` if there is no session.
|
|
178
|
-
*
|
|
179
|
-
* @returns Bearer token string or null
|
|
180
|
-
*/
|
|
181
|
-
getBearer(): string | null {
|
|
182
|
-
const stored = this.readStoredSession();
|
|
183
|
-
return stored && stored.expiresAt > Date.now() ? stored.bearer : null;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Checks whether a non-expired session is available.
|
|
188
|
-
*
|
|
189
|
-
* @returns true if logged in and the bearer has not expired
|
|
190
|
-
*/
|
|
191
|
-
isLoggedIn(): boolean {
|
|
192
|
-
return this.getBearer() !== null;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Performs the full smart-host login handshake.
|
|
197
|
-
*
|
|
198
|
-
* @description
|
|
199
|
-
* 1. Discovers `appId` from the health endpoint.
|
|
200
|
-
* 2. Fetches a challenge from the challenge endpoint.
|
|
201
|
-
* 3. Signs the challenge with the active wallet account.
|
|
202
|
-
* 4. Exchanges the signed challenge for a bearer token.
|
|
203
|
-
* 5. Stores the bearer and expiry in `sessionStorage`.
|
|
204
|
-
*
|
|
205
|
-
* @returns The verify response from the host
|
|
206
|
-
*
|
|
207
|
-
* @throws {Error} If no active account is available
|
|
208
|
-
* @throws {Error} If the health endpoint does not return an `appId`
|
|
209
|
-
* @throws {Error} If the challenge endpoint does not return a `challenge`
|
|
210
|
-
* @throws {Error} If the verify call fails
|
|
211
|
-
*/
|
|
212
|
-
async login(): Promise<SmartHostVerifyResponse> {
|
|
213
|
-
const account = this.walletService.activeAccount();
|
|
214
|
-
if (!account) {
|
|
215
|
-
throw new Error('No active account');
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
logger.info('Starting smart-host login handshake', {
|
|
219
|
-
accountAddress: account.address,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
const health = await this.fetchHealth();
|
|
223
|
-
if (!health.appId) {
|
|
224
|
-
throw new Error('Smart host health endpoint did not return appId');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const challengeResponse = await this.fetchChallenge(health.appId);
|
|
228
|
-
if (!challengeResponse.challenge) {
|
|
229
|
-
throw new Error('Smart host challenge endpoint did not return challenge');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const signResult = await this.transactionService.signMessage(challengeResponse.challenge);
|
|
233
|
-
|
|
234
|
-
const verifyResponse = await this.verifyChallenge(
|
|
235
|
-
health.appId,
|
|
236
|
-
account,
|
|
237
|
-
challengeResponse.challenge,
|
|
238
|
-
signResult,
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
if (!verifyResponse.bearer) {
|
|
242
|
-
throw new Error('Smart host verify endpoint did not return bearer');
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const expiresAt = this.resolveExpiry(verifyResponse);
|
|
246
|
-
this.storeSession({ bearer: verifyResponse.bearer, expiresAt });
|
|
247
|
-
|
|
248
|
-
logger.info('Smart-host login successful', {
|
|
249
|
-
appId: health.appId,
|
|
250
|
-
expiresAt,
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
return verifyResponse;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Clears the stored session.
|
|
258
|
-
*/
|
|
259
|
-
logout(): void {
|
|
260
|
-
this.clearStoredSession();
|
|
261
|
-
logger.info('Smart-host session cleared');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Runs an HTTP operation with automatic 401 recovery.
|
|
266
|
-
*
|
|
267
|
-
* @description
|
|
268
|
-
* Executes the provided operation. If it rejects with an HTTP 401 error,
|
|
269
|
-
* the service clears the current bearer, performs a fresh login, and retries
|
|
270
|
-
* the operation once. Any other error is propagated immediately.
|
|
271
|
-
*
|
|
272
|
-
* @param operation - Async operation that needs a valid session
|
|
273
|
-
* @returns The result of the operation
|
|
274
|
-
*
|
|
275
|
-
* @throws {Error} The original error if retry is not possible or fails
|
|
276
|
-
*/
|
|
277
|
-
async withSession<T>(operation: () => Promise<T>): Promise<T> {
|
|
278
|
-
try {
|
|
279
|
-
return await operation();
|
|
280
|
-
} catch (error) {
|
|
281
|
-
if (this.isUnauthorizedError(error)) {
|
|
282
|
-
logger.warn('Operation received 401; attempting single session refresh');
|
|
283
|
-
this.logout();
|
|
284
|
-
await this.login();
|
|
285
|
-
return await operation();
|
|
286
|
-
}
|
|
287
|
-
throw error;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
private async fetchHealth(): Promise<SmartHostHealth> {
|
|
292
|
-
return firstValueFrom(this.http.get<SmartHostHealth>(`${this.baseUrl}${this.healthEndpoint}`));
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
private async fetchChallenge(appId: string): Promise<SmartHostChallenge> {
|
|
296
|
-
return firstValueFrom(
|
|
297
|
-
this.http.post<SmartHostChallenge>(`${this.baseUrl}${this.challengeEndpoint}`, { appId }),
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
private async verifyChallenge(
|
|
302
|
-
appId: string,
|
|
303
|
-
account: import('../models/unified-account.model').UnifiedAccount,
|
|
304
|
-
challenge: string,
|
|
305
|
-
signResult: SignMessageResult,
|
|
306
|
-
): Promise<SmartHostVerifyResponse> {
|
|
307
|
-
const payload: SmartHostVerifyRequest = {
|
|
308
|
-
appId,
|
|
309
|
-
accountAddress: account.address,
|
|
310
|
-
publicKey: signResult.publicKey ?? account.publicKey,
|
|
311
|
-
signature: signResult.signature,
|
|
312
|
-
algorithm: signResult.algorithm,
|
|
313
|
-
message: challenge,
|
|
314
|
-
caipChainId: signResult.caipChainId,
|
|
315
|
-
ledgerId: account.ledgerId,
|
|
316
|
-
networkId: account.networkId,
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
return firstValueFrom(
|
|
320
|
-
this.http.post<SmartHostVerifyResponse>(`${this.baseUrl}${this.verifyEndpoint}`, payload),
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
private resolveExpiry(response: SmartHostVerifyResponse): number {
|
|
325
|
-
if (response.expiresAt) {
|
|
326
|
-
return response.expiresAt;
|
|
327
|
-
}
|
|
328
|
-
if (response.expiresIn) {
|
|
329
|
-
return Date.now() + response.expiresIn * 1000;
|
|
330
|
-
}
|
|
331
|
-
// Default to 5 minutes if no expiry is provided
|
|
332
|
-
return Date.now() + 5 * 60 * 1000;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
private readStoredSession(): StoredSession | null {
|
|
336
|
-
try {
|
|
337
|
-
const raw = sessionStorage.getItem(this.storageKey);
|
|
338
|
-
if (!raw) {
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
const parsed = JSON.parse(raw) as StoredSession;
|
|
342
|
-
if (!parsed.bearer || typeof parsed.expiresAt !== 'number') {
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
return parsed;
|
|
346
|
-
} catch {
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
private storeSession(session: StoredSession): void {
|
|
352
|
-
try {
|
|
353
|
-
sessionStorage.setItem(this.storageKey, JSON.stringify(session));
|
|
354
|
-
} catch (error) {
|
|
355
|
-
logger.warn('Failed to store smart session', { error });
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
private clearStoredSession(): void {
|
|
360
|
-
try {
|
|
361
|
-
sessionStorage.removeItem(this.storageKey);
|
|
362
|
-
} catch (error) {
|
|
363
|
-
logger.warn('Failed to clear smart session', { error });
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
private isUnauthorizedError(error: unknown): boolean {
|
|
368
|
-
if (!error || typeof error !== 'object') {
|
|
369
|
-
return false;
|
|
370
|
-
}
|
|
371
|
-
const status = (error as { status?: number }).status;
|
|
372
|
-
if (typeof status === 'number') {
|
|
373
|
-
return status === 401;
|
|
374
|
-
}
|
|
375
|
-
const message = String((error as { message?: unknown }).message ?? '');
|
|
376
|
-
return /\b401\b|unauthorized/i.test(message);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
-
* @fileoverview #5 decoupling. The Hedera transaction builder must resolve the
|
|
13
|
-
* active account through the ACTIVE_ACCOUNT_SOURCE token, NOT by injecting
|
|
14
|
-
* UnifiedWalletService directly. A default root provider keeps the token
|
|
15
|
-
* pointing at UnifiedWalletService, so existing SDK consumers are unaffected
|
|
16
|
-
* (the comprehensive hedera-transaction-builder.service.spec, which provides a
|
|
17
|
-
* UnifiedWalletService mock, is the backward-compatibility proof). The embedded
|
|
18
|
-
* shell overrides the token with a one-member account context, which is why the
|
|
19
|
-
* stub-of-UnifiedWalletService and its Proxy guard can be deleted.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { TestBed } from '@angular/core/testing';
|
|
23
|
-
import { describe, it, expect } from 'vitest';
|
|
24
|
-
import { signal } from '@angular/core';
|
|
25
|
-
|
|
26
|
-
import { HederaTransactionBuilderService } from './hedera-transaction-builder.service';
|
|
27
|
-
import { ACTIVE_ACCOUNT_SOURCE, type ActiveAccountSource } from './active-account-source';
|
|
28
|
-
import { LoggerService } from '../logger.service';
|
|
29
|
-
import { UnifiedWalletService } from '../unified-wallet.service';
|
|
30
|
-
import type { UnifiedAccount } from '../../models/unified-account.model';
|
|
31
|
-
|
|
32
|
-
const mockLogger = {
|
|
33
|
-
scoped: () => ({ debug() {}, info() {}, warn() {}, error() {} }),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function testnetSource(networkId = 'hedera:testnet'): ActiveAccountSource {
|
|
37
|
-
const account: UnifiedAccount = {
|
|
38
|
-
id: `embedded:hedera:${networkId}:0.0.2193470`,
|
|
39
|
-
address: '0.0.2193470',
|
|
40
|
-
ledgerId: 'hedera',
|
|
41
|
-
networkId,
|
|
42
|
-
providerId: 'test',
|
|
43
|
-
providerType: 'hsuite-native',
|
|
44
|
-
metadata: {},
|
|
45
|
-
};
|
|
46
|
-
return { activeAccount: signal<UnifiedAccount | null>(account) };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
describe('ACTIVE_ACCOUNT_SOURCE (Hedera builder decoupling, #5)', () => {
|
|
50
|
-
it('builds a Hedera transaction from ACTIVE_ACCOUNT_SOURCE with NO UnifiedWalletService provided', async () => {
|
|
51
|
-
TestBed.configureTestingModule({
|
|
52
|
-
providers: [
|
|
53
|
-
{ provide: ACTIVE_ACCOUNT_SOURCE, useValue: testnetSource() },
|
|
54
|
-
{ provide: LoggerService, useValue: mockLogger },
|
|
55
|
-
// UnifiedWalletService is deliberately NOT provided: the builder must
|
|
56
|
-
// resolve its network purely from the account source.
|
|
57
|
-
],
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const builder = TestBed.inject(HederaTransactionBuilderService);
|
|
61
|
-
const payload = await builder.buildSendHbar('0.0.123', '0.0.456', 1);
|
|
62
|
-
|
|
63
|
-
expect(typeof payload).toBe('string');
|
|
64
|
-
expect(payload.length).toBeGreaterThan(0);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('default provider falls back to UnifiedWalletService (backward compatible)', () => {
|
|
68
|
-
const fakeUnified = { activeAccount: signal<UnifiedAccount | null>(null) };
|
|
69
|
-
TestBed.configureTestingModule({
|
|
70
|
-
providers: [{ provide: UnifiedWalletService, useValue: fakeUnified }],
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(TestBed.inject(ACTIVE_ACCOUNT_SOURCE)).toBe(fakeUnified);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
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 ACTIVE_ACCOUNT_SOURCE: the minimal active-account read surface the
|
|
13
|
-
* transaction builders need.
|
|
14
|
-
*
|
|
15
|
-
* @description
|
|
16
|
-
* The Hedera transaction builder only reads `activeAccount()` from the wallet
|
|
17
|
-
* (to pick the network and the entity key config). Injecting the whole
|
|
18
|
-
* {@link UnifiedWalletService} couples the builder to a heavy root service that
|
|
19
|
-
* also runs the dApp connect stack on construction. This token narrows that
|
|
20
|
-
* dependency to a single member.
|
|
21
|
-
*
|
|
22
|
-
* The default provider points at {@link UnifiedWalletService}, so existing SDK
|
|
23
|
-
* consumers that already provide it need NO wiring change (backward
|
|
24
|
-
* compatible). The embedded widget shell overrides this token with a one-member
|
|
25
|
-
* account context, which keeps the heavy root service from ever being
|
|
26
|
-
* constructed inside the wallet.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { InjectionToken, inject, type Signal } from '@angular/core';
|
|
30
|
-
|
|
31
|
-
import type { UnifiedAccount } from '../../models/unified-account.model';
|
|
32
|
-
import { UnifiedWalletService } from '../unified-wallet.service';
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The only member the transaction builders read from the active wallet account.
|
|
36
|
-
* Implemented by {@link UnifiedWalletService} (the default) and by the embedded
|
|
37
|
-
* shell's one-member account context.
|
|
38
|
-
*/
|
|
39
|
-
export interface ActiveAccountSource {
|
|
40
|
-
readonly activeAccount: Signal<UnifiedAccount | null>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Injection token for the active-account read surface. Defaults to
|
|
45
|
-
* {@link UnifiedWalletService} so consumers that already provide it need no
|
|
46
|
-
* extra wiring; override it to supply a narrower source (the embedded shell
|
|
47
|
-
* does this to avoid constructing the root service inside the wallet).
|
|
48
|
-
*/
|
|
49
|
-
export const ACTIVE_ACCOUNT_SOURCE = new InjectionToken<ActiveAccountSource>(
|
|
50
|
-
'ACTIVE_ACCOUNT_SOURCE',
|
|
51
|
-
{
|
|
52
|
-
providedIn: 'root',
|
|
53
|
-
factory: () => inject(UnifiedWalletService),
|
|
54
|
-
},
|
|
55
|
-
);
|