Skip to content
Open
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/is-hex-string-uppercase-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@agentcommercekit/keys": patch
---

Accept an uppercase `0X` prefix in `isHexString`, matching `hexStringToBytes`.
5 changes: 5 additions & 0 deletions packages/keys/src/encoding/hex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe("isHexString", () => {
expect(isHexString("0x1234567890abcdef")).toBe(true)
})

test("returns true for valid hex strings with uppercase 0X prefix", () => {
// `hexStringToBytes` already accepts this form; the guard must agree.
expect(isHexString("0XABCDEF")).toBe(true)
})

test("returns true for valid hex strings without 0x prefix", () => {
expect(isHexString("1234567890abcdef")).toBe(true)
})
Expand Down
5 changes: 4 additions & 1 deletion packages/keys/src/encoding/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export function isHexString(value: unknown): value is string {
return false
}

const hexWithoutPrefix = value.startsWith("0x") ? value.slice(2) : value
// Match `hexStringToBytes`: accept both `0x` and `0X` prefixes.
const hexWithoutPrefix = value.toLowerCase().startsWith("0x")
? value.slice(2)
: value
return /^[0-9A-Fa-f]+$/.test(hexWithoutPrefix)
}