blockfrost / blockfrost-dotnet

.NET, C# and PowerShell SDK for Blockfrost.io API
Apache License 2.0
17 stars 9 forks source link

Submit transaction via stream #34

Closed tweakch closed 3 years ago

tweakch commented 3 years ago

Description

As described in #35 the Stream could be analyzed prior to sending the transaction. Invalid Streams should be rejected.

Possible implementations

First byte

The first byte appears to (not verified through specific reference) always be a major type 4 followed by the number of elements N.

Example

An array (4 = 0b100) of length 3 = 0b0011 we be represented as 0b100_0011 resp. 0x83

Verification

Peek at the first byte and verify that it is a valid Type 4.

int type0 = 0x83 >> 4; // strip last four bits
bool valid = type0 == 4; // verify it is an array (4)

Second byte

The second byte apears to always be a map major tyoe 5 of the same length as bytes[0].

Example

An map (5 = 0b1001) of length 3 = 0b0011 we be represented as 0b1001_0011 resp. 0xA3

Verfication
int type1 = 0xA3 >> 4;
int len0 = 0x83 & 0xf0;
int len1 = 0xA3 & 0xf0;
bool valid = (type1 == 5) && (len0 == len1);

CBOR specification for reference