2021-12-24 12:52:08 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
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';
|
|
|
|
|
2023-11-30 10:01:58 +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
|
|
|
|
|
|
|
bitcoin.ECPair generateKeyPair(
|
2023-11-30 10:01:58 +00:00
|
|
|
{required bitcoin.HDWallet hd, required int index, required bitcoin.NetworkType network}) =>
|
2022-10-12 17:09:57 +00:00
|
|
|
bitcoin.ECPair.fromWIF(hd.derive(index).wif!, network: network);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
String generateP2WPKHAddress(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd,
|
|
|
|
required int index,
|
|
|
|
required bitcoin.NetworkType networkType}) =>
|
2023-11-30 17:28:29 +00:00
|
|
|
bitcoin.P2wpkhAddress(pubkey: hd.derive(index).pubKey!).toAddress(networkType);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-11-30 10:01:58 +00:00
|
|
|
String generateP2PKHAddress(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd,
|
2023-11-30 10:01:58 +00:00
|
|
|
required int index,
|
2022-10-12 17:09:57 +00:00
|
|
|
required bitcoin.NetworkType networkType}) =>
|
2021-12-24 12:52:08 +00:00
|
|
|
bitcoin
|
2023-11-30 10:01:58 +00:00
|
|
|
.P2PKH(
|
|
|
|
data: PaymentData(pubkey: Uint8List.fromList(HEX.decode(hd.derive(index).pubKey!))),
|
2021-12-24 12:52:08 +00:00
|
|
|
network: networkType)
|
|
|
|
.data
|
2022-10-12 17:09:57 +00:00
|
|
|
.address!;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-11-30 10:01:58 +00:00
|
|
|
String generateP2TRAddress(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd,
|
|
|
|
required int index,
|
|
|
|
required bitcoin.NetworkType networkType}) =>
|
2023-11-30 17:28:29 +00:00
|
|
|
bitcoin.P2trAddress(pubkey: hd.derive(index).pubKey!, network: networkType)
|
|
|
|
.toAddress(networkType);
|