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

@thecodingrasta/react-native-hash

v3.0.42

Published

A hashing library for react-native

Downloads

62

Readme

react-native-hash

Package Forked from Drazail to fix React-Native Peer Dependency issue

Getting started

$ npm install @thecodingrasta\react-native-hash --save


compatibility

| Criteria | Release Version | | ---------------------- | ------------------ | | Android API < 16 | unsupported | | 16 <= Android API < 21 | 1.x | | Gradle >= 7 | >= 2.0.1 | | React Native >= 0.72.1 |


Usage

Constants

HashAlgorithms: Record<string, string>;
HmacAlgorithms: Record<string, string>;
Events: Record<string, string>;

Example

import { CONSTANTS } from 'react-native-hash';

const hashAlgorithm = CONSTANTS.HashAlgorithms.sha256;

const hmacAlgorithm = CONSTANTS.HmacAlgorithms.HmacSHA512;

const EventName = CONSTANTS.Events.onBatchReccieved;

Cross Platform API

Native hashing is only implemented on Android, however, until I get around writing native modules for other platforms ( or if some kind soul makes a PR), you can use JSHash and JSHmac:


NOTE

if you are using expo, JSHash and JSHmac should work out of the box, native implementations however, will require you to eject the project.


Hash Algorithm :

"MD2" | "MD5"| "SHA-1"| "SHA-224" | "SHA-256" | "SHA-384" | "SHA-512"| "keccak"

HMac Algorithm :

"HmacMD5" | "HmacSHA1" | "HmacSHA224" | "HmacSHA256" | "HmacSHA384" | "HmacSHA512"

API:

JSHash(message: string, algorithm: string):Promise<string>;
JSHmac(message: string, secret: string, algorithm: string): Promise<string>;

Example :

import { JSHash, JSHmac, CONSTANTS } from "react-native-hash";

JSHash("message", CONSTANTS.HashAlgorithms.sha256)
  .then(hash => console.log(hash))
  .catch(e => console.log(e));

JSHmac("message", "SecretKey", CONSTANTS.HmacAlgorithms.HmacSHA256)
  .then(hash => console.log(hash))
  .catch(e => console.log(e));
  • keccak implementation defaults to 512 and is not tested against all attack vectors.

check out the example for more information.

React Hooks

Following hooks are available:

useHash(
  hashAlgo?: string = "MD5",
  initialMessage?: string = "hello World",
): [
  hashed: string,
  setMessage: (message: string) => Promise<void>,
  setAlgo: (algo: string) => Promise<void>
];
useHmac(
  hmacAlgo?: string = "HmacMD5",
  initialMessage?: string = "hello World",
  initialSecret?: string = "SecretKey",
): [
  hashed: string,
  setMessage: (message: string) => Promise<void>,
  setAlgo: (algo: string) => Promise<void>,
  setSecret: (secret: string) => Promise<void>
];

Usage

const [hashedMessage, setHashAlgo, setHashMessage] = useHash();
const [hmac, setHmacAlgo, setHmacMessage, setHmacSecret] = useHmac();

hashedMessage and hmac will update after a call to one of the setters is resolved.

note that all the setter functions of these two hooks are async and will return a promise.

check out the [example] for more information.


Android

Hash Algorithm :

"md2" | "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512"

HMAC Algorithm :

"HmacMD5" | "HmacSHA1" | "HmacSHA224" | "HmacSHA256" | "HmacSHA384" | "HmacSHA512" | "PBEwithHmacSHA" "PBEwithHmacSHA1" | "PBEwithHmacSHA224" | "PBEwithHmacSHA256" | "PBEwithHmacSHA384" | "PBEwithHmacSHA512"

API

hashFile(uri: string, algorithm: string): Promise<string>;
hashFilesForFolder(uri: string, algorithm: string, minFileSize: number, maxFileSize: number, extensionFilter: string, batchSize: number, delay: number ):  Promise<{FilesCount:number, isFinalBatch: bool, batchNumber: number, results: Record<string, string>}>;
  • pass an empty string "" to the hashFilesForFolder as extensionFilter if you dont want to filter the results.
  • if you pass -1 as batchSize, the function will return a promise which resolves into an object with all hashes
  • if you pass any number other than -1 to batchSize, instead of returning the results, null will be returned, but when each batch is ready an event will be fired.
  • the delay parameter determines how many ms should the native thread waits before sending the next batch.
  • check "press to hash Folder with events" and "press to hash Folder" in the example app for more details
hashFilesForFolders(uri: string, algorithm: string, minFileSize: number, maxFileSize: number, extensionFilter: string, batchSize: number, delay: number ):  Promise<{FilesCount:number, isFinalBatch: bool, batchNumber: number, results: Record<string, string>}>;
  • behaves the same as the hashFilesForFolder, but reccieves an String array as first argument.
hashUrl(url: string, HTTPMethod: string, headers: Record<string, string>, algorithm: string): Promise<string>;
hashString(message: string, algorithm: string): Promise<string>;
generateHmac(message: string, key: string, algorithm: string): Promise<string>;

Example

import RnHash, { CONSTANTS } from "react-native-hash";

RnHash.hashFile("uri", CONSTANTS.HashAlgorithms.sha256)
  .then(hash => console.log(hash))
  .catch(e => console.log(e));

RNHash.hashFilesForFolders(
  ["uri", "anotherUri"],
  CONSTANTS.HashAlgorithms.sha256,
  0,
  1048576,
  ".mp3",
  -1,
  0
)
  .then(b => setFolderString(JSON.stringify(b)))
  .catch(er => console.log(er));

  RNHash.hashFilesForFolder(
  "uri",
  CONSTANTS.HashAlgorithms.sha256,
  0,
  1048576,
  ".mp3",
  -1,
  0
)
  .then(b => setFolderString(JSON.stringify(b)))
  .catch(er => console.log(er));

RnHash.hashUrl(
  "url",
  "HTTPMethod",
  { "Content-type": "application/json" },
  CONSTANTS.HashAlgorithms.sha256
)
  .then(hash => console.log(hash))
  .catch(e => console.log(e));

RnHash.hashString("message", CONSTANTS.HashAlgorithms.sha256)
  .then(hash => console.log(hash))
  .catch(e => console.log(e));

RNHash.generateHmac("message", "secretKey", CONSTANTS.HmacAlgorithms.HmacSHA512)
  .then(HMAC => console.log(HMAC))
  .catch(er => console.log(er));

check out the example for more information.

Topics

Hashing files and urls are only supported on android at this point

Todo

  • SHA-3
  • other Keccak lengths

Status

| | iOS | Android | windows | | ---------------------- | ------------------ | ------------------ | ------------------ | | hash local files | :x: | :heavy_check_mark: | :x: | | hash network assets | :x: | :heavy_check_mark: | :x: | | hash network responses | :x: | :heavy_check_mark: | :x: | | hash bundle assets | :x: | :x: | :x: | | hash strings | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | HMAC | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

  • all PRs are welcome

Package Quality


Credits

JSHash and JSHMac functions use some Open Source code snippets. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.

  • Original Package forked from Drazail: https://github.com/Drazail/react-native-hash/

  • Project: crypto-es https://github.com/entronad/crypto-es

  • License (MIT) https://github.com/entronad/crypto-es/blob/master/LICENSE