certhis/sdk

该包最新版本(0.1)没有可用的许可证信息。

Certhis-SDK 是一个 PHP 库,允许开发人员与 Certhis API 交互。

0.1 2024-08-22 13:50 UTC

This package is not auto-updated.

Last update: 2024-09-20 12:34:30 UTC


README

Certhis PHP SDK 允许您轻松与 Certhis API 交互。此 SDK 提供了签名消息等功能。

要求

  • PHP 7.4 或更高版本
  • Composer 用于管理依赖项
  • 用于哈希的 kornrunner/keccak
  • 用于椭圆曲线操作的 simplito/elliptic-php

安装

要在您的项目中使用 Certhis SDK,您需要通过 Composer 安装它。如果您尚未安装 Composer,可以从 getcomposer.org 下载。

composer require "certhis/sdk"

1. Web3Helper::__construct($privateKey)

  • 目的:使用给定的私钥初始化 Web3Helper 实例。此密钥用于签名消息等加密操作。
  • 参数:
    • $privateKey:用于加密操作的私钥字符串。

2. Web3Helper::getPublicKey()

  • 目的:检索与在 Web3Helper 实例初始化期间提供的私钥关联的公共地址。
  • 返回:表示公共地址的字符串。

3. Certhis::__construct($api = 'https://api.certhis.io', $apikey = null)

  • 目的:初始化 Certhis 类,它是与 Certhis API 交互的主要入口点。
  • 参数:
    • $api(可选):Certhis API 的基本 URL。默认为 'https://api.certhis.io'
    • $apikey(可选):用于向 Certhis API 发送请求进行身份验证的 API 密钥。如果不提供,必须在稍后或环境中设置 API 密钥。

4. Sign::__construct($certhis)

  • 目的:初始化 Sign 类,负责处理签名和验证过程。
  • 参数:
    • $certhis:用于与 Certhis API 交互的 Certhis 类实例。

5. Sign::get($wallet)

  • 目的:从 Certhis API 获取给定钱包(公共地址)的签名。
  • 参数:
    • $wallet:请求签名的公共地址。
  • 返回:包含签名的关联数组。

6. Web3Helper::signMessage($message)

  • 目的:使用与 Web3Helper 实例关联的私钥签名消息。
  • 参数:
    • $message:要签名的消息字符串。
  • 返回:已签名的消息。

7. Sign::check($wallet, $signedMessage)

  • 目的:验证签名消息是否与从 Certhis API 获取的原始签名相对应。
  • 参数:
    • $wallet:用于生成原始签名的公共地址。
    • $signedMessage:要验证的已签名消息。
  • 返回:表示签名消息是否有效的布尔值。

集成示例

以下是如何将 Certhis SDK 集成到您的 PHP 项目中的示例

require '../vendor/autoload.php';

use Certhis\Sdk\Web3Helper; 
use Certhis\Sdk\Certhis;
use Certhis\Sdk\Sign;

// Initialize the Web3Helper instance with a private key
$web3Helper = new Web3Helper('0xfc3f00a1acf34b12b38a91c89fc502b4851ed6f053be087b88286490966c7db0');
echo "Public address: " . $web3Helper->getPublicKey() . "\n";

// Initialize the Certhis class with an API key
$certhis = new Certhis('https://api.certhis.io', 'your_api_key');

// Initialize the Sign class with the Certhis instance
$sign = new Sign($certhis);

// Get the public address from the Web3Helper
$wallet = $web3Helper->getPublicKey();

// Retrieve a signature from Certhis API for the given wallet
$get_sign = $sign->get($wallet);
echo "Signature from Certhis: " . $get_sign["signature"] . "\n";

// Sign the retrieved message using Web3Helper
$signed = $web3Helper->signMessage($get_sign["signature"]);
echo "Signed Message: " . $signed . "\n";

// Verify the signed message using the Certhis Sign class
$check = $sign->check($wallet, $signed);
echo "Signature Verification Result: " . ($check ? "Valid" : "Invalid") . "\n";