Skip to content

Commit

Permalink
feat!: update transactions inputs hash size (#643)
Browse files Browse the repository at this point in the history
* feat: update transactions inputs hash

* feat: add transaction inputs test

* feat: make X509Envelope class final

---------

Co-authored-by: Oleksandr Prokhorenko <djminikin@gmail.com>
  • Loading branch information
dtscalac and minikin authored Jul 31, 2024
1 parent 69dba1d commit a729823
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ final class TransactionHash extends BaseHash {
int get length => _length;
}

/// Describes the Blake2b-256 hash of the transaction inputs (UTXOs)
/// Describes the Blake2b-128 hash of the transaction inputs (UTXOs)
/// which can be used as a link to a certain transaction
/// (as UTXOs can only be spent once).
final class TransactionInputsHash extends BaseHash {
static const int _length = 32;
static const int _length = 16;

/// Constructs the [TransactionInputsHash] from raw [bytes].
TransactionInputsHash.fromBytes({required super.bytes}) : super.fromBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef ChunkedDataDeserializer<T> = T Function(CborValue value);
/// between those references being altered and closes a potential attack vector
/// where an unrelated registration update is attached to a different
/// transaction.
class X509MetadataEnvelope<T> extends Equatable {
final class X509MetadataEnvelope<T> extends Equatable {
/// The size of a chunk of data that is used to overcome
/// the field size limitation.
static const int metadataChunkSize = 64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,39 @@ void main() {
});
});

group(TransactionInputsHash, () {
const hexString = '4d3f576f26db29139981a69443c2325d';
final bytes = hex.decode(hexString);

test('from and to hex', () {
final hash = TransactionInputsHash.fromHex(hexString);
expect(hash.toHex(), equals(hexString));
});

test('from and to bytes', () {
final hash = TransactionInputsHash.fromBytes(bytes: bytes);
expect(hash.bytes, equals(bytes));
});

test('from transaction inputs', () {
final hash = TransactionInputsHash.fromTransactionInputs([testUtxo()]);
expect(
hash,
equals(
TransactionInputsHash.fromHex('26497de5e0c8fe2e4b0c85651f96b3c9'),
),
);
});

test('toCbor returns bytes', () {
final hash = TransactionInputsHash.fromBytes(bytes: bytes);
final encodedCbor = cbor.encode(hash.toCbor());
final decodedCbor = cbor.decode(encodedCbor);
expect(decodedCbor, isA<CborBytes>());
expect((decodedCbor as CborBytes).bytes, equals(bytes));
});
});

group(AuxiliaryDataHash, () {
const hexString =
'4d3f576f26db29139981a69443c2325daa812cc353a31b5a4db794a5bcbb06c2';
Expand Down

0 comments on commit a729823

Please sign in to comment.