Skip to content

Commit

Permalink
Fix a bug where Key#generate does not generate uncompressed public ke…
Browse files Browse the repository at this point in the history
…y with key type :uncompressed
  • Loading branch information
azuchi committed Dec 22, 2023
1 parent a8b0bfb commit 5d4dca0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tapyrus/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize(priv_key: nil, pubkey: nil, key_type: nil, compressed: true, allo

# generate key pair
def self.generate(key_type = TYPES[:compressed])
priv_key, pubkey = Tapyrus.secp_impl.generate_key_pair
priv_key, pubkey = Tapyrus.secp_impl.generate_key_pair(compressed: key_type != TYPES[:uncompressed])
new(priv_key: priv_key, pubkey: pubkey, key_type: key_type)
end

Expand Down
21 changes: 21 additions & 0 deletions spec/tapyrus/key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,25 @@ def test_with_no_entropy
expect(found_small).to be true
end
end

describe "#generate" do
context "pure ruby" do
it "return decompressed public key" do
test_generate
end
end

context "libsecp256k1", use_secp256k1: true do
it "return decompressed public key" do
test_generate
end
end

def test_generate
compressed = Tapyrus::Key.generate(Tapyrus::Key::TYPES[:compressed])
expect(compressed.compressed?).to be true
uncompressed = Tapyrus::Key.generate(Tapyrus::Key::TYPES[:uncompressed])
expect(uncompressed.compressed?).to be false
end
end
end

0 comments on commit 5d4dca0

Please sign in to comment.