Skip to content

Commit

Permalink
end point Changes handler added
Browse files Browse the repository at this point in the history
  • Loading branch information
neha0921 committed Aug 10, 2021
1 parent 0e78f0d commit 818ddeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Library/ss58.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@ public function ss58_decode($address, $valid_address_type = None){

$checksum_prefix = 'SS58PRE';

$ss58_format = base58.b58decode(address)
$ss58_format = base58.b58decode(address);

if(valid_address_type and ss58_format[0] != valid_address_type){
if($valid_address_type && $ss58_format[0] != $valid_address_type){
// raise ValueError("Invalid Address type")
}
# Determine checksum length according to length of address string
if (len(ss58_format) in [3, 4, 6, 10]){
if (in_array(sizeof($ss58_format) , [3, 4, 6, 10])){
$checksum_length = 1;
}else if (len(ss58_format) in [5, 7, 11, 35]){
}else if (in_array(sizeof($ss58_format) , [5, 7, 11, 35])){
$checksum_length = 2;
}else if (len(ss58_format) in [8, 12]){
}else if (in_array(sizeof($ss58_format) ,[8, 12])){
$checksum_length = 3;
}else if (len(ss58_format) in [9, 13]){
checksum_length = 4
}else if ( len(ss58_format) in [14]){
}else if (in_array(sizeof($ss58_format) ,[9, 13])){
$checksum_length = 4;
}else if ( in_array(sizeof($ss58_format) ,[14])){
$checksum_length = 5;
}else if ( len(ss58_format) in [15]){
}else if ( in_array(sizeof($ss58_format) ,[15])){
$checksum_length = 6;
}else if ( len(ss58_format) in [16]){
}else if ( in_array(sizeof($ss58_format) ,[16])){
$checksum_length = 7;
}else if ( len(ss58_format) in [17]){
}else if ( in_array(sizeof($ss58_format) ,[17])){
$checksum_length = 8;
}else{
// raise ValueError("Invalid address length")
}
$checksum = blake2b(checksum_prefix + ss58_format[0:-checksum_length]).digest()
$checksum = blake2b($checksum_prefix + $ss58_format[0:-$checksum_length]).digest();

if (checksum[0:checksum_length] != ss58_format[-checksum_length:]){
if ($checksum[0:$checksum_length] != $ss58_format[-checksum_length:]){
// raise ValueError("Invalid checksum")
}
return ss58_format[1:len(ss58_format)-checksum_length].hex();
return $ss58_format[1:len($ss58_format)-$checksum_length].hex();
}
}
File renamed without changes.

0 comments on commit 818ddeb

Please sign in to comment.