diff --git a/types/wif/index.d.ts b/types/wif/index.d.ts new file mode 100644 index 0000000000..21b4175905 --- /dev/null +++ b/types/wif/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for wif 2.0 +// Project: https://github.com/bitcoinjs/wif +// Definitions by: Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export interface WIFReturn { + readonly version: number; + readonly privateKey: Buffer; + readonly compressed: boolean; +} + +export function decodeRaw(buffer: Buffer, version?: number): WIFReturn; +export function decode(string: string, version: number): WIFReturn; + +export function encodeRaw( + version: number, + privateKey: Buffer, + compressed: boolean +): Buffer; + +export function encode( + version: number | WIFReturn, + privateKey: Buffer, + compressed: boolean +): Buffer; diff --git a/types/wif/tsconfig.json b/types/wif/tsconfig.json new file mode 100644 index 0000000000..f412a0b7cc --- /dev/null +++ b/types/wif/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "wif-tests.ts" + ] +} diff --git a/types/wif/tslint.json b/types/wif/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/wif/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/wif/wif-tests.ts b/types/wif/wif-tests.ts new file mode 100644 index 0000000000..b833d7b1f5 --- /dev/null +++ b/types/wif/wif-tests.ts @@ -0,0 +1,16 @@ +import wif = require('wif'); + +const testString = 'test'; +const testBuffer = Buffer.from(testString); + +// $ExpectType WIFReturn +wif.decodeRaw(testBuffer); +// $ExpectType WIFReturn +wif.decodeRaw(testBuffer, 0); +// $ExpectType WIFReturn +wif.decode(testString, 0); + +// $ExpectType Buffer +wif.encodeRaw(1, testBuffer, true); +// $ExpectType Buffer +wif.encode(1, testBuffer, true);