ProofOfExistence.sol 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. pragma solidity ^0.4.0;
  2. import "../Rejector.sol";
  3. /*
  4. * Proof of Existence example contract
  5. * see https://medium.com/zeppelin-blog/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05
  6. */
  7. contract ProofOfExistence is Rejector {
  8. mapping (bytes32 => bool) public proofs;
  9. // store a proof of existence in the contract state
  10. function storeProof(bytes32 proof) {
  11. proofs[proof] = true;
  12. }
  13. // calculate and store the proof for a document
  14. function notarize(string document) {
  15. var proof = calculateProof(document);
  16. storeProof(proof);
  17. }
  18. // helper function to get a document's sha256
  19. function calculateProof(string document) constant returns (bytes32) {
  20. return sha256(document);
  21. }
  22. // check if a document has been notarized
  23. function checkDocument(string document) constant returns (bool) {
  24. var proof = calculateProof(document);
  25. return hasProof(proof);
  26. }
  27. // returns true if proof is stored
  28. function hasProof(bytes32 proof) constant returns (bool) {
  29. return proofs[proof];
  30. }
  31. }