Skip to content

Commit 62af5c9

Browse files
committed
V5.2.0
- Renamed constructors in CborListValue and CborMapValue: - fixedLength → definite - dynamicLength → indefinite - `CborListValue`, `CborMapValue`, `CborSetValue`, and `CborTagValue` no longer accept dynamic values. They now only accept `CborValue` instances.
1 parent d6e82d4 commit 62af5c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+719
-441
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 5.2.0
2+
3+
- Renamed constructors in CborListValue and CborMapValue:
4+
- fixedLength → definite
5+
- dynamicLength → indefinite
6+
- `CborListValue`, `CborMapValue`, `CborSetValue`, and `CborTagValue` no longer accept dynamic values.
7+
They now only accept `CborValue` instances.
8+
19
## 5.1.0
210

311
- Added support for HKDF (HMAC-based Key Derivation Function)

example/pubspec.lock

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ packages:
9393
url: "https://pub.dev"
9494
source: hosted
9595
version: "3.0.5"
96-
cryptography:
97-
dependency: transitive
98-
description:
99-
name: cryptography
100-
sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05
101-
url: "https://pub.dev"
102-
source: hosted
103-
version: "2.7.0"
10496
cupertino_icons:
10597
dependency: "direct main"
10698
description:
@@ -109,14 +101,6 @@ packages:
109101
url: "https://pub.dev"
110102
source: hosted
111103
version: "1.0.8"
112-
ffi:
113-
dependency: transitive
114-
description:
115-
name: ffi
116-
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
117-
url: "https://pub.dev"
118-
source: hosted
119-
version: "2.1.4"
120104
file:
121105
dependency: transitive
122106
description:
@@ -472,4 +456,4 @@ packages:
472456
source: hosted
473457
version: "3.1.2"
474458
sdks:
475-
dart: ">=3.7.0 <4.0.0"
459+
dart: ">=3.7.0-0 <4.0.0"

lib/bip/address/ada/ada_byron_addr.dart

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import 'package:blockchain_utils/bip/address/encoder.dart';
6262
import 'package:blockchain_utils/bip/address/exception/exception.dart';
6363
import 'package:blockchain_utils/bip/bip/bip32/bip32_key_data.dart';
6464
import 'package:blockchain_utils/bip/bip/bip32/bip32_path.dart';
65+
import 'package:blockchain_utils/cbor/extention/extenton.dart';
6566
import 'package:blockchain_utils/crypto/quick_crypto.dart';
6667
import 'package:blockchain_utils/cbor/core/cbor.dart';
6768
import 'package:blockchain_utils/cbor/types/bytes.dart';
@@ -144,17 +145,17 @@ class ADAByronAddrConst {
144145
class _AdaByronAddrHdPath {
145146
static Bip32Path decrypt(List<int> hdPathEncBytes, List<int> hdPathKeyBytes) {
146147
final plainTextBytes = QuickCrypto.chaCha20Poly1305Decrypt(
147-
key: hdPathKeyBytes,
148-
nonce: ADAByronAddrConst.chacha20Poly1305Nonce,
149-
assocData: ADAByronAddrConst.chacha20Poly1305AssocData,
150-
cipherText: hdPathEncBytes,
151-
);
148+
key: hdPathKeyBytes,
149+
nonce: ADAByronAddrConst.chacha20Poly1305Nonce,
150+
assocData: ADAByronAddrConst.chacha20Poly1305AssocData,
151+
cipherText: hdPathEncBytes);
152152
final decode = CborObject.fromCbor(plainTextBytes);
153153
if (decode is! CborListValue) {
154154
throw const AddressConverterException("invalid bip32 path");
155155
}
156+
156157
final paths = decode.value
157-
.map((e) => Bip32KeyIndex(e is String ? int.parse(e) : e as int))
158+
.map((e) => Bip32KeyIndex(IntUtils.parse(e.value)))
158159
.toList();
159160
return Bip32Path(elems: paths, isAbsolute: true);
160161
}
@@ -164,7 +165,9 @@ class _AdaByronAddrHdPath {
164165
key: hdPathKeyBytes,
165166
nonce: ADAByronAddrConst.chacha20Poly1305Nonce,
166167
assocData: ADAByronAddrConst.chacha20Poly1305AssocData,
167-
plainText: CborListValue.dynamicLength(hdPath.toList()).encode(),
168+
plainText: CborListValue.inDefinite(
169+
hdPath.toList().map((e) => CborIntValue(e)).toList())
170+
.encode(),
168171
);
169172
return result;
170173
}
@@ -199,16 +202,18 @@ class ADAByronAddrAttrs {
199202
hdPathEncBytes: hdPath, networkMagic: networkMagic);
200203
}
201204

