@onekeyfe/hd-core 0.1.14 → 0.1.16

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 (45) hide show
  1. package/dist/api/GetLogs.d.ts +11 -0
  2. package/dist/api/GetLogs.d.ts.map +1 -0
  3. package/dist/api/index.d.ts +1 -0
  4. package/dist/api/index.d.ts.map +1 -1
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  7. package/dist/device/Device.d.ts.map +1 -1
  8. package/dist/events/core.d.ts +2 -1
  9. package/dist/events/core.d.ts.map +1 -1
  10. package/dist/events/index.d.ts +1 -0
  11. package/dist/events/index.d.ts.map +1 -1
  12. package/dist/events/log.d.ts +15 -0
  13. package/dist/events/log.d.ts.map +1 -0
  14. package/dist/index.d.ts +56 -3
  15. package/dist/index.js +471 -310
  16. package/dist/inject.d.ts.map +1 -1
  17. package/dist/types/api/getLogs.d.ts +3 -0
  18. package/dist/types/api/getLogs.d.ts.map +1 -0
  19. package/dist/types/api/index.d.ts +2 -0
  20. package/dist/types/api/index.d.ts.map +1 -1
  21. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  22. package/dist/utils/index.d.ts +1 -2
  23. package/dist/utils/index.d.ts.map +1 -1
  24. package/dist/utils/logger.d.ts +56 -0
  25. package/dist/utils/logger.d.ts.map +1 -0
  26. package/package.json +4 -4
  27. package/src/api/FirmwareUpdate.ts +1 -1
  28. package/src/api/GetLogs.ts +13 -0
  29. package/src/api/device/DeviceVerify.ts +1 -1
  30. package/src/api/index.ts +2 -0
  31. package/src/core/index.ts +9 -6
  32. package/src/data-manager/TransportManager.ts +8 -6
  33. package/src/device/Device.ts +2 -2
  34. package/src/device/DeviceCommands.ts +5 -5
  35. package/src/device/DeviceConnector.ts +3 -3
  36. package/src/device/DeviceList.ts +3 -3
  37. package/src/events/core.ts +2 -0
  38. package/src/events/index.ts +1 -0
  39. package/src/events/log.ts +23 -0
  40. package/src/inject.ts +2 -0
  41. package/src/types/api/getLogs.ts +3 -0
  42. package/src/types/api/index.ts +2 -0
  43. package/src/utils/deviceFeaturesUtils.ts +2 -10
  44. package/src/utils/index.ts +1 -3
  45. package/src/utils/logger.ts +179 -0
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
32
32
  dispose,
33
33
  uiResponse,
34
34
  cancel,
35
+ getLogs: () => call({ method: 'getLogs' }),
35
36
  searchDevices: () => call({ method: 'searchDevices' }),
36
37
  getFeatures: connectId => call({ connectId, method: 'getFeatures' }),
37
38
  checkFirmwareRelease: connectId => call({ connectId, method: 'checkFirmwareRelease' }),
@@ -610,281 +611,6 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
610
611
  }
611
612
  }
612
613
 
613
- const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
614
- const response = yield axios__default["default"].request({
615
- url,
616
- withCredentials: false,
617
- responseType: type === 'binary' ? 'arraybuffer' : 'json',
618
- });
619
- if (+response.status === 200) {
620
- if (type === 'json') {
621
- return response.data;
622
- }
623
- if (type === 'binary') {
624
- return response.data;
625
- }
626
- return response.data;
627
- }
628
- throw new Error(`httpRequest error: ${url} ${response.statusText}`);
629
- });
630
-
631
- const httpRequest = (url, type) => httpRequest$1(url, type);
632
- const getTimeStamp = () => new Date().getTime();
633
-
634
- const VER_NUMS = 3;
635
- const versionRegex = new RegExp(/^[0-9]{1,3}(\.[0-9]{1,3}){0,2}$/);
636
- const isValidVersionString = (version) => versionRegex.test(version);
637
- const isValidVersionArray = (version) => {
638
- if (!Array.isArray(version)) {
639
- return false;
640
- }
641
- if (version.length === 0 || version.length > VER_NUMS) {
642
- return false;
643
- }
644
- if (version[0] === 0) {
645
- return false;
646
- }
647
- for (let i = 0; i < version.length; i++) {
648
- if (typeof version[i] !== 'number' || version[i] < 0) {
649
- return false;
650
- }
651
- }
652
- return true;
653
- };
654
- const normalizeVersionArray = (version) => {
655
- if (version.length === VER_NUMS) {
656
- return version;
657
- }
658
- const partialVersion = [...version];
659
- for (let i = version.length; i < VER_NUMS; i++) {
660
- partialVersion.push(0);
661
- }
662
- return partialVersion;
663
- };
664
- const versionSplit = (version) => {
665
- if (!isValidVersionString(version)) {
666
- return [0, 0, 0];
667
- }
668
- return version.split('.').map(v => Number(v));
669
- };
670
- const versionCompare = (a, b) => {
671
- if (typeof a === 'string' && typeof b === 'string' && a === b) {
672
- return 0;
673
- }
674
- const pa = typeof a === 'string' ? versionSplit(a) : a;
675
- const pb = typeof b === 'string' ? versionSplit(b) : b;
676
- const vpa = isValidVersionArray(pa);
677
- const vpb = isValidVersionArray(pb);
678
- if (!vpa && !vpb) {
679
- return 0;
680
- }
681
- if (!vpa && vpb) {
682
- return -1;
683
- }
684
- if (vpa && !vpb) {
685
- return 1;
686
- }
687
- const npa = normalizeVersionArray(pa);
688
- const npb = normalizeVersionArray(pb);
689
- for (let i = 0; i < VER_NUMS; i++) {
690
- if (npa[i] > npb[i])
691
- return 1;
692
- if (npb[i] > npa[i])
693
- return -1;
694
- }
695
- return 0;
696
- };
697
-
698
- function patchFeatures(response) {
699
- if (response.type !== 'Features') {
700
- return response;
701
- }
702
- if (response.message.major_version < 1) {
703
- response.message.major_version = 1;
704
- }
705
- return response;
706
- }
707
-
708
- const getDeviceModel = (features) => {
709
- if (!features || typeof features !== 'object') {
710
- return 'model_mini';
711
- }
712
- if (features.model === '1') {
713
- return 'model_mini';
714
- }
715
- return 'model_touch';
716
- };
717
- const getDeviceType = (features) => {
718
- if (!features || typeof features !== 'object' || !features.serial_no) {
719
- return 'classic';
720
- }
721
- const serialNo = features.serial_no;
722
- const miniFlag = serialNo.slice(0, 2);
723
- if (miniFlag.toLowerCase() === 'mi')
724
- return 'mini';
725
- if (miniFlag.toLowerCase() === 'tc')
726
- return 'touch';
727
- return 'classic';
728
- };
729
- const getDeviceTypeOnBootloader = (features) => {
730
- if (!features || typeof features !== 'object') {
731
- return 'classic';
732
- }
733
- if (features.model === 'T') {
734
- return 'touch';
735
- }
736
- return getDeviceType(features);
737
- };
738
- const getDeviceTypeByBleName = (name) => {
739
- if (!name)
740
- return 'classic';
741
- if (name.startsWith('MI'))
742
- return 'mini';
743
- if (name.startsWith('T'))
744
- return 'touch';
745
- return 'classic';
746
- };
747
- const getDeviceTypeByDeviceId = (deviceId) => {
748
- if (!deviceId) {
749
- return 'classic';
750
- }
751
- const miniFlag = deviceId.slice(0, 2);
752
- if (miniFlag.toLowerCase() === 'mi')
753
- return 'mini';
754
- return 'classic';
755
- };
756
- const getDeviceUUID = (features) => {
757
- const deviceType = getDeviceType(features);
758
- if (deviceType === 'classic') {
759
- return features.onekey_serial;
760
- }
761
- return features.serial_no;
762
- };
763
- const getDeviceLabel = (features) => {
764
- const deviceType = getDeviceType(features);
765
- if (typeof features.label === 'string') {
766
- return features.label;
767
- }
768
- return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
769
- };
770
- const getDeviceFirmwareVersion = (features) => {
771
- if (!features)
772
- return [0, 0, 0];
773
- if (features.onekey_version) {
774
- return features.onekey_version.split('.');
775
- }
776
- return [features.major_version, features.minor_version, features.patch_version];
777
- };
778
- const getDeviceBLEFirmwareVersion = (features) => {
779
- if (!features.ble_ver) {
780
- return null;
781
- }
782
- return features.ble_ver.split('.');
783
- };
784
-
785
- const HD_HARDENED = 0x80000000;
786
- const toHardened = (n) => (n | HD_HARDENED) >>> 0;
787
- const fromHardened = (n) => (n & ~HD_HARDENED) >>> 0;
788
- const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
789
- const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
790
- const getHDPath = (path) => {
791
- const parts = path.toLowerCase().split('/');
792
- if (parts[0] !== 'm')
793
- throw PATH_NOT_VALID;
794
- return parts
795
- .filter((p) => p !== 'm' && p !== '')
796
- .map((p) => {
797
- let hardened = false;
798
- if (p.substr(p.length - 1) === "'") {
799
- hardened = true;
800
- p = p.substr(0, p.length - 1);
801
- }
802
- let n = parseInt(p);
803
- if (Number.isNaN(n)) {
804
- throw PATH_NOT_VALID;
805
- }
806
- else if (n < 0) {
807
- throw PATH_NEGATIVE_VALUES;
808
- }
809
- if (hardened) {
810
- n = toHardened(n);
811
- }
812
- return n;
813
- });
814
- };
815
- const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
816
- const isSegwitPath = (path) => Array.isArray(path) && path[0] === toHardened(49);
817
- const getScriptType = (path) => {
818
- if (!Array.isArray(path) || path.length < 1)
819
- return 'SPENDADDRESS';
820
- const p1 = fromHardened(path[0]);
821
- switch (p1) {
822
- case 48:
823
- return 'SPENDMULTISIG';
824
- case 49:
825
- return 'SPENDP2SHWITNESS';
826
- case 84:
827
- return 'SPENDWITNESS';
828
- default:
829
- return 'SPENDADDRESS';
830
- }
831
- };
832
- const getOutputScriptType = (path) => {
833
- if (!Array.isArray(path) || path.length < 1)
834
- return 'PAYTOADDRESS';
835
- if (path[0] === 49) {
836
- return 'PAYTOP2SHWITNESS';
837
- }
838
- const p = fromHardened(path[0]);
839
- switch (p) {
840
- case 48:
841
- return 'PAYTOMULTISIG';
842
- case 49:
843
- return 'PAYTOP2SHWITNESS';
844
- case 84:
845
- return 'PAYTOWITNESS';
846
- default:
847
- return 'PAYTOADDRESS';
848
- }
849
- };
850
- const serializedPath = (path) => {
851
- const pathStr = path
852
- .map((p) => {
853
- if (p & HD_HARDENED) {
854
- return `${p & ~HD_HARDENED}'`;
855
- }
856
- return p;
857
- })
858
- .join('/');
859
- return `m/${pathStr}`;
860
- };
861
- const validatePath = (path, length = 0, base = false) => {
862
- let valid;
863
- if (typeof path === 'string') {
864
- valid = getHDPath(path);
865
- }
866
- else if (Array.isArray(path)) {
867
- valid = path.map((p) => {
868
- const n = parseInt(p);
869
- if (Number.isNaN(n)) {
870
- throw PATH_NOT_VALID;
871
- }
872
- else if (n < 0) {
873
- throw PATH_NEGATIVE_VALUES;
874
- }
875
- return n;
876
- });
877
- }
878
- else {
879
- valid = undefined;
880
- }
881
- if (!valid)
882
- throw PATH_NOT_VALID;
883
- if (length > 0 && valid.length < length)
884
- throw PATH_NOT_VALID;
885
- return base ? valid.splice(0, 3) : valid;
886
- };
887
-
888
614
  var nested = {
889
615
  BinanceGetAddress: {
890
616
  fields: {
@@ -9634,9 +9360,426 @@ var nested = {
9634
9360
  }
9635
9361
  }
9636
9362
  };
9637
- var MessagesJSON = {
9638
- nested: nested
9363
+ var MessagesJSON = {
9364
+ nested: nested
9365
+ };
9366
+
9367
+ const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
9368
+ const response = yield axios__default["default"].request({
9369
+ url,
9370
+ withCredentials: false,
9371
+ responseType: type === 'binary' ? 'arraybuffer' : 'json',
9372
+ });
9373
+ if (+response.status === 200) {
9374
+ if (type === 'json') {
9375
+ return response.data;
9376
+ }
9377
+ if (type === 'binary') {
9378
+ return response.data;
9379
+ }
9380
+ return response.data;
9381
+ }
9382
+ throw new Error(`httpRequest error: ${url} ${response.statusText}`);
9383
+ });
9384
+
9385
+ const httpRequest = (url, type) => httpRequest$1(url, type);
9386
+ const getTimeStamp = () => new Date().getTime();
9387
+
9388
+ const VER_NUMS = 3;
9389
+ const versionRegex = new RegExp(/^[0-9]{1,3}(\.[0-9]{1,3}){0,2}$/);
9390
+ const isValidVersionString = (version) => versionRegex.test(version);
9391
+ const isValidVersionArray = (version) => {
9392
+ if (!Array.isArray(version)) {
9393
+ return false;
9394
+ }
9395
+ if (version.length === 0 || version.length > VER_NUMS) {
9396
+ return false;
9397
+ }
9398
+ if (version[0] === 0) {
9399
+ return false;
9400
+ }
9401
+ for (let i = 0; i < version.length; i++) {
9402
+ if (typeof version[i] !== 'number' || version[i] < 0) {
9403
+ return false;
9404
+ }
9405
+ }
9406
+ return true;
9407
+ };
9408
+ const normalizeVersionArray = (version) => {
9409
+ if (version.length === VER_NUMS) {
9410
+ return version;
9411
+ }
9412
+ const partialVersion = [...version];
9413
+ for (let i = version.length; i < VER_NUMS; i++) {
9414
+ partialVersion.push(0);
9415
+ }
9416
+ return partialVersion;
9417
+ };
9418
+ const versionSplit = (version) => {
9419
+ if (!isValidVersionString(version)) {
9420
+ return [0, 0, 0];
9421
+ }
9422
+ return version.split('.').map(v => Number(v));
9423
+ };
9424
+ const versionCompare = (a, b) => {
9425
+ if (typeof a === 'string' && typeof b === 'string' && a === b) {
9426
+ return 0;
9427
+ }
9428
+ const pa = typeof a === 'string' ? versionSplit(a) : a;
9429
+ const pb = typeof b === 'string' ? versionSplit(b) : b;
9430
+ const vpa = isValidVersionArray(pa);
9431
+ const vpb = isValidVersionArray(pb);
9432
+ if (!vpa && !vpb) {
9433
+ return 0;
9434
+ }
9435
+ if (!vpa && vpb) {
9436
+ return -1;
9437
+ }
9438
+ if (vpa && !vpb) {
9439
+ return 1;
9440
+ }
9441
+ const npa = normalizeVersionArray(pa);
9442
+ const npb = normalizeVersionArray(pb);
9443
+ for (let i = 0; i < VER_NUMS; i++) {
9444
+ if (npa[i] > npb[i])
9445
+ return 1;
9446
+ if (npb[i] > npa[i])
9447
+ return -1;
9448
+ }
9449
+ return 0;
9450
+ };
9451
+
9452
+ function patchFeatures(response) {
9453
+ if (response.type !== 'Features') {
9454
+ return response;
9455
+ }
9456
+ if (response.message.major_version < 1) {
9457
+ response.message.major_version = 1;
9458
+ }
9459
+ return response;
9460
+ }
9461
+
9462
+ const getDeviceModel = (features) => {
9463
+ if (!features || typeof features !== 'object') {
9464
+ return 'model_mini';
9465
+ }
9466
+ if (features.model === '1') {
9467
+ return 'model_mini';
9468
+ }
9469
+ return 'model_touch';
9470
+ };
9471
+ const getDeviceType = (features) => {
9472
+ if (!features || typeof features !== 'object' || !features.serial_no) {
9473
+ return 'classic';
9474
+ }
9475
+ const serialNo = features.serial_no;
9476
+ const miniFlag = serialNo.slice(0, 2);
9477
+ if (miniFlag.toLowerCase() === 'mi')
9478
+ return 'mini';
9479
+ if (miniFlag.toLowerCase() === 'tc')
9480
+ return 'touch';
9481
+ return 'classic';
9482
+ };
9483
+ const getDeviceTypeOnBootloader = (features) => getDeviceType(features);
9484
+ const getDeviceTypeByBleName = (name) => {
9485
+ if (!name)
9486
+ return 'classic';
9487
+ if (name.startsWith('MI'))
9488
+ return 'mini';
9489
+ if (name.startsWith('T'))
9490
+ return 'touch';
9491
+ return 'classic';
9492
+ };
9493
+ const getDeviceTypeByDeviceId = (deviceId) => {
9494
+ if (!deviceId) {
9495
+ return 'classic';
9496
+ }
9497
+ const miniFlag = deviceId.slice(0, 2);
9498
+ if (miniFlag.toLowerCase() === 'mi')
9499
+ return 'mini';
9500
+ return 'classic';
9501
+ };
9502
+ const getDeviceUUID = (features) => {
9503
+ const deviceType = getDeviceType(features);
9504
+ if (deviceType === 'classic') {
9505
+ return features.onekey_serial;
9506
+ }
9507
+ return features.serial_no;
9508
+ };
9509
+ const getDeviceLabel = (features) => {
9510
+ const deviceType = getDeviceType(features);
9511
+ if (typeof features.label === 'string') {
9512
+ return features.label;
9513
+ }
9514
+ return `My OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
9515
+ };
9516
+ const getDeviceFirmwareVersion = (features) => {
9517
+ if (!features)
9518
+ return [0, 0, 0];
9519
+ if (features.onekey_version) {
9520
+ return features.onekey_version.split('.');
9521
+ }
9522
+ return [features.major_version, features.minor_version, features.patch_version];
9523
+ };
9524
+ const getDeviceBLEFirmwareVersion = (features) => {
9525
+ if (!features.ble_ver) {
9526
+ return null;
9527
+ }
9528
+ return features.ble_ver.split('.');
9529
+ };
9530
+
9531
+ const HD_HARDENED = 0x80000000;
9532
+ const toHardened = (n) => (n | HD_HARDENED) >>> 0;
9533
+ const fromHardened = (n) => (n & ~HD_HARDENED) >>> 0;
9534
+ const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
9535
+ const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
9536
+ const getHDPath = (path) => {
9537
+ const parts = path.toLowerCase().split('/');
9538
+ if (parts[0] !== 'm')
9539
+ throw PATH_NOT_VALID;
9540
+ return parts
9541
+ .filter((p) => p !== 'm' && p !== '')
9542
+ .map((p) => {
9543
+ let hardened = false;
9544
+ if (p.substr(p.length - 1) === "'") {
9545
+ hardened = true;
9546
+ p = p.substr(0, p.length - 1);
9547
+ }
9548
+ let n = parseInt(p);
9549
+ if (Number.isNaN(n)) {
9550
+ throw PATH_NOT_VALID;
9551
+ }
9552
+ else if (n < 0) {
9553
+ throw PATH_NEGATIVE_VALUES;
9554
+ }
9555
+ if (hardened) {
9556
+ n = toHardened(n);
9557
+ }
9558
+ return n;
9559
+ });
9560
+ };
9561
+ const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
9562
+ const isSegwitPath = (path) => Array.isArray(path) && path[0] === toHardened(49);
9563
+ const getScriptType = (path) => {
9564
+ if (!Array.isArray(path) || path.length < 1)
9565
+ return 'SPENDADDRESS';
9566
+ const p1 = fromHardened(path[0]);
9567
+ switch (p1) {
9568
+ case 48:
9569
+ return 'SPENDMULTISIG';
9570
+ case 49:
9571
+ return 'SPENDP2SHWITNESS';
9572
+ case 84:
9573
+ return 'SPENDWITNESS';
9574
+ default:
9575
+ return 'SPENDADDRESS';
9576
+ }
9577
+ };
9578
+ const getOutputScriptType = (path) => {
9579
+ if (!Array.isArray(path) || path.length < 1)
9580
+ return 'PAYTOADDRESS';
9581
+ if (path[0] === 49) {
9582
+ return 'PAYTOP2SHWITNESS';
9583
+ }
9584
+ const p = fromHardened(path[0]);
9585
+ switch (p) {
9586
+ case 48:
9587
+ return 'PAYTOMULTISIG';
9588
+ case 49:
9589
+ return 'PAYTOP2SHWITNESS';
9590
+ case 84:
9591
+ return 'PAYTOWITNESS';
9592
+ default:
9593
+ return 'PAYTOADDRESS';
9594
+ }
9595
+ };
9596
+ const serializedPath = (path) => {
9597
+ const pathStr = path
9598
+ .map((p) => {
9599
+ if (p & HD_HARDENED) {
9600
+ return `${p & ~HD_HARDENED}'`;
9601
+ }
9602
+ return p;
9603
+ })
9604
+ .join('/');
9605
+ return `m/${pathStr}`;
9606
+ };
9607
+ const validatePath = (path, length = 0, base = false) => {
9608
+ let valid;
9609
+ if (typeof path === 'string') {
9610
+ valid = getHDPath(path);
9611
+ }
9612
+ else if (Array.isArray(path)) {
9613
+ valid = path.map((p) => {
9614
+ const n = parseInt(p);
9615
+ if (Number.isNaN(n)) {
9616
+ throw PATH_NOT_VALID;
9617
+ }
9618
+ else if (n < 0) {
9619
+ throw PATH_NEGATIVE_VALUES;
9620
+ }
9621
+ return n;
9622
+ });
9623
+ }
9624
+ else {
9625
+ valid = undefined;
9626
+ }
9627
+ if (!valid)
9628
+ throw PATH_NOT_VALID;
9629
+ if (length > 0 && valid.length < length)
9630
+ throw PATH_NOT_VALID;
9631
+ return base ? valid.splice(0, 3) : valid;
9632
+ };
9633
+
9634
+ const LOG_EVENT = 'LOG_EVENT';
9635
+ const LOG = {
9636
+ OUTPUT: 'log-output',
9637
+ };
9638
+ const createLogMessage = (type, payload) => ({
9639
+ event: LOG_EVENT,
9640
+ type,
9641
+ payload,
9642
+ });
9643
+
9644
+ const MAX_ENTRIES = 500;
9645
+ let postMessage$1;
9646
+ class Log$6 {
9647
+ constructor(prefix, enabled) {
9648
+ this.prefix = prefix;
9649
+ this.enabled = enabled;
9650
+ this.messages = [];
9651
+ }
9652
+ addMessage(level, prefix, ...args) {
9653
+ this.messages.push({
9654
+ level,
9655
+ prefix,
9656
+ message: args,
9657
+ timestamp: new Date().getTime(),
9658
+ });
9659
+ if (this.messages.length > MAX_ENTRIES) {
9660
+ this.messages.shift();
9661
+ }
9662
+ }
9663
+ log(...args) {
9664
+ this.addMessage('log', this.prefix, ...args);
9665
+ if (!this.enabled) {
9666
+ return;
9667
+ }
9668
+ sendLogMessage(this.prefix, ...args);
9669
+ console.log(this.prefix, ...args);
9670
+ }
9671
+ error(...args) {
9672
+ this.addMessage('error', this.prefix, ...args);
9673
+ if (!this.enabled) {
9674
+ return;
9675
+ }
9676
+ sendLogMessage(this.prefix, ...args);
9677
+ console.error(this.prefix, ...args);
9678
+ }
9679
+ warn(...args) {
9680
+ this.addMessage('warn', this.prefix, ...args);
9681
+ if (!this.enabled) {
9682
+ return;
9683
+ }
9684
+ sendLogMessage(this.prefix, ...args);
9685
+ console.warn(this.prefix, ...args);
9686
+ }
9687
+ debug(...args) {
9688
+ this.addMessage('debug', this.prefix, ...args);
9689
+ if (!this.enabled) {
9690
+ return;
9691
+ }
9692
+ sendLogMessage(this.prefix, ...args);
9693
+ console.log(this.prefix, ...args);
9694
+ }
9695
+ }
9696
+ const _logs = {};
9697
+ const initLog = (prefix, enabled) => {
9698
+ const instance = new Log$6(prefix, !!enabled);
9699
+ _logs[prefix] = instance;
9700
+ return instance;
9701
+ };
9702
+ const enableLog = (enabled) => {
9703
+ Object.keys(_logs).forEach(key => {
9704
+ _logs[key].enabled = !!enabled;
9705
+ });
9706
+ };
9707
+ const getLog = () => {
9708
+ let logs = [];
9709
+ Object.keys(_logs).forEach(key => {
9710
+ logs = logs.concat(_logs[key].messages);
9711
+ });
9712
+ logs.sort((a, b) => a.timestamp - b.timestamp);
9713
+ return logs;
9639
9714
  };
