mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
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:
parent
fa716d9b92
commit
4a3b5ca5f2
@ -51,7 +51,7 @@ type
|
|||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
name: "rln-relay-eth-contract-address" }: string
|
name: "rln-relay-eth-contract-address" }: string
|
||||||
|
|
||||||
rlnRelayCredentialsPassword* {.
|
rlnRelayCredPassword* {.
|
||||||
desc: "Password for encrypting RLN credentials",
|
desc: "Password for encrypting RLN credentials",
|
||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
name: "rln-relay-cred-password" }: string
|
name: "rln-relay-cred-password" }: string
|
||||||
@ -59,6 +59,12 @@ type
|
|||||||
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()
|
||||||
|
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)
|
ok(conf)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
err(getCurrentExceptionMsg())
|
err(getCurrentExceptionMsg())
|
||||||
|
|||||||
@ -5,26 +5,75 @@ else:
|
|||||||
|
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
stew/[results]
|
stew/[results],
|
||||||
|
std/tempfiles
|
||||||
|
|
||||||
import
|
import
|
||||||
./external_config
|
../../waku/waku_keystore,
|
||||||
|
../../waku/waku_rln_relay/rln,
|
||||||
|
../../waku/waku_rln_relay/conversion_utils,
|
||||||
|
./external_config
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "rln_keystore_generator"
|
topics = "rln_keystore_generator"
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
# 1. load configuration
|
||||||
let confRes = RlnKeystoreGeneratorConf.loadConfig()
|
let confRes = RlnKeystoreGeneratorConf.loadConfig()
|
||||||
if confRes.isErr():
|
if confRes.isErr():
|
||||||
error "failure while loading the configuration", error=confRes.error()
|
error "failure while loading the configuration", error=confRes.error
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
let conf = confRes.get()
|
let conf = confRes.get()
|
||||||
|
|
||||||
debug "configuration", conf = $conf
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user