TypeScript SDK

The official TypeScript SDK for Tenzro Platform provides type-safe access to all services with built-in authentication, error handling, and automatic retries.

Installation

npm install @tenzro/platform
# or
yarn add @tenzro/platform
# or
pnpm add @tenzro/platform

Requirements

  • Node.js 18 or later
  • TypeScript 5.0 or later (recommended)

Basic Usage

import { TenzroPlatform } from '@tenzro/platform';

const platform = new TenzroPlatform({
  apiKey: process.env.TENZRO_API_KEY!,
  tenantId: process.env.TENZRO_TENANT_ID!,
});

// Access services
const wallets = await platform.wallet.list();
const balance = await platform.wallet.getBalance(wallets[0].id);

Configuration Options

interface TenzroPlatformConfig {
  // Required
  apiKey: string;
  tenantId: string;

  // Optional
  baseUrl?: string;          // Default: https://api.platform.tenzro.com
  timeout?: number;          // Request timeout in ms (default: 30000)
  retries?: number;          // Max retry attempts (default: 3)
  retryDelay?: number;       // Base delay between retries in ms (default: 1000)

  // Advanced
  headers?: Record<string, string>;  // Custom headers
  fetch?: typeof fetch;              // Custom fetch implementation
}

Available Services

The SDK provides typed clients for all Tenzro Platform services:

ServicePropertyDescription
Walletplatform.walletCreate and manage wallets
Tokenplatform.tokenToken operations and transfers
Bridgeplatform.bridgeCross-chain transfers
Custodyplatform.custodyMPC key management
Ledgerplatform.ledgerDouble-entry accounting
AIplatform.aiTEE-secured inference
Anchorplatform.anchorBlockchain anchoring
API Keysplatform.apiKeysKey management
Eventsplatform.eventsReal-time events
Provisionplatform.provisionCanton Network allocations

Wallet Service

// Create a wallet
const wallet = await platform.wallet.create({
  name: 'Treasury',
  type: 'multi-sig',
  chain: 'ethereum',
  signers: ['user_1', 'user_2', 'user_3'],
  threshold: 2,
});

// List wallets
const wallets = await platform.wallet.list({
  chain: 'ethereum',
  type: 'multi-sig',
  limit: 10,
});

// Get balance
const balance = await platform.wallet.getBalance(wallet.id);

// Get transactions
const txs = await platform.wallet.getTransactions(wallet.id, {
  limit: 50,
  status: 'confirmed',
});

Token Service

// Transfer tokens
const transfer = await platform.token.transfer({
  from: walletId,
  to: '0x...',
  token: 'USDC',
  amount: '1000000000', // 1000 USDC (6 decimals)
  chain: 'ethereum',
});

// Get token info
const tokenInfo = await platform.token.getInfo('USDC', 'ethereum');

// Get token balance
const balance = await platform.token.getBalance(walletId, 'USDC');

Bridge Service

Cross-chain bridging via Chainlink CCIP.

// Get available routes between chains
const routes = await platform.bridge.getRoutes('base', 'canton');

// Get a quote for a bridge transfer
const quote = await platform.bridge.getQuote({
  sourceChain: 'base',
  destinationChain: 'canton',
  asset: 'USDC',
  amount: '1000000000', // in smallest units
});

// Initiate bridge transfer
const operation = await platform.bridge.initiate({
  quoteId: quote.quoteId,
  sender: '0x742d35Cc6634C0532925a3b...',
  recipient: 'party::myapp::alice',
});

// Track operation status
const status = await platform.bridge.getOperation(operation.id);

// Cancel or retry if needed
await platform.bridge.cancel(operation.id);
await platform.bridge.retry(operation.id);

AI Service

// List available models
const models = await platform.ai.listModels();

// Run inference with TEE attestation
const result = await platform.ai.infer({
  modelId: 'llama-3.1-70b',
  prompt: 'Analyze this transaction for risk.',
  maxTokens: 1024,
  temperature: 0.7,
  attestation: true, // Request TEE attestation
});
console.log(result.content);
console.log(result.teeAttestation?.type); // 'intel_tdx' | 'amd_sev_snp' | 'aws_nitro'

// Streaming inference
for await (const chunk of platform.ai.inferStream({
  modelId: 'llama-3.1-70b',
  prompt: 'Write a detailed analysis...',
})) {
  process.stdout.write(chunk);
}

