@rango-dev/wallets-core 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 (351) hide show
  1. package/CHANGELOG.md +334 -0
  2. package/dist/builders/action.d.ts +22 -0
  3. package/dist/builders/action.d.ts.map +1 -0
  4. package/dist/builders/mod.d.ts +5 -0
  5. package/dist/builders/mod.d.ts.map +1 -0
  6. package/dist/builders/namespace.d.ts +47 -0
  7. package/dist/builders/namespace.d.ts.map +1 -0
  8. package/dist/builders/provider.d.ts +13 -0
  9. package/dist/builders/provider.d.ts.map +1 -0
  10. package/dist/builders/types.d.ts +21 -0
  11. package/dist/builders/types.d.ts.map +1 -0
  12. package/dist/hub/helpers.d.ts +6 -0
  13. package/dist/hub/helpers.d.ts.map +1 -0
  14. package/dist/hub/hub.d.ts +29 -0
  15. package/dist/hub/hub.d.ts.map +1 -0
  16. package/dist/hub/mod.d.ts +9 -0
  17. package/dist/hub/mod.d.ts.map +1 -0
  18. package/dist/hub/namespaces/errors.d.ts +5 -0
  19. package/dist/hub/namespaces/errors.d.ts.map +1 -0
  20. package/dist/hub/namespaces/mod.d.ts +3 -0
  21. package/dist/hub/namespaces/mod.d.ts.map +1 -0
  22. package/dist/hub/namespaces/namespace.d.ts +148 -0
  23. package/dist/hub/namespaces/namespace.d.ts.map +1 -0
  24. package/dist/hub/namespaces/namespace.test.d.ts +11 -0
  25. package/dist/hub/namespaces/namespace.test.d.ts.map +1 -0
  26. package/dist/hub/namespaces/types.d.ts +36 -0
  27. package/dist/hub/namespaces/types.d.ts.map +1 -0
  28. package/dist/hub/provider/mod.d.ts +3 -0
  29. package/dist/hub/provider/mod.d.ts.map +1 -0
  30. package/dist/hub/provider/provider.d.ts +136 -0
  31. package/dist/hub/provider/provider.d.ts.map +1 -0
  32. package/dist/hub/provider/provider.test.d.ts +2 -0
  33. package/dist/hub/provider/provider.test.d.ts.map +1 -0
  34. package/dist/hub/provider/types.d.ts +37 -0
  35. package/dist/hub/provider/types.d.ts.map +1 -0
  36. package/dist/hub/store/events.d.ts +54 -0
  37. package/dist/hub/store/events.d.ts.map +1 -0
  38. package/dist/hub/store/extend.d.ts +14 -0
  39. package/dist/hub/store/extend.d.ts.map +1 -0
  40. package/dist/hub/store/hub.d.ts +11 -0
  41. package/dist/hub/store/hub.d.ts.map +1 -0
  42. package/dist/hub/store/mod.d.ts +8 -0
  43. package/dist/hub/store/mod.d.ts.map +1 -0
  44. package/dist/hub/store/mod.js +2 -0
  45. package/dist/hub/store/mod.js.map +7 -0
  46. package/dist/hub/store/namespaces.d.ts +38 -0
  47. package/dist/hub/store/namespaces.d.ts.map +1 -0
  48. package/dist/hub/store/providers.d.ts +77 -0
  49. package/dist/hub/store/providers.d.ts.map +1 -0
  50. package/dist/hub/store/selectors.d.ts +18 -0
  51. package/dist/hub/store/selectors.d.ts.map +1 -0
  52. package/dist/hub/store/store.d.ts +14 -0
  53. package/dist/hub/store/store.d.ts.map +1 -0
  54. package/dist/hub/store/store.test.d.ts +2 -0
  55. package/dist/hub/store/store.test.d.ts.map +1 -0
  56. package/dist/legacy/helpers.d.ts +12 -0
  57. package/dist/legacy/helpers.d.ts.map +1 -0
  58. package/dist/legacy/mod.d.ts +8 -0
  59. package/dist/legacy/mod.d.ts.map +1 -0
  60. package/dist/legacy/mod.js +2 -0
  61. package/dist/legacy/mod.js.map +7 -0
  62. package/dist/legacy/persistor.d.ts +11 -0
  63. package/dist/legacy/persistor.d.ts.map +1 -0
  64. package/dist/legacy/types.d.ts +247 -0
  65. package/dist/legacy/types.d.ts.map +1 -0
  66. package/dist/legacy/utils.d.ts +8 -0
  67. package/dist/legacy/utils.d.ts.map +1 -0
  68. package/dist/legacy/wallet.d.ts +65 -0
  69. package/dist/legacy/wallet.d.ts.map +1 -0
  70. package/dist/mod.d.ts +9 -0
  71. package/dist/mod.d.ts.map +1 -0
  72. package/dist/mod.js +2 -0
  73. package/dist/mod.js.map +7 -0
  74. package/dist/namespaces/common/actions.d.ts +4 -0
  75. package/dist/namespaces/common/actions.d.ts.map +1 -0
  76. package/dist/namespaces/common/after.d.ts +4 -0
  77. package/dist/namespaces/common/after.d.ts.map +1 -0
  78. package/dist/namespaces/common/and.d.ts +6 -0
  79. package/dist/namespaces/common/and.d.ts.map +1 -0
  80. package/dist/namespaces/common/before.d.ts +4 -0
  81. package/dist/namespaces/common/before.d.ts.map +1 -0
  82. package/dist/namespaces/common/builders.d.ts +5 -0
  83. package/dist/namespaces/common/builders.d.ts.map +1 -0
  84. package/dist/namespaces/common/helpers.d.ts +2 -0
  85. package/dist/namespaces/common/helpers.d.ts.map +1 -0
  86. package/dist/namespaces/common/hooks/changeAccountSubscriber.d.ts +90 -0
  87. package/dist/namespaces/common/hooks/changeAccountSubscriber.d.ts.map +1 -0
  88. package/dist/namespaces/common/hooks/changeAccountSubscriber.test.d.ts +2 -0
  89. package/dist/namespaces/common/hooks/changeAccountSubscriber.test.d.ts.map +1 -0
  90. package/dist/namespaces/common/mod.d.ts +11 -0
  91. package/dist/namespaces/common/mod.d.ts.map +1 -0
  92. package/dist/namespaces/common/mod.js +2 -0
  93. package/dist/namespaces/common/mod.js.map +7 -0
  94. package/dist/namespaces/common/or.d.ts +13 -0
  95. package/dist/namespaces/common/or.d.ts.map +1 -0
  96. package/dist/namespaces/common/types.d.ts +11 -0
  97. package/dist/namespaces/common/types.d.ts.map +1 -0
  98. package/dist/namespaces/common/utils.d.ts +10 -0
  99. package/dist/namespaces/common/utils.d.ts.map +1 -0
  100. package/dist/namespaces/cosmos/actions.d.ts +2 -0
  101. package/dist/namespaces/cosmos/actions.d.ts.map +1 -0
  102. package/dist/namespaces/cosmos/after.d.ts +2 -0
  103. package/dist/namespaces/cosmos/after.d.ts.map +1 -0
  104. package/dist/namespaces/cosmos/and.d.ts +3 -0
  105. package/dist/namespaces/cosmos/and.d.ts.map +1 -0
  106. package/dist/namespaces/cosmos/before.d.ts +2 -0
  107. package/dist/namespaces/cosmos/before.d.ts.map +1 -0
  108. package/dist/namespaces/cosmos/builders.d.ts +4 -0
  109. package/dist/namespaces/cosmos/builders.d.ts.map +1 -0
  110. package/dist/namespaces/cosmos/constants.d.ts +2 -0
  111. package/dist/namespaces/cosmos/constants.d.ts.map +1 -0
  112. package/dist/namespaces/cosmos/mod.d.ts +9 -0
  113. package/dist/namespaces/cosmos/mod.d.ts.map +1 -0
  114. package/dist/namespaces/cosmos/mod.js +2 -0
  115. package/dist/namespaces/cosmos/mod.js.map +7 -0
  116. package/dist/namespaces/cosmos/types.d.ts +19 -0
  117. package/dist/namespaces/cosmos/types.d.ts.map +1 -0
  118. package/dist/namespaces/cosmos/utils.d.ts +3 -0
  119. package/dist/namespaces/cosmos/utils.d.ts.map +1 -0
  120. package/dist/namespaces/evm/actions.d.ts +10 -0
  121. package/dist/namespaces/evm/actions.d.ts.map +1 -0
  122. package/dist/namespaces/evm/after.d.ts +2 -0
  123. package/dist/namespaces/evm/after.d.ts.map +1 -0
  124. package/dist/namespaces/evm/and.d.ts +3 -0
  125. package/dist/namespaces/evm/and.d.ts.map +1 -0
  126. package/dist/namespaces/evm/before.d.ts +2 -0
  127. package/dist/namespaces/evm/before.d.ts.map +1 -0
  128. package/dist/namespaces/evm/builders.d.ts +9 -0
  129. package/dist/namespaces/evm/builders.d.ts.map +1 -0
  130. package/dist/namespaces/evm/constants.d.ts +3 -0
  131. package/dist/namespaces/evm/constants.d.ts.map +1 -0
  132. package/dist/namespaces/evm/eip1193.d.ts +1229 -0
  133. package/dist/namespaces/evm/eip1193.d.ts.map +1 -0
  134. package/dist/namespaces/evm/hooks.d.ts +5 -0
  135. package/dist/namespaces/evm/hooks.d.ts.map +1 -0
  136. package/dist/namespaces/evm/mod.d.ts +10 -0
  137. package/dist/namespaces/evm/mod.d.ts.map +1 -0
  138. package/dist/namespaces/evm/mod.js +2 -0
  139. package/dist/namespaces/evm/mod.js.map +7 -0
  140. package/dist/namespaces/evm/types.d.ts +23 -0
  141. package/dist/namespaces/evm/types.d.ts.map +1 -0
  142. package/dist/namespaces/evm/utils.d.ts +13 -0
  143. package/dist/namespaces/evm/utils.d.ts.map +1 -0
  144. package/dist/namespaces/solana/actions.d.ts +7 -0
  145. package/dist/namespaces/solana/actions.d.ts.map +1 -0
  146. package/dist/namespaces/solana/after.d.ts +2 -0
  147. package/dist/namespaces/solana/after.d.ts.map +1 -0
  148. package/dist/namespaces/solana/and.d.ts +3 -0
  149. package/dist/namespaces/solana/and.d.ts.map +1 -0
  150. package/dist/namespaces/solana/before.d.ts +2 -0
  151. package/dist/namespaces/solana/before.d.ts.map +1 -0
  152. package/dist/namespaces/solana/builders.d.ts +6 -0
  153. package/dist/namespaces/solana/builders.d.ts.map +1 -0
  154. package/dist/namespaces/solana/constants.d.ts +3 -0
  155. package/dist/namespaces/solana/constants.d.ts.map +1 -0
  156. package/dist/namespaces/solana/hooks.d.ts +4 -0
  157. package/dist/namespaces/solana/hooks.d.ts.map +1 -0
  158. package/dist/namespaces/solana/mod.d.ts +10 -0
  159. package/dist/namespaces/solana/mod.d.ts.map +1 -0
  160. package/dist/namespaces/solana/mod.js +2 -0
  161. package/dist/namespaces/solana/mod.js.map +7 -0
  162. package/dist/namespaces/solana/types.d.ts +11 -0
  163. package/dist/namespaces/solana/types.d.ts.map +1 -0
  164. package/dist/namespaces/solana/utils.d.ts +8 -0
  165. package/dist/namespaces/solana/utils.d.ts.map +1 -0
  166. package/dist/namespaces/sui/actions.d.ts +8 -0
  167. package/dist/namespaces/sui/actions.d.ts.map +1 -0
  168. package/dist/namespaces/sui/builders.d.ts +14 -0
  169. package/dist/namespaces/sui/builders.d.ts.map +1 -0
  170. package/dist/namespaces/sui/constants.d.ts +3 -0
  171. package/dist/namespaces/sui/constants.d.ts.map +1 -0
  172. package/dist/namespaces/sui/hooks.d.ts +4 -0
  173. package/dist/namespaces/sui/hooks.d.ts.map +1 -0
  174. package/dist/namespaces/sui/mod.d.ts +7 -0
  175. package/dist/namespaces/sui/mod.d.ts.map +1 -0
  176. package/dist/namespaces/sui/mod.js +2 -0
  177. package/dist/namespaces/sui/mod.js.map +7 -0
  178. package/dist/namespaces/sui/types.d.ts +12 -0
  179. package/dist/namespaces/sui/types.d.ts.map +1 -0
  180. package/dist/namespaces/sui/utils.d.ts +15 -0
  181. package/dist/namespaces/sui/utils.d.ts.map +1 -0
  182. package/dist/namespaces/tron/actions.d.ts +2 -0
  183. package/dist/namespaces/tron/actions.d.ts.map +1 -0
  184. package/dist/namespaces/tron/after.d.ts +2 -0
  185. package/dist/namespaces/tron/after.d.ts.map +1 -0
  186. package/dist/namespaces/tron/and.d.ts +3 -0
  187. package/dist/namespaces/tron/and.d.ts.map +1 -0
  188. package/dist/namespaces/tron/before.d.ts +2 -0
  189. package/dist/namespaces/tron/before.d.ts.map +1 -0
  190. package/dist/namespaces/tron/builders.d.ts +5 -0
  191. package/dist/namespaces/tron/builders.d.ts.map +1 -0
  192. package/dist/namespaces/tron/constants.d.ts +3 -0
  193. package/dist/namespaces/tron/constants.d.ts.map +1 -0
  194. package/dist/namespaces/tron/mod.d.ts +9 -0
  195. package/dist/namespaces/tron/mod.d.ts.map +1 -0
  196. package/dist/namespaces/tron/mod.js +2 -0
  197. package/dist/namespaces/tron/mod.js.map +7 -0
  198. package/dist/namespaces/tron/types.d.ts +8 -0
  199. package/dist/namespaces/tron/types.d.ts.map +1 -0
  200. package/dist/namespaces/tron/utils.d.ts +2 -0
  201. package/dist/namespaces/tron/utils.d.ts.map +1 -0
  202. package/dist/namespaces/utxo/actions.d.ts +2 -0
  203. package/dist/namespaces/utxo/actions.d.ts.map +1 -0
  204. package/dist/namespaces/utxo/after.d.ts +2 -0
  205. package/dist/namespaces/utxo/after.d.ts.map +1 -0
  206. package/dist/namespaces/utxo/and.d.ts +3 -0
  207. package/dist/namespaces/utxo/and.d.ts.map +1 -0
  208. package/dist/namespaces/utxo/before.d.ts +2 -0
  209. package/dist/namespaces/utxo/before.d.ts.map +1 -0
  210. package/dist/namespaces/utxo/builders.d.ts +4 -0
  211. package/dist/namespaces/utxo/builders.d.ts.map +1 -0
  212. package/dist/namespaces/utxo/constants.d.ts +3 -0
  213. package/dist/namespaces/utxo/constants.d.ts.map +1 -0
  214. package/dist/namespaces/utxo/mod.d.ts +9 -0
  215. package/dist/namespaces/utxo/mod.d.ts.map +1 -0
  216. package/dist/namespaces/utxo/mod.js +2 -0
  217. package/dist/namespaces/utxo/mod.js.map +7 -0
  218. package/dist/namespaces/utxo/types.d.ts +8 -0
  219. package/dist/namespaces/utxo/types.d.ts.map +1 -0
  220. package/dist/namespaces/utxo/utils.d.ts +2 -0
  221. package/dist/namespaces/utxo/utils.d.ts.map +1 -0
  222. package/dist/test-utils/fixtures.d.ts +4 -0
  223. package/dist/test-utils/fixtures.d.ts.map +1 -0
  224. package/dist/types/accounts.d.ts +11 -0
  225. package/dist/types/accounts.d.ts.map +1 -0
  226. package/dist/types/actions.d.ts +5 -0
  227. package/dist/types/actions.d.ts.map +1 -0
  228. package/dist/types/mod.d.ts +2 -0
  229. package/dist/types/mod.d.ts.map +1 -0
  230. package/dist/types/utils.d.ts +7 -0
  231. package/dist/types/utils.d.ts.map +1 -0
  232. package/dist/utils/mod.d.ts +4 -0
  233. package/dist/utils/mod.d.ts.map +1 -0
  234. package/dist/utils/mod.js +2 -0
  235. package/dist/utils/mod.js.map +7 -0
  236. package/dist/utils/versions.d.ts +21 -0
  237. package/dist/utils/versions.d.ts.map +1 -0
  238. package/dist/utils/versions.test.d.ts +2 -0
  239. package/dist/utils/versions.test.d.ts.map +1 -0
  240. package/dist/wallets-core.build.json +1 -0
  241. package/legacy/package.json +8 -0
  242. package/package.json +84 -0
  243. package/readme.md +4 -0
  244. package/src/builders/action.ts +86 -0
  245. package/src/builders/mod.ts +5 -0
  246. package/src/builders/namespace.ts +258 -0
  247. package/src/builders/provider.ts +61 -0
  248. package/src/builders/types.ts +29 -0
  249. package/src/hub/helpers.ts +11 -0
  250. package/src/hub/hub.ts +128 -0
  251. package/src/hub/mod.ts +18 -0
  252. package/src/hub/namespaces/errors.ts +11 -0
  253. package/src/hub/namespaces/mod.ts +10 -0
  254. package/src/hub/namespaces/namespace.test.ts +443 -0
  255. package/src/hub/namespaces/namespace.ts +470 -0
  256. package/src/hub/namespaces/types.ts +58 -0
  257. package/src/hub/provider/mod.ts +10 -0
  258. package/src/hub/provider/provider.test.ts +232 -0
  259. package/src/hub/provider/provider.ts +335 -0
  260. package/src/hub/provider/types.ts +50 -0
  261. package/src/hub/store/events.ts +89 -0
  262. package/src/hub/store/extend.ts +125 -0
  263. package/src/hub/store/hub.ts +18 -0
  264. package/src/hub/store/mod.ts +25 -0
  265. package/src/hub/store/namespaces.ts +177 -0
  266. package/src/hub/store/providers.ts +169 -0
  267. package/src/hub/store/selectors.ts +59 -0
  268. package/src/hub/store/store.test.ts +50 -0
  269. package/src/hub/store/store.ts +30 -0
  270. package/src/legacy/helpers.ts +75 -0
  271. package/src/legacy/mod.ts +44 -0
  272. package/src/legacy/persistor.ts +19 -0
  273. package/src/legacy/types.ts +291 -0
  274. package/src/legacy/utils.ts +20 -0
  275. package/src/legacy/wallet.ts +552 -0
  276. package/src/mod.ts +44 -0
  277. package/src/namespaces/common/actions.ts +12 -0
  278. package/src/namespaces/common/after.ts +8 -0
  279. package/src/namespaces/common/and.ts +42 -0
  280. package/src/namespaces/common/before.ts +9 -0
  281. package/src/namespaces/common/builders.ts +14 -0
  282. package/src/namespaces/common/helpers.ts +10 -0
  283. package/src/namespaces/common/hooks/changeAccountSubscriber.test.ts +173 -0
  284. package/src/namespaces/common/hooks/changeAccountSubscriber.ts +236 -0
  285. package/src/namespaces/common/mod.ts +23 -0
  286. package/src/namespaces/common/or.ts +17 -0
  287. package/src/namespaces/common/types.ts +25 -0
  288. package/src/namespaces/common/utils.ts +43 -0
  289. package/src/namespaces/cosmos/actions.ts +3 -0
  290. package/src/namespaces/cosmos/after.ts +3 -0
  291. package/src/namespaces/cosmos/and.ts +5 -0
  292. package/src/namespaces/cosmos/before.ts +3 -0
  293. package/src/namespaces/cosmos/builders.ts +15 -0
  294. package/src/namespaces/cosmos/constants.ts +1 -0
  295. package/src/namespaces/cosmos/mod.ts +9 -0
  296. package/src/namespaces/cosmos/types.ts +26 -0
  297. package/src/namespaces/cosmos/utils.ts +21 -0
  298. package/src/namespaces/evm/actions.ts +119 -0
  299. package/src/namespaces/evm/after.ts +3 -0
  300. package/src/namespaces/evm/and.ts +5 -0
  301. package/src/namespaces/evm/before.ts +3 -0
  302. package/src/namespaces/evm/builders.ts +52 -0
  303. package/src/namespaces/evm/constants.ts +2 -0
  304. package/src/namespaces/evm/eip1193.ts +1415 -0
  305. package/src/namespaces/evm/hooks.ts +43 -0
  306. package/src/namespaces/evm/mod.ts +10 -0
  307. package/src/namespaces/evm/types.ts +33 -0
  308. package/src/namespaces/evm/utils.ts +106 -0
  309. package/src/namespaces/solana/actions.ts +44 -0
  310. package/src/namespaces/solana/after.ts +3 -0
  311. package/src/namespaces/solana/and.ts +5 -0
  312. package/src/namespaces/solana/before.ts +3 -0
  313. package/src/namespaces/solana/builders.ts +40 -0
  314. package/src/namespaces/solana/constants.ts +2 -0
  315. package/src/namespaces/solana/hooks.ts +10 -0
  316. package/src/namespaces/solana/mod.ts +10 -0
  317. package/src/namespaces/solana/types.ts +26 -0
  318. package/src/namespaces/solana/utils.ts +36 -0
  319. package/src/namespaces/sui/actions.ts +27 -0
  320. package/src/namespaces/sui/builders.ts +77 -0
  321. package/src/namespaces/sui/constants.ts +8 -0
  322. package/src/namespaces/sui/hooks.ts +10 -0
  323. package/src/namespaces/sui/mod.ts +8 -0
  324. package/src/namespaces/sui/types.ts +26 -0
  325. package/src/namespaces/sui/utils.ts +56 -0
  326. package/src/namespaces/tron/actions.ts +3 -0
  327. package/src/namespaces/tron/after.ts +3 -0
  328. package/src/namespaces/tron/and.ts +5 -0
  329. package/src/namespaces/tron/before.ts +3 -0
  330. package/src/namespaces/tron/builders.ts +15 -0
  331. package/src/namespaces/tron/constants.ts +8 -0
  332. package/src/namespaces/tron/mod.ts +8 -0
  333. package/src/namespaces/tron/types.ts +15 -0
  334. package/src/namespaces/tron/utils.ts +18 -0
  335. package/src/namespaces/utxo/actions.ts +3 -0
  336. package/src/namespaces/utxo/after.ts +3 -0
  337. package/src/namespaces/utxo/and.ts +5 -0
  338. package/src/namespaces/utxo/before.ts +3 -0
  339. package/src/namespaces/utxo/builders.ts +12 -0
  340. package/src/namespaces/utxo/constants.ts +2 -0
  341. package/src/namespaces/utxo/mod.ts +8 -0
  342. package/src/namespaces/utxo/types.ts +15 -0
  343. package/src/namespaces/utxo/utils.ts +18 -0
  344. package/src/test-utils/fixtures.ts +13 -0
  345. package/src/types/accounts.ts +12 -0
  346. package/src/types/actions.ts +11 -0
  347. package/src/types/mod.ts +1 -0
  348. package/src/types/utils.ts +7 -0
  349. package/src/utils/mod.ts +8 -0
  350. package/src/utils/versions.test.ts +22 -0
  351. package/src/utils/versions.ts +62 -0
