urbit/arvo/jael.hoon

548 lines
20 KiB
Plaintext
Raw Normal View History

2016-04-08 20:08:05 +03:00
:: %jael, secret
::
:::: /hoon/jael
::
!? 164
2016-08-08 00:47:51 +03:00
!: ::
|= pit/vase
2016-04-08 20:08:05 +03:00
=> =~
:: private structures :: ::
:::: :: ::
:: :: ::
2016-08-08 00:47:51 +03:00
|%
++ jael-state :: all crypto state
$: ver/$0 :: %jael version
2016-08-31 01:23:00 +03:00
nav/jael-objective :: all universal state
2016-09-06 20:56:36 +03:00
:: nix/jael-subjective :: all derived state
2016-04-08 20:08:05 +03:00
== ::
2016-08-31 01:23:00 +03:00
++ jael-objective :: all universal state
$: urb/jael-urbit :: all urbit state
2016-09-06 20:56:36 +03:00
web/(map (list @ta) jael-web-domain) :: all web state
2016-04-08 20:08:05 +03:00
== ::
2016-09-06 20:56:36 +03:00
++ jael-web-domain :: per foreign app
$: sec/(map @t jael-web-app) :: client per api key
usr/(map @ta jael-web-user) :: direct user info
2016-04-08 20:08:05 +03:00
== ::
2016-09-06 20:56:36 +03:00
++ jael-web-app :: local app
2016-08-31 01:23:00 +03:00
$: key/(unit (pair @da @)) :: API key
2016-09-06 20:56:36 +03:00
tok/(map @t (pair @da @)) :: token by username
2016-04-08 20:08:05 +03:00
== ::
2016-09-06 20:56:36 +03:00
++ jael-web-user :: per-user secrets
2016-08-31 01:23:00 +03:00
$: pas/(unit @t) :: password
2016-09-06 20:56:36 +03:00
dey/(unit @t) :: display name
2016-08-25 08:05:26 +03:00
== ::
2016-08-31 01:23:00 +03:00
++ jael-urbit :: objective urbit
2016-09-12 04:07:23 +03:00
$: pug/gree :: all public state
2016-08-31 01:23:00 +03:00
pry/(map ship jael-ship) :: all private state
2016-08-08 00:47:51 +03:00
== ::
2016-08-31 01:23:00 +03:00
++ jael-ship :: objective by ship
2016-09-06 20:56:36 +03:00
$: rel/(map ship jael-friend) :: relationships
2016-08-31 01:23:00 +03:00
own/(map life ring) :: private keys
2016-09-06 20:56:36 +03:00
vew/(set duct) :: watchers
== ::
++ jael-friend :: relationship
2016-09-07 20:33:42 +03:00
$: luf/(unit life) :: life as known to
2016-09-06 20:56:36 +03:00
lab/(nap jael-right) :: promises to
vow/(set duct) :: watchers
2016-08-08 00:47:51 +03:00
== ::
2016-08-31 01:23:00 +03:00
++ jael-right :: urbit commitment
2016-09-12 04:07:23 +03:00
$% {$block p/pile} :: reserved block
2016-08-31 01:23:00 +03:00
{$email p/(set @ta)} :: email addresses
{$entry p/(map hand (pair @da code))} :: symmetric keys
2016-09-12 04:07:23 +03:00
{$final p/(map ship @uvG)} :: ticketed ships
2016-08-31 01:23:00 +03:00
{$fungi p/(map term @ud)} :: fungibles
2016-09-12 04:07:23 +03:00
{$guest $~} :: refugee visa
2016-09-07 20:36:06 +03:00
{$lived p/life} :: PKI commitment
2016-08-31 01:23:00 +03:00
== ::
++ jael-task :: operations on
2016-09-07 20:36:06 +03:00
$% {$give p/ship q/(nap jael-right)} :: add rights
2016-08-31 01:23:00 +03:00
{$line p/ship q/@da r/code} :: outbound symkey
{$link p/ship q/@da r/code} :: inbound symkey
2016-09-12 04:07:23 +03:00
{$meet p/ship q/gree} :: integrate pki from
2016-08-31 01:23:00 +03:00
{$over p/ship q/jael-task} :: mirror operation
2016-09-06 20:56:36 +03:00
{$pall p/ship q/life} :: our life acked
2016-09-12 04:07:23 +03:00
{$step p/lamp} :: update private key
2016-09-07 20:36:06 +03:00
{$take p/ship q/(nap jael-right)} :: subtract rights
2016-09-06 20:56:36 +03:00
{$vain $~} :: watch self
{$vest $~} :: watch assets
2016-08-31 01:23:00 +03:00
{$view p/ship} :: watch urbit
2016-09-06 20:56:36 +03:00
{$vile p/(list @ta)} :: watch website
2016-08-31 01:23:00 +03:00
{$west p/ship q/path r/*} :: remote request
2016-09-05 02:35:37 +03:00
{$wink p/@ta q/@t r/(unit (pair @da @))} :: set API key
2016-09-06 20:56:36 +03:00
{$wonk p/@ta q/@t r/@t s/(unit (pair @da @))} :: set API token
== ::
++ jael-report-them :: report on neighbor
$: gur/grue :: certificate
lab/(nap jael-right) :: our promises to
own/(nap jael-right) :: our promises from
== ::
++ jael-report-self :: report on self
$: gur/grue :: certificate
war/(map life ring) :: private keys
== ::
++ jael-report-cash :: neighbors/assets
$: has/(map ship (nap jael-right)) ::
2016-08-31 01:23:00 +03:00
== ::
2016-09-06 20:56:36 +03:00
++ jael-report-paid :: asset diff
$: dif/(list (trel ship ? (nap jael-right))) :: who, +/-, what
== ::
:: ::
2016-09-12 04:07:23 +03:00
++ jael-note :: out request $->
$% {$x $mess p/ship q/path r/*} :: send message
== ::
2016-08-31 01:23:00 +03:00
++ jael-gift :: output
2016-09-06 20:56:36 +03:00
$? {$cash jael-report-cash} :: asset dump
{$clue jael-report-them} :: channel dump
{$paid jael-report-paid} :: asset update
{$self jael-report-self} :: self dump
{$well jael-web-domain} :: service update
2016-08-31 01:23:00 +03:00
== ::
++ jael-message :: p2p message
2016-09-06 20:56:36 +03:00
$% {$hail p/(nap jael-right)} :: re/set rights
2016-09-12 04:07:23 +03:00
{$ping p/gree} :: propagate
2016-08-31 01:23:00 +03:00
== ::
2016-09-12 04:07:23 +03:00
++ jael-edit :: pki change
$: why/?($hear $make) :: import or create
gut/jael-change :: new information
== ::
2016-09-12 04:07:23 +03:00
++ jael-effect :: objective effect
$% {$kick p/ship} :: major update
{$site p/(list @ta)} ::
{$slap p/ship q/ship} :: relationship update
{$ping p/ship q/gree} :: propagate pki to
== ::
++ jael-change :: pki delta
$% {$step p/ship q/life r/lace} :: new deed
{$sure p/ship q/life r/mind s/@} :: new signature
== ::
2016-09-12 04:07:23 +03:00
++ move {p/duct q/(wind jael-note jael-gift)} :: local move
-- ::
. == ::
=| lex/jael-state :: kernel state
2016-09-12 04:07:23 +03:00
|= $: now/@da :: current time
eny/@ :: unique entropy
ski/sley :: current invocation
==
:: :: ::
:::: :::::: interface
:: :: ::
=< |%
:: ::
++ call :: request
2016-09-12 04:07:23 +03:00
|= $: :: hen: cause of this event
:: hic: event data
::
hen/duct
hic/(hypo (hobo jael-task))
==
=> .(q.hic ?.(?=($soft -.q.hic) q.hic ((hard jael-task) p.q.hic)))
^- {p/(list move) q/_..^$}
2016-09-12 04:07:23 +03:00
=^ did lex abet:(^call hen q.hic)
[did ..^$]
2016-09-12 04:07:23 +03:00
:: ::
++ doze :: await
|= $: :: now: current time
:: hen: cause (XX why we need this?)
::
now/@da
hen/duct
==
^- (unit @da)
~
2016-09-12 04:07:23 +03:00
:: ::
++ load :: upgrade
2016-09-12 04:07:23 +03:00
|= $: :: old: previous state
::
old/jael-state
==
^+ ..^$
..^$(lex old)
2016-09-12 04:07:23 +03:00
:: ::
++ 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
tyl/spur
==
^- (unit (unit cage))
!!
2016-09-12 04:07:23 +03:00
:: ::
++ stay :: preserve
lex
:: ::
++ take :: accept
|= $: :: tea: order
:: hen: cause
:: hin: result
::
tea/wire
hen/duct
hin/(hypo sign-arvo)
==
^- {p/(list move) q/_..^$}
[~ ..^$]
--
2016-09-12 04:07:23 +03:00
:: :: ::
:::: :::::: control
:: :: ::
=< =+ moz/(list move)
|%
:: ::
++ abet :: resolve
[(flop moz) lex]
:: ::
++ emil :: effects
|= moz/(list move)
^+(moz (weld (flop moz) ^moz))
:: ::
++ emit :: effect
|= mov/move
^+(moz [mov moz])
:: ::
++ call :: invoke
|= {hen/duct tac/jael-task}
^+ +>
?+ -.tac !!
$give
=< abet
=< abet
(give:(unto:(from our) p.tac) q.tac)
::
$link
=* ryt [%entry [[(shaf %hand r.tac) q.tac r.tac] ~ ~]]
=< abet
=< abet
(give:(unto:(from our) p.tac) [ryt ~ ~])
::
$line
=* ryt [%entry [[(shaf %hand r.tac) q.tac r.tac] ~ ~]]
=< abet
=< abet
(give:(unto:(from p.tac) our) [ryt ~ ~])
::
$meet
=/ rod urb (~(meet ur urb) p.tac q.tac)
|- ^+ ..call
?~ rod ..call
=. ..call (join i.rod)
$(rod t.rod, ..call (make:(join i.rod) i.rod))
::
$over
$(our p.tac, tac q.tac)
::
$pall
!!
:: =< abet
:: =< abet
:: (pall:(unto:(from our) p.tac) q.tac)
==
--
:: ::
:::: :: system
:: ::::::
|%
2016-09-12 04:07:23 +03:00
:: :: ur
++ ur :: urbit core
=| $: :: now: current time
:: eny: unique entropy
:: +>+: all urbit state
::
now/@da
eny/@e
jael-urbit
==
=* urb +>+
::
2016-09-12 04:07:23 +03:00
:: rod: output from this core
::
2016-09-12 04:07:23 +03:00
=| rod/(list jael-effect)
|%
:: :: abet:ur
++ abet :: resolve
[(flop rod) urb]
::
2016-09-12 04:07:23 +03:00
++ join :: join:ur
|= $: :: fex: literal changes to pki
::
fex/(list jael-edit)
^+ +>
|= fex/(list jael-edit)
:: :: make:ur
++ make :: propagate edits
|= $: :: fex: literal changes to pki
::
fex/(list jael-edit)
==
^- (list jael-effect)
--
:: :: meet:ur
2016-09-08 19:29:38 +03:00
++ meet :: merge worlds
|= $: :: via: source of new info
:: new: new pki info
:: old: current pki info
::
via/@p
new/gree
==
2016-09-12 04:07:23 +03:00
^- (list jael-edit)
|^ ::
:: check new info ship by ship
::
=+ (~(tap by new))
2016-09-12 04:07:23 +03:00
|- ^- (list jael-edit)
?~ +< ~
(weld (boat i.+<) $(+< t.+<))
2016-09-07 20:36:06 +03:00
:: ::
2016-09-12 04:07:23 +03:00
++ boat :: merge ships
|= $: :: who: this ship
:: gur: new will for this ship
::
who/ship
gur/grue
==
2016-09-12 04:07:23 +03:00
^- (list jael-edit)
::
:: rug: old will for this ship
::
2016-09-12 04:07:23 +03:00
=+ rug=(fall (~(get by pug.urb.nav.lex) who) *grue)
?: =(gur rug) ~
=+ :* ::
2016-09-12 04:07:23 +03:00
:: num: life counter
:: end: last life in old or new ship
::
2016-09-12 04:07:23 +03:00
num=`life`1
2016-09-08 19:29:38 +03:00
end=(max p.gur p.rug)
==
=| $: :: pre: previous deed
2016-09-12 04:07:23 +03:00
:: fex: edits in reverse order
::
pre/(unit lama)
2016-09-12 04:07:23 +03:00
fex/(list jael-edit)
==
|- ^+ fex
2016-09-12 04:07:23 +03:00
::
:: merge all lives in :%
::
?: (gth num end)
(flop fex)
2016-09-12 04:07:23 +03:00
=+ lub=(bonk who num pre (~(get by q.rug) num) (~(get by q.gur) num))
%= $
num +(num)
pre `p.lub
fex (weld (flop q.lub) fex)
==
:: ::
2016-09-12 04:07:23 +03:00
++ bonk :: merge lives
|= $: :: who: ship we're merging
:: num: life we're merging
:: pre: previous deed
:: lod: old deed
:: wan: new deed
::
who/ship
num/@ud
pre/(unit lama)
lod/(unit lace)
wan/(unit lace)
==
^- $: :: p: next previous deed
2016-09-12 04:07:23 +03:00
:: q: edits in order
::
p/lama
2016-09-12 04:07:23 +03:00
q/(list jael-edit)
2016-09-08 19:29:38 +03:00
==
::
:: if no new information, do nothing
::
?: |(?=($~ wan) =(wan lod))
?> ?=(^ lod)
[dat.u.lod ~]
2016-09-08 19:29:38 +03:00
::
:: ash: hash of deed content
:: def: our default parent
:: dad: our declared parent
:: mir: our rank
2016-09-08 19:29:38 +03:00
::
=/ ash (sham dat.u.wan)
=/ def (sein who)
=* dad dad.doc.dat.u.wan
=/ mir (clan who)
?> ?: |(=(num 1) =(%earl mir) =(%pawn mir))
::
:: comets and moons must stay with default parent
::
=(def dad)
::
:: other ships may migrate to parent of same rank
::
=((clan def) (clan dad))
::
:: if we have an old deed at this life, merge them
::
2016-09-08 19:29:38 +03:00
?: ?=(^ lod)
::
:: use the old deed as the next previous
::
:- dat.u.lod
2016-09-08 19:29:38 +03:00
::
:: deed data must be identical
::
?> =(dat.u.wan dat.u.lod)
::
:: sow: all new signatures
2016-09-08 19:29:38 +03:00
::
=+ sow=`(list (trel ship life @))`(~(tap by syg.u.wan))
2016-09-12 04:07:23 +03:00
|- ^- (list jael-edit)
?~ sow ~
::
2016-09-12 04:07:23 +03:00
:: mor: all further edits
:: och: old signature for this signer
::
=+ mor=$(sow t.sow)
=+ och=(~(get by syg.u.lod) p.i.sow)
2016-09-08 19:29:38 +03:00
::
:: ignore obsolete or equal signature
::
?. |(?=($~ och) (gth q.i.sow p.u.och))
mor
2016-09-08 19:29:38 +03:00
::
:: check and merge new, or newer, signature
2016-09-08 19:29:38 +03:00
::
?> (good [p q]:i.sow ash r.i.sow)
:_(mor [%make %sure who num [p q]:i.sow r.i.sow])
::
:: use the new deed as the next previous
::
:- dat.u.wan
2016-09-08 19:29:38 +03:00
::
:: non-initial deeds must be signed by previous
2016-09-08 19:29:38 +03:00
::
?> ?| ?=($~ pre)
=+ laz=(~(got by syg.u.wan) who)
?> =(p.laz (dec num))
=(ash (need (sure:as:(com:nu:crub pub.u.pre) *code q.laz)))
==
::
:: check the parent has signed, if necessary
::
?> ?| ::
:: no parent signature for existing, non-moon urbits
::
?& ?=(^ pre)
=(dad.doc.u.pre dad)
!=(%earl mir)
==
::
:: public keys for galaxies are hardcoded
::
?& =(%czar mir)
?=($~ pre)
=(pub.dat.u.wan (zeno who))
==
::
:: the deed's secure channel authenticates it
::
=(via who)
::
:: check valid parent signature
::
=+ par=(~(got by syg.u.wan) dad)
(good [dad p.par] ash q.par)
==
:: tep: deed update
::
=/ tep [%hear %step who num u.wan]
::
:: if we don't need to add a signature, report the new deed
2016-09-07 20:36:06 +03:00
::
?: (~(has by syg.u.wan) dad)
[tep ~]
2016-09-07 20:36:06 +03:00
::
:: lyf: life of parent
:: rig: secret key of parent
:: val: new signature
2016-09-08 19:29:38 +03:00
::
2016-09-12 04:07:23 +03:00
=* lyf p:(~(got by pug.urb.nav.lex) dad)
=* rig (~(got by own:(~(got by pry.urb.nav.lex) dad)) lyf)
=* val (sign:as:(nol:nu:crub rig) *@ ash)
[tep [%make %sure who num [dad lyf] val] ~]
2016-09-07 20:36:06 +03:00
:: ::
++ look :: get public key
|= myn/mind
2016-09-08 19:29:38 +03:00
^- @
::
:: first galaxy key is hardcoded
::
?: &((lth who.myn 256) =(1 lyf.myn))
(zeno who.myn)
::
:: cascade search over old and new, new first
::
2016-09-12 04:07:23 +03:00
|^ ((bond |.((need find))) find(pug.urb.nav.lex new))
2016-09-07 20:36:06 +03:00
++ find
^- (unit @)
2016-09-12 04:07:23 +03:00
%+ biff (~(get by pug.urb.nav.lex) who.myn)
2016-09-07 20:36:06 +03:00
|= gur/grue
2016-09-08 19:29:38 +03:00
::
:: crash if this life is revoked
::
?> =(p.gur lyf.myn)
2016-09-07 20:36:06 +03:00
%+ biff (~(get by q.gur) lyf.myn)
2016-09-08 19:29:38 +03:00
|=(lace `pub.dat)
2016-09-07 20:36:06 +03:00
--
2016-09-08 19:29:38 +03:00
:: ::
++ good :: verify signature
2016-09-07 20:36:06 +03:00
|= {myn/mind ash/@ val/@}
2016-09-08 19:29:38 +03:00
^- ?
?>(=(ash (need (sure:as:(com:nu:crub (look myn)) *code val))) &)
2016-09-07 20:33:42 +03:00
--
::
2016-09-12 04:07:23 +03:00
++
:: ::
++ etch ::
|=
2016-09-06 20:56:36 +03:00
++ from
|= rex/ship
2016-09-12 04:07:23 +03:00
=+ ((bond |.(*jael-ship)) (~(get by pry.urb.nav.lex) rex))
2016-09-06 20:56:36 +03:00
|%
++ abet
2016-09-12 04:07:23 +03:00
^+ ..from
..from(pry.urb.nav (~(put by pry.urb.nav.lex) rex `jael-ship`+<))
2016-09-06 20:56:36 +03:00
::
++ unto
|= pal/ship
=+ ((bond |.(*jael-friend)) (~(get by rel) pal))
|%
++ abet :: resolve
2016-09-12 04:07:23 +03:00
^+ ..unto
2016-09-06 20:56:36 +03:00
..unto(rel (~(put by rel) pal `jael-friend`+<))
::
++ give
|= lab/(nap jael-right)
^+ +>
!!
2016-09-07 20:33:42 +03:00
::
++ pall
|= lyf/life
!!
2016-09-06 20:56:36 +03:00
--
--
:: ::
++ zeno :: insert signature
|= who/ship
^- pass
!!
2016-04-08 20:08:05 +03:00
--