At

 view release on metacpan or  search on metacpan

lib/At/Protocol/DID.pm  view on Meta::CPAN


        #~ simple regex to enforce most constraints via just regex and length.
        #~ hand wrote this regex based on above constraints
        throw InvalidDidError(q[DID didn't validate via regex])        if $did !~ /^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/;
        throw InvalidDidError('DID is too long (2048 characters max)') if length $did > 2 * 1024;
        #
        1;
    }

    # fatal error
    register 'InvalidDidError', 1;
};
1;
__END__
=encoding utf-8

=head1 NAME

At::Protocol::DID - AT Protocol DID Validation

=head1 SYNOPSIS

    use At::Protocol::DID qw[:all];
    try {
        ensureValidDid( 'did:method:val' );
    }
    catch($err) {
        ...; # do something about it
    }

=head1 DESCRIPTION

The AT Protocol uses L<Decentralized Identifiers|https://en.wikipedia.org/wiki/Decentralized_identifier> (DIDs) as
persistent, long-term account identifiers. DID is a W3C standard, with many standardized and proposed DID method
implementations.

This package aims to validate them.

=head1 Functions

You may import functions by name or with the C<:all> tag.

=head2 C<new( ... )>

Verifies a DID and creates a new object containing it.

    my $handle = At::Protocol::DID->new( 'did:web:blueskyweb.xyz' );

On success, an object is returned that will stringify to the DID itself.

=head2 C<ensureValidDid( ... )>

    ensureValidDid( 'did:plc:z72i7hdynmk6r22z27h6tvur' );

Validates a DID. Throws errors on failure and returns a true value on success.

=head2 C<ensureValidDidRegex( ... )>

    ensureValidDidRegex( 'did:method::nope' );

Validates a DID with cursory regex provided by the AT protocol designers. Throws errors on failure and returns a true
value on success.

=head1 See Also

L<https://atproto.com/specs/did>

=head1 LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License
2. Other copyrights, terms, and conditions may apply to data transmitted through this module.

=head1 AUTHOR

Sanko Robinson E<lt>sanko@cpan.orgE<gt>

=begin stopwords

atproto

=end stopwords

=cut



( run in 0.721 second using v1.01-cache-2.11-cpan-39bf76dae61 )