@onekeyfe/hd-core 0.1.11 → 0.1.14

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":"CheckBridgeStatus.d.ts","sourceRoot":"","sources":["../../src/api/CheckBridgeStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU;IACvD,IAAI;IAIE,GAAG;CAYV"}
1
+ {"version":3,"file":"CheckBridgeStatus.d.ts","sourceRoot":"","sources":["../../src/api/CheckBridgeStatus.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU;IACvD,IAAI;IAIE,GAAG;CAmBV"}
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceVerify.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceVerify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,UAAU,CAAC,wBAAwB,CAAC;IAC5E,IAAI;IAUE,GAAG;CAmCV"}
1
+ {"version":3,"file":"DeviceVerify.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceVerify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,UAAU,CAAC,wBAAwB,CAAC;IAC5E,IAAI;IAUE,GAAG;CAoCV"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AASlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAkBxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA4JjD,CAAC;AA+DF,eAAO,MAAM,MAAM,0CAalB,CAAC;AAuEF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA+BxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAGzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAgBnE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAQlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAkBxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA4JjD,CAAC;AA+DF,eAAO,MAAM,MAAM,0CAalB,CAAC;AAuEF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA+BxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAGzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAgBnE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_DOMAIN = "https://jssdk.onekey.so/";
2
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/data/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,6BAA6B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TransportManager.d.ts","sourceRoot":"","sources":["../../src/data-manager/TransportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAWnD,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC;IAE5B,MAAM,CAAC,eAAe,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEnD,MAAM,CAAC,eAAe,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEnD,MAAM,CAAC,eAAe,UAAS;IAE/B,MAAM,CAAC,IAAI;WAME,SAAS;WAsBT,WAAW,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,GAAG,IAAI;IAkB1D,MAAM,CAAC,YAAY,CAAC,oBAAoB,EAAE,GAAG;IAY7C,MAAM,CAAC,YAAY;IAInB,MAAM,CAAC,kBAAkB;IAIzB,MAAM,CAAC,kBAAkB;CAG1B"}
1
+ {"version":3,"file":"TransportManager.d.ts","sourceRoot":"","sources":["../../src/data-manager/TransportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAWnD,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC;IAE5B,MAAM,CAAC,eAAe,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IA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CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3C,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAClD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,EACV,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuC7B,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC;IAK3E,kBAAkB,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAkFhF,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,oBAAoB;CAuBhD;AAED,oBAAY,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import * as _onekeyfe_hd_transport from '@onekeyfe/hd-transport';
3
3
  import { Messages, EthereumPublicKey, EthereumMessageSignature, Success as Success$1, Address, MultisigRedeemScriptType, InputScriptType, PublicKey, MessageSignature, PrevInput, TxOutputBinType, TxInput, TxOutputType, TxInputType, RecoveryDeviceType, SafetyCheckLevel, StarcoinAddress as StarcoinAddress$1, StarcoinPublicKey as StarcoinPublicKey$1, StarcoinMessageSignature, StarcoinSignedTx, NEMAddress as NEMAddress$1, NEMSignedTx, SolanaAddress as SolanaAddress$1, SolanaSignedTx as SolanaSignedTx$1, StellarAddress as StellarAddress$1, StellarSignedTx, CipheredKeyValue as CipheredKeyValue$1, Transport, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
4
4
  export { Messages as PROTO } from '@onekeyfe/hd-transport';
5
5
  import { Deferred } from '@onekeyfe/hd-shared';
6
+ export { enableLog, initLog } from '@onekeyfe/hd-shared';
6
7
 
7
8
  interface CommonParams {
8
9
  keepSession?: boolean;
@@ -1242,27 +1243,6 @@ declare class Core extends EventEmitter {
1242
1243
  }
1243
1244
  declare const init: (settings: ConnectSettings, Transport: any) => Promise<Core | undefined>;
1244
1245
 
1245
- declare type LogMessage = {
1246
- level: string;
1247
- prefix: string;
1248
- message: any[];
1249
- timestamp: number;
1250
- };
1251
- declare class Log {
1252
- prefix: string;
1253
- enabled: boolean;
1254
- css: string;
1255
- messages: LogMessage[];
1256
- constructor(prefix: string, enabled: boolean);
1257
- addMessage(level: string, prefix: string, ...args: any[]): void;
1258
- log(...args: any[]): void;
1259
- error(...args: any[]): void;
1260
- warn(...args: any[]): void;
1261
- debug(...args: any[]): void;
1262
- }
1263
- declare const initLog: (prefix: string, enabled?: boolean | undefined) => Log;
1264
- declare const enableLog: (enabled?: boolean | undefined) => void;
1265
-
1266
1246
  declare const httpRequest: (url: string, type: string) => any;
1267
1247
  declare const getTimeStamp: () => number;
1268
1248
 
@@ -1319,4 +1299,4 @@ declare class DataManager {
1319
1299
 
1320
1300
  declare const HardwareSdk: ({ init, call, dispose, eventEmitter, uiResponse, cancel, }: InjectApi) => CoreApi;
1321
1301
 
1322
- export { AccountAddress, AccountAddresses, AssetsMap, BTCAddress, BTCGetAddressParams, BTCGetPublicKeyParams, BTCPublicKey, BTCSignMessageParams, BTCSignTransactionParams, BTCVerifyMessageParams, CORE_EVENT, CallMethod, CallMethodAnyResponse, CallMethodKeys, CallMethodPayload, CallMethodResponse, CallMethodUnion, CipheredKeyValue, CipheredKeyValueParams, CommonParams, ConnectSettings, Core, CoreApi, CoreMessage, DEFAULT_PRIORITY, DEVICE, DEVICE_EVENT, DataManager, Device$1 as Device, DeviceButtonRequest, DeviceButtonRequestPayload, DeviceChangePinParams, DeviceEvent, DeviceEventListenerFn, DeviceEventMessage, DeviceFirmwareRange, DeviceFlagsParams, DeviceMode, DeviceRecoveryParams, DeviceResetParams, DeviceSettingsParams, DeviceStatus, DeviceTypeMap, DeviceVerifyParams, DeviceVerifySignature, EVMAccessList, EVMAddress, EVMGetAddressParams, EVMGetPublicKeyParams, EVMPublicKey, EVMSignMessageEIP712Params, EVMSignMessageParams, EVMSignTransactionParams, EVMSignTypedDataParams, EVMSignedTx, EVMTransaction, EVMTransactionEIP1559, EVMVerifyMessageParams, EthereumSignTypedDataMessage, EthereumSignTypedDataTypeProperty, EthereumSignTypedDataTypes, Features, FirmwareProgress, FirmwareRange, FirmwareRelease, IBLEFirmwareReleaseInfo, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus, IDeviceModel, IDeviceType, IFRAME, IFirmwareReleaseInfo, IFrameBridge, IFrameCallMessage, IFrameCancelMessage, IFrameEvent, IFrameEventMessage, IFrameInit, ILocale, ITransportStatus, IVersionArray, KnownDevice, MajorVersion, MethodResponseMessage, NEMAddress, NEMAggregateModificationTransaction, NEMGetAddressParams, NEMImportanceTransaction, NEMMosaic, NEMMosaicCreationTransaction, NEMMultisigTransaction, NEMProvisionNamespaceTransaction, NEMSignTransactionParams, NEMSupplyChangeTransaction, NEMTransaction, NEMTransferTransaction, Params, PostMessageEvent, RESPONSE_EVENT, RefTransaction, ReleaseInfo, RemoteConfigResponse, Response, SearchDevice, SignedTransaction, SolanaAddress, SolanaGetAddressParams, SolanaSignTransactionParams, SolanaSignedTx, StarcoinAddress, StarcoinGetAddressParams, StarcoinGetPublicKeyParams, StarcoinPublicKey, StarcoinSignMessageParams, StarcoinSignTransactionParams, StarcoinVerifyMessageParams, StellarAddress, StellarAsset, StellarGetAddressParams, StellarOperation, StellarSignTransactionParams, StellarTransaction, StrictFeatures, Success, TransactionOptions, TransportReleaseStatus, UI_EVENT, UI_REQUEST, UI_RESPONSE, UiEvent, UiEventMessage, UiPromise, UiPromiseResponse, UiRequestButton, UiRequestDeviceAction, UiRequestWithoutPayload, UiResponseEvent, UiResponseMessage, UiResponsePin, UnavailableCapabilities, UnavailableCapability, Unsuccessful, VersionArray, corsValidator, createDeviceMessage, createErrorMessage, createIFrameMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default, enableLog, getDeviceLabel, getDeviceType, getDeviceTypeByBleName, getDeviceTypeByDeviceId, getDeviceUUID, getEnv, getHDPath, getScriptType, getTimeStamp, httpRequest, init as initCore, initLog, isValidVersionArray, isValidVersionString, normalizeVersionArray, parseConnectSettings, parseMessage, patchFeatures, safeThrowError, versionCompare, versionSplit };
1302
+ export { AccountAddress, AccountAddresses, AssetsMap, BTCAddress, BTCGetAddressParams, BTCGetPublicKeyParams, BTCPublicKey, BTCSignMessageParams, BTCSignTransactionParams, BTCVerifyMessageParams, CORE_EVENT, CallMethod, CallMethodAnyResponse, CallMethodKeys, CallMethodPayload, CallMethodResponse, CallMethodUnion, CipheredKeyValue, CipheredKeyValueParams, CommonParams, ConnectSettings, Core, CoreApi, CoreMessage, DEFAULT_PRIORITY, DEVICE, DEVICE_EVENT, DataManager, Device$1 as Device, DeviceButtonRequest, DeviceButtonRequestPayload, DeviceChangePinParams, DeviceEvent, DeviceEventListenerFn, DeviceEventMessage, DeviceFirmwareRange, DeviceFlagsParams, DeviceMode, DeviceRecoveryParams, DeviceResetParams, DeviceSettingsParams, DeviceStatus, DeviceTypeMap, DeviceVerifyParams, DeviceVerifySignature, EVMAccessList, EVMAddress, EVMGetAddressParams, EVMGetPublicKeyParams, EVMPublicKey, EVMSignMessageEIP712Params, EVMSignMessageParams, EVMSignTransactionParams, EVMSignTypedDataParams, EVMSignedTx, EVMTransaction, EVMTransactionEIP1559, EVMVerifyMessageParams, EthereumSignTypedDataMessage, EthereumSignTypedDataTypeProperty, EthereumSignTypedDataTypes, Features, FirmwareProgress, FirmwareRange, FirmwareRelease, IBLEFirmwareReleaseInfo, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus, IDeviceModel, IDeviceType, IFRAME, IFirmwareReleaseInfo, IFrameBridge, IFrameCallMessage, IFrameCancelMessage, IFrameEvent, IFrameEventMessage, IFrameInit, ILocale, ITransportStatus, IVersionArray, KnownDevice, MajorVersion, MethodResponseMessage, NEMAddress, NEMAggregateModificationTransaction, NEMGetAddressParams, NEMImportanceTransaction, NEMMosaic, NEMMosaicCreationTransaction, NEMMultisigTransaction, NEMProvisionNamespaceTransaction, NEMSignTransactionParams, NEMSupplyChangeTransaction, NEMTransaction, NEMTransferTransaction, Params, PostMessageEvent, RESPONSE_EVENT, RefTransaction, ReleaseInfo, RemoteConfigResponse, Response, SearchDevice, SignedTransaction, SolanaAddress, SolanaGetAddressParams, SolanaSignTransactionParams, SolanaSignedTx, StarcoinAddress, StarcoinGetAddressParams, StarcoinGetPublicKeyParams, StarcoinPublicKey, StarcoinSignMessageParams, StarcoinSignTransactionParams, StarcoinVerifyMessageParams, StellarAddress, StellarAsset, StellarGetAddressParams, StellarOperation, StellarSignTransactionParams, StellarTransaction, StrictFeatures, Success, TransactionOptions, TransportReleaseStatus, UI_EVENT, UI_REQUEST, UI_RESPONSE, UiEvent, UiEventMessage, UiPromise, UiPromiseResponse, UiRequestButton, UiRequestDeviceAction, UiRequestWithoutPayload, UiResponseEvent, UiResponseMessage, UiResponsePin, UnavailableCapabilities, UnavailableCapability, Unsuccessful, VersionArray, corsValidator, createDeviceMessage, createErrorMessage, createIFrameMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default, getDeviceLabel, getDeviceType, getDeviceTypeByBleName, getDeviceTypeByDeviceId, getDeviceUUID, getEnv, getHDPath, getScriptType, getTimeStamp, httpRequest, init as initCore, isValidVersionArray, isValidVersionString, normalizeVersionArray, parseConnectSettings, parseMessage, patchFeatures, safeThrowError, versionCompare, versionSplit };
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var semver = require('semver');
6
6
  var hdShared = require('@onekeyfe/hd-shared');
7
7
  var axios = require('axios');
8
8
  var BigNumber = require('bignumber.js');
9
+ var sha256 = require('js-sha256');
9
10
  var hdTransport = require('@onekeyfe/hd-transport');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -13,6 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
13
14
  var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
14
15
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
15
16
  var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
17
+ var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
16
18
 
17
19
  const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
18
20
  const api = {
@@ -608,78 +610,6 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
608
610
  }
609
611
  }
610
612
 
611
- const colors = {
612
- '@onekey/connect': 'color: #f4a742; background: #000;',
613
- IFrame: 'color: #f4a742; background: #000;',
614
- Core: 'color: #f4a742; background: #000;',
615
- DescriptorStream: 'color: #77ab59; background: #000;',
616
- DeviceList: 'color: #77ab59; background: #000;',
617
- Device: 'color: #bada55; background: #000;',
618
- DeviceCommands: 'color: #bada55; background: #000;',
619
- DeviceConnector: 'color: #bada55; background: #000;',
620
- Transport: 'color: #ffb6c1; background: #000;',
621
- };
622
- const MAX_ENTRIES = 100;
623
- class Log$6 {
624
- constructor(prefix, enabled) {
625
- this.prefix = prefix;
626
- this.enabled = enabled;
627
- this.messages = [];
628
- this.css = typeof window !== 'undefined' && colors[prefix] ? colors[prefix] : '';
629
- }
630
- addMessage(level, prefix, ...args) {
631
- this.messages.push({
632
- level,
633
- prefix,
634
- message: args,
635
- timestamp: new Date().getTime(),
636
- });
637
- if (this.messages.length > MAX_ENTRIES) {
638
- this.messages.shift();
639
- }
640
- }
641
- log(...args) {
642
- this.addMessage('log', this.prefix, ...args);
643
- if (this.enabled) {
644
- console.log(this.prefix, ...args);
645
- }
646
- }
647
- error(...args) {
648
- this.addMessage('error', this.prefix, ...args);
649
- if (this.enabled) {
650
- console.error(this.prefix, ...args);
651
- }
652
- }
653
- warn(...args) {
654
- this.addMessage('warn', this.prefix, ...args);
655
- if (this.enabled) {
656
- console.warn(this.prefix, ...args);
657
- }
658
- }
659
- debug(...args) {
660
- this.addMessage('debug', this.prefix, ...args);
661
- if (this.enabled) {
662
- if (this.css) {
663
- console.log(`%c${this.prefix}`, this.css, ...args);
664
- }
665
- else {
666
- console.log(this.prefix, ...args);
667
- }
668
- }
669
- }
670
- }
671
- const _logs = {};
672
- const initLog = (prefix, enabled) => {
673
- const instance = new Log$6(prefix, !!enabled);
674
- _logs[prefix] = instance;
675
- return instance;
676
- };
677
- const enableLog = (enabled) => {
678
- Object.keys(_logs).forEach(key => {
679
- _logs[key].enabled = !!enabled;
680
- });
681
- };
682
-
683
613
  const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
684
614
  const response = yield axios__default["default"].request({
685
615
  url,
@@ -9848,7 +9778,7 @@ DataManager.getTransportStatus = (localVersion) => {
9848
9778
  return isLatest ? 'valid' : 'outdated';
9849
9779
  };
9850
9780
 
9851
- const Log$5 = initLog('Transport');
9781
+ const Log$5 = hdShared.initLog('Transport');
9852
9782
  class TransportManager {
9853
9783
  static load() {
9854
9784
  console.log('transport manager load');
@@ -9878,6 +9808,9 @@ class TransportManager {
9878
9808
  }
9879
9809
  catch (error) {
9880
9810
  Log$5.debug('Initializing transports error: ', error);
9811
+ if (error.code === 'ECONNABORTED') {
9812
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
9813
+ }
9881
9814
  }
9882
9815
  });
9883
9816
  }
@@ -10022,10 +9955,10 @@ const createDeviceMessage = (type, payload) => ({
10022
9955
  const assertType = (res, resType) => {
10023
9956
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
10024
9957
  if (!splitResTypes.includes(res.type)) {
10025
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
9958
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
10026
9959
  }
10027
9960
  };
10028
- const Log$4 = initLog('DeviceCommands');
9961
+ const Log$4 = hdShared.initLog('DeviceCommands');
10029
9962
  class DeviceCommands {
10030
9963
  constructor(device, mainId) {
10031
9964
  this.device = device;
@@ -10043,8 +9976,9 @@ class DeviceCommands {
10043
9976
  (_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
10044
9977
  }
10045
9978
  call(type, msg = {}) {
9979
+ var _a, _b;
10046
9980
  return __awaiter(this, void 0, void 0, function* () {
10047
- console.log('[DeviceCommands] [call] Sending', type, this.transport);
9981
+ console.log('[DeviceCommands] [call] Sending', type);
10048
9982
  try {
10049
9983
  const promise = this.transport.call(this.mainId, type, msg);
10050
9984
  this.callPromise = promise;
@@ -10054,6 +9988,9 @@ class DeviceCommands {
10054
9988
  }
10055
9989
  catch (error) {
10056
9990
  Log$4.debug('[DeviceCommands] [call] Received error', error);
9991
+ if (((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === 'device disconnected during action') {
9992
+ return { type: 'BridgeNetworkError', message: {} };
9993
+ }
10057
9994
  throw error;
10058
9995
  }
10059
9996
  });
@@ -10069,7 +10006,16 @@ class DeviceCommands {
10069
10006
  }
10070
10007
  catch (error) {
10071
10008
  console.log('DeviceCommands typedcall error: ', error);
10072
- throw error;
10009
+ if (error instanceof hdShared.HardwareError) {
10010
+ if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
10011
+ if (error.message.indexOf('BridgeNetworkError') > -1) {
10012
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNetworkError);
10013
+ }
10014
+ }
10015
+ }
10016
+ else {
10017
+ throw error;
10018
+ }
10073
10019
  }
10074
10020
  return response;
10075
10021
  });
@@ -10164,13 +10110,12 @@ const UI_REQUEST = {
10164
10110
  NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
10165
10111
  };
10166
10112
 
10167
- const VERSION = '1.0.0-alpha.1';
10168
- const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
10113
+ const DEFAULT_DOMAIN = `https://jssdk.onekey.so/`;
10169
10114
 
10170
10115
  const DEFAULT_PRIORITY = 2;
10171
10116
  const initialSettings = {
10172
10117
  configSrc: './data/config.json',
10173
- version: VERSION,
10118
+ version: '',
10174
10119
  debug: false,
10175
10120
  priority: DEFAULT_PRIORITY,
10176
10121
  trustedHost: false,
@@ -10256,7 +10201,7 @@ const parseRunOptions = (options) => {
10256
10201
  options = {};
10257
10202
  return options;
10258
10203
  };
10259
- const Log$3 = initLog('Device');
10204
+ const Log$3 = hdShared.initLog('Device');
10260
10205
  class Device extends events.exports {
10261
10206
  constructor(descriptor) {
10262
10207
  super();
@@ -10562,7 +10507,7 @@ class Device extends events.exports {
10562
10507
  }
10563
10508
 
10564
10509
  const cacheDeviceMap = new Map();
10565
- const Log$2 = initLog('DeviceList');
10510
+ const Log$2 = hdShared.initLog('DeviceList');
10566
10511
  class DeviceList extends events.exports {
10567
10512
  constructor() {
10568
10513
  super(...arguments);
@@ -11642,15 +11587,23 @@ class CheckBridgeStatus extends BaseMethod {
11642
11587
  }
11643
11588
  run() {
11644
11589
  return __awaiter(this, void 0, void 0, function* () {
11645
- return new Promise(resolve => {
11590
+ return new Promise((resolve, reject) => {
11646
11591
  axios__default["default"]
11647
11592
  .request({
11648
11593
  url: 'http://localhost:21320',
11649
11594
  method: 'POST',
11650
11595
  withCredentials: false,
11596
+ timeout: 3000,
11651
11597
  })
11652
11598
  .then(() => resolve(true))
11653
- .catch(() => resolve(false));
11599
+ .catch(e => {
11600
+ if (e.code === 'ECONNABORTED') {
11601
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError));
11602
+ }
11603
+ else {
11604
+ resolve(false);
11605
+ }
11606
+ });
11654
11607
  });
11655
11608
  });
11656
11609
  }
@@ -11842,7 +11795,7 @@ class DeviceVerify extends BaseMethod {
11842
11795
  const deviceType = getDeviceType(this.device.features);
11843
11796
  let response;
11844
11797
  if (deviceType === 'classic') {
11845
- const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign({}, this.params));
11798
+ const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: sha256__default["default"].sha256(this.params.data) }));
11846
11799
  response = res.message;
11847
11800
  }
11848
11801
  else if (deviceType === 'mini') {
@@ -13314,7 +13267,7 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
13314
13267
  setTimeout(resolve, msec, value);
13315
13268
  });
13316
13269
 
13317
- const Log$1 = initLog('DeviceConnector');
13270
+ const Log$1 = hdShared.initLog('DeviceConnector');
13318
13271
  const getDiff = (current, descriptors) => {
13319
13272
  const env = DataManager.getSettings('env');
13320
13273
  if (env === 'react-native') {
@@ -13453,7 +13406,7 @@ class DeviceConnector {
13453
13406
  }
13454
13407
  }
13455
13408
 
13456
- const Log = initLog('Core');
13409
+ const Log = hdShared.initLog('Core');
13457
13410
  let _core;
13458
13411
  let _deviceList;
13459
13412
  let _connector;
@@ -13540,7 +13493,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13540
13493
  }
13541
13494
  try {
13542
13495
  const response = yield method.run();
13543
- Log.debug('Call API - Inner Method Run: ', device);
13496
+ Log.debug('Call API - Inner Method Run: ');
13544
13497
  messageResponse = createResponseMessage(method.responseID, true, response);
13545
13498
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
13546
13499
  }
@@ -13739,7 +13692,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
13739
13692
  catch (_b) {
13740
13693
  Log.error('DataManager.load error');
13741
13694
  }
13742
- enableLog(DataManager.getSettings('debug'));
13695
+ hdShared.enableLog(DataManager.getSettings('debug'));
13743
13696
  initCore();
13744
13697
  initConnector();
13745
13698
  return _core;
@@ -13758,6 +13711,14 @@ const HardwareSdk = ({ init, call, dispose, eventEmitter, uiResponse, cancel, })
13758
13711
  cancel,
13759
13712
  });
13760
13713
 
13714
+ Object.defineProperty(exports, 'enableLog', {
13715
+ enumerable: true,
13716
+ get: function () { return hdShared.enableLog; }
13717
+ });
13718
+ Object.defineProperty(exports, 'initLog', {
13719
+ enumerable: true,
13720
+ get: function () { return hdShared.initLog; }
13721
+ });
13761
13722
  Object.defineProperty(exports, 'PROTO', {
13762
13723
  enumerable: true,
13763
13724
  get: function () { return hdTransport.Messages; }
@@ -13781,7 +13742,6 @@ exports.createResponseMessage = createResponseMessage;
13781
13742
  exports.createUiMessage = createUiMessage;
13782
13743
  exports.createUiResponse = createUiResponse;
13783
13744
  exports["default"] = HardwareSdk;
13784
- exports.enableLog = enableLog;
13785
13745
  exports.getDeviceLabel = getDeviceLabel;
13786
13746
  exports.getDeviceType = getDeviceType;
13787
13747
  exports.getDeviceTypeByBleName = getDeviceTypeByBleName;
@@ -13793,7 +13753,6 @@ exports.getScriptType = getScriptType;
13793
13753
  exports.getTimeStamp = getTimeStamp;
13794
13754
  exports.httpRequest = httpRequest;
13795
13755
  exports.initCore = init;
13796
- exports.initLog = initLog;
13797
13756
  exports.isValidVersionArray = isValidVersionArray;
13798
13757
  exports.isValidVersionString = isValidVersionString;
13799
13758
  exports.normalizeVersionArray = normalizeVersionArray;
@@ -1,4 +1,4 @@
1
- import { initLog, enableLog } from './logger';
1
+ import { initLog, enableLog } from '@onekeyfe/hd-shared';
2
2
  export * from './assets';
3
3
  export * from './versionUtils';
4
4
  export * from './patch';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEzD,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.1.11",
3
+ "version": "0.1.14",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,10 +25,11 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "^0.1.11",
29
- "@onekeyfe/hd-transport": "^0.1.11",
28
+ "@onekeyfe/hd-shared": "^0.1.14",
29
+ "@onekeyfe/hd-transport": "^0.1.14",
30
30
  "axios": "^0.27.2",
31
31
  "bignumber.js": "^9.0.2",
32
+ "js-sha256": "^0.9.0",
32
33
  "parse-uri": "^1.0.7",
33
34
  "semver": "^7.3.7"
34
35
  },
@@ -36,5 +37,5 @@
36
37
  "@types/parse-uri": "^1.0.0",
37
38
  "@types/semver": "^7.3.9"
38
39
  },
39
- "gitHead": "4a71d9d0de15a8179cac16565be09f1c601ddfd5"
40
+ "gitHead": "216fee1795067013da0d68f4fc25f583509bb509"
40
41
  }
@@ -1,4 +1,5 @@
1
1
  import axios from 'axios';
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
3
  import { BaseMethod } from './BaseMethod';
3
4
 
4
5
  export default class CheckBridgeStatus extends BaseMethod {
@@ -7,15 +8,22 @@ export default class CheckBridgeStatus extends BaseMethod {
7
8
  }
8
9
 
9
10
  async run() {
10
- return new Promise<boolean>(resolve => {
11
+ return new Promise<boolean>((resolve, reject) => {
11
12
  axios
12
13
  .request({
13
14
  url: 'http://localhost:21320',
14
15
  method: 'POST',
15
16
  withCredentials: false,
17
+ timeout: 3000,
16
18
  })
17
19
  .then(() => resolve(true))
18
- .catch(() => resolve(false));
20
+ .catch(e => {
21
+ if (e.code === 'ECONNABORTED') {
22
+ reject(ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError));
23
+ } else {
24
+ resolve(false);
25
+ }
26
+ });
19
27
  });
20
28
  }
21
29
  }
@@ -1,3 +1,4 @@
1
+ import sha256 from 'js-sha256';
1
2
  import { BixinVerifyDeviceRequest } from '@onekeyfe/hd-transport';
2
3
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
4
  import { formatAnyHex } from '../helpers/hexUtils';
@@ -28,6 +29,7 @@ export default class DeviceVerify extends BaseMethod<BixinVerifyDeviceRequest> {
28
29
  'BixinVerifyDeviceAck',
29
30
  {
30
31
  ...this.params,
32
+ data: sha256.sha256(this.params.data),
31
33
  }
32
34
  );
33
35
  response = res.message;
package/src/core/index.ts CHANGED
@@ -6,8 +6,7 @@ import { Device, DeviceEvents } from '../device/Device';
6
6
  import { DeviceList } from '../device/DeviceList';
7
7
  import { findMethod } from '../api/utils';
8
8
  import { DataManager } from '../data-manager';
9
- import { enableLog } from '../utils/logger';
10
- import { initLog } from '../utils';
9
+ import { initLog, enableLog } from '../utils';
11
10
  import {
12
11
  CoreMessage,
13
12
  createResponseMessage,
@@ -162,7 +161,7 @@ export const callAPI = async (message: CoreMessage) => {
162
161
 
163
162
  try {
164
163
  const response: object = await method.run();
165
- Log.debug('Call API - Inner Method Run: ', device);
164
+ Log.debug('Call API - Inner Method Run: ');
166
165
  messageResponse = createResponseMessage(method.responseID, true, response);
167
166
  _callPromise?.resolve(messageResponse);
168
167
  } catch (error) {
@@ -0,0 +1 @@
1
+ export const DEFAULT_DOMAIN = `https://jssdk.onekey.so/`;
@@ -43,6 +43,9 @@ export default class TransportManager {
43
43
  Log.debug('Configuring transports done');
44
44
  } catch (error) {
45
45
  Log.debug('Initializing transports error: ', error);
46
+ if (error.code === 'ECONNABORTED') {
47
+ throw ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError);
48
+ }
46
49
  }
47
50
  }
48
51
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable vars-on-top */
2
2
 
3
3
  import type { ConnectSettings } from '../types';
4
- import { VERSION, DEFAULT_DOMAIN } from '../data/version';
4
+ import { DEFAULT_DOMAIN } from '../data/config';
5
5
 
6
6
  export const DEFAULT_PRIORITY = 2;
7
7
 
@@ -13,7 +13,7 @@ declare global {
13
13
 
14
14
  const initialSettings: ConnectSettings = {
15
15
  configSrc: './data/config.json', // constant
16
- version: VERSION, // constant
16
+ version: '', // constant
17
17
  debug: false,
18
18
  priority: DEFAULT_PRIORITY,
19
19
  trustedHost: false,
@@ -26,7 +26,7 @@ const assertType = (res: DefaultMessageResponse, resType: string | string[]) =>
26
26
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
27
27
  if (!splitResTypes.includes(res.type)) {
28
28
  throw ERRORS.TypedError(
29
- HardwareErrorCode.RuntimeError,
29
+ HardwareErrorCode.ResponseUnexpectTypeError,
30
30
  `assertType: Response of unexpected type: ${res.type}. Should be ${resType as string}`
31
31
  );
32
32
  }
@@ -68,7 +68,7 @@ export class DeviceCommands {
68
68
  type: MessageKey,
69
69
  msg: DefaultMessageResponse['message'] = {}
70
70
  ): Promise<DefaultMessageResponse> {
71
- console.log('[DeviceCommands] [call] Sending', type, this.transport);
71
+ console.log('[DeviceCommands] [call] Sending', type);
72
72
 
73
73
  try {
74
74
  const promise = this.transport.call(this.mainId, type, msg) as any;
@@ -78,6 +78,9 @@ export class DeviceCommands {
78
78
  return res;
79
79
  } catch (error) {
80
80
  Log.debug('[DeviceCommands] [call] Received error', error);
81
+ if (error?.response?.data?.error === 'device disconnected during action') {
82
+ return { type: 'BridgeNetworkError', message: {} } as any;
83
+ }
81
84
  throw error;
82
85
  }
83
86
  }
@@ -112,10 +115,21 @@ export class DeviceCommands {
112
115
  } catch (error) {
113
116
  // handle possible race condition
114
117
  // Bridge may have some unread message in buffer, read it
115
- // await this.transport.read(this.mainId);
116
- // throw error anyway, next call should be resolved properly
118
+ // await this.transport.read?.(this.mainId);
119
+
117
120
  console.log('DeviceCommands typedcall error: ', error);
118
- throw error;
121
+
122
+ // throw bridge network error
123
+ if (error instanceof HardwareError) {
124
+ if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
125
+ if (error.message.indexOf('BridgeNetworkError') > -1) {
126
+ throw ERRORS.TypedError(HardwareErrorCode.BridgeNetworkError);
127
+ }
128
+ }
129
+ } else {
130
+ // throw error anyway, next call should be resolved properly// throw error anyway, next call should be resolved properly
131
+ throw error;
132
+ }
119
133
  }
120
134
  return response;
121
135
  }
@@ -1,4 +1,4 @@
1
- import { initLog, enableLog } from './logger';
1
+ import { initLog, enableLog } from '@onekeyfe/hd-shared';
2
2
 
3
3
  export * from './assets';
4
4
  export * from './versionUtils';
@@ -1,3 +0,0 @@
1
- export declare const VERSION = "1.0.0-alpha.1";
2
- export declare const DEFAULT_DOMAIN = "https://hardware-sdk.onekey.so/";
3
- //# sourceMappingURL=version.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/data/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,kBAAkB,CAAC;AAEvC,eAAO,MAAM,cAAc,oCAAoC,CAAC"}
@@ -1,24 +0,0 @@
1
- declare type LogMessage = {
2
- level: string;
3
- prefix: string;
4
- message: any[];
5
- timestamp: number;
6
- };
7
- declare class Log {
8
- prefix: string;
9
- enabled: boolean;
10
- css: string;
11
- messages: LogMessage[];
12
- constructor(prefix: string, enabled: boolean);
13
- addMessage(level: string, prefix: string, ...args: any[]): void;
14
- log(...args: any[]): void;
15
- error(...args: any[]): void;
16
- warn(...args: any[]): void;
17
- debug(...args: any[]): void;
18
- }
19
- export declare const initLog: (prefix: string, enabled?: boolean | undefined) => Log;
20
- export declare const enableLog: (enabled?: boolean | undefined) => void;
21
- export declare const enableLogByPrefix: (prefix: string, enabled: boolean) => void;
22
- export declare const getLog: () => LogMessage[];
23
- export {};
24
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAeA,aAAK,UAAU,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,cAAM,GAAG;IACP,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,OAAO,CAAC;IAEjB,GAAG,EAAE,MAAM,CAAC;IAEZ,QAAQ,EAAE,UAAU,EAAE,CAAC;gBAEX,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAO5C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAYxD,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAOlB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAOpB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAOnB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAUrB;AAID,eAAO,MAAM,OAAO,WAAY,MAAM,uCAIrC,CAAC;AAEF,eAAO,MAAM,SAAS,yCAIrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,MAAM,WAAW,OAAO,SAIjE,CAAC;AAEF,eAAO,MAAM,MAAM,oBAOlB,CAAC"}
@@ -1,3 +0,0 @@
1
- export const VERSION = '1.0.0-alpha.1';
2
-
3
- export const DEFAULT_DOMAIN = `https://hardware-sdk.onekey.so/`;
@@ -1,113 +0,0 @@
1
- const colors: Record<string, string> = {
2
- // orange, api related
3
- '@onekey/connect': 'color: #f4a742; background: #000;',
4
- IFrame: 'color: #f4a742; background: #000;',
5
- Core: 'color: #f4a742; background: #000;',
6
- // green, device related
7
- DescriptorStream: 'color: #77ab59; background: #000;',
8
- DeviceList: 'color: #77ab59; background: #000;',
9
- Device: 'color: #bada55; background: #000;',
10
- DeviceCommands: 'color: #bada55; background: #000;',
11
- DeviceConnector: 'color: #bada55; background: #000;',
12
- // red, data-manager related
13
- Transport: 'color: #ffb6c1; background: #000;',
14
- };
15
-
16
- type LogMessage = {
17
- level: string;
18
- prefix: string;
19
- message: any[];
20
- timestamp: number;
21
- };
22
-
23
- const MAX_ENTRIES = 100;
24
-
25
- class Log {
26
- prefix: string;
27
-
28
- enabled: boolean;
29
-
30
- css: string;
31
-
32
- messages: LogMessage[];
33
-
34
- constructor(prefix: string, enabled: boolean) {
35
- this.prefix = prefix;
36
- this.enabled = enabled;
37
- this.messages = [];
38
- this.css = typeof window !== 'undefined' && colors[prefix] ? colors[prefix] : '';
39
- }
40
-
41
- addMessage(level: string, prefix: string, ...args: any[]) {
42
- this.messages.push({
43
- level,
44
- prefix,
45
- message: args,
46
- timestamp: new Date().getTime(),
47
- });
48
- if (this.messages.length > MAX_ENTRIES) {
49
- this.messages.shift();
50
- }
51
- }
52
-
53
- log(...args: any[]) {
54
- this.addMessage('log', this.prefix, ...args);
55
- if (this.enabled) {
56
- console.log(this.prefix, ...args);
57
- }
58
- }
59
-
60
- error(...args: any[]) {
61
- this.addMessage('error', this.prefix, ...args);
62
- if (this.enabled) {
63
- console.error(this.prefix, ...args);
64
- }
65
- }
66
-
67
- warn(...args: any[]) {
68
- this.addMessage('warn', this.prefix, ...args);
69
- if (this.enabled) {
70
- console.warn(this.prefix, ...args);
71
- }
72
- }
73
-
74
- debug(...args: any[]) {
75
- this.addMessage('debug', this.prefix, ...args);
76
- if (this.enabled) {
77
- if (this.css) {
78
- console.log(`%c${this.prefix}`, this.css, ...args);
79
- } else {
80
- console.log(this.prefix, ...args);
81
- }
82
- }
83
- }
84
- }
85
-
86
- const _logs: { [k: string]: Log } = {};
87
-
88
- export const initLog = (prefix: string, enabled?: boolean) => {
89
- const instance = new Log(prefix, !!enabled);
90
- _logs[prefix] = instance;
91
- return instance;
92
- };
93
-
94
- export const enableLog = (enabled?: boolean) => {
95
- Object.keys(_logs).forEach(key => {
96
- _logs[key].enabled = !!enabled;
97
- });
98
- };
99
-
100
- export const enableLogByPrefix = (prefix: string, enabled: boolean) => {
101
- if (_logs[prefix]) {
102
- _logs[prefix].enabled = enabled;
103
- }
104
- };
105
-
106
- export const getLog = () => {
107
- let logs: LogMessage[] = [];
108
- Object.keys(_logs).forEach(key => {
109
- logs = logs.concat(_logs[key].messages);
110
- });
111
- logs.sort((a, b) => a.timestamp - b.timestamp);
112
- return logs;
113
- };