OpenAgentID documentation
Source referencesRust module referenceoas-attestation

oas-attestation · sign

Declared module signatures, types, configuration, and source documentation.

Source: oas/oas/oas-attestation/src/sign.rs. SHA-256: 86ff420604f984017407bd53da44360939390bafb44649efcca0007c2c9bff30.

This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.

sign::sign_credential

Signs an OAS credential, producing a new credential with an attached proof.

Implements the Ed25519Signature2020 proof suite per OAS Specification §13.1:

  1. Validates the credential structure
  2. Serializes to JSON without the proof field
  3. Canonicalizes via JCS (RFC 8785)
  4. Signs the canonical bytes with Ed25519
  5. Encodes the signature as multibase base58btc (z prefix)

Arguments

  • credential - The unsigned credential to sign.
  • keypair - The issuer's Ed25519 keypair.
  • verification_method_id - Full ID of the verification method (e.g., "did:oas:test:hmr:auditor#key-1").
  • created - ISO 8601 timestamp for the proof.

Returns

A new [OasCredential] with the proof field populated.

Errors

Returns [AttestationError::ProofGenerationFailed] if canonicalization or signing fails. Returns other [AttestationError] variants if validation fails.

Examples

use oas_attestation::credential::OasCredential;
use oas_attestation::types::AttestationType;
use oas_attestation::sign::sign_credential;
use oas_crypto::keypair::OasKeyPair;

let keypair = OasKeyPair::generate();
let cred = OasCredential::builder()
    .issuer("did:oas:test:hmr:auditor")
    .subject_id("did:oas:test:agent:target")
    .issuance_date("2026-01-15T00:00:00Z")
    .subject_claim("auditType", serde_json::json!("codeAudit"))
    .subject_claim("result", serde_json::json!("pass"))
    .subject_claim("severityFindings", serde_json::json!({"critical": 0}))
    .subject_claim("toolOrMethodology", serde_json::json!("OWASP"))
    .subject_claim("auditDate", serde_json::json!("2026-01-15T00:00:00Z"))
    .attestation_type(AttestationType::SecurityAudit)
    .build()
    .unwrap();

let signed = sign_credential(
    &cred,
    &keypair,
    "did:oas:test:hmr:auditor#key-1",
    "2026-01-15T00:00:00Z",
);
assert!(signed.is_ok());
assert!(signed.unwrap().proof.is_some());
pub fn sign_credential(
    credential: &OasCredential,
    keypair: &OasKeyPair,
    verification_method_id: &str,
    created: &str,
) -> Result<OasCredential, AttestationError>;

Source line: 73.

On this page