@rango-dev/provider-unisat 0.1.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/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/legacy/index.d.ts +6 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/signer.d.ts +4 -0
- package/dist/legacy/signer.d.ts.map +1 -0
- package/dist/legacy/utxoSigner.d.ts +12 -0
- package/dist/legacy/utxoSigner.d.ts.map +1 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/namespaces/utxo.d.ts +4 -0
- package/dist/namespaces/utxo.d.ts.map +1 -0
- package/dist/provider-unisat.build.json +1 -0
- package/dist/provider.d.ts +3 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +31 -0
- package/readme.md +21 -0
- package/src/constants.ts +36 -0
- package/src/legacy/index.ts +70 -0
- package/src/legacy/signer.ts +16 -0
- package/src/legacy/utxoSigner.ts +97 -0
- package/src/mod.ts +12 -0
- package/src/namespaces/utxo.ts +139 -0
- package/src/provider.ts +21 -0
- package/src/utils.ts +32 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,eAAO,MAAM,IAAI,EAAE,YA4BlB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
2
|
+
import { unisat as unisat_instance } from '../utils.js';
|
|
3
|
+
export declare const getInstance: typeof unisat_instance;
|
|
4
|
+
declare const buildLegacyProvider: () => LegacyProviderInterface;
|
|
5
|
+
export { buildLegacyProvider };
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/legacy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAW9E,OAAO,EAAiB,MAAM,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AAQvE,eAAO,MAAM,WAAW,wBAAkB,CAAC;AAwC3C,QAAA,MAAM,mBAAmB,EAAE,MAAM,uBAQ/B,CAAC;AAEH,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/legacy/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,wBAA8B,UAAU,CACtC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,aAAa,CAAC,CAMxB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GenericSigner, Transfer } from 'rango-types';
|
|
2
|
+
type TransferExternalProvider = any;
|
|
3
|
+
export declare class BTCSigner implements GenericSigner<Transfer> {
|
|
4
|
+
private provider;
|
|
5
|
+
constructor(provider: TransferExternalProvider);
|
|
6
|
+
signMessage(): Promise<string>;
|
|
7
|
+
signAndSendTx(tx: Transfer): Promise<{
|
|
8
|
+
hash: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=utxoSigner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utxoSigner.d.ts","sourceRoot":"","sources":["../../src/legacy/utxoSigner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ3D,KAAK,wBAAwB,GAAG,GAAG,CAAC;AAIpC,qBAAa,SAAU,YAAW,aAAa,CAAC,QAAQ,CAAC;IACvD,OAAO,CAAC,QAAQ,CAA2B;gBAC/B,QAAQ,EAAE,wBAAwB;IAIxC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CA0E7D"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,QAAQ,kEAIF,CAAC;AAEb,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var w=Object.defineProperty;var r=(e,t)=>w(e,"name",{value:t,configurable:!0});var _=(e,t)=>()=>(e&&(t=e(e=0)),t);var F=(e,t)=>{for(var o in t)w(e,o,{get:t[o],enumerable:!0})};var v={};F(v,{BTCSigner:()=>h});import{parseErrorAndThrowStandardizeError as R}from"@rango-dev/wallets-core/namespaces/common";import{Networks as W}from"@rango-dev/wallets-shared";import*as P from"bitcoinjs-lib";import{SignerError as D}from"rango-types";var H,h,A=_(()=>{"use strict";H="https://go.getblock.io/f37bad28a991436483c0a3679a3acbee",h=class{static{r(this,"BTCSigner")}provider;constructor(t){this.provider=t}async signMessage(){throw D.UnimplementedError("signMessage")}async signAndSendTx(t){let{asset:o,psbt:n}=t;if(!n)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");if(o.blockchain!==W.BTC)throw new Error(`Signing ${o.blockchain} transaction is not implemented by the signer.`);if((await this.provider.getChain())?.enum!=="BITCOIN_MAINNET")throw new Error("Switch your network to Bitcoin to proceed swap.");let d=Buffer.from(n.unsignedPsbtBase64,"base64").toString("hex"),m=n.inputsToSign.flatMap(({address:c,signingIndexes:M})=>M.map(U=>({index:U,address:c}))),l=await this.provider.signPsbt(d,{autoFinalized:!0,toSignInputs:m}).catch(c=>{R(c)}),L=P.Psbt.fromHex(l).extractTransaction().toHex(),f=await fetch(H,{method:"POST",body:JSON.stringify({method:"sendrawtransaction",params:[L]})});if(!f.ok){let c=await f.text();throw new Error(`Error broadcasting transaction: ${c}`)}let u=await f.json();if(!u.result)throw new Error(`Error broadcasting transaction. Error Code ${u.error.code}: ${u.error.message}`);return{hash:u.result}}}});import{defineVersions as st}from"@rango-dev/wallets-core/utils";import{LegacyNetworks as C}from"@rango-dev/wallets-core/legacy";import"rango-types";import"@rango-dev/wallets-core";import{Networks as O}from"@rango-dev/wallets-shared";var s="unisat",a={name:"UniSat",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/unisat/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/unisat-wallet/ppbibelpcjmhbdihakflkdcoccbgbkpo",homepage:"https://unisat.io/"},properties:[{name:"namespaces",value:{selection:"single",data:[{label:"BTC",value:"UTXO",id:"BTC",getSupportedChains:e=>e.filter(t=>t.name===O.BTC)}]}}]};import{LegacyNetworks as T}from"@rango-dev/wallets-core/legacy";function p(){let{unisat:e}=window;if(!e)return null;let t=new Map;return e&&t.set(T.BTC,e),t}r(p,"unisat");function g(){let t=p()?.get(T.BTC);if(!t)throw new Error("UniSat not injected. Please check your wallet.");return t}r(g,"bitcoinUnisat");import{LegacyNetworks as j}from"@rango-dev/wallets-core/legacy";import{getNetworkInstance as $}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as z,TransactionType as X}from"rango-types";async function b(e){let t=$(e,j.BTC),{BTCSigner:o}=await Promise.resolve().then(()=>(A(),v)),n=new z;return n.registerSigner(X.TRANSFER,new o(t)),n}r(b,"getSigners");var G={type:s},q=p,J=r(e=>{let t=[],o=e.find(n=>n.name===C.BTC);return o&&t.push(o),{name:a.name,img:a.icon,installLink:{CHROME:a.extensions.chrome,DEFAULT:a.extensions.homepage||""},color:"#e9983d",needsNamespace:{selection:"multiple",data:[{label:"BTC",value:"UTXO",id:"BTC",getSupportedChains:n=>n.filter(i=>i.name===C.BTC)}]},supportedChains:t}},"getWalletInfo"),V=b,x=r(()=>({config:G,getWalletInfo:J,connect:async()=>[],getInstance:q,getSigners:V}),"buildLegacyProvider");import{ProviderBuilder as at}from"@rango-dev/wallets-core";import{NamespaceBuilder as K}from"@rango-dev/wallets-core";import{standardizeAndThrowError as Q}from"@rango-dev/wallets-core/namespaces/common";import{builders as Y}from"@rango-dev/wallets-core/namespaces/common";import{builders as Z,CAIP_BITCOIN_CHAIN_ID as I,CAIP_NAMESPACE as S}from"@rango-dev/wallets-core/namespaces/utxo";import{CAIP as B}from"@rango-dev/wallets-core/utils";import{Networks as tt}from"@rango-dev/wallets-shared";var et=r(async()=>({accounts:await g().requestAccounts(),chainId:tt.BTC}),"getBitcoinAccounts");function rt(e){let t;return[(o,n)=>{let i=e();if(!i)throw new Error("Trying to subscribe to your Solana wallet, but seems its instance is not available.");let[,d]=o.state();if(t=r(m=>{if(!m.length){o.action("disconnect");return}let l=m.map(y=>B.AccountId.format({address:y,chainId:{namespace:S,reference:I}}));d("accounts",l)},"eventCallback"),i.on("accountsChanged",t),n instanceof Error)throw n},(o,n)=>{let i=e();return t&&i&&i.removeListener("accountsChanged",t),n}]}r(rt,"getChangeAccountSubscriber");var[ot,k]=rt(g),nt=Z.connect().action(async function(){let e=await et();if(Array.isArray(e))throw new Error("Expecting bitcoin response to be a single value, not an array.");return e.accounts.map(o=>B.AccountId.format({address:o,chainId:{namespace:S,reference:I}}))}).before(ot).or(k).or(Q).build(),it=Y.disconnect().after(k).build(),E=new K("UTXO",s).action(nt).action(it).build();var N=r(()=>new at(s).init(function(e){let[,t]=e.state();p()&&(t("installed",!0),console.debug("[unisat] instance detected.",e))}).config("info",a).add("utxo",E).build(),"buildProvider");var Kt=r(()=>st().version("0.0.0",x()).version("1.0.0",N()).build(),"versions");export{Kt as versions};
|
|
2
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/legacy/utxoSigner.ts", "../src/mod.ts", "../src/legacy/index.ts", "../src/constants.ts", "../src/utils.ts", "../src/legacy/signer.ts", "../src/provider.ts", "../src/namespaces/utxo.ts"],
|
|
4
|
+
"sourcesContent": ["import type { GenericSigner, Transfer } from 'rango-types';\n\nimport { parseErrorAndThrowStandardizeError } from '@rango-dev/wallets-core/namespaces/common';\nimport { Networks } from '@rango-dev/wallets-shared';\nimport * as bitcoin from 'bitcoinjs-lib';\nimport { SignerError } from 'rango-types';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype TransferExternalProvider = any;\n\nconst BTC_RPC_URL = 'https://go.getblock.io/f37bad28a991436483c0a3679a3acbee';\n\nexport class BTCSigner implements GenericSigner<Transfer> {\n private provider: TransferExternalProvider;\n constructor(provider: TransferExternalProvider) {\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 (asset.blockchain !== Networks.BTC) {\n throw new Error(\n `Signing ${asset.blockchain} transaction is not implemented by the signer.`\n );\n }\n\n /*\n * TODO this logic should be added to queue manager rango preset, for safety we are rejecting signing process to avoid asset loss.\n * https://docs.unisat.io/dev/open-api-documentation/unisat-wallet/supported-chains\n */\n const currentChain = await this.provider.getChain();\n if (currentChain?.enum !== 'BITCOIN_MAINNET') {\n throw new Error(`Switch your network to Bitcoin to proceed swap.`);\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 const signedPsbtHex = await this.provider\n .signPsbt(psbtHex, {\n autoFinalized: true,\n toSignInputs,\n })\n .catch((e: unknown) => {\n parseErrorAndThrowStandardizeError(e);\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 // 5. Broadcast PSBT to rpc node\n const response = await fetch(BTC_RPC_URL, {\n method: 'POST',\n body: JSON.stringify({\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 { defineVersions } from '@rango-dev/wallets-core/utils';\n\nimport { buildLegacyProvider } from './legacy/index.js';\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions()\n .version('0.0.0', buildLegacyProvider())\n .version('1.0.0', buildProvider())\n .build();\n\nexport { versions };\n", "import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';\nimport type { WalletInfo } from '@rango-dev/wallets-shared';\n\nimport { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';\nimport {\n type BlockchainMeta,\n type SignerFactory,\n type TransferBlockchainMeta,\n} from 'rango-types';\n\nimport { info, WALLET_ID } from '../constants.js';\nimport { type Provider, unisat as unisat_instance } from '../utils.js';\n\nimport signer from './signer.js';\n\nconst config = {\n type: WALLET_ID,\n};\n\nexport const getInstance = unisat_instance;\n\nconst getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (\n allBlockChains\n) => {\n const supportedChains: BlockchainMeta[] = [];\n const btc = allBlockChains.find((chain) => chain.name === Networks.BTC);\n if (btc) {\n supportedChains.push(btc);\n }\n\n return {\n name: info.name,\n img: info.icon,\n installLink: {\n CHROME: info.extensions.chrome,\n DEFAULT: info.extensions.homepage || '',\n },\n color: '#e9983d',\n needsNamespace: {\n selection: 'multiple',\n data: [\n {\n label: 'BTC',\n value: 'UTXO',\n id: 'BTC',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter(\n (chain): chain is TransferBlockchainMeta =>\n chain.name === Networks.BTC\n ),\n },\n ],\n },\n supportedChains,\n };\n};\n\nconst getSigners: (provider: Provider) => Promise<SignerFactory> = signer;\n\nconst buildLegacyProvider: () => LegacyProviderInterface = () => ({\n config: config,\n getWalletInfo: getWalletInfo,\n connect: async () => {\n return [];\n },\n getInstance,\n getSigners,\n});\n\nexport { buildLegacyProvider };\n", "import type { BlockchainMeta, TransferBlockchainMeta } from 'rango-types';\n\nimport { type ProviderInfo } from '@rango-dev/wallets-core';\nimport { Networks } from '@rango-dev/wallets-shared';\n\nexport const WALLET_ID = 'unisat';\n\nexport const info: ProviderInfo = {\n name: 'UniSat',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/unisat/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/unisat-wallet/ppbibelpcjmhbdihakflkdcoccbgbkpo',\n homepage: 'https://unisat.io/',\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 getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter(\n (chain): chain is TransferBlockchainMeta =>\n chain.name === Networks.BTC\n ),\n },\n ],\n },\n },\n ],\n};\n", "import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ProviderAPI = Record<string, any>;\nexport type Provider = Map<string, unknown>;\n\nexport function unisat(): Provider | null {\n const { unisat } = window;\n\n if (!unisat) {\n return null;\n }\n\n const instances: Provider = new Map();\n\n if (unisat) {\n instances.set(LegacyNetworks.BTC, unisat);\n }\n\n return instances;\n}\n\nexport function bitcoinUnisat(): ProviderAPI {\n const instances = unisat();\n const bitcoinInstance = instances?.get(LegacyNetworks.BTC);\n\n if (!bitcoinInstance) {\n throw new Error('UniSat not injected. Please check your wallet.');\n }\n\n return bitcoinInstance;\n}\n", "import type { Provider } from '../utils.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';\nimport { getNetworkInstance } from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const bitcoinInstance = getNetworkInstance(provider, Networks.BTC);\n const { BTCSigner } = await import('./utxoSigner.js');\n const signers = new DefaultSignerFactory();\n signers.registerSigner(TxType.TRANSFER, new BTCSigner(bitcoinInstance));\n return signers;\n}\n", "import { ProviderBuilder } from '@rango-dev/wallets-core';\n\nimport { info, WALLET_ID } from './constants.js';\nimport { utxo } from './namespaces/utxo.js';\nimport { unisat as unisatInstance } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n\n if (unisatInstance()) {\n setState('installed', true);\n console.debug('[unisat] instance detected.', context);\n }\n })\n .config('info', info)\n .add('utxo', utxo)\n .build();\n\nexport { buildProvider };\n", "import type {\n ProviderAPI,\n UtxoActions,\n} from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport {\n NamespaceBuilder,\n type Subscriber,\n type SubscriberCleanUp,\n} from '@rango-dev/wallets-core';\nimport {\n type CaipAccount,\n standardizeAndThrowError,\n} from '@rango-dev/wallets-core/namespaces/common';\nimport { builders as commonBuilders } from '@rango-dev/wallets-core/namespaces/common';\nimport {\n builders,\n CAIP_BITCOIN_CHAIN_ID,\n CAIP_NAMESPACE,\n} from '@rango-dev/wallets-core/namespaces/utxo';\nimport { CAIP } from '@rango-dev/wallets-core/utils';\nimport {\n Networks,\n type ProviderConnectResult,\n} from '@rango-dev/wallets-shared';\n\nimport { WALLET_ID } from '../constants.js';\nimport { bitcoinUnisat } from '../utils.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\nconst getBitcoinAccounts: () => Promise<ProviderConnectResult> = async () => {\n const instance = bitcoinUnisat();\n const accounts = await instance.requestAccounts();\n\n return {\n accounts: accounts,\n chainId: Networks.BTC,\n };\n};\n\nfunction getChangeAccountSubscriber(\n instance: () => ProviderAPI | undefined\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 Solana wallet, but seems its instance is not available.'\n );\n }\n\n const [, setState] = context.state();\n\n eventCallback = (accounts: string[]) => {\n if (!accounts.length) {\n context.action('disconnect');\n return;\n }\n\n const formatAccounts = accounts.map(\n (account) =>\n CAIP.AccountId.format({\n address: account,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_BITCOIN_CHAIN_ID,\n },\n }) as CaipAccount\n );\n\n setState('accounts', formatAccounts);\n };\n bitcoinInstance.on('accountsChanged', 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('accountsChanged', eventCallback);\n }\n\n return err;\n },\n ];\n}\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n getChangeAccountSubscriber(bitcoinUnisat);\n\nconst connect = builders\n .connect()\n .action(async function () {\n const result = await getBitcoinAccounts();\n if (Array.isArray(result)) {\n throw new Error(\n 'Expecting bitcoin response to be a single value, not an array.'\n );\n }\n\n const formatAccounts = result.accounts.map(\n (account) =>\n CAIP.AccountId.format({\n address: account,\n chainId: {\n namespace: CAIP_NAMESPACE,\n reference: CAIP_BITCOIN_CHAIN_ID,\n },\n }) as CaipAccount\n );\n\n return formatAccounts;\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 .build();\n\nexport { utxo };\n"],
|
|
5
|
+
"mappings": "gLAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAEA,OAAS,sCAAAC,MAA0C,4CACnD,OAAS,YAAAC,MAAgB,4BACzB,UAAYC,MAAa,gBACzB,OAAS,eAAAC,MAAmB,cAL5B,IAUMC,EAEOL,EAZbM,EAAAC,EAAA,kBAUMF,EAAc,0DAEPL,EAAN,KAAmD,CAZ1D,MAY0D,CAAAQ,EAAA,kBAChD,SACR,YAAYC,EAAoC,CAC9C,KAAK,SAAWA,CAClB,CAEA,MAAM,aAA+B,CACnC,MAAML,EAAY,mBAAmB,aAAa,CACpD,CAEA,MAAM,cAAcM,EAAyC,CAC3D,GAAM,CAAE,MAAAC,EAAO,KAAAC,CAAK,EAAIF,EACxB,GAAI,CAACE,EACH,MAAM,IAAI,MACR,yDACF,EAGF,GAAID,EAAM,aAAeT,EAAS,IAChC,MAAM,IAAI,MACR,WAAWS,EAAM,UAAU,gDAC7B,EAQF,IADqB,MAAM,KAAK,SAAS,SAAS,IAChC,OAAS,kBACzB,MAAM,IAAI,MAAM,iDAAiD,EAInE,IAAME,EAAU,OAAO,KAAKD,EAAK,mBAAoB,QAAQ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AUC,EACb,QAAQ,EACR,OAAO,gBAAkB,CACxB,IAAMC,EAAS,MAAMtB,GAAmB,EACxC,GAAI,MAAM,QAAQsB,CAAM,EACtB,MAAM,IAAI,MACR,gEACF,EAcF,OAXuBA,EAAO,SAAS,IACpCT,GACCC,EAAK,UAAU,OAAO,CACpB,QAASD,EACT,QAAS,CACP,UAAWE,EACX,UAAWC,CACb,CACF,CAAC,CACL,CAGF,CAAC,EACA,OAAOE,EAAuB,EAC9B,GAAGC,CAAoB,EACvB,GAAGI,CAAwB,EAC3B,MAAM,EAEHC,GAAaC,EAChB,WAAwB,EACxB,MAAMN,CAAoB,EAC1B,MAAM,EAEHO,EAAO,IAAIC,EAA8B,OAAQC,CAAS,EAC7D,OAAOR,EAAO,EACd,OAAOI,EAAU,EACjB,MAAM,EDlIT,IAAMK,EAAgBC,EAAA,IACpB,IAAIC,GAAgBC,CAAS,EAC1B,KAAK,SAAUC,EAAS,CACvB,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAE/BE,EAAe,IACjBD,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,8BAA+BD,CAAO,EAExD,CAAC,EACA,OAAO,OAAQG,CAAI,EACnB,IAAI,OAAQC,CAAI,EAChB,MAAM,EAZW,iBLDtB,IAAMC,GAAWC,EAAA,IACfC,GAAe,EACZ,QAAQ,QAASC,EAAoB,CAAC,EACtC,QAAQ,QAASC,EAAc,CAAC,EAChC,MAAM,EAJM",
|
|
6
|
+
"names": ["utxoSigner_exports", "__export", "BTCSigner", "parseErrorAndThrowStandardizeError", "Networks", "bitcoin", "SignerError", "BTC_RPC_URL", "init_utxoSigner", "__esmMin", "__name", "provider", "tx", "asset", "psbt", "psbtHex", "toSignInputs", "address", "signingIndexes", "index", "signedPsbtHex", "e", "finalPsbtBaseHex", "response", "errorText", "data", "defineVersions", "Networks", "Networks", "WALLET_ID", "info", "allBlockchains", "chain", "LegacyNetworks", "unisat", "instances", "LegacyNetworks", "__name", "bitcoinUnisat", "bitcoinInstance", "Networks", "getNetworkInstance", "DefaultSignerFactory", "TxType", "getSigners", "provider", "bitcoinInstance", "getNetworkInstance", "Networks", "BTCSigner", "signers", "DefaultSignerFactory", "TxType", "__name", "config", "WALLET_ID", "getInstance", "unisat", "getWalletInfo", "__name", "allBlockChains", "supportedChains", "btc", "chain", "Networks", "info", "allBlockchains", "getSigners", "buildLegacyProvider", "ProviderBuilder", "NamespaceBuilder", "standardizeAndThrowError", "commonBuilders", "builders", "CAIP_BITCOIN_CHAIN_ID", "CAIP_NAMESPACE", "CAIP", "Networks", "getBitcoinAccounts", "__name", "bitcoinUnisat", "Networks", "getChangeAccountSubscriber", "instance", "eventCallback", "context", "err", "bitcoinInstance", "setState", "accounts", "formatAccounts", "account", "CAIP", "CAIP_NAMESPACE", "CAIP_BITCOIN_CHAIN_ID", "_context", "changeAccountSubscriber", "changeAccountCleanup", "connect", "builders", "result", "standardizeAndThrowError", "disconnect", "commonBuilders", "utxo", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "unisat", "info", "utxo", "versions", "__name", "defineVersions", "buildLegacyProvider", "buildProvider"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/namespaces/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACZ,MAAM,yCAAyC,CAAC;AAkIjD,QAAA,MAAM,IAAI,iEAGA,CAAC;AAEX,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/constants.ts":{"bytes":1018,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true}],"format":"esm"},"src/utils.ts":{"bytes":738,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/utxoSigner.ts":{"bytes":3051,"imports":[{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"bitcoinjs-lib","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/signer.ts":{"bytes":676,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/legacy/utxoSigner.ts","kind":"dynamic-import","original":"./utxoSigner.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/index.ts":{"bytes":1752,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../constants.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.js"},{"path":"src/legacy/signer.ts","kind":"import-statement","original":"./signer.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/utxo.ts":{"bytes":3601,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/utxo","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../constants.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/provider.ts":{"bytes":583,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/utxo.ts","kind":"import-statement","original":"./namespaces/utxo.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":332,"imports":[{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"src/legacy/index.ts","kind":"import-statement","original":"./legacy/index.js"},{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/mod.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":18880},"dist/mod.js":{"imports":[{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"bitcoinjs-lib","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/utxo","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/legacy/utxoSigner.ts":{"bytesInOutput":1478},"src/mod.ts":{"bytesInOutput":144},"src/legacy/index.ts":{"bytesInOutput":562},"src/constants.ts":{"bytesInOutput":503},"src/utils.ts":{"bytesInOutput":308},"src/legacy/signer.ts":{"bytesInOutput":365},"src/provider.ts":{"bytesInOutput":246},"src/namespaces/utxo.ts":{"bytesInOutput":1418}},"bytes":5256}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,aAAa,kDAYP,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC9C,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5C,wBAAgB,MAAM,IAAI,QAAQ,GAAG,IAAI,CAcxC;AAED,wBAAgB,aAAa,IAAI,WAAW,CAS3C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rango-dev/provider-unisat",
|
|
3
|
+
"version": "0.1.1-next.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"source": "./src/mod.ts",
|
|
7
|
+
"main": "./dist/mod.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/mod.js"
|
|
10
|
+
},
|
|
11
|
+
"typings": "dist/mod.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-unisat --inputs src/mod.ts",
|
|
18
|
+
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
|
|
21
|
+
"lint": "eslint \"**/*.{ts,tsx}\""
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@rango-dev/wallets-shared": "^0.45.1-next.2",
|
|
25
|
+
"bitcoinjs-lib": "^6.1.7",
|
|
26
|
+
"rango-types": "^0.1.88"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# UniSat Provider
|
|
2
|
+
UniSat integration for hub.
|
|
3
|
+
[Homepage](https://unisat.io/) | [Docs](https://docs.unisat.io/dev/open-api-documentation/unisat-wallet)
|
|
4
|
+
|
|
5
|
+
More about implementation status can be found [here](../readme.md).
|
|
6
|
+
|
|
7
|
+
## Implementation notes/limitation
|
|
8
|
+
|
|
9
|
+
### Group
|
|
10
|
+
|
|
11
|
+
#### ⚠️ UTXO
|
|
12
|
+
Only supports Bitcoin.
|
|
13
|
+
|
|
14
|
+
### Feature
|
|
15
|
+
|
|
16
|
+
#### ❌ Auto Connect
|
|
17
|
+
UniSat Wallet doesn’t support auto-connect
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
More wallet information can be found in [readme.md](../readme.md).
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BlockchainMeta, TransferBlockchainMeta } from 'rango-types';
|
|
2
|
+
|
|
3
|
+
import { type ProviderInfo } from '@rango-dev/wallets-core';
|
|
4
|
+
import { Networks } from '@rango-dev/wallets-shared';
|
|
5
|
+
|
|
6
|
+
export const WALLET_ID = 'unisat';
|
|
7
|
+
|
|
8
|
+
export const info: ProviderInfo = {
|
|
9
|
+
name: 'UniSat',
|
|
10
|
+
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/unisat/icon.svg',
|
|
11
|
+
extensions: {
|
|
12
|
+
chrome:
|
|
13
|
+
'https://chromewebstore.google.com/detail/unisat-wallet/ppbibelpcjmhbdihakflkdcoccbgbkpo',
|
|
14
|
+
homepage: 'https://unisat.io/',
|
|
15
|
+
},
|
|
16
|
+
properties: [
|
|
17
|
+
{
|
|
18
|
+
name: 'namespaces',
|
|
19
|
+
value: {
|
|
20
|
+
selection: 'single',
|
|
21
|
+
data: [
|
|
22
|
+
{
|
|
23
|
+
label: 'BTC',
|
|
24
|
+
value: 'UTXO',
|
|
25
|
+
id: 'BTC',
|
|
26
|
+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
|
|
27
|
+
allBlockchains.filter(
|
|
28
|
+
(chain): chain is TransferBlockchainMeta =>
|
|
29
|
+
chain.name === Networks.BTC
|
|
30
|
+
),
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
2
|
+
import type { WalletInfo } from '@rango-dev/wallets-shared';
|
|
3
|
+
|
|
4
|
+
import { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';
|
|
5
|
+
import {
|
|
6
|
+
type BlockchainMeta,
|
|
7
|
+
type SignerFactory,
|
|
8
|
+
type TransferBlockchainMeta,
|
|
9
|
+
} from 'rango-types';
|
|
10
|
+
|
|
11
|
+
import { info, WALLET_ID } from '../constants.js';
|
|
12
|
+
import { type Provider, unisat as unisat_instance } from '../utils.js';
|
|
13
|
+
|
|
14
|
+
import signer from './signer.js';
|
|
15
|
+
|
|
16
|
+
const config = {
|
|
17
|
+
type: WALLET_ID,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const getInstance = unisat_instance;
|
|
21
|
+
|
|
22
|
+
const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
|
|
23
|
+
allBlockChains
|
|
24
|
+
) => {
|
|
25
|
+
const supportedChains: BlockchainMeta[] = [];
|
|
26
|
+
const btc = allBlockChains.find((chain) => chain.name === Networks.BTC);
|
|
27
|
+
if (btc) {
|
|
28
|
+
supportedChains.push(btc);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
name: info.name,
|
|
33
|
+
img: info.icon,
|
|
34
|
+
installLink: {
|
|
35
|
+
CHROME: info.extensions.chrome,
|
|
36
|
+
DEFAULT: info.extensions.homepage || '',
|
|
37
|
+
},
|
|
38
|
+
color: '#e9983d',
|
|
39
|
+
needsNamespace: {
|
|
40
|
+
selection: 'multiple',
|
|
41
|
+
data: [
|
|
42
|
+
{
|
|
43
|
+
label: 'BTC',
|
|
44
|
+
value: 'UTXO',
|
|
45
|
+
id: 'BTC',
|
|
46
|
+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
|
|
47
|
+
allBlockchains.filter(
|
|
48
|
+
(chain): chain is TransferBlockchainMeta =>
|
|
49
|
+
chain.name === Networks.BTC
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
supportedChains,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getSigners: (provider: Provider) => Promise<SignerFactory> = signer;
|
|
59
|
+
|
|
60
|
+
const buildLegacyProvider: () => LegacyProviderInterface = () => ({
|
|
61
|
+
config: config,
|
|
62
|
+
getWalletInfo: getWalletInfo,
|
|
63
|
+
connect: async () => {
|
|
64
|
+
return [];
|
|
65
|
+
},
|
|
66
|
+
getInstance,
|
|
67
|
+
getSigners,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export { buildLegacyProvider };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Provider } from '../utils.js';
|
|
2
|
+
import type { SignerFactory } from 'rango-types';
|
|
3
|
+
|
|
4
|
+
import { LegacyNetworks as Networks } from '@rango-dev/wallets-core/legacy';
|
|
5
|
+
import { getNetworkInstance } from '@rango-dev/wallets-shared';
|
|
6
|
+
import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
|
|
7
|
+
|
|
8
|
+
export default async function getSigners(
|
|
9
|
+
provider: Provider
|
|
10
|
+
): Promise<SignerFactory> {
|
|
11
|
+
const bitcoinInstance = getNetworkInstance(provider, Networks.BTC);
|
|
12
|
+
const { BTCSigner } = await import('./utxoSigner.js');
|
|
13
|
+
const signers = new DefaultSignerFactory();
|
|
14
|
+
signers.registerSigner(TxType.TRANSFER, new BTCSigner(bitcoinInstance));
|
|
15
|
+
return signers;
|
|
16
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { GenericSigner, Transfer } from 'rango-types';
|
|
2
|
+
|
|
3
|
+
import { parseErrorAndThrowStandardizeError } from '@rango-dev/wallets-core/namespaces/common';
|
|
4
|
+
import { Networks } from '@rango-dev/wallets-shared';
|
|
5
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
6
|
+
import { SignerError } from 'rango-types';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
type TransferExternalProvider = any;
|
|
10
|
+
|
|
11
|
+
const BTC_RPC_URL = 'https://go.getblock.io/f37bad28a991436483c0a3679a3acbee';
|
|
12
|
+
|
|
13
|
+
export class BTCSigner implements GenericSigner<Transfer> {
|
|
14
|
+
private provider: TransferExternalProvider;
|
|
15
|
+
constructor(provider: TransferExternalProvider) {
|
|
16
|
+
this.provider = provider;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async signMessage(): Promise<string> {
|
|
20
|
+
throw SignerError.UnimplementedError('signMessage');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {
|
|
24
|
+
const { asset, psbt } = tx;
|
|
25
|
+
if (!psbt) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
'No PSBT found to sign. Ensure a valid PSBT is provided.'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (asset.blockchain !== Networks.BTC) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Signing ${asset.blockchain} transaction is not implemented by the signer.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* TODO this logic should be added to queue manager rango preset, for safety we are rejecting signing process to avoid asset loss.
|
|
39
|
+
* https://docs.unisat.io/dev/open-api-documentation/unisat-wallet/supported-chains
|
|
40
|
+
*/
|
|
41
|
+
const currentChain = await this.provider.getChain();
|
|
42
|
+
if (currentChain?.enum !== 'BITCOIN_MAINNET') {
|
|
43
|
+
throw new Error(`Switch your network to Bitcoin to proceed swap.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 1. Decode Base64 to hex
|
|
47
|
+
const psbtHex = Buffer.from(psbt.unsignedPsbtBase64, 'base64').toString(
|
|
48
|
+
'hex'
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// 2. Build UniSat inputs
|
|
52
|
+
const toSignInputs = psbt.inputsToSign.flatMap(
|
|
53
|
+
({ address, signingIndexes }) =>
|
|
54
|
+
signingIndexes.map((index) => ({ index, address }))
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// 3. Sign (& auto-finalize)
|
|
58
|
+
const signedPsbtHex = await this.provider
|
|
59
|
+
.signPsbt(psbtHex, {
|
|
60
|
+
autoFinalized: true,
|
|
61
|
+
toSignInputs,
|
|
62
|
+
})
|
|
63
|
+
.catch((e: unknown) => {
|
|
64
|
+
parseErrorAndThrowStandardizeError(e);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// 4. Parse the PSBT hex and extract the raw transaction
|
|
68
|
+
const psbtObject = bitcoin.Psbt.fromHex(signedPsbtHex);
|
|
69
|
+
const finalPsbtBaseHex = psbtObject.extractTransaction().toHex();
|
|
70
|
+
|
|
71
|
+
// 5. Broadcast PSBT to rpc node
|
|
72
|
+
const response = await fetch(BTC_RPC_URL, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
method: 'sendrawtransaction',
|
|
76
|
+
params: [finalPsbtBaseHex],
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
// Handle network and fetch errors
|
|
82
|
+
const errorText = await response.text();
|
|
83
|
+
throw new Error(`Error broadcasting transaction: ${errorText}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const data = await response.json();
|
|
87
|
+
|
|
88
|
+
if (!data.result) {
|
|
89
|
+
// Handle Bitcoin specific errors
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Error broadcasting transaction. Error Code ${data.error.code}: ${data.error.message}`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { hash: data.result };
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineVersions } from '@rango-dev/wallets-core/utils';
|
|
2
|
+
|
|
3
|
+
import { buildLegacyProvider } from './legacy/index.js';
|
|
4
|
+
import { buildProvider } from './provider.js';
|
|
5
|
+
|
|
6
|
+
const versions = () =>
|
|
7
|
+
defineVersions()
|
|
8
|
+
.version('0.0.0', buildLegacyProvider())
|
|
9
|
+
.version('1.0.0', buildProvider())
|
|
10
|
+
.build();
|
|
11
|
+
|
|
12
|
+
export { versions };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProviderAPI,
|
|
3
|
+
UtxoActions,
|
|
4
|
+
} from '@rango-dev/wallets-core/namespaces/utxo';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
NamespaceBuilder,
|
|
8
|
+
type Subscriber,
|
|
9
|
+
type SubscriberCleanUp,
|
|
10
|
+
} from '@rango-dev/wallets-core';
|
|
11
|
+
import {
|
|
12
|
+
type CaipAccount,
|
|
13
|
+
standardizeAndThrowError,
|
|
14
|
+
} from '@rango-dev/wallets-core/namespaces/common';
|
|
15
|
+
import { builders as commonBuilders } from '@rango-dev/wallets-core/namespaces/common';
|
|
16
|
+
import {
|
|
17
|
+
builders,
|
|
18
|
+
CAIP_BITCOIN_CHAIN_ID,
|
|
19
|
+
CAIP_NAMESPACE,
|
|
20
|
+
} from '@rango-dev/wallets-core/namespaces/utxo';
|
|
21
|
+
import { CAIP } from '@rango-dev/wallets-core/utils';
|
|
22
|
+
import {
|
|
23
|
+
Networks,
|
|
24
|
+
type ProviderConnectResult,
|
|
25
|
+
} from '@rango-dev/wallets-shared';
|
|
26
|
+
|
|
27
|
+
import { WALLET_ID } from '../constants.js';
|
|
28
|
+
import { bitcoinUnisat } from '../utils.js';
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
type AnyFunction = (...args: any[]) => any;
|
|
32
|
+
|
|
33
|
+
const getBitcoinAccounts: () => Promise<ProviderConnectResult> = async () => {
|
|
34
|
+
const instance = bitcoinUnisat();
|
|
35
|
+
const accounts = await instance.requestAccounts();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
accounts: accounts,
|
|
39
|
+
chainId: Networks.BTC,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function getChangeAccountSubscriber(
|
|
44
|
+
instance: () => ProviderAPI | undefined
|
|
45
|
+
): [Subscriber<UtxoActions>, SubscriberCleanUp<UtxoActions>] {
|
|
46
|
+
let eventCallback: AnyFunction;
|
|
47
|
+
|
|
48
|
+
// 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.
|
|
49
|
+
return [
|
|
50
|
+
(context, err) => {
|
|
51
|
+
const bitcoinInstance = instance();
|
|
52
|
+
|
|
53
|
+
if (!bitcoinInstance) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'Trying to subscribe to your Solana wallet, but seems its instance is not available.'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [, setState] = context.state();
|
|
60
|
+
|
|
61
|
+
eventCallback = (accounts: string[]) => {
|
|
62
|
+
if (!accounts.length) {
|
|
63
|
+
context.action('disconnect');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const formatAccounts = accounts.map(
|
|
68
|
+
(account) =>
|
|
69
|
+
CAIP.AccountId.format({
|
|
70
|
+
address: account,
|
|
71
|
+
chainId: {
|
|
72
|
+
namespace: CAIP_NAMESPACE,
|
|
73
|
+
reference: CAIP_BITCOIN_CHAIN_ID,
|
|
74
|
+
},
|
|
75
|
+
}) as CaipAccount
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
setState('accounts', formatAccounts);
|
|
79
|
+
};
|
|
80
|
+
bitcoinInstance.on('accountsChanged', eventCallback);
|
|
81
|
+
|
|
82
|
+
if (err instanceof Error) {
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
(_context, err) => {
|
|
87
|
+
const bitcoinInstance = instance();
|
|
88
|
+
|
|
89
|
+
if (eventCallback && bitcoinInstance) {
|
|
90
|
+
bitcoinInstance.removeListener('accountsChanged', eventCallback);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return err;
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const [changeAccountSubscriber, changeAccountCleanup] =
|
|
99
|
+
getChangeAccountSubscriber(bitcoinUnisat);
|
|
100
|
+
|
|
101
|
+
const connect = builders
|
|
102
|
+
.connect()
|
|
103
|
+
.action(async function () {
|
|
104
|
+
const result = await getBitcoinAccounts();
|
|
105
|
+
if (Array.isArray(result)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
'Expecting bitcoin response to be a single value, not an array.'
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const formatAccounts = result.accounts.map(
|
|
112
|
+
(account) =>
|
|
113
|
+
CAIP.AccountId.format({
|
|
114
|
+
address: account,
|
|
115
|
+
chainId: {
|
|
116
|
+
namespace: CAIP_NAMESPACE,
|
|
117
|
+
reference: CAIP_BITCOIN_CHAIN_ID,
|
|
118
|
+
},
|
|
119
|
+
}) as CaipAccount
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return formatAccounts;
|
|
123
|
+
})
|
|
124
|
+
.before(changeAccountSubscriber)
|
|
125
|
+
.or(changeAccountCleanup)
|
|
126
|
+
.or(standardizeAndThrowError)
|
|
127
|
+
.build();
|
|
128
|
+
|
|
129
|
+
const disconnect = commonBuilders
|
|
130
|
+
.disconnect<UtxoActions>()
|
|
131
|
+
.after(changeAccountCleanup)
|
|
132
|
+
.build();
|
|
133
|
+
|
|
134
|
+
const utxo = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)
|
|
135
|
+
.action(connect)
|
|
136
|
+
.action(disconnect)
|
|
137
|
+
.build();
|
|
138
|
+
|
|
139
|
+
export { utxo };
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ProviderBuilder } from '@rango-dev/wallets-core';
|
|
2
|
+
|
|
3
|
+
import { info, WALLET_ID } from './constants.js';
|
|
4
|
+
import { utxo } from './namespaces/utxo.js';
|
|
5
|
+
import { unisat as unisatInstance } from './utils.js';
|
|
6
|
+
|
|
7
|
+
const buildProvider = () =>
|
|
8
|
+
new ProviderBuilder(WALLET_ID)
|
|
9
|
+
.init(function (context) {
|
|
10
|
+
const [, setState] = context.state();
|
|
11
|
+
|
|
12
|
+
if (unisatInstance()) {
|
|
13
|
+
setState('installed', true);
|
|
14
|
+
console.debug('[unisat] instance detected.', context);
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
.config('info', info)
|
|
18
|
+
.add('utxo', utxo)
|
|
19
|
+
.build();
|
|
20
|
+
|
|
21
|
+
export { buildProvider };
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
export type ProviderAPI = Record<string, any>;
|
|
5
|
+
export type Provider = Map<string, unknown>;
|
|
6
|
+
|
|
7
|
+
export function unisat(): Provider | null {
|
|
8
|
+
const { unisat } = window;
|
|
9
|
+
|
|
10
|
+
if (!unisat) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const instances: Provider = new Map();
|
|
15
|
+
|
|
16
|
+
if (unisat) {
|
|
17
|
+
instances.set(LegacyNetworks.BTC, unisat);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return instances;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function bitcoinUnisat(): ProviderAPI {
|
|
24
|
+
const instances = unisat();
|
|
25
|
+
const bitcoinInstance = instances?.get(LegacyNetworks.BTC);
|
|
26
|
+
|
|
27
|
+
if (!bitcoinInstance) {
|
|
28
|
+
throw new Error('UniSat not injected. Please check your wallet.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return bitcoinInstance;
|
|
32
|
+
}
|