@rango-dev/wallets-core 0.49.1-next.0 → 0.49.1-next.2

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 (68) hide show
  1. package/dist/mod.d.ts +1 -0
  2. package/dist/mod.d.ts.map +1 -1
  3. package/dist/namespaces/common/hooks/changeAccountSubscriber.d.ts +65 -0
  4. package/dist/namespaces/common/hooks/changeAccountSubscriber.d.ts.map +1 -0
  5. package/dist/namespaces/common/hooks/changeAccountSubscriber.test.d.ts +2 -0
  6. package/dist/namespaces/common/hooks/changeAccountSubscriber.test.d.ts.map +1 -0
  7. package/dist/namespaces/evm/actions.d.ts +2 -4
  8. package/dist/namespaces/evm/actions.d.ts.map +1 -1
  9. package/dist/namespaces/evm/builders.d.ts +3 -1
  10. package/dist/namespaces/evm/builders.d.ts.map +1 -1
  11. package/dist/namespaces/evm/hooks.d.ts +5 -0
  12. package/dist/namespaces/evm/hooks.d.ts.map +1 -0
  13. package/dist/namespaces/evm/mod.d.ts +1 -0
  14. package/dist/namespaces/evm/mod.d.ts.map +1 -1
  15. package/dist/namespaces/evm/mod.js +1 -1
  16. package/dist/namespaces/evm/mod.js.map +4 -4
  17. package/dist/namespaces/evm/utils.d.ts +1 -0
  18. package/dist/namespaces/evm/utils.d.ts.map +1 -1
  19. package/dist/namespaces/solana/actions.d.ts +1 -3
  20. package/dist/namespaces/solana/actions.d.ts.map +1 -1
  21. package/dist/namespaces/solana/builders.d.ts +3 -1
  22. package/dist/namespaces/solana/builders.d.ts.map +1 -1
  23. package/dist/namespaces/solana/hooks.d.ts +4 -0
  24. package/dist/namespaces/solana/hooks.d.ts.map +1 -0
  25. package/dist/namespaces/solana/mod.d.ts +1 -0
  26. package/dist/namespaces/solana/mod.d.ts.map +1 -1
  27. package/dist/namespaces/solana/mod.js +1 -1
  28. package/dist/namespaces/solana/mod.js.map +4 -4
  29. package/dist/namespaces/solana/utils.d.ts +1 -0
  30. package/dist/namespaces/solana/utils.d.ts.map +1 -1
  31. package/dist/namespaces/sui/actions.d.ts +1 -6
  32. package/dist/namespaces/sui/actions.d.ts.map +1 -1
  33. package/dist/namespaces/sui/builders.d.ts +6 -1
  34. package/dist/namespaces/sui/builders.d.ts.map +1 -1
  35. package/dist/namespaces/sui/hooks.d.ts +4 -0
  36. package/dist/namespaces/sui/hooks.d.ts.map +1 -0
  37. package/dist/namespaces/sui/mod.d.ts +1 -0
  38. package/dist/namespaces/sui/mod.d.ts.map +1 -1
  39. package/dist/namespaces/sui/mod.js +1 -1
  40. package/dist/namespaces/sui/mod.js.map +4 -4
  41. package/dist/namespaces/sui/types.d.ts +5 -1
  42. package/dist/namespaces/sui/types.d.ts.map +1 -1
  43. package/dist/namespaces/sui/utils.d.ts +3 -0
  44. package/dist/namespaces/sui/utils.d.ts.map +1 -1
  45. package/dist/types/mod.d.ts +2 -0
  46. package/dist/types/mod.d.ts.map +1 -0
  47. package/dist/wallets-core.build.json +1 -1
  48. package/package.json +1 -1
  49. package/src/mod.ts +1 -0
  50. package/src/namespaces/common/hooks/changeAccountSubscriber.test.ts +162 -0
  51. package/src/namespaces/common/hooks/changeAccountSubscriber.ts +188 -0
  52. package/src/namespaces/evm/actions.ts +8 -127
  53. package/src/namespaces/evm/builders.ts +39 -1
  54. package/src/namespaces/evm/hooks.ts +43 -0
  55. package/src/namespaces/evm/mod.ts +1 -0
  56. package/src/namespaces/evm/utils.ts +31 -1
  57. package/src/namespaces/solana/actions.ts +2 -56
  58. package/src/namespaces/solana/builders.ts +25 -1
  59. package/src/namespaces/solana/hooks.ts +10 -0
  60. package/src/namespaces/solana/mod.ts +1 -0
  61. package/src/namespaces/solana/utils.ts +18 -0
  62. package/src/namespaces/sui/actions.ts +1 -61
  63. package/src/namespaces/sui/builders.ts +33 -2
  64. package/src/namespaces/sui/hooks.ts +10 -0
  65. package/src/namespaces/sui/mod.ts +1 -0
  66. package/src/namespaces/sui/types.ts +13 -2
  67. package/src/namespaces/sui/utils.ts +14 -0
  68. package/src/types/mod.ts +1 -0
package/dist/mod.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { Store, State, ProviderMetadata, CommonNamespaces, CommonNamespaceKeys, Subscriber, SubscriberCleanUp, Context, GenerateDeepLink, DeepLinkContext, } from './hub/mod.js';
2
+ export type { AnyFunction } from './types/mod.js';
2
3
  export { Hub, Provider, Namespace, createStore, guessProviderStateSelector, namespaceStateSelector, } from './hub/mod.js';
3
4
  export type { ProxiedNamespace, FindProxiedNamespace } from './builders/mod.js';
4
5
  export { NamespaceBuilder, ProviderBuilder, ActionBuilder, } from './builders/mod.js';
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,gBAAgB,EAChB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,GAAG,EACH,QAAQ,EACR,SAAS,EACT,WAAW,EACX,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAgB3B,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,gBAAgB,EAChB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACL,GAAG,EACH,QAAQ,EACR,SAAS,EACT,WAAW,EACX,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAgB3B,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Actions, SubscriberCleanUp } from '../../../hub/namespaces/types.js';
2
+ import type { Subscriber } from '../../../mod.js';
3
+ import type { AutoImplementedActionsByRecommended } from '../types.js';
4
+ export declare class ChangeAccountSubscriberBuilder<EventType, ProviderAPI> {
5
+ #private;
6
+ /**
7
+ * Sets the function that provides the provider API instance.
8
+ *
9
+ * @param operator - Function that returns the provider API instance
10
+ * @returns The builder instance for method chaining
11
+ * @example
12
+ * ```typescript
13
+ * builder.getInstance(() => window.ethereum)
14
+ * ```
15
+ */
16
+ getInstance(operator: () => ProviderAPI): this;
17
+ /**
18
+ * Sets the formatter function that converts provider events to account strings.
19
+ *
20
+ * @param operator - Function that takes a provider instance and event, returns array of account strings
21
+ * @returns The builder instance for method chaining
22
+ * @example
23
+ * ```typescript
24
+ * builder.format(async (instance, event) => event.accounts || [])
25
+ * ```
26
+ */
27
+ format(operator: (instance: ProviderAPI, event: EventType) => Promise<string[]>): this;
28
+ /**
29
+ * Sets the event payload validation function (optional).
30
+ *
31
+ * @param operator - Function that validates if an event payload is valid
32
+ * @returns The builder instance for method chaining
33
+ * @example
34
+ * ```typescript
35
+ * builder.validateEventPayload(event => !!event)
36
+ * ```
37
+ */
38
+ validateEventPayload(operator: (event: EventType) => boolean): this;
39
+ /**
40
+ * Sets the event listener attachment function.
41
+ *
42
+ * @param operator - Function that attaches an event listener and optionally returns a cleanup function
43
+ * @returns The builder instance for method chaining
44
+ * @example
45
+ * ```typescript
46
+ * builder.addEventListener((instance, callback) => {
47
+ * return instance.on('accountsChanged', callback);
48
+ * })
49
+ * ```
50
+ */
51
+ addEventListener(operator: (instance: ProviderAPI, callback: (event: EventType) => void) => (() => void) | void): this;
52
+ /**
53
+ * Sets the event listener removal function.
54
+ *
55
+ * @param operator - Function that removes an event listener from the provider
56
+ * @returns The builder instance for method chaining
57
+ * @example
58
+ * ```typescript
59
+ * builder.removeEventListener((instance, callback) => instance.off('accountsChanged', callback))
60
+ * ```
61
+ */
62
+ removeEventListener(operator: (instance: ProviderAPI, callback: (event: EventType) => void) => void): this;
63
+ build<ActionsType extends Actions<ActionsType> & Actions<AutoImplementedActionsByRecommended>>(): [Subscriber<ActionsType>, SubscriberCleanUp<ActionsType>];
64
+ }
65
+ //# sourceMappingURL=changeAccountSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changeAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../../src/namespaces/common/hooks/changeAccountSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EAClB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAEvE,qBAAa,8BAA8B,CAAC,SAAS,EAAE,WAAW;;IAiBhE;;;;;;;;;OASG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,WAAW;IAK9C;;;;;;;;;OASG;IACI,MAAM,CACX,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;IAM1E;;;;;;;;;OASG;IACI,oBAAoB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO;IAKnE;;;;;;;;;;;OAWG;IACI,gBAAgB,CACrB,QAAQ,EAAE,CACR,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,KACjC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;IAM1B;;;;;;;;;OASG;IACI,mBAAmB,CACxB,QAAQ,EAAE,CACR,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,KACjC,IAAI;IAKJ,KAAK,CACV,WAAW,SAAS,OAAO,CAAC,WAAW,CAAC,GACtC,OAAO,CAAC,mCAAmC,CAAC,KAC3C,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;CAwE/D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=changeAccountSubscriber.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changeAccountSubscriber.test.d.ts","sourceRoot":"","sources":["../../../../src/namespaces/common/hooks/changeAccountSubscriber.test.ts"],"names":[],"mappings":""}
@@ -1,11 +1,9 @@
1
1
  import type { ConnectOptions, EvmActions, ProviderAPI } from './types.js';
2
- import type { Context, Subscriber } from '../../hub/namespaces/mod.js';
3
- import type { CanEagerConnect, SubscriberCleanUp } from '../../hub/namespaces/types.js';
2
+ import type { Context } from '../../hub/namespaces/mod.js';
3
+ import type { CanEagerConnect } from '../../hub/namespaces/types.js';
4
4
  import type { FunctionWithContext } from '../../types/actions.js';
5
5
  export declare const recommended: (readonly ["disconnect", typeof import("../common/actions.js").disconnect])[];
6
6
  export declare function connect(instance: () => ProviderAPI, options?: ConnectOptions): FunctionWithContext<EvmActions['connect'], Context>;
7
- export declare function changeAccountSubscriber(instance: () => ProviderAPI): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>];
8
- export declare function changeChainSubscriber(instance: () => ProviderAPI): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>];
9
7
  export declare function canEagerConnect(instance: () => ProviderAPI | undefined): CanEagerConnect<EvmActions>;
10
8
  export declare function canSwitchNetwork(): FunctionWithContext<EvmActions['canSwitchNetwork'], Context>;
11
9
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAalE,eAAO,MAAM,WAAW,+EAAyB,CAAC;AAElD,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,WAAW,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAsDrD;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,WAAW,GAC1B,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAyDzD;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,WAAW,GAC1B,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC,CA4BzD;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,WAAW,GAAG,SAAS,GACtC,eAAe,CAAC,UAAU,CAAC,CAsB7B;AACD,wBAAgB,gBAAgB,IAAI,mBAAmB,CACrD,UAAU,CAAC,kBAAkB,CAAC,EAC9B,OAAO,CACR,CAKA"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAWlE,eAAO,MAAM,WAAW,+EAAyB,CAAC;AAClD,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,WAAW,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAoCrD;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,WAAW,GAAG,SAAS,GACtC,eAAe,CAAC,UAAU,CAAC,CAsB7B;AACD,wBAAgB,gBAAgB,IAAI,mBAAmB,CACrD,UAAU,CAAC,kBAAkB,CAAC,EAC9B,OAAO,CACR,CAKA"}
@@ -1,6 +1,8 @@
1
- import type { EvmActions } from './types.js';
1
+ import type { EvmActions, ProviderAPI } from './types.js';
2
2
  import { ActionBuilder } from '../../mod.js';
3
+ import { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';
3
4
  export declare const connect: () => ActionBuilder<EvmActions, "connect">;
4
5
  export declare const canEagerConnect: () => ActionBuilder<EvmActions, "canEagerConnect">;
5
6
  export declare const canSwitchNetwork: () => ActionBuilder<EvmActions, "canSwitchNetwork">;
7
+ export declare const changeAccountSubscriber: (getInstance: () => ProviderAPI) => ChangeAccountSubscriberBuilder<string[], import("./eip1193.js").EIP1193Provider>;
6
8
  //# sourceMappingURL=builders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAO7C,eAAO,MAAM,OAAO,4CAIc,CAAC;AAEnC,eAAO,MAAM,eAAe,oDACyC,CAAC;AACtE,eAAO,MAAM,gBAAgB,qDAC0C,CAAC"}
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI1D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAU5F,eAAO,MAAM,OAAO,4CAIc,CAAC;AAEnC,eAAO,MAAM,eAAe,oDACyC,CAAC;AACtE,eAAO,MAAM,gBAAgB,qDAC0C,CAAC;AAGxE,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,WAAW,qFA6BhE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { EvmActions, ProviderAPI } from './types.js';
2
+ import type { Subscriber, SubscriberCleanUp } from '../../mod.js';
3
+ export declare function changeAccountSubscriber(instance: () => ProviderAPI): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>];
4
+ export declare function changeChainSubscriber(instance: () => ProviderAPI): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>];
5
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIlE,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,WAAW,GAC1B,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAEzD;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,WAAW,GAC1B,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC,CA4BzD"}
@@ -1,4 +1,5 @@
1
1
  export * as actions from './actions.js';
2
+ export * as hooks from './hooks.js';
2
3
  export * as after from './after.js';
3
4
  export * as and from './and.js';
