From c23eed3a4d4c467f9e52887b972c4497e0e4e775 Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Fri, 4 Sep 2026 19:40:44 -0700 Subject: [PATCH] committing to cleanup --- {ct => rq/ct}/rubicon.aes | 12 ++++---- rq/src/rq.erl | 41 +++++++++++++++++++++++-- rq/zomp.meta | 6 +++- x04-noisy-echo/duml.erl | 19 ++++++++++++ x04-noisy-echo/nechod | 61 +++++++++++++++++++++++++++++++++++--- x04-noisy-echo/scratch.txt | 2 +- 6 files changed, 126 insertions(+), 15 deletions(-) rename {ct => rq/ct}/rubicon.aes (63%) create mode 100644 x04-noisy-echo/duml.erl diff --git a/ct/rubicon.aes b/rq/ct/rubicon.aes similarity index 63% rename from ct/rubicon.aes rename to rq/ct/rubicon.aes index b898359..f30e35e 100644 --- a/ct/rubicon.aes +++ b/rq/ct/rubicon.aes @@ -2,7 +2,7 @@ * Rubicon contract * * Author: Peter Harpending - * Date: 2026-08-12 + * Date: 2026-09-04 */ contract Rubicon = // this could/should be a record, but records aren't really @@ -11,13 +11,13 @@ contract Rubicon = // record rbx = // {ip : string, // port : int, - // protocol : string, // "tcp", "udp", "sctp", etc - // noise : string, // Noise_Foo_Bar_Baz_Quux - // pubkey : bytes, // responder static pubkey (noise rs field) - // prologue : bytes} // noise prologue (empty = no prologue) + // 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 * bytes * bytes + type rbx_tuple = string * int * string * string * address * option(bytes) type state = list(rbx_tuple) entrypoint init(tuples: list(rbx_tuple)): state = diff --git a/rq/src/rq.erl b/rq/src/rq.erl index 9616766..7fb690f 100644 --- a/rq/src/rq.erl +++ b/rq/src/rq.erl @@ -4,7 +4,6 @@ -author("Peter Harpending"). -copyright("Peter Harpending"). - -export([start/1]). @@ -13,7 +12,43 @@ start(ArgV) -> ok = application:ensure_started(hakuzaru), - ok = hz:chain_nodes([{"testnet.tsuriai.jp", 3013}, - {"testnet.gajumaru.io", 3013}]), + 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/zomp.meta b/rq/zomp.meta index e0e033b..96f8208 100644 --- a/rq/zomp.meta +++ b/rq/zomp.meta @@ -6,7 +6,11 @@ {prefix,none}. {desc,[]}. {package_id,{"otpr","rq",{0,1,0}}}. -{deps,[{"otpr","hakuzaru",{0,9,1}}]}. +{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}}]}. {key_name,none}. {a_email,[]}. {c_email,[]}. diff --git a/x04-noisy-echo/duml.erl b/x04-noisy-echo/duml.erl new file mode 100644 index 0000000..3c99512 --- /dev/null +++ b/x04-noisy-echo/duml.erl @@ -0,0 +1,19 @@ +-module(duml). +-export([shuffle/1]). + +shuffle([]) -> + []; +shuffle([X]) -> + [X]; +shuffle(Items) -> + N = rand:uniform(length(Items)), + {Nth, Rest} = inverse_nth(N, Items), + [Nth | shuffle(Rest)]. + +inverse_nth(N, Items) -> + inverse_nth([], N, Items). + +inverse_nth(Stk, 1, [X | Rest]) -> + {X, lists:reverse(Stk, Rest)}; +inverse_nth(Stk, N, [X | Rest]) when N > 1 -> + inverse_nth([X | Stk], N-1, Rest). diff --git a/x04-noisy-echo/nechod b/x04-noisy-echo/nechod index 80bd21d..8cc6f1a 100755 --- a/x04-noisy-echo/nechod +++ b/x04-noisy-echo/nechod @@ -31,15 +31,17 @@ main([PortNum]) -> p_init(list_to_integer(PortNum)). +% static keypair is static, ephemeral is ephemeral noise_options() -> - % totally safe crypto Secret = crypto:hash(sha3_256, <<"alice">>), Public = <<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>>, - KP = enoise_keypair:new(dh25519, Secret, Public), - [{noise, "Noise_NN_25519_ChaChaPoly_BLAKE2b"}, - {s, KP}]. + SKP = enoise_keypair:new(dh25519, Secret, Public), + EKP = enoise_keypair:new(dh25519), + [{noise, "Noise_NK_25519_ChaChaPoly_BLAKE2b"}, + {s, SKP}, + {e, EKP}]. % pimp process startup @@ -209,6 +211,9 @@ h_send(Name, NSock, Msg) -> init_ho_names() -> + shuffle(plain_ho_names()). + +plain_ho_names() -> ["Crystal", "Tiffany", "Amber", "Brandy", "Lola", "Angel", "Ginger", "Candy", "Charity", "Anastasia", "Cherry", "Kitty", "Jade", "Destiny", "Devon", "Chastity", "Raven", "Scarlett", @@ -221,3 +226,51 @@ init_ho_names() -> recycle([N | Ns]) -> {N, Ns ++ [N]}. + + +%% @private +%% naive shuffle because we aren't cool enough to have +%% `rand:shuffle/1' yet`()' +%% +%% for list of length `N', there there are `N!' permutations +%% +%% ``` +%% [, , ..., <2 options>, <1 options>] +%% ''' +%% +%% so we simply do the stupid +%% +%% conceptually: pick a sequence of integers at random +%% +%% ``` +%% [(1..N), (1..N-1), (1..N-2), ... (1..2), 1] +%% ''' +%% +%% which determines a permuation of the list + +shuffle([]) -> + []; +shuffle([X]) -> + [X]; +shuffle(Items) -> + N = rand:uniform(length(Items)), + {Nth, Rest} = inverse_nth(N, Items), + [Nth | shuffle(Rest)]. + +inverse_nth(N, Items) -> + inverse_nth([], N, Items). + +inverse_nth(Stk, 1, [X | Rest]) -> + {X, lists:reverse(Stk, Rest)}; +inverse_nth(Stk, N, [X | Rest]) when N > 1 -> + inverse_nth([X | Stk], N-1, Rest). + + +%% haven't thought about this, but faster because doesn't involve any +%% lists:reverse calls +% fshuf([]) -> []; +% fshuf([X]) -> [X]; +% fshuf(Items) -> [X]; +% N = rand:uniform(length(Items)), +% fshuf_ii(N, Items) +% shuffle(Items) -> diff --git a/x04-noisy-echo/scratch.txt b/x04-noisy-echo/scratch.txt index 638d4a8..73c8b13 100644 --- a/x04-noisy-echo/scratch.txt +++ b/x04-noisy-echo/scratch.txt @@ -5,7 +5,7 @@ pubkey: rbx_tuple = <<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>> -[{"127.0.0.1", 6969, "tcp", "Noise_NN_25519_ChaChaPoly_BLAKE2b", <<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>>, <<>>}] +[{"127.0.0.1", 6969, "tcp", "Noise_NK_25519_ChaChaPoly_BLAKE2b", <<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>>, <<>>}] {"127.0.0.1", 6970, "tcp", <<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>>, <<>>}, {"127.0.0.1", 6971, "tcp", <<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>>, <<>>}]