User template string type for isHex (#1020)

* User template string type for isHex

* isHex/isString combo checks
This commit is contained in:
Jaco
2021-06-22 16:05:14 +02:00
committed by GitHub
parent 7d09f0892a
commit 0ef761e899
5 changed files with 16 additions and 22 deletions
+1 -1
View File
@@ -29,6 +29,6 @@ export function decodeAddress (encoded?: string | Uint8Array | null, ignoreCheck
return decoded.slice(ss58Length, endPos);
} catch (error) {
throw new Error(`Decoding ${encoded as string}: ${(error as Error).message}`);
throw new Error(`Decoding ${encoded}: ${(error as Error).message}`);
}
}
@@ -60,13 +60,11 @@ export class DeriveJunction {
public soft (value: number | string | BigInt | BN | Uint8Array): DeriveJunction {
if (isNumber(value) || isBn(value) || isBigInt(value)) {
return this.soft(bnToHex(value, BN_OPTIONS));
} else if (isHex(value)) {
return this.soft(hexToU8a(value));
} else if (isString(value)) {
return isHex(value)
? this.soft(hexToU8a(value))
: this.soft(compactAddLength(stringToU8a(value)));
}
if (value.length > JUNCTION_ID_LEN) {
return this.soft(compactAddLength(stringToU8a(value)));
} else if (value.length > JUNCTION_ID_LEN) {
return this.soft(blake2AsU8a(value));
}