Skip to content

Commit

Permalink
[Feature] Add preliminary support of BCH addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Jun 19, 2020
1 parent f99d7e2 commit 29ad693
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion rules/bitcoin.lua
Expand Up @@ -120,7 +120,7 @@ end
local function is_segwit_bech32_address(word)
local prefix = word:sub(1, 3)

if prefix == 'bc1' or prefix.sub(1, 1) == '1' or prefix.sub(1, 1) == '3' then
if prefix == 'bc1' or prefix:sub(1, 1) == '1' or prefix:sub(1, 1) == '3' then
-- Strip beach32 prefix in bitcoin
word = word:lower()
local last_one_pos = word:find('1[^1]*$')
Expand All @@ -134,6 +134,23 @@ local function is_segwit_bech32_address(word)
if decoded then
return verify_beach32_cksum(hrp, decoded)
end
else
-- BCH address
-- 1 byte address type (who cares)
-- XXX bytes address hash (who cares)
-- 40 bit checksum
local rspamd_util = require 'rspamd_util'
local decoded = rspamd_util.decode_base32(word:lower(), 'bleach')

if decoded then
local bytes = decoded:bytes()

if bytes[1] == 0 then
-- TODO: Add checksum validation some day

return true
end
end
end
end

Expand Down

0 comments on commit 29ad693

Please sign in to comment.