const openpgp = require('openpgp');
(async () => {
const passphrase = `HAHAHA`; // what the private key is encrypted with
const {keys: [privateKey]} = await openpgp.key.readArmored(privateKeyPGP);
await privateKey.decrypt(passphrase);
const {data: cleartext} = await openpgp.sign({
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
privateKeys: [privateKey] // for signing
});
console.log(cleartext); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
console.log('end cleartext')
const verified = await openpgp.verify({
message: await openpgp.cleartext.readArmored(cleartext), // parse armored message
publicKeys: (await openpgp.key.readArmored(publicKeyPGP)).keys // for verification
});
const {valid} = verified.signatures[0];
if (valid) {
console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
} else {
throw new Error('signature could not be verified');
}
})();