From 37adda7fff3a5508ddc0b9e5c3bf28c4b4161a6e Mon Sep 17 00:00:00 2001 From: Mohsen <56779182+mrtnetwork@users.noreply.github.com> Date: Sat, 16 Mar 2024 16:23:59 +0330 Subject: [PATCH] V2.1.1 --- CHANGELOG.md | 3 +++ lib/cbor/types/bigint.dart | 15 ++++++--------- lib/cbor/types/int.dart | 8 ++++---- lib/cbor/types/int64.dart | 5 +++-- lib/signer/bitcoin_signer.dart | 8 ++++++-- pubspec.yaml | 2 +- test/signer/bitcoin_test.dart | 1 + test/uuid_test.dart | 3 +++ 8 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 test/signer/bitcoin_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index ed004fb..61a93dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/cbor/types/bigint.dart b/lib/cbor/types/bigint.dart index 1933be1..fa2928d 100644 --- a/lib/cbor/types/bigint.dart +++ b/lib/cbor/types/bigint.dart @@ -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 { @@ -24,14 +25,10 @@ class CborBigIntValue implements CborNumeric { } else { bytes.pushTags(CborTags.posBigInt); } - final b = List.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(); } @@ -67,7 +64,7 @@ class CborBigIntValue implements CborNumeric { return value == other.value; } - /// ovveride hash code + /// overide hash code @override int get hashCode => value.hashCode; } diff --git a/lib/cbor/types/int.dart b/lib/cbor/types/int.dart index 04789fc..54b3fd6 100644 --- a/lib/cbor/types/int.dart +++ b/lib/cbor/types/int.dart @@ -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 { @@ -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 diff --git a/lib/cbor/types/int64.dart b/lib/cbor/types/int64.dart index f1c6a31..a89a383 100644 --- a/lib/cbor/types/int64.dart +++ b/lib/cbor/types/int64.dart @@ -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 diff --git a/lib/signer/bitcoin_signer.dart b/lib/signer/bitcoin_signer.dart index d0900ae..e7aa69c 100644 --- a/lib/signer/bitcoin_signer.dart +++ b/lib/signer/bitcoin_signer.dart @@ -122,10 +122,14 @@ class BitcoinSigner { int lengthR = signature[3]; while (lengthR == 33) { - final attemptBytes = IntUtils.toBytes(attempt, length: 32); + final List extraEntropy = List.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; diff --git a/pubspec.yaml b/pubspec.yaml index caeac4a..bd7dd34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: mrhaydari.t@gmail.com diff --git a/test/signer/bitcoin_test.dart b/test/signer/bitcoin_test.dart new file mode 100644 index 0000000..ab73b3a --- /dev/null +++ b/test/signer/bitcoin_test.dart @@ -0,0 +1 @@ +void main() {} diff --git a/test/uuid_test.dart b/test/uuid_test.dart index 976c762..9e1c98e 100644 --- a/test/uuid_test.dart +++ b/test/uuid_test.dart @@ -2,6 +2,9 @@ import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:test/test.dart'; void main() { + + // print(); + // return; List buffer1 = List.from( [174, 91, 168, 91, 107, 15, 78, 26, 181, 132, 151, 91, 160, 7, 157, 152]); List buffer2 = List.from([