承接 tuupola/base58 相关项目开发

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

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

tuupola/base58

Composer 安装命令:

composer require tuupola/base58

包简介

Base58 encoder and decoder for arbitrary data

关键字:

README 文档

README

This library implements Base58 encoding. In addition to integers it can encode and decode any arbitrary data. That said, Base58 is well suited for decoding big integers but is not designed to decode long portions of binary data.

Latest Version Software License Build Status Coverage

Install

Install with composer.

$ composer require tuupola/base58

This branch requires PHP 7.1 or up. The older 1.x branch supports also PHP 5.6 and 7.0.

$ composer require "tuupola/base58:^1.0"

Usage

This package has both pure PHP and GMP based encoders. By default encoder and decoder will use GMP functions if the extension is installed. If GMP is not available pure PHP encoder will be used instead.

$base58 = new Tuupola\Base58;

$encoded = $base58->encode(random_bytes(128));
$decoded = $base58->decode($encoded);

If you are encoding to and from integer use the implicit decodeInteger() and encodeInteger() methods.

$integer = $base58->encodeInteger(987654321); /* 1TFvCj */
print $base58->decodeInteger("1TFvCj", true); /* 987654321 */

Also note that encoding a string and an integer will yield different results.

$string = $base58->encode("987654321"); /* gE62MGeOBMPt */
$integer = $base58->encodeInteger(987654321); /* 1TFvCj */

Character sets

By default Base58 uses GMP style character set. Shortcuts are provided for Bitcoin, Flickr, Ripple and IPFS character sets. You can also use any custom 58 characters.

use Tuupola\Base58;

print Base58::GMP /* 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv */
print Base58::BITCOIN /* 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz */
print Base58::FLICKR /* 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ */
print Base58::RIPPLE /* rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz */
print Base58::IPFS /* 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz */

$default = new Base58(["characters" => Base58::GMP]);
$bitcoin = new Base58(["characters" => Base58::BITCOIN]);
print $default->encode("Hello world!"); /* 1LDlk6QWOejX6rPrJ */
print $bitcoin->encode("Hello world!"); /* 2NEpo7TZRhna7vSvL */

Base58Check support

This library supports the Base58Check encoding used in Bitcoin addresses. Decoding validates both version and the checksum. If either of them fails a RuntimeException will be thrown;

use Tuupola\Base58;

$base58check = new Base58([
    "characters" => Base58::BITCOIN,
    "check" => true,
    "version" => 0x00
]);

print $base58check->encode("Hello world!"); /* 19wWTEnNTWna86WmtFsTAr5 */

try {
    $base58check->decode("19wWTEnNTWna86WmtFsTArX");
} catch (RuntimeException $exception) {
    /* Checksum "84fec52c" does not match the expected "84fec512" */
    print $exception->getMessage();
}

Speed

Install GMP if you can. It is much faster pure PHP encoder. Below benchmarks are for encoding random_bytes(128) data. BCMatch encoder is also included but it is mostly just a curiosity. It is too slow to be usable.

$ vendor/bin/phpbench run benchmarks/ --report=default

+-----------------------+------------------+--------------+
| subject               | mean             | diff         |
+-----------------------+------------------+--------------+
| benchGmpEncoder       | 101,832.994ops/s | 0.00%        |
| benchGmpEncoderCustom | 97,656.250ops/s  | +4.28%       |
| benchPhpEncoder       | 305.913ops/s     | +33,188.19%  |
| benchBcmathEncoder    | 32.457ops/s      | +313,643.79% |
+-----------------------+------------------+--------------+

Static Proxy

If you prefer to use static syntax use the provided static proxy.

use Tuupola\Base58Proxy as Base58;

$encoded = Base58::encode(random_bytes(128));
$decoded = Base58::decode($encoded);

Testing

You can run tests either manually or automatically on every code change. Automatic tests require entr to work.

$ make test
$ brew install entr
$ make watch

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

tuupola/base58 适用场景与选型建议

tuupola/base58 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 670.91k 次下载、GitHub Stars 达 56, 最近一次更新时间为 2017 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「base58」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tuupola/base58 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tuupola/base58 我们能提供哪些服务?
定制开发 / 二次开发

基于 tuupola/base58 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 670.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 56
  • 点击次数: 19
  • 依赖项目数: 24
  • 推荐数: 0

GitHub 信息

  • Stars: 56
  • Watchers: 1
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-09