English | 中文
The core shared type library for the PeerClaw identity & trust platform. Defines identity, message envelopes, Agent Card, protocol constants, and signaling types -- zero heavy dependencies, shared by both peerclaw-server and peerclaw-agent.
go get github.com/peerclaw/peerclaw-core| Package | Description |
|---|---|
identity | Ed25519 key pair generation, loading, and saving; message signing and verification; X25519 key derivation |
envelope | Unified message envelope Envelope, a cross-protocol common message format with encryption flag support |
agentcard | Agent Card definition (compatible with the A2A standard + PeerClaw extensions), including structured capability declarations for Skills / Tools |
protocol | Protocol (A2A / ACP / MCP) and transport method constants |
signaling | WebRTC signaling message types (offer / answer / ICE candidate / config / bridge_message), ICE Server configuration, X25519 key exchange |
errors | Structured error handling with machine-readable codes (not_found, validation_error, auth_error, conflict, internal_error, timeout, rate_limited) |
contacts | Contact request types and status definitions (pending / approved / rejected) |
package main
import (
"fmt""github.com/peerclaw/peerclaw-core/identity"
)
funcmain() {
kp, _:=identity.GenerateKeypair()
fmt.Println("Public Key:", kp.PublicKeyString())
// Persist to fileidentity.SaveKeypair(kp, "agent.key")
// Load from filekp2, _:=identity.LoadKeypair("agent.key")
fmt.Println("Loaded: ", kp2.PublicKeyString())
}data:= []byte("hello peerclaw")
sig:=identity.Sign(kp.PrivateKey, data)
err:=identity.Verify(kp.PublicKey, data, sig)
// err == nil means the signature is validDerive X25519 keys from an Ed25519 key pair for ECDH key exchange and end-to-end encryption:
x25519Priv, _:=kp.X25519PrivateKey()
x25519Pub, _:=kp.X25519PublicKey()
// Serialize to hex stringpubHex:=kp.X25519PublicKeyString()
// Parse from hexparsedPub, _:=identity.ParseX25519PublicKey(pubHex)import (
"github.com/peerclaw/peerclaw-core/envelope""github.com/peerclaw/peerclaw-core/protocol"
)
env:=envelope.New("agent-alice", "agent-bob", protocol.ProtocolA2A, []byte(`{"text":"hi"}`))
env.WithTTL(30).WithMetadata("priority", "high")
// Mark the message as encryptedenv.Encrypted=trueenv.SenderX25519="hex-encoded-x25519-public-key"Only depends on github.com/google/uuid -- kept minimal by design.
Licensed under the Apache License 2.0.
Copyright 2025 PeerClaw Contributors.