Skip to content

Commit 997aade

Browse files
sgbettclaude
andcommitted
fix: p2pkh_lock accepts 20-byte hash regardless of string encoding (#389)
Callers passing `"\x00" * 20` (UTF-8 encoding) were routed to the Base58Check decode path, which failed on null bytes. A 20-byte string can never be a valid Base58Check address (minimum ~34 chars), so bytesize alone is sufficient to disambiguate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 74c3d11 commit 997aade

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

gem/bsv-sdk/lib/bsv/script/script.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ def self.p2pkh_lock(pubkey_hash_or_address)
171171
# Resolve a pubkey_hash argument that may be a raw binary hash or a
172172
# Base58Check address string.
173173
def self.resolve_pubkey_hash(arg)
174-
# A 20-byte ASCII-8BIT string is treated as a raw binary hash.
175-
return arg if arg.encoding == Encoding::ASCII_8BIT && arg.bytesize == 20
174+
# A 20-byte string is treated as a raw binary hash regardless of
175+
# encoding — callers commonly pass `"\x00" * 20` which is UTF-8.
176+
# A valid Base58Check address is always longer than 20 characters
177+
# (25 raw bytes → ~34 Base58 characters), so this is unambiguous.
178+
return arg.b if arg.bytesize == 20
176179

177180
# Otherwise treat as a Base58Check address string.
178181
decoded = BSV::Primitives::Base58.check_decode(arg, prefix_length: 1)

0 commit comments

Comments
 (0)