4
5
  export * as before from './before.js';
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,2 +1,2 @@
1
- var E=Object.defineProperty;var t=(o,e)=>E(o,"name",{value:e,configurable:!0});var d=(o,e)=>{for(var r in e)E(o,r,{get:e[r],enumerable:!0})};var O={};d(O,{canEagerConnect:()=>Q,canSwitchNetwork:()=>X,changeAccountSubscriber:()=>q,changeChainSubscriber:()=>J,connect:()=>z,recommended:()=>Y});import{AccountId as R}from"caip";function P(o){let[,e]=o.state();e("network",null),e("accounts",null),e("connected",!1),e("connecting",!1)}t(P,"disconnect");var N=[["disconnect",P]];var m="eip155",L="1";var _={};d(_,{filterAndGetEvmBlockchainNames:()=>y,getAccounts:()=>v,isUserRejectionError:()=>$,suggestNetwork:()=>I,switchNetwork:()=>T,switchOrAddNetwork:()=>x});import{evmBlockchains as B}from"rango-types";async function v(o){let[e,r]=await Promise.all([o.request({method:"eth_requestAccounts"}),o.request({method:"eth_chainId"})]);return{accounts:e,chainId:r}}t(v,"getAccounts");async function I(o,e){return await o.request({method:"wallet_addEthereumChain",params:[e]})}t(I,"suggestNetwork");async function T(o,e){return await o.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}t(T,"switchNetwork");function y(o){return B(o).map(e=>e.name)}t(y,"filterAndGetEvmBlockchainNames");async function x(o,e){try{let r=typeof e=="string"?e:e.chainId;await T(o,r)}catch(r){let n=r;if(typeof e!="string"&&(n.code===4902||!n.code)){await I(o,e);return}throw r}}t(x,"switchOrAddNetwork");var k=4001;function $(o){if(typeof o=="object"&&o!==null){let e=o.code,r=o.cause?.code;return e===k||r===k}return!1}t($,"isUserRejectionError");var Y=[...N],G=16;function z(o,e){return async(r,n)=>{let s=o();if(!s)throw new Error("Do your wallet injected correctly and is evm compatible?");n&&(e?.switchOrAddNetwork?await e.switchOrAddNetwork(s,n):await x(s,n));let c=await v(s),i=c.chainId;return typeof i=="number"&&(i=`0x${Number(i).toString(G)}`),{accounts:c.accounts.map(l=>R.format({address:l,chainId:{namespace:m,reference:i}})),network:i}}}t(z,"connect");function q(o){let e;return[(r,n)=>{let s=o();if(!s)throw new Error("Trying to subscribe to your EVM wallet, but seems its instance is not available.");let[,c]=r.state();if(e=t(async i=>{if(!i||i.length===0){r.action("disconnect");return}let A=await s.request({method:"eth_chainId"}),l=i.map(H=>R.format({address:H,chainId:{namespace:m,reference:A}}));c("accounts",l)},"eventCallback"),s.on("accountsChanged",e),n instanceof Error)throw n},(r,n)=>{let s=o();return e&&s&&s.removeListener?.("accountsChanged",e),n}]}t(q,"changeAccountSubscriber");function J(o){let e;return[r=>{let n=o();if(!n)throw new Error("Trying to subscribe to your EVM wallet, but seems its instance is not available.");let[,s]=r.state();e=t(async c=>{s("network",c)},"eventCallback"),n.on("chainChanged",e)},()=>{let r=o();e&&r&&r.removeListener("chainChanged",e)}]}t(J,"changeChainSubscriber");function Q(o){return async()=>{let e=o();if(!e)throw new Error("Trying to eagerly connect to your EVM wallet, but seems its instance is not available.");try{return!!(await e.request({method:"eth_accounts"})).length}catch{return!1}}}t(Q,"canEagerConnect");function X(){return(o,e)=>{let{network:r,supportedChains:n}=e;return y(n).includes(r)}}t(X,"canSwitchNetwork");var j={};d(j,{recommended:()=>Z});function u(o){let[,e]=o.state();e("connecting",!1)}t(u,"intoConnectionFinished");var g=[["connect",u]];var Z=[...g];var V={};d(V,{recommended:()=>ae});import{createStore as xt}from"zustand/vanilla";import{produce as ot}from"immer";import{produce as ct}from"immer";var a=class{static{t(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#o=new Map;#r=new Map;#n;constructor(e){this.name=e}and(e){return this.#e.has(this.name)||this.#e.set(this.name,[]),this.#e.get(this.name)?.push(e),this}or(e){return this.#t.has(this.name)||this.#t.set(this.name,[]),this.#t.get(this.name)?.push(e),this}before(e){return this.#r.has(this.name)||this.#r.set(this.name,[]),this.#r.get(this.name)?.push(e),this}after(e){return this.#o.has(this.name)||this.#o.set(this.name,[]),this.#o.get(this.name)?.push(e),this}action(e){return this.#n=e,this}build(){if(!this.#n)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#n,before:this.#r,after:this.#o,and:this.#e,or:this.#t}}};import*as qt from"caip";import{AccountId as ie}from"caip";function D(o){try{return ie.parse(o),!0}catch{return!1}}t(D,"isValidCaipAddress");function p(o,e){if(!e.accounts.every(D))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${e.accounts}`);let[,r]=o.state();return r("accounts",e.accounts),r("network",e.network),r("connected",!0),e}t(p,"connectAndUpdateStateForMultiNetworks");function h(o){let[,e]=o.state();e("connecting",!0)}t(h,"intoConnecting");var w=[["connect",h]];var ae=[["connect",p]];var M={};d(M,{recommended:()=>ce});var ce=[...w];var W={};d(W,{canEagerConnect:()=>pe,canSwitchNetwork:()=>me,connect:()=>de});var de=t(()=>new a("connect").and(p).before(h).after(u),"connect"),pe=t(()=>new a("canEagerConnect"),"canEagerConnect"),me=t(()=>new a("canSwitchNetwork"),"canSwitchNetwork");export{L as CAIP_ETHEREUM_CHAIN_ID,m as CAIP_NAMESPACE,O as actions,j as after,V as and,M as before,W as builders,_ as utils};
1
+ var _=Object.defineProperty;var t=(r,e)=>_(r,"name",{value:e,configurable:!0});var c=(r,e)=>{for(var o in e)_(r,o,{get:e[o],enumerable:!0})};var M={};c(M,{canEagerConnect:()=>ee,canSwitchNetwork:()=>te,connect:()=>Z,recommended:()=>X});function R(r){let[,e]=r.state();e("network",null),e("accounts",null),e("connected",!1),e("connecting",!1)}t(R,"disconnect");var O=[["disconnect",R]];var D={};c(D,{filterAndGetEvmBlockchainNames:()=>A,formatAccountsToCAIP:()=>P,getAccounts:()=>b,isUserRejectionError:()=>Q,suggestNetwork:()=>F,switchNetwork:()=>K,switchOrAddNetwork:()=>C});import{AccountId as q}from"caip";import{evmBlockchains as z}from"rango-types";var p="eip155",G="1";var J=16;async function b(r){let[e,o]=await Promise.all([r.request({method:"eth_requestAccounts"}),r.request({method:"eth_chainId"})]),n=o;return typeof n=="number"&&(n=`0x${Number(o).toString(J)}`),{accounts:e,chainId:n}}t(b,"getAccounts");async function F(r,e){return await r.request({method:"wallet_addEthereumChain",params:[e]})}t(F,"suggestNetwork");async function K(r,e){return await r.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}t(K,"switchNetwork");function A(r){return z(r).map(e=>e.name)}t(A,"filterAndGetEvmBlockchainNames");async function C(r,e){try{let o=typeof e=="string"?e:e.chainId;await K(r,o)}catch(o){let n=o;if(typeof e!="string"&&(n.code===4902||!n.code)){await F(r,e);return}throw o}}t(C,"switchOrAddNetwork");var j=4001;function Q(r){if(typeof r=="object"&&r!==null){let e=r.code,o=r.cause?.code;return e===j||o===j}return!1}t(Q,"isUserRejectionError");function P(r,e){return r.map(o=>q.format({address:o,chainId:{namespace:p,reference:e}}))}t(P,"formatAccountsToCAIP");var X=[...O];function Z(r,e){return async(o,n)=>{let s=r();if(!s)throw new Error("Do your wallet injected correctly and is evm compatible?");n&&(e?.switchOrAddNetwork?await e.switchOrAddNetwork(s,n):await C(s,n));let a=await b(s);return{accounts:P(a.accounts,a.chainId),network:a.chainId}}}t(Z,"connect");function ee(r){return async()=>{let e=r();if(!e)throw new Error("Trying to eagerly connect to your EVM wallet, but seems its instance is not available.");try{return!!(await e.request({method:"eth_accounts"})).length}catch{return!1}}}t(ee,"canEagerConnect");function te(){return(r,e)=>{let{network:o,supportedChains:n}=e;return A(n).includes(o)}}t(te,"canSwitchNetwork");var V={};c(V,{changeAccountSubscriber:()=>re,changeChainSubscriber:()=>oe});function re(r){return h.changeAccountSubscriber(r).build()}t(re,"changeAccountSubscriber");function oe(r){let e;return[o=>{let n=r();if(!n)throw new Error("Trying to subscribe to your EVM wallet, but seems its instance is not available.");let[,s]=o.state();e=t(async a=>{s("network",a)},"eventCallback"),n.on("chainChanged",e)},()=>{let o=r();e&&o&&o.removeListener("chainChanged",e)}]}t(oe,"changeChainSubscriber");var L={};c(L,{recommended:()=>ne});function v(r){let[,e]=r.state();e("connecting",!1)}t(v,"intoConnectionFinished");var E=[["connect",v]];var ne=[...E];var B={};c(B,{recommended:()=>me});import{createStore as Nt}from"zustand/vanilla";import{produce as ut}from"immer";import{produce as yt}from"immer";var i=class{static{t(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#o=new Map;#r=new Map;#n;constructor(e){this.name=e}and(e){return this.#e.has(this.name)||this.#e.set(this.name,[]),this.#e.get(this.name)?.push(e),this}or(e){return this.#t.has(this.name)||this.#t.set(this.name,[]),this.#t.get(this.name)?.push(e),this}before(e){return this.#r.has(this.name)||this.#r.set(this.name,[]),this.#r.get(this.name)?.push(e),this}after(e){return this.#o.has(this.name)||this.#o.set(this.name,[]),this.#o.get(this.name)?.push(e),this}action(e){return this.#n=e,this}build(){if(!this.#n)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#n,before:this.#r,after:this.#o,and:this.#e,or:this.#t}}};import*as nr from"caip";import{AccountId as ue}from"caip";function H(r){try{return ue.parse(r),!0}catch{return!1}}t(H,"isValidCaipAddress");function u(r,e){if(!e.accounts.every(H))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${e.accounts}`);let[,o]=r.state();return o("accounts",e.accounts),o("network",e.network),o("connected",!0),e}t(u,"connectAndUpdateStateForMultiNetworks");function y(r){let[,e]=r.state();e("connecting",!0)}t(y,"intoConnecting");var k=[["connect",y]];var me=[["connect",u]];var $={};c($,{recommended:()=>fe});var fe=[...k];var h={};c(h,{canEagerConnect:()=>le,canSwitchNetwork:()=>ye,changeAccountSubscriber:()=>ge,connect:()=>ve});import{AccountId as he}from"caip";var g=class{static{t(this,"ChangeAccountSubscriberBuilder")}#e=null;#t=null;#o=null;#r=null;#n=null;getInstance(e){return this.#e=e,this}format(e){return this.#t=e,this}validateEventPayload(e){return this.#o=e,this}addEventListener(e){return this.#r=e,this}removeEventListener(e){return this.#n=e,this}build(){if(this.#e===null)throw new Error(this.#s("getInstance"));if(this.#t===null)throw new Error(this.#s("format"));if(this.#r===null)throw new Error(this.#s("addEventListener"));if(this.#n===null)throw new Error(this.#s("removeEventListener"));let e=this.#e,o=this.#t,n=this.#r,s=this.#n,a=this.#o,m,f;return[async x=>{let[,S]=x.state(),d=e();if(!d)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");m=t(async T=>{if(a&&!a(T)){x.action("disconnect");return}S("accounts",await o(d,T))},"subscriber"),f=n(d,m)},(x,S)=>{f&&typeof f=="function"&&f();let d=e();return s(d,m),S}]}#s(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};var ve=t(()=>new i("connect").and(u).before(y).after(v),"connect"),le=t(()=>new i("canEagerConnect"),"canEagerConnect"),ye=t(()=>new i("canSwitchNetwork"),"canSwitchNetwork"),ge=t(r=>new g().getInstance(r).validateEventPayload(e=>e&&e.length!==0).format(async(e,o)=>{let n=await e.request({method:"eth_chainId"});return o.map(s=>he.format({address:s,chainId:{namespace:p,reference:n}}))}).addEventListener((e,o)=>{e.on("accountsChanged",o)}).removeEventListener((e,o)=>{e.removeListener?.("accountsChanged",o)}),"changeAccountSubscriber");export{G as CAIP_ETHEREUM_CHAIN_ID,p as CAIP_NAMESPACE,M as actions,L as after,B as and,$ as before,h as builders,V as hooks,D as utils};
2
2
  //# sourceMappingURL=mod.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/namespaces/evm/actions.ts", "../../../src/namespaces/common/actions.ts", "../../../src/namespaces/evm/constants.ts", "../../../src/namespaces/evm/utils.ts", "../../../src/namespaces/evm/after.ts", "../../../src/namespaces/common/after.ts", "../../../src/namespaces/evm/and.ts", "../../../src/hub/store/store.ts", "../../../src/hub/store/namespaces.ts", "../../../src/hub/store/providers.ts", "../../../src/builders/action.ts", "../../../src/utils/mod.ts", "../../../src/namespaces/common/helpers.ts", "../../../src/namespaces/common/and.ts", "../../../src/namespaces/common/before.ts", "../../../src/namespaces/evm/before.ts", "../../../src/namespaces/evm/builders.ts"],
4
- "sourcesContent": ["import type { EIP1193EventMap } from './eip1193.js';\nimport type { ConnectOptions, EvmActions, ProviderAPI } from './types.js';\nimport type { Context, Subscriber } from '../../hub/namespaces/mod.js';\nimport type {\n CanEagerConnect,\n SubscriberCleanUp,\n} from '../../hub/namespaces/types.js';\nimport type { CaipAccount } from '../../types/accounts.js';\nimport type { FunctionWithContext } from '../../types/actions.js';\n\nimport { AccountId } from 'caip';\n\nimport { recommended as commonRecommended } from '../common/actions.js';\n\nimport { CAIP_NAMESPACE } from './constants.js';\nimport {\n filterAndGetEvmBlockchainNames,\n getAccounts,\n switchOrAddNetwork,\n} from './utils.js';\n\nexport const recommended = [...commonRecommended];\nconst CHAIN_ID_RADIX = 16;\nexport function connect(\n instance: () => ProviderAPI,\n options?: ConnectOptions\n): FunctionWithContext<EvmActions['connect'], Context> {\n return async (_context, chain) => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Do your wallet injected correctly and is evm compatible?'\n );\n }\n\n if (chain) {\n /*\n * The `switchOrAddNetwork` function can be optionally provided through `options`\n * to handle network switching or addition in a way that is compatible with the specific wallet provider.\n * This approach is necessary because not all providers follow the same conventions\u2014\n * for example, Rabby uses a different error code for \"chain not found\".\n */\n if (options?.switchOrAddNetwork) {\n await options.switchOrAddNetwork(evmInstance, chain);\n } else {\n await switchOrAddNetwork(evmInstance, chain);\n }\n }\n\n const result = await getAccounts(evmInstance);\n\n /*\n * Trust Wallet Compatibility Fix:\n * Trust Wallet's in-app browser has been observed to return the `chainId` as a\n * number (e.g., 1) rather than the standard hexadecimal string (e.g., \"0x1\").\n * This code block standardizes the `chainId` to the required hex format to\n * prevent downstream errors.\n */\n let chainId = result.chainId;\n if (typeof chainId === 'number') {\n chainId = `0x${Number(chainId).toString(CHAIN_ID_RADIX)}`;\n }\n\n const formatAccounts = result.accounts.map(\n (account) =>\n AccountId.format({\n address: account,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: chainId,\n },\n }) as CaipAccount\n );\n\n return {\n accounts: formatAccounts,\n network: chainId,\n };\n };\n}\n\nexport function changeAccountSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {\n let eventCallback: EIP1193EventMap['accountsChanged'];\n\n // subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.\n return [\n (context, err) => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Trying to subscribe to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n const [, setState] = context.state();\n\n eventCallback = async (accounts) => {\n /*\n * In Phantom, when user is switching to an account which is not connected to dApp yet, it returns a null.\n * So null means we don't have access to account and we need to disconnect and let the user connect the account.\n *\n * This assumption may not work for other wallets, if that the case, we need to consider a new approach.\n */\n if (!accounts || accounts.length === 0) {\n context.action('disconnect');\n return;\n }\n\n const chainId = await evmInstance.request({ method: 'eth_chainId' });\n const formatAccounts = accounts.map((account) =>\n AccountId.format({\n address: account,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: chainId,\n },\n })\n );\n\n setState('accounts', formatAccounts);\n };\n evmInstance.on('accountsChanged', eventCallback);\n\n if (err instanceof Error) {\n throw err;\n }\n },\n (_, err) => {\n const evmInstance = instance();\n\n if (eventCallback && evmInstance) {\n evmInstance.removeListener?.('accountsChanged', eventCallback);\n }\n\n return err;\n },\n ];\n}\n\nexport function changeChainSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {\n let eventCallback: EIP1193EventMap['chainChanged'];\n\n return [\n (context) => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Trying to subscribe to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n const [, setState] = context.state();\n\n eventCallback = async (chainId: string) => {\n setState('network', chainId);\n };\n evmInstance.on('chainChanged', eventCallback);\n },\n () => {\n const evmInstance = instance();\n\n if (eventCallback && evmInstance) {\n evmInstance.removeListener('chainChanged', eventCallback);\n }\n },\n ];\n}\n\nexport function canEagerConnect(\n instance: () => ProviderAPI | undefined\n): CanEagerConnect<EvmActions> {\n return async () => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Trying to eagerly connect to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n try {\n const accounts: string[] = await evmInstance.request({\n method: 'eth_accounts',\n });\n if (accounts.length) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n };\n}\nexport function canSwitchNetwork(): FunctionWithContext<\n EvmActions['canSwitchNetwork'],\n Context\n> {\n return (context, params) => {\n const { network, supportedChains } = params;\n return filterAndGetEvmBlockchainNames(supportedChains).includes(network);\n };\n}\n", "import type { Context } from '../../hub/namespaces/mod.js';\n\nexport function disconnect(context: Context): void {\n const [, setState] = context.state();\n setState('network', null);\n setState('accounts', null);\n setState('connected', false);\n setState('connecting', false);\n}\n\nexport const recommended = [['disconnect', disconnect] as const];\n", "export const CAIP_NAMESPACE = 'eip155';\nexport const CAIP_ETHEREUM_CHAIN_ID = '1';\n", "import type { Chain, ChainId, ProviderAPI } from './types.js';\n\nimport { type BlockchainMeta, evmBlockchains } from 'rango-types';\n\nexport async function getAccounts(provider: ProviderAPI) {\n const [accounts, chainId] = await Promise.all([\n provider.request({ method: 'eth_requestAccounts' }),\n provider.request({ method: 'eth_chainId' }),\n ]);\n\n return {\n accounts,\n chainId,\n };\n}\n\nexport async function suggestNetwork(instance: ProviderAPI, chain: Chain) {\n return await instance.request({\n method: 'wallet_addEthereumChain',\n params: [chain],\n });\n}\n\nexport async function switchNetwork(instance: ProviderAPI, chainId: ChainId) {\n return await instance.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: chainId }],\n });\n}\nexport function filterAndGetEvmBlockchainNames(meta: BlockchainMeta[]) {\n return evmBlockchains(meta).map((blockchain) => blockchain.name);\n}\nexport async function switchOrAddNetwork(\n instance: ProviderAPI,\n chain: ChainId | Chain\n) {\n try {\n const chainId = typeof chain === 'string' ? chain : chain.chainId;\n await switchNetwork(instance, chainId);\n } catch (switchError) {\n const error = switchError as { code: number };\n\n /*\n * Error code 4902 is used by MetaMask to indicate that the requested chain has not been added to the wallet.\n * This code is not part of the official EIP-1193 spec (https://eips.ethereum.org/EIPS/eip-1193#supported-rpc-methods),\n * so other providers may use a different code or behavior for the same condition.\n */\n const NOT_FOUND_CHAIN_ERROR_CODE = 4902;\n if (\n typeof chain !== 'string' &&\n (error.code === NOT_FOUND_CHAIN_ERROR_CODE || !error.code)\n ) {\n /*\n * Note: on WalletConnect `code` is undefined so we have to use !switchError.code as fallback.\n * This error code indicates that the chain has not been added to wallet.\n */\n await suggestNetwork(instance, chain);\n return;\n }\n throw switchError;\n }\n}\n\nconst EIP_1193_USER_REJECTION_ERROR_CODE = 4001;\nexport function isUserRejectionError(error: unknown): boolean {\n // EIP-1193 user rejection error can be in error.code or error.cause.code\n if (typeof error === 'object' && error !== null) {\n const code = (error as { code?: number }).code;\n const causeCode = (error as { cause?: { code?: number } }).cause?.code;\n return (\n code === EIP_1193_USER_REJECTION_ERROR_CODE ||\n causeCode === EIP_1193_USER_REJECTION_ERROR_CODE\n );\n }\n return false;\n}\n", "import { recommended as commonRecommended } from '../common/after.js';\n\nexport const recommended = [...commonRecommended];\n", "import type { Context } from '../../hub/namespaces/mod.js';\n\nexport function intoConnectionFinished(context: Context) {\n const [, setState] = context.state();\n setState('connecting', false);\n}\n\nexport const recommended = [['connect', intoConnectionFinished] as const];\n", "import { connectAndUpdateStateForMultiNetworks } from '../common/mod.js';\n\nexport const recommended = [\n ['connect', connectAndUpdateStateForMultiNetworks] as const,\n];\n", "import type { StoreApi } from 'zustand/vanilla';\n\nimport { createStore as createZustandStore } from 'zustand/vanilla';\n\nimport { extend, type Store } from './extend.js';\nimport { hubStore, type HubStore } from './hub.js';\nimport { namespacesStore, type NamespaceStore } from './namespaces.js';\nimport { providersStore, type ProviderStore } from './providers.js';\n\n/************ State ************/\n\nexport interface State {\n hub: HubStore;\n providers: ProviderStore;\n namespaces: NamespaceStore;\n}\n\nexport type RawStore = StoreApi<State>;\n\nexport const createStore = (): Store => {\n const store = createZustandStore<State>((...api) => {\n return {\n hub: hubStore(...api),\n providers: providersStore(...api),\n namespaces: namespacesStore(...api),\n };\n });\n\n return extend(store);\n};\n", "/************ Namespace ************/\n\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport {\n ConsumableEvents,\n type NamespaceConnectedEvent,\n type NamespaceDisconnectedEvent,\n type NamespaceSwitchedAccountEvent,\n type NamespaceSwitchedNetworkEvent,\n} from './events.js';\nimport { namespaceStateSelector, type State } from './mod.js';\n\n// Currently, namespace doesn't has any config.\nexport type NamespaceConfig = object;\n\nexport interface NamespaceData {\n accounts: null | string[];\n network: null | string;\n connected: boolean;\n connecting: boolean;\n}\n\ninterface NamespaceInfo {\n providerId: string;\n namespaceId: string;\n}\n\ninterface NamespaceItem {\n info: NamespaceInfo;\n data: NamespaceData;\n error: unknown;\n}\n\ntype NamespaceState = {\n events: InstanceType<typeof ConsumableEvents>;\n list: Record<string, NamespaceItem>;\n};\n\ninterface NamespaceActions {\n addNamespace: (id: string, config: NamespaceInfo) => void;\n updateStatus: <K extends keyof NamespaceData>(\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof NamespaceData>(\n namespace: NamespaceItem,\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n}\ninterface NamespaceSelectors {\n getNamespaceData(storeId: string): NamespaceData;\n}\n\nexport type NamespaceStore = NamespaceState &\n NamespaceActions &\n NamespaceSelectors;\ntype NamespaceStateCreator = StateCreator<State, [], [], NamespaceStore>;\n\nconst namespacesStore: NamespaceStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addNamespace: (id, info) => {\n const data: NamespaceData = {\n accounts: null,\n network: null,\n connected: false,\n connecting: false,\n };\n\n const item = {\n data,\n error: '',\n info,\n };\n\n set(\n produce((state: State) => {\n state.namespaces.list[id] = item;\n })\n );\n },\n updateStatus: (id, key, value) => {\n const ns = get().namespaces.list[id];\n if (!ns) {\n throw new Error(`No namespace with '${id}' found.`);\n }\n\n get().namespaces._produceEventsWhenUpdatingStatus(ns, id, key, value);\n\n // Updating state\n set(\n produce((state: State) => {\n state.namespaces.list[id].data[key] = value;\n })\n );\n },\n getNamespaceData(storeId) {\n return namespaceStateSelector(get(), storeId);\n },\n\n _produceEventsWhenUpdatingStatus: (namespace, id, key, value) => {\n if (key === 'accounts') {\n // check for both null and empty array\n const isAccountsEmpty =\n Object.is(value, null) || (Array.isArray(value) && value.length === 0);\n\n if (isAccountsEmpty) {\n const currentConnectedStatus = get().namespaces.list[id].data.connected;\n if (currentConnectedStatus) {\n const event: NamespaceDisconnectedEvent = {\n type: 'namespace_disconnected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n };\n\n get().namespaces.events.push(event);\n }\n // Skip emitting disconnect event, if the `connected` is false\n } else {\n const currentAccounts = get().namespaces.list[id].data.accounts;\n\n if (!currentAccounts) {\n const event: NamespaceConnectedEvent = {\n type: 'namespace_connected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n } else {\n const areSameAccounts =\n currentAccounts.sort().toString() ===\n (value as string[]).sort().toString();\n\n if (!areSameAccounts) {\n const event: NamespaceSwitchedAccountEvent = {\n type: 'namespace_account_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n previousAccounts: currentAccounts,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n }\n }\n }\n } else if (key === 'network') {\n const currentNetwork = get().namespaces.list[id].data.network;\n\n const event: NamespaceSwitchedNetworkEvent = {\n type: 'namespace_network_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n network: value as string,\n previousNetwork: currentNetwork,\n };\n\n get().namespaces.events.push(event);\n }\n },\n});\n\nexport { namespacesStore };\n", "import type { Namespace } from '../../namespaces/common/types.js';\nimport type {\n GenerateDeepLink,\n State as InternalProviderState,\n} from '../provider/mod.js';\nimport type { BlockchainMeta, SignerFactory } from 'rango-types';\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport { ConsumableEvents, type ProviderDetectedEvent } from './events.js';\nimport { guessProviderStateSelector, type State } from './mod.js';\n\ntype Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';\ntype Property<N extends string, V> = { name: N; value: V };\n\ntype NamespacesProperty = Property<\n 'namespaces',\n {\n selection: 'single' | 'multiple';\n data: {\n label: string;\n id: string;\n value: Namespace;\n unsupported?: boolean;\n getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];\n }[];\n }\n>;\ntype DerivationPathProperty = Property<\n 'derivationPath',\n {\n data: {\n id: string;\n label: string;\n namespace: Namespace;\n generateDerivationPath: (index: string) => string;\n }[];\n }\n>;\ntype DetailsProperty = Property<\n 'details',\n {\n mobileWallet?: boolean;\n showOnMobile?: boolean;\n isContractWallet?: boolean;\n }\n>;\ntype SignersProperty = Property<\n 'signers',\n {\n getSigners: () => Promise<SignerFactory>;\n }\n>;\n\nexport type ProviderMetadata = {\n name: string;\n icon: string;\n extensions: Partial<Record<Browsers, string>>;\n properties?: Array<\n | NamespacesProperty\n | DerivationPathProperty\n | DetailsProperty\n | SignersProperty\n >;\n};\n\nexport interface ProviderConfig {\n metadata: ProviderMetadata;\n deepLink?: GenerateDeepLink;\n}\n\nexport type ProviderInfo = ProviderConfig;\n\ninterface ProviderData {\n installed: boolean;\n}\n\ninterface ProviderItem {\n config: ProviderConfig;\n data: ProviderData;\n error: unknown;\n}\n\ntype ProviderState = {\n events: ConsumableEvents;\n list: Record<string, ProviderItem>;\n};\ninterface ProviderActions {\n addProvider: (id: string, config: ProviderConfig) => void;\n removeProvider: (id: string) => void;\n updateStatus: <K extends keyof ProviderData>(\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof ProviderData>(\n provider: ProviderItem,\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n}\n\ninterface ProviderSelectors {\n /**\n * Provider has a limited state to itself, to be compatible with legacy, we try to produce same object as legacy\n * which includes namespace state as well.\n */\n guessNamespacesState: (id: string) => InternalProviderState;\n}\n\nexport type ProviderStore = ProviderState & ProviderActions & ProviderSelectors;\ntype ProvidersStateCreator = StateCreator<State, [], [], ProviderStore>;\n\nconst providersStore: ProvidersStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addProvider: (id, config) => {\n const item = {\n data: {\n installed: false,\n },\n error: '',\n config,\n };\n\n set(\n produce((state: State) => {\n state.providers.list[id] = item;\n })\n );\n },\n removeProvider: (id) => {\n set(\n produce((state: State) => {\n delete state.providers.list[id];\n })\n );\n },\n updateStatus: (id, key, value) => {\n const provider = get().providers.list[id];\n if (!provider) {\n throw new Error(`No namespace namespace with '${id}' found.`);\n }\n\n get().providers._produceEventsWhenUpdatingStatus(provider, id, key, value);\n\n set(\n produce((state: State) => {\n state.providers.list[id].data[key] = value;\n })\n );\n },\n guessNamespacesState: (providerId: string): InternalProviderState => {\n return guessProviderStateSelector(get(), providerId);\n },\n\n _produceEventsWhenUpdatingStatus: (_provider, id, key, _value) => {\n if (key === 'installed') {\n const event: ProviderDetectedEvent = {\n type: 'provider_detected',\n provider: id,\n };\n\n get().providers.events.push(event);\n }\n },\n});\n\nexport { providersStore };\n", "import type { Actions, Context, Operators } from '../hub/namespaces/types.js';\nimport type { AnyFunction, FunctionWithContext } from '../types/actions.js';\n\nexport interface ActionByBuilder<T, Context> {\n actionName: keyof T;\n and: Operators<T>;\n or: Operators<T>;\n after: Operators<T>;\n before: Operators<T>;\n action: FunctionWithContext<T[keyof T], Context>;\n}\n\n/*\n * TODO:\n * Currently, to use this builder you will write something like this:\n * new ActionBuilder<EvmActions, 'disconnect'>('disconnect').after(....)\n *\n * I couldn't figure it out to be able typescript infer the constructor value as key of actions.\n * Ideal usage:\n * new ActionBuilder<EvmActions>('disconnect').after(....)\n *\n */\nexport class ActionBuilder<T extends Actions<T>, K extends keyof T> {\n readonly name: K;\n #and: Operators<T> = new Map();\n #or: Operators<T> = new Map();\n #after: Operators<T> = new Map();\n #before: Operators<T> = new Map();\n #action: FunctionWithContext<T[keyof T], Context<T>> | undefined;\n\n constructor(name: K) {\n this.name = name;\n }\n\n public and(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#and.has(this.name)) {\n this.#and.set(this.name, []);\n }\n this.#and.get(this.name)?.push(action);\n return this;\n }\n\n public or(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#or.has(this.name)) {\n this.#or.set(this.name, []);\n }\n this.#or.get(this.name)?.push(action);\n return this;\n }\n\n public before(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#before.has(this.name)) {\n this.#before.set(this.name, []);\n }\n this.#before.get(this.name)?.push(action);\n return this;\n }\n\n public after(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#after.has(this.name)) {\n this.#after.set(this.name, []);\n }\n this.#after.get(this.name)?.push(action);\n return this;\n }\n\n public action(action: FunctionWithContext<T[keyof T], Context<T>>) {\n this.#action = action;\n return this;\n }\n\n public build(): ActionByBuilder<T, Context<T>> {\n if (!this.#action) {\n throw new Error('Your action builder should includes an action.');\n }\n\n return {\n actionName: this.name,\n action: this.#action,\n before: this.#before,\n after: this.#after,\n and: this.#and,\n or: this.#or,\n };\n }\n}\n", "/*\n * It is not a good idea to re-export all of CAIP because if they have a breaking change, we will break as well.\n * It would be better to create an abstraction over them and export our own interface to ensure it is under our control.\n */\nexport * as CAIP from 'caip';\n\nexport { generateStoreId } from '../hub/helpers.js';\nexport * from './versions.js';\n", "import { AccountId } from 'caip';\n\nexport function isValidCaipAddress(address: string): boolean {\n try {\n AccountId.parse(address);\n return true;\n } catch {\n return false;\n }\n}\n", "import type {\n Accounts,\n AccountsWithActiveChain,\n} from './../../types/accounts.js';\nimport type { Context } from '../../hub/namespaces/mod.js';\n\nimport { isValidCaipAddress } from './helpers.js';\n\nexport function connectAndUpdateStateForSingleNetwork(\n context: Context,\n accounts: Accounts\n) {\n if (!accounts.every(isValidCaipAddress)) {\n throw new Error(\n `Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${accounts}`\n );\n }\n\n const [, setState] = context.state();\n setState('accounts', accounts);\n setState('connected', true);\n return accounts;\n}\n\nexport function connectAndUpdateStateForMultiNetworks(\n context: Context,\n accounts: AccountsWithActiveChain\n) {\n if (!accounts.accounts.every(isValidCaipAddress)) {\n throw new Error(\n `Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${accounts.accounts}`\n );\n }\n\n const [, setState] = context.state();\n setState('accounts', accounts.accounts);\n setState('network', accounts.network);\n setState('connected', true);\n return accounts;\n}\n\nexport const recommended = [];\n", "import type { Context } from '../../hub/namespaces/mod.js';\n\nexport function intoConnecting(context: Context) {\n const [, setState] = context.state();\n setState('connecting', true);\n}\n\n// Please consider if you are going to add something here, make sure it works on all namespaces.\nexport const recommended = [['connect', intoConnecting] as const];\n", "import { beforeRecommended } from '../common/mod.js';\n\nexport const recommended = [...beforeRecommended];\n", "import type { EvmActions } from './types.js';\n\nimport { ActionBuilder } from '../../mod.js';\nimport {\n connectAndUpdateStateForMultiNetworks,\n intoConnecting,\n intoConnectionFinished,\n} from '../common/mod.js';\n\nexport const connect = () =>\n new ActionBuilder<EvmActions, 'connect'>('connect')\n .and(connectAndUpdateStateForMultiNetworks)\n .before(intoConnecting)\n .after(intoConnectionFinished);\n\nexport const canEagerConnect = () =>\n new ActionBuilder<EvmActions, 'canEagerConnect'>('canEagerConnect');\nexport const canSwitchNetwork = () =>\n new ActionBuilder<EvmActions, 'canSwitchNetwork'>('canSwitchNetwork');\n"],
5
- "mappings": "6IAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qB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,EAAI,EACnBF,CACT,CAfgBG,EAAAL,EAAA,yCCtBT,SAASM,EAAeC,EAAkB,CAC/C,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EACnCC,EAAS,aAAc,EAAI,CAC7B,CAHgBC,EAAAH,EAAA,kBAMT,IAAMI,EAAc,CAAC,CAAC,UAAWJ,CAAc,CAAU,ERNzD,IAAMK,GAAc,CACzB,CAAC,UAAWC,CAAqC,CACnD,ESJA,IAAAC,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,KAEO,IAAMC,GAAc,CAAC,GAAGA,CAAiB,ECFhD,IAAAC,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,GAAA,qBAAAC,GAAA,YAAAC,KASO,IAAMC,GAAUC,EAAA,IACrB,IAAIC,EAAqC,SAAS,EAC/C,IAAIC,CAAqC,EACzC,OAAOC,CAAc,EACrB,MAAMC,CAAsB,EAJV,WAMVC,GAAkBL,EAAA,IAC7B,IAAIC,EAA6C,iBAAiB,EADrC,mBAElBK,GAAmBN,EAAA,IAC9B,IAAIC,EAA8C,kBAAkB,EADtC",
6
- "names": ["actions_exports", "__export", "canEagerConnect", "canSwitchNetwork", "changeAccountSubscriber", "changeChainSubscriber", "connect", "recommended", "AccountId", "disconnect", "context", "setState", "__name", "recommended", "CAIP_NAMESPACE", "CAIP_ETHEREUM_CHAIN_ID", "utils_exports", "__export", "filterAndGetEvmBlockchainNames", "getAccounts", "isUserRejectionError", "suggestNetwork", "switchNetwork", "switchOrAddNetwork", "evmBlockchains", "getAccounts", "provider", "accounts", "chainId", "__name", "suggestNetwork", "instance", "chain", "switchNetwork", "filterAndGetEvmBlockchainNames", "meta", "evmBlockchains", "blockchain", "switchOrAddNetwork", "switchError", "error", "EIP_1193_USER_REJECTION_ERROR_CODE", "isUserRejectionError", "code", "causeCode", "recommended", "CHAIN_ID_RADIX", "connect", "instance", "options", "_context", "chain", "evmInstance", "switchOrAddNetwork", "result", "getAccounts", "chainId", "account", "AccountId", "CAIP_NAMESPACE", "__name", "changeAccountSubscriber", "eventCallback", "context", "err", "setState", "accounts", "formatAccounts", "_", "changeChainSubscriber", "canEagerConnect", "canSwitchNetwork", "params", "network", "supportedChains", "filterAndGetEvmBlockchainNames", "after_exports", "__export", "recommended", "intoConnectionFinished", "context", "setState", "__name", "recommended", "recommended", "and_exports", "__export", "recommended", "createZustandStore", "produce", "produce", "ActionBuilder", "__name", "#and", "#or", "#after", "#before", "#action", "name", "action", "CAIP", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForMultiNetworks", "context", "accounts", "isValidCaipAddress", "setState", "__name", "intoConnecting", "context", "setState", "__name", "recommended", "recommended", "connectAndUpdateStateForMultiNetworks", "before_exports", "__export", "recommended", "recommended", "builders_exports", "__export", "canEagerConnect", "canSwitchNetwork", "connect", "connect", "__name", "ActionBuilder", "connectAndUpdateStateForMultiNetworks", "intoConnecting", "intoConnectionFinished", "canEagerConnect", "canSwitchNetwork"]
3
+ "sources": ["../../../src/namespaces/evm/actions.ts", "../../../src/namespaces/common/actions.ts", "../../../src/namespaces/evm/utils.ts", "../../../src/namespaces/evm/constants.ts", "../../../src/namespaces/evm/hooks.ts", "../../../src/namespaces/evm/after.ts", "../../../src/namespaces/common/after.ts", "../../../src/namespaces/evm/and.ts", "../../../src/hub/store/store.ts", "../../../src/hub/store/namespaces.ts", "../../../src/hub/store/providers.ts", "../../../src/builders/action.ts", "../../../src/utils/mod.ts", "../../../src/namespaces/common/helpers.ts", "../../../src/namespaces/common/and.ts", "../../../src/namespaces/common/before.ts", "../../../src/namespaces/evm/before.ts", "../../../src/namespaces/evm/builders.ts", "../../../src/namespaces/common/hooks/changeAccountSubscriber.ts"],
4
+ "sourcesContent": ["import type { ConnectOptions, EvmActions, ProviderAPI } from './types.js';\nimport type { Context } from '../../hub/namespaces/mod.js';\nimport type { CanEagerConnect } from '../../hub/namespaces/types.js';\nimport type { FunctionWithContext } from '../../types/actions.js';\n\nimport { recommended as commonRecommended } from '../common/actions.js';\n\nimport {\n filterAndGetEvmBlockchainNames,\n formatAccountsToCAIP,\n getAccounts,\n switchOrAddNetwork,\n} from './utils.js';\n\nexport const recommended = [...commonRecommended];\nexport function connect(\n instance: () => ProviderAPI,\n options?: ConnectOptions\n): FunctionWithContext<EvmActions['connect'], Context> {\n return async (_context, chain) => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Do your wallet injected correctly and is evm compatible?'\n );\n }\n\n if (chain) {\n /*\n * The `switchOrAddNetwork` function can be optionally provided through `options`\n * to handle network switching or addition in a way that is compatible with the specific wallet provider.\n * This approach is necessary because not all providers follow the same conventions\u2014\n * for example, Rabby uses a different error code for \"chain not found\".\n */\n if (options?.switchOrAddNetwork) {\n await options.switchOrAddNetwork(evmInstance, chain);\n } else {\n await switchOrAddNetwork(evmInstance, chain);\n }\n }\n\n const result = await getAccounts(evmInstance);\n\n const formattedAccounts = formatAccountsToCAIP(\n result.accounts,\n result.chainId\n );\n\n return {\n accounts: formattedAccounts,\n network: result.chainId,\n };\n };\n}\n\nexport function canEagerConnect(\n instance: () => ProviderAPI | undefined\n): CanEagerConnect<EvmActions> {\n return async () => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Trying to eagerly connect to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n try {\n const accounts: string[] = await evmInstance.request({\n method: 'eth_accounts',\n });\n if (accounts.length) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n };\n}\nexport function canSwitchNetwork(): FunctionWithContext<\n EvmActions['canSwitchNetwork'],\n Context\n> {\n return (context, params) => {\n const { network, supportedChains } = params;\n return filterAndGetEvmBlockchainNames(supportedChains).includes(network);\n };\n}\n", "import type { Context } from '../../hub/namespaces/mod.js';\n\nexport function disconnect(context: Context): void {\n const [, setState] = context.state();\n setState('network', null);\n setState('accounts', null);\n setState('connected', false);\n setState('connecting', false);\n}\n\nexport const recommended = [['disconnect', disconnect] as const];\n", "import type { Chain, ChainId, ProviderAPI } from './types.js';\nimport type { CaipAccount } from '../../types/accounts.js';\n\nimport { AccountId } from 'caip';\nimport { type BlockchainMeta, evmBlockchains } from 'rango-types';\n\nimport { CAIP_NAMESPACE } from './constants.js';\n\nconst CHAIN_ID_RADIX = 16;\n\nexport async function getAccounts(provider: ProviderAPI) {\n const [accounts, chainId] = await Promise.all([\n provider.request({ method: 'eth_requestAccounts' }),\n provider.request({ method: 'eth_chainId' }),\n ]);\n /*\n * Trust Wallet Compatibility Fix:\n * Trust Wallet's in-app browser has been observed to return the `chainId` as a\n * number (e.g., 1) rather than the standard hexadecimal string (e.g., \"0x1\").\n * This code block standardizes the `chainId` to the required hex format to\n * prevent downstream errors.\n */\n let standardChainId = chainId;\n if (typeof standardChainId === 'number') {\n standardChainId = `0x${Number(chainId).toString(CHAIN_ID_RADIX)}`;\n }\n\n return {\n accounts,\n chainId: standardChainId,\n };\n}\n\nexport async function suggestNetwork(instance: ProviderAPI, chain: Chain) {\n return await instance.request({\n method: 'wallet_addEthereumChain',\n params: [chain],\n });\n}\n\nexport async function switchNetwork(instance: ProviderAPI, chainId: ChainId) {\n return await instance.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: chainId }],\n });\n}\nexport function filterAndGetEvmBlockchainNames(meta: BlockchainMeta[]) {\n return evmBlockchains(meta).map((blockchain) => blockchain.name);\n}\nexport async function switchOrAddNetwork(\n instance: ProviderAPI,\n chain: ChainId | Chain\n) {\n try {\n const chainId = typeof chain === 'string' ? chain : chain.chainId;\n await switchNetwork(instance, chainId);\n } catch (switchError) {\n const error = switchError as { code: number };\n\n /*\n * Error code 4902 is used by MetaMask to indicate that the requested chain has not been added to the wallet.\n * This code is not part of the official EIP-1193 spec (https://eips.ethereum.org/EIPS/eip-1193#supported-rpc-methods),\n * so other providers may use a different code or behavior for the same condition.\n */\n const NOT_FOUND_CHAIN_ERROR_CODE = 4902;\n if (\n typeof chain !== 'string' &&\n (error.code === NOT_FOUND_CHAIN_ERROR_CODE || !error.code)\n ) {\n /*\n * Note: on WalletConnect `code` is undefined so we have to use !switchError.code as fallback.\n * This error code indicates that the chain has not been added to wallet.\n */\n await suggestNetwork(instance, chain);\n return;\n }\n throw switchError;\n }\n}\n\nconst EIP_1193_USER_REJECTION_ERROR_CODE = 4001;\nexport function isUserRejectionError(error: unknown): boolean {\n // EIP-1193 user rejection error can be in error.code or error.cause.code\n if (typeof error === 'object' && error !== null) {\n const code = (error as { code?: number }).code;\n const causeCode = (error as { cause?: { code?: number } }).cause?.code;\n return (\n code === EIP_1193_USER_REJECTION_ERROR_CODE ||\n causeCode === EIP_1193_USER_REJECTION_ERROR_CODE\n );\n }\n return false;\n}\n\nexport function formatAccountsToCAIP(accounts: string[], chainId: string) {\n return accounts.map(\n (account) =>\n AccountId.format({\n address: account,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: chainId,\n },\n }) as CaipAccount\n );\n}\n", "export const CAIP_NAMESPACE = 'eip155';\nexport const CAIP_ETHEREUM_CHAIN_ID = '1';\n", "import type { EIP1193EventMap } from './eip1193.js';\nimport type { EvmActions, ProviderAPI } from './types.js';\nimport type { Subscriber, SubscriberCleanUp } from '../../mod.js';\n\nimport { builders } from './mod.js';\n\nexport function changeAccountSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {\n return builders.changeAccountSubscriber(instance).build();\n}\n\nexport function changeChainSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {\n let eventCallback: EIP1193EventMap['chainChanged'];\n\n return [\n (context) => {\n const evmInstance = instance();\n\n if (!evmInstance) {\n throw new Error(\n 'Trying to subscribe to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n const [, setState] = context.state();\n\n eventCallback = async (chainId: string) => {\n setState('network', chainId);\n };\n evmInstance.on('chainChanged', eventCallback);\n },\n () => {\n const evmInstance = instance();\n\n if (eventCallback && evmInstance) {\n evmInstance.removeListener('chainChanged', eventCallback);\n }\n },\n ];\n}\n", "import { recommended as commonRecommended } from '../common/after.js';\n\nexport const recommended = [...commonRecommended];\n", "import type { Context } from '../../hub/namespaces/mod.js';\n\nexport function intoConnectionFinished(context: Context) {\n const [, setState] = context.state();\n setState('connecting', false);\n}\n\nexport const recommended = [['connect', intoConnectionFinished] as const];\n", "import { connectAndUpdateStateForMultiNetworks } from '../common/mod.js';\n\nexport const recommended = [\n ['connect', connectAndUpdateStateForMultiNetworks] as const,\n];\n", "import type { StoreApi } from 'zustand/vanilla';\n\nimport { createStore as createZustandStore } from 'zustand/vanilla';\n\nimport { extend, type Store } from './extend.js';\nimport { hubStore, type HubStore } from './hub.js';\nimport { namespacesStore, type NamespaceStore } from './namespaces.js';\nimport { providersStore, type ProviderStore } from './providers.js';\n\n/************ State ************/\n\nexport interface State {\n hub: HubStore;\n providers: ProviderStore;\n namespaces: NamespaceStore;\n}\n\nexport type RawStore = StoreApi<State>;\n\nexport const createStore = (): Store => {\n const store = createZustandStore<State>((...api) => {\n return {\n hub: hubStore(...api),\n providers: providersStore(...api),\n namespaces: namespacesStore(...api),\n };\n });\n\n return extend(store);\n};\n", "/************ Namespace ************/\n\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport {\n ConsumableEvents,\n type NamespaceConnectedEvent,\n type NamespaceDisconnectedEvent,\n type NamespaceSwitchedAccountEvent,\n type NamespaceSwitchedNetworkEvent,\n} from './events.js';\nimport { namespaceStateSelector, type State } from './mod.js';\n\n// Currently, namespace doesn't has any config.\nexport type NamespaceConfig = object;\n\nexport interface NamespaceData {\n accounts: null | string[];\n network: null | string;\n connected: boolean;\n connecting: boolean;\n}\n\ninterface NamespaceInfo {\n providerId: string;\n namespaceId: string;\n}\n\ninterface NamespaceItem {\n info: NamespaceInfo;\n data: NamespaceData;\n error: unknown;\n}\n\ntype NamespaceState = {\n events: InstanceType<typeof ConsumableEvents>;\n list: Record<string, NamespaceItem>;\n};\n\ninterface NamespaceActions {\n addNamespace: (id: string, config: NamespaceInfo) => void;\n updateStatus: <K extends keyof NamespaceData>(\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof NamespaceData>(\n namespace: NamespaceItem,\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n}\ninterface NamespaceSelectors {\n getNamespaceData(storeId: string): NamespaceData;\n}\n\nexport type NamespaceStore = NamespaceState &\n NamespaceActions &\n NamespaceSelectors;\ntype NamespaceStateCreator = StateCreator<State, [], [], NamespaceStore>;\n\nconst namespacesStore: NamespaceStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addNamespace: (id, info) => {\n const data: NamespaceData = {\n accounts: null,\n network: null,\n connected: false,\n connecting: false,\n };\n\n const item = {\n data,\n error: '',\n info,\n };\n\n set(\n produce((state: State) => {\n state.namespaces.list[id] = item;\n })\n );\n },\n updateStatus: (id, key, value) => {\n const ns = get().namespaces.list[id];\n if (!ns) {\n throw new Error(`No namespace with '${id}' found.`);\n }\n\n get().namespaces._produceEventsWhenUpdatingStatus(ns, id, key, value);\n\n // Updating state\n set(\n produce((state: State) => {\n state.namespaces.list[id].data[key] = value;\n })\n );\n },\n getNamespaceData(storeId) {\n return namespaceStateSelector(get(), storeId);\n },\n\n _produceEventsWhenUpdatingStatus: (namespace, id, key, value) => {\n if (key === 'accounts') {\n // check for both null and empty array\n const isAccountsEmpty =\n Object.is(value, null) || (Array.isArray(value) && value.length === 0);\n\n if (isAccountsEmpty) {\n const currentConnectedStatus = get().namespaces.list[id].data.connected;\n if (currentConnectedStatus) {\n const event: NamespaceDisconnectedEvent = {\n type: 'namespace_disconnected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n };\n\n get().namespaces.events.push(event);\n }\n // Skip emitting disconnect event, if the `connected` is false\n } else {\n const currentAccounts = get().namespaces.list[id].data.accounts;\n\n if (!currentAccounts) {\n const event: NamespaceConnectedEvent = {\n type: 'namespace_connected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n } else {\n const areSameAccounts =\n currentAccounts.sort().toString() ===\n (value as string[]).sort().toString();\n\n if (!areSameAccounts) {\n const event: NamespaceSwitchedAccountEvent = {\n type: 'namespace_account_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n previousAccounts: currentAccounts,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n }\n }\n }\n } else if (key === 'network') {\n const currentNetwork = get().namespaces.list[id].data.network;\n\n const event: NamespaceSwitchedNetworkEvent = {\n type: 'namespace_network_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n network: value as string,\n previousNetwork: currentNetwork,\n };\n\n get().namespaces.events.push(event);\n }\n },\n});\n\nexport { namespacesStore };\n", "import type { Namespace } from '../../namespaces/common/types.js';\nimport type {\n GenerateDeepLink,\n State as InternalProviderState,\n} from '../provider/mod.js';\nimport type { BlockchainMeta, SignerFactory } from 'rango-types';\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport { ConsumableEvents, type ProviderDetectedEvent } from './events.js';\nimport { guessProviderStateSelector, type State } from './mod.js';\n\ntype Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';\ntype Property<N extends string, V> = { name: N; value: V };\n\ntype NamespacesProperty = Property<\n 'namespaces',\n {\n selection: 'single' | 'multiple';\n data: {\n label: string;\n id: string;\n value: Namespace;\n unsupported?: boolean;\n getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];\n }[];\n }\n>;\ntype DerivationPathProperty = Property<\n 'derivationPath',\n {\n data: {\n id: string;\n label: string;\n namespace: Namespace;\n generateDerivationPath: (index: string) => string;\n }[];\n }\n>;\ntype DetailsProperty = Property<\n 'details',\n {\n mobileWallet?: boolean;\n showOnMobile?: boolean;\n isContractWallet?: boolean;\n }\n>;\ntype SignersProperty = Property<\n 'signers',\n {\n getSigners: () => Promise<SignerFactory>;\n }\n>;\n\nexport type ProviderMetadata = {\n name: string;\n icon: string;\n extensions: Partial<Record<Browsers, string>>;\n properties?: Array<\n | NamespacesProperty\n | DerivationPathProperty\n | DetailsProperty\n | SignersProperty\n >;\n};\n\nexport interface ProviderConfig {\n metadata: ProviderMetadata;\n deepLink?: GenerateDeepLink;\n}\n\nexport type ProviderInfo = ProviderConfig;\n\ninterface ProviderData {\n installed: boolean;\n}\n\ninterface ProviderItem {\n config: ProviderConfig;\n data: ProviderData;\n error: unknown;\n}\n\ntype ProviderState = {\n events: ConsumableEvents;\n list: Record<string, ProviderItem>;\n};\ninterface ProviderActions {\n addProvider: (id: string, config: ProviderConfig) => void;\n removeProvider: (id: string) => void;\n updateStatus: <K extends keyof ProviderData>(\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof ProviderData>(\n provider: ProviderItem,\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n}\n\ninterface ProviderSelectors {\n /**\n * Provider has a limited state to itself, to be compatible with legacy, we try to produce same object as legacy\n * which includes namespace state as well.\n */\n guessNamespacesState: (id: string) => InternalProviderState;\n}\n\nexport type ProviderStore = ProviderState & ProviderActions & ProviderSelectors;\ntype ProvidersStateCreator = StateCreator<State, [], [], ProviderStore>;\n\nconst providersStore: ProvidersStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addProvider: (id, config) => {\n const item = {\n data: {\n installed: false,\n },\n error: '',\n config,\n };\n\n set(\n produce((state: State) => {\n state.providers.list[id] = item;\n })\n );\n },\n removeProvider: (id) => {\n set(\n produce((state: State) => {\n delete state.providers.list[id];\n })\n );\n },\n updateStatus: (id, key, value) => {\n const provider = get().providers.list[id];\n if (!provider) {\n throw new Error(`No namespace namespace with '${id}' found.`);\n }\n\n get().providers._produceEventsWhenUpdatingStatus(provider, id, key, value);\n\n set(\n produce((state: State) => {\n state.providers.list[id].data[key] = value;\n })\n );\n },\n guessNamespacesState: (providerId: string): InternalProviderState => {\n return guessProviderStateSelector(get(), providerId);\n },\n\n _produceEventsWhenUpdatingStatus: (_provider, id, key, _value) => {\n if (key === 'installed') {\n const event: ProviderDetectedEvent = {\n type: 'provider_detected',\n provider: id,\n };\n\n get().providers.events.push(event);\n }\n },\n});\n\nexport { providersStore };\n", "import type { Actions, Context, Operators } from '../hub/namespaces/types.js';\nimport type { AnyFunction, FunctionWithContext } from '../types/actions.js';\n\nexport interface ActionByBuilder<T, Context> {\n actionName: keyof T;\n and: Operators<T>;\n or: Operators<T>;\n after: Operators<T>;\n before: Operators<T>;\n action: FunctionWithContext<T[keyof T], Context>;\n}\n\n/*\n * TODO:\n * Currently, to use this builder you will write something like this:\n * new ActionBuilder<EvmActions, 'disconnect'>('disconnect').after(....)\n *\n * I couldn't figure it out to be able typescript infer the constructor value as key of actions.\n * Ideal usage:\n * new ActionBuilder<EvmActions>('disconnect').after(....)\n *\n */\nexport class ActionBuilder<T extends Actions<T>, K extends keyof T> {\n readonly name: K;\n #and: Operators<T> = new Map();\n #or: Operators<T> = new Map();\n #after: Operators<T> = new Map();\n #before: Operators<T> = new Map();\n #action: FunctionWithContext<T[keyof T], Context<T>> | undefined;\n\n constructor(name: K) {\n this.name = name;\n }\n\n public and(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#and.has(this.name)) {\n this.#and.set(this.name, []);\n }\n this.#and.get(this.name)?.push(action);\n return this;\n }\n\n public or(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#or.has(this.name)) {\n this.#or.set(this.name, []);\n }\n this.#or.get(this.name)?.push(action);\n return this;\n }\n\n public before(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#before.has(this.name)) {\n this.#before.set(this.name, []);\n }\n this.#before.get(this.name)?.push(action);\n return this;\n }\n\n public after(action: FunctionWithContext<AnyFunction, Context<T>>) {\n if (!this.#after.has(this.name)) {\n this.#after.set(this.name, []);\n }\n this.#after.get(this.name)?.push(action);\n return this;\n }\n\n public action(action: FunctionWithContext<T[keyof T], Context<T>>) {\n this.#action = action;\n return this;\n }\n\n public build(): ActionByBuilder<T, Context<T>> {\n if (!this.#action) {\n throw new Error('Your action builder should includes an action.');\n }\n\n return {\n actionName: this.name,\n action: this.#action,\n before: this.#before,\n after: this.#after,\n and: this.#and,\n or: this.#or,\n };\n }\n}\n", "/*\n * It is not a good idea to re-export all of CAIP because if they have a breaking change, we will break as well.\n * It would be better to create an abstraction over them and export our own interface to ensure it is under our control.\n */\nexport * as CAIP from 'caip';\n\nexport { generateStoreId } from '../hub/helpers.js';\nexport * from './versions.js';\n", "import { AccountId } from 'caip';\n\nexport function isValidCaipAddress(address: string): boolean {\n try {\n AccountId.parse(address);\n return true;\n } catch {\n return false;\n }\n}\n", "import type {\n Accounts,\n AccountsWithActiveChain,\n} from './../../types/accounts.js';\nimport type { Context } from '../../hub/namespaces/mod.js';\n\nimport { isValidCaipAddress } from './helpers.js';\n\nexport function connectAndUpdateStateForSingleNetwork(\n context: Context,\n accounts: Accounts\n) {\n if (!accounts.every(isValidCaipAddress)) {\n throw new Error(\n `Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${accounts}`\n );\n }\n\n const [, setState] = context.state();\n setState('accounts', accounts);\n setState('connected', true);\n return accounts;\n}\n\nexport function connectAndUpdateStateForMultiNetworks(\n context: Context,\n accounts: AccountsWithActiveChain\n) {\n if (!accounts.accounts.every(isValidCaipAddress)) {\n throw new Error(\n `Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${accounts.accounts}`\n );\n }\n\n const [, setState] = context.state();\n setState('accounts', accounts.accounts);\n setState('network', accounts.network);\n setState('connected', true);\n return accounts;\n}\n\nexport const recommended = [];\n", "import type { Context } from '../../hub/namespaces/mod.js';\n\nexport function intoConnecting(context: Context) {\n const [, setState] = context.state();\n setState('connecting', true);\n}\n\n// Please consider if you are going to add something here, make sure it works on all namespaces.\nexport const recommended = [['connect', intoConnecting] as const];\n", "import { beforeRecommended } from '../common/mod.js';\n\nexport const recommended = [...beforeRecommended];\n", "import type { EvmActions, ProviderAPI } from './types.js';\n\nimport { AccountId } from 'caip';\n\nimport { ActionBuilder } from '../../mod.js';\nimport { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';\nimport {\n connectAndUpdateStateForMultiNetworks,\n intoConnecting,\n intoConnectionFinished,\n} from '../common/mod.js';\n\nimport { CAIP_NAMESPACE } from './constants.js';\n\n// Actions\nexport const connect = () =>\n new ActionBuilder<EvmActions, 'connect'>('connect')\n .and(connectAndUpdateStateForMultiNetworks)\n .before(intoConnecting)\n .after(intoConnectionFinished);\n\nexport const canEagerConnect = () =>\n new ActionBuilder<EvmActions, 'canEagerConnect'>('canEagerConnect');\nexport const canSwitchNetwork = () =>\n new ActionBuilder<EvmActions, 'canSwitchNetwork'>('canSwitchNetwork');\n\n// Hooks\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n new ChangeAccountSubscriberBuilder<string[], ProviderAPI>()\n .getInstance(getInstance)\n .validateEventPayload(\n (accounts) =>\n /*\n * In some wallets, when a user switches to an account not yet connected to the dApp, it returns null.\n * A null value indicates no access to the account, requiring a disconnect and user reconnection.\n * This behavior may vary across different wallets, and if so, a different approach may be needed.\n */\n accounts && accounts.length !== 0\n )\n .format(async (instance, accounts) => {\n const chainId = await instance.request({ method: 'eth_chainId' });\n return accounts.map((account) =>\n AccountId.format({\n address: account,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: chainId,\n },\n })\n );\n })\n .addEventListener((instance, callback) => {\n instance.on('accountsChanged', callback);\n })\n .removeEventListener((instance, callback) => {\n instance.removeListener?.('accountsChanged', callback);\n });\n", "import type {\n Actions,\n SubscriberCleanUp,\n} from '../../../hub/namespaces/types.js';\nimport type { Subscriber } from '../../../mod.js';\nimport type { AutoImplementedActionsByRecommended } from '../types.js';\n\nexport class ChangeAccountSubscriberBuilder<EventType, ProviderAPI> {\n #getInstance: (() => ProviderAPI) | null = null;\n #format:\n | ((instance: ProviderAPI, event: EventType) => Promise<string[]>)\n | null = null;\n #validateEventPayload: ((event: EventType) => boolean) | null = null;\n\n #addEventListener:\n | ((\n instance: ProviderAPI,\n callback: (event: EventType) => void\n ) => (() => void) | void)\n | null = null;\n #removeEventListener:\n | ((instance: ProviderAPI, callback: (event: EventType) => void) => void)\n | null = null;\n\n /**\n * Sets the function that provides the provider API instance.\n *\n * @param operator - Function that returns the provider API instance\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.getInstance(() => window.ethereum)\n * ```\n */\n public getInstance(operator: () => ProviderAPI) {\n this.#getInstance = operator;\n return this;\n }\n\n /**\n * Sets the formatter function that converts provider events to account strings.\n *\n * @param operator - Function that takes a provider instance and event, returns array of account strings\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.format(async (instance, event) => event.accounts || [])\n * ```\n */\n public format(\n operator: (instance: ProviderAPI, event: EventType) => Promise<string[]>\n ) {\n this.#format = operator;\n return this;\n }\n\n /**\n * Sets the event payload validation function (optional).\n *\n * @param operator - Function that validates if an event payload is valid\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.validateEventPayload(event => !!event)\n * ```\n */\n public validateEventPayload(operator: (event: EventType) => boolean) {\n this.#validateEventPayload = operator;\n return this;\n }\n\n /**\n * Sets the event listener attachment function.\n *\n * @param operator - Function that attaches an event listener and optionally returns a cleanup function\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.addEventListener((instance, callback) => {\n * return instance.on('accountsChanged', callback);\n * })\n * ```\n */\n public addEventListener(\n operator: (\n instance: ProviderAPI,\n callback: (event: EventType) => void\n ) => (() => void) | void\n ) {\n this.#addEventListener = operator;\n return this;\n }\n\n /**\n * Sets the event listener removal function.\n *\n * @param operator - Function that removes an event listener from the provider\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.removeEventListener((instance, callback) => instance.off('accountsChanged', callback))\n * ```\n */\n public removeEventListener(\n operator: (\n instance: ProviderAPI,\n callback: (event: EventType) => void\n ) => void\n ) {\n this.#removeEventListener = operator;\n return this;\n }\n public build<\n ActionsType extends Actions<ActionsType> &\n Actions<AutoImplementedActionsByRecommended>\n >(): [Subscriber<ActionsType>, SubscriberCleanUp<ActionsType>] {\n if (this.#getInstance === null) {\n throw new Error(this.#getErrorMessage('getInstance'));\n }\n if (this.#format === null) {\n throw new Error(this.#getErrorMessage('format'));\n }\n if (this.#addEventListener === null) {\n throw new Error(this.#getErrorMessage('addEventListener'));\n }\n if (this.#removeEventListener === null) {\n throw new Error(this.#getErrorMessage('removeEventListener'));\n }\n\n /**\n * Capture current operator state at build time to ensure immutability.\n *\n * This creates a snapshot of all operators, preventing the built subscriber\n * from being affected by subsequent changes to the builder instance.\n * Each call to build() gets its own isolated set of operators, allowing\n * the builder to be reused for creating multiple independent subscribers.\n */\n const getInstance = this.#getInstance;\n const format = this.#format;\n const addEventListener = this.#addEventListener;\n const removeEventListener = this.#removeEventListener;\n const validateEventPayload = this.#validateEventPayload;\n let subscriber: (event: EventType) => void;\n let unsubscribe: (() => void) | void;\n return [\n async (context) => {\n const [, setState] = context.state();\n const instance = getInstance();\n\n if (!instance) {\n throw new Error(\n 'Trying to subscribe to your wallet, but seems its instance is not available.'\n );\n }\n subscriber = async (event) => {\n if (!!validateEventPayload && !validateEventPayload(event)) {\n context.action('disconnect');\n return;\n }\n setState('accounts', await format(instance, event));\n };\n unsubscribe = addEventListener(instance, subscriber);\n },\n (_, err) => {\n /**\n * Call the cleanup function if addEventListener returned one.\n * This handles providers that return an unsubscribe function from their event listeners.\n */\n if (unsubscribe && typeof unsubscribe === 'function') {\n unsubscribe();\n }\n const instance = getInstance();\n\n /**\n * Always call removeEventListener as well to handle the on/off pattern.\n * This ensures cleanup works regardless of which pattern the provider uses.\n */\n removeEventListener(instance, subscriber);\n\n // subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.\n return err;\n },\n ];\n }\n #getErrorMessage(operatorName: string) {\n return `Required \"${operatorName}\" operation has not been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,EAAcJ,EAAiBO,EAAUJ,CAAU,CACrD,EACA,CAACM,EAAGC,IAAQ,CAKNN,GAAe,OAAOA,GAAgB,YACxCA,EAAY,EAEd,IAAMG,EAAWT,EAAY,EAM7B,OAAAG,EAAoBM,EAAUJ,CAAU,EAGjCO,CACT,CACF,CACF,CACAb,GAAiBc,EAAsB,CACrC,MAAO,aAAaA,CAAY,4DAClC,CACF,ED5KO,IAAMC,GAAUC,EAAA,IACrB,IAAIC,EAAqC,SAAS,EAC/C,IAAIC,CAAqC,EACzC,OAAOC,CAAc,EACrB,MAAMC,CAAsB,EAJV,WAMVC,GAAkBL,EAAA,IAC7B,IAAIC,EAA6C,iBAAiB,EADrC,mBAElBK,GAAmBN,EAAA,IAC9B,IAAIC,EAA8C,kBAAkB,EADtC,oBAInBM,GAA0BP,EAACQ,GACtC,IAAIC,EAAsD,EACvD,YAAYD,CAAW,EACvB,qBACEE,GAMCA,GAAYA,EAAS,SAAW,CACpC,EACC,OAAO,MAAOC,EAAUD,IAAa,CACpC,IAAME,EAAU,MAAMD,EAAS,QAAQ,CAAE,OAAQ,aAAc,CAAC,EAChE,OAAOD,EAAS,IAAKG,GACnBC,GAAU,OAAO,CACf,QAASD,EACT,QAAS,CACP,UAAWE,EACX,UAAWH,CACb,CACF,CAAC,CACH,CACF,CAAC,EACA,iBAAiB,CAACD,EAAUK,IAAa,CACxCL,EAAS,GAAG,kBAAmBK,CAAQ,CACzC,CAAC,EACA,oBAAoB,CAACL,EAAUK,IAAa,CAC3CL,EAAS,iBAAiB,kBAAmBK,CAAQ,CACvD,CAAC,EA7BkC",
6
+ "names": ["actions_exports", "__export", "canEagerConnect", "canSwitchNetwork", "connect", "recommended", "disconnect", "context", "setState", "__name", "recommended", "utils_exports", "__export", "filterAndGetEvmBlockchainNames", "formatAccountsToCAIP", "getAccounts", "isUserRejectionError", "suggestNetwork", "switchNetwork", "switchOrAddNetwork", "AccountId", "evmBlockchains", "CAIP_NAMESPACE", "CAIP_ETHEREUM_CHAIN_ID", "CHAIN_ID_RADIX", "getAccounts", "provider", "accounts", "chainId", "standardChainId", "__name", "suggestNetwork", "instance", "chain", "switchNetwork", "filterAndGetEvmBlockchainNames", "meta", "evmBlockchains", "blockchain", "switchOrAddNetwork", "switchError", "error", "EIP_1193_USER_REJECTION_ERROR_CODE", "isUserRejectionError", "code", "causeCode", "formatAccountsToCAIP", "account", "AccountId", "CAIP_NAMESPACE", "recommended", "connect", "instance", "options", "_context", "chain", "evmInstance", "switchOrAddNetwork", "result", "getAccounts", "formatAccountsToCAIP", "__name", "canEagerConnect", "canSwitchNetwork", "context", "params", "network", "supportedChains", "filterAndGetEvmBlockchainNames", "hooks_exports", "__export", "changeAccountSubscriber", "changeChainSubscriber", "changeAccountSubscriber", "instance", "builders_exports", "__name", "changeChainSubscriber", "eventCallback", "context", "evmInstance", "setState", "chainId", "after_exports", "__export", "recommended", "intoConnectionFinished", "context", "setState", "__name", "recommended", "recommended", "and_exports", "__export", "recommended", "createZustandStore", "produce", "produce", "ActionBuilder", "__name", "#and", "#or", "#after", "#before", "#action", "name", "action", "CAIP", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForMultiNetworks", "context", "accounts", "isValidCaipAddress", "setState", "__name", "intoConnecting", "context", "setState", "__name", "recommended", "recommended", "connectAndUpdateStateForMultiNetworks", "before_exports", "__export", "recommended", "recommended", "builders_exports", "__export", "canEagerConnect", "canSwitchNetwork", "changeAccountSubscriber", "connect", "AccountId", "ChangeAccountSubscriberBuilder", "__name", "#getInstance", "#format", "#validateEventPayload", "#addEventListener", "#removeEventListener", "operator", "#getErrorMessage", "getInstance", "format", "addEventListener", "removeEventListener", "validateEventPayload", "subscriber", "unsubscribe", "context", "setState", "instance", "event", "_", "err", "operatorName", "connect", "__name", "ActionBuilder", "connectAndUpdateStateForMultiNetworks", "intoConnecting", "intoConnectionFinished", "canEagerConnect", "canSwitchNetwork", "changeAccountSubscriber", "getInstance", "ChangeAccountSubscriberBuilder", "accounts", "instance", "chainId", "account", "AccountId", "CAIP_NAMESPACE", "callback"]
7
7
  }
@@ -9,4 +9,5 @@ export declare function switchNetwork(instance: ProviderAPI, chainId: ChainId):
9
9
  export declare function filterAndGetEvmBlockchainNames(meta: BlockchainMeta[]): string[];
10
10
  export declare function switchOrAddNetwork(instance: ProviderAPI, chain: ChainId | Chain): Promise<void>;
11
11
  export declare function isUserRejectionError(error: unknown): boolean;
12
+ export declare function formatAccountsToCAIP(accounts: string[], chainId: string): `${string}:${string}:${string}`[];
12
13
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAElE,wBAAsB,WAAW,CAAC,QAAQ,EAAE,WAAW;;;GAUtD;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,iBAKvE;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,iBAK1E;AACD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,cAAc,EAAE,YAEpE;AACD,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,OAAO,GAAG,KAAK,iBA2BvB;AAGD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAW5D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9D,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAMlE,wBAAsB,WAAW,CAAC,QAAQ,EAAE,WAAW;;;GAqBtD;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,iBAKvE;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,iBAK1E;AACD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,cAAc,EAAE,YAEpE;AACD,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,OAAO,GAAG,KAAK,iBA2BvB;AAGD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAW5D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,qCAWvE"}
@@ -1,8 +1,6 @@
1
1
  import type { ProviderAPI, SolanaActions } from './types.js';
2
- import type { Context, Subscriber } from '../../hub/namespaces/mod.js';
3
- import type { SubscriberCleanUp } from '../../hub/namespaces/types.js';
2
+ import type { Context } from '../../hub/namespaces/mod.js';
4
3
  import type { FunctionWithContext } from '../../types/actions.js';
5
4
  export declare const recommended: (readonly ["disconnect", typeof import("../common/actions.js").disconnect])[];
6
- export declare function changeAccountSubscriber(instance: () => ProviderAPI | undefined): [Subscriber<SolanaActions>, SubscriberCleanUp<SolanaActions>];
7
5
  export declare function connect(instance: () => ProviderAPI): FunctionWithContext<SolanaActions['connect'], Context>;
8
6
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAS/E,eAAO,MAAM,WAAW,+EAAyB,CAAC;AAElD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,WAAW,GAAG,SAAS,GACtC,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAkD/D;AACD,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,WAAW,GAC1B,mBAAmB,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAsBxD"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAE3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AASlE,eAAO,MAAM,WAAW,+EAAyB,CAAC;AAElD,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,WAAW,GAC1B,mBAAmB,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAsBxD"}
@@ -1,4 +1,6 @@
1
- import type { SolanaActions } from './types.js';
1
+ import type { ProviderAPI, SolanaActions } from './types.js';
2
2
  import { ActionBuilder } from '../../mod.js';
3
+ import { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';
3
4
  export declare const connect: () => ActionBuilder<SolanaActions, "connect">;
5
+ export declare const changeAccountSubscriber: (getInstance: () => ProviderAPI) => ChangeAccountSubscriberBuilder<string, ProviderAPI>;
4
6
  //# sourceMappingURL=builders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAO7C,eAAO,MAAM,OAAO,+CAIc,CAAC"}
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAU5F,eAAO,MAAM,OAAO,+CAIc,CAAC;AAGnC,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,WAAW,wDAiBhE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ProviderAPI, SolanaActions } from './types.js';
2
+ import type { Subscriber, SubscriberCleanUp } from '../../mod.js';
3
+ export declare function changeAccountSubscriber(instance: () => ProviderAPI): [Subscriber<SolanaActions>, SubscriberCleanUp<SolanaActions>];
4
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIlE,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,WAAW,GAC1B,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAE/D"}
@@ -1,4 +1,5 @@
1
1
  export * as actions from './actions.js';
2
+ export * as hooks from './hooks.js';
2
3
  export * as after from './after.js';
3
4
  export * as and from './and.js';
4
5
  export * as before from './before.js';
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,2 +1,2 @@
1
- var x=Object.defineProperty;var e=(n,t)=>x(n,"name",{value:t,configurable:!0});var a=(n,t)=>{for(var o in t)x(n,o,{get:t[o],enumerable:!0})};var w={};a(w,{changeAccountSubscriber:()=>j,connect:()=>_,recommended:()=>L});import{AccountId as E}from"caip";function A(n){let[,t]=n.state();t("network",null),t("accounts",null),t("connected",!1),t("connecting",!1)}e(A,"disconnect");var I=[["disconnect",A]];var p="solana",d="5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";async function N(n){return{accounts:[(await n.connect()).publicKey.toString()],chainId:"SOLANA"}}e(N,"getAccounts");var L=[...I];function j(n){let t;return[(o,s)=>{let i=n();if(!i)throw new Error("Trying to subscribe to your Solana wallet, but seems its instance is not available.");let[,D]=o.state();return t=e(C=>{if(!C){o.action("disconnect");return}D("accounts",[E.format({address:C.toString(),chainId:{namespace:p,reference:d}})])},"eventCallback"),i.on("accountChanged",t),s},(o,s)=>{let i=n();return t&&i&&i.off("accountChanged",t),s}]}e(j,"changeAccountSubscriber");function _(n){return async()=>{let t=n(),o=await N(t);if(Array.isArray(o))throw new Error("Expecting solana response to be a single value, not an array.");return o.accounts.map(s=>E.format({address:s,chainId:{namespace:p,reference:d}}))}}e(_,"connect");var b={};a(b,{recommended:()=>H});function u(n){let[,t]=n.state();t("connecting",!1)}e(u,"intoConnectionFinished");var f=[["connect",u]];var H=[...f];var O={};a(O,{recommended:()=>X});import{createStore as Rt}from"zustand/vanilla";import{produce as yt}from"immer";import{produce as At}from"immer";var r=class{static{e(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#n=new Map;#o=new Map;#r;constructor(t){this.name=t}and(t){return this.#e.has(this.name)||this.#e.set(this.name,[]),this.#e.get(this.name)?.push(t),this}or(t){return this.#t.has(this.name)||this.#t.set(this.name,[]),this.#t.get(this.name)?.push(t),this}before(t){return this.#o.has(this.name)||this.#o.set(this.name,[]),this.#o.get(this.name)?.push(t),this}after(t){return this.#n.has(this.name)||this.#n.set(this.name,[]),this.#n.get(this.name)?.push(t),this}action(t){return this.#r=t,this}build(){if(!this.#r)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#r,before:this.#o,after:this.#n,and:this.#e,or:this.#t}}};import*as dn from"caip";import{AccountId as J}from"caip";function T(n){try{return J.parse(n),!0}catch{return!1}}e(T,"isValidCaipAddress");function c(n,t){if(!t.every(T))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t}`);let[,o]=n.state();return o("accounts",t),o("connected",!0),t}e(c,"connectAndUpdateStateForSingleNetwork");function l(n){let[,t]=n.state();t("connecting",!0)}e(l,"intoConnecting");var S=[["connect",l]];var X=[["connect",c]];var R={};a(R,{recommended:()=>q});var q=[...S];var M={};a(M,{connect:()=>Z});var Z=e(()=>new r("connect").and(c).before(l).after(u),"connect");export{p as CAIP_NAMESPACE,d as CAIP_SOLANA_CHAIN_ID,w as actions,b as after,O as and,R as before,M as builders};
1
+ var P=Object.defineProperty;var t=(n,e)=>P(n,"name",{value:e,configurable:!0});var s=(n,e)=>{for(var o in e)P(n,o,{get:e[o],enumerable:!0})};var M={};s(M,{connect:()=>J,recommended:()=>z});import{AccountId as $}from"caip";function T(n){let[,e]=n.state();e("network",null),e("accounts",null),e("connected",!1),e("connecting",!1)}t(T,"disconnect");var k=[["disconnect",T]];var a="solana",c="5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";import{AccountId as Y}from"caip";async function O(n){return{accounts:[(await n.connect()).publicKey.toString()],chainId:"SOLANA"}}t(O,"getAccounts");function R(n){return n.map(e=>Y.format({address:e.toString(),chainId:{namespace:a,reference:c}}))}t(R,"formatAccountsToCAIP");var z=[...k];function J(n){return async()=>{let e=n(),o=await O(e);if(Array.isArray(o))throw new Error("Expecting solana response to be a single value, not an array.");return o.accounts.map(v=>$.format({address:v,chainId:{namespace:a,reference:c}}))}}t(J,"connect");var D={};s(D,{changeAccountSubscriber:()=>X});function X(n){return u.changeAccountSubscriber(n).build()}t(X,"changeAccountSubscriber");var F={};s(F,{recommended:()=>q});function m(n){let[,e]=n.state();e("connecting",!1)}t(m,"intoConnectionFinished");var C=[["connect",m]];var q=[...C];var K={};s(K,{recommended:()=>se});import{createStore as Yt}from"zustand/vanilla";import{produce as kt}from"immer";import{produce as Bt}from"immer";var r=class{static{t(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#o=new Map;#n=new Map;#r;constructor(e){this.name=e}and(e){return this.#e.has(this.name)||this.#e.set(this.name,[]),this.#e.get(this.name)?.push(e),this}or(e){return this.#t.has(this.name)||this.#t.set(this.name,[]),this.#t.get(this.name)?.push(e),this}before(e){return this.#n.has(this.name)||this.#n.set(this.name,[]),this.#n.get(this.name)?.push(e),this}after(e){return this.#o.has(this.name)||this.#o.set(this.name,[]),this.#o.get(this.name)?.push(e),this}action(e){return this.#r=e,this}build(){if(!this.#r)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#r,before:this.#n,after:this.#o,and:this.#e,or:this.#t}}};import*as En from"caip";import{AccountId as re}from"caip";function j(n){try{return re.parse(n),!0}catch{return!1}}t(j,"isValidCaipAddress");function p(n,e){if(!e.every(j))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${e}`);let[,o]=n.state();return o("accounts",e),o("connected",!0),e}t(p,"connectAndUpdateStateForSingleNetwork");function h(n){let[,e]=n.state();e("connecting",!0)}t(h,"intoConnecting");var b=[["connect",h]];var se=[["connect",p]];var W={};s(W,{recommended:()=>ie});var ie=[...b];var u={};s(u,{changeAccountSubscriber:()=>ce,connect:()=>ae});var f=class{static{t(this,"ChangeAccountSubscriberBuilder")}#e=null;#t=null;#o=null;#n=null;#r=null;getInstance(e){return this.#e=e,this}format(e){return this.#t=e,this}validateEventPayload(e){return this.#o=e,this}addEventListener(e){return this.#n=e,this}removeEventListener(e){return this.#r=e,this}build(){if(this.#e===null)throw new Error(this.#s("getInstance"));if(this.#t===null)throw new Error(this.#s("format"));if(this.#n===null)throw new Error(this.#s("addEventListener"));if(this.#r===null)throw new Error(this.#s("removeEventListener"));let e=this.#e,o=this.#t,v=this.#n,_=this.#r,w=this.#o,y,d;return[async g=>{let[,S]=g.state(),i=e();if(!i)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");y=t(async N=>{if(w&&!w(N)){g.action("disconnect");return}S("accounts",await o(i,N))},"subscriber"),d=v(i,y)},(g,S)=>{d&&typeof d=="function"&&d();let i=e();return _(i,y),S}]}#s(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};var ae=t(()=>new r("connect").and(p).before(h).after(m),"connect"),ce=t(n=>new f().getInstance(n).validateEventPayload(e=>!!e).format(async(e,o)=>R([o])).addEventListener((e,o)=>{e.on("accountChanged",o)}).removeEventListener((e,o)=>{e.off("accountChanged",o)}),"changeAccountSubscriber");export{a as CAIP_NAMESPACE,c as CAIP_SOLANA_CHAIN_ID,M as actions,F as after,K as and,W as before,u as builders,D as hooks};
2
2
  //# sourceMappingURL=mod.js.map