aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapi/index.js1
-rw-r--r--api/lib/akLogMessage/index.js4
-rw-r--r--api/lib/checkIfAllowedIP/index.js5
-rw-r--r--api/lib/storeIncomingIP/index.js4
-rw-r--r--api/routes/announceZBlock/index.js4
-rw-r--r--api/routes/announceZChain/index.js4
-rw-r--r--api/routes/default/index.js5
-rw-r--r--api/routes/getChunk/index.js5
-rw-r--r--api/routes/getIPFSHash/index.js23
-rw-r--r--api/routes/getInnerIPFSContent/index.js4
-rw-r--r--api/routes/getLeaf/index.js4
-rw-r--r--api/routes/getMap/index.js5
-rw-r--r--api/routes/getNodeInfo/index.js4
-rw-r--r--api/routes/getPeers/index.js4
-rw-r--r--api/routes/getRemoteNodeInfo/index.js8
-rw-r--r--api/routes/getRemotePeers/index.js7
-rw-r--r--api/routes/getSBlock/index.js8
-rw-r--r--api/routes/getZChain/index.js5
-rw-r--r--api/routes/showEntriesFile/index.js6
-rw-r--r--api/routes/showNSEntriesFile/index.js6
-rw-r--r--api/validators/ZblockValidator/index.js4
-rw-r--r--api/validators/ZchainValidator/index.js5
-rwxr-xr-xbin/ak-mine2
-rwxr-xr-xbin/ak-ns61
-rwxr-xr-xbin/ak-profile2
-rwxr-xr-xbin/ak-transactions2
-rwxr-xr-xlib/_ak_ns202
27 files changed, 345 insertions, 49 deletions
diff --git a/api/index.js b/api/index.js
index f5cf8c8..f2ca713 100755
--- a/api/index.js
+++ b/api/index.js
@@ -59,6 +59,7 @@ function getRoutes(req, res)
case 'peers': getPeers(req, res); break;
case 'node_info': getNodeInfo(req, res); break;
case 'ipfs_hash': getIPFSHash(req, res); break;
+ case 'ipfs': getIPFSHash(req, res); break;
case 'zlatest': getZlatest(req, res); break;
case 'sblock': getSblock(req, res); break;
case 'slatest': getSlatest(req, res); break;
diff --git a/api/lib/akLogMessage/index.js b/api/lib/akLogMessage/index.js
index 6dfb8f2..59a1300 100644
--- a/api/lib/akLogMessage/index.js
+++ b/api/lib/akLogMessage/index.js
@@ -1,7 +1,8 @@
const { spawn } = require('child_process');
const config = require('../../config')
-module.exports = (type, message) => {
+function akLogMessage(type, message)
+{
const command = spawn(
"ak-log",
["-m", "ak-daemon", type, message]
@@ -26,3 +27,4 @@ module.exports = (type, message) => {
console.log(`child process exited with code ${code}`);
});
};
+module.exports = akLogMessage;
diff --git a/api/lib/checkIfAllowedIP/index.js b/api/lib/checkIfAllowedIP/index.js
index d9693d9..2e50418 100644
--- a/api/lib/checkIfAllowedIP/index.js
+++ b/api/lib/checkIfAllowedIP/index.js
@@ -1,8 +1,9 @@
-
-module.exports = (address) => {
+function checkIfAllowedIP(address)
+{
var test_cjdns = /^fc[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/
var test_yggdrasil = /^2[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/
var test_yggdrasil_sub = /^3[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/
return (test_cjdns.test(address) || test_yggdrasil.test(address) || test_yggdrasil_sub.test(address)) ? true : false;
};
+module.exports = checkIfAllowedIP;
diff --git a/api/lib/storeIncomingIP/index.js b/api/lib/storeIncomingIP/index.js
index c45def6..72273d0 100644
--- a/api/lib/storeIncomingIP/index.js
+++ b/api/lib/storeIncomingIP/index.js
@@ -1,6 +1,8 @@
const fs = require("node:fs");
const config = require("../../config");
-module.exports = (ip_address) => {
+function storeIncomingIP(ip_address)
+{
fs.appendFileSync(`${config.peersDir}/incomingRequests`, `${ip_address}\n`);
}
+module.exports = storeIncomingIP;
diff --git a/api/routes/announceZBlock/index.js b/api/routes/announceZBlock/index.js
index 254e1dc..dc1467a 100644
--- a/api/routes/announceZBlock/index.js
+++ b/api/routes/announceZBlock/index.js
@@ -13,7 +13,8 @@
*
*/
const getvalidity = require('../../validators/ZblockValidator')
-module.exports = (req, res) => {
+function announceZBlock(req, res)
+{
console.log(req);
if ( (req.body.zblock) && typeof req.body.zblock === "string" && req.body.zblock.length === 46 ){
let zblock = req.body.zblock;
@@ -27,3 +28,4 @@ module.exports = (req, res) => {
res.send({error:"Invalid data"});
}
}
+module.exports = announceZBlock;
diff --git a/api/routes/announceZChain/index.js b/api/routes/announceZChain/index.js
index 0261aa4..ca23a72 100644
--- a/api/routes/announceZChain/index.js
+++ b/api/routes/announceZChain/index.js
@@ -14,7 +14,8 @@
*/
const getNSvalidity = require('../../validators/ZchainValidator');
-module.exports = (req, res) => {
+function announceZChain(req, res)
+{
console.log(req);
if ( (req.body.zchain) && typeof req.body.zchain === "string" && req.body.zchain.length === 62 ){
let zchain = req.body.zchain;
@@ -30,3 +31,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"Invalid data"}));
}
}
+module.exports = announceZChain;
diff --git a/api/routes/default/index.js b/api/routes/default/index.js
index 24e334b..db1495f 100644
--- a/api/routes/default/index.js
+++ b/api/routes/default/index.js
@@ -1,7 +1,8 @@
const rsettings = require('../../settings');
const settings = rsettings();
-module.exports = (req, res) => {
+function welcome(req, res)
+{
res.writeHead(404, { 'Content-Type': 'application/json'});
res.end(JSON.stringify({
message:"Hello! Welcome to Arching Kaos API! See available routes below!",
@@ -36,4 +37,4 @@ module.exports = (req, res) => {
}
}));
}
-
+module.exports = welcome;
diff --git a/api/routes/getChunk/index.js b/api/routes/getChunk/index.js
index 6106aad..dc86bd8 100644
--- a/api/routes/getChunk/index.js
+++ b/api/routes/getChunk/index.js
@@ -7,7 +7,8 @@
const fs = require('fs');
const config = require("../../config.js");
-module.exports = (req, res) => {
+function getChunk(req, res)
+{
var args = req.url.split("/");
var hash = args[3];
regex= /[a-f0-9]{128}/
@@ -39,4 +40,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"No hash"}));
}
}
-
+module.exports = getChunk;
diff --git a/api/routes/getIPFSHash/index.js b/api/routes/getIPFSHash/index.js
index f412c80..d1bdc5f 100644
--- a/api/routes/getIPFSHash/index.js
+++ b/api/routes/getIPFSHash/index.js
@@ -1,26 +1,29 @@
const { spawn } = require('child_process');
const fs = require("fs");
const config = require("../../config");
+const akLogMessage = require("../../lib/akLogMessage");
+akLogMessage('lol');
/*
- * Returns a cached zblock
+ * Returns a cached ipfs_hash
*
* Returns:
* - JSON object
*
*/
-function fetchIPFShash(zblock, res)
+function fetchIPFShash(ipfs_hash, res)
{
regex= /Qm[A-Za-z0-9]{44}/;
- if (regex.test(zblock)){
- const path = `${config.ipfsArtifactsDir}/${zblock}`;
+ if (regex.test(ipfs_hash)){
+ const path = `${config.ipfsArtifactsDir}/${ipfs_hash}`;
console.log(path)
try
{
if(fs.existsSync(path))
{
- res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
+ res.writeHead(200); //, {'Content-Type': 'application/json'});
+ // res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
+ res.end(fs.readFileSync(path));
}
else
{
@@ -41,9 +44,10 @@ function fetchIPFShash(zblock, res)
}
};
-module.exports = (req, res) => {
+function getIPFSHash(req, res)
+{
var args = req.url.split("/");
- if ( (args[2] === 'ipfs_hash') && args[3] && typeof args[3] === "string" && args[3].length === 46 ){
+ if ( (args[2] === 'ipfs_hash'||args[2] === 'ipfs') && args[3] && typeof args[3] === "string" && args[3].length === 46 ){
regex= /Qm[A-Za-z0-9]{44}/;
if (regex.test(args[3]))
{
@@ -66,6 +70,7 @@ module.exports = (req, res) => {
else
{
res.writeHead(404, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({error:"Invalid data: no valid zblock was provided"}));
+ res.end(JSON.stringify({error:"Invalid data: no valid ipfs_hash was provided"}));
}
}
+module.exports = getIPFSHash;
diff --git a/api/routes/getInnerIPFSContent/index.js b/api/routes/getInnerIPFSContent/index.js
index 721e836..a45b507 100644
--- a/api/routes/getInnerIPFSContent/index.js
+++ b/api/routes/getInnerIPFSContent/index.js
@@ -15,7 +15,8 @@ function fetchZblock(zblock, res){
res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
};
-module.exports = (req, res) => {
+function getInnerIPFSContent(req, res)
+{
console.log(req.query)
if ( (req.query.ipfs) && typeof req.query.ipfs === "string" && req.query.ipfs.length === 46 ){
let ipfs = req.query.ipfs;
@@ -36,3 +37,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"Invalid data: no valid zblock was provided"}));
}
}
+module.exports = getInnerIPFSContent;
diff --git a/api/routes/getLeaf/index.js b/api/routes/getLeaf/index.js
index 8855712..5afbe70 100644
--- a/api/routes/getLeaf/index.js
+++ b/api/routes/getLeaf/index.js
@@ -7,7 +7,8 @@
const fs = require('fs');
const config = require("../../config.js");
-module.exports = (req, res) => {
+function getLeaf(req, res)
+{
var args = req.url.split("/");
var hash = args[3];
regex= /[a-f0-9]{128}/
@@ -40,3 +41,4 @@ module.exports = (req, res) => {
}
}
+module.exports = getLeaf;
diff --git a/api/routes/getMap/index.js b/api/routes/getMap/index.js
index 791afb5..23b4e58 100644
--- a/api/routes/getMap/index.js
+++ b/api/routes/getMap/index.js
@@ -7,7 +7,8 @@
const fs = require('fs');
const config = require("../../config.js");
-module.exports = (req, res) => {
+function getMap(req, res)
+{
var args = req.url.split("/");
var hash = args[3];
regex= /[a-f0-9]{128}/
@@ -39,4 +40,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"No hash"}));
}
}
-
+module.exports = getMap;
diff --git a/api/routes/getNodeInfo/index.js b/api/routes/getNodeInfo/index.js
index 27006ae..b267749 100644
--- a/api/routes/getNodeInfo/index.js
+++ b/api/routes/getNodeInfo/index.js
@@ -1,6 +1,7 @@
const { spawn } = require('child_process');
-module.exports = (req, res) => {
+function getNodeInfo(req, res)
+{
const command = spawn("ak-config", ["--get-published"]);
var buffer = "";
command.stdout.on("data", data => {
@@ -22,3 +23,4 @@ module.exports = (req, res) => {
console.log(`child process exited with code ${code}`);
});
};
+module.exports = getNodeInfo;
diff --git a/api/routes/getPeers/index.js b/api/routes/getPeers/index.js
index b18a015..47c075d 100644
--- a/api/routes/getPeers/index.js
+++ b/api/routes/getPeers/index.js
@@ -1,7 +1,8 @@
const config = require('../../config');
const fs = require('fs');
-module.exports = (req, res) => {
+function getPeers(req, res)
+{
const path = config.peersFile;
if(fs.existsSync(path)){
res.writeHead(200, {'Content-Type': 'application/json'});
@@ -11,3 +12,4 @@ module.exports = (req, res) => {
res.end({"error":"No peers :("})
}
};
+module.exports = getPeers;
diff --git a/api/routes/getRemoteNodeInfo/index.js b/api/routes/getRemoteNodeInfo/index.js
index a88f528..4b766c0 100644
--- a/api/routes/getRemoteNodeInfo/index.js
+++ b/api/routes/getRemoteNodeInfo/index.js
@@ -8,7 +8,8 @@ const { spawn } = require('child_process');
const config = require("../../config.js");
const checkIfAllowedIP = require('../../lib/checkIfAllowedIP/index.js');
-module.exports = (req, res) => {
+function getRemoteNodeInfo(req, res)
+{
var args = req.url.split("/");
var ip = "";
if ( args.length === 4 )
@@ -23,15 +24,12 @@ module.exports = (req, res) => {
command.stdout.on("data", data => {
buffer = buffer + data;
});
-
command.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
-
command.on('error', (error) => {
console.log(`error: ${error.message}`);
});
-
command.on("close", code => {
res.writeHead(200, { 'Content-Type': 'application/json'});
res.end(buffer);
@@ -44,4 +42,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"No IP"}));
}
}
-
+module.exports = getRemoteNodeInfo;
diff --git a/api/routes/getRemotePeers/index.js b/api/routes/getRemotePeers/index.js
index c75a98a..dac0f04 100644
--- a/api/routes/getRemotePeers/index.js
+++ b/api/routes/getRemotePeers/index.js
@@ -8,7 +8,8 @@ const { spawn } = require('child_process');
const config = require("../../config.js");
const checkIfAllowedIP = require('../../lib/checkIfAllowedIP/index.js');
-module.exports = (req, res) => {
+function getRemotePeers(req, res)
+{
var args = req.url.split("/");
var ip = "";
if ( args.length === 4 )
@@ -22,15 +23,12 @@ module.exports = (req, res) => {
command.stdout.on("data", data => {
buffer = buffer + data;
});
-
command.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
-
command.on('error', (error) => {
console.log(`error: ${error.message}`);
});
-
command.on("close", code => {
if ( code === 0 )
{
@@ -52,3 +50,4 @@ module.exports = (req, res) => {
}
}
+module.exports = getRemotePeers;
diff --git a/api/routes/getSBlock/index.js b/api/routes/getSBlock/index.js
index 2fb8c80..85565b2 100644
--- a/api/routes/getSBlock/index.js
+++ b/api/routes/getSBlock/index.js
@@ -7,7 +7,8 @@ const { spawn } = require('child_process');
const fs = require('fs');
const config = require("../../config.js");
-module.exports = (req, res) => {
+function getSBlock(req, res)
+{
var args = req.url.split("/");
var sblock = args[3];
regex= /[a-f0-9]{128}/
@@ -20,16 +21,13 @@ module.exports = (req, res) => {
command.stdout.on("data", data => {
response_string += data;
});
-
command.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
-
command.on('error', (error) => {
console.log(`error: ${error.message}`);
response_string={err:"error.message"};
});
-
command.on("close", code => {
if ( code === 0 ) {
res.writeHead(200, {'Content-Type': 'application/json'});
@@ -49,4 +47,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"No hash"}));
}
}
-
+module.exports = getSBlock;
diff --git a/api/routes/getZChain/index.js b/api/routes/getZChain/index.js
index 6df2d7f..934b436 100644
--- a/api/routes/getZChain/index.js
+++ b/api/routes/getZChain/index.js
@@ -7,7 +7,8 @@ const { spawn } = require('child_process');
* - A JSON array representing the nodes' arching-kaos-zchain
*
*/
-module.exports = (req, res) => {
+function getZChain(req, res)
+{
const command = spawn("ak", ["zchain", "--crawl"]);
response_string = "";
command.stdout.on("data", data => {
@@ -27,3 +28,5 @@ module.exports = (req, res) => {
console.log(`child process exited with code ${code}`);
});
};
+
+module.exports = getZChain;
diff --git a/api/routes/showEntriesFile/index.js b/api/routes/showEntriesFile/index.js
index 3dd1c40..1246460 100644
--- a/api/routes/showEntriesFile/index.js
+++ b/api/routes/showEntriesFile/index.js
@@ -8,7 +8,9 @@ const config = require('../../config');
* - the file, it's already in JSON format.
*
*/
-module.exports = (req, res) => {
+function showEntriesFile(req, res)
+{
var data = JSON.parse(fs.readFileSync(config.blocksFile));
res.send(data);
-}; \ No newline at end of file
+};
+module.exports = showEntriesFile;
diff --git a/api/routes/showNSEntriesFile/index.js b/api/routes/showNSEntriesFile/index.js
index 745ddee..cc5edf6 100644
--- a/api/routes/showNSEntriesFile/index.js
+++ b/api/routes/showNSEntriesFile/index.js
@@ -9,7 +9,9 @@ const config = require('../../config');
* - the file, it's already in JSON format.
*
*/
-module.exports = (req, res) => {
+function showNSEntriesFile(req, res)
+{
var data = JSON.parse(fs.readFileSync(config.pairsFile));
res.send(data);
-}; \ No newline at end of file
+};
+module.exports = showNSEntriesFile;
diff --git a/api/validators/ZblockValidator/index.js b/api/validators/ZblockValidator/index.js
index e3656d6..e1cfd3f 100644
--- a/api/validators/ZblockValidator/index.js
+++ b/api/validators/ZblockValidator/index.js
@@ -64,7 +64,8 @@ function continuethings(exitcode,sh,res){
* We send the data tested and the exit code to continuethings()
*
*/
-module.exports = (ch, res) => {
+function ZblockValidator(ch, res)
+{
const command = spawn("ak",["zchain", "--crawl", ch]);
response_string = "";
command.stdout.on("data", data => {
@@ -85,3 +86,4 @@ module.exports = (ch, res) => {
continuethings(code,ch,res);
});
};
+module.exports = ZblockValidator;
diff --git a/api/validators/ZchainValidator/index.js b/api/validators/ZchainValidator/index.js
index 80939d0..a788719 100644
--- a/api/validators/ZchainValidator/index.js
+++ b/api/validators/ZchainValidator/index.js
@@ -64,7 +64,8 @@ function continuethings(exitcode,sh,res){
* We send the data tested and the exit code to continuethings()
*
*/
-module.exports = (ch, res) => {
+function ZchainValidator(ch, res)
+{
const command = spawn("ak",["zchain", "--crawl", "-n", ch]);
response_string = "";
command.stdout.on("data", data => {
@@ -85,3 +86,5 @@ module.exports = (ch, res) => {
continuethings(code,ch,res);
});
};
+
+module.exports = ZchainValidator;
diff --git a/bin/ak-mine b/bin/ak-mine
index 42202d3..72f90a3 100755
--- a/bin/ak-mine
+++ b/bin/ak-mine
@@ -32,7 +32,7 @@ descriptionString="Sblock mining"
source $AK_LIBDIR/_ak_lib_load
_ak_lib_load _ak_log
_ak_lib_load _ak_script
-_ak_lib_load _ak_utils
+_ak_lib_load _ak_datetime
gather_zblocks(){
if [ "$(cat $AK_ZBLOCKSFILE | jq -r '.[].zblock' | wc -l)" -ne 0 ]
diff --git a/bin/ak-ns b/bin/ak-ns
new file mode 100755
index 0000000..f638e07
--- /dev/null
+++ b/bin/ak-ns
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+##
+## AKNS is a name system for Arching Kaos
+##
+## Usage:
+##
+## -h, --help Prints this help message
+## -c, --create <name> Creates a new key-pair with name
+## -l, --list List names
+## -ll, --list-long List names with keys
+## -rn, --resolve-name <name> Resolves value from name
+## -rk, --resolve-key <key> Resolves value from key
+## -p, --publish <key> <value> Publishes value to key
+## -pn, --publish2name <name> <value> Publishes value to name
+## -pz, --publish-zchain Publishes zchain
+## -pc, --publish-config Publishes config
+##
+fullprogrampath="$(realpath $0)"
+PROGRAM=$(basename $0)
+descriptionString="Name system"
+
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+_ak_lib_load _ak_script
+_ak_lib_load _ak_ns
+
+if [ ! -z $1 ]
+then
+ case $1 in
+ -h | --help) _ak_usage; exit;;
+ -c | --create) shift; _ak_ns_create $1; exit;;
+ -l | --list) shift; _ak_ns_list; exit;;
+ -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;;
+ -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;;
+ -pc | --publish-config) _ak_ns_publish_config; exit;;
+ * ) _ak_usage;;
+ esac
+else _ak_usage
+fi
diff --git a/bin/ak-profile b/bin/ak-profile
index 891dbac..02ed5a7 100755
--- a/bin/ak-profile
+++ b/bin/ak-profile
@@ -46,7 +46,7 @@ ZPROFILEDIR="$AK_WORKDIR/profile"
source $AK_LIBDIR/_ak_lib_load
_ak_lib_load _ak_log
_ak_lib_load _ak_script
-_ak_lib_load _ak_utils
+_ak_lib_load _ak_datetime
_ak_lib_load _ak_ipfs
_ak_lib_load _ak_gpg
_ak_lib_load _ak_zblock
diff --git a/bin/ak-transactions b/bin/ak-transactions
index fe00411..8af4530 100755
--- a/bin/ak-transactions
+++ b/bin/ak-transactions
@@ -27,7 +27,7 @@ descriptionString="Transactions module"
source $AK_LIBDIR/_ak_lib_load
_ak_lib_load _ak_log
_ak_lib_load _ak_script
-_ak_lib_load _ak_utils
+_ak_lib_load _ak_datetime
_ak_lib_load _ak_ipfs
_ak_lib_load _ak_gpg
_ak_lib_load _ak_zblock
diff --git a/lib/_ak_ns b/lib/_ak_ns
new file mode 100755
index 0000000..683f572
--- /dev/null
+++ b/lib/_ak_ns
@@ -0,0 +1,202 @@
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+_ak_lib_load _ak_script
+_ak_lib_load _ak_gpg
+_ak_lib_load _ak_zchain
+
+AK_NS_DIR="${AK_WORKDIR}/akns"
+
+_ak_check_and_create_dir ${AK_NS_DIR}
+
+function _ak_ns_create(){
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_log_error "No key name was given"
+ exit 1
+ fi
+ if [ "$(echo -n $1| tr -d '[:alnum:]')" != "" ]
+ then
+ _ak_log_error "Name $1 is not allowed. Use only letters and numbers"
+ exit 1
+ fi
+ keyname="$1@keynames.kaos.kaos"
+ _ak_log_info "Checking for ${keyname}..."
+ _ak_gpg_list_secret_keys_long | grep ${keyname} > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ _ak_log_info "Creating ${keyname}"
+ _ak_gpg_create_key ${keyname}
+ else
+ _ak_log_error "Name ${keyname} already exists"
+ exit 1
+ fi
+}
+
+function _ak_ns_list(){
+ _ak_gpg_list_secret_keys_long | grep '@keynames.kaos.kaos' | cut -d ' ' -f 2
+}
+
+function _ak_ns_list_long(){
+ _ak_gpg_list_secret_keys_long | grep '@keynames.kaos.kaos'
+}
+
+function _ak_ns_resolve_from_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"
+ if [ ! -f ${AK_NS_DIR}/${key} ]
+ then
+ _ak_log_error "${key} was not found"
+ exit 1
+ fi
+ _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key}
+}
+
+function _ak_ns_resolve_from_name(){
+ # $1; exit;;
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_log_error "No name was given"
+ exit 1
+ fi
+ key_name="$1"
+ _ak_log_info "${key_name} was given"
+ if [ "${key_name}" == "zchain" ] || [ "${key_name}" == "zconfig" ]
+ then
+ _ak_log_info "${key_name} search on local secret keychain"
+ key="$(_ak_gpg_list_secret_keys_long | grep ${key_name}'@keynames.kaos.kaos' | cut -d ' ' -f 1)"
+ if [ ! -n "${key}" ]
+ then
+ _ak_log_error "${key_name} was not found locally"
+ exit 1
+ fi
+ _ak_ns_resolve_from_key ${key}
+ fi
+}
+
+function _ak_ns_publish(){
+ # $1 $2; exit;;
+ _ak_not_implemented "${FUNCNAME}"
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_log_error "No key was given"
+ exit 1
+ fi
+ if [ ! -z $2 ] || [ ! -n "$2" ]
+ then
+ _ak_log_error "No value was given"
+ exit 1
+ fi
+ if [ "$(echo -n $1| sed -e 's/[A-F0-9]\{40\}//')" != "" ]
+ then
+ _ak_log_error "$1 is not a valid key"
+ exit 1
+ fi
+ if [ "$(echo -n $2| sed -e 's/[a-f0-9]\{128\}//')" != "" ]
+ then
+ _ak_log_error "$2 is not a valid hash"
+ exit 1
+ fi
+ key="$(_ak_gpg_list_secret_keys | grep $1)"
+ value="$2"
+ if [ ! -n "${key}" ]
+ then
+ _ak_log_error "Key $1 was not found"
+ exit 1
+ fi
+ _ak_log_info "Key $1 was found"
+ if [ ! -z $2 ] || [ -n "$2" ]
+ then
+ _ak_gpg_sign_clear_with_key $key
+ fi
+}
+
+function _ak_ns_publish2name(){
+ # $1 $2; exit;;
+ _ak_not_implemented "${FUNCNAME}"
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_log_error "No key name was given"
+ exit 1
+ fi
+ if [ "$(echo -n $1| tr -d '[:alnum:]')" != "" ]
+ then
+ _ak_log_error "Name $1 is not allowed. Use only letters and numbers"
+ exit 1
+ fi
+ key="$(_ak_gpg_list_secret_keys_long | grep $1'@keynames.kaos.kaos' | cut -d ' ' -f 1)"
+ if [ ! -n "${key}" ]
+ then
+ _ak_log_error "No key found with name $1"
+ exit 1
+ fi
+ _ak_ns_publish ${key} $2
+}
+
+function _ak_ns_publish_zchain(){
+ zlatest="$(_ak_zchain_get_latest)"
+ zchain_key="$(_ak_gpg_list_secret_keys_long | grep 'zchain@keynames.kaos.kaos' | cut -d ' ' -f 1)"
+ if [ ! -n "${zchain_key}" ]
+ then
+ _ak_log_warning "zchain_key not there"
+ _ak_log_info "Creating zchain_key"
+ _ak_ns_create zchain
+ fi
+ zchain_key="$(_ak_gpg_list_secret_keys_long | grep 'zchain@