Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement eip-1559 support for Trezors #549

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions main/rpc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,24 @@ const rpc = {
},
// setSignerIndex: signers.setSignerIndex,
// unsetSigner: signers.unsetSigner,
trezorPin: (id, pin, cb) => signers.trezorPin(id, pin, cb),
trezorPhrase: (id, phrase, cb) => signers.trezorPhrase(id, phrase, cb),
trezorPin: (id, pin, cb) => {
const signer = signers.get(id)
if (signer && signer.setPin) {
signer.setPin(pin)
cb(null, { status: 'ok' })
} else {
cb(new Error('Set pin not available'))
}
},
trezorPhrase: (id, phrase, cb) => {
const signer = signers.get(id)
if (signer && signer.setPhrase) {
signer.setPhrase(phrase || '')
cb(null, { status: 'ok' })
} else {
cb(new Error('Set phrase not available'))
}
},
createLattice: async (id, cb) => {
try {
cb(null, await signers.createLattice(id))
Expand Down
6 changes: 3 additions & 3 deletions main/signers/Signer/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export function deriveHDAccounts (publicKey: string, chainCode: string, cb: (err
}

const derivationPaths: { [key: string]: string } = {
[Derivation.legacy.valueOf()]: "44'/60'/0'/",
[Derivation.standard.valueOf()]: "44'/60'/0'/0/",
[Derivation.testnet.valueOf()]: "44'/1'/0'/0/"
[Derivation.legacy.valueOf()]: "44'/60'/0'",
[Derivation.standard.valueOf()]: "44'/60'/0'/0",
[Derivation.testnet.valueOf()]: "44'/1'/0'/0"
}

export function getDerivationPath (derivation: Derivation) {
Expand Down
4 changes: 2 additions & 2 deletions main/signers/Signer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export default class Signer extends EventEmitter {
type = '';
name = '';
status = '';
coinbase = '0x';
model = '';
appVersion: AppVersion = { major: 0, minor: 0, patch: 0 }

liveAddressesFound = 0;
addresses: string[];

constructor () {
Expand Down Expand Up @@ -48,7 +49,6 @@ export default class Signer extends EventEmitter {
type: this.type,
addresses: this.addresses,
status: this.status,
liveAddressesFound: this.liveAddressesFound || 0,
appVersion: this.appVersion || { major: 0, minor: 0, patch: 0 }
}
}
Expand Down
1 change: 1 addition & 0 deletions main/signers/hot/HotSigner/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class HotSignerWorker {
signTransaction (key, rawTx, pseudoCallback) {
sign(rawTx, tx => {
const signedTx = tx.sign(key)

const serialized = signedTx.serialize().toString('hex')

pseudoCallback(null, addHexPrefix(serialized))
Expand Down
31 changes: 6 additions & 25 deletions main/signers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck

const EventEmitter = require('events')
import EventEmitter from 'events'
import log from 'electron-log'
import crypto from 'crypto'

Expand All @@ -9,13 +9,15 @@ import { SignerAdapter } from './adapters'

import hot from './hot'
import LedgerAdapter from './ledger/adapter'
import trezorConnect from './trezor-connect'
import TrezorAdapter from './trezor/adapter'

import lattice from './lattice'

import store from '../store'

const registeredAdapters = [
new LedgerAdapter()
new LedgerAdapter(),
new TrezorAdapter()
]

interface AdapterSpec {
Expand All @@ -41,8 +43,7 @@ class Signers extends EventEmitter {
// TODO: convert these scans to adapters
this.scans = {
lattice: lattice.scan(this),
hot: hot.scan(this),
trezor: trezorConnect.scan(this)
hot: hot.scan(this)
}

registeredAdapters.forEach(this.addAdapter.bind(this))
Expand Down Expand Up @@ -88,26 +89,6 @@ class Signers extends EventEmitter {
delete this.adapter[adapter.adapterType]
}

trezorPin (id, pin, cb) {
const signer = this.get(id)
if (signer && signer.setPin) {
signer.setPin(pin)
cb(null, { status: 'ok' })
} else {
cb(new Error('Set pin not avaliable...'))
}
}

trezorPhrase (id, phrase, cb) {
const signer = this.get(id)
if (signer && signer.trezorPhrase) {
signer.trezorPhrase(phrase || '')
cb(null, { status: 'ok' })
} else {
cb(new Error('Set phrase not avaliable...'))
}
}

async latticePair (id, pin) {
try {
const signer = this.get(id)
Expand Down
11 changes: 5 additions & 6 deletions main/signers/ledger/Ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,18 @@ function getStatusForError (err: DeviceError) {

export default class Ledger extends Signer {
private eth: LedgerEthereumApp | undefined;
private devicePath: string;

private derivation: Derivation | undefined;
private accountLimit = 5;
devicePath: string;

derivation: Derivation | undefined;
accountLimit = 5;

// the Ledger device can only handle one request at a time; the transport will reject
// all incoming requests while its busy, so we need to make sure requests are only executed
// when the device is ready
private requestQueue = new RequestQueue()
private statusPoller = setTimeout(() => {})

private coinbase = '0x'

constructor (devicePath: string) {
super()

Expand Down Expand Up @@ -269,7 +268,7 @@ export default class Ledger extends Signer {
throw new Error('attempted to get path with unknown derivation!')
}

return getDerivationPath(this.derivation) + index
return getDerivationPath(this.derivation) + '/' + index
}

// *** request enqueuing methods *** //
Expand Down
4 changes: 2 additions & 2 deletions main/signers/ledger/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import log from 'electron-log'
import { getDevices as getLedgerDevices } from '@ledgerhq/hw-transport-node-hid-noevents'

import { UsbSignerAdapter } from '../adapters'
import Ledger, { Status } from './Ledger'
import Ledger from './Ledger'
import store from '../../store'
import { Derivation } from '../Signer/derive'

Expand All @@ -22,7 +22,7 @@ export default class LedgerSignerAdapter extends UsbSignerAdapter {
private observer: any;

constructor () {
super('Ledger')
super('ledger')

this.knownSigners = {}
this.disconnections = []
Expand Down
Loading