anp

package module
v0.8.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ANP Go SDK

Pure Go implementation of the Agent Network Protocol (ANP) core SDK.

Status

Implemented in this directory:

  • authentication
    • DID WBA document generation
    • legacy DIDWba auth header generation and verification
    • HTTP Message Signatures generation and verification
    • DID resolver for did:wba and did:web
    • request verifier with bearer token issuance
    • federated request verification helpers
  • proof
    • W3C Data Integrity proof generation and verification
    • strict Appendix-B object proof helpers
    • group receipt proof helpers
    • did:wba binding proof helpers
    • IM proof helpers
    • RFC 9421 origin proof helpers for ANP request objects
  • wns
    • handle validation and URI parsing
    • handle resolution
    • handle binding verification
  • direct_e2ee
    • prekey bundle helpers
    • X3DH-derived initial session setup
    • symmetric ratchet step derivation
    • direct init / cipher message processing
    • file-backed stores and reference client helpers

Compatibility

  • Pure Go only
  • No cgo
  • Go 1.22+

Module Path

go get github.com/agent-network-protocol/anp/golang

Quick Start

Generate a DID document
package main

import (
  "fmt"
  "github.com/agent-network-protocol/anp/golang/authentication"
)

func main() {
  bundle, err := authentication.CreateDidWBADocument(
    "example.com",
    authentication.DidDocumentOptions{PathSegments: []string{"user", "alice"}},
  )
  if err != nil {
    panic(err)
  }
  fmt.Println(bundle.DidDocument["id"])
}
Create HTTP signature headers
privateKey, _ := anp.PrivateKeyFromPEM(bundle.Keys[authentication.VMKeyAuth].PrivateKeyPEM)
headers, err := authentication.GenerateHTTPSignatureHeaders(
  bundle.DidDocument,
  "https://api.example.com/orders",
  "POST",
  privateKey,
  map[string]string{"Content-Type": "application/json"},
  []byte(`{"item":"book"}`),
  authentication.HttpSignatureOptions{},
)

Examples

  • examples/create_did_document
  • examples/direct_e2ee
  • examples/proof
  • examples/wns

Docs

  • docs/api.md
  • docs/direct_e2ee-guide.md
  • docs/release-notes.md

Test

go test ./...

Documentation

Overview

Package anp provides shared key material helpers used by the ANP Go SDK.

Index

Constants

View Source
const Version = "0.8.7"

Version is the coordinated ANP SDK release number for the Go package.

Variables

This section is empty.

Functions

func DecodeBase64

func DecodeBase64(value string) ([]byte, error)

DecodeBase64 decodes standard base64.

func DecodeBase64URL

func DecodeBase64URL(value string) ([]byte, error)

DecodeBase64URL decodes raw URL-safe base64.

func EncodeBase64

func EncodeBase64(value []byte) string

EncodeBase64 encodes bytes using standard base64.

func EncodeBase64URL

func EncodeBase64URL(value []byte) string

EncodeBase64URL encodes bytes using raw URL-safe base64.

func GenerateKeyPairPEM

func GenerateKeyPairPEM(keyType KeyType) (PrivateKeyMaterial, PublicKeyMaterial, GeneratedKeyPairPEM, error)

GenerateKeyPairPEM returns a generated ANP key pair in raw and PEM forms.

func PublicKeyToJWK

func PublicKeyToJWK(publicKey PublicKeyMaterial) (map[string]any, error)

PublicKeyToJWK converts a public key to JWK fields used by ANP helpers.

Types

type GeneratedKeyPairPEM

type GeneratedKeyPairPEM struct {
	PrivateKeyPEM string `json:"private_key_pem"`
	PublicKeyPEM  string `json:"public_key_pem"`
}

GeneratedKeyPairPEM stores standard PKCS#8/SPKI PEM encodings for a key pair.

type KeyMaterialError

type KeyMaterialError struct {
	Message string
}

KeyMaterialError reports invalid or unsupported key material operations.

func (*KeyMaterialError) Error

func (e *KeyMaterialError) Error() string

Error implements error.

type KeyType

type KeyType string

KeyType identifies the supported ANP key algorithms.

const (
	KeyTypeSecp256k1 KeyType = "secp256k1"
	KeyTypeSecp256r1 KeyType = "secp256r1"
	KeyTypeEd25519   KeyType = "ed25519"
	KeyTypeX25519    KeyType = "x25519"
)

type PrivateKeyMaterial

type PrivateKeyMaterial struct {
	Type  KeyType `json:"type"`
	Bytes []byte  `json:"bytes"`
}

PrivateKeyMaterial stores an ANP private key in raw form.

func GeneratePrivateKeyMaterial

func GeneratePrivateKeyMaterial(keyType KeyType) (PrivateKeyMaterial, error)

GeneratePrivateKeyMaterial generates a new private key for the requested type.

func PrivateKeyFromPEM

func PrivateKeyFromPEM(input string) (PrivateKeyMaterial, error)

PrivateKeyFromPEM decodes a standard PKCS#8 private key PEM.

func (PrivateKeyMaterial) PublicKey

func (k PrivateKeyMaterial) PublicKey() (PublicKeyMaterial, error)

PublicKey derives the matching public key.

func (PrivateKeyMaterial) SignMessage

func (k PrivateKeyMaterial) SignMessage(message []byte) ([]byte, error)

SignMessage signs a message using ANP's cross-language conventions.

func (PrivateKeyMaterial) ToPEM

func (k PrivateKeyMaterial) ToPEM() string

ToPEM encodes the private key as standard PKCS#8 PEM.

type PublicKeyMaterial

type PublicKeyMaterial struct {
	Type  KeyType `json:"type"`
	Bytes []byte  `json:"bytes"`
}

PublicKeyMaterial stores an ANP public key in raw form.

func PublicKeyFromJWK

func PublicKeyFromJWK(jwk map[string]any) (PublicKeyMaterial, error)

PublicKeyFromJWK converts JWK fields to ANP public key material.

func PublicKeyFromPEM

func PublicKeyFromPEM(input string) (PublicKeyMaterial, error)

PublicKeyFromPEM decodes a standard SubjectPublicKeyInfo public key PEM.

func (PublicKeyMaterial) ToPEM

func (k PublicKeyMaterial) ToPEM() string

ToPEM encodes the public key as standard SubjectPublicKeyInfo PEM.

func (PublicKeyMaterial) VerifyMessage

func (k PublicKeyMaterial) VerifyMessage(message []byte, signature []byte) error

VerifyMessage verifies a signature using ANP's cross-language conventions.

Directories

Path Synopsis
cmd
anp-interop command
examples
direct_e2ee command
proof command
wns command
internal
vm

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL