@ledgerhq/hw-transport-node-speculos-http
Advanced tools
Comparing version 6.27.13 to 6.27.14-nightly.0
# @ledgerhq/hw-transport-node-speculos-http | ||
## 6.27.14-nightly.0 | ||
### Patch Changes | ||
- Updated dependencies [[`87d2349fd8`](https://github.com/LedgerHQ/ledger-live/commit/87d2349fd835e5deb39d1ee8dfcf3539f4195472)]: | ||
- @ledgerhq/errors@6.12.5-nightly.0 | ||
- @ledgerhq/hw-transport@6.28.3-nightly.0 | ||
## 6.27.13 | ||
@@ -4,0 +12,0 @@ |
/// <reference types="node" /> | ||
import { AxiosInstance } from "axios"; | ||
import Transport from "@ledgerhq/hw-transport"; | ||
export declare type SpeculosHttpTransportOpts = { | ||
export type SpeculosHttpTransportOpts = { | ||
baseURL?: string; | ||
@@ -6,0 +6,0 @@ timeout?: number; |
@@ -1,16 +0,1 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -25,29 +10,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import axios from "axios"; | ||
@@ -65,6 +23,5 @@ import { DisconnectedDevice } from "@ledgerhq/errors"; | ||
*/ | ||
var SpeculosHttpTransport = /** @class */ (function (_super) { | ||
__extends(SpeculosHttpTransport, _super); | ||
function SpeculosHttpTransport(instance, opts) { | ||
var _this = _super.call(this) || this; | ||
export default class SpeculosHttpTransport extends Transport { | ||
constructor(instance, opts) { | ||
super(); | ||
/** | ||
@@ -75,79 +32,69 @@ * Press and release button | ||
*/ | ||
_this.button = function (but) { | ||
return new Promise(function (resolve, reject) { | ||
var action = { action: "press-and-release" }; | ||
log("speculos-button", "press-and-release", but); | ||
_this.instance | ||
.post("/button/".concat(but), action) | ||
.then(function (response) { | ||
resolve(response.data); | ||
})["catch"](function (e) { | ||
reject(e); | ||
}); | ||
this.button = (but) => new Promise((resolve, reject) => { | ||
const action = { action: "press-and-release" }; | ||
log("speculos-button", "press-and-release", but); | ||
this.instance | ||
.post(`/button/${but}`, action) | ||
.then((response) => { | ||
resolve(response.data); | ||
}) | ||
.catch((e) => { | ||
reject(e); | ||
}); | ||
}; | ||
_this.instance = instance; | ||
_this.opts = opts; | ||
return _this; | ||
}); | ||
this.instance = instance; | ||
this.opts = opts; | ||
} | ||
SpeculosHttpTransport.prototype.exchange = function (apdu) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hex; | ||
return __generator(this, function (_a) { | ||
hex = apdu.toString("hex"); | ||
log("apdu", "=> " + hex); | ||
return [2 /*return*/, this.instance.post("/apdu", { data: hex }).then(function (r) { | ||
// r.data is {"data": "hex value of response"} | ||
var data = r.data.data; | ||
log("apdu", "<= " + data); | ||
return Buffer.from(data, "hex"); | ||
})]; | ||
exchange(apdu) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const hex = apdu.toString("hex"); | ||
log("apdu", "=> " + hex); | ||
return this.instance.post("/apdu", { data: hex }).then((r) => { | ||
// r.data is {"data": "hex value of response"} | ||
const data = r.data.data; | ||
log("apdu", "<= " + data); | ||
return Buffer.from(data, "hex"); | ||
}); | ||
}); | ||
}; | ||
SpeculosHttpTransport.prototype.close = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
// close event stream | ||
this.eventStream.destroy(); | ||
return [2 /*return*/, Promise.resolve()]; | ||
}); | ||
} | ||
close() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// close event stream | ||
this.eventStream.destroy(); | ||
return Promise.resolve(); | ||
}); | ||
}; | ||
SpeculosHttpTransport.isSupported = function () { return Promise.resolve(true); }; | ||
// this transport is not discoverable | ||
SpeculosHttpTransport.list = function () { return Promise.resolve([]); }; | ||
SpeculosHttpTransport.listen = function (_observer) { return ({ | ||
unsubscribe: function () { } | ||
}); }; | ||
SpeculosHttpTransport.open = function (opts) { | ||
return new Promise(function (resolve, reject) { | ||
var instance = axios.create(opts); | ||
instance.defaults.baseURL = "http://localhost:5000"; | ||
var transport = new SpeculosHttpTransport(instance, opts); | ||
instance({ | ||
url: "/events?stream=true", | ||
responseType: "stream" | ||
}) | ||
.then(function (response) { | ||
response.data.on("data", function (chunk) { | ||
log("speculos-event", chunk.toString()); | ||
// XXX: we could process display events here | ||
// client side automation or UI tests/checks | ||
}); | ||
response.data.on("close", function () { | ||
log("speculos-event", "close"); | ||
transport.emit("disconnect", new DisconnectedDevice("Speculos exited!")); | ||
}); | ||
transport.eventStream = response.data; | ||
// we are connected to speculos | ||
resolve(transport); | ||
})["catch"](function (error) { | ||
reject(error); | ||
}); | ||
} | ||
} | ||
SpeculosHttpTransport.isSupported = () => Promise.resolve(true); | ||
// this transport is not discoverable | ||
SpeculosHttpTransport.list = () => Promise.resolve([]); | ||
SpeculosHttpTransport.listen = (_observer) => ({ | ||
unsubscribe: () => { }, | ||
}); | ||
SpeculosHttpTransport.open = (opts) => new Promise((resolve, reject) => { | ||
const instance = axios.create(opts); | ||
instance.defaults.baseURL = "http://localhost:5000"; | ||
const transport = new SpeculosHttpTransport(instance, opts); | ||
instance({ | ||
url: "/events?stream=true", | ||
responseType: "stream", | ||
}) | ||
.then((response) => { | ||
response.data.on("data", (chunk) => { | ||
log("speculos-event", chunk.toString()); | ||
// XXX: we could process display events here | ||
// client side automation or UI tests/checks | ||
}); | ||
}; | ||
return SpeculosHttpTransport; | ||
}(Transport)); | ||
export default SpeculosHttpTransport; | ||
response.data.on("close", () => { | ||
log("speculos-event", "close"); | ||
transport.emit("disconnect", new DisconnectedDevice("Speculos exited!")); | ||
}); | ||
transport.eventStream = response.data; | ||
// we are connected to speculos | ||
resolve(transport); | ||
}) | ||
.catch((error) => { | ||
reject(error); | ||
}); | ||
}); | ||
//# sourceMappingURL=SpeculosHttpTransport.js.map |
/// <reference types="node" /> | ||
import { AxiosInstance } from "axios"; | ||
import Transport from "@ledgerhq/hw-transport"; | ||
export declare type SpeculosHttpTransportOpts = { | ||
export type SpeculosHttpTransportOpts = { | ||
baseURL?: string; | ||
@@ -6,0 +6,0 @@ timeout?: number; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -26,37 +11,10 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var axios_1 = __importDefault(require("axios")); | ||
var errors_1 = require("@ledgerhq/errors"); | ||
var hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport")); | ||
var logs_1 = require("@ledgerhq/logs"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const axios_1 = __importDefault(require("axios")); | ||
const errors_1 = require("@ledgerhq/errors"); | ||
const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport")); | ||
const logs_1 = require("@ledgerhq/logs"); | ||
/** | ||
@@ -70,6 +28,5 @@ * Speculos TCP transport implementation | ||
*/ | ||
var SpeculosHttpTransport = /** @class */ (function (_super) { | ||
__extends(SpeculosHttpTransport, _super); | ||
function SpeculosHttpTransport(instance, opts) { | ||
var _this = _super.call(this) || this; | ||
class SpeculosHttpTransport extends hw_transport_1.default { | ||
constructor(instance, opts) { | ||
super(); | ||
/** | ||
@@ -80,79 +37,70 @@ * Press and release button | ||
*/ | ||
_this.button = function (but) { | ||
return new Promise(function (resolve, reject) { | ||
var action = { action: "press-and-release" }; | ||
(0, logs_1.log)("speculos-button", "press-and-release", but); | ||
_this.instance | ||
.post("/button/".concat(but), action) | ||
.then(function (response) { | ||
resolve(response.data); | ||
})["catch"](function (e) { | ||
reject(e); | ||
}); | ||
this.button = (but) => new Promise((resolve, reject) => { | ||
const action = { action: "press-and-release" }; | ||
(0, logs_1.log)("speculos-button", "press-and-release", but); | ||
this.instance | ||
.post(`/button/${but}`, action) | ||
.then((response) => { | ||
resolve(response.data); | ||
}) | ||
.catch((e) => { | ||
reject(e); | ||
}); | ||
}; | ||
_this.instance = instance; | ||
_this.opts = opts; | ||
return _this; | ||
}); | ||
this.instance = instance; | ||
this.opts = opts; | ||
} | ||
SpeculosHttpTransport.prototype.exchange = function (apdu) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hex; | ||
return __generator(this, function (_a) { | ||
hex = apdu.toString("hex"); | ||
(0, logs_1.log)("apdu", "=> " + hex); | ||
return [2 /*return*/, this.instance.post("/apdu", { data: hex }).then(function (r) { | ||
// r.data is {"data": "hex value of response"} | ||
var data = r.data.data; | ||
(0, logs_1.log)("apdu", "<= " + data); | ||
return Buffer.from(data, "hex"); | ||
})]; | ||
exchange(apdu) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const hex = apdu.toString("hex"); | ||
(0, logs_1.log)("apdu", "=> " + hex); | ||
return this.instance.post("/apdu", { data: hex }).then((r) => { | ||
// r.data is {"data": "hex value of response"} | ||
const data = r.data.data; | ||
(0, logs_1.log)("apdu", "<= " + data); | ||
return Buffer.from(data, "hex"); | ||
}); | ||
}); | ||
}; | ||
SpeculosHttpTransport.prototype.close = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
// close event stream | ||
this.eventStream.destroy(); | ||
return [2 /*return*/, Promise.resolve()]; | ||
}); | ||
} | ||
close() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// close event stream | ||
this.eventStream.destroy(); | ||
return Promise.resolve(); | ||
}); | ||
}; | ||
SpeculosHttpTransport.isSupported = function () { return Promise.resolve(true); }; | ||
// this transport is not discoverable | ||
SpeculosHttpTransport.list = function () { return Promise.resolve([]); }; | ||
SpeculosHttpTransport.listen = function (_observer) { return ({ | ||
unsubscribe: function () { } | ||
}); }; | ||
SpeculosHttpTransport.open = function (opts) { | ||
return new Promise(function (resolve, reject) { | ||
var instance = axios_1["default"].create(opts); | ||
instance.defaults.baseURL = "http://localhost:5000"; | ||
var transport = new SpeculosHttpTransport(instance, opts); | ||
instance({ | ||
url: "/events?stream=true", | ||
responseType: "stream" | ||
}) | ||
.then(function (response) { | ||
response.data.on("data", function (chunk) { | ||
(0, logs_1.log)("speculos-event", chunk.toString()); | ||
// XXX: we could process display events here | ||
// client side automation or UI tests/checks | ||
}); | ||
response.data.on("close", function () { | ||
(0, logs_1.log)("speculos-event", "close"); | ||
transport.emit("disconnect", new errors_1.DisconnectedDevice("Speculos exited!")); | ||
}); | ||
transport.eventStream = response.data; | ||
// we are connected to speculos | ||
resolve(transport); | ||
})["catch"](function (error) { | ||
reject(error); | ||
}); | ||
} | ||
} | ||
exports.default = SpeculosHttpTransport; | ||
SpeculosHttpTransport.isSupported = () => Promise.resolve(true); | ||
// this transport is not discoverable | ||
SpeculosHttpTransport.list = () => Promise.resolve([]); | ||
SpeculosHttpTransport.listen = (_observer) => ({ | ||
unsubscribe: () => { }, | ||
}); | ||
SpeculosHttpTransport.open = (opts) => new Promise((resolve, reject) => { | ||
const instance = axios_1.default.create(opts); | ||
instance.defaults.baseURL = "http://localhost:5000"; | ||
const transport = new SpeculosHttpTransport(instance, opts); | ||
instance({ | ||
url: "/events?stream=true", | ||
responseType: "stream", | ||
}) | ||
.then((response) => { | ||
response.data.on("data", (chunk) => { | ||
(0, logs_1.log)("speculos-event", chunk.toString()); | ||
// XXX: we could process display events here | ||
// client side automation or UI tests/checks | ||
}); | ||
}; | ||
return SpeculosHttpTransport; | ||
}(hw_transport_1["default"])); | ||
exports["default"] = SpeculosHttpTransport; | ||
response.data.on("close", () => { | ||
(0, logs_1.log)("speculos-event", "close"); | ||
transport.emit("disconnect", new errors_1.DisconnectedDevice("Speculos exited!")); | ||
}); | ||
transport.eventStream = response.data; | ||
// we are connected to speculos | ||
resolve(transport); | ||
}) | ||
.catch((error) => { | ||
reject(error); | ||
}); | ||
}); | ||
//# sourceMappingURL=SpeculosHttpTransport.js.map |
{ | ||
"name": "@ledgerhq/hw-transport-node-speculos-http", | ||
"version": "6.27.13", | ||
"version": "6.27.14-nightly.0", | ||
"description": "Ledger Hardware Wallet communication layer with speculos Nano simulator using the http api", | ||
@@ -32,4 +32,4 @@ "keywords": [ | ||
"axios": "^0.26.1", | ||
"@ledgerhq/errors": "^6.12.4", | ||
"@ledgerhq/hw-transport": "^6.28.2", | ||
"@ledgerhq/errors": "^6.12.5-nightly.0", | ||
"@ledgerhq/hw-transport": "^6.28.3-nightly.0", | ||
"@ledgerhq/logs": "^6.10.1" | ||
@@ -43,7 +43,6 @@ }, | ||
"jest": "^28.1.1", | ||
"rimraf": "^4.1.2", | ||
"rimraf": "^4.4.1", | ||
"source-map-support": "^0.5.21", | ||
"ts-jest": "^28.0.5", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4" | ||
"ts-node": "^10.4.0" | ||
}, | ||
@@ -50,0 +49,0 @@ "scripts": { |
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
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
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
8
46
32703
378
1