Comments (6)
let me check first with the current library. Because in the current project, I have install pod.
Got the solution.
Thanks
from hdwallet.
Hi, @sazzadiproliya, thank you for your question.
Our library provides two ways for generating Litecoin(or Bitcoin, Ethereum and Bitcoin Classic) wallets:
- 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.
- 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.
@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:
from hdwallet.
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
-
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" }
}
-
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.
@sazzadiproliya, please provide your HDWallet version, and mnemonic that u used in your tests.
from hdwallet.
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)
- Private key generation does not work on iPhones having processor make Apple A6 HOT 1
- Use of unresolved identifier 'Scrypt' HOT 1
- does hdwallet support segwit address? HOT 1
- support for usdt
- support iOS 10 HOT 1
- What is minimum OS version for DASH support
- How to switch bitcoin network environment after deleting the network
- Getting Extended Public Key
- I want to generate TestNet bitcoin address with this lib, is there any way? HOT 1
- My build fails because of HDWalletKit
- possible to use master public key to generate addresses and watch for payments?
- How to use segwit address in btc for sending
- How to use segwit address in btc?
- Get exact sign hash.
- [BCH] It is impossible to access to generateCashAddress() function HOT 1
- how to get private key as hex and switch test net bitcoin ? HOT 1
- Will you support Swift Package Manager?
- KeystoreV3.swift An error occurred .error missage: 'Type of expression is ambiguous without more context'
- Build error
- Transactions are not sending
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hdwallet.