module Contracthashtool::EC_ADD

lifted from github.com/GemHQ/money-tree

Constants

NID_secp256k1
POINT_CONVERSION_COMPRESSED
POINT_CONVERSION_UNCOMPRESSED

Public Class Methods

add(point_0, point_1) click to toggle source
# File lib/contracthashtool.rb, line 87
def self.add(point_0, point_1)
  eckey = EC_KEY_new_by_curve_name(NID_secp256k1)
  group = EC_KEY_get0_group(eckey)

  point_0_hex = point_0.to_bn.to_s(16)
  point_0_pt = EC_POINT_hex2point(group, point_0_hex, nil, nil)
  point_1_hex = point_1.to_bn.to_s(16)
  point_1_pt = EC_POINT_hex2point(group, point_1_hex, nil, nil)

  sum_point = EC_POINT_new(group)
  success = EC_POINT_add(group, sum_point, point_0_pt, point_1_pt, nil)
  hex = EC_POINT_point2hex(group, sum_point, POINT_CONVERSION_UNCOMPRESSED, nil)
  EC_KEY_free(eckey)
  EC_POINT_free(sum_point)
  hex
end