Skip to content

Commit

Permalink
Throw errors when trying to RLP encode integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Mar 17, 2020
1 parent 3e44aac commit 9ea16e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/bytes/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
7 changes: 5 additions & 2 deletions packages/rlp/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9ea16e5

Please sign in to comment.