Record your first action
Run these examples against your local sandbox log. Generate and keep keys in your application, never in this page.
1. Install and start locally
Follow the SDK and server setup. These examples require TypeScript SDK 0.6.0 or Python SDK 0.27.0. These are unpublished source candidates; use this checkout until the packages are released. Use synthetic data. An API key is required when your deployment enables write authentication and for protected reads.
2. Record and inspect acceptance
TypeScript / JavaScript
import { ZaniiAgent, generateKeypair, createCert, fetchAndVerifyProof } from '@zanii/sdk';
const owner = generateKeypair(), agent = generateKeypair();
const cert = createCert({ issuer: owner.did, subject: agent.did,
scopes: ['crm.*'], exp: new Date(Date.now() + 86400000).toISOString() }, owner.privateKey);
const zanii = new ZaniiAgent({ serverUrl: 'http://localhost:4600', agentDid: agent.did,
agentPrivateKey: agent.privateKey, delegation: [cert], apiKey: process.env.ZANII_API_KEY });
const { hash } = await zanii.record({ target: 'crm.contact.update', payload: { reference: 'sandbox-1' } });
const delivery = await zanii.flush(); // inspect accepted / duplicate / rejected results
const proof = await fetchAndVerifyProof('http://localhost:4600', hash, undefined, {
apiKey: process.env.ZANII_API_KEY, expectedAgentId: agent.did, expectedOwnerId: owner.did, expectedLogId: process.env.ZANII_LOG_ID });
console.log({ hash, delivery, verified: proof.ok });Python
import os
from datetime import datetime, timedelta, timezone
from zanii import ZaniiAgent, generate_keypair, create_cert, fetch_and_verify_proof
owner, agent = generate_keypair(), generate_keypair()
cert = create_cert(issuer=owner.did, subject=agent.did, scopes=['crm.*'],
exp=(datetime.now(timezone.utc) + timedelta(days=1)).isoformat(), issuer_private_key=owner.private_key)
zanii = ZaniiAgent(server_url='http://localhost:4600', agent_did=agent.did,
agent_private_key=agent.private_key, delegation=[cert], api_key=os.environ.get('ZANII_API_KEY'))
receipt, receipt_hash = zanii.record(target='crm.contact.update', payload={'reference': 'sandbox-1'})
delivery = zanii.flush() # inspect accepted / duplicate / rejected results
proof = fetch_and_verify_proof('http://localhost:4600', receipt_hash,
api_key=os.environ.get('ZANII_API_KEY'), expected_log_id=os.environ.get('ZANII_LOG_ID'),
expected_agent_id=agent.did, expected_owner_id=owner.did)
print({'hash': receipt_hash, 'delivery': delivery, 'verified': proof.ok})Recording queues evidence. A successful business action, a signed receipt and log acceptance are separate states. An unavailable log does not make an action safe to retry.
3. Verify and export
Open /verify/<receipt hash> on your log. Download /v1/export/<agent DID>?download=1 and open it in the offline verifier. Set ZANII_LOG_ID to the expected log identity from your trusted operator configuration. Omitting it leaves the log-identity pin unchecked.