Digi-ID implementation in Perl5


Perl5 implementation of [Digi-ID](

Digi-ID Open Authentication Protocol

Pure DigiByte sites and applications shouldn't have to rely on artificial identification methods such as usernames and passwords. Digi-ID is an open authentication protocol allowing simple and secure authentication using public-key cryptography.

Classical password authentication is an insecure process that could be solved with public key cryptography. The problem however is that it theoretically offloads a lot of complexity and responsibility on the user. Managing private keys securely is complex. However this complexity is already addressed in the DigiByte ecosystem. So doing public key authentication is practically a free lunch to DigiByte users.

The protocol is based on the following BIP draft


 use Dancer2;
 use DigiByte::DigiID qw(get_qrcode extract_nonce verify_signature);

 get '/login' => sub {
     template 'login' => {
         qrcode => {get_qrcode(request->host)},

 get '/callback' => sub {
    my $credential = from_json do { 
        my $input = request->env->{'psgi.input'};
        local $/; <$input>;
    } or halt "credential not found";

    my $nonce = extract_nonce($credential->{uri})
        or do { 
            status 403; 
            return "Nonce is missing";

    eval { verify_signature(@$credential{qw(address signature uri)}) }
        or do { 
            return "Invalid credential, $@";

    my $db = DB->schema; ## using dbix-lite for example

    my $user = $db->table('digiid_users')
        ->find({digiid => $credential->{address}})
        or do {
            return "digiid is not found: $credential->{address}";

    $db->transaction(sub {
            nonce      => $nonce,
            digiid     => $user->id,
            created_at => \'NOW()',

    return 'OK';

 get '/ajax' => sub {
    content_type 'application/json';

    my $nonce = params->{nonce}
        or return to_json {ok => 0, error => 'missing nonce'};

    my $db = DB->schema; ## using dbix-lite for example

    my $session = $db->table('digiid_sessions')
        ->find({nonce => $nonce})
            or return to_json {ok => 0};

    my $user = $session->get_digiid_users->get_user
        or return to_json {ok => 0, next => 'scan to login in digibyte wallet'};


        return to_json {ok => 1};


Demo (Has a custom interface on top)


* Pure Perl5 implementation, no need to run a DigiByte node


Direct Translation from PHP to Perl5 -


Git Repo:

CPAN Module: