2021-12-24 12:52:08 +00:00
|
|
|
import 'dart:typed_data';
|
2024-03-04 19:42:57 +00:00
|
|
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
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';
|
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
bitcoin.PaymentData generatePaymentData({required bitcoin.HDWallet hd, required int index}) =>
|
|
|
|
PaymentData(pubkey: Uint8List.fromList(HEX.decode(hd.derive(index).pubKey!)));
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
ECPrivate generateECPrivate(
|
|
|
|
{required bitcoin.HDWallet hd, required int index, required BasedUtxoNetwork network}) =>
|
|
|
|
ECPrivate.fromWif(hd.derive(index).wif!, netVersion: network.wifNetVer);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
String generateP2WPKHAddress(
|
2024-03-04 19:42:57 +00:00
|
|
|
{required bitcoin.HDWallet hd, required int index, required BasedUtxoNetwork network}) =>
|
|
|
|
ECPublic.fromHex(hd.derive(index).pubKey!).toP2wpkhAddress().toAddress(network);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
String generateP2SHAddress(
|
|
|
|
{required bitcoin.HDWallet hd, required int index, required BasedUtxoNetwork network}) =>
|
|
|
|
ECPublic.fromHex(hd.derive(index).pubKey!).toP2wpkhInP2sh().toAddress(network);
|
|
|
|
|
|
|
|
String generateP2WSHAddress(
|
|
|
|
{required bitcoin.HDWallet hd, required int index, required BasedUtxoNetwork network}) =>
|
|
|
|
ECPublic.fromHex(hd.derive(index).pubKey!).toP2wshAddress().toAddress(network);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
String generateP2PKHAddress(
|
2024-03-04 19:42:57 +00:00
|
|
|
{required bitcoin.HDWallet hd, required int index, required BasedUtxoNetwork network}) =>
|
|
|
|
ECPublic.fromHex(hd.derive(index).pubKey!).toP2pkhAddress().toAddress(network);
|
|
|
|
|
|
|
|
String generateP2TRAddress(
|
|
|
|
{required bitcoin.HDWallet hd, required int index, required BasedUtxoNetwork network}) =>
|
|
|
|
ECPublic.fromHex(hd.derive(index).pubKey!).toTaprootAddress().toAddress(network);
|