@onekeyfe/hd-core 0.2.45 → 0.2.48

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.
@@ -1 +1 @@
1
- {"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAU,WAAW,EAA+B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;AAuCnF,eAAO,MAAM,cAAc,eAAsB,MAAM,kBAKtD,CAAC;AAEF,eAAO,MAAM,cAAc,eACb,UAAU,GAAG,KAAK,aACnB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,eACD,MAAM,cAAc,qBAgDlC,CAAC;AAmCF,eAAO,MAAM,cAAc,cAAqB,SAAS,YAAY,MAAM,QAAQ,WAAW,qBAY7F,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAwBpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAChB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAQpB,CAAC"}
1
+ {"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAU,WAAW,EAA+B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;AAwCnF,eAAO,MAAM,cAAc,eAAsB,MAAM,kBAKtD,CAAC;AAEF,eAAO,MAAM,cAAc,eACb,UAAU,GAAG,KAAK,aACnB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,eACD,MAAM,cAAc,qBAiDlC,CAAC;AAmCF,eAAO,MAAM,cAAc,cAAqB,SAAS,YAAY,MAAM,QAAQ,WAAW,qBAY7F,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAwBpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAChB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAQpB,CAAC"}
@@ -5,7 +5,6 @@ export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
5
5
  hasBundle: boolean;
6
6
  shouldConfirm: boolean;
7
7
  init(): void;
8
- publicKeyToAddress(publicKey: string): string;
9
8
  getVersionRange(): {
10
9
  model_mini: {
11
10
  min: string;
@@ -1 +1 @@
1
- {"version":3,"file":"SuiGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/sui/SuiGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAMhF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAC;AAI9D,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU,CAAC,qBAAqB,EAAE,CAAC;IAC5E,SAAS,UAAS;IAElB,aAAa,UAAS;IAEtB,IAAI;IAiCJ,kBAAkB,CAAC,SAAS,EAAE,MAAM;IASpC,eAAe;;;;;;;;IAWT,GAAG;CAkCV"}
1
+ {"version":3,"file":"SuiGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/sui/SuiGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAIhF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAC;AAI9D,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU,CAAC,qBAAqB,EAAE,CAAC;IAC5E,SAAS,UAAS;IAElB,aAAa,UAAS;IAEtB,IAAI;IAiCJ,eAAe;;;;;;;;IAWT,GAAG;CAkCV"}
@@ -0,0 +1,9 @@
1
+ export declare const SUI_ADDRESS_LENGTH = 32;
2
+ export declare const PUBLIC_KEY_SIZE = 32;
3
+ export declare const SIGNATURE_SCHEME_TO_FLAG: {
4
+ ED25519: number;
5
+ Secp256k1: number;
6
+ };
7
+ export declare function normalizeSuiAddress(value: string, forceAdd0x?: boolean): string;
8
+ export declare function publicKeyToAddress(publicKey: string): string;
9
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/api/sui/normalize.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,wBAAwB;;;CAGpC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,MAAM,CAM7E;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,UAQnD"}
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ var sha256 = require('@noble/hashes/sha256');
14
14
  var JSZip = require('jszip');
15
15
  var sha3 = require('@noble/hashes/sha3');
16
16
  var rippleKeypairs = require('ripple-keypairs');
17
+ var blake2b = require('@noble/hashes/blake2b');
17
18
 
18
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
20
 
@@ -13409,8 +13410,8 @@ const waitBleInstall = (updateType) => __awaiter(void 0, void 0, void 0, functio
13409
13410
  }
13410
13411
  });
