This worked for me
const openpgp = require('openpgp');
const fs = require('fs');
const fetch = require('node-fetch');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const domain = 'https://localhost';
(async () => {
const json = {
version: "1.0.0",
domain: domain,
verify_token: crypto.randomUUID(),
verify_token_expiry: ((Date.now() + (2*60*1000)) / 1000)
}
const passphrase = "ada@passbolt.com";
const clientPrivateKeyArmored = fs.readFileSync('./private.client', {encoding: 'utf8',});
const clientPrivateKey = await openpgp.decryptKey({
privateKey: await openpgp.readPrivateKey({armoredKey: clientPrivateKeyArmored}),
passphrase
});
const serverPublicKeyArmored = fs.readFileSync('./public.server', {encoding: 'utf8',});
const serverPublicKey = await openpgp.readKey({armoredKey: serverPublicKeyArmored});
let encrypted = await openpgp.encrypt({
message: await openpgp.createMessage({text: JSON.stringify(json)}),
encryptionKeys: serverPublicKey,
signingKeys: clientPrivateKey,
});
const response = await fetch(domain + '/auth/jwt/login.json', {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"user_id": "f848277c-5398-58f8-a82a-72397af2d450",
"challenge": encrypted
})
});
const body = await response.text();
console.log(body);
})();