@rango-dev/provider-xverse 0.8.1-next.3 → 0.8.1-next.5

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.
@@ -0,0 +1,9 @@
1
+ import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';
2
+ import type { CanEagerConnect, Context, FunctionWithContext } from '@hub3js/core';
3
+ export declare function connect(): FunctionWithContext<UtxoActions['connect'], Context>;
4
+ export declare function canEagerConnect(instance: () => ProviderAPI): CanEagerConnect<UtxoActions>;
5
+ export declare const utxoActions: {
6
+ connect: typeof connect;
7
+ canEagerConnect: typeof canEagerConnect;
8
+ };
9
+ //# sourceMappingURL=utxo.d.ts.map
@@ -0,0 +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;AAOtB,wBAAgB,OAAO,IAAI,mBAAmB,CAC5C,WAAW,CAAC,SAAS,CAAC,EACtB,OAAO,CACR,CAaA;AAGD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,WAAW,GAC1B,eAAe,CAAC,WAAW,CAAC,CAgB9B;AAED,eAAO,MAAM,WAAW;;;CAA+B,CAAC"}
@@ -1,12 +1,7 @@
1
1
  import type { XVerseEvent } from '../types.js';
2
- import { ActionBuilder } from '@hub3js/core';
3
- import { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';
4
- import { type ProviderAPI, type UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
5
- export declare const changeAccountSubscriber: (getInstance: () => ProviderAPI) => ChangeAccountSubscriberBuilder<XVerseEvent, ProviderAPI, UtxoActions>;
6
- declare function canEagerConnect(getInstance: () => ProviderAPI): ActionBuilder<UtxoActions, "canEagerConnect">;
2
+ import type { ProviderAPI } from '@hub3js/bip122';
3
+ export declare const changeAccountSubscriber: (getInstance: () => ProviderAPI) => import("@hub3js/std/hooks").ChangeAccountSubscriberBuilder<XVerseEvent, ProviderAPI, import("@hub3js/bip122").UtxoActions>;
7
4
  export declare const utxoBuilders: {
8
- changeAccountSubscriber: (getInstance: () => ProviderAPI) => ChangeAccountSubscriberBuilder<XVerseEvent, ProviderAPI, UtxoActions>;
9
- canEagerConnect: typeof canEagerConnect;
5
+ changeAccountSubscriber: (getInstance: () => ProviderAPI) => import("@hub3js/std/hooks").ChangeAccountSubscriberBuilder<XVerseEvent, ProviderAPI, import("@hub3js/bip122").UtxoActions>;
10
6
  };
11
- export {};
12
7
  //# sourceMappingURL=utxo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/builders/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,WAAW,EACjB,MAAM,yCAAyC,CAAC;AAIjD,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,WAAW,0EAyBhE,CAAC;AAEP,iBAAS,eAAe,CAAC,WAAW,EAAE,MAAM,WAAW,iDAiBtD;AAED,eAAO,MAAM,YAAY;2CA9C4B,MAAM,WAAW;;CA8CE,CAAC"}
1
+ {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/builders/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,WAAW,+HA2BhE,CAAC;AAEP,eAAO,MAAM,YAAY;2CA7B4B,MAAM,WAAW;CA6Bf,CAAC"}
@@ -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;AAWrD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,+BAA+B,SAAS,CAAC;AACtD,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,eAAO,MAAM,QAAQ,EAAE,gBA8BtB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUrD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,+BAA+B,SAAS,CAAC;AACtD,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,eAAO,MAAM,QAAQ,EAAE,gBA4BtB,CAAC"}
package/dist/mod.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const versions: () => readonly [readonly ["1.0.0", import("@hub3js/core").Provider<Record<"utxo", import("@rango-dev/wallets-core/namespaces/utxo").UtxoActions>>]];
1
+ declare const versions: () => readonly [readonly ["1.0.0", import("@hub3js/core").Provider<Record<"utxo", import("@hub3js/bip122").UtxoActions>>]];
2
2
  export { versions };
3
3
  export { WALLET_ID } from './constants.js';
4
4
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,QAAQ,qJAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,QAAQ,4HAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/mod.js CHANGED
@@ -1,2 +1,2 @@
1
- var y=Object.defineProperty;var t=(r,e)=>y(r,"name",{value:e,configurable:!0});import{defineVersions as $}from"@hub3js/core/utils";import{ProviderBuilder as z}from"@hub3js/core";import{getChainIdFromCaip2ChainId as R}from"@hub3js/std/utils";import{CAIP_BITCOIN_CHAIN_ID as N,isUtxoNamespace as D}from"@rango-dev/wallets-core/namespaces/utxo";import{UTXO_NAMESPACE as T}from"@hub3js/namespaces";import{DefaultSignerFactory as _,TransactionType as B}from"rango-types";import{isBitcoinBlockchain as C}from"@rango-dev/internal-blockchains";import{SignerError as S}from"rango-types";var a=class{static{t(this,"BTCSigner")}provider;constructor(e){this.provider=e}async signMessage(){throw S.UnimplementedError("signMessage")}async signAndSendTx(e){let{asset:o,psbt:n}=e;if(!n)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");if(!C(o.blockchain))throw new Error(`Signing ${o.blockchain} transaction is not implemented by the signer.`);let u={};n.inputsToSign.forEach(({address:x,signingIndexes:b})=>{u[x]=b});let i=await this.provider.request("signPsbt",{psbt:n.unsignedPsbtBase64,signInputs:u,broadcast:!0});if(i?.error)throw new Error(i.error.message||"Error during transaction sign");if(!i?.result?.txid)throw new Error("Transaction not found!");return{hash:i.result.txid}}};async function p(r){let e=r.get(T),o=new _;return e&&o.registerSigner(B.TRANSFER,new a(e)),o}t(p,"getSigners");import{UTXO_NAMESPACE as f}from"@hub3js/namespaces";function c(){let{XverseProviders:r}=window;if(!r)return null;let e=new Map;return r.BitcoinProvider&&e.set(f,r.BitcoinProvider),e}t(c,"xverse");function l(){let r=c();if(!r)throw new Error("Xverse is not injected. Please check your wallet.");return r}t(l,"getInstanceOrThrow");function m(){let e=c()?.get(f);if(!e)throw new Error("Xverse not injected. Please check your wallet.");return e}t(m,"bitcoinXverse");async function g(){let e=await m().request("wallet_connect",{addresses:["payment"],network:"Mainnet"});if(e.error?.message)throw new Error(e.error.message);return e}t(g,"getBitcoinAccounts");var v=1e3,E=-32002,s="xverse",A={name:"xverse",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/xverse/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/idnnbdplmphpflfnlkomgpfbpcgelopg",homepage:"https://www.xverse.app/"},properties:[{name:"namespaces",value:{selection:"single",data:[{label:"BTC",value:"UTXO",id:"BTC",isChainSupported:r=>D(r)&&R(r)===N}]}},{name:"signers",value:{getSigners:async()=>p(l())}}]};import{NamespaceBuilder as k}from"@hub3js/core";import*as P from"@hub3js/std/builders";import{standardizeAndThrowError as j}from"@hub3js/std/operators";import{CAIP_BITCOIN_CHAIN_ID as F,utils as q}from"@rango-dev/wallets-core/namespaces/utxo";import{builders as W}from"@rango-dev/wallets-core/namespaces/utxo";import{ActionBuilder as X}from"@hub3js/core";import{ChangeAccountSubscriberBuilder as O}from"@hub3js/std/hooks";import{CAIP_BITCOIN_CHAIN_ID as L,utils as U}from"@rango-dev/wallets-core/namespaces/utxo";var M=t(r=>new O().getInstance(r).onSwitchAccount(e=>{e.payload?.addresses?.length||e.preventDefault()}).format(async(e,o)=>U.formatAccountsToCAIP(o.addresses.filter(n=>n.purpose==="payment").map(n=>n.address),L)).addEventListener((e,o)=>e.addListener("accountChange",o)).removeEventListener((e,o)=>{}),"changeAccountSubscriber");function V(r){return new X("canEagerConnect").action(async()=>{let e=r();try{let o=await e.request("getAddresses",{purposes:["payment"]});return o.error?.code===E?!1:!!o.result?.addresses?.length}catch{return!1}})}t(V,"canEagerConnect");var d={changeAccountSubscriber:M,canEagerConnect:V};var[H,h]=d.changeAccountSubscriber(m).build(),G=d.canEagerConnect(m).build(),J=W.connect().action(async function(){let r=await g();if(r.result?.addresses?.length===0)throw new Error("Couldn't find any address!");return q.formatAccountsToCAIP(r.result.addresses.map(e=>e.address),F)}).before(H).or(h).or(j).build(),Y=P.disconnect().after(h).build(),w=new k("UTXO",s).action(J).action(Y).action(G).build();var I=t(()=>new z(s).init(function(r){let[,e]=r.state();setTimeout(()=>{c()&&(e("installed",!0),console.debug("[xverse] instance detected.",r))},v)}).config("metadata",A).add("utxo",w).build(),"buildProvider");var Ue=t(()=>$().version("1.0.0",I()).build(),"versions");export{s as WALLET_ID,Ue as versions};
1
+ var T=Object.defineProperty;var t=(r,e)=>T(r,"name",{value:e,configurable:!0});import{defineVersions as $}from"@hub3js/core/utils";import{ProviderBuilder as z}from"@hub3js/core";import{CAIP_BITCOIN_CHAIN_ID as X,isChainSupported as O}from"@hub3js/bip122";import{UTXO_NAMESPACE as R}from"@hub3js/namespaces";import{DefaultSignerFactory as D,TransactionType as N}from"rango-types";import{isBitcoinBlockchain as _}from"@rango-dev/internal-blockchains";import{SignerError as B}from"rango-types";var c=class{static{t(this,"BTCSigner")}provider;constructor(e){this.provider=e}async signMessage(){throw B.UnimplementedError("signMessage")}async signAndSendTx(e){let{asset:o,psbt:n}=e;if(!n)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");if(!_(o.blockchain))throw new Error(`Signing ${o.blockchain} transaction is not implemented by the signer.`);let d={};n.inputsToSign.forEach(({address:y,signingIndexes:S})=>{d[y]=S});let i=await this.provider.request("signPsbt",{psbt:n.unsignedPsbtBase64,signInputs:d,broadcast:!0});if(i?.error)throw new Error(i.error.message||"Error during transaction sign");if(!i?.result?.txid)throw new Error("Transaction not found!");return{hash:i.result.txid}}};async function m(r){let e=r.get(R),o=new D;return e&&o.registerSigner(N.TRANSFER,new c(e)),o}t(m,"getSigners");import{UTXO_NAMESPACE as f}from"@hub3js/namespaces";function a(){let{XverseProviders:r}=window;if(!r)return null;let e=new Map;return r.BitcoinProvider&&e.set(f,r.BitcoinProvider),e}t(a,"xverse");function l(){let r=a();if(!r)throw new Error("Xverse is not injected. Please check your wallet.");return r}t(l,"getInstanceOrThrow");function p(){let e=a()?.get(f);if(!e)throw new Error("Xverse not injected. Please check your wallet.");return e}t(p,"bitcoinXverse");async function g(){let e=await p().request("wallet_connect",{addresses:["payment"],network:"Mainnet"});if(e.error?.message)throw new Error(e.error.message);return e}t(g,"getBitcoinAccounts");var h=1e3,E=-32002,s="xverse",b={name:"xverse",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/xverse/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/idnnbdplmphpflfnlkomgpfbpcgelopg",homepage:"https://www.xverse.app/"},properties:[{name:"namespaces",value:{selection:"single",data:[{label:"BTC",value:"UTXO",id:"BTC",isChainSupported:O([X])}]}},{name:"signers",value:{getSigners:async()=>m(l())}}]};import{builders as P}from"@hub3js/bip122";import{NamespaceBuilder as W}from"@hub3js/core";import*as x from"@hub3js/std/builders";import{standardizeAndThrowError as q}from"@hub3js/std/operators";import{CAIP_BITCOIN_CHAIN_ID as L,utils as j}from"@hub3js/bip122";function U(){return async()=>{let r=await g();if(r.result?.addresses?.length===0)throw new Error("Couldn't find any address!");return j.formatAccountsToCAIP(r.result.addresses.map(e=>e.address),L)}}t(U,"connect");function M(r){return async()=>{try{let e=await r().request("getAddresses",{purposes:["payment"]});return e.error?.code===E?!1:!!e.result?.addresses?.length}catch{return!1}}}t(M,"canEagerConnect");var u={connect:U,canEagerConnect:M};import{builders as V,CAIP_BITCOIN_CHAIN_ID as v,utils as k}from"@hub3js/bip122";var F=t(r=>V.changeAccountSubscriber(r,{network:v}).onSwitchAccount(e=>{e.payload?.addresses?.length||e.preventDefault()}).format(async(e,o)=>k.formatAccountsToCAIP(o.addresses.filter(n=>n.purpose==="payment").map(n=>n.address),v)).addEventListener((e,o)=>e.addListener("accountChange",o)).removeEventListener((e,o)=>{}),"changeAccountSubscriber"),A={changeAccountSubscriber:F};var[H,w]=A.changeAccountSubscriber(p).build(),G=P.canEagerConnect().action(u.canEagerConnect(p)).build(),J=P.connect().action(u.connect()).before(H).or(w).or(q).build(),Y=x.disconnect().after(w).build(),I=new W("UTXO",s).action(J).action(Y).action(G).build();var C=t(()=>new z(s).init(function(r){let[,e]=r.state();setTimeout(()=>{a()&&(e("installed",!0),console.debug("[xverse] instance detected.",r))},h)}).config("metadata",b).add("utxo",I).build(),"buildProvider");var Ue=t(()=>$().version("1.0.0",C()).build(),"versions");export{s as WALLET_ID,Ue as versions};
2
2
  //# sourceMappingURL=mod.js.map
package/dist/mod.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/mod.ts", "../src/provider.ts", "../src/constants.ts", "../src/signer.ts", "../src/signers/utxoSigner.ts", "../src/utils.ts", "../src/namespaces/utxo.ts", "../src/builders/utxo.ts"],
4
- "sourcesContent": ["import { defineVersions } from '@hub3js/core/utils';\n\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\nexport { WALLET_ID } from './constants.js';\n", "import { ProviderBuilder } from '@hub3js/core';\n\nimport { metadata, WALLET_ID, XVERSE_INJECTION_DELAY_MS } from './constants.js';\nimport { utxo } from './namespaces/utxo.js';\nimport { xverse as unisatInstance } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n // TODO: We should remove this after we solved not initiating issue.\n setTimeout(() => {\n if (unisatInstance()) {\n setState('installed', true);\n console.debug('[xverse] instance detected.', context);\n }\n }, XVERSE_INJECTION_DELAY_MS);\n })\n .config('metadata', metadata)\n .add('utxo', utxo)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport { getChainIdFromCaip2ChainId } from '@hub3js/std/utils';\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n isUtxoNamespace,\n} from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const XVERSE_INJECTION_DELAY_MS = 1000;\nexport const XVERSE_ACCESS_DENIED_ERROR_CODE = -32002;\nexport const WALLET_ID = 'xverse';\n\nexport const metadata: ProviderMetadata = {\n name: 'xverse',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/xverse/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/idnnbdplmphpflfnlkomgpfbpcgelopg',\n homepage: 'https://www.xverse.app/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'single',\n data: [\n {\n label: 'BTC',\n value: 'UTXO',\n id: 'BTC',\n isChainSupported: (chainId: string) =>\n isUtxoNamespace(chainId) &&\n getChainIdFromCaip2ChainId(chainId) === 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 { UTXO_NAMESPACE } from '@hub3js/namespaces';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { BTCSigner } from './signers/utxoSigner.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const bitcoinInstance = provider.get(UTXO_NAMESPACE);\n\n const signers = new DefaultSignerFactory();\n if (!!bitcoinInstance) {\n signers.registerSigner(TxType.TRANSFER, new BTCSigner(bitcoinInstance));\n }\n return signers;\n}\n", "import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';\nimport type { GenericSigner, Transfer } from 'rango-types';\n\nimport { isBitcoinBlockchain } from '@rango-dev/internal-blockchains';\nimport { SignerError } from 'rango-types';\n\nexport class BTCSigner 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\n // 2. Build sign inputs\n const signInputs: Record<string, number[]> = {};\n\n psbt.inputsToSign.forEach(({ address, signingIndexes }) => {\n signInputs[address] = signingIndexes;\n });\n\n // 3. Sign (& broadcast)\n const signPsbtResult = await this.provider.request('signPsbt', {\n psbt: psbt.unsignedPsbtBase64,\n signInputs,\n broadcast: true,\n });\n\n if (signPsbtResult?.error) {\n throw new Error(\n signPsbtResult.error.message || 'Error during transaction sign'\n );\n }\n if (!signPsbtResult?.result?.txid) {\n throw new Error('Transaction not found!');\n }\n\n return { hash: signPsbtResult.result.txid };\n }\n}\n", "import type { Provider, XVerseResponse } from './types.js';\nimport type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { UTXO_NAMESPACE } from '@hub3js/namespaces';\n\nexport function xverse(): Provider | null {\n const { XverseProviders } = window;\n\n if (!XverseProviders) {\n return null;\n }\n\n const instances: Provider = new Map();\n\n if (XverseProviders.BitcoinProvider) {\n instances.set(UTXO_NAMESPACE, XverseProviders.BitcoinProvider);\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = xverse();\n\n if (!instances) {\n throw new Error('Xverse is not injected. Please check your wallet.');\n }\n\n return instances;\n}\n\nexport function bitcoinXverse(): ProviderAPI {\n const instances = xverse();\n const bitcoinInstance = instances?.get(UTXO_NAMESPACE);\n\n if (!bitcoinInstance) {\n throw new Error('Xverse not injected. Please check your wallet.');\n }\n\n return bitcoinInstance;\n}\nexport async function getBitcoinAccounts(): Promise<XVerseResponse> {\n const instance = bitcoinXverse();\n const requestResult = await instance.request('wallet_connect', {\n addresses: ['payment'],\n network: 'Mainnet',\n });\n\n if (requestResult.error?.message) {\n throw new Error(requestResult.error.message);\n }\n\n return requestResult;\n}\n", "import { NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n utils,\n type UtxoActions,\n} from '@rango-dev/wallets-core/namespaces/utxo';\nimport { builders } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { utxoBuilders } from '../builders/utxo.js';\nimport { WALLET_ID } from '../constants.js';\nimport { bitcoinXverse, getBitcoinAccounts } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = utxoBuilders\n .changeAccountSubscriber(bitcoinXverse)\n .build();\n\nconst canEagerConnect = utxoBuilders.canEagerConnect(bitcoinXverse).build();\n\nconst connect = builders\n .connect()\n .action(async function () {\n const accountsResult = await getBitcoinAccounts();\n\n if (accountsResult.result?.addresses?.length === 0) {\n throw new Error(\"Couldn't find any address!\");\n }\n return utils.formatAccountsToCAIP(\n accountsResult.result.addresses.map((address) => address.address),\n CAIP_BITCOIN_CHAIN_ID\n );\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<UtxoActions>()\n .after(changeAccountCleanup)\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 { XVerseEvent } from '../types.js';\n\nimport { ActionBuilder } from '@hub3js/core';\nimport { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n type ProviderAPI,\n utils,\n type UtxoActions,\n} from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { XVERSE_ACCESS_DENIED_ERROR_CODE } from '../constants.js';\n\nexport const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>\n new ChangeAccountSubscriberBuilder<XVerseEvent, ProviderAPI, UtxoActions>()\n .getInstance(getInstance)\n /*\n * Xverse wallet may call the `changeAccount` event with `empty` value\n * but we shouldn't disconnect in this case.\n */\n .onSwitchAccount((event) => {\n if (!event.payload?.addresses?.length) {\n event.preventDefault();\n }\n })\n .format(async (_, event) => {\n return utils.formatAccountsToCAIP(\n event.addresses\n .filter((address) => address.purpose === 'payment')\n .map((address) => address.address),\n CAIP_BITCOIN_CHAIN_ID\n );\n })\n .addEventListener((instance, callback) => {\n return instance.addListener('accountChange', callback);\n })\n .removeEventListener((_, __) => {\n // it will be removed by the main class\n });\n\nfunction canEagerConnect(getInstance: () => ProviderAPI) {\n return new ActionBuilder<UtxoActions, 'canEagerConnect'>(\n 'canEagerConnect'\n ).action(async () => {\n const instance = getInstance();\n try {\n const addressesResponse = await instance.request('getAddresses', {\n purposes: ['payment'],\n });\n if (addressesResponse.error?.code === XVERSE_ACCESS_DENIED_ERROR_CODE) {\n return false;\n }\n return !!addressesResponse.result?.addresses?.length;\n } catch {\n return false;\n }\n });\n}\n\nexport const utxoBuilders = { changeAccountSubscriber, canEagerConnect };\n"],
5
- "mappings": "+EAAA,OAAS,kBAAAA,MAAsB,qBCA/B,OAAS,mBAAAC,MAAuB,eCEhC,OAAS,8BAAAC,MAAkC,oBAC3C,OACE,yBAAAC,EACA,mBAAAC,MACK,0CCHP,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,wBAAAC,EAAsB,mBAAmBC,MAAc,cCDhE,OAAS,uBAAAC,MAA2B,kCACpC,OAAS,eAAAC,MAAmB,cAErB,IAAMC,EAAN,KAAmD,CAN1D,MAM0D,CAAAC,EAAA,kBAChD,SACR,YAAYC,EAAuB,CACjC,KAAK,SAAWA,CAClB,CAEA,MAAM,aAA+B,CACnC,MAAMC,EAAY,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,EAAoBF,EAAM,UAAU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,EAAe,IACjBD,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,8BAA+BD,CAAO,EAExD,EAAGG,CAAyB,CAC9B,CAAC,EACA,OAAO,WAAYC,CAAQ,EAC3B,IAAI,OAAQC,CAAI,EAChB,MAAM,EAdW,iBDFtB,IAAMC,GAAWC,EAAA,IACfC,EAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
- "names": ["defineVersions", "ProviderBuilder", "getChainIdFromCaip2ChainId", "CAIP_BITCOIN_CHAIN_ID", "isUtxoNamespace", "UTXO_NAMESPACE", "DefaultSignerFactory", "TxType", "isBitcoinBlockchain", "SignerError", "BTCSigner", "__name", "provider", "SignerError", "tx", "asset", "psbt", "isBitcoinBlockchain", "signInputs", "address", "signingIndexes", "signPsbtResult", "getSigners", "provider", "bitcoinInstance", "UTXO_NAMESPACE", "signers", "DefaultSignerFactory", "TxType", "BTCSigner", "__name", "UTXO_NAMESPACE", "xverse", "XverseProviders", "instances", "UTXO_NAMESPACE", "__name", "getInstanceOrThrow", "bitcoinXverse", "bitcoinInstance", "getBitcoinAccounts", "requestResult", "XVERSE_INJECTION_DELAY_MS", "XVERSE_ACCESS_DENIED_ERROR_CODE", "WALLET_ID", "metadata", "chainId", "isUtxoNamespace", "getChainIdFromCaip2ChainId", "CAIP_BITCOIN_CHAIN_ID", "getSigners", "getInstanceOrThrow", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "CAIP_BITCOIN_CHAIN_ID", "utils", "builders", "ActionBuilder", "ChangeAccountSubscriberBuilder", "CAIP_BITCOIN_CHAIN_ID", "utils", "changeAccountSubscriber", "__name", "getInstance", "ChangeAccountSubscriberBuilder", "event", "_", "utils", "address", "CAIP_BITCOIN_CHAIN_ID", "instance", "callback", "__", "canEagerConnect", "ActionBuilder", "addressesResponse", "XVERSE_ACCESS_DENIED_ERROR_CODE", "utxoBuilders", "changeAccountSubscriber", "changeAccountCleanup", "utxoBuilders", "bitcoinXverse", "canEagerConnect", "connect", "builders", "accountsResult", "getBitcoinAccounts", "utils", "address", "CAIP_BITCOIN_CHAIN_ID", "standardizeAndThrowError", "disconnect", "utxo", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "xverse", "XVERSE_INJECTION_DELAY_MS", "metadata", "utxo", "versions", "__name", "defineVersions", "buildProvider"]
3
+ "sources": ["../src/mod.ts", "../src/provider.ts", "../src/constants.ts", "../src/signer.ts", "../src/signers/utxoSigner.ts", "../src/utils.ts", "../src/namespaces/utxo.ts", "../src/actions/utxo.ts", "../src/builders/utxo.ts"],
4
+ "sourcesContent": ["import { defineVersions } from '@hub3js/core/utils';\n\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\nexport { WALLET_ID } from './constants.js';\n", "import { ProviderBuilder } from '@hub3js/core';\n\nimport { metadata, WALLET_ID, XVERSE_INJECTION_DELAY_MS } from './constants.js';\nimport { utxo } from './namespaces/utxo.js';\nimport { xverse as unisatInstance } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n // TODO: We should remove this after we solved not initiating issue.\n setTimeout(() => {\n if (unisatInstance()) {\n setState('installed', true);\n console.debug('[xverse] instance detected.', context);\n }\n }, XVERSE_INJECTION_DELAY_MS);\n })\n .config('metadata', metadata)\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';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const XVERSE_INJECTION_DELAY_MS = 1000;\nexport const XVERSE_ACCESS_DENIED_ERROR_CODE = -32002;\nexport const WALLET_ID = 'xverse';\n\nexport const metadata: ProviderMetadata = {\n name: 'xverse',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/xverse/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/idnnbdplmphpflfnlkomgpfbpcgelopg',\n homepage: 'https://www.xverse.app/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'single',\n data: [\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 { UTXO_NAMESPACE } from '@hub3js/namespaces';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { BTCSigner } from './signers/utxoSigner.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const bitcoinInstance = provider.get(UTXO_NAMESPACE);\n\n const signers = new DefaultSignerFactory();\n if (!!bitcoinInstance) {\n signers.registerSigner(TxType.TRANSFER, new BTCSigner(bitcoinInstance));\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 { SignerError } from 'rango-types';\n\nexport class BTCSigner 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\n // 2. Build sign inputs\n const signInputs: Record<string, number[]> = {};\n\n psbt.inputsToSign.forEach(({ address, signingIndexes }) => {\n signInputs[address] = signingIndexes;\n });\n\n // 3. Sign (& broadcast)\n const signPsbtResult = await this.provider.request('signPsbt', {\n psbt: psbt.unsignedPsbtBase64,\n signInputs,\n broadcast: true,\n });\n\n if (signPsbtResult?.error) {\n throw new Error(\n signPsbtResult.error.message || 'Error during transaction sign'\n );\n }\n if (!signPsbtResult?.result?.txid) {\n throw new Error('Transaction not found!');\n }\n\n return { hash: signPsbtResult.result.txid };\n }\n}\n", "import type { Provider, XVerseResponse } from './types.js';\nimport type { ProviderAPI } from '@hub3js/bip122';\n\nimport { UTXO_NAMESPACE } from '@hub3js/namespaces';\n\nexport function xverse(): Provider | null {\n const { XverseProviders } = window;\n\n if (!XverseProviders) {\n return null;\n }\n\n const instances: Provider = new Map();\n\n if (XverseProviders.BitcoinProvider) {\n instances.set(UTXO_NAMESPACE, XverseProviders.BitcoinProvider);\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = xverse();\n\n if (!instances) {\n throw new Error('Xverse is not injected. Please check your wallet.');\n }\n\n return instances;\n}\n\nexport function bitcoinXverse(): ProviderAPI {\n const instances = xverse();\n const bitcoinInstance = instances?.get(UTXO_NAMESPACE);\n\n if (!bitcoinInstance) {\n throw new Error('Xverse not injected. Please check your wallet.');\n }\n\n return bitcoinInstance;\n}\nexport async function getBitcoinAccounts(): Promise<XVerseResponse> {\n const instance = bitcoinXverse();\n const requestResult = await instance.request('wallet_connect', {\n addresses: ['payment'],\n network: 'Mainnet',\n });\n\n if (requestResult.error?.message) {\n throw new Error(requestResult.error.message);\n }\n\n return requestResult;\n}\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 { bitcoinXverse } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] = utxoBuilders\n .changeAccountSubscriber(bitcoinXverse)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(utxoActions.canEagerConnect(bitcoinXverse))\n .build();\n\nconst connect = builders\n .connect()\n .action(utxoActions.connect())\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<UtxoActions>()\n .after(changeAccountCleanup)\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\nimport { XVERSE_ACCESS_DENIED_ERROR_CODE } from '../constants.js';\nimport { getBitcoinAccounts } from '../utils.js';\n\nexport function connect(): FunctionWithContext<\n UtxoActions['connect'],\n Context\n> {\n return async () => {\n const accountsResult = await getBitcoinAccounts();\n\n if (accountsResult.result?.addresses?.length === 0) {\n throw new Error(\"Couldn't find any address!\");\n }\n\n return utils.formatAccountsToCAIP(\n accountsResult.result.addresses.map((address) => address.address),\n CAIP_BITCOIN_CHAIN_ID\n );\n };\n}\n\n// No silent connect: ask for addresses and read the access-denied code instead.\nexport function canEagerConnect(\n instance: () => ProviderAPI\n): CanEagerConnect<UtxoActions> {\n return async () => {\n try {\n const addressesResponse = await instance().request('getAddresses', {\n purposes: ['payment'],\n });\n\n if (addressesResponse.error?.code === XVERSE_ACCESS_DENIED_ERROR_CODE) {\n return false;\n }\n\n return !!addressesResponse.result?.addresses?.length;\n } catch {\n return false;\n }\n };\n}\n\nexport const utxoActions = { connect, canEagerConnect };\n", "import type { XVerseEvent } from '../types.js';\nimport 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<XVerseEvent>(getInstance, {\n network: CAIP_BITCOIN_CHAIN_ID,\n })\n /*\n * Xverse wallet may call the `changeAccount` event with `empty` value\n * but we shouldn't disconnect in this case.\n */\n .onSwitchAccount((event) => {\n if (!event.payload?.addresses?.length) {\n event.preventDefault();\n }\n })\n .format(async (_, event) => {\n return utils.formatAccountsToCAIP(\n event.addresses\n .filter((address) => address.purpose === 'payment')\n .map((address) => address.address),\n CAIP_BITCOIN_CHAIN_ID\n );\n })\n .addEventListener((instance, callback) => {\n return instance.addListener('accountChange', callback);\n })\n .removeEventListener((_, __) => {\n // it will be removed by the main class\n });\n\nexport const utxoBuilders = { changeAccountSubscriber };\n"],
5
+ "mappings": "+EAAA,OAAS,kBAAAA,MAAsB,qBCA/B,OAAS,mBAAAC,MAAuB,eCEhC,OACE,yBAAAC,EACA,oBAAoBC,MACf,iBCFP,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,wBAAAC,EAAsB,mBAAmBC,MAAc,cCDhE,OAAS,uBAAAC,MAA2B,kCACpC,OAAS,eAAAC,MAAmB,cAErB,IAAMC,EAAN,KAAmD,CAN1D,MAM0D,CAAAC,EAAA,kBAChD,SACR,YAAYC,EAAuB,CACjC,KAAK,SAAWA,CAClB,CAEA,MAAM,aAA+B,CACnC,MAAMC,EAAY,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,EAAoBF,EAAM,UAAU,EACvC,MAAM,IAAI,MACR,WAAWA,EAAM,UAAU,gDAC7B,EAIF,IAAMG,EAAuC,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,MAAM,8BAA+BD,CAAO,EAExD,EAAGG,CAAyB,CAC9B,CAAC,EACA,OAAO,WAAYC,CAAQ,EAC3B,IAAI,OAAQC,CAAI,EAChB,MAAM,EAdW,iBDFtB,IAAMC,GAAWC,EAAA,IACfC,EAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
+ "names": ["defineVersions", "ProviderBuilder", "CAIP_BITCOIN_CHAIN_ID", "isBip122ChainSupported", "UTXO_NAMESPACE", "DefaultSignerFactory", "TxType", "isBitcoinBlockchain", "SignerError", "BTCSigner", "__name", "provider", "SignerError", "tx", "asset", "psbt", "isBitcoinBlockchain", "signInputs", "address", "signingIndexes", "signPsbtResult", "getSigners", "provider", "bitcoinInstance", "UTXO_NAMESPACE", "signers", "DefaultSignerFactory", "TxType", "BTCSigner", "__name", "UTXO_NAMESPACE", "xverse", "XverseProviders", "instances", "UTXO_NAMESPACE", "__name", "getInstanceOrThrow", "bitcoinXverse", "bitcoinInstance", "getBitcoinAccounts", "requestResult", "XVERSE_INJECTION_DELAY_MS", "XVERSE_ACCESS_DENIED_ERROR_CODE", "WALLET_ID", "metadata", "isBip122ChainSupported", "CAIP_BITCOIN_CHAIN_ID", "getSigners", "getInstanceOrThrow", "builders", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "CAIP_BITCOIN_CHAIN_ID", "utils", "connect", "accountsResult", "getBitcoinAccounts", "utils", "address", "CAIP_BITCOIN_CHAIN_ID", "__name", "canEagerConnect", "instance", "addressesResponse", "XVERSE_ACCESS_DENIED_ERROR_CODE", "utxoActions", "builders", "CAIP_BITCOIN_CHAIN_ID", "utils", "changeAccountSubscriber", "__name", "getInstance", "builders", "CAIP_BITCOIN_CHAIN_ID", "event", "_", "utils", "address", "instance", "callback", "__", "utxoBuilders", "changeAccountSubscriber", "changeAccountCleanup", "utxoBuilders", "bitcoinXverse", "canEagerConnect", "builders", "utxoActions", "connect", "standardizeAndThrowError", "disconnect", "utxo", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "xverse", "XVERSE_INJECTION_DELAY_MS", "metadata", "utxo", "versions", "__name", "defineVersions", "buildProvider"]
7
7
  }
@@ -1,4 +1,4 @@
1
- import { type UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
1
+ import type { UtxoActions } from '@hub3js/bip122';
2
2
  declare const utxo: import("@hub3js/core").ProxiedNamespace<UtxoActions>;
3
3
  export { utxo };
4
4
  //# sourceMappingURL=utxo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/namespaces/utxo.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,yCAAyC,CAAC;AAoCjD,QAAA,MAAM,IAAI,sDAIA,CAAC;AAEX,OAAO,EAAE,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/namespaces/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAkClD,QAAA,MAAM,IAAI,sDAIA,CAAC;AAEX,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -1,3 +1,3 @@
1
- declare const buildProvider: () => import("@hub3js/core").Provider<Record<"utxo", import("@rango-dev/wallets-core/namespaces/utxo").UtxoActions>>;
1
+ declare const buildProvider: () => import("@hub3js/core").Provider<Record<"utxo", import("@hub3js/bip122").UtxoActions>>;
2
2
  export { buildProvider };
3
3
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,aAAa,sHAcP,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,aAAa,6FAcP,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';
1
+ import type { ProviderAPI } from '@hub3js/bip122';
2
2
  import type { GenericSigner, Transfer } from 'rango-types';
3
3
  export declare class BTCSigner implements GenericSigner<Transfer> {
4
4
  private provider;
@@ -1 +1 @@
1
- {"version":3,"file":"utxoSigner.d.ts","sourceRoot":"","sources":["../../src/signers/utxoSigner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK3D,qBAAa,SAAU,YAAW,aAAa,CAAC,QAAQ,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAc;gBAClB,QAAQ,EAAE,WAAW;IAI3B,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAuC7D"}
1
+ {"version":3,"file":"utxoSigner.d.ts","sourceRoot":"","sources":["../../src/signers/utxoSigner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK3D,qBAAa,SAAU,YAAW,aAAa,CAAC,QAAQ,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAc;gBAClB,QAAQ,EAAE,WAAW;IAI3B,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAuC7D"}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import type { ProviderAPI } from '@hub3js/bip122';
1
2
  import type { UTXO_NAMESPACE } from '@hub3js/namespaces';
2
3
  import type { InstanceMap } from '@hub3js/std/types';
3
- import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';
4
4
  type XVerseAddress = {
5
5
  address: string;
6
6
  publicKey: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAE3E,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACrC,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,MAAM,EAAE;QACN,SAAS,EAAE,aAAa,EAAE,CAAC;QAE3B,OAAO,EAAE;YACP,OAAO,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAA;aAAE,CAAC;YAC7B,KAAK,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAA;aAAE,CAAC;YAC3B,MAAM,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAA;aAAE,CAAC;SAC7B,CAAC;KACH,CAAC;CACH,CAAC;AACF,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,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Q,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Provider, XVerseResponse } from './types.js';
2
- import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';
2
+ import type { ProviderAPI } from '@hub3js/bip122';
3
3
  export declare function xverse(): Provider | null;
4
4
  export declare function getInstanceOrThrow(): Provider;
5
5
  export declare function bitcoinXverse(): ProviderAPI;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAI3E,wBAAgB,MAAM,IAAI,QAAQ,GAAG,IAAI,CAcxC;AAED,wBAAgB,kBAAkB,IAAI,QAAQ,CAQ7C;AAED,wBAAgB,aAAa,IAAI,WAAW,CAS3C;AACD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,cAAc,CAAC,CAYlE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,wBAAgB,MAAM,IAAI,QAAQ,GAAG,IAAI,CAcxC;AAED,wBAAgB,kBAAkB,IAAI,QAAQ,CAQ7C;AAED,wBAAgB,aAAa,IAAI,WAAW,CAS3C;AACD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,cAAc,CAAC,CAYlE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-xverse",
3
- "version": "0.8.1-next.3",
3
+ "version": "0.8.1-next.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/mod.ts",
@@ -21,11 +21,12 @@
21
21
  "lint": "eslint \"**/*.{ts,tsx}\""
22
22
  },
23
23
  "dependencies": {
24
- "@hub3js/core": "^0.61.1",
25
- "@hub3js/namespaces": "^0.3.0",
26
- "@hub3js/std": "^0.3.0",
27
- "@rango-dev/internal-blockchains": "^0.1.1-next.0",
28
- "@rango-dev/wallets-core": "^0.61.1-next.0",
24
+ "@hub3js/bip122": "^0.2.1",
25
+ "@hub3js/core": "^0.62.0",
26
+ "@hub3js/namespaces": "^0.5.1",
27
+ "@hub3js/std": "^0.4.0",
28
+ "@rango-dev/internal-blockchains": "^0.1.1-next.2",
29
+ "@rango-dev/wallets-core": "^0.61.1-next.2",
29
30
  "rango-types": "^0.5.0"
30
31
  },
31
32
  "publishConfig": {
@@ -0,0 +1,52 @@
1
+ import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';
2
+ import type {
3
+ CanEagerConnect,
4
+ Context,
5
+ FunctionWithContext,
6
+ } from '@hub3js/core';
7
+
8
+ import { CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';
9
+
10
+ import { XVERSE_ACCESS_DENIED_ERROR_CODE } from '../constants.js';
11
+ import { getBitcoinAccounts } from '../utils.js';
12
+
13
+ export function connect(): FunctionWithContext<
14
+ UtxoActions['connect'],
15
+ Context
16
+ > {
17
+ return async () => {
18
+ const accountsResult = await getBitcoinAccounts();
19
+
20
+ if (accountsResult.result?.addresses?.length === 0) {
21
+ throw new Error("Couldn't find any address!");
22
+ }
23
+
24
+ return utils.formatAccountsToCAIP(
25
+ accountsResult.result.addresses.map((address) => address.address),
26
+ CAIP_BITCOIN_CHAIN_ID
27
+ );
28
+ };
29
+ }
30
+
31
+ // No silent connect: ask for addresses and read the access-denied code instead.
32
+ export function canEagerConnect(
33
+ instance: () => ProviderAPI
34
+ ): CanEagerConnect<UtxoActions> {
35
+ return async () => {
36
+ try {
37
+ const addressesResponse = await instance().request('getAddresses', {
38
+ purposes: ['payment'],
39
+ });
40
+
41
+ if (addressesResponse.error?.code === XVERSE_ACCESS_DENIED_ERROR_CODE) {
42
+ return false;
43
+ }
44
+
45
+ return !!addressesResponse.result?.addresses?.length;
46
+ } catch {
47
+ return false;
48
+ }
49
+ };
50
+ }
51
+
52
+ export const utxoActions = { connect, canEagerConnect };
@@ -1,19 +1,13 @@
1
1
  import type { XVerseEvent } from '../types.js';
2
+ import type { ProviderAPI } from '@hub3js/bip122';
2
3
 
3
- import { ActionBuilder } from '@hub3js/core';
4
- import { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';
5
- import {
6
- CAIP_BITCOIN_CHAIN_ID,
7
- type ProviderAPI,
8
- utils,
9
- type UtxoActions,
10
- } from '@rango-dev/wallets-core/namespaces/utxo';
11
-
12
- import { XVERSE_ACCESS_DENIED_ERROR_CODE } from '../constants.js';
4
+ import { builders, CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';
13
5
 
14
6
  export const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
15
- new ChangeAccountSubscriberBuilder<XVerseEvent, ProviderAPI, UtxoActions>()
16
- .getInstance(getInstance)
7
+ builders
8
+ .changeAccountSubscriber<XVerseEvent>(getInstance, {
9
+ network: CAIP_BITCOIN_CHAIN_ID,
10
+ })
17
11
  /*
18
12
  * Xverse wallet may call the `changeAccount` event with `empty` value
19
13
  * but we shouldn't disconnect in this case.
@@ -38,23 +32,4 @@ export const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
38
32
  // it will be removed by the main class
39
33
  });
40
34
 
41
- function canEagerConnect(getInstance: () => ProviderAPI) {
42
- return new ActionBuilder<UtxoActions, 'canEagerConnect'>(
43
- 'canEagerConnect'
44
- ).action(async () => {
45
- const instance = getInstance();
46
- try {
47
- const addressesResponse = await instance.request('getAddresses', {
48
- purposes: ['payment'],
49
- });
50
- if (addressesResponse.error?.code === XVERSE_ACCESS_DENIED_ERROR_CODE) {
51
- return false;
52
- }
53
- return !!addressesResponse.result?.addresses?.length;
54
- } catch {
55
- return false;
56
- }
57
- });
58
- }
59
-
60
- export const utxoBuilders = { changeAccountSubscriber, canEagerConnect };
35
+ export const utxoBuilders = { changeAccountSubscriber };
package/src/constants.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import type { ProviderMetadata } from '@hub3js/core';
2
2
 
3
- import { getChainIdFromCaip2ChainId } from '@hub3js/std/utils';
4
3
  import {
5
4
  CAIP_BITCOIN_CHAIN_ID,
6
- isUtxoNamespace,
7
- } from '@rango-dev/wallets-core/namespaces/utxo';
5
+ isChainSupported as isBip122ChainSupported,
6
+ } from '@hub3js/bip122';
8
7
 
9
8
  import getSigners from './signer.js';
10
9
  import { getInstanceOrThrow } from './utils.js';
@@ -31,9 +30,7 @@ export const metadata: ProviderMetadata = {
31
30
  label: 'BTC',
32
31
  value: 'UTXO',
33
32
  id: 'BTC',
34
- isChainSupported: (chainId: string) =>
35
- isUtxoNamespace(chainId) &&
36
- getChainIdFromCaip2ChainId(chainId) === CAIP_BITCOIN_CHAIN_ID,
33
+ isChainSupported: isBip122ChainSupported([CAIP_BITCOIN_CHAIN_ID]),
37
34
  },
38
35
  ],
39
36
  },
@@ -1,36 +1,27 @@
1
+ import type { UtxoActions } from '@hub3js/bip122';
2
+
3
+ import { builders } from '@hub3js/bip122';
1
4
  import { NamespaceBuilder } from '@hub3js/core';
2
5
  import * as commonBuilders from '@hub3js/std/builders';
3
6
  import { standardizeAndThrowError } from '@hub3js/std/operators';
4
- import {
5
- CAIP_BITCOIN_CHAIN_ID,
6
- utils,
7
- type UtxoActions,
8
- } from '@rango-dev/wallets-core/namespaces/utxo';
9
- import { builders } from '@rango-dev/wallets-core/namespaces/utxo';
10
7
 
8
+ import { utxoActions } from '../actions/utxo.js';
11
9
  import { utxoBuilders } from '../builders/utxo.js';
12
10
  import { WALLET_ID } from '../constants.js';
13
- import { bitcoinXverse, getBitcoinAccounts } from '../utils.js';
11
+ import { bitcoinXverse } from '../utils.js';
14
12
 
15
13
  const [changeAccountSubscriber, changeAccountCleanup] = utxoBuilders
16
14
  .changeAccountSubscriber(bitcoinXverse)
17
15
  .build();
18
16
 
19
- const canEagerConnect = utxoBuilders.canEagerConnect(bitcoinXverse).build();
17
+ const canEagerConnect = builders
18
+ .canEagerConnect()
19
+ .action(utxoActions.canEagerConnect(bitcoinXverse))
20
+ .build();
20
21
 
21
22
  const connect = builders
22
23
  .connect()
23
- .action(async function () {
24
- const accountsResult = await getBitcoinAccounts();
25
-
26
- if (accountsResult.result?.addresses?.length === 0) {
27
- throw new Error("Couldn't find any address!");
28
- }
29
- return utils.formatAccountsToCAIP(
30
- accountsResult.result.addresses.map((address) => address.address),
31
- CAIP_BITCOIN_CHAIN_ID
32
- );
33
- })
24
+ .action(utxoActions.connect())
34
25
  .before(changeAccountSubscriber)
35
26
  .or(changeAccountCleanup)
36
27
  .or(standardizeAndThrowError)
@@ -1,4 +1,4 @@
1
- import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';
1
+ import type { ProviderAPI } from '@hub3js/bip122';
2
2
  import type { GenericSigner, Transfer } from 'rango-types';
3
3
 
4
4
  import { isBitcoinBlockchain } from '@rango-dev/internal-blockchains';
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import type { ProviderAPI } from '@hub3js/bip122';
1
2
  import type { UTXO_NAMESPACE } from '@hub3js/namespaces';
2
3
  import type { InstanceMap } from '@hub3js/std/types';
3
- import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';
4
4
 
5
5
  type XVerseAddress = {
6
6
  address: string;
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Provider, XVerseResponse } from './types.js';
2
- import type { ProviderAPI } from '@rango-dev/wallets-core/namespaces/utxo';
2
+ import type { ProviderAPI } from '@hub3js/bip122';
3
3
 
4
4
  import { UTXO_NAMESPACE } from '@hub3js/namespaces';
5
5