From ed5c96c2c189594db08e851059c4a4d9d5189135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kapa=C5=82a?= Date: Mon, 11 Apr 2022 12:16:08 +0200 Subject: [PATCH] Fix arrayLike (#37) * Fix arrayLike * Update src/BigNumber.ts Co-authored-by: Marc Rousavy --- src/BigNumber.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/BigNumber.ts b/src/BigNumber.ts index bb9886b..a231732 100644 --- a/src/BigNumber.ts +++ b/src/BigNumber.ts @@ -225,11 +225,11 @@ export class BN { return native.toArray.call(this.internalBigNum, endian === 'le', len || -1); } - // TODO(MARC ts magician ) + // TODO(MARC ts magician - please check ) toArrayLike { buffer: ArrayBuffer }>( arrayLike: T, - endian: 'le' | 'be', - len: number + endian?: 'le' | 'be', + len?: number ) { if (typeof arrayLike !== 'function') { console.log('toArrayLike exptects constructor'); @@ -240,7 +240,9 @@ export class BN { return this.toArray(endian, len); } - const res = new (arrayLike as any)(len); + const outLen = len != null ? len : this.byteLength(); + + const res = new (arrayLike as any)(outLen); native.toArrayLike.call( this.internalBigNum,