@rango-dev/provider-phantom 0.63.1-next.4 → 0.63.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,7 @@
1
+ import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';
2
+ import type { Context, FunctionWithContext } from '@hub3js/core';
3
+ export declare function connect(instance: () => ProviderAPI): FunctionWithContext<UtxoActions['connect'], Context>;
4
+ export declare const utxoActions: {
5
+ connect: typeof connect;
6
+ };
7
+ //# sourceMappingURL=utxo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/actions/utxo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAIjE,wBAAgB,OAAO,CACrB,QAAQ,EAAE,MAAM,WAAW,GAC1B,mBAAmB,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAWtD;AAED,eAAO,MAAM,WAAW;;CAAc,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { BtcAccount } from '../utils.js';
2
+ import type { ProviderAPI } from '@hub3js/bip122';
3
+ export declare const changeAccountSubscriber: (getInstance: () => ProviderAPI) => import("@hub3js/std/hooks").ChangeAccountSubscriberBuilder<BtcAccount[], ProviderAPI, import("@hub3js/bip122").UtxoActions>;
4
+ export declare const utxoBuilders: {
5
+ changeAccountSubscriber: (getInstance: () => ProviderAPI) => import("@hub3js/std/hooks").ChangeAccountSubscriberBuilder<BtcAccount[], ProviderAPI, import("@hub3js/bip122").UtxoActions>;
6
+ };
7
+ //# sourceMappingURL=utxo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/builders/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,WAAW,gIAYjE,CAAC;AAEN,eAAO,MAAM,YAAY;2CAd4B,MAAM,WAAW;CAcf,CAAC"}
package/dist/mod.js CHANGED
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty;var r=(n,o)=>v(n,"name",{value:o,configurable:!0});var V=(n,o)=>()=>(n&&(o=n(n=0)),o);var R=(n,o)=>{for(var t in o)v(n,t,{get:o[t],enumerable:!0})};var w={};R(w,{BTCSigner:()=>P});import*as H from"@bitcoinerlab/secp256k1";import{isBitcoinBlockchain as F}from"@rango-dev/internal-blockchains";import*as A from"bitcoinjs-lib";import{SignerError as z}from"rango-types";function G(n){let o=atob(n),t=o.length,e=new Uint8Array(t);for(let i=0;i<t;i++)e[i]=o.charCodeAt(i);return e}var $,P,T=V(()=>{"use strict";$="https://go.getblock.io/f37bad28a991436483c0a3679a3acbee";r(G,"base64ToUint8Array");P=class{static{r(this,"BTCSigner")}provider;constructor(o){this.provider=o}async signMessage(){throw z.UnimplementedError("signMessage")}async signAndSendTx(o){let{asset:t,psbt:e}=o;if(!e)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");if(!F(t.blockchain))throw new Error(`Signing ${t.blockchain} transaction is not implemented by the signer.`);A.initEccLib(H);let i=await this.provider.signPSBT(G(e.unsignedPsbtBase64),{inputsToSign:e.inputsToSign}),a=A.Psbt.fromBuffer(Buffer.from(i));a.finalizeAllInputs();let E=a.extractTransaction().toHex(),d=await fetch($,{method:"POST",body:JSON.stringify({method:"sendrawtransaction",params:[E]})});if(!d.ok){let c=await d.text();throw new Error(`Error broadcasting transaction: ${c}`)}let m=await d.json();if(!m.result)throw new Error(`Error broadcasting transaction. Error Code ${m.error.code}: ${m.error.message}`);return{hash:m.result}}}});import{defineVersions as Uo}from"@hub3js/core/utils";import{ProviderBuilder as Oo}from"@hub3js/core";import{CAIP_BASE_CHAIN_ID as oo,CAIP_ETHEREUM_CHAIN_ID as no,CAIP_POLYGON_CHAIN_ID as to,isEvmNamespace as ro}from"@hub3js/evm";import{isSolanaNamespace as eo}from"@hub3js/solana";import{getChainIdFromCaip2ChainId as io}from"@hub3js/std/utils";import{isSuiNamespace as ao}from"@hub3js/sui";import{EVM_NAMESPACE as X,SOLANA_NAMESPACE as J,UTXO_NAMESPACE as Y}from"@hub3js/namespaces";import{getInstance as q}from"@hub3js/sui";import{DefaultSignerFactory as K,TransactionType as h}from"rango-types";async function b(n){let o=n.get(J),t=n.get(X),e=n.get(Y),i=q(l),{DefaultEvmSigner:a}=await import("@rango-dev/signer-evm"),{DefaultSolanaSigner:E}=await import("@rango-dev/signer-solana"),{BTCSigner:d}=await Promise.resolve().then(()=>(T(),w)),{DefaultSuiSigner:m}=await import("@rango-dev/signer-sui"),c=new K;return o&&c.registerSigner(h.SOLANA,new E(o)),t&&c.registerSigner(h.EVM,new a(t)),e&&c.registerSigner(h.TRANSFER,new d(e)),i&&c.registerSigner(h.SUI,new m(i)),c}r(b,"getSigners");import{EVM_NAMESPACE as C,SOLANA_NAMESPACE as I,SUI_NAMESPACE as Q,UTXO_NAMESPACE as Z}from"@hub3js/namespaces";function u(){let{phantom:n}=window;if(!n)return null;let{solana:o,ethereum:t,bitcoin:e,sui:i}=n,a=new Map;return t&&t.isPhantom&&a.set(C,t),o&&o.isPhantom&&a.set(I,o),e&&e.isPhantom&&a.set(Z,e),i&&i.isPhantom&&a.set(Q,i),a}r(u,"phantom");function y(){let n=u();if(!n)throw new Error("Phantom is not injected. Please check your wallet.");return n}r(y,"getInstanceOrThrow");function f(){let o=u()?.get(C);if(!o)throw new Error("Phantom not injected or EVM not enabled. Please check your wallet.");return o}r(f,"evmPhantom");function p(){let o=u()?.get(I);if(!o)throw new Error("Phantom not injected or Solana not enabled. Please check your wallet.");return o}r(p,"solanaPhantom");var so=[no,to,oo],s="phantom",l="Phantom",N={name:"Phantom",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/phantom/icon.svg",extensions:{chrome:"https://chrome.google.com/webstore/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa",homepage:"https://phantom.app/"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"EVM",value:"EVM",id:"ETH",isChainSupported:n=>ro(n)&&so.includes(io(n))},{label:"Solana",value:"Solana",id:"SOLANA",isChainSupported:eo},{label:"Sui",value:"Sui",id:"SUI",isChainSupported:ao}]}},{name:"signers",value:{getSigners:async()=>b(y())}}]};import{NamespaceBuilder as co}from"@hub3js/core";import{actions as g,builders as S,hooks as mo}from"@hub3js/evm";import*as _ from"@hub3js/std/builders";import{standardizeAndThrowError as po}from"@hub3js/std/operators";var[lo,x]=mo.changeAccountSubscriber(f),uo=S.connect().action(g.connect(f)).before(lo).or(x).or(po).build(),fo=_.disconnect().after(x).build(),Ao=S.canEagerConnect().action(g.canEagerConnect(f)).build(),ho=S.canSwitchNetwork().action(g.canSwitchNetwork()).build(),go=S.getChainId().action(g.getChainId(f)).build(),L=new co("EVM",s).action(uo).action(fo).action(Ao).action(ho).action(go).build();import{ActionBuilder as So,NamespaceBuilder as Eo}from"@hub3js/core";import{actions as M,builders as Po,hooks as bo}from"@hub3js/solana";import*as B from"@hub3js/std/builders";import{standardizeAndThrowError as vo}from"@hub3js/std/operators";var[wo,j]=bo.changeAccountSubscriber(p),To=Po.connect().action(M.connect(p)).before(wo).or(j).or(vo).build(),Co=B.disconnect().after(j).build(),Io=new So("canEagerConnect").action(M.canEagerConnect(p)).build(),D=new Eo("Solana",s).action(To).action(Co).action(Io).build();import{ActionBuilder as yo,NamespaceBuilder as No}from"@hub3js/core";import{actions as _o}from"@hub3js/solana";import*as k from"@hub3js/std/builders";import{standardizeAndThrowError as xo}from"@hub3js/std/operators";import{builders as Lo,hooks as Mo}from"@hub3js/sui";var[Bo,O]=Mo.changeAccountSubscriber({name:l}),jo=Lo.connect({name:l}).before(Bo).or(O).or(xo).build(),Do=k.disconnect().after(O).build(),ko=new yo("canEagerConnect").action(_o.canEagerConnect(p)).build(),U=new No("Sui",s).action(jo).action(Do).action(ko).build();var W=r(()=>new Oo(s).init(function(n){let[,o]=n.state();u()&&(o("installed",!0),console.debug("[phantom] instance detected.",n))}).config("metadata",N).add("solana",D).add("evm",L).add("sui",U).build(),"buildProvider");var Dn=r(()=>Uo().version("1.0.0",W()).build(),"versions");export{s as WALLET_ID,Dn as versions};
1
+ var v=Object.defineProperty;var r=(n,o)=>v(n,"name",{value:o,configurable:!0});var V=(n,o)=>()=>(n&&(o=n(n=0)),o);var R=(n,o)=>{for(var t in o)v(n,t,{get:o[t],enumerable:!0})};var w={};R(w,{BTCSigner:()=>P});import*as H from"@bitcoinerlab/secp256k1";import{isBitcoinBlockchain as F}from"@rango-dev/internal-blockchains";import*as h from"bitcoinjs-lib";import{SignerError as z}from"rango-types";function G(n){let o=atob(n),t=o.length,e=new Uint8Array(t);for(let i=0;i<t;i++)e[i]=o.charCodeAt(i);return e}var $,P,T=V(()=>{"use strict";$="https://go.getblock.io/f37bad28a991436483c0a3679a3acbee";r(G,"base64ToUint8Array");P=class{static{r(this,"BTCSigner")}provider;constructor(o){this.provider=o}async signMessage(){throw z.UnimplementedError("signMessage")}async signAndSendTx(o){let{asset:t,psbt:e}=o;if(!e)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");if(!F(t.blockchain))throw new Error(`Signing ${t.blockchain} transaction is not implemented by the signer.`);h.initEccLib(H);let i=await this.provider.signPSBT(G(e.unsignedPsbtBase64),{inputsToSign:e.inputsToSign}),a=h.Psbt.fromBuffer(Buffer.from(i));a.finalizeAllInputs();let E=a.extractTransaction().toHex(),d=await fetch($,{method:"POST",body:JSON.stringify({method:"sendrawtransaction",params:[E]})});if(!d.ok){let c=await d.text();throw new Error(`Error broadcasting transaction: ${c}`)}let m=await d.json();if(!m.result)throw new Error(`Error broadcasting transaction. Error Code ${m.error.code}: ${m.error.message}`);return{hash:m.result}}}});import{defineVersions as Uo}from"@hub3js/core/utils";import{ProviderBuilder as Oo}from"@hub3js/core";import{CAIP_BASE_CHAIN_ID as oo,CAIP_ETHEREUM_CHAIN_ID as no,CAIP_POLYGON_CHAIN_ID as to,isEvmNamespace as ro}from"@hub3js/evm";import{isSolanaNamespace as eo}from"@hub3js/solana";import{getChainIdFromCaip2ChainId as io}from"@hub3js/std/utils";import{isSuiNamespace as ao}from"@hub3js/sui";import{EVM_NAMESPACE as X,SOLANA_NAMESPACE as J,UTXO_NAMESPACE as K}from"@hub3js/namespaces";import{getInstance as Y}from"@hub3js/sui";import{DefaultSignerFactory as q,TransactionType as A}from"rango-types";async function b(n){let o=n.get(J),t=n.get(X),e=n.get(K),i=Y(l),{DefaultEvmSigner:a}=await import("@rango-dev/signer-evm"),{DefaultSolanaSigner:E}=await import("@rango-dev/signer-solana"),{BTCSigner:d}=await Promise.resolve().then(()=>(T(),w)),{DefaultSuiSigner:m}=await import("@rango-dev/signer-sui"),c=new q;return o&&c.registerSigner(A.SOLANA,new E(o)),t&&c.registerSigner(A.EVM,new a(t)),e&&c.registerSigner(A.TRANSFER,new d(e)),i&&c.registerSigner(A.SUI,new m(i)),c}r(b,"getSigners");import{EVM_NAMESPACE as y,SOLANA_NAMESPACE as C,SUI_NAMESPACE as Q,UTXO_NAMESPACE as Z}from"@hub3js/namespaces";function u(){let{phantom:n}=window;if(!n)return null;let{solana:o,ethereum:t,bitcoin:e,sui:i}=n,a=new Map;return t&&t.isPhantom&&a.set(y,t),o&&o.isPhantom&&a.set(C,o),e&&e.isPhantom&&a.set(Z,e),i&&i.isPhantom&&a.set(Q,i),a}r(u,"phantom");function I(){let n=u();if(!n)throw new Error("Phantom is not injected. Please check your wallet.");return n}r(I,"getInstanceOrThrow");function f(){let o=u()?.get(y);if(!o)throw new Error("Phantom not injected or EVM not enabled. Please check your wallet.");return o}r(f,"evmPhantom");function p(){let o=u()?.get(C);if(!o)throw new Error("Phantom not injected or Solana not enabled. Please check your wallet.");return o}r(p,"solanaPhantom");var so=[no,to,oo],s="phantom",l="Phantom",N={name:"Phantom",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/phantom/icon.svg",extensions:{chrome:"https://chrome.google.com/webstore/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa",homepage:"https://phantom.app/"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"EVM",value:"EVM",id:"ETH",isChainSupported:n=>ro(n)&&so.includes(io(n))},{label:"Solana",value:"Solana",id:"SOLANA",isChainSupported:eo},{label:"Sui",value:"Sui",id:"SUI",isChainSupported:ao}]}},{name:"signers",value:{getSigners:async()=>b(I())}}]};import{NamespaceBuilder as co}from"@hub3js/core";import{actions as g,builders as S,hooks as mo}from"@hub3js/evm";import*as _ from"@hub3js/std/builders";import{standardizeAndThrowError as po}from"@hub3js/std/operators";var[lo,x]=mo.changeAccountSubscriber(f),uo=S.connect().action(g.connect(f)).before(lo).or(x).or(po).build(),fo=_.disconnect().after(x).build(),ho=S.canEagerConnect().action(g.canEagerConnect(f)).build(),Ao=S.canSwitchNetwork().action(g.canSwitchNetwork()).build(),go=S.getChainId().action(g.getChainId(f)).build(),L=new co("EVM",s).action(uo).action(fo).action(ho).action(Ao).action(go).build();import{ActionBuilder as So,NamespaceBuilder as Eo}from"@hub3js/core";import{actions as M,builders as Po,hooks as bo}from"@hub3js/solana";import*as B from"@hub3js/std/builders";import{standardizeAndThrowError as vo}from"@hub3js/std/operators";var[wo,j]=bo.changeAccountSubscriber(p),To=Po.connect().action(M.connect(p)).before(wo).or(j).or(vo).build(),yo=B.disconnect().after(j).build(),Co=new So("canEagerConnect").action(M.canEagerConnect(p)).build(),k=new Eo("Solana",s).action(To).action(yo).action(Co).build();import{ActionBuilder as Io,NamespaceBuilder as No}from"@hub3js/core";import{actions as _o}from"@hub3js/solana";import*as D from"@hub3js/std/builders";import{standardizeAndThrowError as xo}from"@hub3js/std/operators";import{builders as Lo,hooks as Mo}from"@hub3js/sui";var[Bo,O]=Mo.changeAccountSubscriber({name:l}),jo=Lo.connect({name:l}).before(Bo).or(O).or(xo).build(),ko=D.disconnect().after(O).build(),Do=new Io("canEagerConnect").action(_o.canEagerConnect(p)).build(),U=new No("Sui",s).action(jo).action(ko).action(Do).build();var W=r(()=>new Oo(s).init(function(n){let[,o]=n.state();u()&&(o("installed",!0),console.debug("[phantom] instance detected.",n))}).config("metadata",N).add("solana",k).add("evm",L).add("sui",U).build(),"buildProvider");var kn=r(()=>Uo().version("1.0.0",W()).build(),"versions");export{s as WALLET_ID,kn 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
3
  "sources": ["../src/signers/utxoSigner.ts", "../src/mod.ts", "../src/provider.ts", "../src/constants.ts", "../src/signer.ts", "../src/utils.ts", "../src/namespaces/evm.ts", "../src/namespaces/solana.ts", "../src/namespaces/sui.ts"],
4
- "sourcesContent": ["import type { GenericSigner, Transfer } from 'rango-types';\n\nimport * as secp256k1 from '@bitcoinerlab/secp256k1';\nimport { isBitcoinBlockchain } from '@rango-dev/internal-blockchains';\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\n// TODO: use Uint8Array.fromBase64() static method and use this function as a polyfill after updating TypeScript DOM lib\nfunction base64ToUint8Array(base64String: string) {\n const binaryString = atob(base64String);\n const length = binaryString.length;\n const uint8Array = new Uint8Array(length);\n\n for (let i = 0; i < length; i++) {\n uint8Array[i] = binaryString.charCodeAt(i);\n }\n\n return uint8Array;\n}\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\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 // Initialize ECC library\n bitcoin.initEccLib(secp256k1);\n\n const signedPSBTBytes = await this.provider.signPSBT(\n base64ToUint8Array(psbt.unsignedPsbtBase64),\n {\n inputsToSign: psbt.inputsToSign,\n }\n );\n\n // Finalize PSBT\n const finalPsbt = bitcoin.Psbt.fromBuffer(Buffer.from(signedPSBTBytes));\n finalPsbt.finalizeAllInputs();\n\n const finalPsbtBaseHex = finalPsbt.extractTransaction().toHex();\n\n // 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 '@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 } from './constants.js';\nimport { evm } from './namespaces/evm.js';\nimport { solana } from './namespaces/solana.js';\nimport { sui } from './namespaces/sui.js';\nimport { phantom as phantomInstance } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n\n if (phantomInstance()) {\n setState('installed', true);\n console.debug('[phantom] instance detected.', context);\n }\n })\n .config('metadata', metadata)\n .add('solana', solana)\n .add('evm', evm)\n .add('sui', sui)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport {\n CAIP_BASE_CHAIN_ID,\n CAIP_ETHEREUM_CHAIN_ID,\n CAIP_POLYGON_CHAIN_ID,\n isEvmNamespace,\n} from '@hub3js/evm';\nimport { isSolanaNamespace } from '@hub3js/solana';\nimport { getChainIdFromCaip2ChainId } from '@hub3js/std/utils';\nimport { isSuiNamespace } from '@hub3js/sui';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const EVM_SUPPORTED_CHAINS = [\n CAIP_ETHEREUM_CHAIN_ID,\n CAIP_POLYGON_CHAIN_ID,\n CAIP_BASE_CHAIN_ID,\n];\n\nexport const WALLET_ID = 'phantom';\nexport const WALLET_NAME_IN_WALLET_STANDARD = 'Phantom';\n\nexport const metadata: ProviderMetadata = {\n name: 'Phantom',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/phantom/icon.svg',\n extensions: {\n chrome:\n 'https://chrome.google.com/webstore/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa',\n homepage: 'https://phantom.app/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'EVM',\n value: 'EVM',\n id: 'ETH',\n isChainSupported: (chainId: string) =>\n isEvmNamespace(chainId) &&\n EVM_SUPPORTED_CHAINS.includes(\n getChainIdFromCaip2ChainId(chainId)\n ),\n },\n {\n label: 'Solana',\n value: 'Solana',\n id: 'SOLANA',\n isChainSupported: isSolanaNamespace,\n },\n {\n label: 'Sui',\n value: 'Sui',\n id: 'SUI',\n isChainSupported: isSuiNamespace,\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners(getInstanceOrThrow()) },\n },\n ],\n};\n", "import type { Provider } from './utils.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport {\n EVM_NAMESPACE,\n SOLANA_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\nimport { getInstance as getSuiInstance } from '@hub3js/sui';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { WALLET_NAME_IN_WALLET_STANDARD } from './constants.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const solProvider = provider.get(SOLANA_NAMESPACE);\n const evmProvider = provider.get(EVM_NAMESPACE);\n const bitcoinInstance = provider.get(UTXO_NAMESPACE);\n\n const suiProvider = getSuiInstance(WALLET_NAME_IN_WALLET_STANDARD);\n\n const { DefaultEvmSigner } = await import('@rango-dev/signer-evm');\n const { DefaultSolanaSigner } = await import('@rango-dev/signer-solana');\n const { BTCSigner } = await import('./signers/utxoSigner.js');\n const { DefaultSuiSigner } = await import('@rango-dev/signer-sui');\n const signers = new DefaultSignerFactory();\n if (!!solProvider) {\n signers.registerSigner(TxType.SOLANA, new DefaultSolanaSigner(solProvider));\n }\n if (!!evmProvider) {\n signers.registerSigner(TxType.EVM, new DefaultEvmSigner(evmProvider));\n }\n if (!!bitcoinInstance) {\n signers.registerSigner(TxType.TRANSFER, new BTCSigner(bitcoinInstance));\n }\n if (!!suiProvider) {\n signers.registerSigner(TxType.SUI, new DefaultSuiSigner(suiProvider));\n }\n return signers;\n}\n", "import type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';\nimport type { ProviderAPI as SolanaProviderApi } from '@hub3js/solana';\nimport type { InstanceMap } from '@hub3js/std/types';\nimport type { ProviderAPI as SuiProviderApi } from '@hub3js/sui';\nimport type { SolanaExternalProvider } from '@rango-dev/signer-solana';\nimport type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport {\n EVM_NAMESPACE,\n SOLANA_NAMESPACE,\n SUI_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\n\nexport type ProviderObject = {\n [EVM_NAMESPACE]: EvmProviderApi;\n [SOLANA_NAMESPACE]: SolanaExternalProvider;\n [UTXO_NAMESPACE]: UtxoProviderApi;\n [SUI_NAMESPACE]: SuiProviderApi;\n};\nexport type Provider = InstanceMap<ProviderObject>;\n\nexport function phantom(): Provider | null {\n const { phantom } = window;\n\n if (!phantom) {\n return null;\n }\n\n const { solana, ethereum, bitcoin, sui } = phantom;\n\n const instances: Provider = new Map();\n\n if (ethereum && ethereum.isPhantom) {\n instances.set(EVM_NAMESPACE, ethereum);\n }\n\n if (solana && solana.isPhantom) {\n instances.set(SOLANA_NAMESPACE, solana);\n }\n\n if (bitcoin && bitcoin.isPhantom) {\n instances.set(UTXO_NAMESPACE, bitcoin);\n }\n if (sui && sui.isPhantom) {\n instances.set(SUI_NAMESPACE, sui);\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = phantom();\n\n if (!instances) {\n throw new Error('Phantom is not injected. Please check your wallet.');\n }\n\n return instances;\n}\n\nexport function evmPhantom(): EvmProviderApi {\n const instances = phantom();\n\n const evmInstance = instances?.get(EVM_NAMESPACE);\n\n if (!evmInstance) {\n throw new Error(\n 'Phantom not injected or EVM not enabled. Please check your wallet.'\n );\n }\n\n return evmInstance;\n}\n\nexport function solanaPhantom(): SolanaProviderApi {\n const instance = phantom();\n const solanaInstance = instance?.get(SOLANA_NAMESPACE);\n\n if (!solanaInstance) {\n throw new Error(\n 'Phantom not injected or Solana not enabled. Please check your wallet.'\n );\n }\n\n return solanaInstance;\n}\n\nexport function bitcoinPhantom(): SolanaProviderApi {\n const instance = phantom();\n const bitcoinInstance = instance?.get(UTXO_NAMESPACE);\n\n if (!bitcoinInstance) {\n throw new Error(\n 'Phantom not injected or Bitcoin not enabled. Please check your wallet.'\n );\n }\n\n return bitcoinInstance;\n}\nexport function suiPhantom(): SuiProviderApi {\n const instance = phantom();\n const suiInstance = instance?.get(SUI_NAMESPACE);\n\n if (!suiInstance) {\n throw new Error(\n 'Phantom not injected or Sui not enabled. Please check your wallet.'\n );\n }\n\n return suiInstance;\n}\n", "import type { EvmActions } from '@hub3js/evm';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport { actions, builders, hooks } from '@hub3js/evm';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { WALLET_ID } from '../constants.js';\nimport { evmPhantom } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(evmPhantom);\n\n/*\n * TODO: If user imported a private key for EVM, it hasn't solana.\n * when trying to connect to solana for this user we go through `-32603` which is an internal error.\n * If phantom added an specific error code for this situation, we can consider handling the error here.\n * @see https://docs.phantom.app/solana/errors\n */\nconst connect = builders\n .connect()\n .action(actions.connect(evmPhantom))\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<EvmActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(actions.canEagerConnect(evmPhantom))\n .build();\n\nconst canSwitchNetwork = builders\n .canSwitchNetwork()\n .action(actions.canSwitchNetwork())\n .build();\n\nconst getChainId = builders\n .getChainId()\n .action(actions.getChainId(evmPhantom))\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .action(canSwitchNetwork)\n .action(getChainId)\n .build();\n\nexport { evm };\n", "import type { SolanaActions } from '@hub3js/solana';\n\nimport { ActionBuilder, NamespaceBuilder } from '@hub3js/core';\nimport { actions, builders, hooks } from '@hub3js/solana';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { WALLET_ID } from '../constants.js';\nimport { solanaPhantom } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(solanaPhantom);\n\n/*\n * TODO: If user imported a private key for EVM, it hasn't solana.\n * when trying to connect to solana for this user we go through `-32603` which is an internal error.\n * If phantom added an specific error code for this situation, we can consider handling the error here.\n * @see https://docs.phantom.app/solana/errors\n */\nconst connect = builders\n .connect()\n .action(actions.connect(solanaPhantom))\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<SolanaActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(actions.canEagerConnect(solanaPhantom))\n .build();\n\nconst solana = new NamespaceBuilder<SolanaActions>('Solana', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { solana };\n", "import type { SolanaActions } from '@hub3js/solana';\nimport type { SuiActions } from '@hub3js/sui';\n\nimport { ActionBuilder, NamespaceBuilder } from '@hub3js/core';\nimport { actions as solanaActions } from '@hub3js/solana';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { builders, hooks } from '@hub3js/sui';\n\nimport { WALLET_ID, WALLET_NAME_IN_WALLET_STANDARD } from '../constants.js';\nimport { solanaPhantom } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber({\n name: WALLET_NAME_IN_WALLET_STANDARD,\n });\n\nconst connect = builders\n .connect({\n name: WALLET_NAME_IN_WALLET_STANDARD,\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<SuiActions>()\n .after(changeAccountCleanup)\n .build();\n\n/*\n * TODO: We are currently using `solanaCanEagerConnectAction` to establish an eager connection to the Sui instance.\n * This is a temporary workaround due to Phantom's limitation in silently connecting to a Sui account.\n * Once Phantom introduces support for silent Sui connections, this implementation should be updated accordingly.\n */\nconst canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(solanaActions.canEagerConnect(solanaPhantom))\n .build();\n\nconst sui = new NamespaceBuilder<SuiActions>('Sui', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { sui };\n"],
4
+ "sourcesContent": ["import type { GenericSigner, Transfer } from 'rango-types';\n\nimport * as secp256k1 from '@bitcoinerlab/secp256k1';\nimport { isBitcoinBlockchain } from '@rango-dev/internal-blockchains';\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\n// TODO: use Uint8Array.fromBase64() static method and use this function as a polyfill after updating TypeScript DOM lib\nfunction base64ToUint8Array(base64String: string) {\n const binaryString = atob(base64String);\n const length = binaryString.length;\n const uint8Array = new Uint8Array(length);\n\n for (let i = 0; i < length; i++) {\n uint8Array[i] = binaryString.charCodeAt(i);\n }\n\n return uint8Array;\n}\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\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 // Initialize ECC library\n bitcoin.initEccLib(secp256k1);\n\n const signedPSBTBytes = await this.provider.signPSBT(\n base64ToUint8Array(psbt.unsignedPsbtBase64),\n {\n inputsToSign: psbt.inputsToSign,\n }\n );\n\n // Finalize PSBT\n const finalPsbt = bitcoin.Psbt.fromBuffer(Buffer.from(signedPSBTBytes));\n finalPsbt.finalizeAllInputs();\n\n const finalPsbtBaseHex = finalPsbt.extractTransaction().toHex();\n\n // 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 '@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 } from './constants.js';\nimport { evm } from './namespaces/evm.js';\nimport { solana } from './namespaces/solana.js';\nimport { sui } from './namespaces/sui.js';\nimport { phantom as phantomInstance } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n\n if (phantomInstance()) {\n setState('installed', true);\n console.debug('[phantom] instance detected.', context);\n }\n })\n .config('metadata', metadata)\n .add('solana', solana)\n .add('evm', evm)\n .add('sui', sui)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport {\n CAIP_BASE_CHAIN_ID,\n CAIP_ETHEREUM_CHAIN_ID,\n CAIP_POLYGON_CHAIN_ID,\n isEvmNamespace,\n} from '@hub3js/evm';\nimport { isSolanaNamespace } from '@hub3js/solana';\nimport { getChainIdFromCaip2ChainId } from '@hub3js/std/utils';\nimport { isSuiNamespace } from '@hub3js/sui';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const EVM_SUPPORTED_CHAINS = [\n CAIP_ETHEREUM_CHAIN_ID,\n CAIP_POLYGON_CHAIN_ID,\n CAIP_BASE_CHAIN_ID,\n];\n\nexport const WALLET_ID = 'phantom';\nexport const WALLET_NAME_IN_WALLET_STANDARD = 'Phantom';\n\nexport const metadata: ProviderMetadata = {\n name: 'Phantom',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/phantom/icon.svg',\n extensions: {\n chrome:\n 'https://chrome.google.com/webstore/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa',\n homepage: 'https://phantom.app/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'EVM',\n value: 'EVM',\n id: 'ETH',\n isChainSupported: (chainId: string) =>\n isEvmNamespace(chainId) &&\n EVM_SUPPORTED_CHAINS.includes(\n getChainIdFromCaip2ChainId(chainId)\n ),\n },\n {\n label: 'Solana',\n value: 'Solana',\n id: 'SOLANA',\n isChainSupported: isSolanaNamespace,\n },\n {\n label: 'Sui',\n value: 'Sui',\n id: 'SUI',\n isChainSupported: isSuiNamespace,\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners(getInstanceOrThrow()) },\n },\n ],\n};\n", "import type { Provider } from './utils.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport {\n EVM_NAMESPACE,\n SOLANA_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\nimport { getInstance as getSuiInstance } from '@hub3js/sui';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { WALLET_NAME_IN_WALLET_STANDARD } from './constants.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const solProvider = provider.get(SOLANA_NAMESPACE);\n const evmProvider = provider.get(EVM_NAMESPACE);\n const bitcoinInstance = provider.get(UTXO_NAMESPACE);\n\n const suiProvider = getSuiInstance(WALLET_NAME_IN_WALLET_STANDARD);\n\n const { DefaultEvmSigner } = await import('@rango-dev/signer-evm');\n const { DefaultSolanaSigner } = await import('@rango-dev/signer-solana');\n const { BTCSigner } = await import('./signers/utxoSigner.js');\n const { DefaultSuiSigner } = await import('@rango-dev/signer-sui');\n const signers = new DefaultSignerFactory();\n if (!!solProvider) {\n signers.registerSigner(TxType.SOLANA, new DefaultSolanaSigner(solProvider));\n }\n if (!!evmProvider) {\n signers.registerSigner(TxType.EVM, new DefaultEvmSigner(evmProvider));\n }\n if (!!bitcoinInstance) {\n signers.registerSigner(TxType.TRANSFER, new BTCSigner(bitcoinInstance));\n }\n if (!!suiProvider) {\n signers.registerSigner(TxType.SUI, new DefaultSuiSigner(suiProvider));\n }\n return signers;\n}\n", "import type { ProviderAPI as UtxoProviderApi } from '@hub3js/bip122';\nimport type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';\nimport type { ProviderAPI as SolanaProviderApi } from '@hub3js/solana';\nimport type { InstanceMap } from '@hub3js/std/types';\nimport type { ProviderAPI as SuiProviderApi } from '@hub3js/sui';\nimport type { SolanaExternalProvider } from '@rango-dev/signer-solana';\n\nimport {\n EVM_NAMESPACE,\n SOLANA_NAMESPACE,\n SUI_NAMESPACE,\n UTXO_NAMESPACE,\n} from '@hub3js/namespaces';\n\nexport type ProviderObject = {\n [EVM_NAMESPACE]: EvmProviderApi;\n [SOLANA_NAMESPACE]: SolanaExternalProvider;\n [UTXO_NAMESPACE]: UtxoProviderApi;\n [SUI_NAMESPACE]: SuiProviderApi;\n};\nexport type Provider = InstanceMap<ProviderObject>;\n\nexport function phantom(): Provider | null {\n const { phantom } = window;\n\n if (!phantom) {\n return null;\n }\n\n const { solana, ethereum, bitcoin, sui } = phantom;\n\n const instances: Provider = new Map();\n\n if (ethereum && ethereum.isPhantom) {\n instances.set(EVM_NAMESPACE, ethereum);\n }\n\n if (solana && solana.isPhantom) {\n instances.set(SOLANA_NAMESPACE, solana);\n }\n\n if (bitcoin && bitcoin.isPhantom) {\n instances.set(UTXO_NAMESPACE, bitcoin);\n }\n if (sui && sui.isPhantom) {\n instances.set(SUI_NAMESPACE, sui);\n }\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = phantom();\n\n if (!instances) {\n throw new Error('Phantom is not injected. Please check your wallet.');\n }\n\n return instances;\n}\n\nexport function evmPhantom(): EvmProviderApi {\n const instances = phantom();\n\n const evmInstance = instances?.get(EVM_NAMESPACE);\n\n if (!evmInstance) {\n throw new Error(\n 'Phantom not injected or EVM not enabled. Please check your wallet.'\n );\n }\n\n return evmInstance;\n}\n\nexport function solanaPhantom(): SolanaProviderApi {\n const instance = phantom();\n const solanaInstance = instance?.get(SOLANA_NAMESPACE);\n\n if (!solanaInstance) {\n throw new Error(\n 'Phantom not injected or Solana not enabled. Please check your wallet.'\n );\n }\n\n return solanaInstance;\n}\n\nexport function bitcoinPhantom(): SolanaProviderApi {\n const instance = phantom();\n const bitcoinInstance = instance?.get(UTXO_NAMESPACE);\n\n if (!bitcoinInstance) {\n throw new Error(\n 'Phantom not injected or Bitcoin not enabled. Please check your wallet.'\n );\n }\n\n return bitcoinInstance;\n}\nexport function suiPhantom(): SuiProviderApi {\n const instance = phantom();\n const suiInstance = instance?.get(SUI_NAMESPACE);\n\n if (!suiInstance) {\n throw new Error(\n 'Phantom not injected or Sui not enabled. Please check your wallet.'\n );\n }\n\n return suiInstance;\n}\n\nexport type BtcAccount = {\n address: string;\n publicKey: string;\n addressType: 'p2tr' | 'p2wpkh' | 'p2sh' | 'p2pkh';\n purpose: 'payment' | 'ordinals';\n};\n", "import type { EvmActions } from '@hub3js/evm';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport { actions, builders, hooks } from '@hub3js/evm';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { WALLET_ID } from '../constants.js';\nimport { evmPhantom } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(evmPhantom);\n\n/*\n * TODO: If user imported a private key for EVM, it hasn't solana.\n * when trying to connect to solana for this user we go through `-32603` which is an internal error.\n * If phantom added an specific error code for this situation, we can consider handling the error here.\n * @see https://docs.phantom.app/solana/errors\n */\nconst connect = builders\n .connect()\n .action(actions.connect(evmPhantom))\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<EvmActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = builders\n .canEagerConnect()\n .action(actions.canEagerConnect(evmPhantom))\n .build();\n\nconst canSwitchNetwork = builders\n .canSwitchNetwork()\n .action(actions.canSwitchNetwork())\n .build();\n\nconst getChainId = builders\n .getChainId()\n .action(actions.getChainId(evmPhantom))\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .action(canSwitchNetwork)\n .action(getChainId)\n .build();\n\nexport { evm };\n", "import type { SolanaActions } from '@hub3js/solana';\n\nimport { ActionBuilder, NamespaceBuilder } from '@hub3js/core';\nimport { actions, builders, hooks } from '@hub3js/solana';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\n\nimport { WALLET_ID } from '../constants.js';\nimport { solanaPhantom } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(solanaPhantom);\n\n/*\n * TODO: If user imported a private key for EVM, it hasn't solana.\n * when trying to connect to solana for this user we go through `-32603` which is an internal error.\n * If phantom added an specific error code for this situation, we can consider handling the error here.\n * @see https://docs.phantom.app/solana/errors\n */\nconst connect = builders\n .connect()\n .action(actions.connect(solanaPhantom))\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<SolanaActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(actions.canEagerConnect(solanaPhantom))\n .build();\n\nconst solana = new NamespaceBuilder<SolanaActions>('Solana', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { solana };\n", "import type { SolanaActions } from '@hub3js/solana';\nimport type { SuiActions } from '@hub3js/sui';\n\nimport { ActionBuilder, NamespaceBuilder } from '@hub3js/core';\nimport { actions as solanaActions } from '@hub3js/solana';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { builders, hooks } from '@hub3js/sui';\n\nimport { WALLET_ID, WALLET_NAME_IN_WALLET_STANDARD } from '../constants.js';\nimport { solanaPhantom } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber({\n name: WALLET_NAME_IN_WALLET_STANDARD,\n });\n\nconst connect = builders\n .connect({\n name: WALLET_NAME_IN_WALLET_STANDARD,\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<SuiActions>()\n .after(changeAccountCleanup)\n .build();\n\n/*\n * TODO: We are currently using `solanaCanEagerConnectAction` to establish an eager connection to the Sui instance.\n * This is a temporary workaround due to Phantom's limitation in silently connecting to a Sui account.\n * Once Phantom introduces support for silent Sui connections, this implementation should be updated accordingly.\n */\nconst canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(solanaActions.canEagerConnect(solanaPhantom))\n .build();\n\nconst sui = new NamespaceBuilder<SuiActions>('Sui', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { sui };\n"],
5
5
  "mappings": "gLAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAEA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AAQ,MAAM,EAE/BE,EAAgB,IAClBD,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,+BAAgCD,CAAO,EAEzD,CAAC,EACA,OAAO,WAAYG,CAAQ,EAC3B,IAAI,SAAUC,CAAM,EACpB,IAAI,MAAOC,CAAG,EACd,IAAI,MAAOC,CAAG,EACd,MAAM,EAdW,iBDJtB,IAAMC,GAAWC,EAAA,IACfC,GAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
6
  "names": ["utxoSigner_exports", "__export", "BTCSigner", "secp256k1", "isBitcoinBlockchain", "bitcoin", "SignerError", "base64ToUint8Array", "base64String", "binaryString", "length", "uint8Array", "BTC_RPC_URL", "init_utxoSigner", "__esmMin", "__name", "provider", "tx", "asset", "psbt", "signedPSBTBytes", "finalPsbt", "finalPsbtBaseHex", "response", "errorText", "data", "defineVersions", "ProviderBuilder", "CAIP_BASE_CHAIN_ID", "CAIP_ETHEREUM_CHAIN_ID", "CAIP_POLYGON_CHAIN_ID", "isEvmNamespace", "isSolanaNamespace", "getChainIdFromCaip2ChainId", "isSuiNamespace", "EVM_NAMESPACE", "SOLANA_NAMESPACE", "UTXO_NAMESPACE", "getSuiInstance", "DefaultSignerFactory", "TxType", "getSigners", "provider", "solProvider", "SOLANA_NAMESPACE", "evmProvider", "EVM_NAMESPACE", "bitcoinInstance", "UTXO_NAMESPACE", "suiProvider", "getSuiInstance", "WALLET_NAME_IN_WALLET_STANDARD", "DefaultEvmSigner", "DefaultSolanaSigner", "BTCSigner", "DefaultSuiSigner", "signers", "DefaultSignerFactory", "TxType", "__name", "EVM_NAMESPACE", "SOLANA_NAMESPACE", "SUI_NAMESPACE", "UTXO_NAMESPACE", "phantom", "solana", "ethereum", "bitcoin", "sui", "instances", "EVM_NAMESPACE", "SOLANA_NAMESPACE", "UTXO_NAMESPACE", "SUI_NAMESPACE", "__name", "getInstanceOrThrow", "evmPhantom", "evmInstance", "solanaPhantom", "solanaInstance", "EVM_SUPPORTED_CHAINS", "CAIP_ETHEREUM_CHAIN_ID", "CAIP_POLYGON_CHAIN_ID", "CAIP_BASE_CHAIN_ID", "WALLET_ID", "WALLET_NAME_IN_WALLET_STANDARD", "metadata", "chainId", "isEvmNamespace", "getChainIdFromCaip2ChainId", "isSolanaNamespace", "isSuiNamespace", "getSigners", "getInstanceOrThrow", "NamespaceBuilder", "actions", "builders", "hooks", "commonBuilders", "standardizeAndThrowError", "changeAccountSubscriber", "changeAccountCleanup", "hooks", "evmPhantom", "connect", "builders", "actions", "standardizeAndThrowError", "disconnect", "canEagerConnect", "canSwitchNetwork", "getChainId", "evm", "NamespaceBuilder", "WALLET_ID", "ActionBuilder", "NamespaceBuilder", "actions", "builders", "hooks", "commonBuilders", "standardizeAndThrowError", "changeAccountSubscriber", "changeAccountCleanup", "hooks", "solanaPhantom", "connect", "builders", "actions", "standardizeAndThrowError", "disconnect", "canEagerConnect", "ActionBuilder", "solana", "NamespaceBuilder", "WALLET_ID", "ActionBuilder", "NamespaceBuilder", "solanaActions", "commonBuilders", "standardizeAndThrowError", "builders", "hooks", "changeAccountSubscriber", "changeAccountCleanup", "hooks", "WALLET_NAME_IN_WALLET_STANDARD", "connect", "builders", "standardizeAndThrowError", "disconnect", "canEagerConnect", "ActionBuilder", "solanaActions", "solanaPhantom", "sui", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "phantom", "metadata", "solana", "evm", "sui", "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":"AACA,OAAO,KAAK,EAEV,WAAW,EACZ,MAAM,yCAAyC,CAAC;AA0JjD,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;AAwClD,QAAA,MAAM,IAAI,sDAIA,CAAC;AAEX,OAAO,EAAE,IAAI,EAAE,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,9 @@
1
+ import type { ProviderAPI as UtxoProviderApi } from '@hub3js/bip122';
1
2
  import type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';
2
3
  import type { ProviderAPI as SolanaProviderApi } from '@hub3js/solana';
3
4
  import type { InstanceMap } from '@hub3js/std/types';
4
5
  import type { ProviderAPI as SuiProviderApi } from '@hub3js/sui';
5
6
  import type { SolanaExternalProvider } from '@rango-dev/signer-solana';
6
- import type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';
7
7
  import { EVM_NAMESPACE, SOLANA_NAMESPACE, SUI_NAMESPACE, UTXO_NAMESPACE } from '@hub3js/namespaces';
8
8
  export type ProviderObject = {
9
9
  [EVM_NAMESPACE]: EvmProviderApi;
@@ -18,4 +18,10 @@ export declare function evmPhantom(): EvmProviderApi;
18
18
  export declare function solanaPhantom(): SolanaProviderApi;
19
19
  export declare function bitcoinPhantom(): SolanaProviderApi;
20
20
  export declare function suiPhantom(): SuiProviderApi;
21
+ export type BtcAccount = {
22
+ address: string;
23
+ publicKey: string;
24
+ addressType: 'p2tr' | 'p2wpkh' | 'p2sh' | 'p2pkh';
25
+ purpose: 'payment' | 'ordinals';
26
+ };
21
27
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings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K,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,cAAc,EACf,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC;IAChC,CAAC,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAC3C,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC;IAClC,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;AAEnD,wBAAgB,OAAO,IAAI,QAAQ,GAAG,IAAI,CA2BzC;AAED,wBAAgB,kBAAkB,IAAI,QAAQ,CAQ7C;AAED,wBAAgB,UAAU,IAAI,cAAc,CAY3C;AAED,wBAAgB,aAAa,IAAI,iBAAiB,CAWjD;AAED,wBAAgB,cAAc,IAAI,iBAAiB,CAWlD;AACD,wBAAgB,UAAU,IAAI,cAAc,CAW3C;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAClD,OAAO,EAAE,SAAS,GAAG,UAAU,CAAC;CACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-phantom",
3
- "version": "0.63.1-next.4",
3
+ "version": "0.63.1-next.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/mod.ts",
@@ -22,18 +22,19 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@bitcoinerlab/secp256k1": "^1.2.0",
25
+ "@hub3js/bip122": "^0.2.1",
25
26
  "@hub3js/core": "^0.62.0",
26
27
  "@hub3js/evm": "^0.5.0",
27
- "@hub3js/namespaces": "^0.4.0",
28
+ "@hub3js/namespaces": "^0.5.1",
28
29
  "@hub3js/solana": "^0.5.0",
29
30
  "@hub3js/std": "^0.4.0",
30
31
  "@hub3js/sui": "^0.4.0",
31
32
  "@mysten/sui": "^1.21.2",
32
33
  "@mysten/wallet-standard": "^0.13.26",
33
- "@rango-dev/internal-blockchains": "^0.1.1-next.1",
34
+ "@rango-dev/internal-blockchains": "^0.1.1-next.2",
34
35
  "@rango-dev/signer-solana": "^0.49.0",
35
36
  "@rango-dev/signer-sui": "^0.11.0",
36
- "@rango-dev/wallets-core": "^0.61.1-next.1",
37
+ "@rango-dev/wallets-core": "^0.61.1-next.2",
37
38
  "bitcoinjs-lib": "^6.1.7",
38
39
  "caip": "^1.1.1",
39
40
  "rango-types": "^0.5.0"
@@ -0,0 +1,22 @@
1
+ import type { BtcAccount } from '../utils.js';
2
+ import type { ProviderAPI, UtxoActions } from '@hub3js/bip122';
3
+ import type { Context, FunctionWithContext } from '@hub3js/core';
4
+
5
+ import { CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';
6
+
7
+ export function connect(
8
+ instance: () => ProviderAPI
9
+ ): FunctionWithContext<UtxoActions['connect'], Context> {
10
+ return async () => {
11
+ const accounts: BtcAccount[] = await instance().requestAccounts();
12
+
13
+ return utils.formatAccountsToCAIP(
14
+ accounts
15
+ .filter((account) => account.purpose === 'payment')
16
+ .map((account) => account.address),
17
+ CAIP_BITCOIN_CHAIN_ID
18
+ );
19
+ };
20
+ }
21
+
22
+ export const utxoActions = { connect };
@@ -0,0 +1,20 @@
1
+ import type { BtcAccount } from '../utils.js';
2
+ import type { ProviderAPI } from '@hub3js/bip122';
3
+
4
+ import { builders, CAIP_BITCOIN_CHAIN_ID, utils } from '@hub3js/bip122';
5
+
6
+ export const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
7
+ builders
8
+ .changeAccountSubscriber<BtcAccount[]>(getInstance, {
9
+ network: CAIP_BITCOIN_CHAIN_ID,
10
+ })
11
+ .format(async (_, accounts) =>
12
+ utils.formatAccountsToCAIP(
13
+ accounts
14
+ .filter((account) => account.purpose === 'payment')
15
+ .map((account) => account.address),
16
+ CAIP_BITCOIN_CHAIN_ID
17
+ )
18
+ );
19
+
20
+ export const utxoBuilders = { changeAccountSubscriber };
@@ -1,140 +1,23 @@
1
- import type { CaipAccount } from '@hub3js/std/types';
2
- import type {
3
- ProviderAPI,
4
- UtxoActions,
5
- } from '@rango-dev/wallets-core/namespaces/utxo';
1
+ import type { UtxoActions } from '@hub3js/bip122';
6
2
 
7
- import {
8
- ActionBuilder,
9
- NamespaceBuilder,
10
- type Subscriber,
11
- type SubscriberCleanUp,
12
- } from '@hub3js/core';
13
- import { actions as solanaActions, type SolanaActions } from '@hub3js/solana';
3
+ import { builders } from '@hub3js/bip122';
4
+ import { NamespaceBuilder } from '@hub3js/core';
5
+ import { actions as solanaActions } from '@hub3js/solana';
14
6
  import * as commonBuilders from '@hub3js/std/builders';
15
7
  import { standardizeAndThrowError } from '@hub3js/std/operators';
16
- import {
17
- builders,
18
- CAIP_BITCOIN_CHAIN_ID,
19
- CAIP_NAMESPACE,
20
- } from '@rango-dev/wallets-core/namespaces/utxo';
21
- import { AccountId } from 'caip';
22
8
 
9
+ import { utxoActions } from '../actions/utxo.js';
10
+ import { utxoBuilders } from '../builders/utxo.js';
23
11
  import { WALLET_ID } from '../constants.js';
24
12
  import { bitcoinPhantom, solanaPhantom } from '../utils.js';
25
13
 
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- type AnyFunction = (...args: any[]) => any;
28
-
29
- type BtcAccount = {
30
- address: string;
31
- publicKey: string;
32
- addressType: 'p2tr' | 'p2wpkh' | 'p2sh' | 'p2pkh';
33
- purpose: 'payment' | 'ordinals';
34
- };
35
-
36
- const getBitcoinAccounts: () => Promise<{
37
- accounts: string[];
38
- chainId: string;
39
- }> = async () => {
40
- const instance = bitcoinPhantom();
41
- const accounts = await instance.requestAccounts();
42
-
43
- return {
44
- accounts: accounts
45
- .filter((account: BtcAccount) => account.purpose === 'payment')
46
- .map((account: BtcAccount) => account.address),
47
- chainId: CAIP_BITCOIN_CHAIN_ID,
48
- };
49
- };
50
-
51
- function getChangeAccountSubscriber(
52
- instance: () => ProviderAPI | undefined
53
- ): [Subscriber<UtxoActions>, SubscriberCleanUp<UtxoActions>] {
54
- let eventCallback: AnyFunction;
55
-
56
- // 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.
57
- return [
58
- (context, err) => {
59
- const bitcoinInstance = instance();
60
-
61
- if (!bitcoinInstance) {
62
- throw new Error(
63
- 'Trying to subscribe to your Solana wallet, but seems its instance is not available.'
64
- );
65
- }
66
-
67
- const [, setState] = context.state();
68
-
69
- eventCallback = (accounts: BtcAccount[]) => {
70
- /*
71
- * In Phantom, when user is switching to an account which is not connected to dApp yet, it returns an empty array on `accountsChanged`.
72
- * So empty array means we don't have access to account and we need to disconnect and let the user connect the account.
73
- */
74
- if (!accounts.length) {
75
- context.action('disconnect');
76
- return;
77
- }
78
-
79
- const formatAccounts = accounts
80
- .filter((account) => account.purpose === 'payment')
81
- .map(
82
- (account: BtcAccount) =>
83
- AccountId.format({
84
- address: account.address,
85
- chainId: {
86
- namespace: CAIP_NAMESPACE,
87
- reference: CAIP_BITCOIN_CHAIN_ID,
88
- },
89
- }) as CaipAccount
90
- );
91
-
92
- setState('accounts', formatAccounts);
93
- };
94
- bitcoinInstance.on('accountsChanged', eventCallback);
95
-
96
- if (err instanceof Error) {
97
- throw err;
98
- }
99
- },
100
- (_context, err) => {
101
- const bitcoinInstance = instance();
102
-
103
- if (eventCallback && bitcoinInstance) {
104
- bitcoinInstance.off('accountsChanged', eventCallback);
105
- }
106
-
107
- return err;
108
- },
109
- ];
110
- }
111
-
112
- const [changeAccountSubscriber, changeAccountCleanup] =
113
- getChangeAccountSubscriber(bitcoinPhantom);
14
+ const [changeAccountSubscriber, changeAccountCleanup] = utxoBuilders
15
+ .changeAccountSubscriber(bitcoinPhantom)
16
+ .build();
114
17
 
115
18
  const connect = builders
116
19
  .connect()
117
- .action(async function () {
118
- const result = await getBitcoinAccounts();
119
- if (Array.isArray(result)) {
120
- throw new Error(
121
- 'Expecting bitcoin response to be a single value, not an array.'
122
- );
123
- }
124
-
125
- const formatAccounts = result.accounts.map(
126
- (account) =>
127
- AccountId.format({
128
- address: account,
129
- chainId: {
130
- namespace: CAIP_NAMESPACE,
131
- reference: CAIP_BITCOIN_CHAIN_ID,
132
- },
133
- }) as CaipAccount
134
- );
135
-
136
- return formatAccounts;
137
- })
20
+ .action(utxoActions.connect(bitcoinPhantom))
138
21
  .before(changeAccountSubscriber)
139
22
  .or(changeAccountCleanup)
140
23
  .or(standardizeAndThrowError)
@@ -150,9 +33,8 @@ const disconnect = commonBuilders
150
33
  * This is a temporary workaround due to Phantom's limitation in silently connecting to a BTC account.
151
34
  * Once Phantom introduces support for silent BTC connections, this implementation should be updated accordingly.
152
35
  */
153
- const canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(
154
- 'canEagerConnect'
155
- )
36
+ const canEagerConnect = builders
37
+ .canEagerConnect()
156
38
  .action(solanaActions.canEagerConnect(solanaPhantom))
157
39
  .build();
158
40
 
package/src/utils.ts CHANGED
@@ -1,9 +1,9 @@
1
+ import type { ProviderAPI as UtxoProviderApi } from '@hub3js/bip122';
1
2
  import type { ProviderAPI as EvmProviderApi } from '@hub3js/evm';
2
3
  import type { ProviderAPI as SolanaProviderApi } from '@hub3js/solana';
3
4
  import type { InstanceMap } from '@hub3js/std/types';
4
5
  import type { ProviderAPI as SuiProviderApi } from '@hub3js/sui';
5
6
  import type { SolanaExternalProvider } from '@rango-dev/signer-solana';
6
- import type { ProviderAPI as UtxoProviderApi } from '@rango-dev/wallets-core/namespaces/utxo';
7
7
 
8
8
  import {
9
9
  EVM_NAMESPACE,
@@ -110,3 +110,10 @@ export function suiPhantom(): SuiProviderApi {
110
110
 
111
111
  return suiInstance;
112
112
  }
113
+
114
+ export type BtcAccount = {
115
+ address: string;
116
+ publicKey: string;
117
+ addressType: 'p2tr' | 'p2wpkh' | 'p2sh' | 'p2pkh';
118
+ purpose: 'payment' | 'ordinals';
119
+ };