@onekeyfe/hd-core 1.2.8-alpha.2 → 1.2.8-alpha.4

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.
Files changed (48) hide show
  1. package/README.md +27 -0
  2. package/__tests__/DeviceCommands.test.ts +13 -66
  3. package/__tests__/btc-derive-context-hash.test.ts +175 -0
  4. package/__tests__/core-error-output.test.ts +3 -34
  5. package/__tests__/device-lifecycle-events.test.ts +17 -22
  6. package/__tests__/protocol-v2-bootloader-mode.test.ts +2 -31
  7. package/__tests__/protocol-v2.test.ts +47 -0
  8. package/__tests__/refresh-device-state.test.ts +17 -19
  9. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  10. package/dist/api/GetDeviceState.d.ts.map +1 -1
  11. package/dist/api/btc/BTCDeriveContextHash.d.ts +13 -0
  12. package/dist/api/btc/BTCDeriveContextHash.d.ts.map +1 -0
  13. package/dist/api/index.d.ts +1 -0
  14. package/dist/api/index.d.ts.map +1 -1
  15. package/dist/core/index.d.ts +1 -0
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/device/DeviceCommands.d.ts +4 -4
  18. package/dist/device/DeviceCommands.d.ts.map +1 -1
  19. package/dist/events/logBlockEvent.d.ts.map +1 -1
  20. package/dist/index.d.ts +14 -6
  21. package/dist/index.js +142 -21
  22. package/dist/inject.d.ts.map +1 -1
  23. package/dist/types/api/btcDeriveContextHash.d.ts +10 -0
  24. package/dist/types/api/btcDeriveContextHash.d.ts.map +1 -0
  25. package/dist/types/api/export.d.ts +1 -0
  26. package/dist/types/api/export.d.ts.map +1 -1
  27. package/dist/types/api/index.d.ts +2 -0
  28. package/dist/types/api/index.d.ts.map +1 -1
  29. package/dist/types/params.d.ts +0 -1
  30. package/dist/types/params.d.ts.map +1 -1
  31. package/dist/utils/patch.d.ts +1 -1
  32. package/dist/utils/patch.d.ts.map +1 -1
  33. package/package.json +4 -4
  34. package/src/api/FirmwareUpdateV4.ts +25 -8
  35. package/src/api/GetDeviceState.ts +5 -2
  36. package/src/api/btc/BTCDeriveContextHash.ts +87 -0
  37. package/src/api/index.ts +1 -0
  38. package/src/core/index.ts +6 -2
  39. package/src/data/messages/messages.json +51 -0
  40. package/src/device/Device.ts +1 -1
  41. package/src/device/DeviceCommands.ts +1 -15
  42. package/src/events/core.ts +2 -2
  43. package/src/events/logBlockEvent.ts +1 -0
  44. package/src/inject.ts +2 -0
  45. package/src/types/api/btcDeriveContextHash.ts +15 -0
  46. package/src/types/api/export.ts +1 -0
  47. package/src/types/api/index.ts +2 -0
  48. package/src/types/params.ts +1 -1
@@ -12485,6 +12485,8 @@
12485
12485
  "(has_bitcoin_only_values)": true
12486
12486
  },
12487
12487
  "values": {
12488
+ "MessageType_BabylonDeriveContextHash": 10054,
12489
+ "MessageType_BabylonDerivedContextHash": 10055,
12488
12490
  "MessageType_Initialize": 0,
12489
12491
  "MessageType_Ping": 1,
12490
12492
  "MessageType_Success": 2,
@@ -12949,6 +12951,55 @@
12949
12951
  "MessageType_UpgradeFileHeader": 10050
12950
12952
  }
12951
12953
  },
