> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# 驗證（Verify）

> Bluesky / AT Protocol 的驗證功能。貼文、圖像、CAR 檔的 CID 驗證方式。

## 概觀

可驗證性是 Bluesky / AT Protocol 的重要概念。

## 驗證貼文

可驗證透過 [com.atproto.repo.getRecord](https://docs.bsky.app/docs/api/com-atproto-repo-get-record) 取得的貼文資料，其 CID 是否與 record 一致。

```php theme={null}
$block = [
    'uri' => 'at://did:plc:***/app.bsky.feed.post/***',
    'cid' => 'bafyreih5y47li4zuvvzevmq4xl7woqxchfc2pnfclv3kfz3zefb2qd3bzm',
    'value' => [
        'text' => 'Hello, Bluesky!',
        '$type' => 'app.bsky.feed.post',
        'createdAt' => '2025-01-01T00:00:00.000Z',
    ],
];
```

```php theme={null}
use Revolution\Bluesky\Core\CBOR;
use Revolution\Bluesky\Core\CID;

$cid = data_get($block, 'cid');
$record = data_get($block, 'value');

// 編碼為 DAG-CBOR
$cbor = CBOR::encode($record);

$bool = CID::verify($cbor, $cid);
```

範例實作：[DownloadRecordCommand](https://github.com/invokable/laravel-bluesky/blob/main/src/Console/DownloadRecordCommand.php)

## 驗證圖像檔案

在包含圖像的貼文中，`$link` 對應圖像的 CID。

```php theme={null}
$block = [
    'uri' => 'at://did:plc:***/app.bsky.feed.post/***',
    'cid' => 'b+++',
    'value' => [
        'text' => '附圖貼文',
        '$type' => 'app.bsky.feed.post',
        'embed' => [
            '$type' => 'app.bsky.embed.images',
            'images' => [
                [
                    'alt' => '',
                    'image' => [
                        'ref' => [
                            '$link' => 'b***image'
                        ],
                        'size' => 100000,
                        '$type' => 'blob',
                        'mimeType' => 'image/jpeg'
                    ],
                    'aspectRatio' => [
                        'width' => 1000,
                        'height' => 1000
                    ]
                ]
            ]
        ],
        'createdAt' => '2025-01-01T00:00:00.000Z'
    ]
];
```

驗證透過 [com.atproto.sync.getBlob](https://docs.bsky.app/docs/api/com-atproto-sync-get-blob) 下載的圖像原始資料。

```php theme={null}
use Revolution\Bluesky\Core\CID;

// 圖像的 CID 從 $link 取得
$cid = data_get($block, 'value.embed.images.0.image.ref.$link');
$file = file_get_contents('path/to/b***image.jpg');

$bool = CID::verify($file, $cid, codec: CID::RAW);
```

範例實作：[DownloadBlobsCommand](https://github.com/invokable/laravel-bluesky/blob/main/src/Console/DownloadBlobsCommand.php)

## 驗證 CAR 檔

CAR 檔中包含使用者的所有 record。

可驗證透過 [com.atproto.sync.getRepo](https://docs.bsky.app/docs/api/com-atproto-sync-get-repo) 下載的 CAR 檔是否屬於目標使用者。

```php theme={null}
use Revolution\Bluesky\Core\CAR;
use Revolution\Bluesky\Crypto\DidKey;
use Revolution\Bluesky\Facades\Bluesky;
use Revolution\Bluesky\Support\DidDocument;

$did = 'did:plc:***';

// 驗證需要 didDoc 中的公鑰
$didDoc = DidDocument::make(Bluesky::identity()->resolveDID($did)->json());

$didKey = DidKey::parse($didDoc->publicKey());

$car = 'CAR 檔的原始資料或指向檔案的 stream';

$signed = CAR::signedCommit($car);

$bool = CAR::verifySignedCommit($signed, $didKey);
```

範例實作：[DownloadRepoCommand](https://github.com/invokable/laravel-bluesky/blob/main/src/Console/DownloadRepoCommand.php)

## CAR 檔展開後的驗證

CAR 檔展開後取得的 record 驗證方式，與貼文的第一個範例相同。

範例實作：[UnpackRepoCommand](https://github.com/invokable/laravel-bluesky/blob/main/src/Console/UnpackRepoCommand.php)

<Info>
  Source：[docs/verify.md](https://github.com/invokable/laravel-bluesky/blob/main/docs/verify.md)
</Info>


## Related topics

- [驗證](/zh-TW/validation.md)
- [電子郵件驗證（Email Verification）](/zh-TW/verification.md)
- [雜湊（Hashing）](/zh-TW/hashing.md)
- [Core — AT Protocol 核心操作](/zh-TW/packages/laravel-bluesky/core.md)
- [從 Laravel 12 升級到 13 指南](/zh-TW/blog/upgrade-12-to-13.md)
