mirror of https://github.com/waku-org/nwaku.git
Rln relay registration (#378)
* cleans up imported modules * adds uploadContract proc and consolidates rln-relay test files * deletes test_rln_relay_wrappers * deletes wrappers tests * adds waku_rln_relay_utils * adds the unit test for the membership key generation * adds the key generation procedure * adds unit test of key gen proc * adds RLNRelayPeer data type * adds the register proc * adds the register proc unit test * minor * edits registration test * adds comments to the registration unit test and relocates some constants * defines constants variables for membership contract inputs and adds todos * fixes a typo * adds rln to gitignore * moves all the types to the top * adds contracts inputs to the utils module * adds a TODO * adds some comments * removes newline! adds some comments
This commit is contained in:
parent
b7ce32cf4b
commit
57a9447972
|
@ -11,10 +11,7 @@ import
|
|||
|
||||
# the address of Ethereum client (ganache-cli for now)
|
||||
const EthClient = "ws://localhost:8540/"
|
||||
# inputs of the membership contract constructor
|
||||
const
|
||||
MembershipFee = 5.u256
|
||||
Depth = 5.u256
|
||||
|
||||
# poseidonHasherCode holds the bytecode of Poseidon hasher solidity smart contract:
|
||||
# https://github.com/kilic/rlnapp/blob/master/packages/contracts/contracts/crypto/PoseidonHasher.sol
|
||||
# the solidity contract is compiled separately and the resultant bytecode is copied here
|
||||
|
@ -166,6 +163,34 @@ procSuite "Waku rln relay":
|
|||
await web3.close()
|
||||
debug "disconnected from", EthClient
|
||||
|
||||
asyncTest "registration procedure":
|
||||
# deploy the contract
|
||||
let contractAddress = await uploadContract(EthClient)
|
||||
|
||||
# prepare rln-relay peer inputs
|
||||
let
|
||||
web3 = await newWeb3(EthClient)
|
||||
accounts = await web3.provider.eth_accounts()
|
||||
# choose one of the existing accounts for the rln-relay peer
|
||||
ethAccountAddress = accounts[9]
|
||||
await web3.close()
|
||||
|
||||
# generate the membership keys
|
||||
let membershipKeyPair = membershipKeyGen()
|
||||
|
||||
check:
|
||||
membershipKeyPair.isSome
|
||||
|
||||
# initialize the RLNRelayPeer
|
||||
var rlnPeer = RLNRelayPeer(membershipKeyPair: membershipKeyPair.get(),
|
||||
ethClientAddress: EthClient,
|
||||
ethAccountAddress: ethAccountAddress,
|
||||
membershipContractAddress: contractAddress)
|
||||
|
||||
# register the rln-relay peer to the membership contract
|
||||
let is_successful = await rlnPeer.register()
|
||||
check:
|
||||
is_successful
|
||||
suite "Waku rln relay":
|
||||
test "Keygen Nim Wrappers":
|
||||
var
|
||||
|
|
|
@ -1,12 +1,29 @@
|
|||
import
|
||||
chronicles, options, chronos, stint,
|
||||
stew/byteutils,
|
||||
web3,
|
||||
eth/keys,
|
||||
rln
|
||||
|
||||
type MembershipKeyPair* = object
|
||||
secretKey*: array[32, byte]
|
||||
publicKey*: array[32, byte]
|
||||
|
||||
type RLNRelayPeer* = object
|
||||
membershipKeyPair*: MembershipKeyPair
|
||||
ethClientAddress*: string
|
||||
ethAccountAddress*: Address
|
||||
membershipContractAddress*: Address
|
||||
|
||||
# inputs of the membership contract constructor
|
||||
const
|
||||
MembershipFee* = 5.u256
|
||||
Depth* = 32.u256
|
||||
|
||||
# membership contract interface
|
||||
contract(MembershipContract):
|
||||
# TODO define a return type of bool for register method to signify a successful registration
|
||||
proc register(pubkey: Uint256) # external payable
|
||||
|
||||
proc membershipKeyGen*(): Option[MembershipKeyPair] =
|
||||
# generates a MembershipKeyPair that can be used for the registration into the rln membership contract
|
||||
|
@ -60,4 +77,17 @@ proc membershipKeyGen*(): Option[MembershipKeyPair] =
|
|||
public = cast[array[32, byte]](generatedKeys[31..^1])
|
||||
keypair = MembershipKeyPair(secretKey: secret, publicKey: public)
|
||||
|
||||
return some(keypair)
|
||||
return some(keypair)
|
||||
|
||||
proc register*(rlnPeer: RLNRelayPeer): Future[bool] {.async.} =
|
||||
## registers the public key of the rlnPeer which is rlnPeer.membershipKeyPair.publicKey
|
||||
## into the membership contract whose address is in rlnPeer.membershipContractAddress
|
||||
let web3 = await newWeb3(rlnPeer.ethClientAddress)
|
||||
web3.defaultAccount = rlnPeer.ethAccountAddress
|
||||
var sender = web3.contractSender(MembershipContract, rlnPeer.membershipContractAddress) # creates a Sender object with a web3 field and contract address of type Address
|
||||
let pk = cast[UInt256](rlnPeer.membershipKeyPair.publicKey)
|
||||
# TODO sign the transaction
|
||||
discard await sender.register(pk).send(MembershipFee)
|
||||
# TODO check the receipt and then return true/false
|
||||
await web3.close()
|
||||
return true
|
Loading…
Reference in New Issue