split aqua file

This commit is contained in:
boneyard93501 2022-12-02 16:49:42 -06:00
parent e8a2193e32
commit 569f21034e
2 changed files with 63 additions and 18 deletions

View File

@ -0,0 +1,59 @@
import "drand_lib.aqua"
-- import "@fluencelabs/aqua-lib/math.aqua"
-- get randomness from one peer/service and verifiication and randomeness from another peer/service
-- returns verification bool and the randomness from the initial reuqest peer and the verification peer, which should be the same
func verified_randomness(addrs: []ServiceAddress, url:string) -> bool, string, string:
on addrs[0].peer_id:
Drand addrs[0].service_id
c_res <- Drand.chains(url)
i_res <- Drand.info(url, c_res.chains[0])
r_res <- Drand.latest(url, c_res.chains[0])
on addrs[1].peer_id:
Drand addrs[1].service_id
v_res <- Drand.verify_bls(i_res.info.public_key, r_res.randomness.round, r_res.randomness.previous_signature, r_res.randomness.signature)
<- v_res.verified, v_res.randomness, r_res.randomness.randomness
-- possible end use function that gets randomness from peer/service, gets the prior
-- round for signature matching from another peer/servive and verifies the latest randomness
data Result:
success: bool
randomness: string
error: string
service MyMath("math"):
-- careful with this
sub(x: u64, y: u64) -> u64
func verified_randomness_plus(addrs: []ServiceAddress, url:string) -> Result:
result: *Result
on addrs[0].peer_id:
Drand addrs[0].service_id
c_res <- Drand.chains(url)
i_res <- Drand.info(url, c_res.chains[0])
r_res <- Drand.latest(url, c_res.chains[0])
on addrs[1].peer_id:
Drand addrs[1].service_id
prev_r_res <- Drand.round(url, c_res.chains[0], MyMath.sub(r_res.randomness.round, 1))
v_res <- Drand.verify_bls(i_res.info.public_key, r_res.randomness.round, r_res.randomness.previous_signature, r_res.randomness.signature)
if r_res.randomness.previous_signature != prev_r_res.randomness.signature:
result <<- Result(success = false, randomness = "", error = "signatures don't match between latest and previous round")
else:
if v_res.randomness != r_res.randomness.randomness:
result <<- Result(success = false, randomness = "", error = "randomness doesn't match between latest request and verification")
else:
if v_res.verified:
result <<- Result(success = v_res.verified, randomness = v_res.randomness, error = "")
else:
result <<- Result(success = v_res.verified, randomness = "", error = "verification failed for round ? and hash ?")
<- result[0]

View File

@ -1,3 +1,4 @@
module Drand declares *
data CResult:
chains: []string
@ -55,39 +56,24 @@ func info(addr: ServiceAddress, url:string, chain_hash: string) -> IResult:
res <- Drand.info(url, chain_hash)
<- res
--
-- https://drand.love/developer/http-api/#chain-hash-public-latest
func latest(addr: ServiceAddress, url:string, chain_hash: string) -> RResult:
on addr.peer_id:
Drand addr.service_id
res <- Drand.latest(url, chain_hash)
<- res
--
-- https://drand.love/developer/http-api/#chain-hash-public-round
func round(addr: ServiceAddress, url:string, chain_hash: string, round:u64) -> RResult:
on addr.peer_id:
Drand addr.service_id
res <- Drand.round(url, chain_hash, round)
<- res
--
-- https://github.com/noislabs/drand-verify/blob/main/examples/drand_verify.rs
func verify(addr: ServiceAddress, pk: string, round_idx:u64, prev_signature: string, signature: string) -> VResult:
on addr.peer_id:
Drand addr.service_id
res <- Drand.verify_bls(pk, round_idx, prev_signature, signature)
<- res
--
func roundtrip(addrs: []ServiceAddress, url:string) -> bool, string, string:
on addrs[0].peer_id:
Drand addrs[0].service_id
c_res <- Drand.chains(url)
i_res <- Drand.info(url, c_res.chains[0])
r_res <- Drand.latest(url, c_res.chains[0])
-- <- true, "yes", "no"
on addrs[1].peer_id:
Drand addrs[1].service_id
v_res <- Drand.verify_bls(i_res.info.public_key, r_res.randomness.round, r_res.randomness.previous_signature, r_res.randomness.signature)
<- v_res.verified, v_res.randomness, r_res.randomness.randomness