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

Add support for WebHID transport for Ledger #1007

Merged
merged 2 commits into from
May 31, 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
23 changes: 16 additions & 7 deletions app/frontend/wallet/shelley/shelley-ledger-crypto-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LedgerTransportU2F from '@ledgerhq/hw-transport-u2f'
import LedgerTransportWebusb from '@ledgerhq/hw-transport-webusb'
import LedgerTransportWebUsb from '@ledgerhq/hw-transport-webusb'
import LedgerTransportWebHid from '@ledgerhq/hw-transport-webhid'
import Ledger, * as LedgerTypes from '@cardano-foundation/ledgerjs-hw-app-cardano'
import * as cbor from 'borc'
import CachedDeriveXpubFactory from '../helpers/CachedDeriveXpubFactory'
Expand Down Expand Up @@ -63,21 +64,29 @@ import {
import {TxRelayType, TxStakepoolOwner, TxStakepoolRelay} from './helpers/poolCertificateUtils'
import assertUnreachable from '../../helpers/assertUnreachable'

const isWebUsbSupported = async () => {
const isSupported = await LedgerTransportWebusb.isSupported()
const isWebUsbSupported = async (): Promise<boolean> => {
const isSupported = await LedgerTransportWebUsb.isSupported()
return isSupported && platform.os.family !== 'Windows' && platform.name !== 'Opera'
}

const isWebHidSupported = async (): Promise<boolean> => {
return await LedgerTransportWebHid.isSupported()
}

const getLedgerTransport = async (forceWebUsb: boolean): Promise<any> => {
if (forceWebUsb) {
return await LedgerTransportWebusb.create()
return await LedgerTransportWebUsb.create()
}

let transport
try {
const support = await isWebUsbSupported()
if (support) {
transport = await LedgerTransportWebusb.create()
const supportWebHid = await isWebHidSupported()
const supportWebUsb = await isWebUsbSupported()

if (supportWebHid) {
transport = await LedgerTransportWebHid.create()
} else if (supportWebUsb) {
transport = await LedgerTransportWebUsb.create()
} else {
transport = await LedgerTransportU2F.create()
}
Expand Down
5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"scripts": {},
"dependencies": {
"@cardano-foundation/ledgerjs-hw-app-cardano": "3.1.0",
"@ledgerhq/hw-transport": "^5.43.0",
"@ledgerhq/hw-transport": "^5.51.1",
"@ledgerhq/hw-transport-u2f": "^5.36.0-deprecated",
"@ledgerhq/hw-transport-webusb": "^5.43.0",
"@ledgerhq/hw-transport-webhid": "^5.51.1",
"@ledgerhq/hw-transport-webusb": "^5.51.1",
"@sentry/browser": "5.22.3",
"@types/lodash": "^4.14.168",
"bip39-light": "^1.0.7",
Expand Down
92 changes: 57 additions & 35 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@
"@ledgerhq/logs" "^5.36.0"
rxjs "^6.6.3"

"@ledgerhq/devices@^5.43.0":
version "5.43.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-5.43.0.tgz#9b8ca838a7f8ece74098dc84aa6468eb7651972d"
integrity sha512-/M5ZLUBdBK7Vl2T4yNJbES3Z4w55LbPdxD9rcOBAKH/5V3V0obQv6MUasP9b7DSkwGSSLCOGZLohoT2NxK2D2A==
"@ledgerhq/devices@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-5.51.1.tgz#d741a4a5d8f17c2f9d282fd27147e6fe1999edb7"
integrity sha512-4w+P0VkbjzEXC7kv8T1GJ/9AVaP9I6uasMZ/JcdwZBS3qwvKo5A5z9uGhP5c7TvItzcmPb44b5Mw2kT+WjUuAA==
dependencies:
"@ledgerhq/errors" "^5.43.0"
"@ledgerhq/logs" "^5.43.0"
rxjs "^6.6.3"
semver "^7.3.4"
"@ledgerhq/errors" "^5.50.0"
"@ledgerhq/logs" "^5.50.0"
rxjs "6"
semver "^7.3.5"

"@ledgerhq/errors@^5.15.0":
version "5.15.0"
Expand All @@ -142,10 +142,10 @@
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-5.36.0.tgz#9d178b54116ae81b1fbdfa80afcd33981453be4c"
integrity sha512-VS6aFzn3IDUmSLaX2kAPg5sQOc5m7IwvswAGvoMc3FCi9/a1dXWwtiYn5rWd1QjDJlTKSfCwmSpvUMp8FKoY2Q==

"@ledgerhq/errors@^5.43.0":
version "5.43.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-5.43.0.tgz#6bec77ebc31c4333a7f8d13b1f3f4d739b859b75"
integrity sha512-ZjKlUQbIn/DHXAefW3Y1VyDrlVhVqqGnXzrqbOXuDbZ2OAIfSe/A1mrlCbWt98jP/8EJQBuCzBOtnmpXIL/nYg==
"@ledgerhq/errors@^5.50.0":
version "5.50.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-5.50.0.tgz#e3a6834cb8c19346efca214c1af84ed28e69dad9"
integrity sha512-gu6aJ/BHuRlpU7kgVpy2vcYk6atjB4iauP2ymF7Gk0ez0Y/6VSMVSJvubeEQN+IV60+OBK0JgeIZG7OiHaw8ow==

"@ledgerhq/hw-transport-u2f@^5.36.0-deprecated":
version "5.36.0-deprecated"
Expand All @@ -157,15 +157,25 @@
"@ledgerhq/logs" "^5.30.0"
u2f-api "0.2.7"

"@ledgerhq/hw-transport-webusb@^5.43.0":
version "5.43.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-5.43.0.tgz#02fa4a51dd93efae73e2caa1005be9782c381066"
integrity sha512-Mf/qRn8cvK20cqqNtxFfpKVut8BvSvXkq/9HSArV7AUk+a6wga2VEvPlfk8xC551dkJlfln6+nECZ9KIEq9hFw==
"@ledgerhq/hw-transport-webhid@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-webhid/-/hw-transport-webhid-5.51.1.tgz#2050d65ef4ce179e8f43cd7245b811d8f05fdcfc"
integrity sha512-w/2qSU0vwFY+D/4ucuYRViO7iS3Uuxmj9sI/Iiqkoiax9Xppb0/6H5m3ffKv6iPMmRYbgwCgXorqx4SLLSD8Kg==
dependencies:
"@ledgerhq/devices" "^5.51.1"
"@ledgerhq/errors" "^5.50.0"
"@ledgerhq/hw-transport" "^5.51.1"
"@ledgerhq/logs" "^5.50.0"

"@ledgerhq/hw-transport-webusb@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-5.51.1.tgz#664a46dcde36ff78107dea44e32a1647d8e2e93f"
integrity sha512-k35KUlMT8I4X/Zj89sRrIyQ8ApSWSRc/uF/eu6Qv+0cp9mMIty/cfg9v0sBwJ3EA9FHQGY5jJHxJrWPWnZLMOg==
dependencies:
"@ledgerhq/devices" "^5.43.0"
"@ledgerhq/errors" "^5.43.0"
"@ledgerhq/hw-transport" "^5.43.0"
"@ledgerhq/logs" "^5.43.0"
"@ledgerhq/devices" "^5.51.1"
"@ledgerhq/errors" "^5.50.0"
"@ledgerhq/hw-transport" "^5.51.1"
"@ledgerhq/logs" "^5.50.0"

"@ledgerhq/hw-transport@^5.12.0":
version "5.15.0"
Expand All @@ -185,14 +195,14 @@
"@ledgerhq/errors" "^5.36.0"
events "^3.2.0"

"@ledgerhq/hw-transport@^5.43.0":
version "5.43.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-5.43.0.tgz#dc9863706d31bae96aed66f193b8922a876cbf82"
integrity sha512-0S+TGmiEJOqgM2MWnolZQPVKU3oRtoDj4yUFUZts9Owbgby+hmo4dIKTvv0vs8mwknQbOZByUgh3MQOQiK70MQ==
"@ledgerhq/hw-transport@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-5.51.1.tgz#8dd14a8e58cbee4df0c29eaeef983a79f5f22578"
integrity sha512-6wDYdbWrw9VwHIcoDnqWBaDFyviyjZWv6H9vz9Vyhe4Qd7TIFmbTl/eWs6hZvtZBza9K8y7zD8ChHwRI4s9tSw==
dependencies:
"@ledgerhq/devices" "^5.43.0"
"@ledgerhq/errors" "^5.43.0"
events "^3.2.0"
"@ledgerhq/devices" "^5.51.1"
"@ledgerhq/errors" "^5.50.0"
events "^3.3.0"

"@ledgerhq/logs@^5.15.0":
version "5.15.0"
Expand All @@ -204,10 +214,10 @@
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.36.0.tgz#78721347162fb834d90effa1123b363dc46e3a52"
integrity sha512-HnD/hByteUL1MsJu1lMinY9bNq8++5mWJ8qHCW9dLC9LbsvWIqwLwmZiGcW0D2tX9p0/C5ESuIpJ9B/d2dReuw==

"@ledgerhq/logs@^5.43.0":
version "5.43.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.43.0.tgz#031bad4b8a3525c5e14210afde0bc09c79564026"
integrity sha512-QWfQjea3ekh9ZU+JeL2tJC9cTKLZ/JrcS0JGatLejpRYxQajvnHvHfh0dbHOKXEaXfCskEPTZ3f1kzuts742GA==
"@ledgerhq/logs@^5.50.0":
version "5.50.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.50.0.tgz#29c6419e8379d496ab6d0426eadf3c4d100cd186"
integrity sha512-swKHYCOZUGyVt4ge0u8a7AwNcA//h4nx5wIi0sruGye1IJ5Cva0GyK9L2/WdX+kWVTKp92ZiEo1df31lrWGPgA==

"@samverschueren/stream-to-observable@^0.3.0":
version "0.3.1"
Expand Down Expand Up @@ -1103,6 +1113,11 @@ events@^3.2.0:
resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379"
integrity sha512-/46HWwbfCX2xTawVfkKLGxMifJYQBWMwY1mjywRtb4c9x8l5NP3KoJtnIOiL1hfdRkIuYhETxQlo62IF8tcnlg==

events@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==

execa@^4.0.2:
version "4.1.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"
Expand Down Expand Up @@ -2184,6 +2199,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^3.0.0"
inherits "^2.0.1"

rxjs@6:
version "6.6.7"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9"
integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==
dependencies:
tslib "^1.9.0"

rxjs@^6.3.3:
version "6.6.6"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.6.tgz#14d8417aa5a07c5e633995b525e1e3c0dec03b70"
Expand Down Expand Up @@ -2220,10 +2242,10 @@ safer-buffer@^2.0.2, safer-buffer@^2.1.0, safer-buffer@~2.1.0:
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

semver@^7.3.4:
version "7.3.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97"
integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==
semver@^7.3.5:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
dependencies:
lru-cache "^6.0.0"

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"ssri": ">=8.0.1",
"redis": ">=3.1.2",
"hosted-git-info": ">=3.0.8",
"lodash": ">=4.17.21"
"lodash": ">=4.17.21",
"ws": ">=7.4.6"
}
}
15 changes: 4 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,6 @@ async-each@^1.0.1:
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
integrity sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==

async-limiter@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

async-retry@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/async-retry/-/async-retry-1.3.1.tgz#139f31f8ddce50c0870b0ba558a6079684aaed55"
Expand Down Expand Up @@ -7584,12 +7579,10 @@ write@1.0.3:
dependencies:
mkdirp "^0.5.1"

ws@^6.1.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"
integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==
dependencies:
async-limiter "~1.0.0"
ws@>=7.4.6, ws@^6.1.0:
version "7.4.6"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c"
integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==

xdg-basedir@^4.0.0:
version "4.0.0"
Expand Down