Skip to content

Commit dc0e45b

Browse files
committed
V7.1.0
- Update dependencies. - Minimum required Dart SDK version updated to 3.7. - Fixed parsing of scripts with disabled or invalid opcodes
1 parent 8dff147 commit dc0e45b

97 files changed

Lines changed: 10146 additions & 6778 deletions

File tree

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 7.1.0
2+
3+
- Update dependencies.
4+
- Minimum required Dart SDK version updated to 3.7.
5+
- Fixed parsing of scripts with disabled or invalid opcodes
6+
17
## 7.0.0
28

39
- Update dependencies.

example/lib/musig/musig_example.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ BtcTransaction _spendWithLeafA(
6363
required List<P2trAddress> existsUtxosScriptPubKeys,
6464
required List<BigInt> existsUtxosAmounts,
6565
required TaprootTree treeScript}) {
66+
const musig = MuSig2();
6667
final internalKey = _getInternalPubKey();
6768
final key1 = _getPrivateKey(path: "m/86'/1'/0'/0/2");
6869
final key3 = _getPrivateKey(path: "m/86'/1'/0'/0/4");
6970
final pk1 = key1.getPublic();
7071
final pk3 = key3.getPublic();
71-
final musigSigner = MuSig2.aggPublicKeys(
72+
final musigSigner = musig.aggPublicKeys(
7273
keys: [pk1.publicKey.compressed, pk3.publicKey.compressed]);
7374
final tapleafScript1 = TaprootLeaf(
7475
script: Script(script: [
@@ -83,11 +84,11 @@ BtcTransaction _spendWithLeafA(
8384
existsUtxosScriptPubKeys.map((e) => e.toScriptPubKey()).toList(),
8485
amounts: existsUtxosAmounts)
8586
.asImmutableBytes;
86-
final nonce1 = MuSig2.nonceGenerate(
87+
final nonce1 = musig.nonceGenerate(
8788
publicKey: pk1.toBytes(mode: PubKeyModes.compressed), msg: digest);
88-
final nonce3 = MuSig2.nonceGenerate(
89+
final nonce3 = musig.nonceGenerate(
8990
publicKey: pk3.toBytes(mode: PubKeyModes.compressed), msg: digest);
90-
final aggNonce = MuSig2.nonceAgg([nonce1.pubnonce, nonce3.pubnonce]);
91+
final aggNonce = musig.nonceAgg([nonce1.pubnonce, nonce3.pubnonce]);
9192
final session = MuSig2Session(
9293
aggnonce: aggNonce,
9394
publicKeys: [
@@ -96,12 +97,12 @@ BtcTransaction _spendWithLeafA(
9697
],
9798
tweaks: [],
9899
msg: digest);
99-
final sig1 = MuSig2.sign(
100+
final sig1 = musig.sign(
100101
secnonce: nonce1.secnonce, sk: key1.toBytes(), session: session);
101-
final sig3 = MuSig2.sign(
102+
final sig3 = musig.sign(
102103
secnonce: nonce3.secnonce, sk: key3.toBytes(), session: session);
103104
final signature =
104-
MuSig2.partialSigAgg(signatures: [sig1, sig3], session: session);
105+
musig.partialSigAgg(signatures: [sig1, sig3], session: session);
105106
final controlBlock = TaprootControlBlock.generate(
106107
xOnlyOrInternalPubKey: internalKey.toXOnly(),
107108
leafScript: tapleafScript1,
@@ -162,7 +163,7 @@ Bip32Slip10Secp256k1 _deriveKey(
162163
String path = "m/86'/1'/0'/0/1"}) {
163164
Bip32Slip10Secp256k1 secp = Bip32Slip10Secp256k1.fromExtendedKey(
164165
key, Bip44Coins.bitcoinTestnet.conf.keyNetVer);
165-
return secp.derivePath(path) as Bip32Slip10Secp256k1;
166+
return secp.derivePath(path);
166167
}
167168

168169
ECPublic _getPubKey({String path = "m/86'/1'/0'/0/1"}) {

example/lib/psbt/psbt_example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,5 @@ Bip32Slip10Secp256k1 _deriveKey(
618618
String path = "m/86'/1'/0'/0/1"}) {
619619
Bip32Slip10Secp256k1 secp = Bip32Slip10Secp256k1.fromExtendedKey(
620620
key, Bip44Coins.bitcoinTestnet.conf.keyNetVer);
621-
return secp.derivePath(path) as Bip32Slip10Secp256k1;
621+
return secp.derivePath(path);
622622
}

example/lib/psbt/psbt_musig2_example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Bip32Slip10Secp256k1 _deriveKey(
88
String path = "m/86'/1'/0'/0/1"}) {
99
Bip32Slip10Secp256k1 secp = Bip32Slip10Secp256k1.fromExtendedKey(
1010
key, Bip44Coins.bitcoinTestnet.conf.keyNetVer);
11-
return secp.derivePath(path) as Bip32Slip10Secp256k1;
11+
return secp.derivePath(path);
1212
}
1313

1414
ECPrivate _getPrivateKey({String path = "m/86'/1'/0'/0/1"}) {

example/pubspec.lock

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ packages:
1515
path: ".."
1616
relative: true
1717
source: path
18-
version: "6.9.0"
18+
version: "7.1.0"
1919
blockchain_utils:
2020
dependency: "direct main"
2121
description:
2222
name: blockchain_utils
23-
sha256: "9129a7b13e50c692387b69f24ca82c06360a75094dd0d286e21430c5b1492707"
23+
sha256: aa4a3051e8577d59b15fb2b4036a1bf6f93d099dff1544d601bef2705b7e945a
2424
url: "https://pub.dev"
2525
source: hosted
26-
version: "5.4.0"
26+
version: "6.0.0"
2727
boolean_selector:
2828
dependency: transitive
2929
description:
@@ -56,6 +56,14 @@ packages:
5656
url: "https://pub.dev"
5757
source: hosted
5858
version: "1.19.1"
59+
convert:
60+
dependency: transitive
61+
description:
62+
name: convert
63+
sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68
64+
url: "https://pub.dev"
65+
source: hosted
66+
version: "3.1.2"
5967
cupertino_icons:
6068
dependency: "direct main"
6169
description:
@@ -158,10 +166,10 @@ packages:
158166
dependency: transitive
159167
description:
160168
name: meta
161-
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
169+
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
162170
url: "https://pub.dev"
163171
source: hosted
164-
version: "1.16.0"
172+
version: "1.17.0"
165173
path:
166174
dependency: transitive
167175
description:
@@ -170,6 +178,14 @@ packages:
170178
url: "https://pub.dev"
171179
source: hosted
172180
version: "1.9.1"
181+
pointycastle:
182+
dependency: transitive
183+
description:
184+
name: pointycastle
185+
sha256: "92aa3841d083cc4b0f4709b5c74fd6409a3e6ba833ffc7dc6a8fee096366acf5"
186+
url: "https://pub.dev"
187+
source: hosted
188+
version: "4.0.0"
173189
sky_engine:
174190
dependency: transitive
175191
description: flutter
@@ -219,10 +235,10 @@ packages:
219235
dependency: transitive
220236
description:
221237
name: test_api
222-
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
238+
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
223239
url: "https://pub.dev"
224240
source: hosted
225-
version: "0.7.6"
241+
version: "0.7.7"
226242
typed_data:
227243
dependency: transitive
228244
description:

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies:
3939
path: ../
4040
# blockchain_utils:
4141
# path: ../../blockchain_utils
42-
blockchain_utils: ^5.4.0
42+
blockchain_utils: ^6.0.0
4343
http: ^1.2.0
4444

4545
dev_dependencies:

lib/src/bitcoin/address/core.dart

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ abstract class BitcoinAddressType implements Enumerate {
88

99
/// Factory method to create a BitcoinAddressType enum value from a name or value.
1010
static BitcoinAddressType fromValue(String? value) {
11-
return values.firstWhere((element) => element.value == value,
12-
orElse: () =>
13-
throw DartBitcoinPluginException('Unknown address type. $value'));
11+
return values.firstWhere(
12+
(element) => element.value == value,
13+
orElse:
14+
() =>
15+
throw DartBitcoinPluginException('Unknown address type. $value'),
16+
);
1417
}
1518

1619
/// Check if the address type is Pay-to-Script-Hash (P2SH).
@@ -21,11 +24,11 @@ abstract class BitcoinAddressType implements Enumerate {
2124
bool get isP2sh32 => isP2sh && hashLength == 32;
2225

2326
bool get supportBip137 => switch (this) {
24-
P2pkhAddressType.p2pkh || P2pkhAddressType.p2pkhwt => true,
25-
P2shAddressType.p2wpkhInP2sh => true,
26-
SegwitAddressType.p2wpkh => true,
27-
_ => false
28-
};
27+
P2pkhAddressType.p2pkh || P2pkhAddressType.p2pkhwt => true,
28+
P2shAddressType.p2wpkhInP2sh => true,
29+
SegwitAddressType.p2wpkh => true,
30+
_ => false,
31+
};
2932

3033
// Enum values as a list for iteration
3134
static const List<BitcoinAddressType> values = [
@@ -43,13 +46,14 @@ abstract class BitcoinAddressType implements Enumerate {
4346
P2shAddressType.p2pkInP2sh32wt,
4447
P2shAddressType.p2pkhInP2shwt,
4548
P2shAddressType.p2pkInP2shwt,
46-
P2pkhAddressType.p2pkhwt
49+
P2pkhAddressType.p2pkhwt,
4750
];
4851
T cast<T extends BitcoinAddressType>() {
4952
if (this is! T) {
5053
throw DartBitcoinPluginException(
51-
"Invalid cast: expected ${T.runtimeType}, but found $runtimeType.",
52-
details: {'expected': '$T', 'type': value});
54+
"Invalid cast: expected ${T.runtimeType}, but found $runtimeType.",
55+
details: {'expected': '$T', 'type': value},
56+
);
5357
}
5458
return this as T;
5559
}
@@ -62,23 +66,29 @@ abstract class BitcoinAddressType implements Enumerate {
6266

6367
abstract class BitcoinBaseAddress {
6468
const BitcoinBaseAddress();
65-
factory BitcoinBaseAddress.fromProgram(
66-
{required String addressProgram, required BitcoinAddressType type}) {
69+
factory BitcoinBaseAddress.fromProgram({
70+
required String addressProgram,
71+
required BitcoinAddressType type,
72+
}) {
6773
if (type.isP2sh) {
6874
return P2shAddress.fromHash160(
69-
addrHash: addressProgram, type: type.cast());
75+
addrHash: addressProgram,
76+
type: type.cast(),
77+
);
7078
}
7179
return switch (type) {
7280
PubKeyAddressType.p2pk => P2pkAddress(publicKey: addressProgram),
73-
P2pkhAddressType.p2pkh ||
74-
P2pkhAddressType.p2pkhwt =>
81+
P2pkhAddressType.p2pkh || P2pkhAddressType.p2pkhwt =>
7582
P2pkhAddress.fromHash160(addrHash: addressProgram, type: type.cast()),
76-
SegwitAddressType.p2wpkh =>
77-
P2wpkhAddress.fromProgram(program: addressProgram),
78-
SegwitAddressType.p2wsh =>
79-
P2wshAddress.fromProgram(program: addressProgram),
80-
SegwitAddressType.p2tr =>
81-
P2trAddress.fromProgram(program: addressProgram),
83+
SegwitAddressType.p2wpkh => P2wpkhAddress.fromProgram(
84+
program: addressProgram,
85+
),
86+
SegwitAddressType.p2wsh => P2wshAddress.fromProgram(
87+
program: addressProgram,
88+
),
89+
SegwitAddressType.p2tr => P2trAddress.fromProgram(
90+
program: addressProgram,
91+
),
8292
_ => throw DartBitcoinPluginException("Unsuported bitcoin address type."),
8393
};
8494
}
@@ -125,15 +135,27 @@ class P2pkhAddressType extends BitcoinAddressType {
125135

126136
class P2shAddressType extends BitcoinAddressType {
127137
const P2shAddressType._(super.value, this.hashLength, this.withToken)
128-
: super._();
138+
: super._();
129139
static const P2shAddressType p2wshInP2sh = P2shAddressType._(
130-
'P2SH/P2WSH', _BitcoinAddressUtils.hash160DigestLength, false);
140+
'P2SH/P2WSH',
141+
BitcoinAddressUtils.hash160DigestLength,
142+
false,
143+
);
131144
static const P2shAddressType p2wpkhInP2sh = P2shAddressType._(
132-
'P2SH/P2WPKH', _BitcoinAddressUtils.hash160DigestLength, false);
145+
'P2SH/P2WPKH',
146+
BitcoinAddressUtils.hash160DigestLength,
147+
false,
148+
);
133149
static const P2shAddressType p2pkhInP2sh = P2shAddressType._(
134-
'P2SH/P2PKH', _BitcoinAddressUtils.hash160DigestLength, false);
150+
'P2SH/P2PKH',
151+
BitcoinAddressUtils.hash160DigestLength,
152+
false,
153+
);
135154
static const P2shAddressType p2pkInP2sh = P2shAddressType._(
136-
'P2SH/P2PK', _BitcoinAddressUtils.hash160DigestLength, false);
155+
'P2SH/P2PK',
156+
BitcoinAddressUtils.hash160DigestLength,
157+
false,
158+
);
137159
@override
138160
bool get isP2sh => true;
139161
@override
@@ -146,26 +168,44 @@ class P2shAddressType extends BitcoinAddressType {
146168
/// specify BCH NETWORK for now!
147169
/// Pay-to-Script-Hash-32
148170
static const P2shAddressType p2pkhInP2sh32 = P2shAddressType._(
149-
'P2SH32/P2PKH', _BitcoinAddressUtils.scriptHashLenght, false);
171+
'P2SH32/P2PKH',
172+
BitcoinAddressUtils.scriptHashLenght,
173+
false,
174+
);
150175
//// Pay-to-Script-Hash-32
151176
static const P2shAddressType p2pkInP2sh32 = P2shAddressType._(
152-
'P2SH32/P2PK', _BitcoinAddressUtils.scriptHashLenght, false);
177+
'P2SH32/P2PK',
178+
BitcoinAddressUtils.scriptHashLenght,
179+
false,
180+
);
153181

154182
/// Pay-to-Script-Hash-32-with-token
155183
static const P2shAddressType p2pkhInP2sh32wt = P2shAddressType._(
156-
'P2SH32WT/P2PKH', _BitcoinAddressUtils.scriptHashLenght, true);
184+
'P2SH32WT/P2PKH',
185+
BitcoinAddressUtils.scriptHashLenght,
186+
true,
187+
);
157188

158189
/// Pay-to-Script-Hash-32-with-token
159190
static const P2shAddressType p2pkInP2sh32wt = P2shAddressType._(
160-
'P2SH32WT/P2PK', _BitcoinAddressUtils.scriptHashLenght, true);
191+
'P2SH32WT/P2PK',
192+
BitcoinAddressUtils.scriptHashLenght,
193+
true,
194+
);
161195

162196
/// Pay-to-Script-Hash-with-token
163197
static const P2shAddressType p2pkhInP2shwt = P2shAddressType._(
164-
'P2SHWT/P2PKH', _BitcoinAddressUtils.hash160DigestLength, true);
198+
'P2SHWT/P2PKH',
199+
BitcoinAddressUtils.hash160DigestLength,
200+
true,
201+
);
165202

166203
/// Pay-to-Script-Hash-with-token
167204
static const P2shAddressType p2pkInP2shwt = P2shAddressType._(
168-
'P2SHWT/P2PK', _BitcoinAddressUtils.hash160DigestLength, true);
205+
'P2SHWT/P2PK',
206+
BitcoinAddressUtils.hash160DigestLength,
207+
true,
208+
);
169209

170210
@override
171211
String toString() {

0 commit comments

Comments
 (0)