63
63
* @prop {TxHexToBytes } hexToBytes
64
64
* @prop {TxBytesToHex } bytesToHex
65
65
* @prop {TxStringToHex } strToHex
66
+ * @prop {TxToUint32LE } toUint32LE
67
+ * @prop {TxToUint64LE } toUint64LE
66
68
*/
67
69
68
70
/**
@@ -1160,7 +1162,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1160
1162
void Tx . serializeInputs ( inputs , { _tx : tx , _sep : _sep } ) ;
1161
1163
void Tx . serializeOutputs ( outputs , { _tx : tx , _sep : _sep } ) ;
1162
1164
1163
- let locktimeHex = TxUtils . _toUint32LE ( locktime ) ;
1165
+ let locktimeHex = TxUtils . toUint32LE ( locktime ) ;
1164
1166
tx . push ( locktimeHex ) ;
1165
1167
1166
1168
if ( extraPayload ) {
@@ -1170,7 +1172,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1170
1172
}
1171
1173
1172
1174
if ( sigHashType ) {
1173
- let sigHashTypeHex = TxUtils . _toUint32LE ( sigHashType ) ;
1175
+ let sigHashTypeHex = TxUtils . toUint32LE ( sigHashType ) ;
1174
1176
tx . push ( sigHashTypeHex ) ;
1175
1177
}
1176
1178
@@ -1221,7 +1223,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1221
1223
`expected utxo property 'input[${ i } ]outputIndex' to be an integer representing this input's previous output index` ,
1222
1224
) ;
1223
1225
}
1224
- let reverseVout = TxUtils . _toUint32LE ( voutIndex ) ;
1226
+ let reverseVout = TxUtils . toUint32LE ( voutIndex ) ;
1225
1227
tx . push ( reverseVout ) ;
1226
1228
1227
1229
//@ts -ignore - enum types not handled properly here
@@ -1309,7 +1311,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1309
1311
if ( ! output . satoshis ) {
1310
1312
throw new Error ( `every output must have 'satoshis'` ) ;
1311
1313
}
1312
- let satoshis = TxUtils . _toUint64LE ( output . satoshis ) ;
1314
+ let satoshis = TxUtils . toUint64LE ( output . satoshis ) ;
1313
1315
tx . push ( satoshis ) ;
1314
1316
1315
1317
if ( ! output . pubKeyHash ) {
@@ -1348,7 +1350,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1348
1350
*/
1349
1351
Tx . _createMemoScript = function ( memoHex , sats , i = 0 ) {
1350
1352
let outputHex = [ ] ;
1351
- let satoshis = TxUtils . _toUint64LE ( sats ) ;
1353
+ let satoshis = TxUtils . toUint64LE ( sats ) ;
1352
1354
outputHex . push ( satoshis ) ;
1353
1355
1354
1356
assertHex ( memoHex , `output[${ i } ].memo` ) ;
@@ -1816,17 +1818,17 @@ var DashTx = ("object" === typeof module && exports) || {};
1816
1818
1817
1819
//@ts -ignore
1818
1820
if ( n <= MAX_U16 ) {
1819
- return "fd" + TxUtils . _toUint32LE ( n ) . slice ( 0 , 4 ) ;
1821
+ return "fd" + TxUtils . toUint32LE ( n ) . slice ( 0 , 4 ) ;
1820
1822
}
1821
1823
1822
1824
//@ts -ignore
1823
1825
if ( n <= MAX_U32 ) {
1824
- return "fe" + TxUtils . _toUint32LE ( n ) ;
1826
+ return "fe" + TxUtils . toUint32LE ( n ) ;
1825
1827
}
1826
1828
1827
1829
//@ts -ignore
1828
1830
if ( n <= MAX_U53 ) {
1829
- return "ff" + TxUtils . _toUint64LE ( n ) ;
1831
+ return "ff" + TxUtils . toUint64LE ( n ) ;
1830
1832
}
1831
1833
1832
1834
if ( "bigint" !== typeof n ) {
@@ -1836,7 +1838,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1836
1838
}
1837
1839
1838
1840
if ( n <= MAX_U64 ) {
1839
- return "ff" + TxUtils . _toUint64LE ( n ) ;
1841
+ return "ff" + TxUtils . toUint64LE ( n ) ;
1840
1842
}
1841
1843
1842
1844
let err = new Error ( E_TOO_BIG_INT ) ;
@@ -1850,7 +1852,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1850
1852
* @param {BigInt|Number } n - 16-bit positive int to encode
1851
1853
*/
1852
1854
TxUtils . _toUint16LE = function ( n ) {
1853
- let hexLE = TxUtils . _toUint32LE ( n ) ;
1855
+ let hexLE = TxUtils . toUint32LE ( n ) ;
1854
1856
// ex: 03000800 => 0300
1855
1857
hexLE = hexLE . slice ( 0 , 4 ) ;
1856
1858
return hexLE ;
@@ -1861,7 +1863,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1861
1863
* which is true in practice, and much simpler.
1862
1864
* @param {BigInt|Number } n - 32-bit positive int to encode
1863
1865
*/
1864
- TxUtils . _toUint32LE = function ( n ) {
1866
+ TxUtils . toUint32LE = function ( n ) {
1865
1867
// make sure n is uint32/int53, not int32
1866
1868
//n = n >>> 0;
1867
1869
@@ -1871,14 +1873,21 @@ var DashTx = ("object" === typeof module && exports) || {};
1871
1873
let hexLE = Tx . utils . reverseHex ( hex ) ;
1872
1874
return hexLE ;
1873
1875
} ;
1876
+ //@ts -ignore
1877
+ TxUtils . _toUint32LE = function ( n ) {
1878
+ console . warn (
1879
+ "warn: use public TxUtils.toUint32LE() instead of internal TxUtils._toUint32LE()" ,
1880
+ ) ;
1881
+ return TxUtils . toUint32LE ( n ) ;
1882
+ } ;
1874
1883
1875
1884
/**
1876
1885
* This can handle Big-Endian CPUs, which don't exist,
1877
1886
* and looks too complicated.
1878
1887
* @param {BigInt|Number } n - 64-bit BigInt or <= 53-bit Number to encode
1879
1888
* @returns {String } - 8 Little-Endian bytes
1880
1889
*/
1881
- TxUtils . _toUint64LE = function ( n ) {
1890
+ TxUtils . toUint64LE = function ( n ) {
1882
1891
let bn ;
1883
1892
if ( "bigint" === typeof n ) {
1884
1893
bn = n ;
@@ -1903,6 +1912,13 @@ var DashTx = ("object" === typeof module && exports) || {};
1903
1912
1904
1913
return hex ;
1905
1914
} ;
1915
+ //@ts -ignore
1916
+ TxUtils . _toUint64LE = function ( n ) {
1917
+ console . warn (
1918
+ "warn: use public TxUtils.toUint64LE() instead of internal TxUtils._toUint64LE()" ,
1919
+ ) ;
1920
+ return TxUtils . toUint64LE ( n ) ;
1921
+ } ;
1906
1922
1907
1923
/** @type TxToVarIntSize */
1908
1924
TxUtils . toVarIntSize = function ( n ) {
@@ -2456,3 +2472,15 @@ if ("object" === typeof module) {
2456
2472
* @param {String } utf8
2457
2473
* @returns {String } - encoded bytes as hex
2458
2474
*/
2475
+
2476
+ /**
2477
+ * @callback TxToUint32LE
2478
+ * @param {Uint32 } n
2479
+ * @returns {Hex }
2480
+ */
2481
+
2482
+ /**
2483
+ * @callback TxToUint64LE
2484
+ * @param {Uint32 } n
2485
+ * @returns {Hex }
2486
+ */
0 commit comments