Does this have support for OpenPGP? If not, you might want to take a look at https://github.com/openpgpjs/openpgpjs which does all the heavily lifting for you. Although it would also be useful if it could talk to a locally running gpg-agent so it would work with smartcards/yubikeys etc.