Class: Stellar::KeyPair
Defined Under Namespace
Modules: FactoryMethods
Instance Method Summary
collapse
from_address, from_network_passphrase, from_public_key, from_raw_seed, from_seed, master, random
Constructor Details
#initialize(public_key, secret_key = nil) ⇒ KeyPair
Returns a new instance of KeyPair.
45
46
47
48
|
# File 'lib/stellar/key_pair.rb', line 45
def initialize(public_key, secret_key = nil)
@public_key = public_key
@secret_key = secret_key
end
|
Instance Method Details
#account_id ⇒ Object
58
59
60
|
# File 'lib/stellar/key_pair.rb', line 58
def account_id
Stellar::AccountID.new :public_key_type_ed25519, raw_public_key
end
|
#address ⇒ Object
50
51
52
|
# File 'lib/stellar/key_pair.rb', line 50
def address
Util::StrKey.check_encode(:account_id, raw_public_key)
end
|
#muxed_account ⇒ Object
62
63
64
|
# File 'lib/stellar/key_pair.rb', line 62
def muxed_account
Stellar::MuxedAccount.new :key_type_ed25519, raw_public_key
end
|
#public_key ⇒ Object
66
67
68
|
# File 'lib/stellar/key_pair.rb', line 66
def public_key
Stellar::PublicKey.new :public_key_type_ed25519, raw_public_key
end
|
#raw_public_key ⇒ Object
79
80
81
|
# File 'lib/stellar/key_pair.rb', line 79
def raw_public_key
@public_key.to_bytes
end
|
#raw_seed ⇒ Object
83
84
85
86
|
# File 'lib/stellar/key_pair.rb', line 83
def raw_seed
raise "no private key" if @secret_key.nil?
@secret_key.to_bytes
end
|
#rbnacl_signing_key ⇒ Object
88
89
90
|
# File 'lib/stellar/key_pair.rb', line 88
def rbnacl_signing_key
@secret_key
end
|
#rbnacl_verify_key ⇒ Object
92
93
94
|
# File 'lib/stellar/key_pair.rb', line 92
def rbnacl_verify_key
@public_key
end
|
#sign(message) ⇒ Object
100
101
102
103
104
|
# File 'lib/stellar/key_pair.rb', line 100
def sign(message)
raise NotImplementedError, "no private key, signing is not available" unless sign?
@secret_key.sign(message)
end
|
#sign? ⇒ Boolean
96
97
98
|
# File 'lib/stellar/key_pair.rb', line 96
def sign?
!@secret_key.nil?
end
|
#sign_decorated(message) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/stellar/key_pair.rb', line 106
def sign_decorated(message)
raw_signature = sign(message)
Stellar::DecoratedSignature.new({
hint: signature_hint,
signature: raw_signature
})
end
|
#signature_hint ⇒ Object
74
75
76
77
|
# File 'lib/stellar/key_pair.rb', line 74
def signature_hint
account_id.to_xdr.slice(-4, 4)
end
|
#signer_key ⇒ Object
70
71
72
|
# File 'lib/stellar/key_pair.rb', line 70
def signer_key
Stellar::SignerKey.new :signer_key_type_ed25519, raw_public_key
end
|
#to_keypair ⇒ Object
122
123
124
|
# File 'lib/stellar/key_pair.rb', line 122
def to_keypair
self
end
|
#verify(signature, message) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/stellar/key_pair.rb', line 114
def verify(signature, message)
@public_key.verify(signature, message)
rescue RbNaCl::LengthError
false
rescue RbNaCl::BadSignatureError
false
end
|