-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7a701c
commit 950c2d3
Showing
3 changed files
with
97 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
export interface OptionsHexOutput { | ||
outputFormat?: 'hex'; | ||
} | ||
|
||
export interface OptionBufferOutput { | ||
outputFormat: 'buffer'; | ||
} | ||
|
||
/** | ||
[SHA-1 is insecure](https://stackoverflow.com/a/38045085/64949) and should not be used for anything sensitive. | ||
_Note that even though it returns a promise, [in Node.js, the operation is synchronous 💩](https://github.com/nodejs/node/issues/678)._ | ||
@returns The hex-encoded hash. | ||
*/ | ||
export function sha1( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options?: OptionsHexOutput | ||
): Promise<string>; | ||
export function sha1( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options: OptionBufferOutput | ||
): Promise<ArrayBuffer>; | ||
|
||
/** | ||
_Note that even though it returns a promise, [in Node.js, the operation is synchronous 💩](https://github.com/nodejs/node/issues/678)._ | ||
@returns The hex-encoded hash. | ||
@example | ||
``` | ||
import {sha256} from 'crypto-hash'; | ||
(async () => { | ||
console.log(await sha256('🦄')); | ||
//=> '5df82936cbf0864be4b7ba801bee392457fde9e4' | ||
})(); | ||
``` | ||
*/ | ||
export function sha256( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options?: OptionsHexOutput | ||
): Promise<string>; | ||
export function sha256( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options: OptionBufferOutput | ||
): Promise<ArrayBuffer>; | ||
|
||
/** | ||
_Note that even though it returns a promise, [in Node.js, the operation is synchronous 💩](https://github.com/nodejs/node/issues/678)._ | ||
@returns The hex-encoded hash. | ||
*/ | ||
export function sha384( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options?: OptionsHexOutput | ||
): Promise<string>; | ||
export function sha384( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options: OptionBufferOutput | ||
): Promise<ArrayBuffer>; | ||
|
||
/** | ||
_Note that even though it returns a promise, [in Node.js, the operation is synchronous 💩](https://github.com/nodejs/node/issues/678)._ | ||
@returns The hex-encoded hash. | ||
*/ | ||
export function sha512( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options?: OptionsHexOutput | ||
): Promise<string>; | ||
export function sha512( | ||
input: string | ArrayBuffer | ArrayBufferView, | ||
options: OptionBufferOutput | ||
): Promise<ArrayBuffer>; |
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,15 @@ | ||
import {expectType} from 'tsd'; | ||
import {sha1, sha256, sha384, sha512} from '.'; | ||
|
||
expectType<Promise<string>>(sha1('🦄')); | ||
expectType<Promise<ArrayBuffer>>(sha1('🦄', {outputFormat: 'buffer'})); | ||
expectType<Promise<string>>(sha1('🦄', {outputFormat: 'hex'})); | ||
expectType<Promise<string>>(sha256('🦄')); | ||
expectType<Promise<ArrayBuffer>>(sha256('🦄', {outputFormat: 'buffer'})); | ||
expectType<Promise<string>>(sha256('🦄', {outputFormat: 'hex'})); | ||
expectType<Promise<string>>(sha384('🦄')); | ||
expectType<Promise<ArrayBuffer>>(sha384('🦄', {outputFormat: 'buffer'})); | ||
expectType<Promise<string>>(sha384('🦄', {outputFormat: 'hex'})); | ||
expectType<Promise<string>>(sha512('🦄')); | ||
expectType<Promise<ArrayBuffer>>(sha512('🦄', {outputFormat: 'buffer'})); | ||
expectType<Promise<string>>(sha512('🦄', {outputFormat: 'hex'})); |
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