@rango-dev/provider-metamask 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 (42) hide show
  1. package/CHANGELOG.md +239 -0
  2. package/dist/actions/solana.d.ts +11 -0
  3. package/dist/actions/solana.d.ts.map +1 -0
  4. package/dist/builders/solana.d.ts +8 -0
  5. package/dist/builders/solana.d.ts.map +1 -0
  6. package/dist/constants.d.ts +6 -0
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/legacy/index.d.ts +20 -0
  9. package/dist/legacy/index.d.ts.map +1 -0
  10. package/dist/mod.d.ts +3 -0
  11. package/dist/mod.d.ts.map +1 -0
  12. package/dist/mod.js +2 -0
  13. package/dist/mod.js.map +7 -0
  14. package/dist/namespaces/evm.d.ts +4 -0
  15. package/dist/namespaces/evm.d.ts.map +1 -0
  16. package/dist/namespaces/solana.d.ts +4 -0
  17. package/dist/namespaces/solana.d.ts.map +1 -0
  18. package/dist/provider-metamask.build.json +1 -0
  19. package/dist/provider.d.ts +3 -0
  20. package/dist/provider.d.ts.map +1 -0
  21. package/dist/signer.d.ts +4 -0
  22. package/dist/signer.d.ts.map +1 -0
  23. package/dist/signers/solana.d.ts +12 -0
  24. package/dist/signers/solana.d.ts.map +1 -0
  25. package/dist/types.d.ts +39 -0
  26. package/dist/types.d.ts.map +1 -0
  27. package/dist/utils.d.ts +7 -0
  28. package/dist/utils.d.ts.map +1 -0
  29. package/package.json +40 -0
  30. package/readme.md +26 -0
  31. package/src/actions/solana.ts +42 -0
  32. package/src/builders/solana.ts +36 -0
  33. package/src/constants.ts +56 -0
  34. package/src/legacy/index.ts +91 -0
  35. package/src/mod.ts +12 -0
  36. package/src/namespaces/evm.ts +81 -0
  37. package/src/namespaces/solana.ts +45 -0
  38. package/src/provider.ts +23 -0
  39. package/src/signer.ts +29 -0
  40. package/src/signers/solana.ts +88 -0
  41. package/src/types.ts +54 -0
  42. package/src/utils.ts +144 -0
package/src/utils.ts ADDED
@@ -0,0 +1,144 @@
1
+ import type {
2
+ MetamaskEvmProviderApi,
3
+ Provider,
4
+ WalletStandardSolanaInstance,
5
+ } from './types.js';
6
+ import type { ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
7
+
8
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
9
+ import { getWallets } from '@wallet-standard/app';
10
+
11
+ import {
12
+ SOLANA_WALLET_STANDARD_MAINNET,
13
+ WALLET_STANDARD_NAME,
14
+ } from './constants.js';
15
+
16
+ export function metamask(): Provider | null {
17
+ const { ethereum } = window;
18
+ const solana = getSolanaWalletInstance();
19
+ if (!ethereum || !isEthereumMetamaskProvider(ethereum)) {
20
+ return null;
21
+ }
22
+
23
+ const instances: Provider = new Map();
24
+
25
+ if (ethereum) {
26
+ instances.set(LegacyNetworks.ETHEREUM, ethereum);
27
+ }
28
+ if (solana) {
29
+ instances.set(LegacyNetworks.SOLANA, solana);
30
+ }
31
+
32
+ return instances;
33
+ }
34
+ function isEthereumMetamaskProvider(ethereum: MetamaskEvmProviderApi): boolean {
35
+ if (!ethereum?.isMetaMask) {
36
+ return false;
37
+ }
38
+ /*
39
+ * Brave tries to make itself look like MetaMask
40
+ * Could also try RPC `web3_clientVersion` if following is unreliable
41
+ */
42
+ if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) {
43
+ return false;
44
+ }
45
+ if (ethereum.isApexWallet) {
46
+ return false;
47
+ }
48
+ if (ethereum.isAvalanche) {
49
+ return false;
50
+ }
51
+ if (ethereum.isBitKeep) {
52
+ return false;
53
+ }
54
+ if (ethereum.isBlockWallet) {
55
+ return false;
56
+ }
57
+ if (ethereum.isCoin98) {
58
+ return false;
59
+ }
60
+ if (ethereum.isFordefi) {
61
+ return false;
62
+ }
63
+ if (ethereum.__XDEFI) {
64
+ return false;
65
+ }
66
+ if (ethereum.isMathWallet) {
67
+ return false;
68
+ }
69
+ if (ethereum.isOkxWallet || ethereum.isOKExWallet) {
70
+ return false;
71
+ }
72
+ if (ethereum.isOneInchIOSWallet || ethereum.isOneInchAndroidWallet) {
73
+ return false;
74
+ }
75
+ if (ethereum.isOpera) {
76
+ return false;
77
+ }
78
+ if (ethereum.isPortal) {
79
+ return false;
80
+ }
81
+ if (ethereum.isRabby) {
82
+ return false;
83
+ }
84
+ if (ethereum.isDefiant) {
85
+ return false;
86
+ }
87
+ if (ethereum.isTokenPocket) {
88
+ return false;
89
+ }
90
+ if (ethereum.isTokenary) {
91
+ return false;
92
+ }
93
+ if (ethereum.isZeal) {
94
+ return false;
95
+ }
96
+ if (ethereum.isZerion) {
97
+ return false;
98
+ }
99
+ if (ethereum.isSafePal) {
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ export function evmMetamask(): EvmProviderApi {
105
+ const instances = metamask();
106
+
107
+ const evmInstance = instances?.get(LegacyNetworks.ETHEREUM);
108
+
109
+ if (!evmInstance) {
110
+ throw new Error(
111
+ 'Metamask not injected or EVM not enabled. Please check your wallet.'
112
+ );
113
+ }
114
+
115
+ return evmInstance as EvmProviderApi;
116
+ }
117
+ export function solanaMetamask(): WalletStandardSolanaInstance {
118
+ const instances = metamask();
119
+ const solanaInstance = instances?.get(LegacyNetworks.SOLANA);
120
+ if (!solanaInstance) {
121
+ throw new Error(
122
+ 'Metamask Solana instance is not available. Ensure that Solana support is enabled in your wallet.'
123
+ );
124
+ }
125
+ return solanaInstance as WalletStandardSolanaInstance;
126
+ }
127
+ export function getInstanceOrThrow(): Provider {
128
+ const instances = metamask();
129
+
130
+ if (!instances) {
131
+ throw new Error('MetaMask is not injected. Please check your wallet.');
132
+ }
133
+
134
+ return instances;
135
+ }
136
+ function getSolanaWalletInstance() {
137
+ return getWallets()
138
+ .get()
139
+ .find(
140
+ (wallet) =>
141
+ wallet.name === WALLET_STANDARD_NAME &&
142
+ wallet.chains.includes(SOLANA_WALLET_STANDARD_MAINNET)
143
+ ) as WalletStandardSolanaInstance;
144
+ }