1.7.0 • Published 7 years ago

tshash v1.7.0

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

TSHash

Build Status

A small framework for digest functions, similar to Java's MessageDigest.

Written in TypeScript, but should be usable from Node or the browser.

Works on Uint8Arrays.

Goal is to include some commmon hash functions, including SHA-1, Tiger, and Merkle tree variants of any of them, along with some utility functions such as UTF-8 and base32 encoding/decoding (i.e. everything you need to generate bitprint URNs).

Currently included algorithms:

  • SHA-1 (tshash.SHA1)
  • CRC32 (tshash.CRC32)
  • Internet checksum (tshash.InternetChecksum)

Example

// import SHA1 from 'tshash/SHA1';
// (or, in Node):
var tshash = require('tshash');
var SHA1 = tshash.SHA1;

// A 'hashing' is the intermediate state of a hash calculation,
// similar to a MessageDigest in Java.
// You can keep updating it with additional data.
// So, like, the thing you're hashing doesn't need to be loaded into memory all at once.
var hashing = SHA1.newHashing();

var someData = new Uint8Array(100);
someData[0] = 42;

hashing.update(someData);
// Could update(more data) here if we wanted.
var someHash = hashing.digest(); // Some 20-byte Uint8Array

There's also some random utility functions buried in here.

var tshash = require('tshash');
// Like this UUID generator
var uuids = tshash.uuids;

var uuid = uuids.newType4Uuid();
// and formatter
var uuidStr = uuids.uuidString(uuid); // "blablah-blah-blah-blah-blahblahblah"
var uuidUrn = uuids.uuidUrn(uuid); // "urn:uuid:blablah-blah-blah-blah-blahblahblah"

// and this base32 encoder
var someUrn = tshash.base32Encode(tshash.hash("Hello, world!", tshash.SHA1)); // "SQ5HALIG6NCZTLXB7DNI56PXFFQDDVUZ"
1.7.0

7 years ago

1.6.3

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.4

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.3

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago