@meshconnect/uwc-core 0.7.4 → 0.7.5-snapshot.3e19fe0

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 (50) hide show
  1. package/README.md +924 -0
  2. package/dist/events.d.ts +71 -0
  3. package/dist/events.d.ts.map +1 -0
  4. package/dist/events.js +2 -0
  5. package/dist/events.js.map +1 -0
  6. package/dist/index.d.ts +2 -3
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -3
  9. package/dist/index.js.map +1 -1
  10. package/dist/managers/event-manager.d.ts +22 -3
  11. package/dist/managers/event-manager.d.ts.map +1 -1
  12. package/dist/managers/event-manager.js +63 -7
  13. package/dist/managers/event-manager.js.map +1 -1
  14. package/dist/services/connection-service.d.ts +5 -2
  15. package/dist/services/connection-service.d.ts.map +1 -1
  16. package/dist/services/connection-service.js +19 -7
  17. package/dist/services/connection-service.js.map +1 -1
  18. package/dist/services/network-switch-service.d.ts +2 -1
  19. package/dist/services/network-switch-service.d.ts.map +1 -1
  20. package/dist/services/network-switch-service.js +15 -3
  21. package/dist/services/network-switch-service.js.map +1 -1
  22. package/dist/services/signature-service.d.ts +3 -1
  23. package/dist/services/signature-service.d.ts.map +1 -1
  24. package/dist/services/signature-service.js +10 -5
  25. package/dist/services/signature-service.js.map +1 -1
  26. package/dist/services/transaction-service.d.ts +3 -1
  27. package/dist/services/transaction-service.d.ts.map +1 -1
  28. package/dist/services/transaction-service.js +10 -5
  29. package/dist/services/transaction-service.js.map +1 -1
  30. package/dist/services/wallet-capabilities-service.d.ts +2 -1
  31. package/dist/services/wallet-capabilities-service.d.ts.map +1 -1
  32. package/dist/services/wallet-capabilities-service.js +9 -2
  33. package/dist/services/wallet-capabilities-service.js.map +1 -1
  34. package/dist/universal-wallet-connector.d.ts +46 -6
  35. package/dist/universal-wallet-connector.d.ts.map +1 -1
  36. package/dist/universal-wallet-connector.js +171 -62
  37. package/dist/universal-wallet-connector.js.map +1 -1
  38. package/package.json +5 -5
  39. package/src/events.ts +73 -0
  40. package/src/index.ts +11 -3
  41. package/src/managers/event-manager.test.ts +70 -0
  42. package/src/managers/event-manager.ts +80 -9
  43. package/src/services/connection-service.test.ts +11 -3
  44. package/src/services/connection-service.ts +34 -7
  45. package/src/services/network-switch-service.ts +22 -3
  46. package/src/services/signature-service.ts +13 -5
  47. package/src/services/transaction-service.ts +13 -5
  48. package/src/services/wallet-capabilities-service.ts +14 -2
  49. package/src/universal-wallet-connector.test.ts +87 -3
  50. package/src/universal-wallet-connector.ts +254 -66
