This commit is contained in:
Peter Harpending
2026-09-21 17:12:53 -07:00
parent c23eed3a4d
commit fcd61c122e
11 changed files with 234 additions and 90 deletions
+14
View File
@@ -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
+10
View File
@@ -1,5 +1,7 @@
# rubicon mega-repo and playground # rubicon mega-repo and playground
This repository lives at <https://git.harpending.org/pharpend/rbx>
## rubicon by example ## rubicon by example
- x00-hello: - x00-hello:
@@ -19,3 +21,11 @@
- telnet echo server - telnet echo server
- budget version of zx template "traditional erlang service - budget version of zx template "traditional erlang service
application" application"
- x04-noisy-echo:
- TUI chat client and daemon escripts
- tunnels connection over noise
- x05-rq:
- rq = Rubicon querier
- has hardcoded contract address
-31
View File
@@ -1,31 +0,0 @@
/**
* Rubicon contract
*
* Author: Peter Harpending <peterharpending@qpq.swiss>
* 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
-54
View File
@@ -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, <<>>}].
+19
View File
@@ -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
+24
View File
@@ -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
+1 -1
View File
@@ -1,4 +1,4 @@
{application,rq, {application,dindu,
[{description,[]}, [{description,[]},
{registered,[]}, {registered,[]},
{included_applications,[]}, {included_applications,[]},
+156
View File
@@ -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.
+10 -4
View File
@@ -1,16 +1,22 @@
{name,"rq"}. {name,"dindu"}.
{type,cli}. {type,cli}.
{modules,[]}. {modules,[]}.
{mod,"rq"}. {mod,"dindu"}.
{author,"Peter Harpending"}. {author,"Peter Harpending"}.
{prefix,none}. {prefix,none}.
{desc,[]}. {desc,[]}.
{package_id,{"otpr","rq",{0,1,0}}}. {package_id,{"otpr","dindu",{0,1,0}}}.
{deps,[{"otpr","base58",{0,1,1}}, {deps,[{"otpr","base58",{0,1,1}},
{"otpr","eblake2",{1,0,1}}, {"otpr","eblake2",{1,0,1}},
{"otpr","gmserialization",{0,1,3}}, {"otpr","gmserialization",{0,1,3}},
{"otpr","ec_utils",{1,0,0}}, {"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}. {key_name,none}.
{a_email,[]}. {a_email,[]}.
{c_email,[]}. {c_email,[]}.