@rango-dev/provider-bitget 0.61.3-next.4 → 0.62.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.
- package/CHANGELOG.md +6 -0
- package/dist/actions/utxo.d.ts.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +3 -3
- package/dist/namespaces/tron.d.ts.map +1 -1
- package/package.json +16 -16
- package/readme.md +2 -0
- package/src/actions/utxo.ts +36 -8
- package/src/constants.ts +5 -0
- package/src/namespaces/tron.ts +8 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# [0.62.0](https://github.com/rango-exchange/rango-client/compare/provider-bitget@0.61.2...provider-bitget@0.62.0) (2026-10-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **approval:** migrate EVM and Tron approval to the prerequisites flow ([23f3bf4](https://github.com/rango-exchange/rango-client/commit/23f3bf4bb871c5b367214c3b82c5786dd9748adc))
|
|
1
7
|
## [0.61.2](https://github.com/rango-exchange/rango-client/compare/provider-bitget@0.61.1...provider-bitget@0.61.2) (2026-09-22)
|
|
2
8
|
|
|
3
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/actions/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EACV,eAAe,EACf,OAAO,EACP,mBAAmB,EACpB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/actions/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EACV,eAAe,EACf,OAAO,EACP,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAUtB,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,WAAW,GAC1B,mBAAmB,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAmCtD;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,WAAW,GAC1B,eAAe,CAAC,WAAW,CAAC,CAK9B;AAED,eAAO,MAAM,WAAW;;;CAA+B,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ProviderMetadata } from '@hub3js/core';
|
|
2
2
|
export declare const WALLET_ID = "bitget";
|
|
3
3
|
export declare const TronOKRequestCode = 200;
|
|
4
|
+
export declare const BITGET_UTXO_REJECTION_CODE = -32603;
|
|
5
|
+
export declare const BITGET_UTXO_REJECTION_MESSAGE = "User rejected the request";
|
|
4
6
|
export declare const metadata: ProviderMetadata;
|
|
5
7
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAarD,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAGrC,eAAO,MAAM,0BAA0B,SAAyB,CAAC;AACjE,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAEzE,eAAO,MAAM,QAAQ,EAAE,gBA0CtB,CAAC"}
|
package/dist/mod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Z=Object.defineProperty;var r=(o,t)=>Z(o,"name",{value:t,configurable:!0});import{ProviderBuilder as oo}from"@hub3js/core";import{CAIP_BITCOIN_CHAIN_ID as st,isChainSupported as at}from"@hub3js/bip122";import{EIP1474_INTERNAL_ERROR as ut}from"@hub3js/core";import{isEvmNamespace as mt}from"@hub3js/evm";import{isTronNamespace as dt}from"@hub3js/tron";import{EVM_NAMESPACE as rt,TRON_NAMESPACE as nt,UTXO_NAMESPACE as it}from"@hub3js/namespaces";import{DefaultSignerFactory as ct,TransactionType as w}from"rango-types";import{isBitcoinBlockchain as tt}from"@rango-dev/internal-blockchains";import*as I from"bitcoinjs-lib";import{SignerError as ot}from"rango-types";var et="https://go.getblock.io/f37bad28a991436483c0a3679a3acbee",E=class{static{r(this,"BitgetUTXOSigner")}provider;constructor(t){this.provider=t}async signMessage(){throw ot.UnimplementedError("signMessage")}async signAndSendTx(t){let{asset:e,psbt:i}=t;if(!i)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");if(!tt(e.blockchain))throw new Error(`Signing ${e.blockchain} transaction is not implemented by the signer.`);let n=Buffer.from(i.unsignedPsbtBase64,"base64").toString("hex"),A=i.inputsToSign.flatMap(({address:p,signingIndexes:Q})=>Q.map(Y=>({index:Y,address:p}))),f;try{f=await this.provider.signPsbt(n,{autoFinalized:!0,toSignInputs:A})}catch(p){throw new Error(p?.message||"Error during signing transaction")}let K=I.Psbt.fromHex(f).extractTransaction().toHex(),h=await fetch(et,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:"sendrawtransaction",params:[K]})});if(!h.ok){let p=await h.text();throw new Error(`Error broadcasting transaction: ${p}`)}let b=await h.json();if(!b.result)throw new Error(`Error broadcasting transaction. Error Code ${b.error.code}: ${b.error.message}`);return{hash:b.result}}};async function T(o){let t=o.get(rt),e=o.get(nt),i=o.get(it),n=new ct,{DefaultEvmSigner:A}=await import("@rango-dev/signer-evm"),{DefaultTronSigner:f}=await import("@rango-dev/signer-tron");return t&&n.registerSigner(w.EVM,new A(t)),e&&n.registerSigner(w.TRON,new f(e)),i&&n.registerSigner(w.TRANSFER,new E(i)),n}r(T,"getSigners");import{EVM_NAMESPACE as y,TRON_NAMESPACE as x,UTXO_NAMESPACE as S}from"@hub3js/namespaces";function u(){let o=new Map,{bitkeep:t}=window;return!t||(t.ethereum&&o.set(y,t.ethereum),t.tronLink&&o.set(x,t.tronLink),t.unisat&&o.set(S,t.unisat),o.size===0)?null:o}r(u,"bitget");function B(){let o=u();if(!o)throw new Error("Bitget is not injected. Please check your wallet.");return o}r(B,"getInstanceOrThrow");function c(){let t=u()?.get(y);if(!t)throw new Error("Bitget not injected or EVM not enabled. Please check your wallet.");return t}r(c,"evmBitget");function a(){let t=u()?.get(x);if(!t)throw new Error("Bitget not injected or Tron not enabled. Please check your wallet.");return t}r(a,"tronBitget");function l(){let t=u()?.get(S);if(!t)throw new Error("Bitget not injected or BTC not enabled. Please check your wallet.");return t}r(l,"utxoBitget");var s="bitget",_=200,N=ut,O="User rejected the request",j={name:"Bitget",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/bitget/icon.svg",extensions:{chrome:"https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak",brave:"https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak",homepage:"https://web3.bitget.com/en/wallet-download?type=1"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"EVM",value:"EVM",id:"ETH",isChainSupported:mt},{label:"Tron",value:"Tron",id:"TRON",isChainSupported:dt},{label:"BTC",value:"UTXO",id:"BTC",isChainSupported:at([st])}]}},{name:"signers",value:{getSigners:async()=>T(B())}}]};import{NamespaceBuilder as pt}from"@hub3js/core";import{actions as m,builders as d,hooks as lt}from"@hub3js/evm";import*as R from"@hub3js/std/builders";import{standardizeAndThrowError as gt}from"@hub3js/std/operators";var[ft,U]=lt.changeAccountSubscriber(c),bt=d.connect().action(m.connect(c)).before(ft).or(U).or(gt).build(),Et=R.disconnect().after(U).build(),At=d.canSwitchNetwork().action(m.canSwitchNetwork()).build(),ht=d.canEagerConnect().action(m.canEagerConnect(c)).build(),wt=d.getChainId().action(m.getChainId(c)).build(),Tt=d.getAllowance().action(m.getAllowance(c)).build(),Pt=d.getTransactionReceipt().action(m.getTransactionReceipt(c)).build(),k=new pt("EVM",s).action(bt).action(Et).action(wt).action(ht).action(At).action(Tt).action(Pt).build();import{getErrorMessage as xt,Hub3Error as St,NamespaceBuilder as Bt}from"@hub3js/core";import*as D from"@hub3js/std/builders";import{standardizeAndThrowError as _t}from"@hub3js/std/operators";import{utils as Nt}from"@hub3js/tron";import{actions as P,builders as g}from"@hub3js/tron";var vt=r(async()=>{let o=c();if(!a())throw new Error("Trying to eagerly connect to your wallet, but seems its tron instance is not available.");if(!o)throw new Error("Trying to eagerly connect to your EVM wallet, but seems its instance is not available.");try{return!!(await o.request({method:"eth_accounts"})).length}catch{return!1}},"canEagerConnectAction"),L={canEagerConnectAction:vt};import{ChangeAccountSubscriberBuilder as Ct}from"@hub3js/std/hooks";import{utils as It}from"@hub3js/tron";var yt=r(o=>new Ct().getInstance(o).onSwitchAccount((t,e)=>{if(!t.payload.data.isBitkeep||t.payload.data.message?.action!=="accountsChanged"){t.preventDefault();return}t.payload.data.message.data.address||(t.preventDefault(),e.action("disconnect"))}).format(async(t,e)=>It.formatAccountsToCAIP([e.data.message.data.address])).addEventListener((t,e)=>{window.addEventListener("message",e)}).removeEventListener((t,e)=>{window.removeEventListener("message",e)}),"changeAccountSubscriber"),M={changeAccountSubscriber:yt};var[Ot,H]=M.changeAccountSubscriber(a).build(),jt=g.connect().action(async()=>{let o=a(),t=await o.request({method:"tron_requestAccounts"});if(t?.code&&t.code!==_)throw new St("PROVIDER_UNEXPECTED",xt(t),{cause:t});return Nt.formatAccountsToCAIP([o.tronWeb.defaultAddress.base58])}).before(Ot).or(H).or(_t).build(),Rt=D.disconnect().after(H).build(),Ut=g.canEagerConnect().action(L.canEagerConnectAction).build(),kt=g.getAllowance().action(P.getAllowance(a)).build(),Lt=g.buildApproveTransaction().action(P.buildApproveTransaction(a)).build(),Mt=g.getTransactionInfo().action(P.getTransactionInfo(a)).build(),V=new Bt("Tron",s).action(jt).action(Rt).action(Ut).action(kt).action(Lt).action(Mt).build();import{builders as G}from"@hub3js/bip122";import{NamespaceBuilder as zt}from"@hub3js/core";import*as q from"@hub3js/std/builders";import{standardizeAndThrowError as $t}from"@hub3js/std/operators";import{CAIP_BITCOIN_CHAIN_ID as Dt,utils as Ht}from"@hub3js/bip122";import{getErrorMessage as Vt,Hub3Error as v}from"@hub3js/core";function Xt(o){return async()=>{try{let t=o();if(!t)throw new v("PROVIDER_UNEXPECTED","Do your wallet injected correctly and is utxo compatible?");let e=await t.requestAccounts();return Ht.formatAccountsToCAIP(e,Dt)}catch(t){throw t instanceof v?t:typeof t=="object"&&t!==null&&"code"in t&&t.code===N&&"message"in t&&t.message===O?new v("PROVIDER_USER_REJECTED_REQUEST",Vt(t),{cause:t}):t}}}r(Xt,"connect");function Ft(o){return async()=>!!(await o().getAccounts()).length}r(Ft,"canEagerConnect");var C={connect:Xt,canEagerConnect:Ft};import{builders as Wt,CAIP_BITCOIN_CHAIN_ID as X,utils as Gt}from"@hub3js/bip122";var qt=r(o=>Wt.changeAccountSubscriber(o,{network:X}).onSwitchAccount((t,e)=>{t.payload||(t.preventDefault(),e.action("disconnect"))}).format(async(t,e)=>Gt.formatAccountsToCAIP(e?[e]:[],X)).addEventListener((t,e)=>t.addListener("accountChanged",e)).removeEventListener((t,e)=>t.removeListener("accountChanged",e)),"changeAccountSubscriber"),F={changeAccountSubscriber:qt};function Jt(o){let t;return[(e,i)=>{let n=o();if(!n)throw new Error("Trying to subscribe to your BTC wallet, but seems its instance is not available.");if(t=r(()=>{e.action("disconnect")},"eventCallback"),n.on("disconnect",t),i instanceof Error)throw i},(e,i)=>{let n=o();return t&&n&&n.removeListener("disconnect",t),i}]}r(Jt,"disconnectSubscriber");var W={disconnectSubscriber:Jt};var[Kt,J]=F.changeAccountSubscriber(l).build(),[Qt,z]=W.disconnectSubscriber(l),Yt=G.connect().action(C.connect(l)).before(Kt).before(Qt).or(J).or(z).or($t).build(),Zt=q.disconnect().after(J).after(z).build(),to=G.canEagerConnect().action(C.canEagerConnect(l)).build(),$=new zt("UTXO",s).action(Yt).action(Zt).action(to).build();var eo=r(()=>new oo(s).init(function(o){let[,t]=o.state();u()&&(t("installed",!0),console.debug("[bitget] instance detected.",o))}).config("metadata",j).add("tron",V).add("evm",k).add("utxo",$).build(),"buildProvider");export{s as WALLET_ID,eo as buildProvider};
|
|
2
2
|
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/provider.ts", "../src/constants.ts", "../src/signer.ts", "../src/signers/utxo.ts", "../src/utils.ts", "../src/namespaces/evm.ts", "../src/namespaces/tron.ts", "../src/actions/tron.ts", "../src/builders/tron.ts", "../src/namespaces/utxo.ts", "../src/actions/utxo.ts", "../src/builders/utxo.ts", "../src/hooks/utxo.ts"],
|
|
4
|
-
"sourcesContent": ["import { ProviderBuilder } from '@hub3js/core';\n\nimport { metadata, WALLET_ID } from './constants.js';\nimport { evm } from './namespaces/evm.js';\nimport { tron } from './namespaces/tron.js';\nimport { utxo } from './namespaces/utxo.js';\nimport { bitget } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n\n if (bitget()) {\n setState('installed', true);\n console.debug('[bitget] instance detected.', context);\n }\n })\n .config('metadata', metadata)\n .add('tron', tron)\n .add('evm', evm)\n .add('utxo', utxo)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n isChainSupported as isBip122ChainSupported,\n} from '@hub3js/bip122';\nimport { isEvmNamespace } from '@hub3js/evm';\nimport { isTronNamespace } from '@hub3js/tron';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const WALLET_ID = 'bitget';\nexport const TronOKRequestCode = 200;\n\nexport const metadata: ProviderMetadata = {\n name: 'Bitget',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/bitget/icon.svg',\n extensions: {\n chrome:\n 'https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak',\n brave:\n 'https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak',\n homepage: 'https://web3.bitget.com/en/wallet-download?type=1',\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 isChainSupported: isEvmNamespace,\n },\n {\n label: 'Tron',\n value: 'Tron',\n id: 'TRON',\n isChainSupported: isTronNamespace,\n },\n {\n label: 'BTC',\n value: 'UTXO',\n id: 'BTC',\n isChainSupported: isBip122ChainSupported([CAIP_BITCOIN_CHAIN_ID]),\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 {\n EVM_NAMESPACE,\n TRON_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { BitgetUTXOSigner } from './signers/utxo.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const ethProvider = provider.get(EVM_NAMESPACE);\n const tronProvider = provider.get(TRON_NAMESPACE);\n const utxoProvider = provider.get(UTXO_NAMESPACE);\n\n const signers = new DefaultSignerFactory();\n const { DefaultEvmSigner } = await import('@rango-dev/signer-evm');\n const { DefaultTronSigner } = await import('@rango-dev/signer-tron');\n if (!!ethProvider) {\n signers.registerSigner(TxType.EVM, new DefaultEvmSigner(ethProvider));\n }\n if (!!tronProvider) {\n signers.registerSigner(TxType.TRON, new DefaultTronSigner(tronProvider));\n }\n if (!!utxoProvider) {\n signers.registerSigner(TxType.TRANSFER, new BitgetUTXOSigner(utxoProvider));\n }\n\n return signers;\n}\n", "import type { ProviderAPI } from '@hub3js/bip122';\nimport type { GenericSigner, Transfer } from 'rango-types';\n\nimport { isBitcoinBlockchain } from '@rango-dev/internal-blockchains';\nimport * as bitcoin from 'bitcoinjs-lib';\nimport { SignerError } from 'rango-types';\n\nconst BTC_RPC_URL = 'https://go.getblock.io/f37bad28a991436483c0a3679a3acbee';\n\nexport class BitgetUTXOSigner implements GenericSigner<Transfer> {\n private provider: ProviderAPI;\n constructor(provider: ProviderAPI) {\n this.provider = provider;\n }\n\n async signMessage(): Promise<string> {\n throw SignerError.UnimplementedError('signMessage');\n }\n\n async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {\n const { asset, psbt } = tx;\n if (!psbt) {\n throw new Error(\n 'No PSBT found to sign. Ensure a valid PSBT is provided.'\n );\n }\n\n if (!isBitcoinBlockchain(asset.blockchain)) {\n throw new Error(\n `Signing ${asset.blockchain} transaction is not implemented by the signer.`\n );\n }\n // 1. Decode Base64 to hex\n const psbtHex = Buffer.from(psbt.unsignedPsbtBase64, 'base64').toString(\n 'hex'\n );\n\n // 2. Build UniSat inputs\n const toSignInputs = psbt.inputsToSign.flatMap(\n ({ address, signingIndexes }) =>\n signingIndexes.map((index) => ({ index, address }))\n );\n\n // 3. Sign (& auto-finalize)\n let signedPsbtHex: string;\n try {\n signedPsbtHex = await this.provider.signPsbt(psbtHex, {\n autoFinalized: true,\n toSignInputs,\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n throw new Error(error?.message || 'Error during signing transaction');\n }\n\n // 4. Parse the PSBT hex and extract the raw transaction\n const psbtObject = bitcoin.Psbt.fromHex(signedPsbtHex);\n const finalPsbtBaseHex = psbtObject.extractTransaction().toHex();\n\n /*\n * 5. Broadcast the raw transaction to the rpc node.\n * Broadcasting through Bitget's `pushPsbt` fails, so we submit the raw\n * transaction ourselves, the same way the UniSat signer does.\n */\n const response = await fetch(BTC_RPC_URL, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'sendrawtransaction',\n params: [finalPsbtBaseHex],\n }),\n });\n\n if (!response.ok) {\n // Handle network and fetch errors\n const errorText = await response.text();\n throw new Error(`Error broadcasting transaction: ${errorText}`);\n }\n\n const data = await response.json();\n\n if (!data.result) {\n // Handle Bitcoin specific errors\n throw new Error(\n `Error broadcasting transaction. Error Code ${data.error.code}: ${data.error.message}`\n );\n }\n\n return { hash: data.result };\n }\n}\n", "import type { Provider } from './types.js';\nimport type { ProviderAPI as UtxoProviderApi } from '@hub3js/bip122';\nimport type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';\nimport type { ProviderAPI as TronProviderApi } from '@hub3js/tron';\n\nimport {\n EVM_NAMESPACE,\n TRON_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\n\nexport function bitget(): Provider | null {\n const instances: Provider = new Map();\n const { bitkeep } = window;\n\n if (!bitkeep) {\n return null;\n }\n\n if (bitkeep.ethereum) {\n instances.set(EVM_NAMESPACE, bitkeep.ethereum);\n }\n\n if (bitkeep.tronLink) {\n instances.set(TRON_NAMESPACE, bitkeep.tronLink);\n }\n if (bitkeep.unisat) {\n instances.set(UTXO_NAMESPACE, bitkeep.unisat);\n }\n\n if (instances.size === 0) {\n return null;\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = bitget();\n\n if (!instances) {\n throw new Error('Bitget is not injected. Please check your wallet.');\n }\n\n return instances;\n}\n\nexport function evmBitget(): EvmProviderApi {\n const instances = bitget();\n\n const evmInstance = instances?.get(EVM_NAMESPACE);\n\n if (!evmInstance) {\n throw new Error(\n 'Bitget not injected or EVM not enabled. Please check your wallet.'\n );\n }\n\n return evmInstance;\n}\n\nexport function tronBitget(): TronProviderApi {\n const instance = bitget();\n const tronInstance = instance?.get(TRON_NAMESPACE);\n\n if (!tronInstance) {\n throw new Error(\n 'Bitget not injected or Tron not enabled. Please check your wallet.'\n );\n }\n\n return tronInstance;\n}\nexport function utxoBitget(): UtxoProviderApi {\n const instance = bitget();\n const utxoInstance = instance?.get(UTXO_NAMESPACE);\n\n if (!utxoInstance) {\n throw new Error(\n 'Bitget not injected or BTC not enabled. Please check your wallet.'\n );\n }\n\n return utxoInstance;\n}\n", "import type { EvmActions } from '@hub3js/evm';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport { actions, builders, hooks } from '@hub3js/evm';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { WALLET_ID } from '../constants.js';\nimport { evmBitget } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(evmBitget);\nconst connect = builders\n .connect()\n .action(actions.connect(evmBitget))\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 canEagerConnect = builders\n .canEagerConnect()\n .action(actions.canEagerConnect(evmBitget))\n .build();\n\nconst getChainId = builders\n .getChainId()\n .action(actions.getChainId(evmBitget))\n .build();\n\nconst getAllowance = builders\n .getAllowance()\n .action(actions.getAllowance(evmBitget))\n .build();\n\nconst getTransactionReceipt = builders\n .getTransactionReceipt()\n .action(actions.getTransactionReceipt(evmBitget))\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(getChainId)\n .action(canEagerConnect)\n .action(canSwitchNetwork)\n .action(getAllowance)\n .action(getTransactionReceipt)\n .build();\n\nexport { evm };\n", "import { NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { type TronActions, utils } from '@hub3js/tron';\nimport { actions, builders } from '@hub3js/tron';\n\nimport { tronActions } from '../actions/tron.js';\nimport { tronBuilders } from '../builders/tron.js';\nimport { TronOKRequestCode, WALLET_ID } from '../constants.js';\nimport { tronBitget } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = tronBuilders\n .changeAccountSubscriber(tronBitget)\n .build();\n\nconst connect = builders\n .connect()\n .action(async () => {\n const instance = tronBitget();\n const accountsResult = await instance.request({\n method: 'tron_requestAccounts',\n });\n if (!accountsResult) {\n throw new Error('Please unlock your Bitget extension first.');\n }\n\n if (\n !!accountsResult?.code &&\n !!accountsResult.message &&\n accountsResult.code !== TronOKRequestCode\n ) {\n throw new Error(accountsResult.message);\n }\n return utils.formatAccountsToCAIP([instance.tronWeb.defaultAddress.base58]);\n })\n .before(changeAccountSubscriber)\n .or(standardizeAndThrowError)\n .or(changeAccountCleanup)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<TronActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(tronActions.canEagerConnectAction)\n .build();\n\nconst getAllowance = builders\n .getAllowance()\n .action(actions.getAllowance(tronBitget))\n .build();\n\nconst buildApproveTransaction = builders\n .buildApproveTransaction()\n .action(actions.buildApproveTransaction(tronBitget))\n .build();\n\nconst getTransactionInfo = builders\n .getTransactionInfo()\n .action(actions.getTransactionInfo(tronBitget))\n .build();\n\nconst tron = new NamespaceBuilder<TronActions>('Tron', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .action(getAllowance)\n .action(buildApproveTransaction)\n .action(getTransactionInfo)\n .build();\n\nexport { tron };\n", "import { evmBitget, tronBitget } from '../utils.js';\n\n/*\n * Bitget does not provide an eager connection mechanism for its Tron wallet.\n * The only workaround is to use the EVM-based eager connect approach.\n * However, this will only work if the EVM namespace has been connected at least once before.\n * If either wallet instance is unavailable, we throw an error.\n */\nconst canEagerConnectAction = async () => {\n const evmInstance = evmBitget();\n const tronInstance = tronBitget();\n // Making sure that the Tron instance is available first to prevent errors.\n if (!tronInstance) {\n throw new Error(\n 'Trying to eagerly connect to your wallet, but seems its tron instance is not available.'\n );\n }\n if (!evmInstance) {\n throw new Error(\n 'Trying to eagerly connect to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n try {\n const accounts: string[] = await evmInstance.request({\n method: 'eth_accounts',\n });\n if (accounts.length) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n};\nexport const tronActions = { canEagerConnectAction };\n", "import type { TronChangeAccountEvent } from '../types.js';\n\nimport { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';\nimport { type ProviderAPI, type TronActions, utils } from '@hub3js/tron';\n\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n new ChangeAccountSubscriberBuilder<\n MessageEvent<TronChangeAccountEvent>,\n ProviderAPI,\n TronActions\n >()\n .getInstance(getInstance)\n .onSwitchAccount((event, context) => {\n if (\n !event.payload.data.isBitkeep ||\n event.payload.data.message?.action !== 'accountsChanged'\n ) {\n event.preventDefault();\n return;\n }\n if (!event.payload.data.message.data.address) {\n event.preventDefault();\n context.action('disconnect');\n }\n })\n .format(async (_, accounts) =>\n utils.formatAccountsToCAIP([accounts.data.message.data.address])\n )\n .addEventListener((_, callback) => {\n window.addEventListener('message', callback);\n })\n .removeEventListener((_, callback) => {\n window.removeEventListener('message', callback);\n });\n\nexport const tronBuilders = { changeAccountSubscriber };\n", "import type { UtxoActions } from '@hub3js/bip122';\n\nimport { builders } from '@hub3js/bip122';\nimport { NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { utxoActions } from '../actions/utxo.js';\nimport { utxoBuilders } from '../builders/utxo.js';\nimport { WALLET_ID } from '../constants.js';\nimport { utxoHooks } from '../hooks/utxo.js';\nimport { utxoBitget } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = utxoBuilders\n .changeAccountSubscriber(utxoBitget)\n .build();\nconst [disconnectSubscriber, disconnectSubscriberCleanup] =\n utxoHooks.disconnectSubscriber(utxoBitget);\nconst connect = builders\n .connect()\n .action(utxoActions.connect(utxoBitget))\n .before(changeAccountSubscriber)\n .before(disconnectSubscriber)\n .or(changeAccountCleanup)\n .or(disconnectSubscriberCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<UtxoActions>()\n .after(changeAccountCleanup)\n .after(disconnectSubscriberCleanup)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(utxoActions.canEagerConnect(utxoBitget))\n .build();\n\nconst utxo = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { utxo };\n", "import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';\nimport type {\n CanEagerConnect,\n Context,\n FunctionWithContext,\n} from '@hub3js/core';\n\nimport { CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';\n\nexport function connect(\n instance: () => ProviderAPI\n): FunctionWithContext<UtxoActions['connect'], Context> {\n return async () => {\n const utxoInstance = instance();\n\n if (!utxoInstance) {\n throw new Error(\n 'Do your wallet injected correctly and is utxo compatible?'\n );\n }\n const accounts = await utxoInstance.requestAccounts();\n\n return utils.formatAccountsToCAIP(accounts, CAIP_BITCOIN_CHAIN_ID);\n };\n}\n\nexport function canEagerConnect(\n instance: () => ProviderAPI\n): CanEagerConnect<UtxoActions> {\n return async () => {\n const accounts = await instance().getAccounts();\n return !!accounts.length;\n };\n}\n\nexport const utxoActions = { connect, canEagerConnect };\n", "import type { ProviderAPI } from '@hub3js/bip122';\n\nimport { builders, CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';\n\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n builders\n .changeAccountSubscriber<string>(getInstance, {\n network: CAIP_BITCOIN_CHAIN_ID,\n })\n .onSwitchAccount((event, context) => {\n if (!event.payload) {\n event.preventDefault();\n context.action('disconnect');\n }\n })\n\n .format(async (_, address) => {\n return utils.formatAccountsToCAIP(\n address ? [address] : [],\n CAIP_BITCOIN_CHAIN_ID\n );\n })\n .addEventListener((instance, callback) => {\n return instance.addListener('accountChanged', callback);\n })\n .removeEventListener((instance, callback) => {\n return instance.removeListener('accountChanged', callback);\n });\n\nexport const utxoBuilders = { changeAccountSubscriber };\n", "import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';\nimport type { AnyFunction, Subscriber, SubscriberCleanUp } from '@hub3js/core';\n\nfunction disconnectSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<UtxoActions>, SubscriberCleanUp<UtxoActions>] {\n let eventCallback: AnyFunction;\n\n // subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.\n return [\n (context, err) => {\n const bitcoinInstance = instance();\n\n if (!bitcoinInstance) {\n throw new Error(\n 'Trying to subscribe to your BTC wallet, but seems its instance is not available.'\n );\n }\n\n eventCallback = () => {\n context.action('disconnect');\n };\n bitcoinInstance.on('disconnect', eventCallback);\n\n if (err instanceof Error) {\n throw err;\n }\n },\n (_context, err) => {\n const bitcoinInstance = instance();\n\n if (eventCallback && bitcoinInstance) {\n bitcoinInstance.removeListener('disconnect', eventCallback);\n }\n\n return err;\n },\n ];\n}\nexport const utxoHooks = { disconnectSubscriber };\n"],
|
|
5
|
-
"mappings": "+EAAA,OAAS,mBAAAA,OAAuB,eCEhC,OACE,yBAAAC,GACA,oBAAoBC,OACf,iBACP,OAAS,kBAAAC,OAAsB,cAC/B,OAAS,mBAAAC,OAAuB,
|
|
6
|
-
"names": ["ProviderBuilder", "CAIP_BITCOIN_CHAIN_ID", "isBip122ChainSupported", "isEvmNamespace", "isTronNamespace", "EVM_NAMESPACE", "TRON_NAMESPACE", "UTXO_NAMESPACE", "DefaultSignerFactory", "TxType", "isBitcoinBlockchain", "bitcoin", "SignerError", "BTC_RPC_URL", "BitgetUTXOSigner", "__name", "provider", "SignerError", "tx", "asset", "psbt", "isBitcoinBlockchain", "psbtHex", "toSignInputs", "address", "signingIndexes", "index", "signedPsbtHex", "error", "finalPsbtBaseHex", "response", "errorText", "data", "getSigners", "provider", "ethProvider", "EVM_NAMESPACE", "tronProvider", "TRON_NAMESPACE", "utxoProvider", "UTXO_NAMESPACE", "signers", "DefaultSignerFactory", "DefaultEvmSigner", "DefaultTronSigner", "TxType", "BitgetUTXOSigner", "__name", "EVM_NAMESPACE", "TRON_NAMESPACE", "UTXO_NAMESPACE", "bitget", "instances", "bitkeep", "EVM_NAMESPACE", "TRON_NAMESPACE", "UTXO_NAMESPACE", "__name", "getInstanceOrThrow", "evmBitget", "evmInstance", "tronBitget", "tronInstance", "utxoBitget", "utxoInstance", "WALLET_ID", "TronOKRequestCode", "metadata", "isEvmNamespace", "isTronNamespace", "isBip122ChainSupported", "CAIP_BITCOIN_CHAIN_ID", "getSigners", "getInstanceOrThrow", "NamespaceBuilder", "actions", "builders", "hooks", "commonBuilders", "standardizeAndThrowError", "changeAccountSubscriber", "changeAccountCleanup", "hooks", "evmBitget", "connect", "builders", "actions", "standardizeAndThrowError", "disconnect", "canSwitchNetwork", "canEagerConnect", "getChainId", "getAllowance", "getTransactionReceipt", "evm", "NamespaceBuilder", "WALLET_ID", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "utils", "actions", "builders", "canEagerConnectAction", "__name", "evmInstance", "evmBitget", "tronBitget", "tronActions", "ChangeAccountSubscriberBuilder", "utils", "changeAccountSubscriber", "__name", "getInstance", "ChangeAccountSubscriberBuilder", "event", "context", "_", "accounts", "utils", "callback", "tronBuilders", "changeAccountSubscriber", "changeAccountCleanup", "tronBuilders", "tronBitget", "connect", "builders", "instance", "accountsResult", "TronOKRequestCode", "utils", "standardizeAndThrowError", "disconnect", "canEagerConnect", "tronActions", "getAllowance", "actions", "buildApproveTransaction", "getTransactionInfo", "tron", "NamespaceBuilder", "WALLET_ID", "builders", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "CAIP_BITCOIN_CHAIN_ID", "utils", "connect", "instance", "utxoInstance", "accounts", "utils", "CAIP_BITCOIN_CHAIN_ID", "__name", "canEagerConnect", "utxoActions", "builders", "CAIP_BITCOIN_CHAIN_ID", "utils", "changeAccountSubscriber", "__name", "getInstance", "builders", "CAIP_BITCOIN_CHAIN_ID", "event", "context", "_", "address", "utils", "instance", "callback", "utxoBuilders", "disconnectSubscriber", "instance", "eventCallback", "context", "err", "bitcoinInstance", "__name", "_context", "utxoHooks", "changeAccountSubscriber", "changeAccountCleanup", "utxoBuilders", "utxoBitget", "disconnectSubscriber", "disconnectSubscriberCleanup", "utxoHooks", "connect", "builders", "utxoActions", "standardizeAndThrowError", "disconnect", "canEagerConnect", "utxo", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "bitget", "metadata", "tron", "evm", "utxo"]
|
|
4
|
+
"sourcesContent": ["import { ProviderBuilder } from '@hub3js/core';\n\nimport { metadata, WALLET_ID } from './constants.js';\nimport { evm } from './namespaces/evm.js';\nimport { tron } from './namespaces/tron.js';\nimport { utxo } from './namespaces/utxo.js';\nimport { bitget } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n\n if (bitget()) {\n setState('installed', true);\n console.debug('[bitget] instance detected.', context);\n }\n })\n .config('metadata', metadata)\n .add('tron', tron)\n .add('evm', evm)\n .add('utxo', utxo)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n isChainSupported as isBip122ChainSupported,\n} from '@hub3js/bip122';\nimport { EIP1474_INTERNAL_ERROR } from '@hub3js/core';\nimport { isEvmNamespace } from '@hub3js/evm';\nimport { isTronNamespace } from '@hub3js/tron';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const WALLET_ID = 'bitget';\nexport const TronOKRequestCode = 200;\n\n// Bitget reports a UTXO rejection with the generic JSON-RPC internal error code, so its message is matched too.\nexport const BITGET_UTXO_REJECTION_CODE = EIP1474_INTERNAL_ERROR;\nexport const BITGET_UTXO_REJECTION_MESSAGE = 'User rejected the request';\n\nexport const metadata: ProviderMetadata = {\n name: 'Bitget',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/bitget/icon.svg',\n extensions: {\n chrome:\n 'https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak',\n brave:\n 'https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak',\n homepage: 'https://web3.bitget.com/en/wallet-download?type=1',\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 isChainSupported: isEvmNamespace,\n },\n {\n label: 'Tron',\n value: 'Tron',\n id: 'TRON',\n isChainSupported: isTronNamespace,\n },\n {\n label: 'BTC',\n value: 'UTXO',\n id: 'BTC',\n isChainSupported: isBip122ChainSupported([CAIP_BITCOIN_CHAIN_ID]),\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 {\n EVM_NAMESPACE,\n TRON_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { BitgetUTXOSigner } from './signers/utxo.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const ethProvider = provider.get(EVM_NAMESPACE);\n const tronProvider = provider.get(TRON_NAMESPACE);\n const utxoProvider = provider.get(UTXO_NAMESPACE);\n\n const signers = new DefaultSignerFactory();\n const { DefaultEvmSigner } = await import('@rango-dev/signer-evm');\n const { DefaultTronSigner } = await import('@rango-dev/signer-tron');\n if (!!ethProvider) {\n signers.registerSigner(TxType.EVM, new DefaultEvmSigner(ethProvider));\n }\n if (!!tronProvider) {\n signers.registerSigner(TxType.TRON, new DefaultTronSigner(tronProvider));\n }\n if (!!utxoProvider) {\n signers.registerSigner(TxType.TRANSFER, new BitgetUTXOSigner(utxoProvider));\n }\n\n return signers;\n}\n", "import type { ProviderAPI } from '@hub3js/bip122';\nimport type { GenericSigner, Transfer } from 'rango-types';\n\nimport { isBitcoinBlockchain } from '@rango-dev/internal-blockchains';\nimport * as bitcoin from 'bitcoinjs-lib';\nimport { SignerError } from 'rango-types';\n\nconst BTC_RPC_URL = 'https://go.getblock.io/f37bad28a991436483c0a3679a3acbee';\n\nexport class BitgetUTXOSigner implements GenericSigner<Transfer> {\n private provider: ProviderAPI;\n constructor(provider: ProviderAPI) {\n this.provider = provider;\n }\n\n async signMessage(): Promise<string> {\n throw SignerError.UnimplementedError('signMessage');\n }\n\n async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {\n const { asset, psbt } = tx;\n if (!psbt) {\n throw new Error(\n 'No PSBT found to sign. Ensure a valid PSBT is provided.'\n );\n }\n\n if (!isBitcoinBlockchain(asset.blockchain)) {\n throw new Error(\n `Signing ${asset.blockchain} transaction is not implemented by the signer.`\n );\n }\n // 1. Decode Base64 to hex\n const psbtHex = Buffer.from(psbt.unsignedPsbtBase64, 'base64').toString(\n 'hex'\n );\n\n // 2. Build UniSat inputs\n const toSignInputs = psbt.inputsToSign.flatMap(\n ({ address, signingIndexes }) =>\n signingIndexes.map((index) => ({ index, address }))\n );\n\n // 3. Sign (& auto-finalize)\n let signedPsbtHex: string;\n try {\n signedPsbtHex = await this.provider.signPsbt(psbtHex, {\n autoFinalized: true,\n toSignInputs,\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n throw new Error(error?.message || 'Error during signing transaction');\n }\n\n // 4. Parse the PSBT hex and extract the raw transaction\n const psbtObject = bitcoin.Psbt.fromHex(signedPsbtHex);\n const finalPsbtBaseHex = psbtObject.extractTransaction().toHex();\n\n /*\n * 5. Broadcast the raw transaction to the rpc node.\n * Broadcasting through Bitget's `pushPsbt` fails, so we submit the raw\n * transaction ourselves, the same way the UniSat signer does.\n */\n const response = await fetch(BTC_RPC_URL, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'sendrawtransaction',\n params: [finalPsbtBaseHex],\n }),\n });\n\n if (!response.ok) {\n // Handle network and fetch errors\n const errorText = await response.text();\n throw new Error(`Error broadcasting transaction: ${errorText}`);\n }\n\n const data = await response.json();\n\n if (!data.result) {\n // Handle Bitcoin specific errors\n throw new Error(\n `Error broadcasting transaction. Error Code ${data.error.code}: ${data.error.message}`\n );\n }\n\n return { hash: data.result };\n }\n}\n", "import type { Provider } from './types.js';\nimport type { ProviderAPI as UtxoProviderApi } from '@hub3js/bip122';\nimport type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';\nimport type { ProviderAPI as TronProviderApi } from '@hub3js/tron';\n\nimport {\n EVM_NAMESPACE,\n TRON_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\n\nexport function bitget(): Provider | null {\n const instances: Provider = new Map();\n const { bitkeep } = window;\n\n if (!bitkeep) {\n return null;\n }\n\n if (bitkeep.ethereum) {\n instances.set(EVM_NAMESPACE, bitkeep.ethereum);\n }\n\n if (bitkeep.tronLink) {\n instances.set(TRON_NAMESPACE, bitkeep.tronLink);\n }\n if (bitkeep.unisat) {\n instances.set(UTXO_NAMESPACE, bitkeep.unisat);\n }\n\n if (instances.size === 0) {\n return null;\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = bitget();\n\n if (!instances) {\n throw new Error('Bitget is not injected. Please check your wallet.');\n }\n\n return instances;\n}\n\nexport function evmBitget(): EvmProviderApi {\n const instances = bitget();\n\n const evmInstance = instances?.get(EVM_NAMESPACE);\n\n if (!evmInstance) {\n throw new Error(\n 'Bitget not injected or EVM not enabled. Please check your wallet.'\n );\n }\n\n return evmInstance;\n}\n\nexport function tronBitget(): TronProviderApi {\n const instance = bitget();\n const tronInstance = instance?.get(TRON_NAMESPACE);\n\n if (!tronInstance) {\n throw new Error(\n 'Bitget not injected or Tron not enabled. Please check your wallet.'\n );\n }\n\n return tronInstance;\n}\nexport function utxoBitget(): UtxoProviderApi {\n const instance = bitget();\n const utxoInstance = instance?.get(UTXO_NAMESPACE);\n\n if (!utxoInstance) {\n throw new Error(\n 'Bitget not injected or BTC not enabled. Please check your wallet.'\n );\n }\n\n return utxoInstance;\n}\n", "import type { EvmActions } from '@hub3js/evm';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport { actions, builders, hooks } from '@hub3js/evm';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { WALLET_ID } from '../constants.js';\nimport { evmBitget } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(evmBitget);\nconst connect = builders\n .connect()\n .action(actions.connect(evmBitget))\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 canEagerConnect = builders\n .canEagerConnect()\n .action(actions.canEagerConnect(evmBitget))\n .build();\n\nconst getChainId = builders\n .getChainId()\n .action(actions.getChainId(evmBitget))\n .build();\n\nconst getAllowance = builders\n .getAllowance()\n .action(actions.getAllowance(evmBitget))\n .build();\n\nconst getTransactionReceipt = builders\n .getTransactionReceipt()\n .action(actions.getTransactionReceipt(evmBitget))\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(getChainId)\n .action(canEagerConnect)\n .action(canSwitchNetwork)\n .action(getAllowance)\n .action(getTransactionReceipt)\n .build();\n\nexport { evm };\n", "import { getErrorMessage, Hub3Error, NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { type TronActions, utils } from '@hub3js/tron';\nimport { actions, builders } from '@hub3js/tron';\n\nimport { tronActions } from '../actions/tron.js';\nimport { tronBuilders } from '../builders/tron.js';\nimport { TronOKRequestCode, WALLET_ID } from '../constants.js';\nimport { tronBitget } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = tronBuilders\n .changeAccountSubscriber(tronBitget)\n .build();\n\nconst connect = builders\n .connect()\n .action(async () => {\n const instance = tronBitget();\n const accountsResult = await instance.request({\n method: 'tron_requestAccounts',\n });\n\n if (!!accountsResult?.code && accountsResult.code !== TronOKRequestCode) {\n throw new Hub3Error(\n 'PROVIDER_UNEXPECTED',\n getErrorMessage(accountsResult),\n { cause: accountsResult }\n );\n }\n return utils.formatAccountsToCAIP([instance.tronWeb.defaultAddress.base58]);\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<TronActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(tronActions.canEagerConnectAction)\n .build();\n\nconst getAllowance = builders\n .getAllowance()\n .action(actions.getAllowance(tronBitget))\n .build();\n\nconst buildApproveTransaction = builders\n .buildApproveTransaction()\n .action(actions.buildApproveTransaction(tronBitget))\n .build();\n\nconst getTransactionInfo = builders\n .getTransactionInfo()\n .action(actions.getTransactionInfo(tronBitget))\n .build();\n\nconst tron = new NamespaceBuilder<TronActions>('Tron', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .action(getAllowance)\n .action(buildApproveTransaction)\n .action(getTransactionInfo)\n .build();\n\nexport { tron };\n", "import { evmBitget, tronBitget } from '../utils.js';\n\n/*\n * Bitget does not provide an eager connection mechanism for its Tron wallet.\n * The only workaround is to use the EVM-based eager connect approach.\n * However, this will only work if the EVM namespace has been connected at least once before.\n * If either wallet instance is unavailable, we throw an error.\n */\nconst canEagerConnectAction = async () => {\n const evmInstance = evmBitget();\n const tronInstance = tronBitget();\n // Making sure that the Tron instance is available first to prevent errors.\n if (!tronInstance) {\n throw new Error(\n 'Trying to eagerly connect to your wallet, but seems its tron instance is not available.'\n );\n }\n if (!evmInstance) {\n throw new Error(\n 'Trying to eagerly connect to your EVM wallet, but seems its instance is not available.'\n );\n }\n\n try {\n const accounts: string[] = await evmInstance.request({\n method: 'eth_accounts',\n });\n if (accounts.length) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n};\nexport const tronActions = { canEagerConnectAction };\n", "import type { TronChangeAccountEvent } from '../types.js';\n\nimport { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';\nimport { type ProviderAPI, type TronActions, utils } from '@hub3js/tron';\n\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n new ChangeAccountSubscriberBuilder<\n MessageEvent<TronChangeAccountEvent>,\n ProviderAPI,\n TronActions\n >()\n .getInstance(getInstance)\n .onSwitchAccount((event, context) => {\n if (\n !event.payload.data.isBitkeep ||\n event.payload.data.message?.action !== 'accountsChanged'\n ) {\n event.preventDefault();\n return;\n }\n if (!event.payload.data.message.data.address) {\n event.preventDefault();\n context.action('disconnect');\n }\n })\n .format(async (_, accounts) =>\n utils.formatAccountsToCAIP([accounts.data.message.data.address])\n )\n .addEventListener((_, callback) => {\n window.addEventListener('message', callback);\n })\n .removeEventListener((_, callback) => {\n window.removeEventListener('message', callback);\n });\n\nexport const tronBuilders = { changeAccountSubscriber };\n", "import type { UtxoActions } from '@hub3js/bip122';\n\nimport { builders } from '@hub3js/bip122';\nimport { NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { utxoActions } from '../actions/utxo.js';\nimport { utxoBuilders } from '../builders/utxo.js';\nimport { WALLET_ID } from '../constants.js';\nimport { utxoHooks } from '../hooks/utxo.js';\nimport { utxoBitget } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = utxoBuilders\n .changeAccountSubscriber(utxoBitget)\n .build();\nconst [disconnectSubscriber, disconnectSubscriberCleanup] =\n utxoHooks.disconnectSubscriber(utxoBitget);\nconst connect = builders\n .connect()\n .action(utxoActions.connect(utxoBitget))\n .before(changeAccountSubscriber)\n .before(disconnectSubscriber)\n .or(changeAccountCleanup)\n .or(disconnectSubscriberCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<UtxoActions>()\n .after(changeAccountCleanup)\n .after(disconnectSubscriberCleanup)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(utxoActions.canEagerConnect(utxoBitget))\n .build();\n\nconst utxo = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { utxo };\n", "import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';\nimport type {\n CanEagerConnect,\n Context,\n FunctionWithContext,\n} from '@hub3js/core';\n\nimport { CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';\nimport { getErrorMessage, Hub3Error } from '@hub3js/core';\n\nimport {\n BITGET_UTXO_REJECTION_CODE,\n BITGET_UTXO_REJECTION_MESSAGE,\n} from '../constants.js';\n\nexport function connect(\n instance: () => ProviderAPI\n): FunctionWithContext<UtxoActions['connect'], Context> {\n return async () => {\n try {\n const utxoInstance = instance();\n\n if (!utxoInstance) {\n throw new Hub3Error(\n 'PROVIDER_UNEXPECTED',\n 'Do your wallet injected correctly and is utxo compatible?'\n );\n }\n const accounts = await utxoInstance.requestAccounts();\n\n return utils.formatAccountsToCAIP(accounts, CAIP_BITCOIN_CHAIN_ID);\n } catch (error) {\n if (error instanceof Hub3Error) {\n throw error;\n }\n if (\n typeof error === 'object' &&\n error !== null &&\n 'code' in error &&\n error.code === BITGET_UTXO_REJECTION_CODE &&\n 'message' in error &&\n error.message === BITGET_UTXO_REJECTION_MESSAGE\n ) {\n throw new Hub3Error(\n 'PROVIDER_USER_REJECTED_REQUEST',\n getErrorMessage(error),\n { cause: error }\n );\n }\n throw error;\n }\n };\n}\n\nexport function canEagerConnect(\n instance: () => ProviderAPI\n): CanEagerConnect<UtxoActions> {\n return async () => {\n const accounts = await instance().getAccounts();\n return !!accounts.length;\n };\n}\n\nexport const utxoActions = { connect, canEagerConnect };\n", "import type { ProviderAPI } from '@hub3js/bip122';\n\nimport { builders, CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';\n\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n builders\n .changeAccountSubscriber<string>(getInstance, {\n network: CAIP_BITCOIN_CHAIN_ID,\n })\n .onSwitchAccount((event, context) => {\n if (!event.payload) {\n event.preventDefault();\n context.action('disconnect');\n }\n })\n\n .format(async (_, address) => {\n return utils.formatAccountsToCAIP(\n address ? [address] : [],\n CAIP_BITCOIN_CHAIN_ID\n );\n })\n .addEventListener((instance, callback) => {\n return instance.addListener('accountChanged', callback);\n })\n .removeEventListener((instance, callback) => {\n return instance.removeListener('accountChanged', callback);\n });\n\nexport const utxoBuilders = { changeAccountSubscriber };\n", "import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';\nimport type { AnyFunction, Subscriber, SubscriberCleanUp } from '@hub3js/core';\n\nfunction disconnectSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<UtxoActions>, SubscriberCleanUp<UtxoActions>] {\n let eventCallback: AnyFunction;\n\n // subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.\n return [\n (context, err) => {\n const bitcoinInstance = instance();\n\n if (!bitcoinInstance) {\n throw new Error(\n 'Trying to subscribe to your BTC wallet, but seems its instance is not available.'\n );\n }\n\n eventCallback = () => {\n context.action('disconnect');\n };\n bitcoinInstance.on('disconnect', eventCallback);\n\n if (err instanceof Error) {\n throw err;\n }\n },\n (_context, err) => {\n const bitcoinInstance = instance();\n\n if (eventCallback && bitcoinInstance) {\n bitcoinInstance.removeListener('disconnect', eventCallback);\n }\n\n return err;\n },\n ];\n}\nexport const utxoHooks = { disconnectSubscriber };\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,mBAAAA,OAAuB,eCEhC,OACE,yBAAAC,GACA,oBAAoBC,OACf,iBACP,OAAS,0BAAAC,OAA8B,eACvC,OAAS,kBAAAC,OAAsB,cAC/B,OAAS,mBAAAC,OAAuB,eCLhC,OACE,iBAAAC,GACA,kBAAAC,GACA,kBAAAC,OACK,qBACP,OAAS,wBAAAC,GAAsB,mBAAmBC,MAAc,cCLhE,OAAS,uBAAAC,OAA2B,kCACpC,UAAYC,MAAa,gBACzB,OAAS,eAAAC,OAAmB,cAE5B,IAAMC,GAAc,0DAEPC,EAAN,KAA0D,CATjE,MASiE,CAAAC,EAAA,yBACvD,SACR,YAAYC,EAAuB,CACjC,KAAK,SAAWA,CAClB,CAEA,MAAM,aAA+B,CACnC,MAAMC,GAAY,mBAAmB,aAAa,CACpD,CAEA,MAAM,cAAcC,EAAyC,CAC3D,GAAM,CAAE,MAAAC,EAAO,KAAAC,CAAK,EAAIF,EACxB,GAAI,CAACE,EACH,MAAM,IAAI,MACR,yDACF,EAGF,GAAI,CAACC,GAAoBF,EAAM,UAAU,EACvC,M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B,MAAM,ETnCT,IAAMI,GAAgBC,EAAA,IACpB,IAAIC,GAAgBC,CAAS,EAC1B,KAAK,SAAUC,EAAS,CACvB,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAE/BE,EAAO,IACTD,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,8BAA+BD,CAAO,EAExD,CAAC,EACA,OAAO,WAAYG,CAAQ,EAC3B,IAAI,OAAQC,CAAI,EAChB,IAAI,MAAOC,CAAG,EACd,IAAI,OAAQC,CAAI,EAChB,MAAM,EAdW",
|
|
6
|
+
"names": ["ProviderBuilder", "CAIP_BITCOIN_CHAIN_ID", "isBip122ChainSupported", "EIP1474_INTERNAL_ERROR", "isEvmNamespace", "isTronNamespace", "EVM_NAMESPACE", "TRON_NAMESPACE", "UTXO_NAMESPACE", "DefaultSignerFactory", "TxType", "isBitcoinBlockchain", "bitcoin", "SignerError", "BTC_RPC_URL", "BitgetUTXOSigner", "__name", "provider", "SignerError", "tx", "asset", "psbt", "isBitcoinBlockchain", "psbtHex", "toSignInputs", "address", "signingIndexes", "index", "signedPsbtHex", "error", "finalPsbtBaseHex", "response", "errorText", "data", "getSigners", "provider", "ethProvider", "EVM_NAMESPACE", "tronProvider", "TRON_NAMESPACE", "utxoProvider", "UTXO_NAMESPACE", "signers", "DefaultSignerFactory", "DefaultEvmSigner", "DefaultTronSigner", "TxType", "BitgetUTXOSigner", "__name", "EVM_NAMESPACE", "TRON_NAMESPACE", "UTXO_NAMESPACE", "bitget", "instances", "bitkeep", "EVM_NAMESPACE", "TRON_NAMESPACE", "UTXO_NAMESPACE", "__name", "getInstanceOrThrow", "evmBitget", "evmInstance", "tronBitget", "tronInstance", "utxoBitget", "utxoInstance", "WALLET_ID", "TronOKRequestCode", "BITGET_UTXO_REJECTION_CODE", "EIP1474_INTERNAL_ERROR", "BITGET_UTXO_REJECTION_MESSAGE", "metadata", "isEvmNamespace", "isTronNamespace", "isBip122ChainSupported", "CAIP_BITCOIN_CHAIN_ID", "getSigners", "getInstanceOrThrow", "NamespaceBuilder", "actions", "builders", "hooks", "commonBuilders", "standardizeAndThrowError", "changeAccountSubscriber", "changeAccountCleanup", "hooks", "evmBitget", "connect", "builders", "actions", "standardizeAndThrowError", "disconnect", "canSwitchNetwork", "canEagerConnect", "getChainId", "getAllowance", "getTransactionReceipt", "evm", "NamespaceBuilder", "WALLET_ID", "getErrorMessage", "Hub3Error", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "utils", "actions", "builders", "canEagerConnectAction", "__name", "evmInstance", "evmBitget", "tronBitget", "tronActions", "ChangeAccountSubscriberBuilder", "utils", "changeAccountSubscriber", "__name", "getInstance", "ChangeAccountSubscriberBuilder", "event", "context", "_", "accounts", "utils", "callback", "tronBuilders", "changeAccountSubscriber", "changeAccountCleanup", "tronBuilders", "tronBitget", "connect", "builders", "instance", "accountsResult", "TronOKRequestCode", "Hub3Error", "getErrorMessage", "utils", "standardizeAndThrowError", "disconnect", "canEagerConnect", "tronActions", "getAllowance", "actions", "buildApproveTransaction", "getTransactionInfo", "tron", "NamespaceBuilder", "WALLET_ID", "builders", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "CAIP_BITCOIN_CHAIN_ID", "utils", "getErrorMessage", "Hub3Error", "connect", "instance", "utxoInstance", "Hub3Error", "accounts", "utils", "CAIP_BITCOIN_CHAIN_ID", "error", "BITGET_UTXO_REJECTION_CODE", "BITGET_UTXO_REJECTION_MESSAGE", "getErrorMessage", "__name", "canEagerConnect", "utxoActions", "builders", "CAIP_BITCOIN_CHAIN_ID", "utils", "changeAccountSubscriber", "__name", "getInstance", "builders", "CAIP_BITCOIN_CHAIN_ID", "event", "context", "_", "address", "utils", "instance", "callback", "utxoBuilders", "disconnectSubscriber", "instance", "eventCallback", "context", "err", "bitcoinInstance", "__name", "_context", "utxoHooks", "changeAccountSubscriber", "changeAccountCleanup", "utxoBuilders", "utxoBitget", "disconnectSubscriber", "disconnectSubscriberCleanup", "utxoHooks", "connect", "builders", "utxoActions", "standardizeAndThrowError", "disconnect", "canEagerConnect", "utxo", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "bitget", "metadata", "tron", "evm", "utxo"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tron.d.ts","sourceRoot":"","sources":["../../src/namespaces/tron.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAS,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tron.d.ts","sourceRoot":"","sources":["../../src/namespaces/tron.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAS,MAAM,cAAc,CAAC;AA2DvD,QAAA,MAAM,IAAI,sDAOA,CAAC;AAEX,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/provider-bitget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.1-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/mod.ts",
|
|
@@ -22,27 +22,27 @@
|
|
|
22
22
|
"lint": "eslint \"**/*.{ts,tsx}\""
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rango-dev/internal-blockchains": "^0.
|
|
26
|
-
"@rango-dev/signer-evm": "^0.
|
|
27
|
-
"@rango-dev/signer-tron": "^0.
|
|
25
|
+
"@rango-dev/internal-blockchains": "^0.3.1-next.0",
|
|
26
|
+
"@rango-dev/signer-evm": "^0.47.0",
|
|
27
|
+
"@rango-dev/signer-tron": "^0.44.0",
|
|
28
28
|
"bitcoinjs-lib": "^6.1.7",
|
|
29
29
|
"rango-types": "^0.6.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@hub3js/bip122": "^0.
|
|
33
|
-
"@hub3js/core": "^0.
|
|
34
|
-
"@hub3js/evm": "^0.
|
|
35
|
-
"@hub3js/namespaces": "^0.
|
|
36
|
-
"@hub3js/std": "^0.
|
|
37
|
-
"@hub3js/tron": "^0.
|
|
32
|
+
"@hub3js/bip122": "^0.4.0",
|
|
33
|
+
"@hub3js/core": "^0.64.0",
|
|
34
|
+
"@hub3js/evm": "^0.8.0",
|
|
35
|
+
"@hub3js/namespaces": "^0.8.0",
|
|
36
|
+
"@hub3js/std": "^0.6.0",
|
|
37
|
+
"@hub3js/tron": "^0.3.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@hub3js/bip122": "^0.
|
|
41
|
-
"@hub3js/core": "^0.
|
|
42
|
-
"@hub3js/evm": "^0.
|
|
43
|
-
"@hub3js/namespaces": "^0.
|
|
44
|
-
"@hub3js/std": "^0.
|
|
45
|
-
"@hub3js/tron": "^0.
|
|
40
|
+
"@hub3js/bip122": "^0.4.0",
|
|
41
|
+
"@hub3js/core": "^0.64.0",
|
|
42
|
+
"@hub3js/evm": "^0.8.0",
|
|
43
|
+
"@hub3js/namespaces": "^0.8.0",
|
|
44
|
+
"@hub3js/std": "^0.6.0",
|
|
45
|
+
"@hub3js/tron": "^0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
package/readme.md
CHANGED
|
@@ -12,6 +12,8 @@ More about implementation status can be found [here](../readme.md).
|
|
|
12
12
|
Tron connection attempts can fail unpredictably, often returning an error on the **first or second try**.
|
|
13
13
|
Users may need to **retry the connection** to successfully establish a Tron session.
|
|
14
14
|
|
|
15
|
+
Bitget returns nothing meaningful when the user rejects the Tron connection request, so a rejection **can't be told apart** from other connection failures and is reported as `unknown`.
|
|
16
|
+
|
|
15
17
|
#### ⚠️ Switch Account
|
|
16
18
|
Switching accounts in the Bitget Wallet triggers a **full page refresh**.
|
|
17
19
|
Switch account would break if a single namespace account is connected.
|
package/src/actions/utxo.ts
CHANGED
|
@@ -6,21 +6,49 @@ import type {
|
|
|
6
6
|
} from '@hub3js/core';
|
|
7
7
|
|
|
8
8
|
import { CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';
|
|
9
|
+
import { getErrorMessage, Hub3Error } from '@hub3js/core';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
BITGET_UTXO_REJECTION_CODE,
|
|
13
|
+
BITGET_UTXO_REJECTION_MESSAGE,
|
|
14
|
+
} from '../constants.js';
|
|
9
15
|
|
|
10
16
|
export function connect(
|
|
11
17
|
instance: () => ProviderAPI
|
|
12
18
|
): FunctionWithContext<UtxoActions['connect'], Context> {
|
|
13
19
|
return async () => {
|
|
14
|
-
|
|
20
|
+
try {
|
|
21
|
+
const utxoInstance = instance();
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
if (!utxoInstance) {
|
|
24
|
+
throw new Hub3Error(
|
|
25
|
+
'PROVIDER_UNEXPECTED',
|
|
26
|
+
'Do your wallet injected correctly and is utxo compatible?'
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const accounts = await utxoInstance.requestAccounts();
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
return utils.formatAccountsToCAIP(accounts, CAIP_BITCOIN_CHAIN_ID);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error instanceof Hub3Error) {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
37
|
+
typeof error === 'object' &&
|
|
38
|
+
error !== null &&
|
|
39
|
+
'code' in error &&
|
|
40
|
+
error.code === BITGET_UTXO_REJECTION_CODE &&
|
|
41
|
+
'message' in error &&
|
|
42
|
+
error.message === BITGET_UTXO_REJECTION_MESSAGE
|
|
43
|
+
) {
|
|
44
|
+
throw new Hub3Error(
|
|
45
|
+
'PROVIDER_USER_REJECTED_REQUEST',
|
|
46
|
+
getErrorMessage(error),
|
|
47
|
+
{ cause: error }
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
24
52
|
};
|
|
25
53
|
}
|
|
26
54
|
|
package/src/constants.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CAIP_BITCOIN_CHAIN_ID,
|
|
5
5
|
isChainSupported as isBip122ChainSupported,
|
|
6
6
|
} from '@hub3js/bip122';
|
|
7
|
+
import { EIP1474_INTERNAL_ERROR } from '@hub3js/core';
|
|
7
8
|
import { isEvmNamespace } from '@hub3js/evm';
|
|
8
9
|
import { isTronNamespace } from '@hub3js/tron';
|
|
9
10
|
|
|
@@ -13,6 +14,10 @@ import { getInstanceOrThrow } from './utils.js';
|
|
|
13
14
|
export const WALLET_ID = 'bitget';
|
|
14
15
|
export const TronOKRequestCode = 200;
|
|
15
16
|
|
|
17
|
+
// Bitget reports a UTXO rejection with the generic JSON-RPC internal error code, so its message is matched too.
|
|
18
|
+
export const BITGET_UTXO_REJECTION_CODE = EIP1474_INTERNAL_ERROR;
|
|
19
|
+
export const BITGET_UTXO_REJECTION_MESSAGE = 'User rejected the request';
|
|
20
|
+
|
|
16
21
|
export const metadata: ProviderMetadata = {
|
|
17
22
|
name: 'Bitget',
|
|
18
23
|
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/bitget/icon.svg',
|
package/src/namespaces/tron.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NamespaceBuilder } from '@hub3js/core';
|
|
1
|
+
import { getErrorMessage, Hub3Error, NamespaceBuilder } from '@hub3js/core';
|
|
2
2
|
import * as commonBuilders from '@hub3js/std/builders';
|
|
3
3
|
import { standardizeAndThrowError } from '@hub3js/std/operators';
|
|
4
4
|
import { type TronActions, utils } from '@hub3js/tron';
|
|
@@ -20,22 +20,19 @@ const connect = builders
|
|
|
20
20
|
const accountsResult = await instance.request({
|
|
21
21
|
method: 'tron_requestAccounts',
|
|
22
22
|
});
|
|
23
|
-
if (!accountsResult) {
|
|
24
|
-
throw new Error('Please unlock your Bitget extension first.');
|
|
25
|
-
}
|
|
26
23
|
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
if (!!accountsResult?.code && accountsResult.code !== TronOKRequestCode) {
|
|
25
|
+
throw new Hub3Error(
|
|
26
|
+
'PROVIDER_UNEXPECTED',
|
|
27
|
+
getErrorMessage(accountsResult),
|
|
28
|
+
{ cause: accountsResult }
|
|
29
|
+
);
|
|
33
30
|
}
|
|
34
31
|
return utils.formatAccountsToCAIP([instance.tronWeb.defaultAddress.base58]);
|
|
35
32
|
})
|
|
36
33
|
.before(changeAccountSubscriber)
|
|
37
|
-
.or(standardizeAndThrowError)
|
|
38
34
|
.or(changeAccountCleanup)
|
|
35
|
+
.or(standardizeAndThrowError)
|
|
39
36
|
.build();
|
|
40
37
|
|
|
41
38
|
const disconnect = commonBuilders
|