Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Incorrect PublicKey and Address for Bitcoin #18

Closed
Ikloo opened this issue Aug 1, 2018 · 6 comments
Closed

Incorrect PublicKey and Address for Bitcoin #18

Ikloo opened this issue Aug 1, 2018 · 6 comments
Assignees

Comments

@Ikloo
Copy link

Ikloo commented Aug 1, 2018

Hello!
I try to create HDWallet with private and public keys

Code I use:

// blockchainCoin is .bitcoin
wallet = TrustCore.HDWallet(mnemonic: mnemonic)
privateKey = wallet.getKey(at: coin.blockchainCoin.derivationPath(at: 0))
publicKey = privateKey.publicKey(for: coin.blockchainCoin.blockchain.type)

But publicKey.address.description return incorrect address, I researched with other services for validating that and came to the conclusion that publicKey is incorrect.

Check please publicKey data generation. I think the problem is somewhere at data compression (33 bytes or 65 bytes length)

If change method at file Crypto.m all works as expected for BTC, but incorrect for ETH:
(Use 33 bytes length instead 65 and ecdsa_get_public_key33 instead ecdsa_get_public_key65)

+ (nonnull NSData *)getPublicKeyFrom:(nonnull NSData *)privateKey {
    NSMutableData *publicKey = [[NSMutableData alloc] initWithLength:33];
    ecdsa_get_public_key33(&secp256k1, privateKey.bytes, publicKey.mutableBytes);
    return publicKey;
}

Please fix this or add examples of correct library work(ex. wallet creation and etc.). Maybe I make something incorrect.
Thank!

@vikmeup
Copy link
Contributor

vikmeup commented Aug 1, 2018

@Ikloo can you message me on telegram: @vikmeup

@alejandro-isaza
Copy link
Contributor

Hey @Ikloo thanks for reporting. Fixing.

@Ikloo
Copy link
Author

Ikloo commented Aug 5, 2018

@alejandro-isaza awesome, thank you!

@Ikloo
Copy link
Author

Ikloo commented Aug 5, 2018

@alejandro-isaza but isValid(data: Data) -> Bool func from PrivateKey start works incorrect:

public final class PrivateKey: Hashable, CustomStringConvertible {
    /// Validates that raw data is a valid private key.
    static public func isValid(data: Data) -> Bool {
        // Check length
        if data.count != Ethereum.privateKeySize {
            return false
        }

        // Check for zero address
        guard data.contains(where: { $0 != 0 }) else {
            return false
        }

        return true
    }

Problem there: if data.count != Ethereum.privateKeySize 😞

@alejandro-isaza
Copy link
Contributor

Private key is always 32 bytes. How are you running into this problem?

@Ikloo
Copy link
Author

Ikloo commented Aug 5, 2018

@alejandro-isaza Sorry, I misunderstood this logic. 😅
All work as expected! Thank you! 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants