Skip to content

Commit 9986dc3

Browse files
committed
Add stricter analysis options and fix problems
1 parent 73b6c57 commit 9986dc3

40 files changed

Lines changed: 92 additions & 76 deletions

coinlib/analysis_options.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
include: package:lints/recommended.yaml
22

3+
analyzer:
4+
language:
5+
strict-casts: true
6+
strict-inference: true
7+
strict-raw-types: true
8+
39
# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
410
linter:
511
rules:
@@ -10,3 +16,4 @@ linter:
1016
- unrelated_type_equality_checks
1117
- valid_regexps
1218
- require_trailing_commas
19+
- comment_references

coinlib/lib/src/common/bytes.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ Uint8List copyCheckBytes(
1616
Uint8List bytes, int length, { String name = "Bytes", }
1717
) => Uint8List.fromList(checkBytes(bytes, length, name: name));
1818

19-
/// Determines if two objects are equal Uint8List data
20-
bool bytesEqual(Object? a, Object? b)
21-
=> (a is Uint8List) && (b is Uint8List) && ListEquality().equals(a, b);
19+
/// Determines if two [Uint8List] lists are equal
20+
bool bytesEqual(Uint8List a, Uint8List b) => ListEquality<int>().equals(a, b);
2221

2322
/// Compares two Uint8List bytes from the left-most to right-most byte. If all
2423
/// bytes are the same apart from one list being longer, the shortest list comes

coinlib/lib/src/common/checks.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

