- incorrect result when first bit is 1 of bytes.

Changed
- throw error by Error oject. #13

Added
- TypeScript interfaces. #12
pull/16/merge v0.9.0
Yi-Cyuan Chen 8 years ago
parent e35c679c2b
commit a36824e9fb

@ -1,5 +1,15 @@
# Change Log
## v0.9.0 / 2017-12-18
### Fixed
- incorrect result when first bit is 1 of bytes.
### Changed
- throw error by Error oject. #13
### Added
- TypeScript interfaces. #12
## v0.8.0 / 2017-11-19
### Added
- support for web worker.

@ -1,6 +1,6 @@
{
"name": "js-sha256",
"version": "0.8.0",
"version": "0.9.0",
"main": ["src/sha256.js"],
"ignore": [
"samples",

File diff suppressed because one or more lines are too long

88
index.d.ts vendored

@ -34,6 +34,63 @@ interface Hasher {
array(): number[];
}
interface Hmac {
/**
* Computes a Hash-based message authentication code (HMAC) using a secret key
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
(secretKey: string, message: Message): string;
/**
* Create a hash object using a secret key.
*
* @param secretKey The Secret Key
*/
create(secretKey: string): Hasher;
/**
* Create a hash object and hash message using a secret key
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
update(secretKey: string, message: Message): Hasher;
/**
* Return hash in hex string.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
hex(secretKey: string, message: Message): string;
/**
* Return hash in ArrayBuffer.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
arrayBuffer(secretKey: string, message: Message): ArrayBuffer;
/**
* Return hash in integer array.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
digest(secretKey: string, message: Message): number[];
/**
* Return hash in integer array.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
array(secretKey: string, message: Message): number[];
}
interface Hash {
/**
* Hash and return hex string.
@ -55,12 +112,37 @@ interface Hash {
update(message: Message): Hasher;
/**
* Computes a Hash-based message authentication code (HMAC) using a secret key
* Return hash in hex string.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
hmac(secretKey: string, message: Message): string;
hex(message: Message): string;
/**
* Return hash in ArrayBuffer.
*
* @param message The message you want to hash.
*/
arrayBuffer(message: Message): ArrayBuffer;
/**
* Return hash in integer array.
*
* @param message The message you want to hash.
*/
digest(message: Message): number[];
/**
* Return hash in integer array.
*
* @param message The message you want to hash.
*/
array(message: Message): number[];
/**
* HMAC interface
*/
hmac: Hmac;
}
export var sha256: Hash;

@ -1,6 +1,6 @@
{
"name": "js-sha256",
"version": "0.8.0",
"version": "0.9.0",
"description": "A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha256.js",
"devDependencies": {

@ -1,7 +1,7 @@
/**
* [js-sha256]{@link https://github.com/emn178/js-sha256}
*
* @version 0.8.0
* @version 0.9.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
@ -257,7 +257,7 @@
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.hBytes << 3 | this.bytes >> 29;
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
blocks[15] = this.bytes << 3;
this.hash();
};

Loading…
Cancel
Save