interplane.Get Omega
Read in your language

open-humanity

Privacy-first peer assistance network for sovereign autonomous agents

Brought by drakestapleton

branch main Branches Tags History

open-humanity / om / trace_receiver_main.om

160 lines · 3923 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/open-humanity/trace_receiver_main.om
3note Standalone pure-Omega CLI for the Open Humanity exact-byte wire codec, consent/export,
4note and AITR v1 trace-receiver contract.
5note Compose with:
6note si/directives/om2.om protocol/open-humanity/lib.om
7note protocol/omnet/om/sha512/sha512.om protocol/omnet/om/ed25519/ed25519.om
8note protocol/open-humanity/trace_contract.om protocol/open-humanity/trace_receiver_main.om
9note Subcommands:
10note version print contract version and wire framing details
11note selfcheck execute signed OHCN v1 consent -> AITR v1 export -> OHTX v1 receive + Register verify
12note wire-check print hex of canonical Challenge, Ack, and keyed BLAKE3 cookie for parity checks
13
14text trm_ver "open-humanity-trace-om 1.0 (wire=0x4f-v1, consent=OHCN-v1, export=OHTX-v1, trace=AITR-v1)\n"
15text trm_usage "usage: open-humanity-trace version|selfcheck|wire-check\n"
16text trm_cmd_ver "version"
17text trm_cmd_sc "selfcheck"
18text trm_cmd_wc "wire-check"
19text trm_ok "TRACE_RECEIVER SELFCHECK PASS bundle_bytes="
20text trm_seg " recv_aitr_bytes="
21text trm_fail "TRACE_RECEIVER SELFCHECK FAIL code="
22text trm_ck_lbl "COOKIE="
23text trm_ch_lbl "CHALLENGE="
24text trm_ak_lbl "ACK="
25text trm_rg_lbl "REGISTER="
26text trm_nl "\n"
27text trm_addr "192.0.2.1:4000"
28text trm_pay0 "sm121_ok lat=400us"
29
30global trm_arg uchar 64
31
32fn trm_arg_eq idx ulong lit view uchar * to bool
33n = argread idx trm_arg 0 64
34if lt n 0
35ret false
36end
37un = ulong n
38if ne un len lit
39ret false
40end
41for i ulong un bound 64
42if ne get trm_arg i get lit i
43ret false
44end
45end
46ret true
47end
48
49fn trm_write_hex buf view uchar * to void
50n = len buf
51out_h = new uchar 2 0
52for i ulong n bound 512
53bv = ulong get buf i
54put out_h 0 get oh_hex_chars shr bv 4
55put out_h 1 get oh_hex_chars and bv 15
56ok = oh_write_all 1 out_h
57if not ok
58ret
59end
60end
61end
62
63fn trm_wire_check_reg ck view uchar 16 now ulong to bool
64seed = new uchar 32 17
65rg = new uchar 133 0
66rn = ohw_encode_register seed now uchar 5 uchar 1 ck rg
67ok = oh_write_all 1 trm_rg_lbl
68trm_write_hex rg
69ok = oh_write_all 1 trm_nl
70ret eq rn 133
71end
72
73fn trm_wire_check to int
74secret = new uchar 32 9
75now = ulong 1000000
76ck = new uchar 16 0
77ohw_relay_cookie secret trm_addr div now OHW_COOKIE_WINDOW ck
78ch = new uchar 19 0
79cn = ohw_encode_challenge ck ch
80ak = new uchar 8 0
81an = ohw_encode_ack uchar 3 120 ak
82ok = oh_write_all 1 trm_ck_lbl
83trm_write_hex ck
84ok = oh_write_all 1 trm_nl
85ok = oh_write_all 1 trm_ch_lbl
86trm_write_hex ch
87ok = oh_write_all 1 trm_nl
88ok = oh_write_all 1 trm_ak_lbl
89trm_write_hex ak
90ok = oh_write_all 1 trm_nl
91if not trm_wire_check_reg ck now
92ret 1
93end
94if and eq cn 19 eq an 8
95ret 0
96end
97ret 1
98end
99
100fn trm_selfcheck to int
101ohtx_reset_replay
102nseed = new uchar 32 31
103rseed = new uchar 32 32
104rpk = new uchar 32 0
105ohtx_ed_pubkey rseed rpk
106now = ulong 1700000000
107consent = new uchar 160 0
108ohtx_sign_consent nseed rpk 2 add now 3600 0 consent
109seg = new uchar 80 0
110ohtx_aitr_write_hdr seg
111rc = ohtx_aitr_write_rec seg 16 or ulong 1 shl ulong 0 16 trm_pay0
112if ne rc OHTX_OK
113ret 1
114end
115bid = new uchar 16 55
116ohtx_set_bundle_id bid
117bundle = new uchar 4408 0
118rc = oh_trace_export nseed consent seg now bundle
119if ne rc OHTX_OK
120ok = oh_write_all 1 trm_fail
121oh_write_u64 1 rc
122ok = oh_write_all 1 trm_nl
123ret 1
124end
125blen = ohtx_export_len
126out_seg = new uchar 256 0
127rc = oh_trace_receive part bundle 0 blen rpk now out_seg
128if ne rc OHTX_OK
129ok = oh_write_all 1 trm_fail
130oh_write_u64 1 rc
131ok = oh_write_all 1 trm_nl
132ret 1
133end
134ok = oh_write_all 1 trm_ok
135oh_write_u64 1 blen
136ok = oh_write_all 1 trm_seg
137oh_write_u64 1 ohtx_recv_len
138ok = oh_write_all 1 trm_nl
139ret 0
140end
141
142fn main to int
143ac = argcnt
144if lt ac 2
145ok = oh_write_all 2 trm_usage
146ret 2
147end
148if trm_arg_eq 1 trm_cmd_ver
149ok = oh_write_all 1 trm_ver
150ret 0
151end
152if trm_arg_eq 1 trm_cmd_sc
153ret trm_selfcheck
154end
155if trm_arg_eq 1 trm_cmd_wc
156ret trm_wire_check
157end
158ok = oh_write_all 2 trm_usage
159ret 2
160end