@rango-dev/provider-trezor 0.29.0 → 0.29.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/actions/utxo.d.ts +12 -0
  3. package/dist/chunk-FTGT4J2G.js +2 -0
  4. package/dist/chunk-FTGT4J2G.js.map +7 -0
  5. package/dist/chunk-HUUVMU7F.js +2 -0
  6. package/dist/chunk-HUUVMU7F.js.map +7 -0
  7. package/dist/{ethereum-AWO7VVVT.js → ethereum-WJFMSBHD.js} +2 -2
  8. package/dist/ethereum-WJFMSBHD.js.map +7 -0
  9. package/dist/init.d.ts +1 -0
  10. package/dist/mod.d.ts +1 -1
  11. package/dist/mod.js +1 -1
  12. package/dist/mod.js.map +4 -4
  13. package/dist/namespaces/utxo.d.ts +3 -0
  14. package/dist/provider-trezor.build.json +1 -1
  15. package/dist/provider.d.ts +1 -1
  16. package/dist/signers/utxo.d.ts +8 -0
  17. package/dist/state.d.ts +2 -0
  18. package/dist/{legacy/helpers.d.ts → utils.d.ts} +1 -2
  19. package/dist/utxo/config.d.ts +17 -0
  20. package/dist/utxo/psbt.d.ts +29 -0
  21. package/dist/utxo/psbt.test.d.ts +1 -0
  22. package/dist/utxo-MZNQ2QK4.js +2 -0
  23. package/dist/utxo-MZNQ2QK4.js.map +7 -0
  24. package/package.json +7 -2
  25. package/readme.md +15 -0
  26. package/src/actions/utxo.ts +56 -0
  27. package/src/constants.ts +23 -1
  28. package/src/init.ts +20 -0
  29. package/src/mod.ts +1 -5
  30. package/src/namespaces/evm.ts +4 -14
  31. package/src/namespaces/utxo.ts +24 -0
  32. package/src/provider.ts +2 -0
  33. package/src/signer.ts +4 -0
  34. package/src/signers/ethereum.ts +1 -1
  35. package/src/signers/utxo.ts +90 -0
  36. package/src/state.ts +15 -0
  37. package/src/{legacy/helpers.ts → utils.ts} +1 -14
  38. package/src/utxo/config.ts +67 -0
  39. package/src/utxo/psbt.test.ts +162 -0
  40. package/src/utxo/psbt.ts +96 -0
  41. package/dist/chunk-DRNBRMLU.js +0 -2
  42. package/dist/chunk-DRNBRMLU.js.map +0 -7
  43. package/dist/ethereum-AWO7VVVT.js.map +0 -7
  44. package/dist/legacy/index.d.ts +0 -18
  45. package/src/legacy/index.ts +0 -151
@@ -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, toHexQuantity } 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 { getTrezorModule, trezorErrorMessages } 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: toHexQuantity(maxFeePerGas || '0'),\n maxPriorityFeePerGas: toHexQuantity(maxPriorityFeePerGas || '0'),\n }\n : {\n gasPrice: toHexQuantity(gasPrice || '0'),\n };\n\n const transaction = {\n to: tx.to,\n data: tx.data || '0x',\n value: toHexQuantity(tx.value?.toString() || '0'),\n gasLimit: toHexQuantity(tx.gasLimit?.toString() || '0'),\n chainId: Number.parseInt(chainId),\n nonce: toHexQuantity(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": "6DAEA,OAAS,iBAAAA,EAAe,iBAAAC,MAAqB,wBAC7C,OAAS,4BAAAC,MAAgC,4BACzC,OAAS,mBAAAC,EAAiB,eAAAC,MAAmB,SAC7C,MAAmC,cAK5B,SAASC,EAAsBC,EAAgB,CACpD,OACE,OAAOA,GAAU,UACjBA,I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CAAO,EAChC,MAAOU,EAAcF,EAAiB,SAAS,CAAC,EAChD,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", "toHexQuantity", "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", "toHexQuantity", "transaction", "errorMessage", "trezorErrorMessages", "r", "s", "serializedTx", "Transaction"]
7
- }
@@ -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,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 };