stack_wallet/lib/utilities/bip47_utils.dart

50 lines
1.4 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'dart:typed_data';
import 'package:bip47/src/util.dart';
2024-05-27 23:56:22 +00:00
import '../models/isar/models/blockchain_data/v2/output_v2.dart';
import '../models/isar/models/blockchain_data/v2/transaction_v2.dart';
abstract class Bip47Utils {
/// looks at tx outputs and returns a blinded payment code if found
2024-01-13 21:49:29 +00:00
static Uint8List? getBlindedPaymentCodeBytesFrom(TransactionV2 transaction) {
2023-01-31 22:21:09 +00:00
for (int i = 0; i < transaction.outputs.length; i++) {
final bytes = getBlindedPaymentCodeBytesFromOutput(
2024-05-27 23:56:22 +00:00
transaction.outputs.elementAt(i),
);
2023-01-31 22:21:09 +00:00
if (bytes != null) {
return bytes;
}
}
return null;
}
2024-01-13 21:49:29 +00:00
static Uint8List? getBlindedPaymentCodeBytesFromOutput(OutputV2 output) {
Uint8List? blindedCodeBytes;
2024-05-27 23:56:22 +00:00
final List<String>? scriptChunks = output.scriptPubKeyAsm?.split(" ");
2023-01-31 22:21:09 +00:00
if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") {
final blindedPaymentCode = scriptChunks![1];
final bytes = blindedPaymentCode.fromHex;
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;
}
}
return blindedCodeBytes;
}
}