feat: enhance profile fetching and update mechanisms in ProtocolManager and MainScreen
This commit is contained in:
@@ -37,8 +37,10 @@ class CryptoManagerTest {
|
||||
val seedPhrase = CryptoManager.generateSeedPhrase()
|
||||
val keyPair = CryptoManager.generateKeyPairFromSeed(seedPhrase)
|
||||
|
||||
assertTrue("Public key should start with 04", keyPair.publicKey.startsWith("04"))
|
||||
assertTrue("Public key should be 130 chars (65 bytes hex)", keyPair.publicKey.length == 130)
|
||||
// Compressed public key: starts with "02" or "03", 66 hex chars (33 bytes)
|
||||
assertTrue("Public key should start with 02 or 03 (compressed)",
|
||||
keyPair.publicKey.startsWith("02") || keyPair.publicKey.startsWith("03"))
|
||||
assertEquals("Public key should be 66 chars (33 bytes hex, compressed)", 66, keyPair.publicKey.length)
|
||||
assertTrue("Private key should be 64 chars (32 bytes hex)", keyPair.privateKey.length == 64)
|
||||
}
|
||||
|
||||
@@ -190,5 +192,77 @@ class CryptoManagerTest {
|
||||
assertEquals("Same seed should produce same private key", privateKey1, privateKey2)
|
||||
assertTrue("Private key should be hex", privateKey1.all { it in '0'..'9' || it in 'a'..'f' })
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross-platform compatibility test.
|
||||
* These test vectors were generated using the Desktop (Electron) app's derivation:
|
||||
* 1. mnemonicToSeed(phrase) → BIP39 PBKDF2-SHA512 (2048 iterations) → 64 bytes
|
||||
* 2. hex(seed) → 128-char hex string
|
||||
* 3. SHA256(hexSeed) → 32-byte privateKey
|
||||
* 4. SHA256(privateKey + "rosetta") → privateKeyHash
|
||||
*
|
||||
* Mnemonic: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
||||
* Desktop equivalent (SetPassword.tsx):
|
||||
* let seed = await mnemonicToSeed(phrase);
|
||||
* let hex = Buffer.from(seed).toString('hex');
|
||||
* let keypair = await generateKeyPairFromSeed(hex);
|
||||
*/
|
||||
@Test
|
||||
fun `seedPhraseToPrivateKey should match Desktop derivation`() {
|
||||
val seedPhrase = listOf("abandon", "abandon", "abandon", "abandon", "abandon",
|
||||
"abandon", "abandon", "abandon", "abandon", "abandon",
|
||||
"abandon", "about")
|
||||
|
||||
val expectedPrivateKey = "0f57707d9198b6dc74195e972fa4fa214a2986a8bdfea7abf952e86f57715a31"
|
||||
val privateKey = CryptoManager.seedPhraseToPrivateKey(seedPhrase)
|
||||
|
||||
assertEquals(
|
||||
"Private key must match Desktop's BIP39 → hex → SHA256 derivation",
|
||||
expectedPrivateKey,
|
||||
privateKey
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `generatePrivateKeyHash should match Desktop derivation`() {
|
||||
// privateKey derived from "abandon...about" seed via BIP39 → SHA256
|
||||
val privateKey = "0f57707d9198b6dc74195e972fa4fa214a2986a8bdfea7abf952e86f57715a31"
|
||||
val expectedHash = "4e218a657b3a993f9f1dfcb18ecf39e2f322e89ddd9f98648b64142b376d910b"
|
||||
|
||||
val hash = CryptoManager.generatePrivateKeyHash(privateKey)
|
||||
|
||||
assertEquals(
|
||||
"Private key hash must match Desktop's SHA256(privateKey + 'rosetta')",
|
||||
expectedHash,
|
||||
hash
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `full key derivation flow should produce Desktop-compatible keys`() {
|
||||
val seedPhrase = listOf("abandon", "abandon", "abandon", "abandon", "abandon",
|
||||
"abandon", "abandon", "abandon", "abandon", "abandon",
|
||||
"abandon", "about")
|
||||
|
||||
val keyPair = CryptoManager.generateKeyPairFromSeed(seedPhrase)
|
||||
|
||||
// Verify privateKey matches Desktop
|
||||
assertEquals(
|
||||
"0f57707d9198b6dc74195e972fa4fa214a2986a8bdfea7abf952e86f57715a31",
|
||||
keyPair.privateKey
|
||||
)
|
||||
|
||||
// Verify compressed public key format (02 or 03 prefix, 66 hex chars)
|
||||
assertTrue("Public key should be compressed (66 hex chars)", keyPair.publicKey.length == 66)
|
||||
assertTrue("Public key should start with 02 or 03",
|
||||
keyPair.publicKey.startsWith("02") || keyPair.publicKey.startsWith("03"))
|
||||
|
||||
// Verify privateKeyHash matches Desktop
|
||||
val hash = CryptoManager.generatePrivateKeyHash(keyPair.privateKey)
|
||||
assertEquals(
|
||||
"4e218a657b3a993f9f1dfcb18ecf39e2f322e89ddd9f98648b64142b376d910b",
|
||||
hash
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user