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

@onekeyfe/hd-transport-react-native

Package Overview
Dependencies
Maintainers
2
Versions
252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onekeyfe/hd-transport-react-native - npm Package Compare versions

Comparing version 0.1.12 to 0.1.13

58

dist/index.js

@@ -169,2 +169,3 @@ 'use strict';

const transportCache = {};
const Log = hdShared.initLog('@onekey/hd-ble-sdk');
let connectOptions = {

@@ -191,2 +192,3 @@ requestMTU: 512,

this.scanTimeout = (_a = options.scanTimeout) !== null && _a !== void 0 ? _a : 3000;
hdShared.enableLog(true);
}

@@ -217,3 +219,3 @@ init() { }

catch (error) {
console.log('subscribeBleOn error: ', error);
Log.debug('subscribeBleOn error: ', error);
reject(error);

@@ -227,4 +229,4 @@ return;

if (error) {
console.log('ble scan manager: ', blePlxManager);
console.log('ble scan error: ', error);
Log.debug('ble scan manager: ', blePlxManager);
Log.debug('ble scan error: ', error);
if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {

@@ -242,7 +244,7 @@ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));

if (isOnekeyDevice((_b = device === null || device === void 0 ? void 0 : device.name) !== null && _b !== void 0 ? _b : null, device === null || device === void 0 ? void 0 : device.id)) {
console.log('search device start ======================');
Log.debug('search device start ======================');
const { name, localName, id } = device !== null && device !== void 0 ? device : {};
console.log(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}`);
Log.debug(`device name: ${name !== null && name !== void 0 ? name : ''}\nlocalName: ${localName !== null && localName !== void 0 ? localName : ''}\nid: ${id !== null && id !== void 0 ? id : ''}`);
addDevice(device);
console.log('search device end ======================\n');
Log.debug('search device end ======================\n');
}

@@ -252,3 +254,3 @@ });

for (const device of devices) {
console.log('search connected peripheral: ', device.id);
Log.debug('search connected peripheral: ', device.id);
addDevice(device);

@@ -278,3 +280,3 @@ }

if (transportCache[uuid]) {
console.log('@onekey/hd-ble-sdk transport not be released, will release: ', uuid);
Log.debug('transport not be released, will release: ', uuid);
yield this.release(uuid);

@@ -287,3 +289,3 @@ }

catch (error) {
console.log('subscribeBleOn error: ', error);
Log.debug('subscribeBleOn error: ', error);
throw error;

@@ -298,7 +300,7 @@ }

const deviceFilter = connectedDevice.filter(device => device.id === uuid);
console.log(`found connected device count: ${deviceFilter.length}`);
Log.debug(`found connected device count: ${deviceFilter.length}`);
[device] = deviceFilter;
}
if (!device) {
console.log('try to connect to device: ', uuid);
Log.debug('try to connect to device: ', uuid);
try {

@@ -308,3 +310,3 @@ device = yield blePlxManager.connectToDevice(uuid, connectOptions);

catch (e) {
console.log('try to connect to device has error: ', e);
Log.debug('try to connect to device has error: ', e);
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||

@@ -324,3 +326,3 @@ e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {

if (!(yield device.isConnected())) {
console.log('not connected, try to connect to device: ', uuid);
Log.debug('not connected, try to connect to device: ', uuid);
try {

@@ -330,3 +332,3 @@ yield device.connect(connectOptions);

catch (e) {
console.log('try to connect to device has error: ', e);
Log.debug('try to connect to device has error: ', e);
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||

@@ -360,3 +362,3 @@ e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {

catch (e) {
console.log(e);
Log.error(e);
}

@@ -401,3 +403,3 @@ }

const disconnectSubscription = device.onDisconnected(() => {
console.log('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
Log.debug('device disconnect: ', device === null || device === void 0 ? void 0 : device.id);
this.release(uuid);

@@ -415,6 +417,6 @@ disconnectSubscription === null || disconnectSubscription === void 0 ? void 0 : disconnectSubscription.remove();

if (error) {
console.log(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
if (this.runPromise) {
this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyError, (_a = error.reason) !== null && _a !== void 0 ? _a : error.message));
console.log('@onekey/hd-ble-sdk: monitor notify error, and has unreleased Promise');
Log.debug(': monitor notify error, and has unreleased Promise');
}

@@ -443,3 +445,3 @@ return;

catch (error) {
console.log('monitor data error: ', error);
Log.debug('monitor data error: ', error);
(_c = this.runPromise) === null || _c === void 0 ? void 0 : _c.reject(error);

@@ -449,3 +451,3 @@ }

return () => {
console.log('remove characteristic monitor: ', characteristic.uuid);
Log.debug('remove characteristic monitor: ', characteristic.uuid);
subscription.remove();

@@ -485,3 +487,3 @@ };

const messages = this._messages;
console.log('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
const buffers = buildBuffers(messages, name, data);

@@ -498,3 +500,3 @@ if (name === 'FirmwareUpload') {

chunk.reset();
console.log('@onekey/hd-ble-sdk send more packet hex strting: ', chunk.toString('hex'));
Log.debug('send more packet hex strting: ', chunk.toString('hex'));
try {

@@ -506,3 +508,3 @@ yield transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));

this.runPromise = null;
console.log('writeCharacteristic write error: ', e);
Log.error('writeCharacteristic write error: ', e);
return;

@@ -516,3 +518,3 @@ }

const outData = o.toString('base64');
console.log('@onekey/hd-ble-sdk send hex strting: ', o.toString('hex'));
Log.debug('send hex strting: ', o.toString('hex'));
try {

@@ -526,3 +528,3 @@ yield transport.writeCharacteristic.writeWithoutResponse(outData);

this.runPromise = null;
console.log('writeCharacteristic write error: ', e);
Log.debug('writeCharacteristic write error: ', e);
return;

@@ -537,3 +539,3 @@ }

}
console.log('@onekey/hd-ble-sdk receive data: ', response);
Log.debug('receive data: ', response);
const jsonData = receiveOne(messages, response);

@@ -543,3 +545,3 @@ return check.call(jsonData);

catch (e) {
console.log('call error: ', e);
Log.error('call error: ', e);
return e;

@@ -556,3 +558,3 @@ }

cancel() {
console.log('transport-react-native canceled');
Log.debug('transport-react-native canceled');
if (this.runPromise) ;

@@ -559,0 +561,0 @@ this.runPromise = null;

{
"name": "@onekeyfe/hd-transport-react-native",
"version": "0.1.12",
"version": "0.1.13",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",

@@ -23,8 +23,8 @@ "license": "MIT",

"dependencies": {
"@onekeyfe/hd-shared": "^0.1.12",
"@onekeyfe/hd-transport": "^0.1.12",
"@onekeyfe/hd-shared": "^0.1.13",
"@onekeyfe/hd-transport": "^0.1.13",
"react-native-ble-manager": "^8.1.0",
"react-native-ble-plx": "^2.0.3"
},
"gitHead": "38d4f8d711d212de8617f217a0148dcf3cdcc477"
"gitHead": "f69fd0696e38efbc838848fb361cb900043bb2ec"
}

@@ -12,3 +12,10 @@ import { Platform } from 'react-native';

import transport, { COMMON_HEADER_SIZE } from '@onekeyfe/hd-transport';
import { createDeferred, Deferred, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
import {
createDeferred,
Deferred,
ERRORS,
HardwareErrorCode,
enableLog,
initLog,
} from '@onekeyfe/hd-shared';
import { initializeBleManager, getConnectedDeviceIds, getBondedDevices } from './BleManager';

@@ -32,2 +39,4 @@ import { subscribeBleOn } from './subscribeBleOn';

const Log = initLog('@onekey/hd-ble-sdk');
let connectOptions: Record<string, unknown> = {

@@ -61,2 +70,3 @@ requestMTU: 512,

this.scanTimeout = options.scanTimeout ?? 3000;
enableLog(true);
}

@@ -96,3 +106,3 @@

} catch (error) {
console.log('subscribeBleOn error: ', error);
Log.debug('subscribeBleOn error: ', error);
reject(error);

@@ -109,4 +119,4 @@ return;

if (error) {
console.log('ble scan manager: ', blePlxManager);
console.log('ble scan error: ', error);
Log.debug('ble scan manager: ', blePlxManager);
Log.debug('ble scan error: ', error);
if (

@@ -127,11 +137,9 @@ [BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(

if (isOnekeyDevice(device?.name ?? null, device?.id)) {
console.log('search device start ======================');
Log.debug('search device start ======================');
const { name, localName, id } = device ?? {};
console.log(
`device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${id ?? ''}`
);
Log.debug(`device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${id ?? ''}`);
addDevice(device as unknown as Device);
console.log('search device end ======================\n');
Log.debug('search device end ======================\n');
}

@@ -143,3 +151,3 @@ }

for (const device of devices) {
console.log('search connected peripheral: ', device.id);
Log.debug('search connected peripheral: ', device.id);
addDevice(device as unknown as Device);

@@ -176,3 +184,3 @@ }

*/
console.log('@onekey/hd-ble-sdk transport not be released, will release: ', uuid);
Log.debug('transport not be released, will release: ', uuid);
await this.release(uuid);

@@ -185,3 +193,3 @@ }

} catch (error) {
console.log('subscribeBleOn error: ', error);
Log.debug('subscribeBleOn error: ', error);
throw error;

@@ -198,3 +206,3 @@ }

const deviceFilter = connectedDevice.filter(device => device.id === uuid);
console.log(`found connected device count: ${deviceFilter.length}`);
Log.debug(`found connected device count: ${deviceFilter.length}`);
[device] = deviceFilter;

@@ -204,7 +212,7 @@ }

if (!device) {
console.log('try to connect to device: ', uuid);
Log.debug('try to connect to device: ', uuid);
try {
device = await blePlxManager.connectToDevice(uuid, connectOptions);
} catch (e) {
console.log('try to connect to device has error: ', e);
Log.debug('try to connect to device has error: ', e);
if (

@@ -227,3 +235,3 @@ e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||

if (!(await device.isConnected())) {
console.log('not connected, try to connect to device: ', uuid);
Log.debug('not connected, try to connect to device: ', uuid);

@@ -233,3 +241,3 @@ try {

} catch (e) {
console.log('try to connect to device has error: ', e);
Log.debug('try to connect to device has error: ', e);
if (

@@ -267,3 +275,3 @@ e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||

} catch (e) {
console.log(e);
Log.error(e);
}

@@ -320,3 +328,3 @@ }

const disconnectSubscription = device.onDisconnected(() => {
console.log('device disconnect: ', device?.id);
Log.debug('device disconnect: ', device?.id);
this.release(uuid);

@@ -334,3 +342,3 @@ disconnectSubscription?.remove();

if (error) {
console.log(
Log.debug(
`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${

@@ -347,3 +355,3 @@ error as unknown as string

);
console.log('@onekey/hd-ble-sdk: monitor notify error, and has unreleased Promise');
Log.debug(': monitor notify error, and has unreleased Promise');
}

@@ -380,3 +388,3 @@ return;

} catch (error) {
console.log('monitor data error: ', error);
Log.debug('monitor data error: ', error);
this.runPromise?.reject(error);

@@ -387,3 +395,3 @@ }

