@rango-dev/provider-trezor 0.4.2-next.0 → 0.4.2-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/helpers.d.ts CHANGED
@@ -3,7 +3,6 @@ export declare const trezorErrorMessages: {
3
3
  [statusCode: string]: string;
4
4
  };
5
5
  export declare function getTrezorModule(): Promise<TrezorConnect>;
6
- export declare function getTrezorErrorMessage(error: any): Error;
7
6
  export declare function getTrezorInstance(): Map<any, any>;
8
7
  export declare function getEthereumAccounts(): Promise<{
9
8
  accounts: string[];
package/dist/index.d.ts CHANGED
@@ -10,5 +10,5 @@ export type { Environments };
10
10
  export declare const init: (environments: Environments) => void;
11
11
  export declare const getInstance: typeof getTrezorInstance;
12
12
  export declare const connect: Connect;
13
- export declare const getSigners: (provider: any) => SignerFactory;
13
+ export declare const getSigners: (provider: any) => Promise<SignerFactory>;
14
14
  export declare const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var G=Object.defineProperty;var r=(e,t)=>G(e,"name",{value:t,configurable:!0});import{Namespace as C,Networks as X,WalletTypes as Z}from"@rango-dev/wallets-shared";import"rango-types";import{cleanEvmError as H}from"@rango-dev/signer-evm";import{ETHEREUM_CHAIN_ID as T,Networks as U}from"@rango-dev/wallets-shared";var y="";function w(e){y=e}r(w,"setDerivationPath");function m(){return y}r(m,"getDerivationPath");var v={Failure_ActionCancelled:"User rejected the transaction."};async function i(){let e=await import("@trezor/connect-web");return e.default.default?e.default.default:e.default}r(i,"getTrezorModule");function P(e){return e?.shortMessage?new Error(e.shortMessage,{cause:e}):H(e)}r(P,"getTrezorErrorMessage");function z(){let e=new Map;return e.set(U.ETHEREUM,{chainId:T}),e}r(z,"getTrezorInstance");async function x(){let t=await(await i()).ethereumGetAddress({path:m()});if(!t.success)throw new Error(t.payload.error);return{accounts:[t.payload.address],chainId:T}}r(x,"getEthereumAccounts");var s=r(e=>{let t=BigInt(0);return BigInt(e)>t?`0x${BigInt(e).toString(16)}`:"0x0"},"valueToHex"),M=r(e=>e&&!e.startsWith("m/")?"m/"+e:e,"getTrezorNormalizedDerivationPath");import{DefaultSignerFactory as O,TransactionType as j}from"rango-types";import{DEFAULT_ETHEREUM_RPC_URL as _}from"@rango-dev/wallets-shared";import{JsonRpcProvider as L,Transaction as W}from"ethers";import"rango-types";var p=class{static{r(this,"EthereumSigner")}async signMessage(t){let o=await i(),{success:a,payload:n}=await o.signMessage({message:t,path:m()});if(!a)throw new Error(n.error);return n.signature}async signAndSendTx(t,o,a){try{let n=await i(),{gasPrice:h,maxFeePerGas:g,maxPriorityFeePerGas:u}=t,c=g&&u;if(c&&!g)throw new Error("Missing maxFeePerGas");if(c&&!u)throw new Error("Missing maxPriorityFeePerGas");if(!c&&!h)throw new Error("Missing gasPrice");let E=new L(_),F=await E.getTransactionCount(o),R=c?{maxFeePerGas:s(g||"0"),maxPriorityFeePerGas:s(u||"0")}:{gasPrice:s(h||"0")},l={to:t.to,data:t.data||"0x",value:s(t.value?.toString()||"0"),gasLimit:s(t.gasLimit?.toString()||"0"),chainId:Number.parseInt(a),nonce:s(F.toString()),...R},{success:D,payload:d}=await n.ethereumSignTransaction({path:m(),transaction:l});if(!D){let k=v[d?.code||""]||d.error;throw new Error(k)}let{r:b,s:A,v:B}=d,N=W.from({...l,nonce:Number.parseInt(l.nonce),type:c?2:0,signature:{r:b,s:A,v:parseInt(B)}}).serialized;return{hash:(await E.broadcastTransaction(N)).hash}}catch(n){throw P(n)}}};function f(){let e=new O;return e.registerSigner(j.EVM,new p),e}r(f,"getSigners");var S={appUrl:"",email:""},ye={type:Z.TREZOR},we=r(e=>{S=e.manifest},"init"),Te=z,I=!1,ve=r(async({namespaces:e})=>{let t=[],o=await i(),a=e?.find(n=>n.namespace===C.Evm);if(a)if(a.derivationPath){w(M(a.derivationPath)),I||(await o.init({lazyLoad:!0,manifest:S}),I=!0);let n=await x();t.push(n)}else throw new Error("Derivation Path can not be empty.");else throw new Error(`It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${e?.map(n=>n.namespace)}`);return t},"connect"),Pe=f,ze=r(e=>{let t=[],o=e.find(a=>a.name===X.ETHEREUM);return o&&t.push(o),{name:"Trezor",img:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg",installLink:{DEFAULT:"https://trezor.io/learn/a/download-verify-trezor-suite"},color:"black",supportedChains:t,namespaces:[C.Evm],singleNamespace:!0,showOnMobile:!1,needsDerivationPath:!0}},"getWalletInfo");export{ye as config,ve as connect,Te as getInstance,Pe as getSigners,ze as getWalletInfo,we as init};
1
+ var v=Object.defineProperty;var r=(e,t)=>v(e,"name",{value:t,configurable:!0});var f=(e,t)=>()=>(e&&(t=e(e=0)),t);var O=(e,t)=>{for(var n in t)v(e,n,{get:t[n],enumerable:!0})};function z(e){P=e}function m(){return P}var P,p=f(()=>{"use strict";P="";r(z,"setDerivationPath");r(m,"getDerivationPath")});import{ETHEREUM_CHAIN_ID as x,Networks as j}from"@rango-dev/wallets-shared";async function i(){let e=await import("@trezor/connect-web");return e.default.default?e.default.default:e.default}function I(){let e=new Map;return e.set(j.ETHEREUM,{chainId:x}),e}async function C(){let t=await(await i()).ethereumGetAddress({path:m()});if(!t.success)throw new Error(t.payload.error);return{accounts:[t.payload.address],chainId:x}}var M,s,S,h=f(()=>{"use strict";p();M={Failure_ActionCancelled:"User rejected the transaction."};r(i,"getTrezorModule");r(I,"getTrezorInstance");r(C,"getEthereumAccounts");s=r(e=>{let t=BigInt(0);return BigInt(e)>t?`0x${BigInt(e).toString(16)}`:"0x0"},"valueToHex"),S=r(e=>e&&!e.startsWith("m/")?"m/"+e:e,"getTrezorNormalizedDerivationPath")});var R={};O(R,{EthereumSigner:()=>E,getTrezorErrorMessage:()=>F});import{cleanEvmError as X}from"@rango-dev/signer-evm";import{DEFAULT_ETHEREUM_RPC_URL as Z}from"@rango-dev/wallets-shared";import{JsonRpcProvider as $,Transaction as J}from"ethers";import"rango-types";function F(e){return e?.shortMessage?new Error(e.shortMessage,{cause:e}):X(e)}var E,D=f(()=>{"use strict";h();p();r(F,"getTrezorErrorMessage");E=class{static{r(this,"EthereumSigner")}async signMessage(t){let n=await i(),{success:a,payload:o}=await n.signMessage({message:t,path:m()});if(!a)throw new Error(o.error);return o.signature}async signAndSendTx(t,n,a){try{let o=await i(),{gasPrice:w,maxFeePerGas:g,maxPriorityFeePerGas:u}=t,c=g&&u;if(c&&!g)throw new Error("Missing maxFeePerGas");if(c&&!u)throw new Error("Missing maxPriorityFeePerGas");if(!c&&!w)throw new Error("Missing gasPrice");let T=new $(Z),N=await T.getTransactionCount(n),k=c?{maxFeePerGas:s(g||"0"),maxPriorityFeePerGas:s(u||"0")}:{gasPrice:s(w||"0")},l={to:t.to,data:t.data||"0x",value:s(t.value?.toString()||"0"),gasLimit:s(t.gasLimit?.toString()||"0"),chainId:Number.parseInt(a),nonce:s(N.toString()),...k},{success:G,payload:d}=await o.ethereumSignTransaction({path:m(),transaction:l});if(!G){let W=M[d?.code||""]||d.error;throw new Error(W)}let{r:H,s:U,v:_}=d,L=J.from({...l,nonce:Number.parseInt(l.nonce),type:c?2:0,signature:{r:H,s:U,v:parseInt(_)}}).serialized;return{hash:(await T.broadcastTransaction(L)).hash}}catch(o){throw F(o)}}}});h();import{Namespace as A,Networks as q,WalletTypes as K}from"@rango-dev/wallets-shared";import"rango-types";import{DefaultSignerFactory as V,TransactionType as Y}from"rango-types";async function y(){let e=new V,{EthereumSigner:t}=await Promise.resolve().then(()=>(D(),R));return e.registerSigner(Y.EVM,new t),e}r(y,"getSigners");p();var B={appUrl:"",email:""},Pe={type:K.TREZOR},ze=r(e=>{B=e.manifest},"init"),xe=I,b=!1,Me=r(async({namespaces:e})=>{let t=[],n=await i(),a=e?.find(o=>o.namespace===A.Evm);if(a)if(a.derivationPath){z(S(a.derivationPath)),b||(await n.init({lazyLoad:!0,manifest:B}),b=!0);let o=await C();t.push(o)}else throw new Error("Derivation Path can not be empty.");else throw new Error(`It appears that you have selected a namespace that is not yet supported by our system. Your namespaces: ${e?.map(o=>o.namespace)}`);return t},"connect"),Ie=y,Ce=r(e=>{let t=[],n=e.find(a=>a.name===q.ETHEREUM);return n&&t.push(n),{name:"Trezor",img:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/trezor/icon.svg",installLink:{DEFAULT:"https://trezor.io/learn/a/download-verify-trezor-suite"},color:"black",supportedChains:t,namespaces:[A.Evm],singleNamespace:!0,showOnMobile:!1,needsDerivationPath:!0}},"getWalletInfo");export{Pe as config,Me as connect,xe as getInstance,Ie as getSigners,Ce as getWalletInfo,ze as init};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts", "../src/helpers.ts", "../src/state.ts", "../src/signer.ts", "../src/signers/ethereum.ts"],
4
- "sourcesContent": ["import type { Environments } from './types.js';\nimport type {\n Connect,\n ProviderConnectResult,\n WalletInfo,\n} from '@rango-dev/wallets-shared';\n\nimport { Namespace, Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport { type BlockchainMeta, type SignerFactory } from 'rango-types';\n\nimport {\n getEthereumAccounts,\n getTrezorInstance,\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from './helpers.js';\nimport signer from './signer.js';\nimport { setDerivationPath } from './state.js';\n\nlet trezorManifest: Environments['manifest'] = {\n appUrl: '',\n email: '',\n};\nexport const config = {\n type: WalletTypes.TREZOR,\n};\n\nexport type { Environments };\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 === 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: any) => SignerFactory = 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 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 namespaces: [Namespace.Evm],\n singleNamespace: true,\n showOnMobile: false,\n needsDerivationPath: true,\n };\n};\n", "import type { TrezorConnect } from '@trezor/connect-web';\n\nimport { cleanEvmError } from '@rango-dev/signer-evm';\nimport { ETHEREUM_CHAIN_ID, Networks } 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 import('@trezor/connect-web');\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 getTrezorErrorMessage(error: any) {\n if (error?.shortMessage) {\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 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<{\n accounts: string[];\n chainId: string;\n}> {\n const TrezorConnect = await getTrezorModule();\n const result = await TrezorConnect.ethereumGetAddress({\n path: getDerivationPath(),\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 };\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", "// We keep derivationPath here because we need to maintain it for signing transactions after it is set in connect method\nlet derivationPath = '';\n\nexport function setDerivationPath(path: string) {\n derivationPath = path;\n}\n\nexport function getDerivationPath() {\n return derivationPath;\n}\n", "import type { SignerFactory } from 'rango-types';\n\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { EthereumSigner } from './signers/ethereum.js';\n\nexport default function getSigners(): SignerFactory {\n const signers = new DefaultSignerFactory();\n signers.registerSigner(TxType.EVM, new EthereumSigner());\n return signers;\n}\n", "import type { EvmTransaction } from 'rango-types/mainApi';\n\nimport { DEFAULT_ETHEREUM_RPC_URL } from '@rango-dev/wallets-shared';\nimport { JsonRpcProvider, Transaction } from 'ethers';\nimport { type GenericSigner } from 'rango-types';\n\nimport {\n getTrezorErrorMessage,\n getTrezorModule,\n trezorErrorMessages,\n valueToHex,\n} from '../helpers.js';\nimport { getDerivationPath } from '../state.js';\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.signMessage({\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": "+EAOA,OAAS,aAAAA,EAAW,YAAAC,EAAU,eAAAC,MAAmB,4BACjD,MAAwD,cCNxD,OAAS,iBAAAC,MAAqB,wBAC9B,OAAS,qBAAAC,EAAmB,YAAAC,MAAgB,4BCF5C,IAAIC,EAAiB,GAEd,SAASC,EAAkBC,EAAc,CAC9CF,EAAiBE,CACnB,CAFgBC,EAAAF,EAAA,qBAIT,SAASG,GAAoB,CAClC,OAAOJ,CACT,CAFgBG,EAAAC,EAAA,qBDAT,IAAMC,EAAwD,CACnE,wBAAyB,gCAC3B,EAGA,eAAsBC,GAAkB,CACtC,IAAMC,EAAM,KAAM,QAAO,qBAAqB,EAG9C,OAAIA,EAAI,QAAQ,QAGPA,EAAI,QAAQ,QAGdA,EAAI,OACb,CAXsBC,EAAAF,EAAA,mBAaf,SAASG,EAAsBC,EAAY,CAChD,OAAIA,GAAO,aAKF,IAAI,MAAMA,EAAM,aAAc,CAAE,MAAOA,CAAM,CAAC,EAEhDC,EAAcD,CAAK,CAC5B,CATgBF,EAAAC,EAAA,yBAWT,SAASG,GAAo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,GAAG,EAC1B,gBAAiB,GACjB,aAAc,GACd,oBAAqB,EACvB,CACF,EAxB+E",
6
- "names": ["Namespace", "Networks", "WalletTypes", "cleanEvmError", "ETHEREUM_CHAIN_ID", "Networks", "derivationPath", "setDerivationPath", "path", "__name", "getDerivationPath", "trezorErrorMessages", "getTrezorModule", "mod", "__name", "getTrezorErrorMessage", "error", "cleanEvmError", "getTrezorInstance", "instances", "Networks", "ETHEREUM_CHAIN_ID", "getEthereumAccounts", "result", "getDerivationPath", "valueToHex", "value", "ZERO_BIGINT", "getTrezorNormalizedDerivationPath", "path", "DefaultSignerFactory", "TxType", "DEFAULT_ETHEREUM_RPC_URL", "JsonRpcProvider", "Transaction", "EthereumSigner", "__name", "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", "v", "serializedTx", "Transaction", "error", "getTrezorErrorMessage", "getSigners", "signers", "DefaultSignerFactory", "TxType", "EthereumSigner", "__name", "trezorManifest", "config", "WalletTypes", "init", "__name", "environments", "getInstance", "getTrezorInstance", "isTrezorInitialized", "connect", "namespaces", "results", "TrezorConnect", "getTrezorModule", "evmNamespace", "namespaceItem", "Namespace", "setDerivationPath", "getTrezorNormalizedDerivationPath", "accounts", "getEthereumAccounts", "getSigners", "getWalletInfo", "allBlockChains", "supportedChains", "ethereumBlockchain", "chain", "Networks"]
3
+ "sources": ["../src/state.ts", "../src/helpers.ts", "../src/signers/ethereum.ts", "../src/index.ts", "../src/signer.ts"],
4
+ "sourcesContent": ["// We keep derivationPath here because we need to maintain it for signing transactions after it is set in connect method\nlet derivationPath = '';\n\nexport function setDerivationPath(path: string) {\n derivationPath = path;\n}\n\nexport function getDerivationPath() {\n return derivationPath;\n}\n", "import type { TrezorConnect } from '@trezor/connect-web';\n\nimport { ETHEREUM_CHAIN_ID, Networks } 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 import('@trezor/connect-web');\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<{\n accounts: string[];\n chainId: string;\n}> {\n const TrezorConnect = await getTrezorModule();\n const result = await TrezorConnect.ethereumGetAddress({\n path: getDerivationPath(),\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 };\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", "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 '../helpers.js';\nimport { getDerivationPath } from '../state.js';\n\nexport function getTrezorErrorMessage(error: any) {\n if (error?.shortMessage) {\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.signMessage({\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", "import type { Environments } from './types.js';\nimport type {\n Connect,\n ProviderConnectResult,\n WalletInfo,\n} from '@rango-dev/wallets-shared';\n\nimport { Namespace, Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport { type BlockchainMeta, type SignerFactory } from 'rango-types';\n\nimport {\n getEthereumAccounts,\n getTrezorInstance,\n getTrezorModule,\n getTrezorNormalizedDerivationPath,\n} from './helpers.js';\nimport signer from './signer.js';\nimport { setDerivationPath } from './state.js';\n\nlet trezorManifest: Environments['manifest'] = {\n appUrl: '',\n email: '',\n};\nexport const config = {\n type: WalletTypes.TREZOR,\n};\n\nexport type { Environments };\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 === 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: any) => Promise<SignerFactory> = 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 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 namespaces: [Namespace.Evm],\n singleNamespace: true,\n showOnMobile: false,\n needsDerivationPath: true,\n };\n};\n", "import type { SignerFactory } from 'rango-types';\n\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 import('./signers/ethereum.js');\n signers.registerSigner(TxType.EVM, new EthereumSigner());\n return signers;\n}\n"],
5
+ "mappings": "gLAGO,SAASA,EAAkBC,EAAc,CAC9CC,EAAiBD,CACnB,CAEO,SAASE,GAAoB,CAClC,OAAOD,CACT,CATA,IACIA,EADJE,EAAAC,EAAA,kBACIH,EAAiB,GAELI,EAAAN,EAAA,qBAIAM,EAAAH,EAAA,uB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EtCC,EAAeJ,GAAY,KAC9BK,GAAkBA,EAAc,YAAcC,EAAU,GAC3D,EAEA,GAAIF,EACF,GAAIA,EAAa,eAAgB,CAC/BG,EACEC,EAAkCJ,EAAa,cAAc,CAC/D,EAEKN,IACH,MAAMI,EAAc,KAAK,CACvB,SAAU,GACV,SAAUZ,CACZ,CAAC,EAEDQ,EAAsB,IAGxB,IAAMW,EAAW,MAAMC,EAAoB,EAC3CT,EAAQ,KAAKQ,CAAQ,CACvB,KACE,OAAM,IAAI,MAAM,mCAAmC,MAGrD,OAAM,IAAI,MACR,2GAA2GT,GAAY,IACpHK,GAAkBA,EAAc,SACnC,CAAC,EACH,EAGF,OAAOJ,CACT,EAtCgC,WAwCnBU,GAAwDA,EAExDC,GAAkElB,EAC7EmB,GACG,CACH,IAAMC,EAAoC,CAAC,EAErCC,EAAqBF,EAAe,KACvCG,GAAUA,EAAM,OAASC,EAAS,QACrC,EACA,OAAIF,GACFD,EAAgB,KAAKC,CAAkB,EAElC,CACL,KAAM,SACN,IAAK,uFACL,YAAa,CACX,QAAS,wDACX,EACA,MAAO,QACP,gBAAAD,EACA,WAAY,CAACR,EAAU,GAAG,EAC1B,gBAAiB,GACjB,aAAc,GACd,oBAAqB,EACvB,CACF,EAxB+E",
6
+ "names": ["setDerivationPath", "path", "derivationPath", "getDerivationPath", "init_state", "__esmMin", "__name", "ETHEREUM_CHAIN_ID", "Networks", "getTrezorModule", "mod", "getTrezorInstance", "instances", "getEthereumAccounts", "result", "getDerivationPath", "trezorErrorMessages", "valueToHex", "getTrezorNormalizedDerivationPath", "init_helpers", "__esmMin", "init_state", "__name", "value", "ZERO_BIGINT", "path", "ethereum_exports", "__export", "EthereumSigner", "getTrezorErrorMessage", "cleanEvmError", "DEFAULT_ETHEREUM_RPC_URL", "JsonRpcProvider", "Transaction", "error", "init_ethereum", "__esmMin", "init_helpers", "init_state", "__name", "msg", "TrezorConnect", "getTrezorModule", "success", "payload", "getDerivationPath", "tx", "fromAddress", "chainId", "gasPrice", "maxFeePerGas", "maxPriorityFeePerGas", "isEIP1559", "provider", "transactionCount", "additionalFields", "valueToHex", "transaction", "errorMessage", "trezorErrorMessages", "r", "s", "v", "serializedTx", "init_helpers", "Namespace", "Networks", "WalletTypes", "DefaultSignerFactory", "TxType", "getSigners", "signers", "DefaultSignerFactory", "EthereumSigner", "TxType", "__name", "init_state", "trezorManifest", "config", "WalletTypes", "init", "__name", "environments", "getInstance", "getTrezorInstance", "isTrezorInitialized", "connect", "namespaces", "results", "TrezorConnect", "getTrezorModule", "evmNamespace", "namespaceItem", "Namespace", "setDerivationPath", "getTrezorNormalizedDerivationPath", "accounts", "getEthereumAccounts", "getSigners", "getWalletInfo", "allBlockChains", "supportedChains", "ethereumBlockchain", "chain", "Networks"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/state.ts":{"bytes":290,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/helpers.ts":{"bytes":2663,"imports":[{"path":"@rango-dev/signer-evm","kind":"import-statement","external":true},{"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":3320,"imports":[{"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/helpers.ts","kind":"import-statement","original":"../helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signer.ts":{"bytes":368,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signers/ethereum.ts","kind":"import-statement","original":"./signers/ethereum.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":2786,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"},{"path":"src/state.ts","kind":"import-statement","original":"./state.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":15318},"dist/index.js":{"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/signer-evm","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true},{"path":"rango-types","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":["config","connect","getInstance","getSigners","getWalletInfo","init"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":1022},"src/helpers.ts":{"bytesInOutput":898},"src/state.ts":{"bytesInOutput":99},"src/signer.ts":{"bytesInOutput":154},"src/signers/ethereum.ts":{"bytesInOutput":1222}},"bytes":3610}}}
1
+ {"inputs":{"src/state.ts":{"bytes":290,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/helpers.ts":{"bytes":2270,"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":3688,"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/helpers.ts","kind":"import-statement","original":"../helpers.js"},{"path":"src/state.ts","kind":"import-statement","original":"../state.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signer.ts":{"bytes":394,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signers/ethereum.ts","kind":"dynamic-import","original":"./signers/ethereum.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":2795,"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"},{"path":"src/state.ts","kind":"import-statement","original":"./state.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":15567},"dist/index.js":{"imports":[{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"@trezor/connect-web","kind":"dynamic-import","external":true},{"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":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true}],"exports":["config","connect","getInstance","getSigners","getWalletInfo","init"],"entryPoint":"src/index.ts","inputs":{"src/state.ts":{"bytesInOutput":125},"src/helpers.ts":{"bytesInOutput":767},"src/signers/ethereum.ts":{"bytesInOutput":1482},"src/index.ts":{"bytesInOutput":1030},"src/signer.ts":{"bytesInOutput":221}},"bytes":3937}}}
package/dist/signer.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { SignerFactory } from 'rango-types';
2
- export default function getSigners(): SignerFactory;
2
+ export default function getSigners(): Promise<SignerFactory>;
@@ -1,5 +1,6 @@
1
1
  import type { EvmTransaction } from 'rango-types/mainApi';
2
2
  import { type GenericSigner } from 'rango-types';
3
+ export declare function getTrezorErrorMessage(error: any): Error;
3
4
  export declare class EthereumSigner implements GenericSigner<EvmTransaction> {
4
5
  signMessage(msg: string): Promise<string>;
5
6
  signAndSendTx(tx: EvmTransaction, fromAddress: string, chainId: string): Promise<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-trezor",
3
- "version": "0.4.2-next.0",
3
+ "version": "0.4.2-next.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@rango-dev/signer-evm": "^0.30.0",
28
- "@rango-dev/wallets-shared": "^0.37.0",
28
+ "@rango-dev/wallets-shared": "^0.37.1-next.1",
29
29
  "@trezor/connect-web": "^9.2.4",
30
30
  "ethers": "^6.13.2",
31
31
  "rango-types": "^0.1.59"
@@ -33,4 +33,4 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  }
36
- }
36
+ }
package/src/helpers.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { TrezorConnect } from '@trezor/connect-web';
2
2
 
3
- import { cleanEvmError } from '@rango-dev/signer-evm';
4
3
  import { ETHEREUM_CHAIN_ID, Networks } from '@rango-dev/wallets-shared';
5
4
 
6
5
  import { getDerivationPath } from './state.js';
@@ -23,17 +22,6 @@ export async function getTrezorModule() {
23
22
  return mod.default;
24
23
  }
25
24
 
26
- export function getTrezorErrorMessage(error: any) {
27
- if (error?.shortMessage) {
28
- /*
29
- * Some error signs have lengthy, challenging-to-read messages.
30
- * shortMessage is used because it is shorter and easier to understand.
31
- */
32
- return new Error(error.shortMessage, { cause: error });
33
- }
34
- return cleanEvmError(error);
35
- }
36
-
37
25
  export function getTrezorInstance() {
38
26
  /*
39
27
  * Instances have a required property which is `chainId` and is using in swap execution.
package/src/index.ts CHANGED
@@ -74,7 +74,7 @@ export const connect: Connect = async ({ namespaces }) => {
74
74
  return results;
75
75
  };
76
76
 
77
- export const getSigners: (provider: any) => SignerFactory = signer;
77
+ export const getSigners: (provider: any) => Promise<SignerFactory> = signer;
78
78
 
79
79
  export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
80
80
  allBlockChains
package/src/signer.ts CHANGED
@@ -2,10 +2,9 @@ import type { SignerFactory } from 'rango-types';
2
2
 
3
3
  import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
4
4
 
5
- import { EthereumSigner } from './signers/ethereum.js';
6
-
7
- export default function getSigners(): SignerFactory {
5
+ export default async function getSigners(): Promise<SignerFactory> {
8
6
  const signers = new DefaultSignerFactory();
7
+ const { EthereumSigner } = await import('./signers/ethereum.js');
9
8
  signers.registerSigner(TxType.EVM, new EthereumSigner());
10
9
  return signers;
11
10
  }
@@ -1,17 +1,28 @@
1
1
  import type { EvmTransaction } from 'rango-types/mainApi';
2
2
 
3
+ import { cleanEvmError } from '@rango-dev/signer-evm';
3
4
  import { DEFAULT_ETHEREUM_RPC_URL } from '@rango-dev/wallets-shared';
4
5
  import { JsonRpcProvider, Transaction } from 'ethers';
5
6
  import { type GenericSigner } from 'rango-types';
6
7
 
7
8
  import {
8
- getTrezorErrorMessage,
9
9
  getTrezorModule,
10
10
  trezorErrorMessages,
11
11
  valueToHex,
12
12
  } from '../helpers.js';
13
13
  import { getDerivationPath } from '../state.js';
14
14
 
15
+ export function getTrezorErrorMessage(error: any) {
16
+ if (error?.shortMessage) {
17
+ /*
18
+ * Some error signs have lengthy, challenging-to-read messages.
19
+ * shortMessage is used because it is shorter and easier to understand.
20
+ */
21
+ return new Error(error.shortMessage, { cause: error });
22
+ }
23
+ return cleanEvmError(error);
24
+ }
25
+
15
26
  export class EthereumSigner implements GenericSigner<EvmTransaction> {
16
27
  async signMessage(msg: string): Promise<string> {
17
28
  const TrezorConnect = await getTrezorModule();