Update Hash Types as per @mratsim's comments on #18
This commit is contained in:
parent
6287573adc
commit
78a830da27
|
@ -17,13 +17,19 @@ deserializing objects and data types.
|
||||||
+ [Serialize/Encode](#serializeencode)
|
+ [Serialize/Encode](#serializeencode)
|
||||||
- [uint: 8/16/24/32/64/256](#uint-816243264256)
|
- [uint: 8/16/24/32/64/256](#uint-816243264256)
|
||||||
- [Address](#address)
|
- [Address](#address)
|
||||||
- [Hash32](#hash32)
|
- [Hash](#hash)
|
||||||
|
* [Hash32](#hash32)
|
||||||
|
* [Hash96](#hash96)
|
||||||
|
* [Hash97](#hash97)
|
||||||
- [Bytes](#bytes)
|
- [Bytes](#bytes)
|
||||||
- [List](#list)
|
- [List](#list)
|
||||||
+ [Deserialize/Decode](#deserializedecode)
|
+ [Deserialize/Decode](#deserializedecode)
|
||||||
- [uint: 8/16/24/32/64/256](#uint-816243264256-1)
|
- [uint: 8/16/24/32/64/256](#uint-816243264256-1)
|
||||||
- [Address](#address-1)
|
- [Address](#address-1)
|
||||||
- [Hash32](#hash32-1)
|
- [Hash](#hash-1)
|
||||||
|
* [Hash32](#hash32-1)
|
||||||
|
* [Hash96](#hash96-1)
|
||||||
|
* [Hash97](#hash97-1)
|
||||||
- [Bytes](#bytes-1)
|
- [Bytes](#bytes-1)
|
||||||
- [List](#list-1)
|
- [List](#list-1)
|
||||||
* [Implementations](#implementations)
|
* [Implementations](#implementations)
|
||||||
|
@ -89,17 +95,61 @@ assert( len(value) == 20 )
|
||||||
return value
|
return value
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Hash32
|
#### Hash
|
||||||
|
|
||||||
The hash32 should already be a 32 byte length serialized data format. The safety
|
| Hash Type | Usage |
|
||||||
check ensures the 32 byte length is satisfied.
|
|:---------:|:------------------------------------------------|
|
||||||
|
| `hash32` | Hash size of ``keccak`` or `blake2b[0.. < 32]`. |
|
||||||
|
| `hash96` | BLS Public Key Size. |
|
||||||
|
| `hash97` | BLS Public Key Size with recovery bit. |
|
||||||
|
|
||||||
| Check to perform | Code |
|
|
||||||
|:-----------------------|:---------------------|
|
| Checks to perform | Code |
|
||||||
| Length is correct (32) | ``len(value) == 32`` |
|
|:-----------------------------------|:---------------------|
|
||||||
|
| Length is correct (32) if `hash32` | ``len(value) == 32`` |
|
||||||
|
| Length is correct (96) if `hash96` | ``len(value) == 96`` |
|
||||||
|
| Length is correct (97) if `hash97` | ``len(value) == 97`` |
|
||||||
|
|
||||||
|
|
||||||
|
**Example all together**
|
||||||
|
|
||||||
```python
|
```python
|
||||||
assert( len(value) == 32 )
|
if (type(value) == 'hash32'):
|
||||||
|
assert(len(value) == 32)
|
||||||
|
elif (type(value) == 'hash96'):
|
||||||
|
assert(len(value) == 96)
|
||||||
|
elif (type(value) == 'hash97'):
|
||||||
|
assert(len(value) == 97)
|
||||||
|
else:
|
||||||
|
raise TypeError('Invalid hash type supplied')
|
||||||
|
|
||||||
|
return value
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Hash32
|
||||||
|
|
||||||
|
Ensure 32 byte length and return the bytes.
|
||||||
|
|
||||||
|
```python
|
||||||
|
assert(len(value) == 32)
|
||||||
|
return value
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Hash96
|
||||||
|
|
||||||
|
Ensure 96 byte length and return the bytes.
|
||||||
|
|
||||||
|
```python
|
||||||
|
assert(len(value) == 96)
|
||||||
|
return value
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Hash97
|
||||||
|
|
||||||
|
Ensure 97 byte length and return the bytes.
|
||||||
|
|
||||||
|
```python
|
||||||
|
assert(len(value) == 97)
|
||||||
return value
|
return value
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -176,7 +226,9 @@ new_index = current_index + 20
|
||||||
return rawbytes[current_index:current_index+20], new_index
|
return rawbytes[current_index:current_index+20], new_index
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Hash32
|
#### Hash
|
||||||
|
|
||||||
|
##### Hash32
|
||||||
|
|
||||||
Return the 32 bytes.
|
Return the 32 bytes.
|
||||||
|
|
||||||
|
@ -185,6 +237,25 @@ new_index = current_index + 32
|
||||||
return rawbytes[current_index:current_index+32], new_index
|
return rawbytes[current_index:current_index+32], new_index
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Hash96
|
||||||
|
|
||||||
|
Return the 96 bytes.
|
||||||
|
|
||||||
|
```python
|
||||||
|
new_index = current_index + 96
|
||||||
|
return rawbytes[current_index:current_index+96], new_index
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Hash97
|
||||||
|
|
||||||
|
Return the 97 bytes.
|
||||||
|
|
||||||
|
```python
|
||||||
|
new_index = current_index + 97
|
||||||
|
return rawbytes[current_index:current_index+97], new_index
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Bytes
|
#### Bytes
|
||||||
|
|
||||||
Get the length of the bytes, return the bytes.
|
Get the length of the bytes, return the bytes.
|
||||||
|
|
Loading…
Reference in New Issue