Canton.Ledger.Kernel 0.4.0-preview.1

Prefix Reserved
This is a prerelease version of Canton.Ledger.Kernel.
dotnet add package Canton.Ledger.Kernel --version 0.4.0-preview.1
                    
NuGet\Install-Package Canton.Ledger.Kernel -Version 0.4.0-preview.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="Canton.Ledger.Kernel" Version="0.4.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Canton.Ledger.Kernel" Version="0.4.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Canton.Ledger.Kernel" />
                    
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 Canton.Ledger.Kernel --version 0.4.0-preview.1
                    
#r "nuget: Canton.Ledger.Kernel, 0.4.0-preview.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 Canton.Ledger.Kernel@0.4.0-preview.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=Canton.Ledger.Kernel&version=0.4.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Canton.Ledger.Kernel&version=0.4.0-preview.1&prerelease
                    
Install as a Cake Tool

Canton.Ledger.Kernel

The transport-neutral client kernel for Canton participant nodes: the Authentication, Telemetry, and Resilience modules — authentication (ITokenProvider), the OpenTelemetry ActivitySource naming convention, and an opt-in Polly retry pipeline. Both the gRPC client and the future JSON client consume this package as peers — neither depends on the other. Authentication sits at the bottom of the kernel's namespace DAG (it depends on neither of the other modules), so it can later be extracted into its own package without a breaking change.

Key Types

Type Purpose
ITokenProvider Interface — Task<string> GetTokenAsync(CancellationToken)
ITokenProvider.None Static singleton signaling unauthenticated access (no Authorization header)
StaticTokenProvider Returns a fixed token string. Use for short-lived processes or testing
ClientCredentialsProvider OAuth2 client-credentials flow with thread-safe TTL cache (SemaphoreSlim + Volatile reads/writes)
ClientCredentialsOptions Config: Domain, ClientId, ClientSecret, Audience, TokenEndpoint, SafetyMargin, AllowInsecureTokenEndpoint
Telemetry.LedgerActivitySource Shared ActivitySource naming convention — NameFor<T>(), Create<T>(), StartActivity<T>()
Resilience.RetryOptions Config for the opt-in retry pipeline. Enabled defaults to false
Resilience.RetryPipelineFactory Builds a Polly ResiliencePipeline from RetryOptionsResiliencePipeline.Empty (a genuine no-op) when disabled

Usage

Client-credentials (OAuth2) via DI

services.AddCantonAuth(configuration.GetSection("Canton:Auth"));
{
  "Canton": {
    "Auth": {
      "Domain": "dev-peaceful.eu.auth0.com",
      "ClientId": "my-client-id",
      "ClientSecret": "my-client-secret",
      "Audience": "https://canton.network/"
    }
  }
}

Domain accepts either a bare hostname (e.g. dev-peaceful.eu.auth0.com) or an absolute https URL (e.g. https://auth.example.com, or https://auth.example.com/tenant-a for per-tenant subpaths). If Domain is a bare hostname, it is treated as https://{hostname}. If it is an absolute URL, that URL is used as the base. In both cases, /oauth/token is appended, preserving any existing path (https://auth.example.com/tenant-ahttps://auth.example.com/tenant-a/oauth/token). Userinfo, query, and fragments are rejected. ClientCredentialsProvider caches tokens until expires_in - SafetyMargin (default 30s) and concurrent callers share a single HTTP request during refresh.

Plaintext http endpoints (whether from Domain or TokenEndpoint) are rejected by default, because the token request POSTs the client secret in cleartext — anyone on the network path could read it. To accept the risk against a local endpoint (e.g. http://localhost:8080 during development), set AllowInsecureTokenEndpoint to true; the provider then logs a warning at construction.

To override the token endpoint (e.g., non-standard OAuth2 servers like Keycloak's /realms/{realm}/protocol/openid-connect/token):

{
  "Canton": {
    "Auth": {
      "TokenEndpoint": "https://custom.example.com/oauth/token",
      "ClientId": "...",
      "ClientSecret": "..."
    }
  }
}

Static token via DI

services.AddCantonStaticAuth("eyJ...");

Action-based configuration

services.AddCantonAuth(options =>
{
    options.Domain = "https://auth.example.com";
    options.ClientId = "my-client-id";
    options.ClientSecret = "my-client-secret";
    options.Audience = "https://canton.network/";
});

Registration precedence

All methods use TryAddSingleton — the first registration wins. Register explicit providers before calling AddLedgerClient/AddAdminClient to override auto-registration.

Unauthenticated access

When no ITokenProvider is registered, AddLedgerClient/AddAdminClient register ITokenProvider.None as a default. Clients detect this and skip the Authorization header. Use this for local development with unauthenticated Canton nodes.

OpenTelemetry ActivitySource naming (Canton.Ledger.Kernel.Telemetry)

LedgerActivitySource centralizes the naming convention every client's ActivitySource follows, so a host registers sources the same way regardless of transport:

public static string ActivitySourceName => LedgerActivitySource.NameFor<MyClient>();
private static readonly ActivitySource ActivitySource = LedgerActivitySource.Create<MyClient>();

using var activity = LedgerActivitySource.StartActivity<MyClient>(ActivitySource);

BCL System.Diagnostics.Activity only — no OpenTelemetry SDK dependency. StartActivity no-ops (returns null) until the host registers a listener.

Opt-in retry pipeline (Canton.Ledger.Kernel.Resilience)

RetryPipelineFactory.Create builds a Polly ResiliencePipeline from RetryOptions:

var pipeline = RetryPipelineFactory.Create(new RetryOptions
{
    Enabled = true,
    MaxRetryAttempts = 3,
    Delay = TimeSpan.FromMilliseconds(200)
});

RetryOptions.Enabled defaults to false, in which case Create returns ResiliencePipeline.Empty — a genuine no-op — so a transport that has not opted in sees no retry behavior. The pipeline is transport-neutral: it references no Grpc.Core or System.Net.Http types, and knows nothing about ledger command semantics. A retried command can double-submit unless the caller reuses a stable command_id/submission_id for ledger-side dedup — the pipeline itself confers no idempotency.

Internals

  • IHttpClientFactory named client "CantonAuth" — no using on the HttpClient (factory manages handler lifetime)
  • TimeProvider for testable time (pass FakeTimeProvider in tests)
  • Volatile.Read/Volatile.Write for cache fields — write order: token before expiry (matches read order)
  • Validates expires_in > 0 and access_token non-empty after deserialization
  • Token endpoint is resolved once at construction — unresolvable options (no TokenEndpoint, invalid Domain, plaintext http without AllowInsecureTokenEndpoint) throw InvalidOperationException when the provider is constructed, not at the first token request
  • Canton.Ledger.Grpc.Client — gRPC client that consumes ITokenProvider
  • Canton.Ledger.Pqs.Client — PQS query client
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Canton.Ledger.Kernel:

Package Downloads
Canton.Ledger.Grpc.Client

High-level gRPC client for the Canton Ledger API with integration to Daml.Runtime types.

Canton.Ledger.Pqs.Client

Typed query client for the Canton Participant Query Store (PQS). Provides expression-based, SQL-injection-safe queries over active Daml contracts via PostgreSQL.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0-preview.1 101 7/18/2026
0.2.0-preview.1 103 7/6/2026