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.
43
44
45
46
|
# File 'lib/stellar/key_pair.rb', line 43
def initialize(public_key, secret_key = nil)
@public_key = public_key
@secret_key = secret_key
end
|
Instance Method Details
#account_id ⇒ Object
48
49
50
|
# File 'lib/stellar/key_pair.rb', line 48
def account_id
Stellar::AccountID.new :public_key_type_ed25519, raw_public_key
end
|
#address ⇒ Object
85
86
87
88
|
# File 'lib/stellar/key_pair.rb', line 85
def address
pk_bytes = raw_public_key
Util::StrKey.check_encode(:account_id, pk_bytes)
end
|
#muxed_account ⇒ Object
52
53
54
|
# File 'lib/stellar/key_pair.rb', line 52
def muxed_account
Stellar::MuxedAccount.new :key_type_ed25519, raw_public_key
end
|
#public_key ⇒ Object
56
57
58
|
# File 'lib/stellar/key_pair.rb', line 56
def public_key
Stellar::PublicKey.new :public_key_type_ed25519, raw_public_key
end
|
#raw_public_key ⇒ Object
64
65
66
|
# File 'lib/stellar/key_pair.rb', line 64
def raw_public_key
@public_key.to_bytes
end
|
#raw_seed ⇒ Object
73
74
75
|
# File 'lib/stellar/key_pair.rb', line 73
def raw_seed
@secret_key.to_bytes
end
|
#rbnacl_signing_key ⇒ Object
77
78
79
|
# File 'lib/stellar/key_pair.rb', line 77
def rbnacl_signing_key
@secret_key
end
|
#rbnacl_verify_key ⇒ Object
81
82
83
|
# File 'lib/stellar/key_pair.rb', line 81
def rbnacl_verify_key
@public_key
end
|
#seed ⇒ Object
90
91
92
93
94
95
|
# File 'lib/stellar/key_pair.rb', line 90
def seed
raise "no private key" if @secret_key.nil?
seed_bytes = raw_seed
Util::StrKey.check_encode(:seed, seed_bytes)
end
|
#sign(message) ⇒ Object
101
102
103
104
105
|
# File 'lib/stellar/key_pair.rb', line 101
def sign(message)
raise "no private key" if @secret_key.nil?
@secret_key.sign(message)
end
|
#sign? ⇒ Boolean
97
98
99
|
# File 'lib/stellar/key_pair.rb', line 97
def sign?
!@secret_key.nil?
end
|
#sign_decorated(message) ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/stellar/key_pair.rb', line 107
def sign_decorated(message)
raw_signature = sign(message)
Stellar::DecoratedSignature.new({
hint: signature_hint,
signature: raw_signature
})
end
|
#signature_hint ⇒ Object
68
69
70
71
|
# File 'lib/stellar/key_pair.rb', line 68
def signature_hint
account_id.to_xdr.slice(-4, 4)
end
|
#signer_key ⇒ Object
60
61
62
|
# File 'lib/stellar/key_pair.rb', line 60
def signer_key
Stellar::SignerKey.new :signer_key_type_ed25519, raw_public_key
end
|
#to_keypair ⇒ Object
123
124
125
|
# File 'lib/stellar/key_pair.rb', line 123
def to_keypair
self
end
|
#verify(signature, message) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/stellar/key_pair.rb', line 115
def verify(signature, message)
@public_key.verify(signature, message)
rescue RbNaCl::LengthError
false
rescue RbNaCl::BadSignatureError
false
end
|