finident

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 8 Imported by: 4

README

finident

Go Reference Go Report Card

finident is a Go library for finance teams that need accurate Legal Entity Identifier (LEI) validation, ISO 6166 ISIN checksum recalculation, ISO 10962 CFI verification, and deterministic ESMA UTI generation. Use it to embed regulatory-grade identifier checks and trade-reporting helpers into Go microservices, batch pipelines, or custom tooling. The project is distributed under the MIT License.

Features

  • Go-native validation for Legal Entity Identifiers (LEI, ISO 17442) including checksum verification
  • International Securities Identification Number (ISIN, ISO 6166) parsing and recalculated check digits
  • Classification of Financial Instruments (CFI, ISO 10962) validation and bulk combination generation based on ESMA guidance
  • ESMA CPMI-IOSCO-aligned Unique Transaction Identifier (UTI) hashing helpers with time + randomness fallback for reliable uniqueness
  • Utility helpers for mod-97 checksum math and CFI tooling so you can compose higher-level finance services quickly

Installation

go get github.com/robfordww/finident

The module requires Go 1.20 or later. Import it in your project and call the helpers you need:

import "github.com/robfordww/finident"

Quick start

package main

import (
    "fmt"

    "github.com/robfordww/finident"
)

func main() {
    if ok, err := finident.ValidateLEI("5493004W1IPC50878Z34"); !ok {
        fmt.Println("LEI failed:", err)
    }

    if ok, err := finident.ValidateISIN("US0378331005"); !ok {
        fmt.Println("ISIN failed:", err)
    }

    if finident.IsValidCFI("ESVTOB") {
        fmt.Println("CFI looks good")
    }
}

ValidateLEI mirrors the ISO 17442 rule set for Legal Entity Identifiers. It checks string length, enforces the reserved 00 characters, restricts the character set to uppercase alphanumerics, and verifies the mod-97 checksum. Pair it with CalculateChecksum if you need to derive compliant suffix digits when issuing new LEIs programmatically.

Generate ESMA-Compliant UTIs

To produce CPMI-IOSCO/ESMA-compliant Unique Transaction Identifiers, use GenerateUTI when you already possess the 32-character suffix, or GenerateUTIFromParts to hash trade metadata and generate the suffix deterministically. When no metadata is available, the helper combines UTC nanoseconds with a cryptographically random 32-bit prefix so concurrently running systems still produce unique UTIs.

Classification of Financial Instruments (CFI) Support

IsValidCFI and GenCFICombinations encode the ESMA mapping for ISO 10962 codes. You can quickly validate single CFIs, enumerate every supported instrument class for discovery workflows, or cache the combinations to power form builders and selection widgets.

Common Use Cases

  • Enrich trade reporting pipelines that must publish ESMA-aligned UTIs and LEIs
  • Validate inbound securities master data before it hits downstream services
  • Generate CFI picklists for compliance portals and audit dashboards
  • Prototype Go microservices that expose validator APIs for finance operations

API overview

  • ValidateLEI(lei string) (bool, error) checks 20-character LEIs for uppercase alphanumerics, reserved 00 positions at indices 4–5, and the ISO 17442 mod-97 checksum, returning a validity flag plus descriptive error.
  • ValidateISIN(isin string) (bool, error) validates 12-character ISINs by enforcing the leading country code letters and recalculating the ISO 6166 check digit; failures return an explanatory error.
  • IsValidCFI(cfi string) bool confirms a six-character CFI matches the ESMA taxonomy segments stored in the map and returns true only for valid combinations.
  • GenCFICombinations() []string materializes every permitted CFI combination from the ESMA mapping, yielding several thousand entries as a convenience for enumeration tasks.
  • Validatemod97(s string) bool normalizes the input to uppercase, converts letters to their 10–35 numeric equivalents, and reports whether the numeric value modulo 97 equals 1.
  • CalculateChecksum(s string) string computes and zero-pads the two-digit string that must be appended so the full value satisfies the mod-97==1 rule used by LEIs.
  • GenerateUTI(lei, value string) (string, error) concatenates a validated LEI with a caller-provided value and ensures the result meets the CPMI-IOSCO/ESMA guidance (upper-case alphanumerics with a maximum length of 52).
  • GenerateUTIFromParts(lei string, parts ...string) (string, error) derives the value component deterministically (SHA-256 + base32) from trade metadata so that callers can produce ESMA-compliant UTIs without hand-crafting the 32-character suffix.
