Zum Inhalt

TypeScript / JavaScript

SDK in Planung

Ein offizielles TypeScript-SDK ist geplant. Aktuell können Sie die REST-API direkt mit fetch() ansprechen.

Installation

Keine SDK-Installation nötig. Die Beispiele verwenden die native fetch()-API (Node 18+, Deno, Browser).

Hash stempeln

const SIEGEL_URL = "https://siegel.kavra.cloud";
const SERVICE_TOKEN = "sk_your_token_here";

async function stampHash(sha256Hex: string, tier = "basic") {
  const resp = await fetch(`${SIEGEL_URL}/api/v1/internal/v1/stamp`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Kavra-Service-Token": SERVICE_TOKEN,
    },
    body: JSON.stringify({
      hash: sha256Hex,
      tier,
      metadata: { source: "my-ts-app" },
    }),
  });

  if (!resp.ok) {
    throw new Error(`Stamp failed: ${resp.status} ${await resp.text()}`);
  }

  return await resp.json();
}

// Beispiel
const token = await stampHash(
  "a1b2c3d4a1b2c3d4a1b2c3d4a1b2c3d4a1b2c3d4a1b2c3d4a1b2c3d4a1b2c3d4"
);
console.log(token.token_id, token.is_qualified);

Stempel verifizieren

async function verifyToken(tokenId: string) {
  const resp = await fetch(
    `${SIEGEL_URL}/api/v1/verify/v1/token/${tokenId}`
  );
  // Kein Auth-Header nötig — öffentlicher Endpoint
  return await resp.json();
}

const result = await verifyToken(token.token_id);
console.log(`Gültig: ${result.valid}`);
console.log(`Provider: ${result.tsp_provider}`);

Content stempeln (mit Hash-Berechnung)

async function stampContent(content: string, tier = "basic") {
  // Hash client-seitig berechnen
  const encoder = new TextEncoder();
  const data = encoder.encode(content);
  const hashBuffer = await crypto.subtle.digest("SHA-256", data);
  const hashHex = Array.from(new Uint8Array(hashBuffer))
    .map((b) => b.toString(16).padStart(2, "0"))
    .join("");

  return stampHash(hashHex, tier);
}

Health-Check

const health = await fetch(`${SIEGEL_URL}/health`).then((r) => r.json());
console.log(health.status);        // "ok"
console.log(health.is_qualified);   // false (Mock-TSP)

Response-Typen (manuell)

interface StampToken {
  token_id: string;
  issued_at: string;
  content_sha256: string;
  token: string;
  tier: "basic" | "plus" | "sealed";
  tsp_provider: string;
  is_qualified: boolean;
  verify_url: string;
  sealed_storage_url: string | null;
}

interface VerificationResult {
  valid: boolean;
  token_id: string | null;
  issued_at: string | null;
  content_sha256: string | null;
  tsp_provider: string | null;
  is_qualified: boolean | null;
  reason: string | null;
}

OpenAPI-Codegen

Die OpenAPI-Spec ist verfügbar unter https://siegel.kavra.cloud/openapi.json. Sie können daraus mit openapi-typescript automatisch Typen generieren.