@rango-dev/provider-trezor 0.28.1-next.1 → 0.28.1-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-XMCEMEDS.js → chunk-4A5SID3U.js} +2 -2
- package/dist/chunk-KQD4IRQZ.js +2 -0
- package/dist/chunk-KQD4IRQZ.js.map +7 -0
- package/dist/{ethereum-67ZOG2D6.js → ethereum-CRCQQH34.js} +2 -2
- package/dist/ethereum-CRCQQH34.js.map +7 -0
- package/dist/mod.d.ts +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +4 -4
- package/dist/provider-trezor.build.json +1 -1
- package/dist/{legacy/helpers.d.ts → utils.d.ts} +1 -2
- package/dist/{utxo-J5P5Q6IJ.js → utxo-BVUYSP2M.js} +2 -2
- package/dist/utxo-BVUYSP2M.js.map +7 -0
- package/package.json +2 -2
- package/src/actions/utxo.ts +2 -2
- package/src/init.ts +1 -1
- package/src/mod.ts +1 -5
- package/src/namespaces/evm.ts +2 -2
- package/src/signers/ethereum.ts +1 -5
- package/src/signers/utxo.ts +1 -1
- package/src/{legacy/helpers.ts → utils.ts} +1 -14
- package/dist/chunk-S7XQ7HPI.js +0 -2
- package/dist/chunk-S7XQ7HPI.js.map +0 -7
- package/dist/ethereum-67ZOG2D6.js.map +0 -7
- package/dist/legacy/index.d.ts +0 -18
- package/dist/utxo-J5P5Q6IJ.js.map +0 -7
- package/src/legacy/index.ts +0 -151
- /package/dist/{chunk-XMCEMEDS.js.map → chunk-4A5SID3U.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as p}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as p}from"./chunk-KQD4IRQZ.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-4A5SID3U.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var e=(t,r)=>s(t,"name",{value:r,configurable:!0});var n="";function g(t){n=t}e(g,"setDerivationPath");function i(){return n}e(i,"getDerivationPath");var a="";function l(t){a=t}e(l,"setBitcoinDerivationPath");function m(){return a}e(m,"getBitcoinDerivationPath");import{dynamicImportWithRefinedError as c,ETHEREUM_CHAIN_ID as u}from"@rango-dev/wallets-shared";var P={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");async function v(){let t=await d(),r=i(),o=await t.ethereumGetAddress({path:r});if(!o.success)throw new Error(o.payload.error);return{accounts:[o.payload.address],chainId:u,derivationPath:r}}e(v,"getEthereumAccounts");var I=e(t=>{let r=BigInt(0);return BigInt(t)>r?`0x${BigInt(t).toString(16)}`:"0x0"},"valueToHex"),w=e(t=>t&&!t.startsWith("m/")?"m/"+t:t,"getTrezorNormalizedDerivationPath");export{e as a,g as b,i as c,l as d,m as e,P as f,d as g,v as h,I as i,w as j};
|
|
2
|
+
//# sourceMappingURL=chunk-KQD4IRQZ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/state.ts", "../src/utils.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 type ProviderConnectResult,\n} from '@rango-dev/wallets-shared';\n\nimport { getDerivationPath } from './state.js';\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 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,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,mBAetB,eAAsBI,GAAsD,CAC1E,IAAMC,EAAgB,MAAML,EAAgB,EACtCM,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,QAASC,EACT,eAAAH,CACF,CACF,CAhBsBH,EAAAC,EAAA,uBAsBf,IAAMM,EAAaP,EAACQ,GAAkB,CAC3C,IAAMC,EAAc,OAAO,CAAC,EAE5B,OAAO,OAAOD,CAAK,EAAIC,EACnB,KAAK,OAAOD,CAAK,EAAE,SAFN,EAEuB,CAAC,GACrC,KACN,EAN0B,cAQbE,EAAoCV,EAC/CW,GACIA,GAAQ,CAACA,EAAK,WAAW,IAAI,EAAI,KAAOA,EAAOA,EAFJ",
|
|
6
|
+
"names": ["derivationPath", "setDerivationPath", "path", "__name", "getDerivationPath", "bitcoinDerivationPath", "setBitcoinDerivationPath", "getBitcoinDerivationPath", "dynamicImportWithRefinedError", "ETHEREUM_CHAIN_ID", "trezorErrorMessages", "getTrezorModule", "mod", "dynamicImportWithRefinedError", "__name", "getEthereumAccounts", "TrezorConnect", "derivationPath", "getDerivationPath", "result", "ETHEREUM_CHAIN_ID", "valueToHex", "value", "ZERO_BIGINT", "getTrezorNormalizedDerivationPath", "path"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as p,c as u,f as P,g as h,
|
|
2
|
-
//# sourceMappingURL=ethereum-
|
|
1
|
+
import{a as p,c as u,f as P,g as h,i as t}from"./chunk-KQD4IRQZ.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-CRCQQH34.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/signers/ethereum.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EvmTransaction } from 'rango-types/mainApi';\n\nimport { cleanEvmError } from '@rango-dev/signer-evm';\nimport { DEFAULT_ETHEREUM_RPC_URL } from '@rango-dev/wallets-shared';\nimport { JsonRpcProvider, Transaction } from 'ethers';\nimport { type GenericSigner } from 'rango-types';\n\nimport { getDerivationPath } from '../state.js';\nimport { getTrezorModule, trezorErrorMessages, valueToHex } from '../utils.js';\n\nexport function getTrezorErrorMessage(error: unknown) {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'shortMessage' in error &&\n typeof error.shortMessage === 'string'\n ) {\n /*\n * Some error signs have lengthy, challenging-to-read messages.\n * shortMessage is used because it is shorter and easier to understand.\n */\n return new Error(error.shortMessage, { cause: error });\n }\n return cleanEvmError(error);\n}\n\nexport class EthereumSigner implements GenericSigner<EvmTransaction> {\n async signMessage(msg: string): Promise<string> {\n const TrezorConnect = await getTrezorModule();\n\n const { success, payload } = await TrezorConnect.ethereumSignMessage({\n message: msg,\n path: getDerivationPath(),\n });\n if (!success) {\n throw new Error(payload.error);\n }\n return payload.signature;\n }\n\n async signAndSendTx(\n tx: EvmTransaction,\n fromAddress: string,\n chainId: string\n ): Promise<{ hash: string }> {\n try {\n const TrezorConnect = await getTrezorModule();\n const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = tx;\n const isEIP1559 = maxFeePerGas && maxPriorityFeePerGas;\n\n if (isEIP1559 && !maxFeePerGas) {\n throw new Error('Missing maxFeePerGas');\n }\n if (isEIP1559 && !maxPriorityFeePerGas) {\n throw new Error('Missing maxPriorityFeePerGas');\n }\n if (!isEIP1559 && !gasPrice) {\n throw new Error('Missing gasPrice');\n }\n const provider = new JsonRpcProvider(DEFAULT_ETHEREUM_RPC_URL); // Provider to broadcast transaction\n const transactionCount = await provider.getTransactionCount(fromAddress); // Get nonce\n const additionalFields = isEIP1559\n ? {\n maxFeePerGas: valueToHex(maxFeePerGas || '0'),\n maxPriorityFeePerGas: valueToHex(maxPriorityFeePerGas || '0'),\n }\n : {\n gasPrice: valueToHex(gasPrice || '0'),\n };\n\n const transaction = {\n to: tx.to,\n data: tx.data || '0x',\n value: valueToHex(tx.value?.toString() || '0'),\n gasLimit: valueToHex(tx.gasLimit?.toString() || '0'),\n chainId: Number.parseInt(chainId),\n nonce: valueToHex(transactionCount.toString()),\n ...additionalFields,\n };\n\n const { success, payload } = await TrezorConnect.ethereumSignTransaction({\n path: getDerivationPath(),\n transaction,\n });\n\n if (!success) {\n const errorMessage =\n trezorErrorMessages[payload?.code || ''] || payload.error;\n throw new Error(errorMessage);\n }\n const { r, s, v } = payload;\n\n const serializedTx = Transaction.from({\n ...transaction,\n nonce: Number.parseInt(transaction.nonce),\n /*\n * Type 0: This refers to the legacy transaction type that has been used since Ethereum's inception.\n * Type 2: This refers to the new transaction type introduced with the EIP-1559 (Ethereum Improvement Proposal 1559) update,\n * which was part of the London hard fork.\n */\n type: isEIP1559 ? 2 : 0,\n signature: { r, s, v: parseInt(v) },\n }).serialized;\n const broadcastResult = await provider.broadcastTransaction(serializedTx);\n\n return { hash: broadcastResult.hash };\n } catch (error) {\n throw getTrezorErrorMessage(error);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "oEAEA,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CAClB,GAAIb,EAAG,GACP,KAAMA,EAAG,MAAQ,KACjB,MAAOY,EAAWZ,EAAG,OAAO,SAAS,GAAK,GAAG,EAC7C,SAAUY,EAAWZ,EAAG,UAAU,SAAS,GAAK,GAAG,EACnD,QAAS,OAAO,SAASE,CAAO,EAChC,MAAOU,EAAWF,EAAiB,SAAS,CAAC,EAC7C,GAAGC,CACL,EAEM,CAAE,QAAAd,EAAS,QAAAC,CAAQ,EAAI,MAAMH,EAAc,wBAAwB,CACvE,KAAMI,EAAkB,EACxB,YAAAc,CACF,CAAC,EAED,GAAI,CAAChB,EAAS,CACZ,IAAMiB,EACJC,EAAoBjB,GAAS,MAAQ,EAAE,GAAKA,EAAQ,MACtD,MAAM,IAAI,MAAMgB,CAAY,CAC9B,CACA,GAAM,CAAE,EAAAE,EAAG,EAAAC,EAAG,CAAE,EAAInB,EAEdoB,EAAeC,EAAY,KAAK,CACpC,GAAGN,EACH,MAAO,OAAO,SAASA,EAAY,KAAK,EAMxC,KAAMP,EAAY,EAAI,EACtB,UAAW,CAAE,EAAAU,EAAG,EAAAC,EAAG,EAAG,SAAS,CAAC,CAAE,CACpC,CAAC,EAAE,WAGH,MAAO,CAAE,MAFe,MAAMV,EAAS,qBAAqBW,CAAY,GAEzC,IAAK,CACtC,OAAS5B,EAAO,CACd,MAAMD,EAAsBC,CAAK,CACnC,CACF,CACF",
|
|
6
|
+
"names": ["cleanEvmError", "DEFAULT_ETHEREUM_RPC_URL", "JsonRpcProvider", "Transaction", "getTrezorErrorMessage", "error", "cleanEvmError", "__name", "EthereumSigner", "msg", "TrezorConnect", "getTrezorModule", "success", "payload", "getDerivationPath", "tx", "fromAddress", "chainId", "gasPrice", "maxFeePerGas", "maxPriorityFeePerGas", "isEIP1559", "provider", "JsonRpcProvider", "DEFAULT_ETHEREUM_RPC_URL", "transactionCount", "additionalFields", "valueToHex", "transaction", "errorMessage", "trezorErrorMessages", "r", "s", "serializedTx", "Transaction"]
|
|
7
|
+
}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const versions: () => readonly [readonly ["
|
|
1
|
+
declare const versions: () => readonly [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
|
|
1
|
+
import{a as f,b as g,c as h}from"./chunk-4A5SID3U.js";import{a as o,b as d,d as l,g as a,h as u,j as c}from"./chunk-KQD4IRQZ.js";import{defineVersions as J}from"@hub3js/core/utils";import{ProviderBuilder as G}from"@hub3js/core";import{Networks as E,WalletTypes as L}from"@rango-dev/wallets-shared";import"rango-types";import{dynamicImportWithRefinedError as T}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as _,TransactionType as v}from"rango-types";async function p(){let t=new _,{EthereumSigner:e}=await T(async()=>await import("./ethereum-CRCQQH34.js")),{BTCSigner:r}=await T(async()=>await import("./utxo-BVUYSP2M.js"));return t.registerSigner(v.EVM,new e),t.registerSigner(v.TRANSFER,new r),t}o(p,"getSigners");var i=L.TREZOR,w={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:t=>t.filter(e=>e.name===E.ETHEREUM)},{label:"Bitcoin",value:"UTXO",id:"BTC",getSupportedChains:t=>t.filter(e=>e.name===E.BTC)}]}},{name:"derivationPath",value:{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}`},...g.map(t=>({id:`bitcoin-${t.id}`,label:`${t.label} (m/${t.purpose}'/0'/index')`,namespace:"UTXO",generateDerivationPath:e=>`${t.purpose}'/0'/${e}'/0/0`}))]}},{name:"signers",value:{getSigners:async()=>p()}}]};import{NamespaceBuilder as N}from"@hub3js/core";import{builders as A,utils as U}from"@hub3js/evm";import*as b from"@hub3js/std/builders";import{standardizeAndThrowError as k}from"@hub3js/std/operators";import{ETHEREUM_CHAIN_ID as O}from"@rango-dev/wallets-shared";var x=!1;async function s(){if(x)return;await(await a()).init({lazyLoad:!0,manifest:y()}),x=!0}o(s,"initTrezor");var R=A.connect().action(async function(t,e,r){if(!r?.derivationPath)throw new Error("Derivation Path can not be empty.");d(c(r.derivationPath)),await s();let n=await u();return{accounts:U.formatAccountsToCAIP(n.accounts,n.chainId),network:n.chainId}}).or(k).build(),W=b.disconnect().build(),$=A.getChainId().action(()=>O).build(),z=new N("EVM",i).action(R).action(W).action($).build();import{NamespaceBuilder as j}from"@hub3js/core";import*as C from"@hub3js/std/builders";import{standardizeAndThrowError as X}from"@hub3js/std/operators";import{builders as q}from"@rango-dev/wallets-core/namespaces/utxo";import{CAIP_BITCOIN_CHAIN_ID as V,utils as F}from"@rango-dev/wallets-core/namespaces/utxo";function H(){return async(t,e)=>{if(!e?.derivationPath)throw new Error("Derivation Path can not be empty.");await s();let r=c(e.derivationPath),n=h(r);l(r);let m=await(await a()).getAddress({path:r,coin:f,scriptType:n,showOnTrezor:!1});if(!m.success)throw new Error(m.payload.error);let{address:S}=m.payload;return F.formatAccountsToCAIP([S],V)}}o(H,"connect");var P={connect:H};var Y=q.connect().action(P.connect()).or(X).build(),Z=C.disconnect().build(),I=new j("UTXO",i).action(Y).action(Z).build();var M,y=o(()=>M,"getTrezorManifest"),B=o(()=>new G(i).init(function(t,e){let[,r]=t.state();if(!e.manifest)throw new Error("Trezor manifest is required");M=e.manifest,r("installed",!0),console.debug("[trezor] instance detected.",t)}).config("metadata",w).add("evm",z).add("utxo",I).build(),"buildProvider");var $t=o(()=>J().version("1.0.0",B()).build(),"versions");export{$t 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/
|
|
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": "
|
|
6
|
-
"names": ["defineVersions", "Networks", "WalletTypes", "dynamicImportWithRefinedError", "DefaultSignerFactory", "TxType", "getSigners", "signers", "DefaultSignerFactory", "EthereumSigner", "dynamicImportWithRefinedError", "BTCSigner", "TxType", "__name", "
|
|
3
|
+
"sources": ["../src/mod.ts", "../src/provider.ts", "../src/constants.ts", "../src/signer.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 { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\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 { 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 { 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 { setDerivationPath } from '../state.js';\nimport {\n getEthereumAccounts,\n getTrezorNormalizedDerivationPath,\n} from '../utils.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 { getTrezorManifest } from './provider.js';\nimport { getTrezorModule } from './utils.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 { setBitcoinDerivationPath } from '../state.js';\nimport {\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from '../utils.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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Q,MAAM,8BAA+BF,CAAO,CACtD,CAAC,EACA,OAAO,WAAYG,CAAQ,EAC3B,IAAI,MAAOC,CAAG,EACd,IAAI,OAAQC,CAAI,EAChB,MAAM,EAhBW,iBDRtB,IAAMC,GAAWC,EAAA,IACfC,EAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
|
|
6
|
+
"names": ["defineVersions", "ProviderBuilder", "Networks", "WalletTypes", "dynamicImportWithRefinedError", "DefaultSignerFactory", "TxType", "getSigners", "signers", "DefaultSignerFactory", "EthereumSigner", "dynamicImportWithRefinedError", "BTCSigner", "TxType", "__name", "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", "buildProvider"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
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}}}
|
|
1
|
+
{"inputs":{"src/state.ts":{"bytes":744,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/utils.ts":{"bytes":2068,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"src/state.ts","kind":"import-statement","original":"./state.js"},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signers/ethereum.ts":{"bytes":3804,"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/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.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":2629,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.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/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":571,"imports":[{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/evm.ts":{"bytes":1477,"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/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.js"}],"format":"esm"},"src/actions/utxo.ts":{"bytes":1692,"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/state.ts","kind":"import-statement","original":"../state.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.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":209,"imports":[{"path":"@hub3js/core/utils","kind":"import-statement","external":true},{"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":14560},"dist/mod.js":{"imports":[{"path":"dist/chunk-4A5SID3U.js","kind":"import-statement"},{"path":"dist/chunk-KQD4IRQZ.js","kind":"import-statement"},{"path":"@hub3js/core/utils","kind":"import-statement","external":true},{"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":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"dist/ethereum-CRCQQH34.js","kind":"dynamic-import"},{"path":"dist/utxo-BVUYSP2M.js","kind":"dynamic-import"},{"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":110},"src/provider.ts":{"bytesInOutput":353},"src/constants.ts":{"bytesInOutput":1141},"src/signer.ts":{"bytesInOutput":412},"src/namespaces/evm.ts":{"bytesInOutput":650},"src/init.ts":{"bytesInOutput":113},"src/namespaces/utxo.ts":{"bytesInOutput":342},"src/actions/utxo.ts":{"bytesInOutput":470}},"bytes":3776},"dist/ethereum-CRCQQH34.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6375},"dist/ethereum-CRCQQH34.js":{"imports":[{"path":"dist/chunk-KQD4IRQZ.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-BVUYSP2M.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":9115},"dist/utxo-BVUYSP2M.js":{"imports":[{"path":"dist/chunk-4A5SID3U.js","kind":"import-statement"},{"path":"dist/chunk-KQD4IRQZ.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-4A5SID3U.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2802},"dist/chunk-4A5SID3U.js":{"imports":[{"path":"dist/chunk-KQD4IRQZ.js","kind":"import-statement"}],"exports":["a","b","c"],"inputs":{"src/utxo/config.ts":{"bytesInOutput":585}},"bytes":698},"dist/chunk-KQD4IRQZ.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":4510},"dist/chunk-KQD4IRQZ.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"],"inputs":{"src/state.ts":{"bytesInOutput":212},"src/utils.ts":{"bytesInOutput":709}},"bytes":1122}}}
|
|
@@ -4,13 +4,12 @@ export declare const trezorErrorMessages: {
|
|
|
4
4
|
[statusCode: string]: string;
|
|
5
5
|
};
|
|
6
6
|
export declare function getTrezorModule(): Promise<TrezorConnect | (Omit<TrezorConnect, "init"> & {
|
|
7
|
-
init: import("@trezor/connect/lib/types/api/init").InitType<import("@trezor/connect").ConnectSettingsWeb>;
|
|
7
|
+
init: import("@trezor/connect/lib/types/api/init.js").InitType<import("@trezor/connect").ConnectSettingsWeb>;
|
|
8
8
|
} & {
|
|
9
9
|
renderWebUSBButton: (className?: string) => void;
|
|
10
10
|
disableWebUSB: () => void;
|
|
11
11
|
requestWebUSBDevice: () => void;
|
|
12
12
|
})>;
|
|
13
|
-
export declare function getTrezorInstance(): Map<any, any>;
|
|
14
13
|
export declare function getEthereumAccounts(): Promise<ProviderConnectResult>;
|
|
15
14
|
export declare const valueToHex: (value: string) => string;
|
|
16
15
|
export declare const getTrezorNormalizedDerivationPath: (path: string) => string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as d,c as h}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=utxo-
|
|
1
|
+
import{a as d,c as h}from"./chunk-4A5SID3U.js";import{a as s,e as g,g as m}from"./chunk-KQD4IRQZ.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-BVUYSP2M.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 { getBitcoinDerivationPath } from '../state.js';\nimport { getTrezorModule } from '../utils.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,I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AMQ,EACN,OAAAN,EACA,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,KAAM,EACR,CAAC,EAED,GAAI,CAACE,EAAO,QACV,MAAMlB,EAAsBkB,EAAO,OAAO,EAG5C,MAAO,CAAE,KAAM,MAAM,KAAKE,GAAaF,EAAO,OAAO,CAAE,CACzD,CAMA,KAAME,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
package/src/actions/utxo.ts
CHANGED
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
} from '@rango-dev/wallets-core/namespaces/utxo';
|
|
8
8
|
|
|
9
9
|
import { initTrezor } from '../init.js';
|
|
10
|
+
import { setBitcoinDerivationPath } from '../state.js';
|
|
10
11
|
import {
|
|
11
12
|
getTrezorModule,
|
|
12
13
|
getTrezorNormalizedDerivationPath,
|
|
13
|
-
} from '../
|
|
14
|
-
import { setBitcoinDerivationPath } from '../state.js';
|
|
14
|
+
} from '../utils.js';
|
|
15
15
|
import { BITCOIN_COIN_NAME, resolveBitcoinScriptType } from '../utxo/config.js';
|
|
16
16
|
|
|
17
17
|
/**
|
package/src/init.ts
CHANGED
package/src/mod.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { defineVersions } from '@hub3js/core/utils';
|
|
2
2
|
|
|
3
|
-
import { buildLegacyProvider } from './legacy/index.js';
|
|
4
3
|
import { buildProvider } from './provider.js';
|
|
5
4
|
|
|
6
5
|
const versions = () =>
|
|
7
|
-
defineVersions()
|
|
8
|
-
.version('0.0.0', buildLegacyProvider())
|
|
9
|
-
.version('1.0.0', buildProvider())
|
|
10
|
-
.build();
|
|
6
|
+
defineVersions().version('1.0.0', buildProvider()).build();
|
|
11
7
|
|
|
12
8
|
export { versions };
|
package/src/namespaces/evm.ts
CHANGED
|
@@ -8,11 +8,11 @@ import { ETHEREUM_CHAIN_ID } from '@rango-dev/wallets-shared';
|
|
|
8
8
|
|
|
9
9
|
import { WALLET_ID } from '../constants.js';
|
|
10
10
|
import { initTrezor } from '../init.js';
|
|
11
|
+
import { setDerivationPath } from '../state.js';
|
|
11
12
|
import {
|
|
12
13
|
getEthereumAccounts,
|
|
13
14
|
getTrezorNormalizedDerivationPath,
|
|
14
|
-
} from '../
|
|
15
|
-
import { setDerivationPath } from '../state.js';
|
|
15
|
+
} from '../utils.js';
|
|
16
16
|
|
|
17
17
|
const connect = builders
|
|
18
18
|
.connect()
|
package/src/signers/ethereum.ts
CHANGED
|
@@ -5,12 +5,8 @@ import { DEFAULT_ETHEREUM_RPC_URL } from '@rango-dev/wallets-shared';
|
|
|
5
5
|
import { JsonRpcProvider, Transaction } from 'ethers';
|
|
6
6
|
import { type GenericSigner } from 'rango-types';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
getTrezorModule,
|
|
10
|
-
trezorErrorMessages,
|
|
11
|
-
valueToHex,
|
|
12
|
-
} from '../legacy/helpers.js';
|
|
13
8
|
import { getDerivationPath } from '../state.js';
|
|
9
|
+
import { getTrezorModule, trezorErrorMessages, valueToHex } from '../utils.js';
|
|
14
10
|
|
|
15
11
|
export function getTrezorErrorMessage(error: unknown) {
|
|
16
12
|
if (
|
package/src/signers/utxo.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { GenericSigner, Transfer } from 'rango-types';
|
|
|
3
3
|
import { Networks } from '@rango-dev/wallets-shared';
|
|
4
4
|
import { SignerError } from 'rango-types';
|
|
5
5
|
|
|
6
|
-
import { getTrezorModule } from '../legacy/helpers.js';
|
|
7
6
|
import { getBitcoinDerivationPath } from '../state.js';
|
|
7
|
+
import { getTrezorModule } from '../utils.js';
|
|
8
8
|
import { BITCOIN_COIN_NAME } from '../utxo/config.js';
|
|
9
9
|
import { buildTrezorBitcoinTransaction } from '../utxo/psbt.js';
|
|
10
10
|
|
|
@@ -3,11 +3,10 @@ import type { TrezorConnect } from '@trezor/connect-web';
|
|
|
3
3
|
import {
|
|
4
4
|
dynamicImportWithRefinedError,
|
|
5
5
|
ETHEREUM_CHAIN_ID,
|
|
6
|
-
Networks,
|
|
7
6
|
type ProviderConnectResult,
|
|
8
7
|
} from '@rango-dev/wallets-shared';
|
|
9
8
|
|
|
10
|
-
import { getDerivationPath } from '
|
|
9
|
+
import { getDerivationPath } from './state.js';
|
|
11
10
|
|
|
12
11
|
export const trezorErrorMessages: { [statusCode: string]: string } = {
|
|
13
12
|
Failure_ActionCancelled: 'User rejected the transaction.',
|
|
@@ -29,18 +28,6 @@ export async function getTrezorModule() {
|
|
|
29
28
|
return mod.default;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
export function getTrezorInstance() {
|
|
33
|
-
/*
|
|
34
|
-
* Instances have a required property which is `chainId` and is using in swap execution.
|
|
35
|
-
* Here we are setting it as Ethereum always since we are supporting only eth for now.
|
|
36
|
-
*/
|
|
37
|
-
const instances = new Map();
|
|
38
|
-
|
|
39
|
-
instances.set(Networks.ETHEREUM, { chainId: ETHEREUM_CHAIN_ID });
|
|
40
|
-
|
|
41
|
-
return instances;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
31
|
export async function getEthereumAccounts(): Promise<ProviderConnectResult> {
|
|
45
32
|
const TrezorConnect = await getTrezorModule();
|
|
46
33
|
const derivationPath = getDerivationPath();
|
package/dist/chunk-S7XQ7HPI.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
|
@@ -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\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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/signers/ethereum.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EvmTransaction } from 'rango-types/mainApi';\n\nimport { cleanEvmError } from '@rango-dev/signer-evm';\nimport { DEFAULT_ETHEREUM_RPC_URL } from '@rango-dev/wallets-shared';\nimport { JsonRpcProvider, Transaction } from 'ethers';\nimport { type GenericSigner } from 'rango-types';\n\nimport {\n getTrezorModule,\n trezorErrorMessages,\n valueToHex,\n} from '../legacy/helpers.js';\nimport { getDerivationPath } from '../state.js';\n\nexport function getTrezorErrorMessage(error: unknown) {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'shortMessage' in error &&\n typeof error.shortMessage === 'string'\n ) {\n /*\n * Some error signs have lengthy, challenging-to-read messages.\n * shortMessage is used because it is shorter and easier to understand.\n */\n return new Error(error.shortMessage, { cause: error });\n }\n return cleanEvmError(error);\n}\n\nexport class EthereumSigner implements GenericSigner<EvmTransaction> {\n async signMessage(msg: string): Promise<string> {\n const TrezorConnect = await getTrezorModule();\n\n const { success, payload } = await TrezorConnect.ethereumSignMessage({\n message: msg,\n path: getDerivationPath(),\n });\n if (!success) {\n throw new Error(payload.error);\n }\n return payload.signature;\n }\n\n async signAndSendTx(\n tx: EvmTransaction,\n fromAddress: string,\n chainId: string\n ): Promise<{ hash: string }> {\n try {\n const TrezorConnect = await getTrezorModule();\n const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = tx;\n const isEIP1559 = maxFeePerGas && maxPriorityFeePerGas;\n\n if (isEIP1559 && !maxFeePerGas) {\n throw new Error('Missing maxFeePerGas');\n }\n if (isEIP1559 && !maxPriorityFeePerGas) {\n throw new Error('Missing maxPriorityFeePerGas');\n }\n if (!isEIP1559 && !gasPrice) {\n throw new Error('Missing gasPrice');\n }\n const provider = new JsonRpcProvider(DEFAULT_ETHEREUM_RPC_URL); // Provider to broadcast transaction\n const transactionCount = await provider.getTransactionCount(fromAddress); // Get nonce\n const additionalFields = isEIP1559\n ? {\n maxFeePerGas: valueToHex(maxFeePerGas || '0'),\n maxPriorityFeePerGas: valueToHex(maxPriorityFeePerGas || '0'),\n }\n : {\n gasPrice: valueToHex(gasPrice || '0'),\n };\n\n const transaction = {\n to: tx.to,\n data: tx.data || '0x',\n value: valueToHex(tx.value?.toString() || '0'),\n gasLimit: valueToHex(tx.gasLimit?.toString() || '0'),\n chainId: Number.parseInt(chainId),\n nonce: valueToHex(transactionCount.toString()),\n ...additionalFields,\n };\n\n const { success, payload } = await TrezorConnect.ethereumSignTransaction({\n path: getDerivationPath(),\n transaction,\n });\n\n if (!success) {\n const errorMessage =\n trezorErrorMessages[payload?.code || ''] || payload.error;\n throw new Error(errorMessage);\n }\n const { r, s, v } = payload;\n\n const serializedTx = Transaction.from({\n ...transaction,\n nonce: Number.parseInt(transaction.nonce),\n /*\n * Type 0: This refers to the legacy transaction type that has been used since Ethereum's inception.\n * Type 2: This refers to the new transaction type introduced with the EIP-1559 (Ethereum Improvement Proposal 1559) update,\n * which was part of the London hard fork.\n */\n type: isEIP1559 ? 2 : 0,\n signature: { r, s, v: parseInt(v) },\n }).serialized;\n const broadcastResult = await provider.broadcastTransaction(serializedTx);\n\n return { hash: broadcastResult.hash };\n } catch (error) {\n throw getTrezorErrorMessage(error);\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "oEAEA,OAAS,iBAAAA,MAAqB,wBAC9B,OAAS,4BAAAC,MAAgC,4BACzC,OAAS,mBAAAC,EAAiB,eAAAC,MAAmB,SAC7C,MAAmC,cAS5B,SAASC,EAAsBC,EAAgB,CACpD,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,iBAAkBA,GAClB,OAAOA,EAAM,cAAiB,SAMvB,IAAI,MAAMA,EAAM,aAAc,CAAE,MAAOA,CAAM,CAAC,EAEhDC,EAAcD,CAAK,CAC5B,CAdgBE,EAAAH,EAAA,yBAgBT,IAAMI,EAAN,KAA8D,CA9BrE,MA8BqE,CAAAD,EAAA,uBACnE,MAAM,YAAYE,EAA8B,CAC9C,IAAMC,EAAgB,MAAMC,EAAgB,EAEtC,CAAE,QAAAC,EAAS,QAAAC,CAAQ,EAAI,MAAMH,EAAc,oBAAoB,CACnE,QAASD,EACT,KAAMK,EAAkB,CAC1B,CAAC,EACD,GAAI,CAACF,EACH,MAAM,IAAI,MAAMC,EAAQ,KAAK,EAE/B,OAAOA,EAAQ,SACjB,CAEA,MAAM,cACJE,EACAC,EACAC,EAC2B,CAC3B,GAAI,CACF,IAAMP,EAAgB,MAAMC,EAAgB,EACtC,CAAE,SAAAO,EAAU,aAAAC,EAAc,qBAAAC,CAAqB,EAAIL,EACnDM,EAAYF,GAAgBC,EAElC,GAAIC,GA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BC,CAAK,CACnC,CACF,CACF",
|
|
6
|
-
"names": ["cleanEvmError", "DEFAULT_ETHEREUM_RPC_URL", "JsonRpcProvider", "Transaction", "getTrezorErrorMessage", "error", "cleanEvmError", "__name", "EthereumSigner", "msg", "TrezorConnect", "getTrezorModule", "success", "payload", "getDerivationPath", "tx", "fromAddress", "chainId", "gasPrice", "maxFeePerGas", "maxPriorityFeePerGas", "isEIP1559", "provider", "JsonRpcProvider", "DEFAULT_ETHEREUM_RPC_URL", "transactionCount", "additionalFields", "valueToHex", "transaction", "errorMessage", "trezorErrorMessages", "r", "s", "serializedTx", "Transaction"]
|
|
7
|
-
}
|
package/dist/legacy/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Environments } from '../types.js';
|
|
2
|
-
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
3
|
-
import type { Connect, WalletInfo } from '@rango-dev/wallets-shared';
|
|
4
|
-
import { WalletTypes } from '@rango-dev/wallets-shared';
|
|
5
|
-
import { type BlockchainMeta, type SignerFactory } from 'rango-types';
|
|
6
|
-
import { getTrezorInstance } from './helpers.js';
|
|
7
|
-
export declare const config: {
|
|
8
|
-
type: WalletTypes;
|
|
9
|
-
};
|
|
10
|
-
export type { Environments };
|
|
11
|
-
type Provider = any;
|
|
12
|
-
export declare const init: (environments: Environments) => void;
|
|
13
|
-
export declare const getInstance: typeof getTrezorInstance;
|
|
14
|
-
export declare const connect: Connect;
|
|
15
|
-
export declare const getSigners: (provider: Provider) => Promise<SignerFactory>;
|
|
16
|
-
export declare const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo;
|
|
17
|
-
declare const buildLegacyProvider: () => LegacyProviderInterface;
|
|
18
|
-
export { buildLegacyProvider };
|
|
@@ -1,7 +0,0 @@
|
|
|
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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,MACR,sEACF,EAGF,IAAME,EAAgB,MAAMC,EAAgB,EACtC,CAAE,OAAAC,EAAQ,QAAAC,EAAS,QAAAC,EAAS,SAAAC,CAAS,EACzCC,EAA8BT,EAAK,mBAAoBC,CAAI,EAGvDS,EAAS,MAAMP,EAAc,gBAAgB,CACjD,KAAMQ,EACN,OAAAN,EACA,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,KAAM,EACR,CAAC,EAED,GAAI,CAACE,EAAO,QACV,MAAMlB,EAAsBkB,EAAO,OAAO,EAG5C,MAAO,CAAE,KAAM,MAAM,KAAKE,GAAaF,EAAO,OAAO,CAAE,CACzD,CAMA,KAAME,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/src/legacy/index.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { Environments } from '../types.js';
|
|
2
|
-
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
3
|
-
import type {
|
|
4
|
-
Connect,
|
|
5
|
-
ProviderConnectResult,
|
|
6
|
-
WalletInfo,
|
|
7
|
-
} from '@rango-dev/wallets-shared';
|
|
8
|
-
|
|
9
|
-
import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
|
|
10
|
-
import { type BlockchainMeta, type SignerFactory } from 'rango-types';
|
|
11
|
-
|
|
12
|
-
import signer from '../signer.js';
|
|
13
|
-
import { setDerivationPath } from '../state.js';
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
getEthereumAccounts,
|
|
17
|
-
getTrezorInstance,
|
|
18
|
-
getTrezorModule,
|
|
19
|
-
getTrezorNormalizedDerivationPath,
|
|
20
|
-
} from './helpers.js';
|
|
21
|
-
|
|
22
|
-
let trezorManifest: Environments['manifest'] = {
|
|
23
|
-
appUrl: '',
|
|
24
|
-
email: '',
|
|
25
|
-
};
|
|
26
|
-
export const config = {
|
|
27
|
-
type: WalletTypes.TREZOR,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type { Environments };
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
type Provider = any;
|
|
33
|
-
|
|
34
|
-
export const init = (environments: Environments) => {
|
|
35
|
-
trezorManifest = environments.manifest;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const getInstance = getTrezorInstance;
|
|
39
|
-
|
|
40
|
-
let isTrezorInitialized = false;
|
|
41
|
-
export const connect: Connect = async ({ namespaces }) => {
|
|
42
|
-
const results: ProviderConnectResult[] = [];
|
|
43
|
-
|
|
44
|
-
const TrezorConnect = await getTrezorModule();
|
|
45
|
-
|
|
46
|
-
const evmNamespace = namespaces?.find(
|
|
47
|
-
(namespaceItem) => namespaceItem.namespace === 'EVM'
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
if (evmNamespace) {
|
|
51
|
-
if (evmNamespace.derivationPath) {
|
|
52
|
-
setDerivationPath(
|
|
53
|
-
getTrezorNormalizedDerivationPath(evmNamespace.derivationPath)
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (!isTrezorInitialized) {
|
|
57
|
-
await TrezorConnect.init({
|
|
58
|
-
lazyLoad: true, // this param will prevent iframe injection until TrezorConnect.method will be called
|
|
59
|
-
manifest: trezorManifest,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
isTrezorInitialized = true;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const accounts = await getEthereumAccounts();
|
|
66
|
-
results.push(accounts);
|
|
67
|
-
} else {
|
|
68
|
-
throw new Error('Derivation Path can not be empty.');
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
throw new Error(
|
|
72
|
-
`It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${namespaces?.map(
|
|
73
|
-
(namespaceItem) => namespaceItem.namespace
|
|
74
|
-
)}`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return results;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const getSigners: (provider: Provider) => Promise<SignerFactory> =
|
|
82
|
-
signer;
|
|
83
|
-
|
|
84
|
-
export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
|
|
85
|
-
allBlockChains
|
|
86
|
-
) => {
|
|
87
|
-
const supportedChains: BlockchainMeta[] = [];
|
|
88
|
-
|
|
89
|
-
const ethereumBlockchain = allBlockChains.find(
|
|
90
|
-
(chain) => chain.name === Networks.ETHEREUM
|
|
91
|
-
);
|
|
92
|
-
if (ethereumBlockchain) {
|
|
93
|
-
supportedChains.push(ethereumBlockchain);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
name: 'Trezor',
|
|
98
|
-
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg',
|
|
99
|
-
installLink: {
|
|
100
|
-
DEFAULT: 'https://trezor.io/learn/a/download-verify-trezor-suite',
|
|
101
|
-
},
|
|
102
|
-
color: 'black',
|
|
103
|
-
supportedChains,
|
|
104
|
-
showOnMobile: false,
|
|
105
|
-
|
|
106
|
-
needsNamespace: {
|
|
107
|
-
selection: 'single',
|
|
108
|
-
data: [
|
|
109
|
-
{
|
|
110
|
-
id: 'ETH',
|
|
111
|
-
value: 'EVM',
|
|
112
|
-
label: 'Ethereum',
|
|
113
|
-
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
|
|
114
|
-
allBlockchains.filter((chain) => chain.name === Networks.ETHEREUM),
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
},
|
|
118
|
-
needsDerivationPath: {
|
|
119
|
-
data: [
|
|
120
|
-
{
|
|
121
|
-
id: 'metamask',
|
|
122
|
-
label: `Metamask (m/44'/60'/0'/0/index)`,
|
|
123
|
-
namespace: 'EVM',
|
|
124
|
-
generateDerivationPath: (index: string) => `44'/60'/0'/0/${index}`,
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
id: 'ledgerLive',
|
|
128
|
-
label: `LedgerLive (m/44'/60'/index'/0/0)`,
|
|
129
|
-
namespace: 'EVM',
|
|
130
|
-
generateDerivationPath: (index: string) => `44'/60'/${index}'/0/0`,
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
id: 'legacy',
|
|
134
|
-
label: `Legacy (m/44'/60'/0'/index)`,
|
|
135
|
-
namespace: 'EVM',
|
|
136
|
-
generateDerivationPath: (index: string) => `44'/60'/0'/${index}`,
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const buildLegacyProvider: () => LegacyProviderInterface = () => ({
|
|
144
|
-
config,
|
|
145
|
-
getInstance,
|
|
146
|
-
connect,
|
|
147
|
-
getSigners,
|
|
148
|
-
getWalletInfo,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
export { buildLegacyProvider };
|
|
File without changes
|