@@ -0,0 +1,75 @@
1
+ import type { Network } from './types.js';
2
+ import type { Options } from './wallet.js';
3
+ import type { BlockchainMeta } from 'rango-types';
4
+
5
+ import { Networks } from './types.js';
6
+
7
+ export function formatAddressWithNetwork(
8
+ address: string,
9
+ network?: Network | null
10
+ ) {
11
+ return `${network || ''}:${address}`;
12
+ }
13
+
14
+ export function accountAddressesWithNetwork(
15
+ addresses: string[] | null,
16
+ network?: Network | null
17
+ ) {
18
+ if (!addresses) {
19
+ return [];
20
+ }
21
+
22
+ return addresses.map((address) => {
23
+ return formatAddressWithNetwork(address, network);
24
+ });
25
+ }
26
+
27
+ export function readAccountAddress(addressWithNetwork: string): {
28
+ address: string;
29
+ network: Network;
30
+ } {
31
+ const [network, address] = addressWithNetwork.split(':');
32
+
33
+ return {
34
+ network,
35
+ address,
36
+ };
37
+ }
38
+
39
+ export function needsCheckInstallation(options: Options) {
40
+ const { checkInstallation = true } = options.config;
41
+ return checkInstallation;
42
+ }
43
+
44
+ export const getBlockChainNameFromId = (
45
+ chainId: string | number,
46
+ blockchains: BlockchainMeta[]
47
+ ): Network | null => {
48
+ chainId =
49
+ typeof chainId === 'string' && chainId.startsWith('0x')
50
+ ? parseInt(chainId)
51
+ : chainId;
52
+
53
+ /*
54
+ * Sometimes providers are passing `Network` as chainId.
55
+ * If chainId is a `Network`, we return itself.
56
+ */
57
+ const allNetworks = Object.values(Networks);
58
+ if (allNetworks.includes(String(chainId) as Networks)) {
59
+ return chainId as Networks;
60
+ }
61
+
62
+ if (chainId === 'Binance-Chain-Tigris') {
63
+ return Networks.BINANCE;
64
+ }
65
+ return (
66
+ blockchains
67
+ .filter((blockchainMeta) => !!blockchainMeta.chainId)
68
+ .find((blockchainMeta) => {
69
+ const blockchainChainId = blockchainMeta.chainId?.startsWith('0x')
70
+ ? parseInt(blockchainMeta.chainId)
71
+ : blockchainMeta.chainId;
72
+ return blockchainChainId == chainId;
73
+ })?.name || null
74
+ );
75
+ };
@@ -0,0 +1,44 @@
1
+ /*
2
+ * All the exported types/values from legacy should be prefixed with `Legacy`
3
+ * since they will be removed soon and isn't part of the main interface for this package.
4
+ */
5
+ export type {
6
+ EventHandler as LegacyEventHandler,
7
+ State as LegacyState,
8
+ Options as LegacyOptions,
9
+ } from './wallet.js';
10
+
11
+ export type {
12
+ Connect as LegacyConnect,
13
+ Disconnect as LegacyDisconnect,
14
+ Subscribe as LegacySubscribe,
15
+ CanEagerConnect as LegacyCanEagerConnect,
16
+ SwitchNetwork as LegacySwitchNetwork,
17
+ Suggest as LegacySuggest,
18
+ CanSwitchNetwork as LegacyCanSwitchNetwork,
19
+ NamespaceData as LegacyNamespaceData,
20
+ ProviderInterface as LegacyProviderInterface,
21
+ NetworkProviderMap as LegacyNetworkProviderMap,
22
+ Network as LegacyNetwork,
23
+ WalletType as LegacyWalletType,
24
+ InstallObjects as LegacyInstallObjects,
25
+ WalletInfo as LegacyWalletInfo,
26
+ ConnectResult as LegacyConnectResult,
27
+ NamespaceInputForConnect as LegacyNamespaceInputForConnect,
28
+ NamespaceMeta as LegacyNamespaceMeta,
29
+ } from './types.js';
30
+
31
+ export { Events as LegacyEvents, Networks as LegacyNetworks } from './types.js';
32
+
33
+ export { Persistor } from './persistor.js';
34
+ export {
35
+ readAccountAddress as legacyReadAccountAddress,
36
+ getBlockChainNameFromId as legacyGetBlockChainNameFromId,
37
+ formatAddressWithNetwork as legacyFormatAddressWithNetwork,
38
+ } from './helpers.js';
39
+ export { default as LegacyWallet } from './wallet.js';
40
+
41
+ export {
42
+ eagerConnectHandler as legacyEagerConnectHandler,
43
+ isEvmNamespace as legacyIsEvmNamespace,
44
+ } from './utils.js';
@@ -0,0 +1,19 @@
1
+ export interface PersistStorage<T> {
2
+ getItem: (name: string) => T | null;
3
+ setItem: (name: string, value: T) => void;
4
+ removeItem: (name: string) => void;
5
+ }
6
+
7
+ export class Persistor<T> implements PersistStorage<T> {
8
+ getItem(name: string) {
9
+ const item = localStorage.getItem(name);
10
+ const parsedItem = item ? (JSON.parse(item) as T) : null;
11
+ return parsedItem;
12
+ }
13
+ setItem(name: string, value: T) {
14
+ localStorage.setItem(name, JSON.stringify(value));
15
+ }
16
+ removeItem(name: string) {
17
+ localStorage.removeItem(name);
18
+ }
19
+ }
@@ -0,0 +1,291 @@
1
+ import type { State as WalletState } from './wallet.js';
2
+ import type { Namespace } from '../namespaces/common/mod.js';
3
+ import type { BlockchainMeta, SignerFactory } from 'rango-types';
4
+
5
+ export enum Networks {
6
+ BTC = 'BTC',
7
+ BSC = 'BSC',
8
+ LTC = 'LTC',
9
+ THORCHAIN = 'THOR',
10
+ BCH = 'BCH',
11
+ BINANCE = 'BNB',
12
+ ETHEREUM = 'ETH',
13
+ POLYGON = 'POLYGON',
14
+ TERRA = 'TERRA',
15
+ POLKADOT = '',
16
+ TRON = 'TRON',
17
+ DOGE = 'DOGE',
18
+ HARMONY = 'HARMONY',
19
+ AVAX_CCHAIN = 'AVAX_CCHAIN',
20
+ FANTOM = 'FANTOM',
21
+ MOONBEAM = 'MOONBEAM',
22
+ ARBITRUM = 'ARBITRUM',
23
+ BOBA = 'BOBA',
24
+ OPTIMISM = 'OPTIMISM',
25
+ FUSE = 'FUSE',
26
+ CRONOS = 'CRONOS',
27
+ SOLANA = 'SOLANA',
28
+ MOONRIVER = 'MOONRIVER',
29
+ GNOSIS = 'GNOSIS',
30
+ COSMOS = 'COSMOS',
31
+ OSMOSIS = 'OSMOSIS',
32
+ AXELAR = 'AXELAR',
33
+ MARS = 'MARS',
34
+ STRIDE = 'STRIDE',
35
+ MAYA = 'MAYA',
36
+ AKASH = 'AKASH',
37
+ IRIS = 'IRIS',
38
+ PERSISTENCE = 'PERSISTENCE',
39
+ SENTINEL = 'SENTINEL',
40
+ REGEN = 'REGEN',
41
+ CRYPTO_ORG = 'CRYPTO_ORG',
42
+ SIF = 'SIF',
43
+ CHIHUAHUA = 'CHIHUAHUA',
44
+ JUNO = 'JUNO',
45
+ KUJIRA = 'KUJIRA',
46
+ STARNAME = 'STARNAME',
47
+ COMDEX = 'COMDEX',
48
+ STARGAZE = 'STARGAZE',
49
+ DESMOS = 'DESMOS',
50
+ BITCANNA = 'BITCANNA',
51
+ SECRET = 'SECRET',
52
+ INJECTIVE = 'INJECTIVE',
53
+ LUMNETWORK = 'LUMNETWORK',
54
+ BANDCHAIN = 'BANDCHAIN',
55
+ EMONEY = 'EMONEY',
56
+ BITSONG = 'BITSONG',
57
+ KI = 'KI',
58
+ MEDIBLOC = 'MEDIBLOC',
59
+ KONSTELLATION = 'KONSTELLATION',
60
+ UMEE = 'UMEE',
61
+ STARKNET = 'STARKNET',
62
+ TON = 'TON',
63
+ BASE = 'BASE',
64
+ SUI = 'SUI',
65
+ // Using instead of null
66
+ Unknown = 'Unkown',
67
+ }
68
+
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ type InstanceType = any;
71
+
72
+ export type NamespaceData = {
73
+ namespace: Namespace;
74
+ derivationPath?: string;
75
+ };
76
+
77
+ export type WalletType = string;
78
+ export type Network = string;
79
+
80
+ export type InstallObjects = {
81
+ CHROME?: string;
82
+ FIREFOX?: string;
83
+ EDGE?: string;
84
+ BRAVE?: string;
85
+ DEFAULT: string;
86
+ };
87
+
88
+ export type NamespaceMeta = {
89
+ label: string;
90
+ /**
91
+ * By using a matched `blockchain.name` (in meta) and `id`, we show logo in Namespace modal
92
+ * e.g. ETH
93
+ */
94
+ id: string;
95
+ value: Namespace;
96
+ unsupported?: boolean;
97
+ getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];
98
+ };
99
+
100
+ interface NeedsNamespace {
101
+ selection: 'single' | 'multiple';
102
+ data: NamespaceMeta[];
103
+ }
104
+
105
+ interface NeedsDerivationPath {
106
+ data: {
107
+ id: string;
108
+ label: string;
109
+ namespace: Namespace;
110
+ generateDerivationPath: (index: string) => string;
111
+ }[];
112
+ }
113
+
114
+ export type WalletInfo = {
115
+ name: string;
116
+ img: string;
117
+ installLink: InstallObjects | string;
118
+ /**
119
+ * @deprecated we don't use this value anymore.
120
+ */
121
+ color: string;
122
+ supportedChains: BlockchainMeta[];
123
+ showOnMobile?: boolean;
124
+ isContractWallet?: boolean;
125
+ mobileWallet?: boolean;
126
+
127
+ needsDerivationPath?: NeedsDerivationPath;
128
+ needsNamespace?: NeedsNamespace;
129
+ };
130
+
131
+ export type State = {
132
+ [key: string]: WalletState | undefined;
133
+ };
134
+
135
+ export type ConnectResult = {
136
+ accounts: string[] | null;
137
+ network: Network | null;
138
+ provider: InstanceType;
139
+ };
140
+
141
+ export type Providers = { [type in WalletType]?: InstanceType };
142
+ export type NetworkProviderMap = Map<Networks, unknown>;
143
+
144
+ export enum Events {
145
+ CONNECTED = 'connected',
146
+ CONNECTING = 'connecting',
147
+ REACHABLE = 'reachable',
148
+ INSTALLED = 'installed',
149
+ ACCOUNTS = 'accounts',
150
+ NETWORK = 'network',
151
+ // Hub only events
152
+ NAMESPACE_DISCONNECTED = 'namespace_disconnected',
153
+
154
+ PROVIDER_DISCONNECTED = 'provider_disconnected',
155
+ }
156
+
157
+ export type ProviderConnectResult = {
158
+ accounts: string[];
159
+ chainId: string;
160
+ derivationPath?: string;
161
+ };
162
+
163
+ export type GetInstanceOptions = {
164
+ network?: Network;
165
+ currentProvider: InstanceType;
166
+ meta: BlockchainMeta[];
167
+ getState: () => WalletState;
168
+ /**
169
+ * We always get the instance once and reuse it whenever we needs. By using this option
170
+ * We can force the library to get a new instance and replace it with the old one.
171
+ *
172
+ * Originally, we used this option for wallet connect 1 and its switching network challenge.
173
+ */
174
+ force?: boolean;
175
+ updateChainId: (chainId: number | string) => void;
176
+ };
177
+
178
+ export type GetInstance =
179
+ | (() => InstanceType)
180
+ | ((options: GetInstanceOptions) => Promise<InstanceType>);
181
+
182
+ export type TryGetInstance =
183
+ | (() => InstanceType)
184
+ | ((
185
+ options: Pick<GetInstanceOptions, 'force' | 'network'>
186
+ ) => Promise<InstanceType>);
187
+
188
+ export type Connect = (options: {
189
+ instance: InstanceType;
190
+ network?: Network;
191
+ meta: BlockchainMeta[];
192
+ namespaces?: NamespaceData[];
193
+ }) => Promise<ProviderConnectResult | ProviderConnectResult[]>;
194
+
195
+ export type Disconnect = (options: {
196
+ instance: InstanceType;
197
+ destroyInstance: () => void;
198
+ }) => Promise<void>;
199
+
200
+ type CleanupSubscribe = () => void;
201
+
202
+ export type Subscribe = (options: {
203
+ instance: InstanceType;
204
+ state: WalletState;
205
+ meta: BlockchainMeta[];
206
+ updateChainId: (chainId: string) => void;
207
+ updateAccounts: (accounts: string[], chainId?: string) => void;
208
+ connect: (network?: Network) => void;
209
+ disconnect: () => void;
210
+ }) => CleanupSubscribe | void;
211
+
212
+ export type SwitchNetwork = (options: {
213
+ instance: InstanceType;
214
+ network: Network;
215
+ meta: BlockchainMeta[];
216
+ newInstance?: TryGetInstance;
217
+ getState?: () => WalletState;
218
+ updateChainId: (chainId: string) => void;
219
+ }) => Promise<void>;
220
+
221
+ export type Suggest = (options: {
222
+ instance: InstanceType;
223
+ network: Network;
224
+ meta: BlockchainMeta[];
225
+ }) => Promise<void>;
226
+
227
+ export type CanSwitchNetwork = (options: {
228
+ network: Network;
229
+ meta: BlockchainMeta[];
230
+ provider: InstanceType;
231
+ }) => boolean;
232
+
233
+ export type CanEagerConnect = (options: {
234
+ instance: InstanceType;
235
+ meta: BlockchainMeta[];
236
+ }) => Promise<boolean>;
237
+
238
+ export type EagerConnectResult<I = unknown> = {
239
+ accounts: string[] | null;
240
+ network: string | null;
241
+ provider: I | null;
242
+ };
243
+
244
+ export interface WalletActions {
245
+ connect: Connect;
246
+ getInstance: InstanceType;
247
+ disconnect?: Disconnect;
248
+ subscribe?: Subscribe;
249
+ // unsubscribe, // coupled to subscribe.
250
+
251
+ // Optional, but should be provided at the same time.
252
+ suggest?: Suggest;
253
+ switchNetwork?: SwitchNetwork;
254
+ getSigners: (provider: InstanceType) => Promise<SignerFactory>;
255
+ canSwitchNetworkTo?: CanSwitchNetwork;
256
+ canEagerConnect?: CanEagerConnect;
257
+ getWalletInfo(allBlockChains: BlockchainMeta[]): WalletInfo;
258
+ }
259
+
260
+ export interface WalletConfig {
261
+ type: WalletType;
262
+ defaultNetwork?: Network;
263
+ checkInstallation?: boolean;
264
+ isAsyncInstance?: boolean;
265
+ isAsyncSwitchNetwork?: boolean;
266
+ }
267
+
268
+ export type WalletProviders = Map<
269
+ WalletType,
270
+ {
271
+ actions: WalletActions;
272
+ config: WalletConfig;
273
+ }
274
+ >;
275
+
276
+ export type ProviderInterface = { config: WalletConfig } & WalletActions;
277
+
278
+ // it comes from wallets.ts and `connect`
279
+ type NetworkTypeFromLegacyConnect = Network | undefined;
280
+
281
+ export type NamespaceInputForConnect<T extends Namespace = Namespace> = {
282
+ /**
283
+ * By default, you should specify namespace (e.g. evm).
284
+ */
285
+ namespace: T;
286
+ /**
287
+ * In some cases, we need to connect a specific network on a namespace. e.g. Polygon on EVM.
288
+ */
289
+ network: NetworkTypeFromLegacyConnect;
290
+ derivationPath?: string;
291
+ };
@@ -0,0 +1,20 @@
1
+ import type { NamespaceInputForConnect } from './types.js';
2
+
3
+ export async function eagerConnectHandler<R = unknown>(params: {
4
+ canEagerConnect: () => Promise<boolean>;
5
+ connectHandler: () => Promise<R>;
6
+ providerName: string;
7
+ }) {
8
+ // Check if we can eagerly connect to the wallet
9
+ if (await params.canEagerConnect()) {
10
+ // Connect to wallet as usual
11
+ return await params.connectHandler();
12
+ }
13
+ throw new Error(`can't restore connection for ${params.providerName}.`);
14
+ }
15
+
16
+ export function isEvmNamespace(
17
+ namespace: NamespaceInputForConnect
18
+ ): namespace is NamespaceInputForConnect<'EVM'> {
19
+ return namespace.namespace === 'EVM';
20
+ }