From 9144dbd13f02215a424f7cdf8ec78c59463b5a19 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Mon, 21 Jul 2025 00:27:59 +0300 Subject: [bin] [api] Supports and resolves base64 encoded fingerprints --- api/index.js | 2 ++ bin/ak-ns | 4 ++++ lib/_ak_ns | 31 ++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/api/index.js b/api/index.js index e9c2eb0..f22d448 100755 --- a/api/index.js +++ b/api/index.js @@ -2,6 +2,7 @@ const http = require("node:http"); const welcomeMessage = require("./routes/default/index.js"); const getAKNSKey = require("./routes/getAKNSKey/index.js"); +const getAKNSKeyFromBase = require("./routes/getAKNSKeyFromBase/index.js"); const getNodeInfo = require('./routes/getNodeInfo/index.js'); const getPeers = require('./routes/getPeers/index.js'); const getIPFSHash = require('./routes/getIPFSHash/index.js'); @@ -70,6 +71,7 @@ function getRoutes(req, res) case 'remote_node_info': getRemoteNodeInfo(req, res); break; case 'remote_peers': getRemotePeers(req, res); break; case 'ns_get': getAKNSKey(req, res); break; + case 'ns_get_base': getAKNSKeyFromBase(req, res); break; default: notImplemented(req, res); } } diff --git a/bin/ak-ns b/bin/ak-ns index f638e07..080538c 100755 --- a/bin/ak-ns +++ b/bin/ak-ns @@ -32,6 +32,8 @@ ## -pn, --publish2name Publishes value to name ## -pz, --publish-zchain Publishes zchain ## -pc, --publish-config Publishes config +## -ek, --encode-key Encodes a key to Base64 +## -dk, --decode-key Decodes a key from Base64 ## fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) @@ -51,6 +53,8 @@ then -ll | --list-long) shift; _ak_ns_list_long; exit;; -rn | --resolve-name) shift; _ak_ns_resolve_from_name $1; exit;; -rk | --resolve-key) shift; _ak_ns_resolve_from_key $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;; -pn | --publish2name) shift; _ak_ns_publish2name $1 $2; exit;; -pz | --publish-zchain) _ak_ns_publish_zchain; exit;; diff --git a/lib/_ak_ns b/lib/_ak_ns index 683f572..f412c93 100755 --- a/lib/_ak_ns +++ b/lib/_ak_ns @@ -56,7 +56,12 @@ function _ak_ns_list(){ } function _ak_ns_list_long(){ - _ak_gpg_list_secret_keys_long | grep '@keynames.kaos.kaos' + _ak_gpg_list_secret_keys_long \ + | grep '@keynames.kaos.kaos' \ + | while read key name + do + printf '%s %s %s\n' "${key}" "$(_ak_ns_encode_key ${key})" "${name}" + done } function _ak_ns_resolve_from_key(){ @@ -76,6 +81,30 @@ function _ak_ns_resolve_from_key(){ _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key} } +function _ak_ns_encode_key(){ + # $1; exit;; + if [ -z $1 ] || [ ! -n "$1" ] + then + _ak_log_error "No key was given" + exit 1 + fi + key="$1" + _ak_log_info "${key} was given" + printf '%s' "$(echo -n ${key}|xxd -r -p|base64)" +} + +function _ak_ns_decode_key(){ + # $1; exit;; + if [ -z $1 ] || [ ! -n "$1" ] + then + _ak_log_error "No key was given" + exit 1 + fi + key="$1" + _ak_log_info "${key} was given" + printf '%s' "$(echo -n ${key}|base64 -d|xxd -p|tr '[:lower:]' '[:upper:]')" +} + function _ak_ns_resolve_from_name(){ # $1; exit;; if [ -z $1 ] || [ ! -n "$1" ] -- cgit v1.2.3