Skip to content

Commit

Permalink
Add BIP44 derivation paths to Bitcoin Cash wallet restoration process (
Browse files Browse the repository at this point in the history
…cypherstack#330)

* add new derive path for bch

and make it the new default.  we currently use slip44 (coinType 145) as the default

* add default cases to DerivePathType switches now failing

* normalize DerivePathType errors

log failing derivePathType or type, as appropriate

* add default derive path case to paynym interface

* use slip44 in bch wallet

* linting

* WIP look up both bip44 and slip44 addresses

slip44 is used by default

* typo fix

* typo fix

thanks Julian

* remove print

* use slip44 addresses by default

* use AddressType unknown for bip44 derive path type

* use address type unknown in _getCurrentAddressForChain, too

* generate different keys for SLIP44 and BIP44 paths

* couple more slips

* return slip44 from addressType

* slip before bip

* revert slip44-bip44, bch's bip44->bch44

* set bch44 derive path to type unknown

do not comingle paths in later output selection by index

* handle bip44 and bch44 path addresses when handling outputs

* use bip44 by default

* typofix

* typo fix in the typo fix

yo dawg

* separate new derivation path functions into their own non-testnet block

* cleanup

* disable test

should re-enable if it can be fixed with the test mnemonic in hand

---------

Co-authored-by: julian <julian@cypherstack.com>
  • Loading branch information
sneurlax and julian-CStack committed Feb 2, 2023
1 parent bd05d6d commit 4aec78f
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 67 deletions.
12 changes: 10 additions & 2 deletions lib/services/coins/bitcoin/bitcoin_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bip32.BIP32 getBip32NodeFromRoot(
case DerivePathType.bip84:
return root.derivePath("m/84'/$coinType'/0'/$chain/$index");
default:
throw Exception("DerivePathType must not be null.");
throw Exception("DerivePathType $derivePathType not supported");
}
}

Expand Down Expand Up @@ -436,7 +436,7 @@ class BitcoinWallet extends CoinServiceAPI
addrType = isar_models.AddressType.p2wpkh;
break;
default:
throw Exception("No Path type $type exists");
throw Exception("DerivePathType $type not supported");
}

final address = isar_models.Address(
Expand Down Expand Up @@ -1560,6 +1560,8 @@ class BitcoinWallet extends CoinServiceAPI
address = P2WPKH(network: _network, data: data).data.address!;
addrType = isar_models.AddressType.p2wpkh;
break;
default:
throw Exception("DerivePathType $derivePathType not supported");
}

// add generated address & info to derivations
Expand Down Expand Up @@ -1606,6 +1608,8 @@ class BitcoinWallet extends CoinServiceAPI
case DerivePathType.bip84:
type = isar_models.AddressType.p2wpkh;
break;
default:
throw Exception("DerivePathType unsupported");
}
address = await db
.getAddresses(walletId)
Expand Down Expand Up @@ -1633,6 +1637,8 @@ class BitcoinWallet extends CoinServiceAPI
case DerivePathType.bip84:
key = "${walletId}_${chainId}DerivationsP2WPKH";
break;
default:
throw Exception("DerivePathType unsupported");
}
return key;
}
Expand Down Expand Up @@ -2645,6 +2651,8 @@ class BitcoinWallet extends CoinServiceAPI
case DerivePathType.bip84:
addressesP2WPKH.add(address);
break;
default:
throw Exception("DerivePathType unsupported");
}
}
}
Expand Down
Loading

0 comments on commit 4aec78f

Please sign in to comment.