naive: add verify signature to /lib/naive-transactions

This commit is contained in:
yosoyubik 2021-07-16 16:15:24 +02:00
parent c79a833678
commit 07f4473c21
2 changed files with 26 additions and 26 deletions

View File

@ -683,7 +683,7 @@
::
~
==
?~ addr=(verify-sig sig message)
?~ addr=(verify-sig:lib sig message)
~? lverb [dap.bowl %cancel-sig-fail]
[~ state]
=. history
@ -694,31 +694,6 @@
|= pend-tx
=(keccak (hash-raw-tx:lib raw-tx))
[~ state]
:: TODO: move to /lib/naive-transactions
::
++ verify-sig
|= [sig=@ txdata=octs]
^- (unit address:naive)
|^
:: 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:lib txdata v r s)
::
++ take
|= =bite
[(end bite sig) (rsh bite sig)]
--
:: +take-tx: accept submitted l2 tx into the :pending list
::
++ take-tx

View File

@ -24,6 +24,31 @@
%| ~
%& `p.result
==
:: 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)]
--
::
++ sign-tx
|= [pk=@ =nonce tx=octs] ^- octs