@onekeyfe/hd-web-sdk 0.0.4 → 0.0.5

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.
@@ -5045,6 +5045,126 @@ const getDeviceBLEFirmwareVersion = features => {
5045
5045
  return features.ble_ver.split('.');
5046
5046
  };
5047
5047
 
5048
+ const HD_HARDENED = 0x80000000;
5049
+
5050
+ const toHardened = n => (n | HD_HARDENED) >>> 0;
5051
+
5052
+ const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
5053
+
5054
+ const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
5055
+ const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
5056
+
5057
+ const getHDPath = path => {
5058
+ const parts = path.toLowerCase().split('/');
5059
+ if (parts[0] !== 'm') throw PATH_NOT_VALID;
5060
+ return parts.filter(p => p !== 'm' && p !== '').map(p => {
5061
+ let hardened = false;
5062
+
5063
+ if (p.substr(p.length - 1) === "'") {
5064
+ hardened = true;
5065
+ p = p.substr(0, p.length - 1);
5066
+ }
5067
+
5068
+ let n = parseInt(p);
5069
+
5070
+ if (Number.isNaN(n)) {
5071
+ throw PATH_NOT_VALID;
5072
+ } else if (n < 0) {
5073
+ throw PATH_NEGATIVE_VALUES;
5074
+ }
5075
+
5076
+ if (hardened) {
5077
+ n = toHardened(n);
5078
+ }
5079
+
5080
+ return n;
5081
+ });
5082
+ };
5083
+
5084
+ const isMultisigPath = path => Array.isArray(path) && path[0] === toHardened(48);
5085
+
5086
+ const isSegwitPath = path => Array.isArray(path) && path[0] === toHardened(49);
5087
+
5088
+ const getScriptType = path => {
5089
+ if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
5090
+ const p1 = fromHardened(path[0]);
5091
+
5092
+ switch (p1) {
5093
+ case 48:
5094
+ return 'SPENDMULTISIG';
5095
+
5096
+ case 49:
5097
+ return 'SPENDP2SHWITNESS';
5098
+
5099
+ case 84:
5100
+ return 'SPENDWITNESS';
5101
+
5102
+ default:
5103
+ return 'SPENDADDRESS';
5104
+ }
5105
+ };
5106
+
5107
+ const getOutputScriptType = path => {
5108
+ if (!Array.isArray(path) || path.length < 1) return 'PAYTOADDRESS';
5109
+
5110
+ if (path[0] === 49) {
5111
+ return 'PAYTOP2SHWITNESS';
5112
+ }
5113
+
5114
+ const p = fromHardened(path[0]);
5115
+
5116
+ switch (p) {
5117
+ case 48:
5118
+ return 'PAYTOMULTISIG';
5119
+
5120
+ case 49:
5121
+ return 'PAYTOP2SHWITNESS';
5122
+
5123
+ case 84:
5124
+ return 'PAYTOWITNESS';
5125
+
5126
+ default:
5127
+ return 'PAYTOADDRESS';
5128
+ }
5129
+ };
5130
+
5131
+ const serializedPath = path => {
5132
+ const pathStr = path.map(p => {
5133
+ if (p & HD_HARDENED) {
5134
+ return `${p & ~HD_HARDENED}'`;
5135
+ }
5136
+
5137
+ return p;
5138
+ }).join('/');
5139
+ return `m/${pathStr}`;
5140
+ };
5141
+
5142
+ const validatePath = (path, length = 0, base = false) => {
5143
+ let valid;
5144
+
5145
+ if (typeof path === 'string') {
5146
+ valid = getHDPath(path);
5147
+ } else if (Array.isArray(path)) {
5148
+ valid = path.map(p => {
5149
+ const n = parseInt(p);
5150
+
5151
+ if (Number.isNaN(n)) {
5152
+ throw PATH_NOT_VALID;
5153
+ } else if (n < 0) {
5154
+ throw PATH_NEGATIVE_VALUES;
5155
+ }
5156
+
5157
+ return n;
5158
+ });
5159
+ } else {
5160
+ valid = undefined;
5161
+ }
5162
+
5163
+ if (!valid) throw PATH_NOT_VALID;
5164
+ if (length > 0 && valid.length < length) throw PATH_NOT_VALID;
5165
+ return base ? valid.splice(0, 3) : valid;
5166
+ };
5167
+
5048
5168
  var nested = {
5049
5169
  BinanceGetAddress: {
5050
5170
  fields: {
@@ -14762,126 +14882,6 @@ class GetFeatures extends BaseMethod {
14762
14882
 
14763
14883
  }
14764
14884
 
14765
- const HD_HARDENED = 0x80000000;
14766
-
14767
- const toHardened = n => (n | HD_HARDENED) >>> 0;
14768
-
14769
- const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
14770
-
14771
- const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
14772
- const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
14773
-
14774
- const getHDPath = path => {
14775
- const parts = path.toLowerCase().split('/');
14776
- if (parts[0] !== 'm') throw PATH_NOT_VALID;
14777
- return parts.filter(p => p !== 'm' && p !== '').map(p => {
14778
- let hardened = false;
14779
-
14780
- if (p.substr(p.length - 1) === "'") {
14781
- hardened = true;
14782
- p = p.substr(0, p.length - 1);
14783
- }
14784
-
14785
- let n = parseInt(p);
14786
-
14787
- if (Number.isNaN(n)) {
14788
- throw PATH_NOT_VALID;
14789
- } else if (n < 0) {
14790
- throw PATH_NEGATIVE_VALUES;
14791
- }
14792
-
14793
- if (hardened) {
14794
- n = toHardened(n);
14795
- }
14796
-
14797
- return n;
14798
- });
14799
- };
14800
-
14801
- const isMultisigPath = path => Array.isArray(path) && path[0] === toHardened(48);
14802
-
14803
- const isSegwitPath = path => Array.isArray(path) && path[0] === toHardened(49);
14804
-
14805
- const getScriptType = path => {
14806
- if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
14807
- const p1 = fromHardened(path[0]);
14808
-
14809
- switch (p1) {
14810
- case 48:
14811
- return 'SPENDMULTISIG';
14812
-
14813
- case 49:
14814
- return 'SPENDP2SHWITNESS';
14815
-
14816
- case 84:
14817
- return 'SPENDWITNESS';
14818
-
14819
- default:
14820
- return 'SPENDADDRESS';
14821
- }
14822
- };
14823
-
14824
- const getOutputScriptType = path => {
14825
- if (!Array.isArray(path) || path.length < 1) return 'PAYTOADDRESS';
14826
-
14827
- if (path[0] === 49) {
14828
- return 'PAYTOP2SHWITNESS';
14829
- }
14830
-
14831
- const p = fromHardened(path[0]);
14832
-
14833
- switch (p) {
14834
- case 48:
14835
- return 'PAYTOMULTISIG';
14836
-
14837
- case 49:
14838
- return 'PAYTOP2SHWITNESS';
14839
-
14840
- case 84:
14841
- return 'PAYTOWITNESS';
14842
-
14843
- default:
14844
- return 'PAYTOADDRESS';
14845
- }
14846
- };
14847
-
14848
- const serializedPath = path => {
14849
- const pathStr = path.map(p => {
14850
- if (p & HD_HARDENED) {
14851
- return `${p & ~HD_HARDENED}'`;
14852
- }
14853
-
14854
- return p;
14855
- }).join('/');
14856
- return `m/${pathStr}`;
14857
- };
14858
-
14859
- const validatePath = (path, length = 0, base = false) => {
14860
- let valid;
14861
-
14862
- if (typeof path === 'string') {
14863
- valid = getHDPath(path);
14864
- } else if (Array.isArray(path)) {
14865
- valid = path.map(p => {
14866
- const n = parseInt(p);
14867
-
14868
- if (Number.isNaN(n)) {
14869
- throw PATH_NOT_VALID;
14870
- } else if (n < 0) {
14871
- throw PATH_NEGATIVE_VALUES;
14872
- }
14873
-
14874
- return n;
14875
- });
14876
- } else {
14877
- valid = undefined;
14878
- }
14879
-
14880
- if (!valid) throw PATH_NOT_VALID;
14881
- if (length > 0 && valid.length < length) throw PATH_NOT_VALID;
14882
- return base ? valid.splice(0, 3) : valid;
14883
- };
14884
-
14885
14885
  const hasHexPrefix = str => str.slice(0, 2).toLowerCase() === '0x';
14886
14886
 
14887
14887
  const stripHexPrefix = str => hasHexPrefix(str) ? str.slice(2) : str;
@@ -15295,8 +15295,8 @@ class BTCGetPublicKey extends BaseMethod {
15295
15295
 
15296
15296
  init() {
15297
15297
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15298
- const hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
15299
- const payload = hasBundle ? this.payload : {
15298
+ this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
15299
+ const payload = this.hasBundle ? this.payload : {
15300
15300
  bundle: [this.payload]
15301
15301
  };
15302
15302
  validateParams(payload, [{
@@ -17616,12 +17616,12 @@ __webpack_unused_export__ = createUiMessage;
17616
17616
  __webpack_unused_export__ = createUiResponse;
17617
17617
  exports.ZP = HardwareSdk;
17618
17618
  exports.yI = enableLog;
17619
- __webpack_unused_export__ = getDeviceBLEFirmwareVersion;
17620
- __webpack_unused_export__ = getDeviceFirmwareVersion;
17621
17619
  __webpack_unused_export__ = getDeviceLabel;
17622
17620
  __webpack_unused_export__ = getDeviceType;
17623
17621
  __webpack_unused_export__ = getDeviceUUID;
17624
17622
  __webpack_unused_export__ = getEnv;
17623
+ __webpack_unused_export__ = getHDPath;
17624
+ __webpack_unused_export__ = getScriptType;
17625
17625
  __webpack_unused_export__ = getTimeStamp;
17626
17626
  __webpack_unused_export__ = httpRequest;
17627
17627
  __webpack_unused_export__ = init;