@rango-dev/provider-walletconnect-2 0.57.0 → 0.57.1-next.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 (122) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/adapter/adapter.d.ts +39 -0
  3. package/dist/adapter/adapter.d.ts.map +1 -0
  4. package/dist/adapter/index.d.ts +3 -0
  5. package/dist/adapter/index.d.ts.map +1 -0
  6. package/dist/adapter/modal-cache.d.ts +14 -0
  7. package/dist/adapter/modal-cache.d.ts.map +1 -0
  8. package/dist/adapter/modal.d.ts +25 -0
  9. package/dist/adapter/modal.d.ts.map +1 -0
  10. package/dist/adapter/networks.d.ts +60 -0
  11. package/dist/adapter/networks.d.ts.map +1 -0
  12. package/dist/adapter/provider-client.d.ts +3 -0
  13. package/dist/adapter/provider-client.d.ts.map +1 -0
  14. package/dist/adapter/registry.d.ts +4 -0
  15. package/dist/adapter/registry.d.ts.map +1 -0
  16. package/dist/adapter/session-cache.d.ts +17 -0
  17. package/dist/adapter/session-cache.d.ts.map +1 -0
  18. package/dist/adapter/task-queue.d.ts +11 -0
  19. package/dist/adapter/task-queue.d.ts.map +1 -0
  20. package/dist/chunk-GEAT645O.js +2 -0
  21. package/dist/chunk-GEAT645O.js.map +7 -0
  22. package/dist/constants.d.ts +4 -48
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/evm-3KFL5N77.js +2 -0
  25. package/dist/evm-3KFL5N77.js.map +7 -0
  26. package/dist/mod.d.ts +4 -0
  27. package/dist/mod.d.ts.map +1 -0
  28. package/dist/mod.js +2 -0
  29. package/dist/mod.js.map +7 -0
  30. package/dist/namespaces/evm/hooks.d.ts +18 -0
  31. package/dist/namespaces/evm/hooks.d.ts.map +1 -0
  32. package/dist/namespaces/evm/namespace.d.ts +4 -0
  33. package/dist/namespaces/evm/namespace.d.ts.map +1 -0
  34. package/dist/namespaces/subscriber.d.ts +24 -0
  35. package/dist/namespaces/subscriber.d.ts.map +1 -0
  36. package/dist/provider.d.ts +3 -0
  37. package/dist/provider.d.ts.map +1 -0
  38. package/dist/session/accounts.d.ts +17 -0
  39. package/dist/session/accounts.d.ts.map +1 -0
  40. package/dist/session/bip122.d.ts +23 -0
  41. package/dist/session/bip122.d.ts.map +1 -0
  42. package/dist/session/chain-state.d.ts +6 -0
  43. package/dist/session/chain-state.d.ts.map +1 -0
  44. package/dist/session/evm-chain.d.ts +29 -0
  45. package/dist/session/evm-chain.d.ts.map +1 -0
  46. package/dist/session/evm.d.ts +25 -0
  47. package/dist/session/evm.d.ts.map +1 -0
  48. package/dist/session/lifecycle.d.ts +30 -0
  49. package/dist/session/lifecycle.d.ts.map +1 -0
  50. package/dist/session/lookup.d.ts +6 -0
  51. package/dist/session/lookup.d.ts.map +1 -0
  52. package/dist/session/proposals.d.ts +27 -0
  53. package/dist/session/proposals.d.ts.map +1 -0
  54. package/dist/session/restore-cache.d.ts +6 -0
  55. package/dist/session/restore-cache.d.ts.map +1 -0
  56. package/dist/session/teardown.d.ts +24 -0
  57. package/dist/session/teardown.d.ts.map +1 -0
  58. package/dist/signer.d.ts +2 -2
  59. package/dist/signer.d.ts.map +1 -0
  60. package/dist/signers/evm.d.ts +6 -4
  61. package/dist/signers/evm.d.ts.map +1 -0
  62. package/dist/types.d.ts +28 -11
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/utils.d.ts +17 -0
  65. package/dist/utils.d.ts.map +1 -0
  66. package/dist/wcConstants.d.ts +61 -0
  67. package/dist/wcConstants.d.ts.map +1 -0
  68. package/package.json +18 -13
  69. package/readme.md +14 -2
  70. package/src/adapter/adapter.ts +289 -0
  71. package/src/adapter/index.ts +2 -0
  72. package/src/adapter/modal-cache.ts +23 -0
  73. package/src/adapter/modal.ts +121 -0
  74. package/src/adapter/networks.ts +85 -0
  75. package/src/adapter/provider-client.ts +13 -0
  76. package/src/adapter/registry.ts +17 -0
  77. package/src/adapter/session-cache.ts +38 -0
  78. package/src/adapter/task-queue.ts +32 -0
  79. package/src/constants.ts +41 -76
  80. package/src/mod.ts +10 -0
  81. package/src/namespaces/evm/hooks.ts +148 -0
  82. package/src/namespaces/evm/namespace.ts +102 -0
  83. package/src/namespaces/subscriber.ts +106 -0
  84. package/src/provider.ts +35 -0
  85. package/src/session/accounts.ts +44 -0
  86. package/src/session/bip122.ts +225 -0
  87. package/src/session/chain-state.ts +38 -0
  88. package/src/session/evm-chain.ts +185 -0
  89. package/src/session/evm.ts +198 -0
  90. package/src/session/lifecycle.ts +241 -0
  91. package/src/session/lookup.ts +54 -0
  92. package/src/session/proposals.ts +96 -0
  93. package/src/session/restore-cache.ts +38 -0
  94. package/src/session/teardown.ts +181 -0
  95. package/src/signer.ts +9 -17
  96. package/src/signers/evm.ts +19 -17
  97. package/src/types.ts +31 -12
  98. package/src/utils.ts +68 -0
  99. package/src/wcConstants.ts +94 -0
  100. package/dist/chunk-6V3WUFOU.js +0 -2
  101. package/dist/chunk-6V3WUFOU.js.map +0 -7
  102. package/dist/chunk-BPSEZJUF.js +0 -2
  103. package/dist/chunk-BPSEZJUF.js.map +0 -7
  104. package/dist/chunk-DXVBX5XQ.js +0 -2
  105. package/dist/chunk-DXVBX5XQ.js.map +0 -7
  106. package/dist/dist-6GI3ECE5.js +0 -139
  107. package/dist/dist-6GI3ECE5.js.map +0 -7
  108. package/dist/evm-3ID4XY4Y.js +0 -2
  109. package/dist/evm-3ID4XY4Y.js.map +0 -7
  110. package/dist/helpers.d.ts +0 -31
  111. package/dist/index.d.ts +0 -21
  112. package/dist/index.js +0 -2
  113. package/dist/index.js.map +0 -7
  114. package/dist/session.d.ts +0 -63
  115. package/dist/signers/solana.d.ts +0 -14
  116. package/dist/solana-MFA7C5XI.js +0 -2
  117. package/dist/solana-MFA7C5XI.js.map +0 -7
  118. package/src/helpers.ts +0 -238
  119. package/src/index.ts +0 -234
  120. package/src/session.ts +0 -376
  121. package/src/signers/solana.ts +0 -160
  122. package/src/wc-types.d.ts +0 -31
@@ -0,0 +1,24 @@
1
+ import type { SignClientInstance, WalletConnectNamespace } from '../types.js';
2
+ import type { ISignClient, SessionTypes } from '@walletconnect/types';
3
+ import type UniversalProvider from '@walletconnect/universal-provider';
4
+ export declare function hasActiveSession(client: ISignClient, topic: string): boolean;
5
+ export declare function hasActivePairing(client: SignClientInstance, topic: string): boolean;
6
+ export declare function expireWalletConnectTopic(client: SignClientInstance, topic: string): Promise<void>;
7
+ export declare function removeSessionRecord(client: SignClientInstance, session: SessionTypes.Struct): Promise<void>;
8
+ export declare function purgeOrphanedSessions(client: SignClientInstance): Promise<void>;
9
+ /**
10
+ * Drops pairings that no session is using.
11
+ *
12
+ * The inverse of {@link purgeOrphanedSessions}, and the only thing that collects
13
+ * them: a cancelled connect leaves behind the pairing `client.connect()` minted,
14
+ * and `cleanupPendingPairings` only unsubscribes pairings - it never deletes the
15
+ * record. Without this they accumulate in `client.pairing` and in storage for the
16
+ * lifetime of the origin.
17
+ *
18
+ * Only safe to call while no connect is in flight (the adapter's `#sessionQueue`
19
+ * guarantees that): a pairing awaiting its first approval has no session yet, so
20
+ * dropping it would kill that handshake.
21
+ */
22
+ export declare function purgeOrphanedPairings(client: SignClientInstance): Promise<void>;
23
+ export declare function cleanupStaleSessionsForNamespace(client: UniversalProvider['client'], namespace: WalletConnectNamespace): Promise<void>;
24
+ //# sourceMappingURL=teardown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teardown.d.ts","sourceRoot":"","sources":["../../src/session/teardown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,iBAAiB,MAAM,mCAAmC,CAAC;AAevE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAM5E;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,MAAM,GACZ,OAAO,CAET;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,MAAM,iBAkBd;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,YAAY,CAAC,MAAM,iBA8C7B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EACnC,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC,CAef"}
package/dist/signer.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { WCInstance } from './types.js';
2
1
  import type { SignerFactory } from 'rango-types';
