From dfa77538eae389a3a9287e2e53d51944a3539334 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 12 Mar 2018 19:17:57 +0000 Subject: [PATCH 1/2] Fix taddr validation and hushlist-send-file off by a factor of 2 bug --- bin/hushlist-send-file | 8 +++----- lib/Hush/Util.pm | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/bin/hushlist-send-file b/bin/hushlist-send-file index 4cd869c..6ddef90 100755 --- a/bin/hushlist-send-file +++ b/bin/hushlist-send-file @@ -26,16 +26,14 @@ my $rpc = Hush::RPC->new; #my $hex_memo = unpack("H*",$memo); # backend wants hex-encoded memo-field #print "Hex memos length=" . length($hex_memo) . "\n"; -if(0){ unless ( is_valid_zaddr($from) or is_valid_taddr($from) ) { die "From address must be a valid taddr or zaddr!"; } die "Invalid zaddr!" unless is_valid_zaddr($to); -} -my @hex_memos = unpack("(H512)*", $memo); +my @hex_memos = unpack("(H1024)*", $memo); # hexify doubles the length -my $num_memos = int(@hex_memos / 2) + (@hex_memos % 2); +my $num_memos = int(@hex_memos); #die Dumper ['array=', @hex_memos, "string=$hex_memo" ]; print "This file will be stored in $num_memos memo fields\n"; @@ -49,7 +47,7 @@ for my $memo (@hex_memos) { memo => $memo, }; } -#die Dumper [ $recipients ]; +die Dumper [ $recipients ]; my $opid = $rpc->z_sendmany($from,$recipients); print "z_sendmany complete\n"; diff --git a/lib/Hush/Util.pm b/lib/Hush/Util.pm index 579edc0..960d952 100644 --- a/lib/Hush/Util.pm +++ b/lib/Hush/Util.pm @@ -37,7 +37,7 @@ sub is_valid_taddr { my ($t) = @_; # TODO: only base58 is valid - if ($t =~ m/^t1[a-z0-9]{35}$/i) { + if ($t =~ m/^t1[a-z0-9]{33}$/i) { return 1; } else { return 0; From d5a3df1b88bacaf40ec27a447e548525e0a21562 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 8 Sep 2018 15:59:44 -0700 Subject: [PATCH 2/2] Start adding support for KMD and better error checking in hushlist-send-file --- bin/hushlist-send-file | 5 +++++ lib/Hush/Util.pm | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/bin/hushlist-send-file b/bin/hushlist-send-file index 6ddef90..9f38942 100755 --- a/bin/hushlist-send-file +++ b/bin/hushlist-send-file @@ -15,9 +15,14 @@ use JSON; my ($from,$to,$filename,$amount) = @ARGV; $amount ||= 0.0; +# this is for Sprout, Sapling will not have a limit except for block size(!) +my $max_size = 512 * 54 - 54; die "You must specify a filename!" unless $filename; die "File does not exist!" unless -e $filename; +my $filesize = -s $filename; +die "File is empty!" unless $filesize; +die "Currently this tool only supports files which fit in one transaction, up to $max_size bytes. Patches welcome!" unless ($filesize <= $max_size); my $memo = read_file($filename); my $length = length $memo; diff --git a/lib/Hush/Util.pm b/lib/Hush/Util.pm index 960d952..5938ffa 100644 --- a/lib/Hush/Util.pm +++ b/lib/Hush/Util.pm @@ -25,6 +25,7 @@ sub is_valid_zaddr { #warn "zaddr=$z"; # TODO: only base58 is valid + # TODO: support Zcash Sapling addresses if ($z =~ m/^zc[a-z0-9]{93}$/i) { return 1; } else { @@ -37,8 +38,11 @@ sub is_valid_taddr { my ($t) = @_; # TODO: only base58 is valid + # HUSH/ZEC and most zec forks if ($t =~ m/^t1[a-z0-9]{33}$/i) { return 1; + } elsif ($t =~ m/^R[a-z0-9]{34}$/i) { # KMD and KMD asset chains + return 1; } else { return 0; } @@ -48,6 +52,7 @@ sub is_valid_taddr { sub is_valid_privkey { my ($p) = @_; $p =~ s!^hushlist://!!g; + # TODO: support KMD + new Sapling privkeys if ($p =~ m/^SK[a-z0-9]{53}$/i) { return 1; } else {