Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Commit c9b19ea

Browse files
committed
fix: bitcoin bech32 vs bech32m encoding
1 parent 50e28b1 commit c9b19ea

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reservoir0x/relay-protocol-sdk",
3-
"version": "0.0.62",
3+
"version": "0.0.63",
44
"description": "Relay protocol SDK",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/utils.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,22 @@ export const encodeAddress = (address: string, vmType: VmType): Uint8Array => {
7070

7171
if (address.startsWith("bc1")) {
7272
const lower = address.toLowerCase();
73-
const decoded = bech32.decode(lower, 90);
74-
return decoded.prefix === "bc" && decoded.words[0] === 0
75-
? "bech32"
76-
: "bech32m";
73+
74+
// Try Bech32 first (v0)
75+
try {
76+
const decoded = bech32.decode(lower, 90);
77+
if (decoded.prefix === "bc" && decoded.words[0] === 0) {
78+
return "bech32";
79+
}
80+
} catch (_) {}
81+
82+
// Try Bech32m (v1+)
83+
try {
84+
const decoded = bech32m.decode(lower, 90);
85+
if (decoded.prefix === "bc" && decoded.words[0] >= 1) {
86+
return "bech32m";
87+
}
88+
} catch (_) {}
7789
}
7890

7991
throw new Error("Unsupported address format");

0 commit comments

Comments
 (0)