Skip to content

Commit 757a2ed

Browse files
committed
Prepare coinlib_flutter for testing MuSig2
1 parent d4574e0 commit 757a2ed

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

coinlib_flutter/example/lib/main.dart

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,49 @@ class MyApp extends StatelessWidget {
4141
prefix: coinlib.Network.mainnet.messagePrefix,
4242
);
4343

44-
final schnorrSignature = coinlib.SchnorrSignature.sign(
45-
privKey, Uint8List(32),
44+
// MuSig with adaptor signature example
45+
46+
int otherI(int i) => i == 0 ? 1 : 0;
47+
48+
final muSigPrivKeys = List.generate(
49+
2,
50+
(i) => coinlib.ECPrivateKey(Uint8List(32)..last = i+1),
51+
);
52+
final muSigPrivs = List.generate(
53+
2,
54+
(i) => coinlib.MuSigPrivate(
55+
muSigPrivKeys[i],
56+
{ muSigPrivKeys[otherI(i)].pubkey },
57+
),
58+
);
59+
final muSigSessions = List.generate(
60+
2,
61+
(i) => coinlib.MuSigStatefulSigningSession(
62+
keys: muSigPrivs[i].public,
63+
ourPublicKey: muSigPrivKeys[i].pubkey,
64+
),
65+
);
66+
final partialSigs = List.generate(
67+
2,
68+
(i) => muSigSessions[i].sign(
69+
otherNonces: {
70+
muSigPrivKeys[otherI(i)].pubkey:
71+
muSigSessions[otherI(i)].ourPublicNonce,
72+
},
73+
hash: Uint8List(32),
74+
privKey: muSigPrivKeys[i],
75+
adaptor: privKey.pubkey,
76+
),
77+
);
78+
79+
muSigSessions.first.addPartialSignature(
80+
partialSig: partialSigs.last,
81+
participantKey: muSigPrivKeys.last.pubkey,
4682
);
83+
final adaptorSig = (
84+
muSigSessions.first.finish() as coinlib.MuSigResultAdaptor
85+
).adaptorSignature;
86+
final finalSig = adaptorSig.adapt(privKey);
4787

4888
return Column(
4989
spacing: 10,
@@ -56,8 +96,8 @@ class MyApp extends StatelessWidget {
5696
" $msgSignature."
5797
),
5898
Text(
59-
"An example Schnorr signature is"
60-
" ${coinlib.bytesToHex(schnorrSignature.data)}."
99+
"An example MuSig2 Schnorr signature is"
100+
" ${coinlib.bytesToHex(finalSig.data)}."
61101
),
62102
],
63103
);

coinlib_flutter/example/pubspec.lock

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@ packages:
3636
coinlib:
3737
dependency: transitive
3838
description:
39-
name: coinlib
40-
sha256: cf8bf904f49339fd5ccd8c51dbdb099c5a616072507076bab724239d2e34b97e
41-
url: "https://pub.dev"
42-
source: hosted
43-
version: "4.0.0"
39+
path: "../../coinlib"
40+
relative: true
41+
source: path
42+
version: "4.1.0"
4443
coinlib_flutter:
4544
dependency: "direct main"
4645
description:
4746
path: ".."
4847
relative: true
4948
source: path
50-
version: "4.0.0"
49+
version: "5.0.0"
5150
collection:
5251
dependency: transitive
5352
description:
@@ -295,14 +294,6 @@ packages:
295294
url: "https://pub.dev"
296295
source: hosted
297296
version: "14.3.1"
298-
wasm_interop:
299-
dependency: transitive
300-
description:
301-
name: wasm_interop
302-
sha256: b1b378f07a4cf0103c25faf34d9a64d2c3312135b9efb47e0ec116ec3b14e48f
303-
url: "https://pub.dev"
304-
source: hosted
305-
version: "2.0.1"
306297
sdks:
307298
dart: ">=3.8.0-0 <4.0.0"
308299
flutter: ">=3.18.0-18.0.pre.54"

coinlib_flutter/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ name: coinlib_flutter
22
description:
33
A flutter wrapper for coinlib, a straight-forward, modular library for
44
Peercoin and other Satoshi-based UTXO blockchains
5-
version: 4.0.0
5+
version: 5.0.0
66
repository: https://github.com/peercoin/coinlib
77

88
environment:
99
sdk: '>=3.2.0 <4.0.0'
1010
flutter: ">=2.17.0"
1111

1212
dependencies:
13-
coinlib: ^4.0.0
13+
coinlib:
14+
path: ../coinlib
1415
flutter:
1516
sdk: flutter
1617
plugin_platform_interface: ^2.0.2

0 commit comments

Comments
 (0)