This repository contains multiple implementations of the same mobility ID domain:
scala/: original Scala implementation (dev.juherr.mobilityid:mobilityid, sbt 2, Scala 2.13 + 3.9 LTS, specs2)java/: Java 21 port (mobilityid4j, Gradle)go/: Go port (mobilityid.juherr.dev/go)php/: PHP port (juherr/mobility-id, PHP 8.4+)ts/: TypeScript port (@juherr/mobilityid, Bun + Vite+)
cd scala
sbt --server --batch "+test"Run a single Scala suite:
cd scala
sbt --server --batch "core/testOnly com.thenewmotion.mobilityid.ContractIdSpec"cd java
./gradlew testRun a single Java suite:
cd java
./gradlew test --tests "*ContractIdTest"cd ts
vp install
vp checkRun a single TypeScript test pattern:
cd ts
vp test ContractId- Scala docs and original usage examples:
scala/README.md - Java-specific docs and design choices:
java/README.md - Go-specific docs and design choices:
go/README.md - PHP-specific docs and design choices:
php/README.md - TypeScript-specific docs and design choices:
ts/README.md
Every port parses ISO EVSE ids case-insensitively, the E id type included, and renders them in
uppercase: fr*55c*e84400*svg*1 is FR*55C*E84400*SVG*1. Only ASCII letters are folded. DIN ids
are digits only and are unaffected. Protocols disagree on case and length, and the parsers
follow the most tolerant of them:
- OCPI 2.3.0
types
EVSE.evse_idasCiString(48), a case-insensitive string. The CDRs module does the same. - OCHP writes the id type as the
ABNF literal
"E". Quoted ABNF strings are case-insensitive (RFC 5234 §2.3). OCHP allows 31 characters after it, as these parsers do. - OICP 2.3
EvseIDTypeis an uppercase-only pattern with an outlet suffix of up to 30 characters. An id these parsers accept can therefore still be refused by OICP. Render it withtoString()to get the uppercase form, and check the length where OICP applies.
The libraries do not ship protocol-specific validators.
An EMAID (ISO and EMI3 contract id) is a country code (2 letters), a provider id (3 alphanumeric
characters), an instance (9 alphanumeric characters, starting with C for EMI3) and an optional
check digit, with an optional - between the parts. The normative text, ISO/IEC 15118-2 Annex H,
is not freely available; the rules below are quoted from the protocols that reproduce it.
OCHP states
that its ContractId "must follow the specification for EMAID in ISO/IEC 15118-2 - Annex H".
- Check digit. OCHP: "The check digit is optional but highly recommended." Every port accepts
an id without it and computes it; when one is supplied it must match the computed digit, or the
id is rejected (
NL-TNM-C00122045-Xfails, the expected digit isK). OICP 2.3EvcoIDTypeis stricter: its ISO pattern ends with a mandatory check digit and requires theCprefix. Before sending an id in that field, check that its instance starts withC(an EMI3 id, or an ISO id that converts to EMI3) and render it with its check digit (toStringortoCompactString); rendering alone does not add a missingC. - Length. OCHP: "Each Contract-ID has a fixed length of at least fourteen and at most fifteen characters excluding the optional hyphens or seventeen respectively eighteen characters including the optional separators." The parsers accept the 14-character compact form (no check digit) and the 15-character one (with it).
- Case. OCHP: "The Contract-ID must be interpreted case insensitive." OICP's
EvcoIDfield notes that "Hubject will automatically convert all characters from lower case to upper case". Every port parses case-insensitively and renders in uppercase:nltnmc00122045kisNL-TNM-C00122045-K. - Separators. OCHP: "If the hyphenated representation is chosen, the separators must be set at
all three places." OICP's
EvcoIDTypepattern makes each hyphen optional on its own ([A-Za-z]{2}\-?[A-Za-z0-9]{3}\-?C[A-Za-z0-9]{8}\-?…) and says "The optional separating character must be “-“." Hubject's Plug and Charge EMAID article is stricter than OICP: its pattern/[a-z]{2}(-?)[\da-z]{3}\1[\da-z]{9}(\1[\da-z])?/ireuses the first separator for the others, so the hyphens are all present or all absent, and "the Hubject ecosystem will always remove Hyphens from the EMAID". The parsers of every port are lenient: each of the three hyphens is optional independently of the others, so ids with mixed separator placement are accepted. Any other separator (*, a space, a doubled hyphen) is rejected. A mixed form such asNL-TNMC00122045Kmatches neither the OCHP rule nor Hubject's pattern: render the id in one consistent form (toStringortoCompactString) before sending it.
| Input | Parsed (ISO and EMI3) | Note |
|---|---|---|
NL-TNM-C00122045-K |
NL-TNM-C00122045-K |
canonical hyphenated form (18 characters) |
NLTNMC00122045K |
NL-TNM-C00122045-K |
canonical compact form (15 characters) |
NLTNMC00122045 |
NL-TNM-C00122045-K |
compact without check digit (14 characters), digit computed |
nl-tnm-c00122045-k |
NL-TNM-C00122045-K |
tolerated: lowercase |
NL-TNMC00122045K |
NL-TNM-C00122045-K |
tolerated: mixed separators |
NLTNM-C00122045-K |
NL-TNM-C00122045-K |
tolerated: mixed separators |
NL-TNM-C00122045 |
NL-TNM-C00122045-K |
tolerated: hyphenated without check digit |
NL-TNM-C00122045-X |
rejected | wrong check digit |
NL*TNM*C00122045*K |
rejected | * is a DIN separator only |
To send an id in a protocol that wants a given form, render it rather than forwarding the input:
| Form | Scala, Java, TypeScript | Go | PHP |
|---|---|---|---|
| hyphenated, with check digit | toString |
String() |
toString(), __toString() |
| compact, with check digit (15) | toCompactString |
ToCompactString() |
toCompactString() |
| compact, without check digit (14) | toCompactStringWithoutCheckDigit |
ToCompactStringWithoutCheckDigit() |
toCompactStringWithoutCheckDigit() |
A stricter, opt-in separator policy (consistent or compact only) is tracked in #127; the default parsing stays lenient.
References:
- OCHP — ContractId (or EVCO-ID)
- OICP 2.3 —
EvcoIDType - Hubject — E-Mobility Authentication Identifier (EMAID)
- OCHP historical EV-ID validator (GPL-licensed; linked for reference only, no code or algorithm is taken from it)
- ISO/IEC 15118-2:2014, Annex H "Specification of Identifiers" (normative, not freely available)
- Renovate manages GitHub Actions, Gradle, npm, sbt/Scala, and
mise.tomltool versions (.github/renovate.json). mise.tomluses simplified version formats: major.minor for sbt/gradle (e.g.,2.0,9.7), major only for Java/Node (e.g.,21,24). SeeAGENTS.mdfor configuration details.- CI validates Gradle Wrapper integrity on every run (
gradle/actions/wrapper-validation). - Gradle distribution integrity is pinned with
distributionSha256Suminjava/gradle/wrapper/gradle-wrapper.properties. .github/workflows/dependency-submission.ymlsubmits the resolved Gradle dependency graph (transitive dependencies and build plugins included) to GitHub onmain; GitHub parses the npm, Composer, Go and Actions manifests itself.- Pull requests get a dependency review gate (
actions/dependency-review-action, high+ in any scope): theTrusted dependency reviewcommit status, computed frommainby.github/workflows/trusted-dependency-review.yml(seeCONTRIBUTING.md); Dependabot alerts covermaincontinuously. - OWASP Dependency-Check scans the full Java dependency set weekly on
main(and on demand) in.github/workflows/security.yml; it is not a pull request gate.
Run from java/:
./gradlew check
./gradlew javadocJar sourcesJar
./gradlew publishToMavenLocalmobilityid4j is published to the Maven Central Portal through the nmcp Gradle plugin; details in java/README.md.
- Java, TypeScript and PHP are released together by the manually dispatched
Releaseworkflow (.github/workflows/release.yml): it validatesCHANGELOG.mdand.github/release-notes/X.Y.Z.md, publishesmobilityid4jto Maven Central,@juherr/mobilityidto npm and thephp/split to thejuherr/mobility-id-phpmirror that Packagist follows, then creates the signedvX.Y.Ztag and the GitHub Release. - Go is released from
go/vX.Y.Ztags (.github/workflows/release-go.yml). - Procedure and required secrets:
CONTRIBUTING.md.
- Repository-level license:
LICENSE - Original Scala license file preserved at:
scala/LICENSE
Many thanks to the original Mobility ID Utils authors and contributors at The New Motion (now Shell Recharge Solutions EU) for creating and open-sourcing the Scala implementation that this repository builds upon.