12954
+ "CanonicalBitcoinNetwork": {
12955
+ "values": {
12956
+ "BITCOIN_MAINNET": 0,
12957
+ "BITCOIN_TESTNET": 1,
12958
+ "BITCOIN_SIGNET": 2,
12959
+ "BITCOIN_REGTEST": 3
12960
+ }
12961
+ },
12962
+ "BabylonDeriveContextHash": {
12963
+ "fields": {
12964
+ "address_n": {
12965
+ "rule": "repeated",
12966
+ "type": "uint32",
12967
+ "id": 1,
12968
+ "options": {
12969
+ "packed": false
12970
+ }
12971
+ },
12972
+ "script_type": {
12973
+ "rule": "required",
12974
+ "type": "InputScriptType",
12975
+ "id": 2
12976
+ },
12977
+ "app_name": {
12978
+ "rule": "required",
12979
+ "type": "bytes",
12980
+ "id": 3
12981
+ },
12982
+ "context": {
12983
+ "rule": "required",
12984
+ "type": "bytes",
12985
+ "id": 4
12986
+ },
12987
+ "network": {
12988
+ "rule": "required",
12989
+ "type": "CanonicalBitcoinNetwork",
12990
+ "id": 5
12991
+ }
12992
+ }
12993
+ },
12994
+ "BabylonDerivedContextHash": {
12995
+ "fields": {
12996
+ "secret": {
12997
+ "rule": "required",
12998
+ "type": "bytes",
12999
+ "id": 1
13000
+ }
13001
+ }
13002
+ },
12952
13003
  "google": {
12953
13004
  "nested": {
12954
13005
  "protobuf": {
@@ -1801,7 +1801,7 @@ export class Device extends EventEmitter {
1801
1801
  // both allow and require cases might generate single unexpected mode
1802
1802
  if (!this.isUnacquired()) {
1803
1803
  // allow cases
1804
- if ((this.isBootloader() || this.isRomloader()) && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1804
+ if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1805
1805
  return UI_REQUEST.BOOTLOADER;
1806
1806
  }
1807
1807
  if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
@@ -549,16 +549,6 @@ export class DeviceCommands {
549
549
  this.device.isProtocolV2() &&
550
550
  DEVICE_CONTROL_CALLS.has(callType) &&
551
551
  subcode === DeviceErrorCode.DeviceError_Busy;
552
- const isProtocolV2PinCancelledBusyFailure =
553
- this.device.isProtocolV2() &&
554
- !DEVICE_SESSION_CALLS.has(callType) &&
555
- subcode === DeviceSessionErrorCode.DeviceSessionError_UserCancelled &&
556
- /^pin cancelled$/i.test(normalizedMessage);
557
- const isProtocolV2FirmwareUpdateBusyFailure =
558
- this.device.isProtocolV2() &&
559
- /^requested command not allowed while a firmware update is in progress$/i.test(
560
- normalizedMessage
561
- );
562
552
  const isLegacyProtocolV2LockedFailure =
563
553
  this.device.isProtocolV2() && /^device (?:is )?locked$/i.test(normalizedMessage);
564
554
  if (
@@ -616,11 +606,7 @@ export class DeviceCommands {
616
606
  subcode,
617
607
  firmwareMessage: message,
618
608
  });
619
- } else if (
620
- isProtocolV2DeviceBusyFailure ||
621
- isProtocolV2PinCancelledBusyFailure ||
622
- isProtocolV2FirmwareUpdateBusyFailure
623
- ) {
609
+ } else if (isProtocolV2DeviceBusyFailure) {
624
610
  error = ERRORS.TypedError(HardwareErrorCode.DeviceBusy, message, {
625
611
  failureCode: code,
626
612
  subcode,
@@ -54,9 +54,9 @@ export const parseMessage = (messageData: any): CoreMessage => {
54
54
  };
55
55
 
56
56
  export const createErrorMessage = (error: Error & { code?: string | number }): Unsuccessful => {
57
- let payload: Unsuccessful['payload'] = { error: error.message, code: error.code };
57
+ let payload = { error: error.message, code: error.code };
58
58
  if (error instanceof HardwareError) {
59
- payload = { error: error.message, code: error.errorCode, params: error.params };
59
+ payload = { error: error.message, code: error.errorCode };
60
60
  }
61
61
  return {
62
62
  success: false,
@@ -11,6 +11,7 @@ export const LogBlockEvent: Set<string> = new Set([
11
11
  // These resource/file APIs did not exist in 1.1.32. Skip the payload so
12
12
  // the log layer does not copy huge Base64 or binary data.
13
13
  const LogPayloadBlockMethod: Set<string> = new Set([
14
+ 'btcDeriveContextHash',
14
15
  'deviceUploadNft',
15
16
  'deviceUploadWallpaper',
16
17
  'uploadPortfolio',
package/src/inject.ts CHANGED
@@ -309,6 +309,8 @@ export const createCoreApi = (
309
309
  call({ ...params, connectId, deviceId, method: 'btcGetAddress' }),
310
310
  btcGetPublicKey: (connectId, deviceId, params) =>
311
311
  call({ ...params, connectId, deviceId, method: 'btcGetPublicKey' }),
312
+ btcDeriveContextHash: (connectId, deviceId, params) =>
313
+ call({ ...params, connectId, deviceId, method: 'btcDeriveContextHash' }),
312
314
  btcSignMessage: (connectId, deviceId, params) =>
313
315
  call({ ...params, connectId, deviceId, method: 'btcSignMessage' }),
314
316
  btcSignPsbt: (connectId, deviceId, params) =>
@@ -0,0 +1,15 @@
1
+ import type { BabylonDerivedContextHash } from '@onekeyfe/hd-transport';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type BTCDeriveContextHashParams = {
5
+ path: string | number[];
6
+ appName: string;
7
+ context: string;
8
+ network: 'bitcoin-mainnet' | 'bitcoin-testnet' | 'bitcoin-signet' | 'bitcoin-regtest';
9
+ };
10
+
11
+ export declare function btcDeriveContextHash(
12
+ connectId: string,
13
+ deviceId: string,
14
+ params: CommonParams & BTCDeriveContextHashParams
15
+ ): Response<BabylonDerivedContextHash>;
@@ -1,5 +1,6 @@
1
1
  export type { BTCAddress, BTCGetAddressParams } from './btcGetAddress';
2
2
  export type { BTCPublicKey, BTCGetPublicKeyParams } from './btcGetPublicKey';
3
+ export type { BTCDeriveContextHashParams } from './btcDeriveContextHash';
3
4
  export type { BTCSignMessageParams } from './btcSignMessage';
4
5
  export type { BTCVerifyMessageParams } from './btcVerifyMessage';
5
6
  export type {
@@ -73,6 +73,7 @@ import type { evmSignTypedData } from './evmSignTypedData';
73
73
  import type { evmVerifyMessage } from './evmVerifyMessage';
74
74
  import type { btcGetAddress } from './btcGetAddress';
75
75
  import type { btcGetPublicKey } from './btcGetPublicKey';
76
+ import type { btcDeriveContextHash } from './btcDeriveContextHash';
76
77
  import type { btcSignMessage } from './btcSignMessage';
77
78
  import type { btcSignPsbt } from './btcSignPsbt';
78
79
  import type { btcSignTransaction } from './btcSignTransaction';
@@ -286,6 +287,7 @@ export type CoreApi = {
286
287
  */
287
288
  btcGetAddress: typeof btcGetAddress;
288
289
  btcGetPublicKey: typeof btcGetPublicKey;
290
+ btcDeriveContextHash: typeof btcDeriveContextHash;
289
291
  btcSignMessage: typeof btcSignMessage;
290
292
  btcSignPsbt: typeof btcSignPsbt;
291
293
  btcSignTransaction: typeof btcSignTransaction;
@@ -83,7 +83,7 @@ export type Params<T> = CommonParams & T & { bundle?: undefined };
83
83
 
84
84
  export interface Unsuccessful {
85
85
  success: false;
86
- payload: { error: string; code?: string | number; params?: Record<string, unknown> };
86
+ payload: { error: string; code?: string | number };
87
87
  }
88
88
 
89
89
  export interface Success<T> {