Bloxberg proof of concept
Summary
This MR allow users to certify a single entity with the Bloxberg blockchain.
Tests are still missing.
Focus
-
Does the API look usable for other programmers?
Test Environment
-
Start your own CaosDB server and make sure that your pycaosdb.ini
will connect to it. -
Install this project with pip3 install .
-
Start Python shell and run:
import caosadvancedtools.bloxberg.bloxberg as blx
blx.demo_run()
-
Check in your CaosDB instance that the RecordTypes and Records look OK: https://localhost:10443/Entity/?query=FIND%20Bloxb* -
Verify the certificate (stored at /tmp/cert.json
or saved from the certificate Record) at https://certify.bloxberg.org/verify
Check List for the Author
-
All automated tests pass -
Reference related Issue: #34 (closed) -
Up-to-date CHANGELOG.md -
Annotations in code (Gitlab comments) - Intent of new code
- Problems with old code
- Why this implementation?
Check List for the Reviewer
-
I understand the intent of this MR -
All automated tests pass -
Up-to-date CHANGELOG.md -
The test environment setup works and the intended behavior is reproducible in the test environment -
In-code documentation and comments are up-to-date. -
Check: Are there spezifications? Are they satisfied?
For further good practices have a look at our review guidelines.
Edited by Alexander Schlemmer
Merge request reports
Activity
- src/caosadvancedtools/bloxberg/bloxberg.py 0 → 100644
118 def verify(self, certificate): 119 """Attempt to verify the certificate. 120 121 A certificate passes verification if the Bloxberg instance says it is good. Typical use cases may 122 also include the `validate` step to make sure that the certificate's original data exists and 123 contains what it claimed to contain when the certificate was created. 124 125 This method does nothing if the verification passes, else it raises an exception. 126 127 Parameters 128 ---------- 129 certificate : caosdb.Record 130 The BloxbergCertificate Record which shall be verified. 131 132 """ 133 raise NotImplementedError("Bloxberg first needs to implement a verification API method.") - src/caosadvancedtools/bloxberg/bloxberg.py 0 → 100644
79 The entity to be certified 80 81 Returns 82 ------- 83 out : caosdb.Record 84 A BloxbergCertificate Record with all the necessary Properties. 85 """ 86 # Calculate hash 87 pepper = str(secrets.randbits(1024)) 88 entity.retrieve() 89 hasher = hashlib.sha256() 90 hasher.update(pepper.encode(encoding="utf8")) 91 hasher.update(str(entity).encode(encoding="utf8")) 92 entity_hash = "0x" + hasher.hexdigest() 93 print(entity_hash) 94 pubkey = "0x9858eC18a269EE69ebfD7C38eb297996827DDa98" # TODO The key of the API server? - src/caosadvancedtools/bloxberg/bloxberg.py 0 → 100644
72 73 def certify(self, entity): 74 """Attempt to certify the given `entity` and return a certificate Record. 75 76 Parameters 77 ---------- 78 entity : caosdb.Entity 79 The entity to be certified 80 81 Returns 82 ------- 83 out : caosdb.Record 84 A BloxbergCertificate Record with all the necessary Properties. 85 """ 86 # Calculate hash 87 pepper = str(secrets.randbits(1024)) - src/caosadvancedtools/bloxberg/bloxberg.py 0 → 100644
171 if isinstance(entity, int): 172 entity = db.Entity(id=entity) 173 174 blx = Bloxberg() 175 print("Obtaining certificate...") 176 certificate = blx.certify(entity) 177 print("Certificate was successfully obtained.") 178 certificate.insert() 179 print("Certificate was stored in CaosDB.") 180 181 if json_filename: 182 with open(json_filename, "w") as json_file: 183 json_file.write(certificate.get_property("certificateJSON").value) 184 185 186 def demo_run(): added 1 commit
- 13f15963 - STY: Exclude autogenerated code from autopep8.
marked the checklist item Check in your CaosDB instance that the RecordTypes and Records look OK: https://localhost:10443/Entity/?query=FIND%20Bloxb* as completed
marked the checklist item Verify the certificate (stored at
/tmp/cert.json
or saved from the certificate Record) at https://certify.bloxberg.org/verify as completed
Please register or sign in to reply