Skip to content
AssemblyScript implementation of SHA256
WebAssembly TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assembly
build
examples
src
.babelrc
.gitignore
.travis.yml
LICENSE
README.md
as-pect.config.js
package.json
yarn.lock

README.md

as-sha256

Assembly Script implementation of SHA256.

This repository contains two npm distributions; a pure AssemblyScript version, and a Typescript wrapper for the WASM build.

Benchmarks

Sha256-Rust#hash x 328,611 ops/sec ±5.99% (75 runs sampled)
Sha256-Js#hash x 340,641 ops/sec ±4.64% (77 runs sampled)
Sha256-Asm#hash x 5,217 ops/sec ±8.83% (74 runs sampled)
Sha256-BCrypto#hash x 411,191 ops/sec ±9.87% (59 runs sampled)
AS-Sha256#hash x 537,124 ops/sec ±8.91% (76 runs sampled)
Fastest is AS-Sha256#hash

AssemblyScript

yarn add @chainsafe/as-sha256

TypeScript Wrapper

yarn add @chainsafe/sha256

Usage

import sha256 from "@chainsafe/sha256";

const message = Buffer.from("Hello world");

const hash = sha256(message);

We also expose the lower level WASM exports for those that may wish to use it. It can be accessed as follows:

import { wasm } from "@chainsafe/sha256"

const buffer = Buffer.from("Hello world");
const input  = wasm.__retain(wasm.__allocArray(wasm.UINT8ARRAY_ID, buffer));
const result = wasm.hash(input);
const output = wasm.__getUint8Array(result);

// To prevent memory leaks
wasm.__release(array);
wasm.__release(result);

console.log(toHexString(output));

License

LGPL-V3

You can’t perform that action at this time.