JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3292
  • Score
    100M100P100Q114512F
  • License Apache-2.0

A hashing library for react-native

Package Exports

  • react-native-hash

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-hash) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-native-hash

Getting started

$ npm install react-native-hash --save

Usage

Constants

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

Example

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

const hashAlgorithm = CONSTANTS.HashAlgorithms.sha256;

const hmacAlgorithm = CONSTANTS.HmacAlgorithms.HmacSHA512;

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 ): Promise<record<string, string>>;
  • pass an empty string "" to the hashFilesForFolder as extensionFilter if you dont want to filter the results.
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.hashFilesForFolder(
  "uri",
  CONSTANTS.HashAlgorithms.sha256,
  0,
  1048576,
  ".mp3"
)
  .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.

Other Platforms

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:

Hash Algorithm :

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

API:

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

Example :

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

JSHash("message", CONSTANTS.HashAlgorithms.keccak)
  .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.

Topics

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

Todo

  • SHA-3
  • other Keccak lengths
  • fully implementing HMAC

Status

iOS Android windows
hash local files ✔️
hash network assets ✔️
hash network responses ✔️
hash bundle assets
hash strings ✔️ ✔️ ✔️
HMAC ✔️
  • all PRs are welcome

Package Quality