NCode.Randomness.Drand
1.0.0
Prefix Reserved
dotnet add package NCode.Randomness.Drand --version 1.0.0
NuGet\Install-Package NCode.Randomness.Drand -Version 1.0.0
<PackageReference Include="NCode.Randomness.Drand" Version="1.0.0" />
<PackageVersion Include="NCode.Randomness.Drand" Version="1.0.0" />
<PackageReference Include="NCode.Randomness.Drand" />
paket add NCode.Randomness.Drand --version 1.0.0
#r "nuget: NCode.Randomness.Drand, 1.0.0"
#:package NCode.Randomness.Drand@1.0.0
#addin nuget:?package=NCode.Randomness.Drand&version=1.0.0
#tool nuget:?package=NCode.Randomness.Drand&version=1.0.0
NCode.Randomness.Drand
The drand adapter for NCode.Randomness. drand is a distributed randomness beacon run by the
League of Entropy, a group of independent organizations that jointly sign each round with a BLS12-381 threshold
signature. This package fetches rounds of the quicknet chain, which publishes a round every 3 seconds, registered as
the beacon drand, and verifies each one before any byte is used:
- every document's text is well-formed Unicode before any member is read;
- the round's signature is a point of the BLS12-381 group G1, other than the identity;
- the signature verifies against the quicknet group public key pinned in
DrandDefaults.PublicKey, so no server or mirror can substitute another key: the pairinge(signature, g2)must equale(H(message), key), where the message is the SHA-256 hash of the round number as 8 big-endian bytes andHis the hash to curve of RFC 9380,BLS12381G1_XMD:SHA-256_SSWU_RO_, with the domain separation tagBLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_; - when the response carries a
randomnessmember, it is the SHA-256 hash of the signature; - the response answers the round that was asked for.
Only the quicknet chain is supported: its chain hash, group public key, genesis time and period are constants in
DrandDefaults, and no chain info document is fetched. Other members of a round that the chain does not sign are
ignored.
The randomness is the 32-byte SHA-256 hash of the round's signature. The beacon's pulse carries the quicknet chain hash as its chain, the round number as its round, the signature in lowercase hex as its identifier, and the time the round is due: the genesis time plus 3 seconds for each round before it. Rounds start at 1, so a round below 1 is reported as not found.
Installation
dotnet add package NCode.Randomness.Drand
The package depends on NCode.Randomness, so adding it brings the generator too. It targets net10.0.
Registration
AddDrandBeacon() registers the drand beacon:
var configuration = builder.Configuration;
var randomness = configuration.GetSection(RandomnessOptions.SectionName);
var drand = configuration.GetSection(DrandBeaconOptions.SectionName);
builder.Services.AddRandomness(randomness).AddDrandBeacon(drand);
Settings bind from RandomnessBeacons:Drand: BaseAddress (default https://api.drand.sh/) and MaxResponseBytes
(default 16 KiB; a round is about 200 bytes). The same chain is served by other relays, such as
https://api2.drand.sh/, https://api3.drand.sh/ and https://drand.cloudflare.com/. Because every round is verified
against the pinned group public key, a mirror can withhold rounds but never forge one. Requests use a named
HttpClient, DrandDefaults.HttpClientName, with retries, attempt and total timeouts and a circuit breaker; add a
proxy or other handlers to it with services.AddHttpClient(DrandDefaults.HttpClientName).
Verifying saved documents
DrandRoundVerifier makes the same checks without the network, on a round a caller supplies as the UTF-8 JSON the
API serves at <chain hash>/public/<round>. It pins the quicknet chain, as the beacon does, so the round is the
only document it needs, and returns the pulse the beacon returns for that round, or throws a BeaconException with
InvalidPulse. Pass the pulse to VerifiableRandom.Create to recompute a published draw, as
docs/draws.md describes:
var pulse = new DrandRoundVerifier().Verify(roundJson);
using var draw = VerifiableRandom.Create(pulse, "example-raffle-2026-11-25");
BLS12-381
The pairing arithmetic comes from the managed Neo.Cryptography.BLS12_381 library, so the package has no native
dependency and runs wherever .NET does. That library does not hash to the curve, so the adapter implements the RFC 9380
hash to G1 itself, and its tests pin the result to the RFC's test vectors. Verifying one round takes about 0.15 seconds.
ADR-1010
records the choice.
Learn more
- Add beacons: register the drand beacon next to the others
- Check a draw: recompute a published draw from saved documents
- Beacon reference: what each beacon publishes and how it is verified
- Configuration reference: every setting, including
RandomnessBeacons:Drand - Documentation site
- Reproducible draws: the procedure and the exact algorithm
- Changelog
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Http (>= 11.0.0)
- Microsoft.Extensions.Http.Resilience (>= 11.0.1)
- NCode.Randomness (>= 1.0.0)
- Neo.Cryptography.BLS12_381 (>= 3.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See the changelog: https://github.com/NCodeGroup/Randomness/blob/HEAD/CHANGELOG.md