Lei.Net 1.0.0

dotnet add package Lei.Net --version 1.0.0
                    
NuGet\Install-Package Lei.Net -Version 1.0.0
                    
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="Lei.Net" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lei.Net" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Lei.Net" />
                    
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 Lei.Net --version 1.0.0
                    
#r "nuget: Lei.Net, 1.0.0"
                    
#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 Lei.Net@1.0.0
                    
#: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=Lei.Net&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lei.Net&version=1.0.0
                    
Install as a Cake Tool

Lei.Net

Correct, zero-dependency validation and parsing of Legal Entity Identifiers (LEI, ISO 17442) for .NET, with ISO 7064 MOD 97-10 check-digit computation and self-checking reference test vectors.

No NuGet package existed for the LEI when this was written. Lei.Net fills that gap for the .NET identifier family alongside SecurityIds.Net, Bic.Net, and Nuban.Net.

  • Zero runtime dependencies. Targets net8.0, AOT-compatible, trimming-safe.
  • Culture-independent (ToUpperInvariant, ordinal comparisons), allocation-light iterative MOD 97.
  • Fully XML-documented public API.

Install

dotnet add package Lei.Net

Quick start

using Lei;

// Fast boolean check
bool ok = LeiValidator.IsValid("529900T8BM49AURSDO55"); // true

// Structured result with parsed parts and a typed failure reason
var result = LeiValidator.Validate("529900T8BM49AURSDO55");
if (result.IsValid)
{
    Console.WriteLine(result.LouPrefix);   // "5299"
    Console.WriteLine(result.EntityPart);  // "T8BM49AURSDO"
    Console.WriteLine(result.CheckDigits); // "55"
}
else
{
    Console.WriteLine(result.Error); // NullOrEmpty | WrongLength | InvalidCharacter | ReservedDigitsNotZero | BadCheckDigits
}

// Compute the correct check digits for the first 18 characters
string check = LeiValidator.ComputeCheckDigits("529900T8BM49AURSDO"); // "55"

Input is trimmed and upper-cased invariantly; null, empty, and whitespace-only values are rejected.

What an LEI is

A Legal Entity Identifier is exactly 20 uppercase alphanumeric characters:

5299 00 T8BM49AURSDO 55
 |   |       |        |
 |   |       |        +-- positions 19-20: 2 check digits
 |   |       +----------- positions  7-18: 12-char entity-specific part
 |   +------------------- positions  5-6:  reserved, always "00"
 +----------------------- positions  1-4:  Local Operating Unit (LOU) prefix

Validate enforces all four structural rules: length 20, allowed character set (0-9, A-Z), reserved "00" at positions 5-6, and correct check digits.

The MOD 97-10 check (ISO 7064)

The two trailing digits protect against typos. To verify them:

  1. Take the full 20-character LEI.
  2. Convert each letter to a two-digit number: A = 10, B = 11, ... Z = 35. Digits stay as themselves.
  3. Read the concatenation as one large base-10 integer.
  4. The LEI is valid when that integer mod 97 equals 1.

To generate the check digits from the first 18 characters: append "00", take the number mod 97, and the check digits are 98 - remainder, zero-padded to two digits.

Lei.Net computes the remainder iteratively, one character at a time, so it needs no big-integer arithmetic and allocates nothing on the hot path.

The test suite is self-checking: for every reference LEI it asserts that ComputeCheckDigits(first18) reproduces the identifier's own last two characters. That equality is the objective correctness oracle.

Who needs this

  • MiFID II transaction reporting and EMIR trade reporting, where the LEI identifies counterparties and issuers.
  • KYC / onboarding pipelines validating a legal entity before it reaches downstream systems.
  • Any service that ingests, stores, or forwards LEIs and wants to reject malformed values at the boundary.

License

MIT (c) Israel Iyonsi. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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.
  • net8.0

    • No dependencies.

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
1.0.0 128 8/21/2026