All files / lib/identity constants.ts

100% Statements 21/21
100% Branches 0/0
100% Functions 0/0
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                              1x     1x   1x   1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x 1x 1x  
/**
 * ProofID Identity System Constants
 *
 * Base58 alphabet excludes characters that are visually ambiguous:
 * - 0 (zero) and O (capital o)
 * - l (lowercase L) and I (capital i)
 *
 * This makes identity codes verbal-friendly and less prone to transcription errors.
 */
 
/**
 * Base58 alphabet for identity codes.
 * Includes both cases for backward compatibility with existing codes.
 * New codes are generated as uppercase for better UX.
 */
export const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
 
// Uppercase-only alphabet for new code generation
export const BASE58_ALPHABET_UPPER = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
 
export const IDENTITY_PREFIX = 'PFID';
 
export const IDENTITY_PAYLOAD_LENGTH = 4;
export const IDENTITY_CHECKSUM_LENGTH = 4;
 
// Full format: PFID-XXXX-XXXX (14 characters)
export const IDENTITY_CODE_LENGTH =
  IDENTITY_PREFIX.length +
  1 + // separator
  IDENTITY_PAYLOAD_LENGTH +
  1 + // separator
  IDENTITY_CHECKSUM_LENGTH;
 
// Regex pattern for validation (case-insensitive for user input)
export const IDENTITY_CODE_PATTERN = new RegExp(
  `^${IDENTITY_PREFIX}-[${BASE58_ALPHABET}]{${IDENTITY_PAYLOAD_LENGTH}}-[${BASE58_ALPHABET}]{${IDENTITY_CHECKSUM_LENGTH}}$`,
  'i'
);
 
// Reserved identity codes (for testing, examples, etc.)
export const RESERVED_IDENTITY_CODES = [
  'PFID-TEST-TEST',
  'PFID-DEMO-DEMO',
  'PFID-XXXX-XXXX',
  'PFID-0000-0000',
];