Download the PHP package nimiq/utils without Composer
On this page you can find all versions of the php package nimiq/utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package utils
Short Description PHP Utilities for Nimiq
License Apache-2.0
Homepage https://github.com/nimiq/php-utils
Informations about the package utils
Nimiq PHP Utilities
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:
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:
To generate byte-encoded strings from HEX representations, you can use sodium_hex2bin(), for example:
AddressUtils
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
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.
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
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:
The expected output is: