UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

1 lines • 3.44 kB
{"version":3,"file":"iso8601Datetime.mjs","names":[],"sources":["../../../../src/modules/w3c-di/proof-processing/iso8601Datetime.ts"],"sourcesContent":["/**\n * ISO 8601 DateTime Validation\n *\n * Inlined from iso-8601-regex (https://github.com/lightningspirit/iso-8601-regex-ts)\n * Licensed under MIT by lightningspirit\n *\n * Enforces strict calendar correctness including leap-year rules and valid day ranges.\n */\n\n/**\n * Strict ISO 8601 datetime regex with full calendar validation.\n *\n * Enforces:\n * - Year: 0000–9999\n * - Month: 01–12\n * - Day: per month (01–31, 30-day months restricted, Feb 29 allowed only on leap years)\n * - Hour: 00–23\n * - Minute: 00–59\n * - Second: 00–59\n * - Milliseconds: optional, 1–3 digits\n * - Timezone: \"Z\" (UTC) or ±HH:MM (offset -12:00…+14:00)\n *\n * Leap-year logic (Gregorian calendar):\n * - Divisible by 4 → leap year\n * - Divisible by 100 → not a leap year\n * - Divisible by 400 → leap year again\n *\n * Format: YYYY-MM-DDTHH:mm:ss(.SSS)?(Z|±HH:MM)\n *\n * Valid examples:\n * - \"2025-11-02T10:20:30Z\" // UTC\n * - \"2025-11-02T10:20:30.123Z\" // With milliseconds\n * - \"2025-11-02T10:20:30+01:00\" // With positive offset\n * - \"2024-02-29T12:00:00Z\" // Leap year (Feb 29 allowed)\n *\n * Invalid examples:\n * - \"2025-11-02T10:20:30\" // Missing timezone\n * - \"2025-04-31T12:00:00Z\" // Invalid day for April\n * - \"1900-02-29T00:00:00Z\" // 1900 not a leap year\n * - \"2025-11-02T24:00:00Z\" // Invalid hour\n */\nexport const ISO8601_DATETIME_REGEX = new RegExp(\n '^' +\n '(?<year>\\\\d{4})-' +\n '(?<month>(?:0[1-9]|1[0-2]))-' +\n '(?<day>' +\n '(?:' +\n '(?<=\\\\d{4}-(?:01|03|05|07|08|10|12)-)(?:0[1-9]|[12]\\\\d|3[01])|' + // 31-day months\n '(?<=\\\\d{4}-(?:04|06|09|11)-)(?:0[1-9]|[12]\\\\d|30)|' + // 30-day months\n '(?<=\\\\d{4}-02-)(?:0[1-9]|1\\\\d|2[0-8])|' + // Feb 01-28\n '(?<=(' +\n '(?:\\\\d{2}(?:0[48]|[2468][048]|[13579][26]))' + // yy % 4 == 0 (leap year non-century)\n '|(?:(?:[02468][048]|[13579][26])00)' + // centuries % 400 == 0 (leap year century)\n ')-02-)29' + // Feb 29 only if preceding matches leap year\n ')' +\n ')' +\n 'T' +\n '(?<hour>(?:[01]\\\\d|2[0-3])):' +\n '(?<minute>[0-5]\\\\d):' +\n '(?<second>[0-5]\\\\d)' +\n '(?:\\\\.(?<millisecond>\\\\d{1,3}))?' + // optional .sss\n '(?<timezone>' +\n 'Z|' + // UTC\n '(?:' +\n '\\\\+(?:(?:0\\\\d|1[0-3]):[0-5]\\\\d|14:00)|' + // +00:00…+13:59 or +14:00\n '-(?:(?:0\\\\d|1[01]):[0-5]\\\\d|12:00)' + // -00:00…-11:59 or -12:00\n ')' +\n ')' +\n '$'\n)\n\n/**\n * Validate XSD dateTimeStamp format per W3C XMLSCHEMA11-2.\n *\n * Requires timezone component (Z or ±HH:MM offset) with full calendar validation.\n * Falls back to Date.parse() for semantic correctness.\n *\n * Spec reference: VC DI EdDSA v1.0 §3.3.5 step 3\n * https://www.w3.org/TR/vc-di-eddsa/#proof-configuration-eddsa-jcs-2022\n */\nexport function isXsdDateTimeStamp(value: string): boolean {\n if (!ISO8601_DATETIME_REGEX.test(value)) {\n return false\n }\n\n return !Number.isNaN(Date.parse(value))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,yCAAyB,IAAI,OACxC,4eA2BF;;;;;;;;;;AAWA,SAAgB,mBAAmB,OAAwB;CACzD,IAAI,CAAC,uBAAuB,KAAK,KAAK,GACpC,OAAO;CAGT,OAAO,CAAC,OAAO,MAAM,KAAK,MAAM,KAAK,CAAC;AACxC"}