mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
fix merge conflicts
This commit is contained in:
parent
af82f7fd82
commit
1f746b3cad
2 changed files with 76 additions and 22 deletions
|
@ -258,16 +258,21 @@ abstract class ElectrumWalletBase
|
||||||
|
|
||||||
@override
|
@override
|
||||||
BitcoinWalletKeys get keys {
|
BitcoinWalletKeys get keys {
|
||||||
|
final extendedPrivateKey = accountHD.privateKey.toExtended;
|
||||||
|
final extendedPublicKey = accountHD.publicKey.toExtended;
|
||||||
|
|
||||||
final p2wpkhMainnetPrivKey = KeysVersionBytesConverter.changePrivateKeyVersionBytes(
|
final p2wpkhMainnetPrivKey = KeysVersionBytesConverter.changePrivateKeyVersionBytes(
|
||||||
key: accountHD.base58Priv!, targetType: PrivateKeyType.zprv);
|
key: extendedPrivateKey, targetType: PrivateKeyType.zprv);
|
||||||
|
|
||||||
final p2wpkhMainnetPubKey = KeysVersionBytesConverter.changePublicKeyVersionBytes(
|
final p2wpkhMainnetPubKey = KeysVersionBytesConverter.changePublicKeyVersionBytes(
|
||||||
key: accountHD.base58!, targetType: PublicKeyType.zpub);
|
key: extendedPublicKey, targetType: PublicKeyType.zpub);
|
||||||
|
|
||||||
|
final wif = WifEncoder.encode(accountHD.privateKey.raw, netVer: network.wifNetVer);
|
||||||
|
|
||||||
return BitcoinWalletKeys(
|
return BitcoinWalletKeys(
|
||||||
wif: accountHD.wif!,
|
wif: wif,
|
||||||
privateKey: accountHD.base58Priv!,
|
privateKey: extendedPrivateKey,
|
||||||
publicKey: accountHD.base58!,
|
publicKey: extendedPublicKey,
|
||||||
p2wpkhMainnetPubKey: p2wpkhMainnetPubKey,
|
p2wpkhMainnetPubKey: p2wpkhMainnetPubKey,
|
||||||
p2wpkhMainnetPrivKey: p2wpkhMainnetPrivKey);
|
p2wpkhMainnetPrivKey: p2wpkhMainnetPrivKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,9 @@
|
||||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
|
|
||||||
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
|
|
||||||
import 'package:hex/hex.dart';
|
import 'package:hex/hex.dart';
|
||||||
import 'package:bs58check/bs58check.dart' as bs58check;
|
import 'package:bs58check/bs58check.dart' as bs58check;
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||||
|
|
||||||
bitcoin.PaymentData generatePaymentData({
|
|
||||||
required bitcoin.HDWallet hd,
|
|
||||||
required int index,
|
|
||||||
}) {
|
|
||||||
final pubKey = hd.derive(index).pubKey!;
|
|
||||||
return PaymentData(pubkey: Uint8List.fromList(HEX.decode(pubKey)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ECPrivate generateECPrivate({
|
ECPrivate generateECPrivate({
|
||||||
required Bip32Slip10Secp256k1 hd,
|
required Bip32Slip10Secp256k1 hd,
|
||||||
required BasedUtxoNetwork network,
|
required BasedUtxoNetwork network,
|
||||||
|
@ -62,14 +51,71 @@ String generateP2TRAddress({
|
||||||
required Bip32Slip10Secp256k1 hd,
|
required Bip32Slip10Secp256k1 hd,
|
||||||
required BasedUtxoNetwork network,
|
required BasedUtxoNetwork network,
|
||||||
required int index,
|
required int index,
|
||||||
}) {
|
}) =>
|
||||||
final pubKey = hd.derive(index).pubKey!;
|
ECPublic.fromBip32(hd.childKey(Bip32KeyIndex(index)).publicKey)
|
||||||
return ECPublic.fromHex(pubKey).toTaprootAddress().toAddress(network);
|
.toTaprootAddress()
|
||||||
|
.toAddress(network);
|
||||||
|
|
||||||
|
/// Enum representing different types of private keys.
|
||||||
|
enum PrivateKeyType {
|
||||||
|
/// BIP32 extended private key (mainnet)
|
||||||
|
xprv,
|
||||||
|
|
||||||
|
/// BIP84 extended private key for native SegWit (P2WPKH) (mainnet)
|
||||||
|
zprv,
|
||||||
|
|
||||||
|
/// BIP49 extended private key for wrapped SegWit (P2SH-P2WPKH) (mainnet)
|
||||||
|
yprv,
|
||||||
|
|
||||||
|
/// BIP49 extended private key (upper Y variant)
|
||||||
|
Yprv,
|
||||||
|
|
||||||
|
/// BIP32 extended private key (testnet)
|
||||||
|
tprv,
|
||||||
|
|
||||||
|
/// BIP32 extended private key (alternative mainnet prefix)
|
||||||
|
uprv,
|
||||||
|
|
||||||
|
/// BIP32 extended private key (alternative mainnet prefix, upper U variant)
|
||||||
|
Uprv,
|
||||||
|
|
||||||
|
/// BIP84 extended private key (native SegWit, upper V variant)
|
||||||
|
vprv,
|
||||||
|
|
||||||
|
/// BIP84 extended private key (native SegWit, upper V variant, uppercase)
|
||||||
|
Vprv
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PrivateKeyType { xprv, zprv, yprv, Yprv, tprv, uprv, Uprv, vprv, Vprv }
|
/// Enum representing different types of public keys.
|
||||||
|
enum PublicKeyType {
|
||||||
|
/// BIP32 extended public key (mainnet)
|
||||||
|
xpub,
|
||||||
|
|
||||||
|
/// BIP84 extended public key for native SegWit (P2WPKH) (mainnet)
|
||||||
|
zpub,
|
||||||
|
|
||||||
|
/// BIP49 extended public key for wrapped SegWit (P2SH-P2WPKH) (mainnet)
|
||||||
|
ypub,
|
||||||
|
|
||||||
|
/// BIP49 extended public key (upper Y variant)
|
||||||
|
Ypub,
|
||||||
|
|
||||||
|
/// BIP32 extended public key (testnet)
|
||||||
|
tpub,
|
||||||
|
|
||||||
|
/// BIP32 extended public key (alternative mainnet prefix)
|
||||||
|
upub,
|
||||||
|
|
||||||
|
/// BIP32 extended public key (alternative mainnet prefix, upper U variant)
|
||||||
|
Upub,
|
||||||
|
|
||||||
|
/// BIP84 extended public key (native SegWit, upper V variant)
|
||||||
|
vpub,
|
||||||
|
|
||||||
|
/// BIP84 extended public key (native SegWit, upper V variant, uppercase)
|
||||||
|
Vpub
|
||||||
|
}
|
||||||
|
|
||||||
enum PublicKeyType { xpub, zpub, ypub, Ypub, tpub, upub, Upub, vpub, Vpub }
|
|
||||||
|
|
||||||
class KeysVersionBytesConverter {
|
class KeysVersionBytesConverter {
|
||||||
static const prvKeyPrefixes = {
|
static const prvKeyPrefixes = {
|
||||||
|
@ -96,24 +142,27 @@ class KeysVersionBytesConverter {
|
||||||
PublicKeyType.Vpub: '02575483',
|
PublicKeyType.Vpub: '02575483',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Converts an extended private key to the specified target type by changing its version bytes.
|
||||||
static String? changePrivateKeyVersionBytes(
|
static String? changePrivateKeyVersionBytes(
|
||||||
{required String key, required PrivateKeyType targetType}) {
|
{required String key, required PrivateKeyType targetType}) {
|
||||||
if (!prvKeyPrefixes.containsKey(targetType)) throw Exception('Invalid target version');
|
if (!prvKeyPrefixes.containsKey(targetType)) throw Exception('Invalid target version');
|
||||||
return _changeVersionBytes(key: key, prefixes: prvKeyPrefixes, targetType: targetType);
|
return _changeVersionBytes(key: key, prefixes: prvKeyPrefixes, targetType: targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts an extended public key to the specified target type by changing its version bytes.
|
||||||
static String? changePublicKeyVersionBytes(
|
static String? changePublicKeyVersionBytes(
|
||||||
{required String key, required PublicKeyType targetType}) {
|
{required String key, required PublicKeyType targetType}) {
|
||||||
if (!pubKeyPrefixes.containsKey(targetType)) throw Exception('Invalid target version');
|
if (!pubKeyPrefixes.containsKey(targetType)) throw Exception('Invalid target version');
|
||||||
return _changeVersionBytes(key: key, prefixes: pubKeyPrefixes, targetType: targetType);
|
return _changeVersionBytes(key: key, prefixes: pubKeyPrefixes, targetType: targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Internal method for changing version bytes of an extended key.
|
||||||
static String? _changeVersionBytes<T>(
|
static String? _changeVersionBytes<T>(
|
||||||
{required String key, required Map<T, String> prefixes, required T targetType}) {
|
{required String key, required Map<T, String> prefixes, required T targetType}) {
|
||||||
try {
|
try {
|
||||||
Uint8List data = bs58check.decode(key);
|
Uint8List data = bs58check.decode(key);
|
||||||
data = data.sublist(4);
|
data = data.sublist(4);
|
||||||
Uint8List newData = Uint8List.fromList(hex.decode(prefixes[targetType]!) + data);
|
Uint8List newData = Uint8List.fromList(HEX.decode(prefixes[targetType]!) + data);
|
||||||
return bs58check.encode(newData);
|
return bs58check.encode(newData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue