Skip to content

Commit 80b1883

Browse files
authored
Feature: Import Bech32 (#25)
The purpose of this branch is to replace Bech32 from bech32 library with our implementation in codec_utils. List of changes: - updated Bech32 implementation to use codec_utils in bitcoin_p2wpkh_address_encoder.dart, cosmos_address_encoder.dart, cosmos_acc_address.dart
1 parent f87b1e0 commit 80b1883

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

lib/src/bip/bip32/address_encoders/bitcoin/bitcoin_p2wpkh_address_encoder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ class BitcoinP2WPKHAddressEncoder extends ABlockchainAddressEncoder<Secp256k1Pub
2626
Uint8List publicKeyFingerprint = Sha256().convert(publicKey.compressed).byteList;
2727
Uint8List publicKeyHash = Ripemd160().process(publicKeyFingerprint);
2828

29-
return SegwitBech32Codec.encode(hrp, _witnessVersion, publicKeyHash);
29+
return SegWitEncoder().encode(SegWit(hrp, _witnessVersion, publicKeyHash));
3030
}
3131
}

lib/src/bip/bip32/address_encoders/cosmos_address_encoder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CosmosAddressEncoder extends ABlockchainAddressEncoder<Secp256k1PublicKey>
2222
String encodePublicKey(Secp256k1PublicKey publicKey) {
2323
Uint8List publicKeyFingerprint = Sha256().convert(publicKey.compressed).byteList;
2424
Uint8List publicKeyHash = Ripemd160().process(publicKeyFingerprint);
25-
26-
return Bech32Codec.encode(Bech32Pair(hrp: hrp, data: publicKeyHash));
25+
Bech32 bech32 = Bech32(hrp, publicKeyHash);
26+
return Bech32Encoder().encode(bech32);
2727
}
2828
}

lib/src/transactions/cosmos/cosmos_acc_address.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,29 @@ class CosmosAccAddress extends AProtobufField {
99
final String hrp;
1010

1111
/// The bytes of the address
12-
final Uint8List bytes;
12+
final Uint8List uint8List;
1313

1414
/// Creates [CosmosAccountAddress] from a Bech32 encoded address.
1515
factory CosmosAccAddress(String address) {
16-
Bech32Pair decodedBech32 = Bech32Codec.decode(address);
17-
return CosmosAccAddress._(decodedBech32.hrp, decodedBech32.data);
16+
Bech32 decodedBech32 = Bech32Decoder().decode(address);
17+
return CosmosAccAddress._(decodedBech32.hrp, decodedBech32.uint8List);
1818
}
1919

2020
/// Private constructor used by the factory to initialize the hrp and bytes.
21-
const CosmosAccAddress._(this.hrp, this.bytes);
21+
const CosmosAccAddress._(this.hrp, this.uint8List);
2222

2323
@override
2424
List<int> encode(int fieldNumber) {
25-
return ProtobufBytes(bytes).encode(fieldNumber);
25+
return ProtobufBytes(uint8List).encode(fieldNumber);
2626
}
2727

2828
/// Returns the Bech32 encoded address as a string.
29-
String get value => Bech32Codec.encode(Bech32Pair(hrp: hrp, data: bytes));
29+
String get value {
30+
return Bech32Encoder().encode(Bech32(hrp, uint8List));
31+
}
3032

3133
@override
32-
List<Object?> get props => <Object?>[hrp, bytes];
34+
List<Object?> get props => <Object?>[hrp, uint8List];
3335

3436
@override
3537
String toString() => value;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: cryptography_utils
22
description: "Dart package containing utility methods for common cryptographic and blockchain-specific operations"
33
publish_to: none
4-
version: 0.0.24
4+
version: 0.0.25
55

66
environment:
77
sdk: ">=3.2.6"

0 commit comments

Comments
 (0)