hash single tag from data

This commit is contained in:
julian
2023-12-29 08:47:00 -06:00
parent f4f58f83d2
commit 0b69b03004
5 changed files with 57 additions and 1 deletions

View File

@@ -180,4 +180,16 @@ void main() {
);
});
});
test('hash tag from x and y', () async {
const x =
'805f27cb4b6b8958587772011606a1fe264eb5cab0140dfc79d53f041d179647';
const y =
'52e22e74a5b57de0bb661a8116b06de8c3e70dc15a3865dea9a56a0288771c0d';
expect(
LibSpark.hashTag(x, y),
'875a3d3fe398ba1084ef68679baa81980ba3448c145afad725a9588c2f7fcfcf',
);
});
}

View File

@@ -746,6 +746,20 @@ abstract final class LibSpark {
return hashes;
}
static String hashTag(String x, String y) {
final xPtr = x.toNativeUtf8().cast<Char>();
final yPtr = y.toNativeUtf8().cast<Char>();
final result = _bindings.hashTag(xPtr, yPtr);
final hash = result.cast<Utf8>().toDartString();
malloc.free(xPtr);
malloc.free(yPtr);
malloc.free(result);
return hash;
}
static int estimateSparkFee({
required String privateKeyHex,
int index = 1,

View File

@@ -295,6 +295,24 @@ class FlutterLibsparkmobileBindings {
late final _hashTags = _hashTagsPtr.asFunction<
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.UnsignedChar>, int)>();
ffi.Pointer<ffi.Char> hashTag(
ffi.Pointer<ffi.Char> x,
ffi.Pointer<ffi.Char> y,
) {
return _hashTag(
x,
y,
);
}
late final _hashTagPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<ffi.Char> Function(
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>>('hashTag');
late final _hashTag = _hashTagPtr.asFunction<
ffi.Pointer<ffi.Char> Function(
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>();
ffi.Pointer<SparkFeeResult> estimateSparkFee(
ffi.Pointer<ffi.UnsignedChar> keyData,
int index,

View File

@@ -529,7 +529,6 @@ ValidateAddressResult* isValidSparkAddress(
}
}
FFI_PLUGIN_EXPORT
const char* hashTags(unsigned char* tags, int tagCount) {
char* result = (char*) malloc(sizeof(char) * 64 * tagCount);
@@ -543,6 +542,16 @@ const char* hashTags(unsigned char* tags, int tagCount) {
return result;
}
FFI_PLUGIN_EXPORT
const char* hashTag(const char* x, const char* y) {
secp_primitives::GroupElement tag = secp_primitives::GroupElement(x, y, 16);
uint256 hash = primitives::GetLTagHash(tag);
std::string hex = hash.GetHex();
char* result = (char*) malloc(sizeof(char) * hex.length());
strcpy(result, hex.c_str());
return result;
}
FFI_PLUGIN_EXPORT
SparkFeeResult* estimateSparkFee(
unsigned char* keyData,

View File

@@ -103,6 +103,9 @@ struct ValidateAddressResult* isValidSparkAddress(
FFI_PLUGIN_EXPORT
const char* hashTags(unsigned char* tags, int tagCount);
FFI_PLUGIN_EXPORT
const char* hashTag(const char* x, const char* y);
FFI_PLUGIN_EXPORT
struct SparkFeeResult* estimateSparkFee(
unsigned char* keyData,