Sigill.Sdk.Policy 0.16.1

dotnet add package Sigill.Sdk.Policy --version 0.16.1
                    
NuGet\Install-Package Sigill.Sdk.Policy -Version 0.16.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sigill.Sdk.Policy" Version="0.16.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sigill.Sdk.Policy" Version="0.16.1" />
                    
Directory.Packages.props
<PackageReference Include="Sigill.Sdk.Policy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sigill.Sdk.Policy --version 0.16.1
                    
#r "nuget: Sigill.Sdk.Policy, 0.16.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sigill.Sdk.Policy@0.16.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sigill.Sdk.Policy&version=0.16.1
                    
Install as a Cake Addin
#tool nuget:?package=Sigill.Sdk.Policy&version=0.16.1
                    
Install as a Cake Tool

Sigill.Sdk (.NET)

NuGet License

Tamper-evident AI evidence envelopes for .NET. Build an AiEvidenceEnvelopeV1 record of any AI generation, seal it with an RFC 3161 timestamp via Sigill, and verify it offline at any later point.

The cryptographic primitives — RFC 8785 canonical JSON, SHA-256 hash binding, RFC 3161 timestamp parsing — are all handled inside the SDK. Your application hands it a prompt, response, and metadata; gets back a sealed envelope. Apps don't need to implement canonicalization, hash binding, or timestamp protocol logic themselves.

For the underlying spec — what's in an envelope, what gets hashed in what order, what "valid" means — see spec/README.md. The same spec ships in this repo's sibling: the Python SDK at sigill-python. Identical test vectors, byte-compatible output.

Install

dotnet add package Sigill.Sdk

Targets net8.0, net9.0, and netstandard2.1. Single dependency on System.Security.Cryptography.Pkcs for RFC 3161 token parsing — built into the runtime since .NET Core 2.1.

30-second example

using Sigill.Sdk;

await using var client = new SigillClient(apiKey: "sigill_..."); // Settings → API Keys at sigill.ai

var envelope = new EnvelopeBuilder()
    .WithPurpose(category: "summarization", businessContext: "support-ticket-summary")
    .WithActor(type: "service", id: "svc-support-summarizer", tenantId: "tenant-acme")
    .WithActivity(name: "ticket.summarize", correlationId: "trace-abc-123")
    .WithModel(provider: "anthropic", name: "claude-opus-4-7",
               parameters: new JsonObject { ["max_tokens"] = 1024, ["temperature"] = 0.2 })
    .WithPromptInline("Summarize the following support ticket in three bullet points.")
    .WithOutputInline("Customer reports login fails after password reset.")
    .Build();

SealedAiEvidenceEnvelope sealed_ = await client.SealAsync(envelope);
// sealed_.EnvelopeHashHex                ← SHA-256 of canonical JSON
// sealed_.Json["proofs"]![0]!["tsrBase64"] ← RFC 3161 timestamp from Sigill

// ...persist sealed_.Json somewhere durable...

// Later — re-verify cryptographically. Anyone with the sealed envelope can do this:
AiEvidenceVerificationResult result = await client.VerifyAsync(sealed_);
Debug.Assert(result.IsValid);
Console.WriteLine($"Stamped at {result.Timestamps[0].GenTime} by {result.Timestamps[0].TsaName}");

That's the whole hot path. Everything below is detail you only reach for when you need it.

Keeping PII out of the envelope

For sensitive prompts and responses, store hash references in the envelope instead of the content itself. The SDK hashes the bytes you supply, records the hash in the envelope, and the original bytes are yours to keep, redact, or delete.

var promptBytes = Encoding.UTF8.GetBytes(
    "Classify identity doc. Subject: Jane Doe, born 1985-03-14.");
var responseBytes = Encoding.UTF8.GetBytes(
    """{"document_type":"passport","confidence":0.97}""");

var envelope = new EnvelopeBuilder()
    .WithPurpose(category: "classification",
                 regulatoryBasis: new[] { "EU-AI-Act:Annex-III" })
    .WithActor(type: "user", id: "user-9b2f1a", tenantId: "tenant-acme")
    .WithActivity(name: "kyc.classify")
    .WithModel(provider: "anthropic", name: "claude-opus-4-7")
    .WithPromptRef("prompt", contentType: "text/plain")
    .WithOutputRef("output", contentType: "application/json")
    .WithPolicyMetadata(new JsonObject
    {
        ["redactionApplied"] = true,
        ["redactionPolicy"] = "pii-redaction-v3",
    })
    .Build();

var sealed_ = await client.SealAsync(envelope, externalPayloads: new()
{
    ["prompt"] = promptBytes,
    ["output"] = responseBytes,
});
// The envelope now contains SHA-256("prompt bytes") and SHA-256("response bytes")
// under prompt.hash and output.hash. The bytes themselves are NOT stored.

When you later need to audit, supply the bytes again — verify confirms they hash to the same registered values:

var result = await client.VerifyAsync(sealed_, new()
{
    ["prompt"] = promptBytes,
    ["output"] = responseBytes,
});
Debug.Assert(result.IsValid);

If the bytes have been deleted or modified, verification reports exactly which ref is missing or wrong:

var result = await client.VerifyAsync(sealed_,
    new() { ["prompt"] = promptBytes }); // 'output' deliberately omitted
// result.IsValid       -> false
// result.Issues[0].Kind   -> VerificationIssueKind.HashMismatch
// result.Issues[0].Target -> "output"
// result.Issues[0].Message -> "payload_not_supplied: external bytes for ref 'output' …"

CAdES document sealing

For workflows where you need to cryptographically seal a specific file or JSON blob (not a full AI evidence envelope), the SDK supports CAdES detached signatures (.p7s). This is the right choice when you want a compact, verifiable proof that a particular document was sealed by a named Sigill certificate at a specific moment.

using Sigill.Sdk;

