<?php
/**
 * Rootz AI Discovery — Vendor Autoloader.
 *
 * PSR-4 autoloader for bundled crypto libraries.
 * These are shipped with the plugin so no Composer is needed in production.
 *
 * Packages:
 *   simplito/elliptic-php  v1.0.9  — secp256k1 ECDSA
 *   simplito/bn-php        v1.1.4  — Big number arithmetic
 *   simplito/bigint-wrapper v1.0.0 — GMP/bcmath wrapper
 *   kornrunner/keccak      v1.1.0  — Keccak-256 hashing
 */

spl_autoload_register( function ( $class ) {
    // Namespace → directory mappings (PSR-4).
    $map = array(
        'Elliptic\\'    => __DIR__ . '/simplito/elliptic-php/lib/',
        'BN\\'          => __DIR__ . '/simplito/bn-php/lib/',
        'BI\\'          => __DIR__ . '/simplito/bigint-wrapper-php/lib/',
        'kornrunner\\'  => __DIR__ . '/kornrunner/keccak/src/',
    );

    foreach ( $map as $prefix => $base_dir ) {
        $len = strlen( $prefix );
        if ( strncmp( $prefix, $class, $len ) !== 0 ) {
            continue;
        }

        $relative_class = substr( $class, $len );
        $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';

        if ( file_exists( $file ) ) {
            require_once $file;
            return;
        }
    }
} );