@@ -12,9 +12,11 @@ export class TransactionService {
12
12
  * Send a transaction with the currently connected wallet
13
13
  * @param request The transaction request parameters
14
14
  * @param provider The wallet provider to use for sending (required for injected connector)
15
+ * @param options Optional cancellation signal
15
16
  * @returns A promise that resolves to the transaction result
16
17
  */
17
- async sendTransaction(request, provider) {
18
+ async sendTransaction(request, provider, options) {
19
+ options?.signal?.throwIfAborted();
18
20
  const session = this.sessionManager.getSession();
19
21
  if (!session.connectionMode) {
20
22
  throw new Error('No active connection');
@@ -32,25 +34,28 @@ export class TransactionService {
32
34
  throw new Error(`Connector does not support transactions`);
33
35
  }
34
36
  // Call the connector's sendTransaction method with the appropriate provider
37
+ let result;
35
38
  if (session.connectionMode === 'injected') {
36
39
  if (!provider) {
37
40
  throw new Error('Provider is required for injected connector');
38
41
  }
39
- return await connector.sendTransaction(request, provider);
42
+ result = await connector.sendTransaction(request, provider);
40
43
  }
41
44
  else if (session.connectionMode === 'tonConnect') {
42
- return await connector.sendTransaction(request);
45
+ result = await connector.sendTransaction(request);
43
46
  }
44
47
  else if (session.connectionMode === 'walletConnect') {
45
48
  if (!provider) {
46
49
  throw new Error('Provider is required for WalletConnect connector');
47
50
  }
48
- return await connector.sendTransaction(request, provider);
51
+ result = await connector.sendTransaction(request, provider);
49
52
  }
50
53
  else {
51
54
  // For other connectors that might not need the provider
52
- return await connector.sendTransaction(request);
55
+ result = await connector.sendTransaction(request);
53
56
  }
57
+ options?.signal?.throwIfAborted();
58
+ return result;
54
59
  }
55
60
  }
56
61
  //# sourceMappingURL=transaction-service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../src/services/transaction-service.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAEnB;IACA;IAFV,YACU,cAA8B,EAC9B,UAA0C;QAD1C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,eAAU,GAAV,UAAU,CAAgC;IACjD,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CACnB,OAA2B,EAC3B,QAA4B;QAE5B,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAA;QAEhD,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,gCAAgC;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAC7D,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,2CAA2C,OAAO,CAAC,cAAc,EAAE,CACpE,CAAA;QACH,CAAC;QAED,+CAA+C;QAC/C,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;QAC5D,CAAC;QAED,4EAA4E;QAC5E,IAAI,OAAO,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;YAChE,CAAC;YACD,OAAO,MAAM,SAAS,CAAC,eAAe,CACpC,OAAO,EACP,QAEqC,CACtC,CAAA;QACH,CAAC;aAAM,IAAI,OAAO,CAAC,cAAc,KAAK,YAAY,EAAE,CAAC;YACnD,OAAO,MAAM,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QACjD,CAAC;aAAM,IAAI,OAAO,CAAC,cAAc,KAAK,eAAe,EAAE,CAAC;YACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;YACrE,CAAC;YACD,OAAO,MAAM,SAAS,CAAC,eAAe,CACpC,OAAO,EACP,QAAiC,CAClC,CAAA;QACH,CAAC;aAAM,CAAC;YACN,wDAAwD;YACxD,OAAO,MAAM,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../src/services/transaction-service.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAEnB;IACA;IAFV,YACU,cAA8B,EAC9B,UAA0C;QAD1C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,eAAU,GAAV,UAAU,CAAgC;IACjD,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CACnB,OAA2B,EAC3B,QAA4B,EAC5B,OAAwB;QAExB,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAA;QAEhD,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,gCAAgC;QAChC,MAAM,SAA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wc-types';
2
2
  import type { SessionManager } from '../managers/session-manager';
3
3
  import type { EventManager } from '../managers/event-manager';
4
+ import type { ServiceOptions } from './connection-service';
4
5
  export declare class WalletCapabilitiesService {
5
6
  private networks;
6
7
  private connectors;
7
8
  private sessionManager;
8
9
  private eventManager;
9
10
  constructor(networks: Network[], connectors: Map<ConnectionMode, Connector>, sessionManager: SessionManager, eventManager: EventManager);
10
- getWalletCapabilities(address: string, activeNetwork?: Network): Promise<void>;
11
+ getWalletCapabilities(address: string, activeNetwork?: Network, options?: ServiceOptions): Promise<void>;
11
12
  }
12
13
  //# sourceMappingURL=wallet-capabilities-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-capabilities-service.d.ts","sourceRoot":"","sources":["../../src/services/wallet-capabilities-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,SAAS,EAEV,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,qBAAa,yBAAyB;IAElC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,YAAY;gBAHZ,QAAQ,EAAE,OAAO,EAAE,EACnB,UAAU,EAAE,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,EAC1C,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY;IAG9B,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,IAAI,CAAC;CAwDjB"}
1
+ {"version":3,"file":"wallet-capabilities-service.d.ts","sourceRoot":"","sources":["../../src/services/wallet-capabilities-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,SAAS,EAEV,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,qBAAa,yBAAyB;IAElC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,YAAY;gBAHZ,QAAQ,EAAE,OAAO,EAAE,EACnB,UAAU,EAAE,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,EAC1C,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY;IAG9B,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,OAAO,EACvB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC;CAkEjB"}
@@ -9,7 +9,8 @@ export class WalletCapabilitiesService {
9
9
  this.sessionManager = sessionManager;
10
10
  this.eventManager = eventManager;
11
11
  }
12
- async getWalletCapabilities(address, activeNetwork) {
12
+ async getWalletCapabilities(address, activeNetwork, options) {
13
+ options?.signal?.throwIfAborted();
13
14
  let activeWalletCapabilities = {};
14
15
  let activeNetworkWalletCapabilities = {};
15
16
  const session = this.sessionManager.getSession();
@@ -30,6 +31,7 @@ export class WalletCapabilitiesService {
30
31
  catch {
31
32
  capabilities = {};
32
33
  }
34
+ options?.signal?.throwIfAborted();
33
35
  // keep only supported networks
34
36
  activeWalletCapabilities = Object.fromEntries(Object.entries(capabilities).filter(([networkId, _]) => this.networks.some(n => n.id === networkId)));
35
37
  if (activeNetwork) {
@@ -46,7 +48,12 @@ export class WalletCapabilitiesService {
46
48
  activeNetworkWalletCapabilities: null
47
49
  });
48
50
  }
49
- this.eventManager.notify();
51
+ this.eventManager.emit('capabilitiesUpdated', {
52
+ capabilities: activeWalletCapabilities
53
+ });
54
+ this.eventManager.emit('sessionChanged', {
55
+ session: this.sessionManager.getSession()
56
+ });
50
57
  }
51
58
  }
52
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-capabilities-service.js","sourceRoot":"","sources":["../../src/services/wallet-capabilities-service.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,yBAAyB;IAE1B;IACA;IACA;IACA;IAJV,YACU,QAAmB,EACnB,UAA0C,EAC1C,cAA8B,EAC9B,YAA0B;QAH1B,aAAQ,GAAR,QAAQ,CAAW;QACnB,eAAU,GAAV,UAAU,CAAgC;QAC1C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ,KAAK,CAAC,qBAAqB,CACzB,OAAe,EACf,aAAuB;QAEvB,IAAI,wBAAwB,GAAoC,EAAE,CAAA;QAClE,IAAI,+BAA+B,GAAoB,EAAE,CAAA;QAEzD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAA;QAEhD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;QACrE,CAAC;QAED,kCAAkC;QAClC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;QAED,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAEnE,IACE,eAAe;YACf,OAAO,eAAe,CAAC,qBAAqB,KAAK,UAAU,EAC3D,CAAC;YACD,IAAI,YAA6C,CAAA;YACjD,IAAI,CAAC;gBACH,YAAY,GAAG,MAAM,eAAe,CAAC,qBAAqB,CACxD,OAAO,EACP,IAAI,CAAC,QAAQ,CACd,CAAA;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY,GAAG,EAAE,CAAA;YACnB,CAAC;YAED,+BAA+B;YAC/B,wBAAwB,GAAG,MAAM,CAAC,WAAW,CAC3C,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CACrD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAC5C,CACF,CAAA;YAED,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAC9D,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,IAAI,aAAa,CAAC,EAAE,CAC/C,CAAA;gBACD,+BAA+B,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACjE,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;oBAChC,wBAAwB,EAAE,wBAAwB;oBAClD,+BAA+B,EAAE,+BAA+B;iBACjE,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;oBAChC,wBAAwB,EAAE,wBAAwB;oBAClD,+BAA+B,EAAE,IAAI;iBACtC,CAAC,CAAA;YACJ,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAA;QAC5B,CAAC;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"wallet-capabilities-service.js","sourceRoot":"","sources":["../../src/services/wallet-capabilities-service.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,yBAAyB;IAE1B;IACA;IACA;IACA;IAJV,YACU,QAAmB,EACnB,UAA0C,EAC1C,cAA8B,EAC9B,YAA0B;QAH1B,aAAQ,GAAR,QAAQ,CAAW;QACnB,eAAU,GAAV,UAAU,CAAgC;QAC1C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;IACjC,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M,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAC9D,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,IAAI,aAAa,CAAC,EAAE,CAC/C,CAAA;gBACD,+BAA+B,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACjE,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;oBAChC,wBAAwB,EAAE,wBAAwB;oBAClD,+BAA+B,EAAE,+BAA+B;iBACjE,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;oBAChC,wBAAwB,EAAE,wBAAwB;oBAClD,+BAA+B,EAAE,IAAI;iBACtC,CAAC,CAAA;YACJ,CAAC;YAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,qBAAqB,EAAE;gBAC5C,YAAY,EAAE,wBAAwB;aACvC,CAAC,CAAA;YACF,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBACvC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE;aAC1C,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -1,5 +1,23 @@
1
1
  import type { UniversalWalletConnectorState, Network, WalletMetadata, NetworkId, ConnectionMode, WalletConnectConfig, TonConnectConfig, TransactionRequest, TransactionResult, EVMCapabilities, SignatureType } from '@meshconnect/uwc-types';
2
+ import type { UWCEventName, UWCEventListener } from './events';
3
+ /**
4
+ * Configuration object form of the UniversalWalletConnector constructor.
5
+ * Prefer this over the positional constructor in new code.
6
+ */
7
+ export interface UWCConfig {
8
+ networks: Network[];
9
+ wallets?: WalletMetadata[];
10
+ usingIntegratedBrowser?: boolean;
11
+ walletConnectConfig?: WalletConnectConfig;
12
+ tonConnectConfig?: TonConnectConfig;
13
+ }
14
+ /** Common options for user-initiated async operations. */
15
+ export interface OperationOptions {
16
+ /** Abort the operation if the signal fires. State mutations are skipped after abort. */
17
+ signal?: AbortSignal;
18
+ }
2
19
  export declare class UniversalWalletConnector {
20
+ private static instance;
3
21
  private static instanceCount;
4
22
  private static hasWarnedAboutMultipleInstances;
5
23
  private sessionManager;
@@ -15,6 +33,15 @@ export declare class UniversalWalletConnector {
15
33
  private usingIntegratedBrowser;
16
34
  private detectionComplete;
17
35
  private networkRpcMap;
36
+ /**
37
+ * Recommended entry point: returns the shared instance, creating it on the
38
+ * first call. Subsequent calls ignore the `config` argument — use
39
+ * `resetInstance()` first if you need to reinitialise (e.g. in tests).
40
+ */
41
+ static getInstance(config?: UWCConfig): UniversalWalletConnector;
42
+ /** Clear the shared instance reference. Primarily for tests and full-logout flows. */
43
+ static resetInstance(): void;
44
+ constructor(config: UWCConfig);
18
45
  constructor(networks: Network[], wallets?: WalletMetadata[], usingIntegratedBrowser?: boolean, walletConnectConfig?: WalletConnectConfig, tonConnectConfig?: TonConnectConfig);
19
46
  /**
20
47
  * Discovers available wallets and updates the wallet metadata
@@ -22,14 +49,23 @@ export declare class UniversalWalletConnector {
22
49
  private initializeDetectedWallets;
23
50
  getSession(): import("@meshconnect/uwc-types").Session;
24
51
  isReady(): boolean;
52
+ /** Subscribe to a typed event. Returns an unsubscribe function. */
53
+ on<K extends UWCEventName>(event: K, listener: UWCEventListener<K>): () => void;
54
+ /** Subscribe once; the listener is removed after the first dispatch. */
55
+ once<K extends UWCEventName>(event: K, listener: UWCEventListener<K>): () => void;
56
+ off<K extends UWCEventName>(event: K, listener: UWCEventListener<K>): void;
57
+ /**
58
+ * @deprecated Prefer `on(eventName, listener)` for targeted updates.
59
+ * Subscribes to the catch-all `change` event.
60
+ */
25
61
  subscribe(listener: () => void): () => void;
26
62
  getState(): UniversalWalletConnectorState;
27
63
  getWallets(): WalletMetadata[];
28
64
  getNetworks(): Network[];
29
- connect(connectionMode: ConnectionMode, walletId: string, networkId?: NetworkId): Promise<void>;
65
+ connect(connectionMode: ConnectionMode, walletId: string, networkId?: NetworkId, options?: OperationOptions): Promise<void>;
30
66
  getConnectionURI(): string | undefined;
31
- disconnect(): Promise<void>;
32
- switchNetwork(networkId: NetworkId): Promise<void>;
67
+ disconnect(options?: OperationOptions): Promise<void>;
68
+ switchNetwork(networkId: NetworkId, options?: OperationOptions): Promise<void>;
33
69
  getNetworkSwitchLoadingState(): {
34
70
  isLoading: boolean;
35
71
  isWaitingForUserApproval: boolean;
@@ -37,22 +73,25 @@ export declare class UniversalWalletConnector {
37
73
  /**
38
74
  * Sign a message with the connected wallet
39
75
  * @param message The message to sign
76
+ * @param options Optional cancellation signal
40
77
  * @returns A promise that resolves to the signature
41
78
  */
42
- signMessage(message: string): Promise<SignatureType>;
79
+ signMessage(message: string, options?: OperationOptions): Promise<SignatureType>;
43
80
  /**
44
81
  * Send a transaction with the connected wallet
45
82
  * @param request The transaction request parameters
83
+ * @param options Optional cancellation signal
46
84
  * @returns A promise that resolves to the transaction result
47
85
  */
48
- sendTransaction(request: TransactionRequest): Promise<TransactionResult>;
86
+ sendTransaction(request: TransactionRequest, options?: OperationOptions): Promise<TransactionResult>;
49
87
  /**
50
88
  * Fetch wallet capabilities for the connected wallet
51
89
  * @param address The wallet address to fetch capabilities for
52
90
  * @param activeNetwork Optional network to set as the active network for capabilities
91
+ * @param options Optional cancellation signal
53
92
  * @returns A promise that resolves when capabilities are fetched and updated
54
93
  */
55
- getWalletCapabilities(address: string, activeNetwork?: Network): Promise<void>;
94
+ getWalletCapabilities(address: string, activeNetwork?: Network, options?: OperationOptions): Promise<void>;
56
95
  /**
57
96
  * Check if a connection mode is available for a specific wallet
58
97
  * @param connectionMode The connection mode to check
@@ -61,5 +100,6 @@ export declare class UniversalWalletConnector {
61
100
  */
62
101
  isConnectionModeAvailable(connectionMode: ConnectionMode, walletId: string): boolean;
63
102
  getActiveWalletCapabilities(): Record<string, EVMCapabilities> | null;
103
+ private emitError;
64
104
  }
65
105
  //# sourceMappingURL=universal-wallet-connector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"universal-wallet-connector.d.ts","sourceRoot":"","sources":["../src/universal-wallet-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,OAAO,EACP,cAAc,EACd,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAOhB,kBAAkB,EAClB,iBAAiB,EAEjB,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAA;AAa/B,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAI;IAChC,OAAO,CAAC,MAAM,CAAC,+BAA+B,CAAQ;IAEtD,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,yBAAyB,CAA2B;IAC5D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,aAAa,CAAe;gBAGlC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,cAAc,EAAO,EAC9B,sBAAsB,UAAQ,EAC9B,mBAAmB,CAAC,EAAE,mBAAmB,EACzC,gBAAgB,CAAC,EAAE,gBAAgB;IAkGrC;;OAEG;YACW,yBAAyB;IAkLvC,UAAU;IAIV,OAAO;IAIP,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAI3C,QAAQ,IAAI,6BAA6B;IAMzC,UAAU,IAAI,cAAc,EAAE;IAI9B,WAAW,IAAI,OAAO,EAAE;IAIlB,OAAO,CACX,cAAc,EA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,CAAC,IAAI,CAAC;IAahB;;;;;OAKG;IACH,yBAAyB,CACvB,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,MAAM,GACf,OAAO;IA8CV,2BAA2B,IAAI,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,IAAI;IAOrE,OAAO,CAAC,SAAS;CAUlB"}
@@ -1,3 +1,4 @@
1
+ import { WalletConnectorError } from '@meshconnect/uwc-types';
1
2
  import { InjectedConnector } from '@meshconnect/uwc-injected-connector';
2
3
  import { WalletConnectConnector } from '@meshconnect/uwc-wallet-connect-connector';
3
4
  import { TonConnectConnector } from '@meshconnect/uwc-ton-connector';
@@ -10,6 +11,7 @@ import { TransactionService } from './services/transaction-service';
10
11
  import { WalletCapabilitiesService } from './services/wallet-capabilities-service';
11
12
  import { createNetworkRpcMap } from './utils/network-rpc-utils';
12
13
  export class UniversalWalletConnector {
14
+ static instance = null;
13
15
  static instanceCount = 0;
14
16
  static hasWarnedAboutMultipleInstances = false;
15
17
  sessionManager;
@@ -25,48 +27,93 @@ export class UniversalWalletConnector {
25
27
  usingIntegratedBrowser;
26
28
  detectionComplete = false;
27
29
  networkRpcMap;
28
- constructor(networks, wallets = [], usingIntegratedBrowser = false, walletConnectConfig, tonConnectConfig) {
29
- // Track instance creation
30
+ /**
31
+ * Recommended entry point: returns the shared instance, creating it on the
32
+ * first call. Subsequent calls ignore the `config` argument — use
33
+ * `resetInstance()` first if you need to reinitialise (e.g. in tests).
34
+ */
35
+ static getInstance(config) {
36
+ if (UniversalWalletConnector.instance) {
37
+ return UniversalWalletConnector.instance;
38
+ }
39
+ if (!config) {
40
+ throw new Error('UniversalWalletConnector.getInstance() was called before an instance existed. Pass a config on the first call.');
41
+ }
42
+ return new UniversalWalletConnector(config);
43
+ }
44
+ /** Clear the shared instance reference. Primarily for tests and full-logout flows. */
45
+ static resetInstance() {
46
+ UniversalWalletConnector.instance = null;
47
+ UniversalWalletConnector.instanceCount = 0;
48
+ UniversalWalletConnector.hasWarnedAboutMultipleInstances = false;
49
+ }
50
+ constructor(networksOrConfig, wallets = [], usingIntegratedBrowser = false, walletConnectConfig, tonConnectConfig) {
51
+ if (!networksOrConfig) {
52
+ throw new Error('Universal Wallet Connector must be initialized with at least one network');
53
+ }
54
+ let config;
55
+ if (Array.isArray(networksOrConfig)) {
56
+ config = {
57
+ networks: networksOrConfig,
58
+ wallets,
59
+ usingIntegratedBrowser
60
+ };
61
+ if (walletConnectConfig) {
62
+ config.walletConnectConfig = walletConnectConfig;
63
+ }
64
+ if (tonConnectConfig) {
65
+ config.tonConnectConfig = tonConnectConfig;
66
+ }
67
+ }
68
+ else {
69
+ config = networksOrConfig;
70
+ }
71
+ const { networks, wallets: configuredWallets = [], usingIntegratedBrowser: configuredUsingIntegratedBrowser = false, walletConnectConfig: configuredWalletConnectConfig, tonConnectConfig: configuredTonConnectConfig } = config;
72
+ // Track instance creation and warn on duplicates
30
73
  UniversalWalletConnector.instanceCount++;
31
- // Warn about multiple instances
32
74
  if (UniversalWalletConnector.instanceCount > 1 &&
33
75
  !UniversalWalletConnector.hasWarnedAboutMultipleInstances) {
34
76
  // eslint-disable-next-line no-console
35
77
  console.error(`⚠️ WARNING: Multiple instances of UniversalWalletConnector detected (${UniversalWalletConnector.instanceCount} instances). ` +
36
78
  'This can lead to state inconsistencies and unexpected behavior. ' +
37
79
  'Please ensure you create only one instance and reuse it throughout your application. ' +
38
- 'Consider using a singleton pattern or a context provider. ' +
80
+ 'Use UniversalWalletConnector.getInstance(config) instead of `new` to guarantee a single instance. ' +
39
81
  'You can ignore this warning if you are using React Strict Mode, which intentionally mounts components twice in development to help identify side effects.');
40
82
  UniversalWalletConnector.hasWarnedAboutMultipleInstances = true;
41
83
  }
42
84
  if (!networks) {
43
85
  throw new Error('Universal Wallet Connector must be initialized with at least one network');
44
86
  }
45
- if (!wallets) {
87
+ if (!configuredWallets) {
46
88
  throw new Error('Universal Wallet Connector must be initialized with at least one wallet');
47
89
  }
48
- this.wallets = wallets;
49
- this.usingIntegratedBrowser = usingIntegratedBrowser;
90
+ this.wallets = configuredWallets;
91
+ this.usingIntegratedBrowser = configuredUsingIntegratedBrowser;
50
92
  // Create RPC map from networks
51
93
  this.networkRpcMap = createNetworkRpcMap(networks);
52
94
  // Initialize connectors with RPC map
53
95
  this.connectors = new Map();
54
- this.injectedConnector = new InjectedConnector(this.networkRpcMap, this.wallets, tonConnectConfig);
96
+ this.injectedConnector = new InjectedConnector(this.networkRpcMap, this.wallets, configuredTonConnectConfig);
55
97
  this.connectors.set('injected', this.injectedConnector);
56
- if (tonConnectConfig) {
57
- this.connectors.set('tonConnect', new TonConnectConnector(tonConnectConfig));
98
+ if (configuredTonConnectConfig) {
99
+ this.connectors.set('tonConnect', new TonConnectConnector(configuredTonConnectConfig));
58
100
  }
59
101
  // Only add WalletConnect connector if config is provided
60
- if (walletConnectConfig) {
61
- this.connectors.set('walletConnect', new WalletConnectConnector(walletConnectConfig, this.networkRpcMap));
102
+ if (configuredWalletConnectConfig) {
103
+ this.connectors.set('walletConnect', new WalletConnectConnector(configuredWalletConnectConfig, this.networkRpcMap));
62
104
  }
63
105
  this.sessionManager = new SessionManager();
64
106
  this.eventManager = new EventManager();
65
- this.connectionService = new ConnectionService(networks, this.wallets, this.sessionManager, this.connectors, usingIntegratedBrowser, this.eventManager);
66
- this.networkSwitchService = new NetworkSwitchService(networks, this.sessionManager, this.connectors, usingIntegratedBrowser, this.eventManager);
107
+ this.connectionService = new ConnectionService(networks, this.wallets, this.sessionManager, this.connectors, configuredUsingIntegratedBrowser, this.eventManager);
108
+ this.networkSwitchService = new NetworkSwitchService(networks, this.sessionManager, this.connectors, configuredUsingIntegratedBrowser, this.eventManager);
67
109
  this.signatureService = new SignatureService(this.sessionManager, this.connectors);
68
110
  this.transactionService = new TransactionService(this.sessionManager, this.connectors);
69
111
  this.walletCapabilitiesService = new WalletCapabilitiesService(networks, this.connectors, this.sessionManager, this.eventManager);
112
+ // Register as the shared instance so getInstance() works
113
+ // (only set if no instance exists, to avoid overwriting an earlier one)
114
+ if (!UniversalWalletConnector.instance) {
115
+ UniversalWalletConnector.instance = this;
116
+ }
70
117
  // Initialize detected wallets after services are created
71
118
  this.initializeDetectedWallets();
72
119
  }
@@ -211,13 +258,13 @@ export class UniversalWalletConnector {
211
258
  this.connectionService.updateWallets(this.wallets);
212
259
  // Mark detection as complete
213
260
  this.detectionComplete = true;
214
- // Notify listeners about the update
215
- this.eventManager.notify();
261
+ this.eventManager.emit('walletsDetected', { wallets: this.wallets });
262
+ this.eventManager.emit('ready', undefined);
216
263
  }
217
- catch {
218
- // Silently handle error during initialization
264
+ catch (error) {
219
265
  this.detectionComplete = true;
220
- this.eventManager.notify();
266
+ this.emitError(error, 'initialize');
267
+ this.eventManager.emit('ready', undefined);
221
268
  }
222
269
  }
223
270
  getSession() {
@@ -226,6 +273,22 @@ export class UniversalWalletConnector {
226
273
  isReady() {
227
274
  return this.detectionComplete;
228
275
  }
276
+ // ---- Event subscription ----
277
+ /** Subscribe to a typed event. Returns an unsubscribe function. */
278
+ on(event, listener) {
279
+ return this.eventManager.on(event, listener);
280
+ }
281
+ /** Subscribe once; the listener is removed after the first dispatch. */
282
+ once(event, listener) {
283
+ return this.eventManager.once(event, listener);
284
+ }
285
+ off(event, listener) {
286
+ this.eventManager.off(event, listener);
287
+ }
288
+ /**
289
+ * @deprecated Prefer `on(eventName, listener)` for targeted updates.
290
+ * Subscribes to the catch-all `change` event.
291
+ */
229
292
  subscribe(listener) {
230
293
  return this.eventManager.subscribe(listener);
231
294
  }
@@ -240,20 +303,35 @@ export class UniversalWalletConnector {
240
303
  getNetworks() {
241
304
  return this.connectionService.getNetworks();
242
305
  }
243
- async connect(connectionMode, walletId, networkId) {
244
- await this.connectionService.connect(connectionMode, walletId, networkId);
245
- this.eventManager.notify();
306
+ async connect(connectionMode, walletId, networkId, options) {
307
+ try {
308
+ await this.connectionService.connect(connectionMode, walletId, networkId, options);
309
+ }
310
+ catch (error) {
311
+ this.emitError(error, 'connect');
312
+ throw error;
313
+ }
246
314
  }
247
315
  getConnectionURI() {
248
316
  return this.connectionService.getConnectionURI();
249
317
  }
250
- async disconnect() {
251
- await this.connectionService.disconnect();
252
- this.eventManager.notify();
318
+ async disconnect(options) {
319
+ try {
320
+ await this.connectionService.disconnect(options);
321
+ }
322
+ catch (error) {
323
+ this.emitError(error, 'disconnect');
324
+ throw error;
325
+ }
253
326
  }
254
- async switchNetwork(networkId) {
255
- await this.networkSwitchService.switchNetwork(networkId);
256
- this.eventManager.notify();
327
+ async switchNetwork(networkId, options) {
328
+ try {
329
+ await this.networkSwitchService.switchNetwork(networkId, options);
330
+ }
331
+ catch (error) {
332
+ this.emitError(error, 'switchNetwork');
333
+ throw error;
334
+ }
257
335
  }
258
336
  getNetworkSwitchLoadingState() {
259
337
  return this.networkSwitchService.getLoadingState();
@@ -261,9 +339,10 @@ export class UniversalWalletConnector {
261
339
  /**
262
340
  * Sign a message with the connected wallet
263
341
  * @param message The message to sign
342
+ * @param options Optional cancellation signal
264
343
  * @returns A promise that resolves to the signature
265
344
  */
266
- async signMessage(message) {
345
+ async signMessage(message, options) {
267
346
  const session = this.sessionManager.getSession();
268
347
  if (!session.activeWallet) {
269
348
  throw new Error('No active wallet');
@@ -271,30 +350,37 @@ export class UniversalWalletConnector {
271
350
  if (!session.connectionMode) {
272
351
  throw new Error('No active connection');
273
352
  }
274
- // Get the provider from the active wallet based on connection mode
275
- let provider;
276
- if (session.connectionMode === 'injected') {
277
- provider = this.usingIntegratedBrowser
278
- ? session.activeWallet.integratedBrowserInjectedProvider
279
- : session.activeWallet.extensionInjectedProvider;
280
- }
281
- else if (session.connectionMode === 'walletConnect') {
282
- provider = session.activeWallet.walletConnectProvider;
283
- }
284
- else if (session.connectionMode === 'tonConnect') {
285
- return await this.signatureService.signMessage(message);
353
+ try {
354
+ // Get the provider from the active wallet based on connection mode
355
+ let provider;
356
+ if (session.connectionMode === 'injected') {
357
+ provider = this.usingIntegratedBrowser
358
+ ? session.activeWallet.integratedBrowserInjectedProvider
359
+ : session.activeWallet.extensionInjectedProvider;
360
+ }
361
+ else if (session.connectionMode === 'walletConnect') {
362
+ provider = session.activeWallet.walletConnectProvider;
363
+ }
364
+ else if (session.connectionMode === 'tonConnect') {
365
+ return await this.signatureService.signMessage(message, undefined, options);
366
+ }
367
+ if (!provider) {
368
+ throw new Error('No provider available for the active wallet');
369
+ }
370
+ return await this.signatureService.signMessage(message, provider, options);
286
371
  }
287
- if (!provider) {
288
- throw new Error('No provider available for the active wallet');
372
+ catch (error) {
373
+ this.emitError(error, 'signMessage');
374
+ throw error;
289
375
  }
290
- return await this.signatureService.signMessage(message, provider);
291
376
  }
292
377
  /**
293
378
  * Send a transaction with the connected wallet
294
379
  * @param request The transaction request parameters
380
+ * @param options Optional cancellation signal
295
381
  * @returns A promise that resolves to the transaction result
296
382
  */
297
- async sendTransaction(request) {
383
+ async sendTransaction(request, options) {
298
384
  const session = this.sessionManager.getSession();
299
385
  if (!session.activeWallet) {
300
386
  throw new Error('No active wallet');
@@ -302,32 +388,45 @@ export class UniversalWalletConnector {
302
388
  if (!session.connectionMode) {
303
389
  throw new Error('No active connection');
304
390
  }
305
- // Get the provider from the active wallet based on connection mode
306
- let provider;
307
- if (session.connectionMode === 'injected') {
308
- provider = this.usingIntegratedBrowser
309
- ? session.activeWallet.integratedBrowserInjectedProvider
310
- : session.activeWallet.extensionInjectedProvider;
311
- }
312
- else if (session.connectionMode === 'walletConnect') {
313
- provider = session.activeWallet.walletConnectProvider;
314
- }
315
- else if (session.connectionMode === 'tonConnect') {
316
- return await this.transactionService.sendTransaction(request);
391
+ try {
392
+ // Get the provider from the active wallet based on connection mode
393
+ let provider;
394
+ if (session.connectionMode === 'injected') {
395
+ provider = this.usingIntegratedBrowser
396
+ ? session.activeWallet.integratedBrowserInjectedProvider
397
+ : session.activeWallet.extensionInjectedProvider;
398
+ }
399
+ else if (session.connectionMode === 'walletConnect') {
400
+ provider = session.activeWallet.walletConnectProvider;
401
+ }
402
+ else if (session.connectionMode === 'tonConnect') {
403
+ return await this.transactionService.sendTransaction(request, undefined, options);
404
+ }
405
+ if (!provider) {
406
+ throw new Error('No provider available for the active wallet');
407
+ }
408
+ return await this.transactionService.sendTransaction(request, provider, options);
317
409
  }
318
- if (!provider) {
319
- throw new Error('No provider available for the active wallet');
410
+ catch (error) {
411
+ this.emitError(error, 'sendTransaction');
412
+ throw error;
320
413
  }
321
- return await this.transactionService.sendTransaction(request, provider);
322
414
  }
323
415
  /**
324
416
  * Fetch wallet capabilities for the connected wallet
325
417
  * @param address The wallet address to fetch capabilities for
326
418
  * @param activeNetwork Optional network to set as the active network for capabilities
419
+ * @param options Optional cancellation signal
327
420
  * @returns A promise that resolves when capabilities are fetched and updated
328
421
  */
329
- async getWalletCapabilities(address, activeNetwork) {
330
- return await this.walletCapabilitiesService.getWalletCapabilities(address, activeNetwork);
422
+ async getWalletCapabilities(address, activeNetwork, options) {
423
+ try {
424
+ return await this.walletCapabilitiesService.getWalletCapabilities(address, activeNetwork, options);
425
+ }
426
+ catch (error) {
427
+ this.emitError(error, 'getWalletCapabilities');
428
+ throw error;
429
+ }
331
430
  }
332
431
  /**
333
432
  * Check if a connection mode is available for a specific wallet
@@ -371,5 +470,15 @@ export class UniversalWalletConnector {
371
470
  const session = this.sessionManager.getSession();
372
471
  return session.activeWalletCapabilities;
373
472
  }
473
+ // ---- private helpers ----
474
+ emitError(error, operation) {
475
+ const walletError = error instanceof WalletConnectorError
476
+ ? { type: error.type, message: error.message }
477
+ : {
478
+ type: 'unknown',
479
+ message: error instanceof Error ? error.message : String(error)
480
+ };
481
+ this.eventManager.emit('error', { error: walletError, operation });
482
+ }
374
483
  }
375
484
  //# sourceMappingURL=universal-wallet-connector.js.map