From b0a7a8d2cb228c9f4bb41103e0ddfef554e5b752 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 16 Jul 2024 12:38:26 -0600 Subject: [PATCH 1/4] update submodule --- src/serai | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serai b/src/serai index 4069593..03289be 160000 --- a/src/serai +++ b/src/serai @@ -1 +1 @@ -Subproject commit 40695938ed32c9c5074edbc12041f3ddb9134834 +Subproject commit 03289be7ad400162e1c37c0202e5ee2e74c9e202 From 4dd900c822f6457903b697085f5c05de5c4ab532 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 16 Jul 2024 14:00:55 -0600 Subject: [PATCH 2/4] WIP address generation --- example/lib/frost_sample_run.dart | 16 +++++- example/pubspec.lock | 72 ++++++++++++++++++--------- lib/frostdart.dart | 27 ++++++++-- lib/frostdart_bindings_generated.dart | 64 ++++++++++++++++-------- lib/output.dart | 8 ++- 5 files changed, 134 insertions(+), 53 deletions(-) diff --git a/example/lib/frost_sample_run.dart b/example/lib/frost_sample_run.dart index d68530f..c1693d4 100644 --- a/example/lib/frost_sample_run.dart +++ b/example/lib/frost_sample_run.dart @@ -28,8 +28,15 @@ abstract class FrostSampleRunner { "9a4885239b97aa945d8c3a4e560ad2067074825122dd036a7aa3a78f3f5c" "f6e2109a4885239b97aa945d8c3a4e560ad2067074825122dd"); - final address = - addressForKeys(network: network, keys: deserializedKeysAlice); + final address = addressForKeys( + network: network, + keys: deserializedKeysAlice, + addressDerivationData: ( + account: 0, + change: false, + index: 0, + ), + ); debugPrint("Address: $address"); @@ -44,6 +51,11 @@ abstract class FrostSampleRunner { ), vout: 1, value: 200000000, + addressDerivationData: ( + account: 0, + change: false, + index: 0, + ), scriptPubKey: Uint8List.fromList( hexStringToList( "5120105968eaa94d798d554d76a381fd65060696c3685ca1434e4d3ba82bd3f5bde0", diff --git a/example/pubspec.lock b/example/pubspec.lock index 862fd4f..85bd2a3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: @@ -90,14 +90,30 @@ packages: relative: true source: path version: "0.0.1" - js: + leak_tracker: dependency: transitive description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" lints: dependency: transitive description: @@ -110,34 +126,34 @@ packages: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.12.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" plugin_platform_interface: dependency: transitive description: @@ -155,26 +171,26 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -195,10 +211,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.7.0" vector_math: dependency: transitive description: @@ -207,6 +223,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + url: "https://pub.dev" + source: hosted + version: "14.2.1" sdks: - dart: ">=3.0.5 <4.0.0" - flutter: ">=3.10.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/frostdart.dart b/lib/frostdart.dart index 7f47197..f429b64 100644 --- a/lib/frostdart.dart +++ b/lib/frostdart.dart @@ -336,6 +336,7 @@ Output signInput({ required String signConfig, required int network, required int index, + required AddressDerivationData addressDerivationData, }) { final signConfigPointer = decodeSignConfig( network: network, @@ -362,6 +363,7 @@ Output signInput({ vout: vout, value: value, scriptPubKey: scriptPubKey, + addressDerivationData: addressDerivationData, ); } @@ -391,11 +393,24 @@ String signPaymentAddress({ String addressForKeys({ required int network, required ffi.Pointer keys, + required AddressDerivationData addressDerivationData, }) { - final ownedString = _bindings.address_for_keys(network, keys); - final string = ownedString.toDartString(); - freeOwnedString(ownedString); - return string; + final result = _bindings.address_for_keys( + network, + keys, + addressDerivationData.account, + addressDerivationData.index, + addressDerivationData.change, + ); + if (result.err != SUCCESS) { + throw FrostdartException(errorCode: result.err); + } else { + final ownedString = result.value.ref; + final string = ownedString.toDartString(); + freeOwnedString(ownedString); + calloc.free(result.value); + return string; + } } String scriptPubKeyForKeys({ @@ -449,6 +464,10 @@ String newSignConfig({ final outputsPointer = calloc(outputs.length); for (int i = 0; i < outputs.length; i++) { + outputsPointer[i].account = outputs[i].addressDerivationData.account; + outputsPointer[i].change = outputs[i].addressDerivationData.change; + outputsPointer[i].address = outputs[i].addressDerivationData.index; + outputsPointer[i].vout = outputs[i].vout; outputsPointer[i].value = outputs[i].value; diff --git a/lib/frostdart_bindings_generated.dart b/lib/frostdart_bindings_generated.dart index e689437..709f795 100644 --- a/lib/frostdart_bindings_generated.dart +++ b/lib/frostdart_bindings_generated.dart @@ -78,9 +78,9 @@ class FrostdartBindings { } late final _multisig_participantsPtr = _lookup< - ffi.NativeFunction< - ffi.UintPtr Function( - ffi.Pointer)>>('multisig_participants'); + ffi + .NativeFunction)>>( + 'multisig_participants'); late final _multisig_participants = _multisig_participantsPtr .asFunction)>(); @@ -125,9 +125,9 @@ class FrostdartBindings { } late final _encode_multisig_configPtr = _lookup< - ffi.NativeFunction< - OwnedString Function( - ffi.Pointer)>>('encode_multisig_config'); + ffi + .NativeFunction)>>( + 'encode_multisig_config'); late final _encode_multisig_config = _encode_multisig_configPtr .asFunction)>(); @@ -354,28 +354,39 @@ class FrostdartBindings { } late final _deserialize_keysPtr = _lookup< - ffi.NativeFunction< - CResult_ThresholdKeysWrapper Function( - StringView)>>('deserialize_keys'); + ffi + .NativeFunction>( + 'deserialize_keys'); late final _deserialize_keys = _deserialize_keysPtr .asFunction(); - OwnedString address_for_keys( + CResult_OwnedString address_for_keys( int network, ffi.Pointer keys, + int account, + int address, + bool change, ) { return _address_for_keys( network, keys, + account, + address, + change, ); } late final _address_for_keysPtr = _lookup< ffi.NativeFunction< - OwnedString Function(ffi.Int32, - ffi.Pointer)>>('address_for_keys'); + CResult_OwnedString Function( + ffi.Int32, + ffi.Pointer, + ffi.Uint32, + ffi.Uint32, + ffi.Bool)>>('address_for_keys'); late final _address_for_keys = _address_for_keysPtr.asFunction< - OwnedString Function(int, ffi.Pointer)>(); + CResult_OwnedString Function( + int, ffi.Pointer, int, int, bool)>(); OwnedString script_pubkey_for_keys( ffi.Pointer keys, @@ -623,9 +634,9 @@ class FrostdartBindings { } late final _decode_sign_configPtr = _lookup< - ffi.NativeFunction< - CResult_SignConfig Function( - ffi.Int32, StringView)>>('decode_sign_config'); + ffi + .NativeFunction>( + 'decode_sign_config'); late final _decode_sign_config = _decode_sign_configPtr .asFunction(); @@ -718,9 +729,9 @@ class FrostdartBindings { } late final _resharer_resharersPtr = _lookup< - ffi.NativeFunction< - ffi.UintPtr Function( - ffi.Pointer)>>('resharer_resharers'); + ffi + .NativeFunction)>>( + 'resharer_resharers'); late final _resharer_resharers = _resharer_resharersPtr .asFunction)>(); @@ -750,9 +761,9 @@ class FrostdartBindings { } late final _resharer_new_participantsPtr = _lookup< - ffi.NativeFunction< - ffi.UintPtr Function( - ffi.Pointer)>>('resharer_new_participants'); + ffi + .NativeFunction)>>( + 'resharer_new_participants'); late final _resharer_new_participants = _resharer_new_participantsPtr .asFunction)>(); @@ -1066,6 +1077,15 @@ final class PortableOutput extends ffi.Struct { @ffi.UintPtr() external int script_pubkey_len; + + @ffi.Uint32() + external int account; + + @ffi.Uint32() + external int address; + + @ffi.Bool() + external bool change; } final class CResult_SignConfig extends ffi.Struct { diff --git a/lib/output.dart b/lib/output.dart index 58bdece..19cd593 100644 --- a/lib/output.dart +++ b/lib/output.dart @@ -1,16 +1,21 @@ import 'dart:typed_data'; +typedef AddressDerivationData = ({int account, bool change, int index}); + class Output { final Uint8List hash; final int vout; final int value; final Uint8List scriptPubKey; + final AddressDerivationData addressDerivationData; + Output({ required this.hash, required this.vout, required this.value, required this.scriptPubKey, + required this.addressDerivationData, }); @override @@ -18,6 +23,7 @@ class Output { 'hash: $hash, ' 'vout: $vout, ' 'value: $value, ' - 'scriptPubKey: $scriptPubKey' + 'scriptPubKey: $scriptPubKey, ' + 'addressDerivationData: $addressDerivationData' '}'; } From d26f220638a32ef1ee0f2055db83843fe68624ad Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 16 Jul 2024 16:11:04 -0600 Subject: [PATCH 3/4] clean up derivation data --- lib/frostdart.dart | 9 ++++----- lib/output.dart | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/frostdart.dart b/lib/frostdart.dart index f429b64..2bbd49e 100644 --- a/lib/frostdart.dart +++ b/lib/frostdart.dart @@ -336,7 +336,6 @@ Output signInput({ required String signConfig, required int network, required int index, - required AddressDerivationData addressDerivationData, }) { final signConfigPointer = decodeSignConfig( network: network, @@ -363,7 +362,7 @@ Output signInput({ vout: vout, value: value, scriptPubKey: scriptPubKey, - addressDerivationData: addressDerivationData, + addressDerivationData: null, ); } @@ -464,9 +463,9 @@ String newSignConfig({ final outputsPointer = calloc(outputs.length); for (int i = 0; i < outputs.length; i++) { - outputsPointer[i].account = outputs[i].addressDerivationData.account; - outputsPointer[i].change = outputs[i].addressDerivationData.change; - outputsPointer[i].address = outputs[i].addressDerivationData.index; + outputsPointer[i].account = outputs[i].addressDerivationData!.account; + outputsPointer[i].change = outputs[i].addressDerivationData!.change; + outputsPointer[i].address = outputs[i].addressDerivationData!.index; outputsPointer[i].vout = outputs[i].vout; outputsPointer[i].value = outputs[i].value; diff --git a/lib/output.dart b/lib/output.dart index 19cd593..7f4f56d 100644 --- a/lib/output.dart +++ b/lib/output.dart @@ -8,7 +8,7 @@ class Output { final int value; final Uint8List scriptPubKey; - final AddressDerivationData addressDerivationData; + final AddressDerivationData? addressDerivationData; Output({ required this.hash, From 43c2cbceb92b483dec1b3eac904fabe92a9881a3 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 17 Jul 2024 08:08:38 -0600 Subject: [PATCH 4/4] disable unused --- lib/frostdart.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/frostdart.dart b/lib/frostdart.dart index 2bbd49e..a61e932 100644 --- a/lib/frostdart.dart +++ b/lib/frostdart.dart @@ -412,14 +412,14 @@ String addressForKeys({ } } -String scriptPubKeyForKeys({ - required ffi.Pointer keys, -}) { - final ownedString = _bindings.script_pubkey_for_keys(keys); - final string = ownedString.toDartString(); - freeOwnedString(ownedString); - return string; -} +// String scriptPubKeyForKeys({ +// required ffi.Pointer keys, +// }) { +// final ownedString = _bindings.script_pubkey_for_keys(keys); +// final string = ownedString.toDartString(); +// freeOwnedString(ownedString); +// return string; +// } int signPaymentAmount({ required ffi.Pointer signConfigPointer,