secp256k1rb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1d7e33a444d5bbf4bf5cdfb3d57870bf810a568dbd5ff739c19b8f06a5e9329
4
- data.tar.gz: 40a5994a593fef14c7f8a9993d9917d27b66405e5ab545f744f03f1d99554f9b
3
+ metadata.gz: aff0d24f08ccdd2fb1d622ca2cb8655a9e36d3960890710861878e32e55850b3
4
+ data.tar.gz: 6915105a7e248f5a1ca810e5f0b8af3dea75731a7b65bd111df74a8691f2d907
5
5
  SHA512:
6
- metadata.gz: 65a12acd88ec6e5b01faed7d98b950d1de72c08d0aab286266d4aceba2844f03319e86fb4a9d687107e94b6729f6c24d93897285c7c92cb036c2c43af2a40b55
7
- data.tar.gz: 4b0f6b2e4b2faf1ebd7e59a07f28396eaf0bc07681ff429ad9189ecbc1fec7259458a53accd1cc618df14fccf240f9635b6ae596cbf88b56a2e297f7dbb73948
6
+ metadata.gz: 307ef35d2afa388b1640a2df6438ca19b14cc5d1bf1920f509e2f1768d610d0534f926ad0122122b5ad30da9ab6a9da3f49b17b6d1215fc0bd1e1fc55c42ab71
7
+ data.tar.gz: a533565583b3af85dbfbb9f259e3c644a4de3ec5a8c52e08b37eb46ff0bdba922e5a14cd3f2588792caa1ae4934881b9563b045c6907dda50571349a97dcef9c
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
-
10
9
  gem "rspec", "~> 3.0"
10
+ gem "csv", '~> 3.3'
data/lib/secp256k1/c.rb CHANGED
@@ -30,10 +30,13 @@ module Secp256k1
30
30
  attach_function(:secp256k1_ecdsa_recoverable_signature_parse_compact, [:pointer, :pointer, :pointer, :int], :int)
31
31
  attach_function(:secp256k1_ellswift_decode, [:pointer, :pointer, :pointer], :int)
32
32
  attach_function(:secp256k1_ellswift_create, [:pointer, :pointer, :pointer, :pointer], :int)
33
- # Define function pointer
34
- callback(:secp256k1_ellswift_xdh_hash_function, [:pointer, :pointer, :pointer, :pointer, :pointer], :int)
35
- attach_variable(:secp256k1_ellswift_xdh_hash_function_bip324, :secp256k1_ellswift_xdh_hash_function)
33
+ attach_variable(:secp256k1_ellswift_xdh_hash_function_bip324, :pointer)
36
34
  attach_function(:secp256k1_ellswift_xdh, [:pointer, :pointer, :pointer, :pointer, :pointer, :int, :pointer, :pointer], :int)
37
35
 
36
+ # Pointer to secp256k1_ellswift_xdh_hash_function_bip324 constant.
37
+ # @return [FFI::Pointer]
38
+ def self.ellswift_xdh_hash_function_bip324
39
+ FFI::Pointer.new(secp256k1_ellswift_xdh_hash_function_bip324)
40
+ end
38
41
  end
39
42
  end
@@ -1,11 +1,13 @@
1
1
  module Secp256k1
2
- module ELLSwift
2
+ module EllSwift
3
+
3
4
  # Decode ellswift public key.
4
5
  # @param [String] ell_key ElligatorSwift key with binary format.
6
+ # @param [Boolean] compressed Whether to compress the public key or not.
5
7
  # @return [String] Decoded public key with hex format.
6
8
  # @raise [Secp256k1::Error] If decode failed.
7
9
  # @raise [ArgumentError] If invalid arguments specified.
8
- def ellswift_decode(ell_key)
10
+ def ellswift_decode(ell_key, compressed: true)
9
11
  raise ArgumentError, "ell_key must be String." unless ell_key.is_a?(String)
