@rango-dev/provider-walletconnect-2 0.0.0-experimental-936229e8-20251208

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 (43) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/dist/chunk-BPSEZJUF.js +2 -0
  3. package/dist/chunk-BPSEZJUF.js.map +7 -0
  4. package/dist/chunk-DXVBX5XQ.js +2 -0
  5. package/dist/chunk-DXVBX5XQ.js.map +7 -0
  6. package/dist/chunk-RPL2NMJC.js +2 -0
  7. package/dist/chunk-RPL2NMJC.js.map +7 -0
  8. package/dist/constants.d.ts +55 -0
  9. package/dist/cosmos-I3Z34UI3.js +2 -0
  10. package/dist/cosmos-I3Z34UI3.js.map +7 -0
  11. package/dist/dist-6GI3ECE5.js +139 -0
  12. package/dist/dist-6GI3ECE5.js.map +7 -0
  13. package/dist/evm-MYSQOTV5.js +2 -0
  14. package/dist/evm-MYSQOTV5.js.map +7 -0
  15. package/dist/helpers.d.ts +31 -0
  16. package/dist/index.d.ts +21 -0
  17. package/dist/index.js +2 -0
  18. package/dist/index.js.map +7 -0
  19. package/dist/provider-walletconnect-2.build.json +1 -0
  20. package/dist/session.d.ts +63 -0
  21. package/dist/signer.d.ts +3 -0
  22. package/dist/signers/cosmos.d.ts +14 -0
  23. package/dist/signers/evm.d.ts +15 -0
  24. package/dist/signers/helper.d.ts +2 -0
  25. package/dist/signers/mock.d.ts +2 -0
  26. package/dist/signers/solana.d.ts +14 -0
  27. package/dist/solana-35I33VLX.js +2 -0
  28. package/dist/solana-35I33VLX.js.map +7 -0
  29. package/dist/types.d.ts +24 -0
  30. package/package.json +52 -0
  31. package/readme.md +8 -0
  32. package/src/constants.ts +91 -0
  33. package/src/helpers.ts +242 -0
  34. package/src/index.ts +233 -0
  35. package/src/session.ts +374 -0
  36. package/src/signer.ts +45 -0
  37. package/src/signers/cosmos.ts +248 -0
  38. package/src/signers/evm.ts +163 -0
  39. package/src/signers/helper.ts +77 -0
  40. package/src/signers/mock.ts +3798 -0
  41. package/src/signers/solana.ts +160 -0
  42. package/src/types.ts +30 -0
  43. package/src/wc-types.d.ts +31 -0
