Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bech32-long-strings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@evolution-sdk/evolution": patch
---

`Bech32.FromBytes` failed on strings longer than 90 characters, such as base addresses, when `@scure/base` 2.4 or later was installed. That version made `bech32.decodeToBytes` enforce the 90-character BIP-173 limit by default, and the SDK called it without a limit. It now passes no limit, as every other bech32 decode in the SDK already does.
2 changes: 1 addition & 1 deletion packages/evolution/src/Bech32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const FromBytes = (prefix: string = "addr") =>
strict: true,
encode: (_, __, ast, toA) =>
Effect.try({
try: () => bech32.decodeToBytes(toA).bytes,
try: () => bech32.decodeToBytes(toA, false).bytes,
catch: () => new ParseResult.Type(ast, toA, ` ${toA} is not a valid Bech32 address`)
}),
decode: (_, __, ___, fromI) => {
Expand Down
16 changes: 16 additions & 0 deletions packages/evolution/test/Bech32.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Schema } from "effect"
import { describe, expect, it } from "vitest"

import * as Bech32 from "../src/Bech32.js"

// A base address is 108 characters, longer than the 90-character BIP-173 default limit
const BASE_ADDRESS =
"addr_test1qpw0djgj0x59ngrjvqthn7enhvruxnsavsw5th63la3mjel3tkc974sr23jmlzgq5zda4gtv8k9cy38756r9y3qgmkqqjz6aa7"

describe("Bech32", () => {
it("decodes a base address longer than 90 characters", () => {
const bytes = Schema.encodeSync(Bech32.FromBytes("addr_test"))(BASE_ADDRESS)
expect(bytes.length).toBe(57)
expect(Schema.decodeSync(Bech32.FromBytes("addr_test"))(bytes)).toBe(BASE_ADDRESS)
})
})
89 changes: 48 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading