Package: drand
Python client to query adrandnetwork for publicly verifiable,
unbiased, and unpredictable random values.To learn more aboutdrandseedrand’s
documentation.WARNING: This software is currently only, strictly, and purely for
experimental purposes. It was developed for prototyping and
experimenting with thedrandnetwork, which is itself still
experimental!IMPORTANT: Currently only works with thedrandserver code
from themasterbranch (as of March 8, 2020). To query thedrand
test network(e.g.:League of Entropy) using Python you may trydrb-client.InstallUsagePrerequisite: Run a local drand networkQuery a drand serverGet the public key of the network (/api/info/distkey)Get and verify a random value (/api/public)AcknowledgmentsReminder & Future WorkInstall$pipinstalldrandUsagePrerequisite: Run a local drand networkFirst, run a local drand network. Seedevnet/README.mdfor
more details.$cddevnet$./run.shGet the addresses of the drand serversfromdrand.utilsimportget_addresses_from_group_filegroup_file='devnet/data/group.toml'addresses=get_addresses_from_group_file(group_file)>>>addresses['172.15.238.2:8084','172.15.238.3:8081','172.15.238.4:8080','172.15.238.6:8082','172.15.238.5:8083']Query a drand serverimportdrandGet the public key of the network (/api/info/distkey)Each node has a public share of this group key.distkey=awaitdrand.get_distkey(addresses[0],tls=False)>>>distkey'9509e2c2a5d04776bedce40839341375c89aa34a0372a1db273f562d89050b4ae54a76a276a26580166b0cd91e63f909'Get and verify a random value (/api/public)The verification means verifying that the “randomness” value is
the hash of the signature, and that the signature is valid for the
public key (distkey) and the the message (round + previous)res=awaitdrand.get_and_verify(addresses[3],distkey=distkey,tls=False,)>>>res{'round':73,'previous':'b894ccc3859d1fb6d2ce6722b7195d359fbe6b0a387a3693e539e4957f1c69025936919fff3bd89a303ccfbcb929aae10eb68172997bdc84ccc6295dd21903a77994a116e203514935e9e25bf3f830cb00e6546470260f9beab65a5e389050bd','signature':'817254f9267e5345f5160a794ad5ffca0a9a2295cbfedc8c3d19215f91c8ccd07faa8354564d18159905477757c21f8a05140761ab5eb7b1d622ef5b62d64cdecf7f5c1e3d06d7ac016e16c4bfaddc4b27985625d32cd73e650e8fb7ea8dccf0','randomness':'66c3554bc0927a4ccbfdd73856071be792e3ddec7c27193d2f2f4d482c78b6b2'}Get a random value for round 5res=awaitdrand.get_and_verify(addresses[3],distkey=distkey,tls=False,round_=5)>>>res{'round':5,'previous':'aab94951afa626c26af5e08baa111fb98b1f5300556dc472f5e976a1ca4ccb074ecb7778cf18e08272fb40e1421a630914fe178ff1353d1247f58ecf4b82c417a55b8867e1f6eca4ca4bc548db2c2d1ce31c52e34f97c7f001774dc3fb6f22d5','signature':'ad3e4f0bf0ef93c2ced95c12e1e7b5d0adbc4791e5592a83ce6119e0b610b7de40786e639861aa62df9d3a01b0ac50f90c84b1b20c5cc0662774c324f03fda0a69f0625a54a0c4c066f3b441cb33a8782f88d53861a5d4d8035a96488e340141','randomness':'baee3fd77cd09349325794f766c0c81c887987907ec2834ac09a8a46c2193747'}Get random values for a range of roundsimportasynciofromaiohttpimportClientSessionasyncdefget_rands(rounds):asyncwithClientSession()assession:tasks=[]forrinrounds:tasks.append(drand.get_and_verify(addresses[4],distkey=distkey,session=session,tls=False,round_=r,))rands=awaitasyncio.gather(*tasks)returnrands>>>asyncio.run(get_rands(range(2,5)))[{'round':2,'previous':'b816229db70d3d7ab727bf0dc8ae3de27c354b066d5d931d3b6fb14d2fcf2433cd72f0271a9c47e7448de7c9589de2250d85ad444175cb616ca6fa0f6f0d376e608378c3688ee528631132c3c7928dfcec9f302a91daac51f1e87c98ebff78d5','signature':'a515fe873dc18810d3aa446614786aa63567930f888c82b1edf66ea1e0f604c46948863dc349320219eba7d11a784813152719f0d6d471a08227c27393d14eb02a8df7c18cb48f5df6918510948e6170922ad5164da0965c47b63ba80ee7a682','randomness':'185963dba81d25158bb60bc0bc16823b7687a87cca739a6a9e4a2bccac16c5f0'},{'round':3,'previous':'a515fe873dc18810d3aa446614786aa63567930f888c82b1edf66ea1e0f604c46948863dc349320219eba7d11a784813152719f0d6d471a08227c27393d14eb02a8df7c18cb48f5df6918510948e6170922ad5164da0965c47b63ba80ee7a682','signature':'81d3a98e63e8480d61e64ef7126dea5f83cc98303d43c66221f15edab8dc4e02d7c229a645f107ee76e0de11673569810f18fc6fd5d27e5a50aa0cbf95e90f1d6c750715a9e4b79ec8a5982421e2a324864d1471e36a0af3c773864923a3e3b4','randomness':'0b7d6c4a465b4cd6099f4a888ea355c2173a8108ad749a7790c64592a9c2ee9f'},{'round':4,'previous':'81d3a98e63e8480d61e64ef7126dea5f83cc98303d43c66221f15edab8dc4e02d7c229a645f107ee76e0de11673569810f18fc6fd5d27e5a50aa0cbf95e90f1d6c750715a9e4b79ec8a5982421e2a324864d1471e36a0af3c773864923a3e3b4','signature':'aab94951afa626c26af5e08baa111fb98b1f5300556dc472f5e976a1ca4ccb074ecb7778cf18e08272fb40e1421a630914fe178ff1353d1247f58ecf4b82c417a55b8867e1f6eca4ca4bc548db2c2d1ce31c52e34f97c7f001774dc3fb6f22d5','randomness':'2dcc3e4894c91d092cdbcbe6daf777c5cbe2e6948cf8a18693009762273d52aa'}]AcknowledgmentsThe initial code interface for this package was based on the
JavaScript clientdrandjs.Thedevnetdirectory under the root of therepowas taken
from thedemodirectory under thedrand/drandrepository, tree
with commit hasha40dc25e1aec6822a79c72b4aaca12e65c700f01. The
code was brought over usinggit-filter-repoin order to preserve the
commit history.The original boilerplate for this package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject
template.Thanks toIC3(The Initiative For Cryptocurrencies & Contracts) for
supporting this work.Reminder & Future WorkThis software is currently only, strictly, and purely for
experimental purposes. It was developed for prototyping and
experimenting with thedrandnetwork, which is itself still
experimental!TheGithub issue trackerwill be used to plan and manage future
work.