3
- export default function getSigners(instance: WCInstance): Promise<SignerFactory>;
2
+ export default function getSigners(): Promise<SignerFactory>;
3
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAOjD,wBAA8B,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAoBjE"}
@@ -1,7 +1,7 @@
1
- import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
- import type { SessionTypes } from '@walletconnect/types';
1
+ import type { ISignClient, SessionTypes } from '@walletconnect/types';
3
2
  import type { EvmTransaction } from 'rango-types/mainApi';
4
3
  import { type GenericSigner } from 'rango-types';
4
+ type SessionGetter = () => SessionTypes.Struct | null;
5
5
  type WalletConnectEvmTx = {
6
6
  from?: string;
7
7
  to?: string;
@@ -15,8 +15,9 @@ type WalletConnectEvmTx = {
15
15
  };
16
16
  declare class EVMSigner implements GenericSigner<EvmTransaction> {
17
17
  private client;
18
- private session;
19
- constructor(client: SignClient, session: SessionTypes.Struct);
18
+ private getSession;
19
+ constructor(client: ISignClient, getSession: SessionGetter);
20
+ private get session();
20
21
  /**
21
22
  * Map Rango's EvmTransaction to WalletConnect eth_sendTransaction params.
22
23
  *
@@ -36,3 +37,4 @@ declare class EVMSigner implements GenericSigner<EvmTransaction> {
36
37
  private isNetworkAndAccountExistInSession;
37
38
  }
38
39
  export default EVMSigner;
40
+ //# sourceMappingURL=evm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/signers/evm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAOjD,KAAK,aAAa,GAAG,MAAM,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;AAEtD,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,SAAU,YAAW,aAAa,CAAC,cAAc,CAAC;IACtD,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,UAAU,CAAgB;gBAEtB,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa;IAK1D,OAAO,KAAK,OAAO,GAMlB;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,kBAAkB;IAgC5C,WAAW,CACtB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,CAAC;IAqCZ,aAAa,CACjB,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAuC5B,OAAO,CAAC,iCAAiC;CAgD1C;AAED,eAAe,SAAS,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,21 +1,38 @@
1
- import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
- import type { ProposalTypes, SessionTypes } from '@walletconnect/types';
1
+ import type { ProposalTypes } from '@walletconnect/types';
2
+ import type { ChainIdParams } from 'caip';
3
3
  import type { BlockchainMeta } from 'rango-types';
4
- export interface Environments extends Record<string, string | undefined> {
4
+ import { SignClient } from '@walletconnect/sign-client';
5
+ export { SignClient };
6
+ export type SignClientInstance = InstanceType<typeof SignClient>;
7
+ export interface Environments {
5
8
  WC_PROJECT_ID: string;
6
9
  DISABLE_MODAL_AND_OPEN_LINK?: string;
10
+ meta?: BlockchainMeta[];
11
+ themeMode?: 'light' | 'dark';
12
+ modalZIndex?: number;
7
13
  }
8
- export interface WCInstance {
9
- client: SignClient;
10
- session: SessionTypes.Struct | null;
11
- request: (params: any) => Promise<string>;
12
- }
14
+ export type WalletConnectNamespace = 'evm' | 'utxo';
13
15
  export interface CreateSessionParams {
14
- requiredNamespaces: ProposalTypes.RequiredNamespaces;
15
- optionalNamespaces?: ProposalTypes.OptionalNamespaces;
16
+ /**
17
+ * The whole proposal goes here - sign-client folds `requiredNamespaces` into
18
+ * this and clears it, so proposing anything as required is deprecated.
19
+ */
20
+ optionalNamespaces: ProposalTypes.OptionalNamespaces;
16
21
  pairingTopic?: string;
17
22
  }
18
23
  export interface ConnectParams {
19
- meta: BlockchainMeta[];
24
+ /**
25
+ * Chains to propose, as CAIP-2 ids. Callers convert rango `BlockchainMeta`
26
+ * at the boundary (see `evmMetaToCaipChainIds`) so the connect path stays
27
+ * decoupled from rango-types' chain shape.
28
+ */
29
+ chains: ChainIdParams[];
20
30
  envs: Environments;
31
+ namespace: WalletConnectNamespace;
32
+ /**
33
+ * Decimal EVM chain reference (e.g. `"137"`).
34
+ * When set, it is the only EVM chain proposed during session creation.
35
+ */
36
+ chainReference?: string;
21
37
  }
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,OAAO,UAAU,CAAC,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;IAEtB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,IAAI,CAAC,EAAE,cAAc,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,kBAAkB,EAAE,aAAa,CAAC,kBAAkB,CAAC;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,sBAAsB,CAAC;IAClC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,17 @@
1
+ import type { Chain } from '@hub3js/evm';
2
+ import type { ChainIdParams } from 'caip';
3
+ import type { BlockchainMeta } from 'rango-types';
4
+ export declare function utf8ToHex(value: string, prefixed?: boolean): string;
5
+ /** Normalizes hub chain input (hex, decimal, or AddEthereumChainParameter) to a decimal reference. */
6
+ export declare function parseChainReference(chain?: string | Chain): string | undefined;
7
+ /** Maps a chain reference to a Rango network name using blockchain meta. */
8
+ export declare function resolveNetworkName(chain: string | Chain | null | undefined, meta: BlockchainMeta[]): string | undefined;
9
+ /** Converts a decimal EVM chain reference to the `0x`-prefixed hex expected by hub EVM actions. */
10
+ export declare function chainReferenceToHex(reference: string): `0x${string}`;
11
+ /**
12
+ * Converts rango EVM blockchain meta to CAIP-2 chain ids - the only chain data the
13
+ * connect/proposal path needs. This is the single boundary where rango-types' chain
14
+ * shape is translated; everything downstream uses caip's ChainIdParams.
15
+ */
16
+ export declare function evmMetaToCaipChainIds(meta: BlockchainMeta[]): ChainIdParams[];
17
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAQlD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAMjE;AAED,sGAAsG;AACtG,wBAAgB,mBAAmB,CACjC,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,GACrB,MAAM,GAAG,SAAS,CAYpB;AAED,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,EACxC,IAAI,EAAE,cAAc,EAAE,GACrB,MAAM,GAAG,SAAS,CAWpB;AAED,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,aAAa,EAAE,CAK7E"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * WalletConnect protocol constants shared across the hub path (session/,
3
+ * adapter/, signers/, namespaces/). Kept separate from `constants.ts` (which
4
+ * holds the hub provider identity/metadata) so this module stays a dependency
5
+ * leaf and importing it never pulls in the signer/provider graph (the
6
+ * `WalletConnectNamespace` import below is type-only, so it is erased at runtime).
7
+ */
8
+ import type { WalletConnectNamespace } from './types.js';
9
+ export declare const PING_TIMEOUT = 10000;
10
+ export declare enum NAMESPACES {
11
+ ETHEREUM = "eip155",
12
+ BITCOIN = "bip122",
13
+ POLKADOT = "polkadot",
14
+ CARDANO = "cip34",
15
+ ERLOND = "elrond",
16
+ MULTIVERSX = "multiversx"
17
+ }
18
+ /**
19
+ * Single source of truth for the namespace-alias -> CAIP-2 prefix relationship
20
+ * (`evm -> eip155`, `utxo -> bip122`). `proposals` and `lookup` read from this
21
+ * instead of re-encoding it. `Record<WalletConnectNamespace, …>` makes a new
22
+ * alias a compile error until it's mapped.
23
+ */
24
+ export declare const WC_NAMESPACE_TO_CAIP: Record<WalletConnectNamespace, string>;
25
+ export declare const CHAIN_ID_STORAGE = "wc@2:client//namespaces";
26
+ export declare enum EthereumRPCMethods {
27
+ PERSONAL_SIGN = "personal_sign",
28
+ SIGN = "eth_sign",
29
+ SIGN_TYPED_DATA = "eth_signTypedData",
30
+ SIGN_TRANSACTION = "eth_signTransaction",
31
+ SEND_TRANSACTION = "eth_sendTransaction",
32
+ SEND_RAW_TRANSACTION = "eth_sendRawTransaction",
33
+ SWITCH_CHAIN = "wallet_switchEthereumChain",
34
+ ADD_CHAIN = "wallet_addEthereumChain",
35
+ GET_CHAIN = "eth_chainId"
36
+ }
37
+ export declare enum EthereumEvents {
38
+ CHAIN_CHANGED = "chainChanged",
39
+ ACCOUNTS_CHANGED = "accountsChanged"
40
+ }
41
+ export declare const DEFAULT_ETHEREUM_EVENTS: EthereumEvents[];
42
+ export declare const DEFAULT_ETHEREUM_METHODS: EthereumRPCMethods[];
43
+ export declare enum BitcoinRPCMethods {
44
+ SIGN_PSBT = "signPsbt",
45
+ GET_ACCOUNT_ADDRESSES = "getAccountAddresses",
46
+ SIGN_MESSAGE = "signMessage",
47
+ SEND_TRANSFER = "sendTransfer"
48
+ }
49
+ export declare enum BitcoinEvents {
50
+ ADDRESSES_CHANGED = "bip122_addressesChanged"
51
+ }
52
+ export declare const DEFAULT_BITCOIN_EVENTS: BitcoinEvents[];
53
+ export declare const DEFAULT_BITCOIN_METHODS: BitcoinRPCMethods[];
54
+ export declare const DEFAULT_APP_METADATA: {
55
+ name: string;
56
+ description: string;
57
+ url: string;
58
+ icons: string[];
59
+ };
60
+ export declare const RELAY_URL = "wss://relay.walletconnect.com";
61
+ //# sourceMappingURL=wcConstants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wcConstants.d.ts","sourceRoot":"","sources":["../src/wcConstants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,eAAO,MAAM,YAAY,QAAS,CAAC;AAEnC,oBAAY,UAAU;IACpB,QAAQ,WAAW;IACnB,OAAO,WAAW;IAClB,QAAQ,aAAa;IACrB,OAAO,UAAU;IACjB,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAGvE,CAAC;AAEF,eAAO,MAAM,gBAAgB,4BAA4B,CAAC;AAG1D,oBAAY,kBAAkB;IAC5B,aAAa,kBAAkB;IAC/B,IAAI,aAAa;IACjB,eAAe,sBAAsB;IACrC,gBAAgB,wBAAwB;IACxC,gBAAgB,wBAAwB;IACxC,oBAAoB,2BAA2B;IAC/C,YAAY,+BAA+B;IAC3C,SAAS,4BAA4B;IACrC,SAAS,gBAAgB;CAC1B;AAED,oBAAY,cAAc;IACxB,aAAa,iBAAiB;IAC9B,gBAAgB,oBAAoB;CACrC;AAED,eAAO,MAAM,uBAAuB,EAAE,cAAc,EAGnD,CAAC;AAEF,eAAO,MAAM,wBAAwB,sBAOpC,CAAC;AAGF,oBAAY,iBAAiB;IAC3B,SAAS,aAAa;IACtB,qBAAqB,wBAAwB;IAC7C,YAAY,gBAAgB;IAC5B,aAAa,iBAAiB;CAC/B;AAED,oBAAY,aAAa;IACvB,iBAAiB,4BAA4B;CAC9C;AAED,eAAO,MAAM,sBAAsB,EAAE,aAAa,EAEjD,CAAC;AAEF,eAAO,MAAM,uBAAuB,qBAGnC,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAC;AAEF,eAAO,MAAM,SAAS,kCAAkC,CAAC"}
package/package.json CHANGED
@@ -1,41 +1,46 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-walletconnect-2",
3
- "version": "0.57.0",
3
+ "version": "0.57.1-next.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "source": "./src/index.ts",
7
- "main": "./dist/index.js",
6
+ "source": "./src/mod.ts",
7
+ "main": "./dist/mod.js",
8
8
  "exports": {
9
- ".": "./dist/index.js"
9
+ ".": "./dist/mod.js"
10
10
  },
