@rango-dev/provider-trezor 0.28.0 → 0.28.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # [0.28.0](https://github.com/rango-exchange/rango-client/compare/provider-trezor@0.27.0...provider-trezor@0.28.0) (2026-07-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * migrate trezor provider to hub ([1d87eac](https://github.com/rango-exchange/rango-client/commit/1d87eac97f8a5d9122b5805b45898db53bc30cad))
7
+
8
+
9
+
1
10
  # [0.27.0](https://github.com/rango-exchange/rango-client/compare/provider-trezor@0.26.1...provider-trezor@0.27.0) (2026-05-31)
2
11
 
3
12
 
@@ -0,0 +1,12 @@
1
+ import type { Context, FunctionWithContext } from '@hub3js/core';
2
+ import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
3
+ /**
4
+ * Connect the Bitcoin account for the selected derivation path: derive the receive
5
+ * address and return it CAIP-encoded with the bip122 Bitcoin chain id. The path is kept
6
+ * (like the EVM namespace does) because Rango's PSBT has no derivation data, so the
7
+ * signer needs it at signing time.
8
+ */
9
+ export declare function connect(): FunctionWithContext<UtxoActions['connect'], Context>;
10
+ export declare const utxoActions: {
11
+ connect: typeof connect;
12
+ };
@@ -0,0 +1,2 @@
1
+ var c=Object.defineProperty;var e=(t,r)=>c(t,"name",{value:r,configurable:!0});var o="";function p(t){o=t}e(p,"setDerivationPath");function i(){return o}e(i,"getDerivationPath");var a="";function l(t){a=t}e(l,"setBitcoinDerivationPath");function m(){return a}e(m,"getBitcoinDerivationPath");import{dynamicImportWithRefinedError as u,ETHEREUM_CHAIN_ID as s,Networks as d}from"@rango-dev/wallets-shared";var v={Failure_ActionCancelled:"User rejected the transaction."};async function f(){let t=await u(async()=>await import("@trezor/connect-web"));return t.default.default?t.default.default:t.default}e(f,"getTrezorModule");function I(){let t=new Map;return t.set(d.ETHEREUM,{chainId:s}),t}e(I,"getTrezorInstance");async function w(){let t=await f(),r=i(),n=await t.ethereumGetAddress({path:r});if(!n.success)throw new Error(n.payload.error);return{accounts:[n.payload.address],chainId:s,derivationPath:r}}e(w,"getEthereumAccounts");var T=e(t=>{let r=BigInt(0);return BigInt(t)>r?`0x${BigInt(t).toString(16)}`:"0x0"},"valueToHex"),z=e(t=>t&&!t.startsWith("m/")?"m/"+t:t,"getTrezorNormalizedDerivationPath");export{e as a,p as b,i as c,l as d,m as e,v as f,f as g,I as h,w as i,T as j,z as k};
2
+ //# sourceMappingURL=chunk-S7XQ7HPI.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/state.ts", "../src/legacy/helpers.ts"],
4
+ "sourcesContent": ["// We keep derivationPath here because we need to maintain it for signing transactions after it is set in connect method\nlet derivationPath = '';\n\nexport function setDerivationPath(path: string) {\n derivationPath = path;\n}\n\nexport function getDerivationPath() {\n return derivationPath;\n}\n\n/*\n * Bitcoin's connect-time path, kept for the same reason as the EVM one: Rango's PSBT\n * carries no derivation data, so the signer must remember which path to sign with. Kept\n * separate from the EVM path so the two namespaces never collide.\n */\nlet bitcoinDerivationPath = '';\n\nexport function setBitcoinDerivationPath(path: string) {\n bitcoinDerivationPath = path;\n}\n\nexport function getBitcoinDerivationPath() {\n return bitcoinDerivationPath;\n}\n", "import type { TrezorConnect } from '@trezor/connect-web';\n\nimport {\n dynamicImportWithRefinedError,\n ETHEREUM_CHAIN_ID,\n Networks,\n type ProviderConnectResult,\n} from '@rango-dev/wallets-shared';\n\nimport { getDerivationPath } from '../state';\n\nexport const trezorErrorMessages: { [statusCode: string]: string } = {\n Failure_ActionCancelled: 'User rejected the transaction.',\n};\n\n// `@trezor/connect-web` is commonjs, when we are importing it dynamically, it has some differences in different tooling. for example vite (you can check widget-examples), goes throw error. this is a workaround for solving this interop issue.\nexport async function getTrezorModule() {\n const mod = await dynamicImportWithRefinedError(\n async () => await import('@trezor/connect-web')\n );\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (mod.default.default) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return mod.default.default as unknown as TrezorConnect;\n }\n\n return mod.default;\n}\n\nexport function getTrezorInstance() {\n /*\n * Instances have a required property which is `chainId` and is using in swap execution.\n * Here we are setting it as Ethereum always since we are supporting only eth for now.\n */\n const instances = new Map();\n\n instances.set(Networks.ETHEREUM, { chainId: ETHEREUM_CHAIN_ID });\n\n return instances;\n}\n\nexport async function getEthereumAccounts(): Promise<ProviderConnectResult> {\n const TrezorConnect = await getTrezorModule();\n const derivationPath = getDerivationPath();\n const result = await TrezorConnect.ethereumGetAddress({\n path: derivationPath,\n });\n\n if (!result.success) {\n throw new Error(result.payload.error);\n }\n\n return {\n accounts: [result.payload.address],\n chainId: ETHEREUM_CHAIN_ID,\n derivationPath,\n };\n}\n\n/*\n * Using BigInt in the valueToHex function ensures that the function\n * can handle very large integer values that exceed the range of standard JavaScript number types.\n */\nexport const valueToHex = (value: string) => {\n const ZERO_BIGINT = BigInt(0);\n const HEX_BASE = 16;\n return BigInt(value) > ZERO_BIGINT\n ? `0x${BigInt(value).toString(HEX_BASE)}`\n : '0x0';\n};\n\nexport const getTrezorNormalizedDerivationPath = (\n path: string // TrezorConnect needs master node to be added to derivation path\n) => (path && !path.startsWith('m/') ? 'm/' + path : path);\n"],
5
+ "mappings": "+EACA,IAAIA,EAAiB,GAEd,SAASC,EAAkBC,EAAc,CAC9CF,EAAiBE,CACnB,CAFgBC,EAAAF,EAAA,qBAIT,SAASG,GAAoB,CAClC,OAAOJ,CACT,CAFgBG,EAAAC,EAAA,qBAShB,IAAIC,EAAwB,GAErB,SAASC,EAAyBJ,EAAc,CACrDG,EAAwBH,CAC1B,CAFgBC,EAAAG,EAAA,4BAIT,SAASC,GAA2B,CACzC,OAAOF,CACT,CAFgBF,EAAAI,EAAA,4BCpBhB,OACE,iCAAAC,EACA,qBAAAC,EACA,YAAAC,MAEK,4BAIA,IAAMC,EAAwD,CACnE,wBAAyB,gCAC3B,EAGA,eAAsBC,GAAkB,CACtC,IAAMC,EAAM,MAAMC,EAChB,SAAY,KAAM,QAAO,qBAAqB,CAChD,EAGA,OAAID,EAAI,QAAQ,QAGPA,EAAI,QAAQ,QAGdA,EAAI,OACb,CAbsBE,EAAAH,EAAA,mBAef,SAASI,GAAoB,CAKlC,IAAMC,EAAY,IAAI,IAEtB,OAAAA,EAAU,IAAIC,EAAS,SAAU,CAAE,QAASC,CAAkB,CAAC,EAExDF,CACT,CAVgBF,EAAAC,EAAA,qBAYhB,eAAsBI,GAAsD,CAC1E,IAAMC,EAAgB,MAAMT,EAAgB,EACtCU,EAAiBC,EAAkB,EACnCC,EAAS,MAAMH,EAAc,mBAAmB,CACpD,KAAMC,CACR,CAAC,EAED,GAAI,CAACE,EAAO,QACV,MAAM,IAAI,MAAMA,EAAO,QAAQ,KAAK,EAGtC,MAAO,CACL,SAAU,CAACA,EAAO,QAAQ,OAAO,EACjC,QAASL,EACT,eAAAG,CACF,CACF,CAhBsBP,EAAAK,EAAA,uBAsBf,IAAMK,EAAaV,EAACW,GAAkB,CAC3C,IAAMC,EAAc,OAAO,CAAC,EAE5B,OAAO,OAAOD,CAAK,EAAIC,EACnB,KAAK,OAAOD,CAAK,EAAE,SAFN,EAEuB,CAAC,GACrC,KACN,EAN0B,cAQbE,EAAoCb,EAC/Cc,GACIA,GAAQ,CAACA,EAAK,WAAW,IAAI,EAAI,KAAOA,EAAOA,EAFJ",
6
+ "names": ["derivationPath", "setDerivationPath", "path", "__name", "getDerivationPath", "bitcoinDerivationPath", "setBitcoinDerivationPath", "getBitcoinDerivationPath", "dynamicImportWithRefinedError", "ETHEREUM_CHAIN_ID", "Networks", "trezorErrorMessages", "getTrezorModule", "mod", "dynamicImportWithRefinedError", "__name", "getTrezorInstance", "instances", "Networks", "ETHEREUM_CHAIN_ID", "getEthereumAccounts", "TrezorConnect", "derivationPath", "getDerivationPath", "result", "valueToHex", "value", "ZERO_BIGINT", "getTrezorNormalizedDerivationPath", "path"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as p}from"./chunk-S7XQ7HPI.js";var S="btc",o=[{id:"native-segwit",label:"Native SegWit",purpose:84,inputScriptType:"SPENDWITNESS"},{id:"nested-segwit",label:"Nested SegWit",purpose:49,inputScriptType:"SPENDP2SHWITNESS"},{id:"legacy",label:"Legacy",purpose:44,inputScriptType:"SPENDADDRESS"},{id:"taproot",label:"Taproot",purpose:86,inputScriptType:"SPENDTAPROOT"}];function n(e){let r=Number.parseInt(e.replace(/^m\//,"").split("/")[0]?.replace(/['h]$/,"")??"",10),t=o.find(i=>i.purpose===r);if(!t)throw new Error(`Unsupported Bitcoin derivation path: ${e}`);return t.inputScriptType}p(n,"resolveBitcoinScriptType");export{S as a,o as b,n as c};
2
+ //# sourceMappingURL=chunk-XMCEMEDS.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/utxo/config.ts"],
4
+ "sourcesContent": ["/*\n * Trezor needs the input `script_type` to sign a Bitcoin input. It is determined by the\n * BIP-43 `purpose` of the derivation path the address was derived from, so we expose the\n * four common address types and let the user connect whichever one they hold funds on.\n */\nexport type TrezorInputScriptType =\n | 'SPENDADDRESS'\n | 'SPENDP2SHWITNESS'\n | 'SPENDWITNESS'\n | 'SPENDTAPROOT';\n\nexport interface BitcoinAddressType {\n /** Stable id used in the derivationPath metadata entries. */\n id: 'legacy' | 'nested-segwit' | 'native-segwit' | 'taproot';\n label: string;\n /** BIP-43 purpose: 44 legacy, 49 nested segwit, 84 native segwit, 86 taproot. */\n purpose: number;\n inputScriptType: TrezorInputScriptType;\n}\n\nexport const BITCOIN_COIN_NAME = 'btc';\n\nexport const BITCOIN_ADDRESS_TYPES: readonly BitcoinAddressType[] = [\n {\n id: 'native-segwit',\n label: 'Native SegWit',\n purpose: 84,\n inputScriptType: 'SPENDWITNESS',\n },\n {\n id: 'nested-segwit',\n label: 'Nested SegWit',\n purpose: 49,\n inputScriptType: 'SPENDP2SHWITNESS',\n },\n {\n id: 'legacy',\n label: 'Legacy',\n purpose: 44,\n inputScriptType: 'SPENDADDRESS',\n },\n {\n id: 'taproot',\n label: 'Taproot',\n purpose: 86,\n inputScriptType: 'SPENDTAPROOT',\n },\n] as const;\n\n/**\n * Resolve the Trezor input script type for a derivation path by reading its BIP-43\n * purpose (the first hardened level). The path always comes from one of our own\n * derivation templates, so an unknown purpose is a programming error.\n */\nexport function resolveBitcoinScriptType(path: string): TrezorInputScriptType {\n const purpose = Number.parseInt(\n path.replace(/^m\\//, '').split('/')[0]?.replace(/['h]$/, '') ?? '',\n 10\n );\n const addressType = BITCOIN_ADDRESS_TYPES.find(\n (type) => type.purpose === purpose\n );\n if (!addressType) {\n throw new Error(`Unsupported Bitcoin derivation path: ${path}`);\n }\n return addressType.inputScriptType;\n}\n"],
5
+ "mappings": "wCAoBO,IAAMA,EAAoB,MAEpBC,EAAuD,CAClE,CACE,GAAI,gBACJ,MAAO,gBACP,QAAS,GACT,gBAAiB,cACnB,EACA,CACE,GAAI,gBACJ,MAAO,gBACP,QAAS,GACT,gBAAiB,kBACnB,EACA,CACE,GAAI,SACJ,MAAO,SACP,QAAS,GACT,gBAAiB,cACnB,EACA,CACE,GAAI,UACJ,MAAO,UACP,QAAS,GACT,gBAAiB,cACnB,CACF,EAOO,SAASC,EAAyBC,EAAqC,CAC5E,IAAMC,EAAU,OAAO,SACrBD,EAAK,QAAQ,OAAQ,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC,GAAG,QAAQ,QAAS,EAAE,GAAK,GAChE,EACF,EACME,EAAcJ,EAAsB,KACvCK,GAASA,EAAK,UAAYF,CAC7B,EACA,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,wCAAwCF,CAAI,EAAE,EAEhE,OAAOE,EAAY,eACrB,CAZgBE,EAAAL,EAAA",
6
+ "names": ["BITCOIN_COIN_NAME", "BITCOIN_ADDRESS_TYPES", "resolveBitcoinScriptType", "path", "purpose", "addressType", "type", "__name"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{a as p,c as u,d as P,e as h,h as t}from"./chunk-WO4Y4OWN.js";import{cleanEvmError as G}from"@rango-dev/signer-evm";import{DEFAULT_ETHEREUM_RPC_URL as z}from"@rango-dev/wallets-shared";import{JsonRpcProvider as S,Transaction as b}from"ethers";import"rango-types";function R(r){return typeof r=="object"&&r!==null&&"shortMessage"in r&&typeof r.shortMessage=="string"?new Error(r.shortMessage,{cause:r}):G(r)}p(R,"getTrezorErrorMessage");var f=class{static{p(this,"EthereumSigner")}async signMessage(e){let n=await h(),{success:o,payload:s}=await n.ethereumSignMessage({message:e,path:u()});if(!o)throw new Error(s.error);return s.signature}async signAndSendTx(e,n,o){try{let s=await h(),{gasPrice:w,maxFeePerGas:i,maxPriorityFeePerGas:c}=e,a=i&&c;if(a&&!i)throw new Error("Missing maxFeePerGas");if(a&&!c)throw new Error("Missing maxPriorityFeePerGas");if(!a&&!w)throw new Error("Missing gasPrice");let d=new S(z),l=await d.getTransactionCount(n),E=a?{maxFeePerGas:t(i||"0"),maxPriorityFeePerGas:t(c||"0")}:{gasPrice:t(w||"0")},g={to:e.to,data:e.data||"0x",value:t(e.value?.toString()||"0"),gasLimit:t(e.gasLimit?.toString()||"0"),chainId:Number.parseInt(o),nonce:t(l.toString()),...E},{success:T,payload:m}=await s.ethereumSignTransaction({path:u(),transaction:g});if(!T){let F=P[m?.code||""]||m.error;throw new Error(F)}let{r:y,s:M,v}=m,x=b.from({...g,nonce:Number.parseInt(g.nonce),type:a?2:0,signature:{r:y,s:M,v:parseInt(v)}}).serialized;return{hash:(await d.broadcastTransaction(x)).hash}}catch(s){throw R(s)}}};export{f as EthereumSigner,R as getTrezorErrorMessage};
2
- //# sourceMappingURL=ethereum-EMJ4SXYX.js.map
1
+ import{a as p,c as u,f as P,g as h,j as t}from"./chunk-S7XQ7HPI.js";import{cleanEvmError as G}from"@rango-dev/signer-evm";import{DEFAULT_ETHEREUM_RPC_URL as z}from"@rango-dev/wallets-shared";import{JsonRpcProvider as S,Transaction as b}from"ethers";import"rango-types";function R(r){return typeof r=="object"&&r!==null&&"shortMessage"in r&&typeof r.shortMessage=="string"?new Error(r.shortMessage,{cause:r}):G(r)}p(R,"getTrezorErrorMessage");var f=class{static{p(this,"EthereumSigner")}async signMessage(e){let n=await h(),{success:o,payload:s}=await n.ethereumSignMessage({message:e,path:u()});if(!o)throw new Error(s.error);return s.signature}async signAndSendTx(e,n,o){try{let s=await h(),{gasPrice:w,maxFeePerGas:i,maxPriorityFeePerGas:c}=e,a=i&&c;if(a&&!i)throw new Error("Missing maxFeePerGas");if(a&&!c)throw new Error("Missing maxPriorityFeePerGas");if(!a&&!w)throw new Error("Missing gasPrice");let d=new S(z),l=await d.getTransactionCount(n),E=a?{maxFeePerGas:t(i||"0"),maxPriorityFeePerGas:t(c||"0")}:{gasPrice:t(w||"0")},g={to:e.to,data:e.data||"0x",value:t(e.value?.toString()||"0"),gasLimit:t(e.gasLimit?.toString()||"0"),chainId:Number.parseInt(o),nonce:t(l.toString()),...E},{success:T,payload:m}=await s.ethereumSignTransaction({path:u(),transaction:g});if(!T){let F=P[m?.code||""]||m.error;throw new Error(F)}let{r:y,s:M,v}=m,x=b.from({...g,nonce:Number.parseInt(g.nonce),type:a?2:0,signature:{r:y,s:M,v:parseInt(v)}}).serialized;return{hash:(await d.broadcastTransaction(x)).hash}}catch(s){throw R(s)}}};export{f as EthereumSigner,R as getTrezorErrorMessage};
2
+ //# sourceMappingURL=ethereum-67ZOG2D6.js.map
package/dist/init.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function initTrezor(): Promise<void>;
package/dist/mod.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const versions: () => readonly [readonly ["0.0.0", import("@rango-dev/wallets-core/legacy").LegacyProviderInterface], readonly ["1.0.0", import("@hub3js/core").Provider<Record<"evm", import("@hub3js/evm").EvmActions>>]];
1
+ declare const versions: () => readonly [readonly ["0.0.0", import("@rango-dev/wallets-core/legacy").LegacyProviderInterface], readonly ["1.0.0", import("@hub3js/core").Provider<Record<"evm", import("@hub3js/evm").EvmActions> & Record<"utxo", import("@rango-dev/wallets-core/namespaces/utxo").UtxoActions>>]];
2
2
  export { versions };
package/dist/mod.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as o,b as s,e as c,f as d,g as m,i as l}from"./chunk-WO4Y4OWN.js";import{defineVersions as j}from"@hub3js/core/utils";import{Networks as f,WalletTypes as L}from"@rango-dev/wallets-shared";import"rango-types";import{dynamicImportWithRefinedError as z}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as b,TransactionType as x}from"rango-types";async function i(){let e=new b,{EthereumSigner:r}=await z(async()=>await import("./ethereum-EMJ4SXYX.js"));return e.registerSigner(x.EVM,new r),e}o(i,"getSigners");var I={appUrl:"",email:""},D={type:L.TREZOR};var k=d,g=!1,A=o(async({namespaces:e})=>{let r=[],n=await c(),t=e?.find(a=>a.namespace==="EVM");if(t)if(t.derivationPath){s(l(t.derivationPath)),g||(await n.init({lazyLoad:!0,manifest:I}),g=!0);let a=await m();r.push(a)}else throw new Error("Derivation Path can not be empty.");else throw new Error(`It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${e?.map(a=>a.namespace)}`);return r},"connect"),C=i,S=o(e=>{let r=[],n=e.find(t=>t.name===f.ETHEREUM);return n&&r.push(n),{name:"Trezor",img:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg",installLink:{DEFAULT:"https://trezor.io/learn/a/download-verify-trezor-suite"},color:"black",supportedChains:r,showOnMobile:!1,needsNamespace:{selection:"single",data:[{id:"ETH",value:"EVM",label:"Ethereum",getSupportedChains:t=>t.filter(a=>a.name===f.ETHEREUM)}]},needsDerivationPath:{data:[{id:"metamask",label:"Metamask (m/44'/60'/0'/0/index)",namespace:"EVM",generateDerivationPath:t=>`44'/60'/0'/0/${t}`},{id:"ledgerLive",label:"LedgerLive (m/44'/60'/index'/0/0)",namespace:"EVM",generateDerivationPath:t=>`44'/60'/${t}'/0/0`},{id:"legacy",label:"Legacy (m/44'/60'/0'/index)",namespace:"EVM",generateDerivationPath:t=>`44'/60'/0'/${t}`}]}}},"getWalletInfo"),u=o(()=>({config:D,getInstance:k,connect:A,getSigners:C,getWalletInfo:S}),"buildLegacyProvider");import{ProviderBuilder as U}from"@hub3js/core";import{Networks as B,WalletTypes as V}from"@rango-dev/wallets-shared";import"rango-types";var p=V.TREZOR,v={name:"Trezor",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg",extensions:{homepage:"https://trezor.io/learn/a/download-verify-trezor-suite"},properties:[{name:"namespaces",value:{selection:"single",data:[{label:"Ethereum",value:"EVM",id:"ETH",getSupportedChains:e=>e.filter(r=>r.name===B.ETHEREUM)}]}},{name:"derivationPath",value:{data:[{id:"metamask",label:"Metamask (m/44'/60'/0'/0/index)",namespace:"EVM",generateDerivationPath:e=>`44'/60'/0'/0/${e}`},{id:"ledgerLive",label:"LedgerLive (m/44'/60'/index'/0/0)",namespace:"EVM",generateDerivationPath:e=>`44'/60'/${e}'/0/0`},{id:"legacy",label:"Legacy (m/44'/60'/0'/index)",namespace:"EVM",generateDerivationPath:e=>`44'/60'/0'/${e}`}]}},{name:"signers",value:{getSigners:async()=>i()}}]};import{NamespaceBuilder as R}from"@hub3js/core";import{builders as E,utils as W}from"@hub3js/evm";import*as y from"@hub3js/std/builders";import{standardizeAndThrowError as N}from"@hub3js/std/operators";import{ETHEREUM_CHAIN_ID as H}from"@rango-dev/wallets-shared";var h=!1,_=E.connect().action(async function(e,r,n){if(!n?.derivationPath)throw new Error("Derivation Path can not be empty.");s(l(n.derivationPath)),h||(await(await c()).init({lazyLoad:!0,manifest:P()}),h=!0);let t=await m();return{accounts:W.formatAccountsToCAIP(t.accounts,t.chainId),network:t.chainId}}).or(N).build(),$=y.disconnect().build(),F=E.getChainId().action(()=>H).build(),T=new R("EVM",p).action(_).action($).action(F).build();var w,P=o(()=>w,"getTrezorManifest"),M=o(()=>new U(p).init(function(e,r){let[,n]=e.state();if(!r.manifest)throw new Error("Trezor manifest is required");w=r.manifest,n("installed",!0),console.debug("[trezor] instance detected.",e)}).config("metadata",v).add("evm",T).build(),"buildProvider");var ze=o(()=>j().version("0.0.0",u()).version("1.0.0",M()).build(),"versions");export{ze as versions};
1
+ import{a as h,b as v,c as y}from"./chunk-XMCEMEDS.js";import{a as n,b as p,d as f,g as a,h as g,i as l,k as s}from"./chunk-S7XQ7HPI.js";import{defineVersions as ce}from"@hub3js/core/utils";import{Networks as w,WalletTypes as U}from"@rango-dev/wallets-shared";import"rango-types";import{dynamicImportWithRefinedError as E}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as R,TransactionType as T}from"rango-types";async function m(){let e=new R,{EthereumSigner:t}=await E(async()=>await import("./ethereum-67ZOG2D6.js")),{BTCSigner:r}=await E(async()=>await import("./utxo-J5P5Q6IJ.js"));return e.registerSigner(T.EVM,new t),e.registerSigner(T.TRANSFER,new r),e}n(m,"getSigners");var V={appUrl:"",email:""},W={type:U.TREZOR};var $=g,x=!1,O=n(async({namespaces:e})=>{let t=[],r=await a(),o=e?.find(i=>i.namespace==="EVM");if(o)if(o.derivationPath){p(s(o.derivationPath)),x||(await r.init({lazyLoad:!0,manifest:V}),x=!0);let i=await l();t.push(i)}else throw new Error("Derivation Path can not be empty.");else throw new Error(`It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${e?.map(i=>i.namespace)}`);return t},"connect"),F=m,H=n(e=>{let t=[],r=e.find(o=>o.name===w.ETHEREUM);return r&&t.push(r),{name:"Trezor",img:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg",installLink:{DEFAULT:"https://trezor.io/learn/a/download-verify-trezor-suite"},color:"black",supportedChains:t,showOnMobile:!1,needsNamespace:{selection:"single",data:[{id:"ETH",value:"EVM",label:"Ethereum",getSupportedChains:o=>o.filter(i=>i.name===w.ETHEREUM)}]},needsDerivationPath:{data:[{id:"metamask",label:"Metamask (m/44'/60'/0'/0/index)",namespace:"EVM",generateDerivationPath:o=>`44'/60'/0'/0/${o}`},{id:"ledgerLive",label:"LedgerLive (m/44'/60'/index'/0/0)",namespace:"EVM",generateDerivationPath:o=>`44'/60'/${o}'/0/0`},{id:"legacy",label:"Legacy (m/44'/60'/0'/index)",namespace:"EVM",generateDerivationPath:o=>`44'/60'/0'/${o}`}]}}},"getWalletInfo"),P=n(()=>({config:W,getInstance:$,connect:O,getSigners:F,getWalletInfo:H}),"buildLegacyProvider");import{ProviderBuilder as se}from"@hub3js/core";import{Networks as z,WalletTypes as j}from"@rango-dev/wallets-shared";import"rango-types";var c=j.TREZOR,b={name:"Trezor",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg",extensions:{homepage:"https://trezor.io/learn/a/download-verify-trezor-suite"},properties:[{name:"namespaces",value:{selection:"single",data:[{label:"Ethereum",value:"EVM",id:"ETH",getSupportedChains:e=>e.filter(t=>t.name===z.ETHEREUM)},{label:"Bitcoin",value:"UTXO",id:"BTC",getSupportedChains:e=>e.filter(t=>t.name===z.BTC)}]}},{name:"derivationPath",value:{data:[{id:"metamask",label:"Metamask (m/44'/60'/0'/0/index)",namespace:"EVM",generateDerivationPath:e=>`44'/60'/0'/0/${e}`},{id:"ledgerLive",label:"LedgerLive (m/44'/60'/index'/0/0)",namespace:"EVM",generateDerivationPath:e=>`44'/60'/${e}'/0/0`},{id:"legacy",label:"Legacy (m/44'/60'/0'/index)",namespace:"EVM",generateDerivationPath:e=>`44'/60'/0'/${e}`},...v.map(e=>({id:`bitcoin-${e.id}`,label:`${e.label} (m/${e.purpose}'/0'/index')`,namespace:"UTXO",generateDerivationPath:t=>`${e.purpose}'/0'/${t}'/0/0`}))]}},{name:"signers",value:{getSigners:async()=>m()}}]};import{NamespaceBuilder as X}from"@hub3js/core";import{builders as A,utils as Y}from"@hub3js/evm";import*as C from"@hub3js/std/builders";import{standardizeAndThrowError as Z}from"@hub3js/std/operators";import{ETHEREUM_CHAIN_ID as q}from"@rango-dev/wallets-shared";var M=!1;async function d(){if(M)return;await(await a()).init({lazyLoad:!0,manifest:I()}),M=!0}n(d,"initTrezor");var G=A.connect().action(async function(e,t,r){if(!r?.derivationPath)throw new Error("Derivation Path can not be empty.");p(s(r.derivationPath)),await d();let o=await l();return{accounts:Y.formatAccountsToCAIP(o.accounts,o.chainId),network:o.chainId}}).or(Z).build(),J=C.disconnect().build(),K=A.getChainId().action(()=>q).build(),B=new X("EVM",c).action(G).action(J).action(K).build();import{NamespaceBuilder as oe}from"@hub3js/core";import*as L from"@hub3js/std/builders";import{standardizeAndThrowError as re}from"@hub3js/std/operators";import{builders as ne}from"@rango-dev/wallets-core/namespaces/utxo";import{CAIP_BITCOIN_CHAIN_ID as Q,utils as ee}from"@rango-dev/wallets-core/namespaces/utxo";function te(){return async(e,t)=>{if(!t?.derivationPath)throw new Error("Derivation Path can not be empty.");await d();let r=s(t.derivationPath),o=y(r);f(r);let u=await(await a()).getAddress({path:r,coin:h,scriptType:o,showOnTrezor:!1});if(!u.success)throw new Error(u.payload.error);let{address:_}=u.payload;return ee.formatAccountsToCAIP([_],Q)}}n(te,"connect");var D={connect:te};var ie=ne.connect().action(D.connect()).or(re).build(),ae=L.disconnect().build(),S=new oe("UTXO",c).action(ie).action(ae).build();var k,I=n(()=>k,"getTrezorManifest"),N=n(()=>new se(c).init(function(e,t){let[,r]=e.state();if(!t.manifest)throw new Error("Trezor manifest is required");k=t.manifest,r("installed",!0),console.debug("[trezor] instance detected.",e)}).config("metadata",b).add("evm",B).add("utxo",S).build(),"buildProvider");var at=n(()=>ce().version("0.0.0",P()).version("1.0.0",N()).build(),"versions");export{at as versions};
2
2
  //# sourceMappingURL=mod.js.map
package/dist/mod.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/mod.ts", "../src/legacy/index.ts", "../src/signer.ts", "../src/provider.ts", "../src/constants.ts", "../src/namespaces/evm.ts"],
4
- "sourcesContent": ["import { defineVersions } from '@hub3js/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 { Environments } from '../types.js';\nimport type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';\nimport type {\n Connect,\n ProviderConnectResult,\n WalletInfo,\n} from '@rango-dev/wallets-shared';\n\nimport { Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport { type BlockchainMeta, type SignerFactory } from 'rango-types';\n\nimport signer from '../signer.js';\nimport { setDerivationPath } from '../state.js';\n\nimport {\n getEthereumAccounts,\n getTrezorInstance,\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from './helpers.js';\n\nlet trezorManifest: Environments['manifest'] = {\n appUrl: '',\n email: '',\n};\nexport const config = {\n type: WalletTypes.TREZOR,\n};\n\nexport type { Environments };\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Provider = any;\n\nexport const init = (environments: Environments) => {\n trezorManifest = environments.manifest;\n};\n\nexport const getInstance = getTrezorInstance;\n\nlet isTrezorInitialized = false;\nexport const connect: Connect = async ({ namespaces }) => {\n const results: ProviderConnectResult[] = [];\n\n const TrezorConnect = await getTrezorModule();\n\n const evmNamespace = namespaces?.find(\n (namespaceItem) => namespaceItem.namespace === 'EVM'\n );\n\n if (evmNamespace) {\n if (evmNamespace.derivationPath) {\n setDerivationPath(\n getTrezorNormalizedDerivationPath(evmNamespace.derivationPath)\n );\n\n if (!isTrezorInitialized) {\n await TrezorConnect.init({\n lazyLoad: true, // this param will prevent iframe injection until TrezorConnect.method will be called\n manifest: trezorManifest,\n });\n\n isTrezorInitialized = true;\n }\n\n const accounts = await getEthereumAccounts();\n results.push(accounts);\n } else {\n throw new Error('Derivation Path can not be empty.');\n }\n } else {\n throw new Error(\n `It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${namespaces?.map(\n (namespaceItem) => namespaceItem.namespace\n )}`\n );\n }\n\n return results;\n};\n\nexport const getSigners: (provider: Provider) => Promise<SignerFactory> =\n signer;\n\nexport const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (\n allBlockChains\n) => {\n const supportedChains: BlockchainMeta[] = [];\n\n const ethereumBlockchain = allBlockChains.find(\n (chain) => chain.name === Networks.ETHEREUM\n );\n if (ethereumBlockchain) {\n supportedChains.push(ethereumBlockchain);\n }\n\n return {\n name: 'Trezor',\n img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg',\n installLink: {\n DEFAULT: 'https://trezor.io/learn/a/download-verify-trezor-suite',\n },\n color: 'black',\n supportedChains,\n showOnMobile: false,\n\n needsNamespace: {\n selection: 'single',\n data: [\n {\n id: 'ETH',\n value: 'EVM',\n label: 'Ethereum',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter((chain) => chain.name === Networks.ETHEREUM),\n },\n ],\n },\n needsDerivationPath: {\n data: [\n {\n id: 'metamask',\n label: `Metamask (m/44'/60'/0'/0/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/0/${index}`,\n },\n {\n id: 'ledgerLive',\n label: `LedgerLive (m/44'/60'/index'/0/0)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/${index}'/0/0`,\n },\n {\n id: 'legacy',\n label: `Legacy (m/44'/60'/0'/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,\n },\n ],\n },\n };\n};\n\nconst buildLegacyProvider: () => LegacyProviderInterface = () => ({\n config,\n getInstance,\n connect,\n getSigners,\n getWalletInfo,\n});\n\nexport { buildLegacyProvider };\n", "import type { SignerFactory } from 'rango-types';\n\nimport { dynamicImportWithRefinedError } from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(): Promise<SignerFactory> {\n const signers = new DefaultSignerFactory();\n const { EthereumSigner } = await dynamicImportWithRefinedError(\n async () => await import('./signers/ethereum.js')\n );\n signers.registerSigner(TxType.EVM, new EthereumSigner());\n return signers;\n}\n", "import type { Environments } from './types.js';\n\nimport { ProviderBuilder } from '@hub3js/core';\n\nimport { metadata, WALLET_ID } from './constants.js';\nimport { evm } from './namespaces/evm.js';\n\nlet trezorManifest: Environments['manifest'];\n\nexport const getTrezorManifest = () => trezorManifest;\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context, environments: Environments) {\n const [, setState] = context.state();\n\n if (!environments.manifest) {\n throw new Error('Trezor manifest is required');\n }\n\n trezorManifest = environments.manifest;\n setState('installed', true);\n console.debug('[trezor] instance detected.', context);\n })\n .config('metadata', metadata)\n .add('evm', evm)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport { Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport { type BlockchainMeta } from 'rango-types';\n\nimport getSigners from './signer.js';\n\nexport const WALLET_ID = WalletTypes.TREZOR;\n\nexport const metadata: ProviderMetadata = {\n name: 'Trezor',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg',\n extensions: {\n homepage: 'https://trezor.io/learn/a/download-verify-trezor-suite',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'single',\n data: [\n {\n label: 'Ethereum',\n value: 'EVM',\n id: 'ETH',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter(\n (chain) => chain.name === Networks.ETHEREUM\n ),\n },\n ],\n },\n },\n {\n name: 'derivationPath',\n value: {\n data: [\n {\n id: 'metamask',\n label: `Metamask (m/44'/60'/0'/0/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/0/${index}`,\n },\n {\n id: 'ledgerLive',\n label: `LedgerLive (m/44'/60'/index'/0/0)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/${index}'/0/0`,\n },\n {\n id: 'legacy',\n label: `Legacy (m/44'/60'/0'/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners() },\n },\n ],\n};\n", "import type { EvmActions } from '@hub3js/evm';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport { builders, utils } from '@hub3js/evm';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { ETHEREUM_CHAIN_ID } from '@rango-dev/wallets-shared';\n\nimport { WALLET_ID } from '../constants.js';\nimport {\n getEthereumAccounts,\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from '../legacy/helpers.js';\nimport { getTrezorManifest } from '../provider.js';\nimport { setDerivationPath } from '../state.js';\n\nlet isTrezorInitialized = false;\n\nconst connect = builders\n .connect()\n .action(async function (_context, _chain, options) {\n if (!options?.derivationPath) {\n throw new Error('Derivation Path can not be empty.');\n }\n setDerivationPath(\n getTrezorNormalizedDerivationPath(options.derivationPath)\n );\n\n if (!isTrezorInitialized) {\n const TrezorConnect = await getTrezorModule();\n await TrezorConnect.init({\n lazyLoad: true, // this param will prevent iframe injection until TrezorConnect.method will be called\n manifest: getTrezorManifest(),\n });\n isTrezorInitialized = true;\n }\n\n const result = await getEthereumAccounts();\n\n const formatAccounts = utils.formatAccountsToCAIP(\n result.accounts,\n result.chainId\n );\n\n return {\n accounts: formatAccounts,\n network: result.chainId,\n };\n })\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders.disconnect<EvmActions>().build();\n\nconst getChainId = builders\n .getChainId()\n .action(() => ETHEREUM_CHAIN_ID)\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(getChainId)\n .build();\n\nexport { evm };\n"],
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,SAC9BC,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,8BAA+BF,CAAO,CACtD,CAAC,EACA,OAAO,WAAYG,CAAQ,EAC3B,IAAI,MAAOC,CAAG,EACd,MAAM,EAfW,iBHNtB,IAAMC,GAAWC,EAAA,IACfC,EAAe,EACZ,QAAQ,QAASC,EAAoB,CAAC,EACtC,QAAQ,QAASC,EAAc,CAAC,EAChC,MAAM,EAJM",
6
- "names": ["defineVersions", "Networks", "WalletTypes", "dynamicImportWithRefinedError", "DefaultSignerFactory", "TxType", "getSigners", "signers", "DefaultSignerFactory", "EthereumSigner", "dynamicImportWithRefinedError", "TxType", "__name", "trezorManifest", "config", "WalletTypes", "getInstance", "getTrezorInstance", "isTrezorInitialized", "connect", "__name", "namespaces", "results", "TrezorConnect", "getTrezorModule", "evmNamespace", "namespaceItem", "setDerivationPath", "getTrezorNormalizedDerivationPath", "trezorManifest", "accounts", "getEthereumAccounts", "getSigners", "getWalletInfo", "allBlockChains", "supportedChains", "ethereumBlockchain", "chain", "Networks", "allBlockchains", "index", "buildLegacyProvider", "config", "ProviderBuilder", "Networks", "WalletTypes", "WALLET_ID", "WalletTypes", "metadata", "allBlockchains", "chain", "Networks", "index", "getSigners", "NamespaceBuilder", "builders", "utils", "commonBuilders", "standardizeAndThrowError", "ETHEREUM_CHAIN_ID", "isTrezorInitialized", "connect", "builders", "_context", "_chain", "options", "setDerivationPath", "getTrezorNormalizedDerivationPath", "getTrezorModule", "getTrezorManifest", "result", "getEthereumAccounts", "utils", "standardizeAndThrowError", "disconnect", "getChainId", "ETHEREUM_CHAIN_ID", "evm", "NamespaceBuilder", "WALLET_ID", "trezorManifest", "getTrezorManifest", "__name", "buildProvider", "ProviderBuilder", "WALLET_ID", "context", "environments", "setState", "metadata", "evm", "versions", "__name", "defineVersions", "buildLegacyProvider", "buildProvider"]
3
+ "sources": ["../src/mod.ts", "../src/legacy/index.ts", "../src/signer.ts", "../src/provider.ts", "../src/constants.ts", "../src/namespaces/evm.ts", "../src/init.ts", "../src/namespaces/utxo.ts", "../src/actions/utxo.ts"],
4
+ "sourcesContent": ["import { defineVersions } from '@hub3js/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 { Environments } from '../types.js';\nimport type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';\nimport type {\n Connect,\n ProviderConnectResult,\n WalletInfo,\n} from '@rango-dev/wallets-shared';\n\nimport { Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport { type BlockchainMeta, type SignerFactory } from 'rango-types';\n\nimport signer from '../signer.js';\nimport { setDerivationPath } from '../state.js';\n\nimport {\n getEthereumAccounts,\n getTrezorInstance,\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from './helpers.js';\n\nlet trezorManifest: Environments['manifest'] = {\n appUrl: '',\n email: '',\n};\nexport const config = {\n type: WalletTypes.TREZOR,\n};\n\nexport type { Environments };\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Provider = any;\n\nexport const init = (environments: Environments) => {\n trezorManifest = environments.manifest;\n};\n\nexport const getInstance = getTrezorInstance;\n\nlet isTrezorInitialized = false;\nexport const connect: Connect = async ({ namespaces }) => {\n const results: ProviderConnectResult[] = [];\n\n const TrezorConnect = await getTrezorModule();\n\n const evmNamespace = namespaces?.find(\n (namespaceItem) => namespaceItem.namespace === 'EVM'\n );\n\n if (evmNamespace) {\n if (evmNamespace.derivationPath) {\n setDerivationPath(\n getTrezorNormalizedDerivationPath(evmNamespace.derivationPath)\n );\n\n if (!isTrezorInitialized) {\n await TrezorConnect.init({\n lazyLoad: true, // this param will prevent iframe injection until TrezorConnect.method will be called\n manifest: trezorManifest,\n });\n\n isTrezorInitialized = true;\n }\n\n const accounts = await getEthereumAccounts();\n results.push(accounts);\n } else {\n throw new Error('Derivation Path can not be empty.');\n }\n } else {\n throw new Error(\n `It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${namespaces?.map(\n (namespaceItem) => namespaceItem.namespace\n )}`\n );\n }\n\n return results;\n};\n\nexport const getSigners: (provider: Provider) => Promise<SignerFactory> =\n signer;\n\nexport const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (\n allBlockChains\n) => {\n const supportedChains: BlockchainMeta[] = [];\n\n const ethereumBlockchain = allBlockChains.find(\n (chain) => chain.name === Networks.ETHEREUM\n );\n if (ethereumBlockchain) {\n supportedChains.push(ethereumBlockchain);\n }\n\n return {\n name: 'Trezor',\n img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg',\n installLink: {\n DEFAULT: 'https://trezor.io/learn/a/download-verify-trezor-suite',\n },\n color: 'black',\n supportedChains,\n showOnMobile: false,\n\n needsNamespace: {\n selection: 'single',\n data: [\n {\n id: 'ETH',\n value: 'EVM',\n label: 'Ethereum',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter((chain) => chain.name === Networks.ETHEREUM),\n },\n ],\n },\n needsDerivationPath: {\n data: [\n {\n id: 'metamask',\n label: `Metamask (m/44'/60'/0'/0/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/0/${index}`,\n },\n {\n id: 'ledgerLive',\n label: `LedgerLive (m/44'/60'/index'/0/0)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/${index}'/0/0`,\n },\n {\n id: 'legacy',\n label: `Legacy (m/44'/60'/0'/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,\n },\n ],\n },\n };\n};\n\nconst buildLegacyProvider: () => LegacyProviderInterface = () => ({\n config,\n getInstance,\n connect,\n getSigners,\n getWalletInfo,\n});\n\nexport { buildLegacyProvider };\n", "import type { SignerFactory } from 'rango-types';\n\nimport { dynamicImportWithRefinedError } from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(): Promise<SignerFactory> {\n const signers = new DefaultSignerFactory();\n const { EthereumSigner } = await dynamicImportWithRefinedError(\n async () => await import('./signers/ethereum.js')\n );\n const { BTCSigner } = await dynamicImportWithRefinedError(\n async () => await import('./signers/utxo.js')\n );\n signers.registerSigner(TxType.EVM, new EthereumSigner());\n signers.registerSigner(TxType.TRANSFER, new BTCSigner());\n return signers;\n}\n", "import type { Environments } from './types.js';\n\nimport { ProviderBuilder } from '@hub3js/core';\n\nimport { metadata, WALLET_ID } from './constants.js';\nimport { evm } from './namespaces/evm.js';\nimport { utxo } from './namespaces/utxo.js';\n\nlet trezorManifest: Environments['manifest'];\n\nexport const getTrezorManifest = () => trezorManifest;\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context, environments: Environments) {\n const [, setState] = context.state();\n\n if (!environments.manifest) {\n throw new Error('Trezor manifest is required');\n }\n\n trezorManifest = environments.manifest;\n setState('installed', true);\n console.debug('[trezor] instance detected.', context);\n })\n .config('metadata', metadata)\n .add('evm', evm)\n .add('utxo', utxo)\n .build();\n\nexport { buildProvider };\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport { Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport { type BlockchainMeta, type TransferBlockchainMeta } from 'rango-types';\n\nimport getSigners from './signer.js';\nimport { BITCOIN_ADDRESS_TYPES } from './utxo/config.js';\n\nexport const WALLET_ID = WalletTypes.TREZOR;\n\nexport const metadata: ProviderMetadata = {\n name: 'Trezor',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg',\n extensions: {\n homepage: 'https://trezor.io/learn/a/download-verify-trezor-suite',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'single',\n data: [\n {\n label: 'Ethereum',\n value: 'EVM',\n id: 'ETH',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter(\n (chain) => chain.name === Networks.ETHEREUM\n ),\n },\n {\n label: 'Bitcoin',\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 name: 'derivationPath',\n value: {\n data: [\n {\n id: 'metamask',\n label: `Metamask (m/44'/60'/0'/0/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/0/${index}`,\n },\n {\n id: 'ledgerLive',\n label: `LedgerLive (m/44'/60'/index'/0/0)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/${index}'/0/0`,\n },\n {\n id: 'legacy',\n label: `Legacy (m/44'/60'/0'/index)`,\n namespace: 'EVM',\n generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,\n },\n /*\n * Bitcoin derivation templates. The BIP-43 purpose (and thus the address\n * type) is what the user picks here; `index` selects the account.\n */\n ...BITCOIN_ADDRESS_TYPES.map((addressType) => ({\n id: `bitcoin-${addressType.id}`,\n label: `${addressType.label} (m/${addressType.purpose}'/0'/index')`,\n namespace: 'UTXO',\n generateDerivationPath: (index: string) =>\n `${addressType.purpose}'/0'/${index}'/0/0`,\n })),\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners() },\n },\n ],\n};\n", "import type { EvmActions } from '@hub3js/evm';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport { builders, utils } from '@hub3js/evm';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { ETHEREUM_CHAIN_ID } from '@rango-dev/wallets-shared';\n\nimport { WALLET_ID } from '../constants.js';\nimport { initTrezor } from '../init.js';\nimport {\n getEthereumAccounts,\n getTrezorNormalizedDerivationPath,\n} from '../legacy/helpers.js';\nimport { setDerivationPath } from '../state.js';\n\nconst connect = builders\n .connect()\n .action(async function (_context, _chain, options) {\n if (!options?.derivationPath) {\n throw new Error('Derivation Path can not be empty.');\n }\n setDerivationPath(\n getTrezorNormalizedDerivationPath(options.derivationPath)\n );\n\n await initTrezor();\n\n const result = await getEthereumAccounts();\n\n const formatAccounts = utils.formatAccountsToCAIP(\n result.accounts,\n result.chainId\n );\n\n return {\n accounts: formatAccounts,\n network: result.chainId,\n };\n })\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders.disconnect<EvmActions>().build();\n\nconst getChainId = builders\n .getChainId()\n .action(() => ETHEREUM_CHAIN_ID)\n .build();\n\nconst evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(getChainId)\n .build();\n\nexport { evm };\n", "import { getTrezorModule } from './legacy/helpers.js';\nimport { getTrezorManifest } from './provider.js';\n\nlet isTrezorInitialized = false;\n\n/*\n * `TrezorConnect.init` throws if called twice, so initialization is shared across every\n * namespace (EVM, UTXO). `lazyLoad` defers iframe injection until the first method call.\n */\nexport async function initTrezor() {\n if (isTrezorInitialized) {\n return;\n }\n const TrezorConnect = await getTrezorModule();\n await TrezorConnect.init({\n lazyLoad: true,\n manifest: getTrezorManifest(),\n });\n isTrezorInitialized = true;\n}\n", "import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { builders } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { utxoActions } from '../actions/utxo.js';\nimport { WALLET_ID } from '../constants.js';\n\nconst connect = builders\n .connect()\n .action(utxoActions.connect())\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders.disconnect<UtxoActions>().build();\n\nconst utxo = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .build();\n\nexport { utxo };\n", "import type { Context, FunctionWithContext } from '@hub3js/core';\nimport type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n utils,\n} from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { initTrezor } from '../init.js';\nimport {\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from '../legacy/helpers.js';\nimport { setBitcoinDerivationPath } from '../state.js';\nimport { BITCOIN_COIN_NAME, resolveBitcoinScriptType } from '../utxo/config.js';\n\n/**\n * Connect the Bitcoin account for the selected derivation path: derive the receive\n * address and return it CAIP-encoded with the bip122 Bitcoin chain id. The path is kept\n * (like the EVM namespace does) because Rango's PSBT has no derivation data, so the\n * signer needs it at signing time.\n */\nexport function connect(): FunctionWithContext<\n UtxoActions['connect'],\n Context\n> {\n return async (_context, options) => {\n if (!options?.derivationPath) {\n throw new Error('Derivation Path can not be empty.');\n }\n\n await initTrezor();\n\n const path = getTrezorNormalizedDerivationPath(options.derivationPath);\n const inputScriptType = resolveBitcoinScriptType(path);\n setBitcoinDerivationPath(path);\n\n const TrezorConnect = await getTrezorModule();\n const result = await TrezorConnect.getAddress({\n path,\n coin: BITCOIN_COIN_NAME,\n scriptType: inputScriptType,\n showOnTrezor: false,\n });\n\n if (!result.success) {\n throw new Error(result.payload.error);\n }\n\n const { address } = result.payload;\n\n return utils.formatAccountsToCAIP([address], CAIP_BITCOIN_CHAIN_ID);\n };\n}\n\nexport const utxoActions = { connect };\n"],
5
+ "mappings": "wIAAA,OAAS,kBAAAA,OAAsB,qBCQ/B,OAAS,YAAAC,EAAU,eAAAC,MAAmB,4BACtC,MAAwD,cCPxD,OAAS,iCAAAC,MAAqC,4BAC9C,OAAS,wBAAAC,EAAsB,mBAAmBC,MAAc,cAEhE,eAAOC,GAA4D,CACjE,IAAMC,EAAU,IAAIC,EACd,CAAE,eAAAC,CAAe,EAAI,MAAMC,EAC/B,SAAY,KAAM,QAAO,wBAAuB,CAClD,EACM,CAAE,UAAAC,CAAU,EAAI,MAAMD,EAC1B,SAAY,KAAM,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,MAAOC,CAAG,EACd,IAAI,OAAQC,CAAI,EAChB,MAAM,EAhBW,iBHPtB,IAAMC,GAAWC,EAAA,IACfC,GAAe,EACZ,QAAQ,QAASC,EAAoB,CAAC,EACtC,QAAQ,QAASC,EAAc,CAAC,EAChC,MAAM,EAJM",
6
+ "names": ["defineVersions", "Networks", "WalletTypes", "dynamicImportWithRefinedError", "DefaultSignerFactory", "TxType", "getSigners", "signers", "DefaultSignerFactory", "EthereumSigner", "dynamicImportWithRefinedError", "BTCSigner", "TxType", "__name", "trezorManifest", "config", "WalletTypes", "getInstance", "getTrezorInstance", "isTrezorInitialized", "connect", "__name", "namespaces", "results", "TrezorConnect", "getTrezorModule", "evmNamespace", "namespaceItem", "setDerivationPath", "getTrezorNormalizedDerivationPath", "trezorManifest", "accounts", "getEthereumAccounts", "getSigners", "getWalletInfo", "allBlockChains", "supportedChains", "ethereumBlockchain", "chain", "Networks", "allBlockchains", "index", "buildLegacyProvider", "config", "ProviderBuilder", "Networks", "WalletTypes", "WALLET_ID", "WalletTypes", "metadata", "allBlockchains", "chain", "Networks", "index", "BITCOIN_ADDRESS_TYPES", "addressType", "getSigners", "NamespaceBuilder", "builders", "utils", "commonBuilders", "standardizeAndThrowError", "ETHEREUM_CHAIN_ID", "isTrezorInitialized", "initTrezor", "getTrezorModule", "getTrezorManifest", "__name", "connect", "builders", "_context", "_chain", "options", "setDerivationPath", "getTrezorNormalizedDerivationPath", "initTrezor", "result", "getEthereumAccounts", "utils", "standardizeAndThrowError", "disconnect", "getChainId", "ETHEREUM_CHAIN_ID", "evm", "NamespaceBuilder", "WALLET_ID", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "builders", "CAIP_BITCOIN_CHAIN_ID", "utils", "connect", "_context", "options", "initTrezor", "path", "getTrezorNormalizedDerivationPath", "inputScriptType", "resolveBitcoinScriptType", "setBitcoinDerivationPath", "result", "getTrezorModule", "BITCOIN_COIN_NAME", "address", "utils", "CAIP_BITCOIN_CHAIN_ID", "__name", "utxoActions", "connect", "builders", "utxoActions", "standardizeAndThrowError", "disconnect", "utxo", "NamespaceBuilder", "WALLET_ID", "trezorManifest", "getTrezorManifest", "__name", "buildProvider", "ProviderBuilder", "WALLET_ID", "context", "environments", "setState", "metadata", "evm", "utxo", "versions", "__name", "defineVersions", "buildLegacyProvider", "buildProvider"]
7
7
  }
@@ -0,0 +1,3 @@
1
+ import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
2
+ declare const utxo: import("@hub3js/core").ProxiedNamespace<UtxoActions>;
3
+ export { utxo };
@@ -1 +1 @@
1
- {"inputs":{"src/state.ts":{"bytes":290,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/helpers.ts":{"bytes":2431,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"src/state.ts","kind":"import-statement","original":"../state"},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signers/ethereum.ts":{"bytes":3820,"imports":[{"path":"@rango-dev/signer-evm","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"ethers","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"../legacy/helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signer.ts":{"bytes":526,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signers/ethereum.ts","kind":"dynamic-import","original":"./signers/ethereum.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/index.ts":{"bytes":4024,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"../signer.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/constants.ts":{"bytes":1774,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"}],"format":"esm"},"src/namespaces/evm.ts":{"bytes":1843,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/evm","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","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/legacy/helpers.ts","kind":"import-statement","original":"../legacy/helpers.js"},{"path":"src/provider.ts","kind":"import-statement","original":"../provider.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"}],"format":"esm"},"src/provider.ts":{"bytes":810,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/evm.ts","kind":"import-statement","original":"./namespaces/evm.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":321,"imports":[{"path":"@hub3js/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":14876},"dist/mod.js":{"imports":[{"path":"dist/chunk-WO4Y4OWN.js","kind":"import-statement"},{"path":"@hub3js/core/utils","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-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"dist/ethereum-EMJ4SXYX.js","kind":"dynamic-import"},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/evm","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/mod.ts":{"bytesInOutput":131},"src/legacy/index.ts":{"bytesInOutput":1528},"src/signer.ts":{"bytesInOutput":310},"src/provider.ts":{"bytesInOutput":339},"src/constants.ts":{"bytesInOutput":894},"src/namespaces/evm.ts":{"bytesInOutput":705}},"bytes":4038},"dist/ethereum-EMJ4SXYX.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6395},"dist/ethereum-EMJ4SXYX.js":{"imports":[{"path":"dist/chunk-WO4Y4OWN.js","kind":"import-statement"},{"path":"@rango-dev/signer-evm","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"ethers","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true}],"exports":["EthereumSigner","getTrezorErrorMessage"],"entryPoint":"src/signers/ethereum.ts","inputs":{"src/signers/ethereum.ts":{"bytesInOutput":1455}},"bytes":1625},"dist/chunk-WO4Y4OWN.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":4404},"dist/chunk-WO4Y4OWN.js":{"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true}],"exports":["a","b","c","d","e","f","g","h","i"],"inputs":{"src/state.ts":{"bytesInOutput":99},"src/legacy/helpers.ts":{"bytesInOutput":814}},"bytes":1107}}}
1
+ {"inputs":{"src/state.ts":{"bytes":744,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/helpers.ts":{"bytes":2431,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"src/state.ts","kind":"import-statement","original":"../state"},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signers/ethereum.ts":{"bytes":3820,"imports":[{"path":"@rango-dev/signer-evm","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"ethers","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"../legacy/helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/utxo/config.ts":{"bytes":1961,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/utxo/psbt.ts":{"bytes":3426,"imports":[{"path":"@bitcoinerlab/secp256k1","kind":"import-statement","external":true},{"path":"bitcoinjs-lib","kind":"import-statement","external":true},{"path":"src/utxo/config.ts","kind":"import-statement","original":"./config.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signers/utxo.ts":{"bytes":2638,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"../legacy/helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/utxo/config.ts","kind":"import-statement","original":"../utxo/config.js"},{"path":"src/utxo/psbt.ts","kind":"import-statement","original":"../utxo/psbt.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signer.ts":{"bytes":702,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signers/ethereum.ts","kind":"dynamic-import","original":"./signers/ethereum.js"},{"path":"src/signers/utxo.ts","kind":"dynamic-import","original":"./signers/utxo.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/legacy/index.ts":{"bytes":4024,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"../signer.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/constants.ts":{"bytes":2728,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"},{"path":"src/utxo/config.ts","kind":"import-statement","original":"./utxo/config.js"}],"format":"esm"},"src/init.ts":{"bytes":580,"imports":[{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"./legacy/helpers.js"},{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/evm.ts":{"bytes":1486,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/evm","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","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/init.ts","kind":"import-statement","original":"../init.js"},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"../legacy/helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"}],"format":"esm"},"src/actions/utxo.ts":{"bytes":1701,"imports":[{"path":"@rango-dev/wallets-core/namespaces/utxo","kind":"import-statement","external":true},{"path":"src/init.ts","kind":"import-statement","original":"../init.js"},{"path":"src/legacy/helpers.ts","kind":"import-statement","original":"../legacy/helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/utxo/config.ts","kind":"import-statement","original":"../utxo/config.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/utxo.ts":{"bytes":736,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/utxo","kind":"import-statement","external":true},{"path":"src/actions/utxo.ts","kind":"import-statement","original":"../actions/utxo.js"},{"path":"src/constants.ts","kind":"import-statement","original":"../constants.js"}],"format":"esm"},"src/provider.ts":{"bytes":878,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/evm.ts","kind":"import-statement","original":"./namespaces/evm.js"},{"path":"src/namespaces/utxo.ts","kind":"import-statement","original":"./namespaces/utxo.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":321,"imports":[{"path":"@hub3js/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":20839},"dist/mod.js":{"imports":[{"path":"dist/chunk-XMCEMEDS.js","kind":"import-statement"},{"path":"dist/chunk-S7XQ7HPI.js","kind":"import-statement"},{"path":"@hub3js/core/utils","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-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"dist/ethereum-67ZOG2D6.js","kind":"dynamic-import"},{"path":"dist/utxo-J5P5Q6IJ.js","kind":"dynamic-import"},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/evm","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/utxo","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/utxo","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/mod.ts":{"bytesInOutput":133},"src/legacy/index.ts":{"bytesInOutput":1528},"src/signer.ts":{"bytesInOutput":412},"src/provider.ts":{"bytesInOutput":355},"src/constants.ts":{"bytesInOutput":1141},"src/namespaces/evm.ts":{"bytesInOutput":650},"src/init.ts":{"bytesInOutput":113},"src/namespaces/utxo.ts":{"bytesInOutput":352},"src/actions/utxo.ts":{"bytesInOutput":475}},"bytes":5351},"dist/ethereum-67ZOG2D6.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6395},"dist/ethereum-67ZOG2D6.js":{"imports":[{"path":"dist/chunk-S7XQ7HPI.js","kind":"import-statement"},{"path":"@rango-dev/signer-evm","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"ethers","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true}],"exports":["EthereumSigner","getTrezorErrorMessage"],"entryPoint":"src/signers/ethereum.ts","inputs":{"src/signers/ethereum.ts":{"bytesInOutput":1455}},"bytes":1625},"dist/utxo-J5P5Q6IJ.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":9124},"dist/utxo-J5P5Q6IJ.js":{"imports":[{"path":"dist/chunk-XMCEMEDS.js","kind":"import-statement"},{"path":"dist/chunk-S7XQ7HPI.js","kind":"import-statement"},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@bitcoinerlab/secp256k1","kind":"import-statement","external":true},{"path":"bitcoinjs-lib","kind":"import-statement","external":true}],"exports":["BTCSigner"],"entryPoint":"src/signers/utxo.ts","inputs":{"src/signers/utxo.ts":{"bytesInOutput":1107},"src/utxo/psbt.ts":{"bytesInOutput":1006}},"bytes":2280},"dist/chunk-XMCEMEDS.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2802},"dist/chunk-XMCEMEDS.js":{"imports":[{"path":"dist/chunk-S7XQ7HPI.js","kind":"import-statement"}],"exports":["a","b","c"],"inputs":{"src/utxo/config.ts":{"bytesInOutput":585}},"bytes":698},"dist/chunk-S7XQ7HPI.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":5089},"dist/chunk-S7XQ7HPI.js":{"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true}],"exports":["a","b","c","d","e","f","g","h","i","j","k"],"inputs":{"src/state.ts":{"bytesInOutput":212},"src/legacy/helpers.ts":{"bytesInOutput":814}},"bytes":1234}}}
@@ -2,5 +2,5 @@ export declare const getTrezorManifest: () => {
2
2
  appUrl: string;
3
3
  email: string;
4
4
  };
5
- declare const buildProvider: () => import("@hub3js/core").Provider<Record<"evm", import("@hub3js/evm").EvmActions>>;
5
+ declare const buildProvider: () => import("@hub3js/core").Provider<Record<"evm", import("@hub3js/evm").EvmActions> & Record<"utxo", import("@rango-dev/wallets-core/namespaces/utxo").UtxoActions>>;
6
6
  export { buildProvider };
@@ -0,0 +1,8 @@
1
+ import type { GenericSigner, Transfer } from 'rango-types';
2
+ export declare class BTCSigner implements GenericSigner<Transfer> {
3
+ #private;
4
+ signMessage(): Promise<string>;
5
+ signAndSendTx(tx: Transfer): Promise<{
6
+ hash: string;
7
+ }>;
8
+ }
package/dist/state.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export declare function setDerivationPath(path: string): void;
2
2
  export declare function getDerivationPath(): string;
3
+ export declare function setBitcoinDerivationPath(path: string): void;
4
+ export declare function getBitcoinDerivationPath(): string;
@@ -0,0 +1,17 @@
1
+ export type TrezorInputScriptType = 'SPENDADDRESS' | 'SPENDP2SHWITNESS' | 'SPENDWITNESS' | 'SPENDTAPROOT';
2
+ export interface BitcoinAddressType {
3
+ /** Stable id used in the derivationPath metadata entries. */
4
+ id: 'legacy' | 'nested-segwit' | 'native-segwit' | 'taproot';
5
+ label: string;
6
+ /** BIP-43 purpose: 44 legacy, 49 nested segwit, 84 native segwit, 86 taproot. */
7
+ purpose: number;
8
+ inputScriptType: TrezorInputScriptType;
9
+ }
10
+ export declare const BITCOIN_COIN_NAME = "btc";
11
+ export declare const BITCOIN_ADDRESS_TYPES: readonly BitcoinAddressType[];
12
+ /**
13
+ * Resolve the Trezor input script type for a derivation path by reading its BIP-43
14
+ * purpose (the first hardened level). The path always comes from one of our own
15
+ * derivation templates, so an unknown purpose is a programming error.
16
+ */
17
+ export declare function resolveBitcoinScriptType(path: string): TrezorInputScriptType;
@@ -0,0 +1,29 @@
1
+ import type { SignTransaction } from '@trezor/connect-web';
2
+ import * as bitcoin from 'bitcoinjs-lib';
3
+ type TrezorInput = SignTransaction['inputs'][number];
4
+ type TrezorOutput = SignTransaction['outputs'][number];
5
+ export interface TrezorBitcoinTransaction {
6
+ inputs: TrezorInput[];
7
+ outputs: TrezorOutput[];
8
+ /** Transaction version from the PSBT — preserved so the signed tx matches Rango's. */
9
+ version: number;
10
+ /** Transaction locktime from the PSBT (e.g. for CLTV) — preserved as-is. */
11
+ locktime: number;
12
+ }
13
+ /**
14
+ * Translate Rango's unsigned PSBT into the transaction Trezor's `signTransaction` expects
15
+ * (Trezor has no "sign this PSBT" call). Every field that affects the resulting bytes is
16
+ * preserved: `version`, `locktime`, and per-input `sequence` (RBF / locktime signaling),
17
+ * alongside each input's amount and script.
18
+ *
19
+ * Rango's PSBT carries no derivation data, so the connected `path` (and the script type
20
+ * from its BIP-43 purpose) is applied to every input — Rango funds the swap from that
21
+ * single address. `refTxs` are omitted: Trezor Connect fetches previous transactions from
22
+ * its Blockbook backend. Pure function -> unit testable.
23
+ *
24
+ * Only SIGHASH_ALL is supported: a non-default per-input sighash can't be honored through
25
+ * Trezor's signTransaction, so we reject it rather than sign the wrong thing. Multisig /
26
+ * script-path spends are out of scope (Rango funds from a single-key address).
27
+ */
28
+ export declare function buildTrezorBitcoinTransaction(unsignedPsbtBase64: string, path: string, network?: bitcoin.Network): TrezorBitcoinTransaction;
29
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import{a as d,c as h}from"./chunk-XMCEMEDS.js";import{a as s,e as g,g as m}from"./chunk-S7XQ7HPI.js";import{Networks as S}from"@rango-dev/wallets-shared";import{SignerError as B}from"rango-types";import*as x from"@bitcoinerlab/secp256k1";import*as e from"bitcoinjs-lib";e.initEccLib(x);var z=s(o=>Buffer.from(o).reverse().toString("hex"),"reverseTxid");function l(o,n,c=e.networks.bitcoin){let r=e.Psbt.fromBase64(o,{network:c}),u=h(n),T=r.txInputs.map((t,p)=>{let i=r.data.inputs[p];if(i.sighashType!=null&&i.sighashType!==e.Transaction.SIGHASH_ALL)throw new Error(`PSBT input #${p} uses sighash type ${i.sighashType}; only SIGHASH_ALL is supported.`);let a=i.witnessUtxo??e.Transaction.fromBuffer(i.nonWitnessUtxo).outs[t.index];return{address_n:n,prev_hash:z(t.hash),prev_index:t.index,amount:a.value.toString(),script_type:u,sequence:t.sequence}}),f=r.txOutputs.map(t=>t.address?{script_type:"PAYTOADDRESS",address:t.address,amount:t.value.toString()}:{script_type:"PAYTOOPRETURN",amount:"0",op_return_data:(e.script.decompile(t.script)?.find(Buffer.isBuffer)??Buffer.alloc(0)).toString("hex")});return{inputs:T,outputs:f,version:r.version,locktime:r.locktime}}s(l,"buildTrezorBitcoinTransaction");function w(o){return new Error(o.code?`${o.error} (${o.code})`:o.error)}s(w,"getTrezorErrorMessage");var b=class{static{s(this,"BTCSigner")}async signMessage(){throw B.UnimplementedError("signMessage")}async signAndSendTx(n){let{blockchain:c}=n.asset;if(c!==S.BTC)throw new Error(`Signing ${c} transactions is not supported by Trezor.`);let{psbt:r}=n;if(!r)throw new Error("No PSBT found to sign. Ensure a valid PSBT is provided.");let u=g();if(!u)throw new Error("No connected Bitcoin account found. Please connect the wallet first.");let T=await m(),{inputs:f,outputs:t,version:p,locktime:i}=l(r.unsignedPsbtBase64,u),a=await T.signTransaction({coin:d,inputs:f,outputs:t,version:p,locktime:i,push:!0});if(!a.success)throw w(a.payload);return{hash:await this.#r(a.payload)}}async#r(n){if(n.txid)return n.txid;if(!n.serializedTx)throw new Error("Trezor did not return a transaction id.");let r=await(await m()).pushTransaction({tx:n.serializedTx,coin:d});if(!r.success)throw w(r.payload);return r.payload.txid}};export{b as BTCSigner};
2
+ //# sourceMappingURL=utxo-J5P5Q6IJ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/signers/utxo.ts", "../src/utxo/psbt.ts"],
4
+ "sourcesContent": ["import type { GenericSigner, Transfer } from 'rango-types';\n\nimport { Networks } from '@rango-dev/wallets-shared';\nimport { SignerError } from 'rango-types';\n\nimport { getTrezorModule } from '../legacy/helpers.js';\nimport { getBitcoinDerivationPath } from '../state.js';\nimport { BITCOIN_COIN_NAME } from '../utxo/config.js';\nimport { buildTrezorBitcoinTransaction } from '../utxo/psbt.js';\n\nfunction getTrezorErrorMessage(payload: { error: string; code?: string }) {\n return new Error(\n payload.code ? `${payload.error} (${payload.code})` : payload.error\n );\n}\n\nexport class BTCSigner implements GenericSigner<Transfer> {\n async signMessage(): Promise<string> {\n throw SignerError.UnimplementedError('signMessage');\n }\n\n async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {\n const { blockchain } = tx.asset;\n if (blockchain !== Networks.BTC) {\n throw new Error(\n `Signing ${blockchain} transactions is not supported by Trezor.`\n );\n }\n\n const { 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 const path = getBitcoinDerivationPath();\n if (!path) {\n throw new Error(\n 'No connected Bitcoin account found. Please connect the wallet first.'\n );\n }\n\n const TrezorConnect = await getTrezorModule();\n const { inputs, outputs, version, locktime } =\n buildTrezorBitcoinTransaction(psbt.unsignedPsbtBase64, path);\n\n // `push: true` signs and broadcasts via Trezor's Blockbook backend.\n const result = await TrezorConnect.signTransaction({\n coin: BITCOIN_COIN_NAME,\n inputs,\n outputs,\n version,\n locktime,\n push: true,\n });\n\n if (!result.success) {\n throw getTrezorErrorMessage(result.payload);\n }\n\n return { hash: await this.#resolveHash(result.payload) };\n }\n\n /**\n * `push: true` usually returns the txid directly. If it isn't present (older\n * firmware/connect), push the serialized transaction explicitly as a fallback.\n */\n async #resolveHash(payload: {\n txid?: string;\n serializedTx?: string;\n }): Promise<string> {\n if (payload.txid) {\n return payload.txid;\n }\n if (!payload.serializedTx) {\n throw new Error('Trezor did not return a transaction id.');\n }\n\n const TrezorConnect = await getTrezorModule();\n const pushResult = await TrezorConnect.pushTransaction({\n tx: payload.serializedTx,\n coin: BITCOIN_COIN_NAME,\n });\n if (!pushResult.success) {\n throw getTrezorErrorMessage(pushResult.payload);\n }\n return pushResult.payload.txid;\n }\n}\n", "import type { SignTransaction } from '@trezor/connect-web';\n\nimport * as ecc from '@bitcoinerlab/secp256k1';\nimport * as bitcoin from 'bitcoinjs-lib';\n\nimport { resolveBitcoinScriptType } from './config.js';\n\n// Lets bitcoinjs-lib decode taproot (witness v1) output addresses.\nbitcoin.initEccLib(ecc);\n\ntype TrezorInput = SignTransaction['inputs'][number];\ntype TrezorOutput = SignTransaction['outputs'][number];\n\nexport interface TrezorBitcoinTransaction {\n inputs: TrezorInput[];\n outputs: TrezorOutput[];\n /** Transaction version from the PSBT \u2014 preserved so the signed tx matches Rango's. */\n version: number;\n /** Transaction locktime from the PSBT (e.g. for CLTV) \u2014 preserved as-is. */\n locktime: number;\n}\n\nconst reverseTxid = (hash: Buffer) =>\n Buffer.from(hash).reverse().toString('hex');\n\n/**\n * Translate Rango's unsigned PSBT into the transaction Trezor's `signTransaction` expects\n * (Trezor has no \"sign this PSBT\" call). Every field that affects the resulting bytes is\n * preserved: `version`, `locktime`, and per-input `sequence` (RBF / locktime signaling),\n * alongside each input's amount and script.\n *\n * Rango's PSBT carries no derivation data, so the connected `path` (and the script type\n * from its BIP-43 purpose) is applied to every input \u2014 Rango funds the swap from that\n * single address. `refTxs` are omitted: Trezor Connect fetches previous transactions from\n * its Blockbook backend. Pure function -> unit testable.\n *\n * Only SIGHASH_ALL is supported: a non-default per-input sighash can't be honored through\n * Trezor's signTransaction, so we reject it rather than sign the wrong thing. Multisig /\n * script-path spends are out of scope (Rango funds from a single-key address).\n */\nexport function buildTrezorBitcoinTransaction(\n unsignedPsbtBase64: string,\n path: string,\n network: bitcoin.Network = bitcoin.networks.bitcoin\n): TrezorBitcoinTransaction {\n const psbt = bitcoin.Psbt.fromBase64(unsignedPsbtBase64, { network });\n const scriptType = resolveBitcoinScriptType(path);\n\n const inputs = psbt.txInputs.map((input, index): TrezorInput => {\n const data = psbt.data.inputs[index];\n\n if (\n data.sighashType != null &&\n data.sighashType !== bitcoin.Transaction.SIGHASH_ALL\n ) {\n throw new Error(\n `PSBT input #${index} uses sighash type ${data.sighashType}; only SIGHASH_ALL is supported.`\n );\n }\n\n const utxo =\n data.witnessUtxo ??\n bitcoin.Transaction.fromBuffer(data.nonWitnessUtxo as Buffer).outs[\n input.index\n ];\n return {\n // Trezor Connect accepts the path string directly (like our EVM signer).\n address_n: path,\n prev_hash: reverseTxid(input.hash),\n prev_index: input.index,\n amount: utxo.value.toString(),\n script_type: scriptType,\n sequence: input.sequence,\n };\n });\n\n const outputs = psbt.txOutputs.map(\n (output): TrezorOutput =>\n output.address\n ? {\n script_type: 'PAYTOADDRESS',\n address: output.address,\n amount: output.value.toString(),\n }\n : {\n script_type: 'PAYTOOPRETURN',\n amount: '0',\n op_return_data: (\n bitcoin.script.decompile(output.script)?.find(Buffer.isBuffer) ??\n Buffer.alloc(0)\n ).toString('hex'),\n }\n );\n\n return { inputs, outputs, version: psbt.version, locktime: psbt.locktime };\n}\n"],
5
+ "mappings": "qGAEA,OAAS,YAAAA,MAAgB,4BACzB,OAAS,eAAAC,MAAmB,cCD5B,UAAYC,MAAS,0BACrB,UAAYC,MAAa,gBAKjB,aAAWC,CAAG,EActB,IAAMC,EAAcC,EAACC,GACnB,OAAO,KAAKA,CAAI,EAAE,QAAQ,EAAE,SAAS,KAAK,EADxB,eAkBb,SAASC,EACdC,EACAC,EACAC,EAAmC,WAAS,QAClB,CAC1B,IAAMC,EAAe,OAAK,WAAWH,EAAoB,CAAE,QAAAE,CAAQ,CAAC,EAC9DE,EAAaC,EAAyBJ,CAAI,EAE1CK,EAASH,EAAK,SAAS,IAAI,CAACI,EAAOC,IAAuB,CAC9D,IAAMC,EAAON,EAAK,KAAK,OAAOK,CAAK,EAEnC,GACEC,EAAK,aAAe,MACpBA,EAAK,cAAwB,cAAY,YAEzC,MAAM,IAAI,MACR,eAAeD,CAAK,sBAAsBC,EAAK,WAAW,kCAC5D,EAGF,IAAMC,EACJD,EAAK,aACG,cAAY,WAAWA,EAAK,cAAwB,EAAE,KAC5DF,EAAM,KACR,EACF,MAAO,CAEL,UAAWN,EACX,UAAWL,EAAYW,EAAM,IAAI,EACjC,WAAYA,EAAM,MAClB,OAAQG,EAAK,MAAM,SAAS,EAC5B,YAAaN,EACb,SAAUG,EAAM,QAClB,CACF,CAAC,EAEKI,EAAUR,EAAK,UAAU,IAC5BS,GACCA,EAAO,QACH,CACE,YAAa,eACb,QAASA,EAAO,QAChB,OAAQA,EAAO,MAAM,SA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AME,GAAanB,EAGC,CAClB,GAAIA,EAAQ,KACV,OAAOA,EAAQ,KAEjB,GAAI,CAACA,EAAQ,aACX,MAAM,IAAI,MAAM,yCAAyC,EAI3D,IAAMoB,EAAa,MADG,MAAMT,EAAgB,GACL,gBAAgB,CACrD,GAAIX,EAAQ,aACZ,KAAMkB,CACR,CAAC,EACD,GAAI,CAACE,EAAW,QACd,MAAMrB,EAAsBqB,EAAW,OAAO,EAEhD,OAAOA,EAAW,QAAQ,IAC5B,CACF",
6
+ "names": ["Networks", "SignerError", "ecc", "bitcoin", "ecc", "reverseTxid", "__name", "hash", "buildTrezorBitcoinTransaction", "unsignedPsbtBase64", "path", "network", "psbt", "scriptType", "resolveBitcoinScriptType", "inputs", "input", "index", "data", "utxo", "outputs", "output", "getTrezorErrorMessage", "payload", "__name", "BTCSigner", "SignerError", "tx", "blockchain", "Networks", "psbt", "path", "getBitcoinDerivationPath", "TrezorConnect", "getTrezorModule", "inputs", "outputs", "version", "locktime", "buildTrezorBitcoinTransaction", "result", "BITCOIN_COIN_NAME", "#resolveHash", "pushResult"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-trezor",
3
- "version": "0.28.0",
3
+ "version": "0.28.1-next.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/mod.ts",
@@ -21,9 +21,14 @@
21
21
  "lint": "eslint \"**/*.{ts,tsx}\""
22
22
  },
23
23
  "dependencies": {
24
+ "@bitcoinerlab/secp256k1": "^1.2.0",
25
+ "@hub3js/core": "^0.60.1",
26
+ "@hub3js/evm": "^0.2.1",
27
+ "@hub3js/std": "^0.1.1",
24
28
  "@rango-dev/signer-evm": "^0.43.0",
25
- "@rango-dev/wallets-shared": "^0.61.0",
29
+ "@rango-dev/wallets-shared": "^0.61.1-next.0",
26
30
  "@trezor/connect-web": "^9.5.0",
31
+ "bitcoinjs-lib": "^6.1.7",
27
32
  "ethers": "^6.13.2",
28
33
  "rango-types": "^0.5.0"
29
34
  },
package/readme.md CHANGED
@@ -11,6 +11,21 @@ Trezor integration for hub.
11
11
 
12
12
  We only support Ethereum for now.
13
13
 
14
+ #### ⚠️ UTXO
15
+
16
+ We support Bitcoin only. The connect flow lets the user pick the address type via
17
+ derivation path (Native SegWit `84'`, Nested SegWit `49'`, Legacy `44'`, Taproot `86'`).
18
+
19
+ Trezor Connect has no PSBT API — its `signTransaction` takes explicit `inputs`/`outputs` —
20
+ so Rango's BTC PSBT is parsed with `bitcoinjs-lib` and translated into that shape, then
21
+ signed and broadcast via Trezor's Blockbook backend (`push: true`). `version`, `locktime`
22
+ and per-input `sequence` are preserved from the PSBT; only `SIGHASH_ALL` is supported.
23
+ Rango's PSBT carries no `bip32Derivation`, so the connect-time path is kept (like the EVM
24
+ signer) and applied to the inputs.
25
+
26
+ Other UTXO chains (LTC/DOGE/BCH/ZEC) are not implemented — they arrive from Rango as plain
27
+ transfers (no PSBT) and would use Trezor's `composeTransaction` instead.
28
+
14
29
  ### Feature
15
30
 
16
31
  #### ❌ Switch Account
@@ -0,0 +1,56 @@
1
+ import type { Context, FunctionWithContext } from '@hub3js/core';
2
+ import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
3
+
4
+ import {
5
+ CAIP_BITCOIN_CHAIN_ID,
6
+ utils,
7
+ } from '@rango-dev/wallets-core/namespaces/utxo';
8
+
9
+ import { initTrezor } from '../init.js';
10
+ import {
11
+ getTrezorModule,
12
+ getTrezorNormalizedDerivationPath,
13
+ } from '../legacy/helpers.js';
14
+ import { setBitcoinDerivationPath } from '../state.js';
15
+ import { BITCOIN_COIN_NAME, resolveBitcoinScriptType } from '../utxo/config.js';
16
+
17
+ /**
18
+ * Connect the Bitcoin account for the selected derivation path: derive the receive
19
+ * address and return it CAIP-encoded with the bip122 Bitcoin chain id. The path is kept
20
+ * (like the EVM namespace does) because Rango's PSBT has no derivation data, so the
21
+ * signer needs it at signing time.
22
+ */
23
+ export function connect(): FunctionWithContext<
24
+ UtxoActions['connect'],
25
+ Context
26
+ > {
27
+ return async (_context, options) => {
28
+ if (!options?.derivationPath) {
29
+ throw new Error('Derivation Path can not be empty.');
30
+ }
31
+
32
+ await initTrezor();
33
+
34
+ const path = getTrezorNormalizedDerivationPath(options.derivationPath);
35
+ const inputScriptType = resolveBitcoinScriptType(path);
36
+ setBitcoinDerivationPath(path);
37
+
38
+ const TrezorConnect = await getTrezorModule();
39
+ const result = await TrezorConnect.getAddress({
40
+ path,
41
+ coin: BITCOIN_COIN_NAME,
42
+ scriptType: inputScriptType,
43
+ showOnTrezor: false,
44
+ });
45
+
46
+ if (!result.success) {
47
+ throw new Error(result.payload.error);
48
+ }
49
+
50
+ const { address } = result.payload;
51
+
52
+ return utils.formatAccountsToCAIP([address], CAIP_BITCOIN_CHAIN_ID);
53
+ };
54
+ }
55
+
56
+ export const utxoActions = { connect };
package/src/constants.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { ProviderMetadata } from '@hub3js/core';
2
2
 
3
3
  import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
4
- import { type BlockchainMeta } from 'rango-types';
4
+ import { type BlockchainMeta, type TransferBlockchainMeta } from 'rango-types';
5
5
 
6
6
  import getSigners from './signer.js';
7
+ import { BITCOIN_ADDRESS_TYPES } from './utxo/config.js';
7
8
 
8
9
  export const WALLET_ID = WalletTypes.TREZOR;
9
10
 
@@ -28,6 +29,16 @@ export const metadata: ProviderMetadata = {
28
29
  (chain) => chain.name === Networks.ETHEREUM
29
30
  ),
30
31
  },
32
+ {
33
+ label: 'Bitcoin',
34
+ value: 'UTXO',
35
+ id: 'BTC',
36
+ getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
37
+ allBlockchains.filter(
38
+ (chain): chain is TransferBlockchainMeta =>
39
+ chain.name === Networks.BTC
40
+ ),
41
+ },
31
42
  ],
32
43
  },
33
44
  },
@@ -53,6 +64,17 @@ export const metadata: ProviderMetadata = {
53
64
  namespace: 'EVM',
54
65
  generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,
55
66
  },
67
+ /*
68
+ * Bitcoin derivation templates. The BIP-43 purpose (and thus the address
69
+ * type) is what the user picks here; `index` selects the account.
70
+ */
71
+ ...BITCOIN_ADDRESS_TYPES.map((addressType) => ({
72
+ id: `bitcoin-${addressType.id}`,
73
+ label: `${addressType.label} (m/${addressType.purpose}'/0'/index')`,
74
+ namespace: 'UTXO',
75
+ generateDerivationPath: (index: string) =>
76
+ `${addressType.purpose}'/0'/${index}'/0/0`,
77
+ })),
56
78
  ],
57
79
  },
58
80
  },
package/src/init.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { getTrezorModule } from './legacy/helpers.js';
2
+ import { getTrezorManifest } from './provider.js';
3
+
4
+ let isTrezorInitialized = false;
5
+
6
+ /*
7
+ * `TrezorConnect.init` throws if called twice, so initialization is shared across every
8
+ * namespace (EVM, UTXO). `lazyLoad` defers iframe injection until the first method call.
9
+ */
10
+ export async function initTrezor() {
11
+ if (isTrezorInitialized) {
12
+ return;
13
+ }
14
+ const TrezorConnect = await getTrezorModule();
15
+ await TrezorConnect.init({
16
+ lazyLoad: true,
17
+ manifest: getTrezorManifest(),
18
+ });
19
+ isTrezorInitialized = true;
20
+ }
@@ -7,16 +7,13 @@ import { standardizeAndThrowError } from '@hub3js/std/operators';
7
7
  import { ETHEREUM_CHAIN_ID } from '@rango-dev/wallets-shared';
8
8
 
9
9
  import { WALLET_ID } from '../constants.js';
10
+ import { initTrezor } from '../init.js';
10
11
  import {
11
12
  getEthereumAccounts,
12
- getTrezorModule,
13
13
  getTrezorNormalizedDerivationPath,
14
14
  } from '../legacy/helpers.js';
15
- import { getTrezorManifest } from '../provider.js';
16
15
  import { setDerivationPath } from '../state.js';
17
16
 
18
- let isTrezorInitialized = false;
19
-
20
17
  const connect = builders
21
18
  .connect()
22
19
  .action(async function (_context, _chain, options) {
@@ -27,14 +24,7 @@ const connect = builders
27
24
  getTrezorNormalizedDerivationPath(options.derivationPath)
28
25
  );
29
26
 
30
- if (!isTrezorInitialized) {
31
- const TrezorConnect = await getTrezorModule();
32
- await TrezorConnect.init({
33
- lazyLoad: true, // this param will prevent iframe injection until TrezorConnect.method will be called
34
- manifest: getTrezorManifest(),
35
- });
36
- isTrezorInitialized = true;
37
- }
27
+ await initTrezor();
38
28
 
39
29
  const result = await getEthereumAccounts();
40
30
 
@@ -0,0 +1,24 @@
1
+ import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
2
+
3
+ import { NamespaceBuilder } from '@hub3js/core';
4
+ import * as commonBuilders from '@hub3js/std/builders';
5
+ import { standardizeAndThrowError } from '@hub3js/std/operators';
6
+ import { builders } from '@rango-dev/wallets-core/namespaces/utxo';
7
+
8
+ import { utxoActions } from '../actions/utxo.js';
9
+ import { WALLET_ID } from '../constants.js';
10
+
11
+ const connect = builders
12
+ .connect()
13
+ .action(utxoActions.connect())
14
+ .or(standardizeAndThrowError)
15
+ .build();
16
+
17
+ const disconnect = commonBuilders.disconnect<UtxoActions>().build();
18
+
19
+ const utxo = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)
20
+ .action(connect)
21
+ .action(disconnect)
22
+ .build();
23
+
24
+ export { utxo };
package/src/provider.ts CHANGED
@@ -4,6 +4,7 @@ import { ProviderBuilder } from '@hub3js/core';
4
4
 
5
5
  import { metadata, WALLET_ID } from './constants.js';
6
6
  import { evm } from './namespaces/evm.js';
7
+ import { utxo } from './namespaces/utxo.js';
7
8
 
8
9
  let trezorManifest: Environments['manifest'];
9
10
 
@@ -24,6 +25,7 @@ const buildProvider = () =>
24
25
  })
25
26
  .config('metadata', metadata)
26
27
  .add('evm', evm)
28
+ .add('utxo', utxo)
27
29
  .build();
28
30
 
29
31
  export { buildProvider };
package/src/signer.ts CHANGED
@@ -8,6 +8,10 @@ export default async function getSigners(): Promise<SignerFactory> {
8
8
  const { EthereumSigner } = await dynamicImportWithRefinedError(
9
9
  async () => await import('./signers/ethereum.js')
10
10
  );
11
+ const { BTCSigner } = await dynamicImportWithRefinedError(
12
+ async () => await import('./signers/utxo.js')
13
+ );
11
14
  signers.registerSigner(TxType.EVM, new EthereumSigner());
15
+ signers.registerSigner(TxType.TRANSFER, new BTCSigner());
12
16
  return signers;
13
17
  }
@@ -0,0 +1,90 @@
1
+ import type { GenericSigner, Transfer } from 'rango-types';
2
+
3
+ import { Networks } from '@rango-dev/wallets-shared';
4
+ import { SignerError } from 'rango-types';
5
+
6
+ import { getTrezorModule } from '../legacy/helpers.js';
7
+ import { getBitcoinDerivationPath } from '../state.js';
8
+ import { BITCOIN_COIN_NAME } from '../utxo/config.js';
9
+ import { buildTrezorBitcoinTransaction } from '../utxo/psbt.js';
10
+
11
+ function getTrezorErrorMessage(payload: { error: string; code?: string }) {
12
+ return new Error(
13
+ payload.code ? `${payload.error} (${payload.code})` : payload.error
14
+ );
15
+ }
16
+
17
+ export class BTCSigner implements GenericSigner<Transfer> {
18
+ async signMessage(): Promise<string> {
19
+ throw SignerError.UnimplementedError('signMessage');
20
+ }
21
+
22
+ async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {
23
+ const { blockchain } = tx.asset;
24
+ if (blockchain !== Networks.BTC) {
25
+ throw new Error(
26
+ `Signing ${blockchain} transactions is not supported by Trezor.`
27
+ );
28
+ }
29
+
30
+ const { psbt } = tx;
31
+ if (!psbt) {
32
+ throw new Error(
33
+ 'No PSBT found to sign. Ensure a valid PSBT is provided.'
34
+ );
35
+ }
36
+
37
+ const path = getBitcoinDerivationPath();
38
+ if (!path) {
39
+ throw new Error(
40
+ 'No connected Bitcoin account found. Please connect the wallet first.'
41
+ );
42
+ }
43
+
44
+ const TrezorConnect = await getTrezorModule();
45
+ const { inputs, outputs, version, locktime } =
46
+ buildTrezorBitcoinTransaction(psbt.unsignedPsbtBase64, path);
47
+
48
+ // `push: true` signs and broadcasts via Trezor's Blockbook backend.
49
+ const result = await TrezorConnect.signTransaction({
50
+ coin: BITCOIN_COIN_NAME,
51
+ inputs,
52
+ outputs,
53
+ version,
54
+ locktime,
55
+ push: true,
56
+ });
57
+
58
+ if (!result.success) {
59
+ throw getTrezorErrorMessage(result.payload);
60
+ }
61
+
62
+ return { hash: await this.#resolveHash(result.payload) };
63
+ }
64
+
65
+ /**
66
+ * `push: true` usually returns the txid directly. If it isn't present (older
67
+ * firmware/connect), push the serialized transaction explicitly as a fallback.
68
+ */
69
+ async #resolveHash(payload: {
70
+ txid?: string;
71
+ serializedTx?: string;
72
+ }): Promise<string> {
73
+ if (payload.txid) {
74
+ return payload.txid;
75
+ }
76
+ if (!payload.serializedTx) {
77
+ throw new Error('Trezor did not return a transaction id.');
78
+ }
79
+
80
+ const TrezorConnect = await getTrezorModule();
81
+ const pushResult = await TrezorConnect.pushTransaction({
82
+ tx: payload.serializedTx,
83
+ coin: BITCOIN_COIN_NAME,
84
+ });
85
+ if (!pushResult.success) {
86
+ throw getTrezorErrorMessage(pushResult.payload);
87
+ }
88
+ return pushResult.payload.txid;
89
+ }
90
+ }
package/src/state.ts CHANGED
@@ -8,3 +8,18 @@ export function setDerivationPath(path: string) {
8
8
  export function getDerivationPath() {
9
9
  return derivationPath;
10
10
  }
11
+
12
+ /*
13
+ * Bitcoin's connect-time path, kept for the same reason as the EVM one: Rango's PSBT
14
+ * carries no derivation data, so the signer must remember which path to sign with. Kept
15
+ * separate from the EVM path so the two namespaces never collide.
16
+ */
17
+ let bitcoinDerivationPath = '';
18
+
19
+ export function setBitcoinDerivationPath(path: string) {
20
+ bitcoinDerivationPath = path;
21
+ }
22
+
23
+ export function getBitcoinDerivationPath() {
24
+ return bitcoinDerivationPath;
25
+ }
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Trezor needs the input `script_type` to sign a Bitcoin input. It is determined by the
3
+ * BIP-43 `purpose` of the derivation path the address was derived from, so we expose the
4
+ * four common address types and let the user connect whichever one they hold funds on.
5
+ */
6
+ export type TrezorInputScriptType =
7
+ | 'SPENDADDRESS'
8
+ | 'SPENDP2SHWITNESS'
9
+ | 'SPENDWITNESS'
10
+ | 'SPENDTAPROOT';
11
+
12
+ export interface BitcoinAddressType {
13
+ /** Stable id used in the derivationPath metadata entries. */
14
+ id: 'legacy' | 'nested-segwit' | 'native-segwit' | 'taproot';
15
+ label: string;
16
+ /** BIP-43 purpose: 44 legacy, 49 nested segwit, 84 native segwit, 86 taproot. */
17
+ purpose: number;
18
+ inputScriptType: TrezorInputScriptType;
19
+ }
20
+
21
+ export const BITCOIN_COIN_NAME = 'btc';
22
+
23
+ export const BITCOIN_ADDRESS_TYPES: readonly BitcoinAddressType[] = [
24
+ {
25
+ id: 'native-segwit',
26
+ label: 'Native SegWit',
27
+ purpose: 84,
28
+ inputScriptType: 'SPENDWITNESS',
29
+ },
30
+ {
31
+ id: 'nested-segwit',
32
+ label: 'Nested SegWit',
33
+ purpose: 49,
34
+ inputScriptType: 'SPENDP2SHWITNESS',
35
+ },
36
+ {
37
+ id: 'legacy',
38
+ label: 'Legacy',
39
+ purpose: 44,
40
+ inputScriptType: 'SPENDADDRESS',
41
+ },
42
+ {
43
+ id: 'taproot',
44
+ label: 'Taproot',
45
+ purpose: 86,
46
+ inputScriptType: 'SPENDTAPROOT',
47
+ },
48
+ ] as const;
49
+
50
+ /**
51
+ * Resolve the Trezor input script type for a derivation path by reading its BIP-43
52
+ * purpose (the first hardened level). The path always comes from one of our own
53
+ * derivation templates, so an unknown purpose is a programming error.
54
+ */
55
+ export function resolveBitcoinScriptType(path: string): TrezorInputScriptType {
56
+ const purpose = Number.parseInt(
57
+ path.replace(/^m\//, '').split('/')[0]?.replace(/['h]$/, '') ?? '',
58
+ 10
59
+ );
60
+ const addressType = BITCOIN_ADDRESS_TYPES.find(
61
+ (type) => type.purpose === purpose
62
+ );
63
+ if (!addressType) {
64
+ throw new Error(`Unsupported Bitcoin derivation path: ${path}`);
65
+ }
66
+ return addressType.inputScriptType;
67
+ }
@@ -0,0 +1,162 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+ import * as ecc from '@bitcoinerlab/secp256k1';
3
+ import * as bitcoin from 'bitcoinjs-lib';
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ import { buildTrezorBitcoinTransaction } from './psbt.js';
7
+
8
+ bitcoin.initEccLib(ecc);
9
+ const NETWORK = bitcoin.networks.bitcoin;
10
+
11
+ const PRIVATE_KEY = Buffer.alloc(32, 7);
12
+ const PUBKEY = Buffer.from(
13
+ ecc.pointFromScalar(PRIVATE_KEY, true) as Uint8Array
14
+ );
15
+ const { address: OWN_ADDRESS } = bitcoin.payments.p2wpkh({
16
+ pubkey: PUBKEY,
17
+ network: NETWORK,
18
+ });
19
+
20
+ const NATIVE_SEGWIT_PATH = "m/84'/0'/0'/0/0";
21
+
22
+ // Non-palindromic on purpose, so the txid byte-reversal is actually exercised.
23
+ const FAKE_PREV_TXID =
24
+ '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
25
+ const RECIPIENT = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
26
+
27
+ function nativeSegwitInput() {
28
+ const witnessScript = bitcoin.payments.p2wpkh({
29
+ pubkey: PUBKEY,
30
+ network: NETWORK,
31
+ }).output as Buffer;
32
+ return {
33
+ hash: FAKE_PREV_TXID,
34
+ index: 0,
35
+ witnessUtxo: { script: witnessScript, value: 100_000 },
36
+ };
37
+ }
38
+
39
+ describe('buildTrezorBitcoinTransaction', () => {
40
+ it('maps each input to the connected path and its script type', () => {
41
+ const psbt = new bitcoin.Psbt({ network: NETWORK });
42
+ psbt.addInput(nativeSegwitInput());
43
+ psbt.addOutput({ address: RECIPIENT, value: 90_000 });
44
+
45
+ const { inputs } = buildTrezorBitcoinTransaction(
46
+ psbt.toBase64(),
47
+ NATIVE_SEGWIT_PATH,
48
+ NETWORK
49
+ );
50
+
51
+ expect(inputs).toHaveLength(1);
52
+ expect(inputs[0].address_n).toBe(NATIVE_SEGWIT_PATH);
53
+ expect(inputs[0].script_type).toBe('SPENDWITNESS');
54
+ expect(inputs[0].prev_hash).toBe(FAKE_PREV_TXID);
55
+ expect(inputs[0].prev_index).toBe(0);
56
+ expect(inputs[0].amount).toBe('100000');
57
+ });
58
+
59
+ it('preserves version, locktime and per-input sequence from the PSBT', () => {
60
+ const psbt = new bitcoin.Psbt({ network: NETWORK });
61
+ psbt.setVersion(2);
62
+ psbt.setLocktime(800_000);
63
+ // RBF-signaling sequence.
64
+ psbt.addInput({ ...nativeSegwitInput(), sequence: 0xfffffffd });
65
+ psbt.addOutput({ address: RECIPIENT, value: 90_000 });
66
+
67
+ const { inputs, version, locktime } = buildTrezorBitcoinTransaction(
68
+ psbt.toBase64(),
69
+ NATIVE_SEGWIT_PATH,
70
+ NETWORK
71
+ );
72
+
73
+ expect(version).toBe(2);
74
+ expect(locktime).toBe(800_000);
75
+ expect(inputs[0].sequence).toBe(0xfffffffd);
76
+ });
77
+
78
+ it('rejects an input with a non-SIGHASH_ALL sighash type', () => {
79
+ const psbt = new bitcoin.Psbt({ network: NETWORK });
80
+ psbt.addInput({
81
+ ...nativeSegwitInput(),
82
+ sighashType: bitcoin.Transaction.SIGHASH_SINGLE,
83
+ });
84
+ psbt.addOutput({ address: RECIPIENT, value: 90_000 });
85
+
86
+ expect(() =>
87
+ buildTrezorBitcoinTransaction(
88
+ psbt.toBase64(),
89
+ NATIVE_SEGWIT_PATH,
90
+ NETWORK
91
+ )
92
+ ).toThrow(/only SIGHASH_ALL is supported/);
93
+ });
94
+
95
+ it('reconstructs outputs as address payments', () => {
96
+ const psbt = new bitcoin.Psbt({ network: NETWORK });
97
+ psbt.addInput(nativeSegwitInput());
98
+ psbt.addOutput({ address: RECIPIENT, value: 60_000 });
99
+ psbt.addOutput({ address: OWN_ADDRESS as string, value: 39_000 });
100
+
101
+ const { outputs } = buildTrezorBitcoinTransaction(
102
+ psbt.toBase64(),
103
+ NATIVE_SEGWIT_PATH,
104
+ NETWORK
105
+ );
106
+
107
+ expect(outputs).toEqual([
108
+ { script_type: 'PAYTOADDRESS', address: RECIPIENT, amount: '60000' },
109
+ { script_type: 'PAYTOADDRESS', address: OWN_ADDRESS, amount: '39000' },
110
+ ]);
111
+ });
112
+
113
+ it('derives the script type from the path purpose (legacy P2PKH)', () => {
114
+ const p2pkh = bitcoin.payments.p2pkh({ pubkey: PUBKEY, network: NETWORK });
115
+
116
+ // A previous transaction that funds the legacy address at vout 0.
117
+ const prevTx = new bitcoin.Transaction();
118
+ prevTx.version = 2;
119
+ prevTx.addInput(Buffer.alloc(32, 1), 0);
120
+ prevTx.addOutput(p2pkh.output as Buffer, 100_000);
121
+
122
+ const psbt = new bitcoin.Psbt({ network: NETWORK });
123
+ psbt.addInput({
124
+ hash: prevTx.getId(),
125
+ index: 0,
126
+ nonWitnessUtxo: prevTx.toBuffer(),
127
+ });
128
+ psbt.addOutput({ address: RECIPIENT, value: 90_000 });
129
+
130
+ const { inputs } = buildTrezorBitcoinTransaction(
131
+ psbt.toBase64(),
132
+ "m/44'/0'/0'/0/0",
133
+ NETWORK
134
+ );
135
+
136
+ expect(inputs[0].script_type).toBe('SPENDADDRESS');
137
+ expect(inputs[0].amount).toBe('100000');
138
+ });
139
+
140
+ it('encodes an OP_RETURN output as PAYTOOPRETURN', () => {
141
+ const memo = Buffer.from('rango', 'utf8');
142
+ const psbt = new bitcoin.Psbt({ network: NETWORK });
143
+ psbt.addInput(nativeSegwitInput());
144
+ psbt.addOutput({ address: RECIPIENT, value: 90_000 });
145
+ psbt.addOutput({
146
+ script: bitcoin.payments.embed({ data: [memo] }).output as Buffer,
147
+ value: 0,
148
+ });
149
+
150
+ const { outputs } = buildTrezorBitcoinTransaction(
151
+ psbt.toBase64(),
152
+ NATIVE_SEGWIT_PATH,
153
+ NETWORK
154
+ );
155
+
156
+ expect(outputs[1]).toEqual({
157
+ script_type: 'PAYTOOPRETURN',
158
+ amount: '0',
159
+ op_return_data: memo.toString('hex'),
160
+ });
161
+ });
162
+ });
@@ -0,0 +1,96 @@
1
+ import type { SignTransaction } from '@trezor/connect-web';
2
+
3
+ import * as ecc from '@bitcoinerlab/secp256k1';
4
+ import * as bitcoin from 'bitcoinjs-lib';
5
+
6
+ import { resolveBitcoinScriptType } from './config.js';
7
+
8
+ // Lets bitcoinjs-lib decode taproot (witness v1) output addresses.
9
+ bitcoin.initEccLib(ecc);
10
+
11
+ type TrezorInput = SignTransaction['inputs'][number];
12
+ type TrezorOutput = SignTransaction['outputs'][number];
13
+
14
+ export interface TrezorBitcoinTransaction {
15
+ inputs: TrezorInput[];
16
+ outputs: TrezorOutput[];
17
+ /** Transaction version from the PSBT — preserved so the signed tx matches Rango's. */
18
+ version: number;
19
+ /** Transaction locktime from the PSBT (e.g. for CLTV) — preserved as-is. */
20
+ locktime: number;
21
+ }
22
+
23
+ const reverseTxid = (hash: Buffer) =>
24
+ Buffer.from(hash).reverse().toString('hex');
25
+
26
+ /**
27
+ * Translate Rango's unsigned PSBT into the transaction Trezor's `signTransaction` expects
28
+ * (Trezor has no "sign this PSBT" call). Every field that affects the resulting bytes is
29
+ * preserved: `version`, `locktime`, and per-input `sequence` (RBF / locktime signaling),
30
+ * alongside each input's amount and script.
31
+ *
32
+ * Rango's PSBT carries no derivation data, so the connected `path` (and the script type
33
+ * from its BIP-43 purpose) is applied to every input — Rango funds the swap from that
34
+ * single address. `refTxs` are omitted: Trezor Connect fetches previous transactions from
35
+ * its Blockbook backend. Pure function -> unit testable.
36
+ *
37
+ * Only SIGHASH_ALL is supported: a non-default per-input sighash can't be honored through
38
+ * Trezor's signTransaction, so we reject it rather than sign the wrong thing. Multisig /
39
+ * script-path spends are out of scope (Rango funds from a single-key address).
40
+ */
41
+ export function buildTrezorBitcoinTransaction(
42
+ unsignedPsbtBase64: string,
43
+ path: string,
44
+ network: bitcoin.Network = bitcoin.networks.bitcoin
45
+ ): TrezorBitcoinTransaction {
46
+ const psbt = bitcoin.Psbt.fromBase64(unsignedPsbtBase64, { network });
47
+ const scriptType = resolveBitcoinScriptType(path);
48
+
49
+ const inputs = psbt.txInputs.map((input, index): TrezorInput => {
50
+ const data = psbt.data.inputs[index];
51
+
52
+ if (
53
+ data.sighashType != null &&
54
+ data.sighashType !== bitcoin.Transaction.SIGHASH_ALL
55
+ ) {
56
+ throw new Error(
57
+ `PSBT input #${index} uses sighash type ${data.sighashType}; only SIGHASH_ALL is supported.`
58
+ );
59
+ }
60
+
61
+ const utxo =
62
+ data.witnessUtxo ??
63
+ bitcoin.Transaction.fromBuffer(data.nonWitnessUtxo as Buffer).outs[
64
+ input.index
65
+ ];
66
+ return {
67
+ // Trezor Connect accepts the path string directly (like our EVM signer).
68
+ address_n: path,
69
+ prev_hash: reverseTxid(input.hash),
70
+ prev_index: input.index,
71
+ amount: utxo.value.toString(),
72
+ script_type: scriptType,
73
+ sequence: input.sequence,
74
+ };
75
+ });
76
+
77
+ const outputs = psbt.txOutputs.map(
78
+ (output): TrezorOutput =>
79
+ output.address
80
+ ? {
81
+ script_type: 'PAYTOADDRESS',
82
+ address: output.address,
83
+ amount: output.value.toString(),
84
+ }
85
+ : {
86
+ script_type: 'PAYTOOPRETURN',
87
+ amount: '0',
88
+ op_return_data: (
89
+ bitcoin.script.decompile(output.script)?.find(Buffer.isBuffer) ??
90
+ Buffer.alloc(0)
91
+ ).toString('hex'),
92
+ }
93
+ );
94
+
95
+ return { inputs, outputs, version: psbt.version, locktime: psbt.locktime };
96
+ }
@@ -1,2 +0,0 @@
1
- var s=Object.defineProperty;var e=(t,r)=>s(t,"name",{value:r,configurable:!0});var o="";function g(t){o=t}e(g,"setDerivationPath");function i(){return o}e(i,"getDerivationPath");import{dynamicImportWithRefinedError as c,ETHEREUM_CHAIN_ID as a,Networks as u}from"@rango-dev/wallets-shared";var h={Failure_ActionCancelled:"User rejected the transaction."};async function d(){let t=await c(async()=>await import("@trezor/connect-web"));return t.default.default?t.default.default:t.default}e(d,"getTrezorModule");function x(){let t=new Map;return t.set(u.ETHEREUM,{chainId:a}),t}e(x,"getTrezorInstance");async function I(){let t=await d(),r=i(),n=await t.ethereumGetAddress({path:r});if(!n.success)throw new Error(n.payload.error);return{accounts:[n.payload.address],chainId:a,derivationPath:r}}e(I,"getEthereumAccounts");var w=e(t=>{let r=BigInt(0);return BigInt(t)>r?`0x${BigInt(t).toString(16)}`:"0x0"},"valueToHex"),T=e(t=>t&&!t.startsWith("m/")?"m/"+t:t,"getTrezorNormalizedDerivationPath");export{e as a,g as b,i as c,h as d,d as e,x as f,I as g,w as h,T as i};
2
- //# sourceMappingURL=chunk-WO4Y4OWN.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/state.ts", "../src/legacy/helpers.ts"],
4
- "sourcesContent": ["// We keep derivationPath here because we need to maintain it for signing transactions after it is set in connect method\nlet derivationPath = '';\n\nexport function setDerivationPath(path: string) {\n derivationPath = path;\n}\n\nexport function getDerivationPath() {\n return derivationPath;\n}\n", "import type { TrezorConnect } from '@trezor/connect-web';\n\nimport {\n dynamicImportWithRefinedError,\n ETHEREUM_CHAIN_ID,\n Networks,\n type ProviderConnectResult,\n} from '@rango-dev/wallets-shared';\n\nimport { getDerivationPath } from '../state';\n\nexport const trezorErrorMessages: { [statusCode: string]: string } = {\n Failure_ActionCancelled: 'User rejected the transaction.',\n};\n\n// `@trezor/connect-web` is commonjs, when we are importing it dynamically, it has some differences in different tooling. for example vite (you can check widget-examples), goes throw error. this is a workaround for solving this interop issue.\nexport async function getTrezorModule() {\n const mod = await dynamicImportWithRefinedError(\n async () => await import('@trezor/connect-web')\n );\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (mod.default.default) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return mod.default.default as unknown as TrezorConnect;\n }\n\n return mod.default;\n}\n\nexport function getTrezorInstance() {\n /*\n * Instances have a required property which is `chainId` and is using in swap execution.\n * Here we are setting it as Ethereum always since we are supporting only eth for now.\n */\n const instances = new Map();\n\n instances.set(Networks.ETHEREUM, { chainId: ETHEREUM_CHAIN_ID });\n\n return instances;\n}\n\nexport async function getEthereumAccounts(): Promise<ProviderConnectResult> {\n const TrezorConnect = await getTrezorModule();\n const derivationPath = getDerivationPath();\n const result = await TrezorConnect.ethereumGetAddress({\n path: derivationPath,\n });\n\n if (!result.success) {\n throw new Error(result.payload.error);\n }\n\n return {\n accounts: [result.payload.address],\n chainId: ETHEREUM_CHAIN_ID,\n derivationPath,\n };\n}\n\n/*\n * Using BigInt in the valueToHex function ensures that the function\n * can handle very large integer values that exceed the range of standard JavaScript number types.\n */\nexport const valueToHex = (value: string) => {\n const ZERO_BIGINT = BigInt(0);\n const HEX_BASE = 16;\n return BigInt(value) > ZERO_BIGINT\n ? `0x${BigInt(value).toString(HEX_BASE)}`\n : '0x0';\n};\n\nexport const getTrezorNormalizedDerivationPath = (\n path: string // TrezorConnect needs master node to be added to derivation path\n) => (path && !path.startsWith('m/') ? 'm/' + path : path);\n"],
5
- "mappings": "+EACA,IAAIA,EAAiB,GAEd,SAASC,EAAkBC,EAAc,CAC9CF,EAAiBE,CACnB,CAFgBC,EAAAF,EAAA,qBAIT,SAASG,GAAoB,CAClC,OAAOJ,CACT,CAFgBG,EAAAC,EAAA,qBCLhB,OACE,iCAAAC,EACA,qBAAAC,EACA,YAAAC,MAEK,4BAIA,IAAMC,EAAwD,CACnE,wBAAyB,gCAC3B,EAGA,eAAsBC,GAAkB,CACtC,IAAMC,EAAM,MAAMC,EAChB,SAAY,KAAM,QAAO,qBAAqB,CAChD,EAGA,OAAID,EAAI,QAAQ,QAGPA,EAAI,QAAQ,QAGdA,EAAI,OACb,CAbsBE,EAAAH,EAAA,mBAef,SAASI,GAAoB,CAKlC,IAAMC,EAAY,IAAI,IAEtB,OAAAA,EAAU,IAAIC,EAAS,SAAU,CAAE,QAASC,CAAkB,CAAC,EAExDF,CACT,CAVgBF,EAAAC,EAAA,qBAYhB,eAAsBI,GAAsD,CAC1E,IAAMC,EAAgB,MAAMT,EAAgB,EACtCU,EAAiBC,EAAkB,EACnCC,EAAS,MAAMH,EAAc,mBAAmB,CACpD,KAAMC,CACR,CAAC,EAED,GAAI,CAACE,EAAO,QACV,MAAM,IAAI,MAAMA,EAAO,QAAQ,KAAK,EAGtC,MAAO,CACL,SAAU,CAACA,EAAO,QAAQ,OAAO,EACjC,QAASL,EACT,eAAAG,CACF,CACF,CAhBsBP,EAAAK,EAAA,uBAsBf,IAAMK,EAAaV,EAACW,GAAkB,CAC3C,IAAMC,EAAc,OAAO,CAAC,EAE5B,OAAO,OAAOD,CAAK,EAAIC,EACnB,KAAK,OAAOD,CAAK,EAAE,SAFN,EAEuB,CAAC,GACrC,KACN,EAN0B,cAQbE,EAAoCb,EAC/Cc,GACIA,GAAQ,CAACA,EAAK,WAAW,IAAI,EAAI,KAAOA,EAAOA,EAFJ",
6
- "names": ["derivationPath", "setDerivationPath", "path", "__name", "getDerivationPath", "dynamicImportWithRefinedError", "ETHEREUM_CHAIN_ID", "Networks", "trezorErrorMessages", "getTrezorModule", "mod", "dynamicImportWithRefinedError", "__name", "getTrezorInstance", "instances", "Networks", "ETHEREUM_CHAIN_ID", "getEthereumAccounts", "TrezorConnect", "derivationPath", "getDerivationPath", "result", "valueToHex", "value", "ZERO_BIGINT", "getTrezorNormalizedDerivationPath", "path"]
7
- }