@trezor/connect 9.5.4 → 9.5.5-beta.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +800 -775
  2. package/README.md +5 -5
  3. package/lib/api/bitcoin/TransactionComposer.d.ts +3 -1
  4. package/lib/api/bitcoin/TransactionComposer.js +6 -3
  5. package/lib/api/bitcoin/index.d.ts +0 -1
  6. package/lib/api/bitcoin/index.js +0 -1
  7. package/lib/api/bitcoin/transactionBytes.d.ts +5 -0
  8. package/lib/api/bitcoin/transactionBytes.js +74 -0
  9. package/lib/api/bleUnpair.d.ts +9 -0
  10. package/lib/api/bleUnpair.js +36 -0
  11. package/lib/api/blockchainEstimateFee.js +4 -16
  12. package/lib/api/common/Discovery.d.ts +12 -10
  13. package/lib/api/common/Discovery.js +2 -4
  14. package/lib/api/composeTransaction.js +1 -1
  15. package/lib/api/ethereum/api/ethereumSignMessage.d.ts +6 -0
  16. package/lib/api/ethereum/api/ethereumSignMessage.js +10 -0
  17. package/lib/api/ethereum/api/ethereumSignTransaction.d.ts +21 -1
  18. package/lib/api/ethereum/api/ethereumSignTransaction.js +66 -0
  19. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +6 -0
  20. package/lib/api/ethereum/api/ethereumSignTypedData.js +10 -0
  21. package/lib/api/getFeatures.js +1 -0
  22. package/lib/api/index.d.ts +1 -0
  23. package/lib/api/index.js +3 -1
  24. package/lib/api/signMessage.d.ts +8 -0
  25. package/lib/api/signMessage.js +16 -6
  26. package/lib/api/signTransaction.d.ts +205 -0
  27. package/lib/api/signTransaction.js +43 -0
  28. package/lib/api/solana/api/solanaSignTransaction.d.ts +20 -0
  29. package/lib/api/solana/api/solanaSignTransaction.js +132 -0
  30. package/lib/api/solana/solanaUtils.d.ts +1 -0
  31. package/lib/api/solana/solanaUtils.js +2 -1
  32. package/lib/backend/BackendManager.js +1 -1
  33. package/lib/backend/Blockchain.d.ts +1 -3
  34. package/lib/backend/Blockchain.js +1 -21
  35. package/lib/{api/bitcoin/BitcoinFees.d.ts → backend/fees/BitcoinFeeLevels.d.ts} +5 -6
  36. package/lib/{api/bitcoin/BitcoinFees.js → backend/fees/BitcoinFeeLevels.js} +5 -4
  37. package/lib/{api/ethereum/EthereumFees.d.ts → backend/fees/EthereumFeeLevels.d.ts} +4 -5
  38. package/lib/{api/ethereum/EthereumFees.js → backend/fees/EthereumFeeLevels.js} +4 -5
  39. package/lib/{api/common/MiscFees.d.ts → backend/fees/MiscFeeLevels.d.ts} +3 -3
  40. package/lib/{api/common/MiscFees.js → backend/fees/MiscFeeLevels.js} +3 -2
  41. package/lib/backend/fees/index.d.ts +6 -0
  42. package/lib/backend/fees/index.js +33 -0
  43. package/lib/constants/firmware.d.ts +0 -1
  44. package/lib/constants/firmware.js +1 -2
  45. package/lib/core/AbstractMethod.d.ts +7 -4
  46. package/lib/core/AbstractMethod.js +8 -1
  47. package/lib/core/index.d.ts +0 -1
  48. package/lib/core/index.js +22 -27
  49. package/lib/core/onCallFirmwareUpdate.js +1 -1
  50. package/lib/data/DataManager.d.ts +4 -1
  51. package/lib/data/DataManager.js +7 -0
  52. package/lib/data/config.d.ts +0 -14
  53. package/lib/data/config.js +4 -12
  54. package/lib/data/connectSettings.d.ts +5 -1
  55. package/lib/data/connectSettings.js +26 -2
  56. package/lib/data/defaultFeeLevels.js +3 -3
  57. package/lib/data/deviceAuthenticityConfig.js +22 -7
  58. package/lib/data/thpSettings.d.ts +3 -0
  59. package/lib/data/thpSettings.js +37 -0
  60. package/lib/data/version.d.ts +1 -1
  61. package/lib/data/version.js +1 -1
  62. package/lib/device/Device.d.ts +8 -11
  63. package/lib/device/Device.js +40 -80
  64. package/lib/device/DeviceCurrentSession.d.ts +9 -1
  65. package/lib/device/DeviceList.js +1 -1
  66. package/lib/events/index.d.ts +2 -0
  67. package/lib/events/ui-request.d.ts +18 -4
  68. package/lib/events/ui-request.js +1 -0
  69. package/lib/events/ui-response.d.ts +7 -1
  70. package/lib/events/ui-response.js +1 -0
  71. package/lib/factory.js +1 -0
  72. package/lib/tsconfig.lib.tsbuildinfo +1 -1
  73. package/lib/types/api/bleUnpair.d.ts +4 -0
  74. package/lib/types/api/bleUnpair.js +3 -0
  75. package/lib/types/api/index.d.ts +2 -0
  76. package/lib/types/api/solana/index.d.ts +4 -0
  77. package/lib/types/api/solana/index.js +1 -0
  78. package/lib/types/device.d.ts +4 -0
  79. package/lib/types/fees.d.ts +2 -0
  80. package/lib/types/fees.js +2 -0
  81. package/lib/types/firmware.d.ts +5 -0
  82. package/lib/types/settings.d.ts +20 -2
  83. package/lib/utils/firmwareUtils.d.ts +3 -1
  84. package/lib/utils/firmwareUtils.js +7 -1
  85. package/lib/utils/uiPromiseManager.d.ts +2 -0
  86. package/lib/utils/versionCheck.js +1 -1
  87. package/package.json +17 -16
