@smartledger/bsv 8.2.0 → 8.3.1

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.
@@ -5,7 +5,7 @@ cryptographic core, and carries the enquiry text to send to vendors. It exists s
5
5
  every vendor prices the *same* thing, and so that the reasoning behind the scope
6
6
  boundary survives past the engagement that prompted it.
7
7
 
8
- Measured against **v8.2.0**, 2026-08-15. Re-measure before sending if the version has
8
+ Measured against **v8.3.0**, 2026-08-16. Re-measure before sending if the version has
9
9
  moved (`docs/AUDIT_SCOPE.md` is not covered by a drift gate).
10
10
 
11
11
  ## 1. The question we are asking
@@ -58,16 +58,16 @@ is not.
58
58
  | Component | Status | Reason |
59
59
  | --- | --- | --- |
60
60
  | `@noble/curves`, `@noble/hashes`, `@noble/ciphers` | Already audited | The primitives come from the Noble libraries, which **Cure53 has audited and published on**. We do not implement curve or hash arithmetic ourselves. State this explicitly to vendors — otherwise they price work we do not need. |
61
- | `lib/smart_contract/`, `lib/ltp/`, `lib/gdaf/`, `lib/ordinals/`, `lib/block/`, plus 9 further directories and 6 top-level files | Excluded | Application layer, 23,016 lines — 18,636 in the five named modules and 4,380 in the remainder. Written in-house and covered by adversarial tests. Worth a separate engagement; including it here would blur the question in §1. |
61
+ | `lib/smart_contract/`, `lib/ltp/`, `lib/gdaf/`, `lib/ordinals/`, `lib/block/`, plus 9 further directories and 6 top-level files | Excluded | Application layer, 24,447 lines — 18,600 in the five named modules and 5,847 in the remainder. Written in-house and covered by adversarial tests. Worth a separate engagement; including it here would blur the question in §1. |
62
62
 
63
- Totals reconcile against `lib/`, which is 36,891 lines across 123 files:
63
+ Totals reconcile against `lib/`, which is 38,322 lines across 130 files:
64
64
 
65
65
  ```
66
66
  tier 1 12,268
67
67
  tier 2 1,607
68
- excluded 23,016
68
+ excluded 24,447
69
69
  ------
70
- total 36,891
70
+ total 38,322
71
71
  ```
72
72
 
73
73
  Core + optional = 13,875.
@@ -94,7 +94,7 @@ Each of these should *reduce* the quote — they remove discovery work.
94
94
  - **`npm run conformance`** — 452 cases across 13 suites, freezing observable behaviour
95
95
  so any change surfaces as a diff. A second, independently written implementation
96
96
  (`smartledger-bsv-core`, the TypeScript port) agrees on all 452.
97
- - **4,503 passing tests**, plus a reproducible-bundle gate, a require-cycle gate, and a
97
+ - **4,626 passing tests**, plus a reproducible-bundle gate, a require-cycle gate, and a
98
98
  type-drift gate that parses the published types against the runtime.
99
99
  - **`SECURITY.md`** — a published advisory (GHSA-gw63-x79h-mhjc) and a changelog of
100
100
  security fixes with the reasoning for each.
@@ -143,7 +143,7 @@ Scope, and we would like these priced separately:
143
143
  JavaScript (CommonJS), Node >= 20.19. The code is public.
144
144
 
145
145
  Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
146
- by the Noble libraries and already audited; and our 23,016-line application
146
+ by the Noble libraries and already audited; and our 24,447-line application
147
147
  layer (credentials, tokens, ordinals), which we would treat as a separate
148
148
  engagement.
149
149
 
@@ -171,7 +171,7 @@ SmartLedger Technology
171
171
  Every figure in this document, including the excluded total, must come out of this
172
172
  script. **Derive the excluded count as the complement — never by subtracting tier 1
173
173
  alone.** The first draft did exactly that, double-counted tier 2, and published parts
