npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ihashgen

v1.1.7

Published

Generate Intergrity hash for the use of CDN.

Downloads

5

Readme

ihashgen

Build Status

Generate Intergrity hash for the use of CDN, which can be used via CLI or Node packages. (Haven't tested on web)

Name: ihashgen

npmjs

Version

Stable

Why use SRI?

https://news.ycombinator.com/item?id=14111499

unpkg website was compromised, so you don't want to risk your website to be phished or whatsoever, a simple intergrity hash check will solve this issue.

Problem Solved

Initially, I wanted to use unpkg for cdn alongside alongside with checksum for intergrity, but I found out that I need to run follwing bash command in order to generate hash. Therefore, I decided to write a CLI tools to "automate" that.

curl https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css | openssl dgst -sha384 -binary | openssl base64 -A

With intergrity checksum, eventhough the CDN is compromised, but your website are still safe from it.

console on webpage when the checksum is not the same

Inspired from srihash.org

Usage

Installation

Install with npm or yarn

npm install -g ihashgen # yarn global add ihashgen

Using it

as Dependency

node.js

ihashgen is a function in typescript

const intergrityGen: (
  url: string,
  type?: "css" | "js" | undefined,
  algo?: "sha384" | undefined
) => Promise<{
  hash: string;
  html: string;
}>;

CLI tools

General
> ihashgen --version
1.1.3
> ihashgen --help
Usage: ihashgen [options] [command]

Options:

  -V, --version                   output the version number
  -h, --help                      output usage information

Commands:

  generate|g [options] <cdn_url>  generate links based on url given
Generate

use ihashgen g <cdn_url> or ihashgen generate <cdn_url>

> ihashgen g --help
Usage: generate|g [options] <cdn_url>

generate links based on url given

Options:

  -t, --type [css/js]  specify file type (css/js)
  -a, --algo [sha384]  specify hashing algorithm (sha384)
  -h, --help           output usage information

Use command ihashgen generate <cdn_url>,

  • -t or --type (file type) is set to default to check the url string ends with js or css
  • -a or --algo (hashing algorithm used) is set to sha384
> ihashgen g https://unpkg.com/[email protected]/umd/react.production.min.js -t js -a sha384
Generatring hashes for [https://unpkg.com/[email protected]/umd/react.production.min.js]
Done hashing 🔑
Hash:  hqL/av/jdhwexbPMcoB6jzLfvBwAgAo5jKJzMpirHW+FBIg769b9IP70lr90RZm0
Html:  <script src="https://unpkg.com/[email protected]/umd/react.production.min.js" integrity="sha384-hqL/av/jdhwexbPMcoB6jzLfvBwAgAo5jKJzMpirHW+FBIg769b9IP70lr90RZm0" crossorigin="anonymous"></script>

Library

  • Typescript
  • Node.js

CLI

  • commander
  • chalk
  • ora
  • inquirer

Test

  • Jest

Library used

  • Crypto-Js
  • Axios

Development

  • yarn test to run unit test.
  • yarn prod to generate for NPM. (This command works on Linux/Unix based machine)
  • yarn sample to run a sample cli command to ihashgen

Roadmaps

License

MIT