is_valid_did_method_webvh

Function is_valid_did_method_webvh 

Source
pub fn is_valid_did_method_webvh(did: &str, strict: bool) -> bool
Expand description

Validates if a string is a properly formatted WebVH DID.

A WebVH DID extends the Web DID format by adding a SCIM (Self-Controlled Identity Marker) segment immediately after the did:webvh: prefix.

§Format

did:webvh:<scim>:<content>

Where:

  • <scim> must contain only base58-btc alphabet characters (123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz)
  • <content> follows the same validation rules as did:web content

§Strict vs Non-Strict Mode

Strict Mode (strict = true):

  • <content> must be a valid hostname only
  • No additional path segments permitted

Non-Strict Mode (strict = false):

  • First segment of <content> must be a valid hostname
  • Additional colon-separated segments are allowed
  • Each additional segment must be non-empty and alphanumeric

§Arguments

  • did - The DID string to validate
  • strict - Whether to use strict hostname-only validation for the content portion

§Returns

true if the DID is a valid WebVH DID according to the specified mode, false otherwise

§Examples

use atproto_identity::validation::is_valid_did_method_webvh;

// Valid WebVH DIDs in both modes
assert!(is_valid_did_method_webvh("did:webvh:abc123:example.com", true));
assert!(is_valid_did_method_webvh("did:webvh:XYZ789:sub.example.com", false));

// Valid only in non-strict mode (has path segments)
assert!(!is_valid_did_method_webvh("did:webvh:abc123:example.com:path", true));
assert!(is_valid_did_method_webvh("did:webvh:abc123:example.com:path", false));
assert!(is_valid_did_method_webvh("did:webvh:def456:example.com:path:subpath", false));

// Invalid - SCIM contains excluded base58 characters (0, O, I, l)
assert!(!is_valid_did_method_webvh("did:webvh:0abc:example.com", true));
assert!(!is_valid_did_method_webvh("did:webvh:Oabc:example.com", false));
assert!(!is_valid_did_method_webvh("did:webvh:Iabc:example.com", true));
assert!(!is_valid_did_method_webvh("did:webvh:labc:example.com", false));

// Invalid - wrong format or missing components
assert!(!is_valid_did_method_webvh("did:web:abc123:example.com", true)); // Wrong prefix
assert!(!is_valid_did_method_webvh("did:webvh:abc123", true)); // Missing content
assert!(!is_valid_did_method_webvh("did:webvh::example.com", true)); // Empty SCIM