From a4815c62dd8e94a518b3c267a68b72a068cd462a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 10:30:17 +0000 Subject: [PATCH 1/6] Initial plan From 257f5d47c030f07536bd9e72dac987a7562236cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 10:44:30 +0000 Subject: [PATCH 2/6] Add TypeScript definitions for bech32.js module Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- .gitignore | 1 + bech32.d.ts | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 6 ++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 bech32.d.ts diff --git a/.gitignore b/.gitignore index ccb6dcfc..c0263b1f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules coverage playground *.tgz +package-lock.json diff --git a/bech32.d.ts b/bech32.d.ts new file mode 100644 index 00000000..4dd664e4 --- /dev/null +++ b/bech32.d.ts @@ -0,0 +1,73 @@ +/** + * Implements bech32 and bech32m from [BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) + * and [BIP350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki). + * + * ```js + * import { fromBech32, toBech32, fromBech32m, toBech32m, getPrefix } from '@exodus/bytes/bech32.js' + * ``` + * + * @module @exodus/bytes/bech32.js + */ + +/// + +import type { Uint8ArrayBuffer } from './array.js'; + +/** + * Result of decoding a bech32 or bech32m string + */ +export interface Bech32DecodeResult { + /** The human-readable prefix */ + prefix: string; + /** The decoded bytes */ + bytes: Uint8Array; +} + +/** + * Encode bytes to a bech32 string (BIP 173) + * + * @param prefix - The human-readable prefix (e.g., 'bc' for Bitcoin) + * @param bytes - The input bytes to encode + * @param limit - Maximum length of the encoded string (default: 90) + * @returns The bech32 encoded string + */ +export function toBech32(prefix: string, bytes: Uint8ArrayBuffer, limit?: number): string; + +/** + * Decode a bech32 string to bytes (BIP 173) + * + * @param str - The bech32 encoded string + * @param limit - Maximum length of the input string (default: 90) + * @returns The decoded prefix and bytes + */ +export function fromBech32(str: string, limit?: number): Bech32DecodeResult; + +/** + * Encode bytes to a bech32m string (BIP 350) + * + * @param prefix - The human-readable prefix (e.g., 'bc' for Bitcoin) + * @param bytes - The input bytes to encode + * @param limit - Maximum length of the encoded string (default: 90) + * @returns The bech32m encoded string + */ +export function toBech32m(prefix: string, bytes: Uint8ArrayBuffer, limit?: number): string; + +/** + * Decode a bech32m string to bytes (BIP 350) + * + * @param str - The bech32m encoded string + * @param limit - Maximum length of the input string (default: 90) + * @returns The decoded prefix and bytes + */ +export function fromBech32m(str: string, limit?: number): Bech32DecodeResult; + +/** + * Extract the prefix from a bech32 or bech32m string without full validation + * + * This is a quick check that skips most validation. + * + * @param str - The bech32/bech32m encoded string + * @param limit - Maximum length of the input string (default: 90) + * @returns The lowercase prefix + */ +export function getPrefix(str: string, limit?: number): string; diff --git a/package.json b/package.json index eaf83675..fd24be9a 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "/base64.js", "/base64.d.ts", "/bech32.js", + "/bech32.d.ts", "/bigint.js", "/bigint.d.ts", "/encoding-browser.js", @@ -149,7 +150,10 @@ "types": "./base64.d.ts", "default": "./base64.js" }, - "./bech32.js": "./bech32.js", + "./bech32.js": { + "types": "./bech32.d.ts", + "default": "./bech32.js" + }, "./bigint.js": { "types": "./bigint.d.ts", "default": "./bigint.js" From 548047b77186de51ce759af7fd673c0cf49a4422 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 13:35:21 +0000 Subject: [PATCH 3/6] Improve formatting of bech32 documentation comments Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- README.md | 3 ++- bech32.d.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 640306c4..6934d891 100644 --- a/README.md +++ b/README.md @@ -449,7 +449,8 @@ Encode a `Uint8Array` to a base32hex string (RFC 4648) ### `@exodus/bytes/bech32.js` -Implements [BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification) +Implements bech32 and bech32m from +[BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification) and [BIP-0350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki#specification). ```js diff --git a/bech32.d.ts b/bech32.d.ts index 4dd664e4..d9a96082 100644 --- a/bech32.d.ts +++ b/bech32.d.ts @@ -1,5 +1,6 @@ /** - * Implements bech32 and bech32m from [BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) + * Implements bech32 and bech32m from + * [BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) * and [BIP350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki). * * ```js From d48657dd475b4de28988e662b5f518c2d8fd1ebf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 15:41:14 +0000 Subject: [PATCH 4/6] Remove unrelated .gitignore change Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c0263b1f..ccb6dcfc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ node_modules coverage playground *.tgz -package-lock.json From 168d623442fbe117e7961985b1c5d03a4e1a31c7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 15:44:18 +0000 Subject: [PATCH 5/6] Sync bech32.d.ts with README formatting and types Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- bech32.d.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bech32.d.ts b/bech32.d.ts index d9a96082..da086fab 100644 --- a/bech32.d.ts +++ b/bech32.d.ts @@ -1,10 +1,12 @@ /** * Implements bech32 and bech32m from - * [BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) - * and [BIP350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki). + * [BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification) + * and [BIP-0350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki#specification). * * ```js - * import { fromBech32, toBech32, fromBech32m, toBech32m, getPrefix } from '@exodus/bytes/bech32.js' + * import { fromBech32, toBech32 } from '@exodus/bytes/bech32.js' + * import { fromBech32m, toBech32m } from '@exodus/bytes/bech32.js' + * import { getPrefix } from '@exodus/bytes/bech32.js' * ``` * * @module @exodus/bytes/bech32.js @@ -21,7 +23,7 @@ export interface Bech32DecodeResult { /** The human-readable prefix */ prefix: string; /** The decoded bytes */ - bytes: Uint8Array; + bytes: Uint8ArrayBuffer; } /** From 2e0c1991dc19ba41112087f67d0afd0d1c571a90 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 15:49:42 +0000 Subject: [PATCH 6/6] Remove BIP references from function docs and sync to README Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com> --- README.md | 14 ++++++++++++++ bech32.d.ts | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6934d891..8cb3a385 100644 --- a/README.md +++ b/README.md @@ -461,12 +461,26 @@ import { getPrefix } from '@exodus/bytes/bech32.js' #### `getPrefix(string, limit = 90)` +Extract the prefix from a bech32 or bech32m string without full validation + +This is a quick check that skips most validation. + #### `fromBech32(string, limit = 90)` + +Decode a bech32 string to bytes + #### `toBech32(prefix, bytes, limit = 90)` +Encode bytes to a bech32 string + #### `fromBech32m(string, limit = 90)` + +Decode a bech32m string to bytes + #### `toBech32m(prefix, bytes, limit = 90)` +Encode bytes to a bech32m string + ### `@exodus/bytes/base58.js` Implements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding. diff --git a/bech32.d.ts b/bech32.d.ts index da086fab..b202d3f2 100644 --- a/bech32.d.ts +++ b/bech32.d.ts @@ -27,7 +27,7 @@ export interface Bech32DecodeResult { } /** - * Encode bytes to a bech32 string (BIP 173) + * Encode bytes to a bech32 string * * @param prefix - The human-readable prefix (e.g., 'bc' for Bitcoin) * @param bytes - The input bytes to encode @@ -37,7 +37,7 @@ export interface Bech32DecodeResult { export function toBech32(prefix: string, bytes: Uint8ArrayBuffer, limit?: number): string; /** - * Decode a bech32 string to bytes (BIP 173) + * Decode a bech32 string to bytes * * @param str - The bech32 encoded string * @param limit - Maximum length of the input string (default: 90) @@ -46,7 +46,7 @@ export function toBech32(prefix: string, bytes: Uint8ArrayBuffer, limit?: number export function fromBech32(str: string, limit?: number): Bech32DecodeResult; /** - * Encode bytes to a bech32m string (BIP 350) + * Encode bytes to a bech32m string * * @param prefix - The human-readable prefix (e.g., 'bc' for Bitcoin) * @param bytes - The input bytes to encode @@ -56,7 +56,7 @@ export function fromBech32(str: string, limit?: number): Bech32DecodeResult; export function toBech32m(prefix: string, bytes: Uint8ArrayBuffer, limit?: number): string; /** - * Decode a bech32m string to bytes (BIP 350) + * Decode a bech32m string to bytes * * @param str - The bech32m encoded string * @param limit - Maximum length of the input string (default: 90)