10
12
  ell_key = hex2bin(ell_key)
11
13
  raise ArgumentError, "ell_key must be 64 bytes." unless ell_key.bytesize == 64
@@ -14,7 +16,7 @@ module Secp256k1
14
16
  internal = FFI::MemoryPointer.new(:uchar, 64)
15
17
  result = secp256k1_ellswift_decode(context, internal, ell64)
16
18
  raise Error, 'Decode failed.' unless result == 1
17
- serialize_pubkey_internal(context, internal, true)
19
+ serialize_pubkey_internal(context, internal, compressed)
18
20
  end
19
21
  end
20
22
 
@@ -27,7 +29,7 @@ module Secp256k1
27
29
  raise ArgumentError, "private_key must be String." unless private_key.is_a?(String)
28
30
  private_key = hex2bin(private_key)
29
31
  raise ArgumentError, "private_key must be 32 bytes." unless private_key.bytesize == 32
30
- with_context(flags: SECP256K1_CONTEXT_SIGN) do |context|
32
+ with_context(flags: CONTEXT_SIGN) do |context|
31
33
  ell64 = FFI::MemoryPointer.new(:uchar, 64)
32
34
  seckey32 = FFI::MemoryPointer.new(:uchar, 32).put_bytes(0, private_key)
33
35
  result = secp256k1_ellswift_create(context, ell64, seckey32, nil)
@@ -54,12 +56,12 @@ module Secp256k1
54
56
  raise ArgumentError, "our_ell_pubkey must be #{ELL_SWIFT_KEY_SIZE} bytes." unless our_ell_pubkey.bytesize == ELL_SWIFT_KEY_SIZE
55
57
  raise ArgumentError, "private_key must be 32 bytes." unless private_key.bytesize == 32
56
58
 
57
- with_context(flags: SECP256K1_CONTEXT_SIGN) do |context|
59
+ with_context(flags: CONTEXT_SIGN) do |context|
58
60
  output = FFI::MemoryPointer.new(:uchar, 32)
59
61
  our_ell_ptr = FFI::MemoryPointer.new(:uchar, 64).put_bytes(0, our_ell_pubkey)
60
62
  their_ell_ptr = FFI::MemoryPointer.new(:uchar, 64).put_bytes(0, their_ell_pubkey)
61
63
  seckey32 = FFI::MemoryPointer.new(:uchar, 32).put_bytes(0, private_key)
62
- hashfp = secp256k1_ellswift_xdh_hash_function_bip324
64
+ hashfp = C.ellswift_xdh_hash_function_bip324
63
65
  result = secp256k1_ellswift_xdh(context, output,
64
66
  initiating ? our_ell_ptr : their_ell_ptr,
65
67
  initiating ? their_ell_ptr : our_ell_ptr,
@@ -42,7 +42,7 @@ module Secp256k1
42
42
  raise ArgumentError, "data must be String." unless data.is_a?(String)
43
43
  raise ArgumentError, "signature must be String." unless signature.is_a?(String)
44
44
  signature = hex2bin(signature)
45
- raise ArgumentError, "signature must be 64 bytes." unless signature.bytesize == 65
45
+ raise ArgumentError, "signature must be 65 bytes." unless signature.bytesize == 65
46
46
  data = hex2bin(data)
47
47
  raise ArgumentError, "data must be 32 bytes." unless data.bytesize == 32
48
48
  rec = (signature[0].ord - 0x1b) & 3
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Secp256k1
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/secp256k1.rb CHANGED
@@ -15,7 +15,7 @@ module Secp256k1
15
15
  include C
16
16
  include Recover
17
17
  include SchnorrSig
18
- include ELLSwift
18
+ include EllSwift
19
19
 
20
20
  FLAGS_TYPE_MASK = ((1 << 8) - 1)
21
21
  FLAGS_TYPE_CONTEXT = (1 << 0)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secp256k1rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi