@smartledger/bsv 9.7.0 → 9.9.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.
@@ -34,14 +34,14 @@ module sounds. That is a deliberate revision: an earlier version of this documen
34
34
  scoped Tier 1 as "the cryptographic core" and would have excluded four of the six real
35
35
  defects this codebase has produced. See §2.1.
36
36
 
37
- ### Tier 1 — 11,247 lines
37
+ ### Tier 1 — 11,962 lines
38
38
 
39
39
  | Module | Lines | Why it matters |
40
40
  | --- | ---: | --- |
41
41
  | `lib/transaction/` | 2,779 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
42
- | `lib/script/interpreter.js` | 2,684 | **Scoped to the flag and era surface, not opcode execution.** Consensus-flag selection and defaults, era derivation (Genesis/Chronicle), the limits derived from them, and the semantics of the exported `verify()`. Opcode execution is excluded — see §2.2. |
42
+ | `lib/script/interpreter.js` | 2,821 | **Scoped to the flag and era surface, not opcode execution.** Consensus-flag selection and defaults, era derivation (Genesis/Chronicle), the limits derived from them, and the semantics of the exported `verify()`. Opcode execution is excluded — see §2.2. |
43
43
  | `lib/crypto/` | 2,519 | ECDSA, nonce derivation, signature encoding, the script-number type. **Scope this for an architectural judgement as well as for bugs** — see §2.3. |
44
- | `lib/notaryhash/` | 1,436 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
44
+ | `lib/notaryhash/` | 2,014 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
45
45
  | `lib/privatekey.js`, `lib/publickey.js` | 843 | Key construction, serialisation, WIF. Recent defects here produced a *different* key without error. |
46
46
  | `lib/smart_contract/` (targeted) | 472 | `locks.js` and the covenant-facing entrypoints in `index.js`: CLTV and HTLC locking semantics, flag plumbing, and any wrapper claiming mainnet-equivalent verification. Not the whole 6,908-line module. |
47
47
  | `lib/covenant/` | 409 | The verification harness. Its flag word is what made covenants verify under 2019 rules while claiming to mirror mainnet. |
@@ -61,8 +61,10 @@ is not.
61
61
 
62
62
  ### 2.1 Why the boundary moved
63
63
 
64
- Six defects have been found in this codebase and fixed. Four of them were in code the
65
- previous version of this scope **excluded**:
64
+ **Ten** defects have been found in this codebase and fixed. Four were in code the
65
+ previous version of this scope excluded; the four most recent all landed on the
66
+ interpreter's era and flag surface, which is why that surface is scoped and opcode
67
+ execution is not.
66
68
 
67
69
  | Defect | Module | Was it in the old scope? |
68
70
  | --- | --- | --- |
@@ -72,11 +74,24 @@ previous version of this scope **excluded**:
72
74
  | The reachable RFC 8785 canonicalizer was non-conformant while a correct one sat private; three downstream packages copied the wrong one | `lib/util/jcs.js`, `lib/ltp` | partly |
73
75
  | `ECDSA.verify()` returned the instance, so `if (verify())` was always truthy — a fail-open accepting forged signatures | `lib/crypto` | yes |
74
76
  | ECDSA nonce reuse across two signings on one instance, leaking the private key | `lib/crypto` | yes |
77
+ | `OP_BIN2NUM` capped every era at the pre-Genesis 4-byte script number, so covenants holding 21.47 BSV or more were unspendable and every `nLockTime` from 2038 was rejected | `lib/script/interpreter.js` | yes (9.4.0) |
78
+ | `policy().lockUntil()` enforced one of `CheckLockTime`'s three rules: a final `nSequence` voided the lock, and a past timestamp cleared a future height floor | `lib/smart_contract` | yes (9.4.0) |
79
+ | `SIGPUSHONLY`, `LOW_S` and `NULLFAIL` are consensus on BSV and were missing from the default flag word, so `verify()` accepted scripts the network judges invalid | `lib/script/interpreter.js` | yes (9.5.0) |
80
+ | The `CHECKMULTISIG` op count read the static cap, refusing a post-Genesis multisig the line above had just permitted | `lib/script/interpreter.js` | yes (9.6.0) |
81
+ | The stack cap was checked once at the end of the script rather than after every opcode, and was still applied after Genesis removed it | `lib/script/interpreter.js` | yes (9.7.0) |
75
82
 
