Skip to content

Commit

Permalink
V2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Mar 16, 2024
1 parent fa4ef97 commit 37adda7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.1
- Fix Cbor bigint encoding.

## 2.1.0
- Implements classes for signing and verifying transaction digests.
- Introduces classes for signing and verifying transaction digests, with support for Cardano.
Expand Down
15 changes: 6 additions & 9 deletions lib/cbor/types/bigint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:blockchain_utils/binary/utils.dart';
import 'package:blockchain_utils/cbor/utils/dynamic_bytes.dart';
import 'package:blockchain_utils/cbor/core/tags.dart';
import 'package:blockchain_utils/cbor/core/cbor.dart';
import 'package:blockchain_utils/numbers/numbers.dart';

/// A class representing a CBOR (Concise Binary Object Representation) Bigint value.
class CborBigIntValue implements CborNumeric {
Expand All @@ -24,14 +25,10 @@ class CborBigIntValue implements CborNumeric {
} else {
bytes.pushTags(CborTags.posBigInt);
}
final b = List<int>.filled((v.bitLength + 7) ~/ 8, 0);

for (var i = b.length - 1; i >= 0; i--) {
b[i] = v.toUnsigned(8).toInt();
v >>= 8;
}
bytes.pushInt(MajorTags.byteString, b.length);
bytes.pushBytes(b);
final toBytes =
BigintUtils.toBytes(v, length: BigintUtils.bitlengthInBytes(v));
bytes.pushInt(MajorTags.byteString, toBytes.length);
bytes.pushBytes(toBytes);
return bytes.toBytes();
}

Expand Down Expand Up @@ -67,7 +64,7 @@ class CborBigIntValue implements CborNumeric {
return value == other.value;
}

/// ovveride hash code
/// overide hash code
@override
int get hashCode => value.hashCode;
}
8 changes: 4 additions & 4 deletions lib/cbor/types/int.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:blockchain_utils/binary/utils.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:blockchain_utils/cbor/utils/dynamic_bytes.dart';
import 'package:blockchain_utils/cbor/core/tags.dart';
import 'package:blockchain_utils/cbor/core/cbor.dart';

/// A class representing a CBOR (Concise Binary Object Representation) int value.
class CborIntValue implements CborNumeric {
Expand Down Expand Up @@ -49,8 +48,9 @@ class CborIntValue implements CborNumeric {
/// overide equal operation
@override
operator ==(other) {
if (other is! CborIntValue) return false;
return value == other.value;
if (other is! CborNumeric) return false;
if (other is CborBigIntValue) return false;
return toBigInt() == other.toBigInt();
}

/// ovveride hash code
Expand Down
5 changes: 3 additions & 2 deletions lib/cbor/types/int64.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class CborSafeIntValue implements CborNumeric {
/// override equal operation
@override
operator ==(other) {
if (other is! CborSafeIntValue) return false;
return value == other.value;
if (other is! CborNumeric) return false;
if (other is CborBigIntValue) return false;
return toBigInt() == other.toBigInt();
}

/// override hashcode
Expand Down
8 changes: 6 additions & 2 deletions lib/signer/bitcoin_signer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ class BitcoinSigner {
int lengthR = signature[3];

while (lengthR == 33) {
final attemptBytes = IntUtils.toBytes(attempt, length: 32);
final List<int> extraEntropy = List<int>.filled(32, 0);
final attemptBytes =
IntUtils.toBytes(attempt, length: IntUtils.bitlengthInBytes(attempt));
extraEntropy.setAll(
extraEntropy.length - attemptBytes.length, attemptBytes);

ecdsaSign = signingKey.signDigestDeterminstic(
digest: digest, hashFunc: () => SHA256(), extraEntropy: attemptBytes);
digest: digest, hashFunc: () => SHA256(), extraEntropy: extraEntropy);

signature = BigintUtils.toDer([ecdsaSign.r, ecdsaSign.s]);
attempt += 1;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: blockchain_utils
description: Comprehensive Crypto & Blockchain Toolkit, Pure Dart, Cross-Platform, Encoding, Cryptography, Addresses, Mnemonics, & More.
version: 2.1.0
version: 2.1.1
homepage: "https://github.com/mrtnetwork/blockchain_utils"
repository: "https://github.com/mrtnetwork/blockchain_utils"
Author: [email protected]
Expand Down
1 change: 1 addition & 0 deletions test/signer/bitcoin_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void main() {}
3 changes: 3 additions & 0 deletions test/uuid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:test/test.dart';

void main() {

// print();
// return;
List<int> buffer1 = List<int>.from(
[174, 91, 168, 91, 107, 15, 78, 26, 181, 132, 151, 91, 160, 7, 157, 152]);
List<int> buffer2 = List<int>.from([
Expand Down

0 comments on commit 37adda7

Please sign in to comment.