承接 oswin.hu/crypto 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

oswin.hu/crypto

最新稳定版本:v1.0.1

Composer 安装命令:

composer require oswin.hu/crypto

包简介

Crypto tool library

README 文档

README

A collection of common utilities and libraries in PHP for use with Bitcoin and Zetacoin compatable crypto currencies ustilizing the secp256k1 ECDSA curve.

The code may be messy and all over the place, but I'm still pulling things together as I merge this code base with items from the PHPECC codebase. The current features include:

  • Private Key Generation and Loading
  • Public Address Print Out
  • Message Signing and Verification
  • Address Generation and Validation
  • Address compression, de-compression, encoding, and decoding.
  • Supports Arbitrary Address Prefixes

Currently, the following items are working

  • Base58.php
  • SECp256k1.php
  • PointMathGMP.php
  • AddressValidation.php
  • AddressCodec.php
  • PrivateKey.php
  • Signature.php

Usage

AddressCodec

The AddressCodec class provides a simple interface for common Zetacoin/Bitcoin (and compatable) address functions. Load the following classes in your PHP code:

use Crypto\AddressCodec;

The most basic example, get the X and Y coordnates of a DER Encoded public key (old format)

$derPublicKey = '04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235';

$point = AddressCodec::Point($derPublicKey);

echo $point['x'];
echo $point['y'];

That will return an array with both X and Y:

X = a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd
Y = 5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235

The more usefull method is with the new compressed public keys used by modern crypto currencies:

$compressedPublicKey = '03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd';

$point = AddressCodec::Decompress($compressedPublicKey);

echo $point['x'];
echo $point['y'];

Works the other way around too:

$compressedPublicKey = AddressCodec::Compress($point);
$derPublicKey = AddressCodec::Hex($point);

On to the more usefull items, Encode a public key into a Crypto Currency address. First Hash your public key then Encode it.

$hash = AddressCodec::Hash($compressedPublicKey);
$address = AddressCodec::Encode($hash);

echo $address;

Gives you:

Address = 1F3sAm6ZtwLAUnj7d38pGFxtP3RVEvtsbV

Specify your own prefix (in HEX):

$address = AddressCodec::Encode($hash, "50");

Gives you:

Address = ZS67wSwchNQFuTt3abnK4HjpjQ2x79YZed

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固