Reference
ReferenceSDK — @zentra/sdk
The Zentra client, GuardedAgent, proveAction, StatusEvent, and supporting types.
@zentra/sdk is the product surface: construct a client, define a policy, guard an
agent, and pay through a proof.
new Zentra(config)
new Zentra(cfg: ZentraConfig)
interface ZentraConfig {
contractId: string;
asset: string;
circuit: { wasmPath: string; zkeyPath: string };
rpcUrl?: string; // defaults to testnet
networkPassphrase?: string; // defaults to testnet
onStatus?: (e: StatusEvent) => void;
}Methods
createPolicy(config: PolicyConfig): Policy
commitPolicy(agent, policy: Policy): Promise<ConfirmedTx>
readState(agentPub: string, policy: Policy): Promise<AuthorityState>
pay(agent, policy: Policy, req: PayRequest): Promise<PayResult>
guard(agent, policy: Policy): GuardedAgentcreatePolicybuilds a policy locally: the Poseidon-MerklerecipientRootand the policy commitment.commitPolicyregisters the commitment + root on-chain (register_policy).readStatesimulatesauthority_stateto read the currentAuthorityState.payruns the full read-state → prove → submit loop for one action.guardreturns aGuardedAgentthat can only pay throughpay.
GuardedAgent
interface GuardedAgent {
pay(req: PayRequest): Promise<PayResult>;
}
interface PayRequest {
recipient: string;
amount: bigint;
invoicePreimage: bigint;
nonce?: bigint;
nowSeconds?: number;
}
interface PayResult {
txHash: string;
nullifier: string;
}proveAction
proveAction(policy: Policy, ctx: ActionContext, artifacts: CircuitArtifacts): Promise<ProveResult>Validates the recipient is in the approved set and throws before proving if it isn't (Panel B). Returns the proof and the 14 public inputs.
StatusEvent
type StatusEvent =
| { phase: 'proving'; recipient: string; amount: bigint }
| { phase: 'proof-ready'; nullifier: string }
| { phase: 'submitting' }
| { phase: 'released'; txHash: string }
| { phase: 'blocked'; reason: string };Derivations
policyCommitment = Poseidon(maxAmount, dailyLimit, recipientRoot, assetField, salt)
recipientRoot = Poseidon-Merkle (depth 4 / 16 leaves), leaf = Poseidon(recipientField), pad 0
nullifier = Poseidon(agentField, policyCommitment, contractField, nonce)
invoiceHash = Poseidon(invoicePreimage)Constants & dependencies
TESTNET = {
rpcUrl: 'https://soroban-testnet.stellar.org',
networkPassphrase: 'Test SDF Network ; September 2015',
};Proof bytes: 256 (a 64 ‖ b 128 ‖ c 64). Built on @stellar/stellar-sdk 15.1.0,
snarkjs 0.7.6, and circomlibjs 0.1.7.