2023-10-18 20:46:57 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:bitcoindart/src/utils/constants/op.dart' as op;
|
|
|
|
import 'package:bitcoindart/src/utils/script.dart' as bscript;
|
2023-10-19 22:03:19 +00:00
|
|
|
import 'package:stackwallet/utilities/extensions/impl/string.dart';
|
2023-10-18 20:46:57 +00:00
|
|
|
|
|
|
|
abstract final class BchUtils {
|
2023-10-19 22:03:19 +00:00
|
|
|
static const FUSE_ID = 'FUZ\x00';
|
|
|
|
|
2023-10-18 20:46:57 +00:00
|
|
|
static bool isSLP(Uint8List scriptPubKey) {
|
|
|
|
const id = [83, 76, 80, 0]; // 'SLP\x00'
|
|
|
|
final decompiled = bscript.decompile(scriptPubKey);
|
|
|
|
|
|
|
|
if (decompiled != null &&
|
|
|
|
decompiled.length > 1 &&
|
|
|
|
decompiled.first == op.OPS["OP_RETURN"]) {
|
|
|
|
final _id = decompiled[1];
|
|
|
|
|
|
|
|
if (_id is List<int> && _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;
|
|
|
|
}
|
2023-10-19 22:03:19 +00:00
|
|
|
|
|
|
|
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<int> && sessionHash.length == 32)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
final _id = decompiled[1];
|
|
|
|
|
|
|
|
if (_id is List<int> && _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;
|
|
|
|
}
|
2023-10-18 20:46:57 +00:00
|
|
|
}
|