174
- summing to 37,430 against a 36,891 whole; §7 could not catch it because it reproduced
174
+ summing to 37,430 against a 38,322 whole; §7 could not catch it because it reproduced
175
175
  every figure except the wrong one.
176
176
 
177
177
  ```sh
@@ -0,0 +1,119 @@
1
+ # Proposed BRC-220 amendment: define the batch Merkle leaf
2
+
3
+ §On-chain record specifies *which* Merkle tree batch mode uses, but never says what goes
4
+ in a leaf. This proposes the definition, with the reasoning that led to it.
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).
8
+
9
+ ---
10
+
11
+ ## What the spec currently says
12
+
13
+ §On-chain record, batch (`kind = 2`):
14
+
15
+ > One transaction anchors many proofs under an RFC 6962 Merkle root, domain-separated
16
+ > (`leaf = SHA256(0x00 ‖ d)`, `node = SHA256(0x01 ‖ l ‖ r)`, split at the largest power of
17
+ > two `< n`, last leaf never duplicated).
18
+
19
+ That parenthetical identifies the **tree construction**: domain separation, the split
20
+ rule, and the no-duplication rule that separate RFC 6962 from Bitcoin's tree. `d`, `l` and
21
+ `r` are RFC 6962's own generic symbols — §2.1 of that RFC writes
22
+ `MTH({d(0)}) = SHA-256(0x00 || d(0))` — so the sentence is naming the tree, not defining
23
+ its contents.
24
+
25
+ **`d` is never bound to a value.** The word `canonicalBytes` occurs once in the entire
26
+ document, in the `proofHash` definition in §Canonical proof bytes; it does not appear in
27
+ the batch text. Neither does `proofHash`.
28
+
29
+ So this is an ambiguity, not a disagreement between spec and implementation. Two
30
+ good-faith implementers reading the same sentence can and did reach different answers:
31
+
32
+ | reading | leaf hash |
33
+ | --- | --- |
34
+ | `d` = the canonical proof bytes | `SHA-256(0x00 ‖ canonicalBytes)` |
35
+ | `d` = the proof's identifier | `SHA-256(0x00 ‖ proofHash)` = `SHA-256(0x00 ‖ SHA-256(canonicalBytes))` |
36
+
37
+ Both are second-preimage resistant, and the domain separation that gives RFC 6962 that
38
+ property is unaffected by which one is chosen. **They are equal in strength and produce
39
+ different roots.** A certificate built under one reading fails inclusion under the other,
40
+ with no error that points at the cause — the fold simply does not reach the root.
41
+
42
+ The published test vectors do not settle it: they cover a certificate-with-SPV-envelope
43
+ golden vector, `txidFromRawTx` against the Bitcoin genesis coinbase, and the SPV Merkle
44
+ fold against block 170. **None of them is a batch-mode vector**, so there is nothing to
45
+ conform to by example.
46
+
47
+ ---
48
+
49
+ ## Proposed text
50
+
51
+ Insert into **§On-chain record**, replacing the batch bullet's parenthetical.
52
+
53
+ > - **batch** (`kind = 2`): `"NOTARYHASH" | u8(1) | u8(2) | merkleRoot(32) | u32be(leafCount)`.
54
+ > One transaction anchors many proofs under an RFC 6962 Merkle root.
55
+ >
56
+ > The leaf datum `d` for a proof is its **`proofHash`** — the 32 bytes defined in
57
+ > §Canonical proof bytes — so a leaf is `SHA-256(0x00 ‖ proofHash)` and an internal node
58
+ > is `SHA-256(0x01 ‖ l ‖ r)`. Leaves are ordered as the batch was assembled, and
59
+ > `leafIndex` in the certificate's `merkle` object is that position. The tree splits at
60
+ > the largest power of two `< n` and the last leaf is never duplicated, per RFC 6962
61
+ > §2.1.
62
+ >
63
+ > Note that `d` is the **hash**, not the canonical bytes: a leaf is therefore
64
+ > `SHA-256(0x00 ‖ SHA-256(canonicalBytes))`. The two readings are equally sound
65
+ > cryptographically but produce different roots, so this is stated explicitly rather
66
+ > than left to RFC 6962's generic `d`.
67
+
68
+ ---
69
+
70
+ ## Why `proofHash` rather than the canonical bytes
71
+
72
+ Both are sound. The choice is on other grounds.
73
+
74
+ **A verifier already holds it.** `proofHash` is a required certificate field. A verifier
75
+ checking batch inclusion reads it directly and folds. Under the other reading it must
76
+ first reconstruct `canonicalBytes` — re-serialising `publicKey`, `signature`,
77
+ `createdAtUnix` and the rest with the exact length-prefix framing — before it can begin.
78
+ That is the whole `proofHash` computation, performed again, as a precondition for a check
79
+ that is supposed to be independent of it. The spec advertises a "dependency-light
80
+ standalone verifier"; this keeps the batch path genuinely light.
81
+
82
+ **It is what a batch anchors.** §On-chain record says a batch transaction "anchors many
83
+ proofs". `proofHash` *is* the proof's identity — it is the integrity root, the value the
84
+ full and hybrid records place on-chain, and the value §Verification checks a certificate
85
+ against. Batching identifiers rather than re-serialised bodies keeps batch mode
86
+ consistent with the other two modes rather than introducing a second notion of what
87
+ represents a proof.
88
+
89
+ **It matches the mode it exists alongside.** Hybrid mode already establishes that BRC-220
90
+ puts hashes on-chain where blobs would be large. Fixed 32-byte leaves keep batch memory
91
+ and proof sizes independent of signature scheme — which matters precisely for the
92
+ post-quantum algorithms §Motivation names, where `canonicalBytes` runs to kilobytes per
93
+ proof.
94
+
95
+ **The extra hash costs nothing.** One SHA-256 over 32 bytes per leaf, against a
96
+ re-serialisation per leaf under the alternative.
97
+
98
+ ---
99
+
100
+ ## Compatibility
101
+
102
+ `@smartledger/bsv` implements the `proofHash` reading as of 8.3.0, and from this change
103
+ states it in `lib/notaryhash/index.js` and enforces it in
104
+ `test/notaryhash/batch_leaf.js` — including a test that a tree built over `canonicalBytes`
105
+ is rejected, so the choice is checked rather than merely intended.
106
+
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.
110
+
111
+ ---
112
+
113
+ ## Recommended alongside
114
+
115
+ Publish a **batch-mode golden vector** with the other test vectors: a small tree — four
116
+ proofs, say — with the four `proofHash` values, the resulting root, and the inclusion path
117
+ for one leaf. One such vector removes this entire class of ambiguity for every future
118
+ implementer, in a way that no amount of prose reliably does. Its absence is why this
119
+ document is necessary.
@@ -0,0 +1,100 @@
1
+ # Proposed BRC-220 amendment: define the `encoding` field
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.
5
+
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.
8
+
9
+ ---
10
+
11
+ ## Proposed text
12
+
13
+ Insert into **§Certificate**, after the sentence listing the required fields.
14
+
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`.
37
+
38
+ ---
39
+
40
+ ## Why `"raw"` rather than DER
41
+
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.
@@ -0,0 +1,233 @@
1
+ # BRC-220 (NotaryHash) — implementation plan
2
+
3
+ Plan for implementing [BRC-220](https://github.com/bitcoin-sv/BRCs/blob/master/apps/0220.md),
4
+ *NotaryHash: Privacy-Preserving Signed-Hash Notarization with SPV-Verifiable Certificates*,
5
+ in `@smartledger/bsv`.
6
+
7
+ Drafted against the spec on 2026-08-16, at v8.2.0. Nothing here is implemented yet.
8
+
9
+ ## 1. Why this library
10
+
11
+ BRC-220 is a notarization protocol, not a signature scheme. It needs a signer, an
12
+ `OP_FALSE OP_RETURN` output, a canonical JSON certificate, an SPV proof, and a Merkle
13
+ tree. Four of those five already exist here:
14
+
15
+ | BRC-220 needs | Already present |
16
+ | --- | --- |
17
+ | RFC 8785 canonical certificate | `AttestationSigner._canonicalizeJCS` (8.2.0) |
18
+ | SPV inclusion proof, TSC format | `lib/spv/merkleproof.js`, `lib/spv/headerchain.js` |
19
+ | Independent block headers, never the provider's word | `verifyHeaderChain`, already the documented stance |
20
+ | `OP_FALSE OP_RETURN` safe data output | `lib/transaction`, `lib/custom-script-helper.js` |
21
+ | Length-prefixed binary | `lib/encoding/bufferwriter.js` |
22
+ | ECDSA-secp256k1 signing | `lib/crypto/ecdsa.js` |
23
+
24
+ The JCS work landed in 8.2.0 for an unrelated reason — GDAF signatures had to be
25
+ verifiable by other implementations — and BRC-220 requires exactly that encoding for its
26
+ certificates. That is the single strongest argument that this belongs here rather than in
27
+ a separate package.
28
+
29
+ ## 2. Post-quantum stays OUT of the dependency tree
30
+
31
+ The spec names ML-DSA (3 parameter sets) and SLH-DSA (12), but `ECDSA-secp256k1` is a
32
+ first-class algorithm alongside them. A conformant implementation can support ECDSA only.
33
+
34
+ `@noble/post-quantum` should NOT become a dependency of this library:
35
+
36
+ - **It is the one unaudited Noble package.** Its README states plainly: *"The library has
37
+ not been independently audited yet"* — a self-audit at 0.6.1 only. `@noble/curves`,
38
+ `@noble/hashes` and `@noble/ciphers` carry a published Cure53 audit, which is why
39
+ `docs/AUDIT_SCOPE.md` can tell a vendor not to price the primitive layer. Adding an
40
+ unaudited implementation trades that away and has to be disclosed.
41
+ - It is **0.x**, so the API is not stable.
42
+ - It does **not claim constant-time execution**, which its README calls out as mattering
43
+ most when an attacker can measure signing.
44
+ - 669 KB unpacked, against bundles this project cut 20% in 8.0.0.
45
+
46
+ **Instead: a suite registry.** `algorithm` is a string in both the certificate and the
47
+ on-chain record, so it maps naturally onto a lookup:
48
+
49
+ ```js
50
+ NotaryHash.registerSuite('ML-DSA-65', {
51
+ verify: function (payloadHash, signature, publicKey) { /* … */ },
52
+ sign: function (payloadHash, privateKey) { /* … */ }
53
+ })
54
+ ```
55
+
56
+ `ECDSA-secp256k1` is registered by default and needs nothing new. Everything else is
57
+ supplied by the caller — most obviously from **`@smartledger/keys`**, which already wraps
58
+ `@noble/post-quantum` for ML-DSA-44/65/87. That keeps one PQ dependency in the ecosystem
59
+ rather than two, and callers who do not need it pay nothing in bundle size or audit
60
+ surface.
61
+
62
+ Note `@smartledger/keys@2.0.0` is currently 8 months stale and behind on all three of its
63
+ crypto dependencies, including a full major on `@noble/hashes` (1.8.0 against 2.3.0).
64
+ Refreshing it is a prerequisite for recommending it as the PQ path, and is separate work.
65
+
66
+ ## 3. The trap: three different Merkle trees
67
+
68
+ BRC-220 batch mode uses **RFC 6962** trees. This library already contains two Merkle
69
+ implementations, and **neither is RFC 6962**:
70
+
71
+ | Tree | Leaf | Internal | Odd node |
72
+ | --- | --- | --- | --- |
73
+ | Bitcoin (`lib/spv/merkleproof.js`) | txid | `sha256d(L‖R)` | rightmost **duplicated** |
74
+ | `lib/gdaf/zk-prover.js` | salted field hash | `sha256(L‖R)` | duplicated |
75
+ | **RFC 6962 (BRC-220 needs)** | `sha256(0x00‖d)` | `sha256(0x01‖L‖R)` | **never duplicated** |
76
+
77
+ Domain separation and the no-duplication rule are what make RFC 6962 resistant to the
78
+ second-preimage attack Bitcoin's tree is famously vulnerable to. Reusing either existing
79
+ implementation would be silently wrong: it would produce a root that no other BRC-220
80
+ implementation computes, and the failure would only appear when someone else verified a
81
+ batch certificate.
82
+
83
+ RFC 6962 splits at the **largest power of two less than the leaf count**, not the middle.
84
+ That must be tested against published RFC 6962 vectors, not against our own output.
85
+
86
+ ## 4. Module layout
87
+
88
+ ```
89
+ lib/notaryhash/
90
+ index.js NotaryHash.create / verify / registerSuite
91
+ encoding.js lp(), canonical bytes, proofHash
92
+ script.js OP_FALSE OP_RETURN builder + parser, all three modes
93
+ certificate.js build, JCS-canonicalize, validate shape
94
+ merkle.js RFC 6962 — NOT the Bitcoin or zk-prover trees
95
+ suites.js registry; ECDSA-secp256k1 registered by default
96
+ ```
97
+
98
+ Exposed as `bsv.NotaryHash`, with a `notaryhash-entry.js` and its own bundle, matching how
99
+ `gdaf`, `ltp` and `didweb` are already packaged.
100
+
101
+ ## 5. What gets built, in order
102
+
103
+ **Phase 1 — encoding and proofHash.** `lp(x) = u32be(len(x)) || x`, and the canonical byte
104
+ string:
105
+
106
+ ```
107
+ lp("NotaryHash/1.0") || u8(version) || lp(algorithm) || lp(hashAlgorithm) ||
108
+ lp(payloadHash) || lp(publicKey) || lp(signature) || u64be(createdAtUnix)
109
+ ```
110
+
111
+ The protocol prefix, version and timestamp are in `proofHash` but never on chain — so the
112
+ on-chain record alone cannot reconstruct it, and a verifier needs the certificate. Worth a
113
+ test that states this, because it looks like an omission otherwise.
114
+
115
+ **Phase 2 — the OP_RETURN record**, all three modes, builder and parser, round-tripping.
116
+ Full mode carries the key and signature; hybrid carries `sha256` of each, which is what
117
+ makes PQ signatures affordable on chain; batch carries only a 32-byte root and a `u32be`
118
+ leaf count.
119
+
120
+ **Phase 3 — certificate**, built on the existing `_canonicalizeJCS`. The SPV envelope is
121
+ additive and must not change `proofHash` — a test should add an envelope to a finished
122
+ certificate and assert the hash is unchanged.
123
+
124
+ **Phase 4 — verification**, the three checks the spec requires, each returning a strict
125
+ boolean and failing closed:
126
+
127
+ 1. signature verifies over `payloadHash` under the registered suite — offline;
128
+ 2. `proofHash` recomputes from canonical bytes and matches — offline;
129
+ 3. anchor confirmed, SPV preferred: `txid = reverse(sha256d(rawTx))`, the `OP_RETURN`
130
+ fields match the certificate, and the TSC Merkle proof folds to a root matching a
131
+ block header **obtained independently**.
132
+
133
+ **Phase 5 — batch mode** and RFC 6962, last because it is the piece most likely to be got
134
+ wrong and benefits from everything else being settled.
135
+
136
+ ## 6. Testing stance
137
+
138
+ Given what the last two reviews found in `zk-prover.js` — a range proof that verified
139
+ nothing and a selective-disclosure scheme that leaked every withheld field, under 4,469
140
+ passing tests — this module starts with adversarial tests rather than acquiring them
141
+ later:
142
+
143
+ - Every `verify` returns a **strict boolean** or throws. Never a truthy result object.
144
+ This is the defect class that has recurred most in this codebase.
145
+ - Each of the three validity checks has a test that **defeats it in isolation**: a valid
146
+ signature with a tampered `proofHash`; a correct `proofHash` with a forged signature; a
147
+ well-formed certificate anchored to a transaction that is not in the block it claims.
148
+ - An unregistered `algorithm` must **fail**, not fall through to a default suite.
149
+ - RFC 6962 vectors from the RFC, not from our own implementation, and a test that a
150
+ Bitcoin-style tree over the same leaves produces a *different* root — that failure is
151
+ the one that would otherwise ship silently.
152
+ - Round-trip the on-chain record for all three modes, and assert hybrid's pushes are
153
+ 32 bytes where full's are variable.
154
+
155
+ ## 7. Questions, settled against the full text
156
+
157
+ The spec is 8,514 bytes. These were resolved by reading all of it rather than querying it
158
+ piecemeal — which is also how the first of them turned out to be an artifact of my own
159
+ summarising rather than anything in the document.
160
+
161
+ - **Push 0 is `"NOTARYHASH"`, 10 ASCII bytes** (`4e4f5441525948415348`). The spec states no
162
+ byte count for it anywhere; the "9 bytes" this section previously flagged came from a
163
+ summarisation step, not the normative text. Verified by fetching the raw file and
164
+ grepping it directly.
165
+ - **`hashAlgorithm` is SHA-256** for every algorithm the spec lists — the Algorithms table
166
+ gives one hash for all three families. It is not stated to be closed, so the field stays
167
+ a string rather than an enum, but SHA-256 is the only conformant value in v1.
168
+ - **The signer signs the 32-byte `payloadHash` directly** (§Algorithms): "post-quantum
169
+ schemes apply their own internal hashing". So ECDSA signs the digest as-is, with no
170
+ second hash. Getting this wrong produces signatures nothing else verifies.
171
+ - **Batch certificates carry BOTH `anchor` and `merkle`** — the spec says a batched
172
+ certificate "additionally carries" the inclusion proof.
173
+ - **The service is a role, not a requirement.** §What a certificate proves: "any party
174
+ holding a valid (hash, signature, publicKey) triple may re-anchor it; the attestation
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`.
185
+ - **`createdAt` is advisory for trust but load-bearing for the hash.** §Verification calls
186
+ it "an advisory client field only" — meaning proof-of-existence time comes from the
187
+ block, not from this field. It is still inside the canonical bytes as `createdAtUnix`,
188
+ so it cannot be altered after issuance.
189
+
190
+ Decided, and proposed back to the spec:
191
+
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`.
195
+
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.
199
+
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`.
205
+
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()`.
215
+
216
+ ### The reference implementation
217
+
218
+ §Implementations describes a reference service, client SDK and standalone verifier, with
219
+ **published test vectors**: a complete certificate-with-SPV-envelope golden vector,
220
+ `txidFromRawTx` against the Bitcoin genesis coinbase, and the Merkle fold against the real
221
+ block-170 two-transaction proof.
222
+
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.
227
+
228
+ ## 8. Not in scope
229
+
230
+ - Post-quantum suites themselves — supplied by the caller, see §2.
231
+ - The notary *service*. This library builds and verifies records and certificates; it does
232
+ not run the submission endpoint the spec describes.
233
+ - Broadcasting. Existing transaction plumbing covers it.
@@ -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@8.2.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.2.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@8.2.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.2.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.2.0/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.2.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.2.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.2.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.2.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@8.3.1/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.3.1/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@8.3.1/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.3.1/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.3.1/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.3.1/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.3.1/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.3.1/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.3.1/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@8.3.1/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@8.3.1/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@8.3.1/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@8.2.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@8.3.1/bsv.min.js"></script>
726
726
  </head>
727
727
  <body>
728
728
  <script>