// Obtain a certificate ID from the Sigill dashboard (Settings → Certificates).
var certId = Guid.Parse("5f498b84-65e2-404c-8791-65d70e3f385b");

var document = """{"decision": "approved", "amount": 42000}"""u8.ToArray();

// Seal: only the SHA-256 hash of the document is sent to Sigill — the document
// itself never leaves your system.
byte[] p7s = await client.SealCadesAsync(document, certId, label: "decision.json");

// p7s is a standard PKCS#7 / CMS detached signature (.p7s). Store it alongside
// the document — you need both to verify later.

// Verify: again, only the hash is transmitted — the document stays local.
CadesVerifyResult result = await client.VerifyCadesAsync(document, p7s);

Debug.Assert(result.IsValid);
Console.WriteLine(result.Signer);   // CN=Sigill Platform Seal, O=SIGILL AS, …
Console.WriteLine(result.Trust);    // "trusted_chain"
Console.WriteLine(result.GenTime);  // "2026-06-25T16:49:04Z"

Post-quantum (hybrid) sealing

Pass pqc: true to add a post-quantum ML-DSA-87 (FIPS 204) signer alongside the classical one — a single .p7s with two independently-verifiable signatures (RFC 5652 §5.1 + RFC 9882). Content still never leaves your system (only SHA-256 and SHA-512 digests are sent).

byte[] p7s = await client.SealCadesAsync(document, certId, label: "decision.json", pqc: true);

CadesVerifyResult result = await client.VerifyCadesAsync(document, p7s);
Debug.Assert(result.IsValid);                     // classical signer — the legal instrument
if (result.PostQuantum is { } pqc)
{
    Console.WriteLine(pqc.Algorithm);             // "ml-dsa-87"
    Console.WriteLine(pqc.SignatureValid);        // true
    Console.WriteLine(pqc.ContentBound);          // "yes"
    Console.WriteLine(pqc.Trusted);               // "not_evaluated" (self-signed platform cert)
}

IsValid reflects the classical signer only — the post-quantum signer is additive (quantum-resistant protection, not a qualified/legal upgrade), and is reported separately via result.PostQuantum.

CadesVerifyResult properties:

Property Type Meaning
IsValid bool HashMatch && SignatureValid && Error is null
HashMatch bool Document hash matches the value embedded in the .p7s
SignatureValid bool RSA/ECDSA signature over signed attributes is valid
Signer string? Subject DN of the signing certificate
Trust string? "trusted_chain", "self_signed", "dev_ca", …
TsaName string? TSA that issued the embedded timestamp
GenTime string? Timestamp generation time (ISO 8601)
Qualified bool Whether the embedded timestamp is eIDAS-qualified
Error string? Set when IsValid is false
Warnings IReadOnlyList<string> Non-fatal issues found during verification

If you also hold an external .tsr file (e.g. from a separate timestamping step), pass it as tsr::

var result = await client.VerifyCadesAsync(document, p7s, tsr: tsrBytes);

JAdES sealing for JSON

For JSON and JSONL content — API payloads, agent logs, AI evidence — prefer JAdES (ETSI TS 119 182-1), the ETSI signature format for JSON. Same detached, hash-only model as CAdES: only digests are transmitted, and the returned .jades.json artifact verifies against the exact original bytes (re-serializing the JSON breaks it by design).

var log = File.ReadAllBytes("agent-log.json");

byte[] jades = await client.SealJadesAsync(log, certId,
    label: "agent-log.json", contentType: "application/json");
// store agent-log.json.jades.json alongside the log

JadesVerifyResult result = await client.VerifyJadesAsync(log, jades);
Debug.Assert(result.IsValid);

pqc: true works here too — the ML-DSA-87 signer is added as a second JWS signatures[] entry (RFC 9964). JadesVerifyResult has the same fields as CadesVerifyResult.

To seal an AI evidence envelope with a JAdES organisation seal in addition to its RFC 3161 proof, sign the canonical bytes:

var sealed_ = await client.SealAsync(input, payloads);
byte[] canonical = EnvelopeHashing.Canonicalize(sealed_.Json);  // full sealed envelope, proofs included
byte[] jades = await client.SealJadesAsync(canonical, certId,
    label: "envelope.jades.json", contentType: "application/json");

Object references (AiEvidenceEnvelopeV2 v2.1)

ETSI TS 119 182-1 §5.2.8.3.1 requires each sigD.pars entry to resolve to a locator, so object URIs are relative references: when you omit Uri, the SDK generates objects/<uuid>, and a Uri you set must match the production profile (segments of A–Z a–z 0–9 . _ ~ - separated by /; no urn:, no URLs, no filenames with personal data). sigill-envelope.json and urn:sigill:envelope are reserved for the envelope.

Verification reads both envelope references — sigill-envelope.json and the urn:sigill:envelope of seals made before v2.1 — from each signature itself, so old evidence and runs that straddle an upgrade keep verifying. To show the form, classify the signed reference:

EnvelopeReferenceForm form = EnvelopeReferences.Classify(signedPars0);
if (form == EnvelopeReferenceForm.LegacyUrn)
    Console.WriteLine(EnvelopeReferences.LegacyDiagnostic); // informational, never a failure

PAdES PDF sealing — the PDF never leaves your machine

For PDFs, the SDK produces an embedded PAdES signature (ETSI EN 319 142-1) without uploading the document. It assembles the PDF signature revision locally, sends Sigill only the ByteRange SHA-256 digest, embeds the returned CMS, and — when the certificate chain supports it — upgrades the seal to B-LT/B-LTA by writing the Document Security Store and a document timestamp, all locally.

var pdf = await File.ReadAllBytesAsync("contract.pdf");

PadesSealResult result = await client.SealPadesAsync(pdf, certId, new PadesSealOptions
{
    Label = "contract.pdf",
    Qualified = false,             // true → eIDAS-qualified timestamps throughout
    SignerName = "ACME Corp AS",   // recommended: your seal cert's subject CN —
                                   // lands in /Name, what Acrobat shows before
                                   // validation runs (otherwise "Unknown")
    Reason = "Approved",           // optional, lands in the PDF /Reason field
});

