API 참조
피어 GraphQL
페어링된 기기 간 서명 및 암호화된 요청입니다.
key = Base64Decode(peer.key)페어링된 피어; c-id = senderClientId
클라이언트
https://<host>:<port>/peer_graphql서버
POST /peer_graphql
c-id: 706c6169-3b80-8f42-9a61-4e312e54d001
HTTP · binary
Ed25519 · PEER_REQUEST
signed = compactJSON(["PEER_REQUEST", channelId, requestId, query, sortedVariables])signature = Base64(Ed25519-Sign(senderPrivateKey, signed))channelId는 배열의 두 번째 값입니다. 직접 피어 요청에서는 비어 있으며 그 외에는 c-cid 채널 ID와 정확히 일치합니다. 서명을 계산할 때 variables 내부의 객체 키를 재귀적으로 정렬합니다.JSON({ signature, requestId, query, variables })
요청을 실행하기 전에 기기의 서명을 검증합니다. UUIDv7 유효 시간은 ±60초이며 중복은 영구적으로 제거됩니다.
XChaCha20-Poly1305 · 필드에 마우스를 올리거나 탭하세요
재전송 공격 방지
requestId = UUIDv7()JSON { signature, requestId, query, variables } → authenticated encryption인증 및 복호화
↓peer.key / channel.key + Ed25519✕ → 거부UUIDv7 시간 검증
↓|serverTime − requestId timestamp| ≤ 60 s✕ → 거부실행 전에 requestId 기록
SQLite: peer_graphql:channelId + senderClientId + requestId✓ ↓GraphQL 실행
✕ ↓재사용된 requestId 거부
라이브러리 호출
Core 발췌이며 직접 연결된 페어링 피어 모드(c-cid 없음)입니다.
text
// plain-rs/src/infrastructure/transport/contract.rs
let payload = contract::signed_request(&signing_keypair, query, variables, "")?;
let request_body = http_request::encrypt_raw(
&peer_key, "POST", "/peer_graphql", payload.as_bytes(),
).ok_or("encrypt failed")?;
let response = transport.post(url, &client_id, None, &request_body).await?;
let plaintext = http_response::Context::new(&request_body)
.decrypt(&peer_key, &response).ok_or("invalid response")?;HTTP 403: 페어링되지 않은 피어. 401: 알 수 없는 피어, 복호화 또는 서명 검증 실패. 400: 형식이 잘못되거나 만료 또는 중복된 봉투.
타입 정의
graphql
enum ChannelSystemMessageType {
INVITE
INVITE_ACCEPT
INVITE_DECLINE
UPDATE
KICK
LEAVE
}
type ChatAttachment {
id: ID!
uri: String!
size: Long!
durationMs: Long!
width: Int!
height: Int!
summary: String!
fileName: String!
}
enum ChatAttachmentType {
IMAGE
FILE
}
union ChatContent = ChatMessageContent | ChatShareContent
type ChatDeliveryResult {
peerId: ID!
peerName: String!
error: String
}
type ChatItem {
"""
`me` when this device created the item, otherwise the client id of
the originating peer.
"""
fromId: ID!
"""
Peer id for direct messages; empty for channel messages —
`channelId` is authoritative there.
"""
toId: ID!
"""
Null for direct messages: the store keeps "" and the contract says
null, because "" is not a channel a client can query.
"""
channelId: ID
id: ID!
content: ChatContent!
createdAt: Instant!
updatedAt: Instant!
status: ChatStatus!
deliveryResults: [ChatDeliveryResult!]!
}
type ChatLinkPreview {
url: String!
title: String
description: String
image: String
imageWidth: Int!
imageHeight: Int!
siteName: String
domain: String
createdAt: Instant!
}
type ChatMessageAttachment {
type: ChatAttachmentType!
attachment: ChatAttachment!
}
type ChatMessageContent {
text: String
format: ChatTextFormat!
items: [ChatMessageAttachment!]!
linkPreviews: [ChatLinkPreview!]!
}
type ChatShareContent {
shareId: ID!
urlToken: String!
peerInfo: ChatSharePeer!
name: String!
itemCount: Long!
totalSize: Long!
expiresAt: Instant
}
type ChatSharePeer {
id: ID!
ip: String!
port: Int!
}
enum ChatStatus {
SENT
FAILED
PARTIAL
PENDING
}
enum ChatTextFormat {
PLAIN
MARKDOWN
}
scalar Instant
scalar Long
type Mutation {
createChatItem(content: String!): [ChatItem!]!
channelSystemMessage(type: ChannelSystemMessageType!, payload: String!): Boolean!
startAware: Boolean!
}
enum PeerStatus {
PAIRED
UNPAIRED
CHANNEL
}
type Query {
}
"""
Directs the executor to include this field or fragment only when the `if` argument is true.
"""
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"""
Directs the executor to skip this field or fragment when the `if` argument is true.
"""
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
schema {
query: Query
mutation: Mutation
}