@@ -0,0 +1,160 @@
1
+ import type { SolanaWeb3Signer } from '@rango-dev/signer-solana';
2
+ import type { Transaction, VersionedTransaction } from '@solana/web3.js';
3
+ import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
4
+ import type { SessionTypes } from '@walletconnect/types';
5
+ import type { GenericSigner, SolanaTransaction } from 'rango-types';
6
+
7
+ import { generalSolanaTransactionExecutor } from '@rango-dev/signer-solana';
8
+ import { PublicKey } from '@solana/web3.js';
9
+ import base58 from 'bs58';
10
+ import { AccountId, ChainId } from 'caip';
11
+ import { SignerError, SignerErrorCode } from 'rango-types';
12
+
13
+ import { NAMESPACES, SolanaRPCMethods } from '../constants.js';
14
+
15
+ const NAMESPACE_NAME = NAMESPACES.SOLANA;
16
+ class SOLANASigner implements GenericSigner<SolanaTransaction> {
17
+ private client: SignClient;
18
+ private session: SessionTypes.Struct;
19
+
20
+ constructor(client: SignClient, session: SessionTypes.Struct) {
21
+ this.client = client;
22
+ this.session = session;
23
+ }
24
+
25
+ public async signMessage(
26
+ msg: string,
27
+ address: string,
28
+ chainId: string | null
29
+ ): Promise<string> {
30
+ const requestedFor = this.isNetworkAndAccountExistInSession({
31
+ address,
32
+ chainId,
33
+ });
34
+
35
+ const caipChainId = new ChainId({
36
+ namespace: NAMESPACE_NAME,
37
+ reference: requestedFor.chainId,
38
+ });
39
+
40
+ try {
41
+ const message = base58.encode(new TextEncoder().encode(msg));
42
+ const pubkey = new PublicKey(address);
43
+ const { signature } = await this.client.request<{
44
+ signature: string;
45
+ }>({
46
+ topic: this.session.topic,
47
+ chainId: caipChainId.toString(),
48
+ request: {
49
+ method: SolanaRPCMethods.SIGN_MESSAGE,
50
+ params: {
51
+ message,
52
+ pubkey,
53
+ },
54
+ },
55
+ });
56
+
57
+ return signature;
58
+ } catch (error) {
59
+ throw new SignerError(SignerErrorCode.SIGN_TX_ERROR, undefined, error);
60
+ }
61
+ }
62
+
63
+ async signAndSendTx(
64
+ tx: SolanaTransaction,
65
+ address: string,
66
+ chainId: string | null
67
+ ): Promise<{ hash: string }> {
68
+ const requestedFor = this.isNetworkAndAccountExistInSession({
69
+ address,
70
+ chainId,
71
+ });
72
+ const DefaultSolanaSigner: SolanaWeb3Signer = async (
73
+ solanaWeb3Transaction: Transaction | VersionedTransaction
74
+ ) => {
75
+ const response: { signature: string } = await this.client.request({
76
+ topic: this.session.topic,
77
+ chainId: requestedFor.caipChainId,
78
+ request: {
79
+ method: SolanaRPCMethods.SIGN_TRANSACTION,
80
+ params: solanaWeb3Transaction,
81
+ },
82
+ });
83
+
84
+ const publicKey = new PublicKey(tx.from);
85
+ const sign = base58.decode(response.signature);
86
+
87
+ solanaWeb3Transaction.addSignature(publicKey, Buffer.from(sign));
88
+ const raw = solanaWeb3Transaction.serialize();
89
+ return raw;
90
+ };
91
+
92
+ const hash = await generalSolanaTransactionExecutor(
93
+ tx,
94
+ DefaultSolanaSigner
95
+ );
96
+ return { hash };
97
+ }
98
+
99
+ private isNetworkAndAccountExistInSession(requestedFor: {
100
+ address: string;
101
+ chainId: string | null;
102
+ }) {
103
+ const { address, chainId } = requestedFor;
104
+
105
+ /*
106
+ * TODO: solana chain id in supported blockchains("mainnet-beta") is different from solana chain id is here ("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp")
107
+ * # Solana Mainnet
108
+ * solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvd
109
+ * refrence: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
110
+ */
111
+
112
+ let solana_chain_id = chainId;
113
+ this.session.namespaces[NAMESPACE_NAME]?.accounts.map((account) => {
114
+ const sol_account = account.split(':');
115
+ if (sol_account[2] === address) {
116
+ solana_chain_id = sol_account[1];
117
+ }
118
+ });
119
+
120
+ if (!solana_chain_id) {
121
+ throw new Error(
122
+ 'You need to set your chain for signing message/transaction.'
123
+ );
124
+ }
125
+ const caipAddress = new AccountId({
126
+ chainId: {
127
+ namespace: NAMESPACE_NAME,
128
+ reference: solana_chain_id,
129
+ },
130
+ address,
131
+ });
132
+
133
+ const addresses = this.session.namespaces[NAMESPACE_NAME]?.accounts.map(
134
+ (address) => address
135
+ );
136
+ if (!addresses || !addresses.includes(caipAddress.toString())) {
137
+ console.warn(
138
+ 'Available adresses and requested address:',
139
+ addresses,
140
+ caipAddress.toString()
141
+ );
142
+ throw new Error(
143
+ `Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.`
144
+ );
145
+ }
146
+
147
+ const caipChainId = new ChainId({
148
+ namespace: NAMESPACE_NAME,
149
+ reference: solana_chain_id,
150
+ });
151
+
152
+ return {
153
+ chainId: solana_chain_id,
154
+ address,
155
+ caipChainId: caipChainId.toString(),
156
+ };
157
+ }
158
+ }
159
+
160
+ export default SOLANASigner;
package/src/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
+ import type { ProposalTypes, SessionTypes } from '@walletconnect/types';
3
+ import type { BlockchainMeta, CosmosBlockchainMeta } from 'rango-types';
4
+
5
+ export interface Environments extends Record<string, string | undefined> {
6
+ WC_PROJECT_ID: string;
7
+ // This is useful for directly opening a listed WC wallet. you will need to pass a url.
8
+ DISABLE_MODAL_AND_OPEN_LINK?: string;
9
+ }
10
+ export interface WCInstance {
11
+ client: SignClient;
12
+ session: SessionTypes.Struct | null;
13
+ request: (params: any) => Promise<string>;
14
+ }
15
+
16
+ export interface CreateSessionParams {
17
+ requiredNamespaces: ProposalTypes.RequiredNamespaces;
18
+ optionalNamespaces?: ProposalTypes.OptionalNamespaces;
19
+ pairingTopic?: string;
20
+ }
21
+
22
+ export interface ConnectParams {
23
+ meta: BlockchainMeta[];
24
+ envs: Environments;
25
+ }
26
+
27
+ export interface CosmosMeta extends CosmosBlockchainMeta {
28
+ // forcing the chainId to be `string` only.
29
+ chainId: string;
30
+ }
@@ -0,0 +1,31 @@
1
+ // see notes.md for more details.
2
+ import type {
3
+ ConfigCtrlState,
4
+ ThemeCtrlState,
5
+ } from '@walletconnect/modal-core';
6
+ /**
7
+ * Types
8
+ */
9
+ export type WalletConnectModalConfig = ConfigCtrlState & ThemeCtrlState;
10
+
11
+ /**
12
+ * Client
13
+ */
14
+ export declare class WalletConnectModal {
15
+ openModal: (
16
+ options?: // eslint-disable-next-line @typescript-eslint/consistent-type-imports
17
+ | import('@walletconnect/modal-core/dist/_types/src/controllers/ModalCtrl').OpenOptions
18
+ | undefined
19
+ ) => Promise<void>;
20
+ closeModal: () => void;
21
+ subscribeModal: (
22
+ callback: (
23
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
24
+ newState: import('@walletconnect/modal-core/dist/_types/src/types/controllerTypes').ModalCtrlState
25
+ ) => void
26
+ ) => () => void;
27
+
28
+ setTheme: (theme: ThemeCtrlState) => void;
29
+ private initUi;
30
+ constructor(config: WalletConnectModalConfig);
31
+ }