Merge pull request #28475 from danwbyrne/wif

adds typings for the 'wif' package
This commit is contained in:
Armando Aguirre
2018-08-29 14:59:52 -07:00
committed by GitHub
4 changed files with 65 additions and 0 deletions

27
types/wif/index.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
// Type definitions for wif 2.0
// Project: https://github.com/bitcoinjs/wif
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
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;

19
types/wif/tsconfig.json Normal file
View File

@@ -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"
]
}

3
types/wif/tslint.json Normal file
View File

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

16
types/wif/wif-tests.ts Normal file
View File

@@ -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);