76
83
  The pattern is not "the primitives are weak". It is that **code making claims about
77
84
  consensus behaviour was wrong about it**, and the tests agreed because they shared the
78
85
  same assumption. Scope has been moved onto that surface.
79
86
 
87
+ **The four most recent are the sharpest evidence in this document**, because in every
88
+ one the reference corpus passed 1,483/1,483 before the fix and 1,483/1,483 after it,
89
+ with zero false accepts either way. A node vector states its own flags, so no vector
90
+ can say which flags or which era belong in a *default*. Every `OP_BIN2NUM` vector, every
91
+ `SIGPUSHONLY` vector and every `OP_COUNT` vector in that corpus runs pre-Genesis; both
92
+ `STACK_SIZE` vectors end over the cap, which is the one case an end-of-script check does
93
+ see. The mechanism was covered in each case. The selection was not.
94
+
80
95
  ### 2.2 Why `lib/script` shrinks rather than leaves
81
96
 
82
97
  `lib/script` has the strongest external evidence in the repository: 1,483/1,483 of the
@@ -84,10 +99,13 @@ reference node's own consensus vectors, zero false accepts and zero false reject
84
99
  is evidence about **opcode execution**, and re-auditing it by hand is the least
85
100
  productive money in this engagement.
86
101
 
87
- It is not evidence about which flags a caller ends up with. Both consensus defects above
88
- were flag-selection and era-derivation failures reachable through `interpreter.js`, and
89
- no vector covers them because every vector states its own flags. So the interpreter stays
90
- in scope, scoped to that surface, and the remaining 1,175 lines of `lib/script` leave.
102
+ It is not evidence about which flags a caller ends up with. **Seven** of the ten defects
103
+ above were flag-selection or era-derivation failures reachable through `interpreter.js`,
104
+ and no vector covers them because every vector states its own flags. Five of those seven
105
+ were found *after* this boundary was drawn, which is the strongest confirmation of it
106
+ available: the surface predicted to be defect-bearing produced five more, while opcode
107
+ execution produced none. So the interpreter stays in scope, scoped to that surface, and
108
+ the remaining 1,175 lines of `lib/script` leave.
91
109
 
92
110
  ### 2.3 A specific instruction for `lib/crypto`
93
111
 
@@ -115,6 +133,14 @@ the tests were written from the same assumption. A file-by-file review finds non
115
133
  them. Checking a claim against something outside this repository finds all of them —
116
134
  which is exactly how each was eventually caught.
117
135
 
136
+ Two of the ten make the point without needing to be taken on trust. `SIGPUSHONLY` was
137
+ settled by broadcasting to mainnet a transaction that violated it and nothing else, and
138
+ reading the node's reject code: 16 `mandatory-script-verify-flag-failed`, against 64
139
+ `non-mandatory` for `MINIMALDATA` in the same run. And the `lockUntil` defect was found
140
+ by comparing the compiled script against the node's `CheckLockTime`, rule by rule,
141
+ rather than against what the library's own tests expected. Neither answer exists inside
142
+ this repository.
143
+
118
144
  ## 3. Out of scope, and why
119
145
 
120
146
  | Component | Status | Reason |
@@ -124,14 +150,14 @@ which is exactly how each was eventually caught.
124
150
  | `lib/address.js`, `lib/networks.js`, `lib/opcode.js`, `lib/hdprivatekey.js`, `lib/hdpublickey.js` (2,391 lines) | Cut to pay for §2.1 | Formatting, network constants and BIP-32 derivation. No defect has originated here, and `networks.js` in particular defines addressing constants — pubkey hashes, xpub prefixes, ports, DNS seeds — and contains **no consensus-flag logic at all**. |
125
151
  | The rest of the application layer — `lib/gdaf/`, `lib/ltp/`, `lib/ordinals/`, `lib/block/`, `lib/didweb/`, `lib/vcjwt/`, `lib/statuslist/`, most of `lib/smart_contract/`, plus assorted top-level files | Excluded | ~26,000 lines. Worth a separate engagement; including it here would blur the question in §1. Note the parts of it with a demonstrated defect history have been pulled *into* Tier 1 rather than left here — see §2.1. |
