@getaid/luhn
v1.0.0
Published
Luhn mod-10 check digit algorithm for AID (Agent ID) generation and validation
Maintainers
Readme
@getaid/luhn
Luhn mod-10 check digit algorithm for AID (Agent ID) generation and validation. Used by getaid.dev, the universal identity registry for AI agents.
Installation
npm install @getaid/luhnUsage
import {
generateCheckDigit,
validateLuhn,
formatAid,
parseAid,
isValidAidFormat,
} from "@getaid/luhn";
// Generate a check digit
generateCheckDigit("00001234"); // "7"
// Validate a Luhn-protected number
validateLuhn("000012347"); // true
validateLuhn("000012348"); // false
// Format a sequential ID into a canonical AID
formatAid(1234n); // "AID-000012347"
// Parse an AID string
parseAid("AID-000012347"); // { numeric: "000012347", checkDigit: "7" }
// Full validation (format + check digit)
isValidAidFormat("AID-000012347"); // true
isValidAidFormat("AID-000012348"); // falseAPI
| Function | Description |
| -------------------- | -------------------------------------------------------- |
| generateCheckDigit | Compute the Luhn check digit for a numeric string |
| validateLuhn | Validate a numeric string including its Luhn check digit |
| formatAid | Format a sequential BigInt ID into a canonical AID |
| parseAid | Parse an AID string into numeric component + check digit |
| isValidAidFormat | Validate format + Luhn check digit in one call |
AID Format
AIDs follow the format AID-XXXXXXXXX where X is a digit and the last digit is the Luhn check digit. The numeric portion is zero-padded to 9 digits (8 payload + 1 check).
License
MIT
