@rango-dev/wallets-core 0.38.0 → 0.38.1-next.1

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 (201) hide show
  1. package/CHANGELOG.md +4 -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 +28 -0
  15. package/dist/hub/hub.d.ts.map +1 -0
  16. package/dist/hub/mod.d.ts +7 -0
  17. package/dist/hub/mod.d.ts.map +1 -0
  18. package/dist/hub/namespaces/errors.d.ts +4 -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 +146 -0
  23. package/dist/hub/namespaces/namespace.d.ts.map +1 -0
  24. package/dist/hub/namespaces/namespace.test.d.ts +2 -0
  25. package/dist/hub/namespaces/namespace.test.d.ts.map +1 -0
  26. package/dist/hub/namespaces/types.d.ts +33 -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 +28 -0
  35. package/dist/hub/provider/types.d.ts.map +1 -0
  36. package/dist/hub/store/hub.d.ts +11 -0
  37. package/dist/hub/store/hub.d.ts.map +1 -0
  38. package/dist/hub/store/mod.d.ts +6 -0
  39. package/dist/hub/store/mod.d.ts.map +1 -0
  40. package/dist/hub/store/namespaces.d.ts +34 -0
  41. package/dist/hub/store/namespaces.d.ts.map +1 -0
  42. package/dist/hub/store/providers.d.ts +45 -0
  43. package/dist/hub/store/providers.d.ts.map +1 -0
  44. package/dist/hub/store/selectors.d.ts +18 -0
  45. package/dist/hub/store/selectors.d.ts.map +1 -0
  46. package/dist/hub/store/store.d.ts +13 -0
  47. package/dist/hub/store/store.d.ts.map +1 -0
  48. package/dist/hub/store/store.test.d.ts +2 -0
  49. package/dist/hub/store/store.test.d.ts.map +1 -0
  50. package/dist/legacy/mod.js +1 -1
  51. package/dist/legacy/mod.js.map +2 -2
  52. package/dist/legacy/types.d.ts +1 -1
  53. package/dist/legacy/types.d.ts.map +1 -1
  54. package/dist/legacy/wallet.d.ts +1 -1
  55. package/dist/legacy/wallet.d.ts.map +1 -1
  56. package/dist/mod.d.ts +6 -1
  57. package/dist/mod.d.ts.map +1 -1
  58. package/dist/mod.js +1 -0
  59. package/dist/mod.js.map +4 -4
  60. package/dist/namespaces/common/actions.d.ts +4 -0
  61. package/dist/namespaces/common/actions.d.ts.map +1 -0
  62. package/dist/namespaces/common/after.d.ts +4 -0
  63. package/dist/namespaces/common/after.d.ts.map +1 -0
  64. package/dist/namespaces/common/and.d.ts +6 -0
  65. package/dist/namespaces/common/and.d.ts.map +1 -0
  66. package/dist/namespaces/common/before.d.ts +4 -0
  67. package/dist/namespaces/common/before.d.ts.map +1 -0
  68. package/dist/namespaces/common/builders.d.ts +4 -0
  69. package/dist/namespaces/common/builders.d.ts.map +1 -0
  70. package/dist/namespaces/common/helpers.d.ts +2 -0
  71. package/dist/namespaces/common/helpers.d.ts.map +1 -0
  72. package/dist/namespaces/common/mod.d.ts +6 -0
  73. package/dist/namespaces/common/mod.d.ts.map +1 -0
  74. package/dist/namespaces/common/mod.js +2 -0
  75. package/dist/namespaces/common/mod.js.map +7 -0
  76. package/dist/namespaces/common/types.d.ts +7 -0
  77. package/dist/namespaces/common/types.d.ts.map +1 -0
  78. package/dist/namespaces/cosmos/mod.d.ts +2 -0
  79. package/dist/namespaces/cosmos/mod.d.ts.map +1 -0
  80. package/dist/namespaces/cosmos/types.d.ts +4 -0
  81. package/dist/namespaces/cosmos/types.d.ts.map +1 -0
  82. package/dist/namespaces/evm/actions.d.ts +8 -0
  83. package/dist/namespaces/evm/actions.d.ts.map +1 -0
  84. package/dist/namespaces/evm/after.d.ts +2 -0
  85. package/dist/namespaces/evm/after.d.ts.map +1 -0
  86. package/dist/namespaces/evm/and.d.ts +3 -0
  87. package/dist/namespaces/evm/and.d.ts.map +1 -0
  88. package/dist/namespaces/evm/before.d.ts +2 -0
  89. package/dist/namespaces/evm/before.d.ts.map +1 -0
  90. package/dist/namespaces/evm/builders.d.ts +4 -0
  91. package/dist/namespaces/evm/builders.d.ts.map +1 -0
  92. package/dist/namespaces/evm/constants.d.ts +3 -0
  93. package/dist/namespaces/evm/constants.d.ts.map +1 -0
  94. package/dist/namespaces/evm/eip1193.d.ts +1228 -0
  95. package/dist/namespaces/evm/eip1193.d.ts.map +1 -0
  96. package/dist/namespaces/evm/mod.d.ts +9 -0
  97. package/dist/namespaces/evm/mod.d.ts.map +1 -0
  98. package/dist/namespaces/evm/mod.js +2 -0
  99. package/dist/namespaces/evm/mod.js.map +7 -0
  100. package/dist/namespaces/evm/types.d.ts +10 -0
  101. package/dist/namespaces/evm/types.d.ts.map +1 -0
  102. package/dist/namespaces/evm/utils.d.ts +9 -0
  103. package/dist/namespaces/evm/utils.d.ts.map +1 -0
  104. package/dist/namespaces/solana/actions.d.ts +6 -0
  105. package/dist/namespaces/solana/actions.d.ts.map +1 -0
  106. package/dist/namespaces/solana/after.d.ts +2 -0
  107. package/dist/namespaces/solana/after.d.ts.map +1 -0
  108. package/dist/namespaces/solana/and.d.ts +3 -0
  109. package/dist/namespaces/solana/and.d.ts.map +1 -0
  110. package/dist/namespaces/solana/before.d.ts +2 -0
  111. package/dist/namespaces/solana/before.d.ts.map +1 -0
  112. package/dist/namespaces/solana/builders.d.ts +4 -0
  113. package/dist/namespaces/solana/builders.d.ts.map +1 -0
  114. package/dist/namespaces/solana/constants.d.ts +3 -0
  115. package/dist/namespaces/solana/constants.d.ts.map +1 -0
  116. package/dist/namespaces/solana/mod.d.ts +8 -0
  117. package/dist/namespaces/solana/mod.d.ts.map +1 -0
  118. package/dist/namespaces/solana/mod.js +2 -0
  119. package/dist/namespaces/solana/mod.js.map +7 -0
  120. package/dist/namespaces/solana/types.d.ts +7 -0
  121. package/dist/namespaces/solana/types.d.ts.map +1 -0
  122. package/dist/test-utils/fixtures.d.ts +3 -0
  123. package/dist/test-utils/fixtures.d.ts.map +1 -0
  124. package/dist/types/accounts.d.ts +11 -0
  125. package/dist/types/accounts.d.ts.map +1 -0
  126. package/dist/types/actions.d.ts +5 -0
  127. package/dist/types/actions.d.ts.map +1 -0
  128. package/dist/types/utils.d.ts +7 -0
  129. package/dist/types/utils.d.ts.map +1 -0
  130. package/dist/utils/mod.d.ts +4 -0
  131. package/dist/utils/mod.d.ts.map +1 -0
  132. package/dist/utils/mod.js +2 -0
  133. package/dist/utils/mod.js.map +7 -0
  134. package/dist/utils/versions.d.ts +21 -0
  135. package/dist/utils/versions.d.ts.map +1 -0
  136. package/dist/utils/versions.test.d.ts +2 -0
  137. package/dist/utils/versions.test.d.ts.map +1 -0
  138. package/dist/wallets-core.build.json +1 -1
  139. package/package.json +25 -4
  140. package/src/builders/action.ts +86 -0
  141. package/src/builders/mod.ts +5 -0
  142. package/src/builders/namespace.ts +229 -0
  143. package/src/builders/provider.ts +61 -0
  144. package/src/builders/types.ts +29 -0
  145. package/src/hub/helpers.ts +11 -0
  146. package/src/hub/hub.ts +122 -0
  147. package/src/hub/mod.ts +10 -0
  148. package/src/hub/namespaces/errors.ts +8 -0
  149. package/src/hub/namespaces/mod.ts +9 -0
  150. package/src/hub/namespaces/namespace.test.ts +333 -0
  151. package/src/hub/namespaces/namespace.ts +443 -0
  152. package/src/hub/namespaces/types.ts +50 -0
  153. package/src/hub/provider/mod.ts +9 -0
  154. package/src/hub/provider/provider.test.ts +231 -0
  155. package/src/hub/provider/provider.ts +330 -0
  156. package/src/hub/provider/types.ts +37 -0
  157. package/src/hub/store/hub.ts +18 -0
  158. package/src/hub/store/mod.ts +8 -0
  159. package/src/hub/store/namespaces.ts +90 -0
  160. package/src/hub/store/providers.ts +97 -0
  161. package/src/hub/store/selectors.ts +59 -0
  162. package/src/hub/store/store.test.ts +32 -0
  163. package/src/hub/store/store.ts +26 -0
  164. package/src/legacy/types.ts +1 -1
  165. package/src/legacy/wallet.ts +2 -2
  166. package/src/mod.ts +35 -1
  167. package/src/namespaces/common/actions.ts +11 -0
  168. package/src/namespaces/common/after.ts +8 -0
  169. package/src/namespaces/common/and.ts +42 -0
  170. package/src/namespaces/common/before.ts +9 -0
  171. package/src/namespaces/common/builders.ts +19 -0
  172. package/src/namespaces/common/helpers.ts +10 -0
  173. package/src/namespaces/common/mod.ts +12 -0
  174. package/src/namespaces/common/types.ts +7 -0
  175. package/src/namespaces/cosmos/mod.ts +1 -0
  176. package/src/namespaces/cosmos/types.ts +10 -0
  177. package/src/namespaces/evm/actions.ts +97 -0
  178. package/src/namespaces/evm/after.ts +3 -0
  179. package/src/namespaces/evm/and.ts +5 -0
  180. package/src/namespaces/evm/before.ts +3 -0
  181. package/src/namespaces/evm/builders.ts +10 -0
  182. package/src/namespaces/evm/constants.ts +2 -0
  183. package/src/namespaces/evm/eip1193.ts +1414 -0
  184. package/src/namespaces/evm/mod.ts +9 -0
  185. package/src/namespaces/evm/types.ts +18 -0
  186. package/src/namespaces/evm/utils.ts +52 -0
  187. package/src/namespaces/solana/actions.ts +70 -0
  188. package/src/namespaces/solana/after.ts +3 -0
  189. package/src/namespaces/solana/and.ts +5 -0
  190. package/src/namespaces/solana/before.ts +3 -0
  191. package/src/namespaces/solana/builders.ts +10 -0
  192. package/src/namespaces/solana/constants.ts +2 -0
  193. package/src/namespaces/solana/mod.ts +8 -0
  194. package/src/namespaces/solana/types.ts +20 -0
  195. package/src/test-utils/fixtures.ts +9 -0
  196. package/src/types/accounts.ts +12 -0
  197. package/src/types/actions.ts +11 -0
  198. package/src/types/utils.ts +7 -0
  199. package/src/utils/mod.ts +8 -0
  200. package/src/utils/versions.test.ts +22 -0
  201. package/src/utils/versions.ts +63 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.38.0](https://github.com/rango-exchange/rango-client/compare/wallets-core@0.37.0...wallets-core@0.38.0) (2024-09-10)
2
+
3
+
4
+
1
5
  # [0.37.0](https://github.com/rango-exchange/rango-client/compare/wallets-core@0.36.1...wallets-core@0.37.0) (2024-08-11)
2
6
 
3
7
 
@@ -0,0 +1,22 @@
1
+ import type { Actions, Context, Operators } from '../hub/namespaces/types.js';
2
+ import type { AnyFunction, FunctionWithContext } from '../types/actions.js';
3
+ export interface ActionByBuilder<T, Context> {
4
+ actionName: keyof T;
5
+ and: Operators<T>;
6
+ or: Operators<T>;
7
+ after: Operators<T>;
8
+ before: Operators<T>;
9
+ action: FunctionWithContext<T[keyof T], Context>;
10
+ }
11
+ export declare class ActionBuilder<T extends Actions<T>, K extends keyof T> {
12
+ #private;
13
+ readonly name: K;
14
+ constructor(name: K);
15
+ and(action: FunctionWithContext<AnyFunction, Context<T>>): this;
16
+ or(action: FunctionWithContext<AnyFunction, Context<T>>): this;
17
+ before(action: FunctionWithContext<AnyFunction, Context<T>>): this;
18
+ after(action: FunctionWithContext<AnyFunction, Context<T>>): this;
19
+ action(action: FunctionWithContext<T[keyof T], Context<T>>): this;
20
+ build(): ActionByBuilder<T, Context<T>>;
21
+ }
22
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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C,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAc/C"}
@@ -0,0 +1,5 @@
1
+ export type { ProxiedNamespace, FindProxiedNamespace } from './types.js';
2
+ export { NamespaceBuilder } from './namespace.js';
3
+ export { ProviderBuilder } from './provider.js';
4
+ export { ActionBuilder } from './action.js';
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/builders/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { ActionByBuilder } from './action.js';
2
+ import type { ProxiedNamespace } from './types.js';
3
+ import type { Actions, Context } from '../hub/namespaces/mod.js';
4
+ import type { NamespaceConfig } from '../hub/store/mod.js';
5
+ import type { FunctionWithContext } from '../types/actions.js';
6
+ /**
7
+ * There are Namespace's methods that should be called directly on Proxy object.
8
+ * The Proxy object is creating in `.build`.
9
+ */
10
+ export declare const allowedMethods: readonly ["init", "state", "after", "before", "and_then", "or_else", "store"];
11
+ export declare class NamespaceBuilder<T extends Actions<T>> {
12
+ #private;
13
+ constructor(id: string, providerId: string);
14
+ /** There are some predefined configs that can be set for each namespace separately */
15
+ config<K extends keyof NamespaceConfig>(name: K, value: NamespaceConfig[K]): this;
16
+ /**
17
+ * Getting a list of actions.
18
+ *
19
+ * e.g.:
20
+ * ```ts
21
+ * .action([
22
+ * ["connect", () => {}],
23
+ * ["disconnect", () => {}]
24
+ * ])
25
+ * ```
26
+ *
27
+ */
28
+ action<K extends keyof T>(action: (readonly [K, FunctionWithContext<T[K], Context<T>>])[]): NamespaceBuilder<T>;
29
+ /**
30
+ *
31
+ * Add a single action
32
+ *
33
+ * e.g.:
34
+ * ```ts
35
+ * .action( ["connect", () => {}] )
36
+ * ```
37
+ */
38
+ action<K extends keyof T>(action: K, actionFn: FunctionWithContext<T[K], Context<T>>): NamespaceBuilder<T>;
39
+ action(action: ActionByBuilder<T, Context<T>>): NamespaceBuilder<T>;
40
+ /**
41
+ * By calling build, an instance of Namespace will be built.
42
+ *
43
+ * Note: it's not exactly a `Namespace`, it returns a Proxy which add more convenient use like `namespace.connect()` instead of `namespace.run("connect")`
44
+ */
45
+ build(): ProxiedNamespace<T>;
46
+ }
47
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/builders/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAc,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAI/D;;;GAGG;AACH,eAAO,MAAM,cAAc,+EAQjB,CAAC;AAEX,qBAAa,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC;;gBAYpC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAM1C,sFAAsF;IAC/E,MAAM,CAAC,CAAC,SAAS,MAAM,eAAe,EAC3C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC;IAM3B;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,EAC7B,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAC9D,gBAAgB,CAAC,CAAC,CAAC;IAEtB;;;;;;;;OAQG;IACI,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,EAC7B,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAC9C,gBAAgB,CAAC,CAAC,CAAC;IAEf,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;IA0C1E;;;;OAIG;IACI,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC;CAsGpC"}
@@ -0,0 +1,13 @@
1
+ import type { FindProxiedNamespace } from './types.js';
2
+ import type { CommonNamespaces, ExtendableInternalActions, ProviderBuilderOptions } from '../hub/provider/mod.js';
3
+ import type { ProviderConfig } from '../hub/store/mod.js';
4
+ import { Provider } from '../hub/provider/mod.js';
5
+ export declare class ProviderBuilder {
6
+ #private;
7
+ constructor(id: string, options?: ProviderBuilderOptions);
8
+ add<K extends keyof CommonNamespaces>(id: K, namespace: FindProxiedNamespace<K, CommonNamespaces>): this;
9
+ config<K extends keyof ProviderConfig>(name: K, value: ProviderConfig[K]): this;
10
+ init(cb: Exclude<ExtendableInternalActions['init'], undefined>): this;
11
+ build(): Provider;
12
+ }
13
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/builders/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,qBAAa,eAAe;;gBAOd,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAKjD,GAAG,CAAC,CAAC,SAAS,MAAM,gBAAgB,EACzC,EAAE,EAAE,CAAC,EACL,SAAS,EAAE,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,CAAC;IAS/C,MAAM,CAAC,CAAC,SAAS,MAAM,cAAc,EAC1C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;IAMnB,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAK9D,KAAK,IAAI,QAAQ;CAczB"}
@@ -0,0 +1,21 @@
1
+ import type { allowedMethods } from './namespace.js';
2
+ import type { Actions, Namespace } from '../hub/namespaces/mod.js';
3
+ type NamespacePublicValues = {
4
+ namespaceId: string;
5
+ providerId: string;
6
+ };
7
+ /**
8
+ * NamespaceBuilder is creating a proxy instead of return Namespace instance.
9
+ * The reason is improving access to actions. e.g `.connect()` instead of `.run('connect')`
10
+ */
11
+ export type ProxiedNamespace<T extends Actions<T>> = T & Pick<Namespace<T>, (typeof allowedMethods)[number]> & NamespacePublicValues;
12
+ /**
13
+ * This is useful when you gave a list of namespaces and want to map a key to corresponding namespace.
14
+ *
15
+ * e.g:
16
+ * Type List = { evm: EvmActions, solana: SolanaActions};
17
+ * FindProxiedNamespace<"solana", List>
18
+ */
19
+ export type FindProxiedNamespace<K extends keyof T, T> = T[K] extends Actions<T[K]> ? ProxiedNamespace<T[K]> : never;
20
+ export {};
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builders/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGnE,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GACpD,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,GACnD,qBAAqB,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAC3E,CAAC,CAAC,CAAC,CAAC,CACL,GACG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACtB,KAAK,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Note: This only works native async, if we are going to support for old transpilers like Babel.
3
+ */
4
+ export declare function isAsync(fn: Function): boolean;
5
+ export declare function generateStoreId(providerId: string, namespace: string): string;
6
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/hub/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,WAEnC;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAEpE"}
@@ -0,0 +1,28 @@
1
+ import type { State as NamespaceState } from './namespaces/mod.js';
2
+ import type { Provider, State as ProviderState } from './provider/mod.js';
3
+ import type { Store } from './store/mod.js';
4
+ type HubState = {
5
+ [key in string]: ProviderState & {
6
+ namespaces: NamespaceState[];
7
+ };
8
+ };
9
+ type RunAllResult = {
10
+ id: string;
11
+ provider: unknown;
12
+ namespaces: unknown[];
13
+ };
14
+ interface HubOptions {
15
+ store?: Store;
16
+ }
17
+ export declare class Hub {
18
+ #private;
19
+ constructor(options?: HubOptions);
20
+ init(): void;
21
+ runAll(action: string): RunAllResult[];
22
+ add(id: string, provider: Provider): this;
23
+ get(providerId: string): Provider | undefined;
24
+ getAll(): Map<string, Provider>;
25
+ state(): HubState;
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=hub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/hub/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,KAAK,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,KAAK,QAAQ,GAAG;KACb,GAAG,IAAI,MAAM,GAAG,aAAa,GAAG;QAC/B,UAAU,EAAE,cAAc,EAAE,CAAC;KAC9B;CACF,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,EAAE,CAAC;CACvB,CAAC;AAEF,UAAU,UAAU;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AACD,qBAAa,GAAG;;gBAIF,OAAO,CAAC,EAAE,UAAU;IAWhC,IAAI;IASJ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE;IAuCtC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;IAQlC,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI7C,MAAM;IAIN,KAAK,IAAI,QAAQ;CAuBlB"}
@@ -0,0 +1,7 @@
1
+ export { Namespace } from './namespaces/mod.js';
2
+ export { Provider } from './provider/mod.js';
3
+ export { Hub } from './hub.js';
4
+ export type { Store, State, ProviderInfo } from './store/mod.js';
5
+ export { createStore, guessProviderStateSelector, namespaceStateSelector, } from './store/mod.js';
6
+ export { generateStoreId } from './helpers.js';
7
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/hub/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,WAAW,EACX,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const ACTION_NOT_FOUND_ERROR: (name: string) => string;
2
+ export declare const OR_ELSE_ACTION_FAILED_ERROR: (name: string) => string;
3
+ export declare const NO_STORE_FOUND_ERROR = "For setup store, you should set `store` first.";
4
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,SAAU,MAAM,WACsB,CAAC;AAE1E,eAAO,MAAM,2BAA2B,SAAU,MAAM,WACZ,CAAC;AAE7C,eAAO,MAAM,oBAAoB,mDACiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { Subscriber, State, RegisteredActions as ActionsMap, Context, Actions, } from './types.js';
2
+ export { Namespace } from './namespace.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,KAAK,EACL,iBAAiB,IAAI,UAAU,EAC/B,OAAO,EACP,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,146 @@
1
+ import type { Actions, Context, GetState, RegisteredActions, SetState } from './types.js';
2
+ import type { AndFunction, AnyFunction, FunctionWithContext } from '../../types/actions.js';
3
+ import type { NamespaceConfig, Store } from '../store/mod.js';
4
+ /**
5
+ *
6
+ * A Namespace is a unit of wallets where usually handles connecting, signing, accounts, ...
7
+ * It will be injected by wallet in its object, for example, `window.phantom.ethereum` or `window.phantom.solana`
8
+ * Each namespace (like solana) has its own functionality which is not shared between all the blockchains.
9
+ * For example in EVM namespaces, you can have different networks (e.g. Ethereum,Polygon, ...) and there are specific flows to handle connecting to them or add a network and etc.
10
+ * But Solana doesn't have this concept and you will directly always connect to solana itself.
11
+ * This is true for signing a transaction, getting information about blockchain and more.
12
+ * So by creating a namespace for each of these, we can define a custom namespace based on blockchain's properties.
13
+ *
14
+ */
15
+ declare class Namespace<T extends Actions<T>> {
16
+ #private;
17
+ /** it will be used for `store` and accessing to store by its id mainly. */
18
+ readonly namespaceId: string;
19
+ /** it will be used for `store` and accessing to store by its id mainly. */
20
+ readonly providerId: string;
21
+ constructor(id: string, providerId: string, options: {
22
+ store?: Store;
23
+ configs?: NamespaceConfig;
24
+ actions: RegisteredActions<T>;
25
+ });
26
+ /**
27
+ * This is an special action that will be called **only once**.
28
+ * We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
29
+ *
30
+ * ```ts
31
+ * const myInit = () => { whatever; }
32
+ * const actions = new Map();
33
+ * actions.set("init", myInit)
34
+ * const ns = new Namespace(..., {actions});
35
+ *
36
+ * // Will run `myInit`
37
+ * ns.init()
38
+ *
39
+ * // Will not run `myInit` anymore.
40
+ * ns.init()
41
+ * ns.init()
42
+ * ```
43
+ */
44
+ init(): void;
45
+ /**
46
+ * Reading states from store and also update them.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const ns = new Namespace(...);
51
+ * const [getState, setState] = ns.state();
52
+ * ```
53
+ */
54
+ state(): [GetState, SetState];
55
+ /**
56
+ * For keeping state, we need a store. all the states will be write to/read from store.
57
+ *
58
+ * Note: Store can be setup on constructor as well.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const myStore = createStore();
63
+ * const ns = new Namespace(...);
64
+ * ns.store(myStore);
65
+ * ```
66
+ */
67
+ store(store: Store): this;
68
+ /**
69
+ * It's a boolean operator to run a sync function if action ran successfully.
70
+ * For example, if we have a `connect` action, we can add function to be run after `connect` if it ran successfully.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const ns = new Namespace(..);
75
+ *
76
+ * ns.and_then('connect', (context) => {
77
+ * ...
78
+ * });
79
+ * ```
80
+ *
81
+ */
82
+ and_then<K extends keyof T>(actionName: K, operatorFn: FunctionWithContext<AndFunction<T, K>, Context>): this;
83
+ /**
84
+ * It's a boolean operator to run a function to handle when an action fails.
85
+ * For example, if we have a `connect` action, we can add function to be run when `connect` fails (throw an error).
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const ns = new Namespace(..);
90
+ *
91
+ * ns.or_else('connect', (context, error) => {
92
+ * ...
93
+ * });
94
+ * ```
95
+ */
96
+ or_else<K extends keyof T>(actionName: K, operatorFn: FunctionWithContext<AnyFunction, Context>): this;
97
+ /**
98
+ * Running a function after a specific action
99
+ *
100
+ * Note: the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const ns = new Namespace(...);
105
+ *
106
+ * ns.after("connect", (context) => {});
107
+ * ```
108
+ */
109
+ after<K extends keyof T, C = unknown>(actionName: K, hook: FunctionWithContext<AnyFunction, C>, options?: {
110
+ context?: C;
111
+ }): this;
112
+ /**
113
+ * Running a function before a specific action
114
+ *
115
+ * Note: the context can be set from outside as well. this is useful for Provider to set its context instead of using namespace context.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const ns = new Namespace(...);
120
+ *
121
+ * ns.before("connect", (context) => {});
122
+ * ```
123
+ */
124
+ before<K extends keyof T, C = unknown>(actionName: K, hook: FunctionWithContext<AnyFunction, C>, options?: {
125
+ context?: C;
126
+ }): this;
127
+ /**
128
+ *
129
+ * Registered actions will be called using `run`. it will run an action and all the operators or hooks that assigned.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const actions = new Map();
134
+ * actions.set('connect', connectAction);
135
+ *
136
+ * const ns = new Namespace(NAMESPACE, PROVIDER_ID, {
137
+ * actions: actions,
138
+ * });
139
+ *
140
+ * ns.run("action");
141
+ * ```
142
+ */
143
+ run<K extends keyof T>(actionName: K, ...args: any[]): unknown | Promise<unknown>;
144
+ }
145
+ export { Namespace };
146
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,QAAQ,EAGR,iBAAiB,EACjB,QAAQ,EAET,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAU9D;;;;;;;;;;GAUG;AACH,cAAM,SAAS,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC;;IAClC,2EAA2E;IAC3E,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,2EAA2E;IAC3E,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAiBjC,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,KAAK,CA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,CAAC,EACb,GAAG,IAAI,EAAE,GAAG,EAAE,GACb,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CA+I9B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=namespace.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.test.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/namespace.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
2
+ import type { NamespaceData } from '../store/mod.js';
3
+ type ActionName<K> = K | Omit<K, string>;
4
+ export type Subscriber<C extends Actions<C>> = (context: Context<C>, ...args: any[]) => void;
5
+ export type SubscriberCleanUp<C extends Actions<C>> = (context: Context<C>, ...args: any[]) => void;
6
+ export type State = NamespaceData;
7
+ export type SetState = <K extends keyof State>(name: K, value: State[K]) => void;
8
+ export type GetState = {
9
+ (): State;
10
+ <K extends keyof State>(name: K): State[K];
11
+ };
12
+ export type RegisteredActions<T extends Actions<T>> = Map<ActionName<keyof T>, FunctionWithContext<T[keyof T], Context<T>>>;
13
+ export type AndUseActions<T> = Map<keyof T, AnyFunction>;
14
+ export type Operators<T> = Map<keyof T, AnyFunction[]>;
15
+ export type HooksWithOptions<T> = Map<keyof T, {
16
+ hook: AnyFunction;
17
+ options?: {
18
+ context?: unknown;
19
+ };
20
+ }[]>;
21
+ export type Context<T extends Actions<T> = object> = {
22
+ state: () => [GetState, SetState];
23
+ action: (name: keyof T, ...args: any[]) => any;
24
+ };
25
+ /**
26
+ * This actually define what kind of action will be implemented in namespaces.
27
+ * For example evm namespace will have .connect(chain: string) and .switchNetwork
28
+ * But solana namespace only have: `.connect()`.
29
+ * This actions will be passed to this generic.
30
+ */
31
+ export type Actions<T> = Record<keyof T, AnyFunction>;
32
+ export {};
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;AACzD,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;AACvD,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,GAAG,CACnC,MAAM,CAAC,EACP;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH,EAAE,CACJ,CAAC;AACF,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IACnD,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { ExtendableInternalActions, CommonNamespaces, State, Context, ProviderBuilderOptions, } from './types.js';
2
+ export { Provider } from './provider.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,136 @@
1
+ import type { CommonNamespaces, Context, ExtendableInternalActions, GetState, RegisteredNamespaces, SetState } from './types.js';
2
+ import type { FindProxiedNamespace } from '../../builders/mod.js';
3
+ import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
4
+ import type { ProviderConfig, Store } from '../store/mod.js';
5
+ export declare class Provider {
6
+ #private;
7
+ readonly id: string;
8
+ readonly version = "1.0";
9
+ constructor(id: string, namespaces: RegisteredNamespaces<keyof CommonNamespaces, CommonNamespaces>, configs: ProviderConfig, options?: {
10
+ /**
11
+ * There are some cases we need to have a behavior like initializing a provider which will be run when we are creating an instance.
12
+ * These internal steps and behaviors will be useful for library user to extend the behavior by running a specific code.
13
+ */
14
+ extendInternalActions?: ExtendableInternalActions;
15
+ store?: Store;
16
+ });
17
+ /**
18
+ * This is an special callback that will be called **only once**.
19
+ * We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
20
+ *
21
+ * ```ts
22
+ * const myInit = () => { whatever; } *
23
+ * const provider = new Provider(..., {extendInternalActions: {init: myInit} });
24
+ *
25
+ * // Will run `myInit`
26
+ * provider.init()
27
+ *
28
+ * // Will not run `myInit` anymore.
29
+ * provider.init()
30
+ * provider.init()
31
+ * ```
32
+ */
33
+ init(): void;
34
+ /**
35
+ * Getting state of a provider
36
+ *
37
+ * **Note:**
38
+ * 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
39
+ * To be compatible with legacy, `getState` has a logic to guess the final state to produce same state as legacy.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const provider = new Provider(...);
44
+ * const [getState, setState] = provider.state();
45
+ *
46
+ * getState('installed');
47
+ * // or
48
+ * getState().installed;
49
+ * ```
50
+ *
51
+ */
52
+ state(): [GetState, SetState];
53
+ /**
54
+ * For keeping state, we need a store. all the states will be write to/read from store.
55
+ *
56
+ * **Note: When you are setting an store for provider, it will be set for its namespaces automatically as well**
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const myStore = createStore();
61
+ * const provider = new Provider(...);
62
+ * provider.store(myStore); // or it can be passed to Provider constructor;
63
+ * ```
64
+ */
65
+ store(store: Store): this;
66
+ /**
67
+ * Getting information about a provider which has been set on constructing Provider.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const walletInfo = {name: "Garbage wallet", ...}
72
+ * const provider = new Provider(..., {info: walletInfo});
73
+ *
74
+ * provider.info();
75
+ * ```
76
+ */
77
+ info(): ProviderConfig['info'] | undefined;
78
+ /**
79
+ * A list of registered _proxied_ namespaces.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const provider = new Provider(...);
84
+ * const allNamespaces = provider.getAll();
85
+ * ```
86
+ */
87
+ getAll(): RegisteredNamespaces<keyof CommonNamespaces, CommonNamespaces>;
88
+ /**
89
+ * Get a registered namespace in provider by its **namespace key**.
90
+ *
91
+ * 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.
92
+ *
93
+ * @param {string} id - evm, solana, cosmos, ... (CommonActions)
94
+ */
95
+ get<K extends keyof CommonNamespaces>(id: K): FindProxiedNamespace<K, CommonNamespaces> | undefined;
96
+ /**
97
+ *
98
+ * Get a registered namespace by its **namespaceId**.
99
+ *
100
+ * 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.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const provider = new Provider(...);
105
+ * provider.findByNamespace("whatever-id-i-set-for-namespace")
106
+ * ```
107
+ */
108
+ findByNamespace<K extends keyof CommonNamespaces>(namespaceLookingFor: K | string): FindProxiedNamespace<K, CommonNamespaces> | undefined;
109
+ /**
110
+ * Running a hook function _after_ a specific action for **all registered namespaces**.
111
+ *
112
+ * **Note:** the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * const provider = new Provider(...);
117
+ *
118
+ * provider.after("connect", (context) => {});
119
+ * ```
120
+ */
121
+ before(actionName: string, hookFn: FunctionWithContext<AnyFunction, Context>): this;
122
+ /**
123
+ * Running a hook function _before_ a specific action for **all registered namespaces**.
124
+ *
125
+ * **Note:** the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const provider = new Provider(...);
130
+ *
131
+ * provider.after("connect", (context) => {});
132
+ * ```
133
+ */
134
+ after(actionName: string, hookFn: FunctionWithContext<AnyFunction, Context>): this;
135
+ }
136
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,OAAO,EACP,yBAAyB,EACzB,QAAQ,EACR,oBAAoB,EACpB,QAAQ,EAET,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7D,qBAAa,QAAQ;;IACnB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,OAAO,SAAW;gBAShC,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,oBAAoB,CAAC,MAAM,gBAAgB,EAAE,gBAAgB,CAAC,EAC1E,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE;QACR;;;WAGG;QACH,qBAAqB,CAAC,EAAE,yBAAyB,CAAC;QAClD,KAAK,CAAC,EAAE,KAAK,CAAC;KACf;IAcH;;;;;;;;;;;;;;;OAeG;IACI,IAAI,IAAI,IAAI;IAanB;;;;;;;;;;;;;;;;;OAiBG;IACI,KAAK,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC;IA+CpC;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAWhC;;;;;;;;;;OAUG;IACI,IAAI,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;IAWjD;;;;;;;;OAQG;IACI,MAAM,IAAI,oBAAoB,CACnC,MAAM,gBAAgB,EACtB,gBAAgB,CACjB;IAID;;;;;;OAMG;IACI,GAAG,CAAC,CAAC,SAAS,MAAM,gBAAgB,EACzC,EAAE,EAAE,CAAC,GACJ,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG,SAAS;IAMxD;;;;;;;;;;;OAWG;IACI,eAAe,CAAC,CAAC,SAAS,MAAM,gBAAgB,EACrD,mBAAmB,EAAE,CAAC,GAAG,MAAM,GAC9B,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG,SAAS;IAaxD;;;;;;;;;;;OAWG;IACI,MAAM,CACX,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,GAChD,IAAI;IAKP;;;;;;;;;;;OAWG;IACI,KAAK,CACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,GAChD,IAAI;CA+CR"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=provider.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.test.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/provider.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import type { LegacyState } from '../../legacy/mod.js';
2
+ import type { NamespaceInterface, Store } from '../../mod.js';
3
+ import type { CosmosActions } from '../../namespaces/cosmos/mod.js';
4
+ import type { EvmActions } from '../../namespaces/evm/mod.js';
5
+ import type { SolanaActions } from '../../namespaces/solana/mod.js';
6
+ import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
7
+ export type Context = {
8
+ state: () => [GetState, SetState];
9
+ };
10
+ export type State = Omit<LegacyState, 'reachable' | 'accounts' | 'network'>;
11
+ export type SetState = <K extends keyof Pick<State, 'installed'>>(name: K, value: State[K]) => void;
12
+ export type GetState = {
13
+ (): State;
14
+ <K extends keyof State>(name: K): State[K];
15
+ };
16
+ export interface CommonNamespaces {
17
+ evm: EvmActions;
18
+ solana: SolanaActions;
19
+ cosmos: CosmosActions;
20
+ }
21
+ export interface ExtendableInternalActions {
22
+ init?: FunctionWithContext<AnyFunction, Context>;
23
+ }
24
+ export type RegisteredNamespaces<K extends keyof T, T> = Map<K, NamespaceInterface<K, T>>;
25
+ export type ProviderBuilderOptions = {
26
+ store?: Store;
27
+ };
28
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;AAC5E,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,EAC9D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KACZ,IAAI,CAAC;AACV,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,KAAK,CAAC;IACV,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,IAAI,GAAG,CAC1D,CAAC,EACD,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ /************ Hub ************/
2
+ import type { State } from './mod.js';
3
+ import type { StateCreator } from 'zustand';
4
+ type HubConfig = object;
5
+ export interface HubStore {
6
+ config: HubConfig;
7
+ }
8
+ type HubStateCreator = StateCreator<State, [], [], HubStore>;
9
+ declare const hubStore: HubStateCreator;
10
+ export { hubStore };
11
+ //# sourceMappingURL=hub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../../src/hub/store/hub.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,KAAK,SAAS,GAAG,MAAM,CAAC;AAExB,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,KAAK,eAAe,GAAG,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;AAE7D,QAAA,MAAM,QAAQ,EAAE,eAEd,CAAC;AAEH,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { guessProviderStateSelector, namespaceStateSelector, } from './selectors.js';
2
+ export type { Store, State } from './store.js';
3
+ export type { ProviderInfo, ProviderConfig } from './providers.js';
4
+ export type { NamespaceConfig, NamespaceData } from './namespaces.js';
5
+ export { createStore } from './store.js';
6
+ //# sourceMappingURL=mod.d.ts.map