verifiable_data Class
Overview
The verifiable_data
class represents digitally signed data whose integrity can be cryptographically verified. It serves as the foundation for higher-level constructs like credentials and transactions, supporting multiple signatures through attached attestations.
Constructors
NOTE: verifiable_data
objects are created by gateway.sign()
or persona.sign()
methods. They cannot be constructed directly with a default constructor.
verifiable_data(const kc::serialized_data& serialized_verifiable_data)
Deserializes verifiable data from serialized_data
.
verifiable_data(const kc::serialized_data& serialized_verifiable_data)
Parameters:
-
serialized_verifiable_data
- Serialized verifiable data object
verifiable_data(const std::string& serialized_signed_data, kc::serialization_format format)
Deserializes verifiable data from a string.
verifiable_data(const std::string& serialized_signed_data,
kc::serialization_format format = kc::serialization_format::protobuf)
Parameters:
-
serialized_signed_data
- String serialization of verifiable data -
format
- Serialization format (defaults to protobuf)
Core Methods
cleartext()
Gets the original data as kc::serialized_data
.
kc::serialized_data cleartext() const
Returns: The original data as serialized_data
content()
Gets the original serialized data string. Equivalent to cleartext().content()
.
std::string content() const
Returns: The original data content string
Signature Management (Inherited from kc::verifiable)
Example Usage
#include <keychain/keychain_headers.hpp>
// Create verifiable data from a message
std::string message = "This is important data that needs to be verified";
verifiable_data vdata(message);
// Add application metadata
tag_set tags;
tags.set("document_type", "contract");
tags.set("version", "1.0");
vdata.set_tags(tags);
// Sign the data (this creates an attestation)
gateway gw;
persona my_persona = gw.get_default_persona();
verifiable_data signed_data = gw.sign(vdata, my_persona);
Multi-Signature Example
// Create multi-signature verifiable data using gateway.add_signature()
std::string contract_text = "Multi-party agreement terms...";
kc::serialized_data contract_data(contract_text);
// First party signs (creates the verifiable_data)
kc::verifiable_data signed_contract = gateway.sign(persona1, contract_data);
// Second party adds their signature to the existing signed data
kc::attestation second_signature = gateway.add_signature(signed_contract, persona2);
// Third party adds their signature
kc::attestation third_signature = gateway.add_signature(signed_contract, persona3);
// Now the contract has multiple signatures
std::cout << "Total signatures: " << signed_contract.num_attestations() << std::endl;
// Verify all signatures
std::vector<kc::verification_result> all_results = gateway.verify(persona1, signed_contract);
for (const auto& result : all_results) {
if (result.is_verified()) {
std::cout << "Valid signature found" << std::endl;
}
}
// Third party adds final signature
verifiable_data final_contract = gw.sign(signed_twice, persona3);
// Verify all signatures
verification_result result = final_contract.verify(gw);
if (result.is_valid() && final_contract.get_attestations().size() == 3) {
std::cout << "Contract valid with all three signatures" << std::endl;
}
See Also
-
credential - W3C verifiable credentials implementation
-
transaction - Consensus-based transactions
-
gateway - Main API for signing and verification
-
verification result - Verification results (C API)