iancoleman / bip39

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

Add Groestlcoin with Tests #353

Closed HashEngineering closed 5 years ago

HashEngineering commented 5 years ago

Purpose This PR is to add Groestlcoin support for mainnet and testnet. Groestlcoin differs from most other Bitcoin derived coins in that it uses different hash functions for blocks, transactions and addresses.

History We made a query about adding coins that do not use SHA256D for the checksum of addresses with #191

Methodology The goal was to add support for Groestlcoin with the minimal amount of changes. Our first approach was to create a javascript module that would take an address that followed the bitcoin rules and convert it to an andress that followed Groestlcoin rules. This method would require many modifications to index.js for every place a base58 string was displayed (addressed, dumped private keys, extended public and private keys).

Our second approach, which is used in this PR, uses the groestlcoin equivalents of bitcoinjs-lib and bitcoinjs-bip38. When ECPair or HDNodes are created using bitcoinjs, we instead use groestlcoinjs when Groestlcoin related networks are selected by the user. This ensures that the addresses, dumped private keys, extended private and public keys are rendered using Groestlcoin Rules. Likewise in the case that the user chooses BIP38, then groestlcoinjs-bip38 is used instead of bitcoinjs-bip38 so that the encrypted private key is rendered correctly for Groestlcoin (mainnet or testnet).

Testing: Some audit testing was done to compare the results of https://iancoleman.io/bip39/ and this PR for Bitcoin and Dash to ensure that the addresses and keys generated matched this PR. Additionally, for Groestlcoin, we used, https://groestlcoin.org/bip39/, a site forked from this repo was used to ensure that this PR generates matching output. https://groestlcoin.org/bip39/ is used as a reference for Groestlcoin software development to double check BIP32, BIP44, BIP49 and BIP84 HD path derivation. Three tests were also added to tests.js.

I will add some comments in a few places in the code.

iancoleman commented 5 years ago

Thanks, this is great and I appreciate the work put in to making this possible. Just mainly the small issue of style regarding if vs try/catch, once that's tidier then it should be good to merge. Thanks again.

HashEngineering commented 5 years ago

@iancoleman Thank you for the feedback, I will make the changes, test and modify this pull request soon.

HashEngineering commented 5 years ago

The changes have been submitted regarding the using if vs exception handling. The commits were squashed.

iancoleman commented 4 years ago

I want to raise an issue with https://github.com/Groestlcoin/bip38grs

But they do not seem to allow issues, nor does https://github.com/Groestlcoin/groestlcoinjs-lib

Can you advise how to get changes into their code?

HashEngineering commented 4 years ago

Both of those repos have issues activated now.

@iancoleman