Verifiable Credentials

@bsv/simple supports W3C Verifiable Credentials backed by BSV MasterCertificate cryptography. Credentials can be issued, verified, and revoked on-chain.

Overview

Component
Role

CredentialSchema

Defines the fields, validation, and computed values for a credential type

CredentialIssuer

Issues, verifies, and revokes credentials

MemoryRevocationStore

Stores revocation secrets in memory (browser/tests)

FileRevocationStore

Stores revocation secrets on disk (server only)

toVerifiableCredential()

Wraps a BSV certificate into W3C VC format

toVerifiablePresentation()

Wraps VCs into a W3C VP

Defining a Schema

import { CredentialSchema } from '@bsv/simple/browser'

const schema = new CredentialSchema({
  id: 'employee-badge',
  name: 'EmployeeBadge',
  description: 'Company employee verification',
  fields: [
    { key: 'name', label: 'Full Name', type: 'text', required: true },
    { key: 'email', label: 'Email', type: 'email', required: true },
    { key: 'department', label: 'Department', type: 'select', options: [
      { value: 'engineering', label: 'Engineering' },
      { value: 'design', label: 'Design' },
      { value: 'sales', label: 'Sales' }
    ]},
    { key: 'startDate', label: 'Start Date', type: 'date' }
  ],
  validate: (values) => {
    if (!values.email?.includes('@')) return 'Invalid email'
    return null
  },
  computedFields: (values) => ({
    ...values,
    issuedAt: new Date().toISOString(),
    verified: 'true'
  })
})

Schema Methods

Field Types

Type
Description

text

Free-form text

email

Email address

date

Date string

number

Numeric value

textarea

Multi-line text

checkbox

Boolean flag

select

Dropdown with predefined options

Creating an Issuer

Issuer Configuration

Parameter
Type
Required
Description

privateKey

string

Yes

Hex-encoded private key

schemas

CredentialSchemaConfig[]

No

Schema definitions

revocation.enabled

boolean

No

Enable on-chain revocation

revocation.wallet

WalletInterface

If enabled

Wallet for creating revocation UTXOs

revocation.store

RevocationStore

No

Custom store (default: MemoryRevocationStore)

Issuing a Credential

What Happens During Issuance

  1. Fields are validated against the schema

  2. Computed fields are merged in

  3. If revocation is enabled:

    • A random 32-byte secret is generated

    • The SHA-256 hash of the secret creates a hash-lock script: OP_SHA256 <hash> OP_EQUAL

    • A 1-satoshi UTXO is created with this script

    • The secret is saved to the revocation store

  4. A MasterCertificate is issued using the BSV SDK

  5. The certificate is wrapped in a W3C Verifiable Credential envelope

Verifiable Credential Structure

Verifying a Credential

Verification checks:

  1. W3C @context is present

  2. VerifiableCredential type is present

  3. Proof and signature are present

  4. BSV certificate data is present

  5. Revocation status (if applicable)

Revoking a Credential

Revocation spends the hash-lock UTXO by revealing the secret. Once spent, the credential is permanently revoked on-chain.

Wallet-Side: Acquiring Credentials

Wallets acquire credentials from remote issuers:

List Credentials

Create a Presentation

Bundle credentials for sharing:

Server-Side Revocation Store

For production servers, use FileRevocationStore to persist secrets to disk:

Important: Add .revocation-secrets.json to .gitignore. These secrets control credential revocation.

Complete Example

Last updated