Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP x Nostr

PHP x Nostr

第170回 PHP勉強会@東京で発表した内容

https://phpstudy.connpass.com/event/335943/

Hakkadaikon

November 21, 2024
Tweet

More Decks by Hakkadaikon

Other Decks in Programming

Transcript

  1. ②電話番号メールアドレスいらない { "content": "test", “created_at”: 1726456407, "id": "7b31d7a9d9e8f65b1e3102a4cdc...", "kind": 1,

    "pubkey": "101b30ee88c27a13de68bf7...", "sig": "3d7d019db85deece5c1d704c987393957bb8c5c61458...", "tags": [] } ・アカウント=鍵(公開鍵/秘密鍵) ・全てのイベント発行時に電子署名する
  2. STEP4. ちょろっと ソース書く(38L) <?php namespace App¥Console¥Commands; use Illuminate¥Console¥Command; use swentel¥nostr¥Filter¥Filter;

    use swentel¥nostr¥Message¥RequestMessage; use swentel¥nostr¥Relay¥Relay; use swentel¥nostr¥Request¥Request; use swentel¥nostr¥Subscription¥Subscription; class FetchTimelineCommand extends Command { protected $signature = 'app:fetch-timeline-command {--kinds=1} {--limit=1}'; protected $description = 'Fetch the nostr timeline'; public function handle() { $kinds = array_map('intval', explode(',', $this->option('kinds'))); $limit = intval($this->option('limit')); $subid = (new Subscription())->setId(); $filter = (new Filter())->setKinds($kinds)->setLimit($limit); $response = ( new Request( new Relay('wss://yabu.me'), new RequestMessage($subid, [$filter]) ) )->send(); echo sprintf("%s¥n", json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); return 0; } }
  3. 早速動かしてみよう! $ php artisan app:fetch-timeline-command --kinds=1 --limit=1 --kinds : イベント種別

    (0:プロフィール 1:投稿 7:リアクション etc…) --limit : イベント取得件数
  4. { "wss://yabu.me": [ { "type": "EVENT", "isSuccess": true, "message": "",

    "subscriptionId": "Wd2SDCfvkh9T0eO6I1Mgw85iJbqGURLtjEr7BKmAyPasZNXHo4cFYuQ3lzxpnV", "event": { "content": "てすと", "created_at": 1732172057, "id": "de20ad56d21cf4c2e1fae1c67a58dbe475120fecded61c4563ed1faeff7b9839", "kind": 1, "pubkey": "101b30ee88c27a13de68bf7c8c06368ea3e3e837641595c18675677d18a46a45", "sig": "4d7002e71853282e61cb97ff0e093457d3dfd5c99fd512b1e074aaaca1a50a84250b3d16f6b895b7ebf0c8df1f247aee1cd0569f7075f937ed5e8ddf5bd0f36d", "tags": [] } }, { "type": "EOSE", "isSuccess": true, "message": "", "subscriptionId": "Wd2SDCfvkh9T0eO6I1Mgw85iJbqGURLtjEr7BKmAyPasZNXHo4cFYuQ3lzxpnV" } ] } こういうjsonが取れます