public function encode(string $data): string
    {
        if (true === $this->options["check"]) {
            $data = chr($this->options["version"]) . $data;
            $hash = hash("sha256", $data, true);
            $hash = hash("sha256", $hash, true);
            $checksum = substr($hash, 0, 4);
            $data .= $checksum;
        }

        $data = str_split($data);
        $data = array_map("ord", $data);

        $leadingZeroes = 0;
        while (!empty($data) && 0 === $data[0]) {
            $leadingZeroes++;
            array_shift($data);
        }

        $converted = $this->baseConvert($data, 256, 58);

        if (0 < $leadingZeroes) {
            $converted = array_merge(
                array_fill(0, $leadingZeroes, 0),
                $converted
            );
        }

        return implode("", array_map(function ($index) {
            return $this->options["characters"][$index];
        }, $converted));
    }
public function encode(string $data): string
    {
        if (true === $this->options["check"]) {
            $data = chr($this->options["version"]) . $data;
            $hash = hash("sha256", $data, true);
            $hash = hash("sha256", $hash, true);
            $checksum = substr($hash, 0, 4);
            $data .= $checksum;
        }

        $data = str_split($data);
        $data = array_map("ord", $data);

        $leadingZeroes = 0;
        while (!empty($data) && 0 === $data[0]) {
            $leadingZeroes++;
            array_shift($data);
        }

        $converted = $this->baseConvert($data, 256, 58);

        if (0 < $leadingZeroes) {
            $converted = array_merge(
                array_fill(0, $leadingZeroes, 0),
                $converted
            );
        }

        return implode("", array_map(function ($index) {
            return $this->options["characters"][$index];
        }, $converted));
    }
public function encode ( string $ data ) : string { if ( true === $ this -> options [ "check" ] ) { $ data = chr ( $ this -> options [ "version" ] ) . $ data ; $ hash = hash ( "sha256" , $ data , true ) ; $ hash = hash ( "sha256" , $ hash , true ) ; $ checksum = substr ( $ hash , 0 , 4 ) ; $ data .= $ checksum ; } $ data = str_split ( $ data ) ; $ data = array_map ( "ord" , $ data ) ; $ leadingZeroes = 0 ; while ( ! empty ( $ data ) && 0 === $ data [ 0 ] ) { $ leadingZeroes ++ ; array_shift ( $ data ) ; } $ converted = $ this -> baseConvert ( $ data , 256 , 58 ) ; if ( 0 < $ leadingZeroes ) { $ converted = array_merge ( array_fill ( 0 , $ leadingZeroes , 0 ) , $ converted ) ; } return implode ( "" , array_map ( function ( $ index ) { return $ this -> options [ "characters" ] [ $ index ] ; } , $ converted ) ) ; }
Encode given data to a base58 string
Encode given data to a base58 string