await File.WriteAllBytesAsync("contract_sealed.pdf", result.SealedPdf);
Console.WriteLine(result.Format);          // "pades-b-lta" | "pades-b-lt" | "pades-b-t" | "pades-bes"
Console.WriteLine(result.TimestampedBy);   // TSA name, or null if no timestamp could be embedded

The sealed PDF validates like any server-produced PAdES seal (Adobe, DSS, POST /seal/verify). Verification requires the PDF and stays server-side.

Unsupported PDFs and the upload fallback

The local parser handles xref-table PDFs, xref-stream PDFs (PDF 1.5+), and FlateDecode object streams. When it cannot handle a document's structure, SealPadesAsync throws SigillPdfUnsupportedException before anything is transmitted — with the default settings the privacy guarantee is absolute: nothing but digests ever leaves your machine.

If your data policy permits it, opt in to the server-side fallback and such documents are sealed by uploading them to POST /seal/sign instead (identical PAdES output, but the PDF is transmitted to Sigill):

var result = await client.SealPadesAsync(pdf, certId, new PadesSealOptions
{
    AllowUploadFallback = true,   // default false
});

Post-quantum hybrid sealing is not offered for PAdES — the baseline profile allows a single SignerInfo per signature. For an ML-DSA-87 hybrid seal over a PDF, use SealCadesAsync(pdf, certId, pqc: true) and keep the detached .p7s alongside the file.

Crash-safe sealing: the two-phase flow

SealPadesAsync prepares, signs, and embeds in one call. If your pipeline can die between the server signing (the seal is minted and billed) and your process persisting the result, use the two-phase flow with the tenant's Store PAdES seal data setting (Settings → Preferences, off by default):

PreparedPadesPdf checkpoint = client.PreparePades(pdf);
Save(checkpoint.Bytes);                       // your checkpoint — plain bytes

var result = await client.SealPreparedPadesAsync(checkpoint.Bytes, certId);
// ... process dies before result.SealedPdf was persisted? Resume later:

byte[]? cms = await client.GetSealCmsAsync(operationId);  // escrowed CMS
byte[] sealed = SigillClient.CompletePades(Load(), cms!); // offline recovery

CompletePades needs no network and recovers a valid sealed PDF at the level the CMS carries — B-T when the signature timestamp succeeded, else B-BES. LTV material (the DSS and the archival DocTimeStamp that Ltv = true would have appended) is not reconstructed on the resume path: with Ltv = false the recovery is byte-identical to the uninterrupted flow; with the default LTV ladder it recovers the B-T seal, and B-LT/B-LTA can be reached later by re-sealing. Without the escrow setting, a signing response lost before embedding cannot be recovered at all.

Evidence lifecycle: tags, CI gates, and audit packages

Every seal and stamp is an evidence in the Sigill evidence store — with a renewal horizon, verification history, and a custody log. The SDK exposes the lifecycle surface an automated caller needs:

// Tag at creation — the grouping/filter dimension of the evidence store
// (≤10 per evidence, ≤40 chars). Available on every seal method.
await client.SealCadesAsync(artifact, certId, tags: new[] { "release-4.2", "backend" });

// CI gate: does evidence exist, and how close is the renewal horizon?
EvidenceRecord? rec = await client.GetEvidenceRecordAsync(artifact);
if (rec is null) throw new Exception("artifact was never sealed");
Console.WriteLine(rec.CertNotAfter);   // the horizon — fail the build when too close

// Public existence check (no API key needed) — consent-gated: null unless the
// evidence owner opted in to public lookups. Third-party release verification.
PublicLookupResult? found = await client.LookupAsync(artifact);

// Everything an auditor needs, independently verifiable offline:
// tokens, certificates, verification report, custody log, SHA-256 manifest.
byte[] zip = await client.ExportAuditPackageAsync(rec.TransactionId);

Expiry-reminder policy can be set per evidence at creation on every seal method: reminders: "on" (with reminderDays: 30/60/90/180), "off" (muted), or the default "inherit".

Agent runs: verifiable multi-step execution

For agents that call tools, retrieve context and act over several steps, a single envelope is not enough: you need to show which controls applied before the run, which security-relevant events were captured and in what order, and that nothing captured was changed or removed afterwards. Three sibling profiles of the v2 envelope (common rules) cover one controlled run:

Phase Profile What it seals
Before Control Artifact configuration, control set, baseline, timestamp policy
During Execution Evidence one artifact per event, chained by signature
During Model Calls (execution schemaVersion "3") per model call: the model that served it and the provider's own ids for the call, so the provider can confirm it against its logs; prompts and responses as digests only
During Enforcement (execution schemaVersion "4") the guard's denials and halts before the action, recomputable from the policy control set v2
After Control Evaluation, v2 what an independent verifier observed, and each control's result; v2 adds policy evaluations (reproducible from the run's facts) and the producer's own attested results

To record model calls, start the run with RecordsModelCalls = true and put ModelCallHandler under any provider client that accepts an HttpClient (Anthropic, OpenAI, Azure OpenAI, Amazon Bedrock, Gemini API, Vertex AI). Values come from the provider's response; for any other provider call RecordModelCallAsync.

var http = new HttpClient(new ModelCallHandler(run, new HttpClientHandler()));

Conversations with hosted assistants recorded on the user's side (the Sigill browser extension) use the same profiles under the client-observed conventions.

var agent = new AgentDefinition
{
    AgentId = "urn:example:agent:support-triage",   // opaque — no personal data
    AgentVersion = "2.4.0",
    Configuration = new AgentConfiguration
    {
        InstructionSet  = systemPromptBytes,
        ToolManifest    = toolSchemasJson,
        ExecutionPolicy = allowlistAndLimitsJson,
        ModelConfig     = modelAndSamplingJson,
    },
};

