The toolkit depends on python wrapper of ursa-bbs-signatures library. Install it using
python3 -m pip install ursa-bbs-signatures
The toolkit consider the following entities
A signer that signs a JSON string. In the rest of this document will use as a reference the following JSON string:
{
"owner": "Device1-admin",
"measurements":{
"temperature":"30oC",
"humidity":"60%"
}
}
The signature is done using a BBS private key. A BBS public private key pair can be constructed as follows:
bls_key_pair = BlsKeyPair.generate_g2()
bbs_public_key = bls_key_pair.public_key
bbs_secret_key = bls_key_pair.secret_key
Then, a JSON string can be signed as follows:
bbs_signer = Signer(public_key=bbs_public_key,secret_key=bbs_secret_key)
bbs_signature = bbs_signer.sign_json(json_string)
print(base64.b64encode(bbs_signature))
A prover reveals a subset of the JSON string proving at the same time a ZKP that proves it knows the signature generated by the signer that corresponds to the original JSON string. The knowledge of the proof means that the prover has not modified the original string (otherwise it wouldn't be possible for the prover to know the proof). In order to guide the toolkit which portion of the JSON string to reveal, frames are used. A frame is constructed by removing from the JSON string all values, as well as the keys we do not want to appear in the revealed string. For example, the following frame can be used for revealing only the value of the ``temperature'' key:
{
"measurements":{
"temperature":"",
}
}
A ZKP is constructed as follows:
bbs_prover = Prover()
claims, revealed_message, zkp = bbs_prover.generate_zkp(public_key=bbs_public_key, message=json_message, frame=json_frame, signature=bbs_signature)
This outputs a number (claims) which corresponds to the number of ``hidden claim'', the revealed JSON string, and the corresponding ZKP. The number of hidden claims are required during the verification phase.
A verifier receives as input a partial JSON string, an integer number that corresponds to the number of hidden claims, as well as ZKP, and verifies the correctness of the ZKP. The verification process is implemented as follows:
bbs_verifier = Verifier()
verification = bbs_verifier.verify_zkp(public_key=bbs_public_key, message=revealed_message, claims=claims, zkp=zkp )
print(verification)