@onekeyfe/hd-core 0.0.10 → 0.1.2

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 (85) hide show
  1. package/dist/api/BaseMethod.d.ts +2 -0
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/CheckBLEFirmwareRelease.d.ts +8 -1
  4. package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -1
  5. package/dist/api/CheckFirmwareRelease.d.ts +8 -1
  6. package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
  7. package/dist/api/FirmwareUpdate.d.ts +14 -0
  8. package/dist/api/FirmwareUpdate.d.ts.map +1 -0
  9. package/dist/api/firmware/getBinary.d.ts +33 -0
  10. package/dist/api/firmware/getBinary.d.ts.map +1 -0
  11. package/dist/api/firmware/uploadFirmware.d.ts +8 -0
  12. package/dist/api/firmware/uploadFirmware.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/api/stellar/StellarSignTransaction.d.ts +1 -1
  16. package/dist/constants/errors.d.ts +2 -0
  17. package/dist/constants/errors.d.ts.map +1 -1
  18. package/dist/core/index.d.ts +1 -0
  19. package/dist/core/index.d.ts.map +1 -1
  20. package/dist/data-manager/DataManager.d.ts +10 -0
  21. package/dist/data-manager/DataManager.d.ts.map +1 -1
  22. package/dist/device/Device.d.ts +3 -1
  23. package/dist/device/Device.d.ts.map +1 -1
  24. package/dist/device/DeviceCommands.d.ts +1 -0
  25. package/dist/device/DeviceCommands.d.ts.map +1 -1
  26. package/dist/device/DeviceList.d.ts.map +1 -1
  27. package/dist/events/call.d.ts +7 -0
  28. package/dist/events/call.d.ts.map +1 -1
  29. package/dist/events/core.d.ts +2 -2
  30. package/dist/events/core.d.ts.map +1 -1
  31. package/dist/events/iframe.d.ts +1 -0
  32. package/dist/events/iframe.d.ts.map +1 -1
  33. package/dist/events/ui-request.d.ts +9 -1
  34. package/dist/events/ui-request.d.ts.map +1 -1
  35. package/dist/index.d.ts +108 -9
  36. package/dist/index.js +269 -50
  37. package/dist/inject.d.ts.map +1 -1
  38. package/dist/types/api/checkBLEFirmwareRelease.d.ts +12 -2
  39. package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -1
  40. package/dist/types/api/checkFirmwareRelease.d.ts +11 -1
  41. package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
  42. package/dist/types/api/firmwareUpdate.d.ts +13 -0
  43. package/dist/types/api/firmwareUpdate.d.ts.map +1 -0
  44. package/dist/types/api/index.d.ts +3 -1
  45. package/dist/types/api/index.d.ts.map +1 -1
  46. package/dist/types/device.d.ts +38 -0
  47. package/dist/types/device.d.ts.map +1 -1
  48. package/dist/types/firmware.d.ts +2 -1
  49. package/dist/types/firmware.d.ts.map +1 -1
  50. package/dist/types/params.d.ts +3 -0
  51. package/dist/types/params.d.ts.map +1 -1
  52. package/dist/utils/assets.d.ts +1 -1
  53. package/dist/utils/assets.d.ts.map +1 -1
  54. package/dist/utils/networkUtils.d.ts.map +1 -1
  55. package/dist/utils/release.d.ts +4 -0
  56. package/dist/utils/release.d.ts.map +1 -0
  57. package/package.json +3 -3
  58. package/src/api/BaseMethod.ts +4 -0
  59. package/src/api/CheckBLEFirmwareRelease.ts +7 -1
  60. package/src/api/CheckFirmwareRelease.ts +7 -1
  61. package/src/api/FirmwareUpdate.ts +78 -0
  62. package/src/api/firmware/getBinary.ts +46 -0
  63. package/src/api/firmware/uploadFirmware.ts +72 -0
  64. package/src/api/index.ts +2 -0
  65. package/src/constants/errors.ts +2 -0
  66. package/src/core/index.ts +29 -1
  67. package/src/data-manager/DataManager.ts +36 -20
  68. package/src/device/Device.ts +22 -11
  69. package/src/device/DeviceCommands.ts +6 -0
  70. package/src/device/DeviceList.ts +13 -1
  71. package/src/events/call.ts +6 -0
  72. package/src/events/core.ts +2 -1
  73. package/src/events/iframe.ts +1 -0
  74. package/src/events/ui-request.ts +15 -1
  75. package/src/inject.ts +2 -0
  76. package/src/types/api/checkBLEFirmwareRelease.ts +12 -4
  77. package/src/types/api/checkFirmwareRelease.ts +11 -1
  78. package/src/types/api/firmwareUpdate.ts +21 -0
  79. package/src/types/api/index.ts +4 -1
  80. package/src/types/device.ts +44 -0
  81. package/src/types/firmware.ts +2 -1
  82. package/src/types/params.ts +2 -0
  83. package/src/utils/assets.ts +1 -1
  84. package/src/utils/networkUtils.ts +3 -1
  85. package/src/utils/release.ts +24 -0
@@ -39,6 +39,7 @@ import { solSignTransaction } from './solSignTransaction';
39
39
  import { stellarGetAddress } from './stellarGetAddress';
40
40
  import { stellarSignTransaction } from './stellarSignTransaction';
41
41
  import { cipherKeyValue } from './cipherKeyValue';
42
+ import { firmwareUpdate } from './firmwareUpdate';
42
43
  export * from './export';
43
44
  export declare type CoreApi = {
44
45
  init: typeof init;
@@ -48,7 +49,7 @@ export declare type CoreApi = {
48
49
  dispose: () => void;
49
50
  call: (params: any) => Promise<any>;
50
51
  uiResponse: typeof uiResponse;
51
- cancel: (params?: string) => void;
52
+ cancel: (connectId?: string) => void;
52
53
  searchDevices: typeof searchDevices;
53
54
  getFeatures: typeof getFeatures;
54
55
  checkFirmwareRelease: typeof checkFirmwareRelease;
@@ -87,5 +88,6 @@ export declare type CoreApi = {
87
88
  solSignTransaction: typeof solSignTransaction;
88
89
  stellarGetAddress: typeof stellarGetAddress;
89
90
  stellarSignTransaction: typeof stellarSignTransaction;
91
+ firmwareUpdate: typeof firmwareUpdate;
90
92
  };
91
93
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;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B,CAAC;IAC1C,gBAAgB,EAAE,OAAO,gBAAgB,CAAC;IAE1C,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,eAAe,EAAE,OAAO,eAAe,CAAC;IACxC,cAAc,EAAE,OAAO,cAAc,CAAC;IACtC,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,gBAAgB,EAAE,OAAO,gBAAgB,CAAC;IAE1C,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,oBAAoB,EAAE,OAAO,oBAAoB,CAAC;IAClD,mBAAmB,EAAE,OAAO,mBAAmB,CAAC;IAChD,uBAAuB,EAAE,OAAO,uBAAuB,CAAC;IACxD,qBAAqB,EAAE,OAAO,qBAAqB,CAAC;IAEpD,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAE9C,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAE9C,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;IAC5C,sBAAsB,EAAE,OAAO,sBAAsB,CAAC;IAEtD,cAAc,EAAE,OAAO,cAAc,CAAC;CACvC,CAAC"}
@@ -41,4 +41,42 @@ export declare type DeviceFirmwareRange = {
41
41
  max?: string;
42
42
  };
43
43
  };
44
+ declare type FeaturesNarrowing = {
45
+ major_version: 2;
46
+ fw_major: null;
47
+ fw_minor: null;
48
+ fw_patch: null;
49
+ bootloader_mode: true;
50
+ firmware_present: false;
51
+ } | {
52
+ major_version: 2;
53
+ fw_major: null;
54
+ fw_minor: null;
55
+ fw_patch: null;
56
+ bootloader_mode: null;
57
+ firmware_present: null;
58
+ } | {
59
+ major_version: 2;
60
+ fw_major: 2;
61
+ fw_minor: number;
62
+ fw_patch: number;
63
+ bootloader_mode: true;
64
+ firmware_present: true;
65
+ } | {
66
+ major_version: 1;
67
+ fw_major: null;
68
+ fw_minor: null;
69
+ fw_patch: null;
70
+ bootloader_mode: true;
71
+ firmware_present: false;
72
+ } | {
73
+ major_version: 1;
74
+ fw_major: null;
75
+ fw_minor: null;
76
+ fw_patch: null;
77
+ bootloader_mode: true;
78
+ firmware_present: true;
79
+ };
80
+ export declare type StrictFeatures = Features & FeaturesNarrowing;
81
+ export {};
44
82
  //# sourceMappingURL=device.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/types/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,oBAAY,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAE7D,oBAAY,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,GAAG,UAAU,CAAC;AAE7E,oBAAY,qBAAqB,GAC7B,eAAe,GACf,YAAY,GACZ,iBAAiB,GACjB,yBAAyB,CAAC;AAE9B,oBAAY,uBAAuB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAA;CAAE,CAAC;AAE/E,oBAAY,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,WAAW,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,SAAS,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;IACzB,uBAAuB,EAAE,uBAAuB,CAAC;IACjD,kBAAkB,EAAE,aAAa,GAAG,IAAI,CAAC;IACzC,eAAe,EAAE,aAAa,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,oBAAY,YAAY,GAAG;IACz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Range {
8
8
  max: string;
9
9
  };
