Skip to content

Commit d447867

Browse files
add type definitions for Bitauth (DefinitelyTyped#47421)
1 parent 4d248b5 commit d447867

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

types/bitauth/bitauth-tests.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as bitauth from 'bitauth';
2+
3+
const keys = bitauth.generateSin();
4+
5+
let pubKey = bitauth.getPublicKeyFromPrivateKey(keys.priv);
6+
pubKey = bitauth.getPublicKeyFromPrivateKey(keys.priv);
7+
bitauth.getSinFromPublicKey(keys.pub);
8+
const contract = 'something to sign';
9+
const signature = bitauth.sign(contract, keys.priv);
10+
let verified = bitauth.verifySignature(contract, keys.pub, signature);
11+
bitauth.verifySignature(contract, keys.pub, signature, (err?: Error, valid?: boolean) => {
12+
verified = err ? false : valid;
13+
});
14+
let valid = bitauth.validateSin(keys.sin);
15+
bitauth.validateSin(keys.sin, (err?: Error) => {
16+
valid = err ? false : true;
17+
});
18+
19+
const secret = 'o hai, nsa. how i do teh cryptos?';
20+
const password = 's4705hiru13z!';
21+
22+
const enc = bitauth.encrypt(password, secret);
23+
bitauth.decrypt(password, enc);

types/bitauth/index.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Type definitions for bitauth 0.4
2+
// Project: https://github.com/bitpay/bitauth#readme
3+
// Definitions by: Justin Langston <https://github.com/nitsujlangston>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
import { BinaryLike } from 'crypto';
7+
import { RequestHandler } from 'express';
8+
9+
export as namespace bitauth;
10+
11+
interface callback {
12+
(err?: Error, valid?: boolean): any;
13+
}
14+
15+
export function generateSin(): {
16+
created: number;
17+
priv: string;
18+
pub: string;
19+
sin: string;
20+
};
21+
export function getPublicKeyFromPrivateKey(privkey: string | Uint8Array): string;
22+
export function getSinFromPublicKey(pubkey: string | Uint8Array): string;
23+
export function sign(data: string | Uint8Array, privkey: string | Uint8Array): Uint8Array;
24+
export function verifySignature(
25+
data: string | Uint8Array,
26+
pubkey: string | Uint8Array,
27+
hexsignature: string | Uint8Array,
28+
callback?: callback,
29+
): boolean | void;
30+
export function validateSin(sin: string, callback?: callback): boolean | void;
31+
export function encrypt(password: BinaryLike, str: string): string;
32+
export function decrypt(password: BinaryLike, str: string): string;
33+
export function middleware(): RequestHandler;
34+
35+
export {};

types/bitauth/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"bitauth-tests.ts"
22+
]
23+
}

types/bitauth/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)