Validates a Direct Trust email address. To be clear, validation with this library guarantees that an email address is a DirectTrust address. It does not guarantee that messages sent to that address will be delivered or that the receiving system will process it correctly.
const {Validator} = require('validate-direct-address');
async main() {
const validator = new Validator();
await validator.isValid('[email protected]'); // Returns 'false' because the domain certificate does not exist
await validator.isValid('[email protected]'); // Returns 'true' because the domain certificate exists.
await validator.assertValid('[email protected]'); // Throws an error
}
We strive for 100% test coverage. To run them, run yarn test
or npm run test
.
Assuming a direct address of "[email protected]":
- do a DNS lookup for a
cert
record forjsmith.direct.hospital.org
. (Note that you must replace the '@' with a '.'. If this succeeds, go to step 4. - do a DNS lookup for a
cert
record fordirect.hospital.org
. (Not the removal of the RHS of the address.) If this succeds, go to step 4. - If you haven't yet gotten the certificate, exit.
- Using node crypto tools, decode the content of the cert record. You may need to play around with it to get it to work, but it is in X.509 format.
- The issuer "cn" of the certificate must be one of the organizations listed in the directTrust trust bundle, which can be downloaded from https://directtrust.org/trust-bundles/accredited-trust-bundle