Notes on CFI generation

GenCFICombinations expands every valid segment defined by the European Securities and Markets Authority (ESMA). The resulting slice contains several thousand entries; allocate or stream the values accordingly if you only need a subset. The source mapping is derived from ESMA's official taxonomy.

FAQ

How do I calculate an LEI checksum in Go? Use CalculateChecksum to compute the two-character suffix that makes a base string pass the ISO 17442 mod-97 check.

How can I ensure UTI uniqueness across services? GenerateUTIFromParts hashes ordered metadata with SHA-256 and falls back to a random 32-bit prefix plus UTC nanoseconds, so services running in parallel will still produce unique identifiers.

Does finident help with CFI discovery? GenCFICombinations expands every valid ISO 10962 segment so you can materialize dropdowns, filter lists, or cache the data for analytics jobs.

Contributing & development

  • Run tests with go test ./... (set GOCACHE if your environment requires a writable cache).
  • Please open an issue or pull request if you discover new instrument classes or additional validation rules we should cover.

License

This project is available under the MIT License. See LICENSE.md for details.

Documentation

Overview

Package finident is a Go toolbox for financial identifiers, covering LEI validation, ISIN checksum recalculation, ISO 10962 CFI verification, and ESMA-compliant UTI generation. MIT License Copyright (c) 2019 robfordww

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateChecksum

func CalculateChecksum(s string) string

CalculateChecksum takes a string and returns the next two characters that, when appended to the string, results in a "stringvalue mod 97 == 1"

func GenCFICombinations

func GenCFICombinations() []string

GenCFICombinations returns a list of all valid CFIs. This validator is based on ESMAs CFI list published here https://www.esma.europa.eu/file/20301/download?token=6K3VKc5m

func GenerateUTI added in v0.2.0

func GenerateUTI(lei, value string) (string, error)

GenerateUTI concatenates the LEI of the generating entity with a caller-supplied value and returns a UTI that complies with ESMA's implementation of the CPMI-IOSCO UTI Technical Guidance (February 2017). The LEI is validated using ValidateLEI; the unique value must contain only A-Z and 0-9 characters and, when appended to the LEI, must not exceed 52 characters in total. The returned UTI is always upper-case.

func GenerateUTIFromParts added in v0.2.0

func GenerateUTIFromParts(lei string, parts ...string) (string, error)

GenerateUTIFromParts derives an ESMA-compliant UTI using the provided LEI and a set of inputs that are hashed into the value component. When no additional parts are supplied a random 32-bit prefix combined with the current UTC time (nanoseconds) is used to guarantee uniqueness. The resulting UTI is deterministic for a given LEI and ordered set of parts.

func IsValidCFI

func IsValidCFI(cfi string) bool

IsValidCFI returns true if the CFI string is a valid CFI code, and false otherwise. This validator is based on ESMAs CFI list published here https://www.esma.europa.eu/file/20301/download?token=6K3VKc5m

func ValidateISIN

func ValidateISIN(isin string) (bool, error)

ValidateISIN takes an ISIN (ISO 6166) as string and validates the checkdigit

func ValidateLEI

func ValidateLEI(lei string) (bool, error)

ValidateLEI takes a possible LEI string as input and returns a boolean value error message. For valid LEIs, the bool == true and error == nil, otherwise bool == false and error != nil

func Validatemod97

func Validatemod97(s string) bool

Validatemod97 takes a string as parameter and returns true if mod 97 of the string, interpreted as a number, returns 1. Letters A-Z are converted to numbers 10-34

Types

type LeiError

type LeiError error

LeiError returned on error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL