mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #22482 from micksatana/add-bip38-type-definition
[@types/bip38] Add bip38 type definition
This commit is contained in:
@@ -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;
|
||||
});
|
||||
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
// Type definitions for bip38 2.0
|
||||
// Project: https://github.com/bitcoinjs/bip38
|
||||
// Definitions by: Satana Charuwichitratana <https://github.com/micksatana>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
// 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;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user