Create one — it takes one more signature.', 'sirius-press' ), esc_url( SPA_Register::url() ) ) ); } return new WP_Error( 'sirius_no_account', __( 'No account on this site uses that wallet, and registration is closed.', 'sirius-press' ) ); } /** * Fires after a wallet signature has been accepted for a user. * * A plugin that wants a second factor can return a WP_Error from the * `authenticate` chain at a later priority; this is the hook that * tells it a wallet proof already succeeded. * * @param WP_User $found * @param string $address */ do_action( 'sirius_press_wallet_authenticated', $found, $address ); return $found; } // ------------------------------------------------------------------- UI public static function enqueue() { self::enqueue_wallet(); wp_enqueue_style( 'sirius-press-login', SIRIUS_PRESS_AUTH_URL . 'assets/login.css', array(), SIRIUS_PRESS_AUTH_VERSION ); } /** Shared by the login screen, the registration screen and the profile. */ public static function enqueue_wallet() { wp_enqueue_script( 'sirius-press-bip39', SIRIUS_PRESS_AUTH_URL . 'assets/bip39-en.js', array(), SIRIUS_PRESS_AUTH_VERSION, true ); wp_enqueue_script( 'sirius-press-wallet', SIRIUS_PRESS_AUTH_URL . 'assets/wallet.js', array( 'sirius-press-bip39' ), SIRIUS_PRESS_AUTH_VERSION, true ); wp_enqueue_script( 'sirius-press-login-js', SIRIUS_PRESS_AUTH_URL . 'assets/login.js', array( 'sirius-press-wallet' ), SIRIUS_PRESS_AUTH_VERSION, true ); } /** Configuration the scripts need, printed once. */ public static function footer_config() { self::print_config(); } public static function print_config() { static $printed = false; if ( $printed ) { return; } $printed = true; printf( '', wp_json_encode( array( 'prefix' => SP_Settings::prefix(), 'path' => SP_Settings::derivation_path(), 'network' => SP_Settings::network(), 'site' => home_url( '/' ), 'strings' => array( 'signing' => __( 'Signing…', 'sirius-press' ), 'noWallet' => __( 'No wallet found in this browser.', 'sirius-press' ), 'generated' => __( 'Write these words down. They are the only way back into this account — nobody, including this site, can reset them for you.', 'sirius-press' ), ), ) ) ); } /** * The wallet block on wp-login.php. * * Rendered by `login_form`, which puts it directly under the password * field, so the wallet path reads as the primary one and passwords as the * leftover they are. */ public static function render_form() { $nonce = SPA_Challenge::issue(); $message = SPA_Challenge::message( $nonce, SPA_Challenge::PURPOSE_LOGIN ); self::render_signing_block( $nonce, $message, SPA_Challenge::PURPOSE_LOGIN, __( 'Sign in with your wallet', 'sirius-press' ) ); } /** * The signing widget, shared by login and registration. * * @param string $nonce * @param string $message Exact text to be signed. * @param string $purpose * @param string $button Label for the primary action. */ public static function render_signing_block( $nonce, $message, $purpose, $button ) { ?>

' . esc_html__( 'This site has no passwords to forget and no email to confirm. Your wallet is the account.', 'sirius-press' ) . '

'; return $intro . $message; } /** * Visually retire the password field when passwords are off. * * The submit button stays. It is what the paste-a-signature path — the one * for people whose keys are on another machine — uses to send the form, * and hiding it would leave that path with no way to submit at all. */ public static function hide_password_fields() { echo ''; } }