TypeScript SDK for interacting with the Agentium Network API. Supports identity connection, OAuth token management, and W3C Verifiable Credentials (VCs) with Ed25519 signatures.
npm install @semiotic-labs/agentium-sdkimport { AgentiumClient } from '@semiotic-labs/agentium-sdk';
const client = new AgentiumClient();
// Connect with Google identity
const response = await client.connectGoogleIdentity(googleJwtToken);
console.log('User DID:', response.did);
console.log('Access Token:', response.accessToken);import { AgentiumClient } from '@semiotic-labs/agentium-sdk';
// Default: https://api.agentium.network
const client = new AgentiumClient();
// Custom endpoint (for local/staging)
const client = new AgentiumClient({ baseURL: 'http://localhost:8080' });
// For bundlers like Vite that require explicit WASM URL
import wasmUrl from '@semiotic-labs/agentium-sdk/wasm?url';
const client = new AgentiumClient({ wasmUrl });Connects a Google identity to an Agentium identity.
// Standard Google Sign-In
const response = await client.connectGoogleIdentity(googleJwtToken);
// External OAuth (e.g., zkLogin) - skip audience validation
const response = await client.connectGoogleIdentity(googleJwtToken, {
skipAudienceValidation: true,
});Returns: ConnectIdentityResponse with did, accessToken, refreshToken, expiresIn, isNew, badge
Exchanges an API key for JWT tokens (M2M authentication).
const tokens = await client.exchangeApiKey('ak_your_api_key');Refreshes an access token using a refresh token.
const newTokens = await client.refreshToken(currentRefreshToken);The SDK supports W3C Verifiable Credentials issued as JWTs with Ed25519 signatures.
import { createBrowserStorage, createMemoryStorage } from '@semiotic-labs/agentium-sdk';
// Browser environment (uses localStorage)
client.setVcStorage(createBrowserStorage());
// Node.js or testing (in-memory)
client.setVcStorage(createMemoryStorage());Fetches a membership credential from the backend.
const vcJwt = await client.fetchMembershipCredential(authToken);Verifies a JWT-VC against the issuer's public key.
const result = await client.verifyCredential(vcJwt);
if (result.valid) {
console.log('Subject DID:', result.claims?.sub);
} else {
console.error('Error:', result.error?.code, result.error?.message);
}Full flow: fetch, verify, and store a membership credential.
const result = await client.connectAndStoreMembership(authToken);Retrieves the stored VC JWT from storage.
const storedVc = client.getStoredCredential();Low-level cryptographic operations for Ed25519. WASM is automatically initialized on first use — no manual setup required.
import { verifyJwt, generateKeypair, getPublicKey } from '@semiotic-labs/agentium-sdk';
// Generate key pair
const { privateKey, publicKey } = await generateKeypair();
// Verify JWT directly
const result = await verifyJwt(jwtString, publicKeyJwk);For bundlers like Vite that require explicit WASM URL resolution, pass wasmUrl to the client constructor (see Client Setup).
If using low-level WASM utilities directly (without AgentiumClient), initialize manually:
import { ensureWasmReady } from '@semiotic-labs/agentium-sdk';
import wasmUrl from '@semiotic-labs/agentium-sdk/wasm?url';
await ensureWasmReady(wasmUrl);All API methods throw AgentiumApiError on failure:
import { AgentiumApiError } from '@semiotic-labs/agentium-sdk';
try {
await client.connectGoogleIdentity(token);
} catch (error) {
if (error instanceof AgentiumApiError) {
console.error(`API Error (${error.statusCode}): ${error.message}`);
}
}The SDK provides a flexible telemetry system that forwards tracing events from the WASM layer to JavaScript. Consumers can define custom sinks to handle events (logging, analytics, monitoring services, etc.).
Note: The WASM layer currently emits events only — spans are not yet supported.
Telemetry must be initialized after WASM is ready and can only be called once. If not initialized, no telemetry is emitted (silent by default).
import { ensureWasmReady, initTelemetry, consoleSink } from '@semiotic-labs/agentium-sdk';
await ensureWasmReady();
initTelemetry({ sink: consoleSink });consoleSink— Logs events to the browser/Node console using the appropriate method (console.error,console.warn, etc.)nullSink— Discards all events (useful for explicitly disabling telemetry)
Filter events by level or target module:
import { withLevelFilter, withTargetFilter, consoleSink } from '@semiotic-labs/agentium-sdk';
// Only log errors and warnings
const errorSink = withLevelFilter(['error', 'warn'], consoleSink);
// Only log events from agentium modules
const agentiumSink = withTargetFilter(['agentium_sdk'], consoleSink);Combine multiple sinks to forward events to different destinations:
import { composeSinks, withLevelFilter, consoleSink, initTelemetry } from '@semiotic-labs/agentium-sdk';
const myAnalyticsSink = (event) => {
// Send to your analytics service
analytics.track('sdk_event', event);
};
initTelemetry({
sink: composeSinks(
withLevelFilter(['error', 'warn', 'info'], consoleSink),
myAnalyticsSink
),
filter: 'agentium_sdk=debug' // tracing-subscriber EnvFilter syntax
});Events passed to sinks have the following shape:
interface TelemetryEvent {
kind: 'event'; // Event type (currently always "event")
level: 'error' | 'warn' | 'info' | 'debug' | 'trace';
target: string; // Module path (e.g., "agentium_sdk_wasm::vc")
name?: string; // Event name
fields: Record<string, unknown>; // Structured fields from the event
ts_ms: number; // Timestamp in milliseconds
}Generate full API documentation from source:
npm run docsDocumentation is output to the docs/ folder.
git clone https://github.com/semiotic-agentium/agentium-sdk.git
cd agentium-sdk
npm installnpm test # Run tests
npm run build # Build (WASM + TypeScript)
npm run docs # Generate API docs
npm run lint # Lint code
npm run check # Lint + format check
npm run check:python # Type-check Python code (mypy)
npm run format:all # Format all code (TS, Python, Rust)
npm run format:rust # Format Rust codeThis project follows the REUSE Specification.
pip install reuse # Install REUSE tool
npm run reuse:check # Verify compliance
npm run reuse:write # Apply SPDX headersA Python SDK is also available with equivalent functionality. See the Python SDK documentation for installation and usage.
pip install agentiumThis project is licensed under the Business Source License 1.1. See the LICENSE file for details.