iancoleman / bip39

A web tool for converting BIP39 mnemonic codes
https://iancoleman.io/bip39/
MIT License
3.41k stars 1.42k forks source link

Bech32 address #590

Open random9brat opened 2 years ago

random9brat commented 2 years ago

Hello, im kinda new in bitcoin/menmonic/nodejs programming. I used your https://iancoleman.io/bip39/ and at the end i saw bc1... address created from specific derivation path.

I created a code which gives me 12 mnemonic words just like your program, it also gives private key, but it gives me public address starting with 1 and not with bc1...

I could use some help of creating that bech32 address in js somehow...is there any code which i could use to create bc1 addresses?

Thanks a lot for help from anyone...<3 cheers

cryptopivot commented 2 years ago

Is there a reason you are attempting to do what is already done? The Ian Coleman's script is a credible and working solution well beyond your mentioned initiative.

BTC addresses starting with a 1 is the initial and first Legacy address format, which starts with the derivation path of m44.

Bech32 is Native Segwit which was an improvement after BIP49 (3 format) chain size and transaction speed. That is bc1 addresses in the m/84 derivation.

IMO, your doing to much and may be better to learn about these protocols before trying to program around them.

random9brat commented 2 years ago

This is the way im learning, i didnt mean to offend anyone. Im just creating a wallet like this for myself to explore. Just want to create and learn more within this space. The thing that I successfully created Legacy address, 12 mnemonic words and a private key makes me super excited. I didnt have chance to get formal education so im learning here on the internet.

I did enter m/84'/0'/0'/0/0 and m/44'/0'/0'/0/0 derivation paths but it always gives me the legacy addreses starting with 1. I know my knowledge is kinda messy and all way around... but im trying within open space, and I thought Bitcoin community is all about that.

cryptopivot commented 2 years ago

No offense buddy, none at all. Fair enough, and I give my apologies on any negativity my comment (doing too much) may have been perceived.

Glad to see your enthusiasm of understanding under the hood of this exciting space. Perhaps someone can help you along with your request. Beyond understanding entropy, derivations and various chain protocols it is out of my league. I find it cool to roll dice or flip cards in order to achieve true randomness. After that, I leave the rest to the big boys :)

Best of Luck and God speed!

random9brat commented 2 years ago

Thanks a lot for kind words... god speed indeed :). Or should some say "to the moon" :D.

If anyone knows im stuck with this code right now:

const bitcoin = require('bitcoinjs-lib');
const ECPair = require('bitcoinjs-lib/src/ecpair');

const keyPair = ECPair.fromWIF('KxCb6hLLBUwxJdThXnSb37gJPKmN5BiibRiA7MXQouAWtRyRTQmo'); //some random private key
const { address } = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey });
console.log(address);

It says it "TypeError: Cannot read property 'p2wpkh' of undefined", i guess i didnt install/require/import all of the important packages.

But thats the example, im trying to get bc1 from private key basically. If anyone knows better and easier code how to get bc1 (i think thats segwit) it would help me a lot...

junderw commented 2 years ago

You are using the wrong version of bitcoinjs-lib