Download the PHP package viz-blockchain/viz-php-lib without Composer
On this page you can find all versions of the php package viz-blockchain/viz-php-lib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download viz-blockchain/viz-php-lib
More information about viz-blockchain/viz-php-lib
Files in viz-blockchain/viz-php-lib
Package viz-php-lib
Short Description Native PHP class for VIZ Keys, Transaction, JsonRPC
License MIT
Homepage https://github.com/VIZ-Blockchain/viz-php-lib
Informations about the package viz-php-lib
viz-php-lib
Native PHP class for VIZ Keys, Transaction, JsonRPC
Features
- JsonRPC — native socket usage (all API methods, hostname cache, ssl flag, full result flag)
- Keys — private (sign), public (verify), shared, encoded keys support (wif, public encoded, compressed/uncompressed public key in hex representation)
- Transaction — easy workflow, multi-signature support, multi-operations support, execute by JsonRPC, support all 40 operations: transfer, transfer_to_vesting, withdraw_vesting, award, create_invite, validator_update, etc...
- Classes support PSR-4
- Contains modificated classes for best fit to VIZ Blockchain (all-in-one)
- Native code without additional installations (sry composer, but we need other changes in third-party classes)
- Utils for keys compatibility with Ethereum, Bitcoin addresses
- Utilities with (Voice protocol)[https://github.com/VIZ-Blockchain/Free-Speech-Project/blob/master/specification.md] support: voice_text, voice_publication
- MIT License
Dependencies
One PHP extension from the list:
- GMP (GNU Multiple Precision) —
sudo apt-get install libgmp-dev php-gmp - BCMath —
sudo apt-get install php-bcmath
Most hosting providers have it turned on already, but if not found, check your control panel.
Thanks to third-party class developers:
- https://github.com/simplito/bigint-wrapper-php
- https://github.com/simplito/bn-php
- https://github.com/simplito/elliptic-php
- https://github.com/kornrunner/php-keccak
Examples
Some examples have placeholders for private keys or accounts. Change them for successfull test.
Keys: init from hex, encode to wif, get public key from private, get encoded version, verify signature.
JsonRPC: init with endpoint, api method without parameters, change endpoint, get account, turn on all json result, request a non-existent account.
Transaction: init with endpoint and private key in wif, build simple transaction with award operation and execute it.
Init with endpoint and private key in wif, activate queue mode and add 2 operations, end queue and get result array. Execute transaction json from array. Add additional signature for multi-sig example (can be false if canonical signature was not found).
Create new private key, get public key from it, execute transaction with create_invite operation.
Find shared key from two sides. Simple string encrypt and decrypt with AES-256-CBC. Encode and decode memo with viz-js-lib compability structure for encrypted memo.
Generate data and signature for passwordless authentication and check it for domain auth action with active authority.
Make transaction with custom operation.
Make transaction with account create operation.
Make transaction with proposal operations as array (need to use build_ prefix). Approve that proposal with other account active key.
Utils method for post text object to Voice protocol. Method attributes (* - is optional):
| Attribute | Description |
|---|---|
| text | Simple text note. |
| reply* | Link to replied context in viz:// url scheme. |
| share* | Link to shared context in any url scheme. |
| beneficiaries* | Array of objects [] contains ["account"=>"committee","weight"=>100] for awarding beneficiaries details. |
| loop* | Block num. Ability to make loop for previous objects, exclude from personal activity feed. |
Utils method for post publication object to Voice protocol. Method attributes (* - is optional):
| Attribute | Description |
|---|---|
| title | Publication title. |
| markdown | Publication text with voice markdown. |
| description* | Publication short description for preview. |
| image* | Link to publication image for preview thumbnail. |
| reply* | Link to replied context in viz:// url scheme. |
| share* | Link to shared context in any url scheme. |
| beneficiaries* | Array of objects [] contains ["account"=>"committee","weight"=>100] for awarding beneficiaries details. |
| loop* | Block num. Ability to make loop for previous objects, exclude from personal activity feed. |
Create Voice text object, hide it with Voice Event.
Create Voice text object, check transaction size, split it for add Voice Event.
Agent access (HF15)
HF15 added set_agent_permission (op 105): a principal may hand a key an explicit, frozen list of
its operations — an agent. An agent is not an account and never appears in any authority, so the
old check ("get_account and look at active_authority.key_auths") silently rejects agent keys.
The recipe is now authority OR agents, and VIZ\Agent::check() does both in one call.
Rules the helper mirrors from the node (agent_evaluator.cpp::usable_agent_row):
- an agent answers direct active/regular requirements only, and only for operations on its list — the master authority is never satisfied by an agent, nor is a nested/other authority;
expirationepoch (1970-01-01T00:00:00) = perpetual; a date in the past = revoked;- empty
operationsandaddons= revoked;addonsare off-chain scopes the node stores and never interprets, so a service matches its own scope there; - one key belongs to one agent of a principal; a change of master/active, a recovery or a sale wipes every agent of the principal.
check($account, $key, $operation) returns ['allowed', 'source' => 'authority'|'agent'|'none', 'role', 'agent', 'operation']; find() returns the raw row, has() a bool. Pass the wire
operation name (transfer, pm_place_bet, ...) to check a specific operation — with no operation
an agent key is only answered as "this is a live agent key", because its grants are per-operation.
A key that is only in a nested authority (account_auths) is not resolved here: use
verify_authority with a signed transaction for the full recursive check. On a node without HF15
the method is unknown, agents are skipped, and the check degrades to authorities only.
Agent::poisoned($row) and Agent::addon_matches($row, $scope) are the two pure row predicates the
verdicts are built from, exported for callers that already hold a row (and mirrored by viz.agent
in the JS lib).
The write side is build_set_agent_permission() on VIZ\Transaction. The raw read method is
get_agent_permissions, mapped to database_api like any other.
Domain auth (VIZ\Auth) also accepts an agent
VIZ\Auth::check() is the signature check a service runs against a signed
domain:action:account:authority:unixtime:nonce string. It used to look at the account's authority
only, so an agent key was refused — an agent is not an account and never appears in any authority.
Now it tries the
authority first and then the agents, gated on the addon: pass the service's own scope as the
6th constructor argument (or set $auth->addon later).
Domain auth is not a chain operation, so the row's operation list is not what a service matches on
— the addon is the grant (compare Agent::grants() for the operation side). The usual agent gates
still hold: an agent never answers a master requirement, the row must be alive, and a row the
node refuses as poisoned grants nothing at all, addons included. With no addon configured the
branch is off and check() behaves exactly as it did before HF15.
Prediction Markets (Onix, HF14)
The library ships all 23 signed prediction-market operations and all 29 prediction_market_api
read methods. Operation builders follow the usual convention (build_ prefix for queued/proposed
operations, no prefix to build-and-sign a standalone transaction) and every op takes an empty
extensions vector automatically. Object ids (market_id, bet_id, liquidity_id,
position_id, commit_id) are the bare integer instance of the on-chain object.
Percent fields are basis points (10000 = 100%) unless a builder note says otherwise. Assets are
VIZ strings ("10.000 VIZ"); share_type/min_tokens args are raw milli-VIZ integers (VIZ×1000).
Operation builders
pm_oracle_register · pm_oracle_update · pm_create_market · pm_oracle_accept_market ·
pm_place_bet · pm_commit_bet · pm_reveal_bet · pm_cancel_bet · pm_add_liquidity ·
pm_withdraw_liquidity · pm_resolve_market · pm_no_contest · pm_dispute_create ·
pm_dispute_vote (regular auth) · pm_dispute_resolve · pm_transfer_position · pm_lazy_deposit ·
pm_lazy_withdraw · pm_leverage_open · pm_leverage_close · pm_leverage_convert ·
pm_dispute_oracle_respond · pm_unban.
Optional fields on pm_oracle_update accept null to leave a field unchanged
(insurance_delta is a signed asset — "-5.000 VIZ" to withdraw):
Commit–reveal betting
pm_commitment(...) builds the byte-exact SHA-256 commitment the node re-checks on reveal (a wrong
preimage forfeits the escrow). amount/min_tokens are milli-VIZ integers:
Read methods (prediction_market_api)
Called via execute_method like any other API. Pagination is (...key..., from, limit) with
limit <= 1000.
Full method set: get_market, list_markets, list_markets_by_oracle, list_markets_by_creator,
get_market_outcomes, get_market_weight_sums, get_market_bets, get_account_positions,
get_market_liquidity, get_market_full, get_account_leverage_positions,
get_market_leverage_positions, get_creator_ban, get_leverage_quote,
get_leverage_close_preview, get_leverage_convert_preview, get_oracle, list_oracles,
get_dispute, get_dispute_votes, get_lazy_pool, get_lazy_deposit, get_lazy_allocations,
get_market_lazy_allocation, get_pm_chain_properties, get_market_meta,
list_markets_by_category, get_market_categories, get_market_kline.
May VIZ be with you.
HF16 compatibility
Committee request limits are checked by the node: from HF16 the maximum is 1% of
current_supply at creation, rounded down to the smallest VIZ unit. The operation
fields and transaction encoding are unchanged. JSON-RPC returns QC, timeout and
equivocation header extensions without decoding their binary format. This library
does not sign or serialize block headers; validator_equivocation is a virtual
operation and must not be broadcast as a transaction.