1import TrezorConnect from 'trezor-connect';
2import { convertToInt } from './convertToInt';
5const TREZOR_PATH = "m/44'/60'/0'/0/x";
7// handles 0x-prefixed hex string as well as number type
8const formatChainId = val =>
9 typeof val === 'number' ? val : convertToInt(val.slice(2), 16);
11const trezorSignTransaction = async (txn, hdpath) => {
12 const trezorFormattedTxn = {
13 to: txn.to.toString('hex'),
14 value: txn.value.toString('hex'),
15 data: txn.data.toString('hex'),
16 gasLimit: txn.gasLimit.toString('hex'),
17 gasPrice: txn.gasPrice.toString('hex'),
18 nonce: txn.nonce.length === 0 ? '00' : txn.nonce.toString('hex'),
19 chainId: formatChainId(txn.common.chainId()),
22 const sig = await TrezorConnect.ethereumSignTransaction({
24 transaction: trezorFormattedTxn,
28 throw new Error(sig.payload.error);
31 const payload = sig.payload;
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');
40export const trezorSignMessage = async (message, hdPath) => {
41 const sig = await TrezorConnect.ethereumSignMessage({
47 throw new Error(sig.payload.error);
50 const { signature } = sig.payload;
55export { 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