@smartledger/bsv 7.11.0 → 7.12.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 +63 -0
- package/README.md +38 -38
- package/bsv-anchor.min.js +11 -17
- package/bsv-didweb.min.js +11 -17
- package/bsv-gdaf.min.js +69 -75
- package/bsv-ltp.min.js +55 -61
- package/bsv-mnemonic.min.js +11 -17
- package/bsv-shamir.min.js +11 -17
- package/bsv-smartcontract.min.js +1 -1
- package/bsv-statuslist.min.js +53 -59
- package/bsv-vcjwt.min.js +11 -17
- package/bsv.bundle.js +69 -75
- package/bsv.min.js +69 -75
- package/build/esbuild/crypto-shim.js +35 -0
- package/build/esbuild.js +7 -3
- package/docs/AUDIT_SCOPE.md +199 -0
- 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/package.json +13 -2
- package/test/build/bundle_crypto_shim.js +104 -0
- package/test/build/bundle_externals.js +6 -1
- package/version.js +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* global describe, it, before */
|
|
4
|
+
|
|
5
|
+
// The browser `crypto` polyfill is our own three-function shim, not crypto-browserify.
|
|
6
|
+
//
|
|
7
|
+
// Two things have to hold, and neither is visible to a test that stays inside lib/.
|
|
8
|
+
//
|
|
9
|
+
// 1. `elliptic` must not re-enter the bundles. It carries an advisory with no patched
|
|
10
|
+
// version, and it is reachable from crypto-browserify via browserify-sign and
|
|
11
|
+
// create-ecdh. build/esbuild.js used to keep it out with a hand-written onResolve
|
|
12
|
+
// stub; removing crypto-browserify removed the need for the stub, and this file
|
|
13
|
+
// replaces it. A stub is silent when it stops matching — an assertion is not.
|
|
14
|
+
//
|
|
15
|
+
// 2. The shim must keep implementing what the bundles actually call. If someone adds a
|
|
16
|
+
// `crypto.pbkdf2` call to a bundled module, resolution still succeeds and the member
|
|
17
|
+
// is simply `undefined`, so the failure surfaces far from its cause.
|
|
18
|
+
//
|
|
19
|
+
// The known-answer test exists because "the bundle builds" and "the bundle hashes
|
|
20
|
+
// correctly" are different claims, and only the second one matters to a caller.
|
|
21
|
+
|
|
22
|
+
require('chai').should()
|
|
23
|
+
var crypto = require('crypto')
|
|
24
|
+
var esbuild = require('../../build/esbuild.js')
|
|
25
|
+
var shim = require('../../build/esbuild/crypto-shim.js')
|
|
26
|
+
|
|
27
|
+
// Reachable from crypto-browserify; `elliptic` is the one with no fix available.
|
|
28
|
+
var BANNED = ['elliptic', 'browserify-sign', 'create-ecdh', 'crypto-browserify']
|
|
29
|
+
|
|
30
|
+
describe('browser crypto shim', function () {
|
|
31
|
+
this.timeout(300000)
|
|
32
|
+
|
|
33
|
+
var pkgsByBundle = {}
|
|
34
|
+
|
|
35
|
+
before(function () {
|
|
36
|
+
return Promise.all(esbuild.BUNDLES.map(function (cfg) {
|
|
37
|
+
return esbuild.buildOne(cfg, { metafile: true, write: false, logLevel: 'silent' })
|
|
38
|
+
.then(function (result) {
|
|
39
|
+
pkgsByBundle[cfg.file] = Object.keys(result.metafile.inputs)
|
|
40
|
+
.map(function (p) {
|
|
41
|
+
var m = /node_modules\/((?:@[^/]+\/)?[^/]+)\//.exec(p)
|
|
42
|
+
return m && m[1]
|
|
43
|
+
})
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
})
|
|
46
|
+
}))
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('built every bundle', function () {
|
|
50
|
+
esbuild.BUNDLES.length.should.be.above(0)
|
|
51
|
+
Object.keys(pkgsByBundle).length.should.equal(esbuild.BUNDLES.length)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Guard against the graph being empty for an unrelated reason, which would make the
|
|
55
|
+
// "no banned packages" assertion below pass without checking anything.
|
|
56
|
+
it('resolved a non-trivial dependency graph', function () {
|
|
57
|
+
Object.keys(pkgsByBundle).forEach(function (file) {
|
|
58
|
+
pkgsByBundle[file].length.should.be.above(0, file + ' has no node_modules inputs')
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('pulls no part of the elliptic chain into any bundle', function () {
|
|
63
|
+
var offenders = []
|
|
64
|
+
Object.keys(pkgsByBundle).forEach(function (file) {
|
|
65
|
+
BANNED.forEach(function (pkg) {
|
|
66
|
+
if (pkgsByBundle[file].indexOf(pkg) !== -1) offenders.push(file + ' → ' + pkg)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
offenders.should.deep.equal([])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('exports exactly the members the bundles call', function () {
|
|
73
|
+
Object.keys(shim).sort().should.deep.equal(['createHash', 'createHmac', 'randomBytes'])
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Deliberately absent: secrets.js-grempe prefers getRandomValues over randomBytes when
|
|
77
|
+
// it is present, so exporting it would silently move the Shamir CSPRNG to another code
|
|
78
|
+
// path. crypto-browserify did not expose it either.
|
|
79
|
+
it('does not expose getRandomValues', function () {
|
|
80
|
+
;(shim.getRandomValues === undefined).should.equal(true)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('hashes identically to node crypto', function () {
|
|
84
|
+
['', 'abc', 'The quick brown fox jumps over the lazy dog'].forEach(function (input) {
|
|
85
|
+
;['sha1', 'sha256', 'sha512', 'ripemd160'].forEach(function (alg) {
|
|
86
|
+
shim.createHash(alg).update(input).digest('hex')
|
|
87
|
+
.should.equal(crypto.createHash(alg).update(input).digest('hex'), alg + ' of ' + JSON.stringify(input))
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('hmacs identically to node crypto', function () {
|
|
93
|
+
shim.createHmac('sha512', Buffer.from('key')).update('message').digest('hex')
|
|
94
|
+
.should.equal(crypto.createHmac('sha512', Buffer.from('key')).update('message').digest('hex'))
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('draws distinct random bytes of the requested length', function () {
|
|
98
|
+
var a = shim.randomBytes(32)
|
|
99
|
+
var b = shim.randomBytes(32)
|
|
100
|
+
a.length.should.equal(32)
|
|
101
|
+
b.length.should.equal(32)
|
|
102
|
+
a.toString('hex').should.not.equal(b.toString('hex'))
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -74,7 +74,12 @@ describe('feature bundles externalise the shared primitives', function () {
|
|
|
74
74
|
// Named FILES, not the directory. `lib/util/` as a prefix exempts anything added
|
|
75
75
|
// under it later, including something stateful — which is the property this test
|
|
76
76
|
// exists to prevent. Listing them means a new util file has to be considered.
|
|
77
|
-
|
|
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']
|
|
78
83
|
var EXPECTED = {
|
|
79
84
|
'bsv-ecies.min.js': ['lib/ecies/'],
|
|
80
85
|
'bsv-message.min.js': ['lib/message/'],
|
package/version.js
CHANGED