@@ -6,26 +6,25 @@ import 'package:pointycastle/export.dart' as pointy;
66
77/// [PublicKey] using EC Algorithm
88class ECPublicKey implements PublicKey {
9- pointy.ECPublicKey _publicKey;
9+ final pointy.ECPublicKey _publicKey;
1010 static final pointy.ECDomainParameters curve = pointy.ECCurve_secp256k1 ();
1111
1212 /// Create an [ECPublicKey] for the given coordinates.
13- ECPublicKey (BigInt x, BigInt y) {
14- var Q = ECPoint (x, y, true );
15- _publicKey = pointy.ECPublicKey (Q .asPointyCastle, curve);
16- }
13+ ECPublicKey (BigInt x, BigInt y)
14+ : _publicKey =
15+ pointy.ECPublicKey (ECPoint (x, y, true ).asPointyCastle, curve);
1716
1817 /// Create an [ECPublicKey] from the given String.
19- ECPublicKey .fromString (String publicKeyString) {
20- var Q = curve.curve.decodePoint (base64Decode (publicKeyString));
21- _publicKey = pointy.ECPublicKey (Q , curve);
22- }
18+ ECPublicKey .fromString (String publicKeyString)
19+ : _publicKey = pointy.ECPublicKey (
20+ curve.curve.decodePoint (base64Decode (publicKeyString)), curve);
2321
2422 /// Verify the signature of a SHA256-hashed message signed with the associated [ECPrivateKey]
2523 @Deprecated ('For SHA256 signature verification use verifySHA256Signature' )
2624 @override
2725 bool verifySignature (String message, String signature) =>
28- verifySHA256Signature (utf8.encode (message), utf8.encode (signature));
26+ verifySHA256Signature (utf8.encode (message) as Uint8List ,
27+ utf8.encode (signature) as Uint8List );
2928
3029 /// Verify the signature of a SHA256-hashed message signed with the associated [ECPrivateKey]
3130 @override
@@ -39,30 +38,30 @@ class ECPublicKey implements PublicKey {
3938
4039 bool _verifySignature (
4140 Uint8List message, Uint8List signatureString, String algorithm) {
42- var sigLength = (signatureString.length / 2 ).round ();
43- var r = BigInt .parse (
41+ final sigLength = (signatureString.length / 2 ).round ();
42+ final r = BigInt .parse (
4443 utf8.decode (signatureString.sublist (0 , sigLength)),
4544 radix: 16 ,
4645 );
47- var s = BigInt .parse (
46+ final s = BigInt .parse (
4847 utf8.decode (signatureString.sublist (sigLength)),
4948 radix: 16 ,
5049 );
51- var signature = pointy.ECSignature (r, s);
52- var signer = pointy.Signer (algorithm);
50+ final signature = pointy.ECSignature (r, s);
51+ final signer = pointy.Signer (algorithm);
5352 signer.init (false , pointy.PublicKeyParameter (_publicKey));
5453 return signer.verifySignature (message, signature);
5554 }
5655
5756 /// Get [ECPoint] Q, which is the Public Point
58- ECPoint get Q => ECPoint (_publicKey.Q .x .toBigInteger (),
59- _publicKey.Q .y .toBigInteger (), _publicKey.Q .isCompressed);
57+ ECPoint get Q => ECPoint (_publicKey.Q ! .x ! .toBigInteger ()! ,
58+ _publicKey.Q ! .y ! .toBigInteger ()! , _publicKey.Q ! .isCompressed);
6059
6160 /// Export a [ECPublicKey] as Pointy Castle ECPublicKey
6261 @override
6362 pointy.ECPublicKey get asPointyCastle => _publicKey;
6463
6564 /// Export a [ECPublicKey] as String which can be reversed using [ECPublicKey.fromString] .
6665 @override
67- String toString () => base64Encode (_publicKey.Q .getEncoded ());
66+ String toString () => base64Encode (_publicKey.Q ! .getEncoded ());
6867}
0 commit comments