langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,25 @@
|
|||
enum B58 <
|
||||
1 2 3 4 5 6 7 8 9
|
||||
A B C D E F G H J K L M N P Q R S T U V W X Y Z
|
||||
a b c d e f g h i j k m n o p q r s t u v w x y z
|
||||
>;
|
||||
|
||||
sub unbase58(Str $str) {
|
||||
my @out = 0 xx 25;
|
||||
for B58.enums.hash{$str.comb} {
|
||||
my $c = $_;
|
||||
for reverse ^25 {
|
||||
$c += 58 * @out[$_];
|
||||
@out[$_] = $c % 256;
|
||||
$c div= 256;
|
||||
}
|
||||
}
|
||||
return @out;
|
||||
}
|
||||
|
||||
sub check-bitcoin-address($addr) {
|
||||
use Digest;
|
||||
my @byte = unbase58 $addr;
|
||||
!!! 'wrong checksum' unless @byte[21..24] ~~
|
||||
sha256(sha256 Buf.new: @byte[0..20]).subbuf(0, 4).list;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})
|
||||
bitcoinregex="^[$(printf "%s" "${base58[@]}")]{34}$"
|
||||
|
||||
decodeBase58() {
|
||||
local s=$1
|
||||
for i in {0..57}
|
||||
do s="${s//${base58[i]}/ $i}"
|
||||
done
|
||||
dc <<< "16o0d${s// /+58*}+f"
|
||||
}
|
||||
|
||||
checksum() {
|
||||
xxd -p -r <<<"$1" |
|
||||
openssl dgst -sha256 -binary |
|
||||
openssl dgst -sha256 -binary |
|
||||
xxd -p -c 80 |
|
||||
head -c 8
|
||||
}
|
||||
|
||||
checkBitcoinAddress() {
|
||||
if [[ "$1" =~ $bitcoinregex ]]
|
||||
then
|
||||
h=$(decodeBase58 "$1")
|
||||
checksum "00${h::${#h}-8}" |
|
||||
grep -qi "^${h: -8}$"
|
||||
else return 2
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue