{"openapi":"3.1.0","info":{"title":"GrID CIC","version":"1.0.0","description":"Agent ID のエージェントについて、各サービスが公開した記録を集めて返す与信の API。事実だけを返し、スコアは付けない。","contact":{"name":"GrID CIC","url":"https://cic.grid.tc"}},"servers":[{"url":"https://cic.grid.tc","description":"本番"},{"url":"http://localhost:8788","description":"wrangler dev"}],"tags":[{"name":"report","description":"エージェントの与信レポート"},{"name":"submit","description":"発行者からの記録の受け付け"},{"name":"admin","description":"運営による API キーの管理"}],"components":{"securitySchemes":{"bearer":{"type":"http","scheme":"bearer"}},"schemas":{"CreditReport":{"type":"object","properties":{"agentId":{"type":"string","pattern":"^[0-9a-f]{64}$"},"generatedAt":{"type":"number"},"identity":{"$ref":"#/components/schemas/Identity"},"totals":{"type":"object","properties":{"records":{"type":"number"},"byType":{"type":"object","additionalProperties":{"type":"number"}},"issuers":{"type":"number"},"rebuttals":{"type":"number"}},"required":["records","byType","issuers","rebuttals"]},"issuers":{"type":"array","items":{"$ref":"#/components/schemas/Issuer"}},"sources":{"type":"object","properties":{"relays":{"type":"array","items":{"type":"string"}},"lastFetchedAt":{"type":"number"}},"required":["relays"]}},"required":["agentId","generatedAt","identity","totals","issuers","sources"]},"Identity":{"type":"object","properties":{"status":{"type":"string","enum":["active","revoked","conflict","unknown"]},"currentKey":{"type":"string","pattern":"^[0-9a-f]{64}$"},"since":{"type":"number"},"ageDays":{"type":"number"},"keyChanges":{"type":"number"},"revokedBy":{"type":"string","enum":["current","recovery"]},"reason":{"type":"string"}},"required":["status"]},"Issuer":{"type":"object","properties":{"issuer":{"type":"string","pattern":"^[0-9a-f]{64}$","description":"記録に署名した発行者の公開鍵"},"services":{"type":"array","items":{"type":"string"},"description":"記録の service タグ。発行者が名乗っているだけで、CIC は確かめていない"},"counts":{"type":"object","additionalProperties":{"type":"number"}},"firstIssuedAt":{"type":"number"},"lastIssuedAt":{"type":"number"},"records":{"type":"array","items":{"$ref":"#/components/schemas/Record"}}},"required":["issuer","services","counts","firstIssuedAt","lastIssuedAt","records"]},"Record":{"type":"object","properties":{"id":{"type":"string","pattern":"^[0-9a-f]{64}$"},"type":{"type":"string"},"service":{"type":"string"},"summary":{"type":"string"},"detailsHash":{"type":"string"},"period":{"type":"object","properties":{"from":{"type":"number"},"to":{"type":"number"}},"required":["from","to"]},"amount":{"type":"object","properties":{"value":{"type":"string"},"unit":{"type":"string"}},"required":["value","unit"]},"issuedAt":{"type":"number"},"expiresAt":{"type":"number"},"expired":{"type":"boolean"},"rebuttal":{"type":"object","properties":{"id":{"type":"string","pattern":"^[0-9a-f]{64}$"},"statement":{"type":"string"},"signedAt":{"type":"number"}},"required":["id","statement","signedAt"]}},"required":["id","type","summary","issuedAt","expired"]},"Problem":{"type":"object","properties":{"type":{"type":"string"},"title":{"type":"string"},"status":{"type":"number"},"detail":{"type":"string"},"instance":{"type":"string"}},"required":["type","title","status"]},"NostrEvent":{"type":"object","properties":{"id":{"type":"string","pattern":"^[0-9a-f]{64}$"},"pubkey":{"type":"string","pattern":"^[0-9a-f]{64}$"},"created_at":{"type":"number"},"kind":{"type":"number"},"tags":{"type":"array","items":{"type":"array","items":{"type":"string"}}},"content":{"type":"string"},"sig":{"type":"string"}},"required":["id","pubkey","created_at","kind","tags","content","sig"]},"ApiKey":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"key":{"type":"string","description":"発行したときに一度だけ返す"},"createdAt":{"type":"number"}},"required":["id","name","key","createdAt"]},"SubmitResult":{"type":"object","properties":{"accepted":{"type":"number"},"duplicates":{"type":"number"},"rejected":{"type":"array","items":{"type":"object","properties":{"index":{"type":"number"},"id":{"type":"string"},"reason":{"type":"string"}},"required":["index","reason"]}}},"required":["accepted","duplicates","rejected"]}},"parameters":{}},"paths":{"/api/v1/agent/{id}/report":{"get":{"operationId":"getReport","tags":["report"],"summary":"エージェントの与信レポートを返す","description":"公開リレーに出た鍵イベント、記録、反論から、ID の状態と、発行者ごとの記録を返す。スコアは付けない。どの発行者を信じるかは使う側が決める。記録がひとつもない AgentID には、identity.status が unknown のレポートを返す。","security":[{"bearer":[]}],"parameters":[{"schema":{"type":"string","pattern":"^[0-9a-f]{64}$","description":"AgentID。開始イベントに署名した最初の公開鍵"},"required":true,"description":"AgentID。開始イベントに署名した最初の公開鍵","name":"id","in":"path"}],"responses":{"200":{"description":"与信レポート","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreditReport"}}}},"400":{"description":"AgentID の形が不正","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"API キーが有効でない","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"この API キーでの問い合わせが多すぎる","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/agent/{id}/event":{"get":{"operationId":"listEvidence","tags":["report"],"summary":"レポートの根拠になったイベントを返す","description":"署名済みの元のイベントをそのまま返す。使う側は SDK などで自分で検証できる。","security":[{"bearer":[]}],"parameters":[{"schema":{"type":"string","pattern":"^[0-9a-f]{64}$","description":"AgentID。開始イベントに署名した最初の公開鍵"},"required":true,"description":"AgentID。開始イベントに署名した最初の公開鍵","name":"id","in":"path"}],"responses":{"200":{"description":"鍵イベント、記録、反論","content":{"application/json":{"schema":{"type":"object","properties":{"events":{"type":"array","items":{"$ref":"#/components/schemas/NostrEvent"}}},"required":["events"]}}}},"400":{"description":"AgentID の形が不正","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"API キーが有効でない","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"この API キーでの問い合わせが多すぎる","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/admin/api-key":{"post":{"operationId":"issueApiKey","tags":["admin"],"summary":"SaaS に API キーを発行する","description":"キーは応答で一度だけ返す。CIC にはハッシュしか残らない。","security":[{"bearer":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":100}},"required":["name"]}}}},"responses":{"201":{"description":"発行したキー","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKey"}}}},"400":{"description":"入力が不正","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"運営用のトークンが有効でない","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/admin/api-key/{id}":{"delete":{"operationId":"revokeApiKey","tags":["admin"],"summary":"API キーを失効させる","description":"失効させたキーでは、以後の問い合わせに 401 を返す。","security":[{"bearer":[]}],"parameters":[{"schema":{"type":"string","minLength":1},"required":true,"name":"id","in":"path"}],"responses":{"204":{"description":"失効させた"},"401":{"description":"運営用のトークンが有効でない","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"404":{"description":"有効なキーが見つからない","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/event":{"post":{"operationId":"submitEvents","tags":["submit"],"summary":"発行者から記録を直接受け取る","description":"署名済みの鍵イベント、規約同意、記録、反論をまとめて受け付ける。公開リレーは記録を保管してくれないので、発行者はリレーに出すのとあわせてここにも送る。API キーは要らず、送信元 IP ごとに回数を制限する。受け付けた記録は、記録を残すリレーにも写しを置く。","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"events":{"type":"array","items":{},"minItems":1,"maxItems":100}},"required":["events"]}}}},"responses":{"200":{"description":"受け付けた件数、重複、拒否したイベントと理由","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SubmitResult"}}}},"400":{"description":"入力が不正","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"この IP からの送信が多すぎる","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}}},"webhooks":{}}