lib/stellar/key_pair.rb in stellar-base-0.0.18 vs lib/stellar/key_pair.rb in stellar-base-0.0.19
- old
+ new
@@ -30,16 +30,25 @@
def initialize(public_key, secret_key=nil)
@public_key = public_key
@secret_key = secret_key
end
+ def account_id
+ Stellar::AccountID.new :key_types_ed25519, raw_public_key
+ end
+
def public_key
+ Stellar::PublicKey.new :key_types_ed25519, raw_public_key
+ end
+
+ def raw_public_key
@public_key.to_bytes
end
- def public_key_hint
- public_key.slice(0, 4)
+ def signature_hint
+ # take last 4 bytes
+ account_id.to_xdr.slice(-4, 4)
end
def raw_seed
@secret_key.to_bytes
end
@@ -51,11 +60,11 @@
def rbnacl_verify_key
@public_key
end
def address
- pk_bytes = public_key
+ pk_bytes = raw_public_key
Util::Base58.stellar.check_encode(:account_id, pk_bytes)
end
def seed
raise "no private key" if @secret_key.nil?
@@ -75,11 +84,11 @@
end
def sign_decorated(message)
raw_signature = sign(message)
Stellar::DecoratedSignature.new({
- hint: public_key_hint,
+ hint: signature_hint,
signature: raw_signature
})
end
def verify(signature, message)
@@ -89,6 +98,6 @@
rescue RbNaCl::BadSignatureError
false
end
end
-end
\ No newline at end of file
+end