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';
|
|
|
|
|
|
|
|
bitcoin.PaymentData generatePaymentData(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd, required int index}) =>
|
2021-12-24 12:52:08 +00:00
|
|
|
PaymentData(
|
2022-10-12 17:09:57 +00:00
|
|
|
pubkey: Uint8List.fromList(HEX.decode(hd.derive(index).pubKey!)));
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
bitcoin.ECPair generateKeyPair(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd,
|
|
|
|
required int index,
|
|
|
|
required bitcoin.NetworkType network}) =>
|
|
|
|
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}) =>
|
2021-12-24 12:52:08 +00:00
|
|
|
bitcoin
|
|
|
|
.P2WPKH(
|
|
|
|
data: PaymentData(
|
|
|
|
pubkey:
|
2022-10-12 17:09:57 +00:00
|
|
|
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
|
|
|
|
|
|
|
String generateP2WPKHAddressByPath(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd,
|
|
|
|
required String path,
|
|
|
|
required bitcoin.NetworkType networkType}) =>
|
2021-12-24 12:52:08 +00:00
|
|
|
bitcoin
|
|
|
|
.P2WPKH(
|
|
|
|
data: PaymentData(
|
|
|
|
pubkey:
|
2022-10-12 17:09:57 +00:00
|
|
|
Uint8List.fromList(HEX.decode(hd.derivePath(path).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
|
|
|
|
|
|
|
String generateP2PKHAddress(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required bitcoin.HDWallet hd,
|
|
|
|
required int index,
|
|
|
|
required bitcoin.NetworkType networkType}) =>
|
2021-12-24 12:52:08 +00:00
|
|
|
bitcoin
|
|
|
|
.P2PKH(
|
|
|
|
data: PaymentData(
|
|
|
|
pubkey:
|
2022-10-12 17:09:57 +00:00
|
|
|
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!;
|