Module: Contracthashtool::EC_ADD

Extended by:
FFI::Library
Defined in:
lib/contracthashtool.rb

Overview

Constant Summary collapse

NID_secp256k1 =
714
POINT_CONVERSION_COMPRESSED =
2
POINT_CONVERSION_UNCOMPRESSED =
4

Class Method Summary collapse

Class Method Details

.add(point_0, point_1) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/contracthashtool.rb', line 82

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