ASN.1 uses the name DER Distinguished Encoding Rules for this purpose.
There are some other edgecases that you aren't considering (or that I missed)
Min and Max integer values - JavaScript has some pretty tight limits here
Keys should be in lexicographic order — you might want to be more specific. Is there a permitted subset of Unicode? Which normalization rule must be used?