The tilde key exists in the key map here: https://developer.apple.com/library/archive/technotes/tn2450...
You can see how I did mine here if you're interested: https://github.com/bruse/dotfiles/tree/main/macOS (I suspect com.local.KeyRemapping.plist is most interesting, but the key layout file is there too, with some comments on how it was generated).