TectraTectra
TypeScript SDK

TypeScript SDK

@tectra/sdk - Official SDK for JavaScript and TypeScript. Sign, verify, and manage records from Node.js or the browser.

Environment support

Works in Node.js 18+ and modern browsers (Chrome, Firefox, Safari, Edge). Browser builds use the Web Crypto API. Node.js builds use the native crypto module.

Installation

bash
npm install @tectra/sdk

Or with yarn/pnpm:

bash
yarn add @tectra/sdk
# or
pnpm add @tectra/sdk

Initialization

Create a client with your API key and optional configuration.

typescript
import { TectraClient } from "@tectra/sdk";

const client = new TectraClient({
  apiKey: "iai_live_abc123...",          // From dashboard → API Keys
  signingKeyId: "your-key-uuid",        // From dashboard → Signing Keys (optional default)
  apiUrl: "https://tectra.vision",      // Default
});

client.sign()

Sign a single image. Accepts a file path (Node.js), Buffer, or Blob (browser).

typescript
// Sign from file path (Node.js)
const result = await client.sign("photo.jpg");

// Sign from Buffer
import { readFileSync } from "fs";
const buf = readFileSync("photo.jpg");
const result = await client.sign(buf, { filename: "photo.jpg" });

// Sign with metadata
const result = await client.sign("generated.png", {
  originType: "ai_generated_image",
  metadata: {
    model: "my-model-v2",
    seed: 42,
  },
});

// Result:
// {
//   recordId: "uuid",
//   sha256: "abc123...",
//   perceptualHash: "def456...",
//   signatureHex: "ghi789...",
//   blockchainStatus: "pending",
//   certificate: {
//     recordId: "uuid",
//     sha256: "abc123...",
//     orgName: "Acme AI Inc.",
//     timestamp: "2025-01-15T12:34:56Z",
//   }
// }

client.signBatch()

Sign multiple images in a single request. Returns an array of results.

typescript
const results = await client.signBatch([
  { input: "photo1.jpg" },
  { input: "photo2.jpg", originType: "camera_image" },
  { input: buffer, filename: "photo3.jpg" },
]);

for (const result of results) {
  console.log(`${result.recordId}: ${result.blockchainStatus}`);
}

client.verify()

Verify any file. Uses a two-tier approach: SHA-256 hash lookup first (no upload), falling back to full upload for image watermark + pHash analysis. Videos are always hash-only — the file never leaves the client.

typescript
const result = await client.verify(file);

console.log(`Authentic: ${result.authentic}`);
console.log(`Confidence: ${(result.confidence * 100).toFixed(0)}%`);

if (result.signer) {
  console.log(`Signed by: ${result.signer.org_name}`);
}

for (const [check, data] of Object.entries(result.checks)) {
  const status = data.passed ? "✓" : "○";
  console.log(`  ${status} ${check}: ${data.details}`);
}

client.verifyByHash()

Verify using a pre-computed SHA-256 hash. No file upload at all. Use this when you have already hashed the file client-side.

typescript
// Compute hash yourself using Web Crypto
const buf = await file.arrayBuffer();
const hashBuf = await crypto.subtle.digest("SHA-256", buf);
const sha256 = Array.from(new Uint8Array(hashBuf))
  .map(b => b.toString(16).padStart(2, "0")).join("");

// Send only the hash — 64 bytes over the wire
const result = await client.verifyByHash(sha256, file.type);

// Useful for videos — the SDK's verify() does this automatically,
// but you can call it directly for full control
console.log(result.authentic);

client.listRecords()

List all signed content records for your account.

typescript
const records = await client.listRecords({
  page: 1,
  limit: 50,
  sort: "created_at",
  order: "desc",
});

for (const record of records.items) {
  console.log(`${record.id} - ${record.originalFilename} - ${record.blockchainStatus}`);
}

client.getRecord()

Get a single content record by ID.

typescript
const record = await client.getRecord("record-uuid");

console.log(record.sha256);
console.log(record.blockchainStatus);
console.log(record.certificate);

client.getCertificate()

Fetch the public certificate for a content record.

typescript
const cert = await client.getCertificate("record-uuid");

console.log(cert.orgName);
console.log(cert.sha256);
console.log(cert.timestamp);
console.log(cert.blockchainTx);

client.revokeRecord()

Revoke a content record. The record will still exist but will fail verification.

typescript
await client.revokeRecord("record-uuid");
// Record is now revoked - verification will return authentic: false

API Key Management

Create and list API keys programmatically.

typescript
// Create a new API key
const key = await client.createApiKey({
  name: "CI Pipeline",
  scopes: ["sign", "verify"],
});
console.log(`Key: ${key.key}`); // Only shown once

// List all API keys
const keys = await client.listApiKeys();
for (const k of keys) {
  console.log(`${k.name} - ${k.prefix}... - ${k.lastUsed}`);
}

Signing Key Management

Create and list Ed25519 signing keys.

typescript
// Create a new signing key
const signingKey = await client.createSigningKey({
  name: "production-v2",
});
console.log(`Key ID: ${signingKey.id}`);
console.log(`Public key: ${signingKey.publicKeyHex}`);

// List all signing keys
const signingKeys = await client.listSigningKeys();
for (const sk of signingKeys) {
  console.log(`${sk.name} - ${sk.id} - ${sk.createdAt}`);
}

Webhook Management

Create, list, and delete webhooks from the SDK.

typescript
// Create a webhook
const webhook = await client.createWebhook({
  url: "https://example.com/webhooks/tectra",
  events: ["content.signed", "batch.anchored"],
});
console.log(`Webhook ID: ${webhook.id}`);
console.log(`Secret: ${webhook.secret}`); // Only shown once

// List all webhooks
const webhooks = await client.listWebhooks();
for (const wh of webhooks) {
  console.log(`${wh.id} - ${wh.url} - ${wh.events.join(", ")}`);
}

// Delete a webhook
await client.deleteWebhook("webhook-uuid");

Error Handling

All methods throw TectraError on failure.

typescript
import { TectraError } from "@tectra/sdk";

try {
  await client.sign("photo.jpg");
} catch (err) {
  if (err instanceof TectraError) {
    console.error(`Tectra error ${err.status}: ${err.message}`);
    console.error(`Request ID: ${err.requestId}`);
  }
}

Browser Usage

In the browser, pass a File or Blob to sign() and verify().

typescript
// Browser: verify an uploaded file
const input = document.querySelector<HTMLInputElement>("#file-input");
const file = input?.files?.[0];

if (file) {
  const result = await client.verify(file);
  console.log(result.authentic);
}

Looking for the Python SDK?

Local signing, video support, and directory watcher.

Python SDK