@onekeyfe/hd-shared 1.2.0-alpha.6 → 1.2.0-alpha.62
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/dist/HardwareError.d.ts +3 -0
- package/dist/HardwareError.d.ts.map +1 -1
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +280 -1
- package/dist/index.js +83 -5
- package/jest.config.js +5 -0
- package/package.json +3 -2
- package/src/HardwareError.test.ts +9 -0
- package/src/HardwareError.ts +20 -0
- package/src/constants.test.ts +132 -0
- package/src/constants.ts +121 -9
package/dist/HardwareError.d.ts
CHANGED
|
@@ -115,6 +115,9 @@ export declare const HardwareErrorCode: {
|
|
|
115
115
|
readonly DeviceSettingsLanguageNotSupport: 826;
|
|
116
116
|
readonly TooManyInputs: 827;
|
|
117
117
|
readonly PinMismatch: 828;
|
|
118
|
+
readonly KaspaPrevTxIdMismatch: 829;
|
|
119
|
+
readonly DeviceLocked: 830;
|
|
120
|
+
readonly WalletSessionInvalid: 831;
|
|
118
121
|
readonly LowlevelTrasnportConnectError: 900;
|
|
119
122
|
readonly WebDeviceNotFoundOrNeedsPermission: 901;
|
|
120
123
|
readonly WebDevicePromptAccessError: 902;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HardwareError.d.ts","sourceRoot":"","sources":["../src/HardwareError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE5C,KAAK,+BAA+B,GAAG;KAAG,CAAC,IAA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,eAAO,MAAM,UAAU,kBACN,cAAc,GAAG,MAAM,YAC5B,MAAM,WACP,GAAG,kBAMb,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,GAAG,QAe1C,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,MAAM,KAAG,aAOtD,CAAC;AAGF,eAAO,MAAM,gCAAgC,QAAS,MAAM,KAAG,aAQ9D,CAAC;AAEF,QAAA,MAAM,uCAAuC;oBAM3B,MAAM;oBACN,MAAM;;;mBAcvB,CAAC;AAEF,QAAA,MAAM,sCAAsC;oBAM1B,MAAM;oBACN,MAAM;;;mBAcvB,CAAC;AAEF,QAAA,MAAM,yCAAyC,cAClC,MAAM,GAAG,SAAS,YACnB,MAAM,GAAG,SAAS,iBACb,CAAC,UAAU,GAAG,KAAK,CAAC,EAAE,oBACnB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,kBAsBF,CAAC;AAEF,QAAA,MAAM,6BAA6B,mBACjB,MAAM,qBACH,MAAM,eACZ,MAAM,kBAQpB,CAAC;AAEF,QAAA,MAAM,4BAA4B,aACtB,MAAM,aACL,MAAM,cACL,MAAM,cACN,MAAM,aACP,MAAM,kBAWlB,CAAC;AAEF,QAAA,MAAM,iCAAiC,eAAgB,MAAM,gBAAgB,aAAa,kBAItF,CAAC;AAEL,OAAO,EACL,uCAAuC,EACvC,sCAAsC,EACtC,yCAAyC,EACzC,6BAA6B,EAC7B,4BAA4B,EAC5B,iCAAiC,GAClC,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ export declare const ONEKEY_WEBUSB_FILTER: {
|
|
|
8
8
|
vendorId: number;
|
|
9
9
|
productId: number;
|
|
10
10
|
}[];
|
|
11
|
+
type WebUsbIdentityDescriptor = {
|
|
12
|
+
vendorId?: number;
|
|
13
|
+
productId?: number;
|
|
14
|
+
manufacturerName?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
|
|
11
17
|
export declare const ERROR_CODES_REQUIRE_RELEASE: readonly [106, 107, 109, 112, 805, 801, 802, 812];
|
|
12
18
|
export declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
|
|
13
19
|
export declare enum EOneKeyBleMessageKeys {
|
|
@@ -39,4 +45,16 @@ export declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000
|
|
|
39
45
|
export declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
40
46
|
export declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
|
|
41
47
|
export declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
|
|
48
|
+
type BluetoothDeviceIdentity = {
|
|
49
|
+
id?: string;
|
|
50
|
+
name?: string | null;
|
|
51
|
+
localName?: string | null;
|
|
52
|
+
serviceUuids?: Array<string | null | undefined> | null;
|
|
53
|
+
};
|
|
54
|
+
export declare const normalizeBleUuid: (uuid?: string | null) => string;
|
|
55
|
+
export declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<string>;
|
|
56
|
+
export declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
|
|
57
|
+
export declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
58
|
+
export declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
59
|
+
export {};
|
|
42
60
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,yBAAyB;;;CAG5B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OA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CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;CACxD,CAAC;AAIF,eAAO,MAAM,gBAAgB,UAAW,MAAM,GAAG,IAAI,WACP,CAAC;AAE/C,eAAO,MAAM,yBAAyB,SAAU,MAAM,KAAG,YAAY,MAAM,CAc1E,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAClB,MAAM,GAAG,IAAI,GAAG,SAAS,WAC5B,YAAY,MAAM,CAAC,YACgB,CAAC;AAQ/C,eAAO,MAAM,6BAA6B,iBAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,YAIhE,CAAC;AAEJ,eAAO,MAAM,uBAAuB,2CAKjC,uBAAuB,KAAG,OAe5B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,21 @@ declare const ONEKEY_WEBUSB_FILTER: {
|
|
|
7
7
|
vendorId: number;
|
|
8
8
|
productId: number;
|
|
9
9
|
}[];
|
|
10
|
+
type WebUsbIdentityDescriptor = {
|
|
11
|
+
vendorId?: number;
|
|
12
|
+
productId?: number;
|
|
13
|
+
manufacturerName?: string | null;
|
|
14
|
+
};
|
|
15
|
+
declare const isKnownTrezorWebUsbDevice: (descriptor: WebUsbIdentityDescriptor) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Error codes that require device release after occurrence
|
|
18
|
+
* These errors indicate the device is in an invalid state and needs to be released
|
|
19
|
+
*/
|
|
10
20
|
declare const ERROR_CODES_REQUIRE_RELEASE: readonly [106, 107, 109, 112, 805, 801, 802, 812];
|
|
21
|
+
/**
|
|
22
|
+
* Error codes that require device disconnect before release
|
|
23
|
+
* These errors indicate a communication failure that requires full reconnection
|
|
24
|
+
*/
|
|
11
25
|
declare const ERROR_CODES_REQUIRE_DISCONNECT: readonly [106, 805];
|
|
12
26
|
declare enum EOneKeyBleMessageKeys {
|
|
13
27
|
BLE_SELECT = "$onekey-ble-select",
|
|
@@ -38,6 +52,17 @@ declare const ONEKEY_WRITE_CHARACTERISTIC_UUID = "00000002-0000-1000-8000-00805f
|
|
|
38
52
|
declare const ONEKEY_NOTIFY_CHARACTERISTIC_UUID = "00000003-0000-1000-8000-00805f9b34fb";
|
|
39
53
|
declare const isHeaderChunk: (chunk: Buffer | Uint8Array) => boolean;
|
|
40
54
|
declare const isOnekeyDevice: (name: string | null, id?: string) => boolean;
|
|
55
|
+
type BluetoothDeviceIdentity = {
|
|
56
|
+
id?: string;
|
|
57
|
+
name?: string | null;
|
|
58
|
+
localName?: string | null;
|
|
59
|
+
serviceUuids?: Array<string | null | undefined> | null;
|
|
60
|
+
};
|
|
61
|
+
declare const normalizeBleUuid: (uuid?: string | null) => string;
|
|
62
|
+
declare const createKnownBleUuidAliases: (uuid: string) => ReadonlySet<string>;
|
|
63
|
+
declare const matchesKnownBleUuid: (actualUuid: string | null | undefined, aliases: ReadonlySet<string>) => boolean;
|
|
64
|
+
declare const hasOnekeyCommunicationService: (serviceUuids: Array<string | null | undefined> | null | undefined) => boolean;
|
|
65
|
+
declare const isOnekeyBluetoothDevice: ({ id, name, localName, serviceUuids, }: BluetoothDeviceIdentity) => boolean;
|
|
41
66
|
|
|
42
67
|
type Deferred<T, I = any, D = any> = {
|
|
43
68
|
id?: I;
|
|
@@ -70,53 +95,201 @@ declare class HardwareError extends Error {
|
|
|
70
95
|
constructor(hardwareError: IHardwareError | string);
|
|
71
96
|
}
|
|
72
97
|
declare const HardwareErrorCode: {
|
|
98
|
+
/**
|
|
99
|
+
* This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
|
|
100
|
+
* Original message is available in message property.
|
|
101
|
+
*/
|
|
73
102
|
readonly UnknownError: 0;
|
|
103
|
+
/**
|
|
104
|
+
* Firmware version mismatch
|
|
105
|
+
*/
|
|
74
106
|
readonly DeviceFwException: 101;
|
|
107
|
+
/**
|
|
108
|
+
* Device unexpected mode
|
|
109
|
+
*/
|
|
75
110
|
readonly DeviceUnexpectedMode: 102;
|
|
111
|
+
/**
|
|
112
|
+
* Device list is not initialized
|
|
113
|
+
*/
|
|
76
114
|
readonly DeviceListNotInitialized: 103;
|
|
115
|
+
/**
|
|
116
|
+
* Please select the connected device
|
|
117
|
+
*/
|
|
77
118
|
readonly SelectDevice: 104;
|
|
119
|
+
/**
|
|
120
|
+
* Device not found
|
|
121
|
+
*/
|
|
78
122
|
readonly DeviceNotFound: 105;
|
|
123
|
+
/**
|
|
124
|
+
* Device is not initialized
|
|
125
|
+
*/
|
|
79
126
|
readonly DeviceInitializeFailed: 106;
|
|
127
|
+
/**
|
|
128
|
+
* Device interrupted from another operation
|
|
129
|
+
*/
|
|
80
130
|
readonly DeviceInterruptedFromOutside: 107;
|
|
131
|
+
/**
|
|
132
|
+
* Device should be in bootloader mode
|
|
133
|
+
*/
|
|
81
134
|
readonly RequiredButInBootloaderMode: 108;
|
|
135
|
+
/**
|
|
136
|
+
* Device interrupted from user
|
|
137
|
+
*/
|
|
82
138
|
readonly DeviceInterruptedFromUser: 109;
|
|
139
|
+
/**
|
|
140
|
+
* Check device id is same
|
|
141
|
+
*/
|
|
83
142
|
readonly DeviceCheckDeviceIdError: 110;
|
|
143
|
+
/**
|
|
144
|
+
* Do not support passphrase
|
|
145
|
+
* @params: { require: string }
|
|
146
|
+
*/
|
|
84
147
|
readonly DeviceNotSupportPassphrase: 111;
|
|
85
148
|
readonly DeviceCheckPassphraseStateError: 112;
|
|
149
|
+
/**
|
|
150
|
+
* use passphrase, but passphrase is not opened
|
|
151
|
+
*/
|
|
86
152
|
readonly DeviceNotOpenedPassphrase: 113;
|
|
153
|
+
/**
|
|
154
|
+
* not use passphrase, but passphrase is opened
|
|
155
|
+
*/
|
|
87
156
|
readonly DeviceOpenedPassphrase: 114;
|
|
157
|
+
/**
|
|
158
|
+
* Detect hardware that is in bootloader mode and return an error.
|
|
159
|
+
*/
|
|
88
160
|
readonly DeviceDetectInBootloaderMode: 115;
|
|
161
|
+
/**
|
|
162
|
+
* Device not allow in bootloader mode
|
|
163
|
+
*/
|
|
89
164
|
readonly NotAllowInBootloaderMode: 116;
|
|
165
|
+
/**
|
|
166
|
+
* Device is busy
|
|
167
|
+
*/
|
|
90
168
|
readonly DeviceBusy: 117;
|
|
169
|
+
/**
|
|
170
|
+
* Device check unlock type not match error
|
|
171
|
+
*/
|
|
91
172
|
readonly DeviceCheckUnlockTypeError: 118;
|
|
173
|
+
/**
|
|
174
|
+
* Not initialized
|
|
175
|
+
*/
|
|
92
176
|
readonly NotInitialized: 200;
|
|
177
|
+
/**
|
|
178
|
+
* Iframe not initialized
|
|
179
|
+
*/
|
|
93
180
|
readonly IFrameNotInitialized: 300;
|
|
181
|
+
/**
|
|
182
|
+
* iframe repeat initialization
|
|
183
|
+
*/
|
|
94
184
|
readonly IFrameAleradyInitialized: 301;
|
|
185
|
+
/**
|
|
186
|
+
* iframe load failure
|
|
187
|
+
*/
|
|
95
188
|
readonly IFrameLoadFail: 302;
|
|
189
|
+
/**
|
|
190
|
+
* init iframe time out
|
|
191
|
+
*/
|
|
96
192
|
readonly IframeTimeout: 303;
|
|
193
|
+
/**
|
|
194
|
+
* iframe blocked
|
|
195
|
+
*/
|
|
97
196
|
readonly IframeBlocked: 304;
|
|
197
|
+
/**
|
|
198
|
+
* iframe host not trust
|
|
199
|
+
*/
|
|
98
200
|
readonly IframeDistrust: 305;
|
|
201
|
+
/**
|
|
202
|
+
* Runtime errors during method execution
|
|
203
|
+
*/
|
|
99
204
|
readonly CallMethodError: 400;
|
|
205
|
+
/**
|
|
206
|
+
* Method does not responding
|
|
207
|
+
*/
|
|
100
208
|
readonly CallMethodNotResponse: 404;
|
|
209
|
+
/**
|
|
210
|
+
* Call method invalid parameter
|
|
211
|
+
*/
|
|
101
212
|
readonly CallMethodInvalidParameter: 405;
|
|
213
|
+
/**
|
|
214
|
+
* firmware update download failed
|
|
215
|
+
*/
|
|
102
216
|
readonly FirmwareUpdateDownloadFailed: 406;
|
|
217
|
+
/**
|
|
218
|
+
* Call method not supported, need update firmware
|
|
219
|
+
* @params: { current: string, require: string }
|
|
220
|
+
*/
|
|
103
221
|
readonly CallMethodNeedUpgradeFirmware: 407;
|
|
222
|
+
/**
|
|
223
|
+
* Call method not supported, is deprecated
|
|
224
|
+
* @params: { current: string, deprecated: string }
|
|
225
|
+
*/
|
|
104
226
|
readonly CallMethodDeprecated: 408;
|
|
227
|
+
/**
|
|
228
|
+
* Only one device can be connected during firmware upgrade
|
|
229
|
+
*/
|
|
105
230
|
readonly FirmwareUpdateLimitOneDevice: 409;
|
|
231
|
+
/**
|
|
232
|
+
* You need to manually enter boot
|
|
233
|
+
*/
|
|
106
234
|
readonly FirmwareUpdateManuallyEnterBoot: 410;
|
|
235
|
+
/**
|
|
236
|
+
* Manual entry fails. You must manually enter the boot
|
|
237
|
+
*/
|
|
107
238
|
readonly FirmwareUpdateAutoEnterBootFailure: 411;
|
|
239
|
+
/**
|
|
240
|
+
* The new firmware has not been released yet
|
|
241
|
+
*/
|
|
108
242
|
readonly NewFirmwareUnRelease: 412;
|
|
243
|
+
/**
|
|
244
|
+
* use OneKey desktop client to update the firmware
|
|
245
|
+
* because need copy resource file to Touch
|
|
246
|
+
*/
|
|
109
247
|
readonly UseDesktopToUpdateFirmware: 413;
|
|
248
|
+
/**
|
|
249
|
+
* Mandatory firmware update
|
|
250
|
+
* @params:{ connectId: string? , deviceId: string? }
|
|
251
|
+
*/
|
|
110
252
|
readonly NewFirmwareForceUpdate: 414;
|
|
253
|
+
/**
|
|
254
|
+
* Device not support this method
|
|
255
|
+
*/
|
|
111
256
|
readonly DeviceNotSupportMethod: 415;
|
|
257
|
+
/**
|
|
258
|
+
* Forbidden key path
|
|
259
|
+
*/
|
|
112
260
|
readonly ForbiddenKeyPath: 416;
|
|
261
|
+
/**
|
|
262
|
+
* Repeat unlocking
|
|
263
|
+
* all network get address by loop need repeat unlocking
|
|
264
|
+
*/
|
|
113
265
|
readonly RepeatUnlocking: 417;
|
|
266
|
+
/**
|
|
267
|
+
* Defective firmware detected
|
|
268
|
+
*/
|
|
114
269
|
readonly DefectiveFirmware: 418;
|
|
270
|
+
/**
|
|
271
|
+
* Netword request error
|
|
272
|
+
*/
|
|
115
273
|
readonly NetworkError: 500;
|
|
274
|
+
/**
|
|
275
|
+
* Transport not configured
|
|
276
|
+
*/
|
|
116
277
|
readonly TransportNotConfigured: 600;
|
|
278
|
+
/**
|
|
279
|
+
* Transport call in progress
|
|
280
|
+
*/
|
|
117
281
|
readonly TransportCallInProgress: 601;
|
|
282
|
+
/**
|
|
283
|
+
* Transport not found
|
|
284
|
+
*/
|
|
118
285
|
readonly TransportNotFound: 602;
|
|
286
|
+
/**
|
|
287
|
+
* Transport invalid protobuf
|
|
288
|
+
*/
|
|
119
289
|
readonly TransportInvalidProtobuf: 603;
|
|
290
|
+
/**
|
|
291
|
+
* Bluetooth error code
|
|
292
|
+
*/
|
|
120
293
|
readonly BleScanError: 700;
|
|
121
294
|
readonly BlePermissionError: 701;
|
|
122
295
|
readonly BleLocationError: 702;
|
|
@@ -140,37 +313,143 @@ declare const HardwareErrorCode: {
|
|
|
140
313
|
readonly BleDeviceDisconnected: 720;
|
|
141
314
|
readonly BlePoweredOff: 721;
|
|
142
315
|
readonly BleUnsupported: 722;
|
|
316
|
+
/**
|
|
317
|
+
* Hardware runtiome errors
|
|
318
|
+
*/
|
|
143
319
|
readonly RuntimeError: 800;
|
|
320
|
+
/**
|
|
321
|
+
* invalid pin
|
|
322
|
+
*/
|
|
144
323
|
readonly PinInvalid: 801;
|
|
324
|
+
/**
|
|
325
|
+
* pin cancelled by user
|
|
326
|
+
*/
|
|
145
327
|
readonly PinCancelled: 802;
|
|
328
|
+
/**
|
|
329
|
+
* Action cancelled by user
|
|
330
|
+
*/
|
|
146
331
|
readonly ActionCancelled: 803;
|
|
332
|
+
/**
|
|
333
|
+
* Firmware installation failed
|
|
334
|
+
*/
|
|
147
335
|
readonly FirmwareError: 804;
|
|
336
|
+
/**
|
|
337
|
+
* transport response unexpect error
|
|
338
|
+
*/
|
|
148
339
|
readonly ResponseUnexpectTypeError: 805;
|
|
340
|
+
/**
|
|
341
|
+
* bridge network error
|
|
342
|
+
*/
|
|
149
343
|
readonly BridgeNetworkError: 806;
|
|
344
|
+
/**
|
|
345
|
+
* Bridge network timeout
|
|
346
|
+
*/
|
|
150
347
|
readonly BridgeTimeoutError: 807;
|
|
348
|
+
/**
|
|
349
|
+
* Bridge not installed
|
|
350
|
+
*/
|
|
151
351
|
readonly BridgeNotInstalled: 808;
|
|
352
|
+
/**
|
|
353
|
+
* ensure connect timeout
|
|
354
|
+
*/
|
|
152
355
|
readonly PollingTimeout: 809;
|
|
356
|
+
/**
|
|
357
|
+
* ensure connect stop polling
|
|
358
|
+
*/
|
|
153
359
|
readonly PollingStop: 810;
|
|
360
|
+
/**
|
|
361
|
+
* Device does not open blid sign
|
|
362
|
+
*/
|
|
154
363
|
readonly BlindSignDisabled: 811;
|
|
155
364
|
readonly UnexpectPassphrase: 812;
|
|
365
|
+
/**
|
|
366
|
+
* NFT file already exists
|
|
367
|
+
*/
|
|
156
368
|
readonly FileAlreadyExists: 813;
|
|
369
|
+
/**
|
|
370
|
+
* check file length error
|
|
371
|
+
*/
|
|
157
372
|
readonly CheckDownloadFileError: 814;
|
|
373
|
+
/**
|
|
374
|
+
* not in signing mode
|
|
375
|
+
*/
|
|
158
376
|
readonly NotInSigningMode: 815;
|
|
377
|
+
/**
|
|
378
|
+
* not in signing mode
|
|
379
|
+
*/
|
|
159
380
|
readonly DataOverload: 816;
|
|
381
|
+
/**
|
|
382
|
+
* device disconnected during action
|
|
383
|
+
*/
|
|
160
384
|
readonly BridgeDeviceDisconnected: 817;
|
|
385
|
+
/**
|
|
386
|
+
* BTC PSBT too many utxos
|
|
387
|
+
* @params:{ count: number }
|
|
388
|
+
*/
|
|
161
389
|
readonly BTCPsbtTooManyUtxos: 818;
|
|
390
|
+
/**
|
|
391
|
+
* EMMC file write firmware error
|
|
392
|
+
*/
|
|
162
393
|
readonly EmmcFileWriteFirmwareError: 819;
|
|
394
|
+
/**
|
|
395
|
+
* Firmware verification failed (e.g., bootloader file verify failed)
|
|
396
|
+
*/
|
|
163
397
|
readonly FirmwareVerificationFailed: 820;
|
|
398
|
+
/**
|
|
399
|
+
* Web bridge coonect needs permission
|
|
400
|
+
*/
|
|
164
401
|
readonly BridgeNeedsPermission: 821;
|
|
165
402
|
readonly CallQueueActionCancelled: 822;
|
|
403
|
+
/**
|
|
404
|
+
* Firmware downgrade not allowed
|
|
405
|
+
*/
|
|
166
406
|
readonly FirmwareDowngradeNotAllowed: 823;
|
|
407
|
+
/**
|
|
408
|
+
* Cosmos invalid JSON message, Only support Amino msgs.
|
|
409
|
+
*/
|
|
167
410
|
readonly CosmosInvalidJsonMessage: 824;
|
|
411
|
+
/**
|
|
412
|
+
* No setting provided
|
|
413
|
+
*/
|
|
168
414
|
readonly DeviceSettingsNotProvided: 825;
|
|
415
|
+
/**
|
|
416
|
+
* Language not supported
|
|
417
|
+
*/
|
|
169
418
|
readonly DeviceSettingsLanguageNotSupport: 826;
|
|
419
|
+
/**
|
|
420
|
+
* Too many inputs
|
|
421
|
+
* @params: { count?: string }
|
|
422
|
+
*/
|
|
170
423
|
readonly TooManyInputs: 827;
|
|
424
|
+
/**
|
|
425
|
+
* The two PIN entries did not match while setting/changing PIN on device
|
|
426
|
+
*/
|
|
171
427
|
readonly PinMismatch: 828;
|
|
428
|
+
/**
|
|
429
|
+
* Device refused to sign: refTxs don't match the spent input's outpoint
|
|
430
|
+
*/
|
|
431
|
+
readonly KaspaPrevTxIdMismatch: 829;
|
|
432
|
+
/**
|
|
433
|
+
* Protocol V2 device must be unlocked before the requested operation.
|
|
434
|
+
* @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
|
|
435
|
+
*/
|
|
436
|
+
readonly DeviceLocked: 830;
|
|
437
|
+
/**
|
|
438
|
+
* The cached wallet session is invalid or has expired.
|
|
439
|
+
* @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
|
|
440
|
+
*/
|
|
441
|
+
readonly WalletSessionInvalid: 831;
|
|
442
|
+
/**
|
|
443
|
+
* Lowlevel transport connect error
|
|
444
|
+
*/
|
|
172
445
|
readonly LowlevelTrasnportConnectError: 900;
|
|
446
|
+
/**
|
|
447
|
+
* Web USB or Web Bluetooth device not found or needs permission
|
|
448
|
+
*/
|
|
173
449
|
readonly WebDeviceNotFoundOrNeedsPermission: 901;
|
|
450
|
+
/**
|
|
451
|
+
* Web USB or Web Bluetooth device prompt access error
|
|
452
|
+
*/
|
|
174
453
|
readonly WebDevicePromptAccessError: 902;
|
|
175
454
|
};
|
|
176
455
|
declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
|
|
@@ -245,4 +524,4 @@ declare enum EDeviceType {
|
|
|
245
524
|
Pro2 = "pro2"
|
|
246
525
|
}
|
|
247
526
|
|
|
248
|
-
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HARDWARE_CONNECT_PROTOCOL, HardwareConnectProtocol, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, isHeaderChunk, isOnekeyDevice, serializeError, wait };
|
|
527
|
+
export { CreateErrorByMessage, CreateHardwareErrorByBridgeError, Deferred, EDeviceType, EFirmwareType, EOneKeyBleMessageKeys, HardwareError$1 as ERRORS, ERROR_CODES_REQUIRE_DISCONNECT, ERROR_CODES_REQUIRE_RELEASE, HARDWARE_CONNECT_PROTOCOL, HardwareConnectProtocol, HardwareError, HardwareErrorCode, HardwareErrorCodeMessage, IHardwareError, ONEKEY_NOTIFY_CHARACTERISTIC_UUID, ONEKEY_SERVICE_UUID, ONEKEY_WEBUSB_FILTER, ONEKEY_WRITE_CHARACTERISTIC_UUID, TypedError, createDefectiveFirmwareError, createDeferred, createDeprecatedHardwareError, createDeviceNotSupportMethodError, createKnownBleUuidAliases, createNeedUpgradeFirmwareHardwareError, createNewFirmwareForceUpdateHardwareError, createNewFirmwareUnReleaseHardwareError, hasOnekeyCommunicationService, isHeaderChunk, isKnownTrezorWebUsbDevice, isOnekeyBluetoothDevice, isOnekeyDevice, matchesKnownBleUuid, normalizeBleUuid, serializeError, wait };
|
package/dist/index.js
CHANGED
|
@@ -164,6 +164,9 @@ const HardwareErrorCode = {
|
|
|
164
164
|
DeviceSettingsLanguageNotSupport: 826,
|
|
165
165
|
TooManyInputs: 827,
|
|
166
166
|
PinMismatch: 828,
|
|
167
|
+
KaspaPrevTxIdMismatch: 829,
|
|
168
|
+
DeviceLocked: 830,
|
|
169
|
+
WalletSessionInvalid: 831,
|
|
167
170
|
LowlevelTrasnportConnectError: 900,
|
|
168
171
|
WebDeviceNotFoundOrNeedsPermission: 901,
|
|
169
172
|
WebDevicePromptAccessError: 902,
|
|
@@ -268,6 +271,9 @@ const HardwareErrorCodeMessage = {
|
|
|
268
271
|
[HardwareErrorCode.DeviceSettingsLanguageNotSupport]: 'Language not supported',
|
|
269
272
|
[HardwareErrorCode.TooManyInputs]: 'Too many inputs',
|
|
270
273
|
[HardwareErrorCode.PinMismatch]: 'PIN mismatch',
|
|
274
|
+
[HardwareErrorCode.DeviceLocked]: 'Device locked',
|
|
275
|
+
[HardwareErrorCode.KaspaPrevTxIdMismatch]: 'Kaspa previous transaction id mismatch',
|
|
276
|
+
[HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
|
|
271
277
|
[HardwareErrorCode.LowlevelTrasnportConnectError]: 'Lowlevel transport connect error',
|
|
272
278
|
[HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission]: 'Web-USB or Web-Bluetooth device not found or needs permission',
|
|
273
279
|
[HardwareErrorCode.WebDevicePromptAccessError]: 'Web-USB or Web-Bluetooth device prompt access error',
|
|
@@ -391,6 +397,15 @@ const ONEKEY_WEBUSB_FILTER = [
|
|
|
391
397
|
{ vendorId: 0x1209, productId: 0x4f4b },
|
|
392
398
|
{ vendorId: 0x1209, productId: 0x4f4c },
|
|
393
399
|
];
|
|
400
|
+
const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
|
|
401
|
+
const isKnownTrezorWebUsbDevice = (descriptor) => {
|
|
402
|
+
var _a;
|
|
403
|
+
const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId);
|
|
404
|
+
if (!isSharedWebUsbId)
|
|
405
|
+
return false;
|
|
406
|
+
const manufacturerName = (_a = descriptor.manufacturerName) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
|
|
407
|
+
return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
|
|
408
|
+
};
|
|
394
409
|
const ERROR_CODES_REQUIRE_RELEASE = [
|
|
395
410
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
396
411
|
HardwareErrorCode.DeviceInterruptedFromOutside,
|
|
@@ -446,16 +461,73 @@ const isHeaderChunk = (chunk) => {
|
|
|
446
461
|
}
|
|
447
462
|
return false;
|
|
448
463
|
};
|
|
464
|
+
const isKnownNonOneKeyDeviceName = (normalizedName) => normalizedName.startsWith('trezor') ||
|
|
465
|
+
normalizedName.startsWith('ledger') ||
|
|
466
|
+
normalizedName.startsWith('nano ') ||
|
|
467
|
+
normalizedName.startsWith('stax') ||
|
|
468
|
+
normalizedName.startsWith('flex');
|
|
469
|
+
const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
|
|
470
|
+
const isOneKeyShortName = (normalizedName) => {
|
|
471
|
+
if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName))
|
|
472
|
+
return true;
|
|
473
|
+
if (normalizedName.length !== 5)
|
|
474
|
+
return false;
|
|
475
|
+
const firstChar = normalizedName[0];
|
|
476
|
+
return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
|
|
477
|
+
};
|
|
449
478
|
const isOnekeyDevice = (name, id) => {
|
|
450
|
-
var _a;
|
|
451
|
-
|
|
479
|
+
var _a, _b;
|
|
480
|
+
const normalizedName = (_a = name === null || name === void 0 ? void 0 : name.trim().toLowerCase()) !== null && _a !== void 0 ? _a : '';
|
|
481
|
+
if (isKnownNonOneKeyDeviceName(normalizedName)) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
if ((_b = id === null || id === void 0 ? void 0 : id.startsWith) === null || _b === void 0 ? void 0 : _b.call(id, 'MI')) {
|
|
452
485
|
return true;
|
|
453
486
|
}
|
|
454
|
-
|
|
455
|
-
|
|
487
|
+
if (!name) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey'))
|
|
491
|
+
return true;
|
|
492
|
+
if (normalizedName.startsWith('touch ') ||
|
|
493
|
+
normalizedName.startsWith('pro ') ||
|
|
494
|
+
normalizedName.startsWith('pro2 ')) {
|
|
456
495
|
return true;
|
|
457
496
|
}
|
|
458
|
-
return
|
|
497
|
+
return isOneKeyShortName(normalizedName);
|
|
498
|
+
};
|
|
499
|
+
const BLUETOOTH_BASE_UUID_SUFFIX = '00001000800000805f9b34fb';
|
|
500
|
+
const normalizeBleUuid = (uuid) => (uuid !== null && uuid !== void 0 ? uuid : '').replace(/-/g, '').toLowerCase();
|
|
501
|
+
const createKnownBleUuidAliases = (uuid) => {
|
|
502
|
+
const normalized = normalizeBleUuid(uuid);
|
|
503
|
+
const aliases = new Set([normalized]);
|
|
504
|
+
if (normalized.length !== 32 || !normalized.endsWith(BLUETOOTH_BASE_UUID_SUFFIX)) {
|
|
505
|
+
return aliases;
|
|
506
|
+
}
|
|
507
|
+
const assignedNumber = normalized.slice(0, 8);
|
|
508
|
+
aliases.add(assignedNumber);
|
|
509
|
+
if (assignedNumber.startsWith('0000')) {
|
|
510
|
+
aliases.add(assignedNumber.slice(4));
|
|
511
|
+
}
|
|
512
|
+
return aliases;
|
|
513
|
+
};
|
|
514
|
+
const matchesKnownBleUuid = (actualUuid, aliases) => aliases.has(normalizeBleUuid(actualUuid));
|
|
515
|
+
const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
|
|
516
|
+
const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
|
|
517
|
+
const isFindMyAdvertisementName = (value) => { var _a; return /\bfinde?\s+my\b/.test((_a = value === null || value === void 0 ? void 0 : value.trim().toLowerCase()) !== null && _a !== void 0 ? _a : ''); };
|
|
518
|
+
const hasOnekeyCommunicationService = (serviceUuids) => (serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : []).some(uuid => matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES));
|
|
519
|
+
const isOnekeyBluetoothDevice = ({ id, name, localName, serviceUuids, }) => {
|
|
520
|
+
const advertisedServiceUuids = serviceUuids !== null && serviceUuids !== void 0 ? serviceUuids : [];
|
|
521
|
+
if (isFindMyAdvertisementName(name) || isFindMyAdvertisementName(localName)) {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
if (advertisedServiceUuids.some(uuid => matchesKnownBleUuid(uuid, FIDO_SERVICE_ALIASES))) {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
return isOnekeyDevice(name !== null && name !== void 0 ? name : null, id) || isOnekeyDevice(localName !== null && localName !== void 0 ? localName : null, id);
|
|
459
531
|
};
|
|
460
532
|
|
|
461
533
|
/******************************************************************************
|
|
@@ -549,10 +621,16 @@ exports.createDefectiveFirmwareError = createDefectiveFirmwareError;
|
|
|
549
621
|
exports.createDeferred = createDeferred;
|
|
550
622
|
exports.createDeprecatedHardwareError = createDeprecatedHardwareError;
|
|
551
623
|
exports.createDeviceNotSupportMethodError = createDeviceNotSupportMethodError;
|
|
624
|
+
exports.createKnownBleUuidAliases = createKnownBleUuidAliases;
|
|
552
625
|
exports.createNeedUpgradeFirmwareHardwareError = createNeedUpgradeFirmwareHardwareError;
|
|
553
626
|
exports.createNewFirmwareForceUpdateHardwareError = createNewFirmwareForceUpdateHardwareError;
|
|
554
627
|
exports.createNewFirmwareUnReleaseHardwareError = createNewFirmwareUnReleaseHardwareError;
|
|
628
|
+
exports.hasOnekeyCommunicationService = hasOnekeyCommunicationService;
|
|
555
629
|
exports.isHeaderChunk = isHeaderChunk;
|
|
630
|
+
exports.isKnownTrezorWebUsbDevice = isKnownTrezorWebUsbDevice;
|
|
631
|
+
exports.isOnekeyBluetoothDevice = isOnekeyBluetoothDevice;
|
|
556
632
|
exports.isOnekeyDevice = isOnekeyDevice;
|
|
633
|
+
exports.matchesKnownBleUuid = matchesKnownBleUuid;
|
|
634
|
+
exports.normalizeBleUuid = normalizeBleUuid;
|
|
557
635
|
exports.serializeError = serializeError;
|
|
558
636
|
exports.wait = wait;
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-shared",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.62",
|
|
4
4
|
"description": "Hardware SDK's shared tool library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Hardware-SDK",
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
|
|
24
24
|
"build": "rimraf dist && rollup -c ../../build/rollup.config.js",
|
|
25
|
+
"test": "jest",
|
|
25
26
|
"lint": "eslint .",
|
|
26
27
|
"lint:fix": "eslint . --fix"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "f38f4fc8bf05aea42a4da5b2bd633544597ad958"
|
|
29
30
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HardwareErrorCode } from './HardwareError';
|
|
2
|
+
|
|
3
|
+
describe('HardwareErrorCode compatibility', () => {
|
|
4
|
+
test('preserves published values when adding Protocol V2 errors', () => {
|
|
5
|
+
expect(HardwareErrorCode.KaspaPrevTxIdMismatch).toBe(829);
|
|
6
|
+
expect(HardwareErrorCode.DeviceLocked).toBe(830);
|
|
7
|
+
expect(HardwareErrorCode.WalletSessionInvalid).toBe(831);
|
|
8
|
+
});
|
|
9
|
+
});
|
package/src/HardwareError.ts
CHANGED
|
@@ -484,6 +484,23 @@ export const HardwareErrorCode = {
|
|
|
484
484
|
*/
|
|
485
485
|
PinMismatch: 828,
|
|
486
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Device refused to sign: refTxs don't match the spent input's outpoint
|
|
489
|
+
*/
|
|
490
|
+
KaspaPrevTxIdMismatch: 829,
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Protocol V2 device must be unlocked before the requested operation.
|
|
494
|
+
* @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
|
|
495
|
+
*/
|
|
496
|
+
DeviceLocked: 830,
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* The cached wallet session is invalid or has expired.
|
|
500
|
+
* @params: { failureCode?: string; subcode?: number; firmwareMessage?: string }
|
|
501
|
+
*/
|
|
502
|
+
WalletSessionInvalid: 831,
|
|
503
|
+
|
|
487
504
|
/**
|
|
488
505
|
* Lowlevel transport connect error
|
|
489
506
|
*/
|
|
@@ -635,6 +652,9 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
|
|
|
635
652
|
[HardwareErrorCode.DeviceSettingsLanguageNotSupport]: 'Language not supported',
|
|
636
653
|
[HardwareErrorCode.TooManyInputs]: 'Too many inputs',
|
|
637
654
|
[HardwareErrorCode.PinMismatch]: 'PIN mismatch',
|
|
655
|
+
[HardwareErrorCode.DeviceLocked]: 'Device locked',
|
|
656
|
+
[HardwareErrorCode.KaspaPrevTxIdMismatch]: 'Kaspa previous transaction id mismatch',
|
|
657
|
+
[HardwareErrorCode.WalletSessionInvalid]: 'Wallet session is invalid or expired',
|
|
638
658
|
|
|
639
659
|
/**
|
|
640
660
|
* Lowlevel transport
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createKnownBleUuidAliases,
|
|
3
|
+
hasOnekeyCommunicationService,
|
|
4
|
+
isKnownTrezorWebUsbDevice,
|
|
5
|
+
isOnekeyBluetoothDevice,
|
|
6
|
+
isOnekeyDevice,
|
|
7
|
+
matchesKnownBleUuid,
|
|
8
|
+
} from './constants';
|
|
9
|
+
|
|
10
|
+
describe('hardware device identity filters', () => {
|
|
11
|
+
it('accepts known OneKey BLE names', () => {
|
|
12
|
+
expect(isOnekeyDevice('Touch A1B2')).toBe(true);
|
|
13
|
+
expect(isOnekeyDevice('Pro A1B2')).toBe(true);
|
|
14
|
+
expect(isOnekeyDevice('K1234')).toBe(true);
|
|
15
|
+
expect(isOnekeyDevice('S8')).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('rejects known Trezor and Ledger BLE names from OneKey discovery', () => {
|
|
19
|
+
expect(isOnekeyDevice('Trezor Safe 7')).toBe(false);
|
|
20
|
+
expect(isOnekeyDevice('Ledger Nano X')).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('does not identify an unnamed FFFD or Find My advertisement as OneKey', () => {
|
|
24
|
+
expect(isOnekeyBluetoothDevice({ name: 'Find My', serviceUuids: ['fffd'] })).toBe(false);
|
|
25
|
+
expect(
|
|
26
|
+
isOnekeyBluetoothDevice({ serviceUuids: ['0000fffd-0000-1000-8000-00805f9b34fb'] })
|
|
27
|
+
).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('keeps Pro2 communication advertisements and rejects its Find My advertisement', () => {
|
|
31
|
+
expect(
|
|
32
|
+
isOnekeyBluetoothDevice({
|
|
33
|
+
name: 'Pro2 A1B2',
|
|
34
|
+
serviceUuids: ['0001', 'fffd'],
|
|
35
|
+
})
|
|
36
|
+
).toBe(true);
|
|
37
|
+
expect(
|
|
38
|
+
isOnekeyBluetoothDevice({
|
|
39
|
+
localName: 'Pro2 A1B2 - Find My',
|
|
40
|
+
serviceUuids: ['fffd'],
|
|
41
|
+
})
|
|
42
|
+
).toBe(false);
|
|
43
|
+
expect(
|
|
44
|
+
isOnekeyBluetoothDevice({
|
|
45
|
+
name: 'Pro2 5E9D - Finde My',
|
|
46
|
+
serviceUuids: ['0001', 'fffd'],
|
|
47
|
+
})
|
|
48
|
+
).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('keeps OneKey discovery on the communication service', () => {
|
|
52
|
+
expect(
|
|
53
|
+
isOnekeyBluetoothDevice({
|
|
54
|
+
name: 'OneKey Pro 2',
|
|
55
|
+
serviceUuids: ['00000001-0000-1000-8000-00805f9b34fb'],
|
|
56
|
+
})
|
|
57
|
+
).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('only aliases standard Bluetooth Base UUID representations', () => {
|
|
61
|
+
const aliases = createKnownBleUuidAliases('00000001-0000-1000-8000-00805f9b34fb');
|
|
62
|
+
|
|
63
|
+
expect(matchesKnownBleUuid('0001', aliases)).toBe(true);
|
|
64
|
+
expect(matchesKnownBleUuid('00000001', aliases)).toBe(true);
|
|
65
|
+
expect(matchesKnownBleUuid('abcd0001-1234-5678-9012-abcdefabcdef', aliases)).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('does not treat vendor-specific UUID fragments as communication or FIDO services', () => {
|
|
69
|
+
expect(
|
|
70
|
+
isOnekeyBluetoothDevice({
|
|
71
|
+
name: 'OneKey Pro 2',
|
|
72
|
+
serviceUuids: ['abcdfffd-1234-5678-9012-abcdefabcdef'],
|
|
73
|
+
})
|
|
74
|
+
).toBe(true);
|
|
75
|
+
expect(
|
|
76
|
+
isOnekeyBluetoothDevice({
|
|
77
|
+
serviceUuids: ['abcd0001-1234-5678-9012-abcdefabcdef'],
|
|
78
|
+
})
|
|
79
|
+
).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('requires an explicitly advertised communication service for strict discovery', () => {
|
|
83
|
+
expect(hasOnekeyCommunicationService([])).toBe(false);
|
|
84
|
+
expect(hasOnekeyCommunicationService(['0001'])).toBe(true);
|
|
85
|
+
expect(hasOnekeyCommunicationService(['abcd0001-1234-5678-9012-abcdefabcdef'])).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('only filters WebUSB descriptors that are explicitly identified as Trezor', () => {
|
|
89
|
+
expect(
|
|
90
|
+
isKnownTrezorWebUsbDevice({
|
|
91
|
+
vendorId: 0x1209,
|
|
92
|
+
productId: 0x53c1,
|
|
93
|
+
manufacturerName: 'Trezor Company',
|
|
94
|
+
})
|
|
95
|
+
).toBe(true);
|
|
96
|
+
expect(
|
|
97
|
+
isKnownTrezorWebUsbDevice({
|
|
98
|
+
vendorId: 0x1209,
|
|
99
|
+
productId: 0x53c1,
|
|
100
|
+
manufacturerName: 'Trezor',
|
|
101
|
+
})
|
|
102
|
+
).toBe(true);
|
|
103
|
+
expect(
|
|
104
|
+
isKnownTrezorWebUsbDevice({
|
|
105
|
+
vendorId: 0x1209,
|
|
106
|
+
productId: 0x53c1,
|
|
107
|
+
manufacturerName: 'SatoshiLabs',
|
|
108
|
+
})
|
|
109
|
+
).toBe(true);
|
|
110
|
+
|
|
111
|
+
expect(
|
|
112
|
+
isKnownTrezorWebUsbDevice({
|
|
113
|
+
vendorId: 0x1209,
|
|
114
|
+
productId: 0x53c1,
|
|
115
|
+
manufacturerName: 'OneKey',
|
|
116
|
+
})
|
|
117
|
+
).toBe(false);
|
|
118
|
+
expect(
|
|
119
|
+
isKnownTrezorWebUsbDevice({
|
|
120
|
+
vendorId: 0x1209,
|
|
121
|
+
productId: 0x53c1,
|
|
122
|
+
})
|
|
123
|
+
).toBe(false);
|
|
124
|
+
expect(
|
|
125
|
+
isKnownTrezorWebUsbDevice({
|
|
126
|
+
vendorId: 0x1209,
|
|
127
|
+
productId: 0x53c1,
|
|
128
|
+
productName: 'Trezor Safe 7',
|
|
129
|
+
})
|
|
130
|
+
).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
});
|
package/src/constants.ts
CHANGED
|
@@ -10,13 +10,31 @@ export type HardwareConnectProtocol =
|
|
|
10
10
|
|
|
11
11
|
export const ONEKEY_WEBUSB_FILTER = [
|
|
12
12
|
{ vendorId: 0x1209, productId: 0x53c0 }, // Classic Boot、Classic1s Boot、Mini Boot
|
|
13
|
-
{ vendorId: 0x1209, productId: 0x53c1 }, // Classic
|
|
14
|
-
{ vendorId: 0x1209, productId: 0x4f4a }, // Pro
|
|
15
|
-
{ vendorId: 0x1209, productId: 0x4f4b }, // Pro
|
|
16
|
-
{ vendorId: 0x1209, productId: 0x4f4c }, // Pro
|
|
13
|
+
{ vendorId: 0x1209, productId: 0x53c1 }, // Classic/Classic1s/Mini/Pro/Touch firmware and legacy Pro2; keep for existing devices
|
|
14
|
+
{ vendorId: 0x1209, productId: 0x4f4a }, // Pro bootloader, Touch bootloader, Pro2
|
|
15
|
+
{ vendorId: 0x1209, productId: 0x4f4b }, // Pro/Touch firmware (Trezor not implemented), Pro2
|
|
16
|
+
{ vendorId: 0x1209, productId: 0x4f4c }, // Pro board and Pro2 with the new firmware PID
|
|
17
17
|
// { vendorId: 0x1209, productId: 0x4f50 }, // Touch Board
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
+
type WebUsbIdentityDescriptor = {
|
|
21
|
+
vendorId?: number;
|
|
22
|
+
productId?: number;
|
|
23
|
+
manufacturerName?: string | null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const TREZOR_WEBUSB_MANUFACTURER_NAMES = new Set(['trezor', 'trezor company', 'satoshilabs']);
|
|
27
|
+
|
|
28
|
+
export const isKnownTrezorWebUsbDevice = (descriptor: WebUsbIdentityDescriptor): boolean => {
|
|
29
|
+
const isSharedWebUsbId = ONEKEY_WEBUSB_FILTER.some(
|
|
30
|
+
filter => descriptor.vendorId === filter.vendorId && descriptor.productId === filter.productId
|
|
31
|
+
);
|
|
32
|
+
if (!isSharedWebUsbId) return false;
|
|
33
|
+
|
|
34
|
+
const manufacturerName = descriptor.manufacturerName?.trim().toLowerCase();
|
|
35
|
+
return manufacturerName != null && TREZOR_WEBUSB_MANUFACTURER_NAMES.has(manufacturerName);
|
|
36
|
+
};
|
|
37
|
+
|
|
20
38
|
/**
|
|
21
39
|
* Error codes that require device release after occurrence
|
|
22
40
|
* These errors indicate the device is in an invalid state and needs to be released
|
|
@@ -97,16 +115,110 @@ export const isHeaderChunk = (chunk: Buffer | Uint8Array): boolean => {
|
|
|
97
115
|
return false;
|
|
98
116
|
};
|
|
99
117
|
|
|
118
|
+
const isKnownNonOneKeyDeviceName = (normalizedName: string): boolean =>
|
|
119
|
+
normalizedName.startsWith('trezor') ||
|
|
120
|
+
normalizedName.startsWith('ledger') ||
|
|
121
|
+
normalizedName.startsWith('nano ') ||
|
|
122
|
+
normalizedName.startsWith('stax') ||
|
|
123
|
+
normalizedName.startsWith('flex');
|
|
124
|
+
|
|
125
|
+
const ONEKEY_EXACT_SHORT_NAMES = new Set(['s8']);
|
|
126
|
+
|
|
127
|
+
const isOneKeyShortName = (normalizedName: string): boolean => {
|
|
128
|
+
if (ONEKEY_EXACT_SHORT_NAMES.has(normalizedName)) return true;
|
|
129
|
+
if (normalizedName.length !== 5) return false;
|
|
130
|
+
const firstChar = normalizedName[0];
|
|
131
|
+
return (firstChar === 'k' || firstChar === 't') && /^\d{4}$/.test(normalizedName.slice(1));
|
|
132
|
+
};
|
|
133
|
+
|
|
100
134
|
export const isOnekeyDevice = (name: string | null, id?: string): boolean => {
|
|
135
|
+
const normalizedName = name?.trim().toLowerCase() ?? '';
|
|
136
|
+
if (isKnownNonOneKeyDeviceName(normalizedName)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
101
140
|
if (id?.startsWith?.('MI')) {
|
|
102
141
|
return true;
|
|
103
142
|
}
|
|
104
143
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
144
|
+
if (!name) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (normalizedName.startsWith('onekey') || normalizedName.startsWith('bixinkey')) return true;
|
|
148
|
+
if (
|
|
149
|
+
normalizedName.startsWith('touch ') ||
|
|
150
|
+
normalizedName.startsWith('pro ') ||
|
|
151
|
+
normalizedName.startsWith('pro2 ')
|
|
152
|
+
) {
|
|
109
153
|
return true;
|
|
110
154
|
}
|
|
111
|
-
return
|
|
155
|
+
return isOneKeyShortName(normalizedName);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type BluetoothDeviceIdentity = {
|
|
159
|
+
id?: string;
|
|
160
|
+
name?: string | null;
|
|
161
|
+
localName?: string | null;
|
|
162
|
+
serviceUuids?: Array<string | null | undefined> | null;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const BLUETOOTH_BASE_UUID_SUFFIX = '00001000800000805f9b34fb';
|
|
166
|
+
|
|
167
|
+
export const normalizeBleUuid = (uuid?: string | null) =>
|
|
168
|
+
(uuid ?? '').replace(/-/g, '').toLowerCase();
|
|
169
|
+
|
|
170
|
+
export const createKnownBleUuidAliases = (uuid: string): ReadonlySet<string> => {
|
|
171
|
+
const normalized = normalizeBleUuid(uuid);
|
|
172
|
+
const aliases = new Set([normalized]);
|
|
173
|
+
|
|
174
|
+
if (normalized.length !== 32 || !normalized.endsWith(BLUETOOTH_BASE_UUID_SUFFIX)) {
|
|
175
|
+
return aliases;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const assignedNumber = normalized.slice(0, 8);
|
|
179
|
+
aliases.add(assignedNumber);
|
|
180
|
+
if (assignedNumber.startsWith('0000')) {
|
|
181
|
+
aliases.add(assignedNumber.slice(4));
|
|
182
|
+
}
|
|
183
|
+
return aliases;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const matchesKnownBleUuid = (
|
|
187
|
+
actualUuid: string | null | undefined,
|
|
188
|
+
aliases: ReadonlySet<string>
|
|
189
|
+
) => aliases.has(normalizeBleUuid(actualUuid));
|
|
190
|
+
|
|
191
|
+
const ONEKEY_COMMUNICATION_SERVICE_ALIASES = createKnownBleUuidAliases(ONEKEY_SERVICE_UUID);
|
|
192
|
+
const FIDO_SERVICE_ALIASES = createKnownBleUuidAliases('0000fffd-0000-1000-8000-00805f9b34fb');
|
|
193
|
+
|
|
194
|
+
const isFindMyAdvertisementName = (value?: string | null) =>
|
|
195
|
+
/\bfinde?\s+my\b/.test(value?.trim().toLowerCase() ?? '');
|
|
196
|
+
|
|
197
|
+
export const hasOnekeyCommunicationService = (
|
|
198
|
+
serviceUuids: Array<string | null | undefined> | null | undefined
|
|
199
|
+
) =>
|
|
200
|
+
(serviceUuids ?? []).some(uuid =>
|
|
201
|
+
matchesKnownBleUuid(uuid, ONEKEY_COMMUNICATION_SERVICE_ALIASES)
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
export const isOnekeyBluetoothDevice = ({
|
|
205
|
+
id,
|
|
206
|
+
name,
|
|
207
|
+
localName,
|
|
208
|
+
serviceUuids,
|
|
209
|
+
}: BluetoothDeviceIdentity): boolean => {
|
|
210
|
+
const advertisedServiceUuids = serviceUuids ?? [];
|
|
211
|
+
if (isFindMyAdvertisementName(name) || isFindMyAdvertisementName(localName)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (hasOnekeyCommunicationService(advertisedServiceUuids)) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (advertisedServiceUuids.some(uuid => matchesKnownBleUuid(uuid, FIDO_SERVICE_ALIASES))) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return isOnekeyDevice(name ?? null, id) || isOnekeyDevice(localName ?? null, id);
|
|
112
224
|
};
|