Skip to content

JavaScript / TypeScript SDK

Installation

bash
npm install tauth

Or install directly from the repo:

bash
npm install ./sdk/js

Quick example

typescript
import { TauthClient } from 'tauth'

const client = new TauthClient({ apiKey: 'tauth_sk_live_xxxxxxxxxxxx' })

const result = await client.sign(file, 'photo.jpg', { creator: 'Alice Johnson' })

console.log(result.tx_hash)       // Ethereum transaction hash
console.log(result.download_url)  // Link to the signed file

The API key is sent as an X-API-Key header on every request.

Custom base URL

typescript
const client = new TauthClient({
  apiKey: 'tauth_sk_live_xxxxxxxxxxxx',
  baseUrl: 'https://api.tauth.io',
})

Sign a file

Works with a browser File, a Blob, or a Node.js Buffer:

typescript
const result = await client.sign(file, 'photo.jpg', {
  creator: 'Alice Johnson',
  description: 'Product shot for summer campaign',
})

console.log(result.asset_id)
console.log(result.tx_hash)

Verify a file

typescript
const result = await client.verifyFile(file, 'photo.jpg')
console.log(result.valid)    // true / false
console.log(result.manifest) // extracted C2PA manifest or null

Verify by URL:

typescript
const result = await client.verifyUrl('https://example.com/photo.jpg')

Verify by SHA-256 hash:

typescript
const result = await client.verifyHash('e3b0c44298fc1c149afb...')

List assets

typescript
const assets = await client.listAssets()
assets.forEach(asset => {
  console.log(asset.file_name, asset.tx_hash)
})

React example

tsx
import { TauthClient } from 'tauth'

const client = new TauthClient({
  apiKey: import.meta.env.VITE_TAUTH_API_KEY,
})

export function SignButton({ file }: { file: File }) {
  async function handleSign() {
    const result = await client.sign(file, file.name, { creator: 'My App' })
    console.log('Signed:', result.tx_hash)
  }

  return <button onClick={handleSign}>Sign file</button>
}

Error handling

typescript
import { TauthClient, TauthError } from 'tauth'

try {
  const result = await client.sign(file, 'photo.jpg', { creator: 'Alice' })
} catch (err) {
  if (err instanceof TauthError) {
    console.error(`Error ${err.status}: ${err.message}`)
  }
}

TypeScript types

typescript
interface SignOptions {
  creator?: string
  description?: string
  extraAssertions?: object[]
}

interface SignResult {
  asset_id: string
  file_name: string
  file_hash: string
  tx_hash: string | null
  download_url: string
}

interface VerifyResult {
  valid: boolean
  manifest: object | null
  blockchain: { tx_hash: string; registered_at?: string } | null
}

Built on C2PA · Secured by Azure Key Vault · Anchored on Ethereum