@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,478 @@
|
|
|
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 xrpl-signer.ts
|
|
13
|
+
* @description XRPL-specific WalletConnect signer implementation
|
|
14
|
+
*
|
|
15
|
+
* Implements the IWalletConnectSigner interface for XRPL ledger.
|
|
16
|
+
* Handles XRPL-specific JSON-RPC methods and transaction formats.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { XrplTransactionEncoder } from '@hsuite/native-connect-sdk';
|
|
20
|
+
import { getLogger } from '@hsuite/native-connect-sdk';
|
|
21
|
+
|
|
22
|
+
import type { SignResult, SubmitResult } from '../../base-wallet-provider';
|
|
23
|
+
import type { IWalletConnectSigner, SignerOperationParams } from '../core/base-signer.interface';
|
|
24
|
+
|
|
25
|
+
const logger = getLogger().scoped?.('XrplSigner') ?? getLogger();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Extract a meaningful error message from various error shapes.
|
|
29
|
+
* WalletConnect SDK throws errors that are not standard Error instances.
|
|
30
|
+
*
|
|
31
|
+
* Handles:
|
|
32
|
+
* - Standard Error objects
|
|
33
|
+
* - WalletConnect SDK errors: { code, message }
|
|
34
|
+
* - Nested errors: { error: { message } }
|
|
35
|
+
* - PIN_REQUIRED errors from wallet
|
|
36
|
+
* - DOMException objects
|
|
37
|
+
* - Objects that stringify to {} (enumerable property check)
|
|
38
|
+
*
|
|
39
|
+
* @param error - Error from WalletConnect SDK (can be Error, object, or string)
|
|
40
|
+
* @returns Human-readable error message
|
|
41
|
+
*/
|
|
42
|
+
function extractErrorMessage(error: unknown): string {
|
|
43
|
+
// Log raw error for debugging
|
|
44
|
+
logger.debug('Raw error object', {
|
|
45
|
+
errorType: typeof error,
|
|
46
|
+
isError: error instanceof Error,
|
|
47
|
+
errorKeys: typeof error === 'object' && error !== null ? Object.keys(error) : [],
|
|
48
|
+
errorProto:
|
|
49
|
+
typeof error === 'object' && error !== null
|
|
50
|
+
? Object.getPrototypeOf(error)?.constructor?.name
|
|
51
|
+
: 'N/A',
|
|
52
|
+
rawError: error,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
return error.message;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (typeof error === 'object' && error !== null) {
|
|
60
|
+
const errorObj = error as Record<string, unknown>;
|
|
61
|
+
|
|
62
|
+
// Check for code property first (common in SDK errors like PIN_REQUIRED)
|
|
63
|
+
if (typeof errorObj['code'] === 'string') {
|
|
64
|
+
const codeMsg = errorObj['message']
|
|
65
|
+
? `${errorObj['code']}: ${errorObj['message']}`
|
|
66
|
+
: errorObj['code'];
|
|
67
|
+
return codeMsg as string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// WalletConnect error format: { code, message }
|
|
71
|
+
if ('message' in errorObj && typeof errorObj['message'] === 'string') {
|
|
72
|
+
return errorObj['message'];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Nested error: { error: { message } }
|
|
76
|
+
if (
|
|
77
|
+
'error' in errorObj &&
|
|
78
|
+
typeof errorObj['error'] === 'object' &&
|
|
79
|
+
errorObj['error'] !== null
|
|
80
|
+
) {
|
|
81
|
+
const nested = errorObj['error'] as Record<string, unknown>;
|
|
82
|
+
if ('message' in nested && typeof nested['message'] === 'string') {
|
|
83
|
+
return nested['message'];
|
|
84
|
+
}
|
|
85
|
+
if ('code' in nested && typeof nested['code'] === 'string') {
|
|
86
|
+
return nested['code'];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check for 'context' property which WalletConnect sometimes uses
|
|
91
|
+
if ('context' in errorObj && typeof errorObj['context'] === 'string') {
|
|
92
|
+
return errorObj['context'];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Check for DOMException
|
|
96
|
+
if (error instanceof DOMException) {
|
|
97
|
+
return error.message || error.name;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Check for reason/cause properties (common in rejected promises)
|
|
101
|
+
if ('reason' in errorObj && typeof errorObj['reason'] === 'string') {
|
|
102
|
+
return errorObj['reason'];
|
|
103
|
+
}
|
|
104
|
+
if ('cause' in errorObj && typeof errorObj['cause'] === 'string') {
|
|
105
|
+
return errorObj['cause'];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// WalletConnect JSON-RPC error format: { code: number, message: string }
|
|
109
|
+
if ('code' in errorObj && 'message' in errorObj) {
|
|
110
|
+
const code = errorObj['code'];
|
|
111
|
+
const msg = errorObj['message'];
|
|
112
|
+
if (typeof msg === 'string') {
|
|
113
|
+
return typeof code === 'number' ? `[${code}] ${msg}` : msg;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Error with 'name' property (common for built-in errors)
|
|
118
|
+
if ('name' in errorObj && typeof errorObj['name'] === 'string') {
|
|
119
|
+
const name = errorObj['name'];
|
|
120
|
+
if (name && name !== 'Error' && name !== 'Object') {
|
|
121
|
+
return name;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Try to stringify, but check if result is empty object
|
|
126
|
+
try {
|
|
127
|
+
const jsonStr = JSON.stringify(error);
|
|
128
|
+
// Don't return empty objects as error messages
|
|
129
|
+
if (jsonStr && jsonStr !== '{}' && jsonStr !== '[]') {
|
|
130
|
+
return jsonStr;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// If stringify returned {}, try Object.keys to get property names
|
|
134
|
+
const keys = Object.keys(errorObj);
|
|
135
|
+
if (keys.length > 0) {
|
|
136
|
+
return `Error object with keys: ${keys.join(', ')}`;
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
// If stringify fails, try toString
|
|
140
|
+
const str = String(error);
|
|
141
|
+
if (str !== '[object Object]') {
|
|
142
|
+
return str;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return 'Unknown error object';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (typeof error === 'string') {
|
|
150
|
+
return error;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return 'Unknown error';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Signer implementation for XRPL ledger.
|
|
158
|
+
*
|
|
159
|
+
* Supports XRPL-specific WalletConnect methods:
|
|
160
|
+
* - xrpl_signTransaction (sign-only, returns signed blob)
|
|
161
|
+
* - xrpl_signAndSubmit (sign + submit, returns transaction hash)
|
|
162
|
+
* - xrpl_submit (submit pre-signed transaction)
|
|
163
|
+
* - xrpl_signMessage (arbitrary message signing)
|
|
164
|
+
*
|
|
165
|
+
* Uses XRPL address format: xrpl:<network>:rAddress...
|
|
166
|
+
*/
|
|
167
|
+
export class XrplSigner implements IWalletConnectSigner {
|
|
168
|
+
readonly ledgerId = 'xrpl';
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Build XRPL namespace configuration for WalletConnect.
|
|
172
|
+
* Defines the JSON-RPC methods and chains this signer supports.
|
|
173
|
+
*
|
|
174
|
+
* @param networkId - Network identifier (e.g., 'xrpl:testnet', 'xrpl:mainnet')
|
|
175
|
+
* @returns Namespace configuration object
|
|
176
|
+
*/
|
|
177
|
+
buildNamespace(networkId: string): {
|
|
178
|
+
methods: string[];
|
|
179
|
+
chains: string[];
|
|
180
|
+
events: string[];
|
|
181
|
+
} {
|
|
182
|
+
// Extract network name (testnet, mainnet, devnet)
|
|
183
|
+
const network = networkId.includes('mainnet')
|
|
184
|
+
? 'mainnet'
|
|
185
|
+
: networkId.includes('devnet')
|
|
186
|
+
? 'devnet'
|
|
187
|
+
: 'testnet';
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
methods: ['xrpl_signTransaction', 'xrpl_submit', 'xrpl_signAndSubmit', 'xrpl_signMessage'],
|
|
191
|
+
chains: [`xrpl:${network}`],
|
|
192
|
+
events: ['chainChanged', 'accountsChanged'],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Sign an XRPL transaction without submitting to network.
|
|
198
|
+
* Uses xrpl_signTransaction method with JSON transaction object.
|
|
199
|
+
*
|
|
200
|
+
* @param params - Signing parameters
|
|
201
|
+
* @returns Promise resolving to signed transaction blob (hex-encoded)
|
|
202
|
+
*/
|
|
203
|
+
async signTransaction(params: SignerOperationParams): Promise<SignResult> {
|
|
204
|
+
// Decode base64 payload to JSON transaction
|
|
205
|
+
logger.debug('Decoding XRPL transaction payload', {
|
|
206
|
+
payloadLength: params.payload?.length,
|
|
207
|
+
networkId: params.networkId,
|
|
208
|
+
topic: params.topic?.substring(0, 16) + '...',
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
let transaction: any;
|
|
212
|
+
try {
|
|
213
|
+
transaction = XrplTransactionEncoder.decodeTransaction(params.payload);
|
|
214
|
+
logger.debug('Transaction decoded successfully', {
|
|
215
|
+
transactionType: transaction?.TransactionType,
|
|
216
|
+
account: transaction?.Account,
|
|
217
|
+
});
|
|
218
|
+
} catch (decodeError) {
|
|
219
|
+
logger.error('Failed to decode transaction payload', {
|
|
220
|
+
error: decodeError instanceof Error ? decodeError.message : String(decodeError),
|
|
221
|
+
});
|
|
222
|
+
throw decodeError;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
logger.debug('Sending xrpl_signTransaction request to wallet', {
|
|
227
|
+
method: 'xrpl_signTransaction',
|
|
228
|
+
chainId: params.networkId,
|
|
229
|
+
topic: params.topic?.substring(0, 16) + '...',
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Use 5-minute expiry to give users time to review and approve
|
|
233
|
+
const result = await params.client.request({
|
|
234
|
+
topic: params.topic,
|
|
235
|
+
chainId: params.networkId,
|
|
236
|
+
request: {
|
|
237
|
+
method: 'xrpl_signTransaction',
|
|
238
|
+
params: {
|
|
239
|
+
transaction, // Native JSON object
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
expiry: 300, // 5 minutes in seconds
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
logger.debug('Received response from wallet', {
|
|
246
|
+
hasResult: !!result,
|
|
247
|
+
resultKeys: result ? Object.keys(result as object) : [],
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
signedPayload:
|
|
252
|
+
(result as { tx_blob?: string; tx_json?: any }).tx_blob || JSON.stringify(result),
|
|
253
|
+
metadata: { result },
|
|
254
|
+
};
|
|
255
|
+
} catch (error) {
|
|
256
|
+
// Check if this is an empty error object (WalletConnect SDK bug)
|
|
257
|
+
const isEmptyError =
|
|
258
|
+
typeof error === 'object' &&
|
|
259
|
+
error !== null &&
|
|
260
|
+
Object.keys(error).length === 0 &&
|
|
261
|
+
!(error instanceof Error);
|
|
262
|
+
|
|
263
|
+
if (isEmptyError) {
|
|
264
|
+
logger.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
265
|
+
topic: params.topic?.substring(0, 16) + '...',
|
|
266
|
+
});
|
|
267
|
+
throw new Error('WalletConnect connection issue - please try again');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const errorMsg = extractErrorMessage(error);
|
|
271
|
+
logger.error('Sign failed', { error: errorMsg });
|
|
272
|
+
throw new Error(`XRPL sign failed: ${errorMsg}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Sign and submit an XRPL transaction to the network.
|
|
278
|
+
* Uses xrpl_signAndSubmit method with JSON transaction object.
|
|
279
|
+
*
|
|
280
|
+
* @param params - Submission parameters
|
|
281
|
+
* @returns Promise resolving to transaction hash and metadata
|
|
282
|
+
*/
|
|
283
|
+
async submitTransaction(params: SignerOperationParams): Promise<SubmitResult> {
|
|
284
|
+
// Decode base64 payload to JSON transaction
|
|
285
|
+
const transaction = XrplTransactionEncoder.decodeTransaction(params.payload);
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
logger.debug('Sending xrpl_signAndSubmit request to wallet', {
|
|
289
|
+
method: 'xrpl_signAndSubmit',
|
|
290
|
+
chainId: params.networkId,
|
|
291
|
+
topic: params.topic?.substring(0, 16) + '...',
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Use 5-minute expiry to give users time to review and approve
|
|
295
|
+
const result = await params.client.request({
|
|
296
|
+
topic: params.topic,
|
|
297
|
+
chainId: params.networkId,
|
|
298
|
+
request: {
|
|
299
|
+
method: 'xrpl_signAndSubmit',
|
|
300
|
+
params: {
|
|
301
|
+
transaction, // Native JSON object
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
expiry: 300, // 5 minutes in seconds
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
logger.debug('Received xrpl_signAndSubmit response', {
|
|
308
|
+
hasResult: !!result,
|
|
309
|
+
resultKeys: result ? Object.keys(result as object) : [],
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
transactionId:
|
|
314
|
+
(result as { hash?: string }).hash ||
|
|
315
|
+
(result as { tx_json?: { hash?: string } }).tx_json?.hash ||
|
|
316
|
+
'',
|
|
317
|
+
transactionHash: (result as { hash?: string }).hash,
|
|
318
|
+
metadata: { result },
|
|
319
|
+
};
|
|
320
|
+
} catch (error) {
|
|
321
|
+
// Check if this is an empty error object (WalletConnect SDK bug)
|
|
322
|
+
// This typically happens when relay subscription is stale
|
|
323
|
+
const isEmptyError =
|
|
324
|
+
typeof error === 'object' &&
|
|
325
|
+
error !== null &&
|
|
326
|
+
Object.keys(error).length === 0 &&
|
|
327
|
+
!(error instanceof Error);
|
|
328
|
+
|
|
329
|
+
if (isEmptyError) {
|
|
330
|
+
// Empty error object is a known WalletConnect SDK issue
|
|
331
|
+
// It usually means the relay subscription was stale
|
|
332
|
+
logger.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
333
|
+
topic: params.topic?.substring(0, 16) + '...',
|
|
334
|
+
hint: 'This can happen when the relay WebSocket connection drops',
|
|
335
|
+
});
|
|
336
|
+
throw new Error('WalletConnect connection issue - please try again');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const errorMsg = extractErrorMessage(error);
|
|
340
|
+
logger.error('Submit failed', { error: errorMsg });
|
|
341
|
+
throw new Error(`XRPL submit failed: ${errorMsg}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Sign and execute a transaction in one call (preferred method to avoid double prompts).
|
|
347
|
+
* Uses xrpl_signAndSubmit method directly instead of sign-then-submit.
|
|
348
|
+
*
|
|
349
|
+
* @param params - Transaction parameters
|
|
350
|
+
* @returns Promise resolving to transaction hash and metadata
|
|
351
|
+
*/
|
|
352
|
+
async signAndExecuteTransaction(params: SignerOperationParams): Promise<SubmitResult> {
|
|
353
|
+
// XRPL's xrpl_signAndSubmit method handles both signing and submission
|
|
354
|
+
// This is the preferred method for XRPL transactions
|
|
355
|
+
return this.submitTransaction(params);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Sign an arbitrary message using xrpl_signMessage method.
|
|
360
|
+
* Used for DAO votes, authentication proofs, and other non-transaction signing.
|
|
361
|
+
*
|
|
362
|
+
* @param params - Signing parameters with message string
|
|
363
|
+
* @returns Promise resolving to signature and metadata
|
|
364
|
+
*/
|
|
365
|
+
async signMessage(
|
|
366
|
+
params: SignerOperationParams & { message: string; encoding?: 'utf-8' | 'base64' },
|
|
367
|
+
): Promise<import('../../base-wallet-provider').SignMessageResult> {
|
|
368
|
+
try {
|
|
369
|
+
// Use 5-minute expiry to give users time to review and approve
|
|
370
|
+
const result = await params.client.request({
|
|
371
|
+
topic: params.topic,
|
|
372
|
+
chainId: params.networkId,
|
|
373
|
+
request: {
|
|
374
|
+
method: 'xrpl_signMessage',
|
|
375
|
+
params: {
|
|
376
|
+
message: params.message, // Can be base64 or utf-8
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
expiry: 300, // 5 minutes in seconds
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
return {
|
|
383
|
+
signature: (result as { signature?: string }).signature || JSON.stringify(result),
|
|
384
|
+
publicKey: (result as { publicKey?: string }).publicKey,
|
|
385
|
+
metadata: { result },
|
|
386
|
+
};
|
|
387
|
+
} catch (error) {
|
|
388
|
+
// Check if this is an empty error object (WalletConnect SDK bug)
|
|
389
|
+
const isEmptyError =
|
|
390
|
+
typeof error === 'object' &&
|
|
391
|
+
error !== null &&
|
|
392
|
+
Object.keys(error).length === 0 &&
|
|
393
|
+
!(error instanceof Error);
|
|
394
|
+
|
|
395
|
+
if (isEmptyError) {
|
|
396
|
+
logger.warn('WalletConnect SDK empty error - relay subscription may have been stale', {
|
|
397
|
+
topic: params.topic?.substring(0, 16) + '...',
|
|
398
|
+
});
|
|
399
|
+
throw new Error('WalletConnect connection issue - please try again');
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const errorMsg = extractErrorMessage(error);
|
|
403
|
+
logger.error('Sign message failed', { error: errorMsg });
|
|
404
|
+
throw new Error(`XRPL sign message failed: ${errorMsg}`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Parse accounts from XRPL namespace in WalletConnect session.
|
|
410
|
+
* Extracts addresses from XRPL format: xrpl:<network>:rAddress...
|
|
411
|
+
*
|
|
412
|
+
* Optionally filters accounts to only include those matching a target network.
|
|
413
|
+
* This is important for respecting the user's network selection in the dApp.
|
|
414
|
+
*
|
|
415
|
+
* @param namespace - XRPL namespace object from session
|
|
416
|
+
* @param targetNetworkId - Optional network ID to filter accounts (e.g., 'xrpl:mainnet')
|
|
417
|
+
* @returns Array of parsed account objects, filtered by target network if specified
|
|
418
|
+
*/
|
|
419
|
+
parseAccounts(
|
|
420
|
+
namespace: any,
|
|
421
|
+
targetNetworkId?: string,
|
|
422
|
+
): Array<{ address: string; chainId: string }> {
|
|
423
|
+
if (
|
|
424
|
+
!(namespace as { accounts?: string[] })?.accounts ||
|
|
425
|
+
!Array.isArray((namespace as { accounts?: string[] }).accounts)
|
|
426
|
+
) {
|
|
427
|
+
return [];
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Parse all accounts from namespace
|
|
431
|
+
const allAccounts = ((namespace as { accounts?: string[] }).accounts || []).map(
|
|
432
|
+
(account: string) => {
|
|
433
|
+
// XRPL format: xrpl:testnet:rN7n7otQDd6FczFgLdlqtyMVrn3WnFBrDB
|
|
434
|
+
const parts = account.split(':');
|
|
435
|
+
|
|
436
|
+
if (parts.length < 3) {
|
|
437
|
+
logger.warn('Invalid account format', { account });
|
|
438
|
+
return { address: account, chainId: 'xrpl:testnet' };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return {
|
|
442
|
+
address: parts[parts.length - 1], // rAddress
|
|
443
|
+
chainId: `${parts[0]}:${parts[1]}`, // xrpl:testnet
|
|
444
|
+
};
|
|
445
|
+
},
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
// If target network specified, filter accounts to only that network
|
|
449
|
+
if (targetNetworkId) {
|
|
450
|
+
const targetNetwork = targetNetworkId.split(':')[1]?.toLowerCase(); // e.g., 'mainnet'
|
|
451
|
+
|
|
452
|
+
if (targetNetwork) {
|
|
453
|
+
const filteredAccounts = allAccounts.filter((acc) =>
|
|
454
|
+
acc.chainId.toLowerCase().includes(targetNetwork),
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
logger.debug('Filtered accounts by target network', {
|
|
458
|
+
targetNetworkId,
|
|
459
|
+
targetNetwork,
|
|
460
|
+
totalAccounts: allAccounts.length,
|
|
461
|
+
filteredCount: filteredAccounts.length,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// If no accounts match the target network, log a warning
|
|
465
|
+
if (filteredAccounts.length === 0 && allAccounts.length > 0) {
|
|
466
|
+
logger.warn('No accounts found for target network', {
|
|
467
|
+
targetNetwork,
|
|
468
|
+
availableNetworks: [...new Set(allAccounts.map((a) => a.chainId))],
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return filteredAccounts;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return allAccounts;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
}
|