function verifyRequestAuthenticity(req,required_headers = []){
  // Extract the signature data
  let parsed = httpSignature.parseRequest(req);
  /* TODO: check that parsed throws no errors rather than letting the
     default error handler show the user a stack trace */

  // Get the key ID and convert it into a slash-free filename
  let key_file = parsed.keyId.replace("/","_");
  let pubkeydata = (function(){
    try{
      // attempt to read the public key
      return fs.readFileSync(key_dir+'/'+key_file+'.pem', 'ascii');
    } catch (e) {
      return null;
    }
  })();

  /* Populate "info" with a failed state so if we fall through to the return,
     the system fails closed */
  let info = { passed_signature: false,
               passed: false,
               key_id: parsed.keyId,
               request_headers: parsed.params.headers,
               required_headers: required_headers
             };
  if(pubkeydata != null){
    // If the public key was loaded, check the signature against it
    info.passed_signature = httpSignature.verifySignature(parsed, pubkeydata);

    // Check that the signature coveres the required parts of the request
    info.passed = info.passed_signature &&
      required_headers.every(h=>info.request_headers.includes(h))
  }
  return info;
}
/* API Authentication function

   req: the request
   required_headers: an array of strings containing the header names that were
     expected to have been signed.

   Returns an object that contains details of the verification process.
   the .verified element of that object should be checked: it's set to true IFF
   the signature was valid and covered all the required headers.

   This is used to authenticate the API request. Authorization is
   implied by the presence of a known key. Future changes may create
   per-api permissions, in which case an authorization function will
   be needed in addition to this authentication function.
*/
API Authentication function
req: the request
required_headers: an array of strings containing the header names that were
expected to have been signed.

Returns an object that contains details of the verification process.
the .verified element of that object should be checked: it's set to true IFF
the signature was valid and covered all the required headers.

This is used to authenticate the API request. Authorization is
implied by the presence of a known key. Future changes may create
per-api permissions, in which case an authorization function will
be needed in addition to this authentication function.
API Authentication function req : the request required_headers : an array of strings containing the header names that were expected to have been signed . Returns an object that contains details of the verification process . the . verified element of that object should be checked : it ' s set to true IFF the signature was valid and covered all the required headers . This is used to authenticate the API request . Authorization is implied by the presence of a known key . Future changes may create per - api permissions in which case an authorization function will be needed in addition to this authentication function .
function verifyRequestAuthenticity(req,required_headers = []){
  let parsed = httpSignature.parseRequest(req);
  let key_file = parsed.keyId.replace("/","_");
  let pubkeydata = (function(){
    try{
      return fs.readFileSync(key_dir+'/'+key_file+'.pem', 'ascii');
    } catch (e) {
      return null;
    }
  })();
  let info = { passed_signature: false,
               passed: false,
               key_id: parsed.keyId,
               request_headers: parsed.params.headers,
               required_headers: required_headers
             };
  if(pubkeydata != null){
    info.passed_signature = httpSignature.verifySignature(parsed, pubkeydata);
    info.passed = info.passed_signature &&
      required_headers.every(h=>info.request_headers.includes(h))
  }
  return info;
}
function verifyRequestAuthenticity ( req , required_headers = [ ] ) { let parsed = httpSignature . parseRequest ( req ) ; let key_file = parsed . keyId . replace ( "/" , "_" ) ; let pubkeydata = ( function ( ) { try { return fs . readFileSync ( key_dir + '/' + key_file + '.pem' , 'ascii' ) ; } catch ( e ) { return null ; } } ) ( ) ; let info = { passed_signature : false , passed : false , key_id : parsed . keyId , request_headers : parsed . params . headers , required_headers : required_headers } ; if ( pubkeydata != null ) { info . passed_signature = httpSignature . verifySignature ( parsed , pubkeydata ) ; info . passed = info . passed_signature && required_headers . every ( h => info . request_headers . includes ( h ) ) } return info ; }
API Authentication function
req: the request
required_headers: an array of strings containing the header names that were
expected to have been signed.
API Authentication function req : the request required_headers : an array of strings containing the header names that were expected to have been signed .
// Extract the signature data /* TODO: check that parsed throws no errors rather than letting the
     default error handler show the user a stack trace */ // Get the key ID and convert it into a slash-free filename // attempt to read the public key /* Populate "info" with a failed state so if we fall through to the return,
     the system fails closed */ // If the public key was loaded, check the signature against it // Check that the signature coveres the required parts of the request