Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/money-tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@
require "money-tree/node"

module MoneyTree

DEFAULT_CURVE_NAME = 'secp256k1'
DEFAULT_CURVE_ID = 714
@curve_name = DEFAULT_CURVE_NAME
@curve_id = DEFAULT_CURVE_ID

def self.setCurve(name, id)
@curve_name = name || DEFAULT_CURVE_NAME
@curve_id = id || DEFAULT_CURVE_ID
end

def self.getCurve()
{ name: @curve_name, id: @curve_id }
end
end
4 changes: 2 additions & 2 deletions lib/money-tree/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PrivateKey < Key

def initialize(opts = {})
@options = opts
@ec_key = PKey::EC.new GROUP_NAME
@ec_key = PKey::EC.new MoneyTree.getCurve()[:name] || GROUP_NAME
if @options[:key]
@raw_key = @options[:key]
@key = parse_raw_key
Expand Down Expand Up @@ -176,7 +176,7 @@ def initialize(p_key, opts = {})
@key = @raw_key = to_hex
else
@raw_key = p_key
@group = PKey::EC::Group.new GROUP_NAME
@group = PKey::EC::Group.new MoneyTree.getCurve()[:name] || GROUP_NAME
@key = parse_raw_key
end

Expand Down
2 changes: 1 addition & 1 deletion lib/money-tree/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MoneyTree
VERSION = "0.10.0"
VERSION = "0.10.1"
end
14 changes: 7 additions & 7 deletions lib/openssl_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ module OpenSSLExtensions
attach_function :EC_POINT_point2hex, [:pointer, :pointer, :int, :pointer], :string
attach_function :EC_POINT_hex2point, [:pointer, :string, :pointer, :pointer], :pointer
attach_function :EC_POINT_new, [:pointer], :pointer

def self.add(point_0, point_1)
validate_points(point_0, point_1)
eckey = EC_KEY_new_by_curve_name(NID_secp256k1)
eckey = EC_KEY_new_by_curve_name(MoneyTree.getCurve()[:id] || 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)
Expand All @@ -52,9 +52,9 @@ def self.add(point_0, point_1)
def self.validate_points(*points)
points.each do |point|
if !point.is_a?(OpenSSL::PKey::EC::Point)
raise ArgumentError, "point must be an OpenSSL::PKey::EC::Point object"
raise ArgumentError, "point must be an OpenSSL::PKey::EC::Point object"
elsif point.infinity?
raise ArgumentError, "point must not be infinity"
raise ArgumentError, "point must not be infinity"
end
end
end
Expand All @@ -64,10 +64,10 @@ def self.validate_points(*points)

class OpenSSL::PKey::EC::Point
include MoneyTree::OpenSSLExtensions

def add(point)
sum_point_hex = MoneyTree::OpenSSLExtensions.add(self, point)
self.class.new group, OpenSSL::BN.new(sum_point_hex, 16)
end

end