-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- TypeScript interfaces. #6, #9 - HMAC feature. - support for web worker. #14 ### Fixed - deprecated `new Buffer`, replace with `Buffer.from`. #10 - dependencies and security issues. - refactor: simplify formatMessage internal logic. - Generates incorrect hash in some cases. ### Changed - remove `eval` and use `require` directly. #8 - throw error by Error oject. - throw error if update after finalize - use unsigned right shift.
- Loading branch information
Showing
15 changed files
with
901 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
type Message = string | number[] | ArrayBuffer | Uint8Array; | ||
|
||
interface Hasher { | ||
/** | ||
* Update hash | ||
* | ||
* @param message The message you want to hash. | ||
*/ | ||
update(message: Message): Hasher; | ||
|
||
/** | ||
* Return hash in hex string. | ||
*/ | ||
hex(): string; | ||
|
||
/** | ||
* Return hash in hex string. | ||
*/ | ||
toString(): string; | ||
|
||
/** | ||
* Return hash in ArrayBuffer. | ||
*/ | ||
arrayBuffer(): ArrayBuffer; | ||
|
||
/** | ||
* Return hash in integer array. | ||
*/ | ||
digest(): number[]; | ||
|
||
/** | ||
* Return hash in integer array. | ||
*/ | ||
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: Message, message: Message): string; | ||
|
||
/** | ||
* Create a hash object using a secret key. | ||
* | ||
* @param secretKey The Secret Key | ||
*/ | ||
create(secretKey: Message): 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: Message, message: Message): Hasher; | ||
|
||
/** | ||
* Return hash in hex string. | ||
* | ||
* @param secretKey The Secret Key | ||
* @param message The message you want to hash. | ||
*/ | ||
hex(secretKey: Message, message: Message): string; | ||
|
||
/** | ||
* Return hash in ArrayBuffer. | ||
* | ||
* @param secretKey The Secret Key | ||
* @param message The message you want to hash. | ||
*/ | ||
arrayBuffer(secretKey: Message, message: Message): ArrayBuffer; | ||
|
||
/** | ||
* Return hash in integer array. | ||
* | ||
* @param secretKey The Secret Key | ||
* @param message The message you want to hash. | ||
*/ | ||
digest(secretKey: Message, message: Message): number[]; | ||
|
||
/** | ||
* Return hash in integer array. | ||
* | ||
* @param secretKey The Secret Key | ||
* @param message The message you want to hash. | ||
*/ | ||
array(secretKey: Message, message: Message): number[]; | ||
} | ||
|
||
interface Hash { | ||
/** | ||
* Hash and return hex string. | ||
* | ||
* @param message The message you want to hash. | ||
*/ | ||
(message: Message): string; | ||
|
||
/** | ||
* Create a hash object. | ||
*/ | ||
create(): Hasher; | ||
|
||
/** | ||
* Create a hash object and hash message. | ||
* | ||
* @param message The message you want to hash. | ||
*/ | ||
update(message: Message): Hasher; | ||
|
||
/** | ||
* Return hash in hex string. | ||
* | ||
* @param message The message you want to hash. | ||
*/ | ||
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 sha1: Hash; |
Oops, something went wrong.