@onekeyfe/hd-web-sdk 0.2.9 → 0.2.11

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.
@@ -25933,11 +25933,12 @@ const modifyAddressParametersForBackwardsCompatibility = address_parameters => {
25933
25933
 
25934
25934
  class CardanoGetAddress extends BaseMethod {
25935
25935
  init() {
25936
- var _a;
25936
+ var _a, _b;
25937
25937
 
25938
25938
  this.checkDeviceId = true;
25939
25939
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
25940
25940
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
25941
+ this.isCheck = !!((_b = this.payload) === null || _b === void 0 ? void 0 : _b.isCheck);
25941
25942
  const payload = this.hasBundle ? this.payload : {
25942
25943
  bundle: [this.payload]
25943
25944
  };
@@ -25961,7 +25962,7 @@ class CardanoGetAddress extends BaseMethod {
25961
25962
  name: 'address',
25962
25963
  type: 'string'
25963
25964
  }, {
25964
- name: 'showOnTrezor',
25965
+ name: 'showOnOneKey',
25965
25966
  type: 'boolean'
25966
25967
  }]);
25967
25968
  validateAddressParameters(batch.addressParameters);
@@ -25971,11 +25972,19 @@ class CardanoGetAddress extends BaseMethod {
25971
25972
  protocol_magic: batch.protocolMagic,
25972
25973
  network_id: batch.networkId,
25973
25974
  derivation_type: typeof batch.derivationType !== 'undefined' ? batch.derivationType : hdTransport.Messages.CardanoDerivationType.ICARUS_TREZOR,
25974
- show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOneKey : true
25975
+ show_display: typeof batch.showOnOneKey === 'boolean' ? !!batch.showOnOneKey : true
25975
25976
  };
25976
25977
  });
25977
25978
  }
25978
25979
 
25980
+ getVersionRange() {
25981
+ return {
25982
+ model_mini: {
25983
+ min: '2.10.0'
25984
+ }
25985
+ };
25986
+ }
25987
+
25979
25988
  run() {
25980
25989
  return __awaiter(this, void 0, void 0, function* () {
25981
25990
  const responses = [];
@@ -25995,11 +26004,30 @@ class CardanoGetAddress extends BaseMethod {
25995
26004
  derivation_type,
25996
26005
  show_display
25997
26006
  });
25998
- const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
25999
- address_n: address_parameters.address_n.slice(0, 3),
26000
- derivation_type,
26001
- show_display
26002
- });
26007
+ let xpub;
26008
+ let stakeAddress;
26009
+
26010
+ if (address_parameters.address_type === hdTransport.Messages.CardanoAddressType.BASE && !this.isCheck) {
26011
+ const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
26012
+ address_n: address_parameters.address_n.slice(0, 3),
26013
+ derivation_type,
26014
+ show_display
26015
+ });
26016
+ xpub = publicKeyRes.message.xpub;
26017
+ const stakeAddressRes = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
26018
+ address_parameters: {
26019
+ address_type: hdTransport.Messages.CardanoAddressType.REWARD,
26020
+ address_n: [],
26021
+ address_n_staking: address_parameters.address_n_staking
26022
+ },
26023
+ protocol_magic,
26024
+ network_id,
26025
+ derivation_type,
26026
+ show_display
26027
+ });
26028
+ stakeAddress = stakeAddressRes.message.address;
26029
+ }
26030
+
26003
26031
  responses.push({
26004
26032
  addressParameters: addressParametersFromProto(batch.address_parameters),
26005
26033
  protocolMagic: batch.protocol_magic,
@@ -26007,7 +26035,8 @@ class CardanoGetAddress extends BaseMethod {
26007
26035
  serializedPath: serializedPath(batch.address_parameters.address_n),
26008
26036
  serializedStakingPath: serializedPath(batch.address_parameters.address_n_staking),
26009
26037
  address: response.message.address,
26010
- xpub: publicKeyRes.message.xpub
26038
+ xpub,
26039
+ stakeAddress
26011
26040
  });
26012
26041
  }
26013
26042
 
@@ -26051,6 +26080,14 @@ class CardanoGetPublicKey extends BaseMethod {
26051
26080
  });
26052
26081
  }
26053
26082
 