return () => {
console.log('remove characteristic monitor: ', characteristic.uuid);
Log.debug('remove characteristic monitor: ', characteristic.uuid);
subscription.remove();

@@ -427,3 +435,3 @@ };

const messages = this._messages;
console.log('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
const buffers = buildBuffers(messages, name, data);

@@ -441,3 +449,3 @@

chunk.reset();
console.log('@onekey/hd-ble-sdk send more packet hex strting: ', chunk.toString('hex'));
Log.debug('send more packet hex strting: ', chunk.toString('hex'));
try {

@@ -448,3 +456,3 @@ await transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));

this.runPromise = null;
console.log('writeCharacteristic write error: ', e);
Log.error('writeCharacteristic write error: ', e);
return;

@@ -457,3 +465,3 @@ }

const outData = o.toString('base64');
console.log('@onekey/hd-ble-sdk send hex strting: ', o.toString('hex'));
Log.debug('send hex strting: ', o.toString('hex'));
try {

@@ -466,3 +474,3 @@ await transport.writeCharacteristic.writeWithoutResponse(outData);

this.runPromise = null;
console.log('writeCharacteristic write error: ', e);
Log.debug('writeCharacteristic write error: ', e);
return;

@@ -480,7 +488,7 @@ }

console.log('@onekey/hd-ble-sdk receive data: ', response);
Log.debug('receive data: ', response);
const jsonData = receiveOne(messages, response);
return check.call(jsonData);
} catch (e) {
console.log('call error: ', e);
Log.error('call error: ', e);
return e;

@@ -497,3 +505,3 @@ } finally {

cancel() {
console.log('transport-react-native canceled');
Log.debug('transport-react-native canceled');
if (this.runPromise) {

@@ -500,0 +508,0 @@ // this.runPromise.reject(new Error('Transport_CallCanceled'));

Sorry, the diff of this file is not supported yet

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