User protocol upgrade and js client lib. (#191)

* Unified js client lib for browser and nodejs.
* Client lib multiple connections support.
* Implemented server challenge response.
* Contract guid and version validation.
* Server key validation.
* User json message encoding improvements.
This commit is contained in:
Ravin Perera
2020-12-11 11:02:58 +05:30
committed by GitHub
parent b77a3fc924
commit f2ed9040c0
34 changed files with 1202 additions and 905 deletions

View File

@@ -227,4 +227,23 @@ namespace crypto
return hash;
}
std::string generate_uuid()
{
std::string rand_bytes;
random_bytes(rand_bytes, 16);
// Set bits for UUID v4 variant 1.
uint8_t *uuid = (uint8_t *)rand_bytes.data();
uuid[6] = (uuid[8] & 0x0F) | 0x40;
uuid[8] = (uuid[8] & 0xBF) | 0x80;
std::string hex;
util::bin2hex(
hex,
reinterpret_cast<const unsigned char *>(rand_bytes.data()),
rand_bytes.length());
return hex.substr(0, 8) + "-" + hex.substr(8, 4) + "-" + hex.substr(12, 4) + "-" + hex.substr(16, 4) + "-" + hex.substr(20);
}
} // namespace crypto