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

@digitalcredentials/sha256-universal

v1.1.1

Published

A minimal Typescript SHA-256 digest library for Node.js, browsers, and React Native.

Downloads

1,164

Readme

Universal SHA-256 digest library (@digitalcredentials/sha256-universal)

Build status NPM Version

A minimal Typescript SHA-256 digest library for Node.js, browsers, and React Native.

Table of Contents

Background

In implementing Verifiable Credentials related libraries, we make frequent use of SHA-256 digests, and found ourselves re-implementing the same digest functions that had to run using native code whenever possible (native Node.js and browser WebCrypto API), but could also drop down to pure JS implementation for React Native.

Other universal SHA-256 libraries we've encountered either did not use the native implementations, or did not support React Native.

Security

  • For Node.js, uses native Node crypto
  • In browsers, uses the built-in WebCryptography API
  • In React Native, uses the Microsoft Research library (msCrypto) via isomorphic-webcrypto.

Install

  • Node.js 16+ is recommended.

NPM

To install via NPM:

npm install @digitalcredentials/sha256-universal

Development

To install locally (for development):

git clone https://github.com/digitalcredentials/sha256-universal.git
cd sha256-universal
npm install

Usage

Usable in Typescript and Javascript.

import { sha256digest } from '@digitalcredentials/sha256-universal'

// The digest function accepts either a string
await sha256digest('test')
// Uint8Array(32) [159, 134, 208, 129, 136,  76, 125, 101, 154,  47, 234, 160, 
// 197,  90, 208,  21, 163, 191,  79,  27,  43,  11, 130,  44, 209,  93, 108,  
// 21, 176, 240,  10,   8]

// or a raw byte array
const data = new TextEncoder().encode('test')
// Uint8Array(4) [ 116, 101, 115, 116 ]
await sha256digest(data)
// Uint8Array(32) [159, 134, 208, 129, 136,  76, 125, 101, 154,  47, 234, 160, 
// 197,  90, 208,  21, 163, 191,  79,  27,  43,  11, 130,  44, 209,  93, 108,  
// 21, 176, 240,  10,   8]

// If you want to hash a JS object, use JSON.stringify() first
const data = JSON.stringify({ "hello": "world" })
// '{"hello":"world"}'
await sha256digest(data)

Notice that the resulting hash digest is just an array of raw bytes. If you're intending to hash an object in order to obtain a deterministic content-addressable identifier string (for use in a database, for example), then you need to pass the result of sha256digest() to a base-X encoding function like base64url-universal.

Contribute

PRs accepted.

If editing the Readme, please conform to the standard-readme specification.

License

MIT License © 2022 Digital Credentials Consortium.