Holochain Forum

How do "agentId" and "agentAddress" differ?

How do “agentId” and “agentAddress” differ? Particularly in js diorama tests.

Do you mean the public address?
The id is just the name of the agent and I think what you are referring to is the public hash key?
Which is used for encryption as part of the public / private key.

  • hdk::AGENT_ADDRESS is the public key of the agent.
  • hdk::AGENT_ID_STR is the second entry in the agent’s source chain, which in the future can contain arbitrary data such as invite codes, certificates signed by an authority that grants the agent permission to join the network, etc.

Right now you can’t actually put any content into the agent ID entry on the source chain, so for Diorama tests agentId == agentAddress.


Hi @pauldaoust, just reading this. Several questions arise from this:

  1. Can a zome force the AgentId to contain certain information? I guess it can, by checking in the validate_agent function and returning and error if it does not.
  2. Can an AgentId contain the agent_address for that agent? I guess the real question is, how is an agent_address derived for any given happ? Can it be derived by the agent itself before initializing the happ and pass it as a parameter? If so, it would open up the possibility of validating trivially who has made the commit or update, by checking the first entry of the source chain.
  3. When can we expect the change to allow arbitrary content in the agentId? Depending on that, we can start planning better designs for hApps ahead of time.

Thanks! :slight_smile:

Yes, exactly!

The agent ID entry’s address is always the public key (rather than the hash of the content), which is always configured when the agent is created in the conductor config. So yes, the agent can (and in fact must) derive it before they can even instantiate and use the hApp. And of course it’s always in the provenances field of the header of each entry they create too.

I misspoke in my first response; looks like you can already do this via the nick field. I wouldn’t rely on this field existing in the future, but it can be used for now. Users can set this field in their conductor config when they create an agent, either statically in the config file itself:

# Internal config reference used to connect agent to an instance; doesn't end up
# in the agent ID entry.
id = "alice"
# String which gets included in the `nick` field of the agent ID entry on
# every instance that uses this agent.
# I wish this were 'nick', not 'name', for consistency, but it isn't :(
name = "{\"invite_code\": \"ABCXYZ\"}"
public_address = "HcSCJts3fQ6Y4c4xr795Zj6inhTjecrfrsSFOrU9Jmnhnj5bdoXkoPSJivrm3wi"
keystore_file = "/org.holochain.holochain/keys/HcSCJts3fQ6Y4c4xr795Zj6inhTjecrfrsSFOrU9Jmnhnj5bdoXkoPSJivrm3wi"

or dynamically by creating an agent via the conductor admin RPC interface (this is useful for UIs, because users will prefer entering an invite code via a GUI rather than mucking about in config files):

    "jsonrpc": "2.0",
    "method": "admin/agent/add",
    "params": {
        "id": "alice",
        "name": "{\"invite_code\": \"ABCXYZ\"}",
        "public_address": "HcSCJts3fQ6Y4c4xr795Zj6inhTjecrfrsSFOrU9Jmnhnj5bdoXkoPSJivrm3wi",
        "keystore_file": "/org.holochain.holochain/keys/HcSCJts3fQ6Y4c4xr795Zj6inhTjecrfrsSFOrU9Jmnhnj5bdoXkoPSJivrm3wi"
    "id": "0"

or even with hc run:

hc run --agent-name '{"invite_code": "ABCXYZ"}'

(you can also do it in Tryorama, I think, but I haven’t figured out how yet.)

Oh so many thanks to you today, much appreciated!! Very clear and relevant responses! Much gold to you!

1 Like