26083
+ getVersionRange() {
26084
+ return {
26085
+ model_mini: {
26086
+ min: '2.10.0'
26087
+ }
26088
+ };
26089
+ }
26090
+
26054
26091
  run() {
26055
26092
  return __awaiter(this, void 0, void 0, function* () {
26056
26093
  const responses = [];
@@ -26628,6 +26665,14 @@ const gatherWitnessPaths = (inputsWithPath, certificatesWithPoolOwnersAndRelays,
26628
26665
  };
26629
26666
 
26630
26667
  class CardanoSignTransaction extends BaseMethod {
26668
+ getVersionRange() {
26669
+ return {
26670
+ model_mini: {
26671
+ min: '2.10.0'
26672
+ }
26673
+ };
26674
+ }
26675
+
26631
26676
  init() {
26632
26677
  var _a;
26633
26678
 
@@ -27912,6 +27957,7 @@ __webpack_unused_export__ = getEnv;
27912
27957
  __webpack_unused_export__ = getHDPath;
27913
27958
  __webpack_unused_export__ = getLog;
27914
27959
  exports.jl = getLogger;
27960
+ __webpack_unused_export__ = getOutputScriptType;
27915
27961
  __webpack_unused_export__ = getSDKVersion;
27916
27962
  __webpack_unused_export__ = getScriptType;
27917
27963
  __webpack_unused_export__ = getTimeStamp;
@@ -43571,7 +43617,7 @@ module.exports = function GetIntrinsic(name, allowMissing) {
43571
43617
 
43572
43618
  var Buffer = (__webpack_require__(7834).Buffer)
43573
43619
  var Transform = (__webpack_require__(4851).Transform)
43574
- var StringDecoder = (__webpack_require__(214)/* .StringDecoder */ .s)
43620
+ var StringDecoder = (__webpack_require__(3974)/* .StringDecoder */ .s)
43575
43621
  var inherits = __webpack_require__(1285)
43576
43622
 
43577
43623
  function CipherBase (hashMode) {
@@ -60863,7 +60909,7 @@ function ReadableState(options, stream, isDuplex) {
60863
60909
  this.encoding = null;
60864
60910
 
60865
60911
  if (options.encoding) {
60866
- if (!StringDecoder) StringDecoder = (__webpack_require__(214)/* .StringDecoder */ .s);
60912
+ if (!StringDecoder) StringDecoder = (__webpack_require__(1922)/* .StringDecoder */ .s);
60867
60913
  this.decoder = new StringDecoder(options.encoding);
60868
60914
  this.encoding = options.encoding;
60869
60915
  }
@@ -61025,7 +61071,7 @@ Readable.prototype.isPaused = function () {
61025
61071
 
61026
61072
 
61027
61073
  Readable.prototype.setEncoding = function (enc) {
61028
- if (!StringDecoder) StringDecoder = (__webpack_require__(214)/* .StringDecoder */ .s);
61074
+ if (!StringDecoder) StringDecoder = (__webpack_require__(1922)/* .StringDecoder */ .s);
61029
61075
  var decoder = new StringDecoder(enc);
61030
61076
  this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
61031
61077
 
@@ -63548,6 +63594,309 @@ module.exports = {
63548
63594
  module.exports = __webpack_require__(2699).EventEmitter;
63549
63595
 
63550
63596
 
63597
+ /***/ }),
63598
+
63599
+ /***/ 1922:
63600
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
63601
+
63602
+ "use strict";
63603
+ // Copyright Joyent, Inc. and other Node contributors.
63604
+ //
63605
+ // Permission is hereby granted, free of charge, to any person obtaining a
63606
+ // copy of this software and associated documentation files (the
63607
+ // "Software"), to deal in the Software without restriction, including
63608
+ // without limitation the rights to use, copy, modify, merge, publish,
63609
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
63610
+ // persons to whom the Software is furnished to do so, subject to the
63611
+ // following conditions:
63612
+ //
63613
+ // The above copyright notice and this permission notice shall be included
63614
+ // in all copies or substantial portions of the Software.
63615
+ //
63616
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
63617
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63618
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
63619
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
63620
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
63621
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
63622
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
63623
+
63624
+
63625
+
63626
+ /*<replacement>*/
63627
+
63628
+ var Buffer = (__webpack_require__(7834).Buffer);
63629
+ /*</replacement>*/
63630
+
63631
+ var isEncoding = Buffer.isEncoding || function (encoding) {
63632
+ encoding = '' + encoding;
63633
+ switch (encoding && encoding.toLowerCase()) {
63634
+ case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
63635
+ return true;
63636
+ default:
63637
+ return false;
63638
+ }
63639
+ };
63640
+
63641
+ function _normalizeEncoding(enc) {
63642
+ if (!enc) return 'utf8';
63643
+ var retried;
63644
+ while (true) {
63645
+ switch (enc) {
63646
+ case 'utf8':
63647
+ case 'utf-8':
63648
+ return 'utf8';
63649
+ case 'ucs2':
63650
+ case 'ucs-2':
63651
+ case 'utf16le':
63652
+ case 'utf-16le':
63653
+ return 'utf16le';
63654
+ case 'latin1':
63655
+ case 'binary':
63656
+ return 'latin1';
63657
+ case 'base64':
63658
+ case 'ascii':
63659
+ case 'hex':
63660
+ return enc;
63661
+ default:
63662
+ if (retried) return; // undefined
63663
+ enc = ('' + enc).toLowerCase();
63664
+ retried = true;
63665
+ }
63666
+ }
63667
+ };
63668
+
63669
+ // Do not cache `Buffer.isEncoding` when checking encoding names as some
63670
+ // modules monkey-patch it to support additional encodings
63671
+ function normalizeEncoding(enc) {
63672
+ var nenc = _normalizeEncoding(enc);
63673
+ if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
63674
+ return nenc || enc;
63675
+ }
63676
+
63677
+ // StringDecoder provides an interface for efficiently splitting a series of
63678
+ // buffers into a series of JS strings without breaking apart multi-byte
63679
+ // characters.
63680
+ exports.s = StringDecoder;
63681
+ function StringDecoder(encoding) {
63682
+ this.encoding = normalizeEncoding(encoding);
63683
+ var nb;
63684
+ switch (this.encoding) {
63685
+ case 'utf16le':
63686
+ this.text = utf16Text;
63687
+ this.end = utf16End;
63688
+ nb = 4;
63689
+ break;
63690
+ case 'utf8':
63691
+ this.fillLast = utf8FillLast;
63692
+ nb = 4;
63693
+ break;
63694
+ case 'base64':
63695
+ this.text = base64Text;
63696
+ this.end = base64End;
63697
+ nb = 3;
63698
+ break;
63699
+ default:
63700
+ this.write = simpleWrite;
63701
+ this.end = simpleEnd;
63702
+ return;
63703
+ }
63704
+ this.lastNeed = 0;
63705
+ this.lastTotal = 0;
63706
+ this.lastChar = Buffer.allocUnsafe(nb);
63707
+ }
63708
+
63709
+ StringDecoder.prototype.write = function (buf) {
63710
+ if (buf.length === 0) return '';
63711
+ var r;
63712
+ var i;
63713
+ if (this.lastNeed) {
63714
+ r = this.fillLast(buf);
63715
+ if (r === undefined) return '';
63716
+ i = this.lastNeed;
63717
+ this.lastNeed = 0;
63718
+ } else {
63719
+ i = 0;
63720
+ }
63721
+ if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
63722
+ return r || '';
63723
+ };
63724
+
63725
+ StringDecoder.prototype.end = utf8End;
63726
+
63727
+ // Returns only complete characters in a Buffer
63728
+ StringDecoder.prototype.text = utf8Text;
63729
+
63730
+ // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
63731
+ StringDecoder.prototype.fillLast = function (buf) {
63732
+ if (this.lastNeed <= buf.length) {
63733
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
63734
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
63735
+ }
63736
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
63737
+ this.lastNeed -= buf.length;
63738
+ };
63739
+
63740
+ // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
63741
+ // continuation byte. If an invalid byte is detected, -2 is returned.
63742
+ function utf8CheckByte(byte) {
63743
+ if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
63744
+ return byte >> 6 === 0x02 ? -1 : -2;
63745
+ }
63746
+
63747
+ // Checks at most 3 bytes at the end of a Buffer in order to detect an
63748
+ // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
63749
+ // needed to complete the UTF-8 character (if applicable) are returned.
63750
+ function utf8CheckIncomplete(self, buf, i) {
63751
+ var j = buf.length - 1;
63752
+ if (j < i) return 0;
63753
+ var nb = utf8CheckByte(buf[j]);
63754
+ if (nb >= 0) {
63755
+ if (nb > 0) self.lastNeed = nb - 1;
63756
+ return nb;
63757
+ }
63758
+ if (--j < i || nb === -2) return 0;
63759
+ nb = utf8CheckByte(buf[j]);
63760
+ if (nb >= 0) {
63761
+ if (nb > 0) self.lastNeed = nb - 2;
63762
+ return nb;
63763
+ }
63764
+ if (--j < i || nb === -2) return 0;
63765
+ nb = utf8CheckByte(buf[j]);
63766
+ if (nb >= 0) {
63767
+ if (nb > 0) {
63768
+ if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
63769
+ }
63770
+ return nb;
63771
+ }
63772
+ return 0;
63773
+ }
63774
+
63775
+ // Validates as many continuation bytes for a multi-byte UTF-8 character as
63776
+ // needed or are available. If we see a non-continuation byte where we expect
63777
+ // one, we "replace" the validated continuation bytes we've seen so far with
63778
+ // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
63779
+ // behavior. The continuation byte check is included three times in the case
63780
+ // where all of the continuation bytes for a character exist in the same buffer.
63781
+ // It is also done this way as a slight performance increase instead of using a
63782
+ // loop.
63783
+ function utf8CheckExtraBytes(self, buf, p) {
63784
+ if ((buf[0] & 0xC0) !== 0x80) {
63785
+ self.lastNeed = 0;
63786
+ return '\ufffd';
63787
+ }
63788
+ if (self.lastNeed > 1 && buf.length > 1) {
63789
+ if ((buf[1] & 0xC0) !== 0x80) {
63790
+ self.lastNeed = 1;
63791
+ return '\ufffd';
63792
+ }
63793
+ if (self.lastNeed > 2 && buf.length > 2) {
63794
+ if ((buf[2] & 0xC0) !== 0x80) {
63795
+ self.lastNeed = 2;
63796
+ return '\ufffd';
63797
+ }
63798
+ }
63799
+ }
63800
+ }
63801
+
63802
+ // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
63803
+ function utf8FillLast(buf) {
63804
+ var p = this.lastTotal - this.lastNeed;
63805
+ var r = utf8CheckExtraBytes(this, buf, p);
63806
+ if (r !== undefined) return r;
63807
+ if (this.lastNeed <= buf.length) {
63808
+ buf.copy(this.lastChar, p, 0, this.lastNeed);
63809
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
63810
+ }
63811
+ buf.copy(this.lastChar, p, 0, buf.length);
63812
+ this.lastNeed -= buf.length;
63813
+ }
63814
+
63815
+ // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
63816
+ // partial character, the character's bytes are buffered until the required
63817
+ // number of bytes are available.
63818
+ function utf8Text(buf, i) {
63819
+ var total = utf8CheckIncomplete(this, buf, i);
63820
+ if (!this.lastNeed) return buf.toString('utf8', i);
63821
+ this.lastTotal = total;
63822
+ var end = buf.length - (total - this.lastNeed);
63823
+ buf.copy(this.lastChar, 0, end);
63824
+ return buf.toString('utf8', i, end);
63825
+ }
63826
+
63827
+ // For UTF-8, a replacement character is added when ending on a partial
63828
+ // character.
63829
+ function utf8End(buf) {
63830
+ var r = buf && buf.length ? this.write(buf) : '';
63831
+ if (this.lastNeed) return r + '\ufffd';
63832
+ return r;
63833
+ }
63834
+
63835
+ // UTF-16LE typically needs two bytes per character, but even if we have an even
63836
+ // number of bytes available, we need to check if we end on a leading/high
63837
+ // surrogate. In that case, we need to wait for the next two bytes in order to
63838
+ // decode the last character properly.
63839
+ function utf16Text(buf, i) {
63840
+ if ((buf.length - i) % 2 === 0) {
63841
+ var r = buf.toString('utf16le', i);
63842
+ if (r) {
63843
+ var c = r.charCodeAt(r.length - 1);
63844
+ if (c >= 0xD800 && c <= 0xDBFF) {
63845
+ this.lastNeed = 2;
63846
+ this.lastTotal = 4;
63847
+ this.lastChar[0] = buf[buf.length - 2];
63848
+ this.lastChar[1] = buf[buf.length - 1];
63849
+ return r.slice(0, -1);
63850
+ }
63851
+ }
63852
+ return r;
63853
+ }
63854
+ this.lastNeed = 1;
63855
+ this.lastTotal = 2;
63856
+ this.lastChar[0] = buf[buf.length - 1];
63857
+ return buf.toString('utf16le', i, buf.length - 1);
63858
+ }
63859
+
63860
+ // For UTF-16LE we do not explicitly append special replacement characters if we
63861
+ // end on a partial character, we simply let v8 handle that.
63862
+ function utf16End(buf) {
63863
+ var r = buf && buf.length ? this.write(buf) : '';
63864
+ if (this.lastNeed) {
63865
+ var end = this.lastTotal - this.lastNeed;
63866
+ return r + this.lastChar.toString('utf16le', 0, end);
63867
+ }
63868
+ return r;
63869
+ }
63870
+
63871
+ function base64Text(buf, i) {
63872
+ var n = (buf.length - i) % 3;
63873
+ if (n === 0) return buf.toString('base64', i);
63874
+ this.lastNeed = 3 - n;
63875
+ this.lastTotal = 3;
63876
+ if (n === 1) {
63877
+ this.lastChar[0] = buf[buf.length - 1];
63878
+ } else {
63879
+ this.lastChar[0] = buf[buf.length - 2];
63880
+ this.lastChar[1] = buf[buf.length - 1];
63881
+ }
63882
+ return buf.toString('base64', i, buf.length - n);
63883
+ }
63884
+
63885
+ function base64End(buf) {
63886
+ var r = buf && buf.length ? this.write(buf) : '';
63887
+ if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
63888
+ return r;
63889
+ }
63890
+
63891
+ // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
63892
+ function simpleWrite(buf) {
63893
+ return buf.toString(this.encoding);
63894
+ }
63895
+
63896
+ function simpleEnd(buf) {
63897
+ return buf && buf.length ? this.write(buf) : '';
63898
+ }
63899
+
63551
63900
  /***/ }),
63552
63901
 
63553
63902
  /***/ 696:
@@ -71332,10 +71681,9 @@ Stream.prototype.pipe = function(dest, options) {
71332
71681
 
71333
71682
  /***/ }),
71334
71683
 
71335
- /***/ 214:
71684
+ /***/ 3974:
71336
71685
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
71337
71686
 
71338
- "use strict";
71339
71687
  // Copyright Joyent, Inc. and other Node contributors.
71340
71688
  //
71341
71689
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -71357,282 +71705,208 @@ Stream.prototype.pipe = function(dest, options) {
71357
71705
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
71358
71706
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
71359
71707
 
71708
+ var Buffer = (__webpack_require__(8834).Buffer);
71360
71709
 
71710
+ var isBufferEncoding = Buffer.isEncoding
71711
+ || function(encoding) {
71712
+ switch (encoding && encoding.toLowerCase()) {
71713
+ case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
71714
+ default: return false;
71715
+ }
71716
+ }
71361
71717
 
71362
- /*<replacement>*/
71363
71718
 
71364
- var Buffer = (__webpack_require__(7834).Buffer);
71365
- /*</replacement>*/
71366
-
71367
- var isEncoding = Buffer.isEncoding || function (encoding) {
71368
- encoding = '' + encoding;
71369
- switch (encoding && encoding.toLowerCase()) {
71370
- case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
71371
- return true;
71372
- default:
71373
- return false;
71719
+ function assertEncoding(encoding) {
71720
+ if (encoding && !isBufferEncoding(encoding)) {
71721
+ throw new Error('Unknown encoding: ' + encoding);
71374
71722
  }
71375
- };
71376
-
71377
- function _normalizeEncoding(enc) {
71378
- if (!enc) return 'utf8';
71379
- var retried;
71380
- while (true) {
71381
- switch (enc) {
71382
- case 'utf8':
71383
- case 'utf-8':
71384
- return 'utf8';
71385
- case 'ucs2':
71386
- case 'ucs-2':
71387
- case 'utf16le':
71388
- case 'utf-16le':
71389
- return 'utf16le';
71390
- case 'latin1':
71391
- case 'binary':
71392
- return 'latin1';
71393
- case 'base64':
71394
- case 'ascii':
71395
- case 'hex':
71396
- return enc;
71397
- default:
71398
- if (retried) return; // undefined
71399
- enc = ('' + enc).toLowerCase();
71400
- retried = true;
71401
- }
71402
- }
71403
- };
71404
-
71405
- // Do not cache `Buffer.isEncoding` when checking encoding names as some
71406
- // modules monkey-patch it to support additional encodings
71407
- function normalizeEncoding(enc) {
71408
- var nenc = _normalizeEncoding(enc);
71409
- if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
71410
- return nenc || enc;
71411
71723
  }
71412
71724
 
71413
71725
  // StringDecoder provides an interface for efficiently splitting a series of
71414
71726
  // buffers into a series of JS strings without breaking apart multi-byte
71415
- // characters.
71416
- exports.s = StringDecoder;
71417
- function StringDecoder(encoding) {
71418
- this.encoding = normalizeEncoding(encoding);
71419
- var nb;
71727
+ // characters. CESU-8 is handled as part of the UTF-8 encoding.
71728
+ //
71729
+ // @TODO Handling all encodings inside a single object makes it very difficult
71730
+ // to reason about this code, so it should be split up in the future.
71731
+ // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
71732
+ // points as used by CESU-8.
71733
+ var StringDecoder = exports.s = function(encoding) {
71734
+ this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
71735
+ assertEncoding(encoding);
71420
71736
  switch (this.encoding) {
71421
- case 'utf16le':
71422
- this.text = utf16Text;
71423
- this.end = utf16End;
71424
- nb = 4;
71425
- break;
71426
71737
  case 'utf8':
71427
- this.fillLast = utf8FillLast;
71428
- nb = 4;
71738
+ // CESU-8 represents each of Surrogate Pair by 3-bytes
71739
+ this.surrogateSize = 3;
71740
+ break;
71741
+ case 'ucs2':
71742
+ case 'utf16le':
71743
+ // UTF-16 represents each of Surrogate Pair by 2-bytes
71744
+ this.surrogateSize = 2;
71745
+ this.detectIncompleteChar = utf16DetectIncompleteChar;
71429
71746
  break;
71430
71747
  case 'base64':
71431
- this.text = base64Text;
71432
- this.end = base64End;
71433
- nb = 3;
71748
+ // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
71749
+ this.surrogateSize = 3;
71750
+ this.detectIncompleteChar = base64DetectIncompleteChar;
71434
71751
  break;
71435
71752
  default:
71436
- this.write = simpleWrite;
71437
- this.end = simpleEnd;
71753
+ this.write = passThroughWrite;
71438
71754
  return;
71439
71755
  }
71440
- this.lastNeed = 0;
71441
- this.lastTotal = 0;
71442
- this.lastChar = Buffer.allocUnsafe(nb);
71443
- }
71444
71756
 
71445
- StringDecoder.prototype.write = function (buf) {
71446
- if (buf.length === 0) return '';
71447
- var r;
71448
- var i;
71449
- if (this.lastNeed) {
71450
- r = this.fillLast(buf);
71451
- if (r === undefined) return '';
71452
- i = this.lastNeed;
71453
- this.lastNeed = 0;
71454
- } else {
71455
- i = 0;
71456
- }
71457
- if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
71458
- return r || '';
71757
+ // Enough space to store all bytes of a single character. UTF-8 needs 4
71758
+ // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
71759
+ this.charBuffer = new Buffer(6);
71760
+ // Number of bytes received for the current incomplete multi-byte character.
71761
+ this.charReceived = 0;
71762
+ // Number of bytes expected for the current incomplete multi-byte character.
71763
+ this.charLength = 0;
71459
71764
  };
71460
71765
 
71461
- StringDecoder.prototype.end = utf8End;
71462
71766
 
71463
- // Returns only complete characters in a Buffer
71464
- StringDecoder.prototype.text = utf8Text;
71767
+ // write decodes the given buffer and returns it as JS string that is
71768
+ // guaranteed to not contain any partial multi-byte characters. Any partial
71769
+ // character found at the end of the buffer is buffered up, and will be
71770
+ // returned when calling write again with the remaining bytes.
71771
+ //
71772
+ // Note: Converting a Buffer containing an orphan surrogate to a String
71773
+ // currently works, but converting a String to a Buffer (via `new Buffer`, or
71774
+ // Buffer#write) will replace incomplete surrogates with the unicode
71775
+ // replacement character. See https://codereview.chromium.org/121173009/ .
71776
+ StringDecoder.prototype.write = function(buffer) {
71777
+ var charStr = '';
71778
+ // if our last write ended with an incomplete multibyte character
71779
+ while (this.charLength) {
71780
+ // determine how many remaining bytes this buffer has to offer for this char
71781
+ var available = (buffer.length >= this.charLength - this.charReceived) ?
71782
+ this.charLength - this.charReceived :
71783
+ buffer.length;
71784
+
71785
+ // add the new bytes to the char buffer
71786
+ buffer.copy(this.charBuffer, this.charReceived, 0, available);
71787
+ this.charReceived += available;
71788
+
71789
+ if (this.charReceived < this.charLength) {
71790
+ // still not enough chars in this buffer? wait for more ...
71791
+ return '';
71792
+ }
71793
+
71794
+ // remove bytes belonging to the current character from the buffer
71795
+ buffer = buffer.slice(available, buffer.length);
71796
+
71797
+ // get the character that was split
71798
+ charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
71799
+
71800
+ // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
71801
+ var charCode = charStr.charCodeAt(charStr.length - 1);
71802
+ if (charCode >= 0xD800 && charCode <= 0xDBFF) {
71803
+ this.charLength += this.surrogateSize;
71804
+ charStr = '';
71805
+ continue;
71806
+ }
71807
+ this.charReceived = this.charLength = 0;
71465
71808
 
71466
- // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
71467
- StringDecoder.prototype.fillLast = function (buf) {
71468
- if (this.lastNeed <= buf.length) {
71469
- buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
71470
- return this.lastChar.toString(this.encoding, 0, this.lastTotal);
71809
+ // if there are no more bytes in this buffer, just emit our char
71810
+ if (buffer.length === 0) {
71811
+ return charStr;
71812
+ }
71813
+ break;
71471
71814
  }
71472
- buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
71473
- this.lastNeed -= buf.length;
71474
- };
71475
71815
 
71476
- // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
71477
- // continuation byte. If an invalid byte is detected, -2 is returned.
71478
- function utf8CheckByte(byte) {
71479
- if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
71480
- return byte >> 6 === 0x02 ? -1 : -2;
71481
- }
71816
+ // determine and set charLength / charReceived
71817
+ this.detectIncompleteChar(buffer);
71482
71818
 
71483
- // Checks at most 3 bytes at the end of a Buffer in order to detect an
71484
- // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
71485
- // needed to complete the UTF-8 character (if applicable) are returned.
71486
- function utf8CheckIncomplete(self, buf, i) {
71487
- var j = buf.length - 1;
71488
- if (j < i) return 0;
71489
- var nb = utf8CheckByte(buf[j]);
71490
- if (nb >= 0) {
71491
- if (nb > 0) self.lastNeed = nb - 1;
71492
- return nb;
71493
- }
71494
- if (--j < i || nb === -2) return 0;
71495
- nb = utf8CheckByte(buf[j]);
71496
- if (nb >= 0) {
71497
- if (nb > 0) self.lastNeed = nb - 2;
71498
- return nb;
71819
+ var end = buffer.length;
71820
+ if (this.charLength) {
71821
+ // buffer the incomplete character bytes we got
71822
+ buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
71823
+ end -= this.charReceived;
71499
71824
  }
71500
- if (--j < i || nb === -2) return 0;
71501
- nb = utf8CheckByte(buf[j]);
71502
- if (nb >= 0) {
71503
- if (nb > 0) {
71504
- if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
71505
- }
71506
- return nb;
71507
- }
71508
- return 0;
71509
- }
71510
71825
 
71511
- // Validates as many continuation bytes for a multi-byte UTF-8 character as
71512
- // needed or are available. If we see a non-continuation byte where we expect
71513
- // one, we "replace" the validated continuation bytes we've seen so far with
71514
- // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
71515
- // behavior. The continuation byte check is included three times in the case
71516
- // where all of the continuation bytes for a character exist in the same buffer.
71517
- // It is also done this way as a slight performance increase instead of using a
71518
- // loop.
71519
- function utf8CheckExtraBytes(self, buf, p) {
71520
- if ((buf[0] & 0xC0) !== 0x80) {
71521
- self.lastNeed = 0;
71522
- return '\ufffd';
71523
- }
71524
- if (self.lastNeed > 1 && buf.length > 1) {
71525
- if ((buf[1] & 0xC0) !== 0x80) {
71526
- self.lastNeed = 1;
71527
- return '\ufffd';
71528
- }
71529
- if (self.lastNeed > 2 && buf.length > 2) {
71530
- if ((buf[2] & 0xC0) !== 0x80) {
71531
- self.lastNeed = 2;
71532
- return '\ufffd';
71533
- }
71534
- }
71535
- }
71536
- }
71826
+ charStr += buffer.toString(this.encoding, 0, end);
71537
71827
 
71538
- // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
71539
- function utf8FillLast(buf) {
71540
- var p = this.lastTotal - this.lastNeed;
71541
- var r = utf8CheckExtraBytes(this, buf, p);
71542
- if (r !== undefined) return r;
71543
- if (this.lastNeed <= buf.length) {
71544
- buf.copy(this.lastChar, p, 0, this.lastNeed);
71545
- return this.lastChar.toString(this.encoding, 0, this.lastTotal);
71828
+ var end = charStr.length - 1;
71829
+ var charCode = charStr.charCodeAt(end);
71830
+ // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
71831
+ if (charCode >= 0xD800 && charCode <= 0xDBFF) {
71832
+ var size = this.surrogateSize;
71833
+ this.charLength += size;
71834
+ this.charReceived += size;
71835
+ this.charBuffer.copy(this.charBuffer, size, 0, size);
71836
+ buffer.copy(this.charBuffer, 0, 0, size);
71837
+ return charStr.substring(0, end);
71546
71838
  }
71547
- buf.copy(this.lastChar, p, 0, buf.length);
71548
- this.lastNeed -= buf.length;
71549
- }
71550
71839
 
71551
- // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
71552
- // partial character, the character's bytes are buffered until the required
71553
- // number of bytes are available.
71554
- function utf8Text(buf, i) {
71555
- var total = utf8CheckIncomplete(this, buf, i);
71556
- if (!this.lastNeed) return buf.toString('utf8', i);
71557
- this.lastTotal = total;
71558
- var end = buf.length - (total - this.lastNeed);
71559
- buf.copy(this.lastChar, 0, end);
71560
- return buf.toString('utf8', i, end);
71561
- }
71840
+ // or just emit the charStr
71841
+ return charStr;
71842
+ };
71562
71843
 
71563
- // For UTF-8, a replacement character is added when ending on a partial
71564
- // character.
71565
- function utf8End(buf) {
71566
- var r = buf && buf.length ? this.write(buf) : '';
71567
- if (this.lastNeed) return r + '\ufffd';
71568
- return r;
71569
- }
71844
+ // detectIncompleteChar determines if there is an incomplete UTF-8 character at
71845
+ // the end of the given buffer. If so, it sets this.charLength to the byte
71846
+ // length that character, and sets this.charReceived to the number of bytes
71847
+ // that are available for this character.
71848
+ StringDecoder.prototype.detectIncompleteChar = function(buffer) {
71849
+ // determine how many bytes we have to check at the end of this buffer
71850
+ var i = (buffer.length >= 3) ? 3 : buffer.length;
71570
71851
 
71571
- // UTF-16LE typically needs two bytes per character, but even if we have an even
71572
- // number of bytes available, we need to check if we end on a leading/high
71573
- // surrogate. In that case, we need to wait for the next two bytes in order to
71574
- // decode the last character properly.
71575
- function utf16Text(buf, i) {
71576
- if ((buf.length - i) % 2 === 0) {
71577
- var r = buf.toString('utf16le', i);
71578
- if (r) {
71579
- var c = r.charCodeAt(r.length - 1);
71580
- if (c >= 0xD800 && c <= 0xDBFF) {
71581
- this.lastNeed = 2;
71582
- this.lastTotal = 4;
71583
- this.lastChar[0] = buf[buf.length - 2];
71584
- this.lastChar[1] = buf[buf.length - 1];
71585
- return r.slice(0, -1);
71586
- }
71852
+ // Figure out if one of the last i bytes of our buffer announces an
71853
+ // incomplete char.
71854
+ for (; i > 0; i--) {
71855
+ var c = buffer[buffer.length - i];
71856
+
71857
+ // See http://en.wikipedia.org/wiki/UTF-8#Description
71858
+
71859
+ // 110XXXXX
71860
+ if (i == 1 && c >> 5 == 0x06) {
71861
+ this.charLength = 2;
71862
+ break;
71587
71863
  }
71588
- return r;
71589
- }
71590
- this.lastNeed = 1;
71591
- this.lastTotal = 2;
71592
- this.lastChar[0] = buf[buf.length - 1];
71593
- return buf.toString('utf16le', i, buf.length - 1);
71594
- }
71595
71864
 
71596
- // For UTF-16LE we do not explicitly append special replacement characters if we
71597
- // end on a partial character, we simply let v8 handle that.
71598
- function utf16End(buf) {
71599
- var r = buf && buf.length ? this.write(buf) : '';
71600
- if (this.lastNeed) {
71601
- var end = this.lastTotal - this.lastNeed;
71602
- return r + this.lastChar.toString('utf16le', 0, end);
71865
+ // 1110XXXX
71866
+ if (i <= 2 && c >> 4 == 0x0E) {
71867
+ this.charLength = 3;
71868
+ break;
71869
+ }
71870
+
71871
+ // 11110XXX
71872
+ if (i <= 3 && c >> 3 == 0x1E) {
71873
+ this.charLength = 4;
71874
+ break;
71875
+ }
71603
71876
  }
71604
- return r;
71605
- }
71877
+ this.charReceived = i;
71878
+ };
71606
71879
 
71607
- function base64Text(buf, i) {
71608
- var n = (buf.length - i) % 3;
71609
- if (n === 0) return buf.toString('base64', i);
71610
- this.lastNeed = 3 - n;
71611
- this.lastTotal = 3;
71612
- if (n === 1) {
71613
- this.lastChar[0] = buf[buf.length - 1];
71614
- } else {
71615
- this.lastChar[0] = buf[buf.length - 2];
71616
- this.lastChar[1] = buf[buf.length - 1];
71880
+ StringDecoder.prototype.end = function(buffer) {
71881
+ var res = '';
71882
+ if (buffer && buffer.length)
71883
+ res = this.write(buffer);
71884
+
71885
+ if (this.charReceived) {
71886
+ var cr = this.charReceived;
71887
+ var buf = this.charBuffer;
71888
+ var enc = this.encoding;
71889
+ res += buf.slice(0, cr).toString(enc);
71617
71890
  }
71618
- return buf.toString('base64', i, buf.length - n);
71619
- }
71620
71891
 
71621
- function base64End(buf) {
71622
- var r = buf && buf.length ? this.write(buf) : '';
71623
- if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
71624
- return r;
71892
+ return res;
71893
+ };
71894
+
71895
+ function passThroughWrite(buffer) {
71896
+ return buffer.toString(this.encoding);
71625
71897
  }
71626
71898
 
71627
- // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
71628
- function simpleWrite(buf) {
71629
- return buf.toString(this.encoding);
71899
+ function utf16DetectIncompleteChar(buffer) {
71900
+ this.charReceived = buffer.length % 2;
71901
+ this.charLength = this.charReceived ? 2 : 0;
71630
71902
  }
71631
71903
 
71632
- function simpleEnd(buf) {
71633
- return buf && buf.length ? this.write(buf) : '';
71904
+ function base64DetectIncompleteChar(buffer) {
71905
+ this.charReceived = buffer.length % 3;
71906
+ this.charLength = this.charReceived ? 3 : 0;
71634
71907
  }
71635
71908
 
71909
+
71636
71910
  /***/ }),
71637
71911
 
71638
71912
  /***/ 5803:
@@ -73403,7 +73677,7 @@ module.exports = {"i8":"6.5.4"};
73403
73677
  /***/ ((module) => {
73404
73678
 
73405
73679
  "use strict";
73406
- module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.9","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.2.9","@onekeyfe/hd-transport":"^0.2.9","axios":"^0.27.2","bignumber.js":"^9.0.2","jszip":"^3.10.1","parse-uri":"^1.0.7","semver":"^7.3.7"},"peerDependencies":{"@noble/hashes":"^1.1.3","ripple-keypairs":"^1.1.4"},"devDependencies":{"@noble/hashes":"^1.1.3","@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9","ripple-keypairs":"^1.1.4"}}');
73680
+ module.exports = JSON.parse('{"name":"@onekeyfe/hd-core","version":"0.2.11","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.2.11","@onekeyfe/hd-transport":"^0.2.11","axios":"^0.27.2","bignumber.js":"^9.0.2","jszip":"^3.10.1","parse-uri":"^1.0.7","semver":"^7.3.7"},"peerDependencies":{"@noble/hashes":"^1.1.3","ripple-keypairs":"^1.1.4"},"devDependencies":{"@noble/hashes":"^1.1.3","@types/parse-uri":"^1.0.0","@types/semver":"^7.3.9","ripple-keypairs":"^1.1.4"}}');
73407
73681
 
73408
73682
  /***/ })
73409
73683
 
@@ -75942,7 +76216,7 @@ const src_init = async settings => {
75942
76216
 
75943
76217
  try {
75944
76218
  await init({ ..._settings,
75945
- version: "0.2.9"
76219
+ version: "0.2.11"
75946
76220
  });
75947
76221
  return true;
75948
76222
  } catch (e) {