Pre-checks on verify input lengths (#608)

* Pre-checks on verify input lengths

* Small cleanup

* Update error signatures
This commit is contained in:
Jaco Greeff
2020-06-01 10:27:08 +02:00
committed by GitHub
parent cc5b7ed0ad
commit bdb14f91a8
12 changed files with 67 additions and 21 deletions
+1 -2
View File
@@ -19,8 +19,7 @@ export default function decode (encoded: string | Uint8Array, ignoreChecksum?: b
}
const decoded = bufferToU8a(bs58.decode(encoded));
const error = (message: string): string =>
`Decoding ${encoded as string}: ${message}`;
const error = (message: string) => `Decoding ${encoded as string}: ${message}`;
// assert(defaults.allowedPrefix.includes(decoded[0] as Prefix), error('Invalid decoded address prefix'));
assert(defaults.allowedEncodedLengths.includes(decoded.length), error('Invalid decoded address length'));
@@ -20,7 +20,6 @@ export default function encode (_key: Uint8Array | string, ss58Format: Prefix =
assert(defaults.allowedDecodedLengths.includes(key.length), `Expected a valid key to convert, with length ${defaults.allowedDecodedLengths.join(', ')}`);
const isPublicKey = key.length === 32;
const input = u8aConcat(new Uint8Array([ss58Format]), key);
const hash = sshash(input);