Skip to content

Commit

Permalink
Update CID.php
Browse files Browse the repository at this point in the history
  • Loading branch information
puklipo committed Dec 15, 2024
1 parent efa7148 commit 3175817
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Support/CID.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Revolution\Bluesky\Support;

use GuzzleHttp\Psr7\Utils;
use Throwable;
use YOCLIB\Multiformats\Multibase\Multibase;

Expand Down Expand Up @@ -77,18 +78,16 @@ public static function verify(string $data, string $cid, ?int $codec = self::RAW
* ```
*
* @return array{version: int, codec: int, hash_algo: int, hash_length: int, hash: string}
*
* @throws Throwable
*/
public static function decode(string $cid): array
{
$bytes = Multibase::decode($cid);
$stream = Utils::streamFor(Multibase::decode($cid));

$version = Varint::decode(substr($bytes, 0, 1));
$codec = Varint::decode(substr($bytes, 1, 1));
$hash_algo = Varint::decode(substr($bytes, 2, 1));
$hash_length = Varint::decode(substr($bytes, 3, 1));
$hash = bin2hex(substr($bytes, 4, $hash_length));
$version = Varint::decodeStream($stream);
$codec = Varint::decodeStream($stream);
$hash_algo = Varint::decodeStream($stream);
$hash_length = Varint::decodeStream($stream);
$hash = bin2hex($stream->read($hash_length));

return compact(
'version',
Expand Down

0 comments on commit 3175817

Please sign in to comment.