Git Product home page Git Product logo

Comments (6)

TBSMobile avatar TBSMobile commented on May 29, 2024 4

let me check first with the current library. Because in the current project, I have install pod.

Got the solution.
Thanks

from hdwallet.

impul avatar impul commented on May 29, 2024 2

Hi, @sazzadiproliya, thank you for your question.

Our library provides two ways for generating Litecoin(or Bitcoin, Ethereum and Bitcoin Classic) wallets:

  1. Simple way, use account generating
let mnemonic = Mnemonic.create()
let seed = Mnemonic.createSeed(mnemonic: mnemonic)
let wallet = Wallet(seed: seed, coin: .litecoin)
let firstAccount = wallet.generateAccount(at: 0) 
let secondAccount = wallet.generateAccount(at: 1) 

It equal "m/44'/2'/0'/0/0" and "m/44'/2'/0'/0/1".
Account have all required fields for creating transaction: private key, public key, address and raw private key.

  1. Second way it is creating HD path manually:
let mnemonic = Mnemonic.create()
let seed = Mnemonic.createSeed(mnemonic: mnemonic)
let privateKey = PrivateKey(seed: seed, coin: . litecoin)
// BIP39 key derivation
// m/44'
let purpose = privateKey.derived(at: .hardened(44))      
// m/44'/2'
let coinType = purpose.derived(at: .hardened(2))
// m/44'/2'/0'
let account = coinType.derived(at: .hardened(0))
// m/44'/2'/0'/0
let change = account.derived(at: .notHardened(0))
// m/44'/2'/0'/0/0
let firstPrivateKey = change.derived(at: .notHardened(0))

Now you can get same to first way information:

let address = firstPrivateKey.publicKey.address
let privateKey = firstPrivateKey.get()
let publicKey = firstPrivateKey.publicKey.get()

These two methods give the same result.
Maybe, you have not specified "Hardened" or "Non-hardened" HD nodes? This functionality is implemented in DerivationNode component.

If something is not clear please ask.

from hdwallet.

impul avatar impul commented on May 29, 2024 2

@sazzadiproliya I checked your mnemonic and got the same result in HDWallet and Coleman.

let mnemonic = "fly weasel genuine enact humor catch prison upper spatial sure mechanic excess hint lazy uphold need violin sport also certain cannon spread include float"
let seed = Mnemonic.createSeed(mnemonic: mnemonic)
let privateKey = PrivateKey(seed: seed, coin: .litecoin)
// BIP44 key derivation
// m/44'
let purpose = privateKey.derived(at: .hardened(44))
// m/44'/2'
let coinType = purpose.derived(at: .hardened(2))
// m/44'/2'/0'
let account = coinType.derived(at: .hardened(0))
// m/44'/2'/0'/0
let change = account.derived(at: .notHardened(0))
// m/44'/2'/0'/0/0
let firstPrivateKey = change.derived(at: .notHardened(0))

let pk = firstPrivateKey.get()
//T4UWHcDKz5hpqbiCwFCoD8ikjZEKxtH1MVHHvSUfbgRjR3WR6JFU
let publicKey = firstPrivateKey.publicKey.get()
//02ddf59d9deb77616c77c8f4c024e0e5137c92c3ad43dd39ad71c8f1e04574110e
let address = firstPrivateKey.publicKey.address
//LXbmmJEuwYrFN21vLGwFkaYz5zeDEDanGv

Also I attached screenshots of Coleman:
screenshot 2018-12-11 at 11 18 55 am
screenshot 2018-12-11 at 11 18 48 am

from hdwallet.

TBSMobile avatar TBSMobile commented on May 29, 2024

Yes, you are true. But my question is that public key and address generate same as "https://iancoleman.io/bip39".

But private key generated from HDwallet and Coleman website both are different.

In HD Wallet:

Path: m/44'/2'/0'/0/0
Mainnet ChildKey0: LXbmmJEuwYrFN21vLGwFkaYz5zeDEDanGv
Mainnet PrivateKey0: KxeEqrv9ahjE4m5LPcFvznBNnhb1toG7YHP34dr82iFZu9taYuP7
Mainnet PublicKey0: 02ddf59d9deb77616c77c8f4c024e0e5137c92c3ad43dd39ad71c8f1e04574110e

Path: m/44'/2'/0'/0/1
Mainnet ChildKey1: LPfb4Rm9WJNQac1WSFwFLN4FkQGY3wecBy
Mainnet PrivateKey1: L1mav5PTxHgW2jeZHDZvSHCcPmTP8CDMebNbSPtibatYXeNHG6vm
Mainnet PublicKey1: 026bc2812d146cd2f4aeec2d2a5d1c69bbadc735a3f7ff30ac73587f327eb427d9

In https://iancoleman.io/bip39

Path: m/44'/2'/0'/0/0
LXbmmJEuwYrFN21vLGwFkaYz5zeDEDanGv
02ddf59d9deb77616c77c8f4c024e0e5137c92c3ad43dd39ad71c8f1e04574110e T4UWHcDKz5hpqbiCwFCoD8ikjZEKxtH1MVHHvSUfbgRjR3WR6JFU

Path: m/44'/2'/0'/0/1
LPfb4Rm9WJNQac1WSFwFLN4FkQGY3wecBy
026bc2812d146cd2f4aeec2d2a5d1c69bbadc735a3f7ff30ac73587f327eb427d9
T7brMpgeMff6oaHRprWnedjzLd6hCHEFToGrJCXGAZ4i3XvorQMs

But My question is that address and public key generate same but private key generated differently.

Implemented Method:

func testMainnetChildKeyDerivation() {
let privateKey = PrivateKey(seed: seed, network: .main(.litecoin))

    // BIP44 key derivation
    // m/44'
    let purpose = privateKey.derived(at: .hardened(44))
    
    // m/44'/2'
    let coinType = purpose.derived(at: .hardened(2))
    
    // m/44'/0'/0'
    let account = coinType.derived(at: .hardened(0))
    
    // m/44'/0'/0'/0
    let change = account.derived(at: .notHardened(0))
    
    // m/44'/0'/0'/0/0
    
    for i in 0..<2{
        let firstPrivateKey = change.derived(at: .notHardened(UInt32(i)))
        print("Mainnet ChildKey_",i,": ",firstPrivateKey.publicKey.address)
        print("Mainnet PrivateKey_",i,": ",firstPrivateKey.get())
        print("Mainnet PublicKey_",i,": ",firstPrivateKey.publicKey.get())
    }
}

change in Class:

name: PrivateKey.swift

  1. public func get() -> String {
    switch self.network.coinType {
    case Network.main(.bitcoin).coinType:
    return self.wif()

     case Network.test(.bitcoin).coinType:
         return self.wif()
     
     case Network.main(.ethereum).coinType:
         return self.raw.toHexString()
     
     case Network.test(.ethereum).coinType:
         return self.raw.toHexString()
         
     case Network.main(.litecoin).coinType:
         return self.wif()
         
     case Network.test(.litecoin).coinType:
         return self.wif()
      
     case Network.main(.bitcoinCash).coinType:
         return self.wif()
     
     case Network.test(.bitcoinCash).coinType:
         return self.wif()
         
     default:
         return "None"
     }
    

    }

  2. public func wif() -> String {
    if self.network.coinType == Network.main(.bitcoin).coinType {
    var data = Data()
    data += UInt8(0x80)
    data += raw
    data += UInt8(0x01)
    data += data.doubleSHA256.prefix(4)
    return Base58.encode(data)
    }else if self.network.coinType == Network.main(.litecoin).coinType {
    var data = Data()
    data += UInt8(0x80)
    data += raw
    data += UInt8(0x01)
    data += data.doubleSHA256.prefix(4)
    return Base58.encode(data)
    }
    return "WIF is not specified"
    }

if any thing please let me know. Please provide a solution or guide me. I have tried to generate private as per iancolemean site.

from hdwallet.

impul avatar impul commented on May 29, 2024

@sazzadiproliya, please provide your HDWallet version, and mnemonic that u used in your tests.

from hdwallet.

TBSMobile avatar TBSMobile commented on May 29, 2024

Hello, I m using 24-word seed.

let mnemonic = "fly weasel genuine enact humor catch prison upper spatial sure mechanic excess hint lazy uphold need violin sport also certain cannon spread include float"

let seed = Mnemonic.createSeed(mnemonic: mnemonic)

from hdwallet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.