Skip to content

Commit f12479b

Browse files
committed
Update changelog
1 parent e439b58 commit f12479b

60 files changed

Lines changed: 1502 additions & 804 deletions

Some content is hidden

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

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
## 6.0.0
2+
- Added support for FF1.
3+
- Added support for f4jumble.
4+
- Added support for BLS12-381.
5+
- Added support for Jubjub.
6+
- Added support for Vesta–Pallas.
7+
- Added support for Sinsemilla.
8+
- Added support for Poseidon
9+
- Added support for ZIP-32 hierarchical key derivation
10+
- Added support for Zcash addresses:
11+
- Unified Addresses (UA)
12+
- Sapling
13+
- Orchard
14+
- Transparent (P2PKH, P2SH)
15+
- Added support for Zcash viewing and spending keys:
16+
- USK
17+
- UFVK
18+
- UIVK
19+
- Added support for RedJubjub / RedDSA signatures
20+
- Minimum required Dart SDK version updated to 3.7.
21+
- Reduce static final variables.
22+
23+
24+
125
## 5.4.0
226
- Update dependecies.
327

lib/bech32/bech32_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Bech32BaseUtils {
131131
}
132132
if (pad) {
133133
if (bits > 0) {
134-
// Pad the value with zeros to reach toBits
134+
// SinsemillaPad the value with zeros to reach toBits
135135
ret.add((acc << (toBits - bits)) & maxOutVal);
136136
}
137137
} else if (bits >= fromBits ||

lib/bip/address/zcash/src/converter.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ZCashAddrDecoder
1111
@override
1212
ZCashDecodedAddressResult decodeAddr(
1313
String addr, {
14-
ZcashNetwork? network,
14+
ZCashNetwork? network,
1515
ZCashAddressType? type,
1616
}) {
1717
final decode = ZCashAddressUtils.parseAddress(
@@ -30,10 +30,10 @@ class ZCashAddrEncoder implements BlockchainAddressEncoder {
3030
@override
3131
String encodeKey(
3232
List<int> keyBytes, {
33-
ZcashNetwork? network,
33+
ZCashNetwork? network,
3434
ZCashAddressType? addrType,
3535
}) {
36-
network ??= ZcashNetwork.mainnet;
36+
network ??= ZCashNetwork.mainnet;
3737
addrType ??= AddrKeyValidator.getAddrArg<ZCashAddressType>(
3838
addrType,
3939
"addrType",
@@ -49,9 +49,9 @@ class ZCashAddrEncoder implements BlockchainAddressEncoder {
4949
class ZCashUnifiedAddrEncoder implements BlockchainAddressEncoder {
5050
String encodeUnifiedReceivers(
5151
List<ZUnifiedReceiver> receivers, {
52-
ZcashNetwork? network,
52+
ZCashNetwork? network,
5353
}) {
54-
network ??= ZcashNetwork.mainnet;
54+
network ??= ZCashNetwork.mainnet;
5555
return ZCashAddressUtils.encodeAddress(
5656
bytes: const [],
5757
type: ZCashAddressType.unified,
@@ -61,8 +61,8 @@ class ZCashUnifiedAddrEncoder implements BlockchainAddressEncoder {
6161
}
6262

6363
@override
64-
String encodeKey(List<int> keyBytes, {ZcashNetwork? network}) {
65-
network ??= ZcashNetwork.mainnet;
64+
String encodeKey(List<int> keyBytes, {ZCashNetwork? network}) {
65+
network ??= ZCashNetwork.mainnet;
6666
return ZCashAddressUtils.encodeAddress(
6767
bytes: keyBytes,
6868
type: ZCashAddressType.unified,

lib/bip/address/zcash/src/types.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum ZCashAddressType {
1616
class ZCashDecodedAddressResult {
1717
final List<ZUnifiedReceiver>? unifiedReceiver;
1818
final List<int> addressBytes;
19-
final ZcashNetwork network;
19+
final ZCashNetwork network;
2020
final ZCashAddressType type;
2121
ZCashDecodedAddressResult({
2222
this.unifiedReceiver,

lib/bip/address/zcash/src/utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ZCashAddressUtils {
107107

108108
static ZCashDecodedAddressResult? parseAddress(
109109
String address, {
110-
ZcashNetwork? expectedNetwork,
110+
ZCashNetwork? expectedNetwork,
111111
ZCashAddressType? exceptedType,
112112
}) {
113113
final decode = _parseAddress(address, exceptedType: exceptedType);
@@ -122,9 +122,9 @@ class ZCashAddressUtils {
122122
}
123123

124124
static void _validate({
125-
required ZcashNetwork network,
125+
required ZCashNetwork network,
126126
required ZCashAddressType type,
127-
ZcashNetwork? expectedNetwork,
127+
ZCashNetwork? expectedNetwork,
128128
ZCashAddressType? exceptedType,
129129
}) {
130130
if (expectedNetwork != null && expectedNetwork != network) {
@@ -144,7 +144,7 @@ class ZCashAddressUtils {
144144
static String encodeAddress({
145145
required List<int> bytes,
146146
required ZCashAddressType type,
147-
required ZcashNetwork network,
147+
required ZCashNetwork network,
148148
List<ZUnifiedReceiver>? receivers,
149149
}) {
150150
final config = ZcashConf().fromNetwork(network);

lib/bip/bip/bip32/base/bip32_base.dart

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,16 @@ abstract class Bip32Base<BIP extends Bip32Base<BIP>>
7171
);
7272
}
7373

74-
/// Creates a BIP-32 key from an extended key string.
75-
Bip32Base.fromExtendedKeyBytes(
74+
/// Creates a BIP-32 key from an extended key bytese.
75+
Bip32Base.fromExtendedPrivateKeyBytes(
7676
List<int> key, [
7777
Bip32KeyNetVersions? keyNetVer,
7878
]) {
7979
keyNetVer ??= defaultKeyNetVersion;
80-
final deserKey = Bip32KeyDeserializer.deserializeKeyBytes(
81-
key,
82-
keyNetVer: keyNetVer,
83-
);
84-
80+
final deserKey = Bip32KeyDeserializer.deserializeKeyBytesWithoutPrefix(key);
8581
final keyBytes = deserKey.keyBytes;
8682
final Bip32KeyData keyData = deserKey.keyData;
87-
final isPublic = deserKey.isPublic;
88-
83+
assert(!deserKey.isPublic);
8984
if (keyData.depth.depth == 0) {
9085
if (!keyData.fingerPrint.isMasterKey()) {
9186
throw Bip32KeyError('Invalid extended master fingerPrint.');
@@ -95,21 +90,56 @@ abstract class Bip32Base<BIP extends Bip32Base<BIP>>
9590
}
9691
}
9792
_privKey = _initializePrivateKey(
98-
isPublic ? null : keyBytes,
99-
isPublic ? keyBytes : null,
93+
keyBytes,
94+
null,
10095
keyData,
10196
keyNetVer,
10297
curveType,
10398
);
10499
_pubKey = _initializePublicKey(
105-
isPublic ? null : keyBytes,
106-
isPublic ? keyBytes : null,
100+
keyBytes,
101+
null,
107102
keyData,
108103
keyNetVer,
109104
curveType,
110105
);
111106
}
112107

108+
// /// Creates a BIP-32 key from an extended key bytese exclude prefix.
109+
// Bip32Base.fromExtendedPrivateKeyBytes(List<int> key) {
110+
// final deserKey = Bip32KeyDeserializer.deserializeKeyBytes(
111+
// key,
112+
// keyNetVer: keyNetVer,
113+
// );
114+
115+
// final keyBytes = deserKey.keyBytes;
116+
// final Bip32KeyData keyData = deserKey.keyData;
117+
// final isPublic = deserKey.isPublic;
118+
119+
// if (keyData.depth.depth == 0) {
120+
// if (!keyData.fingerPrint.isMasterKey()) {
121+
// throw Bip32KeyError('Invalid extended master fingerPrint.');
122+
// }
123+
// if (keyData.index.index != 0) {
124+
// throw Bip32KeyError('Invalid extended master child index.');
125+
// }
126+
// }
127+
// _privKey = _initializePrivateKey(
128+
// isPublic ? null : keyBytes,
129+
// isPublic ? keyBytes : null,
130+
// keyData,
131+
// keyNetVer,
132+
// curveType,
133+
// );
134+
// _pubKey = _initializePublicKey(
135+
// isPublic ? null : keyBytes,
136+
// isPublic ? keyBytes : null,
137+
// keyData,
138+
// keyNetVer,
139+
// curveType,
140+
// );
141+
// }
142+
113143
/// Creates a BIP-32 key from a seed.
114144
///
115145
/// The [seedBytes] parameter is used to generate a master key, and the

lib/bip/bip/bip32/bip32_ex.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import 'package:blockchain_utils/exception/exceptions.dart';
77
/// property, if provided.
88
class Bip32KeyError extends BlockchainUtilsException {
99
const Bip32KeyError(super.message, {super.details});
10-
static const notHardenedIndexNotSupported = Bip32KeyError(
10+
static Bip32KeyError get notHardenedIndexNotSupported => Bip32KeyError(
1111
'Private child derivation with not-hardened index is not supported',
1212
);
13-
static const publicDerivationNotSupported = Bip32KeyError(
14-
'Public child derivation is not supported',
15-
);
16-
static const publicHardenedIndexNotSupported = Bip32KeyError(
13+
static Bip32KeyError get publicDerivationNotSupported =>
14+
Bip32KeyError('Public child derivation is not supported');
15+
static Bip32KeyError get publicHardenedIndexNotSupported => Bip32KeyError(
1716
'Public child derivation with hardened index is not supported',
1817
);
1918
}

lib/bip/bip/bip32/bip32_key_ser.dart

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class _Bip32KeySerializer {
2323
static List<int> serializeBytes(
2424
List<int> keyBytes,
2525
Bip32KeyData keyData,
26-
List<int> keyNetVerBytes,
26+
List<int>? keyNetVerBytes,
2727
) {
2828
return [
29-
...keyNetVerBytes,
29+
...keyNetVerBytes ?? [],
3030
...keyData.depth.toBytes(),
3131
...keyData.fingerPrint.toBytes(),
3232
...keyData.index.toBytes(),
@@ -64,16 +64,17 @@ class Bip32PrivateKeySerializer {
6464
);
6565
}
6666

67-
static List<int> serializeBytes(
68-
IPrivateKey privKey,
69-
Bip32KeyData keyData, [
67+
static List<int> serializeBytes({
68+
required IPrivateKey privKey,
69+
required Bip32KeyData keyData,
7070
Bip32KeyNetVersions? keyNetVer,
71-
]) {
71+
bool withPrefix = true,
72+
}) {
7273
keyNetVer ??= Bip32Const.mainNetKeyNetVersions;
7374
return _Bip32KeySerializer.serializeBytes(
7475
[0x00, ...privKey.raw],
7576
keyData,
76-
keyNetVer.private,
77+
withPrefix ? keyNetVer.private : null,
7778
);
7879
}
7980
}
@@ -95,16 +96,17 @@ class Bip32PublicKeySerializer {
9596
);
9697
}
9798

98-
static List<int> serializeBytes(
99-
IPublicKey pubKey,
100-
Bip32KeyData keyData, [
101-
Bip32KeyNetVersions? keyNetVer,
102-
]) {
99+
static List<int> serializeBytes({
100+
required IPublicKey pubKey,
101+
required Bip32KeyData keyData,
102+
required Bip32KeyNetVersions? keyNetVer,
103+
bool withPrefix = true,
104+
}) {
103105
keyNetVer ??= Bip32Const.mainNetKeyNetVersions;
104106
return _Bip32KeySerializer.serializeBytes(
105107
pubKey.compressed,
106108
keyData,
107-
keyNetVer.private,
109+
withPrefix ? keyNetVer.private : null,
108110
);
109111
}
110112
}
@@ -160,6 +162,30 @@ class Bip32KeyDeserializer {
160162
return Bip32DeserializedKey(keyParts.$1, keyParts.$2, isPublic);
161163
}
162164

165+
static Bip32DeserializedKey deserializeKeyBytesWithoutPrefix(
166+
List<int> serKeyBytes, {
167+
bool isPublic = false,
168+
}) {
169+
// Validate length
170+
if (isPublic &&
171+
serKeyBytes.length !=
172+
(Bip32KeySerConst.serializedPubKeyByteLen -
173+
Bip32KeyNetVersionsConst.keyNetVersionByteLen)) {
174+
throw Bip32KeyError('Invalid extended public key.');
175+
}
176+
if (!isPublic &&
177+
!Bip32KeySerConst.serializedPrivKeyByteLen.contains(
178+
serKeyBytes.length + Bip32KeyNetVersionsConst.keyNetVersionByteLen,
179+
)) {
180+
throw Bip32KeyError('Invalid extended private key.');
181+
}
182+
183+
// Get parts back
184+
final keyParts = _getPartsFromBytes(serKeyBytes, isPublic, offset: 0);
185+
186+
return Bip32DeserializedKey(keyParts.$1, keyParts.$2, isPublic);
187+
}
188+
163189
/// Deserialize a key.
164190
static Bip32DeserializedKey deserializeKey(
165191
String serKeyStr, {
@@ -191,9 +217,10 @@ class Bip32KeyDeserializer {
191217
/// Get back key parts from serialized key bytes.
192218
static (List<int>, Bip32KeyData) _getPartsFromBytes(
193219
List<int> serKeyBytes,
194-
bool isPublic,
195-
) {
196-
final depthIdx = Bip32KeyNetVersions.length;
220+
bool isPublic, {
221+
int offset = Bip32KeyNetVersionsConst.keyNetVersionByteLen,
222+
}) {
223+
final depthIdx = offset;
197224
final fprintIdx = depthIdx + Bip32Depth.fixedLength();
198225
final keyIndexIdx = fprintIdx + Bip32FingerPrint.fixedLength();
199226
final chainCodeIdx = keyIndexIdx + Bip32KeyIndex.fixedLength();

lib/bip/bip/bip32/bip32_keys.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Bip32KeyBase extends CryptoKeyBase<Bip32KeyData> {
1111
const Bip32KeyBase(super.keyData, this.curveType);
1212
final EllipticCurveTypes curveType;
1313
String get toExtended;
14-
List<int> get toExtendedBytes;
14+
List<int> toExtendedBytes({bool withPrefix = true});
1515
}
1616

1717
/// Represents a BIP32 public key with associated data such as the elliptic curve type,
@@ -63,8 +63,13 @@ class Bip32PublicKey extends Bip32KeyBase {
6363
ChainCode get chainCode => keyData.chainCode;
6464

6565
@override
66-
List<int> get toExtendedBytes =>
67-
Bip32PublicKeySerializer.serializeBytes(pubKey, keyData, keyNetVer);
66+
List<int> toExtendedBytes({bool withPrefix = true}) =>
67+
Bip32PublicKeySerializer.serializeBytes(
68+
pubKey: pubKey,
69+
keyData: keyData,
70+
withPrefix: withPrefix,
71+
keyNetVer: keyNetVer,
72+
);
6873

6974
/// Creates a [Bip32PublicKey] from a byte representation, key data, key network versions, and curve type.
7075
static Bip32PublicKey fromBytes(
@@ -126,8 +131,13 @@ class Bip32PrivateKey extends Bip32KeyBase {
126131
}
127132

128133
@override
129-
List<int> get toExtendedBytes =>
130-
Bip32PrivateKeySerializer.serializeBytes(privKey, keyData, keyNetVer);
134+
List<int> toExtendedBytes({bool withPrefix = true}) =>
135+
Bip32PrivateKeySerializer.serializeBytes(
136+
privKey: privKey,
137+
keyData: keyData,
138+
keyNetVer: keyNetVer,
139+
withPrefix: withPrefix,
140+
);
131141

132142
/// Creates a Bip32PrivateKey from a byte representation, key data, key network versions, and curve type.
133143
static Bip32PrivateKey fromBytes(

lib/bip/bip/bip32/slip10/bip32_slip10_secp256k1.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ class Bip32Slip10Secp256k1 extends Bip32Base<Bip32Slip10Secp256k1> {
3939
Bip32Slip10Secp256k1.fromExtendedKey(super.exKeyStr, [super.keyNetVer])
4040
: super.fromExtendedKey();
4141

42-
/// constructor for creating a key from an extended key string.
43-
Bip32Slip10Secp256k1.fromExtendedKeyBytes(super.exKeyStr, [super.keyNetVer])
44-
: super.fromExtendedKeyBytes();
42+
/// constructor for creating a key from an extended key bytes exclude prefix.
43+
Bip32Slip10Secp256k1.fromExtendedPrivateKeyBytes(
44+
super.exKeyStr, [
45+
super.keyNetVer,
46+
]) : super.fromExtendedPrivateKeyBytes();
4547

4648
/// Returns the curve type, SECP256K1.
4749
@override

0 commit comments

Comments
 (0)