Add signatureVerify (#552)

* Add signatureVerify

* addressOrPublicKey typo

* Flatten verify, allow extra types

* Add signatureVerify tests

* De-dup address checksum checks
This commit is contained in:
Jaco Greeff
2020-02-24 11:55:15 +01:00
committed by GitHub
parent 341a6b0c08
commit 804ed13d0a
14 changed files with 221 additions and 50 deletions
+1 -3
View File
@@ -23,9 +23,7 @@ export default function u8aFixLength (value: Uint8Array, bitLength = -1, atStart
if (bitLength === -1 || value.length === byteLength) {
return value;
}
if (value.length > byteLength) {
} else if (value.length > byteLength) {
return value.subarray(0, byteLength);
}
+3 -5
View File
@@ -17,9 +17,7 @@
* ```
*/
export default function u8aToBuffer (value?: Uint8Array | null): Buffer {
if (!value) {
return Buffer.from([]);
}
return Buffer.from(value);
return !value
? Buffer.from([])
: Buffer.from(value);
}
+3 -5
View File
@@ -33,9 +33,7 @@ try {
* ```
*/
export default function u8aToString (value?: Uint8Array | null): string {
if (!value || !value.length) {
return '';
}
return decoder.decode(value);
return !value?.length
? ''
: decoder.decode(value);
}
+5 -11
View File
@@ -27,21 +27,15 @@ import stringToU8a from '../string/toU8a';
export default function u8aToU8a (value?: number[] | Buffer | Uint8Array | string | null): Uint8Array {
if (!value) {
return new Uint8Array();
}
if (isBuffer(value)) {
} else if (isBuffer(value)) {
return bufferToU8a(value);
}
if (isString(value)) {
} else if (isString(value)) {
return isHex(value)
? hexToU8a(value)
: stringToU8a(value);
}
if (Array.isArray(value)) {
return Uint8Array.from(value);
}
return value;
return Array.isArray(value)
? Uint8Array.from(value)
: value;
}