@smartledger/bsv 9.0.0 → 9.1.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.
- package/CHANGELOG.md +164 -0
- package/README.md +152 -1041
- package/STABILITY.md +134 -0
- package/bsv-gdaf.min.js +53 -48
- package/bsv-ltp.min.js +23 -18
- package/bsv-smartcontract.min.js +18 -18
- package/bsv.bundle.js +53 -48
- package/bsv.min.js +53 -48
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- 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 +5 -0
- package/lib/block/merkleblock.js +53 -9
- package/lib/hdprivatekey.js +15 -0
- package/lib/script/interpreter.js +109 -1
- package/lib/smart_contract/builder.js +14 -0
- package/lib/util/deprecate.js +159 -0
- package/package.json +19 -82
- 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 -97
- 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/brc220-batch-vector.json +0 -129
- 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/batch_vector.js +0 -282
- 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 -329
- package/test/ordinals/ordlock.js +0 -567
- 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 -207
- package/test/smart_contract/dsl_debugger.js +0 -92
- 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 -71
- package/test/smart_contract/preimage.js +0 -98
- package/test/smart_contract/sighash_marketplace.js +0 -98
- package/test/smart_contract/token_generalized.js +0 -175
- 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
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it, before */
|
|
4
|
-
|
|
5
|
-
// Feature bundles must EXTERNALISE the shared primitives, not embed a second copy.
|
|
6
|
-
//
|
|
7
|
-
// Getting this wrong is not a size regression. If a feature bundle ships its own
|
|
8
|
-
// PrivateKey class, a key built by bsv.min.js fails `instanceof` inside that bundle
|
|
9
|
-
// and index.js's versionGuard reports two library instances — a failure that is
|
|
10
|
-
// invisible to every test that stays inside one bundle.
|
|
11
|
-
//
|
|
12
|
-
// build/esbuild.js has always had a `metafile` option whose comment said it was "used
|
|
13
|
-
// to assert" this property. Nothing consumed it: `grep -rn metafile` returned only the
|
|
14
|
-
// option itself. This file is that consumer.
|
|
15
|
-
|
|
16
|
-
require('chai').should()
|
|
17
|
-
var esbuild = require('../../build/esbuild.js')
|
|
18
|
-
|
|
19
|
-
// Bundles that resolve bsv from the global instead of embedding it.
|
|
20
|
-
var EXTERNALISED = esbuild.BUNDLES.filter(function (c) { return c.externalBsv })
|
|
21
|
-
|
|
22
|
-
describe('feature bundles externalise the shared primitives', function () {
|
|
23
|
-
this.timeout(120000)
|
|
24
|
-
|
|
25
|
-
var inputsByBundle = {}
|
|
26
|
-
|
|
27
|
-
before(function () {
|
|
28
|
-
// Build each one in memory (write:false) and keep its module graph.
|
|
29
|
-
return Promise.all(EXTERNALISED.map(function (cfg) {
|
|
30
|
-
return esbuild.buildOne(cfg, { metafile: true, write: false, logLevel: 'silent' })
|
|
31
|
-
.then(function (result) {
|
|
32
|
-
inputsByBundle[cfg.file] = Object.keys(result.metafile.inputs)
|
|
33
|
-
.filter(function (p) { return p.indexOf('lib/') === 0 })
|
|
34
|
-
.sort()
|
|
35
|
-
})
|
|
36
|
-
}))
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('has bundles to check', function () {
|
|
40
|
-
EXTERNALISED.length.should.be.above(0)
|
|
41
|
-
Object.keys(inputsByBundle).length.should.equal(EXTERNALISED.length)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
// The primary assertion, derived from the config rather than hand-maintained: every
|
|
45
|
-
// path in LIB_GLOBALS is a module the build promises to take from the global bsv, so
|
|
46
|
-
// none of them may appear as a bundled input. Because it reads the same table the
|
|
47
|
-
// build uses, it cannot drift out of step with it.
|
|
48
|
-
it('never embeds a module that LIB_GLOBALS maps to the global bsv', function () {
|
|
49
|
-
var mapped = Object.keys(esbuild.LIB_GLOBALS)
|
|
50
|
-
var offences = []
|
|
51
|
-
Object.keys(inputsByBundle).forEach(function (file) {
|
|
52
|
-
inputsByBundle[file].forEach(function (input) {
|
|
53
|
-
// 'lib/privatekey.js' -> 'privatekey'; 'lib/script/index.js' -> 'script/index'
|
|
54
|
-
var key = input.replace(/^lib\//, '').replace(/\.js$/, '')
|
|
55
|
-
if (mapped.indexOf(key) !== -1) {
|
|
56
|
-
offences.push(file + ' embeds ' + input + ' (should come from global bsv.' +
|
|
57
|
-
esbuild.LIB_GLOBALS[key] + ')')
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
offences.should.deep.equal([])
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
// LIB_GLOBALS is deliberately not exhaustive — a feature bundle SHOULD contain its own
|
|
65
|
-
// feature code. So the catch-all is to pin what each bundle contains: anything new
|
|
66
|
-
// appearing here is either the feature growing or a primitive leaking in, and a human
|
|
67
|
-
// decides which. Without this, a `require('../mnemonic')` added to a module reachable
|
|
68
|
-
// from an externalised entry would bundle a second copy silently, with every existing
|
|
69
|
-
// test green.
|
|
70
|
-
it('contains only its own feature code, pinned per bundle', function () {
|
|
71
|
-
// Accepted in any bundle: stateless helpers, deliberately duplicated rather than
|
|
72
|
-
// routed through the global.
|
|
73
|
-
//
|
|
74
|
-
// Named FILES, not the directory. `lib/util/` as a prefix exempts anything added
|
|
75
|
-
// under it later, including something stateful — which is the property this test
|
|
76
|
-
// exists to prevent. Listing them means a new util file has to be considered.
|
|
77
|
-
//
|
|
78
|
-
// And listing ONLY what is actually embedded, for the same reason: naming a file
|
|
79
|
-
// that no bundle pulls in pre-approves it, so the consideration never happens.
|
|
80
|
-
// Measured — `lib/util/_.js` is the only one today. If a bundle starts needing
|
|
81
|
-
// another, this line should change in the same commit that causes it.
|
|
82
|
-
var SHARED = ['lib/util/_.js']
|
|
83
|
-
var EXPECTED = {
|
|
84
|
-
'bsv-ecies.min.js': ['lib/ecies/'],
|
|
85
|
-
'bsv-message.min.js': ['lib/message/'],
|
|
86
|
-
'bsv-mnemonic.min.js': ['lib/mnemonic/'],
|
|
87
|
-
'bsv-shamir.min.js': ['lib/crypto/'],
|
|
88
|
-
'bsv-smartcontract.min.js': ['lib/smart_contract/', 'lib/covenant/', 'lib/smartutxo.js'],
|
|
89
|
-
'bsv-covenant.min.js': ['lib/smart_contract/'],
|
|
90
|
-
'bsv-script-helper.min.js': ['lib/custom-script-helper.js']
|
|
91
|
-
}
|
|
92
|
-
var unexpected = []
|
|
93
|
-
Object.keys(inputsByBundle).forEach(function (file) {
|
|
94
|
-
var allowed = (EXPECTED[file] || []).concat(SHARED)
|
|
95
|
-
if (!EXPECTED[file]) {
|
|
96
|
-
unexpected.push(file + ' is externalised but has no expected-input list')
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
inputsByBundle[file].forEach(function (input) {
|
|
100
|
-
var ok = allowed.some(function (prefix) { return input.indexOf(prefix) === 0 })
|
|
101
|
-
if (!ok) unexpected.push(file + ' unexpectedly embeds ' + input)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
unexpected.should.deep.equal([])
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('shares nothing but documented helpers across bundles', function () {
|
|
108
|
-
// A module appearing in two feature bundles is a duplicated copy in the shipped
|
|
109
|
-
// set. Only these are accepted, and each is a deliberate call rather than an
|
|
110
|
-
// accident: lib/util/_.js is a tiny lodash subset, and lib/smart_contract/covenant.js
|
|
111
|
-
// is genuinely the feature of both covenant-flavoured bundles.
|
|
112
|
-
var ACCEPTED_DUPLICATES = ['lib/util/_.js', 'lib/smart_contract/covenant.js']
|
|
113
|
-
var seen = {}
|
|
114
|
-
Object.keys(inputsByBundle).forEach(function (file) {
|
|
115
|
-
inputsByBundle[file].forEach(function (input) {
|
|
116
|
-
(seen[input] = seen[input] || []).push(file)
|
|
117
|
-
})
|
|
118
|
-
})
|
|
119
|
-
var duplicated = Object.keys(seen)
|
|
120
|
-
.filter(function (p) { return seen[p].length > 1 })
|
|
121
|
-
.filter(function (p) { return ACCEPTED_DUPLICATES.indexOf(p) === -1 })
|
|
122
|
-
.sort()
|
|
123
|
-
duplicated.should.deep.equal([])
|
|
124
|
-
})
|
|
125
|
-
})
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// Cutover safety net for the webpack -> esbuild bundle migration: every SHIPPED bundle
|
|
6
|
-
// must load and expose an API. Each bundle is loaded in an ISOLATED child process (they
|
|
7
|
-
// are self-contained bsv builds; loading them all into one process would collide), with a
|
|
8
|
-
// global `bsv` present for the feature bundles that externalise it. Load/shape smoke only —
|
|
9
|
-
// full browser behaviour (window.crypto CSPRNG) is covered by the Chrome browser-smoke.
|
|
10
|
-
|
|
11
|
-
require('chai').should()
|
|
12
|
-
var path = require('path')
|
|
13
|
-
var execFileSync = require('child_process').execFileSync
|
|
14
|
-
|
|
15
|
-
var ROOT = path.resolve(__dirname, '../..')
|
|
16
|
-
|
|
17
|
-
// file -> a key that must be present on the loaded module (null = just needs a non-empty API).
|
|
18
|
-
var BUNDLES = {
|
|
19
|
-
'bsv.min.js': 'PrivateKey',
|
|
20
|
-
'bsv.bundle.js': 'PrivateKey',
|
|
21
|
-
'bsv-ecies.min.js': null,
|
|
22
|
-
'bsv-message.min.js': null,
|
|
23
|
-
'bsv-mnemonic.min.js': null,
|
|
24
|
-
'bsv-shamir.min.js': null,
|
|
25
|
-
'bsv-smartcontract.min.js': 'Covenant',
|
|
26
|
-
'bsv-covenant.min.js': null,
|
|
27
|
-
'bsv-script-helper.min.js': null,
|
|
28
|
-
'bsv-security.min.js': null,
|
|
29
|
-
'bsv-ltp.min.js': null,
|
|
30
|
-
'bsv-gdaf.min.js': null,
|
|
31
|
-
'bsv-didweb.min.js': null,
|
|
32
|
-
'bsv-vcjwt.min.js': null,
|
|
33
|
-
'bsv-statuslist.min.js': null,
|
|
34
|
-
'bsv-anchor.min.js': null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe('bundles: every shipped bundle loads (esbuild cutover)', function () {
|
|
38
|
-
this.timeout(20000)
|
|
39
|
-
|
|
40
|
-
Object.keys(BUNDLES).forEach(function (file) {
|
|
41
|
-
it(file + ' loads via require() and exposes an API', function () {
|
|
42
|
-
var key = BUNDLES[file]
|
|
43
|
-
var script =
|
|
44
|
-
'global.bsv=require(' + JSON.stringify(path.join(ROOT, 'index.js')) + ');' +
|
|
45
|
-
'var m=require(' + JSON.stringify(path.join(ROOT, file)) + ');' +
|
|
46
|
-
'if(m==null)process.exit(2);' +
|
|
47
|
-
'var ok=(typeof m==="function")||(typeof m==="object"&&Object.keys(m).length>0);' +
|
|
48
|
-
'if(!ok)process.exit(3);' +
|
|
49
|
-
(key ? 'if(m[' + JSON.stringify(key) + ']==null)process.exit(4);' : '') +
|
|
50
|
-
'process.exit(0)'
|
|
51
|
-
// execFileSync throws if the child exits non-zero (a broken/unloadable bundle).
|
|
52
|
-
execFileSync(process.execPath, ['-e', script], { stdio: 'pipe' })
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
})
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// Build-integrity gate for the esbuild bundler migration. Proves every browser bundle
|
|
6
|
-
// (all 16) builds — esbuild resolves each Node-core polyfill and, for the feature bundles,
|
|
7
|
-
// externalises the bsv root to the global `bsv` — and that the output is a real UMD module
|
|
8
|
-
// (browser global + require()/AMD). Full browser behaviour (Shamir CSPRNG via window.crypto)
|
|
9
|
-
// is validated by the Chrome browser-smoke against the full bundle.
|
|
10
|
-
|
|
11
|
-
require('chai').should()
|
|
12
|
-
var fs = require('fs')
|
|
13
|
-
var os = require('os')
|
|
14
|
-
var path = require('path')
|
|
15
|
-
var E = require('../../build/esbuild')
|
|
16
|
-
|
|
17
|
-
describe('esbuild: all browser bundles build', function () {
|
|
18
|
-
this.timeout(60000)
|
|
19
|
-
|
|
20
|
-
it('all ' + E.BUNDLES.length + ' bundles build with no unresolved modules', function () {
|
|
21
|
-
return Promise.all(E.BUNDLES.map(function (cfg) {
|
|
22
|
-
return E.buildOne(cfg, { write: false, logLevel: 'silent' }).then(function (res) {
|
|
23
|
-
res.errors.length.should.equal(0)
|
|
24
|
-
var js = res.outputFiles[0].text
|
|
25
|
-
js.length.should.be.above(20000) // smallest bundle (message) ~31KB; a broken build is tiny
|
|
26
|
-
js.indexOf('var ' + cfg.global + '=').should.be.above(-1) // IIFE global assignment
|
|
27
|
-
})
|
|
28
|
-
}))
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// UMD contract: the full bundle must load via CommonJS require() (as the webpack UMD bundle
|
|
32
|
-
// did). Browser <script> global is validated by the Chrome browser-smoke.
|
|
33
|
-
it('the full bundle is require()-able (UMD) with a working static API', function () {
|
|
34
|
-
return E.buildFullBundle({ write: false, logLevel: 'silent' }).then(function (res) {
|
|
35
|
-
var tmp = path.join(os.tmpdir(), 'bsv-esbuild-full-' + process.pid + '.js')
|
|
36
|
-
fs.writeFileSync(tmp, res.outputFiles[0].text)
|
|
37
|
-
try {
|
|
38
|
-
var bsv = require(tmp)
|
|
39
|
-
;(typeof bsv.PrivateKey).should.equal('function')
|
|
40
|
-
bsv.version.should.be.a('string')
|
|
41
|
-
bsv.crypto.Hash.sha256(bsv.deps.Buffer.from('x')).length.should.equal(32)
|
|
42
|
-
;(!!bsv.Ordinals && !!bsv.SPV).should.equal(true)
|
|
43
|
-
} finally { delete require.cache[tmp]; fs.unlinkSync(tmp) }
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// A feature bundle that externalises bsv (bsv-covenant) must load against a global `bsv`.
|
|
48
|
-
it('a feature bundle (bsv-covenant) loads against the global bsv', function () {
|
|
49
|
-
var cfg = E.BUNDLES.filter(function (c) { return c.file === 'bsv-covenant.min.js' })[0]
|
|
50
|
-
return E.buildOne(cfg, { write: false, logLevel: 'silent' }).then(function (res) {
|
|
51
|
-
var tmp = path.join(os.tmpdir(), 'bsv-esbuild-cov-' + process.pid + '.js')
|
|
52
|
-
fs.writeFileSync(tmp, res.outputFiles[0].text)
|
|
53
|
-
var had = 'bsv' in global // Node: global === globalThis, which the bundle reads
|
|
54
|
-
global.bsv = require('../..')
|
|
55
|
-
try {
|
|
56
|
-
var cov = require(tmp)
|
|
57
|
-
;(cov == null).should.equal(false)
|
|
58
|
-
Object.keys(cov).length.should.be.above(0)
|
|
59
|
-
} finally {
|
|
60
|
-
delete require.cache[tmp]; fs.unlinkSync(tmp)
|
|
61
|
-
if (!had) delete global.bsv
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
})
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// Guards index.mjs — the real ESM entry behind the package's `import` condition.
|
|
6
|
-
// Asserts (a) it hasn't drifted from the CJS surface, (b) native ESM default AND
|
|
7
|
-
// named imports actually work, and (c) deprecated getters (SmartUTXO) are NOT
|
|
8
|
-
// forced as named exports (they'd fire their warning on every import).
|
|
9
|
-
//
|
|
10
|
-
// ESM behaviour is exercised in a child process (via an --input-type=module
|
|
11
|
-
// script string) rather than a dynamic import() in this file, so the source
|
|
12
|
-
// stays parseable by the pinned standard@12 linter.
|
|
13
|
-
|
|
14
|
-
require('chai').should()
|
|
15
|
-
var fs = require('fs')
|
|
16
|
-
var path = require('path')
|
|
17
|
-
var execFileSync = require('child_process').execFileSync
|
|
18
|
-
var spawnSync = require('child_process').spawnSync
|
|
19
|
-
|
|
20
|
-
var ROOT = path.resolve(__dirname, '../..')
|
|
21
|
-
var MJS = path.join(ROOT, 'index.mjs')
|
|
22
|
-
|
|
23
|
-
// scripts/ is dev tooling and is not published, so the two checks that
|
|
24
|
-
// regenerate index.mjs can only run from a checkout. The ESM import checks below
|
|
25
|
-
// run everywhere, including against an installed copy. Presence is tested rather
|
|
26
|
-
// than try/catch'd so a broken generator still fails loudly in the repo.
|
|
27
|
-
var GEN = path.join(ROOT, 'scripts', 'gen-esm-wrapper.js')
|
|
28
|
-
var gen = fs.existsSync(GEN) ? require(GEN) : null
|
|
29
|
-
var itFromCheckout = gen ? it : it.skip
|
|
30
|
-
|
|
31
|
-
function runEsm (body) {
|
|
32
|
-
return execFileSync(process.execPath, ['--input-type=module', '-e', body],
|
|
33
|
-
{ cwd: ROOT, stdio: 'pipe' })
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe('ESM wrapper (index.mjs)', function () {
|
|
37
|
-
itFromCheckout('is in sync with the CJS surface (no drift)', function () {
|
|
38
|
-
var onDisk = fs.readFileSync(MJS, 'utf8')
|
|
39
|
-
onDisk.should.equal(gen.generate())
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
itFromCheckout('exports every non-accessor top-level member as a named binding', function () {
|
|
43
|
-
var bsv = require('../..')
|
|
44
|
-
var names = gen.exportableNames(bsv)
|
|
45
|
-
names.length.should.be.above(100)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
// The library currently has NO accessor properties — bsv.SmartUTXO, the last one,
|
|
49
|
-
// was removed in 9.0.0. The exclusion rule still matters: re-exporting a getter as a
|
|
50
|
-
// named ESM binding evaluates it at import time, which for a deprecated accessor
|
|
51
|
-
// means a warning (or worse, a side effect) fires on a bare `import`. Testing that
|
|
52
|
-
// against a synthetic accessor keeps the guarantee under test instead of letting it
|
|
53
|
-
// rot untested until someone adds a getter back.
|
|
54
|
-
itFromCheckout('excludes accessor properties from the named bindings', function () {
|
|
55
|
-
var bsv = require('../..')
|
|
56
|
-
var probe = '__esmAccessorProbe__'
|
|
57
|
-
var touched = false
|
|
58
|
-
Object.defineProperty(bsv, probe, {
|
|
59
|
-
configurable: true,
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function () { touched = true; return 1 }
|
|
62
|
-
})
|
|
63
|
-
try {
|
|
64
|
-
var names = gen.exportableNames(bsv)
|
|
65
|
-
names.should.not.include(probe)
|
|
66
|
-
touched.should.equal(false, 'exportableNames must not invoke the getter')
|
|
67
|
-
} finally {
|
|
68
|
-
delete bsv[probe]
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('resolves real ESM default + named imports natively', function () {
|
|
73
|
-
runEsm(
|
|
74
|
-
'import bsv, { PrivateKey, crypto } from ' + JSON.stringify('./index.mjs') + ';' +
|
|
75
|
-
'process.exit((bsv && typeof PrivateKey === "function" && ' +
|
|
76
|
-
'PrivateKey === bsv.PrivateKey && typeof crypto.ECDSA === "function") ? 0 : 3)')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('emits nothing on stderr at import', function () {
|
|
80
|
-
// Re-exporting a deprecated getter would trip its console.warn at import time;
|
|
81
|
-
// stderr must be empty for a bare `import './index.mjs'`.
|
|
82
|
-
var res = spawnSync(process.execPath,
|
|
83
|
-
['--input-type=module', '-e', 'import ' + JSON.stringify('./index.mjs') + ';'],
|
|
84
|
-
{ cwd: ROOT, encoding: 'utf8' })
|
|
85
|
-
res.status.should.equal(0)
|
|
86
|
-
res.stderr.should.equal('')
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('no longer exposes bsv.SmartUTXO, which was removed in 9.0.0', function () {
|
|
90
|
-
// Deliberately asserted rather than dropped: the namespace export is gone, and the
|
|
91
|
-
// module is reached by direct import — require('@smartledger/bsv/lib/smartutxo') —
|
|
92
|
-
// which is what its deprecation warning instructed from 4.0.1 onward.
|
|
93
|
-
runEsm(
|
|
94
|
-
'import bsv from ' + JSON.stringify('./index.mjs') + ';' +
|
|
95
|
-
'process.exit(("SmartUTXO" in bsv) ? 3 : 0)')
|
|
96
|
-
})
|
|
97
|
-
})
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// Guards the 7.0 package.json `exports` map. Adding `exports` switches Node to
|
|
6
|
-
// strict subpath resolution, so this asserts the surface consumers actually use
|
|
7
|
-
// still resolves (via package self-reference, which Node enables once `exports`
|
|
8
|
-
// exists): the main entry, package.json, ./version, the shipped bundles, and
|
|
9
|
-
// lib/* deep imports in BOTH extension styles. Also smoke-tests the ESM `import`
|
|
10
|
-
// condition in a child process so the dual-ready "." entry can't silently rot.
|
|
11
|
-
|
|
12
|
-
require('chai').should()
|
|
13
|
-
var fs = require('fs')
|
|
14
|
-
var path = require('path')
|
|
15
|
-
var execFileSync = require('child_process').execFileSync
|
|
16
|
-
|
|
17
|
-
var N = '@smartledger/bsv'
|
|
18
|
-
var ROOT = path.resolve(__dirname, '../..')
|
|
19
|
-
|
|
20
|
-
describe('7.0 exports map resolution', function () {
|
|
21
|
-
it('resolves the main entry via self-reference', function () {
|
|
22
|
-
var bsv = require(N)
|
|
23
|
-
bsv.should.be.an('object')
|
|
24
|
-
bsv.PrivateKey.should.be.a('function')
|
|
25
|
-
bsv.crypto.ECDSA.should.be.a('function')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('exposes package.json and ./version, and they agree', function () {
|
|
29
|
-
var pkg = require(N + '/package.json')
|
|
30
|
-
var version = require(N + '/version')
|
|
31
|
-
pkg.name.should.equal(N)
|
|
32
|
-
version.should.equal(pkg.version)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('resolves lib/* deep imports with and without the .js extension', function () {
|
|
36
|
-
var withExt = require(N + '/lib/crypto/ecdsa.js')
|
|
37
|
-
var noExt = require(N + '/lib/crypto/ecdsa')
|
|
38
|
-
withExt.should.be.a('function')
|
|
39
|
-
noExt.should.equal(withExt) // same module, one cache entry
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// `./lib/*` maps to `./lib/*.js`, so a DIRECTORY module (lib/script, lib/ordinals,
|
|
43
|
-
// ...) did not resolve at all — `require('@smartledger/bsv/lib/script')` raised
|
|
44
|
-
// MODULE_NOT_FOUND, because there is no lib/script.js. Explicit entries now point each
|
|
45
|
-
// directory at its index.js. Every directory under lib/ that has one is listed, so a
|
|
46
|
-
// new module cannot be added without also being exported.
|
|
47
|
-
it('resolves every lib/ directory module by its bare directory name', function () {
|
|
48
|
-
var libDir = path.join(ROOT, 'lib')
|
|
49
|
-
var dirs = fs.readdirSync(libDir).filter(function (d) {
|
|
50
|
-
return fs.existsSync(path.join(libDir, d, 'index.js'))
|
|
51
|
-
})
|
|
52
|
-
dirs.length.should.be.above(0)
|
|
53
|
-
dirs.forEach(function (d) {
|
|
54
|
-
var bare = require(N + '/lib/' + d)
|
|
55
|
-
var explicit = require(N + '/lib/' + d + '/index.js')
|
|
56
|
-
;(bare === explicit).should.equal(true) // same module, one cache entry
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('still resolves lib/ FILE modules, which share the same pattern', function () {
|
|
61
|
-
var noExt = require(N + '/lib/address')
|
|
62
|
-
var withExt = require(N + '/lib/address.js')
|
|
63
|
-
;(noExt === withExt).should.equal(true)
|
|
64
|
-
noExt.should.be.a('function')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('serves the full browser bundle over a subpath (loaded in isolation)', function () {
|
|
68
|
-
// The bundle is a self-contained bsv; loading it in-process collides with the
|
|
69
|
-
// main require above ("multiple bsv instances"), so resolve+load it in a child.
|
|
70
|
-
var script = 'var m=require(' + JSON.stringify(N + '/bsv.min.js') + ');' +
|
|
71
|
-
'process.exit(m && m.PrivateKey ? 0 : 3)'
|
|
72
|
-
execFileSync(process.execPath, ['-e', script], { cwd: ROOT, stdio: 'pipe' })
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('routes the ESM `import` condition to index.mjs with default AND named exports', function () {
|
|
76
|
-
// Proves the dual-ESM entry end-to-end through the package specifier: the
|
|
77
|
-
// `import` condition resolves to index.mjs, which exposes real named bindings.
|
|
78
|
-
var script =
|
|
79
|
-
'import bsv, { PrivateKey, Transaction, crypto } from ' + JSON.stringify(N) + ';' +
|
|
80
|
-
'process.exit((bsv && bsv.PrivateKey && PrivateKey === bsv.PrivateKey && ' +
|
|
81
|
-
'typeof Transaction === "function" && typeof crypto.ECDSA === "function") ? 0 : 3)'
|
|
82
|
-
execFileSync(process.execPath, ['--input-type=module', '-e', script], { cwd: ROOT, stdio: 'pipe' })
|
|
83
|
-
})
|
|
84
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// version.js is generated from package.json by the `version` npm hook so the bundles
|
|
6
|
-
// embed only the version string (not the whole package.json). Assert it hasn't drifted.
|
|
7
|
-
|
|
8
|
-
require('chai').should()
|
|
9
|
-
|
|
10
|
-
describe('version.js stays in sync with package.json', function () {
|
|
11
|
-
it('version.js === package.json.version', function () {
|
|
12
|
-
require('../../version').should.equal(require('../../package.json').version)
|
|
13
|
-
})
|
|
14
|
-
})
|