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
}