on master help sign in
trezor: update transaction signing
c118649Fang
package-lock.json+3−3
@@ -33876,9 +33876,9 @@
33876 "integrity": "sha512-74MoNHhwLVuzwaPDcAecFjSkOA9vwWqyOdkeB0Be8Jc/IWSS5SNZKapFllqzkTliqZptkvqX5CZnVeDvfhN8cw=="
33876 "integrity": "sha512-74MoNHhwLVuzwaPDcAecFjSkOA9vwWqyOdkeB0Be8Jc/IWSS5SNZKapFllqzkTliqZptkvqX5CZnVeDvfhN8cw=="
33877 },
33877 },
33878 "trezor-connect": {
33878 "trezor-connect": {
33879− "version": "8.1.27",
33879+ "version": "8.1.29",
33880− "resolved": "https://registry.npmjs.org/trezor-connect/-/trezor-connect-8.1.27.tgz",
33880+ "resolved": "https://registry.npmjs.org/trezor-connect/-/trezor-connect-8.1.29.tgz",
33881− "integrity": "sha512-U6vP8kehQ5enCTY0k01R6jR3EORC+GIzTl4pM80lu9gJB5e988sM5YwK1hED6KZx7LJvFjWuOxB2J3W0pwv7lw==",
33881+ "integrity": "sha512-SYIT2C3mqNxTsDTglqgz6FyhgXbBFBo0q5WH9ABkyLUarjPNNt2PrmmgF5nT78RE5GwX5QvHoGl9Efis6+4e5Q==",
33882 "requires": {
33882 "requires": {
33883 "@babel/runtime": "^7.12.5",
33883 "@babel/runtime": "^7.12.5",
33884 "events": "^3.2.0",
33884 "events": "^3.2.0",
package.json+1−1
@@ -72,7 +72,7 @@
72 "secp256k1": "^4.0.2",
72 "secp256k1": "^4.0.2",
73 "styled-components": "^5.3.0",
73 "styled-components": "^5.3.0",
74 "styled-system": "^5.1.5",
74 "styled-system": "^5.1.5",
75− "trezor-connect": "^8.1.27",
75+ "trezor-connect": "^8.1.29",
76 "typescript": "^4.3.2",
76 "typescript": "^4.3.2",
77 "urbit-key-generation": "^0.19.0",
77 "urbit-key-generation": "^0.19.0",
78 "urbit-ob": "^4.1.4",
78 "urbit-ob": "^4.1.4",
src/lib/trezor.ts+5−4
@@ -1,5 +1,6 @@
1import TrezorConnect from 'trezor-connect';
1import TrezorConnect from 'trezor-connect';
2import { convertToInt } from './convertToInt';
2import { convertToInt } from './convertToInt';
3+import BN from 'bn.js';
3
4
4const TREZOR_PATH = "m/44'/60'/0'/0/x";
5const TREZOR_PATH = "m/44'/60'/0'/0/x";
5
6
@@ -15,7 +16,7 @@ const trezorSignTransaction = async (txn, hdpath) => {
15 gasLimit: txn.gasLimit.toString('hex'),
16 gasLimit: txn.gasLimit.toString('hex'),
16 gasPrice: txn.gasPrice.toString('hex'),
17 gasPrice: txn.gasPrice.toString('hex'),
17 nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
18 nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
18− chainId: formatChainId(txn.getChainId()),
19+ chainId: formatChainId(txn.common.chainId()),
19 };
20 };
20
21
21 const sig = await TrezorConnect.ethereumSignTransaction({
22 const sig = await TrezorConnect.ethereumSignTransaction({
@@ -29,9 +30,9 @@ const trezorSignTransaction = async (txn, hdpath) => {
29
30
30 const payload = sig.payload;
31 const payload = sig.payload;
31
32
32− txn.v = Buffer.from(payload.v.slice(2), 'hex');
33+ txn.v = new BN(payload.v.slice(2), 'hex');
33− txn.r = Buffer.from(payload.r.slice(2), 'hex');
34+ txn.r = new BN(payload.r.slice(2), 'hex');
34− txn.s = Buffer.from(payload.s.slice(2), 'hex');
35+ txn.s = new BN(payload.s.slice(2), 'hex');
35
36
36 return txn;
37 return txn;
37};
38};