@onekeyfe/hd-core 1.2.0-alpha.125 → 1.2.0-alpha.126
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/__tests__/DeviceCommands.test.ts +26 -0
- package/__tests__/device-connector-protocol.test.ts +21 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/package.json +4 -4
- package/src/core/index.ts +4 -0
- package/src/device/DeviceCommands.ts +7 -1
- package/src/device/DeviceConnector.ts +7 -0
|
@@ -276,6 +276,32 @@ describe('DeviceCommands failure mapping', () => {
|
|
|
276
276
|
]);
|
|
277
277
|
});
|
|
278
278
|
|
|
279
|
+
it.each(['Failure_ProcessError', 5])(
|
|
280
|
+
'maps USB-priority link disabled to public BLE error 723 for code %s',
|
|
281
|
+
async code => {
|
|
282
|
+
const commands = createCommands();
|
|
283
|
+
|
|
284
|
+
await expect(
|
|
285
|
+
commands._filterCommonTypes(
|
|
286
|
+
{
|
|
287
|
+
type: 'Failure',
|
|
288
|
+
message: {
|
|
289
|
+
code,
|
|
290
|
+
message: ' link disabled ',
|
|
291
|
+
},
|
|
292
|
+
} as any,
|
|
293
|
+
'DeviceInfo'
|
|
294
|
+
)
|
|
295
|
+
).rejects.toMatchObject({
|
|
296
|
+
errorCode: HardwareErrorCode.BleUnavailableWhileUsbConnected,
|
|
297
|
+
params: {
|
|
298
|
+
failureCode: code,
|
|
299
|
+
firmwareMessage: ' link disabled ',
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
|
|
279
305
|
it('maps an invalid DeviceSessionGet resume to WalletSessionInvalid', async () => {
|
|
280
306
|
const commands = createCommands();
|
|
281
307
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { createProtocolV2LinkDisabledError } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import DeviceConnector from '../src/device/DeviceConnector';
|
|
4
5
|
|
|
@@ -78,4 +79,24 @@ describe('DeviceConnector protocol validation', () => {
|
|
|
78
79
|
'Device protocol mismatch: expected V2, detected V1'
|
|
79
80
|
);
|
|
80
81
|
});
|
|
82
|
+
|
|
83
|
+
it('preserves the Protocol V2 USB-priority failure as public BLE error 723', async () => {
|
|
84
|
+
transportManagerMock.default.getTransport.mockReturnValue({
|
|
85
|
+
acquire: jest
|
|
86
|
+
.fn()
|
|
87
|
+
.mockRejectedValue(
|
|
88
|
+
createProtocolV2LinkDisabledError('Failure_ProcessError', 'link disabled')
|
|
89
|
+
),
|
|
90
|
+
getProtocolType: jest.fn(() => undefined),
|
|
91
|
+
});
|
|
92
|
+
const connector = new DeviceConnector();
|
|
93
|
+
|
|
94
|
+
await expect(connector.acquire('pro2-id', undefined, undefined, 'V2')).rejects.toMatchObject({
|
|
95
|
+
errorCode: HardwareErrorCode.BleUnavailableWhileUsbConnected,
|
|
96
|
+
params: {
|
|
97
|
+
failureCode: 'Failure_ProcessError',
|
|
98
|
+
firmwareMessage: 'link disabled',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
});
|
|
81
102
|
});
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EACV,6BAA6B,EAG9B,MAAM,wBAAwB,CAAC;A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a,uBAYzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAiBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;UASf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceCommands.d.ts","sourceRoot":"","sources":["../../src/device/DeviceCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"DeviceCommands.d.ts","sourceRoot":"","sources":["../../src/device/DeviceCommands.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,oBAAoB,EAG1B,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAU,KAAK,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAQlE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,KAAK,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;AACxC,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI;IACvD,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB,CAAC;AACF,KAAK,oBAAoB,GAAG;KACzB,CAAC,IAAI,UAAU,GAAG,oBAAoB,CAAC,CAAC,CAAC;CAC3C,CAAC;AACF,MAAM,MAAM,sBAAs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C,EAAE,oBAAoB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA4D7B,WAAW,CACf,IAAI,EAAE,UAAU,EAChB,GAAG,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC,EACvC,OAAO,CAAC,EAAE,oBAAoB;IAMhC,kBAAkB,CAChB,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,EAAE,UAAU,EACpB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,sBAAsB,CAAC;IA8QlC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,oBAAoB;IA8D/C,gBAAgB,CACd,OAAO,EAAE,wBAAwB,EACjC,aAAa,GAAE;QAAE,oBAAoB,CAAC,EAAE,OAAO,CAAA;KAAO;CAiEzD;AAED,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceConnector.d.ts","sourceRoot":"","sources":["../../src/device/DeviceConnector.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"DeviceConnector.d.ts","sourceRoot":"","sources":["../../src/device/DeviceConnector.ts"],"names":[],"mappings":";;AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,IAAI,gBAAgB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAI9F,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,eAAe,SAAK;IAEpB,OAAO,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAQ;IAE1C,QAAQ,EAAE,gBAAgB,EAAE,CAAM;IAElC,SAAS,UAAS;;IAQlB,OAAO,CAAC,kBAAkB;IAYpB,SAAS;IAWT,MAAM;IAgCZ,IAAI;IAIE,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EACvB,oBAAoB,CAAC,EAAE,OAAO,EAC9B,gBAAgB,CAAC,EAAE,uBAAuB,EAC1C,YAAY,CAAC,EAAE,uBAAuB;IAkDlC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,OAAO;IAShE,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAWnD,kBAAkB,IAAI,OAAO,CAAC,SAAS,GAAG,eAAe,GAAG,IAAI,CAAC;IAQjE,oBAAoB;CAGrB"}
|
package/dist/index.js
CHANGED
|
@@ -43843,7 +43843,13 @@ class DeviceCommands {
|
|
|
43843
43843
|
});
|
|
43844
43844
|
}
|
|
43845
43845
|
}
|
|
43846
|
-
if (code
|
|
43846
|
+
if (hdTransport.isProtocolV2LinkDisabledFailure(code, message)) {
|
|
43847
|
+
error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
43848
|
+
failureCode: code,
|
|
43849
|
+
firmwareMessage: message,
|
|
43850
|
+
});
|
|
43851
|
+
}
|
|
43852
|
+
else if (code === 'Failure_ProcessError') {
|
|
43847
43853
|
const normalizedMessage = (_a = message === null || message === void 0 ? void 0 : message.trim()) !== null && _a !== void 0 ? _a : '';
|
|
43848
43854
|
const isProtocolV2ActionCancelledFailure = this.device.isProtocolV2() && isProtocolV2ActionCancelledMessage(normalizedMessage);
|
|
43849
43855
|
const isProtocolV2DeviceBusyFailure = this.device.isProtocolV2() &&
|
|
@@ -64706,6 +64712,12 @@ class DeviceConnector {
|
|
|
64706
64712
|
}
|
|
64707
64713
|
catch (error) {
|
|
64708
64714
|
Log$2.error('acquire error: ', error.message);
|
|
64715
|
+
if (hdTransport.isProtocolV2LinkDisabledError(error)) {
|
|
64716
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
64717
|
+
failureCode: error.failureCode,
|
|
64718
|
+
firmwareMessage: error.firmwareMessage,
|
|
64719
|
+
});
|
|
64720
|
+
}
|
|
64709
64721
|
safeThrowError(error);
|
|
64710
64722
|
}
|
|
64711
64723
|
});
|
|
@@ -65672,6 +65684,10 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65672
65684
|
}
|
|
65673
65685
|
catch (error) {
|
|
65674
65686
|
Log.debug('device error: ', error);
|
|
65687
|
+
if (error.errorCode === hdShared.HardwareErrorCode.BleUnavailableWhileUsbConnected) {
|
|
65688
|
+
reject(error);
|
|
65689
|
+
return;
|
|
65690
|
+
}
|
|
65675
65691
|
if (hdTransport.isProtocolV2LinkDisabledError(error)) {
|
|
65676
65692
|
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
65677
65693
|
failureCode: error.failureCode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.126",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.126",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.126",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c82189b36d650aec460a6f29bd467bf16a74e510"
|
|
50
50
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -1079,6 +1079,10 @@ const ensureConnected = async (
|
|
|
1079
1079
|
}
|
|
1080
1080
|
} catch (error) {
|
|
1081
1081
|
Log.debug('device error: ', error);
|
|
1082
|
+
if (error.errorCode === HardwareErrorCode.BleUnavailableWhileUsbConnected) {
|
|
1083
|
+
reject(error);
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1082
1086
|
if (isProtocolV2LinkDisabledError(error)) {
|
|
1083
1087
|
reject(
|
|
1084
1088
|
ERRORS.TypedError(HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type Transport,
|
|
8
8
|
type TransportCallOptions,
|
|
9
9
|
getSafeTransportLogPayload,
|
|
10
|
+
isProtocolV2LinkDisabledFailure,
|
|
10
11
|
} from '@onekeyfe/hd-transport';
|
|
11
12
|
|
|
12
13
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -495,7 +496,12 @@ export class DeviceCommands {
|
|
|
495
496
|
}
|
|
496
497
|
}
|
|
497
498
|
|
|
498
|
-
if (code
|
|
499
|
+
if (isProtocolV2LinkDisabledFailure(code, message)) {
|
|
500
|
+
error = ERRORS.TypedError(HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
501
|
+
failureCode: code,
|
|
502
|
+
firmwareMessage: message,
|
|
503
|
+
});
|
|
504
|
+
} else if (code === 'Failure_ProcessError') {
|
|
499
505
|
const normalizedMessage = message?.trim() ?? '';
|
|
500
506
|
const isProtocolV2ActionCancelledFailure =
|
|
501
507
|
this.device.isProtocolV2() && isProtocolV2ActionCancelledMessage(normalizedMessage);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isProtocolV2LinkDisabledError } from '@onekeyfe/hd-transport';
|
|
1
2
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
3
|
|
|
3
4
|
import { safeThrowError } from '../constants';
|
|
@@ -134,6 +135,12 @@ export default class DeviceConnector {
|
|
|
134
135
|
return res;
|
|
135
136
|
} catch (error) {
|
|
136
137
|
Log.error('acquire error: ', error.message);
|
|
138
|
+
if (isProtocolV2LinkDisabledError(error)) {
|
|
139
|
+
throw ERRORS.TypedError(HardwareErrorCode.BleUnavailableWhileUsbConnected, undefined, {
|
|
140
|
+
failureCode: error.failureCode,
|
|
141
|
+
firmwareMessage: error.firmwareMessage,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
137
144
|
safeThrowError(error);
|
|
138
145
|
}
|
|
139
146
|
}
|