1import TrezorConnect from 'trezor-connect';
2import convertToInt from './convertToInt';
4const TREZOR_PATH = "m/44'/60'/0'/0/x";
6// handles 0x-prefixed hex string as well as number type
7const formatChainId = val =>
8 typeof val === 'number' ? val : convertToInt(val.slice(2), 16);
10const trezorSignTransaction = async (txn, hdpath) => {
11 const trezorFormattedTxn = {
12 to: txn.to.toString('hex'),
13 value: txn.value.toString('hex'),
14 data: txn.data.toString('hex'),
15 gasLimit: txn.gasLimit.toString('hex'),
16 gasPrice: txn.gasPrice.toString('hex'),
17 nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
18 chainId: formatChainId(txn.getChainId()),
21 const sig = await TrezorConnect.ethereumSignTransaction({
23 transaction: trezorFormattedTxn,
27 throw new Error(sig.payload.error);
30 const payload = sig.payload;
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');
39export const trezorSignMessage = async (message, hdPath) => {
40 const sig = await TrezorConnect.ethereumSignMessage({
46 throw new Error(sig.payload.error);
49 const { signature } = sig.payload;
54export { TREZOR_PATH, trezorSignTransaction };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list