// Generate embeddings
const embeddings = await platform.ai.embed({
  modelId: 'text-embedding-3-small',
  input: ['Transaction 1 data', 'Transaction 2 data'],
});

Multi-Party Inference (v1.1)

Run secure inference across multiple parties without exposing individual data.

// Create a multi-party session
const session = await platform.ai.createMultiPartySession({
  name: 'Cross-Bank Analysis',
  modelId: 'risk-analyzer-v2',
  participants: ['party::bankA::treasury', 'party::bankB::treasury'],
  dataPolicy: {
    minParticipants: 2,
    aggregationMethod: 'federated',
    encryptionRequired: true,
  },
});

// Submit encrypted data to session
await platform.ai.submitSessionData({
  sessionId: session.id,
  data: encryptedData,
  dataSchema: 'transaction_records_v1',
});

// Run inference on aggregated data
const result = await platform.ai.runMultiPartyInference({
  sessionId: session.id,
  prompt: 'Analyze combined patterns',
});

Verifiable AI (v1.1)

Record AI inference to Canton Network for immutable audit trails.

// Run inference with attestation
const inference = await platform.ai.infer({
  modelId: 'llama-3.1-70b',
  prompt: 'Compliance analysis...',
  attestation: true,
});

// Record to Canton ledger
const proof = await platform.ai.recordInference({
  modelId: inference.modelId,
  inputHash: inference.inputHash,
  outputHash: inference.outputHash,
  attestation: inference.teeAttestation!,
  metadata: { purpose: 'compliance' },
});

// Verify a recorded inference
const verification = await platform.ai.verifyInference({
  proofId: proof.proofId,
});
console.log('Valid:', verification.valid);

// Query inference history
const history = await platform.ai.getInferenceHistory({
  modelId: 'llama-3.1-70b',
  limit: 100,
});

RAG (Retrieval-Augmented Generation)

// Query with RAG
const result = await platform.ai.ragQuery({
  query: 'What are the compliance requirements?',
  dataSourceIds: ['ds-legal', 'ds-regulations'],
  maxResults: 5,
  includeContext: true,
});

console.log(result.answer);
console.log(result.sources); // Retrieved documents

Ledger Service

Canton Network Ledger API with parties, contracts, and domains.

// Allocate a new party
const party = await platform.ledger.allocateParty({
  displayName: 'Treasury',
  namespace: 'myapp',
  hint: 'treasury',
});

// Get party balance
const balance = await platform.ledger.getBalance(party.identifier);

// Transfer tokens between parties
await platform.ledger.transfer({
  fromParty: 'party::myapp::alice',
  toParty: 'party::myapp::treasury',
  asset: 'CC',
  amount: '100.00',
});

// Create a Daml contract
const contract = await platform.ledger.createContract({
  templateId: 'Tenzro.Token:Asset',
  payload: { owner: party.identifier, amount: '1000.00' },
  signatories: [party.identifier],
});

// Exercise a choice on a contract
await platform.ledger.exerciseChoice({
  contractId: contract.contractId,
  choice: 'Transfer',
  argument: { newOwner: 'party::myapp::bob' },
  actingParties: [party.identifier],
});

// List synchronization domains
const domains = await platform.ledger.listDomains();

Anchor Service

State root anchoring with Merkle proofs.

// Submit a state root for anchoring
const anchor = await platform.anchor.submit({
  stateRoot: '0x1234567890abcdef...',
  namespace: 'myapp',
});

// Verify a Merkle proof
const result = await platform.anchor.verify({
  stateRoot: '0x1234567890abcdef...',
  leaf: '0xabcdef...',
  proof: ['0x...', '0x...'],
  index: 0,
});
console.log(result.valid); // true

// Create a batch of anchors
const batch = await platform.anchor.createBatch({
  stateRoots: ['0x...', '0x...'],
  namespace: 'myapp',
});

Events Service

// Subscribe to real-time events
const subscription = platform.events.subscribe({
  topics: ['wallet:*', 'bridge:completed'],
  onMessage: (event) => {
    console.log('Event received:', event);
  },
  onError: (error) => {
    console.error('Event error:', error);
  },
});

// Unsubscribe when done
subscription.unsubscribe();

TypeScript Types

The SDK exports all types for strong typing:

import type {
  Wallet,
  WalletType,
  Chain,
  Token,
  Transfer,
  BridgeRoute,
  BridgeTransfer,
  LedgerEntry,
  Anchor,
  AIMessage,
  AIResponse,
} from '@tenzro/platform';