web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

528 lines
20 KiB

  1. # ssri [![npm version](https://img.shields.io/npm/v/ssri.svg)](https://npm.im/ssri) [![license](https://img.shields.io/npm/l/ssri.svg)](https://npm.im/ssri) [![Travis](https://img.shields.io/travis/npm/ssri.svg)](https://travis-ci.org/npm/ssri) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/npm/ssri?svg=true)](https://ci.appveyor.com/project/npm/ssri) [![Coverage Status](https://coveralls.io/repos/github/npm/ssri/badge.svg?branch=latest)](https://coveralls.io/github/npm/ssri?branch=latest)
  2. [`ssri`](https://github.com/npm/ssri), short for Standard Subresource
  3. Integrity, is a Node.js utility for parsing, manipulating, serializing,
  4. generating, and verifying [Subresource
  5. Integrity](https://w3c.github.io/webappsec/specs/subresourceintegrity/) hashes.
  6. ## Install
  7. `$ npm install --save ssri`
  8. ## Table of Contents
  9. * [Example](#example)
  10. * [Features](#features)
  11. * [Contributing](#contributing)
  12. * [API](#api)
  13. * Parsing & Serializing
  14. * [`parse`](#parse)
  15. * [`stringify`](#stringify)
  16. * [`Integrity#concat`](#integrity-concat)
  17. * [`Integrity#merge`](#integrity-merge)
  18. * [`Integrity#toString`](#integrity-to-string)
  19. * [`Integrity#toJSON`](#integrity-to-json)
  20. * [`Integrity#match`](#integrity-match)
  21. * [`Integrity#pickAlgorithm`](#integrity-pick-algorithm)
  22. * [`Integrity#hexDigest`](#integrity-hex-digest)
  23. * Integrity Generation
  24. * [`fromHex`](#from-hex)
  25. * [`fromData`](#from-data)
  26. * [`fromStream`](#from-stream)
  27. * [`create`](#create)
  28. * Integrity Verification
  29. * [`checkData`](#check-data)
  30. * [`checkStream`](#check-stream)
  31. * [`integrityStream`](#integrity-stream)
  32. ### Example
  33. ```javascript
  34. const ssri = require('ssri')
  35. const integrity = 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo'
  36. // Parsing and serializing
  37. const parsed = ssri.parse(integrity)
  38. ssri.stringify(parsed) // === integrity (works on non-Integrity objects)
  39. parsed.toString() // === integrity
  40. // Async stream functions
  41. ssri.checkStream(fs.createReadStream('./my-file'), integrity).then(...)
  42. ssri.fromStream(fs.createReadStream('./my-file')).then(sri => {
  43. sri.toString() === integrity
  44. })
  45. fs.createReadStream('./my-file').pipe(ssri.createCheckerStream(sri))
  46. // Sync data functions
  47. ssri.fromData(fs.readFileSync('./my-file')) // === parsed
  48. ssri.checkData(fs.readFileSync('./my-file'), integrity) // => 'sha512'
  49. ```
  50. ### Features
  51. * Parses and stringifies SRI strings.
  52. * Generates SRI strings from raw data or Streams.
  53. * Strict standard compliance.
  54. * `?foo` metadata option support.
  55. * Multiple entries for the same algorithm.
  56. * Object-based integrity hash manipulation.
  57. * Small footprint: no dependencies, concise implementation.
  58. * Full test coverage.
  59. * Customizable algorithm picker.
  60. ### Contributing
  61. The ssri team enthusiastically welcomes contributions and project participation!
  62. There's a bunch of things you can do if you want to contribute! The [Contributor
  63. Guide](CONTRIBUTING.md) has all the information you need for everything from
  64. reporting bugs to contributing entire new features. Please don't hesitate to
  65. jump in if you'd like to, or even ask us questions if something isn't clear.
  66. ### API
  67. #### <a name="parse"></a> `> ssri.parse(sri, [opts]) -> Integrity`
  68. Parses `sri` into an `Integrity` data structure. `sri` can be an integrity
  69. string, an `Hash`-like with `digest` and `algorithm` fields and an optional
  70. `options` field, or an `Integrity`-like object. The resulting object will be an
  71. `Integrity` instance that has this shape:
  72. ```javascript
  73. {
  74. 'sha1': [{algorithm: 'sha1', digest: 'deadbeef', options: []}],
  75. 'sha512': [
  76. {algorithm: 'sha512', digest: 'c0ffee', options: []},
  77. {algorithm: 'sha512', digest: 'bad1dea', options: ['foo']}
  78. ],
  79. }
  80. ```
  81. If `opts.single` is truthy, a single `Hash` object will be returned. That is, a
  82. single object that looks like `{algorithm, digest, options}`, as opposed to a
  83. larger object with multiple of these.
  84. If `opts.strict` is truthy, the resulting object will be filtered such that
  85. it strictly follows the Subresource Integrity spec, throwing away any entries
  86. with any invalid components. This also means a restricted set of algorithms
  87. will be used -- the spec limits them to `sha256`, `sha384`, and `sha512`.
  88. Strict mode is recommended if the integrity strings are intended for use in
  89. browsers, or in other situations where strict adherence to the spec is needed.
  90. ##### Example
  91. ```javascript
  92. ssri.parse('sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo') // -> Integrity object
  93. ```
  94. #### <a name="stringify"></a> `> ssri.stringify(sri, [opts]) -> String`
  95. This function is identical to [`Integrity#toString()`](#integrity-to-string),
  96. except it can be used on _any_ object that [`parse`](#parse) can handle -- that
  97. is, a string, an `Hash`-like, or an `Integrity`-like.
  98. The `opts.sep` option defines the string to use when joining multiple entries
  99. together. To be spec-compliant, this _must_ be whitespace. The default is a
  100. single space (`' '`).
  101. If `opts.strict` is true, the integrity string will be created using strict
  102. parsing rules. See [`ssri.parse`](#parse).
  103. ##### Example
  104. ```javascript
  105. // Useful for cleaning up input SRI strings:
  106. ssri.stringify('\n\rsha512-foo\n\t\tsha384-bar')
  107. // -> 'sha512-foo sha384-bar'
  108. // Hash-like: only a single entry.
  109. ssri.stringify({
  110. algorithm: 'sha512',
  111. digest:'9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==',
  112. options: ['foo']
  113. })
  114. // ->
  115. // 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo'
  116. // Integrity-like: full multi-entry syntax. Similar to output of `ssri.parse`
  117. ssri.stringify({
  118. 'sha512': [
  119. {
  120. algorithm: 'sha512',
  121. digest:'9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==',
  122. options: ['foo']
  123. }
  124. ]
  125. })
  126. // ->
  127. // 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo'
  128. ```
  129. #### <a name="integrity-concat"></a> `> Integrity#concat(otherIntegrity, [opts]) -> Integrity`
  130. Concatenates an `Integrity` object with another IntegrityLike, or an integrity
  131. string.
  132. This is functionally equivalent to concatenating the string format of both
  133. integrity arguments, and calling [`ssri.parse`](#ssri-parse) on the new string.
  134. If `opts.strict` is true, the new `Integrity` will be created using strict
  135. parsing rules. See [`ssri.parse`](#parse).
  136. ##### Example
  137. ```javascript
  138. // This will combine the integrity checks for two different versions of
  139. // your index.js file so you can use a single integrity string and serve
  140. // either of these to clients, from a single `<script>` tag.
  141. const desktopIntegrity = ssri.fromData(fs.readFileSync('./index.desktop.js'))
  142. const mobileIntegrity = ssri.fromData(fs.readFileSync('./index.mobile.js'))
  143. // Note that browsers (and ssri) will succeed as long as ONE of the entries
  144. // for the *prioritized* algorithm succeeds. That is, in order for this fallback
  145. // to work, both desktop and mobile *must* use the same `algorithm` values.
  146. desktopIntegrity.concat(mobileIntegrity)
  147. ```
  148. #### <a name="integrity-merge"></a> `> Integrity#merge(otherIntegrity, [opts])`
  149. Safely merges another IntegrityLike or integrity string into an `Integrity`
  150. object.
  151. If the other integrity value has any algorithms in common with the current
  152. object, then the hash digests must match, or an error is thrown.
  153. Any new hashes will be added to the current object's set.
  154. This is useful when an integrity value may be upgraded with a stronger
  155. algorithm, you wish to prevent accidentally supressing integrity errors by
  156. overwriting the expected integrity value.
  157. ##### Example
  158. ```javascript
  159. const data = fs.readFileSync('data.txt')
  160. // integrity.txt contains 'sha1-X1UT+IIv2+UUWvM7ZNjZcNz5XG4='
  161. // because we were young, and didn't realize sha1 would not last
  162. const expectedIntegrity = ssri.parse(fs.readFileSync('integrity.txt', 'utf8'))
  163. const match = ssri.checkData(data, expectedIntegrity, {
  164. algorithms: ['sha512', 'sha1']
  165. })
  166. if (!match) {
  167. throw new Error('data corrupted or something!')
  168. }
  169. // get a stronger algo!
  170. if (match && match.algorithm !== 'sha512') {
  171. const updatedIntegrity = ssri.fromData(data, { algorithms: ['sha512'] })
  172. expectedIntegrity.merge(updatedIntegrity)
  173. fs.writeFileSync('integrity.txt', expectedIntegrity.toString())
  174. // file now contains
  175. // 'sha1-X1UT+IIv2+UUWvM7ZNjZcNz5XG4= sha512-yzd8ELD1piyANiWnmdnpCL5F52f10UfUdEkHywVZeqTt0ymgrxR63Qz0GB7TKPoeeZQmWCaz7T1+9vBnypkYWg=='
  176. }
  177. ```
  178. #### <a name="integrity-to-string"></a> `> Integrity#toString([opts]) -> String`
  179. Returns the string representation of an `Integrity` object. All hash entries
  180. will be concatenated in the string by `opts.sep`, which defaults to `' '`.
  181. If you want to serialize an object that didn't come from an `ssri` function,
  182. use [`ssri.stringify()`](#stringify).
  183. If `opts.strict` is true, the integrity string will be created using strict
  184. parsing rules. See [`ssri.parse`](#parse).
  185. ##### Example
  186. ```javascript
  187. const integrity = 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo'
  188. ssri.parse(integrity).toString() === integrity
  189. ```
  190. #### <a name="integrity-to-json"></a> `> Integrity#toJSON() -> String`
  191. Returns the string representation of an `Integrity` object. All hash entries
  192. will be concatenated in the string by `' '`.
  193. This is a convenience method so you can pass an `Integrity` object directly to `JSON.stringify`.
  194. For more info check out [toJSON() behavior on mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON%28%29_behavior).
  195. ##### Example
  196. ```javascript
  197. const integrity = '"sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo"'
  198. JSON.stringify(ssri.parse(integrity)) === integrity
  199. ```
  200. #### <a name="integrity-match"></a> `> Integrity#match(sri, [opts]) -> Hash | false`
  201. Returns the matching (truthy) hash if `Integrity` matches the argument passed as
  202. `sri`, which can be anything that [`parse`](#parse) will accept. `opts` will be
  203. passed through to `parse` and [`pickAlgorithm()`](#integrity-pick-algorithm).
  204. ##### Example
  205. ```javascript
  206. const integrity = 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A=='
  207. ssri.parse(integrity).match(integrity)
  208. // Hash {
  209. // digest: '9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A=='
  210. // algorithm: 'sha512'
  211. // }
  212. ssri.parse(integrity).match('sha1-deadbeef')
  213. // false
  214. ```
  215. #### <a name="integrity-pick-algorithm"></a> `> Integrity#pickAlgorithm([opts]) -> String`
  216. Returns the "best" algorithm from those available in the integrity object.
  217. If `opts.pickAlgorithm` is provided, it will be passed two algorithms as
  218. arguments. ssri will prioritize whichever of the two algorithms is returned by
  219. this function. Note that the function may be called multiple times, and it
  220. **must** return one of the two algorithms provided. By default, ssri will make
  221. a best-effort to pick the strongest/most reliable of the given algorithms. It
  222. may intentionally deprioritize algorithms with known vulnerabilities.
  223. ##### Example
  224. ```javascript
  225. ssri.parse('sha1-WEakDigEST sha512-yzd8ELD1piyANiWnmdnpCL5F52f10UfUdEkHywVZeqTt0ymgrxR63Qz0GB7TKPoeeZQmWCaz7T1').pickAlgorithm() // sha512
  226. ```
  227. #### <a name="integrity-hex-digest"></a> `> Integrity#hexDigest() -> String`
  228. `Integrity` is assumed to be either a single-hash `Integrity` instance, or a
  229. `Hash` instance. Returns its `digest`, converted to a hex representation of the
  230. base64 data.
  231. ##### Example
  232. ```javascript
  233. ssri.parse('sha1-deadbeef').hexDigest() // '75e69d6de79f'
  234. ```
  235. #### <a name="from-hex"></a> `> ssri.fromHex(hexDigest, algorithm, [opts]) -> Integrity`
  236. Creates an `Integrity` object with a single entry, based on a hex-formatted
  237. hash. This is a utility function to help convert existing shasums to the
  238. Integrity format, and is roughly equivalent to something like:
  239. ```javascript
  240. algorithm + '-' + Buffer.from(hexDigest, 'hex').toString('base64')
  241. ```
  242. `opts.options` may optionally be passed in: it must be an array of option
  243. strings that will be added to all generated integrity hashes generated by
  244. `fromData`. This is a loosely-specified feature of SRIs, and currently has no
  245. specified semantics besides being `?`-separated. Use at your own risk, and
  246. probably avoid if your integrity strings are meant to be used with browsers.
  247. If `opts.strict` is true, the integrity object will be created using strict
  248. parsing rules. See [`ssri.parse`](#parse).
  249. If `opts.single` is true, a single `Hash` object will be returned.
  250. ##### Example
  251. ```javascript
  252. ssri.fromHex('75e69d6de79f', 'sha1').toString() // 'sha1-deadbeef'
  253. ```
  254. #### <a name="from-data"></a> `> ssri.fromData(data, [opts]) -> Integrity`
  255. Creates an `Integrity` object from either string or `Buffer` data, calculating
  256. all the requested hashes and adding any specified options to the object.
  257. `opts.algorithms` determines which algorithms to generate hashes for. All
  258. results will be included in a single `Integrity` object. The default value for
  259. `opts.algorithms` is `['sha512']`. All algorithm strings must be hashes listed
  260. in `crypto.getHashes()` for the host Node.js platform.
  261. `opts.options` may optionally be passed in: it must be an array of option
  262. strings that will be added to all generated integrity hashes generated by
  263. `fromData`. This is a loosely-specified feature of SRIs, and currently has no
  264. specified semantics besides being `?`-separated. Use at your own risk, and
  265. probably avoid if your integrity strings are meant to be used with browsers.
  266. If `opts.strict` is true, the integrity object will be created using strict
  267. parsing rules. See [`ssri.parse`](#parse).
  268. ##### Example
  269. ```javascript
  270. const integrityObj = ssri.fromData('foobarbaz', {
  271. algorithms: ['sha256', 'sha384', 'sha512']
  272. })
  273. integrity.toString('\n')
  274. // ->
  275. // sha256-l981iLWj8kurw4UbNy8Lpxqdzd7UOxS50Glhv8FwfZ0=
  276. // sha384-irnCxQ0CfQhYGlVAUdwTPC9bF3+YWLxlaDGM4xbYminxpbXEq+D+2GCEBTxcjES9
  277. // sha512-yzd8ELD1piyANiWnmdnpCL5F52f10UfUdEkHywVZeqTt0ymgrxR63Qz0GB7TKPoeeZQmWCaz7T1+9vBnypkYWg==
  278. ```
  279. #### <a name="from-stream"></a> `> ssri.fromStream(stream, [opts]) -> Promise<Integrity>`
  280. Returns a Promise of an Integrity object calculated by reading data from
  281. a given `stream`.
  282. It accepts both `opts.algorithms` and `opts.options`, which are documented as
  283. part of [`ssri.fromData`](#from-data).
  284. Additionally, `opts.Promise` may be passed in to inject a Promise library of
  285. choice. By default, ssri will use Node's built-in Promises.
  286. If `opts.strict` is true, the integrity object will be created using strict
  287. parsing rules. See [`ssri.parse`](#parse).
  288. ##### Example
  289. ```javascript
  290. ssri.fromStream(fs.createReadStream('index.js'), {
  291. algorithms: ['sha1', 'sha512']
  292. }).then(integrity => {
  293. return ssri.checkStream(fs.createReadStream('index.js'), integrity)
  294. }) // succeeds
  295. ```
  296. #### <a name="create"></a> `> ssri.create([opts]) -> <Hash>`
  297. Returns a Hash object with `update(<Buffer or string>[,enc])` and `digest()` methods.
  298. The Hash object provides the same methods as [crypto class Hash](https://nodejs.org/dist/latest-v6.x/docs/api/crypto.html#crypto_class_hash).
  299. `digest()` accepts no arguments and returns an Integrity object calculated by reading data from
  300. calls to update.
  301. It accepts both `opts.algorithms` and `opts.options`, which are documented as
  302. part of [`ssri.fromData`](#from-data).
  303. If `opts.strict` is true, the integrity object will be created using strict
  304. parsing rules. See [`ssri.parse`](#parse).
  305. ##### Example
  306. ```javascript
  307. const integrity = ssri.create().update('foobarbaz').digest()
  308. integrity.toString()
  309. // ->
  310. // sha512-yzd8ELD1piyANiWnmdnpCL5F52f10UfUdEkHywVZeqTt0ymgrxR63Qz0GB7TKPoeeZQmWCaz7T1+9vBnypkYWg==
  311. ```
  312. #### <a name="check-data"></a> `> ssri.checkData(data, sri, [opts]) -> Hash|false`
  313. Verifies `data` integrity against an `sri` argument. `data` may be either a
  314. `String` or a `Buffer`, and `sri` can be any subresource integrity
  315. representation that [`ssri.parse`](#parse) can handle.
  316. If verification succeeds, `checkData` will return the name of the algorithm that
  317. was used for verification (a truthy value). Otherwise, it will return `false`.
  318. If `opts.pickAlgorithm` is provided, it will be used by
  319. [`Integrity#pickAlgorithm`](#integrity-pick-algorithm) when deciding which of
  320. the available digests to match against.
  321. If `opts.error` is true, and verification fails, `checkData` will throw either
  322. an `EBADSIZE` or an `EINTEGRITY` error, instead of just returning false.
  323. ##### Example
  324. ```javascript
  325. const data = fs.readFileSync('index.js')
  326. ssri.checkData(data, ssri.fromData(data)) // -> 'sha512'
  327. ssri.checkData(data, 'sha256-l981iLWj8kurw4UbNy8Lpxqdzd7UOxS50Glhv8FwfZ0')
  328. ssri.checkData(data, 'sha1-BaDDigEST') // -> false
  329. ssri.checkData(data, 'sha1-BaDDigEST', {error: true}) // -> Error! EINTEGRITY
  330. ```
  331. #### <a name="check-stream"></a> `> ssri.checkStream(stream, sri, [opts]) -> Promise<Hash>`
  332. Verifies the contents of `stream` against an `sri` argument. `stream` will be
  333. consumed in its entirety by this process. `sri` can be any subresource integrity
  334. representation that [`ssri.parse`](#parse) can handle.
  335. `checkStream` will return a Promise that either resolves to the
  336. `Hash` that succeeded verification, or, if the verification fails
  337. or an error happens with `stream`, the Promise will be rejected.
  338. If the Promise is rejected because verification failed, the returned error will
  339. have `err.code` as `EINTEGRITY`.
  340. If `opts.size` is given, it will be matched against the stream size. An error
  341. with `err.code` `EBADSIZE` will be returned by a rejection if the expected size
  342. and actual size fail to match.
  343. If `opts.pickAlgorithm` is provided, it will be used by
  344. [`Integrity#pickAlgorithm`](#integrity-pick-algorithm) when deciding which of
  345. the available digests to match against.
  346. ##### Example
  347. ```javascript
  348. const integrity = ssri.fromData(fs.readFileSync('index.js'))
  349. ssri.checkStream(
  350. fs.createReadStream('index.js'),
  351. integrity
  352. )
  353. // ->
  354. // Promise<{
  355. // algorithm: 'sha512',
  356. // digest: 'sha512-yzd8ELD1piyANiWnmdnpCL5F52f10UfUdEkHywVZeqTt0ymgrxR63Qz0GB7TKPoeeZQmWCaz7T1'
  357. // }>
  358. ssri.checkStream(
  359. fs.createReadStream('index.js'),
  360. 'sha256-l981iLWj8kurw4UbNy8Lpxqdzd7UOxS50Glhv8FwfZ0'
  361. ) // -> Promise<Hash>
  362. ssri.checkStream(
  363. fs.createReadStream('index.js'),
  364. 'sha1-BaDDigEST'
  365. ) // -> Promise<Error<{code: 'EINTEGRITY'}>>
  366. ```
  367. #### <a name="integrity-stream"></a> `> integrityStream([opts]) -> IntegrityStream`
  368. Returns a `Transform` stream that data can be piped through in order to generate
  369. and optionally check data integrity for piped data. When the stream completes
  370. successfully, it emits `size` and `integrity` events, containing the total
  371. number of bytes processed and a calculated `Integrity` instance based on stream
  372. data, respectively.
  373. If `opts.algorithms` is passed in, the listed algorithms will be calculated when
  374. generating the final `Integrity` instance. The default is `['sha512']`.
  375. If `opts.single` is passed in, a single `Hash` instance will be returned.
  376. If `opts.integrity` is passed in, it should be an `integrity` value understood
  377. by [`parse`](#parse) that the stream will check the data against. If
  378. verification succeeds, the integrity stream will emit a `verified` event whose
  379. value is a single `Hash` object that is the one that succeeded verification. If
  380. verification fails, the stream will error with an `EINTEGRITY` error code.
  381. If `opts.size` is given, it will be matched against the stream size. An error
  382. with `err.code` `EBADSIZE` will be emitted by the stream if the expected size
  383. and actual size fail to match.
  384. If `opts.pickAlgorithm` is provided, it will be passed two algorithms as
  385. arguments. ssri will prioritize whichever of the two algorithms is returned by
  386. this function. Note that the function may be called multiple times, and it
  387. **must** return one of the two algorithms provided. By default, ssri will make
  388. a best-effort to pick the strongest/most reliable of the given algorithms. It
  389. may intentionally deprioritize algorithms with known vulnerabilities.
  390. ##### Example
  391. ```javascript
  392. const integrity = ssri.fromData(fs.readFileSync('index.js'))
  393. fs.createReadStream('index.js')
  394. .pipe(ssri.integrityStream({integrity}))
  395. ```