From a026855b11801d20d5d014649870dace1963be86 Mon Sep 17 00:00:00 2001 From: Mick Charuwichitratana Date: Sat, 23 Dec 2017 19:14:40 +0700 Subject: [PATCH] [@types/bip38] Add bip38 type definition --- types/bip38/bip38-tests.ts | 30 ++++++++++++++++++++++++++++ types/bip38/index.d.ts | 41 ++++++++++++++++++++++++++++++++++++++ types/bip38/tsconfig.json | 23 +++++++++++++++++++++ types/bip38/tslint.json | 3 +++ 4 files changed, 97 insertions(+) create mode 100644 types/bip38/bip38-tests.ts create mode 100644 types/bip38/index.d.ts create mode 100644 types/bip38/tsconfig.json create mode 100644 types/bip38/tslint.json diff --git a/types/bip38/bip38-tests.ts b/types/bip38/bip38-tests.ts new file mode 100644 index 0000000000..c48fc9597b --- /dev/null +++ b/types/bip38/bip38-tests.ts @@ -0,0 +1,30 @@ +import * as bip38 from 'bip38'; + +const myWifString = '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'; + +// Result from wif.decode for testing +const decoded = { + version: 48, + privateKey: Buffer.from('12345678901234567890123456789012'), + compressed: true +}; + +// Test encrypt without progressCallback +const encryptedKey = bip38.encrypt(decoded.privateKey, decoded.compressed, 'TestingOneTwoThree'); + +// Test encrypt with progressCallback +bip38.encrypt(decoded.privateKey, decoded.compressed, 'TestingOneTwoThree', (status: bip38.ProgressStatus) => { + status.current; + status.total; + status.percent; +}); + +// Test decrypt without progressCallback +const decryptedKey = bip38.decrypt(encryptedKey, 'TestingOneTwoThree'); + +// Test decrypt with progressCallback +bip38.decrypt(encryptedKey, 'TestingOneTwoThree', (status: bip38.ProgressStatus) => { + status.current; + status.total; + status.percent; +}); diff --git a/types/bip38/index.d.ts b/types/bip38/index.d.ts new file mode 100644 index 0000000000..8842c6a241 --- /dev/null +++ b/types/bip38/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for bip38 2.0 +// Project: https://github.com/bitcoinjs/bip38 +// Definitions by: Satana Charuwichitratana +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// + +// Note: When there is @types/scryptsy, ProgressStatus and ScryptParams should be referred from the definition instead +export interface ProgressStatus { + current: number; + total: number; + percent: number; +} +export interface ScryptParams { + N: number; + r: number; + p: number; +} + +export function decrypt(string: string, passphrase: string, + progressCallback?: (status: ProgressStatus) => void, + scryptParams?: ScryptParams): { privateKey: Buffer, compressed: boolean }; + +export function decryptECMult(buffer: Buffer, passphrase: string, + progressCallback?: (status: ProgressStatus) => void, + scryptParams?: ScryptParams): { privateKey: Buffer, compressed: boolean }; + +export function decryptRaw(buffer: Buffer, passphrase: string, + progressCallback?: (status: ProgressStatus) => void, + scryptParams?: ScryptParams): { privateKey: Buffer, compressed: boolean }; + +export function encrypt(buffer: Buffer, compressed: boolean, passphrase: string, + progressCallback?: (status: ProgressStatus) => void, + scryptParams?: ScryptParams): string; + +export function encryptRaw(buffer: Buffer, compressed: boolean, passphrase: string, + progressCallback?: (status: ProgressStatus) => void, + scryptParams?: ScryptParams): Buffer; + +export function verify(string: string): boolean; diff --git a/types/bip38/tsconfig.json b/types/bip38/tsconfig.json new file mode 100644 index 0000000000..6ce875b1d1 --- /dev/null +++ b/types/bip38/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", + "bip38-tests.ts" + ] +} diff --git a/types/bip38/tslint.json b/types/bip38/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/bip38/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}