Signing data structures the right way

How do you package data before feeding it into a cryptographic algorithm, like&#xA;Sign, Encrypt, MAC or Hash? This question has lingered for decades&#xA;without a sufficient solution.&#xA;There are at least two important problems to solve. First,&#xA;the encoding ought to produce canonical outputs,&#xA;as systems like Bitcoin have struggled when&#xA;two different encodings decode to the same…