nimiq/utils
Composer 安装命令:
composer require nimiq/utils
包简介
PHP Utilities for Nimiq
关键字:
README 文档
README
This is a collection of utility classes for working with Nimiq primitives in PHP. It is not meant to enable a Nimiq network node in PHP, but rather to verify signatures, derive and validate addresses and to work with serialized primitives in a PHP environment. This collection is planned to grow over time when the need arises or by additions from the community.
Installation
The Nimiq PHP Utilities are availabe via the Packagist package registry and can be installed with Composer:
composer require nimiq/utils
Please note that PHP >= 7.2 with an installed sodium extention is required to use these utilities. Please make sure that you have your operating system's equivalent of the php-sodium package installed or that you activate the sodium extension in your hosting's PHP settings.
Usage
The utility classes are available in the Nimiq\Utils namespace:
use Nimiq\Utils\AddressUtils; use Nimiq\Utils\SignatureUtils; use Nimiq\Utils\RpcUtils;
To generate byte-encoded strings from HEX representations, you can use sodium_hex2bin(), for example:
$public_key = sodium_hex2bin('873279e12d5af18c4e899a781e55711f7910ed8ddb85b2179ece38a570253527');
AddressUtils
AddressUtils::pubkey2address(string $public_key[, bool $with_spaces = true]): string
Convert a public key into a Nimiq userfriendly address.
$public_keyA byte-encoded string of length 32 representing a Nimiq public key.$with_spaces[optional] Set to FALSE to output the address without spaces.
SignatureUtils
SignatureUtils::verify(string $signature, string $data, string $public_key): bool
Verify a signature for the given data and public key.
$signatureA byte-encoded string representing a Nimiq signature.$dataA byte-encoded string representing the data that the signature should be verified for.$public_keyA byte-encoded string representing the Nimiq public key of the signer.
SignatureUtils::verify_message(string $signature, string $message, string $public_key): bool
Verify a message signature for the given message and public key.
Message signatures are different from regular signatures in that the message is prefixed and hashed before being signed. This method applies these same manipulations to the message before verifying the signature.
$signatureA byte-encoded string representing a Nimiq message signature.$messageThe plain-text representation of the message that the signature should be verified for.$public_keyA byte-encoded string representing the Nimiq public key of the signer.
RpcUtils
RpcUtils::prepareRedirectInvocation(string $targetURL, int $id, string $returnURL, string $command, array $args, string $responseMethod): string
Generate a redirect URL with the parameters encoded in the URL fragment.
$targetURLThe base URL to redirect to, including paths and query parameters (a fragment is discarded).$idA numeric ID for the RPC request, must be >= 0.$returnURLThe URl to redirect back to, when the requests succeeds or fails.$commandThe name of the function that should be called.$argsAn array of function arguments to pass to the called function.$responseMethodHow to receive the response: 'message' (postMessage), 'url' (GET redirect), or 'post' (POST redirect)
Note: Binary strings are not yet supported in
$args!
Development
The sodium cryptographic methods are best documented in the developer's documentation: https://paragonie.com/book/pecl-libsodium.
Setup
- Use PHP >= 7.2
- Install the
sodiumextension - Verify that you have the sodium extension correctly installed by running
php test/version_check.php- if it displays the extension's version numbers, everything is good to go
Testing
To execute a (minimal) test of these utilities' functionality, run:
php test/test.php
The expected output is:
Is valid: bool(true)
Address: NQ03 VDL0 TSF5 CFNX VNCL 4MGK 0BX7 150E VMXA
nimiq/utils 适用场景与选型建议
nimiq/utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「blockchain」 「nimiq」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nimiq/utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nimiq/utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nimiq/utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
A simple class to derive BTC and ETH extended public keys and addresses without GMP.
Solana PHP SDK for interacting with the Solana blockchain
A fast and dynamic Merkle tree implementation
Multichain JSON-RPC Client
Implementation of Bitclout API interaction through its node
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-06-17