diff --git a/helpers/get_place.lua b/helpers/get_place.lua new file mode 100644 index 0000000..d60dbc0 --- /dev/null +++ b/helpers/get_place.lua @@ -0,0 +1,25 @@ + +function _G.get_place () + --[[ + -- Doesn't work for https stuff + local response = send_request({ + method = "GET", + uri = "https://ifconfig.me/", + headers = { + ["accept"] = "text/plain", + }, + body = "" + }) + local place = response.body + ]] + + -- Ideally, this would be a raw request, like above + local cmd = "curl ifconfig.me" + local file = assert(io.popen(cmd, 'r')) + local place = assert(file:read('*a')) + file:close() + + log.info("Current place: " .. place) + + return place +end \ No newline at end of file diff --git a/keys/connect_profile.lua b/keys/connect_profile.lua new file mode 100644 index 0000000..b910c4a --- /dev/null +++ b/keys/connect_profile.lua @@ -0,0 +1,36 @@ +function keys.connect_profile (data) + + local result = {} + + local profile_uuid = data.uuid + result.profile = profile_uuid + + content.write_file(profile_uuid, profile_uuid, { + type = "profile", + name = data.name + }) + + if data.sign_public_key then + local sign_pub_id = uuid.v4() + + content.write_file(profile_uuid, uuid.v4(), { + type = "key", + kind = "sign_public", + }, data.sign_public_key) + + result.sign_public_key = sign_pub_id + end + + if data.place then + local place_id = uuid.v4() + + content.write_file(profile_uuid, uuid.v4(), { + type = "place", + host = data.place, + }) + + result.place = place_id + end + + return result +end \ No newline at end of file diff --git a/keys/get_profile_data.lua b/keys/get_profile_data.lua new file mode 100644 index 0000000..00ab8f8 --- /dev/null +++ b/keys/get_profile_data.lua @@ -0,0 +1,24 @@ +function keys.get_profile_data () + + local data = {} + local uuid, name = keys.get_profile() + log.debug("UUID: " .. tostring(uuid)) + + data.sign_public_key = content.walk_documents(uuid, + function (file_uuid, header, body) + if header.model == "key" + and header.kind == "sign_private" + then return body end + end + ) + + data.place = content.walk_documents(uuid, + function (file_uuid, header, body) + if header.model == "place" then + return header.host + end + end + ) + + return data +end \ No newline at end of file diff --git a/keys/mod.lua b/keys/mod.lua index 3da6632..2bc3054 100644 --- a/keys/mod.lua +++ b/keys/mod.lua @@ -4,5 +4,7 @@ require "keys.get_private_key" require "keys.verify_http_signature" require "keys.sign_http_message" require "keys.witness_document" +require "keys.connect_profile" +require "keys.get_profile_data" return keys \ No newline at end of file diff --git a/mod.lua b/mod.lua index 452183b..79d930b 100644 --- a/mod.lua +++ b/mod.lua @@ -11,5 +11,6 @@ _G.keys = require "keys.mod" require "loaders.package" theme_loader = require "loaders.themes" class_loader = require "loaders.styles" -require "helpers/render" -require "helpers/send_request" +require "helpers.render" +require "helpers.send_request" +require "helpers.get_place"