2023-01-31 20:40:54 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:bip47/src/util.dart';
|
2023-01-31 22:21:09 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/blockchain_data/output.dart';
|
2023-01-31 20:40:54 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
|
|
|
|
|
|
|
|
abstract class Bip47Utils {
|
|
|
|
/// looks at tx outputs and returns a blinded payment code if found
|
|
|
|
static Uint8List? getBlindedPaymentCodeBytesFrom(Transaction transaction) {
|
2023-01-31 22:21:09 +00:00
|
|
|
for (int i = 0; i < transaction.outputs.length; i++) {
|
|
|
|
final bytes = getBlindedPaymentCodeBytesFromOutput(
|
|
|
|
transaction.outputs.elementAt(i));
|
|
|
|
if (bytes != null) {
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Uint8List? getBlindedPaymentCodeBytesFromOutput(Output output) {
|
2023-01-31 20:40:54 +00:00
|
|
|
Uint8List? blindedCodeBytes;
|
|
|
|
|
2023-01-31 22:21:09 +00:00
|
|
|
List<String>? scriptChunks = output.scriptPubKeyAsm?.split(" ");
|
|
|
|
if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") {
|
|
|
|
final blindedPaymentCode = scriptChunks![1];
|
|
|
|
final bytes = blindedPaymentCode.fromHex;
|
2023-01-31 20:40:54 +00:00
|
|
|
|
2023-01-31 22:21:09 +00:00
|
|
|
// https://en.bitcoin.it/wiki/BIP_0047#Sending
|
|
|
|
if (bytes.length == 80 && bytes.first == 1) {
|
|
|
|
blindedCodeBytes = bytes;
|
2023-01-31 20:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return blindedCodeBytes;
|
|
|
|
}
|
|
|
|
}
|