AgentCardSigner¶
The AgentCardSigner class provides methods for signing A2A Agent Cards using Sigstore's keyless signing infrastructure.
Overview¶
from sigstore_a2a import AgentCardSigner
# Create a signer with default settings
signer = AgentCardSigner()
# Sign an agent card
signed_card = signer.sign_agent_card("agent-card.json")
API Reference¶
AgentCardSigner
¶
AgentCardSigner(
identity_token: str | None = None,
trust_config: Path | None = None,
staging: bool = False,
client_id: str | None = None,
client_secret: str | None = None,
use_ambient_credentials: bool = False,
verbose: bool = False,
)
Signs A2A Agent Cards using Sigstore keyless signing.
Initialize the Agent Card signer.
| PARAMETER | DESCRIPTION |
|---|---|
identity_token
|
Pre-obtained identity token
TYPE:
|
staging
|
Use Sigstore staging environment
TYPE:
|
Source code in sigstore_a2a/signer.py
sign_agent_card
¶
sign_agent_card(
agent_card: AgentCard | dict[str, Any] | str | Path,
provenance_bundle: SLSAProvenance | None = None,
) -> SignedAgentCard
Sign an A2A Agent Card.
| PARAMETER | DESCRIPTION |
|---|---|
agent_card
|
Agent card to sign (model, dict, JSON string, or file path)
TYPE:
|
provenance_bundle
|
Optional SLSA provenance bundle
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SignedAgentCard
|
Signed Agent Card with verification material |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If agent card is invalid |
RuntimeError
|
If signing fails |
Source code in sigstore_a2a/signer.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
sign_file
¶
sign_file(
input_path: str | Path,
output_path: str | Path | None = None,
provenance_bundle: SLSAProvenance | None = None,
) -> Path
Sign an Agent Card file.
| PARAMETER | DESCRIPTION |
|---|---|
input_path
|
Path to Agent Card JSON file
TYPE:
|
output_path
|
Output path for signed card (default: input_path with .signed.json)
TYPE:
|
provenance_bundle
|
Optional SLSA provenance bundle
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to signed Agent Card file |
Source code in sigstore_a2a/signer.py
Usage Examples¶
Basic Signing¶
from sigstore_a2a import AgentCardSigner
signer = AgentCardSigner()
# Sign from a file path
signed_card = signer.sign_agent_card("agent-card.json")
# Sign from a dictionary
card_data = {
"name": "My Agent",
"url": "https://agent.example.com",
"protocolVersion": "0.2.9"
}
signed_card = signer.sign_agent_card(card_data)
Using Ambient Credentials (CI/CD)¶
signer = AgentCardSigner(use_ambient_credentials=True)
signed_card = signer.sign_agent_card("agent-card.json")
Using a Pre-obtained Identity Token¶
import os
signer = AgentCardSigner(
identity_token=os.environ.get("OIDC_TOKEN")
)
signed_card = signer.sign_agent_card("agent-card.json")
Using Staging Environment¶
Using Custom Trust Configuration¶
from pathlib import Path
signer = AgentCardSigner(
trust_config=Path("/path/to/trust-config.json")
)
signed_card = signer.sign_agent_card("agent-card.json")
Signing with Provenance¶
from sigstore_a2a import AgentCardSigner, ProvenanceBuilder
# Build provenance
provenance = ProvenanceBuilder().from_github_actions().build()
# Sign with provenance
signer = AgentCardSigner()
signed_card = signer.sign_agent_card(
"agent-card.json",
provenance_bundle=provenance
)
Saving Signed Cards¶
import json
signer = AgentCardSigner()
signed_card = signer.sign_agent_card("agent-card.json")
# Save to file
with open("signed-card.json", "w") as f:
json.dump(signed_card.model_dump(by_alias=True), f, indent=2)
# Or use sign_file for convenience
output_path = signer.sign_file(
"agent-card.json",
output_path="signed-card.json"
)