From b06be7cae52071bdf814818829d9241febc218fc Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:30:16 +0000
Subject: [PATCH 01/10] Initial plan
From ce3a50ac447fcaf242149d0ceea353eb738672cc Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:32:13 +0000
Subject: [PATCH 02/10] Add TypeScript types for bigint.js
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
---
bigint.d.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++
package.json | 6 +++++-
2 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 bigint.d.ts
diff --git a/bigint.d.ts b/bigint.d.ts
new file mode 100644
index 00000000..fffed920
--- /dev/null
+++ b/bigint.d.ts
@@ -0,0 +1,47 @@
+/**
+ * Utilities for converting between BigInt and Uint8Array.
+ *
+ * ```js
+ * import { fromBigInt, toBigInt } from '@exodus/bytes/bigint.js'
+ * ```
+ *
+ * @module @exodus/bytes/bigint.js
+ */
+
+///
+
+import type { OutputFormat, Uint8ArrayBuffer } from './array.js';
+
+/**
+ * Options for converting BigInt to bytes
+ */
+export interface FromBigIntOptions {
+ /** The length in bytes of the output array */
+ length: number;
+ /** Output format (default: 'uint8') */
+ format?: OutputFormat;
+}
+
+/**
+ * Convert a BigInt to a Uint8Array or Buffer
+ *
+ * The BigInt is converted to a hex string and then padded to the specified length.
+ * Throws if the BigInt is negative or cannot fit into the specified length.
+ *
+ * @param x - The BigInt to convert (must be non-negative)
+ * @param options - Conversion options
+ * @returns The converted bytes
+ */
+export function fromBigInt(x: bigint, options: FromBigIntOptions & { format: 'uint8' }): Uint8ArrayBuffer;
+export function fromBigInt(x: bigint, options: FromBigIntOptions & { format: 'buffer' }): Buffer;
+export function fromBigInt(x: bigint, options: FromBigIntOptions): Uint8ArrayBuffer | Buffer;
+
+/**
+ * Convert a Uint8Array or Buffer to a BigInt
+ *
+ * The bytes are interpreted as a big-endian unsigned integer.
+ *
+ * @param a - The bytes to convert
+ * @returns The BigInt representation
+ */
+export function toBigInt(a: ArrayBufferView): bigint;
diff --git a/package.json b/package.json
index 3fa2d797..17e3bdd9 100644
--- a/package.json
+++ b/package.json
@@ -90,6 +90,7 @@
"/base64.d.ts",
"/bech32.js",
"/bigint.js",
+ "/bigint.d.ts",
"/encoding-browser.js",
"/encoding-browser.browser.js",
"/encoding-browser.native.js",
@@ -140,7 +141,10 @@
"default": "./base64.js"
},
"./bech32.js": "./bech32.js",
- "./bigint.js": "./bigint.js",
+ "./bigint.js": {
+ "types": "./bigint.d.ts",
+ "default": "./bigint.js"
+ },
"./hex.js": {
"types": "./hex.d.ts",
"node": "./hex.node.js",
From 478ba4228c4edd4cd8fecef4924ec159a954f9a3 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:35:38 +0000
Subject: [PATCH 03/10] Fix fromBigInt type overloads for default format
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
---
bigint.d.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bigint.d.ts b/bigint.d.ts
index fffed920..350e0f45 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -32,7 +32,7 @@ export interface FromBigIntOptions {
* @param options - Conversion options
* @returns The converted bytes
*/
-export function fromBigInt(x: bigint, options: FromBigIntOptions & { format: 'uint8' }): Uint8ArrayBuffer;
+export function fromBigInt(x: bigint, options: Omit & { format?: 'uint8' }): Uint8ArrayBuffer;
export function fromBigInt(x: bigint, options: FromBigIntOptions & { format: 'buffer' }): Buffer;
export function fromBigInt(x: bigint, options: FromBigIntOptions): Uint8ArrayBuffer | Buffer;
From eb0f9ce59eba122c64e8120125da1c4230b33126 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:36:40 +0000
Subject: [PATCH 04/10] Simplify fromBigInt type overloads for better
readability
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
---
bigint.d.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bigint.d.ts b/bigint.d.ts
index 350e0f45..866b7ac6 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -32,8 +32,8 @@ export interface FromBigIntOptions {
* @param options - Conversion options
* @returns The converted bytes
*/
-export function fromBigInt(x: bigint, options: Omit & { format?: 'uint8' }): Uint8ArrayBuffer;
-export function fromBigInt(x: bigint, options: FromBigIntOptions & { format: 'buffer' }): Buffer;
+export function fromBigInt(x: bigint, options: { length: number; format?: 'uint8' }): Uint8ArrayBuffer;
+export function fromBigInt(x: bigint, options: { length: number; format: 'buffer' }): Buffer;
export function fromBigInt(x: bigint, options: FromBigIntOptions): Uint8ArrayBuffer | Buffer;
/**
From 999da0ee070d4eef36ddd0c841181e055d8a2af5 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:41:17 +0000
Subject: [PATCH 05/10] Document big-endian byte order in fromBigInt
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
---
bigint.d.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/bigint.d.ts b/bigint.d.ts
index 866b7ac6..d097ef29 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -26,11 +26,12 @@ export interface FromBigIntOptions {
* Convert a BigInt to a Uint8Array or Buffer
*
* The BigInt is converted to a hex string and then padded to the specified length.
+ * The output bytes are in big-endian format.
* Throws if the BigInt is negative or cannot fit into the specified length.
*
* @param x - The BigInt to convert (must be non-negative)
* @param options - Conversion options
- * @returns The converted bytes
+ * @returns The converted bytes in big-endian format
*/
export function fromBigInt(x: bigint, options: { length: number; format?: 'uint8' }): Uint8ArrayBuffer;
export function fromBigInt(x: bigint, options: { length: number; format: 'buffer' }): Buffer;
From e56182fb30ad8bc003b5b3fc0dad027eb44f3725 Mon Sep 17 00:00:00 2001
From: Nikita Skovoroda
Date: Thu, 22 Jan 2026 11:47:06 +0300
Subject: [PATCH 06/10] Apply suggestion from @ChALkeR
---
bigint.d.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/bigint.d.ts b/bigint.d.ts
index d097ef29..611fc11f 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -25,7 +25,6 @@ export interface FromBigIntOptions {
/**
* Convert a BigInt to a Uint8Array or Buffer
*
- * The BigInt is converted to a hex string and then padded to the specified length.
* The output bytes are in big-endian format.
* Throws if the BigInt is negative or cannot fit into the specified length.
*
From 1d89770296959e9566cb1b721a4d6b60f23f3ffa Mon Sep 17 00:00:00 2001
From: Nikita Skovoroda
Date: Thu, 22 Jan 2026 11:47:56 +0300
Subject: [PATCH 07/10] Apply suggestion from @ChALkeR
---
bigint.d.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/bigint.d.ts b/bigint.d.ts
index 611fc11f..a8272825 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -26,6 +26,7 @@ export interface FromBigIntOptions {
* Convert a BigInt to a Uint8Array or Buffer
*
* The output bytes are in big-endian format.
+ *
* Throws if the BigInt is negative or cannot fit into the specified length.
*
* @param x - The BigInt to convert (must be non-negative)
From b72c998b6932fad51be8c251aef5d7e3b49ad31b Mon Sep 17 00:00:00 2001
From: Nikita Skovoroda
Date: Thu, 22 Jan 2026 11:49:17 +0300
Subject: [PATCH 08/10] Apply suggestion from @ChALkeR
---
bigint.d.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bigint.d.ts b/bigint.d.ts
index a8272825..dd6410ed 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -1,5 +1,5 @@
/**
- * Utilities for converting between BigInt and Uint8Array.
+ * Convert between BigInt and Uint8Array
*
* ```js
* import { fromBigInt, toBigInt } from '@exodus/bytes/bigint.js'
From 43f57dccfc610bf329deed61b13e887e3b137595 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:51:27 +0000
Subject: [PATCH 09/10] Sync README.md bigint.js section with type definitions
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
---
README.md | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/README.md b/README.md
index 1179fb49..6ddeaa83 100644
--- a/README.md
+++ b/README.md
@@ -298,13 +298,26 @@ That function will have state while `stream = true` is used.
### `@exodus/bytes/bigint.js`
+Convert between BigInt and Uint8Array
+
```js
import { fromBigInt, toBigInt } from '@exodus/bytes/bigint.js'
```
#### `fromBigInt(bigint, { length, format = 'uint8' })`
+
+Convert a BigInt to a Uint8Array or Buffer
+
+The output bytes are in big-endian format.
+
+Throws if the BigInt is negative or cannot fit into the specified length.
+
#### `toBigInt(arr)`
+Convert a Uint8Array or Buffer to a BigInt
+
+The bytes are interpreted as a big-endian unsigned integer.
+
### `@exodus/bytes/hex.js`
Implements Base16 from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)
From 7268fcf47609326edb30b963c1ee76828d5a750a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 Jan 2026 08:54:00 +0000
Subject: [PATCH 10/10] Rename toBigInt parameter from 'a' to 'arr'
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
---
bigint.d.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bigint.d.ts b/bigint.d.ts
index dd6410ed..a0758f99 100644
--- a/bigint.d.ts
+++ b/bigint.d.ts
@@ -42,7 +42,7 @@ export function fromBigInt(x: bigint, options: FromBigIntOptions): Uint8ArrayBuf
*
* The bytes are interpreted as a big-endian unsigned integer.
*
- * @param a - The bytes to convert
+ * @param arr - The bytes to convert
* @returns The BigInt representation
*/
-export function toBigInt(a: ArrayBufferView): bigint;
+export function toBigInt(arr: ArrayBufferView): bigint;