Skip to content

Commit

Permalink
chore(rln_keystore_generator): generate and persist credentials (#1928)
Browse files Browse the repository at this point in the history
* chore(rln_keystore_generator): next iteration

* fix: error accessing

* fix: indentation
  • Loading branch information
rymnc authored Aug 23, 2023
1 parent 8239b45 commit 07945a3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
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 == "":
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",
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




0 comments on commit 07945a3

Please sign in to comment.