Skip to content

Commit

Permalink
FIX: add decode58-check to check if the address is ok
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbegin authored and qtxie committed Jun 25, 2019
1 parent d1b6647 commit aad65fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 1 addition & 4 deletions btc-ui.red
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ context [

check-data: does [
input-addr: trim any [addr-to/text ""]
unless all [
26 <= length? input-addr
36 >= length? input-addr
][
unless btc-addr/decode58-check input-addr [
addr-to/text: copy "Invalid address"
return no
]
Expand Down
10 changes: 10 additions & 0 deletions libs/btc-addr.red
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ btc-addr: context [
enbase/base data 58
]

decode58-check: function [data [string!]][
bin: debase/base data 58
if 4 >= len: length? bin [return none]
raw: copy/part bin len - 4
hash: copy/part skip bin len - 4 4
hash2: copy/part checksum checksum raw 'sha256 'sha256 4
if hash <> hash2 [return none]
raw
]

hash160: func [pubkey [binary!] return: [binary!]][
ripemd160 checksum pubkey 'sha256
]
Expand Down

0 comments on commit aad65fb

Please sign in to comment.