module Ethereum::Secp256k1
Constants
- A
- B
- G
- Gx
- Gy
- N
- P
Elliptic curve parameters
Public Class Methods
priv_to_pub(priv)
click to toggle source
# File lib/ethereum/secp256k1.rb, line 20 def priv_to_pub(priv) priv = PrivateKey.new(priv) privkey = ::Secp256k1::PrivateKey.new privkey: priv.encode(:bin), raw: true pubkey = privkey.pubkey PublicKey.new(pubkey.serialize).encode(priv.format) end
recover_pubkey(msg, vrs, compressed: false)
click to toggle source
# File lib/ethereum/secp256k1.rb, line 48 def recover_pubkey(msg, vrs, compressed: false) pk = ::Secp256k1::PublicKey.new(flags: ::Secp256k1::ALL_FLAGS) sig = Utils.zpad_int(vrs[1]) + Utils.zpad_int(vrs[2]) recsig = pk.ecdsa_recoverable_deserialize(sig, vrs[0]-27) pk.public_key = pk.ecdsa_recover msg, recsig, raw: true pk.serialize compressed: compressed end
recoverable_sign(msg, privkey)
click to toggle source
# File lib/ethereum/secp256k1.rb, line 27 def recoverable_sign(msg, privkey) pk = ::Secp256k1::PrivateKey.new privkey: privkey, raw: true signature = pk.ecdsa_recoverable_serialize pk.ecdsa_sign_recoverable(msg, raw: true) v = signature[1] + 27 r = Utils.big_endian_to_int signature[0][0,32] s = Utils.big_endian_to_int signature[0][32,32] [v,r,s] end
signature_verify(msg, vrs, pubkey)
click to toggle source
# File lib/ethereum/secp256k1.rb, line 38 def signature_verify(msg, vrs, pubkey) pk = ::Secp256k1::PublicKey.new(pubkey: pubkey) raw_sig = Utils.zpad_int(vrs[1]) + Utils.zpad_int(vrs[2]) sig = ::Secp256k1::C::ECDSASignature.new sig[:data].to_ptr.write_bytes(raw_sig) pk.ecdsa_verify(msg, sig) end