21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/bsv/wallet/serializer/create_signature.rb', line 21
def serialize(args)
data = args[:data] && Common.to_binary(args[:data])
hash = args[:hash_to_directly_sign] && Common.to_binary(args[:hash_to_directly_sign])
if data && hash
raise BSV::Wallet::InvalidParameterError.new(
'data and hash_to_directly_sign',
'not both provided — supply one or the other'
)
end
raise BSV::Wallet::InvalidParameterError.new('data or hash_to_directly_sign', 'present') unless data || hash
w = BSV::Wallet::Wire::Writer.new
Common.write_key_related_params(
w,
protocol_id: args[:protocol_id],
key_id: args[:key_id],
counterparty: args[:counterparty],
privileged: args[:privileged],
privileged_reason: args[:privileged_reason]
)
if data
w.write_byte(1)
w.write_varint(data.bytesize)
w.write_bytes(data)
else
w.write_byte(2)
w.write_bytes(hash)
end
w.write_optional_bool(args[:seek_permission])
w.buf
end
|