@meshconnect/uwc-core 1.0.3 → 1.1.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.
Files changed (121) hide show
  1. package/README.md +247 -76
  2. package/dist/events.d.ts +241 -5
  3. package/dist/events.d.ts.map +1 -1
  4. package/dist/events.js +77 -1
  5. package/dist/events.js.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/logger/create-logger.d.ts +32 -0
  11. package/dist/logger/create-logger.d.ts.map +1 -0
  12. package/dist/logger/create-logger.js +79 -0
  13. package/dist/logger/create-logger.js.map +1 -0
  14. package/dist/managers/event-manager.d.ts.map +1 -1
  15. package/dist/managers/event-manager.js +5 -1
  16. package/dist/managers/event-manager.js.map +1 -1
  17. package/dist/observability/connect-observer.d.ts +33 -0
  18. package/dist/observability/connect-observer.d.ts.map +1 -0
  19. package/dist/observability/connect-observer.js +115 -0
  20. package/dist/observability/connect-observer.js.map +1 -0
  21. package/dist/observability/focus-tracker.d.ts +42 -0
  22. package/dist/observability/focus-tracker.d.ts.map +1 -0
  23. package/dist/observability/focus-tracker.js +57 -0
  24. package/dist/observability/focus-tracker.js.map +1 -0
  25. package/dist/observability/instrument-handoff.d.ts +54 -0
  26. package/dist/observability/instrument-handoff.d.ts.map +1 -0
  27. package/dist/observability/instrument-handoff.js +173 -0
  28. package/dist/observability/instrument-handoff.js.map +1 -0
  29. package/dist/observability/lifecycle-bridge.d.ts +69 -0
  30. package/dist/observability/lifecycle-bridge.d.ts.map +1 -0
  31. package/dist/observability/lifecycle-bridge.js +155 -0
  32. package/dist/observability/lifecycle-bridge.js.map +1 -0
  33. package/dist/observability/scrub.d.ts +31 -0
  34. package/dist/observability/scrub.d.ts.map +1 -0
  35. package/dist/observability/scrub.js +167 -0
  36. package/dist/observability/scrub.js.map +1 -0
  37. package/dist/observability/telemetry.d.ts +157 -0
  38. package/dist/observability/telemetry.d.ts.map +1 -0
  39. package/dist/observability/telemetry.js +373 -0
  40. package/dist/observability/telemetry.js.map +1 -0
  41. package/dist/services/connection-service.d.ts +23 -1
  42. package/dist/services/connection-service.d.ts.map +1 -1
  43. package/dist/services/connection-service.js +128 -19
  44. package/dist/services/connection-service.js.map +1 -1
  45. package/dist/services/network-switch-service.d.ts +2 -1
  46. package/dist/services/network-switch-service.d.ts.map +1 -1
  47. package/dist/services/network-switch-service.js +45 -16
  48. package/dist/services/network-switch-service.js.map +1 -1
  49. package/dist/services/signature-service.d.ts +14 -7
  50. package/dist/services/signature-service.d.ts.map +1 -1
  51. package/dist/services/signature-service.js +56 -58
  52. package/dist/services/signature-service.js.map +1 -1
  53. package/dist/services/transaction-service.d.ts +19 -5
  54. package/dist/services/transaction-service.d.ts.map +1 -1
  55. package/dist/services/transaction-service.js +55 -38
  56. package/dist/services/transaction-service.js.map +1 -1
  57. package/dist/universal-wallet-connector.d.ts +56 -1
  58. package/dist/universal-wallet-connector.d.ts.map +1 -1
  59. package/dist/universal-wallet-connector.js +207 -110
  60. package/dist/universal-wallet-connector.js.map +1 -1
  61. package/dist/utils/id.d.ts +2 -0
  62. package/dist/utils/id.d.ts.map +1 -0
  63. package/dist/utils/id.js +41 -0
  64. package/dist/utils/id.js.map +1 -0
  65. package/dist/utils/resolve-session-provider.d.ts +10 -0
  66. package/dist/utils/resolve-session-provider.d.ts.map +1 -0
  67. package/dist/utils/resolve-session-provider.js +21 -0
  68. package/dist/utils/resolve-session-provider.js.map +1 -0
  69. package/dist/utils/to-wallet-error.d.ts +35 -0
  70. package/dist/utils/to-wallet-error.d.ts.map +1 -0
  71. package/dist/utils/to-wallet-error.js +130 -0
  72. package/dist/utils/to-wallet-error.js.map +1 -0
  73. package/dist/utils/validate-wallet-session.d.ts +15 -0
  74. package/dist/utils/validate-wallet-session.d.ts.map +1 -0
  75. package/dist/utils/validate-wallet-session.js +29 -0
  76. package/dist/utils/validate-wallet-session.js.map +1 -0
  77. package/dist/version.d.ts +2 -0
  78. package/dist/version.d.ts.map +1 -0
  79. package/dist/version.js +3 -0
  80. package/dist/version.js.map +1 -0
  81. package/package.json +6 -6
  82. package/src/events.ts +326 -14
  83. package/src/index.ts +10 -0
  84. package/src/logger/create-logger.test.ts +126 -0
  85. package/src/logger/create-logger.ts +112 -0
  86. package/src/managers/event-manager.test.ts +55 -0
  87. package/src/managers/event-manager.ts +5 -1
  88. package/src/observability/connect-observer.test.ts +214 -0
  89. package/src/observability/connect-observer.ts +128 -0
  90. package/src/observability/focus-tracker.test.ts +191 -0
  91. package/src/observability/focus-tracker.ts +96 -0
  92. package/src/observability/instrument-handoff.test.ts +397 -0
  93. package/src/observability/instrument-handoff.ts +231 -0
  94. package/src/observability/lifecycle-bridge.test.ts +398 -0
  95. package/src/observability/lifecycle-bridge.ts +216 -0
  96. package/src/observability/scrub.test.ts +183 -0
  97. package/src/observability/scrub.ts +174 -0
  98. package/src/observability/telemetry.test.ts +549 -0
  99. package/src/observability/telemetry.ts +546 -0
  100. package/src/services/connection-service.test.ts +261 -1
  101. package/src/services/connection-service.ts +167 -38
  102. package/src/services/network-switch-service.test.ts +51 -1
  103. package/src/services/network-switch-service.ts +56 -24
  104. package/src/services/signature-service.test.ts +181 -76
  105. package/src/services/signature-service.ts +75 -85
  106. package/src/services/transaction-service.test.ts +270 -69
  107. package/src/services/transaction-service.ts +74 -51
  108. package/src/universal-wallet-connector.instrumentation-guard.test.ts +199 -0
  109. package/src/universal-wallet-connector.observability.test.ts +610 -0
  110. package/src/universal-wallet-connector.test.ts +27 -146
  111. package/src/universal-wallet-connector.ts +279 -142
  112. package/src/utils/id.test.ts +15 -0
  113. package/src/utils/id.ts +48 -0
  114. package/src/utils/resolve-session-provider.test.ts +54 -0
  115. package/src/utils/resolve-session-provider.ts +25 -0
  116. package/src/utils/to-wallet-error.test.ts +181 -0
  117. package/src/utils/to-wallet-error.ts +152 -0
  118. package/src/utils/validate-wallet-session.test.ts +77 -0
  119. package/src/utils/validate-wallet-session.ts +40 -0
  120. package/src/version.test.ts +11 -0
  121. package/src/version.ts +2 -0