13411
13412
  const uploadFirmware = (updateType, typedCall, postMessage, device, { payload }) => __awaiter(void 0, void 0, void 0, function* () {
13412
- var _a, _b;
13413
- if (((_a = device.features) === null || _a === void 0 ? void 0 : _a.major_version) === 1) {
13413
+ const deviceModel = getDeviceModel(device.features);
13414
+ if (deviceModel === 'model_mini') {
13414
13415
  postConfirmationMessage(device);
13415
13416
  postProgressTip(device, 'ConfirmOnDevice', postMessage);
13416
13417
  const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
@@ -13424,7 +13425,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
13424
13425
  yield waitBleInstall(updateType);
13425
13426
  return message;
13426
13427
  }
13427
- if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
13428
+ if (deviceModel === 'model_touch') {
13428
13429
  postConfirmationMessage(device);
13429
13430
  postProgressTip(device, 'ConfirmOnDevice', postMessage);
13430
13431
  const length = payload.byteLength;
@@ -13445,7 +13446,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
13445
13446
  yield waitBleInstall(updateType);
13446
13447
  return response.message;
13447
13448
  }
13448
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
13449
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown device model');
13449
13450
  });
13450
13451
  const processResourceRequest = (typedCall, res, data) => __awaiter(void 0, void 0, void 0, function* () {
13451
13452
  if (res.type === 'Success') {
@@ -17100,6 +17101,26 @@ class XrpGetAddress extends BaseMethod {
17100
17101
  }
17101
17102
  }
17102
17103
 
17104
+ const SUI_ADDRESS_LENGTH = 32;
17105
+ const PUBLIC_KEY_SIZE = 32;
17106
+ const SIGNATURE_SCHEME_TO_FLAG = {
17107
+ ED25519: 0x00,
17108
+ Secp256k1: 0x01,
17109
+ };
17110
+ function normalizeSuiAddress(value, forceAdd0x = false) {
17111
+ let address = value.toLowerCase();
17112
+ if (!forceAdd0x && address.startsWith('0x')) {
17113
+ address = address.slice(2);
17114
+ }
17115
+ return `0x${address.padStart(SUI_ADDRESS_LENGTH * 2, '0')}`.toLowerCase();
17116
+ }
17117
+ function publicKeyToAddress(publicKey) {
17118
+ const tmp = new Uint8Array(PUBLIC_KEY_SIZE + 1);
17119
+ tmp.set([SIGNATURE_SCHEME_TO_FLAG.ED25519]);
17120
+ tmp.set(utils.hexToBytes(publicKey), 1);
17121
+ return normalizeSuiAddress(utils.bytesToHex(blake2b.blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2));
17122
+ }
17123
+
17103
17124
  class SuiGetAddress extends BaseMethod {
17104
17125
  constructor() {
17105
17126
  super(...arguments);
@@ -17131,19 +17152,13 @@ class SuiGetAddress extends BaseMethod {
17131
17152
  });
17132
17153
  });
17133
17154
  }
17134
- publicKeyToAddress(publicKey) {
17135
- const hash = sha3.sha3_256.create();
17136
- hash.update('\x00');
17137
- hash.update(hexToBytes(publicKey));
17138
- return `0x${utils.bytesToHex(hash.digest().slice(0, 20))}`;
17139
- }
17140
17155
  getVersionRange() {
17141
17156
  return {
17142
17157
  model_mini: {
17143
- min: '2.9.0',
17158
+ min: '3.0.0',
17144
17159
  },
17145
17160
  model_touch: {
17146
- min: '3.5.0',
17161
+ min: '4.3.0',
17147
17162
  },
17148
17163
  };
17149
17164
  }
@@ -17158,7 +17173,7 @@ class SuiGetAddress extends BaseMethod {
17158
17173
  const result = res.message.public_keys.map((publicKey, index) => ({
17159
17174
  path: serializedPath(this.params[index].address_n),
17160
17175
  publicKey,
17161
- address: this.publicKeyToAddress(publicKey),
17176
+ address: publicKeyToAddress(publicKey),
17162
17177
  }));
17163
17178
  return Promise.resolve(result);
17164
17179
  }
@@ -17209,10 +17224,10 @@ class SuiGetPublicKey extends BaseMethod {
17209
17224
  getVersionRange() {
17210
17225
  return {
17211
17226
  model_mini: {
17212
- min: '2.9.0',
17227
+ min: '3.0.0',
17213
17228
  },
17214
17229
  model_touch: {
17215
- min: '3.5.0',
17230
+ min: '4.3.0',
17216
17231
  },
17217
17232
  };
17218
17233
  }
@@ -17249,10 +17264,10 @@ class SuiSignTransaction extends BaseMethod {
17249
17264
  getVersionRange() {
17250
17265
  return {
17251
17266
  model_mini: {
17252
- min: '2.9.0',
17267
+ min: '3.0.0',
17253
17268
  },
17254
17269
  model_touch: {
17255
- min: '3.5.0',
17270
+ min: '4.3.0',
17256
17271
  },
17257
17272
  };
17258
17273
  }
@@ -18290,10 +18305,10 @@ class PolkadotGetAddress extends BaseMethod {
18290
18305
  getVersionRange() {
18291
18306
  return {
18292
18307
  model_mini: {
18293
- min: '2.11.0',
18308
+ min: '3.0.0',
18294
18309
  },
18295
18310
  model_touch: {
18296
- min: '4.2.0',
18311
+ min: '4.3.0',
18297
18312
  },
18298
18313
  };
18299
18314
  }
@@ -18344,10 +18359,10 @@ class PolkadotSignTransaction extends BaseMethod {
18344
18359
  getVersionRange() {
18345
18360
  return {
18346
18361
  model_mini: {
18347
- min: '2.11.0',
18362
+ min: '3.0.0',
18348
18363
  },
18349
18364
  model_touch: {
18350
- min: '4.2.0',
18365
+ min: '4.3.0',
18351
18366
  },
18352
18367
  };
18353
18368
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.2.45",
3
+ "version": "0.2.48",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@onekeyfe/hd-shared": "^0.2.45",
28
- "@onekeyfe/hd-transport": "^0.2.45",
27
+ "@onekeyfe/hd-shared": "^0.2.48",
28
+ "@onekeyfe/hd-transport": "^0.2.48",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
31
  "bytebuffer": "^5.0.1",
@@ -43,5 +43,5 @@
43
43
  "@types/semver": "^7.3.9",
44
44
  "ripple-keypairs": "^1.1.4"
45
45
  },
46
- "gitHead": "d37564501697fb03f6388ec699ad884c8d5dd96a"
46
+ "gitHead": "dd25a5d278b46fd4da7f0833fdd8a1f5b18dedff"
47
47
  }
@@ -9,6 +9,7 @@ import type { Device } from '../../device/Device';
9
9
  import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommands';
10
10
  import { KnownDevice } from '../../types';
11
11
  import { bytesToHex } from '../helpers/hexUtils';
12
+ import { getDeviceModel } from '../../utils/deviceFeaturesUtils';
12
13
 
13
14
  const postConfirmationMessage = (device: Device) => {
14
15
  // only if firmware is already installed. fresh device does not require button confirmation
@@ -59,7 +60,8 @@ export const uploadFirmware = async (
59
60
  device: Device,
60
61
  { payload }: PROTO.FirmwareUpload
61
62
  ) => {
62
- if (device.features?.major_version === 1) {
63
+ const deviceModel = getDeviceModel(device.features);
64
+ if (deviceModel === 'model_mini') {
63
65
  postConfirmationMessage(device);
64
66
  postProgressTip(device, 'ConfirmOnDevice', postMessage);
65
67
  const eraseCommand = updateType === 'firmware' ? 'FirmwareErase' : 'FirmwareErase_ex';
@@ -75,7 +77,7 @@ export const uploadFirmware = async (
75
77
  return message;
76
78
  }
77
79
 
78
- if (device.features?.major_version === 2) {
80
+ if (deviceModel === 'model_touch') {
79
81
  postConfirmationMessage(device);
80
82
  postProgressTip(device, 'ConfirmOnDevice', postMessage);
81
83
  const length = payload.byteLength;
@@ -104,7 +106,7 @@ export const uploadFirmware = async (
104
106
  return response.message;
105
107
  }
106
108
 
107
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
109
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown device model');
108
110
  };
109
111
 
110
112
  const processResourceRequest = async (
@@ -45,10 +45,10 @@ export default class PolkadotGetAddress extends BaseMethod<HardwarePolkadotGetAd
45
45
  getVersionRange() {
46
46
  return {
47
47
  model_mini: {
48
- min: '2.11.0',
48
+ min: '3.0.0',
49
49
  },
50
50
  model_touch: {
51
- min: '4.2.0',
51
+ min: '4.3.0',
52
52
  },
53
53
  };
54
54
  }
@@ -33,10 +33,10 @@ export default class PolkadotSignTransaction extends BaseMethod<HardwarePolkadot
33
33
  getVersionRange() {
34
34
  return {
35
35
  model_mini: {
36
- min: '2.11.0',
36
+ min: '3.0.0',
37
37
  },
38
38
  model_touch: {
39
- min: '4.2.0',
39
+ min: '4.3.0',
40
40
  },
41
41
  };
42
42
  }
@@ -1,14 +1,12 @@
1
1
  import { SuiGetAddress as HardwareSuiGetAddress } from '@onekeyfe/hd-transport';
2
2
 
3
- import { sha3_256 } from '@noble/hashes/sha3';
4
- import { bytesToHex } from '@noble/hashes/utils';
5
3
  import { UI_REQUEST } from '../../constants/ui-request';
6
4
  import { serializedPath, validatePath } from '../helpers/pathUtils';
7
5
  import { BaseMethod } from '../BaseMethod';
8
6
  import { validateParams } from '../helpers/paramsValidator';
9
7
  import { SuiAddress, SuiGetAddressParams } from '../../types';
10
8
  import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
11
- import { hexToBytes } from '../helpers/hexUtils';
9
+ import { publicKeyToAddress } from './normalize';
12
10
 
13
11
  export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
14
12
  hasBundle = false;
@@ -48,22 +46,13 @@ export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
48
46
  });
49
47
  }
50
48
 
51
- publicKeyToAddress(publicKey: string) {
52
- const hash = sha3_256.create();
53
- // Ed25519
54
- hash.update('\x00');
55
- // hash.update('\x01'); Secp256k1
56
- hash.update(hexToBytes(publicKey));
57
- return `0x${bytesToHex(hash.digest().slice(0, 20))}`;
58
- }
59
-
60
49
  getVersionRange() {
61
50
  return {
62
51
  model_mini: {
63
- min: '2.9.0',
52
+ min: '3.0.0',
64
53
  },
65
54
  model_touch: {
66
- min: '3.5.0',
55
+ min: '4.3.0',
67
56
  },
68
57
  };
69
58
  }
@@ -77,7 +66,7 @@ export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
77
66
  const result = res.message.public_keys.map((publicKey: string, index: number) => ({
78
67
  path: serializedPath((this.params as unknown as any[])[index].address_n),
79
68
  publicKey,
80
- address: this.publicKeyToAddress(publicKey),
69
+ address: publicKeyToAddress(publicKey),
81
70
  }));
82
71
  return Promise.resolve(result);
83
72
  }
@@ -39,10 +39,10 @@ export default class SuiGetPublicKey extends BaseMethod<any> {
39
39
  getVersionRange() {
40
40
  return {
41
41
  model_mini: {
42
- min: '2.9.0',
42
+ min: '3.0.0',
43
43
  },
44
44
  model_touch: {
45
- min: '3.5.0',
45
+ min: '4.3.0',
46
46
  },
47
47
  };
48
48
  }
@@ -30,10 +30,10 @@ export default class SuiSignTransaction extends BaseMethod<HardwareSuiSignTx> {
30
30
  getVersionRange() {
31
31
  return {
32
32
  model_mini: {
33
- min: '2.9.0',
33
+ min: '3.0.0',
34
34
  },
35
35
  model_touch: {
36
- min: '3.5.0',
36
+ min: '4.3.0',
37
37
  },
38
38
  };
39
39
  }
@@ -0,0 +1,28 @@
1
+ import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
2
+ import { blake2b } from '@noble/hashes/blake2b';
3
+
4
+ export const SUI_ADDRESS_LENGTH = 32;
5
+ export const PUBLIC_KEY_SIZE = 32;
6
+
7
+ export const SIGNATURE_SCHEME_TO_FLAG = {
8
+ ED25519: 0x00,
9
+ Secp256k1: 0x01,
10
+ };
11
+
12
+ export function normalizeSuiAddress(value: string, forceAdd0x = false): string {
13
+ let address = value.toLowerCase();
14
+ if (!forceAdd0x && address.startsWith('0x')) {
15
+ address = address.slice(2);
16
+ }
17
+ return `0x${address.padStart(SUI_ADDRESS_LENGTH * 2, '0')}`.toLowerCase();
18
+ }
19
+
20
+ export function publicKeyToAddress(publicKey: string) {
21
+ const tmp = new Uint8Array(PUBLIC_KEY_SIZE + 1);
22
+ tmp.set([SIGNATURE_SCHEME_TO_FLAG.ED25519]);
23
+ tmp.set(hexToBytes(publicKey), 1);
24
+
25
+ return normalizeSuiAddress(
26
+ bytesToHex(blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2)
27
+ );
28
+ }