Skip to content

Commit 63a6a86

Browse files
committed
ran dart migrate
1 parent 1e27805 commit 63a6a86

26 files changed

+405
-405
lines changed

example/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void main() async {
7575
"original_amount": utxo.satoshis
7676
});
7777

78-
totalBalance += utxo.satoshis;
78+
totalBalance += utxo.satoshis!;
7979
});
8080

8181
// set an address to send the remaining balance to

lib/src/account.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import 'hdnode.dart';
44
class Account {
55
final HDNode accountNode;
66

7-
int currentChild = 0;
7+
int? currentChild = 0;
88

99
Account(this.accountNode, [this.currentChild]);
1010

1111
/// Returns address at the current position
12-
String getCurrentAddress([legacyFormat = true]) {
12+
String? getCurrentAddress([legacyFormat = true]) {
1313
if (legacyFormat) {
14-
return accountNode.derive(currentChild).toLegacyAddress();
14+
return accountNode.derive(currentChild!).toLegacyAddress();
1515
} else {
16-
return accountNode.derive(currentChild).toCashAddress();
16+
return accountNode.derive(currentChild!).toCashAddress();
1717
}
1818
}
1919

2020
/// moves the position forward and returns an address from the new position
21-
String getNextAddress([legacyFormat = true]) {
21+
String? getNextAddress([legacyFormat = true]) {
2222
if (legacyFormat) {
2323
return accountNode.derive(++currentChild).toLegacyAddress();
2424
} else {

lib/src/address.dart

+19-19
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Address {
5454
/// Returns information about the given Bitcoin Cash address.
5555
///
5656
/// See https://developer.bitcoin.com/bitbox/docs/util for details about returned format
57-
static Future<Map<String, dynamic>> validateAddress(String address) async =>
58-
await RestApi.sendGetRequest("util/validateAddress", address);
57+
static Future<Map<String, dynamic>?> validateAddress(String address) async =>
58+
await (RestApi.sendGetRequest("util/validateAddress", address) as FutureOr<Map<String, dynamic>?>);
5959

6060
/// Returns details of the provided address or addresses
6161
///
@@ -90,7 +90,7 @@ class Address {
9090
return Utxo.convertMapListToUtxos(result["utxos"]);
9191
} else if (result is List<Map>) {
9292
final returnList = <Map>[];
93-
final returnMap = <String, List>{};
93+
final returnMap = <String?, List>{};
9494

9595
result.forEach((addressUtxoMap) {
9696
if (returnAsMap) {
@@ -123,7 +123,7 @@ class Address {
123123
return Utxo.convertMapListToUtxos(result["utxos"]);
124124
} else if (result is List) {
125125
final returnList = <Map>[];
126-
final returnMap = <String, List>{};
126+
final returnMap = <String?, List>{};
127127

128128
result.forEach((addressUtxoMap) {
129129
if (returnAsMap) {
@@ -147,7 +147,7 @@ class Address {
147147
final decoded = _decode(address);
148148
final testnet =
149149
decoded['prefix'] == "bchtest" || decoded['prefix'] == "slptest";
150-
var version;
150+
late var version;
151151
if (testnet) {
152152
switch (decoded['type']) {
153153
case "P2PKH":
@@ -171,7 +171,7 @@ class Address {
171171
}
172172

173173
/// Converts legacy address to cash address
174-
static String toCashAddress(String address, [bool includePrefix = true]) {
174+
static String? toCashAddress(String address, [bool includePrefix = true]) {
175175
final decoded = _decode(address);
176176
switch (decoded["prefix"]) {
177177
case 'bitcoincash':
@@ -195,7 +195,7 @@ class Address {
195195
}
196196

197197
/// Converts legacy or cash address to SLP address
198-
static String toSLPAddress(String address, [bool includePrefix = true]) {
198+
static String? toSLPAddress(String address, [bool includePrefix = true]) {
199199
final decoded = Address._decode(address);
200200
switch (decoded["prefix"]) {
201201
case 'bitcoincash':
@@ -231,7 +231,7 @@ class Address {
231231
}
232232

233233
/// Detects type of the address and returns [legacy], [cashaddr] or [slpaddr]
234-
static String detectAddressFormat(String address) {
234+
static String? detectAddressFormat(String address) {
235235
// decode the address to determine the format
236236
final decoded = _decode(address);
237237
// return the format
@@ -261,7 +261,7 @@ class Address {
261261
/// [prefix] - Network prefix. E.g.: 'bitcoincash'.
262262
/// [type] Type of address to generate. Either 'P2PKH' or 'P2SH'.
263263
/// [hash] is the address hash, which can be decode either using [_decodeCashAddress()] or [_decodeLegacyAddress()]
264-
static _encode(String prefix, String type, Uint8List hash) {
264+
static _encode(String prefix, String? type, Uint8List hash) {
265265
final prefixData = _prefixToUint5List(prefix) + Uint8List(1);
266266
final versionByte = _getTypeBits(type) + _getHashSizeBits(hash);
267267
final payloadData =
@@ -278,7 +278,7 @@ class Address {
278278
assert(addresses is String || addresses is List<String>);
279279

280280
if (addresses is String) {
281-
return await RestApi.sendGetRequest("address/$path", addresses) as Map;
281+
return await RestApi.sendGetRequest("address/$path", addresses) as Map?;
282282
} else if (addresses is List<String>) {
283283
return await RestApi.sendPostRequest(
284284
"address/$path", "addresses", addresses,
@@ -453,7 +453,7 @@ class Address {
453453
throw FormatException("Invalid Address Format: $address");
454454
}
455455

456-
String exception;
456+
late String exception;
457457
// try to decode the address with either one or all three possible prefixes
458458
for (int i = 0; i < prefixes.length; i++) {
459459
final payload = _base32Decode(address);
@@ -514,7 +514,7 @@ class Address {
514514
throw FormatException("Invalid Address Format: $address");
515515
}
516516

517-
String exception;
517+
late String exception;
518518

519519
// try to decode the address with either one or all three possible prefixes
520520
for (int i = 0; i < prefixes.length; i++) {
@@ -642,7 +642,7 @@ class Address {
642642
final value = string[i];
643643
if (!_CHARSET_INVERSE_INDEX.containsKey(value))
644644
throw FormatException("Invalid character '$value'");
645-
data[i] = _CHARSET_INVERSE_INDEX[string[i]];
645+
data[i] = _CHARSET_INVERSE_INDEX[string[i]]!;
646646
}
647647

648648
return data;
@@ -672,12 +672,12 @@ class Address {
672672

673673
/// Container for to make it easier to work with Utxos
674674
class Utxo {
675-
final String txid;
676-
final int vout;
677-
final double amount;
678-
final int satoshis;
679-
final int height;
680-
final int confirmations;
675+
final String? txid;
676+
final int? vout;
677+
final double? amount;
678+
final int? satoshis;
679+
final int? height;
680+
final int? confirmations;
681681

682682
Utxo(this.txid, this.vout, this.amount, this.satoshis, this.height,
683683
this.confirmations);

lib/src/bitcoincash.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BitcoinCash {
4040
return signatureBuffer;
4141
}
4242

43-
static Uint8List getOpReturnScript(String data) {
43+
static Uint8List? getOpReturnScript(String data) {
4444
return compile([Opcodes.OP_RETURN, utf8.encode(data)]);
4545
}
4646
}

lib/src/cashaccounts.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'utils/rest_api.dart';
33
import 'package:http/http.dart' as http;
44

55
class CashAccounts {
6-
static Future<Map> lookup(String account, int number, {int collision}) async {
6+
static Future<Map?> lookup(String account, int number, {int? collision}) async {
77
String col = "";
88
if (collision != null) {
99
col = collision.toString();
@@ -13,19 +13,19 @@ class CashAccounts {
1313
return json.decode(response.body);
1414
}
1515

16-
static Future<Map> check(String account, int number) async {
16+
static Future<Map?> check(String account, int number) async {
1717
final response = await http.get(Uri.parse(
1818
"https://rest.bitcoin.com/v2/cashAccounts/check/$account/$number"));
1919
return json.decode(response.body);
2020
}
2121

22-
static Future<Map> reverseLookup(String cashAddress) async {
22+
static Future<Map?> reverseLookup(String cashAddress) async {
2323
final response = await http.get(Uri.parse(
2424
"https://rest.bitcoin.com/v2/cashAccounts/reverseLookup/$cashAddress"));
2525
return json.decode(response.body);
2626
}
2727

28-
static Future<Map> register(String name, String address) async {
28+
static Future<Map?> register(String name, String address) async {
2929
Map register = {
3030
'name': name,
3131
'payments': [address]
@@ -34,7 +34,7 @@ class CashAccounts {
3434
Uri.parse('https://api.cashaccount.info/register'),
3535
headers: {'Content-Type': 'application/json'},
3636
body: jsonEncode(register));
37-
Map data = jsonDecode(response.body);
37+
Map? data = jsonDecode(response.body);
3838
return data;
3939
}
4040
}

lib/src/crypto/ecies.dart

+13-13
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class Ecies {
3434
/// [recipientPublicKey] - Public Key of the party who can decrypt the message
3535
///
3636
static String encryptData(
37-
{String message,
38-
String senderPrivateKeyHex,
39-
String recipientPublicKeyHex,
37+
{required String message,
38+
required String senderPrivateKeyHex,
39+
required String recipientPublicKeyHex,
4040
String magicValue = "BIE1"}) {
4141
//Encryption requires derivation of a cipher using the other party's Public Key
4242
// Bob is sender, Alice is recipient of encrypted message
@@ -51,10 +51,10 @@ class Ecies {
5151

5252
List<int> messageBuffer = Uint8List.fromList(message.codeUnits);
5353

54-
final ECPoint S = (recipientPublicKey.point *
55-
senderPrivateKey.privateKey); //point multiplication
54+
final ECPoint S = (recipientPublicKey.point! *
55+
senderPrivateKey.privateKey)!; //point multiplication
5656

57-
final pubkeyS = BCHPublicKey.fromXY(S.x.toBigInteger(), S.y.toBigInteger());
57+
final pubkeyS = BCHPublicKey.fromXY(S.x!.toBigInteger()!, S.y!.toBigInteger()!);
5858
final pubkeyBuffer = HEX.decode(pubkeyS.getEncoded(true));
5959
final pubkeyHash = SHA512Digest().process(pubkeyBuffer as Uint8List);
6060

@@ -73,7 +73,7 @@ class Ecies {
7373
final magic = utf8.encode(magicValue);
7474

7575
final encodedBuffer = Uint8List.fromList(
76-
magic + HEX.decode(senderPrivateKey.publicKey.toHex()) + cipherText);
76+
magic + HEX.decode(senderPrivateKey.publicKey!.toHex()) + cipherText);
7777

7878
//calc checksum
7979
final hmac = _calculateHmac(kM, encodedBuffer);
@@ -101,8 +101,8 @@ class Ecies {
101101
/// [recipientPrivateKey] - Private Key of the receiving party
102102
///
103103
static String decryptData(
104-
{String cipherTextStr,
105-
String recipientPrivateKeyHex,
104+
{required String cipherTextStr,
105+
required String recipientPrivateKeyHex,
106106
String magicValue = "BIE1"}) {
107107
//AES Cipher is calculated as
108108
//1) S = recipientPrivateKey o senderPublicKey
@@ -128,8 +128,8 @@ class Ecies {
128128
BCHPublicKey.fromHex(HEX.encode(senderPubkeyBuffer));
129129

130130
//calculate S = recipientPrivateKey o senderPublicKey
131-
final S = (senderPublicKey.point *
132-
recipientPrivateKey.privateKey); //point multiplication
131+
final S = (senderPublicKey.point! *
132+
recipientPrivateKey.privateKey)!; //point multiplication
133133
final cipher = S.x;
134134

135135
if (cipherText.length - _tagLength <= 37) {
@@ -138,7 +138,7 @@ class Ecies {
138138
}
139139

140140
//validate the checksum bytes
141-
final pubkeyS = BCHPublicKey.fromXY(S.x.toBigInteger(), S.y.toBigInteger());
141+
final pubkeyS = BCHPublicKey.fromXY(S.x!.toBigInteger()!, S.y!.toBigInteger()!);
142142
final pubkeyBuffer = HEX.decode(pubkeyS.getEncoded(true));
143143
final pubkeyHash = SHA512Digest().process(pubkeyBuffer as Uint8List);
144144

@@ -153,7 +153,7 @@ class Ecies {
153153
final Uint8List hmac = _calculateHmac(kM, message);
154154

155155
final Uint8List messageChecksum =
156-
cipherText.sublist(cipherText.length - _tagLength, cipherText.length);
156+
cipherText.sublist(cipherText.length - _tagLength, cipherText.length) as Uint8List;
157157

158158
// ignore: prefer_const_constructors
159159
if (!ListEquality().equals(messageChecksum, hmac)) {

lib/src/crypto/ecurve.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ECurve {
3535
return result;
3636
}
3737

38-
static Uint8List privateAdd(Uint8List d, Uint8List tweak) {
38+
static Uint8List? privateAdd(Uint8List d, Uint8List tweak) {
3939
// if (!isPrivate(d)) throw new ArgumentError(THROW_BAD_PRIVATE);
4040
// if (!isOrderScalar(tweak)) throw new ArgumentError(THROW_BAD_TWEAK);
4141
BigInt dd = decodeBigInt(d);
@@ -48,31 +48,31 @@ class ECurve {
4848
static bool isPrivate(Uint8List x) {
4949
if (!isScalar(x)) return false;
5050
return _compare(x, zero32) > 0 && // > 0
51-
_compare(x, ecGroupOrder) < 0; // < G
51+
_compare(x, ecGroupOrder as Uint8List) < 0; // < G
5252
}
5353

5454
static bool isScalar(Uint8List x) {
5555
return x.length == 32;
5656
}
5757

58-
static Uint8List pointFromScalar(Uint8List d, bool _compressed) {
58+
static Uint8List? pointFromScalar(Uint8List d, bool _compressed) {
5959
// if (!isPrivate(d)) throw new ArgumentError(THROW_BAD_PRIVATE);
6060
BigInt dd = decodeBigInt(d);
61-
ECPoint pp = G * dd;
61+
ECPoint pp = (G * dd)!;
6262
if (pp.isInfinity) return null;
6363
return pp.getEncoded(_compressed);
6464
}
6565

66-
static Uint8List pointAddScalar(
66+
static Uint8List? pointAddScalar(
6767
Uint8List p, Uint8List tweak, bool _compressed) {
6868
// if (!isPoint(p)) throw new ArgumentError(THROW_BAD_POINT);
6969
// if (!isOrderScalar(tweak)) throw new ArgumentError(THROW_BAD_TWEAK);
7070
bool compressed = assumeCompression(_compressed, p);
71-
ECPoint pp = decodeFrom(p);
72-
if (_compare(tweak, zero32) == 0) return pp.getEncoded(compressed);
71+
ECPoint? pp = decodeFrom(p);
72+
if (_compare(tweak, zero32) == 0) return pp!.getEncoded(compressed);
7373
BigInt tt = decodeBigInt(tweak);
74-
ECPoint qq = G * tt;
75-
ECPoint uu = pp + qq;
74+
ECPoint? qq = G * tt;
75+
ECPoint uu = (pp! + qq)!;
7676
if (uu.isInfinity) return null;
7777
return uu.getEncoded(compressed);
7878
}
@@ -101,7 +101,7 @@ class ECurve {
101101
if (_compare(x, zero32) == 0) {
102102
return false;
103103
}
104-
if (_compare(x, ecP) == 1) {
104+
if (_compare(x, ecP as Uint8List) == 1) {
105105
return false;
106106
}
107107
try {
@@ -116,7 +116,7 @@ class ECurve {
116116
if (_compare(y, zero32) == 0) {
117117
return false;
118118
}
119-
if (_compare(y, ecP) == 1) {
119+
if (_compare(y, ecP as Uint8List) == 1) {
120120
return false;
121121
}
122122
if (t == 0x04 && p.length == 65) {
@@ -129,5 +129,5 @@ class ECurve {
129129
return p[0] != 0x04;
130130
}
131131

132-
static ECPoint decodeFrom(Uint8List P) => secp256k1.curve.decodePoint(P);
132+
static ECPoint? decodeFrom(Uint8List P) => secp256k1.curve.decodePoint(P);
133133
}

0 commit comments

Comments
 (0)