Class: IOSTSdk::Crypto::KeyPair
- Inherits:
-
Object
- Object
- IOSTSdk::Crypto::KeyPair
- Defined in:
- lib/iost_sdk/crypto.rb
Instance Attribute Summary collapse
-
#algo ⇒ Object
readonly
Returns the value of attribute algo.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(algo:, public_key:, private_key:) ⇒ Object
constructor
Create an instance of KeyPair.
- #private_key ⇒ Object
- #private_key_raw ⇒ Object
- #public_key ⇒ Object
- #public_key_raw ⇒ Object
- #sign(message:) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(algo:, public_key:, private_key:) ⇒ Object
Create an instance of KeyPair
88 89 90 91 92 |
# File 'lib/iost_sdk/crypto.rb', line 88 def initialize(algo:, public_key:, private_key:) @algo = algo @public_key = public_key @private_key = private_key end |
Instance Attribute Details
#algo ⇒ Object (readonly)
Returns the value of attribute algo.
80 81 82 |
# File 'lib/iost_sdk/crypto.rb', line 80 def algo @algo end |
Instance Method Details
#id ⇒ Object
125 126 127 |
# File 'lib/iost_sdk/crypto.rb', line 125 def id public_key end |
#private_key ⇒ Object
112 113 114 |
# File 'lib/iost_sdk/crypto.rb', line 112 def private_key Base58.binary_to_base58(private_key_raw, :bitcoin) end |
#private_key_raw ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/iost_sdk/crypto.rb', line 116 def private_key_raw if @algo == IOSTSdk::Crypto.key_algos[:Secp256k1] # @private_key is in bytes already @private_key elsif @algo == IOSTSdk::Crypto.key_algos[:Ed25519] @private_key.to_bytes end end |
#public_key ⇒ Object
99 100 101 |
# File 'lib/iost_sdk/crypto.rb', line 99 def public_key Base58.binary_to_base58(public_key_raw, :bitcoin) end |
#public_key_raw ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/iost_sdk/crypto.rb', line 103 def public_key_raw if @algo == IOSTSdk::Crypto.key_algos[:Secp256k1] # @public_key is in bytes already @public_key elsif @algo == IOSTSdk::Crypto.key_algos[:Ed25519] @public_key.to_bytes end end |
#sign(message:) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/iost_sdk/crypto.rb', line 129 def sign(message:) if @algo == IOSTSdk::Crypto.key_algos[:Secp256k1] p_key = BTC::Key.new(private_key: @private_key) der_signature = p_key.ecdsa_signature() decoded_der = OpenSSL::ASN1.decode(der_signature) decoded_der.value .map { |v| v.value.to_s(2) } .flatten .join elsif @algo == IOSTSdk::Crypto.key_algos[:Ed25519] @private_key.sign() end end |