mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-02-03 23:42:50 +00:00
[cashaddrjs] Add types for cashaddrjs (#37530)
This commit is contained in:
parent
34dddd92f9
commit
37a3f3dd67
19
types/cashaddrjs/cashaddrjs-tests.ts
Normal file
19
types/cashaddrjs/cashaddrjs-tests.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import * as cashaddr from 'cashaddrjs';
|
||||
|
||||
let someAddress = 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a';
|
||||
let prefix: string;
|
||||
let type: string;
|
||||
let hash: Uint8Array;
|
||||
({ prefix, type, hash } = cashaddr.decode(someAddress));
|
||||
someAddress = cashaddr.encode(prefix, type, hash);
|
||||
const someInvalidInput = 'abcdefghijklmn';
|
||||
try {
|
||||
cashaddr.decode(someInvalidInput);
|
||||
} catch (err) {
|
||||
if (err instanceof cashaddr.ValidationError) {
|
||||
// As expected.
|
||||
} else {
|
||||
const someMessage = 'some error message';
|
||||
throw new cashaddr.ValidationError(someMessage);
|
||||
}
|
||||
}
|
||||
31
types/cashaddrjs/index.d.ts
vendored
Normal file
31
types/cashaddrjs/index.d.ts
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// Type definitions for cashaddrjs 0.3
|
||||
// Project: https://github.com/bitcoincashjs/cashaddrjs#readme
|
||||
// Definitions by: Emilio Almansi <https://github.com/ealmansi>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export as namespace cashaddr;
|
||||
|
||||
/**
|
||||
* Encodes a hash from a given type into a Bitcoin Cash address with the given prefix.
|
||||
*
|
||||
* @param prefix Network prefix. E.g.: 'bitcoincash'.
|
||||
* @param type Type of address to generate. Either 'P2PKH' or 'P2SH'.
|
||||
* @param hash Hash to encode represented as an array of 8-bit integers.
|
||||
* @throws {ValidationError}
|
||||
*/
|
||||
export function encode(prefix: string, type: string, hash: Uint8Array): string;
|
||||
|
||||
/**
|
||||
* Decodes the given address into its constituting prefix, type and hash.
|
||||
*
|
||||
* @param address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'.
|
||||
* @throws {ValidationError}
|
||||
*/
|
||||
export function decode(address: string): { prefix: string, type: string, hash: Uint8Array };
|
||||
|
||||
/**
|
||||
* Error thrown when encoding or decoding fail due to invalid input.
|
||||
*
|
||||
* @param message Error description.
|
||||
*/
|
||||
export class ValidationError extends Error { constructor(message: string); }
|
||||
23
types/cashaddrjs/tsconfig.json
Normal file
23
types/cashaddrjs/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"cashaddrjs-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/cashaddrjs/tslint.json
Normal file
1
types/cashaddrjs/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user