// Seals the Control Artifact (timestamped), then run_start, which binds it.
var run = await client.StartAgentRunAsync(agent, new AgentRunOptions
{
    CertificateId = certId,
    Activity = "support-ticket-close",
    ControlSet = new AgentControlSet { Id = "ticket-close-v2", Version = "2", Content = controlSetJson },
    BaselineState = ticketBeforeJson,      // what "unchanged" controls are checked against
});

await run.RecordToolCallAsync("lookup_ticket", argsJson, operation: "read", useId: "call-1");
await run.RecordToolResultAsync("lookup_ticket", resultJson, useId: "call-1");

// A write that needs a human: the policy decision, the approval, then the call.
await run.RecordAuthorizationAsync(new AgentAuthorization
    { Decision = "allow_with_human_approval", PolicyId = "support-tools-v1" });
await run.RecordHumanApprovalAsync("approved",
    receipt: approvalReceiptJson,          // bound by digest; bytes stay with you
    identityAssertion: approverIdToken,    // e.g. the IdP token of the approver
    approver: "urn:example:approver:42");  // opaque — never a name or e-mail
await run.RecordToolCallAsync("close_ticket", argsJson, operation: "write", consequential: true);

await run.RecordModelOutputAsync(answerBytes);
AgentRunBundle bundle = await run.FinishAsync("completed");   // run_end, timestamped

An independent verifier then reads the target's state and seals its evaluation, with its own certificate:

var evaluation = await verifierClient.SealControlEvaluationAsync(new ControlEvaluationRequest
{
    CertificateId = verifierCertId,
    VerifierId = "urn:example:verifier:ticket-state", VerifierVersion = "1.3.0",
    ControlArtifact = run.ControlArtifact, RunEnd = bundle.Artifacts[^1],
    ObservedState = new[] { AgentRunObject.Json("observed-state", ticketAfter) },
    Controls = new[] { new ControlResult("ticket-closed", "PASS"), new ControlResult("owner-unchanged", "PASS") },
    Overall = "PASS",
});
File.WriteAllText("run.json", bundle.WithEvaluations(evaluation).ToJsonString());

Later, anyone holding the bundle can verify it:

var result = await client.VerifyAgentRunAsync(AgentRunBundle.Parse(File.ReadAllText("run.json")));
// result.Verdict     -> "run_finalized" | "run_open" | "run_invalid"
// result.Checks      -> correlation, sequence, chain, envelope, signatures,
//                       timestamps, objects, finalization, control: ok | warn | bad
// result.Binding     -> "bound" | "run_only" | "control_only" | "unbound"
// result.Findings    -> exactly what failed, e.g. "Sequence gap: no artifact for seq 2 (deleted or withheld)."
// result.Evaluations -> per evaluation: Valid (read this one), the parts it is made of — SubjectBound,
//                       ControlSetDigestMatches, BaselineDigestMatches, SignatureValid, TimestampValid,
//                       ObjectsComplete — and Overall exactly as the verifier claimed it
Console.WriteLine(result.Scope); // what a verdict does — and does not — establish

What to know:

  • Content never leaves your machine. Sealing and verification send digests and opaque URNs only. A bundle carries digests by default; set RetainPayloads (or use bundle.WithPayloads(...)) only when the recipient may read the content — supplying payloads upgrades the objects check from "digests match" to "content matches".
  • Seal every event, timestamp to wrap up. Every event is signed and chained; by default RFC 3161 timestamps go only on the Control Artifact, run_end and each Control Evaluation — three for a whole run. The policy is signed into the Control Artifact, so the verifier knows which events had to carry one. Opt into more with AgentTimestampPolicy { Consequential = true } (every consequential event), EveryEvents / EverySeconds (a cadence), AgentTimestampPolicy.PerEvent, requireTimestamp: true on one event, or run.CheckpointAsync() from a timer while a long run is idle.
  • One certificate per run. The Control Artifact and every event must be sealed with the same certificate; the verifier fails a run that mixes signers, so events forged by anyone else cannot be appended. Pin your certificates' thumbprints with client.VerifyAgentRunAsync(bundle, expectedSigners: new[] { thumbprint }) (result.Signer shows the run's), and the verifier's with expectedEvaluationSigners.
  • Keep the Control Artifact with the run. run_start binds it, so a bundle without it fails the control check: leaving it out must not hide a stricter policy or a broken control basis.
  • What the default does not prove. Events without a timestamp could be rewritten by anyone able to seal with the run's certificate until run_end is timestamped; result.Scope says so. Timestamp consequential events to narrow that window.
  • Timestamps count only from a trusted TSA. The signature service reports each timestamp's TSA trust; until it reports trusted_chain or qualified, the result carries a "TSA trust not established" warning.
  • Evaluations never change the run verdict. They are reported on their own, and the SDK evaluates no controls: Overall is the named verifier's claim (a policy evaluation's rules can be recomputed: see Policy engine). Read it only when Valid is true — the evaluation is then signed over its own envelope, timestamped, intact, and bound to this run's run_end, Control Artifact and pre-sealed control set.
  • Persist as you go. OnArtifactSealed runs after each artifact is sealed, in order. A sealing failure stops the chain; the partial bundle (run.ToBundle()) verifies as open or invalid, never as finalized.
  • Bring your own verifier. AgentRunVerifier.VerifyAsync(bundle, verifier) accepts any BlindObjectsVerifier; AgentRunVerifier.Remote(client) is the blind endpoint used above.

Showing a run in Sigill

Sealing sends digests only, so Sigill cannot show a run it has only sealed. To see the run in your organisation's Sigill (its steps, the guard's refusals, alerts), opt in per run with DeliverRun:

var run = await client.StartAgentRunAsync(agent, options with { DeliverRun = true });
// ... record the run as usual ...
await run.FinishAsync("completed");
AgentRunDelivery? delivery = run.Delivery;   // Status: delivered | pending | rejected; Delivered, Pending, RunId, Error

After each artifact is sealed, and after OnArtifactSealed for it, the SDK uploads it to the organisation's evidence index, in chain order, with the client and credentials the run seals with (DeliverRun needs SigillClient; another client is refused before anything is sealed).

  • What leaves the machine: each artifact's signed envelope, signature and object digests. That is: the agent id, version, tenant id and identity reference, the activity name and run id, the control set's id and version, step types and times, tool names, operations and use ids, authorization decisions and policy ids, rule ids and guard reasons, model names, deployments, regions and stop reasons, model and provider request ids, token counts, approver references, sub-agent ids, object URIs, content types and sizes, the detail text, and the signing certificate inside each signature. Every one of these is your own value, uploaded as written; only detail, the activity name, the approver, the decision and the content type are length-bounded. Never arguments, results, prompts, outputs or receipts. The policy document travels only with DisclosePolicy, on the Control Artifact's upload (run.PolicyDisclosure is its outcome); if the index refuses the document, the Control Artifact is sent again without it and the steps follow.
  • Free text is bounded, with or without delivery. A step's detail is at most 512 characters; the activity name, an approver reference, a step's decision and an object's content type at most 255 (Unicode code points). A longer value is refused with an ArgumentException before anything is sealed — never truncated — and an index may refuse it too (AgentProfiles.CheckFreeTextLimits is the same rule). Object metadata and envelope extensions (at most 2,048 bytes each) cannot be set through this SDK; the bound is there for envelopes built by other means. New in 0.15.0: 0.14 sealed longer values.
  • A delivery failure never fails the run. It is not raised, does not break the chain and does not halt an enforced run (the guard's own exceptions are raised as before). An unreachable index (a timeout, 408, 429 or 5xx) holds the uploads; the next attempt waits for a back-off (5 s, doubling to 5 min) and resumes from the first artifact not delivered. run_end — and FinishAsync on a halted run — make one more attempt past the back-off, at most 30 s. If the index refuses an artifact (any other 4xx — or an answer that is not the index's: another 2xx, a redirect, an unreadable body), delivery stops there: the index holds a true prefix of the run, and run.Delivery says why. Each turn has a time budget: 10 s for a step's uploads together, 30 s for the run's end. So with the index unreachable a step can take up to 10 s longer and the run's end up to 30 s; a guard refusal still blocks the call at once, but its exception is raised after that wait.
  • Catch up later from the bundle: await client.DeliverAgentRunAsync(bundle) uploads the Control Artifact, then the events by seq, skips evaluations, and does not send the policy document. Repeating it is safe (the index answers exists), a partial bundle works, and it stops at the first artifact the index does not take.

Sub-agents: run trees

An agent that starts sub-agents records each one as its own run, bound to the parent in both directions (Agent Delegation v1). Children may run concurrently and under their own certificate and controls.

var parent = await client.StartAgentRunAsync(agent, options with { Delegating = true });

// The parent declares the child before it starts; only the instruction's digest is sealed.
AgentDelegation delegation = await parent.DelegateAsync("urn:example:agent:security-reviewer",
    instruction: taskBytes, useId: "call-7");

// The child's run_start binds the parent's delegation event.
var child = await client.StartChildAgentRunAsync(reviewerAgent, reviewerOptions, delegation);
await child.RecordToolCallAsync("repo.read_file", argsJson, operation: "read");
await child.FinishAsync("completed");

await parent.CompleteDelegationAsync(child);   // binds the child's run_end
await parent.FinishAsync("completed");

var tree = new AgentRunTreeBundle(parent.CorrelationId, new[] { parent.ToBundle(), child.ToBundle() });
var result = await client.VerifyAgentRunTreeAsync(tree);
// result.Verdict -> "tree_finalized" | "tree_open" | "tree_invalid"
// result.Edges   -> per delegation: mutually_bound | child_missing | parent_missing | unbound,
//                   and result_bound | result_mismatch | result_unresolved | no_result
// result.Runs    -> every run with its own verdict, which the tree never changes
  • A withheld child is detected. The parent's delegation_result names the child's run_end; a tree that leaves the child out, swaps it, or edits it is tree_invalid.
  • Close what you open. A parent cannot close completed while a delegation has no result; close it aborted or failed instead, and the tree reports "parent terminated; evidence incomplete". The recorder keeps one event slot per open delegation, plus run_end, inside the 2,000-event bundle limit.
  • Delivery is per run. A child run is shown in Sigill only when its own options set DeliverRun; it does not inherit the parent's.
  • Attribution needs a policy. Pass AgentRunTreeOptions.ExpectedSigners (agent.id → certificate thumbprints) and ExpectedRoot… to bind the tree to what you expected; without them a shared certificate proves consistency, not who ran each sub-agent.

Policy enforcement: tool calls and bound approvals

A run whose control set is a policy control set v2 (AgentPolicy.ControlSetFromDocument, with "schemaVersion": "2") is recorded as execution schemaVersion "4" (Agent Enforcement v1): every tool call has a useId and every result names its call. Only the guard (below) writes an enforcement record or a halted run_end; RecordAsync refuses those members. The verifier adds the enforcement check for v4 runs (results without a call, a second result, reused use ids, misplaced or unrecorded decisions), and reports evidence_version_mismatch when a run under a v2 policy control set is not v4.

Record a call and its result as one lifecycle:

ToolCall call = await run.BeginToolCallAsync("crm.read_customer", argsJson, operation: "read",
    definition: toolManifestEntry);   // optional: binds the tool's definition by digest
byte[] result = await ReadCustomerAsync(argsJson);
await call.CompleteAsync(result);      // same tool and useId; a second completion is refused

Bind an approval to the call it is for with RecordBoundApprovalAsync: its tool and the digest of its exact arguments, optionally its useId and an expiry. One approval binds at most one call, and a rejection is sticky for the run:

