2
0

index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true */
  9. 'use strict';
  10. var MathematicalService = require('./service');
  11. var validator = require('./input-validator');
  12. module.exports = {
  13. /**
  14. * Creates a new MathematicalService object, which encapsulates a
  15. * mathematical service.
  16. *
  17. * @function newService
  18. * @global
  19. * @param {Object}
  20. * [options] An object containing optional arguments.
  21. * @param {SecureRandomService}
  22. * [options.secureRandomService=Created internally] The secure
  23. * random service to use.
  24. * @returns {MathematicalService} The new MathematicalService object.
  25. * @throws {Error}
  26. * If the input data validation fails.
  27. * @example <caption> How to use a provided secure random service, that was
  28. * initialized with a chosen seed</caption>
  29. *
  30. * var mathematical = require('scytl-mathematical');
  31. * var secureRandom = require('scytl-securerandom');
  32. *
  33. * var mySecureRandomService = secureRandom.newService({prngSeed: mySeed});
  34. *
  35. * var mathService_ = mathematical.newService({secureRandomService:
  36. * mySecureRandomService});
  37. */
  38. newService: function(options) {
  39. checkData(options);
  40. return new MathematicalService(options);
  41. }
  42. };
  43. function checkData(options) {
  44. options = options || {};
  45. if (typeof options.secureRandomService !== 'undefined') {
  46. validator.checkIsObjectWithProperties(
  47. options.secureRandomService,
  48. 'Secure random service object provided to mathematical service');
  49. }
  50. }