Tiny steps toward getting away from one global identity.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3932 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-07-14 01:01:14 +00:00
parent ae5560f33a
commit f764007fc6
6 changed files with 220 additions and 5 deletions

View File

@ -1267,11 +1267,8 @@ static bool _tf_ssb_connection_box_stream_recv(tf_ssb_connection_t* connection)
return true;
}
void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message)
void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message)
{
char author[k_id_base64_len];
tf_ssb_id_bin_to_str(author, sizeof(author), ssb->pub);
char previous_id[crypto_hash_sha256_BYTES * 2];
int64_t previous_sequence = 0;
bool have_previous = tf_ssb_db_get_latest_message_by_author(ssb, author, &previous_sequence, previous_id, sizeof(previous_id));
@ -1304,7 +1301,7 @@ void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message)
uint8_t signature[crypto_sign_BYTES];
unsigned long long siglen;
bool valid = crypto_sign_detached(signature, &siglen, (const uint8_t*)json, len, ssb->priv) == 0;
bool valid = crypto_sign_detached(signature, &siglen, (const uint8_t*)json, len, private_key) == 0;
JS_FreeCString(context, json);
JS_FreeValue(context, jsonval);
@ -1342,6 +1339,13 @@ void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message)
JS_FreeValue(context, root);
}
void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message)
{
char author[k_id_base64_len];
tf_ssb_id_bin_to_str(author, sizeof(author), ssb->pub);
tf_ssb_append_message_with_keys(ssb, author, ssb->priv, message);
}
void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* reason)
{
tf_ssb_t* ssb = connection->ssb;
@ -1825,6 +1829,20 @@ void tf_ssb_generate_keys(tf_ssb_t* ssb)
crypto_sign_ed25519_keypair(ssb->pub, ssb->priv);
}
void tf_ssb_generate_keys_buffer(char* out_public, size_t public_size, char* out_private, size_t private_size)
{
uint8_t public[crypto_sign_PUBLICKEYBYTES];
uint8_t private[crypto_sign_SECRETKEYBYTES];
crypto_sign_ed25519_keypair(public, private);
uint8_t buffer[512];
base64c_encode(public, sizeof(public), buffer, sizeof(buffer));
snprintf(out_public, public_size, "%s.ed25519", buffer);
base64c_encode(private, sizeof(private), buffer, sizeof(buffer));
snprintf(out_private, private_size, "%s.ed25519", buffer);
}
void tf_ssb_set_trace(tf_ssb_t* ssb, tf_trace_t* trace)
{
ssb->trace = trace;