Add typings for sha256

This commit is contained in:
Nathan Hardy 2018-09-23 15:53:21 +10:00
parent adf4e18eef
commit b5e6c7c8a8
4 changed files with 57 additions and 0 deletions

23
types/sha256/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
// Type definitions for sha256 0.2
// Project: https://github.com/cryptocoinjs/sha256
// Definitions by: Nathan Hardy <https://github.com/nhardy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
type Message = string | Buffer | number[];
interface Sha256 {
(message: Message, options?: { asString: true }): string;
(message: Message, options: { asBytes: true }): number[];
}
interface Sha256WithX2 extends Sha256 {
x2: Sha256;
}
declare const sha256: Sha256WithX2;
export = sha256;
export as namespace sha256;

View File

@ -0,0 +1,10 @@
import sha256 = require("sha256");
const test1: string = sha256('message');
const test2: number[] = sha256('message', { asBytes: true });
const test3: string = sha256('message', { asString: true });
const test4: string = sha256(Buffer.from('message'));
const test5: string = sha256(Array.from(Buffer.from('message')));
const test6: string = sha256.x2('message');
const test7: number[] = sha256.x2('message', { asBytes: true });
const test8: string = sha256.x2('message', { asString: true });

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sha256-tests.ts"
]
}

1
types/sha256/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }