diff --git a/lib/services/coins/bitcoincash/bch_utils.dart b/lib/services/coins/bitcoincash/bch_utils.dart index 296ecbdab..dfe78a2e8 100644 --- a/lib/services/coins/bitcoincash/bch_utils.dart +++ b/lib/services/coins/bitcoincash/bch_utils.dart @@ -2,8 +2,11 @@ import 'dart:typed_data'; import 'package:bitcoindart/src/utils/constants/op.dart' as op; import 'package:bitcoindart/src/utils/script.dart' as bscript; +import 'package:stackwallet/utilities/extensions/impl/string.dart'; abstract final class BchUtils { + static const FUSE_ID = 'FUZ\x00'; + static bool isSLP(Uint8List scriptPubKey) { const id = [83, 76, 80, 0]; // 'SLP\x00' final decompiled = bscript.decompile(scriptPubKey); @@ -26,4 +29,33 @@ abstract final class BchUtils { return false; } + + static bool isFUZE(Uint8List scriptPubKey) { + final id = FUSE_ID.toUint8ListFromUtf8; + final decompiled = bscript.decompile(scriptPubKey); + + if (decompiled != null && + decompiled.length > 2 && + decompiled.first == op.OPS["OP_RETURN"]) { + // check session hash length. Should be 32 bytes + final sessionHash = decompiled[2]; + if (!(sessionHash is List && sessionHash.length == 32)) { + return false; + } + + final _id = decompiled[1]; + + if (_id is List && _id.length == id.length) { + for (int i = 0; i < id.length; i++) { + if (_id[i] != id[i]) { + return false; + } + } + // lists match! + return true; + } + } + + return false; + } } diff --git a/test/services/coins/bitcoincash/bch_utils_test.dart b/test/services/coins/bitcoincash/bch_utils_test.dart index c25aee4fa..fb2e3220d 100644 --- a/test/services/coins/bitcoincash/bch_utils_test.dart +++ b/test/services/coins/bitcoincash/bch_utils_test.dart @@ -22,4 +22,25 @@ void main() { false, ); }); + + test("script pub key check for fuze is true", () { + expect( + BchUtils.isFUZE("6a0446555a00204d662fb69f34dc23434a61c7bbb65c9f99a247f9c8" + "b377cb4de3cadf7542f8f0" + .toUint8ListFromHex), + true, + ); + }); + + test("script pub key check for fuze is not true", () { + expect( + BchUtils.isFUZE( + "6a04534c500001010747454e45534953044d5430320f4d757461626c652054657374" + "2030321668747470733a2f2f46756c6c537461636b2e63617368200e9a18" + "8911ec0f2ac10cc9425b457d10ba14151a64eb4640f95ed7dab9e8f62601" + "004c00080000000000000001" + .toUint8ListFromHex), + false, + ); + }); }