@onekeyfe/hd-web-sdk 0.1.49 → 0.1.51

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.
@@ -14779,6 +14779,7 @@ const UI_REQUEST$1 = {
14779
14779
  REQUEST_PIN: 'ui-request_pin',
14780
14780
  INVALID_PIN: 'ui-invalid_pin',
14781
14781
  REQUEST_BUTTON: 'ui-button',
14782
+ REQUEST_PASSPHRASE: 'ui-request_passphrase',
14782
14783
  REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request_passphrase_on_device',
14783
14784
  CLOSE_UI_WINDOW: 'ui-close_window',
14784
14785
  BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
@@ -14818,7 +14819,8 @@ const createResponseMessage = (id, success, payload) => ({
14818
14819
  });
14819
14820
 
14820
14821
  const UI_RESPONSE = {
14821
- RECEIVE_PIN: 'ui-receive_pin'
14822
+ RECEIVE_PIN: 'ui-receive_pin',
14823
+ RECEIVE_PASSPHRASE: 'ui-receive_passphrase'
14822
14824
  };
14823
14825
 
14824
14826
  const createUiResponse = (type, payload) => ({
@@ -14977,7 +14979,6 @@ class DevicePool extends events.exports {
14977
14979
  }
14978
14980
  }
14979
14981
 
14980
- Log$7.debug('get devices result : ', devices, deviceList);
14981
14982
  console.log('device poll -> connected: ', this.connectedPool);
14982
14983
  console.log('device poll -> disconnected: ', this.disconnectPool);
14983
14984
  yield this._checkDevicePool(initOptions);
@@ -15309,11 +15310,11 @@ class DeviceCommands {
15309
15310
  _commonCall(type, msg) {
15310
15311
  return __awaiter(this, void 0, void 0, function* () {
15311
15312
  const resp = yield this.call(type, msg);
15312
- return this._filterCommonTypes(resp);
15313
+ return this._filterCommonTypes(resp, type);
15313
15314
  });
15314
15315
  }
15315
15316
 
15316
- _filterCommonTypes(res) {
15317
+ _filterCommonTypes(res, callType) {
15317
15318
  Log$5.debug('_filterCommonTypes: ', res);
15318
15319
 
15319
15320
  if (res.type === 'Failure') {
@@ -15343,6 +15344,10 @@ class DeviceCommands {
15343
15344
  error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlindSignDisabled);
15344
15345
  }
15345
15346
 
15347
+ if (code === 'Failure_UnexpectedMessage' && callType === 'PassphraseAck') {
15348
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.UnexpectPassphrase);
15349
+ }
15350
+
15346
15351
  if (error) {
15347
15352
  return Promise.reject(error);
15348
15353
  }
@@ -15384,9 +15389,17 @@ class DeviceCommands {
15384
15389
  }
15385
15390
 
15386
15391
  if (res.type === 'PassphraseRequest') {
15387
- return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase, 'Device not support passphrase', {
15388
- require: '2.4.0'
15389
- }));
15392
+ return this._promptPassphrase().then(response => {
15393
+ const {
15394
+ passphrase,
15395
+ passphraseOnDevice
15396
+ } = response;
15397
+ return !passphraseOnDevice ? this._commonCall('PassphraseAck', {
15398
+ passphrase
15399
+ }) : this._commonCall('PassphraseAck', {
15400
+ on_device: true
15401
+ });
15402
+ });
15390
15403
  }
15391
15404
 
15392
15405
  if (res.type === 'Deprecated_PassphraseStateRequest') ;
@@ -15414,6 +15427,26 @@ class DeviceCommands {
15414
15427
  });
15415
15428
  }
15416
15429
 
15430
+ _promptPassphrase() {
15431
+ return new Promise((resolve, reject) => {
15432
+ if (this.device.listenerCount(DEVICE.PASSPHRASE) > 0) {
15433
+ this._cancelableRequest = reject;
15434
+ this.device.emit(DEVICE.PASSPHRASE, this.device, (response, error) => {
15435
+ this._cancelableRequest = undefined;
15436
+
15437
+ if (error) {
15438
+ reject(error);
15439
+ } else {
15440
+ resolve(response);
15441
+ }
15442
+ });
15443
+ } else {
15444
+ Log$5.error('[DeviceCommands] [call] Passphrase callback not configured, cancelling request');
15445
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPassphrase: Passphrase callback not configured'));
15446
+ }
15447
+ });
15448
+ }
15449
+
15417
15450
  }
15418
15451
 
15419
15452
  const UI_REQUEST = {
@@ -15550,6 +15583,7 @@ class Device extends events.exports {
15550
15583
  this.needReloadDevice = false;
15551
15584
  this.keepSession = false;
15552
15585
  this.passphraseState = undefined;
15586
+ this.skipPassphraseCheck = false;
15553
15587
  this.originalDescriptor = descriptor;
15554
15588
  }
15555
15589
 
@@ -15689,10 +15723,11 @@ class Device extends events.exports {
15689
15723
  getInternalState(_deviceId) {
15690
15724
  var _a, _b;
15691
15725
 
15692
- Log$4.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
15726
+ Log$4.debug('getInternalState session param: ', `device_id: ${_deviceId}`, `features.device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`, `skipPassphraseCheck: ${this.skipPassphraseCheck}`);
15693
15727
  Log$4.debug('getInternalState session cache: ', deviceSessionCache);
15694
15728
  const deviceId = _deviceId || ((_b = this.features) === null || _b === void 0 ? void 0 : _b.device_id);
15695
15729
  if (!deviceId) return undefined;
15730
+ if (this.skipPassphraseCheck) return deviceSessionCache[deviceId];
15696
15731
  if (!this.passphraseState) return undefined;
15697
15732
  const usePassKey = `${deviceId}@${this.passphraseState}`;
15698
15733
 
@@ -15712,7 +15747,11 @@ class Device extends events.exports {
15712
15747
 
15713
15748
  Log$4.debug('setInternalState session param: ', `state: ${state}`, `initSession: ${initSession}`, `device_id: ${(_a = this.features) === null || _a === void 0 ? void 0 : _a.device_id}`, `passphraseState: ${this.passphraseState}`);
15714
15749
  if (!this.features) return;
15715
- if (!this.passphraseState && !initSession) return;
15750
+
15751
+ if (!this.skipPassphraseCheck) {
15752
+ if (!this.passphraseState && !initSession) return;
15753
+ }
15754
+
15716
15755
  let key = `${this.features.device_id}`;
15717
15756
 
15718
15757
  if (this.passphraseState) {
@@ -15745,6 +15784,7 @@ class Device extends events.exports {
15745
15784
  return __awaiter(this, void 0, void 0, function* () {
15746
15785
  Log$4.debug('initialize param:', options);
15747
15786
  this.passphraseState = options === null || options === void 0 ? void 0 : options.passphraseState;
15787
+ this.skipPassphraseCheck = options === null || options === void 0 ? void 0 : options.skipPassphraseCheck;
15748
15788
 
15749
15789
  if (options === null || options === void 0 ? void 0 : options.initSession) {
15750
15790
  this.clearInternalState(options === null || options === void 0 ? void 0 : options.deviceId);
@@ -20847,6 +20887,7 @@ const Log = getLogger(exports.d0.Core);
20847
20887
  const parseInitOptions = method => ({
20848
20888
  initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
20849
20889
  passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
20890
+ skipPassphraseCheck: method === null || method === void 0 ? void 0 : method.payload.skipPassphraseCheck,
20850
20891
  deviceId: method === null || method === void 0 ? void 0 : method.payload.deviceId
20851
20892
  });
20852
20893
 
@@ -20935,7 +20976,8 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
20935
20976
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
20936
20977
  device.on(DEVICE.PIN, onDevicePinHandler);
20937
20978
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
20938
- device.on(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler);
20979
+ device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
20980
+ device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
20939
20981
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
20940
20982
 
20941
20983
  try {
@@ -21000,12 +21042,14 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
21000
21042
  }));
21001
21043
  }
21002
21044
 
21003
- const passphraseState = yield device.checkPassphraseState();
21004
- checkPassphraseSafety(method, device.features);
21045
+ if (!method.payload.skipPassphraseCheck) {
21046
+ const passphraseState = yield device.checkPassphraseState();
21047
+ checkPassphraseSafety(method, device.features);
21005
21048
 
21006
- if (passphraseState) {
21007
- DevicePool.clearDeviceCache(method.payload.connectId);
21008
- return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
21049
+ if (passphraseState) {
21050
+ DevicePool.clearDeviceCache(method.payload.connectId);
21051
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
21052
+ }
21009
21053
  }
21010
21054
  }
21011
21055
 
@@ -21268,6 +21312,7 @@ const cancel = connectId => {
21268
21312
 
21269
21313
  const checkPassphraseSafety = (method, features) => {
21270
21314
  if (!method.useDevicePassphraseState) return;
21315
+ if (method.payload.skipPassphraseCheck) return;
21271
21316
 
21272
21317
  if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
21273
21318
  DevicePool.clearDeviceCache(method.payload.connectId);
@@ -21288,7 +21333,8 @@ const cleanup = () => {
21288
21333
  const removeDeviceListener = device => {
21289
21334
  device.removeListener(DEVICE.PIN, onDevicePinHandler);
21290
21335
  device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
21291
- device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onDevicePassphraseHandler);
21336
+ device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
21337
+ device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
21292
21338
  device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
21293
21339
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
21294
21340
  };
@@ -21345,7 +21391,27 @@ const onDeviceFeaturesHandler = (...[_, features]) => {
21345
21391
  postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
21346
21392
  };
21347
21393
 
21348
- const onDevicePassphraseHandler = (...[device]) => {
21394
+ const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, void 0, void 0, function* () {
21395
+ Log.debug('onDevicePassphraseHandler');
21396
+ const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
21397
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE, {
21398
+ device: device.toMessageObject(),
21399
+ passphraseState: device.passphraseState
21400
+ }));
21401
+ const uiResp = yield uiPromise.promise;
21402
+ const {
21403
+ value,
21404
+ passphraseOnDevice,
21405
+ save
21406
+ } = uiResp.payload;
21407
+ callback({
21408
+ passphrase: value.normalize('NFKD'),
21409
+ passphraseOnDevice,
21410
+ cache: save
21411
+ });
21412
+ });
21413
+
21414
+ const onEnterPassphraseOnDeviceHandler = (...[device]) => {
21349
21415
  postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
21350
21416
  device: device.toMessageObject(),
21351
21417
  passphraseState: device.passphraseState
@@ -21377,6 +21443,7 @@ class Core extends events.exports {
21377
21443
  return __awaiter(this, void 0, void 0, function* () {
21378
21444
  switch (message.type) {
21379
21445
  case UI_RESPONSE.RECEIVE_PIN:
21446
+ case UI_RESPONSE.RECEIVE_PASSPHRASE:
21380
21447
  {
21381
21448
  const uiPromise = findUiPromise(message.type);
21382
21449
 
@@ -22820,7 +22887,8 @@ const HardwareErrorCode = {
22820
22887
  BridgeNotInstalled: 808,
22821
22888
  PollingTimeout: 809,
22822
22889
  PollingStop: 810,
22823
- BlindSignDisabled: 811
22890
+ BlindSignDisabled: 811,
22891
+ UnexpectPassphrase: 812
22824
22892
  };
22825
22893
  const HardwareErrorCodeMessage = {
22826
22894
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -22879,7 +22947,8 @@ const HardwareErrorCodeMessage = {
22879
22947
  [HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed',
22880
22948
  [HardwareErrorCode.PollingTimeout]: 'Polling timeout',
22881
22949
  [HardwareErrorCode.PollingStop]: 'Polling stop',
22882
- [HardwareErrorCode.BlindSignDisabled]: 'Please confirm the BlindSign enabled'
22950
+ [HardwareErrorCode.BlindSignDisabled]: 'Please confirm the BlindSign enabled',
22951
+ [HardwareErrorCode.UnexpectPassphrase]: 'Unexpect passphrase'
22883
22952
  };
22884
22953
 
22885
22954
  const TypedError = (hardwareError, message, params) => {
@@ -45606,7 +45675,7 @@ try {
45606
45675
  /***/ ((module) => {
45607
45676
 
45608
45677
  "use strict";
45609
- module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.1.49","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.1.49","@onekeyfe/hd-transport":"^0.1.49","axios":"^0.27.2","bignumber.js":"^9.0.2","js-sha256":"^0.9.0","parse-uri":"^1.0.7","semver":"^7.3.7"},"devDependencies":{"@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9"}}');
45678
+ module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.1.51","description":"> TODO: description","author":"OneKey","homepage":"https://github.com/OneKeyHQ/hardware-js-sdk#readme","license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/OneKeyHQ/hardware-js-sdk.git"},"publishConfig":{"access":"public"},"scripts":{"dev":"rimraf dist && rollup -c ../../build/rollup.config.js -w","build":"rimraf dist && rollup -c ../../build/rollup.config.js","lint":"eslint .","lint:fix":"eslint . --fix"},"bugs":{"url":"https://github.com/OneKeyHQ/hardware-js-sdk/issues"},"dependencies":{"@onekeyfe/hd-shared":"^0.1.51","@onekeyfe/hd-transport":"^0.1.51","axios":"^0.27.2","bignumber.js":"^9.0.2","js-sha256":"^0.9.0","parse-uri":"^1.0.7","semver":"^7.3.7"},"devDependencies":{"@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9"}}');
45610
45679
 
45611
45680
  /***/ })
45612
45681
 
@@ -48138,7 +48207,7 @@ const src_init = async settings => {
48138
48207
 
48139
48208
  try {
48140
48209
  await init({ ..._settings,
48141
- version: "0.1.49"
48210
+ version: "0.1.51"
48142
48211
  });
48143
48212
  return true;
48144
48213
  } catch (e) {