@onekeyfe/hd-core 1.2.0-alpha.144 → 1.2.0-alpha.145
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__/device-utils.test.ts +8 -0
- package/__tests__/deviceUploadNft.test.ts +3 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +35 -0
- package/__tests__/protocol-v2.test.ts +2 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/PromptWebDeviceAccess.ts +2 -2
- package/src/api/protocol-v2/DeviceUploadNft.ts +5 -1
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +5 -1
- package/src/utils/deviceInfoUtils.ts +7 -2
|
@@ -123,6 +123,14 @@ describe('device feature selectors', () => {
|
|
|
123
123
|
test('recognizes Neo discovery names before initialization', () => {
|
|
124
124
|
expect(getDeviceTypeByBleName('OneKey Neo 1234')).toBe(EDeviceType.Neo);
|
|
125
125
|
expect(getDeviceTypeByBleName('Neo 1234')).toBe(EDeviceType.Neo);
|
|
126
|
+
expect(getDeviceTypeByBleName('Neo22D8')).toBe(EDeviceType.Neo);
|
|
127
|
+
expect(getDeviceTypeByBleName('OneKeyNeo22D8')).toBe(EDeviceType.Neo);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('recognizes compact Pro2 discovery names before initialization', () => {
|
|
131
|
+
expect(getDeviceTypeByBleName('Pro2 A1B2')).toBe(EDeviceType.Pro2);
|
|
132
|
+
expect(getDeviceTypeByBleName('Pro2A1B2')).toBe(EDeviceType.Pro2);
|
|
133
|
+
expect(getDeviceTypeByBleName('OneKeyPro2A1B2')).toBe(EDeviceType.Pro2);
|
|
126
134
|
});
|
|
127
135
|
|
|
128
136
|
test.each([EDeviceType.Pro2, EDeviceType.Neo])(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
import { encode as encodeJpeg } from 'jpeg-js';
|
|
3
4
|
|
|
4
5
|
import DeviceUploadNft from '../src/api/protocol-v2/DeviceUploadNft';
|
|
@@ -110,6 +111,8 @@ describe('DeviceUploadNft', () => {
|
|
|
110
111
|
|
|
111
112
|
method.init();
|
|
112
113
|
|
|
114
|
+
expect(method.unlockPolicy).toBe('unlock-before-run');
|
|
115
|
+
expect(method.protocolV2PreUnlockPinType).toBe(DeviceSessionPinType.Any);
|
|
113
116
|
expect((method as any).params).toMatchObject({
|
|
114
117
|
chunkSize: 2048,
|
|
115
118
|
paceMs: 0,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import TransportUtils, { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { encode as encodeJpeg } from 'jpeg-js';
|
|
2
3
|
|
|
3
4
|
import ConfluxSignMessageCIP23 from '../src/api/conflux/ConfluxSignMessageCIP23';
|
|
4
5
|
import DeviceChangePin from '../src/api/device/DeviceChangePin';
|
|
@@ -6,6 +7,8 @@ import DeviceLock from '../src/api/device/DeviceLock';
|
|
|
6
7
|
import DeviceSettings from '../src/api/device/DeviceSettings';
|
|
7
8
|
import DeviceVerify from '../src/api/device/DeviceVerify';
|
|
8
9
|
import DeviceWipe from '../src/api/device/DeviceWipe';
|
|
10
|
+
import DeviceUploadNft from '../src/api/protocol-v2/DeviceUploadNft';
|
|
11
|
+
import DeviceUploadWallpaper from '../src/api/protocol-v2/DeviceUploadWallpaper';
|
|
9
12
|
import FirmwareUpdateV4 from '../src/api/FirmwareUpdateV4';
|
|
10
13
|
import OpenWalletSession from '../src/api/OpenWalletSession';
|
|
11
14
|
import DataManager from '../src/data-manager/DataManager';
|
|
@@ -16,6 +19,12 @@ jest.mock('../src/data/config', () => ({
|
|
|
16
19
|
getSDKVersion: () => '0.0.0-test',
|
|
17
20
|
}));
|
|
18
21
|
|
|
22
|
+
const createJpegBase64 = (width: number, height: number) => {
|
|
23
|
+
const data = new Uint8Array(width * height * 4);
|
|
24
|
+
for (let index = 3; index < data.length; index += 4) data[index] = 0xff;
|
|
25
|
+
return encodeJpeg({ width, height, data }, 80).data.toString('base64');
|
|
26
|
+
};
|
|
27
|
+
|
|
19
28
|
describe('Protocol V2 unlock semantics', () => {
|
|
20
29
|
test('serializes genuine-device verification with Protocol V2 certificate messages', async () => {
|
|
21
30
|
const method = new DeviceVerify({
|
|
@@ -258,6 +267,32 @@ describe('Protocol V2 unlock semantics', () => {
|
|
|
258
267
|
payload: { method: 'deviceVerify', dataHex: '00' },
|
|
259
268
|
}),
|
|
260
269
|
],
|
|
270
|
+
[
|
|
271
|
+
'wallpaper uploads',
|
|
272
|
+
() =>
|
|
273
|
+
new DeviceUploadWallpaper({
|
|
274
|
+
id: 1,
|
|
275
|
+
payload: {
|
|
276
|
+
method: 'deviceUploadWallpaper',
|
|
277
|
+
jpegBase64: createJpegBase64(604, 1024),
|
|
278
|
+
},
|
|
279
|
+
}),
|
|
280
|
+
],
|
|
281
|
+
[
|
|
282
|
+
'NFT uploads',
|
|
283
|
+
() =>
|
|
284
|
+
new DeviceUploadNft({
|
|
285
|
+
id: 1,
|
|
286
|
+
payload: {
|
|
287
|
+
method: 'deviceUploadNft',
|
|
288
|
+
imageJpegBase64: createJpegBase64(540, 540),
|
|
289
|
+
thumbnailJpegBase64: createJpegBase64(263, 263),
|
|
290
|
+
title: 'NFT',
|
|
291
|
+
subtitle: '',
|
|
292
|
+
timestampMs: 1,
|
|
293
|
+
},
|
|
294
|
+
}),
|
|
295
|
+
],
|
|
261
296
|
])('allows either PIN type when pre-unlocking %s', async (_name, createMethod) => {
|
|
262
297
|
const method = createMethod();
|
|
263
298
|
method.init();
|
|
@@ -221,7 +221,8 @@ describe('DeviceUploadWallpaper', () => {
|
|
|
221
221
|
const result = await method.run();
|
|
222
222
|
|
|
223
223
|
expect(method.getSupportedProtocols()).toEqual(['V2']);
|
|
224
|
-
expect(method.unlockPolicy).toBe('
|
|
224
|
+
expect(method.unlockPolicy).toBe('unlock-before-run');
|
|
225
|
+
expect(method.protocolV2PreUnlockPinType).toBe(DeviceSessionPinType.Any);
|
|
225
226
|
expect(typedCall).toHaveBeenNthCalledWith(1, 'FilesystemDirMake', 'Success', {
|
|
226
227
|
path: 'vol1:/wallpapers',
|
|
227
228
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceUploadNft.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceUploadNft.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeviceUploadNft.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceUploadNft.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAOF,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,qBAAqB,CAAC;IAC5E,OAAO,CAAC,MAAM,CAAC,CAAgB;IAE/B,qBAAqB;IAIrB,IAAI;YAgFU,kBAAkB;YAiBlB,qBAAqB;YAwBrB,SAAS;IASjB,GAAG,IAAI,OAAO,CAAC,uBAAuB,CAAC;CA0D9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceUploadWallpaper.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceUploadWallpaper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeviceUploadWallpaper.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceUploadWallpaper.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,OAAO,EAGL,KAAK,wBAAwB,EAE9B,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,wBAAwB,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAmBF,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU,CAAC,2BAA2B,CAAC;IACxF,qBAAqB;IAIrB,OAAO,CAAC,OAAO,CAAC,CAA8D;IAE9E,OAAO,CAAC,cAAc,CAAS;IAE/B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,IAAI,CAAM;IAElB,IAAI;YA2BU,kBAAkB;YAgBlB,eAAe;YAaf,MAAM;IAwBd,GAAG,IAAI,OAAO,CAAC,6BAA6B,CAAC;CAyBpD"}
|
package/dist/index.js
CHANGED
|
@@ -466,10 +466,13 @@ const getDeviceTypeByBleName = (name) => {
|
|
|
466
466
|
return hdShared.EDeviceType.Touch;
|
|
467
467
|
if (/^Touch/i.test(name))
|
|
468
468
|
return hdShared.EDeviceType.Touch;
|
|
469
|
-
|
|
469
|
+
const compactName = name.replace(/[\s-]/g, '');
|
|
470
|
+
if (/\bPro\s*2\b/i.test(name) || /^Pro2/i.test(name) || /^(?:OneKey)?Pro2/i.test(compactName)) {
|
|
470
471
|
return hdShared.EDeviceType.Pro2;
|
|
471
|
-
|
|
472
|
+
}
|
|
473
|
+
if (/\bNeo\b/i.test(name) || /^Neo/i.test(name) || /^(?:OneKey)?Neo/i.test(compactName)) {
|
|
472
474
|
return hdShared.EDeviceType.Neo;
|
|
475
|
+
}
|
|
473
476
|
if (/\bPro\b/i.test(name) || /^Pro/i.test(name))
|
|
474
477
|
return hdShared.EDeviceType.Pro;
|
|
475
478
|
return hdShared.EDeviceType.Unknown;
|
|
@@ -53885,7 +53888,7 @@ class PromptWebDeviceAccess extends BaseMethod {
|
|
|
53885
53888
|
}
|
|
53886
53889
|
if (isWebUsbEnv) {
|
|
53887
53890
|
const usbDevice = device;
|
|
53888
|
-
const path = usbDevice
|
|
53891
|
+
const path = hdShared.resolveOneKeyUsbDevicePath(usbDevice);
|
|
53889
53892
|
if (!path) {
|
|
53890
53893
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDevicePromptAccessError);
|
|
53891
53894
|
}
|
|
@@ -54323,7 +54326,8 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54323
54326
|
});
|
|
54324
54327
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
54325
54328
|
this.params = { jpegBase64, fileName, chunkSize };
|
|
54326
|
-
this.unlockPolicy = '
|
|
54329
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
54330
|
+
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
54327
54331
|
this.skipForceUpdateCheck = true;
|
|
54328
54332
|
this.useDevicePassphraseState = false;
|
|
54329
54333
|
}
|
|
@@ -54479,7 +54483,8 @@ class DeviceUploadNft extends BaseMethod {
|
|
|
54479
54483
|
paceMs,
|
|
54480
54484
|
timeoutMs,
|
|
54481
54485
|
};
|
|
54482
|
-
this.unlockPolicy = '
|
|
54486
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
54487
|
+
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
54483
54488
|
this.skipForceUpdateCheck = true;
|
|
54484
54489
|
this.useDevicePassphraseState = false;
|
|
54485
54490
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,WAmBtD,CAAC;AAMF,eAAO,MAAM,gBAAgB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAC3C,CAAC;AAKjC,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,MAClC,CAAC;AAKlC,eAAO,MAAM,aAAa,cANmB,mBAAmB,KAAG,MAMrB,CAAC;AAK/C,eAAO,MAAM,cAAc,cAAe,mBAAmB,kBAkB5D,CAAC;AAMF,eAAO,MAAM,qBAAqB,aACtB,mBAAmB,GAAG,SAAS,iCACV,WAAW,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,KACtF,aAAa,GAAG,SAyBlB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,mBAAmB,gDACzB,CAAC"}
|
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.145",
|
|
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.145",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.145",
|
|
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": "9a136f881865c15e603ef271ae820c2b5a991dcc"
|
|
50
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { ERRORS, HardwareErrorCode, resolveOneKeyUsbDevicePath } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from './BaseMethod';
|
|
4
4
|
import TransportManager from '../data-manager/TransportManager';
|
|
@@ -52,7 +52,7 @@ export default class PromptWebDeviceAccess extends BaseMethod {
|
|
|
52
52
|
|
|
53
53
|
if (isWebUsbEnv) {
|
|
54
54
|
const usbDevice = device as USBDevice;
|
|
55
|
-
const path = usbDevice
|
|
55
|
+
const path = resolveOneKeyUsbDevicePath(usbDevice);
|
|
56
56
|
if (!path) {
|
|
57
57
|
throw ERRORS.TypedError(HardwareErrorCode.WebDevicePromptAccessError);
|
|
58
58
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode, createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
4
5
|
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
@@ -129,7 +130,10 @@ export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
|
129
130
|
paceMs,
|
|
130
131
|
timeoutMs,
|
|
131
132
|
};
|
|
132
|
-
this.unlockPolicy = '
|
|
133
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
134
|
+
// File writes and NftUpdate require an unlocked device. Either PIN may
|
|
135
|
+
// authorize this device-management action.
|
|
136
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
133
137
|
this.skipForceUpdateCheck = true;
|
|
134
138
|
this.useDevicePassphraseState = false;
|
|
135
139
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { blake2s } from '@noble/hashes/blake2s';
|
|
2
2
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
3
3
|
import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
4
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
4
5
|
|
|
5
6
|
import { BaseMethod } from '../BaseMethod';
|
|
6
7
|
import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
|
|
@@ -78,7 +79,10 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
78
79
|
});
|
|
79
80
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
80
81
|
this.params = { jpegBase64, fileName, chunkSize };
|
|
81
|
-
this.unlockPolicy = '
|
|
82
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
83
|
+
// File writes and wallpaper apply require an unlocked device. Either PIN
|
|
84
|
+
// may authorize this device-management action.
|
|
85
|
+
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
82
86
|
this.skipForceUpdateCheck = true;
|
|
83
87
|
this.useDevicePassphraseState = false;
|
|
84
88
|
}
|
|
@@ -30,8 +30,13 @@ export const getDeviceTypeByBleName = (name?: string): IDeviceType => {
|
|
|
30
30
|
if (/^T/i.test(name)) return EDeviceType.Touch;
|
|
31
31
|
if (/^Touch/i.test(name)) return EDeviceType.Touch;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
if (/\
|
|
33
|
+
const compactName = name.replace(/[\s-]/g, '');
|
|
34
|
+
if (/\bPro\s*2\b/i.test(name) || /^Pro2/i.test(name) || /^(?:OneKey)?Pro2/i.test(compactName)) {
|
|
35
|
+
return EDeviceType.Pro2;
|
|
36
|
+
}
|
|
37
|
+
if (/\bNeo\b/i.test(name) || /^Neo/i.test(name) || /^(?:OneKey)?Neo/i.test(compactName)) {
|
|
38
|
+
return EDeviceType.Neo;
|
|
39
|
+
}
|
|
35
40
|
if (/\bPro\b/i.test(name) || /^Pro/i.test(name)) return EDeviceType.Pro;
|
|
36
41
|
|
|
37
42
|
return EDeviceType.Unknown;
|