Method: Klay::Key#sign
- Defined in:
- lib/klay/key.rb
#sign(blob, chain_id = nil) ⇒ String
Signs arbitrary data without validation. Should not be used unless really desired. See also: #personal_sign, #sign_typed_data, and Signature#recover.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/klay/key.rb', line 72 def sign(blob, chain_id = nil) context = Secp256k1::Context.new compact, recovery_id = context.sign_recoverable(@private_key, blob).compact signature = compact.bytes v = Chain.to_v recovery_id, chain_id is_leading_zero = true [v].pack("N").unpack("C*").each do |byte| is_leading_zero = false if byte > 0 and is_leading_zero signature.append byte unless is_leading_zero and byte === 0 end Util.bin_to_hex signature.pack "c*" end |