Throw errors when trying to RLP encode integers.

This commit is contained in:
Richard Moore 2020-03-17 13:55:45 -04:00
parent 3e44aac8f1
commit 9ea16e5172
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 6 additions and 3 deletions

@ -97,7 +97,7 @@ export function arrayify(value: BytesLike | Hexable | number, options?: DataOpti
const result = [];
while (value) {
result.unshift(value & 0xff);
value /= 256;
value = parseInt(String(value / 256));
}
if (result.length === 0) { result.push(0); }

@ -2,8 +2,7 @@
//See: https://github.com/ethereum/wiki/wiki/RLP
import { arrayify, BytesLike, hexlify } from "@ethersproject/bytes";
import { arrayify, BytesLike, hexlify, isBytesLike } from "@ethersproject/bytes";
function arrayifyInteger(value: number): Array<number> {
const result = [];
@ -41,6 +40,10 @@ function _encode(object: Array<any> | string): Array<number> {
}
if (!isBytesLike(object)) {
throw new Error("RLP object must be BytesLike");
}
const data: Array<number> = Array.prototype.slice.call(arrayify(object));
if (data.length === 1 && data[0] <= 0x7f) {