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

fix: checking for keystore file existence #2427

Merged
merged 10 commits into from
Feb 15, 2024
7 changes: 7 additions & 0 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ suite "Onchain group manager":
rlnInstance: manager.rlnInstance)
expect(ValueError): await manager2.init()

asyncTest "should error when keystore path and password are provided but file doesn't exist":
let manager = await setup()
manager.keystorePath = some("/inexistent/file")
manager.keystorePassword = some("password")

expect(CatchableError): await manager.init()

asyncTest "startGroupSync: should start group sync":
let manager = await setup()

Expand Down
65 changes: 35 additions & 30 deletions waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ else:
{.push raises: [].}

import
os,
web3,
web3/ethtypes,
eth/keys as keys,
Expand Down Expand Up @@ -623,37 +624,41 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
g.registryContract = some(registryContract)

if g.keystorePath.isSome() and g.keystorePassword.isSome():
var keystoreQuery = KeystoreMembership(
membershipContract: MembershipContract(
chainId: $g.chainId.get(),
address: g.ethContractAddress
if existsFile(g.keystorePath.get()):
gabrielmer marked this conversation as resolved.
Show resolved Hide resolved
var keystoreQuery = KeystoreMembership(
membershipContract: MembershipContract(
chainId: $g.chainId.get(),
address: g.ethContractAddress
)
)
)
if g.membershipIndex.isSome():
keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get())
waku_rln_membership_credentials_import_duration_seconds.nanosecondTime:
let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(),
password = g.keystorePassword.get(),
query = keystoreQuery,
appInfo = RLNAppInfo)
if keystoreCredRes.isErr():
raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error)
let keystoreCred = keystoreCredRes.get()
g.membershipIndex = some(keystoreCred.treeIndex)
when defined(rln_v2):
g.userMessageLimit = some(keystoreCred.userMessageLimit)
# now we check on the contract if the commitment actually has a membership
try:
let membershipExists = await rlnContract.memberExists(keystoreCred
.identityCredential
.idCommitment.toUInt256()).call()
if membershipExists == 0:
raise newException(CatchableError, "the provided commitment does not have a membership")
except CatchableError:
raise newException(CatchableError, "could not check if the commitment exists on the contract: " &
getCurrentExceptionMsg())

g.idCredentials = some(keystoreCred.identityCredential)
if g.membershipIndex.isSome():
keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get())
waku_rln_membership_credentials_import_duration_seconds.nanosecondTime:
let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(),
password = g.keystorePassword.get(),
query = keystoreQuery,
appInfo = RLNAppInfo)
if keystoreCredRes.isErr():
raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error)
let keystoreCred = keystoreCredRes.get()
g.membershipIndex = some(keystoreCred.treeIndex)
when defined(rln_v2):
g.userMessageLimit = some(keystoreCred.userMessageLimit)
# now we check on the contract if the commitment actually has a membership
try:
let membershipExists = await rlnContract.memberExists(keystoreCred
.identityCredential
.idCommitment.toUInt256()).call()
if membershipExists == 0:
raise newException(CatchableError, "the provided commitment does not have a membership")
except CatchableError:
raise newException(CatchableError, "could not check if the commitment exists on the contract: " &
getCurrentExceptionMsg())

g.idCredentials = some(keystoreCred.identityCredential)
else:
error "File provided as keystore path does not exist", path=g.keystorePath.get()
raise newException(CatchableError, "missing keystore")

let metadataGetRes = g.rlnInstance.getMetadata()
if metadataGetRes.isErr():
Expand Down
Loading