Installation

Terminal
$ npm install @openleash/sdk-ts

Quick Example

Request authorization before performing a risky action. The SDK signs the request with your agent's Ed25519 private key and returns a decision with an optional proof token.

authorize.ts
import {
authorize,
generateEd25519Keypair,
} from '@openleash/sdk-ts';
// Generate a keypair (do this once, store the keys)
const { publicKey, privateKey } = await generateEd25519Keypair();
// Request authorization for an action
const result = await authorize({
baseUrl: 'http://localhost:8787',
agentId: 'agent-uuid',
privateKey,
request: {
action: 'purchase',
resource: 'office-supplies',
context: { amount: 42.00 },
},
});
// result.decision: 'ALLOW' | 'DENY' | 'REQUIRE_APPROVAL' | ...
// result.proofToken: signed PASETO v4.public token (if allowed)

Available Functions

The TypeScript SDK provides 13 functions covering the full agent authorization lifecycle:

  • authorize — request an authorization decision for an action
  • signRequest — sign an HTTP request body with Ed25519
  • registerAgent — register an agent with the OpenLeash server
  • verifyProofOffline — verify a proof token locally using the public key
  • verifyProofOnline — verify a proof token via the server API
  • generateEd25519Keypair — generate a new Ed25519 signing keypair
  • createApprovalRequest — create a pending approval request
  • getApprovalRequest — fetch the status of an approval request
  • pollApprovalRequest — poll until an approval request is resolved
  • getAgent — retrieve agent details from the server
  • listPolicies — list all policies visible to the agent
  • listApprovalRequests — list all approval requests for the agent
  • proposePolicy — propose a new policy for owner review

Proof Verification

Counterparties can verify proof tokens offline without contacting the OpenLeash server. The token is a PASETO v4.public token signed with Ed25519.

verify.ts
import { verifyProofOffline } from '@openleash/sdk-ts';
const claims = await verifyProofOffline({
proofToken,
publicKey: ownerPublicKey,
});
// claims.action, claims.resource, claims.decision, claims.exp

Links