class Secp256k1::PKey
Public Class Methods
new(uncompressed)
click to toggle source
# File lib/secp256k1/pkey.rb, line 5 def initialize(uncompressed) @raw = uncompressed.force_encoding('BINARY') end
Public Instance Methods
+(other)
click to toggle source
# File lib/secp256k1/pkey.rb, line 17 def +(other) cptrs = [to_pointer, other.send(:to_pointer)] cptrs_ptr = FFI::MemoryPointer.new(:pointer, 2) cptrs_ptr.put_pointer(0, cptrs[0]) cptrs_ptr.put_pointer(8, cptrs[1]) out = FFI::MemoryPointer.new(64) valid = Secp256k1.secp256k1_ec_pubkey_combine( Secp256k1.context, out, cptrs_ptr, 2 ) result = PKey.new(out.read_bytes(64)) if valid == 1 out.free cptrs[0].free cptrs[1].free cptrs_ptr.free result end
==(other)
click to toggle source
# File lib/secp256k1/pkey.rb, line 43 def ==(other) @raw == other.uncompressed end
to_s()
click to toggle source
# File lib/secp256k1/pkey.rb, line 9 def to_s @to_s ||= to_compressed end
uncompressed()
click to toggle source
# File lib/secp256k1/pkey.rb, line 13 def uncompressed @raw end
Private Instance Methods
to_compressed()
click to toggle source
# File lib/secp256k1/pkey.rb, line 56 def to_compressed cptr = to_pointer out = FFI::MemoryPointer.new(:char, 33) size_pointer = FFI::MemoryPointer.new(:long) size_pointer.write(:long, 33) Secp256k1.secp256k1_ec_pubkey_serialize( Secp256k1.context, out, size_pointer, cptr, 0x102 ) result = out.read_bytes(33) out.free size_pointer.free cptr.free result end
to_pointer()
click to toggle source
Caller must call free
# File lib/secp256k1/pkey.rb, line 50 def to_pointer out = FFI::MemoryPointer.new(64) out.write_bytes(@raw) out end