Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
disconnect: id =>
id.startsWith("httpdebug|")
? Promise.resolve() // nothing to do
: null,
};
if (__DEV__ && Config.DEVICE_PROXY_URL) {
DebugHttpProxy = withStaticURLs(Config.DEVICE_PROXY_URL.split("|"));
httpdebug.discovery = Observable.create(o => DebugHttpProxy.listen(o)).pipe(
map(({ type, descriptor }) => ({
type,
id: `httpdebug|${descriptor}`,
name: descriptor,
})),
);
} else {
DebugHttpProxy = withStaticURLs([]);
}
registerTransportModule(httpdebug);
// BLE is always the fallback choice because we always keep raw id in it
registerTransportModule({
id: "ble",
open: id => BluetoothTransport.open(id),
disconnect: id => BluetoothTransport.disconnect(id),
});
});
// Add dev mode support of an http proxy
let DebugHttpProxy;
const httpdebug: TransportModule = {
id: "httpdebug",
open: id =>
id.startsWith("httpdebug|") ? DebugHttpProxy.open(id.slice(10)) : null,
disconnect: id =>
id.startsWith("httpdebug|")
? Promise.resolve() // nothing to do
: null,
};
if (__DEV__ && Config.DEVICE_PROXY_URL) {
DebugHttpProxy = withStaticURLs(Config.DEVICE_PROXY_URL.split("|"));
httpdebug.discovery = Observable.create(o => DebugHttpProxy.listen(o)).pipe(
map(({ type, descriptor }) => ({
type,
id: `httpdebug|${descriptor}`,
name: descriptor,
})),
);
} else {
DebugHttpProxy = withStaticURLs([]);
}
registerTransportModule(httpdebug);
// BLE is always the fallback choice because we always keep raw id in it
registerTransportModule({
id: "ble",
})),
);
openHandlers.push(id => {
if (id.startsWith("usb|")) {
const json = JSON.parse(id.slice(4));
// $FlowFixMe: we should have concept of id in HIDTransport
return HIDTransport.open(json);
}
return null;
});
observables.push(hidObservable);
// Add dev mode support of an http proxy
let DebugHttpProxy;
if (__DEV__ && Config.DEBUG_COMM_HTTP_PROXY) {
DebugHttpProxy = withStaticURLs(Config.DEBUG_COMM_HTTP_PROXY.split("|"));
const debugHttpObservable = Observable.create(o =>
DebugHttpProxy.listen(o),
).pipe(
map(({ type, descriptor }) => ({
type,
id: `httpdebug|${descriptor}`,
name: descriptor,
})),
);
observables.push(debugHttpObservable);
} else {
DebugHttpProxy = withStaticURLs([]);
}
openHandlers.push(id => {
if (id.startsWith("httpdebug|")) {
// Add dev mode support of an http proxy
let DebugHttpProxy;
if (__DEV__ && Config.DEBUG_COMM_HTTP_PROXY) {
DebugHttpProxy = withStaticURLs(Config.DEBUG_COMM_HTTP_PROXY.split("|"));
const debugHttpObservable = Observable.create(o =>
DebugHttpProxy.listen(o),
).pipe(
map(({ type, descriptor }) => ({
type,
id: `httpdebug|${descriptor}`,
name: descriptor,
})),
);
observables.push(debugHttpObservable);
} else {
DebugHttpProxy = withStaticURLs([]);
}
openHandlers.push(id => {
if (id.startsWith("httpdebug|")) {
// $FlowFixMe wtf
return DebugHttpProxy.open(id.slice(10));
}
return null;
});
export const devicesObservable: Observable<{
type: string,
id: string,
name: string,
}> = merge(
...observables.map(o =>
implementCountervalues({
storeSelector: state => state.countervalues,
pairsSelector: () => [],
setExchangePairsAction: () => {},
})
setErrorRemapping(e => {
// NB ideally we should solve it in ledgerjs
if (e && e.message && e.message.indexOf('HID') >= 0) {
return throwError(new DisconnectedDevice(e.message))
}
return throwError(e)
})
if (getEnv('DEVICE_PROXY_URL')) {
const Tr = TransportHttp(getEnv('DEVICE_PROXY_URL').split('|'))
registerTransportModule({
id: 'proxy',
open: () => retry(() => Tr.create(3000, 5000)),
disconnect: () => Promise.resolve(),
})
} else {
registerTransportModule({
id: 'hid',
open: devicePath =>
retry(
() =>
getEnv('EXPERIMENTAL_USB')
? TransportNodeHidSingleton.open()
: TransportNodeHid.open(devicePath),
{ maxRetry: 4 },
checkLibs({
NotEnoughBalance,
React,
log,
Transport,
connect
});
import implementLibcore from "@ledgerhq/live-common/lib/libcore/platforms/nodejs";
implementLibcore({
lib: () => require("@ledgerhq/ledger-core"), // eslint-disable-line global-require
dbPath: process.env.LIBCORE_DB_PATH || "./dbdata"
});
if (process.env.DEVICE_PROXY_URL) {
const Tr = createTransportHttp(process.env.DEVICE_PROXY_URL.split("|"));
registerTransportModule({
id: "http",
open: () =>
retry(() => Tr.create(3000, 5000), { context: "open-http-proxy" }),
disconnect: () => Promise.resolve()
});
}
const cacheBle = {};
if (!process.env.CI) {
const {
default: TransportNodeBle
} = require("@ledgerhq/hw-transport-node-ble");
const openBleByQuery = async query => {
const m = query.match(/^ble:?(.*)/);
import { Observable } from "rxjs/Observable";
import { PromiseObservable } from "rxjs/observable/PromiseObservable";
import "rxjs/add/observable/merge";
import "rxjs/add/observable/empty";
import "rxjs/add/operator/first";
import "rxjs/add/operator/map";
import "rxjs/add/operator/catch";
import "rxjs/add/operator/concatMap";
import HIDTransport from "@ledgerhq/react-native-hid";
import BluetoothTransport from "@ledgerhq/react-native-hw-transport-ble";
import { withStaticURL } from "@ledgerhq/hw-transport-http";
import Config from "react-native-config";
const transports: Array<*> = [HIDTransport, BluetoothTransport];
if (__DEV__) {
transports.push(withStaticURL(Config.DEBUG_COMM_HTTP_PROXY));
}
export default () =>
Observable.merge(
...transports.map(t =>
Observable.create(o => t.listen(o))
.map(({ descriptor }) => ({ descriptor, t }))
.catch(e => {
console.warn(`discover failed for ${t.name}: ${e}`);
return Observable.empty();
})
)
)
.first()
.concatMap(({ descriptor, t }) =>
PromiseObservable.create(t.open(descriptor))