How to Generate draft-thomas-crypto-conditions-04 in Dart?

33 Views Asked by At

I am working on a project that requires the generation of draft-thomas-crypto-conditions-04 compatible fulfillment and conditions in Dart.

I attempted to generate conditions and fulfillments using the Pointy Castle package in Dart but was unsuccessful, and the results differ from the corresponding package in Python

Python cryptoconditions package:

secret = "ba5002e0f12d57b5509d3bdb2b53c523212d0fd7307993bee3cd16ff90cf31b1"
fufill = PreimageSha256(preimage=bytes.fromhex(secret))
condition = str.upper(fufill.condition_binary.hex())
fulfillment = str.upper(fufill.serialize_binary().hex())
# result
# condition: A0258020313777FF1205A40753F92474216140B48AF0C63A34E44CD88E28E93A0F61D204810120 
# fulfillment A0228020BA5002E0F12D57B5509D3BDB2B53C523212D0FD7307993BEE3CD16FF90CF31B1

dart using pointycastle:

String getConditionAndFulfillments(Uint8List data) {
  final algo = ASN1AlgorithmIdentifier(ASN1ObjectIdentifier.fromName("SHA-256"));
  final ASN1DigestInfo asn1 = ASN1DigestInfo(data, algo);
  final encode = asn1.encode();
  return bytesToHex(encode);
}
final fullFillments = getConditionAndFulfillments(secret);
final condition = getConditionAndFulfillments(sha256(secret));
print("fulfillment $fullFillments");
print("condition $condition");
/// result
/// fulfillment 3031300d0609608648016503040201050004 **20ba5002e0f12d57b5509d3bdb2b53c523212d0fd7307993bee3cd16ff90cf31b1**
/// condition 3031300d0609608648016503040201050004**20313777ff1205a40753f92474216140b48af0c63a34e44cd88e28e93a0f61d204**
0

There are 0 best solutions below