11
- "typings": "dist/index.d.ts",
11
+ "typings": "dist/mod.d.ts",
12
12
  "files": [
13
13
  "dist",
14
14
  "src"
15
15
  ],
16
16
  "scripts": {
17
- "build": "yarn run rangutopia library build --splitting --external-all-except @walletconnect/modal",
17
+ "build": "yarn run rangutopia library build --splitting",
18
18
  "ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
19
19
  "clean": "rimraf dist",
20
20
  "format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
21
21
  "lint": "eslint \"**/*.{ts,tsx}\""
22
22
  },
23
23
  "dependencies": {
24
+ "@bitcoinerlab/secp256k1": "^1.2.0",
25
+ "@hub3js/core": "^0.61.0",
26
+ "@hub3js/evm": "^0.3.3",
27
+ "@hub3js/std": "^0.2.3",
24
28
  "@rango-dev/logging-core": "^0.14.0",
25
29
  "@rango-dev/signer-evm": "^0.45.0",
26
- "@rango-dev/signer-solana": "^0.49.0",
27
- "@rango-dev/wallets-shared": "^0.62.0",
28
- "@solana/web3.js": "^1.91.4",
30
+ "@rango-dev/wallets-core": "^0.61.0",
31
+ "@rango-dev/wallets-shared": "^0.62.1-next.0",
32
+ "@reown/appkit": "1.8.20",
29
33
  "@walletconnect/encoding": "^1.0.2",
30
- "@walletconnect/sign-client": "^2.11.2",
31
- "@walletconnect/utils": "^2.11.2",
34
+ "@walletconnect/sign-client": "2.23.7",
35
+ "@walletconnect/universal-provider": "2.23.7",
36
+ "@walletconnect/utils": "2.23.7",
37
+ "bitcoinjs-lib": "^6.1.7",
32
38
  "bs58": "^5.0.0",
33
39
  "caip": "^1.1.1",
34
40
  "rango-types": "^0.5.0"
35
41
  },
