@smartledger/bsv 8.3.1 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +228 -0
- package/README.md +152 -1031
- package/STABILITY.md +134 -0
- package/bsv-gdaf.min.js +58 -53
- package/bsv-ltp.min.js +23 -18
- package/bsv-script-helper.min.js +1 -1
- package/bsv-smartcontract.min.js +21 -21
- package/bsv.bundle.js +58 -53
- package/bsv.d.ts +0 -4
- package/bsv.min.js +58 -53
- package/docs/BRC220_BATCH_LEAF_AMENDMENT.md +82 -7
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/README.md +2 -1
- package/docs/THREAT_MODEL.md +10 -2
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/docs/proposals/10.0.0-package-split.md +131 -0
- package/index.js +15 -26
- package/lib/block/merkleblock.js +19 -5
- package/lib/covenant/helpers.js +34 -35
- package/lib/covenant/pushtx.js +2 -2
- package/lib/custom-script-helper.js +0 -16
- package/lib/hdprivatekey.js +15 -0
- package/lib/ordinals/ordlock.js +1 -1
- package/lib/script/interpreter.js +109 -1
- package/lib/smart_contract/builder.js +14 -0
- package/lib/smart_contract/debugger.js +2 -2
- package/lib/smart_contract/dsl.js +2 -2
- package/lib/smart_contract/index.js +0 -3
- package/lib/smart_contract/locks.js +1 -41
- package/lib/smart_contract/pels.js +1 -1
- package/lib/smart_contract/token.js +1 -1
- package/lib/util/deprecate.js +159 -0
- package/package.json +19 -82
- package/tools/gen-brc220-batch-vector.js +205 -0
- package/version.js +1 -1
- package/.mocharc.json +0 -5
- package/test/address.js +0 -629
- package/test/block/block.js +0 -239
- package/test/block/blockheader.js +0 -270
- package/test/block/merkleblock.js +0 -207
- package/test/build/bundle_crypto_shim.js +0 -104
- package/test/build/bundle_externals.js +0 -125
- package/test/build/bundle_smoke.js +0 -55
- package/test/build/esbuild_main.js +0 -65
- package/test/build/esm_wrapper.js +0 -73
- package/test/build/exports_resolution.js +0 -84
- package/test/build/version_sync.js +0 -14
- package/test/cli/smoke.js +0 -261
- package/test/consensus/base58-vectors.js +0 -120
- package/test/consensus/sv-script-vectors.js +0 -81
- package/test/consensus/sv-sighash-vectors.js +0 -51
- package/test/consensus/sv-tx-vectors.js +0 -48
- package/test/credentials-test.js +0 -332
- package/test/crypto/backend_selection.js +0 -126
- package/test/crypto/bn.js +0 -168
- package/test/crypto/ecdsa.js +0 -426
- package/test/crypto/elliptic-fixed.js +0 -61
- package/test/crypto/hash.browser.js +0 -121
- package/test/crypto/hash.js +0 -122
- package/test/crypto/point.js +0 -193
- package/test/crypto/random.js +0 -105
- package/test/crypto/security.js +0 -176
- package/test/crypto/shamir.js +0 -177
- package/test/crypto/shamir_rngcap.js +0 -29
- package/test/crypto/signature.js +0 -399
- package/test/data/bip69.json +0 -215
- package/test/data/bitcoin-sv/README.md +0 -170
- package/test/data/bitcoin-sv/base58_encode_decode.json +0 -14
- package/test/data/bitcoin-sv/base58_keys_invalid.json +0 -152
- package/test/data/bitcoin-sv/base58_keys_valid.json +0 -452
- package/test/data/bitcoin-sv/script_tests.json +0 -2591
- package/test/data/bitcoin-sv/sighash.json +0 -1003
- package/test/data/bitcoin-sv/tx_invalid.json +0 -285
- package/test/data/bitcoin-sv/tx_valid.json +0 -367
- package/test/data/bitcoind/base58_keys_invalid.json +0 -152
- package/test/data/bitcoind/base58_keys_valid.json +0 -452
- package/test/data/bitcoind/blocks.json +0 -27
- package/test/data/bitcoind/script_tests.json +0 -2244
- package/test/data/bitcoind/sig_canonical.json +0 -7
- package/test/data/bitcoind/sig_noncanonical.json +0 -22
- package/test/data/bitcoind/tx_invalid.json +0 -177
- package/test/data/bitcoind/tx_valid.json +0 -224
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +0 -12
- package/test/data/blk86756-testnet.json +0 -684
- package/test/data/ecdsa.json +0 -230
- package/test/data/merkleblocks.js +0 -486
- package/test/data/messages.json +0 -22
- package/test/data/sighash.json +0 -1004
- package/test/data/tx_creation.json +0 -85
- package/test/didweb/relationships.js +0 -144
- package/test/ecies/bitcore-ecies.js +0 -178
- package/test/ecies/electrum-ecies.js +0 -206
- package/test/encoding/base58.js +0 -131
- package/test/encoding/base58check.js +0 -145
- package/test/encoding/bufferreader.js +0 -328
- package/test/encoding/bufferwriter.js +0 -160
- package/test/encoding/varint.js +0 -104
- package/test/gdaf/anchor_no_key_leak.js +0 -146
- package/test/gdaf/anchor_spv.js +0 -163
- package/test/gdaf/canonicalization.js +0 -106
- package/test/gdaf/canonicalize.js +0 -140
- package/test/gdaf/zk_prover.js +0 -204
- package/test/hdkeys.js +0 -365
- package/test/hdprivatekey.js +0 -339
- package/test/hdpublickey.js +0 -293
- package/test/index.js +0 -16
- package/test/ltp/ids.js +0 -74
- package/test/ltp/right.js +0 -198
- package/test/ltp/verify_failclosed.js +0 -134
- package/test/message/message.js +0 -190
- package/test/mnemonic/data/fixtures.json +0 -300
- package/test/mnemonic/mnemonic.js +0 -277
- package/test/mnemonic/mocha.opts +0 -1
- package/test/mnemonic/pbkdf2.test.js +0 -43
- package/test/networks.js +0 -207
- package/test/notaryhash/batch_leaf.js +0 -140
- package/test/notaryhash/certificate.js +0 -249
- package/test/notaryhash/encoding.js +0 -186
- package/test/notaryhash/interop.js +0 -112
- package/test/notaryhash/merkle.js +0 -181
- package/test/notaryhash/script.js +0 -270
- package/test/notaryhash/verify.js +0 -342
- package/test/opcode.js +0 -186
- package/test/ordinals/bsv20.js +0 -337
- package/test/ordinals/inscription.js +0 -319
- package/test/ordinals/ordlock.js +0 -613
- package/test/privatekey.js +0 -540
- package/test/publickey.js +0 -411
- package/test/regressions.js +0 -215
- package/test/script/chronicle.js +0 -543
- package/test/script/defaults.js +0 -160
- package/test/script/genesis_limits.js +0 -203
- package/test/script/interpreter.js +0 -776
- package/test/script/script.js +0 -1259
- package/test/script/string_ops.js +0 -88
- package/test/security/fail_closed_contracts.js +0 -104
- package/test/security/threat_model_coverage.js +0 -31
- package/test/smart_contract/covenants.js +0 -245
- package/test/smart_contract/dsl_debugger.js +0 -101
- package/test/smart_contract/extract_field.js +0 -61
- package/test/smart_contract/nonenforcing_guard.js +0 -44
- package/test/smart_contract/ordinal_transfer.js +0 -81
- package/test/smart_contract/preimage.js +0 -98
- package/test/smart_contract/sighash_marketplace.js +0 -108
- package/test/smart_contract/token_generalized.js +0 -185
- package/test/spv/headerchain.js +0 -86
- package/test/spv/merkleproof.js +0 -133
- package/test/statuslist/failclosed.js +0 -78
- package/test/transaction/deserialize.js +0 -33
- package/test/transaction/input/input.js +0 -92
- package/test/transaction/input/multisig.js +0 -174
- package/test/transaction/input/multisigscripthash.js +0 -111
- package/test/transaction/input/publickey.js +0 -68
- package/test/transaction/input/publickeyhash.js +0 -59
- package/test/transaction/output.js +0 -185
- package/test/transaction/sighash.js +0 -91
- package/test/transaction/signature.js +0 -127
- package/test/transaction/transaction.js +0 -1299
- package/test/transaction/unspentoutput.js +0 -97
- package/test/types/dts_drift.js +0 -124
- package/test/types/surface_honesty.js +0 -102
- package/test/util/id.js +0 -72
- package/test/util/js.js +0 -76
- package/test/util/preconditions.js +0 -79
- package/test/vcjwt/interop.js +0 -126
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "9.1.0",
|
|
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",
|
|
7
7
|
"bugs": {
|
|
@@ -98,10 +98,12 @@
|
|
|
98
98
|
"test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
|
|
99
99
|
"test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
|
|
100
100
|
"preimage:extract": "node examples/preimage/extract_preimage_bidirectional.js",
|
|
101
|
-
"prepublishOnly": "npm run build-all && npm run check:readme",
|
|
101
|
+
"prepublishOnly": "npm run build-all && npm run check:readme && npm run check:api",
|
|
102
102
|
"sync-cdn": "node scripts/sync-cdn-urls.js",
|
|
103
103
|
"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",
|
|
104
|
-
"test:browser:ci": "node tests/browser-smoke-runner.js"
|
|
104
|
+
"test:browser:ci": "node tests/browser-smoke-runner.js",
|
|
105
|
+
"api:snapshot": "node scripts/api-surface.js",
|
|
106
|
+
"check:api": "mocha test/api_surface.js --no-config"
|
|
105
107
|
},
|
|
106
108
|
"unpkg": "bsv.min.js",
|
|
107
109
|
"jsdelivr": "bsv.min.js",
|
|
@@ -110,8 +112,6 @@
|
|
|
110
112
|
"index.js",
|
|
111
113
|
"index.mjs",
|
|
112
114
|
"version.js",
|
|
113
|
-
"test/",
|
|
114
|
-
".mocharc.json",
|
|
115
115
|
"lib/",
|
|
116
116
|
"utilities/*.js",
|
|
117
117
|
"utilities/README.md",
|
|
@@ -142,88 +142,25 @@
|
|
|
142
142
|
"LICENSE",
|
|
143
143
|
"README.md",
|
|
144
144
|
"SECURITY.md",
|
|
145
|
-
"CHANGELOG.md"
|
|
145
|
+
"CHANGELOG.md",
|
|
146
|
+
"STABILITY.md"
|
|
146
147
|
],
|
|
147
148
|
"keywords": [
|
|
148
|
-
"bitcoin",
|
|
149
149
|
"bitcoin-sv",
|
|
150
150
|
"bsv",
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"legal-tokens",
|
|
154
|
-
"primitives-only",
|
|
155
|
-
"legal-compliance",
|
|
156
|
-
"property-rights",
|
|
157
|
-
"obligations",
|
|
158
|
-
"attestations",
|
|
159
|
-
"gdaf",
|
|
160
|
-
"global-digital-attestation",
|
|
161
|
-
"w3c-credentials",
|
|
162
|
-
"verifiable-credentials",
|
|
163
|
-
"decentralized-identity",
|
|
164
|
-
"shamir-secret-sharing",
|
|
165
|
-
"threshold-cryptography",
|
|
166
|
-
"cryptocurrency",
|
|
167
|
-
"blockchain",
|
|
168
|
-
"smart-contracts",
|
|
169
|
-
"defi",
|
|
151
|
+
"bitcoin-script",
|
|
152
|
+
"opcode",
|
|
170
153
|
"covenant",
|
|
171
|
-
"
|
|
172
|
-
"script-debugger",
|
|
173
|
-
"debug-tools",
|
|
174
|
-
"modular-loading",
|
|
175
|
-
"standalone-modules",
|
|
176
|
-
"elliptic-curve-fix",
|
|
177
|
-
"smartledger",
|
|
178
|
-
"transaction",
|
|
179
|
-
"address",
|
|
180
|
-
"signature",
|
|
181
|
-
"wallet",
|
|
182
|
-
"hd-wallet",
|
|
183
|
-
"mnemonic",
|
|
184
|
-
"ecies",
|
|
185
|
-
"encryption",
|
|
186
|
-
"message-signing",
|
|
187
|
-
"pushtx",
|
|
188
|
-
"pels",
|
|
154
|
+
"op-push-tx",
|
|
189
155
|
"bip143",
|
|
190
156
|
"preimage",
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"multisig",
|
|
199
|
-
"timelock",
|
|
200
|
-
"conditional-scripts",
|
|
201
|
-
"utxo-management",
|
|
202
|
-
"ultra-low-fees",
|
|
203
|
-
"javascript-to-script",
|
|
204
|
-
"opcode-mapping",
|
|
205
|
-
"covenant-builder",
|
|
206
|
-
"script-simulation",
|
|
207
|
-
"bitcoin-script",
|
|
208
|
-
"asm-generation",
|
|
209
|
-
"advanced-features",
|
|
210
|
-
"script-development",
|
|
211
|
-
"blockchain-simulator",
|
|
212
|
-
"miner-simulator",
|
|
213
|
-
"testing-tools",
|
|
214
|
-
"development-framework",
|
|
215
|
-
"browser-compatible",
|
|
216
|
-
"nodejs-compatible",
|
|
217
|
-
"webpack-ready",
|
|
218
|
-
"cdn-ready",
|
|
219
|
-
"typescript-definitions",
|
|
220
|
-
"drop-in-replacement",
|
|
221
|
-
"performance-optimized",
|
|
222
|
-
"bip21",
|
|
223
|
-
"bip32",
|
|
224
|
-
"bip37",
|
|
225
|
-
"bip69",
|
|
226
|
-
"bip70"
|
|
157
|
+
"smart-contracts",
|
|
158
|
+
"script-interpreter",
|
|
159
|
+
"transaction",
|
|
160
|
+
"utxo",
|
|
161
|
+
"verifiable-credentials",
|
|
162
|
+
"did-web",
|
|
163
|
+
"legal-token-protocol"
|
|
227
164
|
],
|
|
228
165
|
"repository": {
|
|
229
166
|
"type": "git",
|
|
@@ -246,7 +183,7 @@
|
|
|
246
183
|
"chai": "6.2.2",
|
|
247
184
|
"create-hash": "^1.2.0",
|
|
248
185
|
"create-hmac": "^1.1.7",
|
|
249
|
-
"esbuild": "^0.28.
|
|
186
|
+
"esbuild": "^0.28.2",
|
|
250
187
|
"events": "^3.3.0",
|
|
251
188
|
"jose": "^5.10.0",
|
|
252
189
|
"mocha": "^11.8.0",
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate the BRC-220 batch-mode golden vector.
|
|
5
|
+
*
|
|
6
|
+
* node tools/gen-brc220-batch-vector.js > test/data/brc220-batch-vector.json
|
|
7
|
+
*
|
|
8
|
+
* WHY THIS FILE EXISTS
|
|
9
|
+
*
|
|
10
|
+
* BRC-220 §On-chain record specifies the batch tree as RFC 6962 and writes
|
|
11
|
+
* `leaf = SHA256(0x00 ‖ d)`, but never binds `d` to a value. Two readings are available —
|
|
12
|
+
* `d = proofHash` and `d = canonicalBytes` — both second-preimage resistant, producing
|
|
13
|
+
* DIFFERENT roots. Implementations that choose differently do not interoperate, and the
|
|
14
|
+
* failure is silent: the fold simply does not reach the root.
|
|
15
|
+
*
|
|
16
|
+
* Prose cannot reliably close that. One golden vector can. See
|
|
17
|
+
* docs/BRC220_BATCH_LEAF_AMENDMENT.md.
|
|
18
|
+
*
|
|
19
|
+
* WHAT THIS VECTOR IS, AND IS NOT
|
|
20
|
+
*
|
|
21
|
+
* It is a CONFORMANCE TARGET, generated by this implementation. It is NOT external
|
|
22
|
+
* validation, and nothing here should be read as proving our tree is the "correct" one.
|
|
23
|
+
* What makes it useful is that the tree underneath it IS externally anchored: the RFC 6962
|
|
24
|
+
* construction is checked against the published Certificate Transparency roots in
|
|
25
|
+
* test/notaryhash/merkle.js. Given a tree that provably matches RFC 6962, this vector
|
|
26
|
+
* fixes the one thing the spec leaves open — what goes in the leaf.
|
|
27
|
+
*
|
|
28
|
+
* EVERY VALUE IS DERIVED, NOT CHOSEN
|
|
29
|
+
*
|
|
30
|
+
* Keys and payloads come from labelled SHA-256 preimages, and timestamps are fixed
|
|
31
|
+
* constants, so the file regenerates byte-identically and a third party can reproduce
|
|
32
|
+
* every intermediate with any library. The vector records those intermediates —
|
|
33
|
+
* canonicalBytes, proofHash, leaf hash — precisely so a reader can check each step
|
|
34
|
+
* independently instead of trusting the final root.
|
|
35
|
+
*
|
|
36
|
+
* Do not regenerate this to make a failing test pass. A diff is either a real change in
|
|
37
|
+
* the encoding or a bug.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
var Hash = require('../lib/crypto/hash')
|
|
41
|
+
var BN = require('../lib/crypto/bn')
|
|
42
|
+
var PrivateKey = require('../lib/privatekey')
|
|
43
|
+
var ECDSA = require('../lib/crypto/ecdsa')
|
|
44
|
+
var Point = require('../lib/crypto/point')
|
|
45
|
+
var Encoding = require('../lib/notaryhash/encoding')
|
|
46
|
+
var Merkle = require('../lib/notaryhash/merkle')
|
|
47
|
+
|
|
48
|
+
// Five proofs. Five rather than four on purpose: RFC 6962 splits at the largest power of
|
|
49
|
+
// two BELOW n, so n=5 splits 4/1 where a midpoint split would give 2/3 and a different
|
|
50
|
+
// root. It also makes the leaf count odd, exercising the rule that the last leaf is never
|
|
51
|
+
// duplicated. Those are the two places an implementation of this tree goes wrong, so the
|
|
52
|
+
// vector is worth more at n=5 than at any power of two.
|
|
53
|
+
var LEAF_COUNT = 5
|
|
54
|
+
|
|
55
|
+
// Fixed, so the file is reproducible. ISO-8601 Z, one day apart.
|
|
56
|
+
var CREATED_AT = [
|
|
57
|
+
'2026-01-01T00:00:00.000Z',
|
|
58
|
+
'2026-01-02T00:00:00.000Z',
|
|
59
|
+
'2026-01-03T00:00:00.000Z',
|
|
60
|
+
'2026-01-04T00:00:00.000Z',
|
|
61
|
+
'2026-01-05T00:00:00.000Z'
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
var ALGORITHM = 'ECDSA-secp256k1'
|
|
65
|
+
var HASH_ALGORITHM = 'SHA-256'
|
|
66
|
+
|
|
67
|
+
// Labelled preimages, so anyone can recompute the inputs themselves.
|
|
68
|
+
function derive (label, i) {
|
|
69
|
+
return Hash.sha256(Buffer.from('BRC-220/batch-vector/' + label + '/' + i, 'utf8'))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Raw 64-byte r‖s, low-S, as `encoding: "raw"` requires. Not DER.
|
|
73
|
+
function signRaw (payloadHash, privkey) {
|
|
74
|
+
// set() rather than assigning fields directly: it derives `pubkey` from `privkey`,
|
|
75
|
+
// which sign() requires. RFC 6979 makes this deterministic, so the vector reproduces.
|
|
76
|
+
//
|
|
77
|
+
// NO `endian` option. BRC-220 signs the 32-byte payloadHash directly, so the digest IS
|
|
78
|
+
// the scalar, big-endian. The first version of this file passed `endian: 'little'`,
|
|
79
|
+
// matching the verifier bug fixed in 8.3.1, and produced a "golden" vector whose five
|
|
80
|
+
// signatures no conformant implementation could verify — 0/5 under @noble/curves. A
|
|
81
|
+
// reference vector that is wrong is worse than no vector, because it is published as
|
|
82
|
+
// the thing to match.
|
|
83
|
+
//
|
|
84
|
+
// It survived review because the generator and the checker used the same signer, so
|
|
85
|
+
// both were wrong in the same direction. test/notaryhash/batch_vector.js now verifies
|
|
86
|
+
// every signature under @noble/curves as well, which is the assertion that fails if
|
|
87
|
+
// this line is ever changed back.
|
|
88
|
+
var ecdsa = ECDSA().set({ hashbuf: payloadHash, privkey: privkey })
|
|
89
|
+
ecdsa.sign()
|
|
90
|
+
var sig = ecdsa.sig
|
|
91
|
+
|
|
92
|
+
var halfOrder = Point.getN().div(new BN(2))
|
|
93
|
+
if (sig.s.gt(halfOrder)) {
|
|
94
|
+
throw new Error('signature is not low-S; the signer must produce low-S, not normalise')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var r = sig.r.toBuffer({ size: 32 })
|
|
98
|
+
var s = sig.s.toBuffer({ size: 32 })
|
|
99
|
+
return Buffer.concat([r, s])
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function u32beHex (n) {
|
|
103
|
+
var b = Buffer.alloc(4)
|
|
104
|
+
b.writeUInt32BE(n, 0)
|
|
105
|
+
return b.toString('hex')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var proofs = []
|
|
109
|
+
for (var i = 0; i < LEAF_COUNT; i++) {
|
|
110
|
+
// fromObject rather than new PrivateKey(bn): the bare-BN form leaves `compressed`
|
|
111
|
+
// unset, and public-key derivation then fails.
|
|
112
|
+
var privkey = PrivateKey.fromObject({
|
|
113
|
+
bn: BN.fromBuffer(derive('key', i)),
|
|
114
|
+
compressed: true,
|
|
115
|
+
network: 'livenet'
|
|
116
|
+
})
|
|
117
|
+
var payloadHash = derive('payload', i)
|
|
118
|
+
var publicKey = privkey.publicKey.toBuffer() // 33-byte compressed SEC1
|
|
119
|
+
var signature = signRaw(payloadHash, privkey)
|
|
120
|
+
var createdAtUnix = Encoding.toUnixSeconds(CREATED_AT[i])
|
|
121
|
+
|
|
122
|
+
var fields = {
|
|
123
|
+
algorithm: ALGORITHM,
|
|
124
|
+
hashAlgorithm: HASH_ALGORITHM,
|
|
125
|
+
payloadHash: payloadHash,
|
|
126
|
+
publicKey: publicKey,
|
|
127
|
+
signature: signature,
|
|
128
|
+
createdAtUnix: createdAtUnix
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var canonicalBytes = Encoding.canonicalBytes(fields)
|
|
132
|
+
var proofHash = Encoding.proofHash(fields)
|
|
133
|
+
|
|
134
|
+
proofs.push({
|
|
135
|
+
leafIndex: i,
|
|
136
|
+
keyPreimage: 'BRC-220/batch-vector/key/' + i,
|
|
137
|
+
payloadPreimage: 'BRC-220/batch-vector/payload/' + i,
|
|
138
|
+
algorithm: ALGORITHM,
|
|
139
|
+
hashAlgorithm: HASH_ALGORITHM,
|
|
140
|
+
encoding: 'raw',
|
|
141
|
+
payloadHash: payloadHash.toString('hex'),
|
|
142
|
+
publicKey: publicKey.toString('hex'),
|
|
143
|
+
signature: signature.toString('hex'),
|
|
144
|
+
createdAt: CREATED_AT[i],
|
|
145
|
+
createdAtUnix: createdAtUnix,
|
|
146
|
+
canonicalBytes: canonicalBytes.toString('hex'),
|
|
147
|
+
proofHash: proofHash.toString('hex'),
|
|
148
|
+
// The value the spec leaves open, spelled out at both readings so the divergence is
|
|
149
|
+
// visible in the published artifact rather than only in prose.
|
|
150
|
+
leafHash: Merkle.hashLeaf(proofHash).toString('hex'),
|
|
151
|
+
leafHashUnderRejectedReading: Merkle.hashLeaf(canonicalBytes).toString('hex')
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var leaves = proofs.map(function (p) { return Buffer.from(p.proofHash, 'hex') })
|
|
156
|
+
var root = Merkle.root(leaves)
|
|
157
|
+
|
|
158
|
+
proofs.forEach(function (p, idx) {
|
|
159
|
+
p.path = Merkle.path(leaves, idx).map(function (n) { return n.toString('hex') })
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
var vector = {
|
|
163
|
+
_comment: [
|
|
164
|
+
'BRC-220 batch-mode golden vector. Generated by tools/gen-brc220-batch-vector.js;',
|
|
165
|
+
'do not hand-edit. Every value is derived from the labelled preimages recorded on each',
|
|
166
|
+
'proof, so the file is reproducible from scratch in any language.',
|
|
167
|
+
'',
|
|
168
|
+
'THE POINT OF THIS FILE: BRC-220 writes the batch leaf as SHA256(0x00 || d) and never',
|
|
169
|
+
'says what d is. This vector fixes d = proofHash. The `rejectedReading` block records',
|
|
170
|
+
'what the same five proofs produce under d = canonicalBytes — equally sound',
|
|
171
|
+
'cryptographically, a different root, and therefore not interoperable. An',
|
|
172
|
+
'implementation matching `rejectedReading.root` has made the other choice, which is',
|
|
173
|
+
'exactly the confusion this vector exists to make visible.',
|
|
174
|
+
'',
|
|
175
|
+
'This is a conformance target produced by @smartledger/bsv, not external validation.',
|
|
176
|
+
'The tree beneath it is externally anchored: the RFC 6962 construction is verified',
|
|
177
|
+
'against the published Certificate Transparency roots in test/notaryhash/merkle.js.',
|
|
178
|
+
'',
|
|
179
|
+
'n = 5 deliberately: RFC 6962 splits at the largest power of two BELOW n, so this',
|
|
180
|
+
'splits 4/1 (a midpoint split would give 2/3 and a different root), and the odd count',
|
|
181
|
+
'exercises the rule that the last leaf is never duplicated.'
|
|
182
|
+
].join(' ').replace(/\s+/g, ' ').trim(),
|
|
183
|
+
spec: 'BRC-220',
|
|
184
|
+
tree: 'RFC 6962',
|
|
185
|
+
leafDatum: 'proofHash',
|
|
186
|
+
leafRule: 'leaf = SHA-256(0x00 || proofHash); node = SHA-256(0x01 || left || right)',
|
|
187
|
+
leafCount: LEAF_COUNT,
|
|
188
|
+
root: root.toString('hex'),
|
|
189
|
+
onChainRecordTail: {
|
|
190
|
+
_comment: 'The batch record is "NOTARYHASH" | u8(1) | u8(2) | merkleRoot(32) | u32be(leafCount).',
|
|
191
|
+
merkleRoot: root.toString('hex'),
|
|
192
|
+
leafCountU32be: u32beHex(LEAF_COUNT)
|
|
193
|
+
},
|
|
194
|
+
rejectedReading: {
|
|
195
|
+
_comment: 'What d = canonicalBytes yields over the SAME five proofs. Recorded so the ' +
|
|
196
|
+
'divergence is checkable, not to endorse it.',
|
|
197
|
+
leafDatum: 'canonicalBytes',
|
|
198
|
+
root: Merkle.root(proofs.map(function (p) {
|
|
199
|
+
return Buffer.from(p.canonicalBytes, 'hex')
|
|
200
|
+
})).toString('hex')
|
|
201
|
+
},
|
|
202
|
+
proofs: proofs
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
process.stdout.write(JSON.stringify(vector, null, 2) + '\n')
|
package/version.js
CHANGED