@onekeyfe/hd-transport-react-native 1.1.26 → 1.1.27-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/logger.ts ADDED
@@ -0,0 +1,19 @@
1
+ type LogMethod = (...args: unknown[]) => void;
2
+
3
+ type TransportLogger = {
4
+ debug?: LogMethod;
5
+ error?: LogMethod;
6
+ warn?: LogMethod;
7
+ };
8
+
9
+ let activeLogger: TransportLogger | undefined;
10
+
11
+ export const setBleLogger = (logger?: TransportLogger) => {
12
+ activeLogger = logger;
13
+ };
14
+
15
+ export const bleLogger = {
16
+ debug: (...args: unknown[]) => activeLogger?.debug?.(...args),
17
+ error: (...args: unknown[]) => activeLogger?.error?.(...args),
18
+ warn: (...args: unknown[]) => activeLogger?.warn?.(...args),
19
+ };
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { ProtocolType } from '@onekeyfe/hd-transport';
2
+
1
3
  export type { BleManager as BlePlxManager } from 'react-native-ble-plx';
2
4
 
3
5
  export type TransportOptions = {
@@ -7,4 +9,5 @@ export type TransportOptions = {
7
9
  export type BleAcquireInput = {
8
10
  uuid: string;
9
11
  forceCleanRunPromise?: boolean;
12
+ expectedProtocol?: ProtocolType;
10
13
  };
@@ -1,13 +1,13 @@
1
- import { MESSAGE_HEADER_BYTE, MESSAGE_TOP_CHAR } from '@onekeyfe/hd-transport';
1
+ import { PROTOCOL_V1_HEADER_BYTE, PROTOCOL_V1_REPORT_ID } from '@onekeyfe/hd-transport';
2
2
 
3
3
  export const isHeaderChunk = (chunk: Buffer): boolean => {
4
4
  if (chunk.length < 9) return false;
5
5
  const [MagicQuestionMark, sharp1, sharp2] = chunk;
6
6
 
7
7
  if (
8
- String.fromCharCode(MagicQuestionMark) === String.fromCharCode(MESSAGE_TOP_CHAR) &&
9
- String.fromCharCode(sharp1) === String.fromCharCode(MESSAGE_HEADER_BYTE) &&
10
- String.fromCharCode(sharp2) === String.fromCharCode(MESSAGE_HEADER_BYTE)
8
+ String.fromCharCode(MagicQuestionMark) === String.fromCharCode(PROTOCOL_V1_REPORT_ID) &&
9
+ String.fromCharCode(sharp1) === String.fromCharCode(PROTOCOL_V1_HEADER_BYTE) &&
10
+ String.fromCharCode(sharp2) === String.fromCharCode(PROTOCOL_V1_HEADER_BYTE)
11
11
  ) {
12
12
  return true;
13
13
  }