From b5e6c7c8a8e3ba4818b431bce2819bddbdad42e1 Mon Sep 17 00:00:00 2001 From: Nathan Hardy Date: Sun, 23 Sep 2018 15:53:21 +1000 Subject: [PATCH] Add typings for sha256 --- types/sha256/index.d.ts | 23 +++++++++++++++++++++++ types/sha256/sha256-tests.ts | 10 ++++++++++ types/sha256/tsconfig.json | 23 +++++++++++++++++++++++ types/sha256/tslint.json | 1 + 4 files changed, 57 insertions(+) create mode 100644 types/sha256/index.d.ts create mode 100644 types/sha256/sha256-tests.ts create mode 100644 types/sha256/tsconfig.json create mode 100644 types/sha256/tslint.json diff --git a/types/sha256/index.d.ts b/types/sha256/index.d.ts new file mode 100644 index 0000000000..bf89598fc6 --- /dev/null +++ b/types/sha256/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for sha256 0.2 +// Project: https://github.com/cryptocoinjs/sha256 +// Definitions by: Nathan Hardy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; diff --git a/types/sha256/sha256-tests.ts b/types/sha256/sha256-tests.ts new file mode 100644 index 0000000000..22b35eff31 --- /dev/null +++ b/types/sha256/sha256-tests.ts @@ -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 }); diff --git a/types/sha256/tsconfig.json b/types/sha256/tsconfig.json new file mode 100644 index 0000000000..45039e10d8 --- /dev/null +++ b/types/sha256/tsconfig.json @@ -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" + ] +} diff --git a/types/sha256/tslint.json b/types/sha256/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sha256/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }