Skip to content

Commit 8527d80

Browse files
committed
V4.4.0
- Added support for BCH schnor signig and verifying - Fix schnorr signature validation
1 parent 77cfeff commit 8527d80

33 files changed

+1259
-662
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.4.0
2+
- Added support for BCH schnor signig and verifying
3+
- Fix schnorr signature validation
4+
15
## 4.3.0
26

37
- Added support for MuSig2

example/pubspec.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ packages:
4444
path: ".."
4545
relative: true
4646
source: path
47-
version: "4.0.0"
47+
version: "4.3.0"
4848
boolean_selector:
4949
dependency: transitive
5050
description:
@@ -57,18 +57,18 @@ packages:
5757
dependency: transitive
5858
description:
5959
name: characters
60-
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
60+
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
6161
url: "https://pub.dev"
6262
source: hosted
63-
version: "1.3.0"
63+
version: "1.4.0"
6464
collection:
6565
dependency: transitive
6666
description:
6767
name: collection
68-
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
68+
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
6969
url: "https://pub.dev"
7070
source: hosted
71-
version: "1.19.0"
71+
version: "1.19.1"
7272
convert:
7373
dependency: transitive
7474
description:
@@ -214,10 +214,10 @@ packages:
214214
dependency: transitive
215215
description:
216216
name: meta
217-
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
217+
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
218218
url: "https://pub.dev"
219219
source: hosted
220-
version: "1.15.0"
220+
version: "1.16.0"
221221
mime:
222222
dependency: transitive
223223
description:
@@ -456,4 +456,4 @@ packages:
456456
source: hosted
457457
version: "3.1.2"
458458
sdks:
459-
dart: ">=3.4.0 <4.0.0"
459+
dart: ">=3.7.0-0 <4.0.0"

lib/crypto/crypto/cdsa/curve/curve.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CurveFp extends Curve {
3232
/// Check if two CurveFp objects are equal based on their properties
3333
@override
3434
operator ==(other) {
35+
if (identical(this, other)) return true;
3536
if (other is CurveFp) {
3637
return (p == other.p && a == other.a && b == other.b && h == other.h);
3738
}
@@ -87,8 +88,8 @@ class CurveED extends Curve {
8788
/// Check if two CurveED objects are equal based on their properties
8889
@override
8990
operator ==(other) {
91+
if (identical(this, other)) return true;
9092
if (other is CurveED) {
91-
if (identical(this, other)) return true;
9293
return (p == other.p && a == other.a && d == other.d && h == other.h);
9394
}
9495
return false;

lib/crypto/crypto/cdsa/ecdsa/public_key.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class ECDSAPublicKey {
8383

8484
@override
8585
bool operator ==(Object other) {
86+
if (identical(this, other)) return true;
8687
if (other is ECDSAPublicKey) {
87-
if (identical(this, other)) return true;
8888
return generator.curve == other.generator.curve && point == other.point;
8989
}
9090
return false;

lib/crypto/crypto/cdsa/ecdsa/signature.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ECDSASignature {
2727
/// - r: The `r` component of the signature.
2828
/// - s: The `s` component of the signature.
2929
///
30-
ECDSASignature(this.r, this.s);
30+
const ECDSASignature(this.r, this.s);
3131
@override
3232
String toString() {
3333
return "($r, $s)";
@@ -70,7 +70,7 @@ class ECDSASignature {
7070
return [pk1, pk2];
7171
}
7272

73-
ECDSAPublicKey? recoverPublicKey(
73+
ECDSAPublicKey recoverPublicKey(
7474
List<int> hash, ProjectiveECCPoint generator, int recId) {
7575
final curve = generator.curve;
7676
final order = generator.order!;
@@ -89,6 +89,15 @@ class ECDSASignature {
8989
return ECDSAPublicKey(generator, q1);
9090
}
9191

92+
int? recoverId({required List<int> hash, required ECDSAPublicKey publicKey}) {
93+
final keys = recoverPublicKeys(hash, publicKey.generator);
94+
final recId = keys.indexOf(publicKey);
95+
if (recId.isNegative) {
96+
return null;
97+
}
98+
return recId;
99+
}
100+
92101
List<int> toBytes(int baselen) {
93102
final sBytes = BigintUtils.toBytes(s, length: baselen);
94103
final rBytes = BigintUtils.toBytes(r, length: baselen);

lib/crypto/crypto/cdsa/rfc6979/rfc6979.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ class RFC6979 {
5858
/// Note: The RFC6979 algorithm ensures that K values are generated deterministically
5959
/// and securely, which is essential for cryptographic operations.
6060
static BigInt generateK(
61-
BigInt order, BigInt secexp, HashFunc hashFunc, List<int> data,
62-
{int retryGn = 0, List<int>? extraEntropy}) {
61+
{required BigInt order,
62+
required BigInt secexp,
63+
required HashFunc hashFunc,
64+
required List<int> data,
65+
int retryGn = 0,
66+
List<int>? extraEntropy}) {
6367
final int qlen = order.bitLength;
6468
final hx = hashFunc();
6569
final int holen = hx.getDigestLength;

lib/crypto/crypto/cdsa/utils/utils.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ECDSAUtils {
5858

5959
final jacobiSymbol = jacobi(a, p);
6060

61-
if (jacobiSymbol == BigInt.from(-1)) {
61+
if (jacobiSymbol.isNegative) {
6262
throw SquareRootError("$a has no square root modulo $p");
6363
}
6464

@@ -80,7 +80,7 @@ class ECDSAUtils {
8080
}
8181

8282
for (BigInt b = BigInt.from(2); b < p; b += BigInt.one) {
83-
if (jacobi(b * b - BigInt.from(4) * a, p) == BigInt.from(-1)) {
83+
if (jacobi(b * b - BigInt.from(4) * a, p).isNegative) {
8484
final quadraticForm = [a, -b, BigInt.one];
8585
final result = polynomialExponentiationMod([BigInt.zero, BigInt.one],
8686
(p + BigInt.one) ~/ BigInt.from(2), quadraticForm, p);
@@ -142,20 +142,20 @@ class ECDSAUtils {
142142
///
143143
/// Throws a JacobiError if 'n' is not an odd integer greater than or equal to 3.
144144
///
145-
static BigInt jacobi(BigInt a, BigInt n) {
145+
static int jacobi(BigInt a, BigInt n) {
146146
if (!(n >= BigInt.from(3))) {
147-
throw const JacobiError("n must be larger than 2");
147+
throw const JacobiError("n must be larger than 2.");
148148
}
149149
if (!(n % BigInt.two == BigInt.one)) {
150-
throw const JacobiError("n must be odd");
150+
throw const JacobiError("n must be odd.");
151151
}
152152

153153
a = a % n;
154154
if (a == BigInt.zero) {
155-
return BigInt.zero;
155+
return 0;
156156
}
157157
if (a == BigInt.one) {
158-
return BigInt.one;
158+
return 1;
159159
}
160160

161161
BigInt a1 = a, e = BigInt.zero;
@@ -164,14 +164,14 @@ class ECDSAUtils {
164164
e = e + BigInt.one;
165165
}
166166

167-
BigInt s = BigInt.one;
167+
int s = 1;
168168

169169
if (e % BigInt.two == BigInt.zero ||
170170
n % BigInt.from(8) == BigInt.one ||
171171
n % BigInt.from(8) == BigInt.from(7)) {
172172
// s remains 1
173173
} else {
174-
s = BigInt.from(-1);
174+
s = -1;
175175
}
176176

177177
if (a1 == BigInt.one) {

0 commit comments

Comments
 (0)