Module: Sygna::Signature
- Defined in:
- lib/sygna/signature.rb
Constant Summary collapse
- EMPTY_SIGNATURE =
{ signature: "" }.freeze
Class Method Summary collapse
Class Method Details
.sign(object) ⇒ Object
5 6 7 8 9 |
# File 'lib/sygna/signature.rb', line 5 def self.sign(object) object_string = object.merge(EMPTY_SIGNATURE).to_json Secp256k1::Utils.encode_hex(ecdsa_private_key.ecdsa_serialize_compact(ecdsa_private_key.ecdsa_sign(object_string))) end |
.verify(object, signature, public_key_hex) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sygna/signature.rb', line 11 def self.verify(object, signature, public_key_hex) object_string = object.merge(EMPTY_SIGNATURE).to_json public_key_binary = Secp256k1::Utils.decode_hex(public_key_hex) ecdsa_public_key = Secp256k1::PublicKey.new(pubkey: public_key_binary, raw: true) binary_signature = Secp256k1::Utils.decode_hex(signature) raw_signature = ecdsa_public_key.ecdsa_deserialize_compact(binary_signature) ecdsa_public_key.ecdsa_verify(object_string, raw_signature) end |