diff --git a/DONT_README.md b/DONT_README.md new file mode 100644 index 0000000..2dacdcc --- /dev/null +++ b/DONT_README.md @@ -0,0 +1,14 @@ +## x05 (dindu = rubicon querier) + +### TODONE + +- hz status +- hz prepare contract + +### TODONE + +- deploy names contract +- hz deploy contract +- need to be able to deploy a rubicon contract +- save contract address +- call lookup diff --git a/README.md b/README.md index 94f13a5..ce45213 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # rubicon mega-repo and playground +This repository lives at + ## rubicon by example - x00-hello: @@ -19,3 +21,11 @@ - telnet echo server - budget version of zx template "traditional erlang service application" + +- x04-noisy-echo: + - TUI chat client and daemon escripts + - tunnels connection over noise + +- x05-rq: + - rq = Rubicon querier + - has hardcoded contract address diff --git a/rq/ct/rubicon.aes b/rq/ct/rubicon.aes deleted file mode 100644 index f30e35e..0000000 --- a/rq/ct/rubicon.aes +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Rubicon contract - * - * Author: Peter Harpending - * Date: 2026-09-04 - */ -contract Rubicon = - // this could/should be a record, but records aren't really - // portable across contracts/languages/APIs - // - // record rbx = - // {ip : string, - // port : int, - // protocol : string, // "tcp", "udp", "sctp", etc - // noise : string, // Noise_Foo_Bar_Baz_Quux - // pubkey : address, // responder static pubkey (noise rs field) - // prologue : option(bytes)} // noise prologue (empty = no prologue) - - // (ip, port, protocol, noise, pubkey, prologue) - type rbx_tuple = string * int * string * string * address * option(bytes) - type state = list(rbx_tuple) - - entrypoint init(tuples: list(rbx_tuple)): state = - tuples - - stateful entrypoint set(tuples: list(rbx_tuple)): unit = - require(Call.caller == Contract.creator, "Not allowed") - put(tuples) - - entrypoint lookup(): list(rbx_tuple) = - state diff --git a/rq/src/rq.erl b/rq/src/rq.erl deleted file mode 100644 index 7fb690f..0000000 --- a/rq/src/rq.erl +++ /dev/null @@ -1,54 +0,0 @@ -%% @doc rubicon querier --module(rq). --vsn("0.1.0"). --author("Peter Harpending"). --copyright("Peter Harpending"). - --export([start/1]). - - --spec start(ArgV) -> ok - when ArgV :: [string()]. - -start(ArgV) -> - ok = application:ensure_started(hakuzaru), - ok = hz:tls(true), - ok = hz:chain_nodes(hz_nodes()), - ok = io:format("Hello, World! Args: ~tp~n", [ArgV]), - ok = io:format("hz status: ~tp~n", [hz:status()]), - ok = io:format("rbx_tuples: ~tp~n", [rbx_tuples()]), - ok = io:format("my akstr:~n~ts~n~n", [dummy_akstr()]), - zx:silent_stop(). - - -dummy_seed() -> - crypto:hash(sha3_512, <<"p@ssw0rd">>). - -dummy_keypair() -> - ecu_eddsa:sign_seed_keypair(dummy_seed()). - -% bytes32 -dummy_pubkey32() -> - maps:get(public, dummy_keypair()). - -dummy_akstr() -> - unicode:characters_to_list(gmser_api_encoder:encode(account_pubkey, dummy_pubkey32())). - - -hz_nodes() -> - [ {"tsuriai.jp", 4013} - %, {"testnet.gajumaru.io", 4013} - ]. - -rbx_tuples() -> - NoiseStr = "Noise_NK_25519_ChaChaPoly_BLAKE2b", - ServicePubkey = - <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50, - 81, 110, 137, 163, 44, 76, 48, 130, 225, 95, - 168, 121, 93, 44, 148, 42, 180, 103, 11, 40, - 168, 96>> - , - NoisePrologue = <<>>, - [{"127.0.0.1", 6969, "tcp", NoiseStr, ServicePubkey, <<>>}]. - - diff --git a/rq/.gitignore b/x05-dindu/.gitignore similarity index 100% rename from rq/.gitignore rename to x05-dindu/.gitignore diff --git a/rq/Emakefile b/x05-dindu/Emakefile similarity index 100% rename from rq/Emakefile rename to x05-dindu/Emakefile diff --git a/x05-dindu/ct/names.aes b/x05-dindu/ct/names.aes new file mode 100644 index 0000000..d3e5c9d --- /dev/null +++ b/x05-dindu/ct/names.aes @@ -0,0 +1,19 @@ +contract interface Rubicon = + entrypoint lookup: () => list(string * int * string * string * address * bytes) + +contract Names = + type rbx_tuple = string * int * string * string * address * bytes + type state = map(string, Rubicon) + + entrypoint init(): state = + {} + + stateful entrypoint register(name: string, addr: Rubicon): unit = + put(state{[name] = addr}) + + stateful entrypoint lookup(name: string): option(list(rbx_tuple)) = + switch(Map.lookup(name, state)) + Some(addr) => + Some(addr.lookup()) + None => + None diff --git a/x05-dindu/ct/rubicon.aes b/x05-dindu/ct/rubicon.aes new file mode 100644 index 0000000..426e5ce --- /dev/null +++ b/x05-dindu/ct/rubicon.aes @@ -0,0 +1,24 @@ +contract Rubicon = + // record rbx = + // {ip : string, + // port : int, + // protocol : string, // "tcp", "udp", "sctp", etc + // noise : string, // Noise_Foo_Bar_Baz_Quux + // pubkey : address, // responder static pubkey (noise: rs field) + // prologue : bytes} // noise prologue (empty = no prologue) + + // (ip, port, protocol, noise, pubkey, prologue) + type rbx_tuple = string * int * string * string * address * bytes + type state = list(rbx_tuple) + + entrypoint init(tuples: list(rbx_tuple)): state = + tuples + + stateful entrypoint set(tuples: list(rbx_tuple)): unit = + // this would be nice + // but unfortunately nobody knows how to do this + // require(Call.caller == Contract.creator, "Not allowed") + put(tuples) + + entrypoint lookup(): list(rbx_tuple) = + state diff --git a/rq/ebin/rq.app b/x05-dindu/ebin/dindu.app similarity index 91% rename from rq/ebin/rq.app rename to x05-dindu/ebin/dindu.app index 74b0787..64f4c07 100644 --- a/rq/ebin/rq.app +++ b/x05-dindu/ebin/dindu.app @@ -1,4 +1,4 @@ -{application,rq, +{application,dindu, [{description,[]}, {registered,[]}, {included_applications,[]}, diff --git a/x05-dindu/src/dindu.erl b/x05-dindu/src/dindu.erl new file mode 100644 index 0000000..7e9fcea --- /dev/null +++ b/x05-dindu/src/dindu.erl @@ -0,0 +1,156 @@ +%% @doc dindu: Decentralized Identity Namespace Disambiguation Utility +-module(dindu). +-vsn("0.1.0"). +-author("Peter Harpending"). +-copyright("Peter Harpending"). + +-export([start/1]). + + +-spec start(ArgV) -> ok + when ArgV :: [string()]. + +start(ArgV) -> + ok = hz(), + du(ArgV); + + +du(["-s" | Rest]) -> dindu(Rest); +du(["--shell" | Rest]) -> dindu(Rest); +du(Rest) -> dindu(Rest), zx:silent_stop(). + + +dindu(["debug" | _]) -> + ok = io:format("rbx_tuples: ~tp~n", [rbx_tuples()]), + ok = io:format("my akstr:~n~ts~n~n", [my_akstr()]), + ok = io:format("names ct aaci:~n~tp~n~n", [nct_aaci()]), + ok = io:format("rubicon ct aaci:~n~tp~n~n", [rct_aaci()]), + ok; +dindu(["src", "names.aes"]) -> + {ok, Bytes} = file:read_file(nct_filepath()); + io:format("~s", [Bytes]); +dindu(["src", "rubicon.aes"]) -> + {ok, Bytes} = file:read_file(rct_filepath()); + io:format("~s", [Bytes]); +dindu(["-h" | _]) -> + dindu_help(); +dindu(["--help" | _]) -> + dindu_help(); +dindu(["help" | _]) -> + dindu_help(); +dindu(BadArgs) -> + io:format("arguments are a failure: ~tp~n", [BadArgs]), + dindu_help(). + +dindu_help() -> + io:format("~ts~n", [help_screen()]). + +help_screen() -> + """ + dindu = Decentralized Identity Namespace Disambiguation Utility + version 0.0.0 + 0.0.1i + + USAGE: dindu [ARGS] + """ + +%du_register( + +%% name contract deployed address +nct_ctstr() -> + "ct_2CDom5hKimtKSsTykhBYBKMgGv7youakZPVgk5h9qgNL3P65oV". + +nct_aaci() -> + hz:prepare_contract(nct_filepath()). + +nct_filepath() -> + ct_dir() ++ "/names.aes". + + +%% rubicon contract deployed address +rct_ctstr() -> + "". + +rct_aaci() -> + hz:prepare_contract(rct_filepath()). + +rct_filepath() -> + ct_dir() ++ "/rubicon.aes". + + +ct_dir() -> + zx:get_home() ++ "/ct". + + + +%% my keys +% "ak_2pr2BL1jK625Uedt888p3YKRUEk3GDTo5r2zKW6gMaZePQP5ou" +my_akstr() -> + unicode:characters_to_list(gmser_api_encoder:encode(account_pubkey, my_pubkey32())). + +my_balance() -> + + +my_pubkey32() -> + maps:get(public, my_keypair()). + +my_secret_key() -> + maps:get(secret, my_keypair()). + +my_keypair() -> + ecu_eddsa:sign_seed_keypair(my_seed()). + +my_seed() -> + crypto:hash(sha3_512, <<"p@ssw0rd">>). + + + +%% hz setup +hz() -> + ok = application:ensure_started(hakuzaru), + ok = hz:tls(false), + ok = hz:chain_nodes(hz_nodes()), + ok = io:format("hz status: ~tp~n", [hz:status()]). + +hz_nodes() -> + [ {"tsuriai.jp", 4013} + ]. + + +rbx_tuples() -> + NoiseStr = "Noise_NK_25519_ChaChaPoly_BLAKE2b", + ServicePubkey = <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50, + 81, 110, 137, 163, 44, 76, 48, 130, 225, 95, + 168, 121, 93, 44, 148, 42, 180, 103, 11, 40, + 168, 96>>, + NoisePrologue = <<>>, + [{"127.0.0.1", 6969, "tcp", NoiseStr, ServicePubkey, NoisePrologue}]. + +%% deploying +deploy_rct_with(RbxTuples) -> + case hz:contract_create(my_akstr(), rct_filepath(), [rbx_tuples()]) of + {ok, CreateTx} -> + deploy_rct_II(CreateTx); + Error -> + io:format("you are a failure: ~tp~n", [Error]), + error(Error) + end. + +deploy_rct_II(UnsignedCreateTx) -> + SecretKey = my_secret_key(), + case hz:sign_tx(UnsignedCreateTx, SecretKey) of + {ok, SignedTx} -> + deploy_rct_III(SignedTx); + Error -> + io:format("you are a failure II: ~tp~n", [Error]), + error(Error) + end. + + +deploy_rct_III(SignedCreateTx) -> + case hz:post_tx(SignedCreateTx) of + {ok, Result_III} -> + io:format("Result the third: ~tp~n", [Result_III]); + Error -> + io:format("you are a failure III: ~tp~n", [Error]), + error(Error) + end. diff --git a/rq/zomp.meta b/x05-dindu/zomp.meta similarity index 53% rename from rq/zomp.meta rename to x05-dindu/zomp.meta index 96f8208..c0a0f0f 100644 --- a/rq/zomp.meta +++ b/x05-dindu/zomp.meta @@ -1,16 +1,22 @@ -{name,"rq"}. +{name,"dindu"}. {type,cli}. {modules,[]}. -{mod,"rq"}. +{mod,"dindu"}. {author,"Peter Harpending"}. {prefix,none}. {desc,[]}. -{package_id,{"otpr","rq",{0,1,0}}}. +{package_id,{"otpr","dindu",{0,1,0}}}. {deps,[{"otpr","base58",{0,1,1}}, {"otpr","eblake2",{1,0,1}}, {"otpr","gmserialization",{0,1,3}}, {"otpr","ec_utils",{1,0,0}}, - {"otpr","hakuzaru",{0,9,1}}]}. + {"otpr","hakuzaru",{0,9,1}}, + {"otpr", "sophia", {9,0,0}}, + {"otpr", "gmserialization", {0,1,3}}, + {"otpr", "gmbytecode", {3,4,1}}, + {"otpr", "base58", {0,1,1}}, + {"otpr", "zj", {1,1,0}}, + {"otpr", "getopt", {1,0,2}}]}. {key_name,none}. {a_email,[]}. {c_email,[]}.