v4 signing

Please feel free to try it out and help me debug it if needed. If you need any explanation please be my guest.

It is based on @mludvig 's branch. Thanks a lot for kick-starting it.