@rango-dev/wallets-core 0.51.1-next.1 → 0.53.1-next.0

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.
@@ -1,2 +1,2 @@
1
- var T=Object.defineProperty;var t=(n,e)=>T(n,"name",{value:e,configurable:!0});var r=(n,e)=>{for(var o in e)T(n,o,{get:e[o],enumerable:!0})};var M={};r(M,{canEagerConnect:()=>X,connect:()=>J,recommended:()=>z});function k(n){let[,e]=n.state();e("network",null),e("accounts",null),e("connected",!1),e("connecting",!1)}t(k,"disconnect");var O=[["disconnect",k]];var R={};r(R,{formatAccountsToCAIP:()=>a,getAccounts:()=>C});import{AccountId as $}from"caip";var S="solana",A="5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";async function C(n){let e=await n.connect();return{accounts:[e?e.publicKey.toString():n.publicKey.toString()],chainId:"SOLANA"}}t(C,"getAccounts");function a(n){return n.map(e=>$.format({address:e.toString(),chainId:{namespace:S,reference:A}}))}t(a,"formatAccountsToCAIP");var z=[...O];function J(n){return async()=>{let e=n(),o=await C(e);if(Array.isArray(o))throw new Error("Expecting solana response to be a single value, not an array.");return a(o.accounts)}}t(J,"connect");function X(n){return async()=>{let e=n();if(!e)throw new Error("Trying to eagerly connect to your Solana wallet, but seems its instance is not available.");try{return!!await e.connect({onlyIfTrusted:!0})}catch{return!1}}}t(X,"canEagerConnect");var F={};r(F,{changeAccountSubscriber:()=>q});function q(n){return u.changeAccountSubscriber(n).build()}t(q,"changeAccountSubscriber");var B={};r(B,{recommended:()=>Z});function l(n){let[,e]=n.state();e("connecting",!1)}t(l,"intoConnectionFinished");var x=[["connect",l]];var Z=[...x];var W={};r(W,{recommended:()=>ie});import{createStore as Vt}from"zustand/vanilla";import{produce as Pt}from"immer";import{produce as Ft}from"immer";var s=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 xn from"caip";var c=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,L=this.#n,H=this.#r,N=this.#o,f,d;return[async v=>{let[,y]=v.state(),i=e();if(!i)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");f=t(async P=>{if(N&&!N(P)){v.action("disconnect");return}y("accounts",await o(i,P))},"subscriber"),d=L(i,f)},(v,y)=>{d&&typeof d=="function"&&d();let i=e();return H(i,f),y}]}#s(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};import{AccountId as se}from"caip";function K(n){try{return se.parse(n),!0}catch{return!1}}t(K,"isValidCaipAddress");function p(n,e){if(!e.every(K))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 w=[["connect",h]];var ie=[["connect",p]];var _={};r(_,{recommended:()=>ae});var ae=[...w];var u={};r(u,{changeAccountSubscriber:()=>pe,connect:()=>ce});var ce=t(()=>new s("connect").and(p).before(h).after(l),"connect"),pe=t(n=>new c().getInstance(n).validateEventPayload(e=>!!e).format(async(e,o)=>a([o])).addEventListener((e,o)=>{e.on("accountChanged",o)}).removeEventListener((e,o)=>{e.off("accountChanged",o)}),"changeAccountSubscriber");export{S as CAIP_NAMESPACE,A as CAIP_SOLANA_CHAIN_ID,M as actions,B as after,W as and,_ as before,u as builders,F as hooks,R as utils};
1
+ var T=Object.defineProperty;var t=(n,e)=>T(n,"name",{value:e,configurable:!0});var r=(n,e)=>{for(var o in e)T(n,o,{get:e[o],enumerable:!0})};var M={};r(M,{canEagerConnect:()=>q,connect:()=>X,recommended:()=>J});function k(n){let[,e]=n.state();e("network",null),e("accounts",null),e("connected",!1),e("connecting",!1)}t(k,"disconnect");var O=[["disconnect",k]];var R={};r(R,{formatAccountsToCAIP:()=>a,getAccounts:()=>x});import{AccountId as z}from"caip";var S="solana",A="5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";async function x(n){let e=await n.connect();return{accounts:[e?e.publicKey.toString():n.publicKey.toString()],chainId:"SOLANA"}}t(x,"getAccounts");function a(n){return n.map(e=>z.format({address:e.toString(),chainId:{namespace:S,reference:A}}))}t(a,"formatAccountsToCAIP");var J=[...O];function X(n){return async()=>{let e=n(),o=await x(e);if(Array.isArray(o))throw new Error("Expecting solana response to be a single value, not an array.");return a(o.accounts)}}t(X,"connect");function q(n){return async()=>{let e=n();if(!e)throw new Error("Trying to eagerly connect to your Solana wallet, but seems its instance is not available.");try{return!!await e.connect({onlyIfTrusted:!0})}catch{return!1}}}t(q,"canEagerConnect");var B={};r(B,{changeAccountSubscriber:()=>Z});function Z(n){return u.changeAccountSubscriber(n).build()}t(Z,"changeAccountSubscriber");var F={};r(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={};r(K,{recommended:()=>ae});import{createStore as Gt}from"zustand/vanilla";import{produce as Tt}from"immer";import{produce as Ft}from"immer";var s=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 In from"caip";var c=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}onSwitchAccount(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,L=this.#n,H=this.#r,U=this.#o,f,d;return[async v=>{let[,y]=v.state(),i=e();if(!i)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");f=t(async N=>{let P=!0;U?.({payload:N,preventDefault:()=>{P=!1}},v),P&&y("accounts",await o(i,N))},"subscriber"),d=L(i,f)},(v,y)=>{d&&typeof d=="function"&&d();let i=e();return H(i,f),y}]}#s(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};import{AccountId as ie}from"caip";function j(n){try{return ie.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 w=[["connect",h]];var ae=[["connect",p]];var _={};r(_,{recommended:()=>ce});var ce=[...w];var u={};r(u,{changeAccountSubscriber:()=>de,connect:()=>pe});var pe=t(()=>new s("connect").and(p).before(h).after(m),"connect"),de=t(n=>new c().getInstance(n).onSwitchAccount((e,o)=>{e.payload||(o.action("disconnect"),e.preventDefault())}).format(async(e,o)=>a([o])).addEventListener((e,o)=>{e.on("accountChanged",o)}).removeEventListener((e,o)=>{e.off("accountChanged",o)}),"changeAccountSubscriber");export{S as CAIP_NAMESPACE,A as CAIP_SOLANA_CHAIN_ID,M as actions,F as after,K as and,_ as before,u as builders,B as hooks,R as utils};
2
2
  //# sourceMappingURL=mod.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/namespaces/solana/actions.ts", "../../../src/namespaces/common/actions.ts", "../../../src/namespaces/solana/utils.ts", "../../../src/namespaces/solana/constants.ts", "../../../src/namespaces/solana/hooks.ts", "../../../src/namespaces/solana/after.ts", "../../../src/namespaces/common/after.ts", "../../../src/namespaces/solana/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/hooks/changeAccountSubscriber.ts", "../../../src/namespaces/common/helpers.ts", "../../../src/namespaces/common/and.ts", "../../../src/namespaces/common/before.ts", "../../../src/namespaces/solana/before.ts", "../../../src/namespaces/solana/builders.ts"],
4
- "sourcesContent": ["import type { ProviderAPI, SolanaActions } from './types.js';\nimport type { Context } from '../../hub/namespaces/mod.js';\nimport type { FunctionWithContext } from '../../types/actions.js';\n\nimport { recommended as commonRecommended } from '../common/actions.js';\n\nimport { formatAccountsToCAIP, getAccounts } from './utils.js';\n\nexport const recommended = [...commonRecommended];\n\nexport function connect(\n instance: () => ProviderAPI\n): FunctionWithContext<SolanaActions['connect'], Context> {\n return async () => {\n const solanaInstance = instance();\n const result = await getAccounts(solanaInstance);\n\n if (Array.isArray(result)) {\n throw new Error(\n 'Expecting solana response to be a single value, not an array.'\n );\n }\n\n return formatAccountsToCAIP(result.accounts);\n };\n}\nexport function canEagerConnect(instance: () => ProviderAPI) {\n return async () => {\n const solanaInstance = instance();\n\n if (!solanaInstance) {\n throw new Error(\n 'Trying to eagerly connect to your Solana wallet, but seems its instance is not available.'\n );\n }\n\n try {\n const result = await solanaInstance.connect({ onlyIfTrusted: true });\n return !!result;\n } catch {\n return false;\n }\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 { ProviderAPI } from './types.js';\nimport type { CaipAccount } from '../../types/accounts.js';\n\nimport { AccountId } from 'caip';\n\nimport { LegacyNetworks } from '../../legacy/mod.js';\n\nimport { CAIP_NAMESPACE, CAIP_SOLANA_CHAIN_ID } from './constants.js';\n\nexport async function getAccounts(provider: ProviderAPI) {\n const solanaResponse = await provider.connect();\n /*\n * Fallback for wallets like Coinbase that return no response on connect.\n * If solanaResponse is undefined, use the provider's publicKey directly.\n */\n const account = solanaResponse\n ? solanaResponse.publicKey.toString()\n : provider.publicKey.toString();\n return {\n accounts: [account],\n chainId: LegacyNetworks.SOLANA,\n };\n}\n\nexport function formatAccountsToCAIP(accounts: string[]) {\n return accounts.map(\n (account) =>\n AccountId.format({\n address: account.toString(),\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_SOLANA_CHAIN_ID,\n },\n }) as CaipAccount\n );\n}\n", "export const CAIP_NAMESPACE = 'solana';\nexport const CAIP_SOLANA_CHAIN_ID = '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\n", "import type { ProviderAPI, SolanaActions } 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<SolanaActions>, SubscriberCleanUp<SolanaActions>] {\n return builders.changeAccountSubscriber(instance).build();\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 { connectAndUpdateStateForSingleNetwork } from '../common/mod.js';\n\nexport const recommended = [\n ['connect', connectAndUpdateStateForSingleNetwork] 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 // Clone the object from the Zustand store, as it's immutable, to avoid errors during sorting.\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 { State as InternalProviderState } 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}\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 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 set for \"changeAccountSubscriber\"`;\n }\n}\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 { recommended as commonRecommended } from '../common/before.js';\n\nexport const recommended = [...commonRecommended];\n", "import type { ProviderAPI, SolanaActions } from './types.js';\n\nimport { ActionBuilder } from '../../mod.js';\nimport { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';\nimport {\n connectAndUpdateStateForSingleNetwork,\n intoConnecting,\n intoConnectionFinished,\n} from '../common/mod.js';\n\nimport { formatAccountsToCAIP } from './utils.js';\n\n// Actions\nexport const connect = () =>\n new ActionBuilder<SolanaActions, 'connect'>('connect')\n .and(connectAndUpdateStateForSingleNetwork)\n .before(intoConnecting)\n .after(intoConnectionFinished);\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 */\n !!accounts\n )\n .format(async (_, accounts) => formatAccountsToCAIP([accounts]))\n .addEventListener((instance, callback) => {\n instance.on('accountChanged', callback);\n })\n .removeEventListener((instance, callback) => {\n instance.off('accountChanged', callback);\n });\n"],
5
- "mappings": "6IAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,EAAA,gBAAAC,ICEO,SAASC,EAAWC,EAAwB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AASM,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,ETNzD,IAAMK,GAAc,CACzB,CAAC,UAAWC,CAAqC,CACnD,EUJA,IAAAC,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,KAEO,IAAMC,GAAc,CAAC,GAAGA,CAAiB,ECFhD,IAAAC,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,GAAA,YAAAC,KAaO,IAAMC,GAAUC,EAAA,IACrB,IAAIC,EAAwC,SAAS,EAClD,IAAIC,CAAqC,EACzC,OAAOC,CAAc,EACrB,MAAMC,CAAsB,EAJV,WAOVC,GAA0BL,EAACM,GACtC,IAAIC,EAAoD,EACrD,YAAYD,CAAW,EACvB,qBACEE,GAKC,CAAC,CAACA,CACN,EACC,OAAO,MAAOC,EAAGD,IAAaE,EAAqB,CAACF,CAAQ,CAAC,CAAC,EAC9D,iBAAiB,CAACG,EAAUC,IAAa,CACxCD,EAAS,GAAG,iBAAkBC,CAAQ,CACxC,CAAC,EACA,oBAAoB,CAACD,EAAUC,IAAa,CAC3CD,EAAS,IAAI,iBAAkBC,CAAQ,CACzC,CAAC,EAjBkC",
6
- "names": ["actions_exports", "__export", "canEagerConnect", "connect", "recommended", "disconnect", "context", "setState", "__name", "recommended", "utils_exports", "__export", "formatAccountsToCAIP", "getAccounts", "AccountId", "CAIP_NAMESPACE", "CAIP_SOLANA_CHAIN_ID", "getAccounts", "provider", "solanaResponse", "__name", "formatAccountsToCAIP", "accounts", "account", "AccountId", "CAIP_NAMESPACE", "CAIP_SOLANA_CHAIN_ID", "recommended", "connect", "instance", "solanaInstance", "result", "getAccounts", "formatAccountsToCAIP", "__name", "canEagerConnect", "hooks_exports", "__export", "changeAccountSubscriber", "changeAccountSubscriber", "instance", "builders_exports", "__name", "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", "ChangeAccountSubscriberBuilder", "__name", "#getInstance", "#format", "#validateEventPayload", "#addEventListener", "#removeEventListener", "operator", "#getErrorMessage", "getInstance", "format", "addEventListener", "removeEventListener", "validateEventPayload", "subscriber", "unsubscribe", "context", "setState", "instance", "event", "_", "err", "operatorName", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForSingleNetwork", "context", "accounts", "isValidCaipAddress", "setState", "__name", "intoConnecting", "context", "setState", "__name", "recommended", "recommended", "connectAndUpdateStateForSingleNetwork", "before_exports", "__export", "recommended", "recommended", "builders_exports", "__export", "changeAccountSubscriber", "connect", "connect", "__name", "ActionBuilder", "connectAndUpdateStateForSingleNetwork", "intoConnecting", "intoConnectionFinished", "changeAccountSubscriber", "getInstance", "ChangeAccountSubscriberBuilder", "accounts", "_", "formatAccountsToCAIP", "instance", "callback"]
4
+ "sourcesContent": ["import type { ProviderAPI, SolanaActions } from './types.js';\nimport type { Context } from '../../hub/namespaces/mod.js';\nimport type { FunctionWithContext } from '../../types/actions.js';\n\nimport { recommended as commonRecommended } from '../common/actions.js';\n\nimport { formatAccountsToCAIP, getAccounts } from './utils.js';\n\nexport const recommended = [...commonRecommended];\n\nexport function connect(\n instance: () => ProviderAPI\n): FunctionWithContext<SolanaActions['connect'], Context> {\n return async () => {\n const solanaInstance = instance();\n const result = await getAccounts(solanaInstance);\n\n if (Array.isArray(result)) {\n throw new Error(\n 'Expecting solana response to be a single value, not an array.'\n );\n }\n\n return formatAccountsToCAIP(result.accounts);\n };\n}\nexport function canEagerConnect(instance: () => ProviderAPI) {\n return async () => {\n const solanaInstance = instance();\n\n if (!solanaInstance) {\n throw new Error(\n 'Trying to eagerly connect to your Solana wallet, but seems its instance is not available.'\n );\n }\n\n try {\n const result = await solanaInstance.connect({ onlyIfTrusted: true });\n return !!result;\n } catch {\n return false;\n }\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 { ProviderAPI } from './types.js';\nimport type { CaipAccount } from '../../types/accounts.js';\n\nimport { AccountId } from 'caip';\n\nimport { LegacyNetworks } from '../../legacy/mod.js';\n\nimport { CAIP_NAMESPACE, CAIP_SOLANA_CHAIN_ID } from './constants.js';\n\nexport async function getAccounts(provider: ProviderAPI) {\n const solanaResponse = await provider.connect();\n /*\n * Fallback for wallets like Coinbase that return no response on connect.\n * If solanaResponse is undefined, use the provider's publicKey directly.\n */\n const account = solanaResponse\n ? solanaResponse.publicKey.toString()\n : provider.publicKey.toString();\n return {\n accounts: [account],\n chainId: LegacyNetworks.SOLANA,\n };\n}\n\nexport function formatAccountsToCAIP(accounts: string[]) {\n return accounts.map(\n (account) =>\n AccountId.format({\n address: account.toString(),\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_SOLANA_CHAIN_ID,\n },\n }) as CaipAccount\n );\n}\n", "export const CAIP_NAMESPACE = 'solana';\nexport const CAIP_SOLANA_CHAIN_ID = '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\n", "import type { ProviderAPI, SolanaActions } 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<SolanaActions>, SubscriberCleanUp<SolanaActions>] {\n return builders.changeAccountSubscriber(instance).build();\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 { connectAndUpdateStateForSingleNetwork } from '../common/mod.js';\n\nexport const recommended = [\n ['connect', connectAndUpdateStateForSingleNetwork] 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 // Clone the object from the Zustand store, as it's immutable, to avoid errors during sorting.\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 { State as InternalProviderState } 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}\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 type {\n Actions,\n Context,\n SubscriberCleanUp,\n} from '../../../hub/namespaces/types.js';\nimport type { Subscriber } from '../../../mod.js';\nimport type { AutoImplementedActionsByRecommended } from '../types.js';\n\ntype OnSwitchAccountEvent<EventType> = {\n payload: EventType;\n preventDefault: () => void;\n};\n\nexport class ChangeAccountSubscriberBuilder<EventType, ProviderAPI> {\n #getInstance: (() => ProviderAPI) | null = null;\n #format:\n | ((instance: ProviderAPI, event: EventType) => Promise<string[]>)\n | null = null;\n #onSwitchAccount:\n | (<\n ActionsType extends Actions<ActionsType> &\n Actions<AutoImplementedActionsByRecommended>\n >(\n event: OnSwitchAccountEvent<EventType>,\n context: Context<ActionsType>\n ) => void)\n | 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 * Set a handler that runs whenever a **switch-account** event occurs.\n *\n * The provided operator is called with:\n * - `event`: An object containing:\n * - `payload`: The event payload associated with the account switch.\n * - `preventDefault`: A function that prevents the default switch-account\n * behavior (e.g., updating the active accounts list).\n * - `context`: The execution context of the current flow or action.\n *\n * Calling `event.preventDefault()` inside the handler cancels the built-in\n * account switching logic.\n *\n * @param operator - A function invoked on each switch-account event.\n * It receives `(event, context)` and can call `event.preventDefault()` to\n * stop the default behavior.\n *\n * @returns The builder instance for method chaining.\n *\n * @example\n * ```ts\n * builder.onSwitchAccount((event, context) => {\n * if (!event.payload.userConfirmed) {\n * event.preventDefault(); // cancel default account switch\n * }\n *\n * console.log(\"Switching account:\", event.payload.accountId);\n * });\n * ```\n */\n public onSwitchAccount(\n operator: <\n ActionsType extends Actions<ActionsType> &\n Actions<AutoImplementedActionsByRecommended>\n >(\n event: OnSwitchAccountEvent<EventType>,\n context: Context<ActionsType>\n ) => void\n ) {\n this.#onSwitchAccount = 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 onSwitchAccount = this.#onSwitchAccount;\n\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 let shouldProceedWithDefault = true;\n\n onSwitchAccount?.(\n {\n payload: event,\n preventDefault: () => {\n shouldProceedWithDefault = false;\n },\n },\n context\n );\n if (!shouldProceedWithDefault) {\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 set for \"changeAccountSubscriber\"`;\n }\n}\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 { recommended as commonRecommended } from '../common/before.js';\n\nexport const recommended = [...commonRecommended];\n", "import type { ProviderAPI, SolanaActions } from './types.js';\n\nimport { ActionBuilder } from '../../mod.js';\nimport { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';\nimport {\n connectAndUpdateStateForSingleNetwork,\n intoConnecting,\n intoConnectionFinished,\n} from '../common/mod.js';\n\nimport { formatAccountsToCAIP } from './utils.js';\n\n// Actions\nexport const connect = () =>\n new ActionBuilder<SolanaActions, 'connect'>('connect')\n .and(connectAndUpdateStateForSingleNetwork)\n .before(intoConnecting)\n .after(intoConnectionFinished);\n\n// Hooks\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n new ChangeAccountSubscriberBuilder<string, ProviderAPI>()\n .getInstance(getInstance)\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 */\n .onSwitchAccount((event, context) => {\n if (!event.payload) {\n context.action('disconnect');\n event.preventDefault();\n }\n })\n .format(async (_, accounts) => formatAccountsToCAIP([accounts]))\n .addEventListener((instance, callback) => {\n instance.on('accountChanged', callback);\n })\n .removeEventListener((instance, callback) => {\n instance.off('accountChanged', callback);\n });\n"],
5
+ "mappings": "6IAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,EAAA,gBAAAC,ICEO,SAASC,EAAWC,EAAwB,CACjD,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EACnCC,EAAS,UAAW,IAAI,EACxBA,EAAS,WAAY,IAAI,EACzBA,EAAS,YAAa,EAAK,EAC3BA,EAAS,aAAc,EAAK,CAC9B,CANgBC,EAAAH,EAAA,cAQT,IAAMI,EAAc,CAAC,CAAC,aAAcJ,CAAU,CAAU,ECV/D,IAAAK,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,gBAAAC,IAGA,OAAS,aAAAC,MAAiB,OCHnB,IAAMC,EAAiB,SACjBC,EAAuB,mCDQpC,eAAsBC,EAAYC,EAAuB,CACvD,IAAMC,EAAiB,MAAMD,EAAS,QAAQ,EAQ9C,MAAO,CACL,SAAU,CAJIC,EACZA,EAAe,UAAU,SAAS,EAClCD,EAAS,UAAU,SAAS,CAEZ,EAClB,gBACF,CACF,CAbsBE,EAAAH,EAAA,eAef,SAASI,EAAqBC,EAAoB,CACvD,OAAOA,EAAS,IACbC,GACCC,EAAU,OAAO,CACf,QAASD,EAAQ,SAAS,EAC1B,QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACL,CACF,CAXgBN,EAAAC,EAAA,wBFhBT,IAAMM,EAAc,CAAC,GAAGA,CAAiB,EAEzC,SAASC,EACdC,EACwD,CACxD,MAAO,UAAY,CACjB,IAAMC,EAAiBD,EAAS,EA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AACD,EAAUC,IAAa,CAC3CD,EAAS,IAAI,iBAAkBC,CAAQ,CACzC,CAAC,EAnBkC",
6
+ "names": ["actions_exports", "__export", "canEagerConnect", "connect", "recommended", "disconnect", "context", "setState", "__name", "recommended", "utils_exports", "__export", "formatAccountsToCAIP", "getAccounts", "AccountId", "CAIP_NAMESPACE", "CAIP_SOLANA_CHAIN_ID", "getAccounts", "provider", "solanaResponse", "__name", "formatAccountsToCAIP", "accounts", "account", "AccountId", "CAIP_NAMESPACE", "CAIP_SOLANA_CHAIN_ID", "recommended", "connect", "instance", "solanaInstance", "result", "getAccounts", "formatAccountsToCAIP", "__name", "canEagerConnect", "hooks_exports", "__export", "changeAccountSubscriber", "changeAccountSubscriber", "instance", "builders_exports", "__name", "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", "ChangeAccountSubscriberBuilder", "__name", "#getInstance", "#format", "#onSwitchAccount", "#addEventListener", "#removeEventListener", "operator", "#getErrorMessage", "getInstance", "format", "addEventListener", "removeEventListener", "onSwitchAccount", "subscriber", "unsubscribe", "context", "setState", "instance", "event", "shouldProceedWithDefault", "_", "err", "operatorName", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForSingleNetwork", "context", "accounts", "isValidCaipAddress", "setState", "__name", "intoConnecting", "context", "setState", "__name", "recommended", "recommended", "connectAndUpdateStateForSingleNetwork", "before_exports", "__export", "recommended", "recommended", "builders_exports", "__export", "changeAccountSubscriber", "connect", "connect", "__name", "ActionBuilder", "connectAndUpdateStateForSingleNetwork", "intoConnecting", "intoConnectionFinished", "changeAccountSubscriber", "getInstance", "ChangeAccountSubscriberBuilder", "event", "context", "_", "accounts", "formatAccountsToCAIP", "instance", "callback"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/namespaces/sui/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,WAAW,EACX,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAY5F,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,OAAO,WAAY,aAAa,yCAsBX,CAAC;AAEnC,eAAO,MAAM,eAAe,oDACyC,CAAC;AAGtE,eAAO,MAAM,uBAAuB,WAC1B,6BAA6B;cAGvB,SAAS,aAAa,EAAE;eAiBD,CAAC"}
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/namespaces/sui/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,WAAW,EACX,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAY5F,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,OAAO,WAAY,aAAa,yCAsBX,CAAC;AAEnC,eAAO,MAAM,eAAe,oDACyC,CAAC;AAGtE,eAAO,MAAM,uBAAuB,WAC1B,6BAA6B;cAGvB,SAAS,aAAa,EAAE;eAkBD,CAAC"}
@@ -1,2 +1,2 @@
1
- var N=Object.defineProperty;var t=(r,e)=>N(r,"name",{value:e,configurable:!0});var y=(r,e)=>{for(var n in e)N(r,n,{get:e[n],enumerable:!0})};var I={};y(I,{canEagerConnect:()=>K});function K(r){return async()=>{let e=s(r.name);try{return!!(await e.features["standard:connect"].connect({silent:!0})).accounts.length}catch{return!1}}}t(K,"canEagerConnect");var f={};y(f,{canEagerConnect:()=>q,changeAccountSubscriber:()=>Q,connect:()=>G});import{createStore as Ge}from"zustand/vanilla";import{produce as Fe}from"immer";import{produce as We}from"immer";var o=class{static{t(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#n=new Map;#r=new Map;#o;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.#n.has(this.name)||this.#n.set(this.name,[]),this.#n.get(this.name)?.push(e),this}action(e){return this.#o=e,this}build(){if(!this.#o)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#o,before:this.#r,after:this.#n,and:this.#e,or:this.#t}}};import*as _ from"caip";var a=class{static{t(this,"ChangeAccountSubscriberBuilder")}#e=null;#t=null;#n=null;#r=null;#o=null;getInstance(e){return this.#e=e,this}format(e){return this.#t=e,this}validateEventPayload(e){return this.#n=e,this}addEventListener(e){return this.#r=e,this}removeEventListener(e){return this.#o=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.#o===null)throw new Error(this.#s("removeEventListener"));let e=this.#e,n=this.#t,P=this.#r,E=this.#o,p=this.#n,h,u;return[async l=>{let[,v]=l.state(),i=e();if(!i)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");h=t(async w=>{if(p&&!p(w)){l.action("disconnect");return}v("accounts",await n(i,w))},"subscriber"),u=P(i,h)},(l,v)=>{u&&typeof u=="function"&&u();let i=e();return E(i,h),v}]}#s(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};function b(r){let[,e]=r.state();e("connecting",!1)}t(b,"intoConnectionFinished");import{AccountId as L}from"caip";function F(r){try{return L.parse(r),!0}catch{return!1}}t(F,"isValidCaipAddress");function A(r,e){if(!e.every(F))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${e}`);let[,n]=r.state();return n("accounts",e),n("connected",!0),e}t(A,"connectAndUpdateStateForSingleNetwork");function C(r){let[,e]=r.state();e("connecting",!0)}t(C,"intoConnecting");var c="sui",d="sui";import{getWallets as $,SUI_MAINNET_CHAIN as Y}from"@mysten/wallet-standard";import{AccountId as z}from"caip";function R(r){return $().get().find(n=>n.name===r&&n.chains.includes(Y))}t(R,"getInstance");function s(r){let e=R(r);if(!e)throw new Error("We couldn't find the Sui instance on your wallet. It may be fixed by refreshing the page.");return e}t(s,"getInstanceOrThrow");function j(r){return r.map(e=>z.format({address:e.address,chainId:{namespace:c,reference:d}}))}t(j,"formatAccountsToCAIP");var G=t(r=>new o("connect").action(async function(){return(await s(r.name).features["standard:connect"].connect()).accounts.map(p=>_.AccountId.format({address:p.address,chainId:{namespace:c,reference:d}}))}).and(A).before(C).after(b),"connect"),q=t(()=>new o("canEagerConnect"),"canEagerConnect"),Q=t(r=>new a().getInstance(()=>s(r.name)).validateEventPayload(e=>e.accounts?.length!==0).format(async(e,n)=>j(n.accounts)).addEventListener((e,n)=>e.features["standard:events"].on("change",n)).removeEventListener((e,n)=>{}),"changeAccountSubscriber");var O={};y(O,{changeAccountSubscriber:()=>Z});function Z(r){return f.changeAccountSubscriber({name:r.name}).build()}t(Z,"changeAccountSubscriber");export{c as CAIP_NAMESPACE,d as CAIP_SUI_CHAIN_ID,I as actions,f as builders,R as getInstance,s as getInstanceOrThrow,O as hooks};
1
+ var I=Object.defineProperty;var t=(r,e)=>I(r,"name",{value:e,configurable:!0});var y=(r,e)=>{for(var n in e)I(r,n,{get:e[n],enumerable:!0})};var T={};y(T,{canEagerConnect:()=>D});function D(r){return async()=>{let e=s(r.name);try{return!!(await e.features["standard:connect"].connect({silent:!0})).accounts.length}catch{return!1}}}t(D,"canEagerConnect");var m={};y(m,{canEagerConnect:()=>Q,changeAccountSubscriber:()=>Z,connect:()=>q});import{createStore as qe}from"zustand/vanilla";import{produce as Re}from"immer";import{produce as Ve}from"immer";var o=class{static{t(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#n=new Map;#r=new Map;#o;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.#n.has(this.name)||this.#n.set(this.name,[]),this.#n.get(this.name)?.push(e),this}action(e){return this.#o=e,this}build(){if(!this.#o)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#o,before:this.#r,after:this.#n,and:this.#e,or:this.#t}}};import*as F from"caip";var a=class{static{t(this,"ChangeAccountSubscriberBuilder")}#e=null;#t=null;#n=null;#r=null;#o=null;getInstance(e){return this.#e=e,this}format(e){return this.#t=e,this}onSwitchAccount(e){return this.#n=e,this}addEventListener(e){return this.#r=e,this}removeEventListener(e){return this.#o=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.#o===null)throw new Error(this.#s("removeEventListener"));let e=this.#e,n=this.#t,P=this.#r,w=this.#o,f=this.#n,h,p;return[async l=>{let[,v]=l.state(),i=e();if(!i)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");h=t(async E=>{let N=!0;f?.({payload:E,preventDefault:()=>{N=!1}},l),N&&v("accounts",await n(i,E))},"subscriber"),p=P(i,h)},(l,v)=>{p&&typeof p=="function"&&p();let i=e();return w(i,h),v}]}#s(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};function A(r){let[,e]=r.state();e("connecting",!1)}t(A,"intoConnectionFinished");import{AccountId as $}from"caip";function R(r){try{return $.parse(r),!0}catch{return!1}}t(R,"isValidCaipAddress");function b(r,e){if(!e.every(R))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${e}`);let[,n]=r.state();return n("accounts",e),n("connected",!0),e}t(b,"connectAndUpdateStateForSingleNetwork");function C(r){let[,e]=r.state();e("connecting",!0)}t(C,"intoConnecting");var c="sui",d="sui";import{getWallets as Y,SUI_MAINNET_CHAIN as z}from"@mysten/wallet-standard";import{AccountId as G}from"caip";function O(r){return Y().get().find(n=>n.name===r&&n.chains.includes(z))}t(O,"getInstance");function s(r){let e=O(r);if(!e)throw new Error("We couldn't find the Sui instance on your wallet. It may be fixed by refreshing the page.");return e}t(s,"getInstanceOrThrow");function j(r){return r.map(e=>G.format({address:e.address,chainId:{namespace:c,reference:d}}))}t(j,"formatAccountsToCAIP");var q=t(r=>new o("connect").action(async function(){return(await s(r.name).features["standard:connect"].connect()).accounts.map(f=>F.AccountId.format({address:f.address,chainId:{namespace:c,reference:d}}))}).and(b).before(C).after(A),"connect"),Q=t(()=>new o("canEagerConnect"),"canEagerConnect"),Z=t(r=>new a().getInstance(()=>s(r.name)).onSwitchAccount((e,n)=>{e.payload.accounts?.length||(n.action("disconnect"),e.preventDefault())}).format(async(e,n)=>j(n.accounts)).addEventListener((e,n)=>e.features["standard:events"].on("change",n)).removeEventListener((e,n)=>{}),"changeAccountSubscriber");var K={};y(K,{changeAccountSubscriber:()=>J});function J(r){return m.changeAccountSubscriber({name:r.name}).build()}t(J,"changeAccountSubscriber");export{c as CAIP_NAMESPACE,d as CAIP_SUI_CHAIN_ID,T as actions,m as builders,O as getInstance,s as getInstanceOrThrow,K as hooks};
2
2
  //# sourceMappingURL=mod.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/namespaces/sui/actions.ts", "../../../src/namespaces/sui/builders.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/hooks/changeAccountSubscriber.ts", "../../../src/namespaces/common/after.ts", "../../../src/namespaces/common/helpers.ts", "../../../src/namespaces/common/and.ts", "../../../src/namespaces/common/before.ts", "../../../src/namespaces/sui/constants.ts", "../../../src/namespaces/sui/utils.ts", "../../../src/namespaces/sui/hooks.ts"],
4
- "sourcesContent": ["import type { SuiActions } from './types.js';\nimport type { CanEagerConnect } from '../../hub/namespaces/types.js';\n\nimport { getInstanceOrThrow } from './mod.js';\n\ninterface CanEagerConnectParams {\n name: string;\n}\nexport function canEagerConnect(\n params: CanEagerConnectParams\n): CanEagerConnect<SuiActions> {\n return async () => {\n const wallet = getInstanceOrThrow(params.name);\n\n try {\n const connectResult = await wallet.features['standard:connect'].connect({\n silent: true,\n });\n if (connectResult.accounts.length) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n };\n}\n", "import type {\n ChangeAccountSubscriberParams,\n ProviderAPI,\n SuiActions,\n} from './types.js';\nimport type { WalletAccount } from '@mysten/wallet-standard';\n\nimport { ActionBuilder } from '../../mod.js';\nimport { CAIP } from '../../utils/mod.js';\nimport { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';\nimport {\n type CaipAccount,\n connectAndUpdateStateForSingleNetwork,\n intoConnecting,\n intoConnectionFinished,\n} from '../common/mod.js';\n\nimport { CAIP_NAMESPACE, CAIP_SUI_CHAIN_ID } from './constants.js';\nimport { formatAccountsToCAIP, getInstanceOrThrow } from './utils.js';\n\n// Actions\ninterface ConnectParams {\n name: string;\n}\n\nexport const connect = (params: ConnectParams) =>\n new ActionBuilder<SuiActions, 'connect'>('connect')\n .action(async function () {\n const wallet = getInstanceOrThrow(params.name);\n const features = wallet.features;\n\n const result = await features['standard:connect'].connect();\n\n const accounts = result.accounts.map((account) => {\n return CAIP.AccountId.format({\n address: account.address,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_SUI_CHAIN_ID,\n },\n }) as CaipAccount;\n });\n\n return accounts;\n })\n .and(connectAndUpdateStateForSingleNetwork)\n .before(intoConnecting)\n .after(intoConnectionFinished);\n\nexport const canEagerConnect = () =>\n new ActionBuilder<SuiActions, 'canEagerConnect'>('canEagerConnect');\n\n// Hooks\nexport const changeAccountSubscriber = (\n params: ChangeAccountSubscriberParams\n) =>\n new ChangeAccountSubscriberBuilder<\n { accounts: readonly WalletAccount[] },\n ProviderAPI\n >()\n .getInstance(() => getInstanceOrThrow(params.name))\n .validateEventPayload(\n (event) =>\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 */\n\n event.accounts?.length !== 0\n )\n .format(async (_, event) => formatAccountsToCAIP(event.accounts))\n .addEventListener((instance, callback) =>\n instance.features['standard:events'].on('change', callback)\n )\n .removeEventListener((_, __) => {});\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 // Clone the object from the Zustand store, as it's immutable, to avoid errors during sorting.\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 { State as InternalProviderState } 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}\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 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 set for \"changeAccountSubscriber\"`;\n }\n}\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 { 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", "/*\n * TODO: I couldn't found sui in caip\n * @see https://namespaces.chainagnostic.org/\n */\n\n// if the value neeeds to be change make sure you will update mapCaipNamespaceToLegacyNetworkName as well\nexport const CAIP_NAMESPACE = 'sui';\nexport const CAIP_SUI_CHAIN_ID = 'sui';\n", "import type {\n StandardConnectFeature,\n StandardEventsFeature,\n SuiFeatures,\n WalletWithFeatures,\n} from '@mysten/wallet-standard';\n\nimport { getWallets, SUI_MAINNET_CHAIN } from '@mysten/wallet-standard';\nimport { AccountId } from 'caip';\n\nimport { CAIP_NAMESPACE, CAIP_SUI_CHAIN_ID } from './constants.js';\n\n// TODO: StandardFetures doesn't work, so we should add each feature separately\ntype SuiWalletStandard = WalletWithFeatures<\n StandardConnectFeature & StandardEventsFeature & SuiFeatures\n>;\n\n/**\n * @param name each wallet has a name in WalletStandard. you should pass that value\n */\nexport function getInstance(name: string): SuiWalletStandard | undefined {\n const wallet = getWallets()\n .get()\n .find(\n (wallet) =>\n wallet.name === name && wallet.chains.includes(SUI_MAINNET_CHAIN)\n );\n\n return wallet as SuiWalletStandard;\n}\n\n/**\n * @param name each wallet has a name in WalletStandard. you should pass that value\n */\nexport function getInstanceOrThrow(name: string): SuiWalletStandard {\n const wallet = getInstance(name);\n\n if (!wallet) {\n throw new Error(\n \"We couldn't find the Sui instance on your wallet. It may be fixed by refreshing the page.\"\n );\n }\n\n return wallet;\n}\nexport function formatAccountsToCAIP(accounts: readonly { address: string }[]) {\n return accounts.map((account) => {\n return AccountId.format({\n address: account.address,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_SUI_CHAIN_ID,\n },\n });\n });\n}\n", "import type { ChangeAccountSubscriberParams, SuiActions } from './types.js';\nimport type { Subscriber, SubscriberCleanUp } from '../../mod.js';\n\nimport { builders } from './mod.js';\n\nexport function changeAccountSubscriber(\n params: ChangeAccountSubscriberParams\n): [Subscriber<SuiActions>, SubscriberCleanUp<SuiActions>] {\n return builders.changeAccountSubscriber({ name: params.name }).build();\n}\n"],
5
- "mappings": "6IAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAQO,SAASC,EACdC,EAC6B,CAC7B,MAAO,UAAY,CACjB,IAAMC,EAASC,EAAmBF,EAAO,IAAI,EAE7C,GAAI,CAIF,MAAI,GAHkB,MAAMC,EAAO,SAAS,kBAAkB,EAAE,QAAQ,CACtE,OAAQ,EACV,CAAC,GACiB,SAAS,MAI7B,MAAQ,CACN,MAAO,EACT,CACF,CACF,CAlBgBE,EAAAJ,EAAA,mBCRhB,IAAAK,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,YAAAC,ICEA,OAAS,eAAeC,OAA0B,kBCElD,OAAS,WAAAC,OAAe,QCCxB,OAAS,WAAAC,OAAe,QCiBjB,IAAMC,EAAN,KAA6D,CAtBpE,MAsBoE,CAAAC,EAAA,sBACzD,KACTC,GAAqB,IAAI,IACzBC,GAAoB,IAAI,IACxBC,GAAuB,IAAI,IAC3BC,GAAwB,IAAI,IAC5BC,GAE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QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACF,CACH,CAVgBP,EAAAE,EAAA,wBZpBT,IAAMM,EAAUC,EAACC,GACtB,IAAIC,EAAqC,SAAS,EAC/C,OAAO,gBAAkB,CAgBxB,OAZe,MAHAC,EAAmBF,EAAO,IAAI,EACrB,SAEM,kBAAkB,EAAE,QAAQ,GAElC,SAAS,IAAKG,GAC7BC,EAAK,UAAU,OAAO,CAC3B,QAASD,EAAQ,QACjB,QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACF,CAGH,CAAC,EACA,IAAIC,CAAqC,EACzC,OAAOC,CAAc,EACrB,MAAMC,CAAsB,EAtBV,WAwBVC,EAAkBX,EAAA,IAC7B,IAAIE,EAA6C,iBAAiB,EADrC,mBAIlBU,EAA0BZ,EACrCC,GAEA,IAAIY,EAGF,EACC,YAAY,IAAMV,EAAmBF,EAAO,IAAI,CAAC,EACjD,qBACEa,GAMCA,EAAM,UAAU,SAAW,CAC/B,EACC,OAAO,MAAOC,EAAGD,IAAUE,EAAqBF,EAAM,QAAQ,CAAC,EAC/D,iBAAiB,CAACG,EAAUC,IAC3BD,EAAS,SAAS,iBAAiB,EAAE,GAAG,SAAUC,CAAQ,CAC5D,EACC,oBAAoB,CAACH,EAAGI,IAAO,CAAC,CAAC,EArBC,2BarDvC,IAAAC,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAKO,SAASC,EACdC,EACyD,CACzD,OAAOC,EAAS,wBAAwB,CAAE,KAAMD,EAAO,IAAK,CAAC,EAAE,MAAM,CACvE,CAJgBE,EAAAH,EAAA",
6
- "names": ["actions_exports", "__export", "canEagerConnect", "canEagerConnect", "params", "wallet", "getInstanceOrThrow", "__name", "builders_exports", "__export", "canEagerConnect", "changeAccountSubscriber", "connect", "createZustandStore", "produce", "produce", "ActionBuilder", "__name", "#and", "#or", "#after", "#before", "#action", "name", "action", "CAIP", "ChangeAccountSubscriberBuilder", "__name", "#getInstance", "#format", "#validateEventPayload", "#addEventListener", "#removeEventListener", "operator", "#getErrorMessage", "getInstance", "format", "addEventListener", "removeEventListener", "validateEventPayload", "subscriber", "unsubscribe", "context", "setState", "instance", "event", "_", "err", "operatorName", "intoConnectionFinished", "context", "setState", "__name", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForSingleNetwork", "context", "accounts", "isValidCaipAddress", "setState", "__name", "intoConnecting", "context", "setState", "__name", "CAIP_NAMESPACE", "CAIP_SUI_CHAIN_ID", "getWallets", "SUI_MAINNET_CHAIN", "AccountId", "getInstance", "name", "getWallets", "wallet", "SUI_MAINNET_CHAIN", "__name", "getInstanceOrThrow", "formatAccountsToCAIP", "accounts", "account", "AccountId", "CAIP_NAMESPACE", "CAIP_SUI_CHAIN_ID", "connect", "__name", "params", "ActionBuilder", "getInstanceOrThrow", "account", "CAIP", "CAIP_NAMESPACE", "CAIP_SUI_CHAIN_ID", "connectAndUpdateStateForSingleNetwork", "intoConnecting", "intoConnectionFinished", "canEagerConnect", "changeAccountSubscriber", "ChangeAccountSubscriberBuilder", "event", "_", "formatAccountsToCAIP", "instance", "callback", "__", "hooks_exports", "__export", "changeAccountSubscriber", "changeAccountSubscriber", "params", "builders_exports", "__name"]
4
+ "sourcesContent": ["import type { SuiActions } from './types.js';\nimport type { CanEagerConnect } from '../../hub/namespaces/types.js';\n\nimport { getInstanceOrThrow } from './mod.js';\n\ninterface CanEagerConnectParams {\n name: string;\n}\nexport function canEagerConnect(\n params: CanEagerConnectParams\n): CanEagerConnect<SuiActions> {\n return async () => {\n const wallet = getInstanceOrThrow(params.name);\n\n try {\n const connectResult = await wallet.features['standard:connect'].connect({\n silent: true,\n });\n if (connectResult.accounts.length) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n };\n}\n", "import type {\n ChangeAccountSubscriberParams,\n ProviderAPI,\n SuiActions,\n} from './types.js';\nimport type { WalletAccount } from '@mysten/wallet-standard';\n\nimport { ActionBuilder } from '../../mod.js';\nimport { CAIP } from '../../utils/mod.js';\nimport { ChangeAccountSubscriberBuilder } from '../common/hooks/changeAccountSubscriber.js';\nimport {\n type CaipAccount,\n connectAndUpdateStateForSingleNetwork,\n intoConnecting,\n intoConnectionFinished,\n} from '../common/mod.js';\n\nimport { CAIP_NAMESPACE, CAIP_SUI_CHAIN_ID } from './constants.js';\nimport { formatAccountsToCAIP, getInstanceOrThrow } from './utils.js';\n\n// Actions\ninterface ConnectParams {\n name: string;\n}\n\nexport const connect = (params: ConnectParams) =>\n new ActionBuilder<SuiActions, 'connect'>('connect')\n .action(async function () {\n const wallet = getInstanceOrThrow(params.name);\n const features = wallet.features;\n\n const result = await features['standard:connect'].connect();\n\n const accounts = result.accounts.map((account) => {\n return CAIP.AccountId.format({\n address: account.address,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_SUI_CHAIN_ID,\n },\n }) as CaipAccount;\n });\n\n return accounts;\n })\n .and(connectAndUpdateStateForSingleNetwork)\n .before(intoConnecting)\n .after(intoConnectionFinished);\n\nexport const canEagerConnect = () =>\n new ActionBuilder<SuiActions, 'canEagerConnect'>('canEagerConnect');\n\n// Hooks\nexport const changeAccountSubscriber = (\n params: ChangeAccountSubscriberParams\n) =>\n new ChangeAccountSubscriberBuilder<\n { accounts: readonly WalletAccount[] },\n ProviderAPI\n >()\n .getInstance(() => getInstanceOrThrow(params.name))\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 */\n .onSwitchAccount((event, context) => {\n if (!event.payload.accounts?.length) {\n context.action('disconnect');\n event.preventDefault();\n }\n })\n .format(async (_, event) => formatAccountsToCAIP(event.accounts))\n .addEventListener((instance, callback) =>\n instance.features['standard:events'].on('change', callback)\n )\n .removeEventListener((_, __) => {});\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 // Clone the object from the Zustand store, as it's immutable, to avoid errors during sorting.\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 { State as InternalProviderState } 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}\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 type {\n Actions,\n Context,\n SubscriberCleanUp,\n} from '../../../hub/namespaces/types.js';\nimport type { Subscriber } from '../../../mod.js';\nimport type { AutoImplementedActionsByRecommended } from '../types.js';\n\ntype OnSwitchAccountEvent<EventType> = {\n payload: EventType;\n preventDefault: () => void;\n};\n\nexport class ChangeAccountSubscriberBuilder<EventType, ProviderAPI> {\n #getInstance: (() => ProviderAPI) | null = null;\n #format:\n | ((instance: ProviderAPI, event: EventType) => Promise<string[]>)\n | null = null;\n #onSwitchAccount:\n | (<\n ActionsType extends Actions<ActionsType> &\n Actions<AutoImplementedActionsByRecommended>\n >(\n event: OnSwitchAccountEvent<EventType>,\n context: Context<ActionsType>\n ) => void)\n | 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 * Set a handler that runs whenever a **switch-account** event occurs.\n *\n * The provided operator is called with:\n * - `event`: An object containing:\n * - `payload`: The event payload associated with the account switch.\n * - `preventDefault`: A function that prevents the default switch-account\n * behavior (e.g., updating the active accounts list).\n * - `context`: The execution context of the current flow or action.\n *\n * Calling `event.preventDefault()` inside the handler cancels the built-in\n * account switching logic.\n *\n * @param operator - A function invoked on each switch-account event.\n * It receives `(event, context)` and can call `event.preventDefault()` to\n * stop the default behavior.\n *\n * @returns The builder instance for method chaining.\n *\n * @example\n * ```ts\n * builder.onSwitchAccount((event, context) => {\n * if (!event.payload.userConfirmed) {\n * event.preventDefault(); // cancel default account switch\n * }\n *\n * console.log(\"Switching account:\", event.payload.accountId);\n * });\n * ```\n */\n public onSwitchAccount(\n operator: <\n ActionsType extends Actions<ActionsType> &\n Actions<AutoImplementedActionsByRecommended>\n >(\n event: OnSwitchAccountEvent<EventType>,\n context: Context<ActionsType>\n ) => void\n ) {\n this.#onSwitchAccount = 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 onSwitchAccount = this.#onSwitchAccount;\n\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 let shouldProceedWithDefault = true;\n\n onSwitchAccount?.(\n {\n payload: event,\n preventDefault: () => {\n shouldProceedWithDefault = false;\n },\n },\n context\n );\n if (!shouldProceedWithDefault) {\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 set for \"changeAccountSubscriber\"`;\n }\n}\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 { 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", "/*\n * TODO: I couldn't found sui in caip\n * @see https://namespaces.chainagnostic.org/\n */\n\n// if the value neeeds to be change make sure you will update mapCaipNamespaceToLegacyNetworkName as well\nexport const CAIP_NAMESPACE = 'sui';\nexport const CAIP_SUI_CHAIN_ID = 'sui';\n", "import type {\n StandardConnectFeature,\n StandardEventsFeature,\n SuiFeatures,\n WalletWithFeatures,\n} from '@mysten/wallet-standard';\n\nimport { getWallets, SUI_MAINNET_CHAIN } from '@mysten/wallet-standard';\nimport { AccountId } from 'caip';\n\nimport { CAIP_NAMESPACE, CAIP_SUI_CHAIN_ID } from './constants.js';\n\n// TODO: StandardFetures doesn't work, so we should add each feature separately\ntype SuiWalletStandard = WalletWithFeatures<\n StandardConnectFeature & StandardEventsFeature & SuiFeatures\n>;\n\n/**\n * @param name each wallet has a name in WalletStandard. you should pass that value\n */\nexport function getInstance(name: string): SuiWalletStandard | undefined {\n const wallet = getWallets()\n .get()\n .find(\n (wallet) =>\n wallet.name === name && wallet.chains.includes(SUI_MAINNET_CHAIN)\n );\n\n return wallet as SuiWalletStandard;\n}\n\n/**\n * @param name each wallet has a name in WalletStandard. you should pass that value\n */\nexport function getInstanceOrThrow(name: string): SuiWalletStandard {\n const wallet = getInstance(name);\n\n if (!wallet) {\n throw new Error(\n \"We couldn't find the Sui instance on your wallet. It may be fixed by refreshing the page.\"\n );\n }\n\n return wallet;\n}\nexport function formatAccountsToCAIP(accounts: readonly { address: string }[]) {\n return accounts.map((account) => {\n return AccountId.format({\n address: account.address,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_SUI_CHAIN_ID,\n },\n });\n });\n}\n", "import type { ChangeAccountSubscriberParams, SuiActions } from './types.js';\nimport type { Subscriber, SubscriberCleanUp } from '../../mod.js';\n\nimport { builders } from './mod.js';\n\nexport function changeAccountSubscriber(\n params: ChangeAccountSubscriberParams\n): [Subscriber<SuiActions>, SubscriberCleanUp<SuiActions>] {\n return builders.changeAccountSubscriber({ name: params.name }).build();\n}\n"],
5
+ "mappings": "6IAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAQO,SAASC,EACdC,EAC6B,CAC7B,MAAO,UAAY,CACjB,IAAMC,EAASC,EAAmBF,EAAO,IAAI,EAE7C,GAAI,CAIF,MAAI,GAHkB,MAAMC,EAAO,SAAS,kBAAkB,EAAE,QAAQ,CACtE,OAAQ,EACV,CAAC,GACiB,SAAS,MAI7B,MAAQ,CACN,MAAO,EACT,CACF,CACF,CAlBgBE,EAAAJ,EAAA,mBCRhB,IAAAK,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,YAAAC,ICEA,OAAS,eAAeC,OAA0B,kBCElD,OAAS,WAAAC,OAAe,QCCxB,OAAS,WAAAC,OAAe,QCiBjB,IAAMC,EAAN,KAA6D,CAtBpE,MAsBoE,CAAAC,EAAA,sBACzD,KACTC,GAAqB,IAAI,IACzBC,GAAoB,IAAI,IACxBC,GAAuB,IAAI,IAC3BC,GAAwB,IAA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AAU,OAAO,CACtB,QAASD,EAAQ,QACjB,QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACF,CACH,CAVgBP,EAAAE,EAAA,wBZpBT,IAAMM,EAAUC,EAACC,GACtB,IAAIC,EAAqC,SAAS,EAC/C,OAAO,gBAAkB,CAgBxB,OAZe,MAHAC,EAAmBF,EAAO,IAAI,EACrB,SAEM,kBAAkB,EAAE,QAAQ,GAElC,SAAS,IAAKG,GAC7BC,EAAK,UAAU,OAAO,CAC3B,QAASD,EAAQ,QACjB,QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACF,CAGH,CAAC,EACA,IAAIC,CAAqC,EACzC,OAAOC,CAAc,EACrB,MAAMC,CAAsB,EAtBV,WAwBVC,EAAkBX,EAAA,IAC7B,IAAIE,EAA6C,iBAAiB,EADrC,mBAIlBU,EAA0BZ,EACrCC,GAEA,IAAIY,EAGF,EACC,YAAY,IAAMV,EAAmBF,EAAO,IAAI,CAAC,EAKjD,gBAAgB,CAACa,EAAOC,IAAY,CAC9BD,EAAM,QAAQ,UAAU,SAC3BC,EAAQ,OAAO,YAAY,EAC3BD,EAAM,eAAe,EAEzB,CAAC,EACA,OAAO,MAAOE,EAAGF,IAAUG,EAAqBH,EAAM,QAAQ,CAAC,EAC/D,iBAAiB,CAACI,EAAUC,IAC3BD,EAAS,SAAS,iBAAiB,EAAE,GAAG,SAAUC,CAAQ,CAC5D,EACC,oBAAoB,CAACH,EAAGI,IAAO,CAAC,CAAC,EAtBC,2BarDvC,IAAAC,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAKO,SAASC,EACdC,EACyD,CACzD,OAAOC,EAAS,wBAAwB,CAAE,KAAMD,EAAO,IAAK,CAAC,EAAE,MAAM,CACvE,CAJgBE,EAAAH,EAAA",
6
+ "names": ["actions_exports", "__export", "canEagerConnect", "canEagerConnect", "params", "wallet", "getInstanceOrThrow", "__name", "builders_exports", "__export", "canEagerConnect", "changeAccountSubscriber", "connect", "createZustandStore", "produce", "produce", "ActionBuilder", "__name", "#and", "#or", "#after", "#before", "#action", "name", "action", "CAIP", "ChangeAccountSubscriberBuilder", "__name", "#getInstance", "#format", "#onSwitchAccount", "#addEventListener", "#removeEventListener", "operator", "#getErrorMessage", "getInstance", "format", "addEventListener", "removeEventListener", "onSwitchAccount", "subscriber", "unsubscribe", "context", "setState", "instance", "event", "shouldProceedWithDefault", "_", "err", "operatorName", "intoConnectionFinished", "context", "setState", "__name", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForSingleNetwork", "context", "accounts", "isValidCaipAddress", "setState", "__name", "intoConnecting", "context", "setState", "__name", "CAIP_NAMESPACE", "CAIP_SUI_CHAIN_ID", "getWallets", "SUI_MAINNET_CHAIN", "AccountId", "getInstance", "name", "getWallets", "wallet", "SUI_MAINNET_CHAIN", "__name", "getInstanceOrThrow", "formatAccountsToCAIP", "accounts", "account", "AccountId", "CAIP_NAMESPACE", "CAIP_SUI_CHAIN_ID", "connect", "__name", "params", "ActionBuilder", "getInstanceOrThrow", "account", "CAIP", "CAIP_NAMESPACE", "CAIP_SUI_CHAIN_ID", "connectAndUpdateStateForSingleNetwork", "intoConnecting", "intoConnectionFinished", "canEagerConnect", "changeAccountSubscriber", "ChangeAccountSubscriberBuilder", "event", "context", "_", "formatAccountsToCAIP", "instance", "callback", "__", "hooks_exports", "__export", "changeAccountSubscriber", "changeAccountSubscriber", "params", "builders_exports", "__name"]
7
7
  }
@@ -3,6 +3,7 @@ export * as after from './after.js';
3
3
  export * as and from './and.js';
4
4
  export * as before from './before.js';
5
5
  export * as builders from './builders.js';
6
+ export * as utils from './utils.js';
6
7
  export type { ProviderAPI, UtxoActions } from './types.js';
7
8
  export { CAIP_NAMESPACE, CAIP_BITCOIN_CHAIN_ID } from './constants.js';
8
9
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/utxo/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,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/utxo/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;AAC1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty;var e=(r,t)=>v(r,"name",{value:t,configurable:!0});var s=(r,t)=>{for(var n in t)v(r,n,{get:t[n],enumerable:!0})};var x={};s(x,{recommended:()=>N});function l(r){let[,t]=r.state();t("network",null),t("accounts",null),t("connected",!1),t("connecting",!1)}e(l,"disconnect");var y=[["disconnect",l]];var N=[...y];var g={};s(g,{recommended:()=>T});function a(r){let[,t]=r.state();t("connecting",!1)}e(a,"intoConnectionFinished");var p=[["connect",a]];var T=[...p];var A={};s(A,{recommended:()=>j});import{createStore as We}from"zustand/vanilla";import{produce as Ce}from"immer";import{produce as ke}from"immer";var o=class{static{e(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#r=new Map;#o=new Map;#n;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.#r.has(this.name)||this.#r.set(this.name,[]),this.#r.get(this.name)?.push(t),this}action(t){return this.#n=t,this}build(){if(!this.#n)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#n,before:this.#o,after:this.#r,and:this.#e,or:this.#t}}};import*as yt from"caip";import{AccountId as _}from"caip";function P(r){try{return _.parse(r),!0}catch{return!1}}e(P,"isValidCaipAddress");function i(r,t){if(!t.every(P))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t}`);let[,n]=r.state();return n("accounts",t),n("connected",!0),t}e(i,"connectAndUpdateStateForSingleNetwork");function d(r){let[,t]=r.state();t("connecting",!0)}e(d,"intoConnecting");var h=[["connect",d]];var j=[["connect",i]];var C={};s(C,{recommended:()=>D});var D=[...h];var E={};s(E,{connect:()=>V});var V=e(()=>new o("connect").and(i).before(d).after(a),"connect");var M="bip122",W="000000000019d6689c085ae165831e93";export{W as CAIP_BITCOIN_CHAIN_ID,M as CAIP_NAMESPACE,x as actions,g as after,A as and,C as before,E as builders};
1
+ var y=Object.defineProperty;var e=(o,t)=>y(o,"name",{value:t,configurable:!0});var n=(o,t)=>{for(var s in t)y(o,s,{get:t[s],enumerable:!0})};var g={};n(g,{recommended:()=>k});function x(o){let[,t]=o.state();t("network",null),t("accounts",null),t("connected",!1),t("connecting",!1)}e(x,"disconnect");var S=[["disconnect",x]];var k=[...S];var A={};n(A,{recommended:()=>R});function a(o){let[,t]=o.state();t("connecting",!1)}e(a,"intoConnectionFinished");var d=[["connect",a]];var R=[...d];var E={};n(E,{recommended:()=>M});import{createStore as Ue}from"zustand/vanilla";import{produce as Ne}from"immer";import{produce as _e}from"immer";var r=class{static{e(this,"ActionBuilder")}name;#e=new Map;#t=new Map;#o=new Map;#r=new Map;#n;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.#r.has(this.name)||this.#r.set(this.name,[]),this.#r.get(this.name)?.push(t),this}after(t){return this.#o.has(this.name)||this.#o.set(this.name,[]),this.#o.get(this.name)?.push(t),this}action(t){return this.#n=t,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 gt from"caip";import{AccountId as V}from"caip";function C(o){try{return V.parse(o),!0}catch{return!1}}e(C,"isValidCaipAddress");function i(o,t){if(!t.every(C))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t}`);let[,s]=o.state();return s("accounts",t),s("connected",!0),t}e(i,"connectAndUpdateStateForSingleNetwork");function p(o){let[,t]=o.state();t("connecting",!0)}e(p,"intoConnecting");var h=[["connect",p]];var M=[["connect",i]];var w={};n(w,{recommended:()=>W});var W=[...h];var N={};n(N,{connect:()=>B});var B=e(()=>new r("connect").and(i).before(p).after(a),"connect");var T={};n(T,{formatAccountsToCAIP:()=>U});import{AccountId as H}from"caip";var v="bip122",l="000000000019d6689c085ae165831e93";function U(o){return o.map(t=>H.format({address:t.toString(),chainId:{namespace:v,reference:l}}))}e(U,"formatAccountsToCAIP");export{l as CAIP_BITCOIN_CHAIN_ID,v as CAIP_NAMESPACE,g as actions,A as after,E as and,w as before,N as builders,T as utils};
2
2
  //# sourceMappingURL=mod.js.map