ZKIdentity class for privacy-preserving identity attestations

// Create identity
const identity = new ZKIdentity('github:12345')

// Get commitment (safe to share publicly)
const commitment = identity.getCommitment()

// Create commitment transaction
const commitmentTx = await identity.createCommitmentTransaction('http://localhost:3000')

// Later: Create anonymous attestation
const attestationTx = await identity.createAttestationTransaction(
'http://localhost:3000',
'dao_vote_123'
)

Constructors

  • Create a new ZK identity

    Parameters

    • providerId: string

      Provider identifier (e.g., "github:12345", "discord:67890")

    • Optionalsecret: string

      Optional secret (will be generated if not provided)

      WARNING: Keep the secret secure! Store it encrypted in local storage. If lost, you cannot create attestations for this commitment.

    Returns ZKIdentity

Methods

  • Create an anonymous attestation transaction

    This proves you have a valid identity commitment in the Merkle tree without revealing which one. Uses ZK-SNARKs for privacy.

    Parameters

    • rpcUrl: string

      Node RPC URL

    • context: string

      Context string for this attestation (e.g., "dao_vote_123")

    Returns Promise<IdentityAttestationPayload>

    Attestation transaction payload

    NOTE: Each context can only be used once per identity (nullifier prevents reuse)

  • Export identity for backup

    Returns {
        providerId: string;
        secret: string;
    }

    Object containing provider ID and secret

    WARNING: Store this securely! Anyone with this data can create attestations as you.

    • providerId: string
    • secret: string
  • Get the identity commitment hash

    This is safe to share publicly and will be stored in the Merkle tree.

    Returns string

    Commitment hash as string