mirror of
https://github.com/kccleoc/seedpgp-web.git
synced 2026-03-07 09:57:50 +08:00
feat: seedpgp v1.1.0 - BIP39 mnemonic PGP encryption tool
- Implement cv25519 PGP encryption/decryption - Add Base45 encoding with CRC16 integrity checks - Create SEEDPGP1 frame format for QR codes - Support BIP39 passphrase flag indicator - Add comprehensive test suite with Trezor BIP39 vectors - 15 passing tests covering all core functionality
This commit is contained in:
24
src/lib/bip39.ts
Normal file
24
src/lib/bip39.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Prototype-level BIP39 validation:
|
||||
// - enforces allowed word counts
|
||||
// - normalizes whitespace/case
|
||||
// NOTE: checksum + wordlist membership verification is intentionally omitted here.
|
||||
|
||||
export function normalizeBip39Mnemonic(words: string): string {
|
||||
return words.trim().toLowerCase().replace(/\s+/g, " ");
|
||||
}
|
||||
|
||||
export function validateBip39Mnemonic(words: string): { valid: boolean; error?: string } {
|
||||
const normalized = normalizeBip39Mnemonic(words);
|
||||
const arr = normalized.length ? normalized.split(" ") : [];
|
||||
|
||||
const validCounts = new Set([12, 15, 18, 21, 24]);
|
||||
if (!validCounts.has(arr.length)) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Invalid word count: ${arr.length}. Must be 12, 15, 18, 21, or 24.`,
|
||||
};
|
||||
}
|
||||
|
||||
// In production: verify each word is in the selected wordlist + verify checksum.
|
||||
return { valid: true };
|
||||
}
|
||||
Reference in New Issue
Block a user