TLSNotary class for browser-based HTTPS attestation

This class handles:

  • Running the Prover (MPC-TLS client) in the browser via WASM
  • Communicating with the Demos Node's Notary server
  • Attesting HTTPS requests with cryptographic proofs
  • Verifying attestations offline

Constructors

Methods

  • Attest an HTTPS request using the step-by-step method

    This provides full control over the attestation process including custom commit ranges for selective disclosure.

    Parameters

    • request: AttestRequest

      Request configuration (URL, method, headers, body)

    • Optionalcommit: CommitRanges

      Optional commit ranges for selective disclosure

    • OptionalonStatus: StatusCallback

      Optional status callback for progress updates

    Returns Promise<AttestResult>

    Attestation result with proof and verification

    const result = await tlsn.attest({
    url: 'https://api.example.com/user',
    method: 'GET',
    headers: { 'Authorization': 'Bearer token' },
    }, {
    // Hide authorization header in the proof
    sent: [{ start: 0, end: 50 }, { start: 100, end: 200 }],
    recv: [{ start: 0, end: 500 }],
    });
  • Quick attestation using the helper method

    Simpler API with less control over the process. Good for straightforward use cases.

    Parameters

    • options: AttestOptions

      Attestation options including request and commit config

    Returns Promise<AttestResult>

    Attestation result with proof and verification

    const result = await tlsn.attestQuick({
    url: 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd',
    });
  • Get the transcript from an attestation for inspection

    Useful for determining commit ranges for selective disclosure.

    Parameters

    • request: AttestRequest

      Request to send (without creating attestation)

    Returns Promise<TranscriptInfo>

    Transcript with sent and received bytes

  • Initialize the WASM module

    Must be called before any attestation operations. Only needs to be called once per page load.

    Returns Promise<void>

    Error if WASM initialization fails

  • Update configuration

    Note: Changes take effect on next attestation. If changing notary URL, you may want to re-initialize.

    Parameters

    Returns void

  • Verify a presentation/proof

    Can be used to verify proofs from other sources. This operation can be done offline.

    Parameters

    • presentationJSON: PresentationJSON

      The presentation to verify

    Returns Promise<VerificationResult>

    Verification result with extracted data

    // Load a saved proof
    const savedProof = JSON.parse(localStorage.getItem('proof'));
    const result = await tlsn.verify(savedProof);

    console.log('Server:', result.serverName);
    console.log('Time:', new Date(result.time * 1000));
    console.log('Response:', result.recv);