62
62
* @prop {TxHexToBytes } hexToBytes
63
63
* @prop {TxBytesToHex } bytesToHex
64
64
* @prop {TxStringToHex } strToHex
65
+ * @prop {TxToUint32LE } toUint32LE
66
+ * @prop {TxToUint64LE } toUint64LE
65
67
*/
66
68
67
69
/**
@@ -1153,7 +1155,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1153
1155
void Tx . serializeInputs ( inputs , { _tx : tx , _sep : _sep } ) ;
1154
1156
void Tx . serializeOutputs ( outputs , { _tx : tx , _sep : _sep } ) ;
1155
1157
1156
- let locktimeHex = TxUtils . _toUint32LE ( locktime ) ;
1158
+ let locktimeHex = TxUtils . toUint32LE ( locktime ) ;
1157
1159
tx . push ( locktimeHex ) ;
1158
1160
1159
1161
if ( extraPayload ) {
@@ -1165,7 +1167,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1165
1167
let txHex = tx . join ( _sep ) ;
1166
1168
1167
1169
if ( sigHashType ) {
1168
- let sigHashTypeHex = TxUtils . _toUint32LE ( sigHashType ) ;
1170
+ let sigHashTypeHex = TxUtils . toUint32LE ( sigHashType ) ;
1169
1171
txHex = `${ txHex } ${ sigHashTypeHex } ` ;
1170
1172
}
1171
1173
@@ -1215,7 +1217,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1215
1217
`expected utxo property 'input[${ i } ]outputIndex' to be an integer representing this input's previous output index` ,
1216
1218
) ;
1217
1219
}
1218
- let reverseVout = TxUtils . _toUint32LE ( voutIndex ) ;
1220
+ let reverseVout = TxUtils . toUint32LE ( voutIndex ) ;
1219
1221
tx . push ( reverseVout ) ;
1220
1222
1221
1223
//@ts -ignore - enum types not handled properly here
@@ -1303,7 +1305,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1303
1305
if ( ! output . satoshis ) {
1304
1306
throw new Error ( `every output must have 'satoshis'` ) ;
1305
1307
}
1306
- let satoshis = TxUtils . _toUint64LE ( output . satoshis ) ;
1308
+ let satoshis = TxUtils . toUint64LE ( output . satoshis ) ;
1307
1309
tx . push ( satoshis ) ;
1308
1310
1309
1311
if ( ! output . pubKeyHash ) {
@@ -1342,7 +1344,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1342
1344
*/
1343
1345
Tx . _createMemoScript = function ( memoHex , sats , i = 0 ) {
1344
1346
let outputHex = [ ] ;
1345
- let satoshis = TxUtils . _toUint64LE ( sats ) ;
1347
+ let satoshis = TxUtils . toUint64LE ( sats ) ;
1346
1348
outputHex . push ( satoshis ) ;
1347
1349
1348
1350
assertHex ( memoHex , `output[${ i } ].memo` ) ;
@@ -1817,17 +1819,17 @@ var DashTx = ("object" === typeof module && exports) || {};
1817
1819
1818
1820
//@ts -ignore
1819
1821
if ( n <= MAX_U16 ) {
1820
- return "fd" + TxUtils . _toUint32LE ( n ) . slice ( 0 , 4 ) ;
1822
+ return "fd" + TxUtils . toUint32LE ( n ) . slice ( 0 , 4 ) ;
1821
1823
}
1822
1824
1823
1825
//@ts -ignore
1824
1826
if ( n <= MAX_U32 ) {
1825
- return "fe" + TxUtils . _toUint32LE ( n ) ;
1827
+ return "fe" + TxUtils . toUint32LE ( n ) ;
1826
1828
}
1827
1829
1828
1830
//@ts -ignore
1829
1831
if ( n <= MAX_U53 ) {
1830
- return "ff" + TxUtils . _toUint64LE ( n ) ;
1832
+ return "ff" + TxUtils . toUint64LE ( n ) ;
1831
1833
}
1832
1834
1833
1835
if ( "bigint" !== typeof n ) {
@@ -1837,7 +1839,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1837
1839
}
1838
1840
1839
1841
if ( n <= MAX_U64 ) {
1840
- return "ff" + TxUtils . _toUint64LE ( n ) ;
1842
+ return "ff" + TxUtils . toUint64LE ( n ) ;
1841
1843
}
1842
1844
1843
1845
let err = new Error ( E_TOO_BIG_INT ) ;
@@ -1851,7 +1853,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1851
1853
* @param {BigInt|Number } n - 16-bit positive int to encode
1852
1854
*/
1853
1855
TxUtils . _toUint16LE = function ( n ) {
1854
- let hexLE = TxUtils . _toUint32LE ( n ) ;
1856
+ let hexLE = TxUtils . toUint32LE ( n ) ;
1855
1857
// ex: 03000800 => 0300
1856
1858
hexLE = hexLE . slice ( 0 , 4 ) ;
1857
1859
return hexLE ;
@@ -1862,7 +1864,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1862
1864
* which is true in practice, and much simpler.
1863
1865
* @param {BigInt|Number } n - 32-bit positive int to encode
1864
1866
*/
1865
- TxUtils . _toUint32LE = function ( n ) {
1867
+ TxUtils . toUint32LE = function ( n ) {
1866
1868
// make sure n is uint32/int53, not int32
1867
1869
//n = n >>> 0;
1868
1870
@@ -1872,14 +1874,21 @@ var DashTx = ("object" === typeof module && exports) || {};
1872
1874
let hexLE = Tx . utils . reverseHex ( hex ) ;
1873
1875
return hexLE ;
1874
1876
} ;
1877
+ //@ts -ignore
1878
+ TxUtils . _toUint32LE = function ( n ) {
1879
+ console . warn (
1880
+ "warn: use public TxUtils.toUint32LE() instead of internal TxUtils._toUint32LE()" ,
1881
+ ) ;
1882
+ return TxUtils . toUint32LE ( n ) ;
1883
+ } ;
1875
1884
1876
1885
/**
1877
1886
* This can handle Big-Endian CPUs, which don't exist,
1878
1887
* and looks too complicated.
1879
1888
* @param {BigInt|Number } n - 64-bit BigInt or <= 53-bit Number to encode
1880
1889
* @returns {String } - 8 Little-Endian bytes
1881
1890
*/
1882
- TxUtils . _toUint64LE = function ( n ) {
1891
+ TxUtils . toUint64LE = function ( n ) {
1883
1892
let bn ;
1884
1893
if ( "bigint" === typeof n ) {
1885
1894
bn = n ;
@@ -1904,6 +1913,13 @@ var DashTx = ("object" === typeof module && exports) || {};
1904
1913
1905
1914
return hex ;
1906
1915
} ;
1916
+ //@ts -ignore
1917
+ TxUtils . _toUint64LE = function ( n ) {
1918
+ console . warn (
1919
+ "warn: use public TxUtils.toUint64LE() instead of internal TxUtils._toUint64LE()" ,
1920
+ ) ;
1921
+ return TxUtils . toUint64LE ( n ) ;
1922
+ } ;
1907
1923
1908
1924
/** @type TxToVarIntSize */
1909
1925
TxUtils . toVarIntSize = function ( n ) {
@@ -2446,3 +2462,15 @@ if ("object" === typeof module) {
2446
2462
* @param {String } utf8
2447
2463
* @returns {String } - encoded bytes as hex
2448
2464
*/
2465
+
2466
+ /**
2467
+ * @callback TxToUint32LE
2468
+ * @param {Uint32 } n
2469
+ * @returns {Hex }
2470
+ */
2471
+
2472
+ /**
2473
+ * @callback TxToUint64LE
2474
+ * @param {Uint32 } n
2475
+ * @returns {Hex }
2476
+ */
0 commit comments