Skip to content

Commit 4fab39e

Browse files
committed
publicKeyToPoint() helper.
1 parent 23216b5 commit 4fab39e

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

lib/src/bip340.dart

+2-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,8 @@ String sign(String privateKey, String message, String aux) {
7373
/// signature must be 64-bytes hex-encoded, i.e., 128 characters.
7474
/// It returns true if the signature is valid, false otherwise.
7575
/// For more information on BIP-340 see bips.xyz/340.
76-
bool verify(String? publicKey, String message, String signature) {
77-
// turn public key into a point (we only get y, but we find out the y)
78-
BigInt x = bigFromBytes(hex.decode(publicKey!.padLeft(64, '0')));
79-
BigInt y;
80-
try {
81-
y = liftX(x);
82-
} on Error {
83-
return false;
84-
}
85-
ECPoint P = secp256k1.curve.createPoint(x, y);
86-
87-
return verifyWithPoint(P, message, signature);
76+
bool verify(String publicKey, String message, String signature) {
77+
return verifyWithPoint(publicKeyToPoint(publicKey), message, signature);
8878
}
8979

9080
bool verifyWithPoint(ECPoint P, String message, String signature) {

lib/src/helpers.dart

+7
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ BigInt getE(ECPoint P, List<int> rX, List<int> m) {
5050
) %
5151
secp256k1.n;
5252
}
53+
54+
ECPoint publicKeyToPoint(String publicKey) {
55+
// turn public key into a point (we only get y, but we find out the y)
56+
BigInt x = bigFromBytes(hex.decode(publicKey.padLeft(64, '0')));
57+
BigInt y = liftX(x);
58+
return secp256k1.curve.createPoint(x, y);
59+
}

0 commit comments

Comments
 (0)