Skip to content

Commit 7fbb468

Browse files
committedDec 4, 2024·
Merge branch 'dart_v2_final'
2 parents f451e9c + 76deefa commit 7fbb468

22 files changed

+196
-121
lines changed
 

‎CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
## 4.9.2
1+
## 4.9.4
2+
* Improved serialization process for large transaction scripts.
3+
* Added support for the Electra network.
4+
* Create and spent from uncomprossed public key format.
5+
* Important Notice: This is the final version supporting Dart v2. The next release will require Dart v3.3 or higher.
6+
27

8+
## 4.9.2
39
* Update dependencies
410
* Resolved issue with transaction deserialization (unsigned tx)
511

‎analysis_options.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# include: package:lints/recommended.yaml
22
include: package:flutter_lints/flutter.yaml
3-
# Additional information about this file can be found at
4-
# https://dart.dev/guides/language/analysis-options
53
# Uncomment the following section to specify additional rules.
64
linter:
75
rules:
8-
- unnecessary_const
9-
- prefer_const_declarations
10-
- prefer_final_locals # Warns when a local variable could be final
11-
- prefer_final_in_for_each # Warns when a forEach variable could be final
6+
prefer_final_locals: true # Warns when a local variable could be final
7+
prefer_final_in_for_each: true # Warns when a forEach variable could be final
8+
prefer_const_constructors: true # Warns when a constructor could be const
9+
prefer_const_declarations: true # Warns when a declaration could be const

‎example/pubspec.lock

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ packages:
1515
path: ".."
1616
relative: true
1717
source: path
18-
version: "4.9.2"
18+
version: "4.9.4"
1919
blockchain_utils:
2020
dependency: "direct main"
2121
description:
22-
path: "../../blockchain_utils"
23-
relative: true
24-
source: path
25-
version: "3.5.0"
22+
name: blockchain_utils
23+
sha256: "1e4f30b98d92f7ccf2eda009a23b53871a1c9b8b6dfa00bb1eb17ec00ae5eeeb"
24+
url: "https://pub.dev"
25+
source: hosted
26+
version: "3.6.0"
2627
boolean_selector:
2728
dependency: transitive
2829
description:

‎example/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ dependencies:
3737
cupertino_icons: ^1.0.2
3838
bitcoin_base:
3939
path: ../
40-
blockchain_utils:
41-
path: ../../../blockchain_utils
42-
# blockchain_utils: ^3.5.0
40+
# blockchain_utils:
41+
# path: ../../blockchain_utils
42+
blockchain_utils: ^3.6.0
4343
http: ^1.2.0
4444

4545
dev_dependencies:

‎lib/bitcoin_base.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// including spending transactions, Bitcoin address management,
55
/// Bitcoin Schnorr signatures, BIP-39 mnemonic phrase generation,
66
/// hierarchical deterministic (HD) wallet derivation, and Web3 Secret Storage Definition.
7-
library;
7+
library bitcoin_base;
88

99
export 'package:bitcoin_base/src/bitcoin/address/address.dart';
1010

‎lib/src/bitcoin/address/address.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// - Utility functions for address manipulation.
77
// - encode/decode Segregated Witness (SegWit) address implementation.
88
// - Enhanced functionality for improved handling of addresses across diverse networks.
9-
library;
9+
library address;
1010

1111
import 'package:bitcoin_base/bitcoin_base.dart';
1212
import 'package:bitcoin_base/src/exception/exception.dart';

