aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2025-07-22 02:29:12 +0300
committerkaotisk <kaotisk@arching-kaos.org>2025-07-22 02:29:12 +0300
commitde3fab3c70befe6920d5436ce0bef62f3e70ba29 (patch)
tree63af5d628c62c846a436d006674ddc66f80137ea
parentfd12421d9e9589cc8d68a8a64bc2630266e3288f (diff)
downloadarching-kaos-tools-de3fab3c70befe6920d5436ce0bef62f3e70ba29.tar.gz
arching-kaos-tools-de3fab3c70befe6920d5436ce0bef62f3e70ba29.tar.bz2
arching-kaos-tools-de3fab3c70befe6920d5436ce0bef62f3e70ba29.zip
[api+ns] ns tool outputs JSON format and it's used for the API
-rw-r--r--api/routes/getAKNSKey/index.js7
-rw-r--r--api/routes/getAKNSKeyFromBase/index.js7
-rwxr-xr-xbin/ak-ns2
-rwxr-xr-xlib/_ak_ns17
4 files changed, 23 insertions, 10 deletions
diff --git a/api/routes/getAKNSKey/index.js b/api/routes/getAKNSKey/index.js
index c5adff0..5e78f81 100644
--- a/api/routes/getAKNSKey/index.js
+++ b/api/routes/getAKNSKey/index.js
@@ -13,7 +13,7 @@ const config = require("../../config.js");
function replyIfOkay(key, res)
{
const program = "ak-ns";
- const command = spawn(program, ["-rk", key]);
+ const command = spawn(program, ["-rj", key]);
var buffer = "";
command.stdout.on("data", data => {
buffer += data;
@@ -29,10 +29,7 @@ function replyIfOkay(key, res)
if (code === 0){
buffer = buffer.trim()
res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({
- key:`${key}`,
- resolved:`${buffer}`
- }));
+ res.end(`${buffer}`);
} else {
res.writeHead(404, {'Content-Type': 'application/json'});
res.end({"error":"unreachable"});
diff --git a/api/routes/getAKNSKeyFromBase/index.js b/api/routes/getAKNSKeyFromBase/index.js
index 587314a..7da3d9b 100644
--- a/api/routes/getAKNSKeyFromBase/index.js
+++ b/api/routes/getAKNSKeyFromBase/index.js
@@ -35,7 +35,7 @@ function replyIfOkay(key, res)
const base64String = key;
const decodedHexString = decodeBase64ToHex(base64String);
formatted_key = decodedHexString.toUpperCase();
- const command = spawn(program, ["-rk", `${formatted_key}`]);
+ const command = spawn(program, ["-rj", `${formatted_key}`]);
var buffer = "";
command.stdout.on("data", data => {
@@ -52,10 +52,7 @@ function replyIfOkay(key, res)
if (code === 0){
buffer = buffer.trim()
res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({
- key:`${formatted_key}`,
- resolved:`${buffer}`
- }));
+ res.end(`${buffer}`);
} else {
res.writeHead(404, {'Content-Type': 'application/json'});
res.end(JSON.stringify({error:"unreachable"}));
diff --git a/bin/ak-ns b/bin/ak-ns
index 4238250..4e08cfc 100755
--- a/bin/ak-ns
+++ b/bin/ak-ns
@@ -30,6 +30,7 @@
## -rk, --resolve-key <key> Resolves value from key
## -rp, --resolve-key-proof <key> Resolves value from key and provides
## an akfs_map_v3 to clear signed proof
+## -rj, --resolve-key-json <key> Resolves a key to a JSON format
## -p, --publish <key> <value> Publishes value to key
## -pn, --publish2name <name> <value> Publishes value to name
## -pz, --publish-zchain Publishes zchain
@@ -56,6 +57,7 @@ then
-rn | --resolve-name) shift; _ak_ns_resolve_from_name $1; exit;;
-rk | --resolve-key) shift; _ak_ns_resolve_from_key $1; exit;;
-rp | --resolve-key-proof) shift; _ak_ns_resolve_from_key_with_proof $1; exit;;
+ -rj | --resolve-key-json) shift; _ak_ns_resolve_from_key_with_proof_json $1; exit;;
-ek | --encode-key) shift; _ak_ns_encode_key $1; exit;;
-dk | --decode-key) shift; _ak_ns_decode_key $1; exit;;
-p | --publish) shift; _ak_ns_publish $1 $2; exit;;
diff --git a/lib/_ak_ns b/lib/_ak_ns
index 8afef83..3499232 100755
--- a/lib/_ak_ns
+++ b/lib/_ak_ns
@@ -99,6 +99,23 @@ function _ak_ns_resolve_from_key_with_proof(){
cat ${AK_NS_DIR}/${key}.map
}
+function _ak_ns_resolve_from_key_with_proof_json(){
+ # $1; exit;;
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_log_error "No key was given"
+ exit 1
+ fi
+ key="$1"
+ json=$(_ak_ns_resolve_from_key_with_proof $key | while read proof resolved; do printf '{"fingerprint":"%s","proof":"%s","resolved":"%s"}' "$1" "$proof" "$resolved"; done)
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "Something happened"
+ exit 1
+ fi
+ echo $json
+}
+
function _ak_ns_encode_key(){
# $1; exit;;
if [ -z $1 ] || [ ! -n "$1" ]