Certification Module

The certification module provides the standalone Certifier class for issuing BSV MasterCertificate credentials, plus wallet methods for acquiring, listing, and revoking certificates.

Source: src/modules/certification.ts

Certifier Class

Certifier.create()

static async create(config?: {
  privateKey?: string
  certificateType?: string
  defaultFields?: Record<string, string>
  includeTimestamp?: boolean
}): Promise<Certifier>

Create a new certifier instance.

Parameter
Type
Default
Description

config.privateKey

string

random

Hex-encoded private key

config.certificateType

string

base64('certification')

Certificate type identifier

config.defaultFields

Record<string, string>

{ certified: 'true' }

Fields included in every certificate

config.includeTimestamp

boolean

true

Add timestamp field automatically

Example:

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

// Random key (ephemeral certifier)
const certifier = await Certifier.create()

// Persistent certifier with specific key
const certifier = await Certifier.create({
  privateKey: 'a1b2c3d4...',
  certificateType: Utils.toBase64(Utils.toArray('my-cert-type', 'utf8')),
  defaultFields: { role: 'admin', organization: 'ACME' },
  includeTimestamp: true
})

certifier.getInfo()

Returns the certifier's public key and certificate type.

certifier.certify()

Issue a certificate to a wallet and acquire it into that wallet in one step.

Parameter
Type
Required
Description

wallet

WalletCore

Yes

The wallet to certify

additionalFields

Record<string, string>

No

Extra fields beyond defaults

Returns: CertificateData

What happens:

  1. Merges defaultFields + additionalFields + optional timestamp

  2. Issues a MasterCertificate via MasterCertificate.issueCertificateForSubject()

  3. Calls wallet.getClient().acquireCertificate() to store it in the wallet

  4. Returns the full certificate data

Wallet Methods

acquireCertificateFrom()

Acquire a certificate from a remote certification server.

Parameter
Type
Default
Description

config.serverUrl

string

required

Base URL of the certification server

config.replaceExisting

boolean

true

Revoke existing certificates from this certifier first

What happens:

  1. Fetches {serverUrl}/api/info to get certifierPublicKey and certificateType

  2. If replaceExisting, lists and relinquishes existing certs from this certifier

  3. POSTs to {serverUrl}/api/certify with the wallet's identity key

  4. Acquires the returned certificate into the wallet

Server API contract:

  • GET /api/info returns { certifierPublicKey: string, certificateType: string }

  • POST /api/certify accepts { identityKey: string }, returns CertificateData

listCertificatesFrom()

List certificates from specific certifiers.

Parameter
Type
Default
Description

config.certifiers

string[]

required

Array of certifier public keys

config.types

string[]

required

Array of certificate type strings

config.limit

number

100

Maximum results

relinquishCert()

Revoke/relinquish a certificate from the wallet.

Parameter
Type
Description

args.type

string

Certificate type

args.serialNumber

string

Certificate serial number

args.certifier

string

Certifier's public key

Last updated