@@ -18,6 +18,211 @@ type Params = {
18
18
  export default class SignTransaction extends AbstractMethod<'signTransaction', Params> {
19
19
  init(): void;
20
20
  get info(): string;
21
+ payloadToPrecomposed(): Promise<{
22
+ type: "final";
23
+ inputs: (({
24
+ sequence?: number | undefined;
25
+ multisig?: {
26
+ address_n?: number[] | undefined;
27
+ nodes?: {
28
+ private_key?: string | undefined;
29
+ public_key: string;
30
+ depth: number;
31
+ fingerprint: number;
32
+ child_num: number;
33
+ chain_code: string;
34
+ }[] | undefined;
35
+ pubkeys_order?: PROTO.MultisigPubkeysOrder | undefined;
36
+ pubkeys: {
37
+ address_n: number[];
38
+ node: string | {
39
+ private_key?: string | undefined;
40
+ public_key: string;
41
+ depth: number;
42
+ fingerprint: number;
43
+ child_num: number;
44
+ chain_code: string;
45
+ };
46
+ }[];
47
+ signatures: string[];
48
+ m: number;
49
+ } | undefined;
50
+ decred_tree?: number | undefined;
51
+ orig_hash?: string | undefined;
52
+ orig_index?: number | undefined;
53
+ decred_staking_spend?: PROTO.DecredStakingSpendType | undefined;
54
+ script_pubkey?: string | undefined;
55
+ coinjoin_flags?: number | undefined;
56
+ script_sig?: string | undefined;
57
+ witness?: string | undefined;
58
+ ownership_proof?: string | undefined;
59
+ commitment_data?: string | undefined;
60
+ amount: string | number;
61
+ prev_hash: string;
62
+ prev_index: number;
63
+ } & {
64
+ script_type?: "SPENDADDRESS" | "SPENDMULTISIG" | "SPENDWITNESS" | "SPENDP2SHWITNESS" | "SPENDTAPROOT" | undefined;
65
+ address_n: number[];
66
+ }) | ({
67
+ sequence?: number | undefined;
68
+ multisig?: {
69
+ address_n?: number[] | undefined;
70
+ nodes?: {
71
+ private_key?: string | undefined;
72
+ public_key: string;
73
+ depth: number;
74
+ fingerprint: number;
75
+ child_num: number;
76
+ chain_code: string;
77
+ }[] | undefined;
78
+ pubkeys_order?: PROTO.MultisigPubkeysOrder | undefined;
79
+ pubkeys: {
80
+ address_n: number[];
81
+ node: string | {
82
+ private_key?: string | undefined;
83
+ public_key: string;
84
+ depth: number;
85
+ fingerprint: number;
86
+ child_num: number;
87
+ chain_code: string;
88
+ };
89
+ }[];
90
+ signatures: string[];
91
+ m: number;
92
+ } | undefined;
93
+ decred_tree?: number | undefined;
94
+ orig_hash?: string | undefined;
95
+ orig_index?: number | undefined;
96
+ decred_staking_spend?: PROTO.DecredStakingSpendType | undefined;
97
+ script_pubkey?: string | undefined;
98
+ coinjoin_flags?: number | undefined;
99
+ script_sig?: string | undefined;
100
+ witness?: string | undefined;
101
+ ownership_proof?: string | undefined;
102
+ commitment_data?: string | undefined;
103
+ amount: string | number;
104
+ prev_hash: string;
105
+ prev_index: number;
106
+ } & {
107
+ address_n?: undefined;
108
+ script_pubkey: string;
109
+ script_type: "EXTERNAL";
110
+ }))[];
111
+ outputs: ({
112
+ address_n?: undefined;
113
+ multisig?: {
114
+ address_n?: number[] | undefined;
115
+ nodes?: {
116
+ private_key?: string | undefined;
117
+ public_key: string;
118
+ depth: number;
119
+ fingerprint: number;
120
+ child_num: number;
121
+ chain_code: string;
122
+ }[] | undefined;
123
+ pubkeys_order?: PROTO.MultisigPubkeysOrder | undefined;
124
+ pubkeys: {
125
+ address_n: number[];
126
+ node: string | {
127
+ private_key?: string | undefined;
128
+ public_key: string;
129
+ depth: number;
130
+ fingerprint: number;
131
+ child_num: number;
132
+ chain_code: string;
133
+ };
134
+ }[];
135
+ signatures: string[];
136
+ m: number;
137
+ } | undefined;
138
+ orig_hash?: string | undefined;
139
+ orig_index?: number | undefined;
140
+ payment_req_index?: number | undefined;
141
+ address: string;
142
+ amount: string | number;
143
+ script_type: "PAYTOADDRESS";
144
+ } | {
145
+ address?: undefined;
146
+ multisig?: {
147
+ address_n?: number[] | undefined;
148
+ nodes?: {
149
+ private_key?: string | undefined;
150
+ public_key: string;
151
+ depth: number;
152
+ fingerprint: number;
153
+ child_num: number;
154
+ chain_code: string;
155
+ }[] | undefined;
156
+ pubkeys_order?: PROTO.MultisigPubkeysOrder | undefined;
157
+ pubkeys: {
158
+ address_n: number[];
159
+ node: string | {
160
+ private_key?: string | undefined;
161
+ public_key: string;
162
+ depth: number;
163
+ fingerprint: number;
164
+ child_num: number;
165
+ chain_code: string;
166
+ };
167
+ }[];
168
+ signatures: string[];
169
+ m: number;
170
+ } | undefined;
171
+ orig_hash?: string | undefined;
172
+ orig_index?: number | undefined;
173
+ script_type?: "PAYTOADDRESS" | "PAYTOSCRIPTHASH" | "PAYTOMULTISIG" | "PAYTOWITNESS" | "PAYTOP2SHWITNESS" | "PAYTOTAPROOT" | undefined;
174
+ payment_req_index?: number | undefined;
175
+ address_n: number[];
176
+ amount: string | number;
177
+ } | {
178
+ address_n?: undefined;
179
+ multisig?: {
180
+ address_n?: number[] | undefined;
181
+ nodes?: {
182
+ private_key?: string | undefined;
183
+ public_key: string;
184
+ depth: number;
185
+ fingerprint: number;
186
+ child_num: number;
187
+ chain_code: string;
188
+ }[] | undefined;
189
+ pubkeys_order?: PROTO.MultisigPubkeysOrder | undefined;
190
+ pubkeys: {
191
+ address_n: number[];
192
+ node: string | {
193
+ private_key?: string | undefined;
194
+ public_key: string;
195
+ depth: number;
196
+ fingerprint: number;
197
+ child_num: number;
198
+ chain_code: string;
199
+ };
200
+ }[];
201
+ signatures: string[];
202
+ m: number;
203
+ } | undefined;
204
+ orig_hash?: string | undefined;
205
+ orig_index?: number | undefined;
206
+ script_type?: "PAYTOADDRESS" | "PAYTOSCRIPTHASH" | "PAYTOMULTISIG" | "PAYTOWITNESS" | "PAYTOP2SHWITNESS" | "PAYTOTAPROOT" | undefined;
207
+ payment_req_index?: number | undefined;
208
+ address: string;
209
+ amount: string | number;
210
+ } | {
211
+ address_n?: undefined;
212
+ address?: undefined;
213
+ orig_hash?: string | undefined;
214
+ orig_index?: number | undefined;
215
+ payment_req_index?: number | undefined;
216
+ amount: 0 | "0";
217
+ script_type: "PAYTOOPRETURN";
218
+ op_return_data: string;
219
+ })[];
220
+ outputsPermutation: number[];
221
+ totalSpent: string;
222
+ fee: string;
223
+ feePerByte: string;
224
+ bytes: number;
225
+ } | undefined>;
21
226
  private fetchAddresses;
22
227
  private fetchRefTxs;
23
228
  run(): Promise<import("../types").SignedTransaction>;
@@ -8,6 +8,7 @@ const AbstractMethod_1 = require("../core/AbstractMethod");
8
8
  const paramsValidator_1 = require("./common/paramsValidator");
9
9
  const coinInfo_1 = require("../data/coinInfo");
10
10
  const pathUtils_1 = require("../utils/pathUtils");
11
+ const transactionBytes_1 = require("./bitcoin/transactionBytes");
11
12
  class SignTransaction extends AbstractMethod_1.AbstractMethod {
12
13
  init() {
13
14
  this.requiredPermissions = ['read', 'write'];
@@ -102,6 +103,48 @@ class SignTransaction extends AbstractMethod_1.AbstractMethod {
102
103
  const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(this.payload.coin);
103
104
  return (0, pathUtils_1.getLabel)('Sign #NETWORK transaction', coinInfo);
104
105
  }
106
+ async payloadToPrecomposed() {
107
+ try {
108
+ const { inputs, outputs, coinInfo } = this.params;
109
+ const refTxs = this.params.refTxs ?? (await this.fetchRefTxs(false));
110
+ const inputsTotal = inputs.reduce((bn, input) => {
111
+ if (typeof input.amount === 'string') {
112
+ return bn.plus(input.amount);
113
+ }
114
+ else {
115
+ const refTx = refTxs.find(tx => tx.hash === input.prev_hash);
116
+ const refOutput = refTx?.outputs?.[input.prev_index] ??
117
+ refTx?.bin_outputs?.[input.prev_index];
118
+ if (refOutput)
119
+ return bn.plus(refOutput.amount);
120
+ }
121
+ return bn;
122
+ }, new bigNumber_1.BigNumber(0));
123
+ const outputsTotal = outputs.reduce((bn, output) => bn.plus(typeof output.amount === 'string' ? output.amount : '0'), new bigNumber_1.BigNumber(0));
124
+ const bytes = (0, transactionBytes_1.getTransactionVbytes)(inputs, outputs, coinInfo);
125
+ if (!bytes)
126
+ throw constants_1.ERRORS.TypedError('Runtime', 'Transaction bytes not calculated');
127
+ const fee = inputsTotal.minus(outputsTotal);
128
+ if (fee.lte(0)) {
129
+ throw constants_1.ERRORS.TypedError('Runtime', 'Computed fee is non-positive');
130
+ }
131
+ const feePerByte = fee.dividedBy(bytes);
132
+ return {
133
+ type: 'final',
134
+ inputs,
135
+ outputs,
136
+ outputsPermutation: Array.from({ length: outputs.length }, (_, i) => i),
137
+ totalSpent: inputsTotal.toString(),
138
+ fee: fee.toString(),
139
+ feePerByte: feePerByte.toString(),
140
+ bytes,
141
+ };
142
+ }
143
+ catch (e) {
144
+ console.error('Error in payloadToPrecomposed', e);
145
+ return undefined;
146
+ }
147
+ }
105
148
  async fetchAddresses(blockchain) {
106
149
  const { device, params: { inputs, coinInfo }, } = this;
107
150
  const accountPath = inputs.find(i => i.address_n);
@@ -1,3 +1,4 @@
1
+ import { TokenInfo } from '@trezor/blockchain-link-types';
1
2
  import { PROTO } from '../../../constants';
2
3
  import { AbstractMethod } from '../../../core/AbstractMethod';
3
4
  type Params = PROTO.SolanaSignTx & {
@@ -6,6 +7,25 @@ type Params = PROTO.SolanaSignTx & {
6
7
  export default class SolanaSignTransaction extends AbstractMethod<'solanaSignTransaction', Params> {
7
8
  init(): void;
8
9
  get info(): string;
10
+ payloadToPrecomposed(): Promise<undefined> | Promise<{
11
+ type: "final";
12
+ inputs: never[];
13
+ outputsPermutation: number[];
14
+ outputs: {
15
+ address: string;
16
+ amount: string;
17
+ script_type: "PAYTOADDRESS";
18
+ }[];
19
+ totalSpent: string;
20
+ fee: string;
21
+ feePerByte: string;
22
+ feeLimit: string;
23
+ bytes: number;
24
+ max: undefined;
25
+ isTokenKnown: boolean;
26
+ token: TokenInfo | undefined;
27
+ createdTimestamp: number | undefined;
28
+ }>;
9
29
  run(): Promise<{
10
30
  signature: string;
11
31
  serializedTx: string;
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const kit_1 = require("@solana/kit");
4
+ const compute_budget_1 = require("@solana-program/compute-budget");
5
+ const system_1 = require("@solana-program/system");
6
+ const token_1 = require("@solana-program/token");
3
7
  const schema_utils_1 = require("@trezor/schema-utils");
8
+ const utils_1 = require("@trezor/utils");
9
+ const constants_1 = require("../../../constants");
4
10
  const AbstractMethod_1 = require("../../../core/AbstractMethod");
5
11
  const coinInfo_1 = require("../../../data/coinInfo");
6
12
  const solana_1 = require("../../../types/api/solana");
@@ -26,6 +32,132 @@ class SolanaSignTransaction extends AbstractMethod_1.AbstractMethod {
26
32
  get info() {
27
33
  return 'Sign Solana transaction';
28
34
  }
35
+ payloadToPrecomposed() {
36
+ try {
37
+ let messageBytes;
38
+ if (this.payload.serialize) {
39
+ const transaction = (0, kit_1.pipe)(this.payload.serializedTx, (0, kit_1.getBase16Encoder)().encode, (0, kit_1.getTransactionDecoder)().decode);
40
+ messageBytes = transaction.messageBytes;
41
+ }
42
+ else {
43
+ messageBytes = (0, kit_1.getBase16Encoder)().encode(this.payload.serializedTx);
44
+ }
45
+ const compiledMessage = (0, kit_1.pipe)(messageBytes, (0, kit_1.getCompiledTransactionMessageDecoder)().decode);
46
+ const message = (0, kit_1.decompileTransactionMessage)(compiledMessage);
47
+ const baseFee = new utils_1.BigNumber(solanaUtils_1.SOLANA_BASE_FEE).multipliedBy(compiledMessage.header.numSignerAccounts);
48
+ const outputs = [];
49
+ let feePerUnit = new utils_1.BigNumber(0);
50
+ let feeLimit = new utils_1.BigNumber(0);
51
+ let rent = new utils_1.BigNumber(0);
52
+ let sendAmount = new utils_1.BigNumber(0);
53
+ let token;
54
+ for (const instruction of message.instructions) {
55
+ if (instruction.programAddress === compute_budget_1.COMPUTE_BUDGET_PROGRAM_ADDRESS &&
56
+ instruction.data) {
57
+ const data = instruction.data;
58
+ const type = (0, compute_budget_1.identifyComputeBudgetInstruction)({ data });
59
+ if (type === compute_budget_1.ComputeBudgetInstruction.SetComputeUnitPrice) {
60
+ const parsed = (0, compute_budget_1.parseSetComputeUnitPriceInstruction)({
61
+ data,
62
+ programAddress: compute_budget_1.COMPUTE_BUDGET_PROGRAM_ADDRESS,
63
+ });
64
+ feePerUnit = new utils_1.BigNumber(parsed.data.microLamports.toString());
65
+ }
66
+ if (type === compute_budget_1.ComputeBudgetInstruction.SetComputeUnitLimit) {
67
+ const parsed = (0, compute_budget_1.parseSetComputeUnitLimitInstruction)({
68
+ data,
69
+ programAddress: compute_budget_1.COMPUTE_BUDGET_PROGRAM_ADDRESS,
70
+ });
71
+ feeLimit = new utils_1.BigNumber(parsed.data.units.toString());
72
+ }
73
+ }
74
+ if (instruction.programAddress === system_1.SYSTEM_PROGRAM_ADDRESS &&
75
+ instruction.data &&
76
+ instruction.accounts) {
77
+ const instructionSafe = {
78
+ ...instruction,
79
+ data: instruction.data,
80
+ accounts: instruction.accounts,
81
+ };
82
+ const type = (0, system_1.identifySystemInstruction)(instructionSafe);
83
+ if (type === system_1.SystemInstruction.TransferSol) {
84
+ const parsed = (0, system_1.parseTransferSolInstruction)(instructionSafe);
85
+ outputs.push({
86
+ address: parsed.accounts.destination.address,
87
+ amount: parsed.data.amount.toString(),
88
+ script_type: 'PAYTOADDRESS',
89
+ });
90
+ sendAmount = sendAmount.plus(parsed.data.amount.toString());
91
+ }
92
+ else if (type === system_1.SystemInstruction.CreateAccount) {
93
+ const parsed = (0, system_1.parseCreateAccountInstruction)(instructionSafe);
94
+ outputs.push({
95
+ address: parsed.accounts.newAccount.address,
96
+ amount: parsed.data.lamports.toString(),
97
+ script_type: 'PAYTOADDRESS',
98
+ });
99
+ rent = rent.plus(parsed.data.lamports.toString());
100
+ }
101
+ }
102
+ if (instruction.programAddress === token_1.TOKEN_PROGRAM_ADDRESS &&
103
+ instruction.data &&
104
+ instruction.accounts) {
105
+ const instructionSafe = {
106
+ ...instruction,
107
+ data: instruction.data,
108
+ accounts: instruction.accounts,
109
+ };
110
+ const type = (0, token_1.identifyTokenInstruction)(instructionSafe);
111
+ if (type === token_1.TokenInstruction.TransferChecked) {
112
+ const parsed = (0, token_1.parseTransferCheckedInstruction)(instructionSafe);
113
+ const destinationATA = parsed.accounts.destination.address;
114
+ const tokenInfo = this.payload.additionalInfo?.tokenAccountsInfos?.find(t => t.tokenAccount === destinationATA &&
115
+ t.tokenMint === parsed.accounts.mint.address);
116
+ if (!sendAmount.isZero()) {
117
+ throw constants_1.ERRORS.TypedError('Runtime', 'Multiple token transfers in a single transaction are not supported');
118
+ }
119
+ outputs.push({
120
+ address: tokenInfo?.baseAddress || destinationATA,
121
+ amount: parsed.data.amount.toString(),
122
+ script_type: 'PAYTOADDRESS',
123
+ });
124
+ sendAmount = new utils_1.BigNumber(parsed.data.amount.toString());
125
+ token = {
126
+ type: 'SPL',
127
+ standard: 'SPL',
128
+ contract: parsed.accounts.mint.address,
129
+ decimals: parsed.data.decimals,
130
+ symbol: tokenInfo?.symbol,
131
+ };
132
+ }
133
+ }
134
+ }
135
+ if (outputs.length === 0) {
136
+ throw constants_1.ERRORS.TypedError('Runtime', 'No outputs decoded');
137
+ }
138
+ const fee = baseFee.plus(feePerUnit.multipliedBy(feeLimit).dividedBy(1e6));
139
+ const totalSpent = sendAmount.plus(rent).plus(fee);
140
+ return Promise.resolve({
141
+ type: 'final',
142
+ inputs: [],
143
+ outputsPermutation: [0],
144
+ outputs,
145
+ totalSpent: token ? sendAmount.toString() : totalSpent.toString(),
146
+ fee: fee.toString(),
147
+ feePerByte: feePerUnit.toString(),
148
+ feeLimit: feeLimit.toString(),
149
+ bytes: 0,
150
+ max: undefined,
151
+ isTokenKnown: false,
152
+ token,
153
+ createdTimestamp: 'blockhash' in message.lifetimeConstraint ? new Date().getTime() : undefined,
154
+ });
155
+ }
156
+ catch (e) {
157
+ console.error('Error in payloadToPrecomposed', e);
158
+ return Promise.resolve(undefined);
159
+ }
160
+ }
29
161
  async run() {
30
162
  const cmd = this.device.getCommands();
31
163
  if (this.params.serialize) {
@@ -3,6 +3,7 @@ import type { TokenAccount } from '@trezor/blockchain-link-types';
3
3
  import type { TokenProgramName } from '@trezor/blockchain-link-utils/lib/solana';
4
4
  import { BigNumber } from '@trezor/utils/lib/bigNumber';
5
5
  import { Blockchain } from '../../backend/Blockchain';
6
+ export declare const SOLANA_BASE_FEE = 5000;
6
7
  export declare const getLamportsFromSol: (amountInSol: string) => bigint;
7
8
  type PriorityFees = {
8
9
  computeUnitPrice: string;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.fetchAccountOwnerAndTokenInfoForAddress = exports.buildTokenTransferTransaction = exports.getMinimumRequiredTokenAccountsForTransfer = exports.buildCreateAssociatedTokenAccountInstruction = exports.getAssociatedTokenAccountAddress = exports.buildTokenTransferInstruction = exports.buildTransferTransaction = exports.dummyPriorityFeesForFeeEstimation = exports.getLamportsFromSol = void 0;
36
+ exports.fetchAccountOwnerAndTokenInfoForAddress = exports.buildTokenTransferTransaction = exports.getMinimumRequiredTokenAccountsForTransfer = exports.buildCreateAssociatedTokenAccountInstruction = exports.getAssociatedTokenAccountAddress = exports.buildTokenTransferInstruction = exports.buildTransferTransaction = exports.dummyPriorityFeesForFeeEstimation = exports.getLamportsFromSol = exports.SOLANA_BASE_FEE = void 0;
37
37
  exports.createTransactionShim = createTransactionShim;
38
38
  exports.createTransactionShimFromHex = createTransactionShimFromHex;
39
39
  const ts_belt_1 = require("@mobily/ts-belt");
@@ -53,6 +53,7 @@ const loadSolanaTokenProgramLib = async (tokenProgramName) => {
53
53
  throw new Error(`Unsupported token program: ${tokenProgramName}`);
54
54
  }
55
55
  };
56
+ exports.SOLANA_BASE_FEE = 5000;
56
57
  const getLamportsFromSol = (amountInSol) => BigInt(new bigNumber_1.BigNumber(amountInSol).times(10 ** 9).toString());
57
58
  exports.getLamportsFromSol = getLamportsFromSol;
58
59
  exports.dummyPriorityFeesForFeeEstimation = {
@@ -107,7 +107,7 @@ class BackendManager {
107
107
  patchCoinInfo(coinInfo) {
108
108
  const custom = this.custom[coinInfo.shortcut];
109
109
  const preferred = this.preferred[coinInfo.shortcut];
110
- const url = preferred ? [preferred] : custom?.url ?? coinInfo.blockchainLink?.url;
110
+ const url = preferred ? [preferred] : (custom?.url ?? coinInfo.blockchainLink?.url);
111
111
  return {
112
112
  ...coinInfo,
113
113
  blockchainLink: {
@@ -1,4 +1,4 @@
1
- import BlockchainLink, { BlockchainLinkParams, BlockchainLinkResponse, ServerInfo, SubscriptionAccountInfo } from '@trezor/blockchain-link';
1
+ import BlockchainLink, { BlockchainLinkParams, ServerInfo, SubscriptionAccountInfo } from '@trezor/blockchain-link';
2
2
  import { ERRORS } from '../constants';
3
3
  import { CoreEventMessage } from '../events';
4
4
  import type { CoinInfo, Proxy } from '../types';
@@ -16,8 +16,6 @@ export declare class Blockchain {
16
16
  readonly identity?: string;
17
17
  readonly coinInfo: BlockchainOptions['coinInfo'];
18
18
  readonly postMessage: BlockchainOptions['postMessage'];
19
- feeForBlock: BlockchainLinkResponse<'estimateFee'>;
20
- feeTimestamp: number;
21
19
  private onDisconnected;
22
20
  private initPromise?;
23
21
  constructor(options: BlockchainOptions);
@@ -34,8 +34,6 @@ class Blockchain {
34
34
  identity;
35
35
  coinInfo;
36
36
  postMessage;
37
- feeForBlock = [];
38
- feeTimestamp = 0;
39
37
  onDisconnected;
40
38
  initPromise;
41
39
  constructor(options) {
@@ -147,25 +145,7 @@ class Blockchain {
147
145
  rpcCall(params) {
148
146
  return this.link.rpcCall(params);
149
147
  }
150
- async estimateFee(request) {
151
- const { blocks } = request;
152
- const useCache = !request.specific && Array.isArray(blocks) && blocks.length > 0;
153
- if (useCache) {
154
- const outdated = Date.now() - this.feeTimestamp > 20 * 60 * 1000;
155
- const unknownBlocks = outdated
156
- ? blocks
157
- : blocks.filter(block => !this.feeForBlock[block]);
158
- if (unknownBlocks.length < 1) {
159
- return blocks.map(block => this.feeForBlock[block]);
160
- }
161
- this.feeForBlock = [];
162
- const fees = await this.link.estimateFee(request);
163
- blocks.forEach((block, index) => {
164
- this.feeForBlock[block] = fees[index];
165
- });
166
- this.feeTimestamp = Date.now();
167
- return fees;
168
- }
148
+ estimateFee(request) {
169
149
  return this.link.estimateFee(request);
170
150
  }
171
151
  subscribeBlocks() {
@@ -1,9 +1,8 @@
1
- import { Blockchain } from '../../backend/BlockchainLink';
2
- import type { BitcoinNetworkInfo, FeeLevel } from '../../types';
3
- import { Blocks } from '../common/MiscFees';
4
- export declare class BitcoinFeeLevels {
1
+ import type { BitcoinNetworkInfo } from '../../types';
2
+ import { Blockchain } from '../Blockchain';
3
+ import { Blocks, MiscFeeLevels } from './MiscFeeLevels';
4
+ export declare class BitcoinFeeLevels extends MiscFeeLevels {
5
5
  coinInfo: BitcoinNetworkInfo;
6
- levels: FeeLevel[];
7
6
  longTermFeeRate?: string;
8
7
  blocks: Blocks;
9
8
  constructor(coinInfo: BitcoinNetworkInfo);
@@ -20,4 +19,4 @@ export declare class BitcoinFeeLevels {
20
19
  }[]>;
21
20
  updateBitcoinCustomFee(feePerUnit: string): void;
22
21
  }
23
- //# sourceMappingURL=BitcoinFees.d.ts.map
22
+ //# sourceMappingURL=BitcoinFeeLevels.d.ts.map
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BitcoinFeeLevels = void 0;
4
4
  const bigNumber_1 = require("@trezor/utils/lib/bigNumber");
5
+ const MiscFeeLevels_1 = require("./MiscFeeLevels");
5
6
  const findBlocksForFee = (feePerUnit, blocks) => {
6
7
  const fee = new bigNumber_1.BigNumber(feePerUnit);
7
8
  const lower = blocks.find(block => typeof block === 'string' && fee.gte(block));
@@ -46,14 +47,13 @@ const findLowest = (blocks) => blocks
46
47
  .slice(0)
47
48
  .reverse()
48
49
  .find(item => typeof item === 'string');
49
- class BitcoinFeeLevels {
50
+ class BitcoinFeeLevels extends MiscFeeLevels_1.MiscFeeLevels {
50
51
  coinInfo;
51
- levels;
52
52
  longTermFeeRate;
53
53
  blocks = [];
54
54
  constructor(coinInfo) {
55
+ super(coinInfo);
55
56
  this.coinInfo = coinInfo;
56
- this.levels = coinInfo.defaultFees;
57
57
  }
58
58
  async load(blockchain) {
59
59
  let blocks = fillGap(0, 1, 10);
@@ -85,6 +85,7 @@ class BitcoinFeeLevels {
85
85
  }
86
86
  });
87
87
  this.longTermFeeRate = findLowest(this.blocks);
88
+ this.wasFetchedSuccessfully = true;
88
89
  }
89
90
  catch {
90
91
  }
@@ -101,4 +102,4 @@ class BitcoinFeeLevels {
101
102
  }
102
103
  }
103
104
  exports.BitcoinFeeLevels = BitcoinFeeLevels;
104
- //# sourceMappingURL=BitcoinFees.js.map
105
+ //# sourceMappingURL=BitcoinFeeLevels.js.map
@@ -1,9 +1,8 @@
1
- import { Blockchain } from '../../backend/BlockchainLink';
2
- import type { EthereumNetworkInfo, FeeLevel } from '../../types';
3
- import { Blocks, MiscFeeLevels } from '../common/MiscFees';
1
+ import type { EthereumNetworkInfo } from '../../types';
2
+ import { Blockchain } from '../Blockchain';
3
+ import { Blocks, MiscFeeLevels } from './MiscFeeLevels';
4
4
  export declare class EthereumFeeLevels extends MiscFeeLevels {
5
5
  coinInfo: EthereumNetworkInfo;
6
- levels: FeeLevel[];
7
6
  blocks: Blocks;
8
7
  constructor(coinInfo: EthereumNetworkInfo);
9
8
  load(blockchain: Blockchain, request: Parameters<typeof blockchain.estimateFee>[0]): Promise<{
@@ -18,4 +17,4 @@ export declare class EthereumFeeLevels extends MiscFeeLevels {
18
17
  feePerUnit: string;
19
18
  }[]>;
20
19
  }
21
- //# sourceMappingURL=EthereumFees.d.ts.map
20
+ //# sourceMappingURL=EthereumFeeLevels.d.ts.map
@@ -2,15 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EthereumFeeLevels = void 0;
4
4
  const bigNumber_1 = require("@trezor/utils/lib/bigNumber");
5
- const MiscFees_1 = require("../common/MiscFees");
6
- class EthereumFeeLevels extends MiscFees_1.MiscFeeLevels {
5
+ const MiscFeeLevels_1 = require("./MiscFeeLevels");
6
+ class EthereumFeeLevels extends MiscFeeLevels_1.MiscFeeLevels {
7
7
  coinInfo;
8
- levels;
9
8
  blocks = [];
10
9
  constructor(coinInfo) {
11
10
  super(coinInfo);
12
11
  this.coinInfo = coinInfo;
13
- this.levels = coinInfo.defaultFees;
14
12
  }
15
13
  async load(blockchain, request) {
16
14
  try {
@@ -47,6 +45,7 @@ class EthereumFeeLevels extends MiscFees_1.MiscFeeLevels {
47
45
  feePerUnit,
48
46
  };
49
47
  }
48
+ this.wasFetchedSuccessfully = true;
50
49
  }
51
50
  catch {
52
51
  }
@@ -54,4 +53,4 @@ class EthereumFeeLevels extends MiscFees_1.MiscFeeLevels {
54
53
  }
55
54
  }
56
55
  exports.EthereumFeeLevels = EthereumFeeLevels;
57
- //# sourceMappingURL=EthereumFees.js.map
56
+ //# sourceMappingURL=EthereumFeeLevels.js.map
@@ -1,11 +1,11 @@
1
- import { Blockchain } from '../../backend/BlockchainLink';
2
1
  import type { CoinInfo, FeeLevel } from '../../types';
2
+ import { Blockchain } from '../Blockchain';
3
3
  export type Blocks = Array<string | undefined>;
4
4
  export declare class MiscFeeLevels {
5
5
  coinInfo: CoinInfo;
6
6
  levels: FeeLevel[];
7
- longTermFeeRate?: string;
8
7
  blocks: Blocks;
8
+ wasFetchedSuccessfully: boolean;
9
9
  constructor(coinInfo: CoinInfo);
10
10
  load(blockchain: Blockchain, request: Parameters<typeof blockchain.estimateFee>[0]): Promise<{
11
11
  feePerTx?: string | undefined;
@@ -19,4 +19,4 @@ export declare class MiscFeeLevels {
19
19
  feePerUnit: string;
20
20
  }[]>;
21
21
  }
22
- //# sourceMappingURL=MiscFees.d.ts.map
22
+ //# sourceMappingURL=MiscFeeLevels.d.ts.map