yuzushioh / EthereumKit

EthereumKit is a free, open-source Swift framework for easily interacting with the Ethereum.
Apache License 2.0
476 stars 100 forks source link

HDWallet.privateKey().raw returns 31 byte key instead of 32-byte #168

Open DmitryBespalov opened 5 years ago

DmitryBespalov commented 5 years ago

This code returns private key data with a length of 31 byte, which is not correct. The data doesn't have leading zero byte.

        let mnemonic = "half try deer tray hockey ball notable abstract affair main desert session"
        let seed = Mnemonic.createSeed(mnemonic: mnemonic)
        let hdWallet = HDWallet(seed: seed, network: Network.private(chainID: 0, testUse: false))
        let privateKey = try! hdWallet.privateKey(at: 1).raw

The expected private key is 0x007179e85007a04d2a9cae63be80326aa2c218f75394b7d37ccd1b660c8b180d but the actual is 0x7179e85007a04d2a9cae63be80326aa2c218f75394b7d37ccd1b660c8b180d .

sachin-chauhan-dev commented 5 years ago

Facing similar issue. Web3j creates complete 32 byte private key with zero padding with the same mnemonics but EthereumKit doesn't. Because of this invalid signatures are getting created.