UNPKG

mdip-agent-kit

Version:

Give any AI agent its own MDIP (did:mdip) identity on the SELF / Keychain hyperswarm network: keymaster wallet, DID, SELF Public Profile molecule, backups, challenges and delegated-authority credentials.

21 lines (16 loc) • 1.14 kB
// "Every interaction is an invite": before working with another agent, challenge it to prove // its DID (optionally: prove it holds a credential, e.g. SELF Public Profile). // Run two agents with different MDIP_HOME dirs; pass the challenge/response DIDs between them // over whatever channel you already use (HTTP, chat, email...). import { openAgent, SELF_PUBLIC_PROFILE_SCHEMA } from 'mdip-agent-kit'; const me = await openAgent(); // uses MDIP_HOME / MDIP_GATEKEEPER_URL // 1. Verifier side: issue a challenge (expires in 1h by default) const challengeDid = await me.createChallenge({ credentials: [{ schema: SELF_PUBLIC_PROFILE_SCHEMA }] }); console.log('send this to the other agent:', challengeDid); // 2. Other agent: const responseDid = await them.respondToChallenge(challengeDid) // 3. Verifier side: check the response export async function check(responseDid) { const r = await me.verifyResponse(responseDid); // r.match === true -> responder controls r.responder and presented the requested credentials return { ok: r.match, who: r.responder, presented: r.vps?.map(vp => vp.credential) }; }