Code Explain
- Under "./data", there are several owners, and each owner has two directories:
- localStorage is used to store "DID"
- TPM is used to store "DID-privateKey" and "vc"
- owner.py:
- create a new owner
- create directory
- create keypair, and save private one in TPM
- create did document, and save it in localStorage and blockchain
- item.py:
- create a new item
- create keypair, and save private one in TPM
- create did document, and save it in localStorage and blockchain
- vc.py:
- VC_transfer
- VC_revoke
How to execute?
- go to directory pi@raspberrypi:~/nmlab/src
- type
python main.py
- The format of input statement:
- if you want factory A to create a new item, please input
createAnItem factory_A_did
- if the ownership of item I is transfered from organization A to organization B and having an issuer C, please input
transfer organization_A_did organization_B_did issuer_C_did item_I_did
- if a gun is assembled by item 1, item 2, item 3 in the facory A and having an issuer C, please input
assemble factory_A_did issuer_C_did item_I1_did item_I2_did item_I3_did
- if the item I need to be revocated, please input
revoke organization_A_did item_I_did
The discription of VC type:
-
transfer (A sells i to D):
- holder: A
- issuer: MOD
- verifier: D
- (issuer encrypt doc with own private key)
- (holder decrypt doc with issuer's public key)
- system generate the current time
- holder "sign" vc with own private key
- verifier "verify" vc with holder's public key
- add vc(related to i)/private key from holder's TPM to verifier's TPM
- remove i's DID from holder's localStorage
-
revoke (Army revokes i):
- holder: Army
- issuer: MOD
- verifier: MOD
- (issuer encrypt doc with own private key)
- (holder decrypt doc with issuer's public key)
- holder encrypt vc with own private key
- verifier decrypt vc with holder's public key
- remove vc(related to i)/private key from holder's TPM
- remove i's DID from holder's localStorage# nmlab