36
42
  "devDependencies": {
37
- "@walletconnect/modal": "^2.6.2",
38
- "@walletconnect/types": "^2.11.2"
43
+ "@walletconnect/types": "2.23.7"
39
44
  },
40
45
  "publishConfig": {
41
46
  "access": "public"
package/readme.md CHANGED
@@ -1,8 +1,20 @@
1
- # @rango-dev/provider-walletconnect2
1
+ # WalletConnect
2
2
 
3
+ WalletConnect integration for hub.
4
+ [Homepage](https://walletconnect.com/) | [Docs](https://docs.walletconnect.com/)
5
+
6
+ More about implementation status can be found [here](../readme.md).
7
+
8
+ ## Implementation notes/limitations
9
+
10
+ ### Group
11
+
12
+ #### ⚠️ UTXO
13
+
14
+ Only supports Bitcoin.
3
15
 
4
16
  ## Known issues
5
17
 
6
- - Using Private key to import wallets other than `Ethereum` will be problematic. Because it imports only a single blockchain and we are by default asking for `Ethereum`.
18
+ - Using Private key to import wallets other than `Ethereum` will be problematic. Because it imports only a single blockchain and we are by default asking for `Ethereum`.
7
19
  - Signing a transaction on Metamask goes through an internal error.
8
20
  - We couldn't update exist session during a bug in `@walletconnect/utils`, so we are creating new session for accessing to new chains.
@@ -0,0 +1,289 @@
1
+ import type { WalletConnectNamespace } from '../types.js';
2
+ import type { Chain } from '@hub3js/evm';
3
+ import type { SessionTypes } from '@walletconnect/types';
4
+ import type UniversalProvider from '@walletconnect/universal-provider';
5
+ import type { BlockchainMeta } from 'rango-types';
6
+
7
+ import { debug } from '@rango-dev/logging-core';
8
+
9
+ import {
10
+ ensureConnectedToChain as ensureConnectedToChainHelper,
11
+ getCurrentChainId as getCurrentChainIdHelper,
12
+ resolveActiveChainReference as resolveActiveChainReferenceHelper,
13
+ switchEvmNetwork as switchEvmNetworkHelper,
14
+ } from '../session/evm-chain.js';
15
+ import {
16
+ connectWalletConnectSession,
17
+ prepareWalletConnectNamespace,
18
+ } from '../session/lifecycle.js';
19
+ import { restoreAndCacheSession } from '../session/restore-cache.js';
20
+ import { removeSessionRecord } from '../session/teardown.js';
21
+ import { evmMetaToCaipChainIds } from '../utils.js';
22
+
23
+ import { ModalCache } from './modal-cache.js';
24
+ import { createUniversalProvider } from './provider-client.js';
25
+ import { createSessionCache } from './session-cache.js';
26
+ import { TaskQueue } from './task-queue.js';
27
+
28
+ /**
29
+ * Central coordinator for WalletConnect sessions used by hub EVM/UTXO namespaces.
30
+ *
31
+ * Owns provider state (client, session cache, modal) and delegates protocol/domain
32
+ * logic to `session/*` helpers.
33
+ */
34
+ export interface WalletConnectAdapterConfig {
35
+ projectId: string;
36
+ meta: BlockchainMeta[];
37
+ disableModalLink?: string;
38
+ themeMode?: 'light' | 'dark';
39
+ modalZIndex?: number;
40
+ }
41
+
42
+ export class WalletConnectAdapter {
43
+ readonly #projectId: string;
44
+ readonly #disableModalLink?: string;
45
+ readonly #themeMode?: 'light' | 'dark';
46
+ readonly #modalZIndex?: number;
47
+ readonly #meta: BlockchainMeta[];
48
+ #universalProvider: UniversalProvider | null = null;
49
+ #universalProviderPromise: Promise<UniversalProvider> | null = null;
50
+
51
+ readonly #cache = createSessionCache();
52
+ readonly #modalCache = new ModalCache();
53
+
54
+ /**
55
+ * Serializes everything that mutates WalletConnect session state.
56
+ *
57
+ * Connecting and disconnecting must never overlap: tearing a session down also
58
+ * deletes its pairing, and an overlapping connect has already minted a new one
59
+ * by then - the teardown unsubscribes it, so `wc_proposeSession` publishes to a
60
+ * topic we no longer listen on and the relay answers
61
+ * `Topic repository: AlreadyExists`.
62
+ *
63
+ * The hub can't order this for us: `useHubAdapter.disconnect` drops the
64
+ * promises `namespace.disconnect()` returns (it iterates with `forEach`), so it
65
+ * resolves while teardown is still in flight and never joins the queue that
66
+ * serializes `connect`.
67
+ *
68
+ * The cost is that a connect holds the queue for its whole lifetime, including
69
+ * the wait for the user to approve in their wallet, so a disconnect raised
70
+ * meanwhile waits its turn instead of interleaving. That is deliberate rather
71
+ * than an oversight: the pairing has to survive from `client.connect()` through
72
+ * settle, which is exactly the span being protected.
73
+ */
74
+ readonly #sessionQueue = new TaskQueue();
75
+
76
+ constructor(config: WalletConnectAdapterConfig) {
77
+ this.#projectId = config.projectId;
78
+ this.#meta = config.meta;
79
+ this.#disableModalLink = config.disableModalLink;
80
+ this.#themeMode = config.themeMode;
81
+ this.#modalZIndex = config.modalZIndex;
82
+ }
83
+
84
+ async getUniversalProvider(): Promise<UniversalProvider> {
85
+ /*
86
+ * Memoize the in-flight promise, not the resolved value. A namespace's
87
+ * `before` subscribers are invoked with `forEach` (nothing awaits between
88
+ * them), so several reach this method in the same tick - awaiting first and
89
+ * assigning after would let each start its own `UniversalProvider`, leaving
90
+ * several SignClients sharing one storage. The extra clients answer relay
91
+ * traffic for a handshake they never made ("Pending session not found for
92
+ * topic X", then "No matching key. session topic doesn't exist: X").
93
+ */
94
+ if (!this.#universalProviderPromise) {
95
+ this.#universalProviderPromise = createUniversalProvider(this.#projectId)
96
+ .then((provider) => {
97
+ this.#universalProvider = provider;
98
+ return provider;
99
+ })
100
+ .catch((error: unknown) => {
101
+ // Don't cache a failed init - let the next caller retry.
102
+ this.#universalProviderPromise = null;
103
+ throw error;
104
+ });
105
+ }
106
+
107
+ return this.#universalProviderPromise;
108
+ }
109
+
110
+ async getClient() {
111
+ return (await this.getUniversalProvider()).client;
112
+ }
113
+
114
+ getSession(namespace: WalletConnectNamespace): SessionTypes.Struct | null {
115
+ return this.#cache.get(namespace);
116
+ }
117
+
118
+ cacheSession(
119
+ namespace: WalletConnectNamespace,
120
+ session: SessionTypes.Struct
121
+ ) {
122
+ this.#cache.set(namespace, session);
123
+ }
124
+
125
+ clearSession(namespace: WalletConnectNamespace) {
126
+ this.#cache.clear(namespace);
127
+ }
128
+
129
+ clearAllSessions() {
130
+ this.#cache.clearAll();
131
+ }
132
+
133
+ async tryRestoreEagerSession(
134
+ namespace: WalletConnectNamespace
135
+ ): Promise<boolean> {
136
+ return this.#sessionQueue.run(async () => {
137
+ const client = await this.getClient();
138
+ return !!(await restoreAndCacheSession(
139
+ client,
140
+ namespace,
141
+ this.#cache,
142
+ { validateAccounts: true },
143
+ async (targetNamespace) =>
144
+ this.#disconnectSessionQueued(targetNamespace)
145
+ ));
146
+ });
147
+ }
148
+
149
+ async ensureSession(options: {
150
+ namespace: WalletConnectNamespace;
151
+ chainReference?: string;
152
+ }): Promise<SessionTypes.Struct> {
153
+ return this.#sessionQueue.run(async () =>
154
+ this.#ensureSessionQueued(options)
155
+ );
156
+ }
157
+
158
+ async disconnectSession(namespace: WalletConnectNamespace) {
159
+ return this.#sessionQueue.run(async () =>
160
+ this.#disconnectSessionQueued(namespace)
161
+ );
162
+ }
163
+
164
+ async resolveActiveChainReference(): Promise<string | undefined> {
165
+ const session = this.getSession('evm');
166
+ if (!session) {
167
+ return undefined;
168
+ }
169
+
170
+ return resolveActiveChainReferenceHelper(await this.getClient(), session);
171
+ }
172
+
173
+ async getCurrentChainId(): Promise<`0x${string}`> {
174
+ const session = this.getSession('evm');
175
+ if (!session) {
176
+ throw new Error(
177
+ 'Unable to determine EVM chain id from WalletConnect session.'
178
+ );
179
+ }
180
+
181
+ return getCurrentChainIdHelper(await this.getClient(), session);
182
+ }
183
+
184
+ async ensureConnectedToChain(
185
+ chain?: string | Chain
186
+ ): Promise<SessionTypes.Struct> {
187
+ return ensureConnectedToChainHelper(this.#evmChainDeps(), chain);
188
+ }
189
+
190
+ async switchEvmNetwork(
191
+ requestedChainId: string,
192
+ currentChainId: string
193
+ ): Promise<void> {
194
+ const session = this.getSession('evm');
195
+ if (!session) {
196
+ throw new Error('WalletConnect session is not available.');
197
+ }
198
+
199
+ this.cacheSession(
200
+ 'evm',
201
+ await switchEvmNetworkHelper({
202
+ client: await this.getClient(),
203
+ session,
204
+ meta: this.#meta,
205
+ requestedChainId,
206
+ currentChainId,
207
+ })
208
+ );
209
+ }
210
+
211
+ /*
212
+ * The `Queued` suffix means "already running inside `#sessionQueue`". These
213
+ * call each other directly and must never go back through the public methods
214
+ * above: re-entering the queue from inside a task would wait for a turn that
215
+ * cannot come until that same task finishes, which deadlocks.
216
+ */
217
+
218
+ async #ensureSessionQueued(options: {
219
+ namespace: WalletConnectNamespace;
220
+ chainReference?: string;
221
+ }): Promise<SessionTypes.Struct> {
222
+ const { namespace, chainReference } = options;
223
+ const client = await this.getClient();
224
+ const restored = await restoreAndCacheSession(
225
+ client,
226
+ namespace,
227
+ this.#cache,
228
+ undefined,
229
+ async (targetNamespace) => this.#disconnectSessionQueued(targetNamespace)
230
+ );
231
+ if (restored) {
232
+ return restored;
233
+ }
234
+
235
+ await prepareWalletConnectNamespace(client, namespace);
236
+
237
+ const universalProvider = await this.getUniversalProvider();
238
+ await universalProvider.cleanupPendingPairings().catch(() => undefined);
239
+
240
+ const session = await connectWalletConnectSession(
241
+ client,
242
+ this.#modalCache.getModal({
243
+ projectId: this.#projectId,
244
+ universalProvider,
245
+ themeMode: this.#themeMode,
246
+ zIndex: this.#modalZIndex,
247
+ }),
248
+ {
249
+ chains: evmMetaToCaipChainIds(this.#meta),
250
+ envs: {
251
+ WC_PROJECT_ID: this.#projectId,
252
+ DISABLE_MODAL_AND_OPEN_LINK: this.#disableModalLink,
253
+ },
254
+ namespace,
255
+ chainReference,
256
+ }
257
+ );
258
+
259
+ this.#cache.set(namespace, session);
260
+ return session;
261
+ }
262
+
263
+ async #disconnectSessionQueued(namespace: WalletConnectNamespace) {
264
+ const session = this.getSession(namespace);
265
+ if (this.#universalProvider?.client && session) {
266
+ await removeSessionRecord(this.#universalProvider.client, session).catch(
267
+ (error) => debug(error)
268
+ );
269
+ }
270
+ this.clearSession(namespace);
271
+ if (session) {
272
+ this.#cache.clearTopic(session.topic);
273
+ }
274
+ }
275
+
276
+ #evmChainDeps() {
277
+ return {
278
+ meta: this.#meta,
279
+ getSession: (namespace: 'evm') => this.getSession(namespace),
280
+ cacheSession: (namespace: 'evm', session: SessionTypes.Struct) =>
281
+ this.cacheSession(namespace, session),
282
+ getClient: async () => this.getClient(),
283
+ ensureSession: async (options: {
284
+ namespace: 'evm';
285
+ chainReference?: string;
286
+ }) => this.ensureSession(options),
287
+ };
288
+ }
289
+ }
@@ -0,0 +1,2 @@
1
+ export { WalletConnectAdapter } from './adapter.js';
2
+ export { type AppKitModal, createAppKitModal } from './modal.js';
@@ -0,0 +1,23 @@
1
+ import type { AppKitModal, ModalParams } from './modal.js';
2
+
3
+ import { createAppKitModal } from './modal.js';
4
+
5
+ /**
6
+ * Holds the single AppKit modal for the adapter's lifetime.
7
+ *
8
+ * One instance serves every namespace - all its networks are registered up front
9
+ * and the active one is chosen per connect with `switchNetwork`. It is built once
10
+ * and reused: rebuilding per namespace re-ran AppKit init against its shared
11
+ * singleton controllers and left stale router/filter state behind.
12
+ */
13
+ export class ModalCache {
14
+ #web3Modal: AppKitModal | null = null;
15
+
16
+ getModal(params: ModalParams): AppKitModal {
17
+ if (!this.#web3Modal) {
18
+ this.#web3Modal = createAppKitModal(params);
19
+ }
20
+
21
+ return this.#web3Modal;
22
+ }
23
+ }