cake_wallet/cw_bitcoin/lib/utils.dart

56 lines
1.8 KiB
Dart
Raw Normal View History

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