graph-store/view: move all signing out to %graph-view

This commit is contained in:
Logan Allen 2020-06-18 15:59:50 -04:00
parent 289e0b2aba
commit e6e4e370d3
5 changed files with 157 additions and 29 deletions

View File

@ -113,36 +113,22 @@
^- graph:store
?~ index graph
=* atom i.index
:: last index in list
::
%^ put:orm
graph
atom
:: add child
::
?~ t.index
:: verify hash if it exists, otherwise calculate
::
=* p post.node
=/ =validated-portion:store
[parent-hash author.p index.p time-sent.p contents.p]
=/ calculated-hash (mug validated-portion)
?^ hash.p
:: hash is present, validate it
~| "hash of post does not match calculated hash"
?> =(calculated-hash u.hash.p)
node
:: no hash present
::
%= node
hash.post `calculated-hash
signatures.post
?. =(our.bowl author.post.node) ~
%- ~(gas in *signatures:store) ~
:::_ ~
:: TODO: how to sign a message using our private key?
:::+ `@ux`(sign:as:crub:crypto calculated-hash)
:: our.bowl
::.^(=life %j /=life/(scot %p our.bowl))
==
=/ =hash:store (mug validated-portion)
?~ hash.p node
~| "hash of post does not match calculated hash"
?> =(hash u.hash.p)
node
:: recurse children
::
~| "index does not exist to add a node to!"
=/ parent=node:store (need (get:orm graph atom))
%_ parent
@ -338,9 +324,39 @@
=/ =ship (slav %p i.t.t.path)
=/ =term i.t.t.t.path
=/ graph=(unit graph:store) (~(get by graphs) [ship term])
?~ graph
~
?~ graph ~
``noun+!>(u.graph)
::
:: [%x %graph-subset @ @ @ @ ~]
:: =/ =ship (slav %p i.t.t.path)
:: =/ =term i.t.t.t.path
:: :: TODO: parse out either '~' literal into null or parse out @ud
:: =/ start=(unit @ud)
:: =/ graph=(unit graph:store) (~(get by graphs) [ship term])
:: ?~ graph ~
:: ``noun+!>((subset:orm u.graph [~
:: ``noun+!>(u.graph)
::
[%x %node @ @ @ *]
=/ =ship (slav %p i.t.t.path)
=/ =term i.t.t.t.path
=/ =index:store (turn t.t.t.t.path |=(=cord (slav %ud cord)))
=/ graph=(unit graph:store) (~(get by graphs) [ship term])
?~ graph ~
=/ node=(unit node:store) [~ *node:store]
|-
?~ index
?~ node ~
``noun+!>(u.node)
?~ t.index
=. node (get:orm u.graph i.index)
?~ node ~
``noun+!>(u.node)
?~ node ~
?- -.children.u.node
%empty ~
%graph $(node (get:orm p.children.u.node i.index))
==
==
::
++ on-arvo on-arvo:def

View File

@ -1,4 +1,4 @@
/+ view=graph-view, store=graph-store, default-agent, verb, dbug
/+ view=graph-view, store=graph-store, sigs=signatures, default-agent, dbug
::
|%
+$ versioned-state
@ -16,7 +16,6 @@
=| state-0
=* state -
::
%+ verb |
%- agent:dbug
^- agent:gall
|_ =bowl:gall
@ -35,10 +34,116 @@
?> (team:title our.bowl src.bowl)
=^ cards state
?+ mark (on-poke:def mark vase)
%graph-action (action !<(action:store vase))
%graph-view-action (view-action !<(action:view vase))
==
[cards this]
::
++ action
|= =action:store
^- (quip card _state)
|^
:: TODO: decide who to send it to based on resource
::
?> ?=(%0 -.action)
:_ state
?+ +<.action [(poke-store action) ~]
%add-nodes (add-nodes +>.action)
%add-signatures (add-signatures +>.action)
==
::
++ add-nodes
|= [=resource:store nodes=(map index:store node:store)]
^- (list card)
:_ ~
%- poke-store
:- %0
:+ %add-nodes
resource
(sign-nodes resource nodes)
::
++ add-signatures
|= [=uid:store =signatures:store]
^- (list card)
:_ ~
%- poke-store
:- %0
:+ %add-signatures
uid
=* resource resource.uid
=* index index.uid
=* ship entity.resource.uid
=* name name.resource.uid
%- ~(gas in *signatures:store)
:_ ~
-:(sign-node resource (scry-for-node ship name index))
::
++ sign-nodes
|= [=resource:store nodes=(map index:store node:store)]
^- (map index:store node:store)
%- ~(run by nodes)
|= =node:store
^- node:store
+:(sign-node resource node)
::
++ sign-node
|= [=resource:store =node:store]
^- [signature:store node:store]
=* p post.node
=* ship entity.resource
=* name name.resource
=/ parent-hash (scry-for-parent-hash ship name index.p)
=/ =validated-portion:store
[parent-hash author.p index.p time-sent.p contents.p]
=/ =hash:store (mug validated-portion)
=/ =signature:store (sign:sigs our.bowl now.bowl hash)
:- signature
%_ node
hash.post `hash
signatures.post
%- ~(uni in signatures.post.node)
(~(gas in *signatures:store) [signature]~)
==
::
++ scry-for-node
|= [=ship =term =index:store]
^- node:store
%+ scry-for node:store
%+ weld
/node/(scot %p ship)/[term]
(index-to-path index)
::
++ scry-for-parent-hash
|= [=ship =term =index:store]
^- (unit hash:store)
?~ index ~
?~ t.index ~
=/ parent=node:store
%+ scry-for node:store
%+ weld
/node/(scot %p ship)/[term]
(index-to-path t.index)
hash.post.parent
::
++ index-to-path
|= =index:store
^- path
%+ turn index
|= i=atom:store
(scot %ud i)
::
++ poke-store
|= =action:store
^- card
:* %pass
/(scot %da now.bowl)
%agent
[our.bowl %graph-store]
%poke
[%graph-action !>(action)]
==
--
::
++ view-action
|= =action:view
^- (quip card _state)

View File

@ -363,5 +363,4 @@
*signatures
==
--
::
--

View File

@ -3,6 +3,14 @@
=< [post .]
=, post
|%
++ sign
|= [our=ship now=time =hash]
^- signature
=/ =life .^(life %j /=life/(scot %da now)/(scot %p our))
=/ =ring .^(ring %j /=vein/(scot %da now)/(scot %ud life))
:+ `@ux`(sign:as:(nol:nu:crub:crypto ring) hash)
our
life
::
:: sha256 noun hash
::

View File

@ -1,6 +1,6 @@
/- *resource
|%
+$ atom @
+$ atom @u
+$ index (list atom)
+$ uid [=resource =index]
::