shrub/pkg/arvo/sys/vane/jael.hoon

1206 lines
35 KiB
Plaintext
Raw Normal View History

2019-08-07 01:42:37 +03:00
!: :: /vane/jael
2016-11-24 07:25:07 +03:00
:: :: %reference/0
!? 150
::
::
:: %jael: secrets and promises.
::
:: todo:
::
2016-11-24 07:25:07 +03:00
:: - communication with other vanes:
:: - actually use %behn for expiring secrets
:: - report %ames propagation errors to user
::
:: - nice features:
:: - scry namespace
:: - task for converting invites to tickets
::
|= pit/vase
=, pki:jael
=, able:jael
2016-12-02 22:34:07 +03:00
=, crypto
2016-11-24 07:25:07 +03:00
=, jael
=, ethereum
=, rpc
=, azimuth
2019-08-07 01:42:37 +03:00
=, point=point:able:jael
2016-11-24 07:25:07 +03:00
:: ::::
:::: # models :: data structures
:: ::::
:: the %jael state comes in two parts: absolute
:: and relative.
::
:: ++state-relative is subjective, denormalized and
:: derived. it consists of all the state we need to
:: manage subscriptions efficiently.
::
=> |%
2019-08-07 01:42:37 +03:00
+$ state :: all vane state
2019-06-21 21:03:53 +03:00
$: ver=$0 :: vane version
2019-08-07 01:42:37 +03:00
pki=state-pki ::
etn=state-eth-node :: eth connection state
2016-11-24 07:25:07 +03:00
== ::
2019-08-07 01:42:37 +03:00
+$ state-pki :: urbit metadata
$: $= own :: vault (vein)
2019-06-21 21:03:53 +03:00
$: yen=(set duct) :: trackers
sig=(unit oath) :: for a moon
tuf=(list turf) :: domains
boq=@ud :: boot block
2019-08-07 01:42:37 +03:00
nod=purl:eyre :: eth gateway
2019-06-21 21:03:53 +03:00
fak=_| :: fake keys
lyf=life :: version
jaw=(map life ring) :: private keys
2016-11-24 07:25:07 +03:00
== ::
2019-08-07 01:42:37 +03:00
$= zim :: public
$: yen=(jug duct ship) :: trackers
ney=(jug ship duct) :: reverse trackers
2019-08-20 20:22:52 +03:00
nel=(set duct) :: trackers of all
dns=dnses :: on-chain dns state
pos=(map ship point) :: on-chain ship state
== ::
== ::
2019-08-07 01:42:37 +03:00
+$ message :: message to her jael
$% [%nuke whos=(set ship)] :: cancel trackers
[%public-keys whos=(set ship)] :: view ethereum events
2016-11-24 07:25:07 +03:00
== ::
2019-08-20 02:40:57 +03:00
+$ message-result
$% [%public-keys-result =public-keys-result] :: public keys boon
==
2019-08-07 01:42:37 +03:00
+$ card :: i/o action
(wind note gift) ::
2016-11-24 07:25:07 +03:00
:: ::
2019-06-22 00:45:00 +03:00
+$ move :: output
2019-06-21 21:03:53 +03:00
[p=duct q=card] ::
:: ::
+$ note :: out request $->
$~ [%a %plea *ship *plea:ames] ::
2019-08-07 01:42:37 +03:00
$% $: %a :: to %ames
2019-07-29 14:05:52 +03:00
$>(%plea task:able:ames) :: send request message
== ::
$: %b :: to %behn
$>(%wait task:able:behn) :: set timer
== ::
$: %g :: to %gall
$>(%deal task:able:gall) :: talk to app
2019-07-04 03:08:23 +03:00
== ::
$: %j :: to self
2019-08-07 01:42:37 +03:00
$>(%listen task) :: set ethereum source
== ::
$: @tas ::
$% $>(%init vane-task) :: report install
== == == ::
:: ::
2019-08-07 01:42:37 +03:00
+$ peer-sign [=ship =udiff:point] ::
:: ::
+$ sign :: in result $<-
$~ [%a %done ~] ::
$% $: %a ::
$% $>(%boon gift:able:ames) :: message response
$>(%done gift:able:ames) :: message (n)ack
$>(%lost gift:able:ames) :: lost boon
== == ::
$: %b ::
$>(%wake gift:able:behn) ::
== ::
2019-11-19 07:36:21 +03:00
$: %g ::
2019-08-07 01:42:37 +03:00
$> $? %onto ::
%unto ::
== ::
2019-11-19 07:36:21 +03:00
gift:able:gall ::
2019-08-07 01:42:37 +03:00
==
== ::
2016-11-24 07:25:07 +03:00
-- ::
:: ::::
:::: # light :: light cores
:: ::::
=> |%
:: :: ++ez
:::: ## ethereum^light :: wallet algebra
:: ::::
++ ez
:: simple ethereum-related utility arms.
::
|%
::
:: +order-events: sort changes by block and log numbers
::
++ order-events
|= loz=(list (pair event-id diff-azimuth))
^+ loz
%+ sort loz
:: sort by block number, then by event log number,
::TODO then by diff priority.
|= [[[b1=@ud l1=@ud] *] [[b2=@ud l2=@ud] *]]
?. =(b1 b2) (lth b1 b2)
?. =(l1 l2) (lth l1 l2)
&
--
2016-11-24 07:25:07 +03:00
--
:: ::::
:::: # heavy :: heavy engines
:: ::::
=> |%
:: :: ++of
:::: ## main^heavy :: main engine
:: ::::
++ of
:: this core handles all top-level %jael semantics,
:: changing state and recording moves.
::
2019-08-07 01:42:37 +03:00
:: logically we could nest the ++su core within it, but
:: we keep them separated for clarity. the ++curd and
:: ++cure arms complete relative and absolute effects,
:: respectively, at the top level.
::
:: XX doc
2016-11-24 07:25:07 +03:00
::
2019-08-07 01:42:37 +03:00
:: a general pattern here is that we use the ++et core
:: to generate absolute effects (++change), then invoke
2016-11-24 07:25:07 +03:00
:: ++su to calculate the derived effect of these changes.
::
:: for ethereum-related events, this is preceded by
:: invocation of ++et, which produces ethereum-level
:: changes (++chain). these get turned into absolute
:: effects by ++cute.
::
2016-11-24 07:25:07 +03:00
:: arvo issues: should be merged with the top-level
:: vane interface when that gets cleaned up a bit.
::
=| moz/(list move)
2018-12-12 11:34:05 +03:00
=| $: $: :: our: identity
:: now: current time
2016-11-24 07:25:07 +03:00
:: eny: unique entropy
::
2018-12-12 11:34:05 +03:00
our=ship
2018-12-06 00:41:21 +03:00
now=@da
eny=@uvJ
2016-11-24 07:25:07 +03:00
==
:: all vane state
::
state
==
:: lex: all durable state
:: moz: pending actions
::
=* lex ->
|%
:: :: ++abet:of
++ abet :: resolve
[(flop moz) lex]
2018-10-12 19:48:52 +03:00
:: :: ++sein:of
2019-08-07 01:42:37 +03:00
++ emit
|= =move
+>.$(moz [move moz])
::
++ poke-watch
|= [hen=duct app=term =purl:eyre]
%- emit
:* hen
%pass
/[app]/poke
2019-11-19 07:36:21 +03:00
%g
2019-08-07 01:42:37 +03:00
%deal
[our our]
app
%poke
%azimuth-tracker-poke
!>([%watch (crip (en-purl:html purl))])
==
::
2018-10-12 19:48:52 +03:00
++ sein :: sponsor
|= who=ship
^- ship
:: XX save %dawn sponsor in .own.sub, check there
::
2019-08-07 01:42:37 +03:00
=/ pot (~(get by pos.zim.pki) who)
?: ?& ?=(^ pot)
2019-08-07 01:42:37 +03:00
?=(^ sponsor.u.pot)
2018-10-12 19:48:52 +03:00
==
2019-08-07 01:42:37 +03:00
u.sponsor.u.pot
(^sein:title who)
2018-10-12 19:48:52 +03:00
:: :: ++saxo:of
++ saxo :: sponsorship chain
|= who/ship
^- (list ship)
=/ dad (sein who)
[who ?:(=(who dad) ~ $(who dad))]
2016-11-24 07:25:07 +03:00
:: :: ++call:of
++ call :: invoke
|= $: :: hen: event cause
:: tac: event data
::
hen/duct
tac/task
==
^+ +>
?- -.tac
::
:: boot from keys
:: $: $dawn
:: =seed
:: spon=ship
2019-08-07 01:42:37 +03:00
:: czar=(map ship [=rift =life =pass])
:: turf=(list turf)}
:: bloq=@ud
:: node=purl
:: ==
::
%dawn
2018-12-12 11:34:05 +03:00
:: single-homed
::
2019-08-07 01:42:37 +03:00
~| [our who.seed.tac]
2018-12-12 11:34:05 +03:00
?> =(our who.seed.tac)
:: save our boot block
::
2019-08-07 01:42:37 +03:00
=. boq.own.pki bloq.tac
:: save our ethereum gateway (required for galaxies)
::
2019-08-07 01:42:37 +03:00
=. nod.own.pki
%+ fall node.tac
(need (de-purl:html 'http://eth-mainnet.urbit.org:8545'))
:: save our parent signature (only for moons)
::
2019-08-07 01:42:37 +03:00
=. sig.own.pki sig.seed.tac
2019-08-07 23:54:47 +03:00
:: load our initial public key
::
=/ spon-ship=(unit ship)
=/ flopped-spon (flop spon.tac)
?~(flopped-spon ~ `ship.i.flopped-spon)
2019-08-07 01:42:37 +03:00
=. pos.zim.pki
=/ cub (nol:nu:crub:crypto key.seed.tac)
2019-08-07 01:42:37 +03:00
%+ ~(put by pos.zim.pki)
our
[0 lyf.seed.tac (my [lyf.seed.tac [1 pub:ex:cub]] ~) spon-ship]
2019-08-07 01:42:37 +03:00
:: our initial private key
::
2019-08-07 01:42:37 +03:00
=. lyf.own.pki lyf.seed.tac
=. jaw.own.pki (my [lyf.seed.tac key.seed.tac] ~)
:: XX save sponsor in .own.pki
:: XX reconcile with .dns.eth
:: set initial domains
::
=. tuf.own.pki turf.tac
:: our initial galaxy table as a +map from +life to +public
::
=/ spon-points=(list [ship point])
%+ turn spon.tac
|= [=ship az-point=point:azimuth]
~| [%sponsor-point az-point]
?> ?=(^ net.az-point)
:* ship
continuity-number.u.net.az-point
life.u.net.az-point
(malt [life.u.net.az-point 1 pass.u.net.az-point] ~)
?. has.sponsor.u.net.az-point
2019-08-07 01:42:37 +03:00
~
`who.sponsor.u.net.az-point
2019-08-07 01:42:37 +03:00
==
=/ points=(map =ship =point)
%- ~(run by czar.tac)
2019-08-07 01:42:37 +03:00
|= [=a=rift =a=life =a=pass]
^- point
[a-rift a-life (malt [a-life 1 a-pass] ~) ~]
=. points
(~(gas by points) spon-points)
=. +>.$
%- curd =< abet
(public-keys:~(feel su hen our now pki etn) %full points)
::
2019-08-07 01:42:37 +03:00
:: start subscriptions
::
=. +>.$ (poke-watch hen %azimuth-tracker nod.own.pki)
=. +>.$
2019-12-17 10:38:44 +03:00
:: get everything from azimuth-tracker because jael subscriptions
:: seem to be flaky for now
::
?: &
%- curd =< abet
(sources:~(feel su hen our now pki etn) ~ [%| %azimuth-tracker])
::
?- (clan:title our)
%czar
%- curd =< abet
(sources:~(feel su hen our now pki etn) ~ [%| %azimuth-tracker])
::
*
=. +>.$
%- curd =< abet
%+ sources:~(feel su hen our now pki etn)
(silt (turn spon-points head))
[%| %azimuth-tracker]
%- curd =< abet
(sources:~(feel su hen our now pki etn) ~ [%& (need spon-ship)])
==
::
=. moz
%+ weld moz
:: order is crucial!
::
2019-11-19 07:36:21 +03:00
:: %dill must init after %gall
:: the %give init (for unix) must be after %dill init
:: %jael init must be deferred (makes http requests)
::
^- (list move)
2019-08-07 01:42:37 +03:00
:~ [hen %give %init our]
2019-07-04 02:01:45 +03:00
[hen %slip %e %init our]
[hen %slip %d %init our]
2019-11-19 07:36:21 +03:00
[hen %slip %g %init our]
[hen %slip %c %init our]
[hen %slip %a %init our]
==
+>.$
::
:: boot fake
2018-12-12 11:50:40 +03:00
:: [%fake =ship]
::
%fake
2018-12-12 11:34:05 +03:00
:: single-homed
::
2018-12-12 11:50:40 +03:00
?> =(our ship.tac)
:: fake keys are deterministically derived from the ship
::
=/ cub (pit:nu:crub:crypto 512 our)
:: our initial public key
::
2019-08-07 01:42:37 +03:00
=. pos.zim.pki
%+ ~(put by pos.zim.pki)
our
[rift=1 life=1 (my [`@ud`1 [`life`1 pub:ex:cub]] ~) `(^sein:title our)]
:: our private key
::
:: Private key updates are disallowed for fake ships,
:: so we do this first.
::
2019-08-07 01:42:37 +03:00
=. lyf.own.pki 1
=. jaw.own.pki (my [1 sec:ex:cub] ~)
:: set the fake bit
::
2019-08-07 01:42:37 +03:00
=. fak.own.pki &
:: initialize other vanes per the usual procedure
::
:: Except for ourselves!
::
=. moz
%+ weld moz
^- (list move)
:~ [hen %give %init our]
2019-07-04 02:01:45 +03:00
[hen %slip %e %init our]
[hen %slip %d %init our]
2019-11-19 07:36:21 +03:00
[hen %slip %g %init our]
[hen %slip %c %init our]
[hen %slip %a %init our]
==
+>.$
::
:: set ethereum source
2019-08-07 01:42:37 +03:00
:: [%listen whos=(set ship) =source]
2016-11-24 07:25:07 +03:00
::
2019-08-07 01:42:37 +03:00
%listen
~& [%jael-listen whos source]:tac
%- curd =< abet
(sources:~(feel su hen our now pki etn) [whos source]:tac)
2016-11-24 07:25:07 +03:00
::
:: cancel all trackers from duct
2019-08-07 01:42:37 +03:00
:: {$nuke whos=(set ship)}
2016-11-24 07:25:07 +03:00
::
$nuke
2019-08-07 01:42:37 +03:00
=/ ships=(list ship)
%~ tap in
%- ~(int in whos.tac)
(~(get ju yen.zim.pki) hen)
=. ney.zim.pki
|- ^- (jug ship duct)
?~ ships
ney.zim.pki
(~(del ju $(ships t.ships)) i.ships hen)
=. yen.zim.pki
|- ^- (jug duct ship)
?~ ships
yen.zim.pki
(~(del ju $(ships t.ships)) hen i.ships)
2019-08-20 20:22:52 +03:00
=? nel.zim.pki ?=(~ whos.tac)
(~(del in nel.zim.pki) hen)
2019-08-07 01:42:37 +03:00
?^ whos.tac
+>.$
%_ +>.$
yen.own.pki (~(del in yen.own.pki) hen)
2016-11-24 07:25:07 +03:00
==
::
2019-08-08 01:15:25 +03:00
:: update private keys
::
%rekey
%- curd =< abet
(private-keys:~(feel su hen our now pki etn) life.tac ring.tac)
2019-08-08 01:15:25 +03:00
::
:: update private keys
::
%moon
?. =(%earl (clan:title ship.tac))
~& [%not-moon ship.tac]
+>.$
?. =(our (^sein:title ship.tac))
~& [%not-our-moon ship.tac]
+>.$
%- curd =< abet
(~(new-event su hen our now pki etn) [ship udiff]:tac)
::
:: watch public keys
2019-08-07 01:42:37 +03:00
:: [%public-keys ships=(set ship)]
::
2019-08-07 01:42:37 +03:00
%public-keys
%- curd =< abet
(~(public-keys ~(feed su hen our now pki etn) hen) ships.tac)
::
:: seen after breach
:: [%meet our=ship who=ship]
::
%meet
2019-08-07 01:42:37 +03:00
+>.$
::
:: XX should be a subscription
:: XX reconcile with .dns.eth
:: request domains
:: [%turf ~]
::
%turf
:: ships with real keys must have domains,
:: those with fake keys must not
::
2019-08-07 01:42:37 +03:00
~| [fak.own.pki tuf.own.pki]
?< =(fak.own.pki ?=(^ tuf.own.pki))
+>.$(moz [[hen %give %turf tuf.own.pki] moz])
::
:: learn of kernel upgrade
:: [%vega ~]
::
%vega
+>.$::
:: in response to memory pressure
:: [%trim p=@ud]
::
%trim
+>.$
::
2016-11-24 07:25:07 +03:00
:: watch private keys
2019-08-07 01:42:37 +03:00
:: {$private-keys $~}
::
2019-08-07 01:42:37 +03:00
%private-keys
(curd abet:~(private-keys ~(feed su hen our now pki etn) hen))
2019-01-30 01:41:55 +03:00
::
%wegh
%_ +>
moz
:_ moz
^- move
:^ hen %give %mass
^- mass
:+ %jael %|
2019-08-07 01:42:37 +03:00
:~ pki+&+pki
2019-01-30 01:41:55 +03:00
etn+&+etn
dot+&+lex
2019-01-30 01:41:55 +03:00
==
==
2016-11-24 07:25:07 +03:00
::
:: authenticated remote request
:: {$west p/ship q/path r/*}
::
2019-07-29 14:05:52 +03:00
%plea
=* her ship.tac
=/ mes ;;(message payload.plea.tac)
2016-11-24 07:25:07 +03:00
?- -.mes
::
:: cancel trackers
2019-08-07 01:42:37 +03:00
:: [%nuke whos=(set ship)]
::
%nuke
=. moz [[hen %give %done ~] moz]
$(tac mes)
::
2018-06-01 01:34:21 +03:00
:: view ethereum events
2019-08-07 01:42:37 +03:00
:: [%public-keys whos=(set ship)]
::
2019-08-07 01:42:37 +03:00
%public-keys
=. moz [[hen %give %done ~] moz]
2019-08-07 01:42:37 +03:00
$(tac mes)
2016-11-24 07:25:07 +03:00
==
==
::
++ take
|= [tea=wire hen=duct hin=sign]
^+ +>
?- hin
2019-07-29 14:05:52 +03:00
[%a %done *]
?~ error.hin +>.$
2019-07-29 14:05:52 +03:00
~& [%done-bad tag.u.error.hin]
%- (slog tang.u.error.hin)
::TODO fail:et
+>.$
2019-08-20 02:40:57 +03:00
::
[%a %boon *]
=+ ;; [%public-keys-result =public-keys-result] payload.hin
%- curd =< abet
(public-keys:~(feel su hen our now pki etn) public-keys-result)
::
[%a %lost *]
:: TODO: better error handling
::
~| %jael-ames-lost
!!
::
[%b %wake *]
?^ error.hin
%- %+ slog
leaf+"jael unable to resubscribe, run :azimuth-tracker|listen"
u.error.hin
+>.$
?> ?=([%breach @ ~] tea)
=/ =source-id (slav %ud i.t.tea)
=/ =source (~(got by sources.etn) source-id)
=/ ships (~(get ju ship-sources-reverse.etn) source-id)
%- curd =< abet
(sources:~(feel su hen our now pki etn) ships source)
::
2019-11-19 07:36:21 +03:00
[%g %onto *]
2019-08-07 01:42:37 +03:00
~& [%jael-onto tea hin]
+>.$
::
2019-11-19 07:36:21 +03:00
[%g %unto *]
2019-08-07 01:42:37 +03:00
?- +>-.hin
$kick ~|([%jael-unexpected-quit tea hin] !!)
$poke-ack
2019-08-07 01:42:37 +03:00
?~ p.p.+>.hin
+>.$
%- (slog leaf+"jael-bad-coup" u.p.p.+>.hin)
+>.$
::
2019-11-07 09:19:32 +03:00
$watch-ack
2019-08-07 01:42:37 +03:00
?~ p.p.+>.hin
+>.$
%- (slog u.p.p.+>.hin)
~|([%jael-unexpected-reap tea hin] +>.$)
::
2019-11-07 09:19:32 +03:00
$fact
2019-08-07 01:42:37 +03:00
?> ?=([@ *] tea)
=* app i.tea
=/ =peer-sign ;;(peer-sign q.q.cage.p.+>.hin)
2019-08-07 01:42:37 +03:00
%- curd =< abet
(~(new-event su hen our now pki etn) peer-sign)
2019-08-07 01:42:37 +03:00
==
==
2016-11-24 07:25:07 +03:00
:: :: ++curd:of
++ curd :: relative moves
2018-10-26 00:37:04 +03:00
|= $: moz/(list move)
2019-08-07 01:42:37 +03:00
pki/state-pki
2018-10-26 00:37:04 +03:00
etn/state-eth-node
==
2019-08-07 23:54:47 +03:00
+>(pki pki, etn etn, moz (weld (flop moz) ^moz))
2016-11-24 07:25:07 +03:00
--
:: :: ++su
:::: ## relative^heavy :: subjective engine
:: ::::
++ su
:: the ++su core handles all derived state,
2016-11-24 07:25:07 +03:00
:: subscriptions, and actions.
::
:: ++feed:su registers subscriptions.
2016-11-24 07:25:07 +03:00
::
:: ++feel:su checks if a ++change should notify
:: any subscribers.
::
2019-08-07 01:42:37 +03:00
=| moz=(list move)
=| $: hen=duct
our=ship
now=@da
2019-08-07 01:42:37 +03:00
state-pki
state-eth-node
2016-11-24 07:25:07 +03:00
==
:: moz: moves in reverse order
2019-08-07 01:42:37 +03:00
:: pki: relative urbit state
2016-11-24 07:25:07 +03:00
::
=* pki ->+>-
=* etn ->+>+
2016-11-24 07:25:07 +03:00
|%
2019-08-07 01:42:37 +03:00
++ this-su .
2016-11-24 07:25:07 +03:00
:: :: ++abet:su
++ abet :: resolve
2019-08-07 23:54:47 +03:00
[(flop moz) pki etn]
2016-11-24 07:25:07 +03:00
:: :: ++exec:su
2019-08-07 01:42:37 +03:00
++ emit
|= =move
+>.$(moz [move moz])
::
2016-11-24 07:25:07 +03:00
++ exec :: mass gift
|= {yen/(set duct) cad/card}
=/ noy ~(tap in yen)
2019-08-07 01:42:37 +03:00
|- ^+ this-su
?~ noy this-su
2016-11-24 07:25:07 +03:00
$(noy t.noy, moz [[i.noy cad] moz])
::
2019-08-07 01:42:37 +03:00
++ emit-peer
|= [app=term =path]
%- emit
:* hen
%pass
[app path]
2019-11-19 07:36:21 +03:00
%g
2019-08-07 01:42:37 +03:00
%deal
[our our]
app
2019-11-07 09:19:32 +03:00
%watch
2019-08-07 01:42:37 +03:00
path
==
::
++ peer
|= [app=term whos=(set ship)]
?: =(~ whos)
(emit-peer app /)
=/ whol=(list ship) ~(tap in whos)
|- ^+ this-su
?~ whol this-su
=. this-su (emit-peer app /(scot %p i.whol))
$(whol t.whol)
::
++ public-keys-give
|= [yen=(set duct) =public-keys-result]
=+ yez=~(tap in yen)
2019-08-07 01:42:37 +03:00
|- ^+ this-su
?~ yez this-su
=* d i.yez
=. this-su
?. &(?=([[%a @ @ *] *] d) !=(%pubs i.t.i.d))
%- emit
[d %give %public-keys public-keys-result]
%- emit
2019-08-20 02:54:30 +03:00
[d %give %boon %public-keys-result public-keys-result]
2019-07-12 00:41:43 +03:00
$(yez t.yez)
2018-11-03 03:05:41 +03:00
::
2019-08-07 01:42:37 +03:00
++ get-source
|= who=@p
^- source
=/ ship-source (~(get by ship-sources.etn) who)
?^ ship-source
(~(got by sources) u.ship-source)
?: =((clan:title who) %earl)
[%& (^sein:title who)]
(~(got by sources) default-source.etn)
::
++ get-source-id
|= =source
^- [source-id _this-su]
=/ source-reverse (~(get by sources-reverse) source)
?^ source-reverse
[u.source-reverse this-su]
:- top-source-id.etn
%_ this-su
top-source-id.etn +(top-source-id.etn)
sources.etn (~(put by sources) top-source-id.etn source)
sources-reverse.etn (~(put by sources-reverse) source top-source-id.etn)
2018-11-03 03:05:41 +03:00
==
2019-08-07 01:42:37 +03:00
::
++ new-event
|= [=a=ship =a=udiff:point]
^+ this-su
=/ a-point=point (~(gut by pos.zim.pki) a-ship *point)
=/ a-diff=(unit diff:point) (udiff-to-diff:point a-udiff a-point)
?~ a-diff
this-su
(public-keys:feel %diff a-ship u.a-diff)
::
2019-08-20 20:22:52 +03:00
++ subscribers-on-ship
|= =ship
^- (set duct)
=/ specific-subs (~(get ju ney.zim) ship)
=/ general-subs=(set duct)
?: ?=(?(%czar %king %duke) (clan:title ship))
nel.zim
~
2019-08-20 20:22:52 +03:00
(~(uni in specific-subs) general-subs)
::
2019-08-07 01:42:37 +03:00
++ feed
2016-11-24 07:25:07 +03:00
|_ :: hen: subscription source
::
hen/duct
::
2019-08-07 01:42:37 +03:00
:: Handle subscription to public-keys
::
++ public-keys
|= whos=(set ship)
?: fak.own.pki
(public-keys:fake whos)
:: Subscribe to parent of moons
::
=. ..feed
=/ moons=(jug ship ship)
%- ~(gas ju *(jug spon=ship who=ship))
%+ murn ~(tap in whos)
|= who=ship
^- (unit [spon=ship child=ship])
?. =(%earl (clan:title who))
~
?: (~(has by ship-sources) who)
~
`[(^sein:title who) who]
=/ moonl=(list [spon=ship ships=(set ship)])
~(tap by moons)
|- ^+ ..feed
?~ moonl
..feed
?: =(our spon.i.moonl)
2019-08-07 01:42:37 +03:00
$(moonl t.moonl)
=. ..feed (sources:feel ships.i.moonl [%& spon.i.moonl])
$(moonl t.moonl)
2019-08-07 01:42:37 +03:00
:: Add to subscriber list
::
=. ney.zim
=/ whol=(list ship) ~(tap in whos)
|- ^- (jug ship duct)
?~ whol
ney.zim
(~(put ju $(whol t.whol)) i.whol hen)
=. yen.zim
%- ~(gas ju yen.zim)
%+ turn ~(tap in whos)
|= who=ship
[hen who]
2019-08-20 20:22:52 +03:00
=? nel.zim ?=(~ whos)
(~(put in nel.zim) hen)
2019-08-07 01:42:37 +03:00
:: Give initial result
::
=/ =public-keys-result
:- %full
?: =(~ whos)
pos.zim
%- my ^- (list (pair ship point))
%+ murn
~(tap in whos)
|= who=ship
^- (unit (pair ship point))
=/ pub (~(get by pos.zim) who)
?~ pub ~
?: =(0 life.u.pub) ~
`[who u.pub]
=. ..feed (public-keys-give (sy hen ~) public-keys-result)
..feed
::
:: Handle subscription to private-keys
::
++ private-keys
2016-11-24 07:25:07 +03:00
%_ ..feed
2019-08-07 01:42:37 +03:00
moz [[hen %give %private-keys [lyf jaw]:own] moz]
2016-11-24 07:25:07 +03:00
yen.own (~(put in yen.own) hen)
==
::
2019-08-07 01:42:37 +03:00
++ fake
?> fak.own.pki
|%
2019-08-07 01:42:37 +03:00
++ public-keys
|= whos=(set ship)
=/ whol=(list ship) ~(tap in whos)
=/ passes
|- ^- (list [who=ship =pass])
?~ whol
~
=/ cub (pit:nu:crub:crypto 512 i.whol)
:- [i.whol pub:ex:cub]
$(whol t.whol)
=/ points=(list (pair ship point))
%+ turn passes
|= [who=ship =pass]
^- [who=ship =point]
[who [rift=1 life=1 (my [1 1 pass] ~) `(^sein:title who)]]
=. moz [[hen %give %public-keys %full (my points)] moz]
..feel
2019-08-07 01:42:37 +03:00
--
2016-11-24 07:25:07 +03:00
--
2019-08-07 01:42:37 +03:00
::
++ feel
2016-11-24 07:25:07 +03:00
|%
::
2019-08-07 01:42:37 +03:00
:: Update public-keys
2016-11-24 07:25:07 +03:00
::
2019-08-07 01:42:37 +03:00
++ public-keys
|= =public-keys-result
^+ ..feel
?: ?=(%full -.public-keys-result)
=/ pointl=(list [who=ship =point])
~(tap by points.public-keys-result)
|- ^+ ..feel
?~ pointl
..feel(pos.zim (~(uni by pos.zim) points.public-keys-result))
:: if changing rift upward, then signal a breach
::
=? ..feel
=/ point
(~(get by pos.zim) who.i.pointl)
?& ?=(^ point)
(gth rift.point.i.pointl rift.u.point)
==
=. ..feel
%+ public-keys-give
(subscribers-on-ship who.i.pointl)
[%breach who.i.pointl]
=/ sor (~(get by sources-reverse) %& who.i.pointl)
?~ sor
..feel
:: delay resubscribing because Ames is going to clear any
:: messages we send now.
::
(emit hen %pass /breach/(scot %ud u.sor) %b %wait now)
::
=. ..feel
%+ public-keys-give
(subscribers-on-ship who.i.pointl)
[%full (my i.pointl ~)]
$(pointl t.pointl)
::
?: ?=(%breach -.public-keys-result)
:: we calculate our own breaches based on our local state
::
..feel
2019-08-07 01:42:37 +03:00
=* who who.public-keys-result
=/ a-diff=diff:point diff.public-keys-result
=/ maybe-point (~(get by pos.zim) who)
=/ =point (fall maybe-point *point)
:: if changing rift upward, then signal a breach
::
=? ..feel
?& ?=(%rift -.a-diff)
(gth to.a-diff rift.point)
==
%+ public-keys-give
(subscribers-on-ship who)
[%breach who]
::
2019-08-07 01:42:37 +03:00
=. point
?- -.a-diff
%spon point(sponsor to.a-diff)
%rift point(rift to.a-diff)
%keys
%_ point
life life.to.a-diff
keys
%+ ~(put by keys.point)
life.to.a-diff
[crypto-suite pass]:to.a-diff
==
2018-10-26 00:37:04 +03:00
==
::
2019-08-07 01:42:37 +03:00
=. pos.zim (~(put by pos.zim) who point)
%+ public-keys-give
2019-08-20 20:22:52 +03:00
(subscribers-on-ship who)
2019-08-07 01:42:37 +03:00
?~ maybe-point
[%full (my [who point]~)]
[%diff who a-diff]
2016-11-24 07:25:07 +03:00
::
2019-08-07 01:42:37 +03:00
:: Update private-keys
2018-10-12 19:48:52 +03:00
::
2019-08-07 01:42:37 +03:00
++ private-keys
|= [=life =ring]
^+ ..feel
?: &(=(lyf.own life) =((~(get by jaw.own) life) `ring))
..feel
=. lyf.own life
=. jaw.own (~(put by jaw.own) life ring)
(exec yen.own [%give %private-keys lyf.own jaw.own])
2018-10-26 00:37:04 +03:00
::
:: Change sources for ships
::
2019-08-07 01:42:37 +03:00
++ sources
|= [whos=(set ship) =source]
^+ ..feel
=^ =source-id this-su (get-source-id source)
=. ..feed
?~ whos
..feed(default-source.etn source-id)
=/ whol=(list ship) ~(tap in `(set ship)`whos)
=. ship-sources.etn
|- ^- (map ship ^source-id)
?~ whol
ship-sources.etn
(~(put by $(whol t.whol)) i.whol source-id)
=. ship-sources-reverse.etn
%- ~(gas ju ship-sources-reverse.etn)
(turn whol |=(=ship [source-id ship]))
..feed
2019-12-07 09:04:06 +03:00
::
?: ?=(%& -.source)
=/ send-message
|= =message
[hen %pass /public-keys %a %plea p.source %j /public-keys message]
(emit (send-message %public-keys whos))
2019-08-07 01:42:37 +03:00
(peer p.source whos)
--
::
2019-08-07 01:42:37 +03:00
:: No-op
::
2019-08-07 01:42:37 +03:00
++ meet
|= [who=ship =life =pass]
^+ +>
2019-08-07 01:42:37 +03:00
+>.$
--
2017-04-23 06:13:14 +03:00
--
2016-11-24 07:25:07 +03:00
:: ::::
:::: # vane :: interface
:: ::::
::
:: lex: all durable %jael state
::
=| lex/state
|= $: ::
2018-12-06 00:41:21 +03:00
:: our: identity
2016-11-24 07:25:07 +03:00
:: now: current time
:: eny: unique entropy
:: ski: namespace resolver
::
2018-12-06 00:41:21 +03:00
our=ship
now=@da
eny=@uvJ
ski=sley
2016-11-24 07:25:07 +03:00
==
2019-04-11 04:49:20 +03:00
^?
2016-11-24 07:25:07 +03:00
|%
:: :: ++call
++ call :: request
|= $: :: hen: cause of this event
:: hic: event data
::
hen/duct
hic/(hypo (hobo task:able))
2016-11-24 07:25:07 +03:00
==
^- [(list move) _..^$]
2018-12-12 11:34:05 +03:00
=/ =task:able
?. ?=($soft -.q.hic)
q.hic
2019-01-15 01:04:13 +03:00
(task:able p.q.hic)
2018-12-12 11:34:05 +03:00
=^ did lex
abet:(~(call of [our now eny] lex) hen task)
2016-11-24 07:25:07 +03:00
[did ..^$]
:: :: ++load
++ load :: upgrade
|= $: :: old: previous state
::
2019-08-07 01:42:37 +03:00
:: old/*
2016-11-24 07:25:07 +03:00
old/state
==
^+ ..^$
2019-08-07 01:42:37 +03:00
:: ..^$
2016-11-24 07:25:07 +03:00
..^$(lex old)
:: :: ++scry
++ scry :: inspect
|= $: :: fur: event security
:: ren: access mode
:: why: owner
:: syd: desk (branch)
:: lot: case (version)
:: tyl: rest of path
::
fur/(unit (set monk))
ren/@tas
why/shop
syd/desk
lot/coin
2016-11-24 07:25:07 +03:00
tyl/spur
==
^- (unit (unit cage))
:: XX review for security, stability, cases other than now
2018-10-12 19:48:52 +03:00
::
?. =(lot [%$ %da now]) ~
2018-10-12 19:48:52 +03:00
?. =(%$ ren) [~ ~]
?+ syd
~
::
%code
?. ?=([@ ~] tyl) [~ ~]
2019-08-07 01:42:37 +03:00
?. =([%& our] why)
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
2019-08-07 01:42:37 +03:00
=/ sec (~(got by jaw.own.pki.lex) lyf.own.pki.lex)
=/ cub (nol:nu:crub:crypto sec)
:: XX use pac:ex:cub?
::
``[%noun !>((end 6 1 (shaf %pass (shax sec:ex:cub))))]
2018-10-12 19:48:52 +03:00
::
%life
?. ?=([@ ~] tyl) [~ ~]
2019-08-07 01:42:37 +03:00
?. =([%& our] why)
2018-10-12 19:48:52 +03:00
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
:: fake ships always have life=1
::
2019-08-07 01:42:37 +03:00
?: fak.own.pki.lex
2018-10-12 19:48:52 +03:00
``[%atom !>(1)]
?: =(u.who p.why)
2019-08-07 01:42:37 +03:00
``[%atom !>(lyf.own.pki.lex)]
=/ pub (~(get by pos.zim.pki.lex) u.who)
2018-10-12 19:48:52 +03:00
?~ pub ~
``[%atom !>(life.u.pub)]
::
%lyfe :: unitized %life
?. ?=([@ ~] tyl) [~ ~]
?. =([%& our] why)
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
:: fake ships always have life=1
::
?: fak.own.pki.lex
``[%noun !>((some 1))]
?: =(u.who p.why)
``[%noun !>((some lyf.own.pki.lex))]
=/ pub (~(get by pos.zim.pki.lex) u.who)
?~ pub ``[%noun !>(~)]
``[%noun !>((some life.u.pub))]
2019-02-02 00:46:09 +03:00
::
%rift
?. ?=([@ ~] tyl) [~ ~]
2019-08-07 01:42:37 +03:00
?. =([%& our] why)
2019-02-02 00:46:09 +03:00
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
:: fake ships always have rift=1
::
2019-08-07 01:42:37 +03:00
?: fak.own.pki.lex
2019-02-02 00:46:09 +03:00
``[%atom !>(1)]
2019-08-07 01:42:37 +03:00
=/ pos (~(get by pos.zim.pki.lex) u.who)
2019-02-02 00:46:09 +03:00
?~ pos ~
2019-08-07 01:42:37 +03:00
``[%atom !>(rift.u.pos)]
::
%ryft :: unitized %rift
?. ?=([@ ~] tyl) [~ ~]
?. =([%& our] why)
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
:: fake ships always have rift=1
::
?: fak.own.pki.lex
``[%noun !>((some 1))]
=/ pos (~(get by pos.zim.pki.lex) u.who)
?~ pos ``[%noun !>(~)]
``[%noun !>((some rift.u.pos))]
::
%vein
?. ?=([@ ~] tyl) [~ ~]
?. &(?=(%& -.why) =(p.why our))
[~ ~]
=/ lyf (slaw %ud i.tyl)
?~ lyf [~ ~]
::
?~ r=(~(get by jaw.own.pki.lex) u.lyf)
[~ ~]
::
[~ ~ %noun !>(u.r)]
::
%deed
?. ?=([@ @ ~] tyl) [~ ~]
2018-12-12 11:34:05 +03:00
?. &(?=(%& -.why) =(p.why our))
[~ ~]
=/ who (slaw %p i.tyl)
=/ lyf (slaw %ud i.t.tyl)
?~ who [~ ~]
?~ lyf [~ ~]
2018-10-18 01:56:41 +03:00
::
?: fak.own.pki.lex
=/ cub (pit:nu:crub:crypto 512 u.who)
:^ ~ ~ %noun
2019-08-20 02:40:57 +03:00
!> [1 pub:ex:cub ~]
::
=/ rac (clan:title u.who)
2018-10-18 01:56:41 +03:00
?: ?=(%pawn rac)
?. =(u.who p.why)
[~ ~]
?. =(1 u.lyf)
[~ ~]
2019-08-07 01:42:37 +03:00
=/ sec (~(got by jaw.own.pki.lex) u.lyf)
2018-10-18 01:56:41 +03:00
=/ cub (nol:nu:crub:crypto sec)
=/ sig (sign:as:cub (shaf %self (sham [u.who 1 pub:ex:cub])))
:^ ~ ~ %noun
2019-07-29 14:05:52 +03:00
!> [1 pub:ex:cub `sig]
2018-10-18 01:56:41 +03:00
::
2019-08-07 01:42:37 +03:00
=/ pub (~(get by pos.zim.pki.lex) u.who)
2018-12-19 22:36:05 +03:00
?~ pub
~
?: (gth u.lyf life.u.pub)
~
2019-08-07 01:42:37 +03:00
=/ pas (~(get by keys.u.pub) u.lyf)
2018-12-19 22:36:05 +03:00
?~ pas
~
:^ ~ ~ %noun
!> [u.lyf pass.u.pas ~]
2018-10-12 19:48:52 +03:00
::
%earl
2019-08-07 01:42:37 +03:00
?. ?=([@ @ ~] tyl) [~ ~]
?. =([%& our] why)
2018-10-12 19:48:52 +03:00
[~ ~]
=/ who (slaw %p i.tyl)
=/ lyf (slaw %ud i.t.tyl)
?~ who [~ ~]
?~ lyf [~ ~]
2019-08-07 01:42:37 +03:00
?: (gth u.lyf lyf.own.pki.lex)
2018-10-12 19:48:52 +03:00
~
2019-08-07 01:42:37 +03:00
?: (lth u.lyf lyf.own.pki.lex)
2018-10-12 19:48:52 +03:00
[~ ~]
:: XX check that who/lyf hasn't been booted
::
2019-08-07 01:42:37 +03:00
=/ sec (~(got by jaw.own.pki.lex) u.lyf)
=/ moon-sec (shaf %earl (sham our u.lyf sec u.who))
=/ cub (pit:nu:crub:crypto 128 moon-sec)
=/ =seed [u.who 1 sec:ex:cub ~]
``[%seed !>(seed)]
2018-10-12 19:48:52 +03:00
::
%sein
?. ?=([@ ~] tyl) [~ ~]
2019-08-07 01:42:37 +03:00
?. =([%& our] why)
2018-10-12 19:48:52 +03:00
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
:^ ~ ~ %atom
!> ^- ship
2018-12-12 11:34:05 +03:00
(~(sein of [our now eny] lex) u.who)
2018-10-12 19:48:52 +03:00
::
%saxo
?. ?=([@ ~] tyl) [~ ~]
2019-08-07 01:42:37 +03:00
?. =([%& our] why)
2018-10-12 19:48:52 +03:00
[~ ~]
=/ who (slaw %p i.tyl)
?~ who [~ ~]
:^ ~ ~ %noun
!> ^- (list ship)
2018-12-12 11:34:05 +03:00
(~(saxo of [our now eny] lex) u.who)
::
%subscriptions
?. ?=([@ ~] tyl) [~ ~]
?. =([%& our] why)
[~ ~]
:^ ~ ~ %noun
!>([yen ney nel]:zim.pki.lex)
::
2019-08-07 01:42:37 +03:00
%sources
?. ?=(~ tyl) [~ ~]
:^ ~ ~ %noun !>
2019-08-07 01:42:37 +03:00
etn.lex
2019-04-12 04:01:35 +03:00
::
%turf
?. ?=(~ tyl) [~ ~]
2019-08-07 01:42:37 +03:00
[~ ~ %noun !>(tuf.own.pki.lex)]
2018-10-12 19:48:52 +03:00
==
2016-11-24 07:25:07 +03:00
:: :: ++stay
++ stay :: preserve
lex
:: :: ++take
++ take :: accept
|= $: :: tea: order
:: hen: cause
:: hin: result
::
tea/wire
hen/duct
hin/(hypo sign)
2016-11-24 07:25:07 +03:00
==
^- [(list move) _..^$]
2018-12-12 11:34:05 +03:00
=^ did lex abet:(~(take of [our now eny] lex) tea hen q.hin)
[did ..^$]
2016-11-24 07:25:07 +03:00
--