Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rln_keystore_generator): generate and persist credentials #1928

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tools/rln_keystore_generator/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ type
defaultValue: "",
name: "rln-relay-eth-contract-address" }: string

rlnRelayCredentialsPassword* {.
rlnRelayCredPassword* {.
desc: "Password for encrypting RLN credentials",
defaultValue: "",
name: "rln-relay-cred-password" }: string

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 == "":
rymnc marked this conversation as resolved.
Show resolved Hide resolved
return err("--rln-relay-cred-password must be set")
ok(conf)
except CatchableError:
err(getCurrentExceptionMsg())
Expand Down
57 changes: 53 additions & 4 deletions tools/rln_keystore_generator/rln_keystore_generator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
rymnc marked this conversation as resolved.
Show resolved Hide resolved
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