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

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

// Get available routes
const routes = await platform.bridge.getRoutes({
  fromChain: 'ethereum',
  toChain: 'polygon',
  token: 'USDC',
  amount: '1000000000',
});

// Execute bridge transfer
const bridgeTx = await platform.bridge.transfer({
  fromChain: 'ethereum',
  toChain: 'polygon',
  fromWallet: walletId,
  toAddress: '0x...',
  token: 'USDC',
  amount: '1000000000',
  route: routes[0].id,
});

// Check bridge status
const status = await platform.bridge.getStatus(bridgeTx.id);

AI Service

// Run inference in TEE
const response = await platform.ai.inference({
  model: 'gpt-4',
  messages: [
    { role: 'system', content: 'You are a financial analyst.' },
    { role: 'user', content: 'Analyze this transaction for risk.' },
  ],
  attestation: true,
});

console.log(response.content);
console.log(response.attestation); // TEE attestation proof

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

Ledger Service

// Create journal entry
const entry = await platform.ledger.createEntry({
  description: 'Token transfer',
  entries: [
    { account: 'assets:wallet:treasury', debit: '1000.00' },
    { account: 'assets:wallet:operations', credit: '1000.00' },
  ],
  metadata: { txHash: '0x...' },
});

// Get account balance
const balance = await platform.ledger.getBalance('assets:wallet:treasury');

// Query transactions
const transactions = await platform.ledger.query({
  account: 'assets:*',
  startDate: '2024-01-01',
  endDate: '2024-12-31',
});

Anchor Service

// Anchor data to blockchain
const anchor = await platform.anchor.create({
  data: { documentId: 'doc_123', hash: 'sha256:...' },
  chain: 'ethereum',
});

// Verify anchor
const verification = await platform.anchor.verify(anchor.id);
console.log(verification.verified); // true
console.log(verification.txHash);   // On-chain transaction

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';