Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@metamask/eth-ledger-bridge-keyring

Package Overview
Dependencies
Maintainers
6
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/eth-ledger-bridge-keyring - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

81

index.js

@@ -6,6 +6,8 @@ const { EventEmitter } = require('events')

const hdPathString = `m/44'/60'/0'`
const pathBase = 'm'
const hdPathString = `${pathBase}/44'/60'/0'`
const type = 'Ledger Hardware'
const BRIDGE_URL = 'https://metamask.github.io/eth-ledger-bridge-keyring'
const pathBase = 'm'
const MAX_INDEX = 1000

@@ -34,2 +36,4 @@ const NETWORK_API_URLS = {

this.deserialize(opts)
this.iframeLoaded = false
this._setupIframe()

@@ -67,3 +71,3 @@ }

_migrateAccountDetails (opts) {
if (this._isBIP44() && opts.accountIndexes) {
if (this._isLedgerLiveHdPath() && opts.accountIndexes) {
for (const account of Object.keys(opts.accountIndexes)) {

@@ -77,4 +81,4 @@ this.accountDetails[account] = {

// try to migrate non-bip44 accounts too
if (!this._isBIP44()) {
// try to migrate non-LedgerLive accounts too
if (!this._isLedgerLiveHdPath()) {
this.accounts

@@ -145,3 +149,3 @@ .filter((account) => !Object.keys(this.accountDetails).includes(ethUtil.toChecksumAddress(account)))

let address
if (this._isBIP44()) {
if (this._isLedgerLiveHdPath()) {
address = await this.unlock(path)

@@ -152,3 +156,5 @@ } else {

this.accountDetails[ethUtil.toChecksumAddress(address)] = {
bip44: this._isBIP44(),
// TODO: consider renaming this property, as the current name is misleading
// It's currently used to represent whether an account uses the Ledger Live path.
bip44: this._isLedgerLiveHdPath(),
hdPath: path,

@@ -164,5 +170,3 @@ }

})
.catch((e) => {
reject(e)
})
.catch(reject)
})

@@ -196,2 +200,28 @@ }

updateTransportMethod (useLedgerLive = false) {
return new Promise((resolve, reject) => {
// If the iframe isn't loaded yet, let's store the desired useLedgerLive value and
// optimistically return a successful promise
if (!this.iframeLoaded) {
this.delayedPromise = {
resolve,
reject,
useLedgerLive,
}
return
}
this._sendMessage({
action: 'ledger-update-transport',
params: { useLedgerLive },
}, ({ success }) => {
if (success) {
resolve(true)
} else {
reject(new Error('Ledger transport could not be updated'))
}
})
})
}
// tx is an instance of the ethereumjs-transaction class.

@@ -312,2 +342,19 @@ signTransaction (address, tx) {

this.iframe.src = this.bridgeUrl
this.iframe.onload = async () => {
// If the ledger live preference was set before the iframe is loaded,
// set it after the iframe has loaded
this.iframeLoaded = true
if (this.delayedPromise) {
try {
const result = await this.updateTransportMethod(
this.delayedPromise.useLedgerLive,
)
this.delayedPromise.resolve(result)
} catch (e) {
this.delayedPromise.reject(e)
} finally {
delete this.delayedPromise
}
}
}
document.head.appendChild(this.iframe)

@@ -329,6 +376,8 @@ }

}
if (data && data.action && data.action === `${msg.action}-reply`) {
if (data && data.action && data.action === `${msg.action}-reply` && cb) {
cb(data)
return undefined
}
window.removeEventListener('message', eventListener)

@@ -352,3 +401,3 @@ return undefined

let accounts
if (this._isBIP44()) {
if (this._isLedgerLiveHdPath()) {
accounts = await this._getAccountsBIP44(from, to)

@@ -413,3 +462,3 @@ } else {

.toString('hex')
return ethUtil.toChecksumAddress(address)
return ethUtil.toChecksumAddress(`0x${address}`)
}

@@ -452,6 +501,6 @@

// Check if the path is BIP 44 (Ledger Live)
return this._isBIP44() ? `m/44'/60'/${index}'/0/0` : `${this.hdPath}/${index}`
return this._isLedgerLiveHdPath() ? `m/44'/60'/${index}'/0/0` : `${this.hdPath}/${index}`
}
_isBIP44 () {
_isLedgerLiveHdPath () {
return this.hdPath === `m/44'/60'/0'/0/0`

@@ -475,3 +524,3 @@ }

_getApiUrl () {
return NETWORK_API_URLS[this.network] ? NETWORK_API_URLS[this.network] : NETWORK_API_URLS.mainnet
return NETWORK_API_URLS[this.network] || NETWORK_API_URLS.mainnet
}

@@ -478,0 +527,0 @@

7

package.json
{
"name": "@metamask/eth-ledger-bridge-keyring",
"version": "0.3.0",
"version": "0.4.0",
"description": "A MetaMask compatible keyring, for ledger hardware wallets",

@@ -9,2 +9,5 @@ "main": "index.js",

],
"engines": {
"node": ">=12.0.0"
},
"scripts": {

@@ -41,3 +44,3 @@ "test": "mocha",

"ethereumjs-tx": "^1.3.4",
"ethereumjs-util": "^5.1.5",
"ethereumjs-util": "^7.0.9",
"events": "^2.0.0",

@@ -44,0 +47,0 @@ "hdkey": "0.8.0"

@@ -48,5 +48,5 @@ eth-ledger-bridge-keyring [![CircleCI](https://circleci.com/gh/MetaMask/eth-ledger-bridge-keyring.svg?style=svg)](https://circleci.com/gh/MetaMask/eth-ledger-bridge-keyring)

```bash
yarn test
```
npm test
```

@@ -53,0 +53,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc