Holochain Forum

Using one of multiple available cap grants

Hi all -
Well, this sounds like a duplicate of this, but that’s about managing issued grants as a grantor. This post is a related question but from a grantee perspective.

My use case is as follows:

  • Alice issues a Cap grant to Bob, letting Bob read Alice’s private entries (CapClaim[0].secret())
  • Alice then issues another cap grant to Bob, letting him create a private entry (CapClaim[1].secret())
  • Bob creates the entry but then wants to list Alice’s entries again.

So Bob now has multiple active cap grants, and may decide to use any of them at any time. How do we write the function which picks the right secret at any time to pass to a call_remote function?

I have been hardcoding CapClaim[0].secret() which is obviously Bad, but I noticed in the Holochain Gym that Guillem uses pop() to get (I think?) the most recent one every time. This is obviously more dynamic, but it doesn’t solve the problem of Bob wanting to use a cap grant that is not the most recent.

Alice could of course just issue a new cap grant which Bob could use immediately after, but that feels a bit clunky.

What is a good pattern to achieve this?
Thank you! alex.