await run.RecordBoundApprovalAsync("approved", approver: "urn:example:approver:42",
    covers: ApprovalCovers.ForArguments("payments.refund", refundArgs, expiresAt: DateTimeOffset.UtcNow.AddMinutes(15)));
ToolCall refund = await run.BeginToolCallAsync("payments.refund", refundArgs, consequential: true);
// Or covers: call.Covers() for one sealed call exactly, including its useId.

AgentPolicy.Validate checks a v2 document (entities, enforcement settings, annotations, the schema v2 digest; strict Cedar validation needs a Cedar engine, below), AgentPolicy.Enforcement gives its effective settings and each rule's effect, and AgentPolicy.BuildFactsV2 builds the facts v2 a guard and an evaluator evaluate.

Policy engine

The package Sigill.Sdk.Policy adds CedarEngine: the official Cedar policy core, cedar-policy 4.14.0, compiled to one WebAssembly module (sha256 a0cd395067e77a157116f6b25bcdb612d34c61d1a4446918d75da1a07c80d1f3, built reproducibly from engine/) and run in-process with Wasmtime. The module is embedded in the package and refused if its digest differs; it has no filesystem, network, clock or environment, and at most 256 MiB of memory. Sigill.Sdk itself has no dependency on it: the methods below take any IPolicyEngine. The licences and notices of Cedar and the other Rust crates compiled into the module are in THIRD-PARTY-NOTICES.md, which the package also carries.

dotnet add package Sigill.Sdk.Policy
using Sigill.Sdk.Policy;

var engine = new CedarEngine();   // loads on first use; share one instance between threads

// Everything Validate checks, plus Cedar's strict validation of the rules against the schema of the
// document's version (and, for v2, of cedar.entities against schema v2).
IReadOnlyList<string> problems = AgentPolicy.ValidateStrict(controlSetBytes, engine);

// Per-rule results over a run's facts: PASS / FAIL / INDETERMINATE with where, overall, the engine id
// ("cedar-policy@4.14.0") and per request the rules that matched or errored.
PolicyFacts facts = AgentPolicy.BuildFacts(agentId, correlationId, events);
PolicyEvaluationResult evaluated = AgentPolicy.Evaluate(controlSetBytes, facts.Bytes, engine);

// Verify a run and recompute each policy evaluation of a v1 control set from its sealed facts:
// ResultsRecomputed is true when they match; results that differ make the evaluation invalid.
var result = await client.VerifyAgentRunWithEngineAsync(bundle, engine);

An evaluation made with another Cedar version, or beyond the verification's recomputation budget, is not recomputed (a note says so); a request the engine refuses makes the evaluation invalid. A failure inside the engine is a PolicyEngineException, and never makes the verifier throw. The engine runs where Wasmtime ships native libraries: Linux (glibc), macOS and Windows on x64 and arm64.

Enforcement: deny a tool call, halt a run

With a policy engine the run gets a guard (Control Set v2 §7): after each event is sealed it evaluates the event's facts, and under enforcement.mode: "enforce" it denies a tool call or halts the run before the agent acts, and seals that decision in the run's chain as an enforcement record (and, for a halt, a run_end with runDisposition: "halted").

using var engine = new CedarEngine();
var run = await client.StartAgentRunAsync(agent, new AgentRunOptions
{
    CertificateId = certId, Activity = "support-session",
    ControlSet = AgentPolicy.ControlSetFromDocument(controlSetBytes),
    Enforcement = new AgentEnforcement(engine) { OnEvent = e => log.Information("guard {Kind} {Reason}", e.Kind, e.Reason) },
});

try
{
    // Begins the call; runs the tool only if the guard allows it; seals its result.
    byte[] result = await run.InvokeToolAsync("payments.refund", argsJson, ct => RefundAsync(argsJson, ct), consequential: true);
}
catch (PolicyDeniedException denied)   // denied.Reason, .Rules, .Tool, .UseId, .Seq, .Record, .Halted
{
    // The tool did not run. A retry is a new call (a new use id): e.g. after a human approves exactly this call
    // with RecordBoundApprovalAsync(..., covers: ApprovalCovers.ForArguments("payments.refund", argsJson)).
}
  • Switching it on. A control set whose enforcement.mode is enforce requires Enforcement: starting without one is an ArgumentException, before anything is sealed. With Enforcement, the control set is validated strictly (AgentPolicy.ValidateStrict) before anything is sealed. With mode: "observe", a v1 control set or no policy control set, the guard never denies or halts and seals nothing; matching rules are only reported to OnEvent (kind observed, naming the tool on a tool_call or tool_result), as are effect: observe (shadow) rules in enforce mode. The producer's own run_end is not evaluated. In observe mode an engine that fails at start raises a PolicyEngineException before anything is sealed; later failures are silent.
  • A denied call. BeginToolCallAsync, RecordToolCallAsync and InvokeToolAsync raise PolicyDeniedException after the call and its record (and the halt, when it halts) are sealed. No ToolCall is returned, and a result for that use id is refused.
  • A halt. A halt rule, haltAfterDenials, or an engine that fails halts the run. The recording call that caused it raises RunHaltedException; so does every later recording call (a call allowed just before the halt is not started: BeginToolCallAsync, RecordToolCallAsync and InvokeToolAsync raise it too), and ModelCallHandler sends no further model call. In an enforced run ModelCallHandler also raises a failure to record a model call (after onError) and sends nothing once the run is broken or finished. IsHalted is true and HaltedToken is cancelled: pass it to the agent's other work. FinishAsync returns the halted run's bundle without sealing anything. A halt rule on delegation hands out no delegation at all.
  • A refused start. A locked configuration that differs, or an engine that cannot load, refuses the start: StartAsync raises StartRefusedException; its Run is the closed run (Control Artifact, run_start, the record, the halted run_end).
  • Callbacks. OnEvent runs after the evidence is sealed, outside the run's lock, in seal order, and before the exception reaches the caller. A failing callback never breaks the run or hides a denial (it becomes the denial's inner exception).
  • Nothing leaves. Records, messages and events name the tool alias, use id, rule ids, reason and seq only; never arguments, results or definitions. The engine sees facts and the control set, not content.

