validate.js 825 B

1234567891011121314151617181920212223242526
  1. function validateCredentials(credentials) {
  2. const certificate = credentials.certificates[0];
  3. if (credentials.key.fingerprint() !== certificate.key().fingerprint()) {
  4. throw new Error('certificate and key do not match');
  5. }
  6. const validity = certificate.validity();
  7. if (validity.notAfter.getTime() < Date.now()) {
  8. throw new Error('certificate has expired: ' + validity.notAfter.toJSON());
  9. }
  10. if (credentials.production !== undefined) {
  11. const environment = certificate.environment();
  12. if (
  13. (credentials.production && !environment.production) ||
  14. (!credentials.production && !environment.sandbox)
  15. ) {
  16. throw new Error(
  17. 'certificate does not support configured environment, production: ' + credentials.production
  18. );
  19. }
  20. }
  21. }
  22. module.exports = validateCredentials;