Skip to content

Commit 77cfeff

Browse files
committed
V4.3.0
- Added support for MuSig2 - Signing and verification - Nonce generation - Aggregate public key computation - Aggregate nonce computation
1 parent 6258bdd commit 77cfeff

32 files changed

+1956
-52
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 4.3.0
2+
3+
- Added support for MuSig2
4+
- Signing and verification
5+
- Nonce generation
6+
- Aggregate public key computation
7+
- Aggregate nonce computation
8+
19
## 4.2.0
210

311
- Added support for aptos addresses using Secp256k1, Secp256r1, Multikey and MultiEd25519.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ These features make your package a comprehensive solution for encoding, cryptogr
149149
- XRP (EDDSA, ECDSA)
150150
- Solana (EDDSA, EDDSA Khalow)
151151

152+
26. **MuSig2 Operation:**
153+
154+
- Signing and verification
155+
- Nonce generation
156+
- Aggregate public key computation
157+
- Aggregate nonce computation
158+
152159
**Example: Explore Our Toolkit**
153160

154161
Discover the capabilities of our comprehensive crypto and blockchain toolkit through interactive tests. Visit our [test page](https://github.com/mrtnetwork/blockchain_utils/tree/main/test) to access thousands of examples, showcasing pure Dart's cross-platform functionality. Learn encoding, cryptography, address management, mnemonics, and more.

lib/bip/address/p2tr_addr.dart

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ class P2TRUtils {
8282
///
8383
/// Throws:
8484
/// - Exception if the x-coordinate cannot be lifted.
85-
static ProjectiveECCPoint liftX(ProjectiveECCPoint pubKeyPoint) {
85+
static ProjectiveECCPoint liftX(BigInt x) {
8686
final BigInt p = Curves.curveSecp256k1.p;
87-
final BigInt x = pubKeyPoint.x;
8887
if (x >= p) {
8988
throw const AddressConverterException("Unable to compute LiftX point");
9089
}
@@ -155,28 +154,12 @@ class P2TRUtils {
155154
final tweek = taggedHash("TapTweak", [...keyX, ...merkleRoot]);
156155
return tweek;
157156
}
158-
// /// Tweak a public key to create a P2TR address.
159-
// ///
160-
// /// This method tweaks a public key using a hashTapTweak and lifting the x-coordinate.
161-
// ///
162-
// /// Parameters:
163-
// /// - pubKey: The public key to be tweaked.
164-
// ///
165-
// /// Returns:
166-
// /// A `List<int>` representing the tweaked public key for P2TR.
167-
// static `List<int>` tweakPublicKey(ProjectiveECCPoint pubPoint) {
168-
// final h = hashTapTweak(pubPoint);
169-
// final n = Curves.generatorSecp256k1 * BigintUtils.fromBytes(h);
170-
// final outPoint = liftX(pubPoint) + n;
171-
// return BigintUtils.toBytes(outPoint.x,
172-
// length: Curves.curveSecp256k1.baselen);
173-
// }
174157

175158
static ProjectiveECCPoint tweakPublicKey(ProjectiveECCPoint pubPoint,
176159
{List<dynamic>? script}) {
177160
final h = calculateTweek(pubPoint, script: script);
178161
final n = Curves.generatorSecp256k1 * BigintUtils.fromBytes(h);
179-
final outPoint = liftX(pubPoint) + n;
162+
final outPoint = liftX(pubPoint.x) + n;
180163

181164
return outPoint as ProjectiveECCPoint;
182165
}

lib/bip/bip/bip32/bip32_path.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Bip32Path {
104104
if (!elem.isHardened) {
105105
pathStr += "${elem.toInt()}/";
106106
} else {
107-
pathStr += "${Bip32KeyIndex.unhardenIndex(elem.toInt())}'/";
107+
pathStr += "${Bip32KeyIndex.unhardenIndex(elem.toInt()).toInt()}'/";
108108
}
109109
}
110110
return pathStr.substring(0, pathStr.length - 1);

lib/crypto/crypto/cdsa/cdsa.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ export 'point/ec_projective_point.dart';
2424
/// Export statement for RFC 6979, which provides deterministic ECDSA signatures,
2525
/// allowing for secure signature generation.
2626
export 'rfc6979/rfc6979.dart';
27-
2827
export 'crypto_ops/crypto_ops.dart';
28+
29+
export 'musig2/musig2.dart';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:blockchain_utils/blockchain_utils.dart';
2+
import 'package:blockchain_utils/crypto/crypto/cdsa/curve/curve.dart';
3+
4+
class MuSig2Const {
5+
static const int xOnlyBytesLength = 32;
6+
static const int partialSignatureLength = 32;
7+
static const int minimumRequiredKey = 2;
8+
static const int pubnonceLength = 66;
9+
// static const int schnorrSignatureLength = 64;
10+
static const int secnoncelength =
11+
QuickCrypto.sha256DigestSize * 2 + EcdsaKeysConst.pubKeyCompressedByteLen;
12+
static final CurveFp curve = Curves.curveSecp256k1;
13+
static final BigInt order = Curves.generatorSecp256k1.order!;
14+
static final ProjectiveECCPoint generator = Curves.generatorSecp256k1;
15+
static final List<int> zero =
16+
List.unmodifiable(List.filled(EcdsaKeysConst.pubKeyCompressedByteLen, 0));
17+
static const String deterministicNonceDomain = "MuSig/deterministic/nonce";
18+
static const String auxDomain = "MuSig/deterministic/nonce";
19+
static const String noncecoefDomain = 'MuSig/noncecoef';
20+
static const String challengeDomain = 'BIP0340/challenge';
21+
static const String keyAggListDomain = 'KeyAgg list';
22+
static const String keyAggCoeffDomain = 'KeyAgg coefficient';
23+
static const String nonceDomain = 'MuSig/nonce';
24+
static const String musigAuxDomain = "MuSig/aux";
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'package:blockchain_utils/exception/exceptions.dart';
2+
3+
class MuSig2Exception extends BlockchainUtilsException {
4+
const MuSig2Exception(super.message, {super.details});
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export 'musig2/musig2.dart';
2+
export 'exception/exception.dart';
3+
export 'types/types.dart';
4+
export 'utils/utils.dart';

0 commit comments

Comments
 (0)