Currently there is no way to enforce or check integrity of resources being imported as an ESModule.
There is an existing SRI Standard at W3C which outlines cryptographic hashing functions, an algorithm for response verification, and defines an integrity attribute which is utilized by various elements in HTML. There is an MDN Article on SRI that does a great job of covering some of the higher level benefits as well as provides examples of SRI being used to verify resource in script tags.
There have been a number of discussions at TC39 that have resulted in the committee holding the opinion that Integrity data belongs out of band. There are a number of reasons for this, module cycles and maintainability being the some of the easier to explain.
WICG is already incubating the Import Map proposal, but the explainer outlines that integrity is currently out of scope. There is a possibility that an integrity map and an import map could merge into a single manifest, but it would appear that it should be explored and spec’d on its own merits first.
A straw proposal for syntax below
{
"https://example.com/example-framework.js": "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
}
The left hand side is the resource, the right hand side the SRI. This would scale to various resource types, not limited to JavaScript. it could integrate into the existing integrity checks already in HTML for any resources in the map. I would imagine that it would likely support all the types of meta data currently support by the integrity attribute
As we see more adoption of modules in JavaScript and individuals consuming resources VIA HTTPS URLs I think having a mechanism for integrity checks with be extremely important, having a standard mechanism for this even more so.
Thoughts?