Class: IOSTSdk::Models::Signature

Inherits:
Object
  • Object
show all
Includes:
IOSTSdk::Models
Defined in:
lib/iost_sdk/models/signature.rb

Constant Summary collapse

ALGORITHM =
{
  ED25519: 'ED25519',
  SECP256K1: 'SECP256K1'
}

Constants included from IOSTSdk::Models

MODEL_REGISTRY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IOSTSdk::Models

included, #parse, #raw_data

Class Method Details

.algorithmObject



16
17
18
# File 'lib/iost_sdk/models/signature.rb', line 16

def self.algorithm
  ALGORITHM
end

.attr_namesObject



20
21
22
23
24
25
26
# File 'lib/iost_sdk/models/signature.rb', line 20

def self.attr_names
  [
    'algorithm',
    'public_key',
    'signature'
  ]
end

Instance Method Details

#bytesObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/iost_sdk/models/signature.rb', line 28

def bytes
  serializer = IOSTSdk::Models::Util::Serializer
  public_key_raw = public_key.unpack('m0').first
  signature_raw = signature.unpack('m0').first

  byte_value = (algorithm == ALGORITHM[:SECP256K1] ? [1] : [2]) +
                    serializer.int32_to_bytes(signature_raw.size) +
                    signature_raw.unpack('C*') +
                    serializer.int32_to_bytes(public_key_raw.size) +
                    public_key_raw.unpack('C*')
  byte_value
end