diff options
52 files changed, 1001 insertions, 158 deletions
@@ -6,6 +6,9 @@ Arching Kaos Tools > Hint: Find the "Script usage" section for sum up of the scripts +> Disclaimer: Any use of "AI" tools upon this repository, is STRICTLY forbidden. +> This affects all commits and branches. + Introduction ------------ Tools that help to create a blockchain called `zchain` by preparing small JSON @@ -74,6 +77,7 @@ programs used are: - curl (v7.79.1) - git (v2.34.1) - which (v2.21) +- rlwrap (v0.46.2) - jq (v1.6) - nodejs (v16+) - npm (v9.5.0) @@ -104,6 +108,9 @@ git pull Uninstall --------- +> WARNING: It will REMOVE the whole $HOME/.arching-kaos directory but your GPG +> keyring. Proceed with caution! Back up if you want to. + Navigate to your cloned repository and execute the following command: ``` @@ -111,8 +118,6 @@ Navigate to your cloned repository and execute the following command: ``` This will output an archive with your aknet-gpg-keyring to your $HOME folder. -It will NOT remove your IPFS repository, neither is going to clean it. - Podman (or Docker) ------------------ There is a ContainerFile that you can use to build an image which you can then @@ -170,6 +175,8 @@ Utilities - ak-network # Network Tools (connect to, scan for, dump peers) - ak-node-info # Returns IPFS CID or IPNS key for your online config - ak-pkg # Package manager + - ak-fs # File system + - ak-ns # Name system - ak-sblock # sblock tools - ak-schain # schain tools - ak-zblock # zblock tools @@ -234,6 +241,7 @@ Libraries - lib/_ak_settings - lib/_ak_gpg - lib/_ak_fs + - lib/_ak_ns - lib/_ak_pkg - lib/_ak_zblock - lib/_ak_log @@ -393,3 +401,49 @@ $ ak pkg --help # --uninstall Uninstalls a module selected from a menu # ``` + +NS tools +-------- + - ak-ns + +```bash +$ ak ns --help +# ak-ns - Name system +# =================== +# +# 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 +# -ek, --encode-key <key> Encodes a key to Base64 +# -dk, --decode-key <base64 key> Decodes a key from Base64 +# +ns command finished +``` + +Donations +--------- +While this project is developed with enthusiasm and it uses the spare time of +the only developer that is coding for it, donations would help allocating more +time on the project instead of the developer looking for different occupations +to support their life and project. + +If you do appreciate the project's goals and the developers efforts towards it, +take your time and consider donating some satoshis to the developer via BTC at +the following address + +``` +bc1q70rgp65t7acfgpwp74m7vdz0g4eduxm6a43gd8 +``` + +Thank you! diff --git a/api/config.js b/api/config.js index 3fe7c0d..82f90b8 100644 --- a/api/config.js +++ b/api/config.js @@ -25,6 +25,7 @@ const config = { chunksDir: env.AK_CHUNKSDIR, leafsDir: env.AK_LEAFSDIR, mapsDir: env.AK_MAPSDIR, - printDebug: env.AK_DEBUG + printDebug: env.AK_DEBUG, + akNSDir: `${env.AK_WORKDIR}/akns` } module.exports = config; diff --git a/api/index.js b/api/index.js index f2ca713..6fd2066 100755 --- a/api/index.js +++ b/api/index.js @@ -1,6 +1,9 @@ const http = require("node:http"); +// Route functions 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'); @@ -13,6 +16,7 @@ const getSlatest = require('./routes/getSLatest/index.js'); const getRemoteNodeInfo = require('./routes/getRemoteNodeInfo/index.js'); const getRemotePeers = require('./routes/getRemotePeers/index.js'); +// Libraries const akLogMessage = require('./lib/akLogMessage'); const checkIfAllowedIP = require('./lib/checkIfAllowedIP/index.js'); const storeIncomingIP = require("./lib/storeIncomingIP/index.js"); @@ -68,6 +72,8 @@ function getRoutes(req, res) case 'map': getMap(req, res); break; 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/api/routes/getAKNSKey/index.js b/api/routes/getAKNSKey/index.js new file mode 100644 index 0000000..5e78f81 --- /dev/null +++ b/api/routes/getAKNSKey/index.js @@ -0,0 +1,75 @@ +const { spawn } = require('child_process'); +const fs = require('fs'); +const config = require("../../config.js"); + +/* + * Gets the local latest zblock AKA zlatest + * + * Returns: + * - JSON object + * { zlatest: "Qm..." } + * + */ +function replyIfOkay(key, res) +{ + const program = "ak-ns"; + const command = spawn(program, ["-rj", key]); + var buffer = ""; + command.stdout.on("data", data => { + buffer += data; + }); + command.stderr.on("data", data => { + console.log(`stderr: ${data}`); + }); + command.on('error', (error) => { + console.log(`error: ${error.message}`); + }); + command.on("close", code => { + console.log(`child process ${program} exited with code ${code}`); + if (code === 0){ + buffer = buffer.trim() + res.writeHead(200, {'Content-Type': 'application/json'}); + res.end(`${buffer}`); + } else { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end({"error":"unreachable"}); + } + }); +} + +function getAKNSKey(req, res) +{ + var args = req.url.split("/"); + var key = args[3]; + regex= /[a-fA-F0-9]{40}/ + if (regex.test(key)) + { + key = key.toUpperCase(); + var path = config.akNSDir+"/"+key; + try + { + if(fs.existsSync(path)) + { + replyIfOkay(key, res) + } + else + { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({"error":"not found"})); + } + } + catch (error) + { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({"error":error.message})); + } + } + else + { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"No hash"})); + } +} + +module.exports = getAKNSKey; + diff --git a/api/routes/getAKNSKeyFromBase/index.js b/api/routes/getAKNSKeyFromBase/index.js new file mode 100644 index 0000000..7da3d9b --- /dev/null +++ b/api/routes/getAKNSKeyFromBase/index.js @@ -0,0 +1,91 @@ +const { spawn } = require('child_process'); +const fs = require('fs'); +const config = require("../../config.js"); + +/* + * Gets the local latest zblock AKA zlatest + * + * Returns: + * - JSON object + * { zlatest: "Qm..." } + * + */ +function decodeBase64ToHex(base64String) { + // Decode the Base64 string + const binaryString = atob(base64String); + + // Convert the binary string to a byte array + const byteArray = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + byteArray[i] = binaryString.charCodeAt(i); + } + + // Convert the byte array to a hex string representation + return Array.from(byteArray) + .map(byte => byte.toString(16).padStart(2, '0')) // Convert to hex and pad with zeros + .join(''); // Join with spaces for readability +} + +// Example usage + + +function replyIfOkay(key, res) +{ + const program = "ak-ns"; + const base64String = key; + const decodedHexString = decodeBase64ToHex(base64String); + formatted_key = decodedHexString.toUpperCase(); + const command = spawn(program, ["-rj", `${formatted_key}`]); + + var buffer = ""; + command.stdout.on("data", data => { + buffer += data; + }); + command.stderr.on("data", data => { + console.log(`stderr: ${data}`); + }); + command.on('error', (error) => { + console.log(`error: ${error.message}`); + }); + command.on("close", code => { + console.log(`child process ${program} exited with code ${code}`); + if (code === 0){ + buffer = buffer.trim() + res.writeHead(200, {'Content-Type': 'application/json'}); + res.end(`${buffer}`); + } else { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"unreachable"})); + } + }); +} + +function getAKNSKeyFromBase(req, res) +{ + var args = req.url.split("/"); + var key = args[3]; + regex= /[a-zA-Z0-9+\/=]{29}/ + const base64Regex = /^[A-Z0-9+\/=]{28}/i; + if (base64Regex.test(key)) + { + // key = key.toUpperCase(); + // var path = config.akNSDir+"/"+key; + try + { + replyIfOkay(key, res) + } + catch (error) + { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({"error":error.message})); + } + } + else + { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"No hash"})); + } +} + +module.exports = getAKNSKeyFromBase; + @@ -17,7 +17,8 @@ ### You should have received a copy of the GNU General Public License ### along with this program. If not, see <http://www.gnu.org/licenses/>. ### -export AK_DEBUG="yes" +export AK_DEBUG=0 +export AK_DEBUG_IRC="no" ## ## Arching Kaos CLI tool is the main executable script to use for exploring, ## creating and distributing local blockchain(s) called zchain(s). @@ -28,14 +29,16 @@ export AK_DEBUG="yes" ## ## Run with no arguments to see available commands ## -## -h, --help Prints this help message +## -h, --help Prints this help message. ## -## -s, --shell Starts an interactive shell +## -s, --shell Starts an interactive shell. ## ## -m, --module [module] Run a specified module. If no module provided ## the list of available modules will be printed. ## -## -f, --function [function] Get the list of available functions +## -f, --function [function] Get the list of available functions. +## +## -v Print all log messages. ## ## [command] [args] Run a command. If none provided a list of ## commands will be printed. @@ -49,6 +52,43 @@ source $AK_LIBDIR/_ak_lib_load _ak_lib_load _ak_log _ak_lib_load _ak_script +if [ "$1" == "-vi" ] +then + export AK_DEBUG_IRC="yes" + export AK_DEBUG="no" + shift +fi +if [ "$1" == "-vn" ] +then + export AK_DEBUG="no" + shift +fi +if [ "$1" == "-vvvvv" ] +then + export AK_DEBUG=5 + shift +fi +if [ "$1" == "-vvvv" ] +then + export AK_DEBUG=4 + shift +fi +if [ "$1" == "-vvv" ] +then + export AK_DEBUG=3 + shift +fi +if [ "$1" == "-vv" ] +then + export AK_DEBUG=2 + shift +fi +if [ "$1" == "-v" ] +then + export AK_DEBUG=1 + shift +fi + if [ $# -eq 0 ] then _ak_log_warning "No command given" @@ -61,11 +101,11 @@ then args="-h" if [ -n "$subcmd" ] then - echo $subcmd | cut -d '-' -f 2 | sort | uniq | sed -e 's/^/ak /g' + echo $subcmd | cut -d '-' -f 2 | sort | uniq #| sed -e 's/^/ak /g' #$(echo $subcmd) $args fi done - ) | sort | uniq | sed 's/^/# /g' | while read line; do _ak_log_info "$line";done + ) | sort | uniq #| sed 's/^/# /g' | while read line; do _ak_log_info "$line";done exit 1 fi @@ -179,7 +219,7 @@ else fi counter=$(($counter + 1)) done - _ak_usage + # _ak_usage err find $AK_BINDIR | while read available do echo $(basename $available) |\ diff --git a/bin/ak-cjdns b/bin/ak-cjdns index 1b2e4c0..dfd6560 100755 --- a/bin/ak-cjdns +++ b/bin/ak-cjdns @@ -47,7 +47,8 @@ then --install) _ak_cjdns_install; exit;; --connect) _ak_cjdns_connect_peers; exit;; --ip) _ak_cjdns_get_ip; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-clean b/bin/ak-clean index b77e74b..98d9c8c 100755 --- a/bin/ak-clean +++ b/bin/ak-clean @@ -54,8 +54,8 @@ then case $1 in -h | --help) _ak_usage; exit;; -c | --clean) _ak_tmp_cleanup; exit;; - *) _ak_usage; + *) _ak_usage err; esac else - _ak_usage + _ak_usage err fi diff --git a/bin/ak-coin b/bin/ak-coin index c7478ab..4f97dd2 100755 --- a/bin/ak-coin +++ b/bin/ak-coin @@ -41,7 +41,7 @@ then case $1 in -h | --help) _ak_usage; exit;; --stats) _ak_coin_stats; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else _ak_usage err fi diff --git a/bin/ak-config b/bin/ak-config index 770255b..ff8918f 100755 --- a/bin/ak-config +++ b/bin/ak-config @@ -43,8 +43,8 @@ then --publish) _ak_config_publish;exit;; --get-published) _ak_config_published;exit;; --get-ipns-key) _ak_ipfs_get_config_ipns_key;exit;; - *) _ak_usage;exit;; + *) _ak_usage err;exit;; esac else - _ak_usage + _ak_usage err fi @@ -27,6 +27,7 @@ ## --get, --export <roothash> <output file> Exports a file from the AKFS system ## --cat <roothash> Concatenates from given hash ## --list Lists names and roots available +## --llist Lists names available and their dates ## --net-cat-from-map <maphash> Concatenates from map via the network ## --net-get-from-map <maphash> Downloads from map via the network ## --cfm <maphash> Concatenates from map @@ -53,12 +54,13 @@ then --net-cat-from-map) _ak_fs_net_cat_from_map_hash $2; exit;; --net-get-from-map) _ak_fs_net_get_from_map_hash $2; exit;; --list) _ak_fs_list; exit;; + --llist) _ak_fs_long_list; exit;; --cfm) _ak_fs_cat_from_map_hash $2; exit;; --gfm) _ak_fs_get_from_map_hash $2; exit;; --rhd) _ak_fs_return_hash_dir $2; echo ;exit;; --rhp) _ak_fs_return_hash_path $2; echo ; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac else - _ak_usage + _ak_usage err fi diff --git a/bin/ak-get-balances b/bin/ak-get-balances index f5f57ca..a8ee44e 100755 --- a/bin/ak-get-balances +++ b/bin/ak-get-balances @@ -286,9 +286,12 @@ function _ak_schain_counting_balances(){ fi } -if [ ! -z $1 ] && [ -n "$1" ] +if [ ! -z $1 ] && [ -n "$1" ] && [ [ "$1" == "--help" ] || [ "$1" == "-h" ] ] then _ak_usage +elif [ ! -z $1 ] && [ -n "$1" ] +then + _ak_usage err else CUR_TARGET="$LATEST" _ak_log_info "$CUR_TARGET $LATEST" @@ -26,6 +26,8 @@ ## --get-key-self-as-ipfs Returns your key as an IPFS hash ## --get-key-self-as-fingerprint Returns the fingerprint of your key ## --get-key-fingerprint-from-ipfs Returns the fingerprint of a given key +## --export-key <fingerprint> <out> Exports a public key as <out> filename +## --export-selected-key Selects a key to export ## --export-key-self-to-file Exports self public key as 'self.pub' ## --clear-sign <file> <output> Sign a file clearly ## --verify-file <file> Verify a clear signed file @@ -39,6 +41,7 @@ ## plain GPG output ## -lsl, --list-secret-keys-long Returns a list of secret GPG keys with ## their 1st uid +## -i, --import-key <file> Imports a GPG key from a <file> ## -c, --create-key <email> Creates a GPG key with a label <email> ## -s, --select-key Selects the GPG key you want to use ## -d, --delete-key Delete GPG keys from your keyring @@ -62,11 +65,12 @@ _ak_lib_load _ak_gpg if [ ! -z $1 ]; then case $1 in -h | --help) _ak_usage; exit;; - --example) example; exit;; --get-key-self-as-ipfs) _ak_gpg_key_self_get_fingerprint_from_config; exit;; --get-key-self-as-fingerprint) _ak_gpg_key_self_get_fingerprint; exit;; --get-key-fingerprint-from-ipfs) shift; _ak_gpg_key_get_fingerprint_from_ipfs $1; exit;; --export-key-self-to-file) _ak_gpg_key_self_export 'self.pub'; exit;; + --export-selected-key) _ak_gpg_select_key_to_export; exit;; + --export-key) _ak_gpg_key_export "$2" "$3"; exit;; --clear-sign) shift; _ak_gpg_sign_clear "$2" "$1"; exit;; --verify-file) shift; _ak_gpg_verify_clear_signature "$1"; exit;; --list-keys | -l) _ak_gpg_list_keys; exit;; @@ -75,12 +79,14 @@ if [ ! -z $1 ]; then --list-secret-keys | -ls) _ak_gpg_list_secret_keys; exit;; --list-secret-keys-long | -lsl) _ak_gpg_list_secret_keys_long; exit;; --list-secret-keys-plain | -lsp) _ak_gpg_list_secret_keys_plain; exit;; + --import-key | -i) shift; _ak_gpg_key_import_from_file $1; exit;; --create-key | -c) shift; _ak_gpg_create_key $1; exit;; --select-key | -s) _ak_gpg_select_key; exit;; --delete-key | -d) _ak_gpg_delete_key; exit;; --delete-secret-key | -ds) shift; _ak_gpg_delete_secret_key $1; exit;; --run | -r) shift; _ak_gpg $*; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-ipfs b/bin/ak-ipfs index f3ef6da..ff66895 100755 --- a/bin/ak-ipfs +++ b/bin/ak-ipfs @@ -42,7 +42,8 @@ then -h | --help) _ak_usage; exit;; -d | --daemon) _ak_ipfs_starter; exit;; -r | --run) shift; _ak_ipfs_runner $*; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi @@ -46,7 +46,8 @@ then -h | --help) _ak_usage; exit;; --example) example; exit;; --connect) _ak_irc_connect; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi @@ -53,7 +53,8 @@ if [ ! -z $1 ]; then -g | --grep) _ak_log_grep; exit;; -m | --message) shift; _ak_log_message $*; exit;; -r | --rotate) _ak_log_rotate; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-maintainance b/bin/ak-maintainance index e0cd82d..ea85211 100755 --- a/bin/ak-maintainance +++ b/bin/ak-maintainance @@ -46,8 +46,9 @@ then -r | --restore) _ak_maintainance_restore $2; exit;; -b | --backup) _ak_maintainance_backup; exit;; -n | --nuke) _ak_maintainance_nuke_all_but_core; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi |
