* 3.7

* Update new rules

* RegExp

* formatBalance cleanups

* Revert

* Formatting

* fill

* format test fix

* cleanups

* Cleanups

* Expand bip39 tests

* Cleanups

* Cleanups
This commit is contained in:
Jaco Greeff
2020-11-01 14:44:14 +01:00
committed by GitHub
parent 4a0fa7f615
commit 3230663ae1
37 changed files with 345 additions and 2434 deletions
+20 -13
View File
@@ -7,6 +7,22 @@ for (let n = 0; n < 256; ++n) {
ALPHABET[n] = n.toString(16).padStart(2, '0');
}
/** @internal */
function extract (value: Uint8Array): string {
const result = new Array(value.length) as string[];
for (let i = 0; i < value.length; i++) {
result[i] = ALPHABET[value[i]];
}
return result.join('');
}
/** @internal */
function trim (value: Uint8Array, halfLength: number): string {
return `${u8aToHex(value.subarray(0, halfLength), -1, false)}…${u8aToHex(value.subarray(value.length - halfLength), -1, false)}`;
}
/**
* @name u8aToHex
* @summary Creates a hex string from a Uint8Array object.
@@ -32,17 +48,8 @@ export default function u8aToHex (value?: Uint8Array | null, bitLength = -1, isP
const byteLength = Math.ceil(bitLength / 8);
if (byteLength > 0 && value.length > byteLength) {
const halfLength = Math.ceil(byteLength / 2);
return `${u8aToHex(value.subarray(0, halfLength), -1, isPrefixed)}…${u8aToHex(value.subarray(value.length - halfLength), -1, false)}`;
}
const result = new Array(value.length) as string[];
for (let i = 0; i < value.length; i++) {
result[i] = ALPHABET[value[i]];
}
return prefix + result.join('');
return prefix + ((byteLength > 0 && value.length > byteLength)
? trim(value, Math.ceil(byteLength / 2))
: extract(value)
);
}