2-
_checkInt(int i, int min, int max, String type, String name) {
2+
void _checkInt(int i, int min, int max, String type, String name) {
33
if (i < min || i > max) {
44
throw ArgumentError.value(i, name, "must be a $type");
55
}
66
}
77

8-
checkUint8(int i, [String name = "i"])
8+
void checkUint8(int i, [String name = "i"])
99
=> _checkInt(i, 0, 0xff, "uint8", name);
1010

11-
checkUint16(int i, [String name = "i"])
11+
void checkUint16(int i, [String name = "i"])
1212
=> _checkInt(i, 0, 0xffff, "uint16", name);
1313

14-
checkUint32(int i, [String name = "i"])
14+
void checkUint32(int i, [String name = "i"])
1515
=> _checkInt(i, 0, 0xffffffff, "uint32", name);
1616

17-
checkInt32(int i, [String name = "i"])
17+
void checkInt32(int i, [String name = "i"])
1818
=> _checkInt(i, -0x80000000, 0x7fffffff, "int32", name);
1919

2020
final BigInt maxUint64 = (BigInt.from(1) << 64) - BigInt.one;
2121

22-
checkUint64(BigInt i, [String name = "i"]) {
22+
void checkUint64(BigInt i, [String name = "i"]) {
2323
if (i.isNegative || i > maxUint64) {
2424
throw ArgumentError.value(i, name, "must be a uint64");
2525
}

coinlib/lib/src/crypto/ec_public_key.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:typed_data';
22
import 'package:coinlib/src/secp256k1/secp256k1.dart';
33
import 'package:coinlib/src/common/bytes.dart';
44
import 'package:coinlib/src/common/hex.dart';
5-
import 'package:collection/collection.dart';
65

76
class InvalidPublicKey implements Exception {}
87

@@ -70,7 +69,7 @@ class ECPublicKey {
7069

7170
@override
7271
bool operator ==(Object other)
73-
=> (other is ECPublicKey) && ListEquality().equals(_data, other._data);
72+
=> (other is ECPublicKey) && bytesEqual(_data, other._data);
7473

7574
@override
7675
int get hashCode => _data[1] | _data[2] << 8 | _data[3] << 16 | _data[4] << 24;

coinlib/lib/src/crypto/ecdsa_signature.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ECDSASignature {
4545
}
4646
}
4747

48-
/// Takes a BIP66 DER formatted [signature] as a HEX string.
48+
/// Takes a BIP66 DER formatted signature as a HEX string.
4949
/// See [ECDSASignature.fromDer].
5050
factory ECDSASignature.fromDerHex(String hex)
5151
=> ECDSASignature.fromDer(hexToBytes(hex));

coinlib/lib/src/crypto/message_signature.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MagicHash with Writable {
1414
final String prefix;
1515
MagicHash(this.message, this.prefix);
1616

17-
static _writeUtf8(Writer writer, String msg)
17+
static void _writeUtf8(Writer writer, String msg)
1818
=> writer.writeVarSlice(utf8.encode(msg));
1919

2020
@override
@@ -33,7 +33,7 @@ class MessageSignature {
3333

3434
final ECDSARecoverableSignature signature;
3535

36-
static magicHash(String message, String prefix)
36+
static Uint8List magicHash(String message, String prefix)
3737
=> MagicHash(message, prefix).hash;
3838

3939
MessageSignature.fromBase64(String str)

coinlib/lib/src/crypto/nums_public_key.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import 'package:coinlib/src/crypto/random.dart';
44

55
/// A "nothing up my sleeve" [ECPublicKey] that is created from a point with no
66
/// known private key and tweaked with a scalar value named [rTweak]. The key is
7-
/// reproduceable from this scalar using [fromRTweak]. Any of these keys have no
8-
/// known associted private key. Sharing the [rTweak] allows others to verify
9-
/// this. These keys can be used as Taproot internal keys where no key-path
10-
/// spending is desired.
7+
/// reproduceable from this scalar using [fromRTweak()]. Any of
8+
/// these keys have no known associted private key. Sharing the [rTweak] allows
9+
/// others to verify this. These keys can be used as Taproot internal keys where
10+
/// no key-path spending is desired.
1111
class NUMSPublicKey extends ECPublicKey {
1212

1313
/// To prove that this point does not have an associated private key, the

coinlib/lib/src/scripts/operations.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:typed_data';
2+
import 'package:coinlib/src/common/bytes.dart';
23
import 'package:coinlib/src/common/hex.dart';
34
import 'package:coinlib/src/common/serial.dart';
45
import 'package:coinlib/src/crypto/ec_public_key.dart';
56
import 'package:coinlib/src/tx/inputs/input_signature.dart';
6-
import 'package:collection/collection.dart';
77
import 'codes.dart';
88

99
class InvalidScriptAsm implements Exception {}
@@ -312,7 +312,7 @@ class ScriptPushData implements ScriptOp {
312312

313313
@override
314314
bool match(ScriptOp other)
315-
=> (other is ScriptPushData && ListEquality().equals(_data, other._data))
315+
=> (other is ScriptPushData && bytesEqual(_data, other._data))
316316
|| (other is ScriptPushDataMatcher && _data.length == other.size);
317317

318318
}

coinlib/lib/src/scripts/program.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ abstract class Program {
2020

2121
/// Takes a [script] and constructs a matching Program subclass if one exists,
2222
/// or a basic [RawProgram] if there is no match. The script should use
23-
/// minimal pushes. [decompile] can be used directly on compiled scripts or
24-
/// [fromAsm] can be used to match directly against ASM.
23+
/// minimal pushes. [Program.decompile] can be used directly on compiled
24+
/// scripts or [Program.fromAsm] can be used to match directly against ASM.
2525
factory Program.match(Script script) {
2626

2727
try {

coinlib/lib/src/scripts/programs/p2sh.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class P2SH implements Program {
1515
late final Uint8List _scriptHash;
1616

1717
/// Construct using an output script, not to be confused with the redeem
18-
/// script. For that use [fromRedeemScript].
18+
/// script. For that use [fromRedeemScript()].
1919
P2SH.fromScript(this.script) {
2020
if (!template.match(script)) throw NoProgramMatch();
2121
_scriptHash = (script[1] as ScriptPushData).data;

0 commit comments

Comments
 (0)