diff --git a/sdk/src/androidTest/java/network/xyo/client/account/AccountTest.kt b/sdk/src/androidTest/java/network/xyo/client/account/AccountTest.kt index 998db91..f6deb88 100644 --- a/sdk/src/androidTest/java/network/xyo/client/account/AccountTest.kt +++ b/sdk/src/androidTest/java/network/xyo/client/account/AccountTest.kt @@ -25,7 +25,8 @@ class AccountTest { fun testRandomAccount() { val account = Account.random() assert(account.privateKey.count() == 32) - assert(account.publicKey.count() == 64) + assert(account.publicKey.count() == 33) + assert(account.publicKeyUncompressed.count() == 64) } @OptIn(ExperimentalStdlibApi::class) @@ -34,8 +35,9 @@ class AccountTest { runBlocking { val account = Account.fromPrivateKey(hexStringToByteArray(testVectorPrivateKey)) assert(account.privateKey.count() == 32) - assert(account.publicKey.count() == 64) - assert(account.publicKey.toHexString() == testVectorPublicKey) + assert(account.publicKey.count() == 33) + assert(account.publicKeyUncompressed.count() == 64) + assert(account.publicKeyUncompressed.toHexString() == testVectorPublicKey) assert(account.address.toHexString() == testVectorAddress) val signature = account.sign(hexStringToByteArray(testVectorHash)) assert(signature.toHexString() == testVectorSignature) @@ -51,7 +53,7 @@ class AccountTest { val account = Account.fromPrivateKey(address) account.sign(hexStringToByteArray(testVectorHash)) - val savedAddressInStore = Account.addressFromPublicKey(account.publicKey) + val savedAddressInStore = Account.addressFromUncompressedPublicKey(account.publicKeyUncompressed) val previousHashInStore = Account.previousHashStore?.getItem(savedAddressInStore)?.toHexString() assert(previousHashInStore == testVectorHash) } diff --git a/sdk/src/androidTest/java/network/xyo/client/account/WalletTest.kt b/sdk/src/androidTest/java/network/xyo/client/account/WalletTest.kt index a8317ec..5dc1bae 100644 --- a/sdk/src/androidTest/java/network/xyo/client/account/WalletTest.kt +++ b/sdk/src/androidTest/java/network/xyo/client/account/WalletTest.kt @@ -14,12 +14,4 @@ class WalletTest { Log.i("privateKey", wallet.privateKey.toHexString()) assert(wallet.privateKey.toHexString() == privateKeyVectors[1]) } - - @OptIn(ExperimentalStdlibApi::class) - @Test - fun testWalletWithoutPath() { - val wallet = Wallet.fromMnemonic(words) - Log.i("privateKey", wallet.privateKey.toHexString()) - assert(wallet.privateKey.toHexString() == privateKeyVectors[1]) - } } \ No newline at end of file diff --git a/sdk/src/main/java/network/xyo/client/account/Account.kt b/sdk/src/main/java/network/xyo/client/account/Account.kt index d6b811e..e5de77f 100644 --- a/sdk/src/main/java/network/xyo/client/account/Account.kt +++ b/sdk/src/main/java/network/xyo/client/account/Account.kt @@ -18,7 +18,7 @@ open class Account private constructor (private val _privateKey: PrivateKey, pri constructor(privateKey: ByteArray, previousHash: ByteArray? = null) : this(PrivateKey.fromBytes(privateKey, secp256k1Curve), previousHash) {} constructor(privateKey: BigInteger, previousHash: ByteArray? = null) : this(privateKey.toByteArray(), previousHash) {} - private val _address = addressFromPublicKey(publicKeyUncompressed) + private val _address = addressFromUncompressedPublicKey(publicKeyUncompressed) final override val address: ByteArray get() = _address @@ -60,7 +60,8 @@ open class Account private constructor (private val _privateKey: PrivateKey, pri return fromPrivateKey(generatePrivateKeyBytes()) } - fun addressFromPublicKey(key: ByteArray): ByteArray { + fun addressFromUncompressedPublicKey(key: ByteArray): ByteArray { + assert(key.size == 64, ) { "Invalid Key Length" } val publicKeyHash = toKeccak(key) return publicKeyHash.copyOfRange(12, publicKeyHash.size) } diff --git a/sdk/src/main/java/network/xyo/client/account/Wallet.kt b/sdk/src/main/java/network/xyo/client/account/Wallet.kt index 88f3eca..e295292 100644 --- a/sdk/src/main/java/network/xyo/client/account/Wallet.kt +++ b/sdk/src/main/java/network/xyo/client/account/Wallet.kt @@ -21,6 +21,8 @@ open class Wallet(private val _extKey: ExtKey, previousHash: ByteArray? = null): companion object: WalletStatic { + val defaultPath = "m/44'/60'/0'/0/0" + override var previousHashStore: PreviousHashStore? = null override fun fromExtendedKey(key: ExtKey): WalletInstance { @@ -34,7 +36,7 @@ open class Wallet(private val _extKey: ExtKey, previousHash: ByteArray? = null): override fun fromMnemonic(mnemonic: MnemonicWords, path: String?): WalletInstance { val root = fromSeed(mnemonic.toSeed("".toCharArray())) return if (path === null) { - root.derivePath("m/44'/0'/0'/0/0") + root.derivePath(defaultPath) } else { root.derivePath(path) }