@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,232 @@
1
+ import type { EvmActions } from '../../namespaces/evm/types.js';
2
+ import type { SolanaActions } from '../../namespaces/solana/types.js';
3
+ import type { Store } from '../store/mod.js';
4
+
5
+ import { beforeEach, describe, expect, test, vi } from 'vitest';
6
+
7
+ import { NamespaceBuilder } from '../../builders/namespace.js';
8
+ import { ProviderBuilder } from '../../builders/provider.js';
9
+ import {
10
+ garbageWalletInfo,
11
+ garbageWalletMetaData,
12
+ } from '../../test-utils/fixtures.js';
13
+ import { createStore } from '../store/mod.js';
14
+
15
+ import { Provider } from './provider.js';
16
+
17
+ describe('check providers', () => {
18
+ let namespaces: {
19
+ evm: NamespaceBuilder<EvmActions>;
20
+ solana: NamespaceBuilder<SolanaActions>;
21
+ };
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ let namespacesMap: Map<any, any>;
24
+ let store: Store;
25
+
26
+ beforeEach(() => {
27
+ store = createStore();
28
+ const evmNamespace = new NamespaceBuilder<EvmActions>('eip155', 'garbage');
29
+ const solanaNamespace = new NamespaceBuilder<SolanaActions>(
30
+ 'solana',
31
+ 'garbage'
32
+ );
33
+
34
+ namespaces = {
35
+ evm: evmNamespace,
36
+ solana: solanaNamespace,
37
+ };
38
+
39
+ namespacesMap = new Map();
40
+ namespacesMap.set('evm', evmNamespace.build());
41
+ namespacesMap.set('solana', solanaNamespace.build());
42
+
43
+ return () => {
44
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
+ // @ts-ignore-next-line
46
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
47
+ (store = undefined), (namespaces = undefined);
48
+ };
49
+ });
50
+
51
+ test('Initialize providers correctly', () => {
52
+ const provider = new Provider('garbage', namespacesMap, garbageWalletInfo);
53
+
54
+ const allNamespaces = provider.getAll();
55
+
56
+ expect(allNamespaces.size).toBe(2);
57
+ });
58
+
59
+ test('throw error if state() is called before store initialization', () => {
60
+ const provider = new Provider('garbage', namespacesMap, garbageWalletInfo);
61
+
62
+ expect(() => provider.state()).toThrowError();
63
+ });
64
+
65
+ test('should return wallet info via info() without store initialization', () => {
66
+ const provider = new Provider('garbage', namespacesMap, garbageWalletInfo);
67
+
68
+ expect(provider.info()).toBe(garbageWalletInfo);
69
+ });
70
+
71
+ test('should return wallet info via info() after store initialization', () => {
72
+ const store = createStore();
73
+ const provider = new Provider('garbage', namespacesMap, garbageWalletInfo, {
74
+ store,
75
+ });
76
+
77
+ expect(provider.info()).toMatchObject(
78
+ store.getState().providers.list['garbage'].config
79
+ );
80
+ });
81
+
82
+ test('access state correctly', () => {
83
+ const provider = new Provider('garbage', namespacesMap, garbageWalletInfo, {
84
+ store: createStore(),
85
+ });
86
+
87
+ const [getState, setState] = provider.state();
88
+
89
+ expect(getState().connected).toBe(false);
90
+ expect(getState('connected')).toBe(false);
91
+ expect(() => {
92
+ // @ts-expect-error intentionally using an state that doesn't exist.
93
+ getState('not_exist_state');
94
+ }).toThrowError();
95
+ expect(() => {
96
+ // @ts-expect-error intentionally using an state that doesn't exist and try to update.
97
+ setState('another_not_exist_state');
98
+ }).toThrowError();
99
+ });
100
+ test('update state properly', () => {
101
+ const store = createStore();
102
+ const provider = new Provider('garbage', namespacesMap, garbageWalletInfo, {
103
+ store,
104
+ });
105
+
106
+ const [getState, setState] = provider.state();
107
+
108
+ provider.store(store);
109
+ setState('installed', true);
110
+ const isInstalled = getState('installed');
111
+ expect(isInstalled).toBe(true);
112
+ });
113
+
114
+ test('run namespace actions from provider', async () => {
115
+ const { evm, solana } = namespaces;
116
+ solana.action('connect', async () => [
117
+ 'solana:mainnet:0x000000000000000000000000000000000000dead',
118
+ ]);
119
+ const testNamespaces = new Map();
120
+ testNamespaces.set('evm', evm.build());
121
+ testNamespaces.set('solana', solana.build());
122
+
123
+ const provider = new Provider('garbage', testNamespaces, garbageWalletInfo);
124
+
125
+ const result = await provider.get('solana')?.connect();
126
+
127
+ expect(result).toStrictEqual([
128
+ 'solana:mainnet:0x000000000000000000000000000000000000dead',
129
+ ]);
130
+ // Since we didn't add any action regarding connect for `evm`
131
+ await expect(async () =>
132
+ provider.get('evm')?.connect('0x1')
133
+ ).rejects.toThrowError();
134
+ });
135
+
136
+ test('sets config properly', () => {
137
+ const builder = new ProviderBuilder('garbage');
138
+ builder.config('metadata', garbageWalletMetaData);
139
+ const provider = builder.build().store(store);
140
+
141
+ expect(provider.info()?.metadata).toStrictEqual(garbageWalletMetaData);
142
+ });
143
+
144
+ test('.init should works on Provider', () => {
145
+ const builder = new ProviderBuilder('garbage').config(
146
+ 'metadata',
147
+ garbageWalletMetaData
148
+ );
149
+ let count = 0;
150
+ builder.init(() => {
151
+ count++;
152
+ });
153
+ const provider = builder.build().store(store);
154
+ expect(count).toBe(0);
155
+ provider.init();
156
+ provider.init();
157
+ provider.init();
158
+ expect(count).toBe(1);
159
+ });
160
+
161
+ test(".init shouldn't do anything when use hasn't set anything", () => {
162
+ const builder = new ProviderBuilder('garbage').config(
163
+ 'metadata',
164
+ garbageWalletMetaData
165
+ );
166
+ const provider = builder.build().store(store);
167
+ expect(() => {
168
+ provider.init();
169
+ provider.init();
170
+ provider.init();
171
+ }).not.toThrow();
172
+ });
173
+
174
+ test('A provider can be found using its namespace', () => {
175
+ const builder = new ProviderBuilder('garbage', { store }).config(
176
+ 'metadata',
177
+ garbageWalletMetaData
178
+ );
179
+
180
+ const { evm, solana } = namespaces;
181
+ builder.add('evm', evm.build()).add('solana', solana.build());
182
+ const provider = builder.build();
183
+
184
+ const result = provider.findByNamespace('solana');
185
+ expect(result).toBeDefined();
186
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
187
+ // @ts-ignore-next-line
188
+ expect(result?.namespaceId).toBe('solana');
189
+
190
+ const result2 = provider.findByNamespace('evm');
191
+ expect(result2).toBeUndefined();
192
+ });
193
+
194
+ test('`before/after` is calling with correct context ', () => {
195
+ const connect = vi.fn();
196
+ const before = vi.fn(function (context) {
197
+ const [, setState] = context.state();
198
+ setState('installed', true);
199
+ });
200
+ const after = vi.fn(function (context) {
201
+ const [, setState] = context.state();
202
+ setState('installed', false);
203
+ });
204
+
205
+ const { evm } = namespaces;
206
+ const evmNamespace = evm.action('connect', connect).build();
207
+
208
+ const builder = new ProviderBuilder('garbage', { store })
209
+ .add('evm', evmNamespace)
210
+ .config('metadata', garbageWalletMetaData);
211
+ const provider = builder.build();
212
+
213
+ const [getState] = provider.state();
214
+ const result = provider.get('evm');
215
+
216
+ // Adding `after` then make it will run
217
+ provider.before('connect', before);
218
+ void result?.connect('whatever');
219
+
220
+ expect(connect).toBeCalledTimes(1);
221
+ expect(before).toBeCalledTimes(1);
222
+ expect(getState('installed')).toBe(true);
223
+
224
+ // Adding `after` then make it will run
225
+ provider.after('connect', after);
226
+ void result?.connect('whatever');
227
+ expect(connect).toBeCalledTimes(2);
228
+ expect(after).toBeCalledTimes(1);
229
+
230
+ expect(getState('installed')).toBe(false);
231
+ });
232
+ });
@@ -0,0 +1,335 @@
1
+ import type {
2
+ CommonNamespaces,
3
+ Context,
4
+ ExtendableInternalActions,
5
+ GetState,
6
+ RegisteredNamespaces,
7
+ SetState,
8
+ State,
9
+ } from './types.js';
10
+ import type { FindProxiedNamespace } from '../../builders/mod.js';
11
+ import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
12
+ import type { ProviderConfig, ProviderInfo, Store } from '../store/mod.js';
13
+
14
+ const VERSION = '1.0';
15
+
16
+ export class Provider {
17
+ public readonly id: string;
18
+ public readonly version = VERSION;
19
+
20
+ #namespaces: RegisteredNamespaces<keyof CommonNamespaces, CommonNamespaces>;
21
+ #initiated = false;
22
+ #extendInternalActions: ExtendableInternalActions = {};
23
+ #store: Store | undefined;
24
+ #configs: ProviderConfig;
25
+
26
+ constructor(
27
+ id: string,
28
+ namespaces: RegisteredNamespaces<keyof CommonNamespaces, CommonNamespaces>,
29
+ configs: ProviderConfig,
30
+ options?: {
31
+ /**
32
+ * There are some cases we need to have a behavior like initializing a provider which will be run when we are creating an instance.
33
+ * These internal steps and behaviors will be useful for library user to extend the behavior by running a specific code.
34
+ */
35
+ extendInternalActions?: ExtendableInternalActions;
36
+ store?: Store;
37
+ }
38
+ ) {
39
+ this.id = id;
40
+ this.#configs = configs;
41
+ // it should be only created here, to make sure `after/before` will work properly.
42
+ this.#extendInternalActions = options?.extendInternalActions || {};
43
+ this.#namespaces = namespaces;
44
+
45
+ /**
46
+ * Our assumption is that the store will be optional for the provider.
47
+ * If a store is provided in the options, it will be initialized and set up.
48
+ */
49
+ if (options?.store) {
50
+ this.#store = options.store;
51
+ this.#setupStore();
52
+ }
53
+ }
54
+
55
+ /**
56
+ * This is an special callback that will be called **only once**.
57
+ * We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
58
+ *
59
+ * ```ts
60
+ * const myInit = () => { whatever; } *
61
+ * const provider = new Provider(..., {extendInternalActions: {init: myInit} });
62
+ *
63
+ * // Will run `myInit`
64
+ * provider.init()
65
+ *
66
+ * // Will not run `myInit` anymore.
67
+ * provider.init()
68
+ * provider.init()
69
+ * ```
70
+ */
71
+ public init(): void {
72
+ if (this.#initiated) {
73
+ return;
74
+ }
75
+
76
+ const definedInitByUser = this.#extendInternalActions.init;
77
+ if (definedInitByUser) {
78
+ definedInitByUser(this.#context());
79
+ }
80
+
81
+ this.#initiated = true;
82
+ }
83
+
84
+ /**
85
+ * Getting state of a provider
86
+ *
87
+ * **Note:**
88
+ * Each namespace has it's own state as well, in Legacy we didn't have this separation and all of them was accessible through Provider itself
89
+ * To be compatible with legacy, `getState` has a logic to guess the final state to produce same state as legacy.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const provider = new Provider(...);
94
+ * const [getState, setState] = provider.state();
95
+ *
96
+ * getState('installed');
97
+ * // or
98
+ * getState().installed;
99
+ * ```
100
+ *
101
+ */
102
+ public state(): [GetState, SetState] {
103
+ const store = this.#store;
104
+ if (!store) {
105
+ throw new Error(
106
+ `Any store detected for ${this.id}. You need to set your store using '.store' method first.`
107
+ );
108
+ }
109
+
110
+ /**
111
+ * State updater
112
+ */
113
+ const setState: SetState = (name, value) => {
114
+ switch (name) {
115
+ case 'installed':
116
+ return store.getState().providers.updateStatus(this.id, name, value);
117
+ default:
118
+ throw new Error(
119
+ `Unhandled state update for provider. (provider id: ${this.id}, state name: ${name})`
120
+ );
121
+ }
122
+ };
123
+
124
+ /**
125
+ * State getter
126
+ */
127
+ const getState: GetState = <K extends keyof State>(name?: K) => {
128
+ const state: State = store
129
+ .getState()
130
+ .providers.guessNamespacesState(this.id);
131
+
132
+ if (!name) {
133
+ return state;
134
+ }
135
+
136
+ switch (name) {
137
+ case 'installed':
138
+ case 'connected':
139
+ case 'connecting':
140
+ return state[name];
141
+ default:
142
+ throw new Error('Unhandled state for provider');
143
+ }
144
+ };
145
+
146
+ return [getState, setState];
147
+ }
148
+
149
+ /**
150
+ * For keeping state, we need a store. all the states will be write to/read from store.
151
+ *
152
+ * **Note: When you are setting an store for provider, it will be set for its namespaces automatically as well**
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const myStore = createStore();
157
+ * const provider = new Provider(...);
158
+ * provider.store(myStore); // or it can be passed to Provider constructor;
159
+ * ```
160
+ */
161
+ public store(store: Store): this {
162
+ if (this.#store) {
163
+ console.warn(
164
+ "You've already set an store for your Provider. Old store will be replaced by the new one."
165
+ );
166
+ }
167
+ this.#store = store;
168
+ this.#setupStore();
169
+ return this;
170
+ }
171
+
172
+ /**
173
+ * Getting information about a provider which has been set on constructing Provider.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const walletInfo = {name: "Garbage wallet", ...}
178
+ * const provider = new Provider(..., {info: walletInfo});
179
+ *
180
+ * provider.info();
181
+ * ```
182
+ */
183
+ public info(): ProviderInfo | undefined {
184
+ const store = this.#store;
185
+ if (!store) {
186
+ return this.#configs;
187
+ }
188
+ const config = store.getState().providers.list[this.id].config;
189
+
190
+ return { metadata: config.metadata };
191
+ }
192
+
193
+ /**
194
+ * A list of registered _proxied_ namespaces.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * const provider = new Provider(...);
199
+ * const allNamespaces = provider.getAll();
200
+ * ```
201
+ */
202
+ public getAll(): RegisteredNamespaces<
203
+ keyof CommonNamespaces,
204
+ CommonNamespaces
205
+ > {
206
+ return this.#namespaces;
207
+ }
208
+
209
+ /**
210
+ * Get a registered namespace in provider by its **namespace key**.
211
+ *
212
+ * Note: difference between namespace key and namespace id is the first one is setting from a predefined list the second one can be anything and will be chosen by library's user.
213
+ *
214
+ * @param {string} id - evm, solana, cosmos, ... (CommonActions)
215
+ */
216
+ public get<K extends keyof CommonNamespaces>(
217
+ id: K
218
+ ): FindProxiedNamespace<K, CommonNamespaces> | undefined {
219
+ return this.#namespaces.get(id) as unknown as
220
+ | FindProxiedNamespace<K, CommonNamespaces>
221
+ | undefined;
222
+ }
223
+
224
+ /**
225
+ *
226
+ * Get a registered namespace by its **namespaceId**.
227
+ *
228
+ * Note: difference between namespace key and namespace id is the first one is setting from a predefined list the second one can be anything and will be chosen by library's user.
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * const provider = new Provider(...);
233
+ * provider.findByNamespace("whatever-id-i-set-for-namespace")
234
+ * ```
235
+ */
236
+ public findByNamespace<K extends keyof CommonNamespaces>(
237
+ namespaceLookingFor: K | string
238
+ ): FindProxiedNamespace<K, CommonNamespaces> | undefined {
239
+ // If we didn't found any match, we will return `undefined`.
240
+ let result: object | undefined = undefined;
241
+
242
+ this.#namespaces.forEach((namespace) => {
243
+ if (namespace.namespaceId === namespaceLookingFor) {
244
+ result = namespace;
245
+ }
246
+ });
247
+
248
+ return result;
249
+ }
250
+
251
+ /**
252
+ * Running a hook function _after_ a specific action for **all registered namespaces**.
253
+ *
254
+ * **Note:** the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * const provider = new Provider(...);
259
+ *
260
+ * provider.after("connect", (context) => {});
261
+ * ```
262
+ */
263
+ public before(
264
+ actionName: string,
265
+ hookFn: FunctionWithContext<AnyFunction, Context>
266
+ ): this {
267
+ this.#addHook('before', actionName, hookFn);
268
+ return this;
269
+ }
270
+
271
+ /**
272
+ * Running a hook function _before_ a specific action for **all registered namespaces**.
273
+ *
274
+ * **Note:** the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * const provider = new Provider(...);
279
+ *
280
+ * provider.after("connect", (context) => {});
281
+ * ```
282
+ */
283
+ public after(
284
+ actionName: string,
285
+ hookFn: FunctionWithContext<AnyFunction, Context>
286
+ ): this {
287
+ this.#addHook('after', actionName, hookFn);
288
+ return this;
289
+ }
290
+
291
+ #addHook(
292
+ hookName: 'after' | 'before',
293
+ actionName: string,
294
+ cb: FunctionWithContext<AnyFunction, Context>
295
+ ): this {
296
+ const context = {
297
+ state: this.state.bind(this),
298
+ };
299
+
300
+ this.#namespaces.forEach((namespace) => {
301
+ if (hookName === 'after') {
302
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
303
+ namespace.after(actionName as any, cb, {
304
+ context,
305
+ });
306
+ } else if (hookName === 'before') {
307
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
+ namespace.before(actionName as any, cb, {
309
+ context,
310
+ });
311
+ } else {
312
+ throw new Error(`You hook name is invalid: ${hookName}`);
313
+ }
314
+ });
315
+
316
+ return this;
317
+ }
318
+
319
+ #setupStore(): void {
320
+ const store = this.#store;
321
+ if (!store) {
322
+ throw new Error('For setup store, you should set `store` first.');
323
+ }
324
+ store.getState().providers.addProvider(this.id, this.#configs);
325
+ this.#namespaces.forEach((provider) => {
326
+ provider.store(store);
327
+ });
328
+ }
329
+
330
+ #context(): Context {
331
+ return {
332
+ state: this.state.bind(this),
333
+ };
334
+ }
335
+ }
@@ -0,0 +1,50 @@
1
+ import type { FindProxiedNamespace } from '../../builders/mod.js';
2
+ import type { Store } from '../../hub/mod.js';
3
+ import type { LegacyState } from '../../legacy/mod.js';
4
+ import type { CosmosActions } from '../../namespaces/cosmos/mod.js';
5
+ import type { EvmActions } from '../../namespaces/evm/mod.js';
6
+ import type { SolanaActions } from '../../namespaces/solana/mod.js';
7
+ import type { SuiActions } from '../../namespaces/sui/mod.js';
8
+ import type { TronActions } from '../../namespaces/tron/types.js';
9
+ import type { UtxoActions } from '../../namespaces/utxo/mod.js';
10
+ import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
11
+ import type { Prettify } from '../../types/utils.js';
12
+
13
+ export type Context = {
14
+ state: () => [GetState, SetState];
15
+ };
16
+
17
+ export type State = Omit<
18
+ LegacyState,
19
+ 'reachable' | 'accounts' | 'network' | 'derivationPath'
20
+ >;
21
+ export type SetState = <K extends keyof Pick<State, 'installed'>>(
22
+ name: K,
23
+ value: State[K]
24
+ ) => void;
25
+ export type GetState = {
26
+ (): State;
27
+ <K extends keyof State>(name: K): State[K];
28
+ };
29
+
30
+ export interface CommonNamespaces {
31
+ evm: EvmActions;
32
+ solana: SolanaActions;
33
+ cosmos: CosmosActions;
34
+ sui: SuiActions;
35
+ utxo: UtxoActions;
36
+ tron: TronActions;
37
+ }
38
+
39
+ export type CommonNamespaceKeys = Prettify<keyof CommonNamespaces>;
40
+
41
+ export interface ExtendableInternalActions {
42
+ init?: FunctionWithContext<AnyFunction, Context>;
43
+ }
44
+
45
+ export type RegisteredNamespaces<K extends keyof T, T> = Map<
46
+ K,
47
+ FindProxiedNamespace<K, T>
48
+ >;
49
+
50
+ export type ProviderBuilderOptions = { store?: Store };
@@ -0,0 +1,89 @@
1
+ export type NamespaceDisconnectedEvent = {
2
+ type: 'namespace_disconnected';
3
+ provider: string;
4
+ namespace: string;
5
+ };
6
+
7
+ export type NamespaceConnectedEvent = {
8
+ type: 'namespace_connected';
9
+ provider: string;
10
+ namespace: string;
11
+ accounts: string[];
12
+ };
13
+
14
+ export type NamespaceSwitchedAccountEvent = {
15
+ type: 'namespace_account_switched';
16
+ provider: string;
17
+ namespace: string;
18
+ accounts: string[];
19
+ previousAccounts: string[];
20
+ };
21
+
22
+ export type NamespaceSwitchedNetworkEvent = {
23
+ type: 'namespace_network_switched';
24
+ provider: string;
25
+ namespace: string;
26
+ network: string;
27
+ previousNetwork: string | null;
28
+ };
29
+
30
+ export type ProviderDetectedEvent = {
31
+ type: 'provider_detected';
32
+ provider: string;
33
+ };
34
+
35
+ export type ProviderConnectingEvent = {
36
+ type: 'provider_connecting';
37
+ provider: string;
38
+ value: boolean;
39
+ };
40
+
41
+ export type ProviderConnectedEvent = {
42
+ type: 'provider_connected';
43
+ provider: string;
44
+ };
45
+
46
+ export type ProviderDisconnectedEvent = {
47
+ type: 'provider_disconnected';
48
+ provider: string;
49
+ };
50
+
51
+ export type Event =
52
+ | NamespaceDisconnectedEvent
53
+ | NamespaceConnectedEvent
54
+ | NamespaceSwitchedAccountEvent
55
+ | NamespaceSwitchedNetworkEvent
56
+ | ProviderDetectedEvent
57
+ | ProviderConnectingEvent
58
+ | ProviderConnectedEvent
59
+ | ProviderDisconnectedEvent;
60
+
61
+ /**
62
+ *
63
+ * Keeping an array of Event and when iterates over its values, it will be removed (consume) from the array.
64
+ *
65
+ */
66
+ export class ConsumableEvents {
67
+ #data: Event[] = [];
68
+
69
+ push(val: Event) {
70
+ this.#data.push(val);
71
+ }
72
+
73
+ [Symbol.iterator](): Iterator<Event> {
74
+ return {
75
+ next: (): IteratorResult<Event> => {
76
+ if (this.#data.length == 0) {
77
+ return { done: true, value: undefined };
78
+ }
79
+
80
+ // Typescript can not narrow the type, but we have a runtime check to ensure it will never be an empty list
81
+ const value = this.#data.shift()!;
82
+ return {
83
+ done: false,
84
+ value,
85
+ };
86
+ },
87
+ };
88
+ }
89
+ }