Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing committed Mar 2, 2021
1 parent 868c90c commit 8690228
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ const HDKey = require('hdkey')
const ethUtil = require('ethereumjs-util')
const sigUtil = require('eth-sig-util')

const hdPathString = `m/44'/60'/0'`
const pathBase = 'm'
const hdPathString = `${pathBase}/44'/60'/0'`
const type = 'Ledger Hardware'

// TODO: Change this to metamask once gh-pages is published
const BRIDGE_URL = 'https://darkwing.github.io/eth-ledger-bridge-keyring'
const BRIDGE_URL = 'https://metamask.github.io/eth-ledger-bridge-keyring'

const pathBase = 'm'
const MAX_INDEX = 1000
const NETWORK_API_URLS = {
ropsten: 'http://api-ropsten.etherscan.io',
Expand All @@ -20,7 +19,6 @@ const NETWORK_API_URLS = {

class LedgerBridgeKeyring extends EventEmitter {
constructor (opts = {}) {
console.log("[LedgerBridgeKeyring][constructor] Initialize with options: ", opts)
super()
this.accountIndexes = {}
this.bridgeUrl = null
Expand Down Expand Up @@ -57,8 +55,6 @@ class LedgerBridgeKeyring extends EventEmitter {
this.implementFullBIP44 = opts.implementFullBIP44 || false
this.useLedgerLive = opts.useLedgerLive || false

console.log("[LedgerBridgeKeyring] useLedgerLive initialized with: ", opts.useLedgerLive);

if (this._isBIP44()) {
// Remove accounts that don't have corresponding account indexes
this.accounts = this.accounts
Expand All @@ -85,30 +81,22 @@ class LedgerBridgeKeyring extends EventEmitter {
}

unlock (hdPath) {
console.log("[LedgerBridgeKeyring][unlock] Called")
if (this.isUnlocked() && !hdPath) {
console.log("[LedgerBridgeKeyring][unlock] Already unlocked, resolving immediately")
return Promise.resolve('already unlocked')
}
const path = hdPath ? this._toLedgerPath(hdPath) : this.hdPath

return new Promise((resolve, reject) => {
console.log("[LedgerBridgeKeyring][unlock] Sending 'ledger-unlock' with params: ", {
hdPath: path,
})
this._sendMessage({
action: 'ledger-unlock',
params: {
hdPath: path,
},
},
({ success, payload }) => {
console.log("[LedgerBridgeKeyring][unlock] Received 'ledger-unlock' response: ", success, payload)
if (success) {
this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex')
this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex')
console.log("[LedgerBridgeKeyring][unlock][success!] hdkey:", this.hdk)

resolve(payload.address)
} else {
reject(payload.error || 'Unknown error')
Expand All @@ -118,7 +106,6 @@ class LedgerBridgeKeyring extends EventEmitter {
}

addAccounts (n = 1) {
console.log("[LedgerBridgeKeyring][addAccounts] Called!")
return new Promise((resolve, reject) => {
this.unlock()
.then(async (_) => {
Expand All @@ -134,15 +121,12 @@ class LedgerBridgeKeyring extends EventEmitter {
} else {
address = this._addressFromIndex(pathBase, i)
}
console.log("[LedgerBridgeKeyring][addAccounts] Adding account: ", address)
this.accounts.push(address)
this.page = 0
}
console.log("[LedgerBridgeKeyring][addAccounts] Returning accounts: ", this.accounts)
resolve(this.accounts)
})
.catch(e => {
console.log("[LedgerBridgeKeyring][addAccounts] Unlock catch: ", e)
reject(e)
})
})
Expand Down Expand Up @@ -175,7 +159,6 @@ class LedgerBridgeKeyring extends EventEmitter {
}

updateTransportMethod(useLedgerLive = false) {
console.log("[LedgerBridgeKeyring] Sending message to iFrame to update Ledger Live preference to: ", useLedgerLive)
this._sendMessage({ action: 'ledger-update-transport', params: { useLedgerLive } })
}

Expand Down Expand Up @@ -286,7 +269,6 @@ class LedgerBridgeKeyring extends EventEmitter {
}

forgetDevice () {
console.log("[LedgerBridgeKeyring][forgetDevice] Called")
this.accounts = []
this.page = 0
this.unlockedAccount = 0
Expand All @@ -300,7 +282,6 @@ class LedgerBridgeKeyring extends EventEmitter {
_setupIframe () {
this.iframe = document.createElement('iframe')
this.iframe.onload = () => { this.updateTransportMethod(this.useLedgerLive) }
this.iframe.allow = 'usb'
this.iframe.src = this.bridgeUrl
document.head.appendChild(this.iframe)
}
Expand All @@ -312,7 +293,6 @@ class LedgerBridgeKeyring extends EventEmitter {
}

_sendMessage (msg, cb) {
console.log("[LedgerBridgeKeyring][_sendMessage] message / callback is:", msg, cb)
msg.target = 'LEDGER-IFRAME'
this.iframe.contentWindow.postMessage(msg, '*')
const eventListener = ({ origin, data }) => {
Expand Down

0 comments on commit 8690228

Please sign in to comment.