{"id":20163467,"url":"https://github.com/sjinks/sri-calc","last_synced_at":"2025-07-22T23:32:45.418Z","repository":{"id":34289933,"uuid":"174432213","full_name":"sjinks/sri-calc","owner":"sjinks","description":"Module to calculate a SRI hash of a file","archived":false,"fork":false,"pushed_at":"2024-04-10T19:00:34.000Z","size":273,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T03:16:53.132Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sjinks.png","metadata":{"funding":{"custom":["https://www.paypal.com/donate/?hosted_button_id=SAG6877JDJ3KU"]},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-07T22:49:38.000Z","updated_at":"2024-06-09T08:43:25.974Z","dependencies_parsed_at":"2023-02-17T11:25:13.375Z","dependency_job_id":"5df7fc17-5690-445d-854a-a060d8f12428","html_url":"https://github.com/sjinks/sri-calc","commit_stats":{"total_commits":95,"total_committers":5,"mean_commits":19.0,"dds":0.4842105263157894,"last_synced_commit":"1d8867852dc50bc04fc104adb778c24381822fd5"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fsri-calc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fsri-calc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fsri-calc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fsri-calc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sjinks","download_url":"https://codeload.github.com/sjinks/sri-calc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241600493,"owners_count":19988715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T00:29:43.005Z","updated_at":"2025-03-03T03:12:18.007Z","avatar_url":"https://github.com/sjinks.png","language":"JavaScript","funding_links":["https://www.paypal.com/donate/?hosted_button_id=SAG6877JDJ3KU"],"categories":[],"sub_categories":[],"readme":"# sri-calc\n\n[![Build and Test](https://github.com/sjinks/sri-calc/actions/workflows/build.yml/badge.svg)](https://github.com/sjinks/sri-calc/actions/workflows/build.yml)\n\n`sri-calc` is a simple module to generate SRI hashes of files, which then can be used to implement [sub-resource integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).\n\nThis module was inspired by [odino/node-sri](https://github.com/odino/node-sri), but it operates differently:\n  * it does not require a Linux environment;\n  * it uses NodeJS Crypto API instead of launching an external process to calculate a digest\n\n## Installation\n\n```bash\nnpm install --save sri-calc\n```\n\n## Usage\n\nUsing the module is pretty straightforward, as you can use it\nboth with callbacks:\n\n``` javascript\nconst sri = require('sri-calc');\n\nsri.hash('/path/to/my/file.js', (err, hash) =\u003e {\n  if (err) {\n    throw err;\n  }\n\n  console.log('The hash is', hash);\n});\n```\n\nand with promises:\n\n``` javascript\nconst sri = require('sri-calc');\n\nsri.hash('/path/to/my/file.js')\n  .then(hash =\u003e console.log('The hash is', hash))\n  .catch(err =\u003e console.log(err))\n;\n```\n\n## Options\n\nThe first parameter of `sri.hash()` can either be a name of the file to process, or an object with the following configuration options:\n\n  * `hash`: digest to use, the default value is `sha256`. In theory you can use any digest supported by [crypto.createHash](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options),\n    but [the specification](https://w3c.github.io/webappsec-subresource-integrity/#grammardef-hash-algo) [allows](https://w3c.github.io/webappsec-csp/2/#source-list-valid-hashes) only for\n    `sha256`, `sha384`, and `sha512`.\n  * `prefix`: if `true` (default), the name of the digest algorithm will be prepended to the digest value, i.e., `sha512-z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==`.\n  * `file`: name of the file to process\n\n\n``` javascript\nsri.hash({file: '/path/to/my/file.js', algo: 'sha512', prefix: false}) // z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==\n```\n\n## Tests\n\nRun `npm test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjinks%2Fsri-calc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsjinks%2Fsri-calc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjinks%2Fsri-calc/lists"}