2021-12-24 12:52:08 +00:00
|
|
|
import 'package:crypto/crypto.dart';
|
2024-03-21 02:51:57 +00:00
|
|
|
import 'package:cw_bitcoin/address_to_output_script.dart';
|
|
|
|
import 'package:bitcoin_base/bitcoin_base.dart' as bitcoin;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-03-21 02:51:57 +00:00
|
|
|
String scriptHash(String address, {required bitcoin.BasedUtxoNetwork network}) {
|
|
|
|
final outputScript = addressToOutputScript(address, network);
|
2021-12-24 12:52:08 +00:00
|
|
|
final parts = sha256.convert(outputScript).toString().split('');
|
|
|
|
var res = '';
|
|
|
|
|
|
|
|
for (var i = parts.length - 1; i >= 0; i--) {
|
|
|
|
final char = parts[i];
|
|
|
|
i--;
|
|
|
|
final nextChar = parts[i];
|
|
|
|
res += nextChar;
|
|
|
|
res += char;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|