Skip to content

Repository files navigation

English | 中文

peerclaw-core

License

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.

Installation

go get github.com/peerclaw/peerclaw-core

Package Overview

PackageDescription
identityEd25519 key pair generation, loading, and saving; message signing and verification; X25519 key derivation
envelopeUnified message envelope Envelope, a cross-protocol common message format with encryption flag support
agentcardAgent Card definition (compatible with the A2A standard + PeerClaw extensions), including structured capability declarations for Skills / Tools
protocolProtocol (A2A / ACP / MCP) and transport method constants
signalingWebRTC signaling message types (offer / answer / ICE candidate / config / bridge_message), ICE Server configuration, X25519 key exchange
errorsStructured error handling with machine-readable codes (not_found, validation_error, auth_error, conflict, internal_error, timeout, rate_limited)
contactsContact request types and status definitions (pending / approved / rejected)

Quick Examples

Generate a Key Pair

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())
}

Signing and Verification

data:= []byte("hello peerclaw")
sig:=identity.Sign(kp.PrivateKey, data)
err:=identity.Verify(kp.PublicKey, data, sig)
// err == nil means the signature is valid

X25519 Key Derivation

Derive 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)

Create a Message Envelope

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"

Dependencies

Only depends on github.com/google/uuid -- kept minimal by design.

License

Licensed under the Apache License 2.0.

Copyright 2025 PeerClaw Contributors.

About

PeerClaw Core — shared types library for identity (Ed25519), envelope, agent card, protocol constants

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages