async validateMessageSignature (address, signature) {
    return new Promise((resolve, reject) => {
      db.get(address, (error, value) => {
        if (value === undefined) {
          return reject(new Error('Not found'))
        } else if (error) {
          return reject(error)
        }

        value = JSON.parse(value)

        if (value.messageSignature === 'valid') {
          return resolve({
            registerStar: true,
            status: value
          })
        } else {
          let isValid = false

          // Check if request timeStamp is < that five minutes
          if (isExpired(value.requestTimeStamp)) {
            // Set validation window to zero
            value.validationWindow = 0
            // Inform expired validation message
            value.messageSignature = 'Validation expired!'
          } else {
            // CRITERION: The request must be configured with a limited validation window of five minutes.
            value.validationWindow = Math.floor(
              (value.requestTimeStamp - (Date.now() - 5 * 60 * 1000)) / 1000
            )

            try {
              // CRITERION: The application will validate their request and grant access to register a star.
              isValid = bitcoinMessage.verify(value.message, address, signature)
            } catch (error) {
              isValid = false
            }

            value.messageSignature = isValid ? 'valid' : 'invalid'
          }

          db.put(address, JSON.stringify(value))

          return resolve({
            registerStar: !isExpired(value.requestTimeStamp) && isValid,
            status: value
          })
        }
      })
    })
  }
// CRITERION: Web API post endpoint validates message signature with JSON response.
Web API post endpoint validates message signature with JSON response.
Web API post endpoint validates message signature with JSON response .
async validateMessageSignature (address, signature) {
    return new Promise((resolve, reject) => {
      db.get(address, (error, value) => {
        if (value === undefined) {
          return reject(new Error('Not found'))
        } else if (error) {
          return reject(error)
        }
        value = JSON.parse(value)
        if (value.messageSignature === 'valid') {
          return resolve({
            registerStar: true,
            status: value
          })
        } else {
          let isValid = false
          if (isExpired(value.requestTimeStamp)) {
            value.validationWindow = 0
            value.messageSignature = 'Validation expired!'
          } else {
            value.validationWindow = Math.floor(
              (value.requestTimeStamp - (Date.now() - 5 * 60 * 1000)) / 1000
            )
            try {
              isValid = bitcoinMessage.verify(value.message, address, signature)
            } catch (error) {
              isValid = false
            }
            value.messageSignature = isValid ? 'valid' : 'invalid'
          }
          db.put(address, JSON.stringify(value))
          return resolve({
            registerStar: !isExpired(value.requestTimeStamp) && isValid,
            status: value
          })
        }
      })
    })
  }
async validateMessageSignature ( address , signature ) { return new Promise ( ( resolve , reject ) => { db . get ( address , ( error , value ) => { if ( value === undefined ) { return reject ( new Error ( 'Not found' ) ) } else if ( error ) { return reject ( error ) } value = JSON . parse ( value ) if ( value . messageSignature === 'valid' ) { return resolve ( { registerStar : true , status : value } ) } else { let isValid = false if ( isExpired ( value . requestTimeStamp ) ) { value . validationWindow = 0 value . messageSignature = 'Validation expired!' } else { value . validationWindow = Math . floor ( ( value . requestTimeStamp - ( Date . now ( ) - 5 * 60 * 1000 ) ) / 1000 ) try { isValid = bitcoinMessage . verify ( value . message , address , signature ) } catch ( error ) { isValid = false } value . messageSignature = isValid ? 'valid' : 'invalid' } db . put ( address , JSON . stringify ( value ) ) return resolve ( { registerStar : ! isExpired ( value . requestTimeStamp ) && isValid , status : value } ) } } ) } ) }
CRITERION: Web API post endpoint validates message signature with JSON response.
CRITERION : Web API post endpoint validates message signature with JSON response .
// Check if request timeStamp is < that five minutes // Set validation window to zero // Inform expired validation message // CRITERION: The request must be configured with a limited validation window of five minutes. // CRITERION: The application will validate their request and grant access to register a star.