Class: CryptoconditionsRuby::Types::PreimageSha256Fulfillment
Constant Summary
collapse
- TYPE_ID =
0
- FEATURE_BITMASK =
0x03
Constants inherited
from Fulfillment
Fulfillment::REGEX
Instance Attribute Summary collapse
Instance Method Summary
collapse
#generate_hash
Methods inherited from Fulfillment
#calculate_max_fulfillment_length, #condition, #condition_binary, #condition_uri, from_binary, from_dict, from_uri, #generate_hash, #serialize_binary, #serialize_payload, #serialize_uri, #type_id
#base64_add_padding, #base64_remove_padding, #ed25519_generate_key_pair
Constructor Details
Returns a new instance of PreimageSha256Fulfillment.
9
10
11
12
13
14
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 9
def initialize(preimage = nil)
if preimage && !preimage.respond_to?(:bytes)
raise TypeError, "Preimage must be bytes, was #{preimage.class.name}"
end
@preimage = preimage
end
|
Instance Attribute Details
#preimage=(value) ⇒ Object
Sets the attribute preimage
7
8
9
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 7
def preimage=(value)
@preimage = value
end
|
Instance Method Details
#bitmask ⇒ Object
16
17
18
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 16
def bitmask
FEATURE_BITMASK
end
|
#parse_dict(data) ⇒ Object
55
56
57
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 55
def parse_dict(data)
self.preimage = data['preimage'].encode
end
|
#parse_payload(reader, payload_size) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 30
def parse_payload(reader, payload_size)
unless reader.is_a?(Utils::Reader)
raise TypeError, 'reader must be a Reader instance'
end
self.preimage = reader.read(payload_size)
end
|
#to_dict ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 46
def to_dict
{
'type' => 'fulfillment',
'type_id' => TYPE_ID,
'bitmask' => bitmask,
'preimage' => preimage
}
end
|
#validate(**_kwargs) ⇒ Object
59
60
61
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 59
def validate(**_kwargs)
true
end
|
#write_hash_payload(hasher) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 20
def write_hash_payload(hasher)
unless hasher.is_a?(Utils::Hasher)
raise TypeError, 'hasher must be a Hasher instance'
end
unless preimage
raise TypeError, 'Could not calculate hash, no preimage provided'
end
hasher.write(preimage)
end
|
#write_payload(writer) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/cryptoconditions_ruby/types/preimage_sha_256_fulfillment.rb', line 37
def write_payload(writer)
unless [Utils::Writer, Utils::Predictor].include?(writer.class)
raise TypeError, 'writer must be a Writer instance'
end
raise TypeError, 'Preimage must be specified' unless preimage
writer.write(preimage)
writer
end
|