mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-10 14:06:38 +00:00
feat(rln_keystore_generator): wired to onchain group manager (#1931)
* feat(rln_keystore_generator): wired to onchain group manager * fix(Makefile): rename target to best practice
This commit is contained in:
parent
505d196796
commit
c9b48ea1a0
4
Makefile
4
Makefile
@ -184,9 +184,9 @@ chat2: | build deps librln
|
|||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim chat2 $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims
|
$(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/$@" && \
|
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
|
chat2bridge: | build deps
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
|
@ -56,6 +56,11 @@ type
|
|||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
name: "rln-relay-cred-password" }: string
|
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] =
|
proc loadConfig*(T: type RlnKeystoreGeneratorConf): Result[T, string] =
|
||||||
try:
|
try:
|
||||||
let conf = RlnKeystoreGeneratorConf.load()
|
let conf = RlnKeystoreGeneratorConf.load()
|
||||||
@ -65,6 +70,8 @@ proc loadConfig*(T: type RlnKeystoreGeneratorConf): Result[T, string] =
|
|||||||
return err("--rln-relay-eth-contract-address must be set")
|
return err("--rln-relay-eth-contract-address must be set")
|
||||||
if conf.rlnRelayCredPassword == "":
|
if conf.rlnRelayCredPassword == "":
|
||||||
return err("--rln-relay-cred-password must be set")
|
return err("--rln-relay-cred-password must be set")
|
||||||
|
if conf.rlnRelayEthPrivateKey == "":
|
||||||
|
return err("--rln-relay-eth-private-key must be set")
|
||||||
ok(conf)
|
ok(conf)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
err(getCurrentExceptionMsg())
|
err(getCurrentExceptionMsg())
|
||||||
|
@ -12,6 +12,7 @@ import
|
|||||||
../../waku/waku_keystore,
|
../../waku/waku_keystore,
|
||||||
../../waku/waku_rln_relay/rln,
|
../../waku/waku_rln_relay/rln,
|
||||||
../../waku/waku_rln_relay/conversion_utils,
|
../../waku/waku_rln_relay/conversion_utils,
|
||||||
|
../../waku/waku_rln_relay/group_manager/on_chain,
|
||||||
./external_config
|
./external_config
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
@ -50,17 +51,44 @@ when isMainModule:
|
|||||||
idSecretHash = credential.idSecretHash.inHex(),
|
idSecretHash = credential.idSecretHash.inHex(),
|
||||||
idCommitment = credential.idCommitment.inHex()
|
idCommitment = credential.idCommitment.inHex()
|
||||||
|
|
||||||
# 4. write to keystore
|
|
||||||
## TODO: after hooking up to the OnchainGroupManager,
|
if not conf.execute:
|
||||||
## obtain chainId and treeIndex from the contract
|
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(
|
let keystoreCred = MembershipCredentials(
|
||||||
identityCredential: credential,
|
identityCredential: credential,
|
||||||
membershipGroups: @[MembershipGroup(
|
membershipGroups: @[MembershipGroup(
|
||||||
membershipContract: MembershipContract(
|
membershipContract: MembershipContract(
|
||||||
chainId: "1155511",
|
chainId: $groupManager.chainId.get(),
|
||||||
address: conf.rlnRelayEthContractAddress,
|
address: conf.rlnRelayEthContractAddress,
|
||||||
),
|
),
|
||||||
treeIndex: 0,
|
treeIndex: groupManager.membershipIndex.get(),
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,6 +102,5 @@ when isMainModule:
|
|||||||
|
|
||||||
info "credentials persisted", path = conf.rlnRelayCredPath
|
info "credentials persisted", path = conf.rlnRelayCredPath
|
||||||
|
|
||||||
|
waitFor groupManager.stop()
|
||||||
|
quit(0)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user