Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/synapse/claims/src/70_cmds.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / synapse / claims / src / 70_cmds.om` 849 lines ยท 14009 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Subcommands. Options live in gop as (offset, length) pairs into the argument buffer av (offset tbad 3 note = absent); see 90_main.om for the slot map. 4 5 const ohome ulong 0 6 const onow ulong 2 7 const osig ulong 4 8 const oag ulong 6 9 const ose ulong 8 10 const otg ulong 10 11 const ottl ulong 12 12 const omode ulong 14 13 const ost ulong 16 14 const oin ulong 18 15 const oev ulong 20 16 const oimp ulong 22 17 const oid ulong 24 18 const oall ulong 26 19 const oapf ulong 28 20 const opos ulong 30 21 const ocmd ulong 32 22 const oevn ulong 33 23 24 global gevl ulong 512 25 26 text musage "usage: synapse-claims [--home DIR] [--now TS] [--sig-bin PATH] init|claim|renew|release|state|who|list|conflicts|verify|expire ..." 27 text mmagent "missing or invalid --agent" 28 text mmsess "missing or invalid --session" 29 text mmtg "missing or invalid --target" 30 text mmttl "invalid --ttl (1..`2592000`)" 31 text mmmode "invalid --mode (excl|shared)" 32 text mmst "invalid --state" 33 text mmin "invalid --intent (UTF-8, at most 4096 bytes)" 34 text mmev "invalid --evidence" 35 text mmimp "invalid --import" 36 text mmid "missing --id" 37 text mkeyg "keygen failed (synapse-claims-sig)" 38 text mpub "ledger.pub unreadable" 39 text mverb "signature check failed to run (synapse-claims-sig)" 40 text tcli "cli" 41 text tpulse "pulse" 42 text tdefag "synapse-claims" 43 text timp "import:" 44 text tconf "{\"ok\":false,\"error\":\"conflict\",\"holder\":" 45 text tconf2 "conflict: " 46 text theld " held by " 47 text tuntil ") until " 48 text tokid "{\"ok\":true,\"id\":\"" 49 text tseq "\",\"seq\":" 50 text texp2 ",\"expires\":" 51 text tokpub "{\"ok\":true,\"pub\":\"" 52 text tvok "{\"ok\":true,\"events\":" 53 text thead ",\"head\":\"" 54 text tvbad "{\"ok\":false,\"seq\":" 55 text terr2 ",\"error\":\"" 56 text ta "{\"a\":" 57 text tb ",\"b\":" 58 text treas ",\"reason\":\"" 59 text tdid "did:key:" 60 text tokv "ok " 61 text tbadv "bad " 62 63 fn op_has slot ulong to bool 64 ret ne get gop slot tbad 65 end 66 67 fn op_sf av edit uchar * slot ulong msg view uchar * to ulong 68 if eq op_has slot false 69 die 64 msg 70 end 71 o = get gop slot 72 n = get gop add slot 1 73 if eq sf_ok part av o n false 74 die 64 msg 75 end 76 ret ar_ln av o n 77 end 78 79 note decimal option value, 1..19 digits; tbad when absent or not a number 80 fn op_uint av edit uchar * slot ulong to ulong 81 if eq op_has slot false 82 ret tbad 83 end 84 o = get gop slot 85 n = get gop add slot 1 86 if or eq n 0 gt n 19 87 ret tbad 88 end 89 v = ulong 0 90 for i ulong n 91 c = get av add o i 92 if or lt c 48 gt c 57 93 ret tbad 94 end 95 v = add mul v 10 ulong sub c 48 96 end 97 ret v 98 end 99 100 fn op_ttl av edit uchar * to ulong 101 if eq op_has ottl false 102 ret 3600 103 end 104 v = op_uint av ottl 105 if or or eq v tbad eq v 0 gt v `2592000` 106 die 64 mmttl 107 end 108 ret v 109 end 110 111 note option word from wall[base .. base+cnt); base 18 is --mode, base 5 is --state 112 fn op_word av edit uchar * slot ulong base ulong cnt ulong to ulong 113 o = get gop slot 114 n = get gop add slot 1 115 w = tw_find part av o n wall base cnt 116 if eq w tbad 117 if eq base 18 118 die 64 mmmode 119 end 120 die 64 mmst 121 end 122 ret sub w base 123 end 124 125 note u8_cont: the k continuation bytes after av[p] are 128..191, the first one within lo..hi 126 fn u8_cont av edit uchar * p ulong k ulong lo ulong hi ulong to bool 127 for j ulong k 128 d = ulong get av add p add j 1 129 if eq j 0 130 if or lt d lo gt d hi 131 ret false 132 end 133 else 134 if or lt d 128 gt d 191 135 ret false 136 end 137 end 138 end 139 ret true 140 end 141 142 note UTF-8 check (RFC 3629: no overlongs, no surrogates, max U+10FFFF) of av[o..o+n) 143 fn utf8_ok av edit uchar * o ulong n ulong to bool 144 i = ulong 0 145 while lt i n bound 5000 146 c = ulong get av add o i 147 k = ulong 0 148 lo = ulong 128 149 hi = ulong 191 150 if lt c 128 151 i = add i 1 152 continue 153 end 154 if and ge c 194 le c 223 155 k = 1 156 end 157 if and ge c 224 le c 239 158 k = 2 159 if eq c 224 160 lo = 160 161 end 162 if eq c 237 163 hi = 159 164 end 165 end 166 if and ge c 240 le c 244 167 k = 3 168 if eq c 240 169 lo = 144 170 end 171 if eq c 244 172 hi = 143 173 end 174 end 175 if eq k 0 176 ret false 177 end 178 if gt add i k sub n 1 179 ret false 180 end 181 if eq u8_cont av add o i k lo hi false 182 ret false 183 end 184 i = add add i k 1 185 end 186 ret true 187 end 188 189 note intent: JSON-escaped copy in the arena (offset; length in gx xpos); empty when absent 190 fn op_intent av edit uchar * to ulong 191 st = get gx xarn 192 put gx xpos 0 193 if eq op_has oin false 194 ret st 195 end 196 o = get gop oin 197 n = get gop add oin 1 198 if gt n 4096 199 die 64 mmin 200 end 201 if eq utf8_ok av o n false 202 die 64 mmin 203 end 204 for i ulong n 205 c = get av add o i 206 if or eq c 34 eq c 92 207 ar_b 92 208 ar_b c 209 continue 210 end 211 if eq c 10 212 ar_b 92 213 ar_b 110 214 continue 215 end 216 if eq c 9 217 ar_b 92 218 ar_b 116 219 continue 220 end 221 if eq c 13 222 ar_b 92 223 ar_b 114 224 continue 225 end 226 if lt c 32 227 ar_b 92 228 ar_b 117 229 ar_b 48 230 ar_b 48 231 ar_b hexd ulong shr c 4 232 ar_b hexd ulong and c 15 233 continue 234 end 235 ar_b c 236 end 237 put gx xpos sub get gx xarn st 238 ret st 239 end 240 241 note evidence: `"u1","u2"` in the arena (offset; length in gx xpos) 242 fn op_evid av edit uchar * to ulong 243 st = get gx xarn 244 for i ulong get gop oevn 245 o = get gevl mul i 2 246 n = get gevl add mul i 2 1 247 if eq sf_ok part av o n false 248 die 64 mmev 249 end 250 if gt i 0 251 ar_b 44 252 end 253 ar_b 34 254 ar_lnv av o n 255 ar_b 34 256 end 257 put gx xpos sub get gx xarn st 258 ret st 259 end 260 261 note origin: "cli" | "import:" ORIGIN (prefix kept when already present) 262 fn op_origin av edit uchar * to ulong 263 if eq op_has oimp false 264 st = ar_t tcli 265 put gx xpos len tcli 266 ret st 267 end 268 o = get gop oimp 269 n = get gop add oimp 1 270 if eq sf_ok part av o n false 271 die 64 mmimp 272 end 273 st = get gx xarn 274 pre = false 275 if ge n len timp 276 pre = true 277 for i ulong len timp 278 if ne get av add o i get timp i 279 pre = false 280 end 281 end 282 end 283 if eq pre false 284 ar_tv timp 285 end 286 ar_lnv av o n 287 put gx xpos sub get gx xarn st 288 if gt get gx xpos 256 289 die 64 mmimp 290 end 291 ret st 292 end 293 294 fn o_ok id ulong seq ulong ex ulong to void 295 o_t tokid 296 o_id id 297 o_t tseq 298 o_u seq 299 o_t texp2 300 o_tsq ex 301 o_b 125 302 o_b 10 303 end 304 305 fn conflict i ulong to void 306 o_t tconf 307 o_hold i 308 o_b 125 309 o_b 10 310 o_flush 311 put gx xsel 1 312 o_t tpref 313 o_t tconf2 314 o_ar c_get i ctg c_get i ctgl 315 o_t theld 316 o_ar c_get i cag c_get i cagl 317 o_b 32 318 o_b 40 319 o_id c_get i cid 320 o_t tuntil 321 o_ts c_get i cexp 322 o_b 58 323 o_b 32 324 o_ar c_get i cin c_get i cinl 325 o_b 10 326 e_flush 327 exit 2 328 end 329 330 note holder of a conflicting active excl claim against (kind, target, agent), or ncl 331 fn cl_clash kd ulong t ulong tl ulong a ulong al ulong to ulong 332 for i ulong get gx xnc 333 if c_act i 334 if eq c_get i cmode 0 335 if eq ar_eq c_get i cag c_get i cagl a al false 336 if ne ov c_get i ckind c_get i ctg c_get i ctgl kd t tl 0 337 ret i 338 end 339 end 340 end 341 end 342 end 343 ret ncl 344 end 345 346 fn ev_emit ln edit uchar * echo bool to void 347 n = ev_build ln 348 pend_add ln n 349 if echo 350 ret 351 end 352 pe_flush false 353 end 354 355 fn cm_claim av edit uchar * ln edit uchar * to void 356 ag = op_sf av oag mmagent 357 agl = get gop add oag 1 358 se = op_sf av ose mmsess 359 if eq op_has otg false 360 die 64 mmtg 361 end 362 t = tg_canon av get gop otg get gop add otg 1 363 if eq t tbad 364 die 64 mmtg 365 end 366 put gev etg t 367 put gev etgl get gx xpos 368 put gev ekind get gx xkind 369 put gev ettl op_ttl av 370 md = ulong 0 371 if eq get gx xkind 0 372 md = 1 373 end 374 if op_has omode 375 md = op_word av omode 18 2 376 end 377 put gev emode md 378 put gev est 0 379 if op_has ost 380 put gev est op_word av ost 5 8 381 end 382 put gev ein op_intent av 383 put gev einl get gx xpos 384 put gev eev op_evid av 385 put gev eevl get gx xpos 386 put gev eor op_origin av 387 put gev eorl get gx xpos 388 put gev eag ag 389 put gev eagl agl 390 put gev ese se 391 put gev esel get gop add ose 1 392 put gev eop 0 393 put gev eexp add get gx xnow get gev ettl 394 lk_take 2 395 ld_all ln 396 if eq md 0 397 h = cl_clash get gev ekind get gev etg get gev etgl ag agl 398 if and ne h ncl eq op_has oimp false 399 conflict h 400 end 401 end 402 ev_emit ln false 403 o_ok get gev eid get gx xseq get gev eexp 404 end 405 406 note cl_mine: claim index for --id held by --agent (exit 4 otherwise) 407 fn cl_mine av edit uchar * to ulong 408 if eq op_has oid false 409 die 64 mmid 410 end 411 ag = op_sf av oag mmagent 412 o = get gop oid 413 n = get gop add oid 1 414 if ne n 16 415 die 4 mnf 416 end 417 for i ulong 16 418 if eq hexv get av add o i 16 419 die 4 mnf 420 end 421 end 422 c = ht_find hx_u av o 423 if eq c ncl 424 die 4 mnf 425 end 426 if eq ar_eq c_get c cag c_get c cagl ag get gop add oag 1 false 427 die 4 mnh 428 end 429 if ne c_get c cclo 0 430 die 4 mna 431 end 432 ret c 433 end 434 435 fn ev_from i ulong to void 436 put gev eid c_get i cid 437 put gev eag c_get i cag 438 put gev eagl c_get i cagl 439 put gev ese c_get i cse 440 put gev esel c_get i csel 441 put gev ekind c_get i ckind 442 put gev etg c_get i ctg 443 put gev etgl c_get i ctgl 444 put gev emode c_get i cmode 445 put gev est c_get i cst 446 put gev ein c_get i cin 447 put gev einl c_get i cinl 448 put gev ettl 0 449 put gev eexp c_get i cexp 450 put gev eev 0 451 put gev eevl 0 452 end 453 454 note hd_live: renew needs a lease that has not expired yet (exit 4 otherwise) 455 fn hd_live i ulong to void 456 if le c_get i cexp get gx xnow 457 die 4 mna 458 end 459 end 460 461 note hd_fin: sets the renew/release expiry of the event in gev, appends it and prints the result 462 fn hd_fin ln edit uchar * op ulong ttl ulong to void 463 if eq op 1 464 put gev ettl ttl 465 put gev eexp add get gx xnow ttl 466 end 467 if eq op 2 468 put gev eexp get gx xnow 469 end 470 ev_emit ln false 471 o_ok get gev eid get gx xseq get gev eexp 472 end 473 474 note cm_hold: renew (op 1), release (op 2), state (op 3) 475 fn cm_hold av edit uchar * ln edit uchar * op ulong to void 476 ttl = ulong 0 477 if eq op 1 478 ttl = op_ttl av 479 end 480 if and eq op 3 eq op_has ost false 481 die 64 mmst 482 end 483 stc = tbad 484 if op_has ost 485 stc = op_word av ost 5 8 486 end 487 ev = op_evid av 488 evl = get gx xpos 489 orr = op_origin av 490 orl = get gx xpos 491 lk_take 2 492 ld_all ln 493 i = cl_mine av 494 if eq op 1 495 hd_live i 496 end 497 ev_from i 498 put gev eop op 499 put gev eor orr 500 put gev eorl orl 501 put gev eev ev 502 put gev eevl evl 503 if ne stc tbad 504 put gev est stc 505 end 506 hd_fin ln op ttl 507 end 508 509 fn cm_who av edit uchar * ln edit uchar * to void 510 if eq op_has opos false 511 die 64 mmtg 512 end 513 t = tg_canon av get gop opos get gop add opos 1 514 if eq t tbad 515 die 64 mmtg 516 end 517 kd = get gx xkind 518 tl = get gx xpos 519 lk_take 1 520 ld_all ln 521 for i ulong get gx xnc 522 if c_act i 523 if ne ov c_get i ckind c_get i ctg c_get i ctgl kd t tl 0 524 o_claim i 525 o_b 10 526 end 527 end 528 end 529 end 530 531 note agent prefix filter: agent == P or starts with P "." 532 fn apf_ok av edit uchar * i ulong to bool 533 if eq op_has oapf false 534 ret true 535 end 536 o = get gop oapf 537 n = get gop add oapf 1 538 a = c_get i cag 539 al = c_get i cagl 540 if lt al n 541 ret false 542 end 543 for k ulong n 544 if ne ar_g add a k get av add o k 545 ret false 546 end 547 end 548 if eq al n 549 ret true 550 end 551 ret eq ar_g add a n 46 552 end 553 554 fn cm_list av edit uchar * ln edit uchar * to void 555 lk_take 1 556 ld_all ln 557 all = op_has oall 558 for i ulong get gx xnc 559 if or all c_act i 560 if apf_ok av i 561 o_claim i 562 o_b 10 563 end 564 end 565 end 566 end 567 568 note cf_pair: prints the conflict line of exclusive claims i and k (k active, other agent, overlapping) 569 fn cf_pair i ulong k ulong to bool 570 if eq c_act k false 571 ret false 572 end 573 if ne c_get k cmode 0 574 ret false 575 end 576 if ar_eq c_get i cag c_get i cagl c_get k cag c_get k cagl 577 ret false 578 end 579 ka = c_get k ckind 580 kt = c_get k ctg 581 kl = c_get k ctgl 582 r = ov c_get i ckind c_get i ctg c_get i ctgl ka kt kl 583 if eq r 0 584 ret false 585 end 586 o_t ta 587 o_claim i 588 o_t tb 589 o_claim k 590 o_t treas 591 o_wd wreason sub r 1 592 o_q 593 o_b 125 594 o_b 10 595 ret true 596 end 597 598 fn cm_conf ln edit uchar * to void 599 lk_take 1 600 ld_all ln 601 found = false 602 nc = get gx xnc 603 for i ulong nc 604 if c_act i 605 if eq c_get i cmode 0 606 for j ulong sub nc add i 1 607 if cf_pair i add add i j 1 608 found = true 609 end 610 end 611 end 612 end 613 end 614 if found 615 o_flush 616 exit 1 617 end 618 end 619 620 fn cm_expire av edit uchar * ln edit uchar * to void 621 ag = ulong 0 622 agl = ulong 0 623 if op_has oag 624 ag = op_sf av oag mmagent 625 agl = get gop add oag 1 626 else 627 ag = ar_t tdefag 628 agl = len tdefag 629 end 630 orr = ar_t tcli 631 orl = len tcli 632 pst = ar_t tpulse 633 if ar_eq ag agl pst len tpulse 634 orr = pst 635 orl = len tpulse 636 end 637 lk_take 2 638 ld_all ln 639 for i ulong get gx xnc 640 if eq c_get i cclo 0 641 if le c_get i cexp get gx xnow 642 ev_from i 643 put gev eop 4 644 put gev eag ag 645 put gev eagl agl 646 put gev eor orr 647 put gev eorl orl 648 n = ev_build ln 649 pend_add ln n 650 c_put i cclo 2 651 if eq pe_room false 652 pe_flush true 653 end 654 end 655 end 656 end 657 pe_flush true 658 end 659 660 note read a small file (whole) into gso; returns its length 661 fn rd_small off ulong n ulong to ulong 662 fd = fopen gpth off n 524288 0 663 if lt fd 0 664 die 70 mpub 665 end 666 k = read int fd gso 0 4096 667 c = fclose int fd 668 if le k 0 669 die 70 mpub 670 end 671 ret ulong k 672 end 673 674 fn cm_init to void 675 a = faccess gpth get gx xpkey get gx xpkeyl 0 676 if ne a 0 677 si_open 678 pk_reset 679 pk_g get gx xsig get gx xsigl 680 pk_t tkeyg 681 pk_g get gx xpkd get gx xpkdl 682 r = si_run 683 if ne r 0 684 die 70 mkeyg 685 end 686 end 687 n = rd_small get gx xppub get gx xppubl 688 if eq get gso sub n 1 10 689 n = sub n 1 690 end 691 if lt n len tdid 692 die 70 mpub 693 end 694 for i ulong n 695 c = get gso i 696 if or or lt c 33 gt c 126 or eq c 34 eq c 92 697 die 70 mpub 698 end 699 end 700 o_t tokpub 701 for j ulong n 702 o_b get gso j 703 end 704 o_b 34 705 o_b 125 706 o_b 10 707 end 708 709 fn v_fail seq ulong why ulong to void 710 o_t tvbad 711 o_u seq 712 o_t terr2 713 o_wd wwhy why 714 o_b 34 715 o_b 125 716 o_b 10 717 o_flush 718 exit 3 719 end 720 721 note vf_line: full check of one line k (= expected seq). 0 ok, else wwhy index + 1. 722 fn vf_line ln edit uchar * n ulong to ulong 723 r = ld_line ln n 724 if ne r 0 725 ret r 726 end 727 hp = get gp qhpos 728 ev_hash ln hp 729 for i ulong 64 730 if ne get ln add add hp 9 i get glh i 731 ret 4 732 end 733 end 734 if eq get gp qop 0 735 q = get gp qid 736 for j ulong 16 737 put gst j get ln add q j 738 put ln add q j 48 739 end 740 ev_hash ln hp 741 for k ulong 16 742 if ne get ln add add hp 9 k get gst k 743 ret 5 744 end 745 end 746 end 747 for a ulong 64 748 si_b get glh a 749 end 750 si_b 32 751 s = get gp qsig 752 for b ulong 128 753 si_b get ln add s b 754 end 755 si_b 10 756 ret 0 757 end 758 759 note vf_sigs: verify the staged `hash sig` lines; a bad line K sets gx[xbad] = K 760 fn vf_sigs to void 761 put gx xbad 0 762 good = get gx xevn 763 if eq good 0 764 x = fclose int get gx xmfd 765 ret 766 end 767 pk_reset 768 pk_g get gx xsig get gx xsigl 769 pk_t tver 770 pk_g get gx xppub get gx xppubl 771 r = si_run 772 n = get gx xson 773 if lt n 4 774 die 70 mverb 775 end 776 if and eq r 0 eq get gso 0 111 777 ret 778 end 779 if ne r 3 780 die 70 mverb 781 end 782 v = ulong 0 783 for i ulong sub n 4 784 c = get gso add i 4 785 if or lt c 48 gt c 57 786 break 787 end 788 v = add mul v 10 ulong sub c 48 789 end 790 if or eq v 0 gt v good 791 die 70 mverb 792 end 793 put gx xbad v 794 end 795 fn cm_verify ln edit uchar * to void 796 lk_take 1 797 ld_reset 798 fail = ulong 0 799 why = ulong 0 800 k = ulong 0 801 fd = ld_open 802 if ge fd 0 803 si_open 804 r_open fd 805 while true bound 999999 806 n = r_line ln 807 if eq n -1 808 break 809 end 810 k = add k 1 811 if eq n -3 812 die 70 mio 813 end 814 if lt n 0 815 fail = k 816 break 817 end 818 r = vf_line ln ulong n 819 if ne r 0 820 fail = k 821 why = sub r 1 822 break 823 end 824 end 825 c = fclose int fd 826 if eq k 0 827 x = fclose int get gx xmfd 828 end 829 if gt k 0 830 vf_sigs 831 end 832 end 833 if gt get gx xbad 0 834 v_fail get gx xbad 5 835 end 836 if gt fail 0 837 v_fail fail why 838 end 839 o_t tvok 840 o_u get gx xevn 841 o_t thead 842 for i ulong 64 843 o_b get glh i 844 end 845 o_b 34 846 o_b 125 847 o_b 10 848 end 849