2
0

validation-data.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 CommonTestData = require('./common-data');
  11. var zkProof = require('../../lib/index');
  12. var mathematical = require('scytl-mathematical');
  13. module.exports = ValidationTestData;
  14. /**
  15. * Provides the input validation data needed by the zero-knowledge proof service
  16. * unit tests.
  17. */
  18. function ValidationTestData() {
  19. var proofService = zkProof.newService();
  20. var mathRandomGenerator = mathematical.newService().newRandomGenerator();
  21. var commonTestData = new CommonTestData();
  22. var nonObject_ = 999;
  23. var emptyObject_ = {};
  24. var nonPolicy_ = zkProof.newService();
  25. var nonSecureRandomService_ = zkProof.newService();
  26. var nonMathematicalService_ = zkProof.newService();
  27. var nonMessageDigestService_ = zkProof.newService();
  28. var nonBoolean_ = '';
  29. var nonNumber_ = '';
  30. var nonPositiveNumber_ = 0;
  31. var nonString_ = 999;
  32. var emptyString_ = '';
  33. var nonJsonString_ = 'Not a JSON string';
  34. var nonArray_ = '';
  35. var emptyArray_ = [];
  36. var nonObjectArray_ = ['1', '2', '3'];
  37. var nonStringArray_ = [];
  38. nonStringArray_.push(0);
  39. nonStringArray_.push(1);
  40. nonStringArray_.push(2);
  41. var nonFunction_ = '';
  42. var nonAuxiliaryData_ = 999;
  43. var nonProofObject_ = mathematical.newService();
  44. var group = commonTestData.getGroup();
  45. var secret = mathRandomGenerator.nextExponent(group);
  46. var gamma = group.generator.exponentiate(secret);
  47. var proof =
  48. proofService.newSchnorrProofHandler(group).generate(secret, gamma, '');
  49. var proofHash_ = proof.hash;
  50. var proofValues_ = proof.values;
  51. var preComputation = proofService.newSchnorrProofHandler(group).preCompute();
  52. var preComputationExponents_ = preComputation.exponents;
  53. var preComputationPhiOutputs_ = preComputation.phiOutputs;
  54. this.getNonObject = function() {
  55. return nonObject_;
  56. };
  57. this.getEmptyObject = function() {
  58. return emptyObject_;
  59. };
  60. this.getNonPolicy = function() {
  61. return nonPolicy_;
  62. };
  63. this.getNonSecureRandomService = function() {
  64. return nonSecureRandomService_;
  65. };
  66. this.getNonMathematicalService = function() {
  67. return nonMathematicalService_;
  68. };
  69. this.getNonMessageDigestService = function() {
  70. return nonMessageDigestService_;
  71. };
  72. this.getNonBoolean = function() {
  73. return nonBoolean_;
  74. };
  75. this.getNonNumber = function() {
  76. return nonNumber_;
  77. };
  78. this.getNonPositiveNumber = function() {
  79. return nonPositiveNumber_;
  80. };
  81. this.getNonString = function() {
  82. return nonString_;
  83. };
  84. this.getEmptyString = function() {
  85. return emptyString_;
  86. };
  87. this.getNonJsonString = function() {
  88. return nonJsonString_;
  89. };
  90. this.getNonArray = function() {
  91. return nonArray_;
  92. };
  93. this.getEmptyArray = function() {
  94. return emptyArray_;
  95. };
  96. this.getNonObjectArray = function() {
  97. return nonObjectArray_;
  98. };
  99. this.getNonStringArray = function() {
  100. return nonStringArray_;
  101. };
  102. this.getNonFunction = function() {
  103. return nonFunction_;
  104. };
  105. this.getNonAuxiliaryData = function() {
  106. return nonAuxiliaryData_;
  107. };
  108. this.getNonProofObject = function() {
  109. return nonProofObject_;
  110. };
  111. this.getProofHash = function() {
  112. return proofHash_;
  113. };
  114. this.getProofValues = function() {
  115. return proofValues_;
  116. };
  117. this.getPreComputationExponents = function() {
  118. return preComputationExponents_;
  119. };
  120. this.getPreComputationPhiOutputs = function() {
  121. return preComputationPhiOutputs_;
  122. };
  123. }