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 +4 -4
- data/Gemfile +1 -1
- data/lib/secp256k1/c.rb +6 -3
- data/lib/secp256k1/ellswift.rb +8 -6
- data/lib/secp256k1/recovery.rb +1 -1
- data/lib/secp256k1/version.rb +1 -1
- data/lib/secp256k1.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aff0d24f08ccdd2fb1d622ca2cb8655a9e36d3960890710861878e32e55850b3
|
4
|
+
data.tar.gz: 6915105a7e248f5a1ca810e5f0b8af3dea75731a7b65bd111df74a8691f2d907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 307ef35d2afa388b1640a2df6438ca19b14cc5d1bf1920f509e2f1768d610d0534f926ad0122122b5ad30da9ab6a9da3f49b17b6d1215fc0bd1e1fc55c42ab71
|
7
|
+
data.tar.gz: a533565583b3af85dbfbb9f259e3c644a4de3ec5a8c52e08b37eb46ff0bdba922e5a14cd3f2588792caa1ae4934881b9563b045c6907dda50571349a97dcef9c
|
data/Gemfile
CHANGED
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
|
-
|
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
|
data/lib/secp256k1/ellswift.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Secp256k1
|
2
|
-
module
|
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,
|
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:
|
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:
|
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 =
|
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,
|
data/lib/secp256k1/recovery.rb
CHANGED
@@ -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
|
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
|
data/lib/secp256k1/version.rb
CHANGED
data/lib/secp256k1.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|