@onekeyfe/hd-transport-react-native 1.1.27-alpha.40 → 1.1.27-alpha.5

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/types.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { ProtocolType } from '@onekeyfe/hd-transport';
2
-
3
1
  export type { BleManager as BlePlxManager } from 'react-native-ble-plx';
4
2
 
5
3
  export type TransportOptions = {
@@ -9,5 +7,4 @@ export type TransportOptions = {
9
7
  export type BleAcquireInput = {
10
8
  uuid: string;
11
9
  forceCleanRunPromise?: boolean;
12
- expectedProtocol?: ProtocolType;
13
10
  };
@@ -1,13 +1,13 @@
1
- import { PROTOCOL_V1_HEADER_BYTE, PROTOCOL_V1_REPORT_ID } from '@onekeyfe/hd-transport';
1
+ import { MESSAGE_HEADER_BYTE, MESSAGE_TOP_CHAR } 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(PROTOCOL_V1_REPORT_ID) &&
9
- String.fromCharCode(sharp1) === String.fromCharCode(PROTOCOL_V1_HEADER_BYTE) &&
10
- String.fromCharCode(sharp2) === String.fromCharCode(PROTOCOL_V1_HEADER_BYTE)
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)
11
11
  ) {
12
12
  return true;
13
13
  }
@@ -1,15 +0,0 @@
1
- export type BlePlatform = 'ios' | 'android' | string;
2
- export type BleWriteCapability = {
3
- isWritableWithResponse?: boolean | null;
4
- isWritableWithoutResponse?: boolean | null;
5
- };
6
- export type BleWriteMode = 'withResponse' | 'withoutResponse';
7
- export declare function hasWritableCapability(characteristic: BleWriteCapability): boolean;
8
- export declare function resolveBleWriteMode(characteristic: BleWriteCapability, preferredMode?: BleWriteMode): BleWriteMode;
9
- export declare function resolveProtocolV2PacketCapacity({ platform, iosPacketLength, androidPacketLength, mtu, }: {
10
- platform: BlePlatform;
11
- iosPacketLength?: number;
12
- androidPacketLength?: number;
13
- mtu?: number | null;
14
- }): number;
15
- //# sourceMappingURL=bleStrategy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAE9D,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,kBAAkB,WAIvE;AAED,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,kBAAkB,EAClC,aAAa,GAAE,YAAgC,GAC9C,YAAY,CAkBd;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,eAAmC,EACnC,mBAA2C,EAC3C,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,UAWA"}
package/dist/logger.d.ts DELETED
@@ -1,14 +0,0 @@
1
- type LogMethod = (...args: unknown[]) => void;
2
- type TransportLogger = {
3
- debug?: LogMethod;
4
- error?: LogMethod;
5
- warn?: LogMethod;
6
- };
7
- export declare const setBleLogger: (logger?: TransportLogger) => void;
8
- export declare const bleLogger: {
9
- debug: (...args: unknown[]) => void | undefined;
10
- error: (...args: unknown[]) => void | undefined;
11
- warn: (...args: unknown[]) => void | undefined;
12
- };
13
- export {};
14
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE9C,KAAK,eAAe,GAAG;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAIF,eAAO,MAAM,YAAY,YAAa,eAAe,SAEpD,CAAC;AAEF,eAAO,MAAM,SAAS;qBACH,OAAO,EAAE;qBACT,OAAO,EAAE;oBACV,OAAO,EAAE;CAC1B,CAAC"}
@@ -1,47 +0,0 @@
1
- import {
2
- hasWritableCapability,
3
- resolveBleWriteMode,
4
- resolveProtocolV2PacketCapacity,
5
- } from '../bleStrategy';
6
-
7
- describe('React Native BLE strategy', () => {
8
- test('accepts writeWithoutResponse-only characteristics', () => {
9
- const characteristic = {
10
- isWritableWithResponse: false,
11
- isWritableWithoutResponse: true,
12
- };
13
-
14
- expect(hasWritableCapability(characteristic)).toBe(true);
15
- expect(resolveBleWriteMode(characteristic)).toBe('withoutResponse');
16
- });
17
-
18
- test('falls back to Android default ATT payload when MTU is unavailable', () => {
19
- expect(
20
- resolveProtocolV2PacketCapacity({
21
- platform: 'android',
22
- androidPacketLength: 192,
23
- mtu: null,
24
- })
25
- ).toBe(20);
26
- });
27
-
28
- test('caps Android packet length by negotiated MTU payload', () => {
29
- expect(
30
- resolveProtocolV2PacketCapacity({
31
- platform: 'android',
32
- androidPacketLength: 192,
33
- mtu: 100,
34
- })
35
- ).toBe(97);
36
- });
37
-
38
- test('keeps iOS packet length controlled by tuning profile', () => {
39
- expect(
40
- resolveProtocolV2PacketCapacity({
41
- platform: 'ios',
42
- iosPacketLength: 244,
43
- mtu: 256,
44
- })
45
- ).toBe(244);
46
- });
47
- });
@@ -1,62 +0,0 @@
1
- import { ANDROID_DEFAULT_MTU, ANDROID_PACKET_LENGTH, IOS_PACKET_LENGTH } from './constants';
2
-
3
- export type BlePlatform = 'ios' | 'android' | string;
4
-
5
- export type BleWriteCapability = {
6
- isWritableWithResponse?: boolean | null;
7
- isWritableWithoutResponse?: boolean | null;
8
- };
9
-
10
- export type BleWriteMode = 'withResponse' | 'withoutResponse';
11
-
12
- export function hasWritableCapability(characteristic: BleWriteCapability) {
13
- return !!(
14
- characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse
15
- );
16
- }
17
-
18
- export function resolveBleWriteMode(
19
- characteristic: BleWriteCapability,
20
- preferredMode: BleWriteMode = 'withoutResponse'
21
- ): BleWriteMode {
22
- if (preferredMode === 'withoutResponse' && characteristic.isWritableWithoutResponse) {
23
- return 'withoutResponse';
24
- }
25
-
26
- if (preferredMode === 'withResponse' && characteristic.isWritableWithResponse) {
27
- return 'withResponse';
28
- }
29
-
30
- if (characteristic.isWritableWithoutResponse) {
31
- return 'withoutResponse';
32
- }
33
-
34
- if (characteristic.isWritableWithResponse) {
35
- return 'withResponse';
36
- }
37
-
38
- return preferredMode;
39
- }
40
-
41
- export function resolveProtocolV2PacketCapacity({
42
- platform,
43
- iosPacketLength = IOS_PACKET_LENGTH,
44
- androidPacketLength = ANDROID_PACKET_LENGTH,
45
- mtu,
46
- }: {
47
- platform: BlePlatform;
48
- iosPacketLength?: number;
49
- androidPacketLength?: number;
50
- mtu?: number | null;
51
- }) {
52
- if (platform === 'ios') {
53
- return iosPacketLength;
54
- }
55
-
56
- if (platform === 'android') {
57
- const payloadLength = Math.max((mtu ?? ANDROID_DEFAULT_MTU) - 3, 1);
58
- return Math.min(androidPacketLength, payloadLength);
59
- }
60
-
61
- return androidPacketLength;
62
- }
package/src/logger.ts DELETED
@@ -1,19 +0,0 @@
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
- };