fix: reject base58 public keys that are too short (#474)

This commit is contained in:
Justin Starry
2019-08-28 10:45:17 -04:00
committed by Michael Vines
parent 0379615c76
commit eec8f6184c
2 changed files with 17 additions and 1 deletions

View File

@@ -19,7 +19,11 @@ export class PublicKey {
this._bn = new BN(value.substring(2), 16);
} else {
// assume base 58 encoding by default
this._bn = new BN(bs58.decode(value));
const decoded = bs58.decode(value);
if (decoded.length != 32) {
throw new Error(`Invalid public key input`);
}
this._bn = new BN(decoded);
}
} else {
this._bn = new BN(value);