primas /node
Ethereum secp256k1 PHP库
v0.1
2018-08-01 07:52 UTC
Requires
- php: >=7.0
- ext-gmp: *
- ext-keccak: ~0.2
- ext-scrypt: ~1.4
- ext-secp256k1: ^0.1.3
- bitwasp/buffertools: ^0.5.0
- guzzlehttp/guzzle: ~6.0
This package is not auto-updated.
Last update: 2024-09-29 05:08:26 UTC
README
- Primas Node API 文档 https://github.com/primasio/primas-api-doc
依赖
使用签名机进行签名
"php": ">=7.0",
"ext-gmp": "*",
"guzzlehttp/guzzle": "~6.0"
使用keystore进行签名
"php-64bit": ">=7.0",
"ext-gmp": "*",
"ext-scrypt": "~1.4",
"ext-secp256k1": ">=0.1.0",
"ext-keccak": "~0.2",
"guzzlehttp/guzzle": "~6.0",
"bitwasp/buffertools": "^0.5.0"
- ext-scrypt: https://github.com/DomBlack/php-scrypt
- ext-secp256k1: https://github.com/Bit-Wasp/secp256k1-php
- ext-keccak: https://github.com/EricYChu/php-keccak-hash
安装
- 1、使用Git克隆整个仓库到根目录,或导出仓库的zip文件并在本地解压。
- 2、composer require primas/node
快速入门
- 注意:在使用API方法之前,需要初始化API配置。
- 如果需要大整数,请将其作为字符串使用。
示例
创建根账户
- 请记住保存根账户id
$config = [ "http_options" => [ "base_uri" => "https://staging.primas.io" // testnet ] ]; $app = \Primas\Factory::account($config); // Sign with the keystore // Import the keystore $keystore = '{"version":3,"id":"e1a1909a-7a38-44aa-af04-61cd3a342008","address":"d75407ad8cabeeebfed78c4f3794208b3339fbf4","Crypto":{"ciphertext":"bcf8d3037432f731d3dbb0fde1b32be47faa202936c303ece7f53890a79f49d2","cipherparams":{"iv":"e28edaeff90032f24481c6117e593e01"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"7d7c824367d7f6607128c721d6e1729abf706a3165384bbfc2aae80510ec0ce2","n":1024,"r":8,"p":1},"mac":"52f98caaa4959448ec612e4314146b6a2d5022d5394b77e31f5a79780079c22f"}}'; $password = "Test123:::"; \Primas\Kernel\Eth\Keystore::init($keyStore, $password); $parameters = [ "name" => "Test123", "abstract" => "first test", "created" => time(), "address" => (string)\Primas\Kernel\Eth\Keystore::getAddress(); ]; $metadataJson = $app->buildCreateAccount($parameters); $signature = $app->sign($metadataJson); $metadata = $app->setSignature($metadataJson, $signature); $res = $account->createAccount($metadata); // ...... // Sign with a signature machine $parameters = [ "name" => "Test123", "abstract" => "first test", "created" => time(), "address" => "0xd75407ad8cabeeebfed78c4f3794208"; ]; $metadataJson = $app->buildCreateAccount($parameters); // TODO request signature machine get signature // If it is asynchronous, save the correspondence between the signature result and the application. $signature="your signature from your signature machine"; $metadata = $app->setSignature($metadataJson, $signature); $res = $account->createAccount($metadata); var_dump($res); // save the root account id // save the root account id // save the root account id // result /* array(3) { ["result_code"]=> int(0) ["result_msg"]=> string(7) "success" ["data"]=> array(2) { ["id"]=> string(64) "e19aa9a8cdc217c345925b7e824baea0ef6dab0e11117dfd2746be469b412724" ["dna"]=> string(64) "4659b4848c8e9e3ec60c94ded2cc58a35419411f58ff27dc51f116bb05577eb9" } } */
工厂
1、静态方法
/** * Class Factory * * @method static \Primas\Account\Application account(array $config) * @method static \Primas\Content\Application content(array $config) * @method static \Primas\ContentInteraction\Application content_interaction(array $config) * @method static \Primas\Group\Application group(array $config) * @method static \Primas\Node\Application node(array $config) * @method static \Primas\Query\Application query(array $config) * @method static \Primas\System\Application system(array $config) * @method static \Primas\TimeLine\Application time_line(array $config) * @method static \Primas\Token\Application token(array $config) * * @package Primas */ class Factory { ... }
2、配置介绍
- 数组类型
$config = [ /* * refer guzzle http document http://guzzle.readthedocs.io/en/stable/request-options.html */ "http_options" => [ "base_uri" => BASE_URI, // default https://rigel-a.primas.network "headers" => [ /* * default application/json * when Content-Type is multipart/form-data,if you want to post a file,the file field should be a file path like "F:/tmp/test.png" or an object instance CURLFile */ "Content-Type" => "application/json" // // ... ], ], /* * root account id */ "account_id" => $account_id ];