@rango-dev/provider-binance 0.0.2-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.
package/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,6 @@
1
+ import { type ProviderMetadata } from '@rango-dev/wallets-core';
2
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
3
+ export declare const WALLET_ID = "binance";
4
+ export declare const EVM_SUPPORTED_CHAINS: LegacyNetworks[];
5
+ export declare const metadata: ProviderMetadata;
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAMhE,eAAO,MAAM,SAAS,YAAY,CAAC;AACnC,eAAO,MAAM,oBAAoB,kBAiBhC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,gBAmCtB,CAAC"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const versions: () => import("@rango-dev/wallets-core/utils").VersionedProviders;
2
+ export { versions };
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,QAAQ,kEAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/mod.js ADDED
@@ -0,0 +1,2 @@
1
+ var b=Object.defineProperty;var n=(e,t)=>b(e,"name",{value:t,configurable:!0});import{defineVersions as _}from"@rango-dev/wallets-core/utils";import{ProviderBuilder as R}from"@rango-dev/wallets-core";import"@rango-dev/wallets-core";import{LegacyNetworks as o}from"@rango-dev/wallets-core/legacy";import"rango-types";import{LegacyNetworks as v}from"@rango-dev/wallets-core/legacy";import{dynamicImportWithRefinedError as A,getNetworkInstance as I}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as y,TransactionType as S}from"rango-types";async function m(e){let t=I(e,v.ETHEREUM),r=new y,{DefaultEvmSigner:E}=await A(async()=>await import("@rango-dev/signer-evm"));return r.registerSigner(S.EVM,new E(t)),r}n(m,"getSigners");import{LegacyNetworks as l}from"@rango-dev/wallets-core/legacy";import"@rango-dev/wallets-core/namespaces/evm";function i(){let{binancew3w:e}=window;if(!e)return null;let t=new Map;return e.ethereum&&t.set(l.ETHEREUM,e.ethereum),t.size===0?null:t}n(i,"binance");function p(){let e=i();if(!e)throw new Error("Binance Wallet is not injected. Please check your wallet.");return e}n(p,"getInstanceOrThrow");function c(){let t=i()?.get(l.ETHEREUM);if(!t)throw new Error("Binance not injected or EVM not enabled. Please check your wallet.");return t}n(c,"evmBinance");async function u(e){let[t]=await e.request({method:"eth_requestAccounts"}),r=await e.request({method:"eth_chainId"});return{accounts:[t],chainId:r}}n(u,"getEvmAccounts");var a="binance",P=[o.OPTIMISM,o.ETHEREUM,o.LINEA,o.METIS,o.BLAST,o.CELO,o.FANTOM,o.MONAD,o.SONIC,o.BERACHAIN,o.BASE,o.ZETA_CHAIN,o.ARBITRUM,o.BSC,o.SCROLL,o.AVAX_CCHAIN],f={name:"Binance Wallet",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/binance/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/binance-wallet/cadiboklkpojfamcoggejbbdjcoiljjk",brave:"https://chromewebstore.google.com/detail/binance-wallet/cadiboklkpojfamcoggejbbdjcoiljjk",homepage:"https://www.binance.com/binancewallet"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"EVM",value:"EVM",id:"ETH",getSupportedChains:e=>e.filter(t=>P.includes(t.name))}]}},{name:"signers",value:{getSigners:async()=>m(p())}}]};import{NamespaceBuilder as T}from"@rango-dev/wallets-core";import{builders as M,standardizeAndThrowError as k}from"@rango-dev/wallets-core/namespaces/common";import{actions as d,builders as s,utils as N}from"@rango-dev/wallets-core/namespaces/evm";var[B,g]=s.changeAccountSubscriber(c).format(async(e,t)=>{let r=await e.request({method:"eth_chainId"});return N.formatAccountsToCAIP([t[0]],r)}).build(),C=s.connect().action(d.connect(c,{getAccounts:u})).before(B).or(g).or(k).build(),L=M.disconnect().after(g).build(),j=s.canSwitchNetwork().action(d.canSwitchNetwork()).build(),x=s.getChainId().action(d.getChainId(c)).build(),w=new T("EVM",a).action(C).action(L).action(j).action(x).build();var h=n(()=>new R(a).init(function(e){let[,t]=e.state();i()&&(t("installed",!0),console.debug("[binance-wallet] instance detected.",e))}).config("metadata",f).add("evm",w).build(),"buildProvider");var ue=n(()=>_().version("1.0.0",h()).build(),"versions");export{ue as versions};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/mod.ts", "../src/provider.ts", "../src/constants.ts", "../src/signer.ts", "../src/utils.ts", "../src/namespaces/evm.ts"],
4
+ "sourcesContent": ["import { defineVersions } from '@rango-dev/wallets-core/utils';\n\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\n", "import { ProviderBuilder } from '@rango-dev/wallets-core';\n\nimport { metadata, WALLET_ID } from './constants.js';\nimport { evm } from './namespaces/evm.js';\nimport { binance as binanceInstance } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n if (binanceInstance()) {\n setState('installed', true);\n console.debug('[binance-wallet] instance detected.', context);\n }\n })\n .config('metadata', metadata)\n .add('evm', evm)\n .build();\n\nexport { buildProvider };\n", "import { type ProviderMetadata } from '@rango-dev/wallets-core';\nimport { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\nimport { type BlockchainMeta } from 'rango-types';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const WALLET_ID = 'binance';\nexport const EVM_SUPPORTED_CHAINS = [\n LegacyNetworks.OPTIMISM,\n LegacyNetworks.ETHEREUM,\n LegacyNetworks.LINEA,\n LegacyNetworks.METIS,\n LegacyNetworks.BLAST,\n LegacyNetworks.CELO,\n LegacyNetworks.FANTOM,\n LegacyNetworks.MONAD,\n LegacyNetworks.SONIC,\n LegacyNetworks.BERACHAIN,\n LegacyNetworks.BASE,\n LegacyNetworks.ZETA_CHAIN,\n LegacyNetworks.ARBITRUM,\n LegacyNetworks.BSC,\n LegacyNetworks.SCROLL,\n LegacyNetworks.AVAX_CCHAIN,\n];\n\nexport const metadata: ProviderMetadata = {\n name: 'Binance Wallet',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/binance/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/binance-wallet/cadiboklkpojfamcoggejbbdjcoiljjk',\n brave:\n 'https://chromewebstore.google.com/detail/binance-wallet/cadiboklkpojfamcoggejbbdjcoiljjk',\n homepage: 'https://www.binance.com/binancewallet',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'EVM',\n value: 'EVM',\n id: 'ETH',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter((blockchainMeta) =>\n EVM_SUPPORTED_CHAINS.includes(\n blockchainMeta.name as LegacyNetworks\n )\n ),\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners(getInstanceOrThrow()) },\n },\n ],\n};\n", "import type { Provider } from './types.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';\nimport {\n dynamicImportWithRefinedError,\n getNetworkInstance,\n} from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const evmProvider = getNetworkInstance(provider, Networks.ETHEREUM);\n const signers = new DefaultSignerFactory();\n const { DefaultEvmSigner } = await dynamicImportWithRefinedError(\n async () => await import('@rango-dev/signer-evm')\n );\n signers.registerSigner(TxType.EVM, new DefaultEvmSigner(evmProvider));\n return signers;\n}\n", "import type { Provider } from './types.js';\n\nimport { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\nimport { type ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';\n\nexport function binance(): Provider | null {\n const { binancew3w } = window;\n\n if (!binancew3w) {\n return null;\n }\n\n const instances = new Map();\n if (binancew3w.ethereum) {\n instances.set(LegacyNetworks.ETHEREUM, binancew3w.ethereum);\n }\n\n if (instances.size === 0) {\n return null;\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = binance();\n\n if (!instances) {\n throw new Error(\n 'Binance Wallet is not injected. Please check your wallet.'\n );\n }\n\n return instances;\n}\n\nexport function evmBinance(): EvmProviderApi {\n const instances = binance();\n\n const evmInstance = instances?.get(LegacyNetworks.ETHEREUM);\n\n if (!evmInstance) {\n throw new Error(\n 'Binance not injected or EVM not enabled. Please check your wallet.'\n );\n }\n\n return evmInstance;\n}\n/**\n * * WORKAROUND 1: Binance Wallet Race Condition\n * Simultaneous calls to 'eth_chainId' and 'eth_requestAccounts' fail to return\n * a chainId. These must be executed sequentially to ensure both values resolve.\n */\nexport async function getEvmAccounts(provider: EvmProviderApi) {\n /**\n * * WORKAROUND 2: Account Indexing Consistency\n * Binance Wallet's `connect` returns a list where the currently selected account\n * is always the first item. We're directly taking this first item as the active account.\n *\n */\n const [account] = await provider.request({\n method: 'eth_requestAccounts',\n });\n const chainId = await provider.request({ method: 'eth_chainId' });\n\n return {\n accounts: [account],\n chainId,\n };\n}\n", "import type { EvmActions } from '@rango-dev/wallets-core/namespaces/evm';\n\nimport { NamespaceBuilder } from '@rango-dev/wallets-core';\nimport {\n builders as commonBuilders,\n standardizeAndThrowError,\n} from '@rango-dev/wallets-core/namespaces/common';\nimport {\n actions,\n builders,\n utils,\n} from '@rango-dev/wallets-core/namespaces/evm';\n\nimport { WALLET_ID } from '../constants.js';\nimport { evmBinance, getEvmAccounts } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = builders\n .changeAccountSubscriber(evmBinance)\n /*\n * Binance returns an array of connected accounts with the active one first.\n * Since we only need the active account, we take the first element as a workaround.\n */\n .format(async (instance, accounts) => {\n const chainId = await instance.request({ method: 'eth_chainId' });\n return utils.formatAccountsToCAIP([accounts[0]], chainId);\n })\n .build();\n\nconst connect = builders\n .connect()\n .action(\n actions.connect(evmBinance, {\n getAccounts: getEvmAccounts,\n })\n )\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<EvmActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canSwitchNetwork = builders\n .canSwitchNetwork()\n .action(actions.canSwitchNetwork())\n .build();\n\nconst getChainId = builders\n .getChainId()\n .action(actions.getChainId(evmBinance))\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canSwitchNetwork)\n .action(getChainId)\n .build();\n\nexport { evm };\n"],
5
+ "mappings": "+EAAA,OAAS,kBAAAA,MAAsB,gCCA/B,OAAS,mBAAAC,MAAuB,0BCAhC,MAAsC,0BACtC,OAAS,kBAAAC,MAAsB,iCAC/B,MAAoC,cCCpC,OAAS,kBAAkBC,MAAgB,iCAC3C,OACE,iCAAAC,EACA,sBAAAC,MACK,4BACP,OAAS,wBAAAC,EAAsB,mBAAmBC,MAAc,cAEhE,eAAOC,EACLC,EACwB,CACxB,IAAMC,EAAcC,EAAmBF,EAAUG,EAAS,QAAQ,EAC5DC,EAAU,IAAIC,EACd,CAAE,iBAAAC,CAAiB,EAAI,MAAMC,EACjC,SAAY,KAAM,QAAO,uBAAuB,CAClD,EACA,OAAAH,EAAQ,eAAeI,EAAO,IAAK,IAAIF,EAA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AC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAC/BE,EAAgB,IAClBD,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,sCAAuCD,CAAO,EAEhE,CAAC,EACA,OAAO,WAAYG,CAAQ,EAC3B,IAAI,MAAOC,CAAG,EACd,MAAM,EAXW,iBDFtB,IAAMC,GAAWC,EAAA,IACfC,EAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
+ "names": ["defineVersions", "ProviderBuilder", "LegacyNetworks", "Networks", "dynamicImportWithRefinedError", "getNetworkInstance", "DefaultSignerFactory", "TxType", "getSigners", "provider", "evmProvider", "getNetworkInstance", "Networks", "signers", "DefaultSignerFactory", "DefaultEvmSigner", "dynamicImportWithRefinedError", "TxType", "__name", "LegacyNetworks", "binance", "binancew3w", "instances", "LegacyNetworks", "__name", "getInstanceOrThrow", "evmBinance", "evmInstance", "getEvmAccounts", "provider", "account", "chainId", "WALLET_ID", "EVM_SUPPORTED_CHAINS", "LegacyNetworks", "metadata", "allBlockchains", "blockchainMeta", "getSigners", "getInstanceOrThrow", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "actions", "builders", "utils", "changeAccountSubscriber", "changeAccountCleanup", "builders", "evmBinance", "instance", "accounts", "chainId", "utils", "connect", "actions", "getEvmAccounts", "standardizeAndThrowError", "disconnect", "commonBuilders", "canSwitchNetwork", "getChainId", "evm", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "binance", "metadata", "evm", "versions", "__name", "defineVersions", "buildProvider"]
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { EvmActions } from '@rango-dev/wallets-core/namespaces/evm';
2
+ declare const evm: import("@rango-dev/wallets-core").ProxiedNamespace<EvmActions>;
3
+ export { evm };
4
+ //# sourceMappingURL=evm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/namespaces/evm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAuDzE,QAAA,MAAM,GAAG,gEAKC,CAAC;AAEX,OAAO,EAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/signer.ts":{"bytes":780,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/signer-evm","kind":"dynamic-import","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/utils.ts":{"bytes":1789,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/evm","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/constants.ts":{"bytes":1836,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"}],"format":"esm"},"src/namespaces/evm.ts":{"bytes":1656,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/evm","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../constants.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.js"}],"format":"esm"},"src/provider.ts":{"bytes":601,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/evm.ts","kind":"import-statement","original":"./namespaces/evm.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":220,"imports":[{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/mod.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":11368},"dist/mod.js":{"imports":[{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/signer-evm","kind":"dynamic-import","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/evm","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/evm","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/mod.ts":{"bytesInOutput":121},"src/provider.ts":{"bytesInOutput":255},"src/constants.ts":{"bytesInOutput":872},"src/signer.ts":{"bytesInOutput":421},"src/utils.ts":{"bytesInOutput":732},"src/namespaces/evm.ts":{"bytesInOutput":691}},"bytes":3227}}}
@@ -0,0 +1,3 @@
1
+ declare const buildProvider: () => import("@rango-dev/wallets-core").Provider;
2
+ export { buildProvider };
3
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,aAAa,kDAWP,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Provider } from './types.js';
2
+ import type { SignerFactory } from 'rango-types';
3
+ export default function getSigners(provider: Provider): Promise<SignerFactory>;
4
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AASjD,wBAA8B,UAAU,CACtC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,aAAa,CAAC,CAQxB"}
@@ -0,0 +1,7 @@
1
+ import type { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
2
+ import type { ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
3
+ export type ProviderObject = {
4
+ [LegacyNetworks.ETHEREUM]: EvmProviderApi;
5
+ };
6
+ export type Provider = Map<keyof ProviderObject, ProviderObject[keyof ProviderObject]>;
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE5F,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3C,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,GAAG,CACxB,MAAM,cAAc,EACpB,cAAc,CAAC,MAAM,cAAc,CAAC,CACrC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Provider } from './types.js';
2
+ import { type ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
3
+ export declare function binance(): Provider | null;
4
+ export declare function getInstanceOrThrow(): Provider;
5
+ export declare function evmBinance(): EvmProviderApi;
6
+ /**
7
+ * * WORKAROUND 1: Binance Wallet Race Condition
8
+ * Simultaneous calls to 'eth_chainId' and 'eth_requestAccounts' fail to return
9
+ * a chainId. These must be executed sequentially to ensure both values resolve.
10
+ */
11
+ export declare function getEvmAccounts(provider: EvmProviderApi): Promise<{
12
+ accounts: `0x${string}`[];
13
+ chainId: `0x${string}`;
14
+ }>;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,KAAK,WAAW,IAAI,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE5F,wBAAgB,OAAO,IAAI,QAAQ,GAAG,IAAI,CAiBzC;AAED,wBAAgB,kBAAkB,IAAI,QAAQ,CAU7C;AAED,wBAAgB,UAAU,IAAI,cAAc,CAY3C;AACD;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,cAAc;;;GAgB5D"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@rango-dev/provider-binance",
3
+ "version": "0.0.2-next.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "source": "./src/mod.ts",
7
+ "main": "./dist/mod.js",
8
+ "exports": {
9
+ ".": "./dist/mod.js"
10
+ },
11
+ "typings": "dist/mod.d.ts",
12
+ "files": [
13
+ "dist",
14
+ "src"
15
+ ],
16
+ "scripts": {
17
+ "build": "node ../../scripts/build/command.mjs --path wallets/provider-binance --inputs src/mod.ts",
18
+ "ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
19
+ "clean": "rimraf dist",
20
+ "format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
21
+ "lint": "eslint \"**/*.{ts,tsx}\""
22
+ },
23
+ "dependencies": {
24
+ "@rango-dev/signer-evm": "^0.40.0",
25
+ "@rango-dev/wallets-core": "^0.56.1-next.0",
26
+ "@rango-dev/wallets-shared": "^0.57.1-next.0",
27
+ "rango-types": "^0.1.89"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }
package/readme.md ADDED
@@ -0,0 +1,40 @@
1
+ # Binance Wallet
2
+ Binance Wallet integration for hub.
3
+ [Homepage](https://www.binance.com/en/binancewallet) | [Docs](https://developers.binance.com/docs/binance-w3w/introduction)
4
+
5
+ More about implementation status can be found [here](../readme.md).
6
+
7
+ ## Implementation notes/limitations
8
+
9
+ ### Group
10
+
11
+ #### EVM
12
+ Binance Wallet supports following EVM chains:
13
+
14
+ - `ETHEREUM`
15
+ - `OPTIMISM`
16
+ - `LINEA`
17
+ - `METIS`
18
+ - `BLAST`
19
+ - `CELO`
20
+ - `FANTOM`
21
+ - `MONAD`
22
+ - `SONIC`
23
+ - `BERACHAIN`
24
+ - `BASE`
25
+ - `ZETA_CHAIN`
26
+ - `ARBITRUM`
27
+ - `BSC`
28
+ - `SCROLL`
29
+ - `AVAX_CCHAIN`
30
+
31
+ ### Feature
32
+
33
+ #### ❌ Auto Connect
34
+ Binance Wallet does **not provide a functional eager-connect (silent connect) mechanism**.
35
+
36
+ All other supported features—connect, switch account, signing, and network handling—work without known issues.
37
+
38
+ ---
39
+
40
+ More wallet information can be found in [readme.md](../readme.md).
@@ -0,0 +1,63 @@
1
+ import { type ProviderMetadata } from '@rango-dev/wallets-core';
2
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
3
+ import { type BlockchainMeta } from 'rango-types';
4
+
5
+ import getSigners from './signer.js';
6
+ import { getInstanceOrThrow } from './utils.js';
7
+
8
+ export const WALLET_ID = 'binance';
9
+ export const EVM_SUPPORTED_CHAINS = [
10
+ LegacyNetworks.OPTIMISM,
11
+ LegacyNetworks.ETHEREUM,
12
+ LegacyNetworks.LINEA,
13
+ LegacyNetworks.METIS,
14
+ LegacyNetworks.BLAST,
15
+ LegacyNetworks.CELO,
16
+ LegacyNetworks.FANTOM,
17
+ LegacyNetworks.MONAD,
18
+ LegacyNetworks.SONIC,
19
+ LegacyNetworks.BERACHAIN,
20
+ LegacyNetworks.BASE,
21
+ LegacyNetworks.ZETA_CHAIN,
22
+ LegacyNetworks.ARBITRUM,
23
+ LegacyNetworks.BSC,
24
+ LegacyNetworks.SCROLL,
25
+ LegacyNetworks.AVAX_CCHAIN,
26
+ ];
27
+
28
+ export const metadata: ProviderMetadata = {
29
+ name: 'Binance Wallet',
30
+ icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/binance/icon.svg',
31
+ extensions: {
32
+ chrome:
33
+ 'https://chromewebstore.google.com/detail/binance-wallet/cadiboklkpojfamcoggejbbdjcoiljjk',
34
+ brave:
35
+ 'https://chromewebstore.google.com/detail/binance-wallet/cadiboklkpojfamcoggejbbdjcoiljjk',
36
+ homepage: 'https://www.binance.com/binancewallet',
37
+ },
38
+ properties: [
39
+ {
40
+ name: 'namespaces',
41
+ value: {
42
+ selection: 'multiple',
43
+ data: [
44
+ {
45
+ label: 'EVM',
46
+ value: 'EVM',
47
+ id: 'ETH',
48
+ getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
49
+ allBlockchains.filter((blockchainMeta) =>
50
+ EVM_SUPPORTED_CHAINS.includes(
51
+ blockchainMeta.name as LegacyNetworks
52
+ )
53
+ ),
54
+ },
55
+ ],
56
+ },
57
+ },
58
+ {
59
+ name: 'signers',
60
+ value: { getSigners: async () => getSigners(getInstanceOrThrow()) },
61
+ },
62
+ ],
63
+ };
package/src/mod.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { defineVersions } from '@rango-dev/wallets-core/utils';
2
+
3
+ import { buildProvider } from './provider.js';
4
+
5
+ const versions = () =>
6
+ defineVersions().version('1.0.0', buildProvider()).build();
7
+
8
+ export { versions };
@@ -0,0 +1,63 @@
1
+ import type { EvmActions } from '@rango-dev/wallets-core/namespaces/evm';
2
+
3
+ import { NamespaceBuilder } from '@rango-dev/wallets-core';
4
+ import {
5
+ builders as commonBuilders,
6
+ standardizeAndThrowError,
7
+ } from '@rango-dev/wallets-core/namespaces/common';
8
+ import {
9
+ actions,
10
+ builders,
11
+ utils,
12
+ } from '@rango-dev/wallets-core/namespaces/evm';
13
+
14
+ import { WALLET_ID } from '../constants.js';
15
+ import { evmBinance, getEvmAccounts } from '../utils.js';
16
+
17
+ const [changeAccountSubscriber, changeAccountCleanup] = builders
18
+ .changeAccountSubscriber(evmBinance)
19
+ /*
20
+ * Binance returns an array of connected accounts with the active one first.
21
+ * Since we only need the active account, we take the first element as a workaround.
22
+ */
23
+ .format(async (instance, accounts) => {
24
+ const chainId = await instance.request({ method: 'eth_chainId' });
25
+ return utils.formatAccountsToCAIP([accounts[0]], chainId);
26
+ })
27
+ .build();
28
+
29
+ const connect = builders
30
+ .connect()
31
+ .action(
32
+ actions.connect(evmBinance, {
33
+ getAccounts: getEvmAccounts,
34
+ })
35
+ )
36
+ .before(changeAccountSubscriber)
37
+ .or(changeAccountCleanup)
38
+ .or(standardizeAndThrowError)
39
+ .build();
40
+
41
+ const disconnect = commonBuilders
42
+ .disconnect<EvmActions>()
43
+ .after(changeAccountCleanup)
44
+ .build();
45
+
46
+ const canSwitchNetwork = builders
47
+ .canSwitchNetwork()
48
+ .action(actions.canSwitchNetwork())
49
+ .build();
50
+
51
+ const getChainId = builders
52
+ .getChainId()
53
+ .action(actions.getChainId(evmBinance))
54
+ .build();
55
+
56
+ const evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)
57
+ .action(connect)
58
+ .action(disconnect)
59
+ .action(canSwitchNetwork)
60
+ .action(getChainId)
61
+ .build();
62
+
63
+ export { evm };
@@ -0,0 +1,20 @@
1
+ import { ProviderBuilder } from '@rango-dev/wallets-core';
2
+
3
+ import { metadata, WALLET_ID } from './constants.js';
4
+ import { evm } from './namespaces/evm.js';
5
+ import { binance as binanceInstance } from './utils.js';
6
+
7
+ const buildProvider = () =>
8
+ new ProviderBuilder(WALLET_ID)
9
+ .init(function (context) {
10
+ const [, setState] = context.state();
11
+ if (binanceInstance()) {
12
+ setState('installed', true);
13
+ console.debug('[binance-wallet] instance detected.', context);
14
+ }
15
+ })
16
+ .config('metadata', metadata)
17
+ .add('evm', evm)
18
+ .build();
19
+
20
+ export { buildProvider };
package/src/signer.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { Provider } from './types.js';
2
+ import type { SignerFactory } from 'rango-types';
3
+
4
+ import { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';
5
+ import {
6
+ dynamicImportWithRefinedError,
7
+ getNetworkInstance,
8
+ } from '@rango-dev/wallets-shared';
9
+ import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
10
+
11
+ export default async function getSigners(
12
+ provider: Provider
13
+ ): Promise<SignerFactory> {
14
+ const evmProvider = getNetworkInstance(provider, Networks.ETHEREUM);
15
+ const signers = new DefaultSignerFactory();
16
+ const { DefaultEvmSigner } = await dynamicImportWithRefinedError(
17
+ async () => await import('@rango-dev/signer-evm')
18
+ );
19
+ signers.registerSigner(TxType.EVM, new DefaultEvmSigner(evmProvider));
20
+ return signers;
21
+ }
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
2
+ import type { ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
3
+
4
+ export type ProviderObject = {
5
+ [LegacyNetworks.ETHEREUM]: EvmProviderApi;
6
+ };
7
+ export type Provider = Map<
8
+ keyof ProviderObject,
9
+ ProviderObject[keyof ProviderObject]
10
+ >;
package/src/utils.ts ADDED
@@ -0,0 +1,71 @@
1
+ import type { Provider } from './types.js';
2
+
3
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
4
+ import { type ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm';
5
+
6
+ export function binance(): Provider | null {
7
+ const { binancew3w } = window;
8
+
9
+ if (!binancew3w) {
10
+ return null;
11
+ }
12
+
13
+ const instances = new Map();
14
+ if (binancew3w.ethereum) {
15
+ instances.set(LegacyNetworks.ETHEREUM, binancew3w.ethereum);
16
+ }
17
+
18
+ if (instances.size === 0) {
19
+ return null;
20
+ }
21
+
22
+ return instances;
23
+ }
24
+
25
+ export function getInstanceOrThrow(): Provider {
26
+ const instances = binance();
27
+
28
+ if (!instances) {
29
+ throw new Error(
30
+ 'Binance Wallet is not injected. Please check your wallet.'
31
+ );
32
+ }
33
+
34
+ return instances;
35
+ }
36
+
37
+ export function evmBinance(): EvmProviderApi {
38
+ const instances = binance();
39
+
40
+ const evmInstance = instances?.get(LegacyNetworks.ETHEREUM);
41
+
42
+ if (!evmInstance) {
43
+ throw new Error(
44
+ 'Binance not injected or EVM not enabled. Please check your wallet.'
45
+ );
46
+ }
47
+
48
+ return evmInstance;
49
+ }
50
+ /**
51
+ * * WORKAROUND 1: Binance Wallet Race Condition
52
+ * Simultaneous calls to 'eth_chainId' and 'eth_requestAccounts' fail to return
53
+ * a chainId. These must be executed sequentially to ensure both values resolve.
54
+ */
55
+ export async function getEvmAccounts(provider: EvmProviderApi) {
56
+ /**
57
+ * * WORKAROUND 2: Account Indexing Consistency
58
+ * Binance Wallet's `connect` returns a list where the currently selected account
59
+ * is always the first item. We're directly taking this first item as the active account.
60
+ *
61
+ */
62
+ const [account] = await provider.request({
63
+ method: 'eth_requestAccounts',
64
+ });
65
+ const chainId = await provider.request({ method: 'eth_chainId' });
66
+
67
+ return {
68
+ accounts: [account],
69
+ chainId,
70
+ };
71
+ }