diff --git a/packages/bytes/src.ts/index.ts b/packages/bytes/src.ts/index.ts index 1872e15cf..f291c5191 100644 --- a/packages/bytes/src.ts/index.ts +++ b/packages/bytes/src.ts/index.ts @@ -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); } diff --git a/packages/rlp/src.ts/index.ts b/packages/rlp/src.ts/index.ts index 6fd0dfad6..1f00f1033 100644 --- a/packages/rlp/src.ts/index.ts +++ b/packages/rlp/src.ts/index.ts @@ -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 { const result = []; @@ -41,6 +40,10 @@ function _encode(object: Array | string): Array { } + if (!isBytesLike(object)) { + throw new Error("RLP object must be BytesLike"); + } + const data: Array = Array.prototype.slice.call(arrayify(object)); if (data.length === 1 && data[0] <= 0x7f) {