@onekeyfe/hd-core 1.2.0-alpha.15 → 1.2.0-alpha.16
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 +77 -0
- package/__tests__/DeviceEventRegistration.test.ts +8 -3
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +1 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/index.js +14 -22
- package/package.json +4 -4
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +8 -13
- package/src/core/deviceEventRegistration.ts +1 -8
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { DeviceCommands } from '../src/device/DeviceCommands';
|
|
4
|
+
import { DEVICE } from '../src/events';
|
|
4
5
|
|
|
5
6
|
jest.mock('../src/data/config', () => ({
|
|
6
7
|
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
@@ -169,3 +170,79 @@ describe('DeviceCommands failure mapping', () => {
|
|
|
169
170
|
});
|
|
170
171
|
});
|
|
171
172
|
});
|
|
173
|
+
|
|
174
|
+
describe('DeviceCommands Protocol V2 interactive response compatibility', () => {
|
|
175
|
+
it('still auto-acks ButtonRequest when no hardware UI listener is registered', async () => {
|
|
176
|
+
const commands = createCommands();
|
|
177
|
+
commands.device = {
|
|
178
|
+
...commands.device,
|
|
179
|
+
getCurrentDeviceType: jest.fn(() => 'pro2'),
|
|
180
|
+
setCancelableAction: jest.fn(),
|
|
181
|
+
emit: jest.fn(),
|
|
182
|
+
listenerCount: jest.fn(() => 0),
|
|
183
|
+
} as any;
|
|
184
|
+
commands._commonCall = jest.fn().mockResolvedValue({
|
|
185
|
+
type: 'Success',
|
|
186
|
+
message: {},
|
|
187
|
+
}) as any;
|
|
188
|
+
|
|
189
|
+
await expect(
|
|
190
|
+
commands._filterCommonTypes(
|
|
191
|
+
{
|
|
192
|
+
type: 'ButtonRequest',
|
|
193
|
+
message: { code: 'ButtonRequest_PinEntry' },
|
|
194
|
+
} as any,
|
|
195
|
+
'GetAddress'
|
|
196
|
+
)
|
|
197
|
+
).resolves.toMatchObject({ type: 'Success' });
|
|
198
|
+
|
|
199
|
+
expect(commands.device.emit).toHaveBeenCalledWith(
|
|
200
|
+
DEVICE.BUTTON,
|
|
201
|
+
commands.device,
|
|
202
|
+
expect.objectContaining({ code: 'ButtonRequest_PinEntry' })
|
|
203
|
+
);
|
|
204
|
+
expect(commands._commonCall).toHaveBeenCalledWith('ButtonAck', {}, undefined);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('rejects PassphraseRequest when the Pro2 UI listener is not registered', async () => {
|
|
208
|
+
const commands = createCommands();
|
|
209
|
+
commands.device = {
|
|
210
|
+
...commands.device,
|
|
211
|
+
listenerCount: jest.fn(() => 0),
|
|
212
|
+
} as any;
|
|
213
|
+
|
|
214
|
+
await expect(
|
|
215
|
+
commands._filterCommonTypes(
|
|
216
|
+
{
|
|
217
|
+
type: 'PassphraseRequest',
|
|
218
|
+
message: { exists_attach_pin_user: true },
|
|
219
|
+
} as any,
|
|
220
|
+
'GetAddress'
|
|
221
|
+
)
|
|
222
|
+
).rejects.toMatchObject({
|
|
223
|
+
errorCode: HardwareErrorCode.RuntimeError,
|
|
224
|
+
message: '_promptPassphrase: Passphrase callback not configured',
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('rejects PinMatrixRequest when the Pro2 UI listener is not registered', async () => {
|
|
229
|
+
const commands = createCommands();
|
|
230
|
+
commands.device = {
|
|
231
|
+
...commands.device,
|
|
232
|
+
instanceId: 'pro2-test-device',
|
|
233
|
+
listenerCount: jest.fn(() => 0),
|
|
234
|
+
} as any;
|
|
235
|
+
|
|
236
|
+
await expect(
|
|
237
|
+
commands._filterCommonTypes(
|
|
238
|
+
{
|
|
239
|
+
type: 'PinMatrixRequest',
|
|
240
|
+
message: { type: 'PinMatrixRequestType_Current' },
|
|
241
|
+
} as any,
|
|
242
|
+
'GetAddress'
|
|
243
|
+
)
|
|
244
|
+
).rejects.toMatchObject({
|
|
245
|
+
errorCode: HardwareErrorCode.RuntimeError,
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -14,11 +14,16 @@ const createDevice = (protocolV2: boolean) => ({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
describe('hardware UI event registration', () => {
|
|
17
|
-
test('
|
|
17
|
+
test('keeps all interactive UI events for Protocol V2 devices during compatibility mode', () => {
|
|
18
18
|
const device = createDevice(true);
|
|
19
19
|
|
|
20
|
-
expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(
|
|
21
|
-
expect(device.on
|
|
20
|
+
expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(true);
|
|
21
|
+
expect(device.on.mock.calls.map(([type]) => type)).toEqual([
|
|
22
|
+
DEVICE.PIN,
|
|
23
|
+
DEVICE.BUTTON,
|
|
24
|
+
DEVICE.PASSPHRASE,
|
|
25
|
+
DEVICE.PASSPHRASE_ON_DEVICE,
|
|
26
|
+
]);
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
test('keeps the existing interactive event listeners for Protocol V1 devices', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AllNetworkGetAddressBase.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddressBase.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"AllNetworkGetAddressBase.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddressBase.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAe3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,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,kBAAkB,CAAC,EACjB,OAAO,EACP,OAAO,EACP,aAAa,GACd,EAAE;QACD,OAAO,EAAE,QAAQ,CAAC;QAClB,OAAO,EAAE,uBAAuB,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC;KACvB,GAAG,YAAY;IAqBV,UAAU,CACd,UAAU,EAAE,MAAM,OAAO,EACzB,MAAM,EAAE,GAAG,GAAG;QACZ,MAAM,EAAE,CAAC,GAAG,GAAG;YAAE,oBAAoB,EAAE,oBAAoB,CAAA;SAAE,CAAC,EAAE,CAAC;KAClE,EACD,eAAe,EAAE,MAAM;IAoHzB,QAAQ,CAAC,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAE9E,GAAG;CAuBV"}
|
|
@@ -6,6 +6,5 @@ export type HardwareUiEventHandlers = {
|
|
|
6
6
|
passphrase: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE]) => void;
|
|
7
7
|
passphraseOnDevice: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE_ON_DEVICE]) => void;
|
|
8
8
|
};
|
|
9
|
-
export declare
|
|
10
|
-
export declare function registerHardwareUiEventListeners(device: Pick<Device, 'isProtocolV2' | 'on'>, handlers: HardwareUiEventHandlers): boolean;
|
|
9
|
+
export declare function registerHardwareUiEventListeners(device: Pick<Device, 'on'>, handlers: HardwareUiEventHandlers): boolean;
|
|
11
10
|
//# sourceMappingURL=deviceEventRegistration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceEventRegistration.d.ts","sourceRoot":"","sources":["../../src/core/deviceEventRegistration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IACzD,MAAM,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC/D,UAAU,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IACvE,kBAAkB,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;CAC1F,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"deviceEventRegistration.d.ts","sourceRoot":"","sources":["../../src/core/deviceEventRegistration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IACzD,MAAM,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC/D,UAAU,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IACvE,kBAAkB,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;CAC1F,CAAC;AAEF,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAC1B,QAAQ,EAAE,uBAAuB,WAOlC"}
|
package/dist/index.js
CHANGED
|
@@ -48610,18 +48610,6 @@ class CipherKeyValue extends BaseMethod {
|
|
|
48610
48610
|
}
|
|
48611
48611
|
}
|
|
48612
48612
|
|
|
48613
|
-
const shouldRegisterHardwareUiEvents = (device) => !device.isProtocolV2();
|
|
48614
|
-
function registerHardwareUiEventListeners(device, handlers) {
|
|
48615
|
-
if (!shouldRegisterHardwareUiEvents(device)) {
|
|
48616
|
-
return false;
|
|
48617
|
-
}
|
|
48618
|
-
device.on(DEVICE.PIN, handlers.pin);
|
|
48619
|
-
device.on(DEVICE.BUTTON, handlers.button);
|
|
48620
|
-
device.on(DEVICE.PASSPHRASE, handlers.passphrase);
|
|
48621
|
-
device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
|
|
48622
|
-
return true;
|
|
48623
|
-
}
|
|
48624
|
-
|
|
48625
48613
|
const Mainnet = 'mainnet';
|
|
48626
48614
|
const networkAliases = {
|
|
48627
48615
|
tbtc: { name: 'btc', coin: 'Testnet' },
|
|
@@ -48889,11 +48877,9 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
48889
48877
|
commandsInstanceId: (_c = this.device.commands) === null || _c === void 0 ? void 0 : _c.instanceId,
|
|
48890
48878
|
});
|
|
48891
48879
|
}
|
|
48892
|
-
|
|
48893
|
-
|
|
48894
|
-
|
|
48895
|
-
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
48896
|
-
}
|
|
48880
|
+
this.device.on(DEVICE.BUTTON, buttonListener);
|
|
48881
|
+
this.device.on(DEVICE.PIN, onSignalAbort);
|
|
48882
|
+
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
48897
48883
|
preCheckDeviceSupport(this.device, method);
|
|
48898
48884
|
if (this.temporarySafetyCheckPrompted) {
|
|
48899
48885
|
method.temporarySafetyCheckPrompted = true;
|
|
@@ -48932,11 +48918,9 @@ class AllNetworkGetAddressBase extends BaseMethod {
|
|
|
48932
48918
|
}
|
|
48933
48919
|
}
|
|
48934
48920
|
finally {
|
|
48935
|
-
|
|
48936
|
-
|
|
48937
|
-
|
|
48938
|
-
this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
|
|
48939
|
-
}
|
|
48921
|
+
this.device.off(DEVICE.BUTTON, buttonListener);
|
|
48922
|
+
this.device.off(DEVICE.PIN, onSignalAbort);
|
|
48923
|
+
this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
|
|
48940
48924
|
}
|
|
48941
48925
|
return result;
|
|
48942
48926
|
});
|
|
@@ -58185,6 +58169,14 @@ class RequestQueue {
|
|
|
58185
58169
|
}
|
|
58186
58170
|
}
|
|
58187
58171
|
|
|
58172
|
+
function registerHardwareUiEventListeners(device, handlers) {
|
|
58173
|
+
device.on(DEVICE.PIN, handlers.pin);
|
|
58174
|
+
device.on(DEVICE.BUTTON, handlers.button);
|
|
58175
|
+
device.on(DEVICE.PASSPHRASE, handlers.passphrase);
|
|
58176
|
+
device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
|
|
58177
|
+
return true;
|
|
58178
|
+
}
|
|
58179
|
+
|
|
58188
58180
|
const getMutex = () => {
|
|
58189
58181
|
const DEFAULT_ID = Symbol();
|
|
58190
58182
|
const locks = {};
|
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.16",
|
|
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.16",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.16",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"bytebuffer": "^5.0.1",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"@types/w3c-web-usb": "^1.0.10",
|
|
45
45
|
"@types/web-bluetooth": "^0.0.21"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2356d951f63a39a46bc995c2090348a383966175"
|
|
48
48
|
}
|
|
@@ -15,7 +15,6 @@ import { DEVICE, IFRAME, createUiMessage } from '../../events';
|
|
|
15
15
|
import { isMethodVersionRangeUnsupported } from '../../utils';
|
|
16
16
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
17
17
|
import { onDeviceButtonHandler } from '../../core';
|
|
18
|
-
import { shouldRegisterHardwareUiEvents } from '../../core/deviceEventRegistration';
|
|
19
18
|
import {
|
|
20
19
|
completeRequestContext,
|
|
21
20
|
createRequestContext,
|
|
@@ -365,13 +364,11 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
365
364
|
});
|
|
366
365
|
}
|
|
367
366
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
374
|
-
}
|
|
367
|
+
// pro pin event
|
|
368
|
+
this.device.on(DEVICE.BUTTON, buttonListener);
|
|
369
|
+
// classic pin event
|
|
370
|
+
this.device.on(DEVICE.PIN, onSignalAbort);
|
|
371
|
+
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
375
372
|
|
|
376
373
|
preCheckDeviceSupport(this.device, method);
|
|
377
374
|
if (this.temporarySafetyCheckPrompted) {
|
|
@@ -425,11 +422,9 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
425
422
|
);
|
|
426
423
|
}
|
|
427
424
|
} finally {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
|
|
432
|
-
}
|
|
425
|
+
this.device.off(DEVICE.BUTTON, buttonListener);
|
|
426
|
+
this.device.off(DEVICE.PIN, onSignalAbort);
|
|
427
|
+
this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
|
|
433
428
|
}
|
|
434
429
|
|
|
435
430
|
return result;
|
|
@@ -9,17 +9,10 @@ export type HardwareUiEventHandlers = {
|
|
|
9
9
|
passphraseOnDevice: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE_ON_DEVICE]) => void;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const shouldRegisterHardwareUiEvents = (device: Pick<Device, 'isProtocolV2'>) =>
|
|
13
|
-
!device.isProtocolV2();
|
|
14
|
-
|
|
15
12
|
export function registerHardwareUiEventListeners(
|
|
16
|
-
device: Pick<Device, '
|
|
13
|
+
device: Pick<Device, 'on'>,
|
|
17
14
|
handlers: HardwareUiEventHandlers
|
|
18
15
|
) {
|
|
19
|
-
if (!shouldRegisterHardwareUiEvents(device)) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
16
|
device.on(DEVICE.PIN, handlers.pin);
|
|
24
17
|
device.on(DEVICE.BUTTON, handlers.button);
|
|
25
18
|
device.on(DEVICE.PASSPHRASE, handlers.passphrase);
|