@smartledger/bsv 4.5.0 → 4.6.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/CHANGELOG.md +27 -0
- package/bsv-covenant.min.js +2 -2
- package/bsv-gdaf.min.js +3 -3
- package/bsv-ltp.min.js +3 -3
- package/bsv-smartcontract.min.js +3 -3
- package/bsv.bundle.js +3 -3
- package/bsv.min.js +3 -3
- package/lib/smart_contract/covenant_helpers.js +13 -3
- package/lib/smart_contract/pushtx.js +8 -3
- package/package.json +1 -1
|
@@ -17,15 +17,18 @@ var Signature = require('../crypto/signature')
|
|
|
17
17
|
// SIGHASH_ALL | SIGHASH_FORKID — the BSV default these covenants are built for.
|
|
18
18
|
var SIGHASH = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID // 0x41
|
|
19
19
|
|
|
20
|
-
// Post-Genesis consensus flags
|
|
21
|
-
//
|
|
22
|
-
// (
|
|
20
|
+
// Post-Genesis consensus + STANDARD RELAY flags — what mainnet miners actually
|
|
21
|
+
// enforce. Includes SCRIPT_VERIFY_MINIMALDATA (every push must be minimal) and
|
|
22
|
+
// SCRIPT_VERIFY_LOW_S (canonical signatures). Verifying with these locally
|
|
23
|
+
// catches non-relayable covenants BEFORE broadcast — covenants verified here
|
|
24
|
+
// have been deployed and spent on BSV mainnet.
|
|
23
25
|
function flags () {
|
|
24
26
|
var I = bsv.Script.Interpreter
|
|
25
27
|
return I.SCRIPT_VERIFY_P2SH |
|
|
26
28
|
I.SCRIPT_VERIFY_STRICTENC |
|
|
27
29
|
I.SCRIPT_VERIFY_DERSIG |
|
|
28
30
|
I.SCRIPT_VERIFY_LOW_S |
|
|
31
|
+
I.SCRIPT_VERIFY_MINIMALDATA |
|
|
29
32
|
I.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
|
|
30
33
|
I.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY |
|
|
31
34
|
I.SCRIPT_ENABLE_SIGHASH_FORKID |
|
|
@@ -102,6 +105,13 @@ function p2pkhOutput (addressOrPubKey, satoshis) {
|
|
|
102
105
|
|
|
103
106
|
/** Minimal little-endian script-number Buffer (push as data to put a number on-stack). */
|
|
104
107
|
function scriptNum (n) {
|
|
108
|
+
// Minimal on-stack number: 0..16 and -1 use the dedicated opcodes (OP_0..OP_16,
|
|
109
|
+
// OP_1NEGATE) instead of a data push, so covenant scripts stay MINIMALDATA-clean
|
|
110
|
+
// (mainnet relay policy). Larger values use a minimal scriptNum push. The result
|
|
111
|
+
// is passed to Script.add(), which accepts an opcode number or a Buffer.
|
|
112
|
+
if (n === 0) return bsv.Opcode.OP_0
|
|
113
|
+
if (n === -1) return bsv.Opcode.OP_1NEGATE
|
|
114
|
+
if (n >= 1 && n <= 16) return bsv.Opcode['OP_' + n]
|
|
105
115
|
return new BN(n).toScriptNumBuffer()
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -54,8 +54,9 @@ function reverseBytes (script, n) {
|
|
|
54
54
|
*/
|
|
55
55
|
function pushTxCore (script) {
|
|
56
56
|
script.add(Opcode.OP_HASH256) // z = HASH256(preimage), 32B BE
|
|
57
|
-
reverseBytes(script, 32) // -> little-endian
|
|
58
|
-
|
|
57
|
+
reverseBytes(script, 32) // -> little-endian = e. The grind guarantees e is
|
|
58
|
+
// already positive and minimally encoded (z[0] in 0x01..0x7f), so NO 0x00 sign
|
|
59
|
+
// byte is appended — keeping the script MINIMALDATA-clean (mainnet-relayable).
|
|
59
60
|
script.add(gxLe).add(Opcode.OP_ADD) // e + Gx
|
|
60
61
|
script.add(N_LE).add(Opcode.OP_MOD) // s = (e + Gx) mod n
|
|
61
62
|
script.add(scriptNum(32)).add(Opcode.OP_NUM2BIN) // s -> 32-byte LE
|
|
@@ -64,7 +65,7 @@ function pushTxCore (script) {
|
|
|
64
65
|
// r-value inside the DER prefix and the body of the 02||Gx pubkey). Sharing it
|
|
65
66
|
// via the altstack saves a 32-byte constant vs. embedding Gx twice.
|
|
66
67
|
script.add(Gx).add(Opcode.OP_DUP) // [s_be, Gx, Gx]
|
|
67
|
-
script.add(
|
|
68
|
+
script.add(Opcode.OP_2).add(Opcode.OP_SWAP).add(Opcode.OP_CAT) // pubkey = 02||Gx (OP_2 = minimal push of 0x02)
|
|
68
69
|
script.add(Opcode.OP_TOALTSTACK) // park pubkey ; [s_be, Gx]
|
|
69
70
|
script.add(Buffer.from([0x30, 0x44, 0x02, 0x20])).add(Opcode.OP_SWAP).add(Opcode.OP_CAT) // 30440220||Gx
|
|
70
71
|
script.add(Buffer.from([0x02, 0x20])).add(Opcode.OP_CAT) // ||0220 => DER prefix
|
|
@@ -117,6 +118,10 @@ var HALF_N = new BN('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681
|
|
|
117
118
|
*/
|
|
118
119
|
function sFromPreimage (preimage) {
|
|
119
120
|
var z = Hash.sha256sha256(preimage)
|
|
121
|
+
// Script no longer sign-extends z, so e (= reverse(z) as a number) must be
|
|
122
|
+
// positive AND minimally encoded: its little-endian MSB (= z[0]) in 0x01..0x7f.
|
|
123
|
+
// This keeps the locking script MINIMALDATA-clean (mainnet-relayable).
|
|
124
|
+
if (z[0] < 0x01 || z[0] > 0x7f) return null
|
|
120
125
|
var s = new BN(z).add(new BN(Gx)).mod(N)
|
|
121
126
|
if (s.gt(HALF_N)) return null // enforce low-S (canonical / non-malleable)
|
|
122
127
|
var sBE = s.toBuffer('be', 32)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "🚀 Complete Bitcoin SV development framework with legally-recognizable DID:web + W3C VC-JWT toolkit, Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), StatusList2021 revocation, and 16 flexible loading options. Standards-based credentials with ES256/ES256K support, on-chain BSV anchoring, and comprehensive Bitcoin SV API. Perfect for legal tokens, verifiable credentials, DeFi, smart contracts, and secure Bitcoin applications.",
|
|
5
5
|
"author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
|
|
6
6
|
"homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
|