@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,478 +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 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
|
-
}
|
|
@@ -1,159 +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 HTTP interceptor that attaches wallet-attributed auth headers.
|
|
13
|
-
*
|
|
14
|
-
* @module services/hsuite-auth-interceptor
|
|
15
|
-
*
|
|
16
|
-
* @description
|
|
17
|
-
* `HsuiteAuthInterceptor` automatically adds the active smart-host bearer token
|
|
18
|
-
* and wallet ledger identifier to outgoing HTTP requests. When a request fails
|
|
19
|
-
* with HTTP 401, it delegates recovery to {@link SmartSessionService} for a
|
|
20
|
-
* single re-login and retry.
|
|
21
|
-
*
|
|
22
|
-
* **Registration (standalone apps):**
|
|
23
|
-
* ```typescript
|
|
24
|
-
* provideHttpClient(withInterceptors([provideHsuiteAuthInterceptor()]))
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* **Registration (module-based apps):**
|
|
28
|
-
* ```typescript
|
|
29
|
-
* { provide: HTTP_INTERCEPTORS, useClass: HsuiteAuthInterceptor, multi: true }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import {
|
|
34
|
-
HttpErrorResponse,
|
|
35
|
-
HttpEvent,
|
|
36
|
-
HttpHandler,
|
|
37
|
-
HttpInterceptor,
|
|
38
|
-
HttpInterceptorFn,
|
|
39
|
-
HttpRequest,
|
|
40
|
-
} from '@angular/common/http';
|
|
41
|
-
import { inject, Injectable } from '@angular/core';
|
|
42
|
-
import { catchError, from, Observable, switchMap, throwError } from 'rxjs';
|
|
43
|
-
|
|
44
|
-
import { SmartSessionService } from './smart-session.service';
|
|
45
|
-
import { UnifiedWalletService } from './unified-wallet.service';
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Headers injected by the interceptor.
|
|
49
|
-
*/
|
|
50
|
-
export const HSUITE_AUTH_HEADER = 'Authorization';
|
|
51
|
-
export const HSUITE_LEDGER_HEADER = 'X-Ledger-Id';
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Functional HTTP interceptor that attaches wallet-attributed auth headers.
|
|
55
|
-
*
|
|
56
|
-
* @description
|
|
57
|
-
* Adds:
|
|
58
|
-
* - `Authorization: Bearer <token>` when {@link SmartSessionService.getBearer} returns a token
|
|
59
|
-
* - `X-Ledger-Id: <ledgerId>` when a wallet account is active
|
|
60
|
-
*
|
|
61
|
-
* On 401 responses, clears the stale bearer and retries once after re-login.
|
|
62
|
-
*
|
|
63
|
-
* @param req - The outgoing HTTP request
|
|
64
|
-
* @param next - The downstream request handler
|
|
65
|
-
* @returns Observable of HTTP events
|
|
66
|
-
*/
|
|
67
|
-
export const hsuiteAuthInterceptor: HttpInterceptorFn = (req, next) => {
|
|
68
|
-
const session = inject(SmartSessionService);
|
|
69
|
-
const wallet = inject(UnifiedWalletService);
|
|
70
|
-
|
|
71
|
-
const authenticated = appendAuthHeaders(req, session, wallet);
|
|
72
|
-
|
|
73
|
-
return next(authenticated).pipe(
|
|
74
|
-
catchError((error) => {
|
|
75
|
-
if (error instanceof HttpErrorResponse && error.status === 401) {
|
|
76
|
-
session.logout();
|
|
77
|
-
return from(session.login()).pipe(
|
|
78
|
-
switchMap(() => next(appendAuthHeaders(req, session, wallet))),
|
|
79
|
-
catchError((loginError) => throwError(() => loginError)),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
return throwError(() => error);
|
|
83
|
-
}),
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Class-based HTTP interceptor for module-based Angular apps.
|
|
89
|
-
*
|
|
90
|
-
* @description
|
|
91
|
-
* Provides the same behavior as {@link hsuiteAuthInterceptor} in a class form
|
|
92
|
-
* suitable for registration via `HTTP_INTERCEPTORS`.
|
|
93
|
-
*/
|
|
94
|
-
@Injectable({ providedIn: 'root' })
|
|
95
|
-
export class HsuiteAuthInterceptor implements HttpInterceptor {
|
|
96
|
-
private readonly session = inject(SmartSessionService);
|
|
97
|
-
private readonly wallet = inject(UnifiedWalletService);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Intercepts outgoing HTTP requests to attach wallet-attributed auth headers.
|
|
101
|
-
*
|
|
102
|
-
* @param req - The outgoing HTTP request
|
|
103
|
-
* @param next - The downstream request handler
|
|
104
|
-
* @returns Observable of HTTP events
|
|
105
|
-
*/
|
|
106
|
-
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
|
107
|
-
const authenticated = appendAuthHeaders(req, this.session, this.wallet);
|
|
108
|
-
|
|
109
|
-
return next.handle(authenticated).pipe(
|
|
110
|
-
catchError((error) => {
|
|
111
|
-
if (error instanceof HttpErrorResponse && error.status === 401) {
|
|
112
|
-
this.session.logout();
|
|
113
|
-
return from(this.session.login()).pipe(
|
|
114
|
-
switchMap(() => next.handle(appendAuthHeaders(req, this.session, this.wallet))),
|
|
115
|
-
catchError((loginError) => throwError(() => loginError)),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
return throwError(() => error);
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Helper that clones a request with the active auth headers attached.
|
|
126
|
-
*
|
|
127
|
-
* @param req - The outgoing HTTP request
|
|
128
|
-
* @param session - Smart session service for bearer lookup
|
|
129
|
-
* @param wallet - Unified wallet service for ledger ID lookup
|
|
130
|
-
* @returns The request cloned with Authorization and/or X-Ledger-Id headers
|
|
131
|
-
*/
|
|
132
|
-
function appendAuthHeaders(
|
|
133
|
-
req: HttpRequest<unknown>,
|
|
134
|
-
session: SmartSessionService,
|
|
135
|
-
wallet: UnifiedWalletService,
|
|
136
|
-
): HttpRequest<unknown> {
|
|
137
|
-
const bearer = session.getBearer();
|
|
138
|
-
const activeAccount = wallet.activeAccount();
|
|
139
|
-
const ledgerId = activeAccount?.ledgerId;
|
|
140
|
-
|
|
141
|
-
// Avoid mutating requests that already carry an Authorization header
|
|
142
|
-
if (!bearer && !ledgerId) {
|
|
143
|
-
return req;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const headers: Record<string, string> = {};
|
|
147
|
-
if (bearer && !req.headers.has(HSUITE_AUTH_HEADER)) {
|
|
148
|
-
headers[HSUITE_AUTH_HEADER] = `Bearer ${bearer}`;
|
|
149
|
-
}
|
|
150
|
-
if (ledgerId && !req.headers.has(HSUITE_LEDGER_HEADER)) {
|
|
151
|
-
headers[HSUITE_LEDGER_HEADER] = ledgerId;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (Object.keys(headers).length === 0) {
|
|
155
|
-
return req;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return req.clone({ setHeaders: headers });
|
|
159
|
-
}
|