on master help sign in
Merge pull request #609 from urbit/m/trezor-fix

trezor: update transaction signing

commite3f37088f04e3b7515747f47156798a107855eb3 authorfang <github@fang.io> dateTue 17 Aug 2021, 15:33 (5 years ago) parent9e88ab0c118649
3 files changed+9−8
package-lock.json+3−3 package.json+1−1 src/lib/trezor.ts+5−4
package-lock.json+3−3
@@ -33876,9 +33876,9 @@
3387633876 "integrity": "sha512-74MoNHhwLVuzwaPDcAecFjSkOA9vwWqyOdkeB0Be8Jc/IWSS5SNZKapFllqzkTliqZptkvqX5CZnVeDvfhN8cw=="
3387733877 },
3387833878 "trezor-connect": {
33879− "version": "8.1.27",
33880− "resolved": "https://registry.npmjs.org/trezor-connect/-/trezor-connect-8.1.27.tgz",
33881− "integrity": "sha512-U6vP8kehQ5enCTY0k01R6jR3EORC+GIzTl4pM80lu9gJB5e988sM5YwK1hED6KZx7LJvFjWuOxB2J3W0pwv7lw==",
33879+ "version": "8.1.29",
33880+ "resolved": "https://registry.npmjs.org/trezor-connect/-/trezor-connect-8.1.29.tgz",
33881+ "integrity": "sha512-SYIT2C3mqNxTsDTglqgz6FyhgXbBFBo0q5WH9ABkyLUarjPNNt2PrmmgF5nT78RE5GwX5QvHoGl9Efis6+4e5Q==",
3388233882 "requires": {
3388333883 "@babel/runtime": "^7.12.5",
3388433884 "events": "^3.2.0",
package.json+1−1
@@ -72,7 +72,7 @@
7272 "secp256k1": "^4.0.2",
7373 "styled-components": "^5.3.0",
7474 "styled-system": "^5.1.5",
75− "trezor-connect": "^8.1.27",
75+ "trezor-connect": "^8.1.29",
7676 "typescript": "^4.3.2",
7777 "urbit-key-generation": "^0.19.0",
7878 "urbit-ob": "^4.1.4",
src/lib/trezor.ts+5−4
@@ -1,5 +1,6 @@
11import TrezorConnect from 'trezor-connect';
22import { convertToInt } from './convertToInt';
3+import BN from 'bn.js';
34
45const TREZOR_PATH = "m/44'/60'/0'/0/x";
56
@@ -15,7 +16,7 @@ const trezorSignTransaction = async (txn, hdpath) => {
1516 gasLimit: txn.gasLimit.toString('hex'),
1617 gasPrice: txn.gasPrice.toString('hex'),
1718 nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
18− chainId: formatChainId(txn.getChainId()),
19+ chainId: formatChainId(txn.common.chainId()),
1920 };
2021
2122 const sig = await TrezorConnect.ethereumSignTransaction({
@@ -29,9 +30,9 @@ const trezorSignTransaction = async (txn, hdpath) => {
2930
3031 const payload = sig.payload;
3132
32− txn.v = Buffer.from(payload.v.slice(2), 'hex');
33− txn.r = Buffer.from(payload.r.slice(2), 'hex');
34− txn.s = Buffer.from(payload.s.slice(2), 'hex');
33+ txn.v = new BN(payload.v.slice(2), 'hex');
34+ txn.r = new BN(payload.r.slice(2), 'hex');
35+ txn.s = new BN(payload.s.slice(2), 'hex');
3536
3637 return txn;
3738};