bsv2 2.0.23 → 2.1.0
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.
- package/{.babelrc.test → .babel.test} +1 -1
- package/.husky/pre-commit +1 -1
- package/.mocharc.yml +1 -1
- package/.travis.yml +1 -1
- package/babel.config.cjs +44 -0
- package/benchmark.js +10 -18
- package/bin/bsv.js +1 -1
- package/bin/network.js +2 -1
- package/dist/bsv2.mjs +36061 -4
- package/dist/bsv2.umd.js +28 -0
- package/doc/assets/anchor.js +350 -0
- package/doc/assets/bass-addons.css +12 -0
- package/doc/assets/bass.css +544 -0
- package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/doc/assets/fonts/LICENSE.txt +93 -0
- package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/doc/assets/fonts/source-code-pro.css +23 -0
- package/doc/assets/github.css +123 -0
- package/doc/assets/site.js +168 -0
- package/doc/assets/split.css +15 -0
- package/doc/assets/split.js +782 -0
- package/doc/assets/style.css +147 -0
- package/doc/index.html +9461 -0
- package/entry.js +2 -3
- package/eslint.config.mjs +8 -0
- package/index.js +1 -5
- package/{karma.conf.js → karma.conf.ts} +2 -3
- package/lib/ach.js +5 -5
- package/lib/address.js +11 -9
- package/lib/aescbc.js +3 -3
- package/lib/bip-39.js +12 -11
- package/lib/block.js +2 -2
- package/lib/bn.js +12 -17
- package/lib/bsm.js +1 -1
- package/lib/config.js +1 -1
- package/lib/constants.js +1 -1
- package/lib/ecdsa.js +24 -23
- package/lib/interp.js +190 -26
- package/lib/merkle.js +1 -1
- package/lib/op-code.js +137 -135
- package/lib/priv-key.js +1 -1
- package/lib/script.js +44 -42
- package/lib/sig.js +12 -12
- package/lib/struct.js +9 -6
- package/lib/tx.js +8 -7
- package/load-babel.js +3 -1
- package/mtest/test.html +6 -4
- package/mtest/test.js +1 -1
- package/out/Sig.html +541 -0
- package/out/bip-32.js.html +523 -0
- package/out/bip-39.js.html +336 -0
- package/out/block.js.html +183 -0
- package/out/bn.js.html +512 -0
- package/out/ecdsa.js.html +546 -0
- package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/out/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/out/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Light-webfont.eot +0 -0
- package/out/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/out/fonts/OpenSans-Light-webfont.woff +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/out/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/out/global.html +220 -0
- package/out/index.html +128 -0
- package/out/interp.js.html +2064 -0
- package/out/merkle.js.html +143 -0
- package/out/msg.js.html +235 -0
- package/out/priv-key.js.html +208 -0
- package/out/pub-key.js.html +281 -0
- package/out/script.js.html +876 -0
- package/out/scripts/linenumber.js +25 -0
- package/out/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/out/scripts/prettify/lang-css.js +2 -0
- package/out/scripts/prettify/prettify.js +28 -0
- package/out/sig-operations.js.html +171 -0
- package/out/sig.js.html +450 -0
- package/out/struct.js.html +440 -0
- package/out/styles/jsdoc-default.css +358 -0
- package/out/styles/prettify-jsdoc.css +111 -0
- package/out/styles/prettify-tomorrow.css +132 -0
- package/out/tx-builder.js.html +644 -0
- package/out/tx-in.js.html +223 -0
- package/out/tx-verifier.js.html +260 -0
- package/out/tx.js.html +481 -0
- package/package.json +34 -39
- package/vite.config.js +36 -0
- package/dist/bsv2.bundle.js +0 -8
- package/dist/bsv2.cjs.js +0 -2
- package/dist/bsv2.cjs.js.LICENSE.txt +0 -1
- package/dist/bsv2.module.js +0 -2
- /package/{webpack.config.js → mtest/webpack.config.js} +0 -0
package/lib/interp.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
'use strict'
|
|
19
19
|
|
|
20
|
+
import { Br } from './br'
|
|
20
21
|
import { Bn } from './bn'
|
|
21
22
|
import { Bw } from './bw'
|
|
22
23
|
import { cmp } from './cmp'
|
|
@@ -28,6 +29,51 @@ import { Sig } from './sig'
|
|
|
28
29
|
import { Struct } from './struct'
|
|
29
30
|
import { Tx } from './tx'
|
|
30
31
|
import { TxIn } from './tx-in'
|
|
32
|
+
import { Ecdsa } from './ecdsa'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const minimallyEncode = (buf) => {
|
|
36
|
+
if (buf.length === 0) {
|
|
37
|
+
return buf
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// If the last byte is not 0x00 or 0x80, we are minimally encoded.
|
|
41
|
+
const last = buf[buf.length - 1]
|
|
42
|
+
if ((last & 0x7f) !== 0) {
|
|
43
|
+
return buf
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// If the script is one byte long, then we have a zero, which encodes as an
|
|
47
|
+
// empty array.
|
|
48
|
+
if (buf.length === 1) {
|
|
49
|
+
return []
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// If the next byte has it sign bit set, then we are minimaly encoded.
|
|
53
|
+
if ((buf[buf.length - 2] & 0x80) !== 0) {
|
|
54
|
+
return buf
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// We are not minimally encoded, we need to figure out how much to trim.
|
|
58
|
+
for (let i = buf.length - 1; i > 0; i--) {
|
|
59
|
+
// We found a non zero byte, time to encode.
|
|
60
|
+
if (buf[i - 1] !== 0) {
|
|
61
|
+
if ((buf[i - 1] & 0x80) !== 0) {
|
|
62
|
+
// We found a byte with it sign bit set so we need one more
|
|
63
|
+
// byte.
|
|
64
|
+
buf[i] = last
|
|
65
|
+
return buf.slice(0, i + 1)
|
|
66
|
+
} else {
|
|
67
|
+
// the sign bit is clear, we can use it.
|
|
68
|
+
buf[i - 1] |= last
|
|
69
|
+
return buf.slice(0, i)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// If we found the whole thing is zeros, then we have a zero.
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
31
77
|
|
|
32
78
|
class Interp extends Struct {
|
|
33
79
|
constructor (
|
|
@@ -154,7 +200,9 @@ import { TxIn } from './tx-in'
|
|
|
154
200
|
nOpCount: this.nOpCount,
|
|
155
201
|
ifStack: this.ifStack,
|
|
156
202
|
errStr: this.errStr,
|
|
157
|
-
flags: this.flags
|
|
203
|
+
flags: this.flags,
|
|
204
|
+
preImage: this?.preImage ? this.preImage.toString("hex"):"",
|
|
205
|
+
hashBuf: this?.hashBuf ? this.hashBuf.toString("hex"):""
|
|
158
206
|
}
|
|
159
207
|
}
|
|
160
208
|
|
|
@@ -446,11 +494,10 @@ import { TxIn } from './tx-in'
|
|
|
446
494
|
this.errStr = 'SCRIPT_ERR_BAD_OPCODE'
|
|
447
495
|
return false
|
|
448
496
|
}
|
|
449
|
-
/* REMOVING LIMIT
|
|
450
497
|
if (chunk.buf && chunk.buf.length > Interp.MAX_SCRIPT_ELEMENT_SIZE) {
|
|
451
498
|
this.errStr = 'SCRIPT_ERR_PUSH_SIZE'
|
|
452
499
|
return false
|
|
453
|
-
}
|
|
500
|
+
}
|
|
454
501
|
|
|
455
502
|
// Note how OpCode.OP_RESERVED does not count towards the opCode limit.
|
|
456
503
|
if (opCodeNum > OpCode.OP_16 && ++this.nOpCount > 201) {
|
|
@@ -459,8 +506,6 @@ import { TxIn } from './tx-in'
|
|
|
459
506
|
}
|
|
460
507
|
|
|
461
508
|
if (
|
|
462
|
-
opCodeNum === OpCode.OP_LEFT ||
|
|
463
|
-
opCodeNum === OpCode.OP_RIGHT ||
|
|
464
509
|
opCodeNum === OpCode.OP_2MUL ||
|
|
465
510
|
opCodeNum === OpCode.OP_2DIV
|
|
466
511
|
) {
|
|
@@ -960,8 +1005,8 @@ import { TxIn } from './tx-in'
|
|
|
960
1005
|
this.errStr = 'SCRIPT_ERR_INVALID_STACK_OPERATION'
|
|
961
1006
|
return false
|
|
962
1007
|
}
|
|
963
|
-
|
|
964
|
-
|
|
1008
|
+
var buf1 = this.stack[this.stack.length - 2]
|
|
1009
|
+
var buf2 = this.stack[this.stack.length - 1]
|
|
965
1010
|
|
|
966
1011
|
if (buf1.length != buf2.length) {
|
|
967
1012
|
this.errStr = 'SCRIPT_ERR_INVALID_OPERAND_SIZE'
|
|
@@ -995,7 +1040,7 @@ import { TxIn } from './tx-in'
|
|
|
995
1040
|
this.errStr = 'SCRIPT_ERR_INVALID_STACK_OPERATION'
|
|
996
1041
|
return false
|
|
997
1042
|
}
|
|
998
|
-
|
|
1043
|
+
var buf = this.stack[this.stack.length - 1]
|
|
999
1044
|
for(let i = 0; i < buf.length; i++) {
|
|
1000
1045
|
buf[i] = ~buf[i]
|
|
1001
1046
|
}
|
|
@@ -1319,13 +1364,19 @@ import { TxIn } from './tx-in'
|
|
|
1319
1364
|
|
|
1320
1365
|
let bufSig = this.stack[this.stack.length - 2]
|
|
1321
1366
|
let bufPubKey = this.stack[this.stack.length - 1]
|
|
1367
|
+
if (
|
|
1368
|
+
!this.checkSigEncoding(bufSig) ||
|
|
1369
|
+
!this.checkPubKeyEncoding(bufPubKey)
|
|
1370
|
+
) {
|
|
1371
|
+
// serror is set
|
|
1372
|
+
return false
|
|
1373
|
+
}
|
|
1322
1374
|
|
|
1323
1375
|
// Subset of script starting at the most recent codeseparator
|
|
1324
1376
|
// CScript scriptCode(pBeginCodeHash, pend)
|
|
1325
1377
|
let subScript = new Script().fromObject({
|
|
1326
1378
|
chunks: this.script.chunks.slice(this.pBeginCodeHash)
|
|
1327
1379
|
})
|
|
1328
|
-
|
|
1329
1380
|
// https://github.com/Bitcoin-UAHF/spec/blob/master/replay-protected-sighash.md
|
|
1330
1381
|
let nHashType =
|
|
1331
1382
|
bufSig.length > 0 ? bufSig.readUInt8(bufSig.length - 1) : 0
|
|
@@ -1338,18 +1389,39 @@ import { TxIn } from './tx-in'
|
|
|
1338
1389
|
subScript.findAndDelete(new Script().writeBuffer(bufSig))
|
|
1339
1390
|
}
|
|
1340
1391
|
|
|
1341
|
-
if (
|
|
1342
|
-
!this.checkSigEncoding(bufSig) ||
|
|
1343
|
-
!this.checkPubKeyEncoding(bufPubKey)
|
|
1344
|
-
) {
|
|
1345
|
-
// serror is set
|
|
1346
|
-
return false
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
1392
|
let fSuccess
|
|
1350
1393
|
try {
|
|
1351
1394
|
let sig = new Sig().fromTxFormat(bufSig)
|
|
1352
1395
|
let pubKey = new PubKey().fromBuffer(bufPubKey, false)
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
this.nHashType = sig.nHashType
|
|
1399
|
+
|
|
1400
|
+
if (typeof this.nIn === "undefined"){
|
|
1401
|
+
console.log("Missing tx input nIn")
|
|
1402
|
+
}
|
|
1403
|
+
if (typeof this.tx === "undefined"){
|
|
1404
|
+
this.tx = new Tx()
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
//subScript is usually the redeemScript
|
|
1408
|
+
|
|
1409
|
+
try{
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
this.preImage = this.tx.sighashPreimage (sig.nHashType, this.nIn, subScript, this.valueBn, Tx.SCRIPT_ENABLE_SIGHASH_FORKID )
|
|
1413
|
+
//this.hashBuf = this.tx.sighash(sig.nHashType, this.nIn, subScript, this.valueBn, Tx.SCRIPT_ENABLE_SIGHASH_FORKID)
|
|
1414
|
+
|
|
1415
|
+
if (this.preImage.compare(Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')) === 0) {
|
|
1416
|
+
this.hashBuf = this.preImage
|
|
1417
|
+
}else{
|
|
1418
|
+
this.hashBuf = new Br(Hash.sha256Sha256(this.preImage)).readReverse()
|
|
1419
|
+
}
|
|
1420
|
+
this.verify = Ecdsa.verify( this.hashBuf, sig, pubKey, 'little', true)
|
|
1421
|
+
|
|
1422
|
+
}catch(e){
|
|
1423
|
+
console.log("ERROR: ",e.message)
|
|
1424
|
+
}
|
|
1353
1425
|
fSuccess = this.tx.verify(
|
|
1354
1426
|
sig,
|
|
1355
1427
|
pubKey,
|
|
@@ -1357,8 +1429,9 @@ import { TxIn } from './tx-in'
|
|
|
1357
1429
|
subScript,
|
|
1358
1430
|
Boolean(this.flags & Interp.SCRIPT_VERIFY_LOW_S),
|
|
1359
1431
|
this.valueBn,
|
|
1360
|
-
|
|
1432
|
+
Tx.SCRIPT_ENABLE_SIGHASH_FORKID
|
|
1361
1433
|
)
|
|
1434
|
+
|
|
1362
1435
|
} catch (e) {
|
|
1363
1436
|
// invalid sig or pubKey
|
|
1364
1437
|
fSuccess = false
|
|
@@ -1481,6 +1554,7 @@ import { TxIn } from './tx-in'
|
|
|
1481
1554
|
this.valueBn,
|
|
1482
1555
|
this.flags
|
|
1483
1556
|
)
|
|
1557
|
+
|
|
1484
1558
|
} catch (e) {
|
|
1485
1559
|
// invalid sig or pubKey
|
|
1486
1560
|
fOk = false
|
|
@@ -1546,8 +1620,9 @@ import { TxIn } from './tx-in'
|
|
|
1546
1620
|
this.errStr = 'SCRIPT_ERR_INVALID_STACK_OPERATION'
|
|
1547
1621
|
return false
|
|
1548
1622
|
}
|
|
1549
|
-
|
|
1623
|
+
|
|
1550
1624
|
let vch1 = this.stack[this.stack.length - 2]
|
|
1625
|
+
|
|
1551
1626
|
let vch2 = this.stack[this.stack.length - 1]
|
|
1552
1627
|
|
|
1553
1628
|
this.stack[this.stack.length - 2] = Buffer.concat([vch1, vch2])
|
|
@@ -1559,8 +1634,9 @@ import { TxIn } from './tx-in'
|
|
|
1559
1634
|
this.errStr = 'SCRIPT_ERR_INVALID_STACK_OPERATION'
|
|
1560
1635
|
return false
|
|
1561
1636
|
}
|
|
1562
|
-
|
|
1637
|
+
|
|
1563
1638
|
let data = this.stack[this.stack.length - 2]
|
|
1639
|
+
|
|
1564
1640
|
let position = new Bn().fromScriptNumBuffer(
|
|
1565
1641
|
this.stack[this.stack.length - 1],
|
|
1566
1642
|
fRequireMinimal
|
|
@@ -1570,8 +1646,9 @@ import { TxIn } from './tx-in'
|
|
|
1570
1646
|
this.errStr = 'SCRIPT_ERR_INVALID_SPLIT_RANGE'
|
|
1571
1647
|
return false
|
|
1572
1648
|
}
|
|
1573
|
-
|
|
1649
|
+
|
|
1574
1650
|
let n1 = data.slice(0, position)
|
|
1651
|
+
|
|
1575
1652
|
let n2 = data.slice(position)
|
|
1576
1653
|
|
|
1577
1654
|
this.stack.pop()
|
|
@@ -1581,7 +1658,77 @@ import { TxIn } from './tx-in'
|
|
|
1581
1658
|
this.stack.push(n2)
|
|
1582
1659
|
|
|
1583
1660
|
break
|
|
1661
|
+
// input: a b
|
|
1662
|
+
// output: out
|
|
1663
|
+
// Converts numeric value a into byte sequence of length b.
|
|
1664
|
+
case OpCode.OP_NUM2BIN:
|
|
1665
|
+
if (this.stack.length < 2) {
|
|
1666
|
+
this.errStr = 'OP_NUM2BIN requires at least two items to be on the stack.'
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
let size = new Bn().fromScriptNumBuffer(
|
|
1670
|
+
this.stack[this.stack.length - 1],
|
|
1671
|
+
fRequireMinimal,
|
|
1672
|
+
Interp.DEFAULT_SCRIPT_NUM_LENGTH_POLICY_AFTER_GENESIS
|
|
1673
|
+
).toNumber()
|
|
1674
|
+
if (size > Interp.MAX_SCRIPT_ELEMENT_SIZE) {
|
|
1675
|
+
this.errStr=`It's not currently possible to push data larger than ${Interp.MAX_SCRIPT_ELEMENT_SIZE} bytes.`
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
this.stack.pop()
|
|
1679
|
+
|
|
1680
|
+
let rawnum = this.stack[this.stack.length - 1]
|
|
1681
|
+
// Try to see if we can fit that number in the number of
|
|
1682
|
+
// byte requested.
|
|
1683
|
+
rawnum = minimallyEncode(rawnum)
|
|
1684
|
+
|
|
1685
|
+
if (rawnum.length > size) {
|
|
1686
|
+
this.errStr='OP_NUM2BIN requires that the size expressed in the top stack item is large enough to hold the value expressed in the second-from-top stack item.'
|
|
1687
|
+
}
|
|
1584
1688
|
|
|
1689
|
+
// We already have an element of the right size, we
|
|
1690
|
+
// don't need to do anything.
|
|
1691
|
+
if (rawnum.length === size) {
|
|
1692
|
+
this.stack[this.stack.length - 1] = rawnum
|
|
1693
|
+
break
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
var signbit = 0x00
|
|
1697
|
+
if (rawnum.length > 0) {
|
|
1698
|
+
signbit = rawnum[rawnum.length - 1] & 0x80
|
|
1699
|
+
rawnum[rawnum.length - 1] &= 0x7f
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
var num = new Array(size)
|
|
1703
|
+
num.fill(0)
|
|
1704
|
+
for (var n = 0; n < size; n++) {
|
|
1705
|
+
num[n] = rawnum[n]
|
|
1706
|
+
}
|
|
1707
|
+
n = rawnum.length - 1
|
|
1708
|
+
while (n++ < size - 2) {
|
|
1709
|
+
num[n] = 0x00
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
num[n] = signbit
|
|
1713
|
+
|
|
1714
|
+
this.stack[this.stack.length - 1] = Buffer.from(new Uint8Array(num).buffer, "binary")
|
|
1715
|
+
break
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
// input: x
|
|
1719
|
+
// output: out
|
|
1720
|
+
// Converts byte sequence x into a numeric value.
|
|
1721
|
+
case OpCode.OP_BIN2NUM:
|
|
1722
|
+
if (this.stack.length < 1) {
|
|
1723
|
+
this.errStr='OP_BIN2NUM requires at least one item to be on the stack.'
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
var tmp1 = this.stack[this.stack.length - 1]
|
|
1727
|
+
var tmp2 = minimallyEncode(tmp1)
|
|
1728
|
+
// The resulting number must be a valid number.
|
|
1729
|
+
this.stack[this.stack.length - 1] = new Bn().fromScriptNumBuffer(tmp2, fRequireMinimal, Interp.DEFAULT_SCRIPT_NUM_LENGTH_POLICY_AFTER_GENESIS)
|
|
1730
|
+
|
|
1731
|
+
break
|
|
1585
1732
|
default:
|
|
1586
1733
|
this.errStr = 'SCRIPT_ERR_BAD_OPCODE'
|
|
1587
1734
|
return false
|
|
@@ -1774,8 +1921,8 @@ import { TxIn } from './tx-in'
|
|
|
1774
1921
|
// TODO: https://github.com/bitcoin-sv/bitcoin-sv/blob/b489c32ef55d428c5c3825d5526de018031a20af/src/policy/policy.h
|
|
1775
1922
|
/** Maximum stack memory usage (used instead of MAX_SCRIPT_ELEMENT_SIZE and MAX_STACK_ELEMENTS) after Genesis. **/
|
|
1776
1923
|
|
|
1777
|
-
|
|
1778
|
-
Interp.DEFAULT_SCRIPT_NUM_LENGTH_POLICY_AFTER_GENESIS =
|
|
1924
|
+
Interp.MAX_SCRIPT_ELEMENT_SIZE = 500*1000
|
|
1925
|
+
Interp.DEFAULT_SCRIPT_NUM_LENGTH_POLICY_AFTER_GENESIS = 10*1000 // 10KB
|
|
1779
1926
|
|
|
1780
1927
|
Interp.LOCKTIME_THRESHOLD = 500000000 // Tue Nov 5 00:53:20 1985 UTC
|
|
1781
1928
|
|
|
@@ -1846,8 +1993,25 @@ import { TxIn } from './tx-in'
|
|
|
1846
1993
|
// These are the things we wish to verify by default. At the time of writing,
|
|
1847
1994
|
// P2SH and CHECKLOCKTIMEVERIFY are both active, but CHECKSEQUENCEVERIFY is
|
|
1848
1995
|
// not.
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
//
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
// https://github.com/bitcoin-sv/bitcoin-sv/blob/86eb5e8bdf5573c3cd844a1d81bd4fb151b909e0/src/policy/policy.h#L176
|
|
1999
|
+
// https://github.com/bitcoin-sv/bitcoin-sv/blob/86eb5e8bdf5573c3cd844a1d81bd4fb151b909e0/src/script/standard.h#L41
|
|
2000
|
+
Interp.defaultFlags = Interp.SCRIPT_VERIFY_P2SH |
|
|
2001
|
+
Interp.SCRIPT_VERIFY_STRICTENC |
|
|
2002
|
+
Interp.SCRIPT_ENABLE_SIGHASH_FORKID |
|
|
2003
|
+
Interp.SCRIPT_VERIFY_LOW_S |
|
|
2004
|
+
Interp.SCRIPT_VERIFY_NULLDUMMY |
|
|
2005
|
+
Interp.SCRIPT_VERIFY_DERSIG |
|
|
2006
|
+
Interp.SCRIPT_VERIFY_MINIMALDATA |
|
|
2007
|
+
Interp.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
|
|
2008
|
+
Interp.SCRIPT_VERIFY_CLEANSTACK |
|
|
2009
|
+
Interp.SCRIPT_VERIFY_SIGPUSHONLY |
|
|
2010
|
+
Interp.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
|
|
2011
|
+
Interp.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
|
|
2012
|
+
|
|
2013
|
+
|
|
2014
|
+
// Interp.SCRIPT_VERIFY_P2SH | Interp.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
|
|
2015
|
+
// Interp.defaultFlags = Interp.SCRIPT_VERIFY_P2SH |
|
|
1852
2016
|
|
|
1853
2017
|
export { Interp }
|
package/lib/merkle.js
CHANGED
|
@@ -40,7 +40,7 @@ class Merkle extends Struct {
|
|
|
40
40
|
// that we copy *the actual object* over and over again, which ensures
|
|
41
41
|
// that when we finds its hash, the hash is cached.
|
|
42
42
|
const lastval = bufs[bufs.length - 1]
|
|
43
|
-
|
|
43
|
+
const len = Math.pow(2, Math.ceil(log))
|
|
44
44
|
for (let i = bufs.length; i < len; i++) {
|
|
45
45
|
bufs.push(lastval)
|
|
46
46
|
}
|