hdfchain/hdfchain-php-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hdfchain/hdfchain-php-api

Composer 安装命令:

composer require hdfchain/hdfchain-php-api

包简介

PHP API for the Hdfchain Cryptocurrency

README 文档

README

Build Status ISC License

PHP API for the Hdfchain Cryptocurrency

Installation

IF PHP version >7.0 composer It can be ignored version, Command:

composer install --ignore-platform-reqs

or

composer update --ignore-platform-reqs

PHP COMMOND CLI VERSION = 7.0 Add composer package to your project

composer require hdfchain/hdfchain-php-api

Make sure GMP PHP extesion is installed. In ubuntu:

sudo apt install php7.0-gmp

From repository

You also can clone git package with

git clone https://github.com/hdfchain/hdfchain-php-api.git

But still you will need to fetch library dependencies with composer.

composer install --no-dev

Don't forget to include composer autoloader.

include __DIR__.'/../vendor/autoload.php';

Usage examples

Library have wide functionality, so you could find usage examples in examples library or looking into PHPUnit tests.

Generating seed

First of all we need to get Network intance to start working with library.

$testnet = \Hdfchain\TestNet::instance();

And mainnet accordingly

$mainnet = \Hdfchain\MainNet::instance();

Now lets generate a seed, that will be also verified for usage on testnet. Defaut account and branch address will be derivded to verify the seed.

$seed = \Hdfchain\Crypto\ExtendedKey::generateSeed($testnet);

HD Wallets

When we have usable seed we can create HD master key.

$master = \Hdfchain\Crypto\ExtendedKey::newMaster($seed, $testnet);

newMaster method will return ExtendedKey object, that have variant API for working with HD wallets.

ExtendedKey::privateChildKey($index)

Derives HD private child key from parent HD private key, returns ExtendedKey object.

ExtendedKey::hardenedChildKey($index)

Derives HD hardened child key from parent HD private key, returns ExtendedKey object.

Can't be dervied from HD public key.

ExtendedKey::publicChildKey($index)

Derives HD public child key from parent HD private or public key, returns ExtendedKey object.

ExtendedKey::neuter

Verify that extended key is public, returns ExtendedKey object.

Default account

Using this basic methods we can derive default account HD private and public keys accourding to BIP44.

HD path (m\44'\42'\0')

$defaultAccountPrivateKey = $master
    ->hardenedChildKey(44)
    ->hardenedChildKey(42)
    ->hardenedChildKey(0);

$defaultAccountPublicKey = $master->neuter();

ExtendedKey implements __toString() method, so you can easily get Base58 representation of HD key.

echo sprintf("Default account HD private key: %s\n", $defaultAccountPrivateKey);
echo sprintf("Default account HD public key: %s\n", $defaultAccountPublicKey);

From default account we can derive 0 branch and 0 index and the get default address.

$defaultAddress = $defaultAccountPublicKey
    ->publicChildKey(0)
    ->publicChildKey(0)
    ->getAddress();

echo sprintf("Default address: %s\n", $defaultAddress);

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: ISC
  • 更新时间: 2020-09-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固