@smartledger/bsv 9.2.0 → 9.4.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 +133 -0
- package/README.md +19 -19
- package/SECURITY.md +23 -23
- package/anchor-entry.d.ts +8 -0
- package/bsv-gdaf.min.js +52 -52
- package/bsv-ltp.min.js +1 -1
- package/bsv-smartcontract.min.js +18 -18
- package/bsv.bundle.js +52 -52
- package/bsv.d.ts +9 -1
- package/bsv.min.js +52 -52
- package/covenant-entry.d.ts +17 -0
- package/didweb-entry.d.ts +7 -0
- package/docs/AUDIT_SCOPE.md +136 -29
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/ORDINALS_ENVELOPE_FIELDS.md +159 -0
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/audit-rfq/README.md +41 -0
- package/docs/audit-rfq/cure53.txt +49 -0
- package/docs/audit-rfq/ncc-group.txt +49 -0
- package/docs/audit-rfq/trail-of-bits.txt +49 -0
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/gdaf-entry.d.ts +7 -0
- package/lib/ordinals/inscription.js +112 -0
- package/lib/script/interpreter.js +7 -2
- package/lib/smart_contract/dsl.js +55 -3
- package/ltp-entry.d.ts +7 -0
- package/package.json +49 -14
- package/script-helper-entry.d.ts +75 -0
- package/security-entry.d.ts +52 -0
- package/shamir-entry.d.ts +10 -0
- package/smartcontract-entry.d.ts +8 -0
- package/statuslist-entry.d.ts +11 -0
- package/vcjwt-entry.d.ts +15 -0
- package/version.js +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
To: NCC Group — Cryptography Services
|
|
2
|
+
Route: nccgroup.com — Cryptography Services enquiry (verify route)
|
|
3
|
+
Reply-to: support@smartledger.technology
|
|
4
|
+
|
|
5
|
+
Subject: Audit enquiry — BSV cryptographic library core (~13k LOC JavaScript)
|
|
6
|
+
|
|
7
|
+
Hello,
|
|
8
|
+
|
|
9
|
+
We are approaching your Cryptography Services team specifically rather than
|
|
10
|
+
a general assurance engagement, because the sighash construction and key-
|
|
11
|
+
derivation portions are the parts we are least able to review ourselves.
|
|
12
|
+
|
|
13
|
+
We maintain @smartledger/bsv, a Bitcoin SV library published on npm. We are
|
|
14
|
+
seeking a quote for an independent security review of its cryptographic core.
|
|
15
|
+
|
|
16
|
+
Scope, and we would like these priced separately:
|
|
17
|
+
|
|
18
|
+
Tier 1 — 12,391 lines, 33 files. Script interpreter, sighash and signing,
|
|
19
|
+
ECDSA and signature encoding, BIP-32 derivation, key and address
|
|
20
|
+
construction.
|
|
21
|
+
|
|
22
|
+
Tier 2 — 1,607 lines. BIP-39 mnemonics, ECIES, and the Base58Check/varint
|
|
23
|
+
decoding surface.
|
|
24
|
+
|
|
25
|
+
JavaScript (CommonJS), Node >= 20.19. The code is public.
|
|
26
|
+
|
|
27
|
+
Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
|
|
28
|
+
by the Noble libraries and already audited; and our 24,769-line application
|
|
29
|
+
layer (credentials, tokens, ordinals), which we would treat as a separate
|
|
30
|
+
engagement.
|
|
31
|
+
|
|
32
|
+
Context that should shorten discovery: the core is inherited from bitcore and
|
|
33
|
+
has been fixed reactively but never independently reviewed. We can provide a
|
|
34
|
+
test-backed threat model, a 452-case behavioural conformance corpus that a
|
|
35
|
+
second independent implementation agrees with, and a documented history of the
|
|
36
|
+
defects we have found ourselves.
|
|
37
|
+
|
|
38
|
+
The failure mode we most want examined is code that reports a check as passed
|
|
39
|
+
without performing it — several of our own findings have had that shape.
|
|
40
|
+
|
|
41
|
+
Could you indicate availability, an approximate cost range, and what you would
|
|
42
|
+
need from us to firm that up?
|
|
43
|
+
|
|
44
|
+
Repository: https://github.com/codenlighten/smartledger-bsv
|
|
45
|
+
Package: https://www.npmjs.com/package/@smartledger/bsv
|
|
46
|
+
|
|
47
|
+
Thank you,
|
|
48
|
+
SmartLedger Technology
|
|
49
|
+
support@smartledger.technology
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
To: Trail of Bits
|
|
2
|
+
Route: Contact form on trailofbits.com — verify current route
|
|
3
|
+
Reply-to: support@smartledger.technology
|
|
4
|
+
|
|
5
|
+
Subject: Audit enquiry — BSV cryptographic library core (~13k LOC JavaScript)
|
|
6
|
+
|
|
7
|
+
Hello,
|
|
8
|
+
|
|
9
|
+
We are approaching you for the exploit-oriented methodology in particular:
|
|
10
|
+
the failure mode described below — a check reported as passed without being
|
|
11
|
+
performed — is the one our own findings keep taking.
|
|
12
|
+
|
|
13
|
+
We maintain @smartledger/bsv, a Bitcoin SV library published on npm. We are
|
|
14
|
+
seeking a quote for an independent security review of its cryptographic core.
|
|
15
|
+
|
|
16
|
+
Scope, and we would like these priced separately:
|
|
17
|
+
|
|
18
|
+
Tier 1 — 12,391 lines, 33 files. Script interpreter, sighash and signing,
|
|
19
|
+
ECDSA and signature encoding, BIP-32 derivation, key and address
|
|
20
|
+
construction.
|
|
21
|
+
|
|
22
|
+
Tier 2 — 1,607 lines. BIP-39 mnemonics, ECIES, and the Base58Check/varint
|
|
23
|
+
decoding surface.
|
|
24
|
+
|
|
25
|
+
JavaScript (CommonJS), Node >= 20.19. The code is public.
|
|
26
|
+
|
|
27
|
+
Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
|
|
28
|
+
by the Noble libraries and already audited; and our 24,769-line application
|
|
29
|
+
layer (credentials, tokens, ordinals), which we would treat as a separate
|
|
30
|
+
engagement.
|
|
31
|
+
|
|
32
|
+
Context that should shorten discovery: the core is inherited from bitcore and
|
|
33
|
+
has been fixed reactively but never independently reviewed. We can provide a
|
|
34
|
+
test-backed threat model, a 452-case behavioural conformance corpus that a
|
|
35
|
+
second independent implementation agrees with, and a documented history of the
|
|
36
|
+
defects we have found ourselves.
|
|
37
|
+
|
|
38
|
+
The failure mode we most want examined is code that reports a check as passed
|
|
39
|
+
without performing it — several of our own findings have had that shape.
|
|
40
|
+
|
|
41
|
+
Could you indicate availability, an approximate cost range, and what you would
|
|
42
|
+
need from us to firm that up?
|
|
43
|
+
|
|
44
|
+
Repository: https://github.com/codenlighten/smartledger-bsv
|
|
45
|
+
Package: https://www.npmjs.com/package/@smartledger/bsv
|
|
46
|
+
|
|
47
|
+
Thank you,
|
|
48
|
+
SmartLedger Technology
|
|
49
|
+
support@smartledger.technology
|
|
@@ -48,7 +48,7 @@ const tx: Transaction = new Transaction();
|
|
|
48
48
|
#### **Core Library Only (937KB)**
|
|
49
49
|
For basic Bitcoin SV operations:
|
|
50
50
|
```html
|
|
51
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
52
52
|
<script>
|
|
53
53
|
const privateKey = new bsv.PrivateKey();
|
|
54
54
|
const address = privateKey.toAddress();
|
|
@@ -58,7 +58,7 @@ For basic Bitcoin SV operations:
|
|
|
58
58
|
#### **Complete Bundle (937KB)**
|
|
59
59
|
Everything in one file:
|
|
60
60
|
```html
|
|
61
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js"></script>
|
|
62
62
|
<script>
|
|
63
63
|
// All features available immediately
|
|
64
64
|
const shares = bsv.splitSecret('secret', 5, 3);
|
|
@@ -71,9 +71,9 @@ Everything in one file:
|
|
|
71
71
|
|
|
72
72
|
#### **Smart Contract Development (~2.7MB total — each bundle is self-contained and re-embeds core BSV)**
|
|
73
73
|
```html
|
|
74
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js"></script>
|
|
77
77
|
<script>
|
|
78
78
|
const covenant = bsv.SmartContract.createCovenantBuilder()
|
|
79
79
|
.extractField('amount').push(50000).greaterThanOrEqual().build();
|
|
@@ -82,9 +82,9 @@ Everything in one file:
|
|
|
82
82
|
|
|
83
83
|
#### **Legal & Identity Development (~3.2MB total — each bundle is self-contained and re-embeds core BSV)**
|
|
84
84
|
```html
|
|
85
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js"></script>
|
|
88
88
|
<script>
|
|
89
89
|
// Legal Token Protocol
|
|
90
90
|
const propertyToken = bsv.createPropertyToken({
|
|
@@ -98,9 +98,9 @@ Everything in one file:
|
|
|
98
98
|
|
|
99
99
|
#### **Security & Cryptography (~1.4MB total — each bundle is self-contained and re-embeds core BSV)**
|
|
100
100
|
```html
|
|
101
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-shamir.min.js"></script>
|
|
104
104
|
<script>
|
|
105
105
|
// Threshold Cryptography
|
|
106
106
|
const shares = bsv.splitSecret('my_secret_key', 5, 3);
|
|
@@ -114,18 +114,18 @@ Everything in one file:
|
|
|
114
114
|
|
|
115
115
|
| Module | Size | Purpose | CDN Link |
|
|
116
116
|
|--------|------|---------|----------|
|
|
117
|
-
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.4.0/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.4.0/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.4.0/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.4.0/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.4.0/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.4.0/bsv-message.min.js` |
|
|
129
129
|
|
|
130
130
|
## ⚙️ **Development Environment Setup**
|
|
131
131
|
|
|
@@ -14,10 +14,10 @@ npm install @smartledger/bsv
|
|
|
14
14
|
### Browser CDN (Instant)
|
|
15
15
|
```html
|
|
16
16
|
<!-- Core library (937KB) -->
|
|
17
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js"></script>
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 💰 **Your First Transaction (60 seconds)**
|
|
@@ -127,19 +127,19 @@ SmartLedger-BSV offers 12 different loading options - use only what you need:
|
|
|
127
127
|
|
|
128
128
|
```html
|
|
129
129
|
<!-- Core BSV only (937KB) -->
|
|
130
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js"></script>
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
## ⚡ **Key Advantages**
|
|
@@ -159,17 +159,17 @@ const recovered = bsv.reconstructSecret([shares[0], shares[2], shares[4]]);
|
|
|
159
159
|
### **New Modular Options**
|
|
160
160
|
```html
|
|
161
161
|
<!-- Core compatibility (same size as bsv@1.5.6) -->
|
|
162
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
package/gdaf-entry.d.ts
ADDED
|
@@ -89,6 +89,103 @@ function resolveLock (params) {
|
|
|
89
89
|
throw new Error('buildInscription requires an address or a lock script')
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
// Tags the Ordinals spec names. Everything else is "unrecognized", and the spec
|
|
93
|
+
// treats unrecognized tags by parity — see assertTagIsSafe.
|
|
94
|
+
var KNOWN_TAGS = [0, 1, 2, 3, 5, 7, 9, 11]
|
|
95
|
+
|
|
96
|
+
var BODY_TAG = 0
|
|
97
|
+
var CONTENT_TYPE_TAG = 1
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Push a field tag the way a parser expects to read it back.
|
|
101
|
+
*
|
|
102
|
+
* Tags are script numbers. 1..16 have dedicated opcodes; anything larger has no
|
|
103
|
+
* opcode form at all, because OP_16 is the largest numeric opcode — so tag 21
|
|
104
|
+
* must be a data push. Indexers read the resulting STACK ELEMENT, so `OP_5` and
|
|
105
|
+
* a one-byte push of `0x05` are the same tag; the opcode form is used wherever
|
|
106
|
+
* it exists because the data-push form of a small number is non-minimal, and
|
|
107
|
+
* non-minimal pushes are non-standard.
|
|
108
|
+
*/
|
|
109
|
+
function addTag (script, tag) {
|
|
110
|
+
if (tag >= 1 && tag <= 16) return script.add(Opcode.OP_1 - 1 + tag)
|
|
111
|
+
|
|
112
|
+
var le = []
|
|
113
|
+
var n = tag
|
|
114
|
+
while (n > 0) { le.push(n & 0xff); n = Math.floor(n / 256) }
|
|
115
|
+
// A script number carries its sign in the high bit of its last byte, so a
|
|
116
|
+
// value ending >= 0x80 needs a zero pad or it reads back negative.
|
|
117
|
+
if (le[le.length - 1] & 0x80) le.push(0x00)
|
|
118
|
+
return script.add(Buffer.from(le))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Refuse a tag that would produce a permanently broken inscription.
|
|
123
|
+
*
|
|
124
|
+
* The parity rule is the one that costs money. From the spec: "inscriptions with
|
|
125
|
+
* unrecognized even fields must be displayed as unbound, that is, without a
|
|
126
|
+
* location". An unknown ODD tag is simply ignored by an indexer that does not
|
|
127
|
+
* know it; an unknown EVEN tag costs the inscription its location, everywhere,
|
|
128
|
+
* permanently, on an output already paid for — and nothing local reports it,
|
|
129
|
+
* because a builder and its own parser agreeing proves only that they agree.
|
|
130
|
+
*
|
|
131
|
+
* This refuses rather than warns, but it is deliberately not a hard wall. The
|
|
132
|
+
* set of named tags grows as the protocol does, so a library that can never be
|
|
133
|
+
* overridden would eventually be wrong AND unbypassable, and the workaround —
|
|
134
|
+
* hand-assembling envelope bytes — is far more dangerous than the thing being
|
|
135
|
+
* prevented. Hence `allowUnknownEvenFields`, which exists to be reached for
|
|
136
|
+
* knowingly and named so it cannot be passed by accident.
|
|
137
|
+
*/
|
|
138
|
+
function assertTagIsSafe (tag, allowUnknownEven) {
|
|
139
|
+
if (!Number.isSafeInteger(tag) || tag < 0) {
|
|
140
|
+
throw new Error('field tag must be a non-negative integer, got ' + JSON.stringify(tag))
|
|
141
|
+
}
|
|
142
|
+
if (tag === BODY_TAG) {
|
|
143
|
+
throw new Error('field tag 0 opens the inscription body and cannot carry a field: ' +
|
|
144
|
+
'anything pushed after it becomes part of the content')
|
|
145
|
+
}
|
|
146
|
+
if (tag === CONTENT_TYPE_TAG) {
|
|
147
|
+
throw new Error('field tag 1 is the content type; pass `contentType` instead of ' +
|
|
148
|
+
'a field, or the inscription declares it twice')
|
|
149
|
+
}
|
|
150
|
+
if (tag % 2 === 0 && KNOWN_TAGS.indexOf(tag) === -1 && !allowUnknownEven) {
|
|
151
|
+
throw new Error('field tag ' + tag + ' is an unrecognized even tag. The Ordinals ' +
|
|
152
|
+
'spec requires such an inscription to be treated as unbound — it would be ' +
|
|
153
|
+
'indexed without a location, permanently, and nothing local would report it. ' +
|
|
154
|
+
'Use an odd tag, or pass { allowUnknownEvenFields: true } if you have ' +
|
|
155
|
+
'established that every indexer you care about recognises ' + tag + '.')
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Normalise `params.fields` into ordered [tag, value] pairs.
|
|
161
|
+
*
|
|
162
|
+
* Emitted in ascending tag order rather than in whatever order the object was
|
|
163
|
+
* written, so the same fields always produce the same bytes. Field order is not
|
|
164
|
+
* significant to a parser before the body opens, but reproducibility is worth
|
|
165
|
+
* more than honouring insertion order nobody specified.
|
|
166
|
+
*/
|
|
167
|
+
function resolveFields (params) {
|
|
168
|
+
var fields = params.fields
|
|
169
|
+
if (fields == null) return []
|
|
170
|
+
if (typeof fields !== 'object' || Array.isArray(fields) || Buffer.isBuffer(fields)) {
|
|
171
|
+
throw new Error('fields must be an object of tag numbers to values, e.g. { 5: metadata }')
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return Object.keys(fields)
|
|
175
|
+
.filter(function (k) { return fields[k] != null })
|
|
176
|
+
.map(function (k) {
|
|
177
|
+
var tag = Number(k)
|
|
178
|
+
assertTagIsSafe(tag, params.allowUnknownEvenFields)
|
|
179
|
+
var value = toBuf(fields[k], 'field ' + tag)
|
|
180
|
+
if (!value.length) {
|
|
181
|
+
throw new Error('field ' + tag + ' has an empty value; omit the field instead ' +
|
|
182
|
+
'of inscribing a zero-length one permanently')
|
|
183
|
+
}
|
|
184
|
+
return [tag, value]
|
|
185
|
+
})
|
|
186
|
+
.sort(function (a, b) { return a[0] - b[0] })
|
|
187
|
+
}
|
|
188
|
+
|
|
92
189
|
/**
|
|
93
190
|
* Build a 1Sat Ordinals inscription locking script: a base lock followed by the
|
|
94
191
|
* inert `OP_FALSE OP_IF ... OP_ENDIF` envelope carrying the content.
|
|
@@ -106,6 +203,12 @@ function resolveLock (params) {
|
|
|
106
203
|
* with `address`)
|
|
107
204
|
* @param {Address|string} [params.address] P2PKH owner (mutually exclusive with `lock`)
|
|
108
205
|
* @param {boolean} [params.allowEmptyLock] permit an empty base lock; see resolveLock
|
|
206
|
+
* @param {object} [params.fields] additional envelope fields as tag numbers
|
|
207
|
+
* to values, e.g. `{ 5: manifest, 21: thumbnail }`. Tag 5 is `metadata`, the spec's
|
|
208
|
+
* own home for an object's own record. Emitted in ascending tag order, between the
|
|
209
|
+
* content type and the body. Unrecognized EVEN tags are refused — see assertTagIsSafe.
|
|
210
|
+
* @param {boolean} [params.allowUnknownEvenFields] permit an unrecognized even tag.
|
|
211
|
+
* Costs the inscription its location in conformant indexers, permanently.
|
|
109
212
|
* @returns {Script} the full inscription locking script
|
|
110
213
|
*/
|
|
111
214
|
function buildInscription (params) {
|
|
@@ -135,12 +238,21 @@ function buildInscription (params) {
|
|
|
135
238
|
}
|
|
136
239
|
|
|
137
240
|
// Clone the base lock so we never mutate the caller's Script.
|
|
241
|
+
var fields = resolveFields(params)
|
|
242
|
+
|
|
138
243
|
var s = Script.fromBuffer(lock.toBuffer())
|
|
139
244
|
s.add(Opcode.OP_FALSE)
|
|
140
245
|
s.add(Opcode.OP_IF)
|
|
141
246
|
s.add(ORD)
|
|
142
247
|
s.add(Opcode.OP_1)
|
|
143
248
|
s.add(contentType)
|
|
249
|
+
// Every field goes here, between the content type and the body. Tag 0 opens
|
|
250
|
+
// the body and everything after it IS the body, so a field emitted late does
|
|
251
|
+
// not fail — it silently becomes part of the file.
|
|
252
|
+
fields.forEach(function (f) {
|
|
253
|
+
addTag(s, f[0])
|
|
254
|
+
s.add(f[1])
|
|
255
|
+
})
|
|
144
256
|
s.add(Opcode.OP_0)
|
|
145
257
|
s.add(content)
|
|
146
258
|
s.add(Opcode.OP_ENDIF)
|
|
@@ -2667,8 +2667,13 @@ Interpreter.prototype.step = function () {
|
|
|
2667
2667
|
|
|
2668
2668
|
this.stack[this.stack.length - 1] = buf2
|
|
2669
2669
|
|
|
2670
|
-
// The resulting number must be a valid number.
|
|
2671
|
-
|
|
2670
|
+
// The resulting number must be a valid number. The width is the era's,
|
|
2671
|
+
// not a constant: `_isMinimallyEncoded` defaults to MAXIMUM_ELEMENT_SIZE
|
|
2672
|
+
// (4), so omitting the argument capped every era at the pre-Genesis
|
|
2673
|
+
// width. No vector caught it because every BIN2NUM vector in the node's
|
|
2674
|
+
// corpus runs under P2SH,STRICTENC alone — pre-Genesis, where 4 is the
|
|
2675
|
+
// right answer either way.
|
|
2676
|
+
if (!Interpreter._isMinimallyEncoded(buf2, this.maxScriptNumLength())) {
|
|
2672
2677
|
this.errstr = 'SCRIPT_ERR_INVALID_NUMBER_RANGE'
|
|
2673
2678
|
return false
|
|
2674
2679
|
}
|
|
@@ -28,6 +28,11 @@ var Opcode = require('../opcode')
|
|
|
28
28
|
var Transaction = require('../transaction')
|
|
29
29
|
var n = helpers.scriptNum
|
|
30
30
|
|
|
31
|
+
// Consensus constants, named so the compiled script can be read against the node.
|
|
32
|
+
var LOCKTIME_THRESHOLD = 500000000 // below: block height. at or above: unix time.
|
|
33
|
+
var SEQUENCE_FINAL = Buffer.from([0xff, 0xff, 0xff, 0xff])
|
|
34
|
+
var SIGN_PAD = Buffer.from([0x00]) // makes an unsigned 32-bit field read positive
|
|
35
|
+
|
|
31
36
|
function toOutput (dest, satoshis) {
|
|
32
37
|
if (dest instanceof Transaction.Output) return dest
|
|
33
38
|
if (dest instanceof Script) return new Transaction.Output({ script: dest, satoshis: satoshis })
|
|
@@ -59,8 +64,22 @@ Policy.prototype.payTo = function (dest, satoshis) {
|
|
|
59
64
|
return this
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Require the spend's nLockTime to be >= height.
|
|
69
|
+
*
|
|
70
|
+
* Below LOCKTIME_THRESHOLD (500000000) the value is a BLOCK HEIGHT; at or above
|
|
71
|
+
* it, a UNIX TIMESTAMP. The compiled script enforces the same unit the floor
|
|
72
|
+
* uses, so a height floor cannot be satisfied by a timestamp.
|
|
73
|
+
*
|
|
74
|
+
* 0 is rejected: consensus reads nLockTime 0 as "no lock" and treats the
|
|
75
|
+
* transaction as final regardless of any input's sequence, so a floor of 0
|
|
76
|
+
* would compile to a lock that binds nothing.
|
|
77
|
+
*/
|
|
63
78
|
Policy.prototype.lockUntil = function (height) {
|
|
79
|
+
if (!Number.isInteger(height) || height < 1 || height > 0xffffffff) {
|
|
80
|
+
throw new Error('lockUntil: expected an integer in 1..4294967295, got ' + height +
|
|
81
|
+
' (nLockTime 0 means "no lock" — consensus treats such a transaction as final)')
|
|
82
|
+
}
|
|
64
83
|
this._minLockTime = height
|
|
65
84
|
return this
|
|
66
85
|
}
|
|
@@ -75,7 +94,11 @@ Policy.prototype.describe = function () {
|
|
|
75
94
|
this._outputs.forEach(function (o, i) {
|
|
76
95
|
parts.push('output[' + i + '] = ' + o.satoshis + ' sat to ' + o.script.toASM().slice(0, 24) + '...')
|
|
77
96
|
})
|
|
78
|
-
if (this._minLockTime !== null)
|
|
97
|
+
if (this._minLockTime !== null) {
|
|
98
|
+
var unit = this._minLockTime < LOCKTIME_THRESHOLD ? 'block height' : 'unix time'
|
|
99
|
+
parts.push('nLockTime >= ' + this._minLockTime + ' as a ' + unit)
|
|
100
|
+
parts.push('this input is non-final (nSequence != 0xffffffff)')
|
|
101
|
+
}
|
|
79
102
|
return 'spend allowed iff: ' + parts.join(' AND ')
|
|
80
103
|
}
|
|
81
104
|
|
|
@@ -97,9 +120,38 @@ Policy.prototype.compile = function () {
|
|
|
97
120
|
}
|
|
98
121
|
|
|
99
122
|
if (this._minLockTime !== null) {
|
|
123
|
+
// A time lock is three consensus rules, not one comparison. All three are in
|
|
124
|
+
// the node's CheckLockTime; checking only the number reproduces none of them.
|
|
125
|
+
|
|
126
|
+
// 1. nSequence of THIS input must be non-final. IsFinalTx() ignores nLockTime
|
|
127
|
+
// outright when every input is 0xffffffff, so without this the spend is
|
|
128
|
+
// minable in the next block no matter how large a locktime it declares.
|
|
129
|
+
// One non-final input is enough to make the whole transaction non-final,
|
|
130
|
+
// and this input is the only one the preimage lets us see.
|
|
131
|
+
s.add(Opcode.OP_DUP)
|
|
132
|
+
s.add(n(44)).add(Opcode.OP_RIGHT).add(n(4)).add(Opcode.OP_LEFT) // last 44, first 4 = nSequence
|
|
133
|
+
s.add(SEQUENCE_FINAL).add(Opcode.OP_EQUAL).add(Opcode.OP_NOT).add(Opcode.OP_VERIFY)
|
|
134
|
+
|
|
135
|
+
// 2. nLockTime is an UNSIGNED 32-bit field, and OP_BIN2NUM reads a SIGNED
|
|
136
|
+
// one. From 19 Jan 2038 the high bit is set, and 0x80000000 minimally
|
|
137
|
+
// encodes to negative zero — the floor would be compared against 0 and no
|
|
138
|
+
// spend would ever satisfy it. Sign-pad to five bytes first. That push is
|
|
139
|
+
// only legal because OP_BIN2NUM now honours the era's script-number width.
|
|
100
140
|
s.add(Opcode.OP_DUP)
|
|
101
141
|
s.add(n(8)).add(Opcode.OP_RIGHT).add(n(4)).add(Opcode.OP_LEFT) // last 8, first 4 = nLockTime
|
|
102
|
-
s.add(
|
|
142
|
+
s.add(SIGN_PAD).add(Opcode.OP_CAT).add(Opcode.OP_BIN2NUM)
|
|
143
|
+
|
|
144
|
+
// 3. Units must match the floor's. Consensus reads nLockTime below
|
|
145
|
+
// LOCKTIME_THRESHOLD as a height and at or above it as a timestamp, so a
|
|
146
|
+
// bare `>=` lets a long-past timestamp clear a future height floor —
|
|
147
|
+
// 1500000000 >= 900000 is true, and that transaction is minable today.
|
|
148
|
+
// A floor already at or above the threshold needs no guard: `>= floor`
|
|
149
|
+
// implies `>= threshold`.
|
|
150
|
+
if (this._minLockTime < LOCKTIME_THRESHOLD) {
|
|
151
|
+
s.add(Opcode.OP_DUP).add(n(LOCKTIME_THRESHOLD)).add(Opcode.OP_LESSTHAN).add(Opcode.OP_VERIFY)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
s.add(n(this._minLockTime)).add(Opcode.OP_GREATERTHANOREQUAL).add(Opcode.OP_VERIFY)
|
|
103
155
|
}
|
|
104
156
|
|
|
105
157
|
s.add(Opcode.OP_DROP).add(Opcode.OP_1) // drop preimage; succeed
|
package/ltp-entry.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "Bitcoin SV library with an interpreter-verified script engine: OP_PUSH_TX covenants, BIP-143 preimage tooling, and consensus flags that match what miners actually enforce. Also ships DID:web / W3C VC-JWT credentials and the Legal Token Protocol.",
|
|
5
5
|
"author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
|
|
6
6
|
"homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
|
|
@@ -18,21 +18,54 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./package.json": "./package.json",
|
|
20
20
|
"./version": "./version.js",
|
|
21
|
-
"./anchor":
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
"./anchor": {
|
|
22
|
+
"types": "./anchor-entry.d.ts",
|
|
23
|
+
"default": "./anchor-entry.js"
|
|
24
|
+
},
|
|
25
|
+
"./covenant": {
|
|
26
|
+
"types": "./covenant-entry.d.ts",
|
|
27
|
+
"default": "./covenant-entry.js"
|
|
28
|
+
},
|
|
29
|
+
"./didweb": {
|
|
30
|
+
"types": "./didweb-entry.d.ts",
|
|
31
|
+
"default": "./didweb-entry.js"
|
|
32
|
+
},
|
|
33
|
+
"./gdaf": {
|
|
34
|
+
"types": "./gdaf-entry.d.ts",
|
|
35
|
+
"default": "./gdaf-entry.js"
|
|
36
|
+
},
|
|
25
37
|
"./jcs": {
|
|
26
38
|
"types": "./jcs-entry.d.ts",
|
|
27
39
|
"default": "./jcs-entry.js"
|
|
28
40
|
},
|
|
29
|
-
"./ltp":
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"./
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
"./ltp": {
|
|
42
|
+
"types": "./ltp-entry.d.ts",
|
|
43
|
+
"default": "./ltp-entry.js"
|
|
44
|
+
},
|
|
45
|
+
"./script-helper": {
|
|
46
|
+
"types": "./script-helper-entry.d.ts",
|
|
47
|
+
"default": "./script-helper-entry.js"
|
|
48
|
+
},
|
|
49
|
+
"./security": {
|
|
50
|
+
"types": "./security-entry.d.ts",
|
|
51
|
+
"default": "./security-entry.js"
|
|
52
|
+
},
|
|
53
|
+
"./shamir": {
|
|
54
|
+
"types": "./shamir-entry.d.ts",
|
|
55
|
+
"default": "./shamir-entry.js"
|
|
56
|
+
},
|
|
57
|
+
"./smartcontract": {
|
|
58
|
+
"types": "./smartcontract-entry.d.ts",
|
|
59
|
+
"default": "./smartcontract-entry.js"
|
|
60
|
+
},
|
|
61
|
+
"./statuslist": {
|
|
62
|
+
"types": "./statuslist-entry.d.ts",
|
|
63
|
+
"default": "./statuslist-entry.js"
|
|
64
|
+
},
|
|
65
|
+
"./vcjwt": {
|
|
66
|
+
"types": "./vcjwt-entry.d.ts",
|
|
67
|
+
"default": "./vcjwt-entry.js"
|
|
68
|
+
},
|
|
36
69
|
"./lib/anchor": "./lib/anchor/index.js",
|
|
37
70
|
"./lib/block": "./lib/block/index.js",
|
|
38
71
|
"./lib/covenant": "./lib/covenant/index.js",
|
|
@@ -102,12 +135,13 @@
|
|
|
102
135
|
"test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
|
|
103
136
|
"test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
|
|
104
137
|
"preimage:extract": "node examples/preimage/extract_preimage_bidirectional.js",
|
|
105
|
-
"prepublishOnly": "npm run build-all && npm run check:readme && npm run check:api",
|
|
138
|
+
"prepublishOnly": "npm run build-all && npm run check:readme && npm run check:api && npm run check:types",
|
|
106
139
|
"sync-cdn": "node scripts/sync-cdn-urls.js",
|
|
107
140
|
"version": "node scripts/sync-cdn-urls.js && node scripts/sync-version.js && node scripts/gen-esm-wrapper.js && git add README.md docs version.js index.mjs",
|
|
108
141
|
"test:browser:ci": "node tests/browser-smoke-runner.js",
|
|
109
142
|
"api:snapshot": "node scripts/api-surface.js",
|
|
110
|
-
"check:api": "mocha test/api_surface.js --no-config"
|
|
143
|
+
"check:api": "mocha test/api_surface.js --no-config",
|
|
144
|
+
"check:types": "node scripts/check-types.js"
|
|
111
145
|
},
|
|
112
146
|
"unpkg": "bsv.min.js",
|
|
113
147
|
"jsdelivr": "bsv.min.js",
|
|
@@ -178,6 +212,7 @@
|
|
|
178
212
|
"@noble/ciphers": "^2.3.0",
|
|
179
213
|
"@noble/curves": "^2.3.0",
|
|
180
214
|
"@noble/hashes": "^2.3.0",
|
|
215
|
+
"@types/node": "^20.19.0",
|
|
181
216
|
"bn.js": "=4.12.5",
|
|
182
217
|
"secrets.js-grempe": "^2.0.0"
|
|
183
218
|
},
|