lib/WalletManager.php
/*
     * Convert a seed to mnemonic words
     *
     * @param string $seed
     * @return string
     */
Convert a seed to mnemonic words
@param string $seed
@return string
Convert a seed to mnemonic words @param string $seed @return string
public function mn_encode($seed = null)
    {
        $words = json_decode(file_get_contents(__DIR__ . '/mnemonic.json'), true);
        $words = $words[$this->mnemonic_language];
        if (empty($words)) {
            $words = $words['en'];
        }
        $wordsLen = count($words['words']);
        if ($seed === null) {
            $seed = $this->gen_new_hex_seed();
        }
        $swapped = $seed;
        for ($i = 0; $i < strlen($seed); $i += 8) {
            $swapped = substr($swapped, 0, $i) . $this->mn_swap_endian_4byte(substr($swapped, $i, 8)) . substr($swapped, $i + 8);
        }
        $result = [];
        for ($i = 0; $i < strlen($swapped); $i += 8)
        {
            $x = intval(substr($swapped, $i, 8), 16);
            $w1 = $x % $wordsLen;
            $w2 = (floor($x / $wordsLen) + $w1) % $wordsLen;
            $w3 = (floor(floor($x / $wordsLen) / $wordsLen) + $w2) % $wordsLen;
            $result = array_merge($result, [$words['words'][$w1], $words['words'][$w2], $words['words'][$w3]]);
        }
        if ($words['prefix_len'] > 0) {
            $result[] = $result[$this->mn_get_checksum_index($result, $words['prefix_len'])];
        }
        return implode(' ', $result);
    }
public function mn_encode ( $ seed = null ) { $ words = json_decode ( file_get_contents ( __DIR__ . '/mnemonic.json' ) , true ) ; $ words = $ words [ $ this -> mnemonic_language ] ; if ( empty ( $ words ) ) { $ words = $ words [ 'en' ] ; } $ wordsLen = count ( $ words [ 'words' ] ) ; if ( $ seed === null ) { $ seed = $ this -> gen_new_hex_seed ( ) ; } $ swapped = $ seed ; for ( $ i = 0 ; $ i < strlen ( $ seed ) ; $ i += 8 ) { $ swapped = substr ( $ swapped , 0 , $ i ) . $ this -> mn_swap_endian_4byte ( substr ( $ swapped , $ i , 8 ) ) . substr ( $ swapped , $ i + 8 ) ; } $ result = [ ] ; for ( $ i = 0 ; $ i < strlen ( $ swapped ) ; $ i += 8 ) { $ x = intval ( substr ( $ swapped , $ i , 8 ) , 16 ) ; $ w1 = $ x % $ wordsLen ; $ w2 = ( floor ( $ x / $ wordsLen ) + $ w1 ) % $ wordsLen ; $ w3 = ( floor ( floor ( $ x / $ wordsLen ) / $ wordsLen ) + $ w2 ) % $ wordsLen ; $ result = array_merge ( $ result , [ $ words [ 'words' ] [ $ w1 ] , $ words [ 'words' ] [ $ w2 ] , $ words [ 'words' ] [ $ w3 ] ] ) ; } if ( $ words [ 'prefix_len' ] > 0 ) { $ result [ ] = $ result [ $ this -> mn_get_checksum_index ( $ result , $ words [ 'prefix_len' ] ) ] ; } return implode ( ' ' , $ result ) ; }
Convert a seed to mnemonic words
 @param string $seed
 @return string
Convert a seed to mnemonic words @param string $seed @return string
// Get the mnemonic word list for the given language. // Default mnemonic words to English if unknown language was supplied. // Generate a random seed if required.