1
1
/**
2
2
* @typedef Tx
3
- * @prop {Number } SATOSHIS
4
- * @prop {Number } _HEADER_ONLY_SIZE
5
- * @prop {Number } HEADER_SIZE
6
- * @prop {Number } LEGACY_DUST
7
- * @prop {Number } MIN_INPUT_SIZE - 147 each
8
- * @prop {Number } MAX_INPUT_PAD - 2 (possible ASN.1 BigInt padding)
9
- * @prop {Number } MAX_INPUT_SIZE - 149 each (with padding)
10
- * @prop {Number } OUTPUT_SIZE - 34 each
3
+ * @prop {Uint53 } SATOSHIS
4
+ * @prop {Uint32 } _HEADER_ONLY_SIZE
5
+ * @prop {Uint32 } HEADER_SIZE
6
+ * @prop {Uint32 } LEGACY_DUST
7
+ * @prop {Uint32 } MIN_INPUT_SIZE - 147 each
8
+ * @prop {Uint32 } MAX_INPUT_PAD - 2 (possible ASN.1 BigInt padding)
9
+ * @prop {Uint32 } MAX_INPUT_SIZE - 149 each (with padding)
10
+ * @prop {Uint32 } OUTPUT_SIZE - 34 each
11
11
* @prop {TxAppraise } appraise
12
12
* @prop {TxToDash } toDash
13
13
* @prop {TxToSats } toSats
@@ -71,7 +71,7 @@ var DashTx = ("object" === typeof module && exports) || {};
71
71
const MAX_U8 = Math . pow ( 2 , 8 ) - 1 ;
72
72
const MAX_U16 = Math . pow ( 2 , 16 ) - 1 ;
73
73
const MAX_U32 = Math . pow ( 2 , 32 ) - 1 ;
74
- const MAX_U52 = Number . MAX_SAFE_INTEGER ;
74
+ const MAX_U53 = Number . MAX_SAFE_INTEGER ; // Math.pow(2, 53) - 1
75
75
const MAX_U64 = 2n ** 64n - 1n ;
76
76
77
77
const CH_0 = 48 ;
@@ -95,7 +95,7 @@ var DashTx = ("object" === typeof module && exports) || {};
95
95
const PKH_SCRIPT_SIZE = ( 25 ) . toString ( 16 ) ; // 0x19
96
96
97
97
const E_LITTLE_INT =
98
- "JavaScript 'Number's only go up to uint51 , you must use 'BigInt' (ex: `let amount = 18014398509481984n`) for larger values" ;
98
+ "JavaScript 'Number's only go up to uint53 , you must use 'BigInt' (ex: `let amount = 18014398509481984n`) for larger values" ;
99
99
const E_TOO_BIG_INT =
100
100
"JavaScript 'BigInt's are arbitrarily large, but you may only use up to UINT64 for transactions" ;
101
101
@@ -378,7 +378,7 @@ var DashTx = ("object" === typeof module && exports) || {};
378
378
*
379
379
* @param {TxOutputSortable } a
380
380
* @param {TxOutputSortable } b
381
- * @returns {Number }
381
+ * @returns {Uint32 }
382
382
*/
383
383
Tx . sortOutputs = function ( a , b ) {
384
384
// the complexity is inherent, and doesn't seem to be reasonable to break out
@@ -501,7 +501,7 @@ var DashTx = ("object" === typeof module && exports) || {};
501
501
* @param {TxInfo } txInfo
502
502
* TODO _param {Array<TxInputRaw>} txInfo.inputs - needs type narrowing check
503
503
* TODO _param {Array<TxOutput>} txInfo.outputs
504
- * TODO _param {Number } [txInfo.version]
504
+ * TODO _param {Uint32 } [txInfo.version]
505
505
* TODO _param {Boolean} [txInfo._debug] - bespoke debug output
506
506
* @param {TxDeps } myUtils
507
507
* @returns {Promise<TxInfoSigned> }
@@ -679,9 +679,9 @@ var DashTx = ("object" === typeof module && exports) || {};
679
679
/**
680
680
* @param {Object } opts
681
681
* @param {Array<TxInputRaw|TxInputHashable|TxInputSigned> } opts.inputs
682
- * @param {Number } [opts.locktime]
682
+ * @param {Uint32 } [opts.locktime]
683
683
* @param {Array<TxOutput> } opts.outputs
684
- * @param {Number } [opts.version]
684
+ * @param {Uint32 } [opts.version]
685
685
* @param {Boolean } [opts._debug] - bespoke debug output
686
686
*/
687
687
Tx . _create = function ( {
@@ -936,7 +936,7 @@ var DashTx = ("object" === typeof module && exports) || {};
936
936
let reverseU8 = new Uint8Array ( hashU8 . length ) ;
937
937
let reverseIndex = reverseU8 . length - 1 ;
938
938
hashU8 . forEach (
939
- /** @param {Number } b */
939
+ /** @param {Uint8 } b */
940
940
function ( b ) {
941
941
reverseU8 [ reverseIndex ] = b ;
942
942
reverseIndex -= 1 ;
@@ -1093,10 +1093,6 @@ var DashTx = ("object" === typeof module && exports) || {};
1093
1093
return pubKeyBuf ;
1094
1094
} ;
1095
1095
1096
- /**
1097
- * Caution: JS can't handle 64-bit ints
1098
- * @param {BigInt|Number } n - 64-bit BigInt or < 52-bit Number
1099
- */
1100
1096
TxUtils . toVarInt = function ( n ) {
1101
1097
//@ts -ignore - see https://github.com/microsoft/TypeScript/issues/57953
1102
1098
if ( n < 253 ) {
@@ -1117,7 +1113,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1117
1113
}
1118
1114
1119
1115
//@ts -ignore
1120
- if ( n <= MAX_U52 ) {
1116
+ if ( n <= MAX_U53 ) {
1121
1117
return "ff" + toUint64LE ( n ) ;
1122
1118
}
1123
1119
@@ -1144,7 +1140,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1144
1140
* @param {BigInt|Number } n - 32-bit positive int to encode
1145
1141
*/
1146
1142
function toUint32LE ( n ) {
1147
- // make sure n is uint32/int52 , not int32
1143
+ // make sure n is uint32/int53 , not int32
1148
1144
//n = n >>> 0;
1149
1145
1150
1146
// 0x00000003
@@ -1157,7 +1153,7 @@ var DashTx = ("object" === typeof module && exports) || {};
1157
1153
/**
1158
1154
* This can handle Big-Endian CPUs, which don't exist,
1159
1155
* and looks too complicated.
1160
- * @param {BigInt|Number } n - 64-bit BigInt or <= 51 -bit Number to encode
1156
+ * @param {BigInt|Number } n - 64-bit BigInt or <= 53 -bit Number to encode
1161
1157
* @returns {String } - 8 Little-Endian bytes
1162
1158
*/
1163
1159
function toUint64LE ( n ) {
@@ -1186,10 +1182,6 @@ var DashTx = ("object" === typeof module && exports) || {};
1186
1182
return hex ;
1187
1183
}
1188
1184
1189
- /**
1190
- * @param {BigInt|Number } n
1191
- * @returns {Number }
1192
- */
1193
1185
TxUtils . toVarIntSize = function ( n ) {
1194
1186
//@ts -ignore - see https://github.com/microsoft/TypeScript/issues/57953
1195
1187
if ( n < 253 ) {
@@ -1257,6 +1249,7 @@ if ("object" === typeof module) {
1257
1249
/** @typedef {Number } Float64 */
1258
1250
/** @typedef {Number } Uint53 */
1259
1251
/** @typedef {Number } Uint32 */
1252
+ /** @typedef {Number } Uint8 */
1260
1253
/** @typedef {Uint8Array } TxPrivateKey */
1261
1254
/** @typedef {Uint8Array } TxPublicKey */
1262
1255
/** @typedef {Uint8Array } TxSignature */
@@ -1273,27 +1266,27 @@ if ("object" === typeof module) {
1273
1266
1274
1267
/**
1275
1268
* @typedef TxFees
1276
- * @prop {Number } max
1277
- * @prop {Number } mid
1278
- * @prop {Number } min
1269
+ * @prop {Uint53 } max
1270
+ * @prop {Uint53 } mid
1271
+ * @prop {Uint53 } min
1279
1272
*/
1280
1273
1281
1274
/**
1282
1275
* @typedef TxInfo
1283
1276
* @prop {Array<TxInputHashable> } inputs
1284
- * @prop {Number } [locktime] - 0 by default
1277
+ * @prop {Uint32 } [locktime] - 0 by default
1285
1278
* @prop {Array<TxOutput> } outputs
1286
- * @prop {Number } [version]
1279
+ * @prop {Uint32 } [version]
1287
1280
* @prop {String } [transaction] - signed transaction hex
1288
1281
* @prop {Boolean } [_debug] - bespoke debug output
1289
1282
*/
1290
1283
1291
1284
/**
1292
1285
* @typedef TxInfoSigned
1293
1286
* @prop {Array<TxInputSigned> } inputs
1294
- * @prop {Number } locktime - 0 by default
1287
+ * @prop {Uint32 } locktime - 0 by default
1295
1288
* @prop {Array<TxOutput> } outputs
1296
- * @prop {Number } version
1289
+ * @prop {Uint32 } version
1297
1290
* @prop {String } transaction - signed transaction hex
1298
1291
* @prop {Boolean } [_debug] - bespoke debug output
1299
1292
*/
@@ -1302,52 +1295,52 @@ if ("object" === typeof module) {
1302
1295
* @typedef TxInput
1303
1296
* @prop {String } [address] - BaseCheck58-encoded pubKeyHash
1304
1297
* @prop {String } txId - hex (not pre-reversed)
1305
- * @prop {Number } outputIndex - index in previous tx's output (vout index)
1298
+ * @prop {Uint32 } outputIndex - index in previous tx's output (vout index)
1306
1299
* @prop {String } signature - hex-encoded ASN.1 (DER) signature (starts with 0x30440220 or 0x30440221)
1307
1300
* @prop {String } [script] - the previous lock script (default: derived from public key as p2pkh)
1308
1301
* @prop {String } publicKey - hex-encoded public key (typically starts with a 0x02 or 0x03 prefix)
1309
1302
* @prop {String } [pubKeyHash] - the 20-byte pubKeyHash (address without magic byte or checksum)
1310
- * @prop {Number } sigHashType - typically 0x01 (SIGHASH_ALL)
1303
+ * @prop {Uint32 } sigHashType - typically 0x01 (SIGHASH_ALL)
1311
1304
*/
1312
1305
1313
1306
/**
1314
1307
* @typedef TxInputHashable
1315
1308
* @prop {String } [address] - BaseCheck58-encoded pubKeyHash
1316
1309
* @prop {String } txId - hex (not pre-reversed)
1317
- * @prop {Number } outputIndex - index in previous tx's output (vout index)
1318
- * @prop {Number } [satoshis] - (included for convenience as type hack)
1310
+ * @prop {Uint32 } outputIndex - index in previous tx's output (vout index)
1311
+ * @prop {Uint53 } [satoshis] - (included for convenience as type hack)
1319
1312
* @prop {String } [signature] - (included as type hack)
1320
1313
* @prop {String } [script] - the previous lock script (default: derived from public key as p2pkh)
1321
1314
* @prop {String } [publicKey] - hex-encoded public key (typically starts with a 0x02 or 0x03 prefix)
1322
1315
* @prop {String } [pubKeyHash] - the 20-byte pubKeyHash (address without magic byte or checksum)
1323
- * @prop {Number } [sigHashType] - typically 0x01 (SIGHASH_ALL)
1316
+ * @prop {Uint32 } [sigHashType] - typically 0x01 (SIGHASH_ALL)
1324
1317
*/
1325
1318
1326
1319
/**
1327
1320
* @typedef TxInputRaw
1328
1321
* @prop {String } [address] - BaseCheck58-encoded pubKeyHash
1329
- * @prop {Number } [satoshis] - for convenience
1322
+ * @prop {Uint53 } [satoshis] - for convenience
1330
1323
* @prop {String } txId - hex (not pre-reversed)
1331
- * @prop {Number } outputIndex - index in previous tx's output (vout index)
1324
+ * @prop {Uint32 } outputIndex - index in previous tx's output (vout index)
1332
1325
*/
1333
1326
1334
1327
/**
1335
1328
* @typedef TxInputUnspent
1336
1329
* @prop {String } [address] - BaseCheck58-encoded pubKeyHash
1337
- * @prop {Number } satoshis
1330
+ * @prop {Uint53 } satoshis
1338
1331
* @prop {String } txId - hex (not pre-reversed)
1339
- * @prop {Number } outputIndex - index in previous tx's output (vout index)
1332
+ * @prop {Uint32 } outputIndex - index in previous tx's output (vout index)
1340
1333
*/
1341
1334
1342
1335
/**
1343
1336
* @typedef TxInputSortable
1344
1337
* @prop {String } txId
1345
- * @prop {Number } outputIndex
1338
+ * @prop {Uint32 } outputIndex
1346
1339
*/
1347
1340
1348
1341
/**
1349
1342
* @typedef TxHasSats
1350
- * @prop {Number } satoshis
1343
+ * @prop {Uint53 } satoshis
1351
1344
*/
1352
1345
1353
1346
/**
@@ -1359,12 +1352,12 @@ if ("object" === typeof module) {
1359
1352
* @prop {String } [memo] - hex bytes of a memo (incompatible with pubKeyHash / address)
1360
1353
* @prop {String } [address] - payAddr as Base58Check (human-friendly)
1361
1354
* @prop {String } [pubKeyHash] - payAddr's raw hex value (decoded, not Base58Check)
1362
- * @prop {Number } satoshis - the number of smallest units of the currency
1355
+ * @prop {Uint53 } satoshis - the number of smallest units of the currency
1363
1356
*/
1364
1357
1365
1358
/**
1366
1359
* @typedef TxOutputSortable
1367
- * @prop {Number } satoshis
1360
+ * @prop {Uint53 } satoshis
1368
1361
* @prop {String } [script] - hex bytes in wire order
1369
1362
* @prop {String } [memo] - 0x6a, hex bytes
1370
1363
* @prop {String } [pubKeyHash] - 0x76, 0xa9, hex bytes
@@ -1398,7 +1391,7 @@ if ("object" === typeof module) {
1398
1391
/**
1399
1392
* @callback TxCreateHashable
1400
1393
* @param {TxInfo } txInfo
1401
- * @param {Number } inputIndex - create hashable tx for this input
1394
+ * @param {Uint32 } inputIndex - create hashable tx for this input
1402
1395
* @returns {String } - hashable tx hex
1403
1396
*/
1404
1397
@@ -1407,7 +1400,7 @@ if ("object" === typeof module) {
1407
1400
* @param {Object } opts
1408
1401
* @param {Array<TxInputRaw> } opts.inputs
1409
1402
* @param {Array<TxOutput> } opts.outputs
1410
- * @param {Number } [opts.version]
1403
+ * @param {Uint32 } [opts.version]
1411
1404
* @param {Boolean } [opts._debug] - bespoke debug output
1412
1405
*/
1413
1406
@@ -1416,7 +1409,7 @@ if ("object" === typeof module) {
1416
1409
* @param {Object } opts
1417
1410
* @param {Array<TxInputSigned> } opts.inputs
1418
1411
* @param {Array<TxOutput> } opts.outputs
1419
- * @param {Number } [opts.version]
1412
+ * @param {Uint32 } [opts.version]
1420
1413
* @param {Boolean } [opts._debug] - bespoke debug output
1421
1414
* xparam {String} [opts.sigHashType] - hex, typically 01 (ALL)
1422
1415
*/
@@ -1430,15 +1423,15 @@ if ("object" === typeof module) {
1430
1423
/**
1431
1424
* @callback TxGetPrivateKey
1432
1425
* @param {TxInputHashable } txInput
1433
- * @param {Number } i
1426
+ * @param {Uint53 } i
1434
1427
* @param {Array<TxInputRaw|TxInputHashable> } txInputs
1435
1428
* @returns {Uint8Array } - private key Uint8Array
1436
1429
*/
1437
1430
1438
1431
/**
1439
1432
* @callback TxGetPublicKey
1440
1433
* @param {TxInputHashable } txInput
1441
- * @param {Number } i
1434
+ * @param {Uint53 } i
1442
1435
* @param {Array<TxInputRaw|TxInputHashable> } txInputs
1443
1436
* @returns {Uint8Array } - public key Uint8Array
1444
1437
*/
@@ -1452,7 +1445,7 @@ if ("object" === typeof module) {
1452
1445
/**
1453
1446
* @callback TxHashPartial
1454
1447
* @param {String } txHex - signable tx hex (like raw tx, but with (lock)script)
1455
- * @param {Number } sigHashType - typically 0x01 (SIGHASH_ALL) for signable
1448
+ * @param {Uint32 } sigHashType - typically 0x01 (SIGHASH_ALL) for signable
1456
1449
* @returns {Promise<Uint8Array> }
1457
1450
*/
1458
1451
@@ -1487,39 +1480,39 @@ if ("object" === typeof module) {
1487
1480
* @callback TxSortBySats
1488
1481
* @param {TxHasSats } a
1489
1482
* @param {TxHasSats } b
1490
- * @returns {Number }
1483
+ * @returns {Uint8 }
1491
1484
*/
1492
1485
1493
1486
/**
1494
1487
* @callback TxSortInputs
1495
1488
* @param {TxInputSortable } a
1496
1489
* @param {TxInputSortable } b
1497
- * @returns {Number }
1490
+ * @returns {Uint8 }
1498
1491
*/
1499
1492
1500
1493
/**
1501
1494
* @callback TxSortOutputs
1502
1495
* @param {TxOutputSortable } a
1503
1496
* @param {TxOutputSortable } b
1504
- * @returns {Number }
1497
+ * @returns {Uint8 }
1505
1498
*/
1506
1499
1507
1500
/**
1508
1501
* @callback TxSum
1509
1502
* @param {Array<TxHasSats> } coins
1510
- * @returns {Number }
1503
+ * @returns {Uint53 }
1511
1504
*/
1512
1505
1513
1506
/**
1514
1507
* @callback TxToDash
1515
- * @param {Number } satoshis
1516
- * @returns {Number } - float
1508
+ * @param {Uint53 } satoshis
1509
+ * @returns {Float64 } - float
1517
1510
*/
1518
1511
1519
1512
/**
1520
1513
* @callback TxToSats
1521
- * @param {Number } dash - as float (decimal) DASH, not uint satoshis
1522
- * @returns {Number } - duffs
1514
+ * @param {Float64 } dash - as float (decimal) DASH, not uint satoshis
1515
+ * @returns {Uint53 } - duffs
1523
1516
*/
1524
1517
1525
1518
/**
@@ -1529,15 +1522,16 @@ if ("object" === typeof module) {
1529
1522
*/
1530
1523
1531
1524
/**
1525
+ * Caution: JS can't handle 64-bit ints
1532
1526
* @callback TxToVarInt
1533
- * @param {Number } n
1527
+ * @param {BigInt|Uint53 } n - 64-bit BigInt or < 53-bit Number
1534
1528
* @returns {String } - hex
1535
1529
*/
1536
1530
1537
1531
/**
1538
1532
* @callback TxToVarIntSize
1539
- * @param {Number } n
1540
- * @returns {Number } - byte size of n
1533
+ * @param {BigInt|Uint53 } n
1534
+ * @returns {Uint8 } - byte size of n
1541
1535
*/
1542
1536
1543
1537
/**
0 commit comments