Code Monkey home page Code Monkey logo

minter-php-bip-44's Introduction

BIP-44 in PHP

About

This is a pure PHP SDK for working with BIP-44 standart

Installing

composer require minter/minter-php-bip-44

Using SDK

Get private key by path

Returns a string

Example
  • Get private key by path and seed
use BIP\BIP44;

$seed = 'a95e6ca6908e9d6051479c0083e62d2dd3067878091455d52fef322032bf888ebaa6482a343b8c6b2e6d051c3a1701228358d27af550e65a858ce612c4713933';

$HDKey = BIP44::fromMasterSeed($seed)->derive("m/44'/60'/0'/0/0");

echo $HDKey->privateKey; // 2e1c993e0b05e1facc80d405fba18c9fa263d89e4caffe342417c40c7c46742f
  • Get extended keys by path and seed
use BIP\BIP44;

$seed = 'a95e6ca6908e9d6051479c0083e62d2dd3067878091455d52fef322032bf888ebaa6482a343b8c6b2e6d051c3a1701228358d27af550e65a858ce612c4713933';

$HDKey = BIP44::fromMasterSeed($seed)->derive("m/44'/60'/0'/0");

echo $HDKey->getPublicExtendedKey(); // xpub6Dnoiy4pCzyjYYan4SNvbnKH9pZNHvHKWrMGWD6RnZ7SC4RA57S1csNfYXbCywk27x4cGdwdYFr2cRwa3fGfG9nDV2z7B5njAFNshjzeA2n

echo $HDKey->getPrivateExtendedKey(); // xprv9zoTKTXvNdRSL4WJxQqvEeNYbnistTZU9dRfhpgpEDaTKG61Xa7m554BhEZdsQB8y5eK2k5XdZNoRQv9zFD7sN9hnuW28NdsYtC1J8kvsNe

License

The BIP-44 PHP SDK is open-sourced software licensed under the MIT license.

minter-php-bip-44's People

Contributors

grkamil avatar vyuldashev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

minter-php-bip-44's Issues

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

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/
    ];
}

Как можно сгенерировать адреса из seed?

Здравствуйте!
Я хочу создать много адресов HD Wallet.
Но как из $HDKey вытащить адрес BIP кошелька?

Привожу код:

use BIP\BIP44;

$seed = 'bcffab2ee26426c09a8486215a07a1a4b6a6b71b0db1947575477f1e113b08cafbe9465d41eb06573d29f298245a80f2be3a215aeb69d8f4c606168c8d334cc8';

$HDKey = BIP44::fromMasterSeed($seed)->derive("m/44'/60'/0'/0/0");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.