BengarTrust infrastructure

Developers

TypeScript SDK PREVIEW

A typed client for the authorization and execution API.

Install

pnpm add @bengar/sdk

Authorize

import { Bengar } from "@bengar/sdk";

const bengar = new Bengar({ apiKey: process.env.BENGAR_API_KEY! });

const decision = await bengar.authorize({
  agent:    "did:key:z6MkProcurement",
  permit,
  action:   "purchase",
  resource: "resource://company/procurement/laptop",
  amount:   { minor: 500_000, currency: "TRY" },
});

if (decision.decision !== "ALLOW") {
  // "DENY" or "REQUIRE_APPROVAL". Neither means go.
  return;
}

Closed vocabularies

`DECISIONS` and `EXECUTION_STATUSES` are exported as values, so a switch over them is exhaustive and a new status is a type error rather than a runtime surprise.

import { DECISIONS, EXECUTION_STATUSES } from "@bengar/sdk";

DECISIONS;           // ["ALLOW", "DENY", "REQUIRE_APPROVAL"]
EXECUTION_STATUSES;  // ["PENDING", "SUCCEEDED", "FAILED", "UNKNOWN"]

Errors

import { BengarError } from "@bengar/sdk";

try {
  await bengar.authorize(input);
} catch (error) {
  if (error instanceof BengarError) {
    // A closed kind. `unknown` means the outcome is undetermined —
    // never retry it automatically.
    error.kind;
  }
}

Server-only. It holds a tenant API key; a browser bundle that imports it ships that key to every visitor.

What it does not cover yet

Limits today

API reference · Errors