TypeScript SDK v0.4.0

TypeScript SDK

The official TypeScript SDK for Skalor. Full type safety with ESM + CJS support. Built for Node.js agents and TypeScript backends.

Quickstart

1

Install

npm install @skalor/sdk
2

Initialize the client

agent.ts
import { Client } from "@skalor/sdk"

const zc = new Client({
  apiKey: "zc_your_key_here",
})
3

Authorize a payment

authorize.ts
const result = await zc.authorizeSpend({
  amount: 0.05,
  merchant: "api.openai.com",
  intent: "Purchasing GPT-4o tokens for lead scoring pipeline",
})

if (result.approved) {
  console.log(`CLEARED: $${result.amountUsd}`)
  console.log(`Transaction ID: ${result.transactionId}`)
  // Now safe to call the paid API
} else {
  console.log(`DENIED: ${result.denialReason}`)
}

Methods

MethodDescription
authorizeSpend(params)Clear 5 fiduciary gates and authorize a payment
payX402Invoice(params)Pay an HTTP 402 invoice and get a signed receipt (JWT)

Examples

Pay an x402 invoice

x402_payment.ts
const receipt = await zc.payX402Invoice({
  amount: 0.05,
  destination: "vendor-api.example.com/pay",
  intent: "Clearing paywall for real-time market data feed",
  currency: "USDC",
})

if (receipt.approved) {
  // Present the JWT to the vendor
  const headers = {
    Authorization: `x402 ${receipt.paymentReceipt}`,
  }
  const data = await fetch("https://vendor-api.example.com/data", { headers })
}

With ECDSA signing

signed_agent.ts
import { Client } from "@skalor/sdk"

const zc = new Client({
  apiKey: "zc_your_key",
  agentPrivateKey: "ed25519_hex_private_key", // Optional DID signing
})

// Every request is now cryptographically signed
const result = await zc.authorizeSpend({
  amount: 1.00,
  merchant: "api.anthropic.com",
  intent: "Signed inference call for audit compliance",
})

Types

types.ts
interface AuthorizeSpendParams {
  amount: number          // USD amount
  merchant: string        // Vendor URL or name
  intent: string          // Business justification (>= 15 chars)
  memo?: string           // Optional note
  executeOnChain?: boolean // Settle on-chain (default: false)
  currency?: "SOL" | "USDC"
  network?: "solana" | "base"
  metadata?: Record<string, unknown>
}

interface ApprovalResult {
  approved: boolean
  transactionId: string
  amountUsd: number
  merchant: string
  remainingDailyLimit: number
  denialReason?: string
  message: string
  solanaSignature?: string
  baseTxHash?: string
}