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 actionsignRequest— sign an HTTP request body with Ed25519registerAgent— register an agent with the OpenLeash serververifyProofOffline— verify a proof token locally using the public keyverifyProofOnline— verify a proof token via the server APIgenerateEd25519Keypair— generate a new Ed25519 signing keypaircreateApprovalRequest— create a pending approval requestgetApprovalRequest— fetch the status of an approval requestpollApprovalRequest— poll until an approval request is resolvedgetAgent— retrieve agent details from the serverlistPolicies— list all policies visible to the agentlistApprovalRequests— list all approval requests for the agentproposePolicy— 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