suicore/walrus-sdk-php
Composer 安装命令:
composer require suicore/walrus-sdk-php
包简介
A PHP wrapper of Walrus
关键字:
README 文档
README
The Walrus PHP SDK provides a convenient, strongly-typed interface for interacting with the Walrus HTTP APIs. It supports storing and retrieving blobs and quilts via the publisher and aggregator endpoints of the Walrus service, leveraging Guzzle HTTP for robust HTTP communication.
Features
- Store Blobs: Upload data (or files) as blobs with configurable storage epochs, send-to address, and deletability options.
- Retrieve Blobs: Easily retrieve blob content using a unique blob ID.
- Strongly Typed Responses: Work with dedicated response classes such as
StoreBlobResponse,NewlyCreatedResponse, andAlreadyCertifiedResponse.
Installation
Install via Composer:
composer require suicore/walrus-sdk
Usage
Here’s a basic example of how to use the SDK:
<?php require 'vendor/autoload.php'; use Suicore\Walrus\Types\StoreBlobOrQuiltOptions; use Suicore\Walrus\WalrusClient; // Set your API endpoints $publisherUrl = 'https://publisher.walrus-testnet.walrus.space'; $aggregatorUrl = 'https://aggregator.walrus-testnet.walrus.space'; // Instantiate the client $client = new WalrusClient($publisherUrl, $aggregatorUrl); // Prepare options for storing a blob $options = new StoreBlobOrQuiltOptions(epochs: 2); // Store a text blob $storeResponse = $client->storeBlob("Hello, Walrus!", $options); // Check if the blob was newly created if ($storeResponse->isNewlyCreated()) { $blobId = $storeResponse->getNewlyCreated()->getBlobObject()->getBlobId(); echo "Blob stored successfully with ID: {$blobId}\n"; } else { // Handle the already certified case $blobId = $storeResponse->getAlreadyCertified()->getBlobId(); echo "Blob was already certified with ID: {$blobId}\n"; } // Retrieve the blob content $content = $client->getBlob($blobId); echo "Retrieved content: {$content}\n";
Uploading Files
To upload a blob, simply pass the file path to the storeBlob method and set the $isFile parameter to true:
// Save a file as a blob $file = '/path/to/file.txt'; $options = new StoreBlobOrQuiltOptions(epochs: 2); $storeResponse = $client->storeBlob(dataOrPath: $file, options: $options, isFile: true);
Uploading a file in a quilt
The SDK supports uploading multiple files as a single quilt using the storeQuilt method. Each file can be associated with custom metadata.
use Suicore\Walrus\WalrusClient; use Suicore\Walrus\Types\StoreBlobOrQuiltOptions; use Suicore\Walrus\Types\QuiltElementFile; use Suicore\Walrus\Types\QuiltElementFileMetadata; $client = new WalrusClient($publisherUrl, $aggregatorUrl); $options = new StoreBlobOrQuiltOptions(epochs: 2); $files = [ new QuiltElementFile('wal1.jpg', __DIR__ . '/walrus.jpg'), new QuiltElementFile('wal2.jpg', fopen(__DIR__ . '/walrus.jpg', 'rb')), // Open resource ]; $metadata = [ new QuiltElementFileMetadata('wal1.jpg', (object)['creator' => 'walrus', 'version' => '1.0']), new QuiltElementFileMetadata('wal2.jpg', (object)['type' => 'logo', 'format' => 'png']), ]; $storeResponse = $client->storeQuilt($files, $options, $metadata); $files = $storeResponse->getStoredQuiltBlobs()->getQuiltFiles(); foreach ($files as $file) { echo "Stored patch ID: " . $file->getQuiltPatchId() . "\n"; }
Retrieving a Quilt Patch or Quilt by name
$patchId = 'quilt-file-patch-id'; $content = $client->getQuilt($patchId); $blobId = 'quilt-blob-id'; $fileContent = $client->getQuilt($blobId, 'wal1.jpg');
Encryption
The Walrus SDK provides a simple, but secure way to encrypt and decrypt data using the Aes256Encryptor class. Here’s an example:
use Suicore\Walrus\Helpers\Aes256Encryptor; // Encrypt data $encryptor = new Aes256Encryptor('01234567890123456789012345678901'); // EXAMPLE, USE A DIFFERENT KEY! $encryptedData = $encryptor->encrypt('Hello, Walrus!'); echo "Encrypted data: {$encryptedData}\n"; // Decrypt data $decryptedData = $encryptor->decrypt($encryptedData); echo "Decrypted data: {$decryptedData}\n";
A key length of 32 bytes is required for AES-256 encryption. Shorter or longer keys will work, but will be more unpredictable and less secure.
API Methods
storeBlob
Stores a blob using the publisher API.
Parameters:
string dataOrPath: The blob data or file path.StoreBlobOrQuiltOptions $options: Options such as epochs, sendObjectTo address, and deletability.bool $isFile: Set to true if $dataOrPath is a file path.- Returns: A StoreBlobResponse object representing the response from the API.
getBlob
Retrieves a blob from the aggregator API.
Parameters:
string $blobId: The unique blob identifier.- Returns: The blob content as a string.
storeQuilt
Stores multiple files as a quilt with optional metadata.
Parameters:
QuiltFile[] $files: An array of QuiltFile objects containing identifier and file source.StoreBlobOrQuiltOptions $options: Storage options.QuiltMetadata[] $metadata: (Optional) Metadata associated with each file.- Returns: StoreQuiltResponse
getQuilt
Retrieves quilt content from the aggregator.
Parameters:
string $blobOrPatchId: A blob ID (for full quilt) or a patch ID (for specific patch).string|null $filename: Optional filename to extract a specific file from the quilt.- Returns: File contents as a string.
Testing
To run the test suite, use the following commands:
Unit Tests
composer test
Include Integration Tests
export RUN_INTEGRATION_TESTS=1
vendor/bin/phpunit --filter WalrusClientE2ETest
Contributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License. See the LICENSE file for details.
suicore/walrus-sdk-php 适用场景与选型建议
suicore/walrus-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sdk」 「blockchain」 「walrus」 「sui」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 suicore/walrus-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 suicore/walrus-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 suicore/walrus-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Solana PHP SDK for interacting with the Solana blockchain
A fast and dynamic Merkle tree implementation
Multichain JSON-RPC Client
Alfabank REST API integration
Implementation of Bitclout API interaction through its node
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-17