fix: remove decimal string support from PublicKey ctor

This commit is contained in:
Michael Vines
2018-10-24 07:58:25 -07:00
parent 02787df7b9
commit e50b705de3
2 changed files with 20 additions and 21 deletions

View File

@ -12,25 +12,17 @@ export class PublicKey {
/**
* Create a new PublicKey object
*/
constructor(number: number | string | Buffer | Array<number>) {
for (;;) {
if (typeof number === 'string') {
// base 58 encoded?
if (/^[1-9A-HJ-NP-Za-km-z]{43,44}$/.test(number)) {
this._bn = new BN(bs58.decode(number));
break;
}
// hexadecimal number
if (number.startsWith('0x')) {
this._bn = new BN(number.substring(2), 16);
break;
}
constructor(value: number | string | Buffer | Array<number>) {
if (typeof value === 'string') {
// hexadecimal number
if (value.startsWith('0x')) {
this._bn = new BN(value.substring(2), 16);
} else {
// assume base 58 encoding by default
this._bn = new BN(bs58.decode(value));
}
this._bn = new BN(number);
break;
} else {
this._bn = new BN(value);
}
if (this._bn.byteLength() > 32) {