@@ -65,7 +65,8 @@ const mockSignatureService = {
65
65
  }
66
66
 
67
67
  const mockTransactionService = {
68
- sendTransaction: vi.fn()
68
+ sendTransaction: vi.fn(),
69
+ signSolanaTransactionBytes: vi.fn()
69
70
  }
70
71
 
71
72
  // Mock the dependencies
@@ -513,16 +514,24 @@ describe('UniversalWalletConnector', () => {
513
514
 
514
515
  describe('error handling', () => {
515
516
  it('should handle signMessage errors gracefully', async () => {
517
+ // Validation lives in the (mocked-out) SignatureService now, so drive the
518
+ // failure from the service and assert the facade propagates it.
519
+ mockSignatureService.signMessage.mockRejectedValueOnce(
520
+ new Error('No active wallet')
521
+ )
516
522
  const connector = new UniversalWalletConnector(mockNetworks, mockWallets)
517
523
 
518
- // This should not throw an error, but should handle the case where session manager is not properly mocked
519
- await expect(connector.signMessage('test')).rejects.toThrow()
524
+ await expect(connector.signMessage('test')).rejects.toThrow(
525
+ 'No active wallet'
526
+ )
520
527
  })
521
528
 
522
529
  it('should handle sendTransaction errors gracefully', async () => {
530
+ mockTransactionService.sendTransaction.mockRejectedValueOnce(
531
+ new Error('No active wallet')
532
+ )
523
533
  const connector = new UniversalWalletConnector(mockNetworks, mockWallets)
524
534
 
525
- // This should not throw an error, but should handle the case where session manager is not properly mocked
526
535
  await expect(
527
536
  connector.sendTransaction({
528
537
  to: '0x123',
@@ -656,162 +665,34 @@ describe('UniversalWalletConnector', () => {
656
665
  })
657
666
 
658
667
  describe('signSolanaTransaction', () => {
659
- const SERIALIZED_TX = new Uint8Array([1, 2, 3, 4, 5])
660
- const SIGNED_TX = new Uint8Array([6, 7, 8, 9, 10])
661
-
662
- it('throws "No active wallet" when session has no activeWallet', async () => {
663
- mockSessionManager.getSession.mockReturnValue({
664
- connectionMode: 'injected',
665
- activeWallet: null,
666
- activeNetwork: null,
667
- activeAddress: null,
668
- availableNetworks: [],
669
- availableAddresses: [],
670
- activeWalletCapabilities: null
671
- })
672
- const uwc = new UniversalWalletConnector(mockNetworks, mockWallets)
673
-
674
- await expect(uwc.signSolanaTransaction(SERIALIZED_TX)).rejects.toThrow(
675
- 'No active wallet'
676
- )
677
- })
678
-
679
- it('throws "No active connection" when session has no connectionMode', async () => {
680
- mockSessionManager.getSession.mockReturnValue({
681
- connectionMode: null,
682
- activeWallet: mockWallets[0],
683
- activeNetwork: null,
684
- activeAddress: null,
685
- availableNetworks: [],
686
- availableAddresses: [],
687
- activeWalletCapabilities: null
688
- })
689
- const uwc = new UniversalWalletConnector(mockNetworks, mockWallets)
690
-
691
- await expect(uwc.signSolanaTransaction(SERIALIZED_TX)).rejects.toThrow(
692
- 'No active connection'
693
- )
694
- })
695
-
696
- it('throws "not supported" when the active connector lacks signSolanaTransactionBytes (tonConnect)', async () => {
697
- mockSessionManager.getSession.mockReturnValue({
698
- connectionMode: 'tonConnect',
699
- activeWallet: mockWallets[0],
700
- activeNetwork: null,
701
- activeAddress: null,
702
- availableNetworks: [],
703
- availableAddresses: [],
704
- activeWalletCapabilities: null
705
- })
706
- const uwc = new UniversalWalletConnector(
707
- mockNetworks,
708
- mockWallets,
709
- false,
710
- undefined,
711
- { manifestUrl: 'https://example.com/manifest.json' }
712
- )
713
-
714
- await expect(uwc.signSolanaTransaction(SERIALIZED_TX)).rejects.toThrow(
715
- 'signSolanaTransaction is not supported for connection mode "tonConnect"'
716
- )
717
- })
718
-
719
- it('throws "not supported" when connectionMode maps to no registered connector', async () => {
720
- // UWC built without walletConnect config — the connectors map has no
721
- // 'walletConnect' entry, so the lookup returns undefined.
722
- mockSessionManager.getSession.mockReturnValue({
723
- connectionMode: 'walletConnect' as any,
724
- activeWallet: mockWallets[0],
725
- activeNetwork: null,
726
- activeAddress: null,
727
- availableNetworks: [],
728
- availableAddresses: [],
729
- activeWalletCapabilities: null
730
- })
731
- const uwc = new UniversalWalletConnector(mockNetworks, mockWallets)
732
-
733
- await expect(uwc.signSolanaTransaction(SERIALIZED_TX)).rejects.toThrow(
734
- 'signSolanaTransaction is not supported for connection mode "walletConnect"'
735
- )
736
- })
737
-
738
- it('routes serializedTx to injected connector.signSolanaTransactionBytes', async () => {
739
- mockInjectedConnector.signSolanaTransactionBytes.mockResolvedValue(
668
+ // Validation, routing, and the sign-only invariant live in
669
+ // TransactionService.signSolanaTransactionBytes (transaction-service.test.ts).
670
+ // The facade only delegates and propagates.
671
+ it('delegates to TransactionService and propagates the signed bytes', async () => {
672
+ const SERIALIZED_TX = new Uint8Array([1, 2, 3, 4, 5])
673
+ const SIGNED_TX = new Uint8Array([6, 7, 8, 9, 10])
674
+ mockTransactionService.signSolanaTransactionBytes.mockResolvedValueOnce(
740
675
  SIGNED_TX
741
676
  )
742
- mockSessionManager.getSession.mockReturnValue({
743
- connectionMode: 'injected',
744
- activeWallet: mockWallets[0],
745
- activeNetwork: null,
746
- activeAddress: null,
747
- availableNetworks: [],
748
- availableAddresses: [],
749
- activeWalletCapabilities: null
750
- })
751
677
  const uwc = new UniversalWalletConnector(mockNetworks, mockWallets)
752
678
 
753
679
  const result = await uwc.signSolanaTransaction(SERIALIZED_TX)
754
680
 
755
681
  expect(
756
- mockInjectedConnector.signSolanaTransactionBytes
757
- ).toHaveBeenCalledOnce()
758
- expect(
759
- mockInjectedConnector.signSolanaTransactionBytes
760
- ).toHaveBeenCalledWith(SERIALIZED_TX)
761
- expect(result).toBe(SIGNED_TX)
762
- })
763
-
764
- it('routes serializedTx to walletConnect connector.signSolanaTransactionBytes', async () => {
765
- mockWalletConnectConnector.signSolanaTransactionBytes.mockResolvedValue(
766
- SIGNED_TX
767
- )
768
- mockSessionManager.getSession.mockReturnValue({
769
- connectionMode: 'walletConnect',
770
- activeWallet: mockWallets[0],
771
- activeNetwork: null,
772
- activeAddress: null,
773
- availableNetworks: [],
774
- availableAddresses: [],
775
- activeWalletCapabilities: null
776
- })
777
- const uwc = new UniversalWalletConnector(
778
- mockNetworks,
779
- mockWallets,
780
- false,
781
- mockWalletConnectConfig
782
- )
783
-
784
- const result = await uwc.signSolanaTransaction(SERIALIZED_TX)
785
-
786
- expect(
787
- mockWalletConnectConnector.signSolanaTransactionBytes
788
- ).toHaveBeenCalledOnce()
789
- expect(
790
- mockWalletConnectConnector.signSolanaTransactionBytes
682
+ mockTransactionService.signSolanaTransactionBytes
791
683
  ).toHaveBeenCalledWith(SERIALIZED_TX)
792
684
  expect(result).toBe(SIGNED_TX)
793
685
  })
794
686
 
795
- it('INVARIANT: injected connector.sendTransaction is never called on the sign-only path', async () => {
796
- const sendTx = vi.fn()
797
- ;(mockInjectedConnector as any).sendTransaction = sendTx
798
- mockInjectedConnector.signSolanaTransactionBytes.mockResolvedValue(
799
- SIGNED_TX
687
+ it('propagates a service rejection', async () => {
688
+ mockTransactionService.signSolanaTransactionBytes.mockRejectedValueOnce(
689
+ new Error('No active wallet')
800
690
  )
801
- mockSessionManager.getSession.mockReturnValue({
802
- connectionMode: 'injected',
803
- activeWallet: mockWallets[0],
804
- activeNetwork: null,
805
- activeAddress: null,
806
- availableNetworks: [],
807
- availableAddresses: [],
808
- activeWalletCapabilities: null
809
- })
810
691
  const uwc = new UniversalWalletConnector(mockNetworks, mockWallets)
811
692
 
812
- await uwc.signSolanaTransaction(SERIALIZED_TX)
813
-
814
- expect(sendTx).not.toHaveBeenCalled()
693
+ await expect(
694
+ uwc.signSolanaTransaction(new Uint8Array([1]))
695
+ ).rejects.toThrow('No active wallet')
815
696
  })
816
697
  })
817
698
  })