Three runnable examples are in examples/Sigill.Sdk.Examples (scripted agents, no model calls, under the example's own control set): loop, an agent that keeps retrying a forbidden call until the run is halted; graph, two branches recording concurrently on one run (one denied, one finishing) and a delegated child run; approval, a call denied, approved with covers, retried and allowed. Each prints what the guard decided and the verification of the run with the engine:

SIGILL_API_KEY=… SIGILL_CERTIFICATE_ID=… dotnet run --project examples/Sigill.Sdk.Examples -- loop
# SIGILL_BASE_URL selects another endpoint; SIGILL_CA_BUNDLE (a PEM file) makes only that CA trusted for it.

What enforcement does and does not show.

  • Enforcement is done by the producer's own SDK, in the producer's process. The evidence shows what that guard decided; it cannot show that a producer did not bypass it.
  • A stop means the SDK refused the call, not that the tool could not be reached another way.
  • That a denied tool did not run is not proven by the evidence: the evidence shows that the call was denied and that no result was recorded for it.
  • Anyone with the control set and the signed events can recompute each decision with the Cedar core named in the record — except a record with reason unavailable (the engine failed), which cannot be recomputed.
  • A tool that is already executing when another event halts the run is not stopped by the SDK; its result is not sealed.
  • Model calls the SDK cannot recognise or parse are not recorded, so no rule sees them.
  • The run's state is checked once more after the call's callbacks have run and, in InvokeToolAsync, immediately before the function is called; a halt sealed by another thread after that check does not stop the function.
  • An engine that does not answer holds the run: there is no timeout on a decision.
  • A child run is refused after its parent halted only when it is started from the delegation object the parent returned in the same process.

Evaluating an enforced run: did the guard do what the control set required?

The verifier checks that a run's enforcement records hang together; it does not check that the guard denied or halted when it had to. An independent evaluator does: from the Control Artifact, the signed events with their signed object digests and the control-set document — never a payload — AgentPolicy.CompareEnforcement recomputes, for each event, what was due and compares it with what the chain records (ControlEvaluation v3 §5). It needs nothing an evidence index does not hold, and any IPolicyEngine.

JsonObject enforcement = AgentPolicy.CompareEnforcement(bundle.ControlArtifact!, bundle.Artifacts, controlSetBytes, engine);
var facts = AgentPolicy.BuildFactsV2(agentId, bundle.CorrelationId!, bundle.Artifacts, controlSetBytes);
var evaluated = AgentPolicy.Evaluate(controlSetBytes, facts.Bytes, engine);
var prepared = ControlEvaluation.PreparePolicy(new PolicyEvaluationRequest
{
    CertificateId = evaluatorCert, EvaluatorId = "urn:example:policy-evaluator", EvaluatorVersion = "1.0.0",
    ControlArtifact = bundle.ControlArtifact!, ControlSetDocument = controlSetBytes, Events = bundle.Artifacts,
    Rules = evaluated.Rules, Engine = evaluated.Engine, Enforcement = enforcement, PolicyStatus = "unapproved",
});
var evaluation = await ControlEvaluation.SealAsync(client, prepared, evaluatorCert);   // a ControlEvaluation v3

Conclude that the guard did what was due only when verdict.Valid, verdict.EnforcementRecomputed, verdict.EnforcementResult == "as_required" and verdict.PolicyState == "finalized" all hold (verdict is the evaluation's entry in the verification result's Evaluations): without EnforcementRecomputed the result is the evaluator's unconfirmed word, and a partial prefix says nothing about the events after it.

A policy evaluation of a run under a v2 control set is a ControlEvaluation v3 (facts v2 plus policy.enforcement); a v1 control set keeps getting ControlEvaluation v2. A rule's result keeps its meaning — a matching rule is FAIL whether it was observed, refused or let through — and overall ignores the comparison; read enforcement.result beside it. AgentRunVerifier.VerifyWithEngineAsync recomputes the comparison with the core the evaluation names; the verdict gives EnforcementComparison, EnforcementResult and EnforcementRecomputed (true only for a performed comparison this verifier reproduced). A not_performed comparison is not a pass: EnforcementResult is then null.

Outcome Meaning Findings
as_required the chain records what was due —
let_through the chain records less than was due refusal_missing, unknown_tool_allowed, configuration_not_enforced, halt_missing
over_enforced the chain records more than was due, or the wrong reason or rules; it records no forbidden action unfounded_record, unfounded_halt, reason_mismatch, rules_mismatch
not_checkable the record says the guard's core was unavailable —
pending the evaluated prefix ends on this event or its record: what follows is not known —

The result speaks for the evaluated prefix only: a run with a gap is compared up to the gap, and can be as_required with state: "partial".

The comparison is not_performed — never to be read as as_required — when the chain contradicts its own records or holds an event that is not Execution Evidence v4 (chain_inconsistent), when its records name more than one core (engine_inconsistent), or one the evaluator cannot run (engine_unavailable).

The comparison knows only what the chain records. It does not show which tool was in fact run under a call's name, that the per-call digests are those of what was sent and run, an action recorded as another step type, that a human approved, when an approval in fact expired, that a refused tool or anything after a halt did not run outside the recorded run, whether the guard or other code of the producer sealed a record, whether the guard's core in fact failed where a record says unavailable, which core the guard ran when the run holds no record, that the sealed configuration is the one the runtime used, anything a rule matches only at run level, or anything after the evaluated prefix. agent.id is the producer's own name for its agent.

Error handling

Producer-time errors throw; verification errors are collected. This split is deliberate: when sealing, you have a single in-flight operation that either works or doesn't. When verifying, an audit UI wants every problem at once, not just the first.

When Surface Spec §7 kind
SealAsync() — every TSA Sigill tried failed SigillTimestampUnavailableException (with Failures) timestamp_unavailable
SealAsync() — caller pre-declared a hash that doesn't match supplied bytes SigillHashMismatchException hash_mismatch
SealAsync() — input contains values JCS rejects (NaN, Infinity) SigillCanonicalizationException canonicalization_failed
VerifyAsync() — anything wrong result.Issues, result.IsValid == false per-issue Kind field

All of these inherit from SigillException. A typical seal-with-fallback:

try
{
    var sealed_ = await client.SealAsync(envelope, externalPayloads: payloads);
    await Persist(sealed_);
}
catch (SigillTimestampUnavailableException ex)
{
    // All TSAs in our rotation failed. Persist unsealed, seal asynchronously.
    logger.LogWarning("TSA outage: {Attempts} attempts, failures={@Failures}",
        ex.AttemptsTried, ex.Failures);
    await PersistForAsyncSealing(envelope, payloads);
}

Integration patterns

A common pattern is to call the SDK from a response post-processor that runs after every model call. Two scenarios:

Inline path (no PII): the prompt and response are non-sensitive enough to store verbatim. Build the envelope inline, seal, persist:

public sealed class AiEvidenceLogger
{
    private readonly ISigillAiEvidenceClient _sigill;
    private readonly IEvidenceStore _store;

    public async Task LogAsync(AiCallContext ctx, ModelInvocation call, ModelResponse resp)
    {
        var envelope = new EnvelopeBuilder()
            .WithPurpose(category: ctx.PurposeCategory)
            .WithActor(type: "service", id: ctx.ServiceId, tenantId: ctx.TenantId)
            .WithActivity(name: ctx.ActivityName, correlationId: ctx.TraceId)
            .WithModel(provider: call.Provider, name: call.ModelName,
                       parameters: call.ParametersAsJson)
            .WithPromptInline(call.PromptText)
            .WithOutputInline(resp.OutputText)
            .Build();

        var sealed_ = await _sigill.SealAsync(envelope);
        await _store.WriteAsync(ctx.TraceId, sealed_.Json);
    }
}

PII path: the prompt or response carries personal data. Hash-reference them in the envelope; store the bytes separately under your normal data-retention policy. When you delete them later (right-to-erasure, retention expiry), the sealed envelope still proves the call happened, just not what was in it.

Register SigillClient once at startup with IHttpClientFactory:

services.AddHttpClient<ISigillAiEvidenceClient, SigillClient>(http =>
{
    http.BaseAddress = new Uri("https://api.sigill.ai");
    http.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue("Bearer", configuration["Sigill:ApiKey"]);
});

Cross-language interop

This SDK and the Python SDK at sigill-python share the same spec, JSON Schema, and test vectors. An envelope sealed by either SDK verifies with either SDK — the canonical bytes are byte-identical.

The interop guarantee is enforced by tests: both test suites read the same files under spec/test-vectors/ and assert that their canonical output matches the committed reference bytes. The spec/ directory in this repo is a vendored copy of the canonical source; both repos hold byte-identical copies, and the CI in each repo will fail if its copy drifts from what the canonicalizer produces.

The same holds for agent runs: both verifiers reproduce every shared agent-run vector — verdict, checks, binding, findings and warnings — so a run recorded with either SDK verifies identically with the other. The run-tree vectors (agent-run-tree/) pin the delegation rules the same way; this SDK reproduces all of them, and the Python SDK follows.

Pinning a specific TSA

By default, SealAsync() uses Sigill's auto mode — round-robin across the TSAs you have enabled, with automatic failover. That's the recommended setting for production. If you need to record that a specific TSA produced the timestamp (compliance reason, specific policy OID), pass it explicitly:

var sealed_ = await client.SealAsync(envelope, options: new SealOptions
{
    TsaSlug = "skid-ecc",      // eIDAS Qualified TSA from SK ID Solutions
    Qualified = true,
});

Available slugs and their properties: see Sigill's TSA documentation.

Lower-level surface

The SDK exposes its primitives in case you need them outside the seal/verify flow:

using Sigill.Sdk;

// Canonicalize a JSON object per RFC 8785
byte[] canonical = EnvelopeHashing.Canonicalize(jsonObj);

// Compute the envelope hash per spec §4 (strips integrity.envelopeHash + proofs)
var (digestHex, canonicalBytes) = EnvelopeHashing.ComputeEnvelopeHash(envelopeJson);

// Hash arbitrary bytes
string hex = EnvelopeHashing.HashHex(someBytes, "SHA-256");

This is what every test vector is built from, and it's what the cross-language interop guarantee comes down to.

What this SDK is not

It is not a substitute for TSA chain validation. The SDK confirms the TSR's embedded message-imprint matches your envelope, but it does not — by design in v1 — validate the TSA's certificate chain back to a trust anchor. Sigill's POST /tsa/verify endpoint does that server-side. v2 of this SDK will provide a pluggable trust policy.

Verifying a release

Every release is sealed with Sigill before it is published: the .nupkg and .snupkg each get a detached CAdES seal (.p7s) with a qualified (eIDAS) RFC 3161 timestamp and a post-quantum hybrid signature (ML-DSA-87 strengthens the classic seal). The seals are attached to the GitHub release. nuget.org adds its own repository signature inside the package, so the file it serves differs from the one we built; that file is sealed too (Sigill.Sdk.<version>.nuget-org.nupkg.p7s). To check a download, put the file and the matching .p7s into sigill.ai/verify.

Development

git clone https://github.com/sigill-ai/sigill-dotnet.git
cd sigill-dotnet
dotnet test

CI runs net8.0 and net9.0 on Ubuntu and Windows.

License

Apache 2.0 — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.16.1 100 11/16/2026
0.16.0 228 11/14/2026
0.15.0 92 11/14/2026
0.14.0 90 11/13/2026