How to use the ssri.fromData function in ssri

To help you get started, we’ve selected a few ssri examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Leaflet / Leaflet / build / integrity.js View on Github external
// This script calculates the integrity hashes of the files in dist/ , and
// **overwrites** the values in the documentation.

var ssri = require('ssri');
var fs   = require('fs');
var version = require('../package.json').version;

const integritySrc = ssri.fromData(fs.readFileSync('dist/leaflet-src.js'));
const integrityUglified = ssri.fromData(fs.readFileSync('dist/leaflet.js'));
const integrityCss = ssri.fromData(fs.readFileSync('dist/leaflet.css'));


console.log('Integrity hashes for ', version, ':');
console.log('dist/leaflet-src.js: ', integritySrc.toString());
console.log('dist/leaflet.js:     ', integrityUglified.toString());
console.log('dist/leaflet.css:    ', integrityCss.toString());

var docConfig = fs.readFileSync('docs/_config.yml').toString();

docConfig = docConfig.
	replace(/latest_leaflet_version:.*/,  'latest_leaflet_version: ' + version).
	replace(/integrity_hash_source:.*/,   'integrity_hash_source: "' +   integritySrc.toString() + '"').
	replace(/integrity_hash_uglified:.*/, 'integrity_hash_uglified: "' + integrityUglified.toString() + '"').
	replace(/integrity_hash_css:.*/,      'integrity_hash_css: "' +      integrityCss.toString() + '"');
github Leaflet / Leaflet / build / integrity.js View on Github external
// This script calculates the integrity hashes of the files in dist/ , and
// **overwrites** the values in the documentation.

var ssri = require('ssri');
var fs   = require('fs');
var version = require('../package.json').version;

const integritySrc = ssri.fromData(fs.readFileSync('dist/leaflet-src.js'));
const integrityUglified = ssri.fromData(fs.readFileSync('dist/leaflet.js'));
const integrityCss = ssri.fromData(fs.readFileSync('dist/leaflet.css'));


console.log('Integrity hashes for ', version, ':');
console.log('dist/leaflet-src.js: ', integritySrc.toString());
console.log('dist/leaflet.js:     ', integrityUglified.toString());
console.log('dist/leaflet.css:    ', integrityCss.toString());

var docConfig = fs.readFileSync('docs/_config.yml').toString();

docConfig = docConfig.
	replace(/latest_leaflet_version:.*/,  'latest_leaflet_version: ' + version).
	replace(/integrity_hash_source:.*/,   'integrity_hash_source: "' +   integritySrc.toString() + '"').
	replace(/integrity_hash_uglified:.*/, 'integrity_hash_uglified: "' + integrityUglified.toString() + '"').
	replace(/integrity_hash_css:.*/,      'integrity_hash_css: "' +      integrityCss.toString() + '"');

// console.log('New jekyll docs config: \n', docConfig);
github npm / cacache / test / content.write.js View on Github external
test("checks input digest doesn't match data", (t) => {
  const CONTENT = 'foobarbaz'
  const integrity = ssri.fromData(CONTENT)
  let int1 = null
  let int2 = null

  return t.rejects(
    write.stream(CACHE, { integrity })
      .on('integrity', (int) => { int1 = int })
      .end('bazbarfoo')
      .promise(),
    { code: 'EINTEGRITY' },
    'returns integrity error'
  )
    .then(() => t.equal(int1, null, 'no digest emitted'))
    .then(() => write.stream(CACHE, { integrity })
      .on('integrity', int => { int2 = int })
      .end(CONTENT)
      .promise())
github npm / cacache / test / content.write.js View on Github external
t.throws(() => {
        fs.statSync(contentPath(CACHE, ssri.fromData('foobarbaz')))
      }, {
        code: 'ENOENT'
github npm / pacote / test / finalize-manifest.js View on Github external
}).then(tarData => {
    const integrity = ssri.fromData(tarData, { algorithms: ['sha512'] }).toString()
    tnock(t, OPTS.registry).get('/' + tarballPath).reply(200, tarData)
    return finalizeManifest(base, npa(base.name), OPTS).then(manifest => {
      t.deepEqual(manifest._integrity, integrity, 'integrity hash successfully added')
    })
  })
})
github graalvm / graaljs / deps / npm / lib / install / audit.js View on Github external
function scrub (value, rid) {
  return ssri.fromData((rid || runId) + ' ' + value, {algorithms: ['sha256']}).hexDigest()
}
github npm / tink / lib / installer.js View on Github external
async writeLockHash (map) {
    const nm = path.join(this.prefix, 'node_modules')
    try {
      await mkdirp(nm)
    } catch (err) {
      if (err.code !== 'EEXIST') {
        throw err
      }
    }
    return writeFileAsync(path.join(nm, '.pkglock-hash'), JSON.stringify({
      lockfile_integrity: ssri.fromData(
        JSON.stringify(this.pkg._shrinkwrap)
      ).toString()
    }))
  }
}

ssri

Standard Subresource Integrity library -- parses, serializes, generates, and verifies integrity metadata according to the SRI spec.

ISC
Latest version published 3 months ago

Package Health Score

92 / 100
Full package analysis