chore(rln_keystore_generator): generate and persist credentials (#1928)

* chore(rln_keystore_generator): next iteration

* fix: error accessing

* fix: indentation
This commit is contained in:
Aaryamann Challani 2023-08-23 12:51:33 +05:30 committed by GitHub
parent 8239b45582
commit 07945a37c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 5 deletions

View File

@ -51,7 +51,7 @@ type
defaultValue: "",
name: "rln-relay-eth-contract-address" }: string
rlnRelayCredentialsPassword* {.
rlnRelayCredPassword* {.
desc: "Password for encrypting RLN credentials",
defaultValue: "",
name: "rln-relay-cred-password" }: string
@ -59,6 +59,12 @@ type
proc loadConfig*(T: type RlnKeystoreGeneratorConf): Result[T, string] =
try:
let conf = RlnKeystoreGeneratorConf.load()
if conf.rlnRelayCredPath == "":
return err("--rln-relay-cred-path must be set")
if conf.rlnRelayEthContractAddress == "":
return err("--rln-relay-eth-contract-address must be set")
if conf.rlnRelayCredPassword == "":
return err("--rln-relay-cred-password must be set")
ok(conf)
except CatchableError:
err(getCurrentExceptionMsg())

View File

@ -5,26 +5,75 @@ else:
import
chronicles,
stew/[results]
stew/[results],
std/tempfiles
import
./external_config
../../waku/waku_keystore,
../../waku/waku_rln_relay/rln,
../../waku/waku_rln_relay/conversion_utils,
./external_config
logScope:
topics = "rln_keystore_generator"
when isMainModule:
{.pop.}
# 1. load configuration
let confRes = RlnKeystoreGeneratorConf.loadConfig()
if confRes.isErr():
error "failure while loading the configuration", error=confRes.error()
error "failure while loading the configuration", error=confRes.error
quit(1)
let conf = confRes.get()
debug "configuration", conf = $conf
# initialize keystore
# 2. initialize rlnInstance
let rlnInstanceRes = createRLNInstance(d=20,
tree_path = genTempPath("rln_tree", "rln_keystore_generator"))
if rlnInstanceRes.isErr():
error "failure while creating RLN instance", error=rlnInstanceRes.error
quit(1)
let rlnInstance = rlnInstanceRes.get()
# 3. generate credentials
let credentialRes = rlnInstance.membershipKeyGen()
if credentialRes.isErr():
error "failure while generating credentials", error=credentialRes.error
quit(1)
let credential = credentialRes.get()
debug "credentials", idTrapdoor = credential.idTrapdoor.inHex(),
idNullifier = credential.idNullifier.inHex(),
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
let keystoreCred = MembershipCredentials(
identityCredential: credential,
membershipGroups: @[MembershipGroup(
membershipContract: MembershipContract(
chainId: "1155511",
address: conf.rlnRelayEthContractAddress,
),
treeIndex: 0,
)]
)
let persistRes = addMembershipCredentials(conf.rlnRelayCredPath,
@[keystoreCred],
conf.rlnRelayCredPassword,
RLNAppInfo)
if persistRes.isErr():
error "failed to persist credentials", error=persistRes.error
quit(1)
info "credentials persisted", path = conf.rlnRelayCredPath