@sidhujag/sysweb3-keyring 2.1.8 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.9
4
+
5
+ - Share canonical Trezor EVM signing across all six existing transaction paths and explicitly hosted native consumers. Preserve reviewed nonces, fees, access lists and account identity, with current-session checks before and after device signing.
6
+ - Preserve trusted, locally observed pre-broadcast failure information for Ledger and Trezor without accepting device or provider claims. Reject mismatched signed envelopes without attaching their transaction hash.
7
+
3
8
  ## 2.1.8
4
9
 
5
10
  - Allow native and browser hosts to supply their Ledger transport through the same keyring engine and explicit session authority.
@@ -21,6 +21,7 @@ const evm_local_signer_1 = require("./evm-local-signer");
21
21
  const evm_submission_1 = require("./evm-submission");
22
22
  const ledger_signing_1 = require("./ledger-signing");
23
23
  const prepared_evm_1 = require("./prepared-evm");
24
+ const trezor_signing_1 = require("./trezor-signing");
24
25
  const derivation_paths_1 = require("../utils/derivation-paths");
25
26
  const hardwareSignerUnavailable = (hardware) => Object.assign(new Error(`${hardware} signer is unavailable in this host`), {
26
27
  code: 'HARDWARE_SIGNER_UNAVAILABLE',
@@ -38,26 +39,6 @@ const stripHexPrefix = (value) => {
38
39
  ? value.slice(2)
39
40
  : value;
40
41
  };
41
- // Connect returns hexadecimal signature fields; normalize their encoding
42
- // without mutating the response or reparsing an already numeric recovery v.
43
- const trezorSignature = (signature) => {
44
- const { r, s, v } = signature;
45
- if (![r, s].every((value) => /^(?:0x)?[0-9a-f]{64}$/i.test(value))) {
46
- throw new Error('Invalid Trezor signature scalar encoding');
47
- }
48
- if (typeof v === 'string' && !/^(?:0x)?[0-9a-f]+$/i.test(v)) {
49
- throw new Error('Invalid Trezor signature recovery value');
50
- }
51
- const recovery = typeof v === 'number' ? v : Number.parseInt(v, 16);
52
- if (!Number.isSafeInteger(recovery) || recovery < 0) {
53
- throw new Error('Invalid Trezor signature recovery value');
54
- }
55
- return {
56
- r: `0x${stripHexPrefix(r)}`,
57
- s: `0x${stripHexPrefix(s)}`,
58
- v: recovery,
59
- };
60
- };
61
42
  const normalizeEthersOverrideValue = (value) => (0, ethers_v6_1.normalizeTxValue)(value);
62
43
  // The same protocol bound applies to software and external-device envelopes.
63
44
  // Keep this at serialization as well as before handing a request to a device.
@@ -1067,29 +1048,20 @@ class EthereumTransactions {
1067
1048
  const expectedUnsignedTransaction = serializeTransaction(txFormattedForTrezor);
1068
1049
  if (retained)
1069
1050
  assertCancellationEnvelope(expectedUnsignedTransaction);
1070
- const signature = await this.requireTrezorSigner().signEthTransaction({
1051
+ const { rawTransaction: signedTx } = await (0, trezor_signing_1.signTrezorEvmTransaction)(this.requireTrezorSigner(), {
1052
+ accountIndex: activeAccountId,
1071
1053
  coin: trezorCoin,
1072
- tx: txFormattedForTrezor,
1073
- index: activeAccountId.toString(),
1054
+ expectedAddress: activeAccount.address,
1074
1055
  slip44: activeNetwork.slip44,
1056
+ unsignedTransaction: expectedUnsignedTransaction,
1075
1057
  }, await this.authorizeHardwareTransaction(provider, assertCurrent));
1076
1058
  assertCurrent();
1077
- if (signature.success) {
1078
- const signedTx = serializeTransaction(txFormattedForTrezor, trezorSignature(signature.payload));
1079
- assertCurrent();
1080
- assertHardwareTransactionSender(signedTx, activeAccount.address);
1081
- const transactionResponse = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, undefined, expectedUnsignedTransaction);
1082
- return {
1083
- isCanceled: true,
1084
- transaction: transactionResponse,
1085
- };
1086
- }
1087
- else {
1088
- return {
1089
- isCanceled: false,
1090
- error: true,
1091
- };
1092
- }
1059
+ assertHardwareTransactionSender(signedTx, activeAccount.address);
1060
+ const transactionResponse = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, undefined, expectedUnsignedTransaction);
1061
+ return {
1062
+ isCanceled: true,
1063
+ transaction: transactionResponse,
1064
+ };
1093
1065
  }
1094
1066
  catch (error) {
1095
1067
  return {
@@ -1504,40 +1476,17 @@ class EthereumTransactions {
1504
1476
  ...txFormattedForTrezor,
1505
1477
  type: isLegacy ? 0 : 2,
1506
1478
  });
1507
- const signature = await this.requireTrezorSigner().signEthTransaction({
1508
- index: `${activeAccountId}`,
1509
- tx: txFormattedForTrezor,
1479
+ const { rawTransaction: signedTx } = await (0, trezor_signing_1.signTrezorEvmTransaction)(this.requireTrezorSigner(), {
1480
+ accountIndex: activeAccountId,
1510
1481
  coin: activeNetwork.currency,
1482
+ expectedAddress: activeAccount.address,
1511
1483
  slip44: activeNetwork.slip44,
1484
+ unsignedTransaction: expectedUnsignedTransaction,
1512
1485
  }, await this.authorizeHardwareTransaction(provider, assertCurrent));
1513
1486
  assertCurrent();
1514
- if (signature.success) {
1515
- try {
1516
- const txFormattedForEthers = isLegacy
1517
- ? {
1518
- ...formatParams,
1519
- nonce: transactionNonce,
1520
- chainId: activeNetwork.chainId,
1521
- type: 0, // Force Type 0 for legacy
1522
- }
1523
- : {
1524
- ...formatParams,
1525
- nonce: transactionNonce,
1526
- chainId: activeNetwork.chainId,
1527
- type: 2, // Need explicit type for hardware wallet serialization
1528
- };
1529
- const signedTx = serializeTransaction(txFormattedForEthers, trezorSignature(signature.payload));
1530
- assertHardwareTransactionSender(signedTx, activeAccount.address);
1531
- const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, assertBeforeBroadcast, expectedUnsignedTransaction);
1532
- return finalTx;
1533
- }
1534
- catch (error) {
1535
- throw error;
1536
- }
1537
- }
1538
- else {
1539
- throw new Error(`Transaction Signature Failed. Error: ${signature}`);
1540
- }
1487
+ assertHardwareTransactionSender(signedTx, activeAccount.address);
1488
+ const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, assertBeforeBroadcast, expectedUnsignedTransaction);
1489
+ return finalTx;
1541
1490
  };
1542
1491
  const sendEVMTransaction = async () => {
1543
1492
  assertCurrent();
@@ -1869,28 +1818,20 @@ class EthereumTransactions {
1869
1818
  assertCurrent();
1870
1819
  assertTransactionGasLimit(txFormattedForTrezor);
1871
1820
  const expectedUnsignedTransaction = serializeTransaction(txFormattedForTrezor);
1872
- const signature = await this.requireTrezorSigner().signEthTransaction({
1821
+ const { rawTransaction: signedTx } = await (0, trezor_signing_1.signTrezorEvmTransaction)(this.requireTrezorSigner(), {
1822
+ accountIndex: activeAccountId,
1873
1823
  coin: trezorCoin,
1874
- tx: txFormattedForTrezor,
1875
- index: activeAccountId.toString(),
1824
+ expectedAddress: activeAccount.address,
1876
1825
  slip44: activeNetwork.slip44,
1826
+ unsignedTransaction: expectedUnsignedTransaction,
1877
1827
  }, await this.authorizeHardwareTransaction(provider, assertCurrent));
1878
- if (signature.success) {
1879
- const signedTx = serializeTransaction(txFormattedForTrezor, trezorSignature(signature.payload));
1880
- assertSignedSender(signedTx);
1881
- assertHardwareTransactionSender(signedTx, activeAccount.address);
1882
- const transactionResponse = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, assertBeforeBroadcast, expectedUnsignedTransaction);
1883
- return {
1884
- isSpeedUp: true,
1885
- transaction: transactionResponse,
1886
- };
1887
- }
1888
- else {
1889
- return {
1890
- isSpeedUp: false,
1891
- error: true,
1892
- };
1893
- }
1828
+ assertSignedSender(signedTx);
1829
+ assertHardwareTransactionSender(signedTx, activeAccount.address);
1830
+ const transactionResponse = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, assertBeforeBroadcast, expectedUnsignedTransaction);
1831
+ return {
1832
+ isSpeedUp: true,
1833
+ transaction: transactionResponse,
1834
+ };
1894
1835
  }
1895
1836
  catch (error) {
1896
1837
  console.error('[SpeedUp] Failed to send replacement transaction with Trezor:', error);
@@ -2105,58 +2046,21 @@ class EthereumTransactions {
2105
2046
  ...txToBeSignedByTrezor,
2106
2047
  type: isLegacy ? 0 : 2,
2107
2048
  });
2108
- const signature = await this.requireTrezorSigner().signEthTransaction({
2109
- index: `${activeAccountId}`,
2110
- tx: txToBeSignedByTrezor,
2049
+ const { rawTransaction: signedTx } = await (0, trezor_signing_1.signTrezorEvmTransaction)(this.requireTrezorSigner(), {
2050
+ accountIndex: activeAccountId,
2111
2051
  coin: activeNetwork.currency,
2052
+ expectedAddress: activeAccount.address,
2112
2053
  slip44: activeNetwork.slip44,
2054
+ unsignedTransaction: expectedUnsignedTransaction,
2113
2055
  }, await this.authorizeHardwareTransaction(provider, assertCurrent, signal));
2114
2056
  assertCurrent();
2115
- if (signature.success) {
2116
- try {
2117
- let txFormattedForEthers;
2118
- if (isLegacy) {
2119
- txFormattedForEthers = {
2120
- to: tokenAddress,
2121
- value: '0x0',
2122
- gasLimit: gasLimit,
2123
- gasPrice,
2124
- data: txData,
2125
- nonce,
2126
- chainId: activeNetwork.chainId,
2127
- type: 0,
2128
- };
2129
- }
2130
- else {
2131
- txFormattedForEthers = {
2132
- to: tokenAddress,
2133
- value: '0x0',
2134
- gasLimit: gasLimit,
2135
- maxFeePerGas,
2136
- maxPriorityFeePerGas,
2137
- data: txData,
2138
- nonce,
2139
- chainId: activeNetwork.chainId,
2140
- type: 2, // Need explicit type for hardware wallet serialization
2141
- };
2142
- }
2143
- const signedTx = serializeTransaction(txFormattedForEthers, trezorSignature(signature.payload));
2144
- assertCurrent();
2145
- assertHardwareTransactionSender(signedTx, activeAccount.address);
2146
- const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, async ({ rawTransaction, admit }) => {
2147
- const response = await admit(() => provider.sendTransaction(rawTransaction));
2148
- saveTrezorTx && saveTrezorTx(response);
2149
- return response;
2150
- }, submission, undefined, expectedUnsignedTransaction);
2151
- return finalTx;
2152
- }
2153
- catch (error) {
2154
- throw error;
2155
- }
2156
- }
2157
- else {
2158
- throw new Error(`Transaction Signature Failed. Error: ${signature}`);
2159
- }
2057
+ assertHardwareTransactionSender(signedTx, activeAccount.address);
2058
+ const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, async ({ rawTransaction, admit }) => {
2059
+ const response = await admit(() => provider.sendTransaction(rawTransaction));
2060
+ saveTrezorTx && saveTrezorTx(response);
2061
+ return response;
2062
+ }, submission, undefined, expectedUnsignedTransaction);
2063
+ return finalTx;
2160
2064
  }
2161
2065
  catch (error) {
2162
2066
  throw error;
@@ -2311,55 +2215,17 @@ class EthereumTransactions {
2311
2215
  ...txToBeSignedByTrezor,
2312
2216
  type: isLegacy ? 0 : 2,
2313
2217
  });
2314
- const signature = await this.requireTrezorSigner().signEthTransaction({
2315
- index: `${activeAccountId}`,
2316
- tx: txToBeSignedByTrezor,
2218
+ const { rawTransaction: signedTx } = await (0, trezor_signing_1.signTrezorEvmTransaction)(this.requireTrezorSigner(), {
2219
+ accountIndex: activeAccountId,
2317
2220
  coin: trezorCoin,
2221
+ expectedAddress: activeAccount.address,
2318
2222
  slip44: activeNetwork.slip44,
2223
+ unsignedTransaction: expectedUnsignedTransaction,
2319
2224
  }, await this.authorizeHardwareTransaction(provider, assertCurrent, signal));
2320
2225
  assertCurrent();
2321
- if (signature.success) {
2322
- try {
2323
- let txFormattedForEthers;
2324
- if (isLegacy) {
2325
- txFormattedForEthers = {
2326
- to: tokenAddress,
2327
- value: '0x0',
2328
- gasLimit,
2329
- gasPrice,
2330
- data: txData,
2331
- nonce,
2332
- chainId: activeNetwork.chainId,
2333
- type: 0,
2334
- };
2335
- }
2336
- else {
2337
- txFormattedForEthers = {
2338
- to: tokenAddress,
2339
- value: '0x0',
2340
- gasLimit,
2341
- maxFeePerGas,
2342
- maxPriorityFeePerGas,
2343
- data: txData,
2344
- nonce,
2345
- chainId: activeNetwork.chainId,
2346
- type: 2, // Need explicit type for hardware wallet serialization
2347
- };
2348
- }
2349
- const signedTx = serializeTransaction(txFormattedForEthers, trezorSignature(signature.payload));
2350
- assertCurrent();
2351
- assertHardwareTransactionSender(signedTx, activeAccount.address);
2352
- const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, undefined, expectedUnsignedTransaction);
2353
- return finalTx;
2354
- }
2355
- catch (error) {
2356
- console.log({ error });
2357
- throw error;
2358
- }
2359
- }
2360
- else {
2361
- throw new Error(`Transaction Signature Failed. Error: ${signature}`);
2362
- }
2226
+ assertHardwareTransactionSender(signedTx, activeAccount.address);
2227
+ const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, undefined, expectedUnsignedTransaction);
2228
+ return finalTx;
2363
2229
  }
2364
2230
  catch (error) {
2365
2231
  console.log({ errorDois: error });
@@ -2508,55 +2374,17 @@ class EthereumTransactions {
2508
2374
  ...txToBeSignedByTrezor,
2509
2375
  type: isLegacy ? 0 : 2,
2510
2376
  });
2511
- const signature = await this.requireTrezorSigner().signEthTransaction({
2512
- index: `${activeAccountId}`,
2513
- tx: txToBeSignedByTrezor,
2377
+ const { rawTransaction: signedTx } = await (0, trezor_signing_1.signTrezorEvmTransaction)(this.requireTrezorSigner(), {
2378
+ accountIndex: activeAccountId,
2514
2379
  coin: activeNetwork.currency,
2380
+ expectedAddress: activeAccount.address,
2515
2381
  slip44: activeNetwork.slip44,
2382
+ unsignedTransaction: expectedUnsignedTransaction,
2516
2383
  }, await this.authorizeHardwareTransaction(provider, assertCurrent, signal));
2517
2384
  assertCurrent();
2518
- if (signature.success) {
2519
- try {
2520
- let txFormattedForEthers;
2521
- if (isLegacy) {
2522
- txFormattedForEthers = {
2523
- to: tokenAddress,
2524
- value: '0x0',
2525
- gasLimit,
2526
- gasPrice,
2527
- data: txData,
2528
- nonce,
2529
- chainId: activeNetwork.chainId,
2530
- type: 0,
2531
- };
2532
- }
2533
- else {
2534
- txFormattedForEthers = {
2535
- to: tokenAddress,
2536
- value: '0x0',
2537
- gasLimit,
2538
- maxFeePerGas,
2539
- maxPriorityFeePerGas,
2540
- data: txData,
2541
- nonce,
2542
- chainId: activeNetwork.chainId,
2543
- type: 2, // Need explicit type for hardware wallet serialization
2544
- };
2545
- }
2546
- const signedTx = serializeTransaction(txFormattedForEthers, trezorSignature(signature.payload));
2547
- assertCurrent();
2548
- assertHardwareTransactionSender(signedTx, activeAccount.address);
2549
- const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, undefined, expectedUnsignedTransaction);
2550
- return finalTx;
2551
- }
2552
- catch (error) {
2553
- console.log({ error });
2554
- throw error;
2555
- }
2556
- }
2557
- else {
2558
- throw new Error(`Transaction Signature Failed. Error: ${signature}`);
2559
- }
2385
+ assertHardwareTransactionSender(signedTx, activeAccount.address);
2386
+ const finalTx = await this.submitSignedHardwareTransaction(provider, signedTx, ({ rawTransaction, admit }) => admit(() => provider.sendTransaction(rawTransaction)), submission, undefined, expectedUnsignedTransaction);
2387
+ return finalTx;
2560
2388
  }
2561
2389
  catch (error) {
2562
2390
  console.log({ error });