Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chainsafe/as-sha256

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/as-sha256 - npm Package Compare versions

Comparing version 0.2.4 to 0.3.0

lib/hashObject.d.ts

15

CHANGELOG.md

@@ -0,1 +1,16 @@

# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [0.3.0](https://github.com/chainsafe/as-sha256/compare/@chainsafe/as-sha256@0.2.4...@chainsafe/as-sha256@0.3.0) (2022-03-24)
* Convert as-sha256 to typescript (#244) ([2d4e3fe](https://github.com/chainsafe/as-sha256/commit/2d4e3febec89ca8ca7c89a19c6949c3213c2c45c)), closes [#244](https://github.com/chainsafe/as-sha256/issues/244)
### BREAKING CHANGES
* export digest* functions as named exports
## 0.2.4 (2021-08-18)

@@ -2,0 +17,0 @@

38

lib/index.d.ts

@@ -1,29 +0,13 @@

import { HashObject, byteArrayToHashObject, hashObjectToByteArray } from "./hashObject";
import SHA256 from "./sha256";
export { HashObject, byteArrayToHashObject, hashObjectToByteArray, SHA256 };
export declare function digest(data: Uint8Array): Uint8Array;
export declare function digest64(data: Uint8Array): Uint8Array;
/**
* This is a hash representation with 8 numbers, each 4 bytes.
* That makes it 32 bytes, the same to Uint8Array(32).
* Digest 2 objects, each has 8 properties from h0 to h7.
* The performance is a little bit better than digest64 due to the use of Uint32Array
* and the memory is a little bit better than digest64 due to no temporary Uint8Array.
* @returns
*/
export interface HashObject {
h0: number;
h1: number;
h2: number;
h3: number;
h4: number;
h5: number;
h6: number;
h7: number;
}
export default class SHA256 {
constructor();
init(): this;
update(data: Uint8Array): this;
final(): Uint8Array;
static digest(data: Uint8Array): Uint8Array;
static digest64(data: Uint8Array): Uint8Array;
static digestTwoHashObjects(obj1: HashObject, obj2: HashObject): HashObject;
}
export function hashObjectToByteArray(obj: HashObject, byteArr: ArrayLike<number>, offset: number): void;
export function byteArrayToHashObject(byteArr: ArrayLike<number>): HashObject;
export declare function digest64HashObjects(obj1: HashObject, obj2: HashObject): HashObject;
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hashObjectToByteArray = hashObjectToByteArray;
exports.byteArrayToHashObject = byteArrayToHashObject;
exports.default = void 0;
var _wasm = require("./wasm");
class SHA256 {
constructor() {
this.ctx = (0, _wasm.newInstance)();
this.wasmInputValue = this.ctx.input.value;
this.wasmOutputValue = this.ctx.output.value;
this.uint8InputArray = new Uint8Array(this.ctx.memory.buffer, this.wasmInputValue, this.ctx.INPUT_LENGTH);
this.uint8OutputArray = new Uint8Array(this.ctx.memory.buffer, this.wasmOutputValue, 32);
this.uint32InputArray = new Uint32Array(this.ctx.memory.buffer, this.wasmInputValue, this.ctx.INPUT_LENGTH); // extracting numbers from Uint32Array causes more memory
// this.uint32OutputArray = new Uint32Array(this.ctx.memory.buffer, this.wasmOutputValue, 32);
}
init() {
this.ctx.init();
return this;
}
update(data) {
const INPUT_LENGTH = this.ctx.INPUT_LENGTH;
if (data.length > INPUT_LENGTH) {
for (let i = 0; i < data.length; i += INPUT_LENGTH) {
const sliced = data.slice(i, i + INPUT_LENGTH);
this.uint8InputArray.set(sliced);
this.ctx.update(this.wasmInputValue, sliced.length);
}
} else {
this.uint8InputArray.set(data);
this.ctx.update(this.wasmInputValue, data.length);
}
return this;
}
final() {
this.ctx.final(this.wasmOutputValue);
const output = new Uint8Array(32);
output.set(this.uint8OutputArray);
return output;
}
static digest(data) {
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.digest64HashObjects = exports.digest64 = exports.digest = exports.SHA256 = exports.hashObjectToByteArray = exports.byteArrayToHashObject = void 0;
const wasm_1 = require("./wasm");
const hashObject_1 = require("./hashObject");
Object.defineProperty(exports, "byteArrayToHashObject", { enumerable: true, get: function () { return hashObject_1.byteArrayToHashObject; } });
Object.defineProperty(exports, "hashObjectToByteArray", { enumerable: true, get: function () { return hashObject_1.hashObjectToByteArray; } });
const sha256_1 = __importDefault(require("./sha256"));
exports.SHA256 = sha256_1.default;
const ctx = wasm_1.newInstance();
const wasmInputValue = ctx.input.value;
const wasmOutputValue = ctx.output.value;
const inputUint8Array = new Uint8Array(ctx.memory.buffer, wasmInputValue, ctx.INPUT_LENGTH);
const outputUint8Array = new Uint8Array(ctx.memory.buffer, wasmOutputValue, 32);
const inputUint32Array = new Uint32Array(ctx.memory.buffer, wasmInputValue, ctx.INPUT_LENGTH);
function digest(data) {
if (data.length === 64) {
return SHA256.digest64(data);
return digest64(data);
}
if (data.length <= staticInstance.ctx.INPUT_LENGTH) {
staticInstance.uint8InputArray.set(data);
staticInstance.ctx.digest(data.length);
const output = new Uint8Array(32);
output.set(staticInstance.uint8OutputArray);
return output;
if (data.length <= ctx.INPUT_LENGTH) {
inputUint8Array.set(data);
ctx.digest(data.length);
const output = new Uint8Array(32);
output.set(outputUint8Array);
return output;
}
return staticInstance.init().update(data).final();
}
static digest64(data) {
ctx.init();
update(data);
return final();
}
exports.digest = digest;
function digest64(data) {
if (data.length === 64) {
staticInstance.uint8InputArray.set(data);
staticInstance.ctx.digest64(staticInstance.wasmInputValue, staticInstance.wasmOutputValue);
const output = new Uint8Array(32);
output.set(staticInstance.uint8OutputArray);
return output;
inputUint8Array.set(data);
ctx.digest64(wasmInputValue, wasmOutputValue);
const output = new Uint8Array(32);
output.set(outputUint8Array);
return output;
}
throw new Error("InvalidLengthForDigest64");
}
/**
* Digest 2 objects, each has 8 properties from h0 to h7.
* The performance is a little bit better than digest64 due to the use of Uint32Array
* and the memory is a little bit better than digest64 due to no temporary Uint8Array.
* @returns
*/
static digestTwoHashObjects(obj1, obj2) {
// TODO: expect obj1 and obj2 as HashObject
staticInstance.uint32InputArray[0] = obj1.h0;
staticInstance.uint32InputArray[1] = obj1.h1;
staticInstance.uint32InputArray[2] = obj1.h2;
staticInstance.uint32InputArray[3] = obj1.h3;
staticInstance.uint32InputArray[4] = obj1.h4;
staticInstance.uint32InputArray[5] = obj1.h5;
staticInstance.uint32InputArray[6] = obj1.h6;
staticInstance.uint32InputArray[7] = obj1.h7;
staticInstance.uint32InputArray[8] = obj2.h0;
staticInstance.uint32InputArray[9] = obj2.h1;
staticInstance.uint32InputArray[10] = obj2.h2;
staticInstance.uint32InputArray[11] = obj2.h3;
staticInstance.uint32InputArray[12] = obj2.h4;
staticInstance.uint32InputArray[13] = obj2.h5;
staticInstance.uint32InputArray[14] = obj2.h6;
staticInstance.uint32InputArray[15] = obj2.h7;
staticInstance.ctx.digest64(staticInstance.wasmInputValue, staticInstance.wasmOutputValue); // extracting numbers from Uint32Array causes more memory
return byteArrayToHashObject(staticInstance.uint8OutputArray);
}
}
exports.default = SHA256;
const staticInstance = new SHA256();
exports.digest64 = digest64;
/**
* Pass 8 numbers in an object and set that to inputArray.
* This function contains multiple same procedures but we intentionally
* do it step by step to improve performance a bit.
**/
function hashObjectToByteArray(obj, byteArr, offset) {
let tmp = obj.h0;
byteArr[0 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[1 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[2 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[3 + offset] = tmp & 0xff;
tmp = obj.h1;
byteArr[4 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[5 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[6 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[7 + offset] = tmp & 0xff;
tmp = obj.h2;
byteArr[8 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[9 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[10 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[11 + offset] = tmp & 0xff;
tmp = obj.h3;
byteArr[12 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[13 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[14 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[15 + offset] = tmp & 0xff;
tmp = obj.h4;
byteArr[16 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[17 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[18 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[19 + offset] = tmp & 0xff;
tmp = obj.h5;
byteArr[20 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[21 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[22 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[23 + offset] = tmp & 0xff;
tmp = obj.h6;
byteArr[24 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[25 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[26 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[27 + offset] = tmp & 0xff;
tmp = obj.h7;
byteArr[28 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[29 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[30 + offset] = tmp & 0xff;
tmp = tmp >> 8;
byteArr[31 + offset] = tmp & 0xff;
* Digest 2 objects, each has 8 properties from h0 to h7.
* The performance is a little bit better than digest64 due to the use of Uint32Array
* and the memory is a little bit better than digest64 due to no temporary Uint8Array.
* @returns
*/
function digest64HashObjects(obj1, obj2) {
// TODO: expect obj1 and obj2 as HashObject
inputUint32Array[0] = obj1.h0;
inputUint32Array[1] = obj1.h1;
inputUint32Array[2] = obj1.h2;
inputUint32Array[3] = obj1.h3;
inputUint32Array[4] = obj1.h4;
inputUint32Array[5] = obj1.h5;
inputUint32Array[6] = obj1.h6;
inputUint32Array[7] = obj1.h7;
inputUint32Array[8] = obj2.h0;
inputUint32Array[9] = obj2.h1;
inputUint32Array[10] = obj2.h2;
inputUint32Array[11] = obj2.h3;
inputUint32Array[12] = obj2.h4;
inputUint32Array[13] = obj2.h5;
inputUint32Array[14] = obj2.h6;
inputUint32Array[15] = obj2.h7;
ctx.digest64(wasmInputValue, wasmOutputValue);
// extracting numbers from Uint32Array causes more memory
return hashObject_1.byteArrayToHashObject(outputUint8Array);
}
/**
* Parse outputArray into an object of 8 numbers.
* This is the order that makes Uint32Array the same to Uint8Array
* This function contains multiple same procedures but we intentionally
* do it step by step to improve performance a bit.
**/
function byteArrayToHashObject(byteArr) {
let tmp = 0;
tmp |= byteArr[3] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[2] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[1] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[0] & 0xff;
const h0 = tmp;
tmp = 0;
tmp |= byteArr[7] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[6] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[5] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[4] & 0xff;
const h1 = tmp;
tmp = 0;
tmp |= byteArr[11] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[10] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[9] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[8] & 0xff;
const h2 = tmp;
tmp = 0;
tmp |= byteArr[15] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[14] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[13] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[12] & 0xff;
const h3 = tmp;
tmp = 0;
tmp |= byteArr[19] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[18] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[17] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[16] & 0xff;
const h4 = tmp;
tmp = 0;
tmp |= byteArr[23] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[22] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[21] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[20] & 0xff;
const h5 = tmp;
tmp = 0;
tmp |= byteArr[27] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[26] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[25] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[24] & 0xff;
const h6 = tmp;
tmp = 0;
tmp |= byteArr[31] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[30] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[29] & 0xff;
tmp = tmp << 8;
tmp |= byteArr[28] & 0xff;
const h7 = tmp;
return {
h0,
h1,
h2,
h3,
h4,
h5,
h6,
h7
};
}
exports.digest64HashObjects = digest64HashObjects;
function update(data) {
const INPUT_LENGTH = ctx.INPUT_LENGTH;
if (data.length > INPUT_LENGTH) {
for (let i = 0; i < data.length; i += INPUT_LENGTH) {
const sliced = data.slice(i, i + INPUT_LENGTH);
inputUint8Array.set(sliced);
ctx.update(wasmInputValue, sliced.length);
}
}
else {
inputUint8Array.set(data);
ctx.update(wasmInputValue, data.length);
}
}
function final() {
ctx.final(wasmOutputValue);
const output = new Uint8Array(32);
output.set(outputUint8Array);
return output;
}
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "__esModule", { value: true });
exports.newInstance = void 0;
const wasmCode_1 = require("./wasmCode");
const _module = new WebAssembly.Module(wasmCode_1.wasmCode);
const importObj = {
env: {
// modified from https://github.com/AssemblyScript/assemblyscript/blob/v0.9.2/lib/loader/index.js#L70
abort: function (msg, file, line, col) {
throw Error(`abort: ${msg}:${file}:${line}:${col}`);
},
},
};
function newInstance() {
return new WebAssembly.Instance(_module, importObj).exports;
}
exports.newInstance = newInstance;
var _loader = _interopRequireDefault(require("@assemblyscript/loader"));
var _buffer = require("buffer");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* babel-plugin-inline-binary-import '../build/optimized.wasm' */
const wasmCode = "\0asm\x01\0\0\0\x01\x1F\x06`\x01\x7F\0`\x02\x7F\x7F\0`\0\0`\x01\x7F\x01\x7F`\x03\x7F\x7F\x7F\0`\x04\x7F\x7F\x7F\x7F\0\x02\r\x01\x03env\x05abort\0\x05\x03\x10\x0F\0\x03\x01\x03\x02\x02\x04\x01\x01\x03\0\0\0\x01\x02\x05\x03\x01\0\x01\x06\xAC\x01\"\x7F\0A\x80\x04\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x7F\x01A\0\x0B\x07V\t\x06memory\x02\0\fINPUT_LENGTH\x03\0\x05input\x03\x1C\x06output\x03\x1E\x04init\0\x06\x06update\0\t\x05final\0\x0B\x06digest\0\f\bdigest64\0\x0E\b\x01\x0F\n\xCA\x0E\x0FF\x01\x02\x7F \0?\0\"\x02A\x10t\"\x01K\x04@ \x02 \0 \x01kA\xFF\xFF\x03jA\x80\x80|qA\x10v\"\x01 \x02 \x01J\x1B@\0A\0H\x04@ \x01@\0A\0H\x04@\0\x0B\x0B\x0B \0$\x17\x0BR\x01\x03\x7F \0A\xF0\xFF\xFF\xFF\x03K\x04@\0\x0B#\x17A\x10j\"\x02 \0A\x0FjApq\"\x01A\x10 \x01A\x10K\x1B\"\x03j\x10\x01 \x02A\x10k\"\x01 \x036\x02\0 \x01A\x016\x02\x04 \x01A\x006\x02\b \x01 \x006\x02\f \x02\x0B%\x01\x01\x7F\x03@ \x01\x04@ \0\"\x02A\x01j!\0 \x02A\0:\0\0 \x01A\x01k!\x01\f\x01\x0B\x0B\x0B)\x01\x01\x7F \0A\xF0\xFF\xFF\xFF\x03K\x04@A\x80\x05A\xB0\x05A6A*\x10\0\0\x0B \0\x10\x02\"\x01 \0\x10\x03 \x01\x0BG\0A\xB4\x02(\x02\0$\x01A\xE4\x04(\x02\0$\x02A\xE0\x05$\x16A\xE0\x05$\x17A\xC0\0\x10\x04$\x18#\x18$\x19A\x80\x02\x10\x04$\x1A#\x1A$\x1BA\x80\x04\x10\x04$\x1C#\x1C$\x1DA \x10\x04$\x1E#\x1E$\x1F\x0BJ\0A\xE7\xCC\xA7\xD0\x06$\x03A\x85\xDD\x9E\xDB{$\x04A\xF2\xE6\xBB\xE3\x03$\x05A\xBA\xEA\xBF\xAAz$\x06A\xFF\xA4\xB9\x88\x05$\x07A\x8C\xD1\x95\xD8y$\bA\xAB\xB3\x8F\xFC\x01$\tA\x99\x9A\x83\xDF\x05$\nA\0$ A\0$!\x0Bg\x01\x02\x7F\x02@ \x02!\x03 \0 \x01F\r\0 \0 \x01I\x04@\x03@ \x03\x04@ \0\"\x02A\x01j!\0 \x01\"\x04A\x01j!\x01 \x02 \x04-\0\0:\0\0 \x03A\x01k!\x03\f\x01\x0B\x0B\x05\x03@ \x03\x04@ \x03A\x01k\"\x03 \0j \x01 \x03j-\0\0:\0\0\f\x01\x0B\x0B\x0B\x0B\x0B\xE7\x03\x01\x01\x7F#\x03$\x0B#\x04$\f#\x05$\r#\x06$\x0E#\x07$\x0F#\b$\x10#\t$\x11#\n$\x12A\0$\x13\x03@#\x13A\x10I\x04@ \0#\x13A\x02tj \x01#\x13A\x02t\"\x02j-\0\0A\x18t \x01 \x02A\x01jj-\0\0A\x10tr \x01 \x02A\x02jj-\0\0A\btr \x01 \x02A\x03jj-\0\0r6\x02\0#\x13A\x01j$\x13\f\x01\x0B\x0BA\x10$\x13\x03@#\x13A\xC0\0I\x04@ \0#\x13A\x02tj \0#\x13A\x10kA\x02tj(\x02\0 \0#\x13A\x07kA\x02tj(\x02\0 \0#\x13A\x02kA\x02tj(\x02\0\"\x01A\x11x \x01A\x13xs \x01A\nvsj \0#\x13A\x0FkA\x02tj(\x02\0\"\x01A\x07x \x01A\x12xs \x01A\x03vsjj6\x02\0#\x13A\x01j$\x13\f\x01\x0B\x0BA\0$\x13\x03@#\x13A\xC0\0I\x04@ \0#\x13A\x02tj(\x02\0#\x01#\x13A\x02tj(\x02\0#\x12#\x0F\"\x01A\x06x \x01A\x0Bxs \x01A\x19xsj#\x0F\"\x01#\x10q#\x11 \x01A\x7Fsqsjjj$\x14#\x0B\"\x01A\x02x \x01A\rxs \x01A\x16xs#\x0B\"\x01#\f\"\x02q \x01#\r\"\x01qs \x01 \x02qsj$\x15#\x11$\x12#\x10$\x11#\x0F$\x10#\x0E#\x14j$\x0F#\r$\x0E#\f$\r#\x0B$\f#\x14#\x15j$\x0B#\x13A\x01j$\x13\f\x01\x0B\x0B#\x03#\x0Bj$\x03#\x04#\fj$\x04#\x05#\rj$\x05#\x06#\x0Ej$\x06#\x07#\x0Fj$\x07#\b#\x10j$\b#\t#\x11j$\t#\n#\x12j$\n\x0B\xB1\x01\x01\x02\x7F \x01#!j$!# \x04@A\xC0\0# k \x01L\x04@#\x19# j \0A\xC0\0# k\x10\x07# A\xC0\0# kj$ A\xC0\0# k!\x02 \x01A\xC0\0# kk!\x01#\x1B#\x19\x10\bA\0$ \x05#\x19# j \0 \x01\x10\x07 \x01# j$ \x0F\x0B\x0B\x03@ \x03 \x01A\xC0\0mH\x04@#\x1B \0 \x02j\x10\b \x03A\x01j!\x03 \x02A@k!\x02\f\x01\x0B\x0B \x01A?q\x04@#\x19# j \0 \x02j \x01A?q\"\0\x10\x07 \0# j$ \x0B\x0B\x19\0 \0A\x80\xFE\x83xqA\bw \0A\xFF\x81\xFC\x07qA\bxr\x0B\xAD\x02\x01\x02\x7F#!A?qA?H\x04@#\x19# jA\x80\x01:\0\0# A\x01j$ \x0B#!A?qA8N\x04@#\x19# j\"\x01A\xC0\0# kj!\x02\x03@ \x01 \x02I\x04@ \x01A\0:\0\0 \x01A\x01j!\x01\f\x01\x0B\x0B#\x1B#\x19\x10\bA\0$ \x0B#!A?qA?N\x04@#\x19# jA\x80\x01:\0\0# A\x01j$ \x0B#\x19# j\"\x01A8# kj!\x02\x03@ \x01 \x02I\x04@ \x01A\0:\0\0 \x01A\x01j!\x01\f\x01\x0B\x0B#\x19A8j#!A\x80\x80\x80\x80\x02m\x10\n6\x02\0#\x19A<j#!A\x03t\x10\n6\x02\0#\x1B#\x19\x10\b \0#\x03\x10\n6\x02\0 \0A\x04j#\x04\x10\n6\x02\0 \0A\bj#\x05\x10\n6\x02\0 \0A\fj#\x06\x10\n6\x02\0 \0A\x10j#\x07\x10\n6\x02\0 \0A\x14j#\b\x10\n6\x02\0 \0A\x18j#\t\x10\n6\x02\0 \0A\x1Cj#\n\x10\n6\x02\0\x0B\x0E\0\x10\x06#\x1D \0\x10\t#\x1F\x10\x0B\x0B\xFD\x01\x01\x02\x7F#\x03$\x0B#\x04$\f#\x05$\r#\x06$\x0E#\x07$\x0F#\b$\x10#\t$\x11#\n$\x12A\0$\x13\x03@#\x13A\xC0\0I\x04@ \0#\x13A\x02tj(\x02\0#\x12#\x0F\"\x01A\x06x \x01A\x0Bxs \x01A\x19xsj#\x0F\"\x01#\x10q#\x11 \x01A\x7Fsqsjj$\x14#\x0B\"\x01A\x02x \x01A\rxs \x01A\x16xs#\x0B\"\x01#\f\"\x02q \x01#\r\"\x01qs \x01 \x02qsj$\x15#\x11$\x12#\x10$\x11#\x0F$\x10#\x0E#\x14j$\x0F#\r$\x0E#\f$\r#\x0B$\f#\x14#\x15j$\x0B#\x13A\x01j$\x13\f\x01\x0B\x0B#\x03#\x0Bj$\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\x1C\0\0\0I\0n\0v\0a\0l\0i\0d\0 \0l\0e\0n\0g\0t\0h\0A\xA0\x05\x0B5&\0\0\0\x01\0\0\0\x01\0\0\0&\0\0\0~\0l\0i\0b\0/\0a\0r\0r\0a\0y\0b\0u\0f\0f\0e\0r\0.\0t\0s";
const _module = new WebAssembly.Module(_buffer.Buffer.from(wasmCode, 'binary'));
function newInstance() {
return _loader.default.instantiateSync(_module);
}
//# sourceMappingURL=wasm.js.map
{
"name": "@chainsafe/as-sha256",
"version": "0.2.4",
"description": "An AssemblyScript implementation of SHA256",
"author": "ChainSafe Systems",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/ChainSafe/as-sha256/issues"
},
"homepage": "https://github.com/ChainSafe/as-sha256#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/chainsafe/as-sha256.git"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"build"
],
"scripts": {
"prebuild": "rm -rf ./dist",
"prepublish": "yarn build",
"build": "yarn asbuild:untouched && yarn asbuild:optimized && yarn build:lib",
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --runtime none --validate --debug",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --runtime none --validate -O3z --noAssert",
"build:lib": "babel src -d lib --copy-files",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"test": "yarn run test:as-ci && yarn run test:unit",
"test:unit": "yarn run test:unit:node && yarn run test:unit:browser",
"test:unit:node": "mocha -r .babel-register test/*.spec.js",
"benchmark": "node ./node_modules/.bin/benchmark 'test/benchmark.test.js'",
"benchmark:local": "yarn benchmark --local",
"test:unit:browser": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless karma.config.js",
"test:ci": "yarn test:as-ci",
"test:as": "asp --nortrace --verbose",
"test:as-ci": "asp --nortrace 2> /dev/null"
},
"dependencies": {
"@assemblyscript/loader": "^0.9.2",
"buffer": "^5.4.3"
},
"devDependencies": {
"@as-pect/assembly": "2.8.1",
"@as-pect/cli": "2.8.1",
"@as-pect/core": "2.8.1",
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/register": "^7.7.4",
"@chainsafe/babel-plugin-inline-binary-import": "^1.0.3",
"assemblyscript": "0.9.2",
"babel-loader": "^8.0.6",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"karma": "^4.4.1",
"karma-babel-preprocessor": "^8.0.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-webpack": "^4.0.2",
"@dapplion/benchmark": "^0.1.6",
"mocha": "^8.3.0",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7"
}
"name": "@chainsafe/as-sha256",
"version": "0.3.0",
"description": "An AssemblyScript implementation of SHA256",
"author": "ChainSafe Systems",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/ChainSafe/as-sha256/issues"
},
"homepage": "https://github.com/ChainSafe/as-sha256#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/chainsafe/as-sha256.git"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"build"
],
"scripts": {
"prebuild": "rm -rf ./dist && node -r ts-node/register ./scripts/codegen.ts",
"prepublish": "yarn build",
"build": "yarn asbuild:untouched && yarn asbuild:optimized && yarn build:lib",
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --runtime none --validate --debug",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --runtime none --validate -O3z --noAssert",
"build:lib": "tsc -p tsconfig.build.json",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"test": "yarn run test:as-ci && yarn run test:unit",
"test:unit": "yarn run test:unit:node && yarn run test:unit:browser",
"test:unit:node": "mocha -r ts-node/register test/unit/*.test.ts",
"test:unit:browser": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless karma.config.js",
"benchmark": "node -r ts-node/register ./node_modules/.bin/benchmark 'test/perf/index.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test:ci": "yarn test:as-ci",
"test:as": "asp --nortrace --verbose",
"test:as-ci": "asp --nortrace 2> /dev/null"
},
"devDependencies": {
"@as-pect/assembly": "2.8.1",
"@as-pect/cli": "2.8.1",
"@as-pect/core": "2.8.1",
"@chainsafe/babel-plugin-inline-binary-import": "^1.0.3",
"assemblyscript": "0.9.2",
"benchmark": "^2.1.4"
},
"gitHead": "59065e6965a04d829d49dfaa870f237a38280c4e"
}

@@ -13,3 +13,3 @@ # as-sha256

```typescript
import SHA256 from "@chainsafe/as-sha256";
import {digest, digest64, SHA256} from "@chainsafe/as-sha256";

@@ -24,6 +24,6 @@ let hash: Uint8Array;

// or use a one-pass interface
hash = SHA256.digest(Buffer.from("Hello world"));
hash = digest(Buffer.from("Hello world"));
// or use a faster one-pass interface for hashing (only) 64 bytes
hash = SHA256.digest64(Buffer.from("abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh"));
hash = digest64(Buffer.from("abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh"));
```

@@ -30,0 +30,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc