@onekeyfe/hd-web-sdk 0.0.2 → 0.0.3

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.
@@ -4108,10 +4108,10 @@ const inject = ({
4108
4108
  connectId,
4109
4109
  method: 'deviceReset'
4110
4110
  })),
4111
- deviceSettings: connectId => call({
4111
+ deviceSettings: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4112
4112
  connectId,
4113
4113
  method: 'deviceSettings'
4114
- }),
4114
+ })),
4115
4115
  deviceUpdateReboot: connectId => call({
4116
4116
  connectId,
4117
4117
  method: 'deviceUpdateReboot'
@@ -4167,6 +4167,26 @@ const inject = ({
4167
4167
  btcVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4168
4168
  connectId,
4169
4169
  method: 'btcVerifyMessage'
4170
+ })),
4171
+ starcoinGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4172
+ connectId,
4173
+ method: 'starcoinGetAddress'
4174
+ })),
4175
+ starcoinGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4176
+ connectId,
4177
+ method: 'starcoinGetPublicKey'
4178
+ })),
4179
+ starcoinSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4180
+ connectId,
4181
+ method: 'starcoinSignMessage'
4182
+ })),
4183
+ starcoinSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4184
+ connectId,
4185
+ method: 'starcoinSignTransaction'
4186
+ })),
4187
+ starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4188
+ connectId,
4189
+ method: 'starcoinVerifyMessage'
4170
4190
  }))
4171
4191
  };
4172
4192
  return api;
@@ -4978,6 +4998,53 @@ function create(arg, data) {
4978
4998
  };
4979
4999
  }
4980
5000
 
5001
+ const getDeviceType = features => {
5002
+ if (!features || typeof features !== 'object' || !features.serial_no) {
5003
+ return 'classic';
5004
+ }
5005
+
5006
+ const serialNo = features.serial_no;
5007
+ const miniFlag = serialNo.slice(0, 2);
5008
+ if (miniFlag.toLowerCase() === 'mi') return 'mini';
5009
+ return 'classic';
5010
+ };
5011
+
5012
+ const getDeviceUUID = features => {
5013
+ const deviceType = getDeviceType(features);
5014
+
5015
+ if (deviceType === 'classic') {
5016
+ return features.onekey_serial;
5017
+ }
5018
+
5019
+ return features.serial_no;
5020
+ };
5021
+
5022
+ const getDeviceLabel = features => {
5023
+ const deviceType = getDeviceType(features);
5024
+
5025
+ if (typeof features.label === 'string') {
5026
+ return features.label;
5027
+ }
5028
+
5029
+ return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
5030
+ };
5031
+
5032
+ const getDeviceFirmwareVersion = features => {
5033
+ if (features.onekey_version) {
5034
+ return features.onekey_version.split('.');
5035
+ }
5036
+
5037
+ return [features.major_version, features.minor_version, features.patch_version];
5038
+ };
5039
+
5040
+ const getDeviceBLEFirmwareVersion = features => {
5041
+ if (!features.ble_ver) {
5042
+ return null;
5043
+ }
5044
+
5045
+ return features.ble_ver.split('.');
5046
+ };
5047
+
4981
5048
  var nested = {
4982
5049
  BinanceGetAddress: {
4983
5050
  fields: {
@@ -13638,53 +13705,6 @@ var MessagesJSON = {
13638
13705
  nested: nested
13639
13706
  };
13640
13707
 
13641
- const getDeviceType = features => {
13642
- if (!features || typeof features !== 'object' || !features.serial_no) {
13643
- return 'classic';
13644
- }
13645
-
13646
- const serialNo = features.serial_no;
13647
- const miniFlag = serialNo.slice(0, 2);
13648
- if (miniFlag.toLowerCase() === 'mi') return 'mini';
13649
- return 'classic';
13650
- };
13651
-
13652
- const getDeviceUUID = features => {
13653
- const deviceType = getDeviceType(features);
13654
-
13655
- if (deviceType === 'classic') {
13656
- return features.onekey_serial;
13657
- }
13658
-
13659
- return features.serial_no;
13660
- };
13661
-
13662
- const getDeviceLabel = features => {
13663
- const deviceType = getDeviceType(features);
13664
-
13665
- if (typeof features.label === 'string') {
13666
- return features.label;
13667
- }
13668
-
13669
- return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
13670
- };
13671
-
13672
- const getDeviceFirmwareVersion = features => {
13673
- if (features.onekey_version) {
13674
- return features.onekey_version.split('.');
13675
- }
13676
-
13677
- return [features.major_version, features.minor_version, features.patch_version];
13678
- };
13679
-
13680
- const getDeviceBLEFirmwareVersion = features => {
13681
- if (!features.ble_ver) {
13682
- return null;
13683
- }
13684
-
13685
- return features.ble_ver.split('.');
13686
- };
13687
-
13688
13708
  var _a;
13689
13709
 
13690
13710
  class DataManager {
@@ -16446,7 +16466,7 @@ class EVMGetPublicKey extends BaseMethod {
16446
16466
 
16447
16467
  }
16448
16468
 
16449
- class EVMSignMessage$1 extends BaseMethod {
16469
+ class EVMSignMessage$2 extends BaseMethod {
16450
16470
  init() {
16451
16471
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16452
16472
  validateParams(this.payload, [{
@@ -16536,7 +16556,7 @@ class EVMSignTransaction extends BaseMethod {
16536
16556
  const r = request.signature_r;
16537
16557
  const s = request.signature_s;
16538
16558
 
16539
- if (!v || !r || !s) {
16559
+ if (v == null || r == null || s == null) {
16540
16560
  throw TypedError('Runtime', 'processTxRequest: Unexpected request');
16541
16561
  }
16542
16562
 
@@ -16799,7 +16819,7 @@ class EVMSignMessageEIP712 extends BaseMethod {
16799
16819
 
16800
16820
  }
16801
16821
 
16802
- class EVMSignMessage extends BaseMethod {
16822
+ class EVMSignMessage$1 extends BaseMethod {
16803
16823
  init() {
16804
16824
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16805
16825
  validateParams(this.payload, [{
@@ -16836,6 +16856,217 @@ class EVMSignMessage extends BaseMethod {
16836
16856
 
16837
16857
  }
16838
16858
 
16859
+ class StarcoinGetAddress extends BaseMethod {
16860
+ constructor() {
16861
+ super(...arguments);
16862
+ this.hasBundle = false;
16863
+ }
16864
+
16865
+ init() {
16866
+ var _a;
16867
+
16868
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16869
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16870
+ const payload = this.hasBundle ? this.payload : {
16871
+ bundle: [this.payload]
16872
+ };
16873
+ validateParams(payload, [{
16874
+ name: 'bundle',
16875
+ type: 'array'
16876
+ }]);
16877
+ this.params = [];
16878
+ payload.bundle.forEach(batch => {
16879
+ var _a;
16880
+
16881
+ const addressN = validatePath(batch.path, 3);
16882
+ validateParams(batch, [{
16883
+ name: 'path',
16884
+ required: true
16885
+ }, {
16886
+ name: 'showOnOneKey',
16887
+ type: 'boolean'
16888
+ }]);
16889
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
16890
+ this.params.push({
16891
+ address_n: addressN,
16892
+ show_display: showOnOneKey
16893
+ });
16894
+ });
16895
+ }
16896
+
16897
+ run() {
16898
+ return __awaiter(this, void 0, void 0, function* () {
16899
+ const responses = [];
16900
+
16901
+ for (let i = 0; i < this.params.length; i++) {
16902
+ const param = this.params[i];
16903
+ const res = yield this.device.commands.typedCall('StarcoinGetAddress', 'StarcoinAddress', Object.assign({}, param));
16904
+ responses.push(Object.assign({
16905
+ path: serializedPath(param.address_n)
16906
+ }, res.message));
16907
+ }
16908
+
16909
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
16910
+ });
16911
+ }
16912
+
16913
+ }
16914
+
16915
+ class StarcoinGetPublicKey extends BaseMethod {
16916
+ constructor() {
16917
+ super(...arguments);
16918
+ this.hasBundle = false;
16919
+ }
16920
+
16921
+ init() {
16922
+ var _a;
16923
+
16924
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16925
+ this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16926
+ const payload = this.hasBundle ? this.payload : {
16927
+ bundle: [this.payload]
16928
+ };
16929
+ validateParams(payload, [{
16930
+ name: 'bundle',
16931
+ type: 'array'
16932
+ }]);
16933
+ this.params = [];
16934
+ payload.bundle.forEach(batch => {
16935
+ var _a;
16936
+
16937
+ const addressN = validatePath(batch.path, 3);
16938
+ validateParams(batch, [{
16939
+ name: 'path',
16940
+ required: true
16941
+ }, {
16942
+ name: 'showOnOneKey',
16943
+ type: 'boolean'
16944
+ }]);
16945
+ const showOnOneKey = (_a = batch.showOnOneKey) !== null && _a !== void 0 ? _a : true;
16946
+ this.params.push({
16947
+ address_n: addressN,
16948
+ show_display: showOnOneKey
16949
+ });
16950
+ });
16951
+ }
16952
+
16953
+ run() {
16954
+ return __awaiter(this, void 0, void 0, function* () {
16955
+ const responses = [];
16956
+
16957
+ for (let i = 0; i < this.params.length; i++) {
16958
+ const param = this.params[i];
16959
+ const res = yield this.device.commands.typedCall('StarcoinGetPublicKey', 'StarcoinPublicKey', Object.assign({}, param));
16960
+ responses.push(Object.assign({
16961
+ path: serializedPath(param.address_n)
16962
+ }, res.message));
16963
+ }
16964
+
16965
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
16966
+ });
16967
+ }
16968
+
16969
+ }
16970
+
16971
+ class StarcoinSignMessage extends BaseMethod {
16972
+ init() {
16973
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16974
+ validateParams(this.payload, [{
16975
+ name: 'path',
16976
+ required: true
16977
+ }, {
16978
+ name: 'messageHex',
16979
+ type: 'hexString',
16980
+ required: true
16981
+ }]);
16982
+ const {
16983
+ path,
16984
+ messageHex
16985
+ } = this.payload;
16986
+ const addressN = validatePath(path, 3);
16987
+ this.params = {
16988
+ address_n: addressN,
16989
+ message: formatAnyHex(messageHex)
16990
+ };
16991
+ }
16992
+
16993
+ run() {
16994
+ return __awaiter(this, void 0, void 0, function* () {
16995
+ const res = yield this.device.commands.typedCall('StarcoinSignMessage', 'StarcoinMessageSignature', Object.assign({}, this.params));
16996
+ return Promise.resolve(res.message);
16997
+ });
16998
+ }
16999
+
17000
+ }
17001
+
17002
+ class StarcoinSignTransaction extends BaseMethod {
17003
+ init() {
17004
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17005
+ validateParams(this.payload, [{
17006
+ name: 'path',
17007
+ required: true
17008
+ }, {
17009
+ name: 'rawTx',
17010
+ type: 'hexString',
17011
+ required: true
17012
+ }]);
17013
+ const {
17014
+ path,
17015
+ rawTx
17016
+ } = this.payload;
17017
+ const addressN = validatePath(path, 3);
17018
+ this.params = {
17019
+ address_n: addressN,
17020
+ raw_tx: formatAnyHex(rawTx)
17021
+ };
17022
+ }
17023
+
17024
+ run() {
17025
+ return __awaiter(this, void 0, void 0, function* () {
17026
+ const res = yield this.device.commands.typedCall('StarcoinSignTx', 'StarcoinSignedTx', Object.assign({}, this.params));
17027
+ return Promise.resolve(res.message);
17028
+ });
17029
+ }
17030
+
17031
+ }
17032
+
17033
+ class EVMSignMessage extends BaseMethod {
17034
+ init() {
17035
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17036
+ validateParams(this.payload, [{
17037
+ name: 'publicKey',
17038
+ type: 'string',
17039
+ required: true
17040
+ }, {
17041
+ name: 'messageHex',
17042
+ type: 'hexString',
17043
+ required: true
17044
+ }, {
17045
+ name: 'signature',
17046
+ type: 'hexString',
17047
+ required: true
17048
+ }]);
17049
+ const {
17050
+ publicKey,
17051
+ messageHex,
17052
+ signature
17053
+ } = formatAnyHex(this.payload);
17054
+ this.params = {
17055
+ public_key: publicKey,
17056
+ message: messageHex,
17057
+ signature
17058
+ };
17059
+ }
17060
+
17061
+ run() {
17062
+ return __awaiter(this, void 0, void 0, function* () {
17063
+ const res = yield this.device.commands.typedCall('StarcoinVerifyMessage', 'Success', Object.assign({}, this.params));
17064
+ return Promise.resolve(res.message);
17065
+ });
17066
+ }
17067
+
17068
+ }
17069
+
16839
17070
  var ApiMethods = /*#__PURE__*/Object.freeze({
16840
17071
  __proto__: null,
16841
17072
  searchDevices: SearchDevices,
@@ -16859,11 +17090,16 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
16859
17090
  deviceWipe: DeviceWipe,
16860
17091
  evmGetAddress: EvmGetAddress,
16861
17092
  evmGetPublicKey: EVMGetPublicKey,
16862
- evmSignMessage: EVMSignMessage$1,
17093
+ evmSignMessage: EVMSignMessage$2,
16863
17094
  evmSignMessageEIP712: EVMSignMessageEIP712$1,
16864
17095
  evmSignTransaction: EVMSignTransaction,
16865
17096
  evmSignTypedData: EVMSignMessageEIP712,
16866
- evmVerifyMessage: EVMSignMessage
17097
+ evmVerifyMessage: EVMSignMessage$1,
17098
+ starcoinGetAddress: StarcoinGetAddress,
17099
+ starcoinGetPublicKey: StarcoinGetPublicKey,
17100
+ starcoinSignMessage: StarcoinSignMessage,
17101
+ starcoinSignTransaction: StarcoinSignTransaction,
17102
+ starcoinVerifyMessage: EVMSignMessage
16867
17103
  });
16868
17104
 
16869
17105
  function findMethod(message) {
@@ -17344,6 +17580,11 @@ __webpack_unused_export__ = createUiMessage;
17344
17580
  __webpack_unused_export__ = createUiResponse;
17345
17581
  exports.ZP = HardwareSdk;
17346
17582
  exports.yI = enableLog;
17583
+ __webpack_unused_export__ = getDeviceBLEFirmwareVersion;
17584
+ __webpack_unused_export__ = getDeviceFirmwareVersion;
17585
+ __webpack_unused_export__ = getDeviceLabel;
17586
+ __webpack_unused_export__ = getDeviceType;
17587
+ __webpack_unused_export__ = getDeviceUUID;
17347
17588
  __webpack_unused_export__ = getEnv;
17348
17589
  __webpack_unused_export__ = getTimeStamp;
17349
17590
  __webpack_unused_export__ = httpRequest;
@@ -17671,22 +17912,28 @@ function buildOne(messages, name, data) {
17671
17912
  });
17672
17913
  }
17673
17914
 
17674
- const buildBuffer = (messages, name, data) => {
17915
+ const buildBuffers = (messages, name, data) => {
17675
17916
  const {
17676
17917
  Message,
17677
17918
  messageType
17678
17919
  } = createMessageFromName(messages, name);
17679
17920
  const buffer = encode$1(Message, data);
17680
- const encodeBuffer = encode(buffer, {
17921
+ const encodeBuffers = encode(buffer, {
17681
17922
  addTrezorHeaders: true,
17682
- chunked: false,
17923
+ chunked: true,
17683
17924
  messageType
17684
17925
  });
17685
- const outBuffer = new ByteBuffer__default["default"](BUFFER_SIZE + 1);
17686
- outBuffer.writeByte(MESSAGE_TOP_CHAR);
17687
- outBuffer.append(encodeBuffer);
17688
- outBuffer.reset();
17689
- return outBuffer;
17926
+ const outBuffers = [];
17927
+
17928
+ for (const buf of encodeBuffers) {
17929
+ const chunkBuffer = new ByteBuffer__default["default"](BUFFER_SIZE + 1);
17930
+ chunkBuffer.writeByte(MESSAGE_TOP_CHAR);
17931
+ chunkBuffer.append(buf);
17932
+ chunkBuffer.reset();
17933
+ outBuffers.push(chunkBuffer);
17934
+ }
17935
+
17936
+ return outBuffers;
17690
17937
  };
17691
17938
 
17692
17939
  function receiveOne(messages, data) {
@@ -18357,7 +18604,7 @@ protobuf__namespace.configure();
18357
18604
  var index = {
18358
18605
  check,
18359
18606
  buildOne,
18360
- buildBuffer,
18607
+ buildBuffers,
18361
18608
  receiveOne,
18362
18609
  parseConfigure
18363
18610
  };
@@ -42953,7 +43200,7 @@ const createJSBridge = messageEvent => {
42953
43200
  }
42954
43201
  };
42955
43202
 
42956
- const src_init = settings => {
43203
+ const src_init = async settings => {
42957
43204
  if (instance) {
42958
43205
  throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_AlreadyInitialized');
42959
43206
  }
@@ -42961,17 +43208,18 @@ const src_init = settings => {
42961
43208
  _settings = (0,dist/* parseConnectSettings */._4)({ ..._settings,
42962
43209
  ...settings
42963
43210
  });
42964
-
42965
- if (_settings.lazyLoad) {
42966
- _settings.lazyLoad = false;
42967
- return;
42968
- }
42969
-
42970
43211
  (0,dist/* enableLog */.yI)(!!settings.debug);
42971
43212
  src_Log.debug('init');
42972
43213
  window.addEventListener('message', createJSBridge);
42973
43214
  window.addEventListener('unload', src_dispose);
42974
- init(_settings);
43215
+
43216
+ try {
43217
+ await init(_settings);
43218
+ return true;
43219
+ } catch (e) {
43220
+ console.log('init error: ', e);
43221
+ return false;
43222
+ }
42975
43223
  };
42976
43224
 
42977
43225
  const call = async params => {