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-12-11 22:41:48 +00:00
|
|
|
bitcoin.P2wpkhAddress(pubkey: hd.derive(index).pubKey!, networkType: networkType).address;
|
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}) =>
|
2023-12-11 22:41:48 +00:00
|
|
|
bitcoin.P2pkhAddress(pubkey: hd.derive(index).pubKey!, networkType: networkType).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-12-11 22:41:48 +00:00
|
|
|
bitcoin.P2trAddress(pubkey: hd.derive(index).pubKey!, networkType: networkType).address;
|