diff options
55 files changed, 1121 insertions, 338 deletions
@@ -74,6 +74,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 +105,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 +115,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 +172,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 +238,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 +398,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..f22d448 100755 --- a/api/index.js +++ b/api/index.js @@ -1,6 +1,8 @@ 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'); @@ -68,6 +70,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; + @@ -18,6 +18,7 @@ ### along with this program. If not, see <http://www.gnu.org/licenses/>. ### export AK_DEBUG="yes" +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). @@ -49,6 +50,13 @@ 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 [ $# -eq 0 ] then _ak_log_warning "No command given" 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 @@ -57,8 +57,8 @@ then --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 @@ -67,6 +69,8 @@ if [ ! -z $1 ]; then --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;; @@ -80,7 +84,8 @@ if [ ! -z $1 ]; then --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 diff --git a/bin/ak-mine b/bin/ak-mine index 72f90a3..53f7549 100755 --- a/bin/ak-mine +++ b/bin/ak-mine @@ -90,7 +90,8 @@ then -h | --help) _ak_usage; exit;; --example) example; exit;; --mine) proofofwork; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-network b/bin/ak-network index 40efd72..529d2ea 100755 --- a/bin/ak-network +++ b/bin/ak-network @@ -49,7 +49,8 @@ if [ ! -z $1 ]; then -s | --scan) shift; _ak_network_scan $*; exit;; -c | --connect) _ak_network_connect $2; exit;; -p | --peers) _ak_network_show_peers $2; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-node-info b/bin/ak-node-info index 29eea87..b0a9663 100755 --- a/bin/ak-node-info +++ b/bin/ak-node-info @@ -47,9 +47,9 @@ then _ak_node_info_ipns_key ;; *) - _ak_usage + _ak_usage err ;; esac else - _ak_usage + _ak_usage err fi @@ -28,10 +28,16 @@ ## -ll, --list-long List names with keys ## -rn, --resolve-name <name> Resolves value from name ## -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 +## -ra, --resolve-all Resolve all reachable keys ## -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 ## fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) @@ -51,11 +57,17 @@ 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;; + -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;; + -ra | --resolve-all) _ak_ns_resolve_all_keys; 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;; -pc | --publish-config) _ak_ns_publish_config; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi @@ -53,7 +53,8 @@ then --install-from-zblock) shift; _ak_pkg_install_from_zblock $1; exit;; --install-from-akfs) shift; _ak_pkg_install_from_akfsmap $1; exit;; --uninstall) _ak_pkg_uninstall; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-profile b/bin/ak-profile index 02ed5a7..eaf8e0b 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -235,7 +235,8 @@ if [ ! -z $1 ]; then -a | --add) _ak_modules_profile_add $2; exit;; -s | --set) _ak_modules_profile_propset $2 "$3"; exit;; -g | --get) _ak_modules_profile_propget $2; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage +else + _ak_usage err fi diff --git a/bin/ak-sblock b/bin/ak-sblock index 7c6ab23..ec7464e 100755 --- a/bin/ak-sblock +++ b/bin/ak-sblock @@ -41,7 +41,8 @@ then case $1 in -h | --help) _ak_usage; exit;; -s | --show) shift; _ak_sblock_show $1; exit;; - * ) _ak_usage;; + * ) _ak_usage err;; esac -else _ak_usage |