9715
+ const setLoggerPostMessage = (postMessageFn) => {
9716
+ postMessage$1 = postMessageFn;
9717
+ };
9718
+ const serializeLog = (...args) => args.map(arg => {
9719
+ if (typeof arg === 'string') {
9720
+ return arg;
9721
+ }
9722
+ if (typeof arg === 'number') {
9723
+ return arg;
9724
+ }
9725
+ if (typeof arg === 'boolean') {
9726
+ return arg;
9727
+ }
9728
+ if (typeof arg === 'undefined') {
9729
+ return arg;
9730
+ }
9731
+ if (typeof arg === 'object') {
9732
+ return JSON.stringify(arg, getCircularReplacer());
9733
+ }
9734
+ return arg;
9735
+ });
9736
+ const getCircularReplacer = () => {
9737
+ const seen = new WeakSet();
9738
+ return (_, value) => {
9739
+ if (typeof value === 'object' && value !== null) {
9740
+ if (seen.has(value)) {
9741
+ return;
9742
+ }
9743
+ seen.add(value);
9744
+ }
9745
+ return value;
9746
+ };
9747
+ };
9748
+ const sendLogMessage = (prefix, ...args) => {
9749
+ postMessage$1 === null || postMessage$1 === void 0 ? void 0 : postMessage$1(createLogMessage(LOG.OUTPUT, serializeLog(prefix, ...args)));
9750
+ };
9751
+ exports.LoggerNames = void 0;
9752
+ (function (LoggerNames) {
9753
+ LoggerNames["Core"] = "Core";
9754
+ LoggerNames["Transport"] = "Transport";
9755
+ LoggerNames["Device"] = "Device";
9756
+ LoggerNames["DeviceCommands"] = "DeviceCommands";
9757
+ LoggerNames["DeviceConnector"] = "DeviceConnector";
9758
+ LoggerNames["DeviceList"] = "DeviceList";
9759
+ LoggerNames["HdBleSdk"] = "@onekey/hd-ble-sdk";
9760
+ LoggerNames["HdTransportHttp"] = "@onekey/hd-transport-http";
9761
+ LoggerNames["HdBleTransport"] = "@onekey/hd-ble-transport";
9762
+ LoggerNames["Connect"] = "@onekey/connect";
9763
+ LoggerNames["Iframe"] = "IFrame";
9764
+ LoggerNames["SendMessage"] = "[SendMessage]";
9765
+ LoggerNames["Method"] = "[Method]";
9766
+ })(exports.LoggerNames || (exports.LoggerNames = {}));
9767
+ const LoggerMap = {
9768
+ [exports.LoggerNames.Core]: initLog(exports.LoggerNames.Core),
9769
+ [exports.LoggerNames.Transport]: initLog(exports.LoggerNames.Transport),
9770
+ [exports.LoggerNames.Device]: initLog(exports.LoggerNames.Device),
9771
+ [exports.LoggerNames.DeviceCommands]: initLog(exports.LoggerNames.DeviceCommands),
9772
+ [exports.LoggerNames.DeviceConnector]: initLog(exports.LoggerNames.DeviceConnector),
9773
+ [exports.LoggerNames.DeviceList]: initLog(exports.LoggerNames.DeviceList),
9774
+ [exports.LoggerNames.HdBleSdk]: initLog(exports.LoggerNames.HdBleSdk),
9775
+ [exports.LoggerNames.HdTransportHttp]: initLog(exports.LoggerNames.HdTransportHttp),
9776
+ [exports.LoggerNames.HdBleTransport]: initLog(exports.LoggerNames.HdBleTransport),
9777
+ [exports.LoggerNames.Connect]: initLog(exports.LoggerNames.Connect),
9778
+ [exports.LoggerNames.Iframe]: initLog(exports.LoggerNames.Iframe),
9779
+ [exports.LoggerNames.SendMessage]: initLog(exports.LoggerNames.SendMessage),
9780
+ [exports.LoggerNames.Method]: initLog(exports.LoggerNames.Method),
9781
+ };
9782
+ const getLogger = (key) => LoggerMap[key];
9640
9783
 
9641
9784
  const getReleaseStatus = (releases, currentVersion) => {
9642
9785
  const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
@@ -9778,10 +9921,12 @@ DataManager.getTransportStatus = (localVersion) => {
9778
9921
  return isLatest ? 'valid' : 'outdated';
9779
9922
  };
9780
9923
 
9781
- const Log$5 = hdShared.initLog('Transport');
9924
+ const Log$5 = getLogger(exports.LoggerNames.Transport);
9925
+ const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
9926
+ const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
9782
9927
  class TransportManager {
9783
9928
  static load() {
9784
- console.log('transport manager load');
9929
+ Log$5.debug('transport manager load');
9785
9930
  this.defaultMessages = DataManager.getProtobufMessages();
9786
9931
  this.currentMessages = this.defaultMessages;
9787
9932
  }
@@ -9792,7 +9937,7 @@ class TransportManager {
9792
9937
  Log$5.debug('Initializing transports');
9793
9938
  if (env === 'react-native') {
9794
9939
  if (!this.reactNativeInit) {
9795
- yield this.transport.init();
9940
+ yield this.transport.init(BleLogger);
9796
9941
  this.reactNativeInit = true;
9797
9942
  }
9798
9943
  else {
@@ -9800,7 +9945,7 @@ class TransportManager {
9800
9945
  }
9801
9946
  }
9802
9947
  else {
9803
- yield this.transport.init();
9948
+ yield this.transport.init(HttpLogger);
9804
9949
  }
9805
9950
  Log$5.debug('Configuring transports');
9806
9951
  yield this.transport.configure(JSON.stringify(this.defaultMessages));
@@ -9839,7 +9984,7 @@ class TransportManager {
9839
9984
  else {
9840
9985
  this.transport = new TransportConstructor();
9841
9986
  }
9842
- console.log('set transport: ', this.transport);
9987
+ Log$5.debug('set transport: ', this.transport);
9843
9988
  }
9844
9989
  static getTransport() {
9845
9990
  return this.transport;
@@ -9958,7 +10103,7 @@ const assertType = (res, resType) => {
9958
10103
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
9959
10104
  }
9960
10105
  };
9961
- const Log$4 = hdShared.initLog('DeviceCommands');
10106
+ const Log$4 = getLogger(exports.LoggerNames.DeviceCommands);
9962
10107
  class DeviceCommands {
9963
10108
  constructor(device, mainId) {
9964
10109
  this.device = device;
@@ -9978,7 +10123,7 @@ class DeviceCommands {
9978
10123
  call(type, msg = {}) {
9979
10124
  var _a, _b;
9980
10125
  return __awaiter(this, void 0, void 0, function* () {
9981
- console.log('[DeviceCommands] [call] Sending', type);
10126
+ Log$4.debug('[DeviceCommands] [call] Sending', type);
9982
10127
  try {
9983
10128
  const promise = this.transport.call(this.mainId, type, msg);
9984
10129
  this.callPromise = promise;
@@ -10005,7 +10150,7 @@ class DeviceCommands {
10005
10150
  assertType(response, resType);
10006
10151
  }
10007
10152
  catch (error) {
10008
- console.log('DeviceCommands typedcall error: ', error);
10153
+ Log$4.debug('DeviceCommands typedcall error: ', error);
10009
10154
  if (error instanceof hdShared.HardwareError) {
10010
10155
  if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
10011
10156
  if (error.message.indexOf('BridgeNetworkError') > -1) {
@@ -10027,7 +10172,7 @@ class DeviceCommands {
10027
10172
  });
10028
10173
  }
10029
10174
  _filterCommonTypes(res) {
10030
- console.log('_filterCommonTypes: ', res);
10175
+ Log$4.debug('_filterCommonTypes: ', res);
10031
10176
  if (res.type === 'Failure') {
10032
10177
  const { code } = res.message;
10033
10178
  const { message } = res.message;
@@ -10201,7 +10346,7 @@ const parseRunOptions = (options) => {
10201
10346
  options = {};
10202
10347
  return options;
10203
10348
  };
10204
- const Log$3 = hdShared.initLog('Device');
10349
+ const Log$3 = getLogger(exports.LoggerNames.Device);
10205
10350
  class Device extends events.exports {
10206
10351
  constructor(descriptor) {
10207
10352
  super();
@@ -10507,7 +10652,7 @@ class Device extends events.exports {
10507
10652
  }
10508
10653
 
10509
10654
  const cacheDeviceMap = new Map();
10510
- const Log$2 = hdShared.initLog('DeviceList');
10655
+ const Log$2 = getLogger(exports.LoggerNames.DeviceList);
10511
10656
  class DeviceList extends events.exports {
10512
10657
  constructor() {
10513
10658
  super(...arguments);
@@ -10521,7 +10666,7 @@ class DeviceList extends events.exports {
10521
10666
  const descriptorList = (_c = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _c !== void 0 ? _c : [];
10522
10667
  this.devices = {};
10523
10668
  const deviceList = [];
10524
- console.log('get device list');
10669
+ Log$2.debug('get device list');
10525
10670
  try {
10526
10671
  for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
10527
10672
  const descriptor = descriptorList_1_1.value;
@@ -11581,7 +11726,7 @@ class CheckTransportRelease extends BaseMethod {
11581
11726
  }
11582
11727
  }
11583
11728
 
11584
- class CheckBridgeStatus extends BaseMethod {
11729
+ class CheckBridgeStatus$1 extends BaseMethod {
11585
11730
  init() {
11586
11731
  this.useDevice = false;
11587
11732
  }
@@ -11798,7 +11943,7 @@ class DeviceVerify extends BaseMethod {
11798
11943
  const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: sha256__default["default"].sha256(this.params.data) }));
11799
11944
  response = res.message;
11800
11945
  }
11801
- else if (deviceType === 'mini') {
11946
+ else {
11802
11947
  const signatureRes = yield this.device.commands.typedCall('SESignMessage', 'SEMessageSignature', {
11803
11948
  message: this.params.data,
11804
11949
  });
@@ -13170,6 +13315,7 @@ class FirmwareUpdate extends BaseMethod {
13170
13315
  }
13171
13316
  }
13172
13317
  run() {
13318
+ var _a;
13173
13319
  return __awaiter(this, void 0, void 0, function* () {
13174
13320
  const { device, params } = this;
13175
13321
  let binary;
@@ -13190,13 +13336,25 @@ class FirmwareUpdate extends BaseMethod {
13190
13336
  }
13191
13337
  }
13192
13338
  catch (err) {
13193
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, err);
13339
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, (_a = err.message) !== null && _a !== void 0 ? _a : err);
13194
13340
  }
13195
13341
  return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, { payload: binary });
13196
13342
  });
13197
13343
  }
13198
13344
  }
13199
13345
 
13346
+ class CheckBridgeStatus extends BaseMethod {
13347
+ init() {
13348
+ this.useDevice = false;
13349
+ }
13350
+ run() {
13351
+ return __awaiter(this, void 0, void 0, function* () {
13352
+ const logs = getLog();
13353
+ return Promise.resolve(logs);
13354
+ });
13355
+ }
13356
+ }
13357
+
13200
13358
  var ApiMethods = /*#__PURE__*/Object.freeze({
13201
13359
  __proto__: null,
13202
13360
  searchDevices: SearchDevices,
@@ -13210,7 +13368,7 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
13210
13368
  checkFirmwareRelease: CheckFirmwareRelease,
13211
13369
  checkBLEFirmwareRelease: CheckBLEFirmwareRelease,
13212
13370
  checkTransportRelease: CheckTransportRelease,
13213
- checkBridgeStatus: CheckBridgeStatus,
13371
+ checkBridgeStatus: CheckBridgeStatus$1,
13214
13372
  deviceBackup: DeviceBackup,
13215
13373
  deviceChangePin: DeviceChangePin,
13216
13374
  deviceFlags: DeviceFlags,
@@ -13239,7 +13397,8 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
13239
13397
  solSignTransaction: SolSignTransaction,
13240
13398
  stellarGetAddress: StellarGetAddress,
13241
13399
  stellarSignTransaction: StellarSignTransaction,
13242
- firmwareUpdate: FirmwareUpdate
13400
+ firmwareUpdate: FirmwareUpdate,
13401
+ getLogs: CheckBridgeStatus
13243
13402
  });
13244
13403
 
13245
13404
  function findMethod(message) {
@@ -13267,7 +13426,7 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
13267
13426
  setTimeout(resolve, msec, value);
13268
13427
  });
13269
13428
 
13270
- const Log$1 = hdShared.initLog('DeviceConnector');
13429
+ const Log$1 = getLogger(exports.LoggerNames.DeviceConnector);
13271
13430
  const getDiff = (current, descriptors) => {
13272
13431
  const env = DataManager.getSettings('env');
13273
13432
  if (env === 'react-native') {
@@ -13371,7 +13530,7 @@ class DeviceConnector {
13371
13530
  }
13372
13531
  acquire(path, session) {
13373
13532
  return __awaiter(this, void 0, void 0, function* () {
13374
- console.log('acquire', path, session);
13533
+ Log$1.debug('acquire', path, session);
13375
13534
  const env = DataManager.getSettings('env');
13376
13535
  try {
13377
13536
  let res;
@@ -13406,7 +13565,7 @@ class DeviceConnector {
13406
13565
  }
13407
13566
  }
13408
13567
 
13409
- const Log = hdShared.initLog('Core');
13568
+ const Log = getLogger(exports.LoggerNames.Core);
13410
13569
  let _core;
13411
13570
  let _deviceList;
13412
13571
  let _connector;
@@ -13457,7 +13616,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13457
13616
  catch (error) {
13458
13617
  return Promise.reject(error);
13459
13618
  }
13460
- Log.debug('Call API - setDevice: ', device);
13619
+ Log.debug('Call API - setDevice: ', device.mainId);
13461
13620
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
13462
13621
  device.on(DEVICE.PIN, onDevicePinHandler);
13463
13622
  device.on(DEVICE.BUTTON, (d, code) => {
@@ -13503,14 +13662,14 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13503
13662
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
13504
13663
  }
13505
13664
  });
13506
- Log.debug('Call API - Device Run: ', device);
13665
+ Log.debug('Call API - Device Run: ', device.mainId);
13507
13666
  const deviceRun = () => device.run(inner);
13508
13667
  _callPromise = hdShared.createDeferred(deviceRun);
13509
13668
  try {
13510
13669
  return yield _callPromise.promise;
13511
13670
  }
13512
13671
  catch (e) {
13513
- console.log('Device Run Error: ', e);
13672
+ Log.debug('Device Run Error: ', e);
13514
13673
  return createResponseMessage(method.responseID, false, { error: e });
13515
13674
  }
13516
13675
  }
@@ -13607,7 +13766,7 @@ const closePopup = () => {
13607
13766
  postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
13608
13767
  };
13609
13768
  const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, void 0, void 0, function* () {
13610
- console.log('onDevicePinHandler');
13769
+ Log.debug('onDevicePinHandler');
13611
13770
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
13612
13771
  postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PIN, {
13613
13772
  device: device.toMessageObject(),
@@ -13692,7 +13851,10 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
13692
13851
  catch (_b) {
13693
13852
  Log.error('DataManager.load error');
13694
13853
  }
13695
- hdShared.enableLog(DataManager.getSettings('debug'));
13854
+ enableLog(DataManager.getSettings('debug'));
13855
+ if (DataManager.getSettings('env') !== 'react-native') {
13856
+ setLoggerPostMessage(postMessage);
13857
+ }
13696
13858
  initCore();
13697
13859
  initConnector();
13698
13860
  return _core;
@@ -13711,14 +13873,6 @@ const HardwareSdk = ({ init, call, dispose, eventEmitter, uiResponse, cancel, })
13711
13873
  cancel,
13712
13874
  });
13713
13875
 
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
- });
13722
13876
  Object.defineProperty(exports, 'PROTO', {
13723
13877
  enumerable: true,
13724
13878
  get: function () { return hdTransport.Messages; }
@@ -13730,6 +13884,8 @@ exports.DEVICE = DEVICE;
13730
13884
  exports.DEVICE_EVENT = DEVICE_EVENT;
13731
13885
  exports.DataManager = DataManager;
13732
13886
  exports.IFRAME = IFRAME;
13887
+ exports.LOG = LOG;
13888
+ exports.LOG_EVENT = LOG_EVENT;
13733
13889
  exports.RESPONSE_EVENT = RESPONSE_EVENT;
13734
13890
  exports.UI_EVENT = UI_EVENT;
13735
13891
  exports.UI_REQUEST = UI_REQUEST$1;
@@ -13738,10 +13894,12 @@ exports.corsValidator = corsValidator;
13738
13894
  exports.createDeviceMessage = createDeviceMessage;
13739
13895
  exports.createErrorMessage = createErrorMessage;
13740
13896
  exports.createIFrameMessage = createIFrameMessage;
13897
+ exports.createLogMessage = createLogMessage;
13741
13898
  exports.createResponseMessage = createResponseMessage;
13742
13899
  exports.createUiMessage = createUiMessage;
13743
13900
  exports.createUiResponse = createUiResponse;
13744
13901
  exports["default"] = HardwareSdk;
13902
+ exports.enableLog = enableLog;
13745
13903
  exports.getDeviceLabel = getDeviceLabel;
13746
13904
  exports.getDeviceType = getDeviceType;
13747
13905
  exports.getDeviceTypeByBleName = getDeviceTypeByBleName;
@@ -13749,6 +13907,8 @@ exports.getDeviceTypeByDeviceId = getDeviceTypeByDeviceId;
13749
13907
  exports.getDeviceUUID = getDeviceUUID;
13750
13908
  exports.getEnv = getEnv;
13751
13909
  exports.getHDPath = getHDPath;
13910
+ exports.getLog = getLog;
13911
+ exports.getLogger = getLogger;
13752
13912
  exports.getScriptType = getScriptType;
13753
13913
  exports.getTimeStamp = getTimeStamp;
13754
13914
  exports.httpRequest = httpRequest;
@@ -13760,5 +13920,6 @@ exports.parseConnectSettings = parseConnectSettings;
13760
13920
  exports.parseMessage = parseMessage;
13761
13921
  exports.patchFeatures = patchFeatures;
13762
13922
  exports.safeThrowError = safeThrowError;
13923
+ exports.setLoggerPostMessage = setLoggerPostMessage;
13763
13924
  exports.versionCompare = versionCompare;
13764
13925
  exports.versionSplit = versionSplit;