123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/6/27
- * @time: 19:16
- */
- namespace qiniu\services\blockchain;
- use BitWasp\Bitcoin\Base58;
- use BitWasp\Buffertools\Buffer;
- use think\Exception;
- class SolanaService
- {
- private static $node = 'https://solana-mainnet.core.chainstack.com/867a25e325f29ac68e3b5185af1abb68';
- public static function signCheck($sign, $address, $message)
- {
- if (!is_array($sign)) {
- $sign = explode(',', $sign);
- }
- if (!count($sign) == 64) {
- throw new Exception('Sign fail');
- }
- $sign_str = self::uint8ArrayToByteString($sign);
- $sign_buffer = new Buffer($sign_str, 64);
- $key_buffer2 = Base58::decode($address);
- return sodium_crypto_sign_verify_detached($sign_buffer->getBinary(), $message, $key_buffer2->getBinary());
- }
- private static function uint8ArrayToByteString(array $uint8Array): string
- {
- return call_user_func_array('pack', array_merge(array('C*'), $uint8Array));
- }
- private static function byteStringToUint8Array(string $byteString): array
- {
- $uint8Array = unpack('C*', $byteString);
- return array_values($uint8Array);
- }
- public static function getTransaction($tx)
- {
- $data = [
- 'jsonrpc' => '2.0',
- 'id' => 1,
- 'method' => 'getTransaction',
- 'params' => [
- $tx,
- [
- 'maxSupportedTransactionVersion' => 0,
- 'encoding' => 'json'
- ],
- ],
- ];
- $res = do_request(self::$node, [], $data, ['Content-Type: application/json'], true, true);
- return json_decode($res, true);
- }
- }
|