commit 29ad693: [Feature] Add preliminary support of BCH addresses

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jun 19 20:28:08 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-06-19 21:27:08 +0100
URL: https://github.com/rspamd/rspamd/commit/29ad693e4190d3ad7e6a6025df28d39955c2091c (HEAD -> master)

[Feature] Add preliminary support of BCH addresses

---
 rules/bitcoin.lua | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/rules/bitcoin.lua b/rules/bitcoin.lua
index d9c94fdf1..b7f9f1dbc 100644
--- a/rules/bitcoin.lua
+++ b/rules/bitcoin.lua
@@ -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]*$')
@@ -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
 


More information about the Commits mailing list