diff --git a/lib/wallets/crypto_currency/coins/bitcoin.dart b/lib/wallets/crypto_currency/coins/bitcoin.dart index dd71ce22d..e7a933072 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin.dart @@ -27,7 +27,7 @@ class Bitcoin extends Bip39HDCurrency { @override List get supportedDerivationPathTypes => [ DerivePathType.bip44, - // DerivePathType.bip49, + DerivePathType.bip49, DerivePathType.bip84, ]; @@ -107,9 +107,9 @@ class Bitcoin extends Bip39HDCurrency { case DerivePathType.bip44: purpose = 44; break; - // case DerivePathType.bip49: - // purpose = 49; - // break; + case DerivePathType.bip49: + purpose = 49; + break; case DerivePathType.bip84: purpose = 84; break; @@ -134,26 +134,18 @@ class Bitcoin extends Bip39HDCurrency { return (address: addr, addressType: AddressType.p2pkh); - // case DerivePathType.bip49: - // // addressString = P2SH( - // // data: PaymentData( - // // redeem: P2WPKH(data: data, network: _network).data), - // // network: _network) - // // .data - // // .address!; - // - // // todo ?????????????????? Does not match with current BTC - // final adr = coinlib.P2WPKHAddress.fromPublicKey( - // publicKey, - // hrp: networkParams.bech32Hrp, - // ); - // final addr = coinlib.P2SHAddress.fromHash( - // adr.program.pkHash, - // version: networkParams.p2shPrefix, - // ); - // - // // TODO ?????????????? - // return (address: addr, addressType: AddressType.p2sh); + case DerivePathType.bip49: + final p2wpkhScript = coinlib.P2WPKHAddress.fromPublicKey( + publicKey, + hrp: networkParams.bech32Hrp, + ).program.script; + + final addr = coinlib.P2SHAddress.fromScript( + p2wpkhScript, + version: networkParams.p2shPrefix, + ); + + return (address: addr, addressType: AddressType.p2sh); case DerivePathType.bip84: final addr = coinlib.P2WPKHAddress.fromPublicKey( diff --git a/lib/wallets/crypto_currency/coins/litecoin.dart b/lib/wallets/crypto_currency/coins/litecoin.dart index 229d1a5c6..5c964db5a 100644 --- a/lib/wallets/crypto_currency/coins/litecoin.dart +++ b/lib/wallets/crypto_currency/coins/litecoin.dart @@ -27,7 +27,7 @@ class Litecoin extends Bip39HDCurrency { @override List get supportedDerivationPathTypes => [ DerivePathType.bip44, - // DerivePathType.bip49, + DerivePathType.bip49, DerivePathType.bip84, ]; @@ -107,9 +107,9 @@ class Litecoin extends Bip39HDCurrency { case DerivePathType.bip44: purpose = 44; break; - // case DerivePathType.bip49: - // purpose = 49; - // break; + case DerivePathType.bip49: + purpose = 49; + break; case DerivePathType.bip84: purpose = 84; break; @@ -134,26 +134,18 @@ class Litecoin extends Bip39HDCurrency { return (address: addr, addressType: AddressType.p2pkh); - // case DerivePathType.bip49: - // // addressString = P2SH( - // // data: PaymentData( - // // redeem: P2WPKH(data: data, network: _network).data), - // // network: _network) - // // .data - // // .address!; - // - // // todo ?????????????????? Does not match with current BTC - // final adr = coinlib.P2WPKHAddress.fromPublicKey( - // publicKey, - // hrp: networkParams.bech32Hrp, - // ); - // final addr = coinlib.P2SHAddress.fromHash( - // adr.program.pkHash, - // version: networkParams.p2shPrefix, - // ); - // - // // TODO ?????????????? - // return (address: addr, addressType: AddressType.p2sh); + case DerivePathType.bip49: + final p2wpkhScript = coinlib.P2WPKHAddress.fromPublicKey( + publicKey, + hrp: networkParams.bech32Hrp, + ).program.script; + + final addr = coinlib.P2SHAddress.fromScript( + p2wpkhScript, + version: networkParams.p2shPrefix, + ); + + return (address: addr, addressType: AddressType.p2sh); case DerivePathType.bip84: final addr = coinlib.P2WPKHAddress.fromPublicKey( diff --git a/lib/wallets/crypto_currency/coins/namecoin.dart b/lib/wallets/crypto_currency/coins/namecoin.dart index 02fc3b1c0..ce5906ee3 100644 --- a/lib/wallets/crypto_currency/coins/namecoin.dart +++ b/lib/wallets/crypto_currency/coins/namecoin.dart @@ -46,10 +46,9 @@ class Namecoin extends Bip39HDCurrency { purpose = 44; break; - // TODO: [prio=low] Add P2SH support. Disable for now as our p2sh was actually p2sh-p2wpkh (wrapped segwit) - // case DerivePathType.bip49: - // purpose = 49; - // break; + case DerivePathType.bip49: + purpose = 49; + break; case DerivePathType.bip84: purpose = 84; @@ -116,8 +115,18 @@ class Namecoin extends Bip39HDCurrency { return (address: addr, addressType: AddressType.p2pkh); - // TODO: [prio=low] Add P2SH support. Disable for now as our p2sh was actually p2sh-p2wpkh (wrapped segwit) - // case DerivePathType.bip49: + case DerivePathType.bip49: + final p2wpkhScript = coinlib.P2WPKHAddress.fromPublicKey( + publicKey, + hrp: networkParams.bech32Hrp, + ).program.script; + + final addr = coinlib.P2SHAddress.fromScript( + p2wpkhScript, + version: networkParams.p2shPrefix, + ); + + return (address: addr, addressType: AddressType.p2sh); case DerivePathType.bip84: final addr = coinlib.P2WPKHAddress.fromPublicKey( @@ -157,8 +166,7 @@ class Namecoin extends Bip39HDCurrency { List get supportedDerivationPathTypes => [ // DerivePathType.bip16, DerivePathType.bip44, - // TODO: [prio=low] Add P2SH support. Disable for now as our p2sh was actually p2sh-p2wpkh (wrapped segwit) - // DerivePathType.bip49, + DerivePathType.bip49, DerivePathType.bip84, ]; diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart index 00754cd5a..852b36509 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart @@ -578,23 +578,24 @@ mixin ElectrumXInterface on Bip39HDWallet { ) .data; break; - // - // case DerivePathType.bip49: - // - // input = P2s - // - // final p2wpkh = P2WPKH( - // data: PaymentData( - // pubkey: Format.stringToUint8List(pubKey), - // ), - // network: _network, - // ).data; - // redeemScript = p2wpkh.output; - // data = P2SH( - // data: PaymentData(redeem: p2wpkh), - // network: _network, - // ).data; - // break; + + case DerivePathType.bip49: + final p2wpkh = bitcoindart + .P2WPKH( + data: bitcoindart.PaymentData( + pubkey: pubKey, + ), + network: convertedNetwork, + ) + .data; + sd.redeemScript = p2wpkh.output; + data = bitcoindart + .P2SH( + data: bitcoindart.PaymentData(redeem: p2wpkh), + network: convertedNetwork, + ) + .data; + break; case DerivePathType.bip84: // input = coinlib.P2WPKHInput(