2020-08-25 16:32:40 +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(
|
|
|
|
{@required bitcoin.HDWallet hd, @required int index}) =>
|
|
|
|
PaymentData(
|
|
|
|
pubkey: Uint8List.fromList(HEX.decode(hd.derive(index).pubKey)));
|
|
|
|
|
|
|
|
bitcoin.ECPair generateKeyPair(
|
|
|
|
{@required bitcoin.HDWallet hd,
|
|
|
|
@required int index,
|
|
|
|
bitcoin.NetworkType network}) =>
|
2021-05-07 07:36:38 +00:00
|
|
|
bitcoin.ECPair.fromWIF(hd.derive(index).wif, network: network);
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
String generateP2WPKHAddress(
|
|
|
|
{@required bitcoin.HDWallet hd,
|
|
|
|
@required int index,
|
|
|
|
bitcoin.NetworkType networkType}) =>
|
|
|
|
bitcoin
|
|
|
|
.P2WPKH(
|
|
|
|
data: PaymentData(
|
|
|
|
pubkey:
|
|
|
|
Uint8List.fromList(HEX.decode(hd.derive(index).pubKey))),
|
|
|
|
network: networkType)
|
|
|
|
.data
|
|
|
|
.address;
|
|
|
|
|
|
|
|
String generateP2WPKHAddressByPath(
|
|
|
|
{@required bitcoin.HDWallet hd,
|
|
|
|
@required String path,
|
|
|
|
bitcoin.NetworkType networkType}) =>
|
2020-08-25 16:32:40 +00:00
|
|
|
bitcoin
|
|
|
|
.P2WPKH(
|
|
|
|
data: PaymentData(
|
|
|
|
pubkey:
|
2021-05-07 07:36:38 +00:00
|
|
|
Uint8List.fromList(HEX.decode(hd.derivePath(path).pubKey))),
|
|
|
|
network: networkType)
|
|
|
|
.data
|
|
|
|
.address;
|
|
|
|
|
|
|
|
String generateP2PKHAddress(
|
|
|
|
{@required bitcoin.HDWallet hd,
|
|
|
|
@required int index,
|
|
|
|
bitcoin.NetworkType networkType}) =>
|
|
|
|
bitcoin
|
|
|
|
.P2PKH(
|
|
|
|
data: PaymentData(
|
|
|
|
pubkey:
|
|
|
|
Uint8List.fromList(HEX.decode(hd.derive(index).pubKey))),
|
|
|
|
network: networkType)
|
2020-08-25 16:32:40 +00:00
|
|
|
.data
|
|
|
|
.address;
|