I am attempting to make a new account, I listed the directory
and got a new nonce
Here is what i have made so far:
import * as jose from './jose/index.js';
export async function createAccount(nonce, newAccountUrl) {
const { publicKey, privateKey } = await jose.generateKeyPair('ES256', { extractable: true });
const jwk = await jose.exportJWK(publicKey);
const payload = { termsOfServiceAgreed: true };
const protectedHeader = {
alg: "ES256",
jwk,
nonce: nonce,
url: newAccountUrl,
};
const jws = new jose.FlattenedSign(new TextEncoder().encode(JSON.stringify(payload)));
jws.setProtectedHeader(protectedHeader);
const signed = await jws.sign(privateKey);
const request = {
method: 'POST',
headers: {
'Content-Type': 'application/jose+json'
},
body: JSON.stringify(signed) // accepted answer
};
const response = await fetch(newAccountUrl, request);
if (!response.ok) {
const errorData = await response.text();
throw new Error(errorData || 'Unknown error');
}
return {
answer: { account: await response.json(), location: response.headers.get('location') },
nonce: response.headers.get('replay-nonce')
};
}
JWT.io says that the signature is valid and no matter what I do I always get the same response.
request {
method: 'POST',
headers: { 'Content-Type': 'application/jose+json' },
body: {
signature: 'LuF2LdSkmGaX3YzxWnDZwqJJ9JguXFttwADcrilGmuTpBNPiVvRs7dg6ZugleF9PIcbAOU7UYD1Snf4o9FO4_w',
payload: 'eyJ0ZXJtc09mU2VydmljZUFncmVlZCI6dHJ1ZX0',
protected: 'eyJhbGciOiJFUzI1NiIsImp3ayI6eyJrdHkiOiJFQyIsIngiOiJVTHBzTm45azZsWDBlVTVjcnhuckR2YVhxYW5zVndtMnZ1TWpLUTRPancwIiwieSI6Ijk2Y1pqeFhvWUl6RnVqUG1mVVpYLVZFeURUd05FOS1JeDRQZXBEVk5XVFUiLCJjcnYiOiJQLTI1NiJ9LCJub25jZSI6IkZXOVN3TFNMRTRYZXFTNkwyRUliTGtlQl9kTnV4d3ZucWI5eUc1TExFY2FxSkRPczEzbyIsInVybCI6Imh0dHBzOi8vYWNtZS1zdGFnaW5nLXYwMi5hcGkubGV0c2VuY3J5cHQub3JnL2FjbWUvbmV3LWFjY3QifQ'
}
}
Error: {
"type": "urn:ietf:params:acme:error:malformed",
"detail": "Parse error reading JWS",
"status": 400
}
Edit:
If you are using Javascript and looking for help, You may find this useful: lets-encrypt.js
At the time of writing it only creates accounts