202-
Map<int, List<int>> toJson() {
203-
final attrs = <int, List<int>>{};
205+
CborMapValue<CborIntValue, CborBytesValue> toJson() {
206+
final attrs = <CborIntValue, CborBytesValue>{};
204207
if (hdPathEncBytes != null) {
205-
attrs[1] = CborBytesValue(hdPathEncBytes!).encode();
208+
attrs[CborIntValue(1)] =
209+
CborBytesValue(CborBytesValue(hdPathEncBytes!).encode());
206210
}
207211
if (networkMagic != null &&
208212
networkMagic != ADANetwork.mainnet.protocolMagic) {
209-
attrs[2] = CborIntValue(networkMagic!).encode();
213+
attrs[CborIntValue(2)] =
214+
CborBytesValue(CborIntValue(networkMagic!).encode());
210215
}
211-
return attrs;
216+
return CborMapValue.definite(attrs);
212217
}
213218
}
214219

@@ -231,10 +236,12 @@ class _AdaByronAddrRoot {
231236
}
232237

233238
List<int> serialize() {
234-
return CborListValue.fixedLength([
239+
return CborListValue<CborObject>.definite([
235240
CborIntValue(type.value),
236-
CborListValue.fixedLength(
237-
[spendingData.type.value, spendingData.keyBytes]),
241+
CborListValue<CborObject>.definite([
242+
CborIntValue(spendingData.type.value),
243+
CborBytesValue(spendingData.keyBytes)
244+
]),
238245
attrs.toJson(),
239246
]).encode();
240247
}
@@ -265,13 +272,13 @@ class ADAByronAddrPayload {
265272

266273
return ADAByronAddrPayload(
267274
rootHashBytes: cborBytes.value,
268-
attrs: ADAByronAddrAttrs.fromCbor(addrPayload.value[1]),
269-
type: ADAByronAddrTypes.fromCbor(addrPayload.value[2]),
275+
attrs: ADAByronAddrAttrs.fromCbor(addrPayload.value[1].cast()),
276+
type: ADAByronAddrTypes.fromCbor(addrPayload.value[2].cast()),
270277
);
271278
}
272279

273280
List<int> serialize() {
274-
return CborListValue.fixedLength([
281+
return CborListValue<CborObject>.definite([
275282
CborBytesValue(rootHashBytes),
276283
attrs.toJson(),
277284
CborIntValue(type.value)
@@ -327,8 +334,9 @@ class ADAByronAddr {
327334

328335
CborObject toCbor() {
329336
final payloadBytes = payload.serialize();
330-
return CborListValue.fixedLength([
331-
CborTagValue(payloadBytes, [ADAByronAddrConst.payloadTag]),
337+
return CborListValue<CborObject>.definite([
338+
CborTagValue(
339+
CborBytesValue(payloadBytes), [ADAByronAddrConst.payloadTag]),
332340
CborIntValue(Crc32.quickIntDigest(payloadBytes)),
333341
]);
334342
}

lib/bip/bip/bip32/bip32_const.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Bip32Const {
1313
List<int>.from([0x04, 0x35, 0x83, 0x94]));
1414

1515
/// kholaw key net version
16-
static Bip32KeyNetVersions kholawKeyNetVersions = Bip32KeyNetVersions(
16+
static final Bip32KeyNetVersions kholawKeyNetVersions = Bip32KeyNetVersions(
1717
List<int>.from([0x04, 0x88, 0xb2, 0x1e]),
1818
List<int>.from([0x0f, 0x43, 0x31, 0xd4]));
1919
}

lib/bip/bip/conf/bip/bip_coins.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:blockchain_utils/bip/bip/conf/bip44/bip44_coins.dart';
99
import 'package:blockchain_utils/bip/bip/conf/bip49/bip49_coins.dart';
1010
import 'package:blockchain_utils/bip/bip/conf/bip84/bip84_coins.dart';
1111
import 'package:blockchain_utils/bip/bip/conf/bip86/bip86_coins.dart';
12+
import 'package:blockchain_utils/bip/ecc/bip_ecc.dart';
1213

1314
abstract class BipCoins implements CryptoCoins<BipCoinConfig> {
1415
const BipCoins();
@@ -41,6 +42,29 @@ abstract class BipCoins implements CryptoCoins<BipCoinConfig> {
4142
}
4243
}
4344

45+
static List<CryptoCoins> fromCurve(EllipticCurveTypes type,
46+
{CoinProposal? proposal}) {
47+
switch (proposal) {
48+
case BipProposal.bip44:
49+
return Bip44Coins.fromCurve(type);
50+
case BipProposal.bip49:
51+
return Bip49Coins.fromCurve(type);
52+
case BipProposal.bip84:
53+
return Bip84Coins.fromCurve(type);
54+
case BipProposal.bip86:
55+
return Bip86Coins.fromCurve(type);
56+
case null:
57+
return [
58+
...Bip44Coins.fromCurve(type),
59+
...Bip49Coins.fromCurve(type),
60+
...Bip84Coins.fromCurve(type),
61+
...Bip86Coins.fromCurve(type)
62+
];
63+
default:
64+
return [];
65+
}
66+
}
67+
4468
@override
4569
BipProposal get proposal;
4670

lib/bip/bip/conf/bip44/bip44_coins.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import 'package:blockchain_utils/bip/bip/conf/bip/bip_coins.dart';
5656
import 'package:blockchain_utils/bip/bip/conf/bip44/bip44_conf.dart';
5757
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
58+
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
5859

5960
/// An enumeration of supported cryptocurrencies for BIP44. It includes both main
6061
/// networks and test networks of various cryptocurrencies.
@@ -413,6 +414,13 @@ class Bip44Coins extends BipCoins {
413414
}
414415
}
415416

417+
static List<Bip44Coins> fromCurve(EllipticCurveTypes type) {
418+
return _coinToConf.entries
419+
.where((element) => element.value.type == type)
420+
.map((e) => e.key)
421+
.toList();
422+
}
423+
416424
static List<Bip44Coins> get values => _coinToConf.keys.toList();
417425

418426
/// A mapping that associates each BIP44Coin (enum) with its corresponding

lib/bip/bip/conf/bip49/bip49_coins.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:blockchain_utils/bip/bip/conf/bip/bip_coins.dart';
22
import 'package:blockchain_utils/bip/bip/conf/bip49/bip49_conf.dart';
33
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
4+
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
45

56
/// An enumeration of supported cryptocurrencies for BIP49. It includes both main
67
/// networks and test networks of various cryptocurrencies.
@@ -53,6 +54,13 @@ class Bip49Coins extends BipCoins {
5354
}
5455
}
5556

57+
static List<Bip49Coins> fromCurve(EllipticCurveTypes type) {
58+
return _coinToConf.entries
59+
.where((element) => element.value.type == type)
60+
.map((e) => e.key)
61+
.toList();
62+
}
63+
5664
static List<Bip49Coins> get values => _coinToConf.keys.toList();
5765

5866
/// A mapping that associates each BIP49Coin (enum) with its corresponding

lib/bip/bip/conf/bip84/bip84_coins.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import 'package:blockchain_utils/bip/bip/conf/bip/bip_coins.dart';
5656
import 'package:blockchain_utils/bip/bip/conf/bip84/bip84_conf.dart';
5757
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
58+
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
5859

5960
/// An enumeration of supported cryptocurrencies for BIP84. It includes both main
6061
/// networks and test networks of various cryptocurrencies.
@@ -98,6 +99,13 @@ class Bip84Coins extends BipCoins {
9899
}
99100
}
100101

102+
static List<Bip84Coins> fromCurve(EllipticCurveTypes type) {
103+
return _coinToConf.entries
104+
.where((element) => element.value.type == type)
105+
.map((e) => e.key)
106+
.toList();
107+
}
108+
101109
/// A mapping that associates each BIP84Coin (enum) with its corresponding
102110
/// BipCoinConfig configuration.
103111
static final Map<Bip84Coins, BipCoinConfig> _coinToConf = {

lib/bip/bip/conf/bip86/bip86_coins.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:blockchain_utils/bip/bip/conf/bip/bip_coins.dart';
22
import 'package:blockchain_utils/bip/bip/conf/bip86/bip86_conf.dart';
33
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
4+
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
45

56
/// An enumeration of supported cryptocurrencies for BIP86. It includes both main
67
/// networks and test networks of various cryptocurrencies.
@@ -38,6 +39,13 @@ class Bip86Coins extends BipCoins {
3839
}
3940
}
4041

42+
static List<Bip86Coins> fromCurve(EllipticCurveTypes type) {
43+
return _coinToConf.entries
44+
.where((element) => element.value.type == type)
45+
.map((e) => e.key)
46+
.toList();
47+
}
48+
4149
/// A mapping that associates each BIP86Coin (enum) with its corresponding
4250
/// BipCoinConfig configuration.
4351
static final Map<Bip86Coins, BipCoinConfig> _coinToConf = {

lib/bip/bip/conf/core/coins.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:blockchain_utils/bip/bip/conf/bip/bip_coins.dart';
22
import 'package:blockchain_utils/bip/cardano/cip1852/conf/cip1852_coins.dart';
3+
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
34
import 'package:blockchain_utils/bip/monero/conf/monero_coins.dart';
45
import 'package:blockchain_utils/bip/substrate/conf/substrate_coins.dart';
56
import 'package:blockchain_utils/exception/exceptions.dart';
@@ -37,6 +38,32 @@ abstract class CryptoCoins<T extends CoinConfig> {
3738
}
3839
}
3940

41+
static List<CryptoCoins> fromCurve(EllipticCurveTypes curve,
42+
{CoinProposal? proposal}) {
43+
switch (proposal) {
44+
case BipProposal.bip44:
45+
case BipProposal.bip49:
46+
case BipProposal.bip84:
47+
case BipProposal.bip86:
48+
return BipCoins.fromCurve(curve, proposal: proposal);
49+
case CipProposal.cip1852:
50+
return Cip1852Coins.fromCurve(curve);
51+
case SubstratePropoosal.substrate:
52+
return SubstrateCoins.fromCurve(curve);
53+
case MoneroProposal.monero:
54+
return MoneroCoins.fromCurve(curve);
55+
case null:
56+
return [
57+
...BipCoins.fromCurve(curve),
58+
...Cip1852Coins.fromCurve(curve),
59+
...SubstrateCoins.fromCurve(curve),
60+
...MoneroCoins.fromCurve(curve)
61+
];
62+
default:
63+
return [];
64+
}
65+
}
66+
4067
CoinProposal get proposal;
4168

4269
bool get isBipCoin;

0 commit comments

Comments
 (0)