2021-05-11 23:47:33 +03:00
|
|
|
/+ naive, ethereum
|
|
|
|
:: Types
|
|
|
|
|%
|
2021-05-12 00:33:57 +03:00
|
|
|
+$ address address:ethereum
|
2021-05-11 23:47:33 +03:00
|
|
|
+$ nonce @ud
|
|
|
|
+$ proxy ?(%own %spawn %manage %vote %transfer)
|
|
|
|
--
|
|
|
|
::
|
|
|
|
|%
|
|
|
|
::
|
|
|
|
:: TODO: does this uniquely produce the pubkey?
|
|
|
|
++ verifier
|
|
|
|
^- ^verifier:naive
|
|
|
|
|= [dat=octs v=@ r=@ s=@]
|
|
|
|
?: (gth v 3) ~ :: TODO: move to jet
|
|
|
|
=/ result
|
|
|
|
%- mule
|
|
|
|
|.
|
|
|
|
=, secp256k1:secp:crypto
|
|
|
|
%- address-from-pub:key:ethereum
|
|
|
|
%- serialize-point
|
2021-07-15 15:23:08 +03:00
|
|
|
(ecdsa-raw-recover (hash-tx dat) v r s)
|
2021-05-11 23:47:33 +03:00
|
|
|
?- -.result
|
|
|
|
%| ~
|
|
|
|
%& `p.result
|
|
|
|
==
|
2021-07-16 17:15:24 +03:00
|
|
|
:: Verify signature and produce signer address
|
|
|
|
::
|
|
|
|
++ verify-sig
|
|
|
|
|= [sig=@ txdata=octs]
|
|
|
|
^- (unit address)
|
|
|
|
|^
|
|
|
|
:: Reversed of the usual r-s-v order because Ethereum integers are
|
|
|
|
:: big-endian
|
|
|
|
::
|
|
|
|
=^ v sig (take 3)
|
|
|
|
=^ s sig (take 3 32)
|
|
|
|
=^ r sig (take 3 32)
|
|
|
|
:: In Ethereum, v is generally 27 + recid, and verifier expects a
|
|
|
|
:: recid. Old versions of geth used 0 + recid, so most software
|
|
|
|
:: now supports either format. See:
|
|
|
|
::
|
|
|
|
:: https://github.com/ethereum/go-ethereum/issues/2053
|
|
|
|
::
|
|
|
|
=? v (gte v 27) (sub v 27)
|
|
|
|
(verifier txdata v r s)
|
|
|
|
::
|
|
|
|
++ take
|
|
|
|
|= =bite
|
|
|
|
[(end bite sig) (rsh bite sig)]
|
|
|
|
--
|
2021-05-11 23:47:33 +03:00
|
|
|
::
|
|
|
|
++ sign-tx
|
|
|
|
|= [pk=@ =nonce tx=octs] ^- octs
|
|
|
|
=/ prepared-data (prepare-for-sig 1.337 nonce tx)
|
|
|
|
=/ sign-data
|
|
|
|
=/ len (rsh [3 2] (scot %ui p.prepared-data))
|
2021-07-15 15:23:08 +03:00
|
|
|
%- hash-tx
|
2021-05-11 23:47:33 +03:00
|
|
|
%: cad:naive 3
|
|
|
|
26^'\19Ethereum Signed Message:\0a'
|
|
|
|
(met 3 len)^len
|
|
|
|
prepared-data
|
|
|
|
~
|
|
|
|
==
|
|
|
|
=+ (ecdsa-raw-sign:secp256k1:secp:crypto sign-data pk)
|
|
|
|
(cad:naive 3 1^v 32^s 32^r tx ~)
|
|
|
|
::
|
|
|
|
++ prepare-for-sig
|
|
|
|
|= [chain-id=@ud =nonce tx=octs]
|
|
|
|
^- octs
|
|
|
|
=/ chain-t (rsh [3 2] (scot %ui chain-id))
|
|
|
|
%: cad:naive 3
|
|
|
|
14^'UrbitIDV1Chain'
|
|
|
|
(met 3 chain-t)^chain-t
|
|
|
|
1^':'
|
|
|
|
4^nonce
|
|
|
|
tx
|
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
2021-05-25 22:05:39 +03:00
|
|
|
++ gen-tx
|
2021-05-20 22:55:24 +03:00
|
|
|
|= [=nonce tx=tx:naive pk=@]
|
2021-05-25 22:05:39 +03:00
|
|
|
:: takes in a nonce, tx:naive, and private key and returned a signed transactions as octs
|
|
|
|
%^ sign-tx pk nonce (gen-tx-octs tx)
|
|
|
|
::
|
|
|
|
++ gen-tx-octs
|
|
|
|
:: generates octs for a transaction
|
|
|
|
|= tx=tx:naive
|
2021-05-20 22:55:24 +03:00
|
|
|
|^
|
|
|
|
^- octs
|
|
|
|
=/ raw=octs
|
|
|
|
?- +<.tx
|
|
|
|
%spawn (get-spawn +>.tx)
|
|
|
|
%transfer-point (get-transfer +>.tx)
|
|
|
|
%configure-keys (get-keys +>.tx)
|
|
|
|
%escape (get-escape +.tx)
|
|
|
|
%cancel-escape (get-escape +.tx)
|
|
|
|
%adopt (get-escape +.tx)
|
|
|
|
%reject (get-escape +.tx)
|
|
|
|
%detach (get-escape +.tx)
|
|
|
|
%set-management-proxy (get-ship-address +.tx)
|
|
|
|
%set-spawn-proxy (get-ship-address +.tx)
|
|
|
|
%set-transfer-proxy (get-ship-address +.tx)
|
|
|
|
==
|
2021-05-25 22:05:39 +03:00
|
|
|
raw
|
2021-05-11 23:47:33 +03:00
|
|
|
::
|
|
|
|
++ get-spawn
|
2021-05-20 22:55:24 +03:00
|
|
|
|= [child=ship to=address] ^- octs
|
2021-05-11 23:47:33 +03:00
|
|
|
%: cad:naive 3
|
2021-05-20 22:55:24 +03:00
|
|
|
(from-proxy proxy.from.tx)
|
|
|
|
4^ship.from.tx
|
2021-05-11 23:47:33 +03:00
|
|
|
1^%1 :: %spawn
|
|
|
|
4^child
|
2021-05-20 22:55:24 +03:00
|
|
|
20^to
|
2021-05-11 23:47:33 +03:00
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ get-transfer
|
2021-05-20 22:55:24 +03:00
|
|
|
|= [=address reset=?] ^- octs
|
2021-05-11 23:47:33 +03:00
|
|
|
%: cad:naive 3
|
2021-05-20 22:55:24 +03:00
|
|
|
(from-proxy proxy.from.tx)
|
|
|
|
4^ship.from.tx
|
2021-05-11 23:47:33 +03:00
|
|
|
1^(can 0 7^%0 1^reset ~) :: %transfer-point
|
|
|
|
20^address
|
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ get-keys
|
2021-06-10 22:34:42 +03:00
|
|
|
|= [crypt=@ auth=@ suite=@ breach=?] ^- octs
|
2021-05-11 23:47:33 +03:00
|
|
|
%: cad:naive 3
|
2021-05-20 22:55:24 +03:00
|
|
|
(from-proxy proxy.from.tx)
|
|
|
|
4^ship.from.tx
|
2021-05-11 23:47:33 +03:00
|
|
|
1^(can 0 7^%2 1^breach ~) :: %configure-keys
|
2021-05-20 22:55:24 +03:00
|
|
|
32^crypt
|
2021-05-11 23:47:33 +03:00
|
|
|
32^auth
|
|
|
|
4^suite
|
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ get-escape
|
2021-05-20 22:55:24 +03:00
|
|
|
|= [action=@tas other=ship] ^- octs
|
2021-05-11 23:47:33 +03:00
|
|
|
=/ op
|
|
|
|
?+ action !!
|
|
|
|
%escape %3
|
|
|
|
%cancel-escape %4
|
|
|
|
%adopt %5
|
|
|
|
%reject %6
|
|
|
|
%detach %7
|
|
|
|
==
|
|
|
|
%: cad:naive 3
|
2021-05-20 22:55:24 +03:00
|
|
|
(from-proxy proxy.from.tx)
|
|
|
|
4^ship.from.tx
|
2021-05-11 23:47:33 +03:00
|
|
|
1^(can 0 7^op 1^0 ~)
|
|
|
|
4^other
|
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ get-ship-address
|
2021-05-20 22:55:24 +03:00
|
|
|
|= [action=@tas =address] ^- octs
|
2021-05-11 23:47:33 +03:00
|
|
|
=/ op
|
|
|
|
?+ action !!
|
|
|
|
%set-management-proxy %8
|
|
|
|
%set-spawn-proxy %9
|
|
|
|
%set-transfer-proxy %10
|
|
|
|
==
|
|
|
|
%: cad:naive 3
|
2021-05-20 22:55:24 +03:00
|
|
|
(from-proxy proxy.from.tx)
|
|
|
|
4^ship.from.tx
|
2021-05-11 23:47:33 +03:00
|
|
|
1^(can 0 7^op 1^0 ~)
|
|
|
|
20^address
|
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ from-proxy
|
|
|
|
|= prx=@tas
|
|
|
|
^- [@ @]
|
|
|
|
=/ proxy
|
|
|
|
?+ prx !!
|
|
|
|
%own %0
|
|
|
|
%spawn %1
|
|
|
|
%manage %2
|
|
|
|
%vote %3
|
|
|
|
%transfer %4
|
|
|
|
==
|
|
|
|
1^(can 0 3^proxy 5^0 ~)
|
|
|
|
::
|
|
|
|
--
|
|
|
|
::
|
2021-07-15 15:23:08 +03:00
|
|
|
++ hash-tx keccak-256:keccak:crypto
|
|
|
|
::
|
|
|
|
++ hash-raw-tx
|
|
|
|
|= =raw-tx:naive
|
|
|
|
^- @ux
|
|
|
|
(hash-tx raw.raw-tx)
|
|
|
|
::
|
2021-05-11 23:47:33 +03:00
|
|
|
--
|