TLSNotary Service for managing attestation tokens and proof storage

Constructors

Methods

  • Calculate the storage fee for a proof

    Fee structure:

    • 1 DEM base fee
    • 1 DEM per KB of proof data

    Parameters

    • proofSizeKB: number

      Size of proof in kilobytes

    Returns number

    Total fee in DEM

    const fee = service.calculateStorageFee(5); // 6 DEM for 5KB proof
    
  • Request attestation token and create a pre-configured TLSNotary instance

    This is the recommended way to perform attestations. It handles:

    1. Creating and broadcasting the TLSN_REQUEST transaction
    2. Waiting for the token to be created
    3. Getting the proxy URL
    4. Creating a TLSNotary instance configured with that proxy
    5. Initializing the WASM module

    The returned TLSNotary instance is ready to call attest() immediately.

    Parameters

    Returns Promise<{
        expiresAt: number;
        proxyUrl: string;
        requestTxHash: string;
        tlsn: TLSNotary;
        tokenId: string;
    }>

    Object with TLSNotary instance, tokenId, and proxyUrl

    const service = new TLSNotaryService(demos);

    // Get a ready-to-use TLSNotary instance
    const { tlsn, tokenId, proxyUrl } = await service.createTLSNotary({
    targetUrl: 'https://api.github.com/users/octocat'
    });

    // Perform attestation - the proxy is already configured!
    const result = await tlsn.attest({
    url: 'https://api.github.com/users/octocat',
    });

    // Store proof on-chain
    await service.storeProof(tokenId, JSON.stringify(result.presentation), { storage: 'onchain' });
  • Request attestation token and create a pre-configured TLSNotary instance WITH user confirmation before broadcasting the transaction.

    This is the recommended way to perform attestations in user-facing applications. It handles:

    1. Creating the TLSN_REQUEST transaction
    2. Asking the user to confirm via the onConfirm callback
    3. Broadcasting the transaction if confirmed
    4. Waiting for the token to be created
    5. Getting the proxy URL
    6. Creating a TLSNotary instance configured with that proxy
    7. Initializing the WASM module

    Parameters

    Returns Promise<{
        expiresAt: number;
        proxyUrl: string;
        requestTxHash: string;
        tlsn: TLSNotary;
        tokenId: string;
    }>

    Object with TLSNotary instance, tokenId, and proxyUrl

    Error if user rejects the transaction

    const service = new TLSNotaryService(demos);

    // Get a ready-to-use TLSNotary instance with user confirmation
    const { tlsn, tokenId, proxyUrl } = await service.createTLSNotaryWithConfirmation(
    { targetUrl: 'https://api.github.com/users/octocat' },
    {
    onConfirm: async (details) => {
    // Show confirmation dialog to user in your UI
    return await showConfirmDialog({
    title: 'Confirm Attestation',
    message: `Burn ${details.amount} DEM for attestation?`,
    txHash: details.txHash,
    });
    }
    },
    (status) => console.log(status)
    );

    // Perform attestation - the proxy is already configured!
    const result = await tlsn.attest({
    url: 'https://api.github.com/users/octocat',
    });
  • Get attestation token information by token ID

    Parameters

    • tokenId: string

      The attestation token ID

    Returns Promise<TLSNotaryToken>

    Token information or null if not found

    const token = await service.getToken(tokenId);
    if (token?.status === 'stored') {
    console.log('Proof already stored:', token.proofHash);
    }
  • Get attestation token information by transaction hash

    Parameters

    • txHash: string

      The transaction hash of the TLSN_REQUEST transaction

    Returns Promise<TLSNotaryToken>

    Token information or null if not found

    const token = await service.getTokenByTxHash(txHash);
    
  • Request an attestation token for a target URL

    This submits a TLSN_REQUEST native transaction that burns 1 DEM and returns a token ID with a proxy URL for performing the attestation.

    Parameters

    Returns Promise<AttestationTokenResponse>

    Attestation token response with proxyUrl and tokenId

    const { proxyUrl, tokenId } = await service.requestAttestation({
    targetUrl: 'https://api.coingecko.com/api/v3/simple/price'
    });
  • Request an attestation token with user confirmation before broadcasting

    This method shows the transaction details to the user via the onConfirm callback and only broadcasts if the user confirms. This is the recommended way to request attestation tokens in user-facing applications.

    Parameters

    Returns Promise<AttestationTokenResponse>

    Attestation token response with proxyUrl and tokenId

    Error if user rejects the transaction

    const { proxyUrl, tokenId } = await service.requestAttestationWithConfirmation(
    { targetUrl: 'https://api.github.com/users/octocat' },
    {
    onConfirm: async (details) => {
    // Show confirmation dialog to user
    return await showConfirmDialog({
    title: 'Confirm Attestation Request',
    message: `This will burn ${details.amount} DEM to request attestation for ${details.targetUrl}`,
    txHash: details.txHash,
    });
    }
    }
    );
  • Store a TLSNotary proof on-chain or IPFS

    This submits a TLSN_STORE native transaction that burns:

    • 1 DEM base fee
    • 1 DEM per KB of proof data

    Parameters

    • tokenId: string

      The attestation token ID

    • proof: string

      The proof data (JSON string or serialized presentation)

    • options: StoreProofOptions

      Storage options (on-chain or IPFS)

    Returns Promise<StoreProofResponse>

    Storage response with transaction hash and fee

    const { txHash, storageFee } = await service.storeProof(
    tokenId,
    JSON.stringify(presentation),
    { storage: 'onchain' }
    );
    console.log(`Proof stored! Fee: ${storageFee} DEM`);
  • Store a TLSNotary proof on-chain or IPFS with user confirmation

    This method shows the transaction details to the user via the onConfirm callback and only broadcasts if the user confirms. This is the recommended way to store proofs in user-facing applications.

    Parameters

    • tokenId: string

      The attestation token ID

    • proof: string

      The proof data (JSON string or serialized presentation)

    • options: StoreProofOptions

      Storage options (on-chain or IPFS)

    • confirmOptions: WithConfirmationOptions

      Options containing the confirmation callback

    Returns Promise<StoreProofResponse>

    Storage response with transaction hash and fee

    Error if user rejects the transaction

    const { txHash, storageFee } = await service.storeProofWithConfirmation(
    tokenId,
    JSON.stringify(presentation),
    { storage: 'onchain' },
    {
    onConfirm: async (details) => {
    // Show confirmation dialog to user
    return await showConfirmDialog({
    title: 'Confirm Proof Storage',
    message: `This will burn ${details.amount} DEM to store the proof on-chain`,
    txHash: details.txHash,
    });
    }
    }
    );