mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
20 lines
592 B
TypeScript
20 lines
592 B
TypeScript
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);
|
|
}
|
|
}
|