10
10
  }
11
- export declare type VersionArray = [1 | 2, number, number];
11
+ export declare type MajorVersion = 1 | 2;
12
+ export declare type VersionArray = [MajorVersion, number, number];
12
13
  export declare type FirmwareRelease = {
13
14
  required: boolean;
14
15
  url: string;
@@ -1 +1 @@
1
- {"version":3,"file":"firmware.d.ts","sourceRoot":"","sources":["../../src/types/firmware.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE;QACH,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,GAAG,EAAE;QACH,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,oBAAY,YAAY,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEnD,oBAAY,eAAe,GAAG;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,EAAE,YAAY,CAAC;IACtB,oBAAoB,EAAE,YAAY,CAAC;IACnC,sBAAsB,EAAE,YAAY,CAAC;IACrC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,oBAAY,WAAW,GAAG;IACxB,SAAS,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;I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zB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,oBAAY,sBAAsB,GAAG,OAAO,GAAG,UAAU,CAAC"}
@@ -1,6 +1,9 @@
1
1
  export interface CommonParams {
2
2
  keepSession?: boolean;
3
3
  }
4
+ export declare type Params<T> = CommonParams & T & {
5
+ bundle?: undefined;
6
+ };
4
7
  export interface Unsuccessful {
5
8
  success: false;
6
9
  payload: {
@@ -1 +1 @@
1
- {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
@@ -1,3 +1,3 @@
1
- export declare const httpRequest: (url: string, _type: string) => any;
1
+ export declare const httpRequest: (url: string, type: string) => any;
2
2
  export declare const getTimeStamp: () => number;
3
3
  //# sourceMappingURL=assets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAAS,MAAM,SAAS,MAAM,KAAG,GAA8B,CAAC;AAExF,eAAO,MAAM,YAAY,cAA6B,CAAC"}
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAAS,MAAM,QAAQ,MAAM,KAAG,GAAoC,CAAC;AAE7F,eAAO,MAAM,YAAY,cAA6B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"networkUtils.d.ts","sourceRoot":"","sources":["../../src/utils/networkUtils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAAe,MAAM,gCAe5C,CAAC"}
1
+ {"version":3,"file":"networkUtils.d.ts","sourceRoot":"","sources":["../../src/utils/networkUtils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAAe,MAAM,gCAiB5C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { IBLEFirmwareReleaseInfo, IDeviceFirmwareStatus, IFirmwareReleaseInfo } from '../types';
2
+ export declare const getReleaseStatus: (releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[], currentVersion: string) => IDeviceFirmwareStatus;
3
+ export declare const getReleaseChangelog: (releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[], currentVersion: string) => IFirmwareReleaseInfo['changelog'][];
4
+ //# sourceMappingURL=release.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../../src/utils/release.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhG,eAAO,MAAM,gBAAgB,aACjB,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,EAAE,kBAC5C,MAAM,KACrB,qBASF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,EAAE,kBAC5C,MAAM,KACrB,oBAAoB,CAAC,WAAW,CAAC,EAGnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.0.10",
3
+ "version": "0.1.2",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-transport": "^0.0.10",
28
+ "@onekeyfe/hd-transport": "^0.1.2",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
31
  "parse-uri": "^1.0.7",
@@ -35,5 +35,5 @@
35
35
  "@types/parse-uri": "^1.0.0",
36
36
  "@types/semver": "^7.3.9"
37
37
  },
38
- "gitHead": "b1f3f06c56fda840f4e55f2d033f7b84f16e8873"
38
+ "gitHead": "5640e7870a99d8f3bade996fb5f57af055c749d8"
39
39
  }
@@ -2,6 +2,7 @@ import { UI_REQUEST } from '../constants/ui-request';
2
2
  import { Device } from '../device/Device';
3
3
  import DeviceConnector from '../device/DeviceConnector';
4
4
  import { DeviceFirmwareRange } from '../types';
5
+ import { CoreMessage } from '../events';
5
6
 
6
7
  export abstract class BaseMethod<Params = undefined> {
7
8
  responseID: number;
@@ -48,6 +49,9 @@ export abstract class BaseMethod<Params = undefined> {
48
49
  */
49
50
  requireDeviceMode: string[];
50
51
 
52
+ // @ts-expect-error: strictPropertyInitialization
53
+ postMessage: (message: CoreMessage) => void;
54
+
51
55
  constructor(message: { id?: number; payload: any }) {
52
56
  const { payload } = message;
53
57
  this.name = payload.method;
@@ -11,7 +11,13 @@ export default class CheckBLEFirmwareRelease extends BaseMethod {
11
11
  run() {
12
12
  if (this.device.features) {
13
13
  const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
14
- return Promise.resolve(firmwareStatus);
14
+ const changelog = DataManager.getBleFirmwareChangelog(this.device.features);
15
+ const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
16
+ return Promise.resolve({
17
+ status: firmwareStatus,
18
+ changelog,
19
+ release,
20
+ });
15
21
  }
16
22
  return Promise.resolve(null);
17
23
  }
@@ -8,7 +8,13 @@ export default class CheckFirmwareRelease extends BaseMethod {
8
8
  run() {
9
9
  if (this.device.features) {
10
10
  const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
11
- return Promise.resolve(firmwareStatus);
11
+ const changelog = DataManager.getFirmwareChangelog(this.device.features);
12
+ const release = DataManager.getFirmwareLeatestRelease(this.device.features);
13
+ return Promise.resolve({
14
+ status: firmwareStatus,
15
+ changelog,
16
+ release,
17
+ });
12
18
  }
13
19
  return Promise.resolve(null);
14
20
  }
@@ -0,0 +1,78 @@
1
+ import { ERRORS } from '../constants';
2
+ import { UI_REQUEST } from '../constants/ui-request';
3
+ import { BaseMethod } from './BaseMethod';
4
+ import { validateParams } from './helpers/paramsValidator';
5
+ import { getBinary } from './firmware/getBinary';
6
+ import { uploadFirmware } from './firmware/uploadFirmware';
7
+
8
+ type Params = {
9
+ binary?: ArrayBuffer;
10
+ version?: number[];
11
+ updateType: 'firmware' | 'ble';
12
+ };
13
+
14
+ export default class FirmwareUpdate extends BaseMethod<Params> {
15
+ init() {
16
+ this.allowDeviceMode = [UI_REQUEST.BOOTLOADER, UI_REQUEST.INITIALIZE];
17
+ this.requireDeviceMode = [UI_REQUEST.BOOTLOADER];
18
+
19
+ const { payload } = this;
20
+
21
+ validateParams(payload, [
22
+ { name: 'version', type: 'array' },
23
+ { name: 'binary', type: 'buffer' },
24
+ ]);
25
+
26
+ if (!payload.updateType) {
27
+ throw ERRORS.TypedError('Method_InvalidParameter', 'updateType is required');
28
+ }
29
+
30
+ this.params = { updateType: payload.updateType };
31
+
32
+ if ('version' in payload) {
33
+ this.params = {
34
+ ...this.params,
35
+ version: payload.version,
36
+ };
37
+ }
38
+
39
+ if ('binary' in payload) {
40
+ this.params = {
41
+ ...this.params,
42
+ binary: payload.binary,
43
+ };
44
+ }
45
+ }
46
+
47
+ async run() {
48
+ const { device, params } = this;
49
+
50
+ let binary;
51
+
52
+ try {
53
+ if (params.binary) {
54
+ binary = this.params.binary;
55
+ } else {
56
+ if (!device.features) {
57
+ throw ERRORS.TypedError('Runtime', 'no features found for this device');
58
+ }
59
+ const firmware = await getBinary({
60
+ features: device.features,
61
+ version: params.version,
62
+ updateType: params.updateType,
63
+ });
64
+ binary = firmware.binary;
65
+ }
66
+ } catch (err) {
67
+ throw ERRORS.TypedError('Method_FirmwareUpdate_DownloadFailed', err);
68
+ }
69
+
70
+ return uploadFirmware(
71
+ params.updateType,
72
+ this.device.getCommands().typedCall.bind(this.device.getCommands()),
73
+ this.postMessage,
74
+ device,
75
+ { payload: binary }
76
+ );
77
+ }
78
+ }
@@ -0,0 +1,46 @@
1
+ import semver from 'semver';
2
+ import { Features } from '../../types';
3
+ import { getDeviceType, httpRequest } from '../../utils';
4
+ import { DataManager } from '../../data-manager';
5
+ import { ERRORS } from '../../constants';
6
+
7
+ export interface GetInfoProps {
8
+ features: Features;
9
+ updateType: 'firmware' | 'ble';
10
+ }
11
+
12
+ interface GetBinaryProps extends GetInfoProps {
13
+ version?: number[];
14
+ }
15
+
16
+ export const getBinary = async ({ features, updateType, version }: GetBinaryProps) => {
17
+ const releaseInfo = getInfo({ features, updateType });
18
+
19
+ if (!releaseInfo) {
20
+ throw ERRORS.TypedError('Runtime', 'no firmware found for this device');
21
+ }
22
+
23
+ if (
24
+ version &&
25
+ !semver.eq(releaseInfo.version as unknown as semver.SemVer, version as unknown as semver.SemVer)
26
+ ) {
27
+ throw ERRORS.TypedError('Runtime', 'firmware version mismatch');
28
+ }
29
+
30
+ // @ts-expect-error
31
+ const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
32
+ const fw = await httpRequest(url, 'binary');
33
+
34
+ return {
35
+ ...releaseInfo,
36
+ binary: fw,
37
+ };
38
+ };
39
+
40
+ const getInfo = ({ features, updateType }: GetInfoProps) => {
41
+ const deviceType = getDeviceType(features);
42
+ const { deviceMap } = DataManager;
43
+ const releaseInfo = deviceMap?.[deviceType]?.[updateType]?.[0] ?? null;
44
+
45
+ return releaseInfo;
46
+ };
@@ -0,0 +1,72 @@
1
+ import { DEVICE, CoreMessage, createUiMessage, UI_REQUEST } from '../../events';
2
+ import { ERRORS, PROTO } from '../../constants';
3
+ import type { Device } from '../../device/Device';
4
+ import type { TypedCall } from '../../device/DeviceCommands';
5
+ import { KnownDevice } from '../../types';
6
+
7
+ const postConfirmationMessage = (device: Device) => {
8
+ // only if firmware is already installed. fresh device does not require button confirmation
9
+ if (device.features?.firmware_present) {
10
+ device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
11
+ }
12
+ };
13
+
14
+ const postProgressMessage = (
15
+ device: Device,
16
+ progress: number,
17
+ postMessage: (message: CoreMessage) => void
18
+ ) => {
19
+ postMessage(
20
+ createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
21
+ device: device.toMessageObject() as KnownDevice,
22
+ progress,
23
+ })
24
+ );
25
+ };
26
+
27
+ export const uploadFirmware = async (
28
+ updateType: 'firmware' | 'ble',
29
+ typedCall: TypedCall,
30
+ postMessage: (message: CoreMessage) => void,
31
+ device: Device,
32
+ { payload }: PROTO.FirmwareUpload
33
+ ) => {
34
+ if (device.features?.major_version === 1) {
35
+ postConfirmationMessage(device);
36
+ const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
37
+ await typedCall(eraseCommand as unknown as any, 'Success', {});
38
+ postProgressMessage(device, 0, postMessage);
39
+ const { message } = await typedCall('FirmwareUpload', 'Success', {
40
+ payload,
41
+ });
42
+
43
+ return message;
44
+ }
45
+
46
+ if (device.features?.major_version === 2) {
47
+ postConfirmationMessage(device);
48
+ const length = payload.byteLength;
49
+
50
+ let response = await typedCall('FirmwareErase', ['FirmwareRequest', 'Success'], { length });
51
+ while (response.type !== 'Success') {
52
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
53
+ const start = response.message.offset!;
54
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
+ const end = response.message.offset! + response.message.length!;
56
+ const chunk = payload.slice(start, end);
57
+
58
+ if (start > 0) {
59
+ postProgressMessage(device, Math.round((start / length) * 100), postMessage);
60
+ }
61
+
62
+ response = await typedCall('FirmwareUpload', ['FirmwareRequest', 'Success'], {
63
+ payload: chunk,
64
+ });
65
+ }
66
+
67
+ postProgressMessage(device, 100, postMessage);
68
+ return response.message;
69
+ }
70
+
71
+ throw ERRORS.TypedError('Runtime', 'uploadFirmware: unknown major_version');
72
+ };
package/src/api/index.ts CHANGED
@@ -39,3 +39,5 @@ export { default as solSignTransaction } from './solana/SolSignTransaction';
39
39
 
40
40
  export { default as stellarGetAddress } from './stellar/StellarGetAddress';
41
41
  export { default as stellarSignTransaction } from './stellar/StellarSignTransaction';
42
+
43
+ export { default as firmwareUpdate } from './FirmwareUpdate';
@@ -3,6 +3,7 @@ export const ERROR_CODES = {
3
3
  Method_InvalidParameter: '',
4
4
  Call_API: '',
5
5
  Call_NotResponse: 'No response data',
6
+ Method_FirmwareUpdate_DownloadFailed: '',
6
7
 
7
8
  // device error
8
9
  Transport_InvalidProtobuf: '',
@@ -10,6 +11,7 @@ export const ERROR_CODES = {
10
11
  Device_UnexpectedMode: '',
11
12
  Device_CallInProgress: '',
12
13
  Device_InitializeFailed: '',
14
+ Device_Interrupted: 'The device is performing other operations',
13
15
  Not_Use_Onekey_Device: 'Please use onekey device',
14
16
 
15
17
  // runtime error
package/src/core/index.ts CHANGED
@@ -41,6 +41,8 @@ let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui
41
41
  let _callPromise: Deferred<any> | undefined;
42
42
  const callApiQueue = [];
43
43
 
44
+ const deviceCacheMap = new Map<string, Device>();
45
+
44
46
  export const callAPI = async (message: CoreMessage) => {
45
47
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
46
48
  return Promise.reject(
@@ -57,6 +59,7 @@ export const callAPI = async (message: CoreMessage) => {
57
59
  try {
58
60
  method = findMethod(message as IFrameCallMessage);
59
61
  method.connector = _connector;
62
+ method.postMessage = postMessage;
60
63
  method.init();
61
64
  } catch (error) {
62
65
  return Promise.reject(error);
@@ -249,11 +252,32 @@ function initDeviceForBle(method: BaseMethod) {
249
252
  return initDevice(method);
250
253
  }
251
254
 
252
- const device = Device.fromDescriptor({ id: method.connectId } as OneKeyDeviceInfo);
255
+ let device: Device;
256
+ if (deviceCacheMap.has(method.connectId)) {
257
+ device = deviceCacheMap.get(method.connectId) as Device;
258
+ } else {
259
+ device = Device.fromDescriptor({ id: method.connectId } as OneKeyDeviceInfo);
260
+ deviceCacheMap.set(method.connectId, device);
261
+ }
253
262
  device.deviceConnector = _connector;
254
263
  return device;
255
264
  }
256
265
 
266
+ export const cancel = (connectId?: string) => {
267
+ const env = DataManager.getSettings('env');
268
+ if (connectId) {
269
+ let device;
270
+ if (env === 'react-native') {
271
+ device = initDeviceForBle({ connectId } as BaseMethod);
272
+ } else {
273
+ device = initDevice({ connectId } as BaseMethod);
274
+ }
275
+ device?.interruption();
276
+ }
277
+ cleanup();
278
+ closePopup();
279
+ };
280
+
257
281
  const cleanup = () => {
258
282
  _uiPromises = [];
259
283
  Log.debug('Cleanup...');
@@ -345,6 +369,10 @@ export default class Core extends EventEmitter {
345
369
  const response = await callAPI(message);
346
370
  return response;
347
371
  }
372
+ case IFRAME.CANCEL: {
373
+ cancel(message.payload.connectId);
374
+ break;
375
+ }
348
376
  default:
349
377
  break;
350
378
  }
@@ -18,6 +18,7 @@ import type {
18
18
  IDeviceBLEFirmwareStatus,
19
19
  ITransportStatus,
20
20
  } from '../types';
21
+ import { getReleaseChangelog, getReleaseStatus } from '../utils/release';
21
22
 
22
23
  export default class DataManager {
23
24
  static deviceMap: DeviceTypeMap = {
@@ -59,21 +60,30 @@ export default class DataManager {
59
60
  }
60
61
 
61
62
  const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
62
- const latestFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
63
-
64
- if (!latestFirmware) return 'valid';
65
-
66
- const latestVersion = latestFirmware.version.join('.');
67
63
  const currentVersion = deviceFirmwareVersion.join('.');
64
+ return getReleaseStatus(targetDeviceConfigList, currentVersion);
65
+ };
68
66
 
69
- /** latest is greater or equal current */
70
- if (semver.gt(latestVersion, currentVersion)) {
71
- if (latestFirmware.required) return 'required';
67
+ static getFirmwareChangelog = (features: Features) => {
68
+ const deviceType = getDeviceType(features);
69
+ const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
72
70
 
73
- return 'outdated';
71
+ if (
72
+ features.firmware_present === false ||
73
+ (deviceType === 'classic' && features.bootloader_mode)
74
+ ) {
75
+ return [];
74
76
  }
75
77
 
76
- return 'valid';
78
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
79
+ const currentVersion = deviceFirmwareVersion.join('.');
80
+ return getReleaseChangelog(targetDeviceConfigList, currentVersion);
81
+ };
82
+
83
+ static getFirmwareLeatestRelease = (features: Features) => {
84
+ const deviceType = getDeviceType(features);
85
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
86
+ return targetDeviceConfigList[targetDeviceConfigList.length - 1];
77
87
  };
78
88
 
79
89
  static getBLEFirmwareStatus = (features: Features): IDeviceBLEFirmwareStatus => {
@@ -86,21 +96,27 @@ export default class DataManager {
86
96
  }
87
97
 
88
98
  const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
89
- const latestBLEFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
90
-
91
- if (!latestBLEFirmware) return 'valid';
92
-
93
- const latestVersion = latestBLEFirmware.version.join('.');
94
99
  const currentVersion = deviceBLEFirmwareVersion.join('.');
100
+ return getReleaseStatus(targetDeviceConfigList, currentVersion);
101
+ };
95
102
 
96
- /** latest is greater or equal current */
97
- if (semver.gt(latestVersion, currentVersion)) {
98
- if (latestBLEFirmware.required) return 'required';
103
+ static getBleFirmwareChangelog = (features: Features) => {
104
+ const deviceType = getDeviceType(features);
105
+ const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
99
106
 
100
- return 'outdated';
107
+ if (!deviceBLEFirmwareVersion) {
108
+ return [];
101
109
  }
102
110
 
103
- return 'valid';
111
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
112
+ const currentVersion = deviceBLEFirmwareVersion.join('.');
113
+ return getReleaseChangelog(targetDeviceConfigList, currentVersion);
114
+ };
115
+
116
+ static getBleFirmwareLeatestRelease = (features: Features) => {
117
+ const deviceType = getDeviceType(features);
118
+ const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
119
+ return targetDeviceConfigList[targetDeviceConfigList.length - 1];
104
120
  };
105
121
 
106
122
  static getTransportStatus = (localVersion: string): ITransportStatus => {