DidMethodUtils

Common utilities for DID method implementations.

Provides helper functions for:

  • DID parsing and validation

  • Verification method type mapping (algorithm → verification method type)

  • DID document builder helpers

  • Resolution metadata helpers

Functions

Link copied to clipboard

Maps a cryptographic algorithm to its verification method type.

Maps a KeyAlgorithm enum to its verification method type.

Link copied to clipboard
fun buildDidDocument(did: String, verificationMethod: List<VerificationMethod>, authentication: List<String>? = null, assertionMethod: List<String>? = null, keyAgreement: List<String>? = null, service: List<DidService>? = null): DidDocument

Builds a DID document with standard structure.

Link copied to clipboard
fun buildWebDid(domain: String, path: String? = null): String

Builds a did:web identifier from a domain.

Link copied to clipboard

Compresses an EC public key point to SEC1 compressed form (0x02/0x03 || x), as required by the multicodec table for secp256k1-pub, p256-pub, p384-pub and p521-pub.

Link copied to clipboard
fun createErrorResolutionResult(error: String, message: String? = null, method: String? = null, did: String? = null): DidResolutionResult

Creates an error DID resolution result.

Link copied to clipboard
fun createSuccessResolutionResult(document: DidDocument, method: String, created: Instant? = null, updated: Instant? = null, deactivated: Boolean = false, retrieved: Instant? = null): DidResolutionResult

Creates a DID resolution result for a document found on the method's backing store.

Link copied to clipboard
fun createVerificationMethod(did: String, keyHandle: KeyHandle, algorithm: String, controller: String? = null): VerificationMethod

Creates a verification method reference from a key handle.

fun createVerificationMethod(did: String, keyHandle: KeyHandle, algorithm: KeyAlgorithm, controller: String? = null): VerificationMethod

Creates a verification method reference from a key handle using KeyAlgorithm enum.

Link copied to clipboard

Decompresses an EC public key point to SEC1 uncompressed form (0x04 || x || y).

Link copied to clipboard
fun ecCoordinateSize(algorithm: String): Int?

Returns the field-element (coordinate) size in bytes for algorithm, or null if it is not a supported short-Weierstrass EC algorithm.

Link copied to clipboard

Returns the 2-byte multicodec prefix for algorithm.

Link copied to clipboard

Normalizes a domain name for did:web.

Link copied to clipboard

Parses a DID string into method and identifier parts.

Link copied to clipboard

Parses a multicodec-prefixed byte array and returns a (algorithm, publicKeyBytes) pair.

Link copied to clipboard
fun percentDecode(segment: String): String

Percent-decodes a single did:web method-specific-id segment (RFC 3986 §2.1).

Link copied to clipboard
fun validateDidMethod(did: String, expectedMethod: String)

Validates that a DID matches a specific method.