From 6dae2f07493c7500664cb6b1e231e37685934cc9 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 20 Oct 2023 12:55:05 +0000 Subject: [PATCH] Expose the server's public key. Going to use this to make local accounts visible externally and also to make it easy to show the room link. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4557 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.js.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ssb.js.c b/src/ssb.js.c index 55982359..a08dff6f 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -96,6 +96,21 @@ static JSValue _tf_ssb_getIdentities(JSContext* context, JSValueConst this_val, return result; } +static JSValue _tf_ssb_getServerIdentity(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) +{ + JSValue result = JS_NewArray(context); + tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId); + if (ssb) + { + char id[k_id_base64_len] = { 0 }; + if (tf_ssb_whoami(ssb, id, sizeof(id))) + { + result = JS_NewString(context, id); + } + } + return result; +} + static JSValue _tf_ssb_getAllIdentities(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { JSValue result = JS_NewArray(context); @@ -1459,6 +1474,7 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb) JS_SetPropertyStr(context, object, "appendMessageWithIdentity", JS_NewCFunction(context, _tf_ssb_appendMessageWithIdentity, "appendMessageWithIdentity", 3)); /* Does not require an identity. */ + JS_SetPropertyStr(context, object, "getServerIdentity", JS_NewCFunction(context, _tf_ssb_getServerIdentity, "getServerIdentity", 0)); JS_SetPropertyStr(context, object, "getAllIdentities", JS_NewCFunction(context, _tf_ssb_getAllIdentities, "getAllIdentities", 0)); JS_SetPropertyStr(context, object, "getMessage", JS_NewCFunction(context, _tf_ssb_getMessage, "getMessage", 2)); JS_SetPropertyStr(context, object, "blobGet", JS_NewCFunction(context, _tf_ssb_blobGet, "blobGet", 1));