@ledgerhq/hw-transport-webusb
Advanced tools
Comparing version 4.35.0 to 4.35.1-beta.28
@@ -13,8 +13,10 @@ "use strict"; | ||
var _webusb = require("./webusb"); | ||
var _hidFraming = require("@ledgerhq/devices/lib/hid-framing"); | ||
var _hidFraming = require("./hid-framing"); | ||
var _hidFraming2 = _interopRequireDefault(_hidFraming); | ||
var _devices = require("@ledgerhq/devices"); | ||
var _webusb = require("./webusb"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -65,13 +67,17 @@ | ||
_context.next = 2; | ||
return this.device.releaseInterface(interfaceNumber); | ||
return this.exchangeBusyPromise; | ||
case 2: | ||
_context.next = 4; | ||
return this.device.reset(); | ||
return this.device.releaseInterface(interfaceNumber); | ||
case 4: | ||
_context.next = 6; | ||
return this.device.reset(); | ||
case 6: | ||
_context.next = 8; | ||
return this.device.close(); | ||
case 6: | ||
case 8: | ||
case "end": | ||
@@ -93,5 +99,2 @@ return _context.stop(); | ||
value: function setScrambleKey() {} | ||
// $FlowFixMe | ||
}], [{ | ||
@@ -154,3 +157,4 @@ key: "open", | ||
if (!unsubscribed) { | ||
observer.next({ type: "add", descriptor: device, device: device }); | ||
var deviceModel = (0, _devices.identifyUSBProductId)(device.productId); | ||
observer.next({ type: "add", descriptor: device, deviceModel: deviceModel }); | ||
observer.complete(); | ||
@@ -172,3 +176,3 @@ } | ||
this.exchange = function (apdu) { | ||
return _this2.atomic(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { | ||
return _this2.exchangeAtomicImpl(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { | ||
var debug, channel, packetSize, framing, blocks, i, result, acc, r; | ||
@@ -243,51 +247,2 @@ return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
}; | ||
this.atomic = function () { | ||
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(f) { | ||
var resolveBusy, busyPromise, res; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
if (!_this2.busy) { | ||
_context4.next = 2; | ||
break; | ||
} | ||
throw new _hwTransport.TransportError("Transport race condition", "RaceCondition"); | ||
case 2: | ||
resolveBusy = void 0; | ||
busyPromise = new Promise(function (r) { | ||
resolveBusy = r; | ||
}); | ||
_this2.busy = busyPromise; | ||
_context4.prev = 5; | ||
_context4.next = 8; | ||
return f(); | ||
case 8: | ||
res = _context4.sent; | ||
return _context4.abrupt("return", res); | ||
case 10: | ||
_context4.prev = 10; | ||
if (resolveBusy) resolveBusy(); | ||
_this2.busy = null; | ||
return _context4.finish(10); | ||
case 14: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, _this2, [[5,, 10, 14]]); | ||
})); | ||
return function (_x2) { | ||
return _ref4.apply(this, arguments); | ||
}; | ||
}(); | ||
}; | ||
@@ -294,0 +249,0 @@ |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.getLedgerDevices = exports.isSupported = undefined; | ||
@@ -11,10 +12,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.requestLedgerDevice = requestLedgerDevice; | ||
var ledgerDevices = [{ vendorId: 0x2581, productId: 0x3b7c }, { vendorId: 0x2c97 }]; | ||
var isLedgerDevice = function isLedgerDevice(device) { | ||
return ledgerDevices.some(function (info) { | ||
return (!info.productId || info.productId === device.productId) && (!info.vendorId || info.vendorId === device.vendorId); | ||
}); | ||
}; | ||
var _devices = require("@ledgerhq/devices"); | ||
var ledgerDevices = [{ vendorId: _devices.ledgerUSBVendorId }]; | ||
function requestLedgerDevice() { | ||
@@ -42,5 +40,7 @@ return Promise.resolve().then(function () { | ||
}).then(function (devices) { | ||
return devices.filter(isLedgerDevice); | ||
return devices.filter(function (d) { | ||
return d.vendorId === _devices.ledgerUSBVendorId; | ||
}); | ||
}); | ||
}; | ||
//# sourceMappingURL=webusb.js.map |
{ | ||
"name": "@ledgerhq/hw-transport-webusb", | ||
"version": "4.35.0", | ||
"version": "4.35.1-beta.28+0f83986", | ||
"description": "Ledger Hardware Wallet WebUSB implementation of the communication layer", | ||
@@ -27,6 +27,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^4.35.0" | ||
"@ledgerhq/devices": "^4.35.1-beta.28+0f83986", | ||
"@ledgerhq/errors": "^4.35.1-beta.28+0f83986", | ||
"@ledgerhq/hw-transport": "^4.35.1-beta.28+0f83986" | ||
}, | ||
"devDependencies": { | ||
"flow-bin": "^0.66.0", | ||
"flow-bin": "^0.92.1", | ||
"flow-typed": "^2.3.0" | ||
@@ -36,6 +38,8 @@ }, | ||
"flow": "flow", | ||
"clean": "rm -rf lib/", | ||
"build": "cd ../.. && export PATH=$(yarn bin):$PATH && cd - && babel --source-maps -d lib src && flow-copy-source -v src lib", | ||
"watch": "cd ../.. && export PATH=$(yarn bin):$PATH && cd - && babel --watch --source-maps -d lib src & flow-copy-source -w -v src lib" | ||
} | ||
"clean": "bash ../../script/clean.sh", | ||
"build": "bash ../../script/build.sh", | ||
"watch": "bash ../../script/watch.sh", | ||
"doc": "bash ../../script/doc.sh" | ||
}, | ||
"gitHead": "0f839862fcbb7b74581b74162c1534c9897463cf" | ||
} |
<img src="https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png" height="100" /> | ||
[Github](https://github.com/LedgerHQ/ledgerjs/), | ||
[API Doc](http://ledgerhq.github.io/ledgerjs/), | ||
[Ledger Devs Slack](https://ledger-dev.slack.com/) | ||
## @ledgerhq/hw-transport-webusb | ||
Library for Ledger Hardware Wallets. | ||
Allows to communicate with Ledger Hardware Wallets. | ||
[Github](https://github.com/LedgerHQ/ledgerjs/), | ||
[API Doc](http://ledgerhq.github.io/ledgerjs/), | ||
[Ledger Devs Slack](https://ledger-dev.slack.com/) | ||
**[Web]** **(WebUSB)** – WebUSB [check browser support](https://caniuse.com/webusb). | ||
## API | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
#### Table of Contents | ||
- [TransportWebUSB](#transportwebusb) | ||
- [Parameters](#parameters) | ||
- [Examples](#examples) | ||
### TransportWebUSB | ||
**Extends Transport** | ||
WebUSB Transport implementation | ||
#### Parameters | ||
- `device` **USBDevice** | ||
#### Examples | ||
```javascript | ||
import TransportWebUSB from "@ledgerhq/hw-transport-webusb"; | ||
... | ||
TransportWebUSB.create().then(transport => ...) | ||
``` |
//@flow | ||
import Transport, { TransportError } from "@ledgerhq/hw-transport"; | ||
import Transport from "@ledgerhq/hw-transport"; | ||
import type { | ||
@@ -8,4 +8,5 @@ Observer, | ||
} from "@ledgerhq/hw-transport"; | ||
import hidFraming from "@ledgerhq/devices/lib/hid-framing"; | ||
import { identifyUSBProductId } from "@ledgerhq/devices"; | ||
import { getLedgerDevices, requestLedgerDevice, isSupported } from "./webusb"; | ||
import hidFraming from "./hid-framing"; | ||
@@ -43,3 +44,4 @@ const configurationValue = 1; | ||
if (!unsubscribed) { | ||
observer.next({ type: "add", descriptor: device, device }); | ||
const deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ type: "add", descriptor: device, deviceModel }); | ||
observer.complete(); | ||
@@ -65,2 +67,3 @@ } | ||
async close(): Promise<void> { | ||
await this.exchangeBusyPromise; | ||
await this.device.releaseInterface(interfaceNumber); | ||
@@ -72,3 +75,3 @@ await this.device.reset(); | ||
exchange = (apdu: Buffer): Promise<Buffer> => | ||
this.atomic(async () => { | ||
this.exchangeAtomicImpl(async () => { | ||
const { debug, channel, packetSize } = this; | ||
@@ -102,23 +105,2 @@ if (debug) { | ||
setScrambleKey() {} | ||
busy: ?Promise<void>; | ||
// $FlowFixMe | ||
atomic = async f => { | ||
if (this.busy) { | ||
throw new TransportError("Transport race condition", "RaceCondition"); | ||
} | ||
let resolveBusy; | ||
const busyPromise = new Promise(r => { | ||
resolveBusy = r; | ||
}); | ||
this.busy = busyPromise; | ||
try { | ||
const res = await f(); | ||
return res; | ||
} finally { | ||
if (resolveBusy) resolveBusy(); | ||
this.busy = null; | ||
} | ||
}; | ||
} |
// @flow | ||
import { ledgerUSBVendorId } from "@ledgerhq/devices"; | ||
const ledgerDevices = [ | ||
{ vendorId: 0x2581, productId: 0x3b7c }, | ||
{ vendorId: 0x2c97 } | ||
]; | ||
const ledgerDevices = [{ vendorId: ledgerUSBVendorId }]; | ||
const isLedgerDevice = device => | ||
ledgerDevices.some( | ||
info => | ||
(!info.productId || info.productId === device.productId) && | ||
(!info.vendorId || info.vendorId === device.vendorId) | ||
); | ||
export function requestLedgerDevice(): Promise<USBDevice> { | ||
@@ -35,2 +26,2 @@ return Promise.resolve().then(() => | ||
) | ||
.then(devices => devices.filter(isLedgerDevice)); | ||
.then(devices => devices.filter(d => d.vendorId === ledgerUSBVendorId)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40
41509
3
13
470
1
1