126
152
 
127
- Totals reconcile against `lib/`, which is 38,879 lines across 131 files:
153
+ Totals reconcile against `lib/`, which is 39,646 lines across 131 files:
128
154
 
129
155
  ```
130
- tier 1 11,247
156
+ tier 1 11,962
131
157
  tier 2 1,607
132
- excluded 26,025
158
+ excluded 26,077
133
159
  ------
134
- total 38,879
160
+ total 39,646
135
161
  ```
136
162
 
137
163
  Measured 2026-08-29 at `a954c27`. These figures drift as the library changes — an
@@ -202,7 +228,7 @@ seeking a quote for an independent security review.
202
228
 
203
229
  Scope, and we would like these priced separately:
204
230
 
205
- Tier 1 — 11,247 lines. Sighash construction and signing; ECDSA, nonce
231
+ Tier 1 — 11,962 lines. Sighash construction and signing; ECDSA, nonce
206
232
  derivation and signature encoding; the consensus-flag and era-derivation
207
233
  surface of the script interpreter; BRC-220 signing and verification;
208
234
  key construction and serialisation; the covenant verification harness and
@@ -3,8 +3,16 @@
3
3
  §On-chain record specifies *which* Merkle tree batch mode uses, but never says what goes
4
4
  in a leaf. This proposes the definition, with the reasoning that led to it.
5
5
 
6
- Prepared 2026-08-17 while implementing BRC-220 in `@smartledger/bsv`. The second gap of
7
- this kind, after `encoding` — see [BRC220_ENCODING_AMENDMENT.md](BRC220_ENCODING_AMENDMENT.md).
6
+ Prepared 2026-08-17 while implementing BRC-220 in `@smartledger/bsv`.
7
+
8
+ **Status: filed** as [bsv-blockchain/BRCs#246](https://github.com/bsv-blockchain/BRCs/pull/246)
9
+ on 2026-09-11, together with a clarification of the ECDSA digest convention. Before filing
10
+ it was checked against the BRC-220 reference implementation, whose batcher uses exactly
11
+ this leaf (`leaves = batch.map(e => e.proofHash)`), and the vector below was rebuilt
12
+ without any of this library's code — the root from the reference's own RFC 6962 tree.
13
+
14
+ A companion draft on the `encoding` field was **wrong and has been withdrawn**; see
15
+ [BRC220_ENCODING_AMENDMENT.md](BRC220_ENCODING_AMENDMENT.md).
8
16
 
9
17
  ---
10
18
 
@@ -104,9 +112,10 @@ states it in `lib/notaryhash/index.js` and enforces it in
104
112
  `test/notaryhash/batch_leaf.js` — including a test that a tree built over `canonicalBytes`
105
113
  is rejected, so the choice is checked rather than merely intended.
106
114
 
107
- No deployed batch certificates are known to use the other reading. If any exist, they were
108
- built against an ambiguous sentence and would need reissuing; batch mode is the least-used
109
- of the three and this is the moment to fix it, before that stops being true.
115
+ The reference implementation uses the same reading, so certificates its service has
116
+ issued in batch mode already conform. An implementation that chose `d = canonicalBytes`
117
+ built against an ambiguous sentence and would need to reissue; the second root published
118
+ below makes that diagnosable in one line.
110
119
 
111
120
  ---
112
121
 
@@ -129,7 +138,8 @@ regenerates byte-identically and any implementation can rebuild it from scratch:
129
138
  - private key `i` = `SHA-256("BRC-220/batch-vector/key/" + i)`
130
139
  - `payloadHash` `i` = `SHA-256("BRC-220/batch-vector/payload/" + i)`
131
140
  - `createdAt` `i` = `2026-01-0(i+1)T00:00:00.000Z`
132
- - `algorithm` = `ECDSA-secp256k1`, `hashAlgorithm` = `SHA-256`, `encoding` = `"raw"`
141
+ - `algorithm` = `ECDSA-secp256k1`, `hashAlgorithm` = `SHA-256`, a 64-byte `r ‖ s`
142
+ signature normalised to low-S, and a 33-byte compressed public key
133
143
 
134
144
  **Signing.** The signer signs the 32-byte `payloadHash` directly — the digest *is* the
135
145
  scalar, big-endian. RFC 6979 makes the nonce deterministic, so the signatures, and every
@@ -1,100 +1,39 @@
1
- # Proposed BRC-220 amendment: define the `encoding` field
1
+ # Withdrawn: proposed BRC-220 `encoding` amendment
2
2
 
3
- `encoding` is listed among the certificate's required fields, but its values are never
4
- enumerated. This proposes the definition, with the reasoning that led to it.
3
+ **This proposal was wrong and has been withdrawn. It was never filed.**
5
4
 
6
- Prepared 2026-08-16 while implementing BRC-220 in `@smartledger/bsv`. The gap surfaced
7
- because an implementation cannot emit a required field whose values are undefined.
5
+ It proposed defining the certificate's `encoding` field as `"raw"` or `"der"` — the
6
+ signature's byte format — and requiring ECDSA signatures to be low-S, with a 33-byte
7
+ compressed public key. It was written from this library's implementation alone.
8
8
 
9
- ---
9
+ Checked against the BRC-220 reference implementation before filing, it contradicted
10
+ it on every point:
10
11
 
11
- ## Proposed text
12
+ | | this proposal | reference implementation |
13
+ | --- | --- | --- |
14
+ | `encoding` means | the signature's byte format | how `publicKey` and `signature` are written into the JSON |
15
+ | `encoding` values | `"raw"`, `"der"` | `"hex"`, `"base64"` |
16
+ | signature bytes | 64-byte `r ‖ s` only, DER discouraged | 64-byte `r ‖ s` or DER, told apart by the bytes |
17
+ | high-S signatures | rejected | accepted, deliberately |
18
+ | public keys | 33-byte compressed | 33-byte compressed or 65-byte uncompressed |
12
19
 
13
- Insert into **§Certificate**, after the sentence listing the required fields.
20
+ Every certificate the reference service has issued uses `"hex"` or `"base64"`. Filing
21
+ this would have proposed a spec change incompatible with all of them.
14
22
 
15
- > #### `encoding`
16
- >
17
- > `encoding` names the byte representation of `publicKey` and `signature` as they appear
18
- > in the certificate and in the canonical proof bytes.
19
- >
20
- > Implementations **MUST** support `"raw"` and **SHOULD** emit it:
21
- >
22
- > - **`"raw"`** — the scheme's native fixed-length byte string.
23
- > - For `ECDSA-secp256k1`, a signature is exactly **64 bytes**: `r ‖ s`, each a 32-byte
24
- > big-endian unsigned integer, zero-padded on the left. A public key is the 33-byte
25
- > compressed SEC1 form.
26
- > - For `ML-DSA-*` and `SLH-DSA-*`, the signature and public key are the byte strings the
27
- > scheme itself defines (FIPS 204, FIPS 205). No further framing is applied.
28
- > - **`"der"`** — ECDSA signatures in ASN.1 DER, as produced by Bitcoin tooling.
29
- > Accepted for compatibility with existing Bitcoin-native signers; **SHOULD NOT** be
30
- > emitted by new implementations, for the reason given below. Undefined for post-quantum
31
- > algorithms, which have no DER form.
32
- >
33
- > For `ECDSA-secp256k1`, `s` **MUST** be in the lower half of the curve order
34
- > (`s ≤ n/2`). A signature with a high `s` **MUST** be rejected rather than normalised on
35
- > receipt: normalising changes the signature bytes, and the signature bytes are inside
36
- > `proofHash`.
23
+ It also exposed that `@smartledger/bsv` 8.3.0–9.8.0 could not verify a single
24
+ certificate the reference issued: its `version`, `mode`, `encoding`, `anchor` and batch
25
+ `path` fields all differed. The library now reads both formats, and
26
+ writes the reference one given `format: 'reference'` — the default from 10.0.0. See
27
+ `lib/notaryhash/certificate.js`.
37
28
 
38
- ---
29
+ ## What is still true
39
30
 
40
- ## Why `"raw"` rather than DER
31
+ The gap this draft set out to close is real: BRC-220 lists `encoding` as a required field
32
+ and never enumerates its values, and says nothing about the JSON form of `version`,
33
+ `mode`, `anchor` or the batch `path`. A clarification defining those fields **as the
34
+ reference writes them** is a separate, later proposal.
41
35
 
42
- ### 1. DER is not canonical, and `proofHash` covers the signature bytes
43
-
44
- The canonical proof bytes include `lp(signature)`, so the signature's exact byte
45
- representation determines `proofHash`. DER does not have one representation per signature.
46
- Measured over 200 signatures from a single key with `@smartledger/bsv`:
47
-
48
- ```
49
- DER lengths: { "69": 1, "70": 108, "71": 91 }
50
- raw lengths: { "64": 200 }
51
- ```
52
-
53
- The variance is ordinary leading-zero handling in the two INTEGERs, and it is entirely
54
- legal DER. But it means the same signing act can yield different `proofHash` values
55
- depending on which library encoded it — and a certificate re-encoded in transit no longer
56
- matches its own integrity root.
57
-
58
- That is the property §Motivation names first: *"any implementation in any language
59
- reproduces identical bytes"*, and the reason the spec already rejects `JSON.stringify`.
60
- A non-canonical signature encoding reintroduces exactly the problem the binary encoding was
61
- chosen to avoid.
62
-
63
- ### 2. Every other algorithm in the spec is already raw
64
-
65
- ML-DSA-65 signatures are 3,309 bytes; SLH-DSA-SHA2-128s are 7,856. Both are fixed-length
66
- byte strings with no DER form. With ECDSA on DER and the post-quantum schemes on raw,
67
- every verifier needs per-algorithm branching on `encoding`. With ECDSA on raw, all sixteen
68
- algorithm identifiers share one representation and the branch disappears.
69
-
70
- ### 3. It matches what the signature actually is
71
-
72
- §Algorithms specifies that the signer signs the 32-byte `payloadHash` **directly**. This is
73
- a detached signature over a digest, not a Bitcoin script signature — the case ES256K
74
- (RFC 7515) and WebCrypto both address, and both use `r ‖ s`, not DER.
75
-
76
- ### 4. Low-S is a separate malleability, and raw does not fix it
77
-
78
- For any ECDSA signature, `s` and `n − s` both verify. They are different bytes, so they
79
- produce different `proofHash` values. Without a normative rule, two valid certificates
80
- exist for one signing act — an ambiguity a notarization protocol should not carry.
81
-
82
- Requiring low-S at signing, and **rejecting** rather than normalising on receipt, keeps
83
- `proofHash` a function of the certificate as issued.
84
-
85
- ---
86
-
87
- ## Note on `toCompact`
88
-
89
- Some Bitcoin libraries expose a 65-byte "compact" signature. That is not this format: it
90
- carries a leading recovery byte for public-key recovery. `"raw"` is the bare 64 bytes,
91
- with no recovery byte, because the public key is already a certificate field.
92
-
93
- ---
94
-
95
- ## Impact on existing certificates
96
-
97
- None, if no certificate has yet been issued with `encoding: "der"`. If any have, they
98
- remain valid — `"der"` stays an accepted value, and the SPV envelope and `proofHash`
99
- semantics are untouched. This amendment defines a field that was previously unspecified;
100
- it does not change any field that was.
36
+ The batch-leaf clarification written alongside this one was correct, and was confirmed
37
+ against the reference implementation: it was filed as
38
+ [bsv-blockchain/BRCs#246](https://github.com/bsv-blockchain/BRCs/pull/246). See
39
+ [BRC220_BATCH_LEAF_AMENDMENT.md](BRC220_BATCH_LEAF_AMENDMENT.md).
@@ -173,45 +173,44 @@ summarising rather than anything in the document.
173
173
  - **The service is a role, not a requirement.** §What a certificate proves: "any party
174
174
  holding a valid (hash, signature, publicKey) triple may re-anchor it; the attestation
175
175
  remains valid". A self-notarizing caller producing its own certificate is conformant.
176
- - **The batch Merkle leaf is NOT settled by the spec — it is a choice this
177
- implementation made.** §On-chain record writes `leaf = SHA256(0x00 ‖ d)`, but that is
178
- RFC 6962's own generic notation for the construction and `d` is never bound to a value.
179
- `canonicalBytes` appears once in the whole document, in the `proofHash` definition, and
180
- nowhere in the batch text. We read `d` as `proofHash`; reading it as `canonicalBytes` is
181
- equally sound and produces a different root, so the two do not interoperate. Recorded as
182
- an ambiguity rather than a settled question, with proposed spec text in
183
- [BRC220_BATCH_LEAF_AMENDMENT.md](BRC220_BATCH_LEAF_AMENDMENT.md) and enforcement in
184
- `test/notaryhash/batch_leaf.js`. This is the second gap of the kind, after `encoding`.
176
+ - **The batch Merkle leaf is NOT settled by the spec.** §On-chain record writes
177
+ `leaf = SHA256(0x00 ‖ d)`, but that is RFC 6962's own generic notation for the
178
+ construction and `d` is never bound to a value. `canonicalBytes` appears once in the whole
179
+ document, in the `proofHash` definition, and nowhere in the batch text. We read `d` as
180
+ `proofHash`; so does the reference implementation's batcher, and given the same five
181
+ proofs it builds the same root. Reading it as `canonicalBytes` is equally sound and
182
+ produces a different root, so the two do not interoperate. Filed upstream as
183
+ [bsv-blockchain/BRCs#246](https://github.com/bsv-blockchain/BRCs/pull/246); see
184
+ [BRC220_BATCH_LEAF_AMENDMENT.md](BRC220_BATCH_LEAF_AMENDMENT.md), enforced in
185
+ `test/notaryhash/batch_leaf.js`.
185
186
  - **`createdAt` is advisory for trust but load-bearing for the hash.** §Verification calls
186
187
  it "an advisory client field only" — meaning proof-of-existence time comes from the
187
188
  block, not from this field. It is still inside the canonical bytes as `createdAtUnix`,
188
189
  so it cannot be altered after issuance.
189
190
 
190
- Decided, and proposed back to the spec:
191
+ Decided here, then reversed against the reference implementation:
191
192
 
192
- - **`encoding` is `"raw"`.** The field is required by the spec but its values were never
193
- enumerated, so this library defines them and proposes the definition upstream — see
194
- `docs/BRC220_ENCODING_AMENDMENT.md`.
193
+ - **`encoding` was defined as `"raw"` — the signature's byte format — and low-S was
194
+ required.** Both were wrong. The spec requires the field without enumerating its values,
195
+ and 8.3.0–9.8.0 filled that gap from this library's own reasoning: raw `r ‖ s` because DER
196
+ is not canonical, low-S because `s` and `n − s` both verify and hash differently.
195
197
 
196
- For `ECDSA-secp256k1` that is 64 bytes, `r ‖ s`, each a 32-byte big-endian integer, with
197
- a 33-byte compressed public key. NOT DER, and not the 65-byte `toCompact` form, which
198
- carries a recovery byte the certificate does not need because it already has the key.
198
+ The reference implementation, which is what issued certificates are checked against,
199
+ decided otherwise on every point. `encoding` is `"hex"` or `"base64"` — how `publicKey`
200
+ and `signature` are written into the JSON, not what their bytes are. A signature may be
201
+ 64-byte `r ‖ s` or DER, told apart by the bytes. A public key may be compressed or
202
+ uncompressed. High-S is accepted deliberately.
199
203
 
200
- The deciding argument is that `proofHash` covers `lp(signature)`, and **DER is not
201
- canonical**. Measured over 200 signatures from one key: DER came out at 69, 70 and 71
202
- bytes depending on leading-zero handling, all of it legal. Raw was 64 bytes every time.
203
- The same signing act producing different `proofHash` values is precisely the failure the
204
- binary encoding exists to prevent — it is why the spec already refuses `JSON.stringify`.
204
+ The reasoning behind the reversal holds: `proofHash` covers the signature bytes exactly
205
+ as the signer produced them, so a DER or malleated form is a *different* certificate,
206
+ not a forgery of this one. What the original argument protected against — two
207
+ certificates for one signing act — is real, but it is the issuer's choice to make, and
208
+ every certificate still commits to exactly one form.
205
209
 
206
- Two supporting reasons: ML-DSA and SLH-DSA have no DER form, so raw makes `encoding`
207
- uniform across all sixteen algorithm identifiers instead of forcing per-algorithm
208
- branching in every verifier; and the signature is detached over a digest rather than a
209
- Bitcoin script signature, which is the ES256K/WebCrypto case, and both use `r ‖ s`.
210
-
211
- **Low-S is required and must be rejected, not normalised.** `s` and `n − s` both verify
212
- and hash differently, so without the rule two valid certificates exist for one signing
213
- act. Normalising on receipt would change the signature bytes, which are inside
214
- `proofHash`. This library already emits low-S and has `Signature.toCanonical()`.
210
+ The library now reads both formats and writes the reference one given
211
+ `format: 'reference'`. Per STABILITY.md the default stays the old format through 9.x,
212
+ with a one-time notice, and becomes 'reference' in 10.0.0. The proposed amendment
213
+ (`docs/BRC220_ENCODING_AMENDMENT.md`) was withdrawn before filing.
215
214
 
216
215
  ### The reference implementation
217
216
 
@@ -220,10 +219,16 @@ Decided, and proposed back to the spec:
220
219
  `txidFromRawTx` against the Bitcoin genesis coinbase, and the Merkle fold against the real
221
220
  block-170 two-transaction proof.
222
221
 
223
- Those vectors are worth more than anything in §6, and should be wired in as gates before
224
- Phase 2 goes far. This module's characteristic failure is being self-consistent and wrong
225
- — every local test green, no other implementation agreeing — and a golden vector from a
226
- second implementation is the only thing that actually rules it out. Our own tests cannot.
222
+ Those vectors are worth more than anything in §6. This module's characteristic failure is
223
+ being self-consistent and wrong — every local test green, no other implementation agreeing
224
+ — and a golden vector from a second implementation is the only thing that actually rules
225
+ it out. Our own tests cannot.
226
+
227
+ That is exactly how it went. Until the reference was checked, every test here passed and
228
+ this library could not verify one certificate the reference had issued: the cryptography
229
+ agreed and the JSON did not. `test/notaryhash/reference_certs.js` now verifies certificates
230
+ the reference produced — full and hybrid, hex and base64, DER, high-S, an uncompressed key,
231
+ and a five-leaf batch — and rebuilds each one byte for byte.
227
232
 
228
233
  ## 8. Not in scope
229
234
 
@@ -55,19 +55,19 @@ Three advanced modules totaling **~2.7MB** of functionality:
55
55
  - **Purpose**: Threshold cryptography for secure secret distribution
56
56
  - **Use Cases**: Backup keys, multi-party security, key recovery
57
57
  - **Features**: Split secrets into N shares, require M to reconstruct
58
- - **CDN**: `unpkg.com/@smartledger/bsv@9.7.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.9.0/bsv-shamir.min.js`
59
59
 
60
60
  #### **🌐 Global Digital Attestation Framework - GDAF (1184KB)**
61
61
  - **Purpose**: W3C Verifiable Credentials and decentralized identity
62
62
  - **Use Cases**: Identity verification, attestations, zero-knowledge proofs
63
63
  - **Features**: DID creation, credential issuance, selective disclosure
64
- - **CDN**: `unpkg.com/@smartledger/bsv@9.7.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.9.0/bsv-gdaf.min.js`
65
65
 
66
66
  #### **⚖️ Legal Token Protocol - LTP (1184KB)**
67
67
  - **Purpose**: Legal compliance framework for tokenized assets
68
68
  - **Use Cases**: Property rights, obligations, compliant tokenization
69
69
  - **Features**: Legal primitives, compliance checking, attestation anchoring
70
- - **CDN**: `unpkg.com/@smartledger/bsv@9.7.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.9.0/bsv-ltp.min.js`
71
71
 
72
72
  ### **2. Incorrect File Sizes in Documentation**
73
73
 
@@ -81,18 +81,18 @@ Three advanced modules totaling **~2.7MB** of functionality:
81
81
 
82
82
  | Module | Size | Use Case | CDN Link |
83
83
  |--------|------|----------|----------|
84
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.7.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.7.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.7.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.7.0/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.7.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.7.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.7.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.7.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.9.0/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.9.0/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.9.0/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.9.0/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.9.0/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.9.0/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.9.0/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.9.0/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-ltp.min.js` |
96
96
 
97
97
  ## 🎯 **Updated Usage Examples**
98
98
 
@@ -100,22 +100,22 @@ Three advanced modules totaling **~2.7MB** of functionality:
100
100
 
101
101
  #### **1. Basic Development (~963KB)**
102
102
  ```html
103
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-script-helper.min.js"></script>
105
105
  ```
106
106
 
107
107
  #### **2. Smart Contract Development (~2.7MB — each bundle re-embeds core BSV)**
108
108
  ```html
109
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-smartcontract.min.js"></script>
112
112
  ```
113
113
 
114
114
  #### **3. 🆕 Legal & Compliance Development (~3.2MB — each bundle re-embeds core BSV)**
115
115
  ```html
116
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-gdaf.min.js"></script>
119
119
  <script>
120
120
  // Legal Token Protocol
121
121
  const legalToken = bsv.createLegalToken({
@@ -132,9 +132,9 @@ Three advanced modules totaling **~2.7MB** of functionality:
132
132
 
133
133
  #### **4. 🆕 Security & Cryptography (~1.4MB)**
134
134
  ```html
135
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv-shamir.min.js"></script>
138
138
  <script>
139
139
  // Shamir Secret Sharing
140
140
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -146,7 +146,7 @@ Three advanced modules totaling **~2.7MB** of functionality:
146
146
 
147
147
  #### **5. Everything Bundle (937KB)**
148
148
  ```html
149
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv.bundle.js"></script>
150
150
  <script>
151
151
  // Everything available immediately
152
152
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -722,7 +722,7 @@ interface UTXO {
722
722
  <html>
723
723
  <head>
724
724
  <title>UTXO Manager Demo</title>
725
- <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.7.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.9.0/bsv.min.js"></script>
726
726
  </head>
727
727
  <body>
728
728
  <script>
@@ -15,9 +15,11 @@ seeking a quote for an independent security review of its cryptographic core.
15
15
 
16
16
  Scope, and we would like these priced separately:
17
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.
18
+ Tier 1 — 11,962 lines. Sighash construction and signing; ECDSA, nonce
19
+ derivation and signature encoding; the consensus-flag and era surface of the
20
+ script interpreter; BRC-220 signing; the covenant verification harness; RFC
21
+ 8785 canonicalization; and the covenant-facing entrypoints of the smart
22
+ contract module.
21
23
 
22
24
  Tier 2 — 1,607 lines. BIP-39 mnemonics, ECIES, and the Base58Check/varint
23
25
  decoding surface.
@@ -25,18 +27,30 @@ Scope, and we would like these priced separately:
25
27
  JavaScript (CommonJS), Node >= 20.19. The code is public.
26
28
 
27
29
  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.
30
+ by the Noble libraries and already audited; opcode EXECUTION in the script
31
+ interpreter, which passes 1,483 of 1,483 of the reference node's own consensus
32
+ vectors with zero false accepts and zero false rejects; and the remaining
33
+ 26,077-line application layer (credentials, tokens, ordinals), which we would
34
+ treat as a separate engagement.
35
+
36
+ Note the shape of that first exclusion, because it is what we want priced. The
37
+ node's vectors each state their own flags, so they say nothing about which flags
38
+ or which consensus era a caller ends up with by DEFAULT. Every consensus defect
39
+ we have found has been in that selection rather than in the execution — the
40
+ corpus passed 1,483/1,483 before each fix and after it.
31
41
 
32
42
  Context that should shorten discovery: the core is inherited from bitcore and
33
43
  has been fixed reactively but never independently reviewed. We can provide a
34
44
  test-backed threat model, a 452-case behavioural conformance corpus that a
35
45
  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.
46
+ ten defects we have found and fixed ourselves, with the module each was in.
47
+
48
+ The failure mode we most want examined is an exported security claim, its
49
+ default, and the test asserting it being wrong together, because all three were
50
+ written from the same assumption. Every one of our ten findings has had that
51
+ shape, and a file-by-file review would have found none of them. We would like
52
+ the statement of work to require checking claims against an independent oracle
53
+ or specification rather than against this repository's own tests.
40
54
 
41
55
  Could you indicate availability, an approximate cost range, and what you would
42
56
  need from us to firm that up?