Skip to content

Commit

Permalink
feat(rln_keystore_generator): wired to onchain group manager (#1931)
Browse files Browse the repository at this point in the history
* feat(rln_keystore_generator): wired to onchain group manager

* fix(Makefile): rename target to best practice
  • Loading branch information
rymnc committed Aug 23, 2023
1 parent 505d196 commit c9b48ea
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ chat2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim chat2 $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims

rln_keystore_generator: | build deps librln
rln-keystore-generator: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim rlnkeystoregenerator $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims
$(ENV_SCRIPT) nim rln_keystore_generator $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims

chat2bridge: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
Expand Down
7 changes: 7 additions & 0 deletions tools/rln_keystore_generator/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type
defaultValue: "",
name: "rln-relay-cred-password" }: string

rlnRelayEthPrivateKey* {.
desc: "Private key for broadcasting transactions",
defaultValue: "",
name: "rln-relay-eth-private-key" }: string

proc loadConfig*(T: type RlnKeystoreGeneratorConf): Result[T, string] =
try:
let conf = RlnKeystoreGeneratorConf.load()
Expand All @@ -65,6 +70,8 @@ proc loadConfig*(T: type RlnKeystoreGeneratorConf): Result[T, string] =
return err("--rln-relay-eth-contract-address must be set")
if conf.rlnRelayCredPassword == "":
return err("--rln-relay-cred-password must be set")
if conf.rlnRelayEthPrivateKey == "":
return err("--rln-relay-eth-private-key must be set")
ok(conf)
except CatchableError:
err(getCurrentExceptionMsg())
Expand Down
45 changes: 36 additions & 9 deletions tools/rln_keystore_generator/rln_keystore_generator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import
../../waku/waku_keystore,
../../waku/waku_rln_relay/rln,
../../waku/waku_rln_relay/conversion_utils,
../../waku/waku_rln_relay/group_manager/on_chain,
./external_config

logScope:
Expand All @@ -35,7 +36,7 @@ when isMainModule:
if rlnInstanceRes.isErr():
error "failure while creating RLN instance", error=rlnInstanceRes.error
quit(1)

let rlnInstance = rlnInstanceRes.get()

# 3. generate credentials
Expand All @@ -50,17 +51,44 @@ when isMainModule:
idSecretHash = credential.idSecretHash.inHex(),
idCommitment = credential.idCommitment.inHex()

# 4. write to keystore
## TODO: after hooking up to the OnchainGroupManager,
## obtain chainId and treeIndex from the contract

if not conf.execute:
info "not executing, exiting"
quit(0)

# 4. initialize OnchainGroupManager
let groupManager = OnchainGroupManager(ethClientUrl: conf.rlnRelayEthClientAddress,
ethContractAddress: conf.rlnRelayEthContractAddress,
rlnInstance: rlnInstance,
keystorePath: none(string),
keystorePassword: none(string),
ethPrivateKey: some(conf.rlnRelayEthPrivateKey),
# saveKeystore = false, since we're managing it
saveKeystore: false)
try:
waitFor groupManager.init()
except CatchableError:
error "failure while initializing OnchainGroupManager", error=getCurrentExceptionMsg()
quit(1)

# 5. register on-chain
try:
waitFor groupManager.register(credential)
except CatchableError:
error "failure while registering credentials on-chain", error=getCurrentExceptionMsg()
quit(1)

debug "Transaction hash", txHash = groupManager.registrationTxHash.get()

# 6. write to keystore
let keystoreCred = MembershipCredentials(
identityCredential: credential,
membershipGroups: @[MembershipGroup(
membershipContract: MembershipContract(
chainId: "1155511",
chainId: $groupManager.chainId.get(),
address: conf.rlnRelayEthContractAddress,
),
treeIndex: 0,
treeIndex: groupManager.membershipIndex.get(),
)]
)

Expand All @@ -74,6 +102,5 @@ when isMainModule:

info "credentials persisted", path = conf.rlnRelayCredPath




waitFor groupManager.stop()
quit(0)

0 comments on commit c9b48ea

Please sign in to comment.