Skip to content

Latest commit

 

History

History
97 lines (63 loc) · 1.92 KB

README.md

File metadata and controls

97 lines (63 loc) · 1.92 KB

pepto

NPM

NPM version build codecov

Generate a hex string digest from a given message. See SubtleCrypto.digest() and Replit demo.

Quick Start

import { digest } from 'pepto';

await digest('SHA-256', 'Hello, World!');

Installation

NPM:

npm install pepto

Yarn:

yarn add pepto

Usage

Import ES Modules:

import { digest } from 'pepto';

Require with CommonJS:

const { digest } = require('pepto');

Hash message with SHA-1 algorithm:

await digest('SHA-1', 'message');

Hash message with SHA-256 algorithm:

await digest('SHA-256', 'message');

Hash message with SHA-384 algorithm:

await digest('SHA-384', 'message');

Hash message with SHA-512 algorithm:

await digest('SHA-512', 'message');

Use promise instead of async-await:

digest('SHA-512', 'message').then((hex) => console.log(hex));

FAQ

ReferenceError: TextEncoder is not defined

If you get this error in your Jest tests, then add the following to your setupTests.ts:

import { TextEncoder } from 'util';
window.TextEncoder = TextEncoder;

Or add the following to your setupTests.js:

const { TextEncoder } = require('util');
window.TextEncoder = TextEncoder;

License

MIT