furqansiddiqui/bip39-mnemonic-php
PHP implementation of BIP39 mnemonics for generating and validating seed phrases. Supports multiple wordlists/languages, entropy-to-mnemonic and mnemonic-to-seed conversion, checksum handling, and deterministic wallet seed derivation for crypto apps.
Use Case Alignment (Unchanged):
\SensitiveParameter support aligns with Laravel’s security best practices for handling sensitive inputs (e.g., entropy sources).Laravel Synergy (Updated):
SensitiveWhen trait (e.g., for masking mnemonics in logs).Statelessness (Unchanged):
Low Friction (Updated):
$mnemonic = new Mnemonic(
entropy: random_bytes(16),
passphrase: $request->passphrase,
);
debugbar).Laravel Service Provider (Updated):
#[Inject]
public Mnemonic $mnemonicGenerator;
Str::of() for safe string manipulation in validation.| Risk Area | Mitigation Strategy | Update |
|---|---|---|
| Seed Entropy Security | Validate input entropy and enforce BIP39 wordlist. | New: \SensitiveParameter ensures entropy sources are handled securely. |
| Side-Channel Attacks | Use random_bytes() or Laravel’s Str::random(). |
New: PHP 8.2’s random_int() is now preferred over mt_rand(). |
| Version Drift | Pin version in composer.json (e.g., ^0.2). |
New: Monitor for BIP39 standard updates and PHP 8.2 deprecations. |
| Performance | Benchmark generation/validation. | New: "Optimized" release may improve throughput; test under load. |
| Buffer Overflows | New Risk: "Charcoal buffers" may imply low-level optimizations. | Mitigation: Use Laravel’s Str::of() or PHP’s hash_equals() for comparisons. |
\SensitiveParameter? If so, ensure it’s not logged or exposed.\SensitiveParameter for secure serialization (e.g., encrypting mnemonics with SensitiveWhen).Throwable).create_function) in the package’s internals.PHP/Laravel (Updated):
SensitiveWhen for masking).Dependencies (Updated):
phpunit/phpunit (for included tests).symfony/sensitive-component (if extending \SensitiveParameter usage).random_compat (PHP 8.2 has native random_bytes()).Tooling (Updated):
public function __construct(
private string $entropy,
private ?string $passphrase = null,
) {}
#[ValidateMnemonic]
public function generateMnemonic(): string { ... }
Proof of Concept (PoC) (Updated):
$mnemonic = (new Mnemonic(entropy: random_bytes(16)))->generate();
assert($mnemonic instanceof string);
\SensitiveParameter works with Laravel’s SensitiveWhen:
use Symfony\Component\Security\Core\SensitiveWhen;
class MnemonicDto implements SensitiveWhen {
public function isSensitive(): bool { return true; }
}
Service Provider Integration (Updated):
autowire: true in config/services.php:
'bindings' => [
Mnemonic::class => fn() => new Mnemonic(entropy: random_bytes(32)),
],
#[Inject]:
#[Inject]
public Mnemonic $mnemonic;
public function generateSecureMnemonic(): string {
return $this->mnemonic->generate();
}
Sequencing (Updated):
\SensitiveParameter.SensitiveWhen (e.g., encrypt with Laravel\Sanctum).web3p/bip39.random_bytes() with random_int() where applicable.\SensitiveParameter for secure handling.each() in PHP 8.1).composer require --with-all-dependencies to pull in phpunit/phpunit.0.2.* in composer.json to avoid breaking changes.symfony/sensitive-component if extending \SensitiveParameter.create_function, call_user_func_array hacks).\SensitiveParameter usage for secure logging/masking.try {
$mnemonic = $this->mnemonic->recover($userInput);
} catch (InvalidArgumentException $e) {
report($e); // Use Laravel’s error reporting
return back()->withError("Invalid mnemonic");
}
Throwable for broader exception catching:
catch (Throwable
How can I help you explore Laravel packages today?