Skip to content

mnemonic to address,Unable to get: uncompressed public key / address / Y coordinate #7

Description

@k6xiao

php:

I have calculated the private key / compressed public key from 12 mnemonics

How to continue to get the address?

<?php
use BIP\BIP44; //助记词生成种子,种子生成私钥公钥

var_dump(mnemonic_to('chicken home nothing witness quick credit post crystal omit once arrow digital'));

// 助记词→私钥..
// mnemonic:助记词字符串 空格隔开
// passphrase:BIP39 密码(可选)
// address_index:地址索引
function mnemonic_to($mnemonic, $passphrase = '', $address_index = '0') {
    $seed = hash_pbkdf2("sha512", $mnemonic, 'mnemonic' . $passphrase, 2048, 0, false);
    $DerivationPath = "m/44'/60'/0'/0";  //ETH
    $HDKey          = BIP44::fromMasterSeed($seed)->derive($DerivationPath . "/" . $address_index);
    dump($HDKey);
    $HDKey2 = BIP44::fromMasterSeed($seed)->derive($DerivationPath);
    dump($HDKey2);
    return [
        'privateKey'         => $HDKey->privateKey, //私钥-64字符-bip44第0个    BIP-32 主密钥?
        'publicKeyFull'      => '???', //未压缩公钥-130字符-前缀04+椭圆x坐标(64字符)+椭圆y坐标(64字符)
        'publicKey'          => $HDKey->publicKey, //压缩公钥-66字符-前缀03+x(如果y是奇数),前缀02+x(如果y是偶数)
        'address'            => phpKeccak256($HDKey->publicKey), //地址-42字符
        'mnemonic'           => $mnemonic, //助记词-12个单词
        'wordsCount'         => count(explode(" ", $mnemonic)), //助记词数
        'entropy'            => BIP39::Words($mnemonic)->entropy, //熵
        'seed'               => $seed, // BIP39 种子
        'derivationPath'     => $DerivationPath, // BIP32 推导路径
        'privateExtendedKey' => $HDKey2->getPrivateExtendedKey(), //BIP32 扩展私钥
        'publicExtendedKey'  => $HDKey2->getPublicExtendedKey(), //BIP32 扩展公钥
        // 压缩公钥与未压缩公钥见   https://www.freesion.com/article/93101100036/
    ];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions