@smartledger/bsv 9.2.0 → 9.3.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.
@@ -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.2.0/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.2.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.2.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.2.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.2.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.2.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.2.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.2.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.2.0/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.3.0/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.3.0/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.3.0/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.3.0/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.3.0/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.3.0/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.3.0/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.3.0/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.3.0/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.3.0/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.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.2.0/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@9.3.0/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -0,0 +1,7 @@
1
+ /**
2
+ * GDAF — governed data anchoring.
3
+ *
4
+ * Same class as `require("@smartledger/bsv").GDAF`.
5
+ */
6
+ import { GDAF } from '@smartledger/bsv';
7
+ export = GDAF;
@@ -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)
package/ltp-entry.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Legal Token Protocol — rights, claims, obligations, and their registry.
3
+ *
4
+ * Same class as `require("@smartledger/bsv").LTP`, including its statics.
5
+ */
6
+ import { LTP } from '@smartledger/bsv';
7
+ export = LTP;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "9.2.0",
3
+ "version": "9.3.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": "./anchor-entry.js",
22
- "./covenant": "./covenant-entry.js",
23
- "./didweb": "./didweb-entry.js",
24
- "./gdaf": "./gdaf-entry.js",
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": "./ltp-entry.js",
30
- "./script-helper": "./script-helper-entry.js",
31
- "./security": "./security-entry.js",
32
- "./shamir": "./shamir-entry.js",
33
- "./smartcontract": "./smartcontract-entry.js",
34
- "./statuslist": "./statuslist-entry.js",
35
- "./vcjwt": "./vcjwt-entry.js",
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",
@@ -85,7 +118,7 @@
85
118
  "test:all": "npm test && npm run test:covenants && npm run test:scripts",
86
119
  "coverage": "nyc --reporter=text npm run test",
87
120
  "demo": "node demos/smart_contract_demo.js",
88
- "demo:web": "echo '🌐 Open demos/smart_contract_demo.html in your browser'",
121
+ "demo:web": "echo '\ud83c\udf10 Open demos/smart_contract_demo.html in your browser'",
89
122
  "demo:basics": "node demos/smart_contract_demo.js --feature basics",
90
123
  "demo:covenant": "node demos/smart_contract_demo.js --feature covenant",
91
124
  "demo:preimage": "node demos/smart_contract_demo.js --feature preimage",
@@ -94,7 +127,7 @@
94
127
  "demo:legacy": "npm run test:covenants",
95
128
  "demo:legacy:basic": "npm run test:basic",
96
129
  "demo:legacy:scripts": "npm run test:scripts",
97
- "demo:legacy:preimage": "echo '🧠 BIP-143 Preimage Extractor Demo' && node examples/preimage/extract_preimage_bidirectional.js",
130
+ "demo:legacy:preimage": "echo '\ud83e\udde0 BIP-143 Preimage Extractor Demo' && node examples/preimage/extract_preimage_bidirectional.js",
98
131
  "smart-contracts": "node examples/smart_contract_templates.js",
99
132
  "smart-contracts:working": "node examples/final_working_contracts.js",
100
133
  "workflow": "node examples/complete_workflow_demo.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
  },
@@ -0,0 +1,75 @@
1
+ /**
2
+ * CustomScriptHelper — script construction and signing helpers.
3
+ *
4
+ * All members are static; the class is never instantiated. Signatures follow
5
+ * the JSDoc in `lib/custom-script-helper.js`.
6
+ */
7
+ import { Transaction, Script, PrivateKey, PublicKey } from '@smartledger/bsv';
8
+
9
+ declare class CustomScriptHelper {
10
+ /** SIGHASH_ALL | SIGHASH_FORKID. */
11
+ static readonly SIGHASH_ALL: number;
12
+ /** SIGHASH_NONE | SIGHASH_FORKID. */
13
+ static readonly SIGHASH_NONE: number;
14
+ /** SIGHASH_SINGLE | SIGHASH_FORKID. */
15
+ static readonly SIGHASH_SINGLE: number;
16
+
17
+ /**
18
+ * DER signature with the sighash byte appended, ready to push.
19
+ * Defaults to SIGHASH_ALL | SIGHASH_FORKID.
20
+ */
21
+ static createSignature(
22
+ transaction: Transaction,
23
+ privateKey: PrivateKey,
24
+ inputIndex: number,
25
+ lockingScript: Script,
26
+ satoshis: number,
27
+ sighashType?: number | null
28
+ ): Buffer;
29
+
30
+ /** m-of-n locking script over the supplied keys. */
31
+ static createMultisigScript(m: number, publicKeys: PublicKey[]): Script;
32
+ /** Unlocking script for a multisig input; prepends OP_0 for the CHECKMULTISIG off-by-one. */
33
+ static createMultisigUnlocking(signatures: Buffer[]): Script;
34
+ /** OP_IF / [OP_ELSE] / OP_ENDIF around the supplied branches. */
35
+ static createConditionalScript(ifScript: Script, elseScript?: Script | null): Script;
36
+
37
+ static createP2PKHScript(publicKey: PublicKey): Script;
38
+ static createP2PKHUnlocking(signature: Buffer, publicKey: PublicKey): Script;
39
+
40
+ /**
41
+ * BIP-143 preimage for the given input.
42
+ * Defaults to SIGHASH_ALL | SIGHASH_FORKID.
43
+ */
44
+ static getPreimage(
45
+ transaction: Transaction,
46
+ inputIndex: number,
47
+ lockingScript: Script,
48
+ satoshis: number,
49
+ sighashType?: number | null
50
+ ): Buffer;
51
+
52
+ /** A bare data push. A string is encoded as UTF-8. */
53
+ static createDataScript(data: Buffer | string): Script;
54
+ /** OP_FALSE OP_RETURN <data>. A string is encoded as UTF-8. */
55
+ static createOpReturnScript(data: Buffer | string): Script;
56
+
57
+ /** Returns false rather than throwing when verification fails. */
58
+ static validateTransaction(transaction: Transaction): boolean;
59
+ /** Runs the interpreter over one input. Returns false rather than throwing. */
60
+ static validateScript(
61
+ unlockingScript: Script,
62
+ lockingScript: Script,
63
+ transaction: Transaction,
64
+ inputIndex: number
65
+ ): boolean;
66
+
67
+ /** Builds a transaction at the given fee rate. Defaults to 10 sat/kb. */
68
+ static createLowFeeTransaction(
69
+ utxos: object[],
70
+ outputs: Array<{ address: string; satoshis: number }>,
71
+ feePerKb?: number
72
+ ): Transaction;
73
+ }
74
+
75
+ export = CustomScriptHelper;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * SmartMiner — an in-process BSV miner simulator for tests and development.
3
+ *
4
+ * This simulates mempool acceptance and block assembly; it is not a miner and
5
+ * performs no proof of work.
6
+ */
7
+ import { Transaction } from '@smartledger/bsv';
8
+
9
+ declare class SmartMiner {
10
+ constructor(bsv: unknown, options?: {
11
+ difficulty?: number;
12
+ /** Milliseconds. Defaults to 10000. */
13
+ blockTime?: number;
14
+ /** Defaults to true. */
15
+ validateScripts?: boolean;
16
+ logLevel?: string;
17
+ [key: string]: unknown;
18
+ });
19
+
20
+ options: Record<string, unknown>;
21
+ mempool: Transaction[];
22
+ currentBlock: { height: number; transactions: Transaction[]; timestamp: number; hash?: string };
23
+
24
+ /** Accepts into the mempool, or returns false if rejected. */
25
+ acceptTransaction(transaction: Transaction): boolean;
26
+ validateTransactionSignatures(transaction: Transaction): boolean;
27
+ /** Assembles a block from the mempool. Defaults to 10 transactions. */
28
+ mineBlock(maxTransactions?: number): {
29
+ height: number;
30
+ transactions: Transaction[];
31
+ timestamp: number;
32
+ hash?: string;
33
+ [key: string]: unknown;
34
+ };
35
+ getMempoolStats(): {
36
+ transactionCount: number;
37
+ transactions: Array<{ id: string; size: number; inputs: number; outputs: number }>;
38
+ };
39
+ getBlockchainStats(): {
40
+ currentHeight: number;
41
+ currentBlockHash: string | undefined;
42
+ currentBlockTimestamp: number;
43
+ mempoolSize: number;
44
+ difficulty: number;
45
+ blockTime: number;
46
+ };
47
+ /** Returns the miner to genesis state and empties the mempool. */
48
+ reset(): void;
49
+ log(level: string, message: string): void;
50
+ }
51
+
52
+ export = SmartMiner;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shamir secret sharing.
3
+ *
4
+ * Same class as `require("@smartledger/bsv").crypto.Shamir`. The underscore-
5
+ * prefixed `_*Legacy` helpers present at runtime are deliberately not declared:
6
+ * they exist to reconstruct shares produced by pre-6.x releases and are not
7
+ * part of the supported surface.
8
+ */
9
+ import { crypto } from '@smartledger/bsv';
10
+ export = crypto.Shamir;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Script-level contract construction: OP_PUSH_TX covenants, BIP-143 preimage
3
+ * tooling, the interpreter-backed tester, and the template library.
4
+ *
5
+ * Same surface as `require("@smartledger/bsv").SmartContract`.
6
+ */
7
+ import { SmartContract } from '@smartledger/bsv';
8
+ export = SmartContract;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * StatusList2021 revocation lists.
3
+ *
4
+ * Note `getCredentialStatusEntry` is async — awaiting it is not optional.
5
+ * Comparing the returned Promise to a string type-checks and is always false,
6
+ * which is how a revoked credential passes.
7
+ *
8
+ * Same surface as `require("@smartledger/bsv").StatusList`.
9
+ */
10
+ import { StatusList } from '@smartledger/bsv';
11
+ export = StatusList;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * W3C Verifiable Credentials as JWTs.
3
+ *
4
+ * Same surface as `require("@smartledger/bsv").VcJwt`, plus `ALG_TO_CRV`, which
5
+ * the module exports at runtime but the root declaration does not describe.
6
+ */
7
+ import { VcJwt } from '@smartledger/bsv';
8
+
9
+ declare namespace vcjwt {
10
+ /** Maps a JWS algorithm to the JWK curve it requires. */
11
+ const ALG_TO_CRV: Readonly<Record<string, string>>;
12
+ }
13
+ declare const vcjwt: typeof VcJwt & { readonly ALG_TO_CRV: Readonly<Record<string, string>> };
14
+
15
+ export = vcjwt;
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict'
2
2
  // GENERATED by scripts/sync-version.js on `npm version` — do not edit.
3
- module.exports = '9.2.0'
3
+ module.exports = '9.3.0'