‎lib/src/bitcoin/address/core.dart

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ abstract class BitcoinAddressType implements Enumerate {
2121
// Enum values as a list for iteration
2222
static const List<BitcoinAddressType> values = [
2323
P2pkhAddressType.p2pkh,
24-
SegwitAddresType.p2wpkh,
25-
SegwitAddresType.p2tr,
26-
SegwitAddresType.p2wsh,
24+
SegwitAddressType.p2wpkh,
25+
SegwitAddressType.p2tr,
26+
SegwitAddressType.p2wsh,
2727
P2shAddressType.p2wshInP2sh,
2828
P2shAddressType.p2wpkhInP2sh,
2929
P2shAddressType.p2pkhInP2sh,
@@ -59,7 +59,7 @@ abstract class BitcoinBaseAddress {
5959
}
6060

6161
class PubKeyAddressType extends BitcoinAddressType {
62-
const PubKeyAddressType._(super.value) : super._();
62+
const PubKeyAddressType._(String value) : super._(value);
6363
static const PubKeyAddressType p2pk = PubKeyAddressType._("P2PK");
6464
@override
6565
bool get isP2sh => false;
@@ -75,7 +75,7 @@ class PubKeyAddressType extends BitcoinAddressType {
7575
}
7676

7777
class P2pkhAddressType extends BitcoinAddressType {
78-
const P2pkhAddressType._(super.value) : super._();
78+
const P2pkhAddressType._(String value) : super._(value);
7979
static const P2pkhAddressType p2pkh = P2pkhAddressType._("P2PKH");
8080
static const P2pkhAddressType p2pkhwt = P2pkhAddressType._("P2PKHWT");
8181

@@ -93,8 +93,8 @@ class P2pkhAddressType extends BitcoinAddressType {
9393
}
9494

9595
class P2shAddressType extends BitcoinAddressType {
96-
const P2shAddressType._(super.value, this.hashLength, this.withToken)
97-
: super._();
96+
const P2shAddressType._(String value, this.hashLength, this.withToken)
97+
: super._(value);
9898
static const P2shAddressType p2wshInP2sh = P2shAddressType._(
9999
"P2SH/P2WSH", _BitcoinAddressUtils.hash160DigestLength, false);
100100
static const P2shAddressType p2wpkhInP2sh = P2shAddressType._(
@@ -142,11 +142,11 @@ class P2shAddressType extends BitcoinAddressType {
142142
}
143143
}
144144

145-
class SegwitAddresType extends BitcoinAddressType {
146-
const SegwitAddresType._(super.value) : super._();
147-
static const SegwitAddresType p2wpkh = SegwitAddresType._("P2WPKH");
148-
static const SegwitAddresType p2tr = SegwitAddresType._("P2TR");
149-
static const SegwitAddresType p2wsh = SegwitAddresType._("P2WSH");
145+
class SegwitAddressType extends BitcoinAddressType {
146+
const SegwitAddressType._(String value) : super._(value);
147+
static const SegwitAddressType p2wpkh = SegwitAddressType._("P2WPKH");
148+
static const SegwitAddressType p2tr = SegwitAddressType._("P2TR");
149+
static const SegwitAddressType p2wsh = SegwitAddressType._("P2WSH");
150150
@override
151151
bool get isP2sh => false;
152152
@override
@@ -155,7 +155,7 @@ class SegwitAddresType extends BitcoinAddressType {
155155
@override
156156
int get hashLength {
157157
switch (this) {
158-
case SegwitAddresType.p2wpkh:
158+
case SegwitAddressType.p2wpkh:
159159
return 20;
160160
default:
161161
return 32;
@@ -164,6 +164,6 @@ class SegwitAddresType extends BitcoinAddressType {
164164

165165
@override
166166
String toString() {
167-
return "SegwitAddresType.$value";
167+
return "SegwitAddressType.$value";
168168
}
169169
}

‎lib/src/bitcoin/address/legacy_address.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ abstract class LegacyAddress implements BitcoinBaseAddress {
4545

4646
class P2shAddress extends LegacyAddress {
4747
P2shAddress.fromScript(
48-
{required super.script, this.type = P2shAddressType.p2pkInP2sh})
49-
: super.fromScript();
48+
{required Script script, this.type = P2shAddressType.p2pkInP2sh})
49+
: super.fromScript(script: script);
5050

5151
P2shAddress.fromAddress(
52-
{required super.address,
53-
required super.network,
52+
{required String address,
53+
required BasedUtxoNetwork network,
5454
this.type = P2shAddressType.p2pkInP2sh})
55-
: super.fromAddress();
55+
: super.fromAddress(address: address, network: network);
5656
P2shAddress.fromHash160(
5757
{required String addrHash, this.type = P2shAddressType.p2pkInP2sh})
5858
: super.fromHash160(addrHash, type);
@@ -81,13 +81,13 @@ class P2shAddress extends LegacyAddress {
8181

8282
class P2pkhAddress extends LegacyAddress {
8383
P2pkhAddress.fromScript(
84-
{required super.script, this.type = P2pkhAddressType.p2pkh})
85-
: super.fromScript();
84+
{required Script script, this.type = P2pkhAddressType.p2pkh})
85+
: super.fromScript(script: script);
8686
P2pkhAddress.fromAddress(
87-
{required super.address,
88-
required super.network,
87+
{required String address,
88+
required BasedUtxoNetwork network,
8989
this.type = P2pkhAddressType.p2pkh})
90-
: super.fromAddress();
90+
: super.fromAddress(address: address, network: network);
9191
P2pkhAddress.fromHash160(
9292
{required String addrHash, this.type = P2pkhAddressType.p2pkh})
9393
: super.fromHash160(addrHash, type);

‎lib/src/bitcoin/address/network_address.dart

+19
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,22 @@ class BitcoinSVAddress extends BitcoinNetworkAddress<BitcoinSVNetwork> {
162162
baseAddress, baseAddress.toAddress(network), network);
163163
}
164164
}
165+
166+
/// A concrete implementation of [BitcoinNetworkAddress] for Electra protocol network.
167+
class ElectraProtocolAddress
168+
extends BitcoinNetworkAddress<ElectraProtocolNetwork> {
169+
const ElectraProtocolAddress._(BitcoinBaseAddress baseAddress, String address,
170+
ElectraProtocolNetwork network)
171+
: super._(address: address, baseAddress: baseAddress, network: network);
172+
factory ElectraProtocolAddress(String address,
173+
{ElectraProtocolNetwork network = ElectraProtocolNetwork.mainnet}) {
174+
return ElectraProtocolAddress._(
175+
_BitcoinAddressUtils.decodeAddress(address, network), address, network);
176+
}
177+
factory ElectraProtocolAddress.fromBaseAddress(BitcoinBaseAddress address,
178+
{ElectraProtocolNetwork network = ElectraProtocolNetwork.mainnet}) {
179+
final baseAddress = _BitcoinAddressUtils.validateAddress(address, network);
180+
return ElectraProtocolAddress._(
181+
baseAddress, baseAddress.toAddress(network), network);
182+
}
183+
}

‎lib/src/bitcoin/address/segwit_address.dart

+40-22
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class SegwitAddress implements BitcoinBaseAddress {
1515
SegwitAddress.fromProgram(
1616
{required String program,
1717
required this.segwitVersion,
18-
required SegwitAddresType addresType})
18+
required SegwitAddressType addresType})
1919
: addressProgram =
2020
_BitcoinAddressUtils.validateAddressProgram(program, addresType);
2121
SegwitAddress.fromScript(
@@ -46,15 +46,21 @@ abstract class SegwitAddress implements BitcoinBaseAddress {
4646
}
4747

4848
class P2wpkhAddress extends SegwitAddress {
49-
P2wpkhAddress.fromAddress({required super.address, required super.network})
50-
: super.fromAddress(segwitVersion: _BitcoinAddressUtils.segwitV0);
49+
P2wpkhAddress.fromAddress(
50+
{required String address, required BasedUtxoNetwork network})
51+
: super.fromAddress(
52+
segwitVersion: _BitcoinAddressUtils.segwitV0,
53+
address: address,
54+
network: network);
5155

52-
P2wpkhAddress.fromProgram({required super.program})
56+
P2wpkhAddress.fromProgram({required String program})
5357
: super.fromProgram(
5458
segwitVersion: _BitcoinAddressUtils.segwitV0,
55-
addresType: SegwitAddresType.p2wpkh);
56-
P2wpkhAddress.fromScript({required super.script})
57-
: super.fromScript(segwitVersion: _BitcoinAddressUtils.segwitV0);
59+
addresType: SegwitAddressType.p2wpkh,
60+
program: program);
61+
P2wpkhAddress.fromScript({required Script script})
62+
: super.fromScript(
63+
segwitVersion: _BitcoinAddressUtils.segwitV0, script: script);
5864

5965
/// returns the scriptPubKey of a P2WPKH witness script
6066
@override
@@ -64,18 +70,24 @@ class P2wpkhAddress extends SegwitAddress {
6470

6571
/// returns the type of address
6672
@override
67-
SegwitAddresType get type => SegwitAddresType.p2wpkh;
73+
SegwitAddressType get type => SegwitAddressType.p2wpkh;
6874
}
6975

7076
class P2trAddress extends SegwitAddress {
71-
P2trAddress.fromAddress({required super.address, required super.network})
72-
: super.fromAddress(segwitVersion: _BitcoinAddressUtils.segwitV1);
73-
P2trAddress.fromProgram({required super.program})
77+
P2trAddress.fromAddress(
78+
{required String address, required BasedUtxoNetwork network})
79+
: super.fromAddress(
80+
segwitVersion: _BitcoinAddressUtils.segwitV1,
81+
address: address,
82+
network: network);
83+
P2trAddress.fromProgram({required String program})
7484
: super.fromProgram(
7585
segwitVersion: _BitcoinAddressUtils.segwitV1,
76-
addresType: SegwitAddresType.p2tr);
77-
P2trAddress.fromScript({required super.script})
78-
: super.fromScript(segwitVersion: _BitcoinAddressUtils.segwitV1);
86+
addresType: SegwitAddressType.p2tr,
87+
program: program);
88+
P2trAddress.fromScript({required Script script})
89+
: super.fromScript(
90+
segwitVersion: _BitcoinAddressUtils.segwitV1, script: script);
7991

8092
/// returns the scriptPubKey of a P2TR witness script
8193
@override
@@ -85,18 +97,24 @@ class P2trAddress extends SegwitAddress {
8597

8698
/// returns the type of address
8799
@override
88-
SegwitAddresType get type => SegwitAddresType.p2tr;
100+
SegwitAddressType get type => SegwitAddressType.p2tr;
89101
}
90102

91103
class P2wshAddress extends SegwitAddress {
92-
P2wshAddress.fromAddress({required super.address, required super.network})
93-
: super.fromAddress(segwitVersion: _BitcoinAddressUtils.segwitV0);
94-
P2wshAddress.fromProgram({required super.program})
104+
P2wshAddress.fromAddress(
105+
{required String address, required BasedUtxoNetwork network})
106+
: super.fromAddress(
107+
segwitVersion: _BitcoinAddressUtils.segwitV0,
108+
address: address,
109+
network: network);
110+
P2wshAddress.fromProgram({required String program})
95111
: super.fromProgram(
96112
segwitVersion: _BitcoinAddressUtils.segwitV0,
97-
addresType: SegwitAddresType.p2wsh);
98-
P2wshAddress.fromScript({required super.script})
99-
: super.fromScript(segwitVersion: _BitcoinAddressUtils.segwitV0);
113+
addresType: SegwitAddressType.p2wsh,
114+
program: program);
115+
P2wshAddress.fromScript({required Script script})
116+
: super.fromScript(
117+
segwitVersion: _BitcoinAddressUtils.segwitV0, script: script);
100118

101119
/// Returns the scriptPubKey of a P2WPKH witness script
102120
@override
@@ -106,5 +124,5 @@ class P2wshAddress extends SegwitAddress {
106124

107125
/// Returns the type of address
108126
@override
109-
SegwitAddresType get type => SegwitAddresType.p2wsh;
127+
SegwitAddressType get type => SegwitAddressType.p2wsh;
110128
}

‎lib/src/bitcoin/address/utils/address_utils.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class _BitcoinAddressUtils {
153153
static BitcoinBaseAddress decodeAddress(
154154
String address, BasedUtxoNetwork network) {
155155
BitcoinBaseAddress? baseAddress;
156-
if (network.supportedAddress.contains(SegwitAddresType.p2wpkh)) {
156+
if (network.supportedAddress.contains(SegwitAddressType.p2wpkh)) {
157157
baseAddress = toSegwitAddress(address, network);
158158
}
159159
baseAddress ??= toLegacy(address, network);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library;
1+
library op_code;
22

33
export 'constant.dart';
44
export 'tools.dart';

‎lib/src/bitcoin_cash/bcmr_registery.dart

+24-13
Original file line numberDiff line numberDiff line change
@@ -699,17 +699,26 @@ class ChainSnapshot extends IdentitySnapshot {
699699
: null,
700700
);
701701
}
702-
const ChainSnapshot({
703-
required super.name,
704-
required TokenCategory super.token,
705-
super.description,
706-
super.tags,
707-
super.migrated,
708-
super.status,
709-
super.splitId,
710-
super.uris,
711-
super.extensions,
712-
});
702+
ChainSnapshot(
703+
{required String name,
704+
required String? description,
705+
required List<String>? tags,
706+
required String? migrated,
707+
required TokenCategory token,
708+
required String? status,
709+
required String? splitId,
710+
required URIs? uris,
711+
required Extensions? extensions})
712+
: super(
713+
name: name,
714+
description: description,
715+
tags: tags,
716+
migrated: migrated,
717+
token: token,
718+
status: status,
719+
splitId: splitId,
720+
uris: uris,
721+
extensions: extensions);
713722
}
714723

715724
class RegistryTimestampKeyedValues<T extends IdentitySnapshot> {
@@ -722,7 +731,8 @@ class RegistryTimestampKeyedValues<T extends IdentitySnapshot> {
722731
}
723732

724733
class ChainHistory extends RegistryTimestampKeyedValues<ChainSnapshot> {
725-
const ChainHistory({required super.timestampMap});
734+
const ChainHistory({required Map<String, ChainSnapshot> timestampMap})
735+
: super(timestampMap: timestampMap);
726736

727737
factory ChainHistory.fromJson(Map<String, dynamic> json) {
728738
return ChainHistory(
@@ -734,7 +744,8 @@ class ChainHistory extends RegistryTimestampKeyedValues<ChainSnapshot> {
734744
}
735745

736746
class IdentityHistory extends RegistryTimestampKeyedValues<IdentitySnapshot> {
737-
const IdentityHistory({required super.timestampMap});
747+
const IdentityHistory({required Map<String, IdentitySnapshot> timestampMap})
748+
: super(timestampMap: timestampMap);
738749

739750
factory IdentityHistory.fromJson(Map<String, dynamic> json) {
740751
return IdentityHistory(

‎lib/src/crypto/crypto.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library;
1+
library crypto;
22

33
import 'package:bitcoin_base/src/bitcoin/script/op_code/constant_lib.dart';
44
import 'package:blockchain_utils/crypto/quick_crypto.dart';

‎lib/src/exception/exception.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:blockchain_utils/blockchain_utils.dart';
22

33
class DartBitcoinPluginException extends BlockchainUtilsException {
4-
const DartBitcoinPluginException(super.message, {super.details});
4+
const DartBitcoinPluginException(String message,
5+
{Map<String, dynamic>? details})
6+
: super(message, details: details);
57
}

‎lib/src/models/network.dart

+20-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import 'package:bitcoin_base/bitcoin_base.dart';
22
import 'package:bitcoin_base/src/exception/exception.dart';
33
import 'package:bitcoin_base/src/utils/enumerate.dart';
4-
import 'package:blockchain_utils/bip/coin_conf/coin_conf.dart';
5-
import 'package:blockchain_utils/bip/coin_conf/coins_conf.dart';
64
import 'package:blockchain_utils/blockchain_utils.dart';
75

86
/// Abstract class representing a base for UTXO-based cryptocurrency networks.
@@ -159,10 +157,10 @@ class BitcoinNetwork implements BasedUtxoNetwork {
159157
@override
160158
List<BitcoinAddressType> get supportedAddress => [
161159
P2pkhAddressType.p2pkh,
162-
SegwitAddresType.p2wpkh,
160+
SegwitAddressType.p2wpkh,
163161
PubKeyAddressType.p2pk,
164-
SegwitAddresType.p2tr,
165-
SegwitAddresType.p2wsh,
162+
SegwitAddressType.p2tr,
163+
SegwitAddressType.p2wsh,
166164
P2shAddressType.p2wshInP2sh,
167165
P2shAddressType.p2wpkhInP2sh,
168166
P2shAddressType.p2pkhInP2sh,
@@ -231,9 +229,9 @@ class LitecoinNetwork implements BasedUtxoNetwork {
231229
@override
232230
final List<BitcoinAddressType> supportedAddress = const [
233231
P2pkhAddressType.p2pkh,
234-
SegwitAddresType.p2wpkh,
232+
SegwitAddressType.p2wpkh,
235233
PubKeyAddressType.p2pk,
236-
SegwitAddresType.p2wsh,
234+
SegwitAddressType.p2wsh,
237235
P2shAddressType.p2wshInP2sh,
238236
P2shAddressType.p2wpkhInP2sh,
239237
P2shAddressType.p2pkhInP2sh,
@@ -501,26 +499,21 @@ class PepeNetwork implements BasedUtxoNetwork {
501499
class ElectraProtocolNetwork implements BasedUtxoNetwork {
502500
/// Mainnet configuration with associated `CoinConf`.
503501
static const ElectraProtocolNetwork mainnet = ElectraProtocolNetwork._(
504-
"electraProtocolMainnet",
505-
CoinsConf.electraProtocolMainNet,
506-
);
502+
"electraProtocolMainnet", CoinsConf.electraProtocolMainNet);
507503

508504
/// Testnet configuration with associated `CoinConf`.
509505
static const ElectraProtocolNetwork testnet = ElectraProtocolNetwork._(
510-
"electraProtocolTestnet",
511-
CoinsConf.electraProtocolTestNet,
512-
);
506+
"electraProtocolTestnet", CoinsConf.electraProtocolTestNet);
513507

514508
/// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`.
515509
@override
516510
final CoinConf conf;
517-
518-
/// Constructor for creating a OmniXEP network with a specific configuration.
519-
const ElectraProtocolNetwork._(this.value, this.conf);
520-
521511
@override
522512
final String value;
523513

514+
/// Constructor for creating a Electra Protocol network with a specific configuration.
515+
const ElectraProtocolNetwork._(this.value, this.conf);
516+
524517
/// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`.
525518
@override
526519
List<int> get wifNetVer => conf.params.wifNetVer!;
@@ -533,7 +526,8 @@ class ElectraProtocolNetwork implements BasedUtxoNetwork {
533526
@override
534527
List<int> get p2shNetVer => conf.params.p2shNetVer!;
535528

536-
/// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses.
529+
/// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses
530+
/// from the associated `CoinConf`.
537531
@override
538532
String get p2wpkhHrp => conf.params.p2wpkhHrp!;
539533

@@ -543,14 +537,14 @@ class ElectraProtocolNetwork implements BasedUtxoNetwork {
543537

544538
@override
545539
final List<BitcoinAddressType> supportedAddress = const [
546-
PubKeyAddressType.p2pk,
547540
P2pkhAddressType.p2pkh,
548-
SegwitAddresType.p2wpkh,
549-
SegwitAddresType.p2wsh,
550-
P2shAddressType.p2pkInP2sh,
551-
P2shAddressType.p2pkhInP2sh,
552-
P2shAddressType.p2wpkhInP2sh,
541+
SegwitAddressType.p2wpkh,
542+
PubKeyAddressType.p2pk,
543+
SegwitAddressType.p2wsh,
553544
P2shAddressType.p2wshInP2sh,
545+
P2shAddressType.p2wpkhInP2sh,
546+
P2shAddressType.p2pkhInP2sh,
547+
P2shAddressType.p2pkInP2sh,
554548
];
555549

556550
@override
@@ -559,13 +553,13 @@ class ElectraProtocolNetwork implements BasedUtxoNetwork {
559553
return [
560554
Bip44Coins.electraProtocol,
561555
Bip49Coins.electraProtocol,
562-
Bip84Coins.electraProtocol,
556+
Bip84Coins.electraProtocol
563557
];
564558
}
565559
return [
566560
Bip44Coins.electraProtocolTestnet,
567561
Bip49Coins.electraProtocolTestnet,
568-
Bip84Coins.electraProtocolTestnet,
562+
Bip84Coins.electraProtocolTestnet
569563
];
570564
}
571565
}

‎lib/src/provider/models/multisig_script.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MultiSignatureSigner {
2323
{required String publicKey, required int weight}) {
2424
ECPublic.fromHex(publicKey);
2525
return MultiSignatureSigner._(
26-
publicKey, weight, BtcUtils.isCompressedPubKey(publicKey));
26+
publicKey, weight, BtcUtils.hasCompressedPubKeyLength(publicKey));
2727
}
2828
}
2929

@@ -91,7 +91,7 @@ class MultiSignatureAddress {
9191
{required BasedUtxoNetwork network,
9292
required BitcoinAddressType addressType}) {
9393
switch (addressType) {
94-
case SegwitAddresType.p2wsh:
94+
case SegwitAddressType.p2wsh:
9595
return toP2wshAddress(network: network);
9696
case P2shAddressType.p2wshInP2sh:
9797
return toP2wshInP2shAddress(network: network);

‎lib/src/provider/models/utxo_details.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class UtxoAddressDetails {
2121
required this.address,
2222
}) : _multiSigAddress = null,
2323
_publicKey = publicKey;
24+
25+
/// The public key format (compressed or uncompressed) is crucial for non-SegWit addresses.
26+
/// If your address is non-SegWit, ensure you use the correct public key format.
2427
factory UtxoAddressDetails(
2528
{required String publicKey, required BitcoinBaseAddress address}) {
2629
ECPublic.fromHex(publicKey);
@@ -56,7 +59,7 @@ class UtxoWithAddress {
5659
utxo: utxo,
5760
ownerDetails: ownerDetails,
5861
isCompressed: ownerDetails._publicKey != null && !utxo.isSegwit
59-
? BtcUtils.isCompressedPubKey(ownerDetails._publicKey)
62+
? BtcUtils.hasCompressedPubKeyLength(ownerDetails._publicKey!)
6063
: true);
6164
}
6265

@@ -225,7 +228,7 @@ class BitcoinUtxo {
225228
token: token,
226229
vout: vout,
227230
scriptType: scriptType,
228-
isP2tr: scriptType == SegwitAddresType.p2tr,
231+
isP2tr: scriptType == SegwitAddressType.p2tr,
229232
isP2shSegwit: isP2shSegwit,
230233
isSegwit: isP2shSegwit || scriptType.isSegwit);
231234
}

‎lib/src/provider/transaction_builder/transaction_builder.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
180180
.toScriptPubKey();
181181
}
182182
return script;
183-
case SegwitAddresType.p2wsh:
183+
case SegwitAddressType.p2wsh:
184184
if (isTaproot) {
185185
return multiSigAAddr
186186
.toP2wshAddress(network: network)
@@ -202,7 +202,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
202202
switch (utxo.utxo.scriptType) {
203203
case PubKeyAddressType.p2pk:
204204
return senderPub.toRedeemScript(compressed: utxo.isCompressed);
205-
case SegwitAddresType.p2wsh:
205+
case SegwitAddressType.p2wsh:
206206
if (isTaproot) {
207207
return senderPub.toP2wshAddress().toScriptPubKey();
208208
}
@@ -211,12 +211,12 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder {
211211
return senderPub
212212
.toAddress(compressed: utxo.isCompressed)
213213
.toScriptPubKey();
214-
case SegwitAddresType.p2wpkh:
214+
case SegwitAddressType.p2wpkh:
215215
if (isTaproot) {
216216
return senderPub.toSegwitAddress().toScriptPubKey();
217217
}
218218
return senderPub.toAddress().toScriptPubKey();
219-
case SegwitAddresType.p2tr:
219+
case SegwitAddressType.p2tr:
220220
return senderPub.toTaprootAddress().toScriptPubKey();
221221
case P2shAddressType.p2pkhInP2sh:
222222
if (isTaproot) {
@@ -354,10 +354,10 @@ that demonstrate the right to spend the bitcoins associated with the correspondi
354354
}
355355
switch (utx.utxo.scriptType) {
356356
case P2shAddressType.p2wshInP2sh:
357-
case SegwitAddresType.p2wsh:
357+
case SegwitAddressType.p2wsh:
358358
final script = senderPub.toP2wshScript();
359359
return ['', signedDigest, script.toHex()];
360-
case SegwitAddresType.p2wpkh:
360+
case SegwitAddressType.p2wpkh:
361361
case P2shAddressType.p2wpkhInP2sh:
362362
return [signedDigest, senderPub.toHex()];
363363
default:

‎lib/src/utils/btc_utils.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:blockchain_utils/utils/numbers/rational/big_rational.dart';
22
import 'package:blockchain_utils/utils/string/string.dart';
33

44
class BtcUtils {
5-
static bool isCompressedPubKey(String publicKey) {
5+
static bool hasCompressedPubKeyLength(String publicKey) {
66
return StringUtils.strip0x(publicKey.toLowerCase()).length == 66;
77
}
88

‎pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: bitcoin_base
22
description: A versatile library for Bitcoin, Dogecoin, Litecoin, Dash, BSV, and BCH. Supports P2PKH, P2SH, P2WPKH, P2WSH, P2TR, with advanced creation, signing, and spending capabilities.
3-
version: 4.9.2
3+
version: 4.9.4
44
homepage: "https://github.com/mrtnetwork/bitcoin_base"
55
repository: "https://github.com/mrtnetwork/bitcoin_base"
66
Author: mrhaydari.t@gmail.com
@@ -12,14 +12,14 @@ topics:
1212
- dash
1313

1414
environment:
15-
sdk: '>=3.3.0 <4.0.0'
15+
sdk: '>=2.15.0 <4.0.0'
1616

1717

1818
dependencies:
19-
blockchain_utils: ^3.5.0
19+
blockchain_utils: ^3.6.0
2020

2121
# blockchain_utils:
22-
# path: ../../blockchain_utils
22+
# path: ../blockchain_utils
2323

2424

2525
dev_dependencies:

‎test/xep_address_test.dart

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'package:bitcoin_base/bitcoin_base.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
_test();
6+
}
7+
8+
void _test() {
9+
test("xep address parsing", () {
10+
ElectraProtocolAddress address =
11+
ElectraProtocolAddress("ep1qyv4uspwsphhvj5keth02dk37pd0gqzmt5tw973");
12+
expect(address.type, SegwitAddressType.p2wpkh);
13+
address =
14+
ElectraProtocolAddress("ep1q2nxmsj9h9s6ps4tp5fce2vclm8uvkn00dtrnu7");
15+
expect(address.type, SegwitAddressType.p2wpkh);
16+
address = ElectraProtocolAddress("x8UFjR4n2h6hgFRJDdAna5nvN71qfsDmns");
17+
expect(address.type, P2shAddressType.p2pkInP2sh);
18+
address = ElectraProtocolAddress("xWzvSGpYUPucJaodadUh3yzEmLJGvHUYsP");
19+
expect(address.type, P2shAddressType.p2pkInP2sh);
20+
address = ElectraProtocolAddress("xWzvSGpYUPucJaodadUh3yzEmLJGvHUYsP");
21+
expect(address.type, P2shAddressType.p2pkInP2sh);
22+
});
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.