bip-schnorr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bip-schnorrrb.gemspec +28 -0
- data/lib/schnorr.rb +118 -0
- data/lib/schnorr/ec_point_ext.rb +57 -0
- data/lib/schnorr/signature.rb +38 -0
- data/lib/schnorr/version.rb +3 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c22da99e3fed7eea60436b7007532b752066996c9f2dd87f1f71028d7eaec357
|
4
|
+
data.tar.gz: 87bf98d7796bb6a31aad59e12914dd2f67584b852d45a7561e505061b3876284
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa3263695c27d8453971bb881c19f5b05c5d69bea52770823de956fc5cfe8d65fdd5393790fbd282eb8a78a13f56fbde3046f0222d9bbfefc668fedb099d150d
|
7
|
+
data.tar.gz: f828993f5d2c149aebc61dbd51c3569bf3ba97fe71aaab5e5aafbf1c7742d880e55b2db6dfa698e7dae521c50eea5d43c7ace1eb1e750b389ab11e8c2a0d9991
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
schnorrrb
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.0
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at azuchi@haw.co.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018-2019 Chaintope, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# bip-schnorrrb [![Build Status](https://travis-ci.org/chaintope/bip-schnorrrb.svg?branch=master)](https://travis-ci.org/chaintope/bip-schnorrrb) [![Gem Version](https://badge.fury.io/rb/bip-schnorr.svg)](https://badge.fury.io/rb/bip-schnorr) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
|
2
|
+
|
3
|
+
This is a Ruby implementation of the Schnorr signature scheme over the elliptic curve.
|
4
|
+
This implementation relies on the [ecdsa gem](https://github.com/DavidEGrayson/ruby_ecdsa) for operate elliptic curves.
|
5
|
+
|
6
|
+
The code is based upon the initial proposal of Pieter Wuille's [bip-schnorr](https://github.com/sipa/bips/blob/bip-schnorr/bip-schnorr.mediawiki).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'bip-schnorr', require: 'schnorr'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install bip-schnorr
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Singing
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'schnorr'
|
30
|
+
|
31
|
+
private_key = 0xB7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF
|
32
|
+
|
33
|
+
message = ['5E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C'].pack('H*')
|
34
|
+
|
35
|
+
# create signature
|
36
|
+
signature = Schnorr.sign(message, private_key)
|
37
|
+
|
38
|
+
# signature r value
|
39
|
+
signature.r
|
40
|
+
|
41
|
+
# signature s value
|
42
|
+
signature.s
|
43
|
+
|
44
|
+
# convert signature to binary
|
45
|
+
|
46
|
+
signature.encode
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
### Verification
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
require 'schnorr'
|
54
|
+
|
55
|
+
# public key does not start with 02 or 03.
|
56
|
+
public_key = ['DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659'].pack('H*')
|
57
|
+
|
58
|
+
signature = ['e7758e20e67a0607433cf8a1f0383a02c7b56792aab71763173ab7085cab8768082aae167787bc3572d15176dc26c073d9b03726aed0b59c728aa6538dc03d57'].pack('H*')
|
59
|
+
|
60
|
+
message = ['5E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C'].pack('H*')
|
61
|
+
|
62
|
+
# verify signature.(result is true or false)
|
63
|
+
result = Schnorr.valid_sig?(message, public_key, signature)
|
64
|
+
|
65
|
+
# signature convert to Signature object
|
66
|
+
sig = Schnorr::Signature.decode(signature)
|
67
|
+
```
|
68
|
+
|
69
|
+
## Note
|
70
|
+
|
71
|
+
This library changes the following functions of `ecdsa` gem in `lib/schnorr/ec_point_ext.rb`.
|
72
|
+
|
73
|
+
* `ECDSA::Point` class has following two instance methods.
|
74
|
+
* `#has_square_y?` check this point does not infinity and square?(y coordinate)
|
75
|
+
* `#square?(x)` check whether `x` is a quadratic residue modulo p.
|
76
|
+
* `ECDSA::Format::PointOctetString#decode` supports decoding only from x coordinate.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "schnorr"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "schnorr/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bip-schnorr"
|
8
|
+
spec.version = Schnorr::VERSION
|
9
|
+
spec.authors = ["azuchi"]
|
10
|
+
spec.email = ["azuchi@chaintope.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{The ruby implementation of bip-schnorr.}
|
13
|
+
spec.description = %q{The ruby implementation of bip-schnorr.}
|
14
|
+
spec.homepage = "https://github.com/chaintope/bip-schnorrrb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.add_runtime_dependency "ecdsa", "~> 1.2.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
data/lib/schnorr.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'ecdsa'
|
2
|
+
require 'securerandom'
|
3
|
+
require_relative 'schnorr/ec_point_ext'
|
4
|
+
require_relative 'schnorr/signature'
|
5
|
+
|
6
|
+
module Schnorr
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
GROUP = ECDSA::Group::Secp256k1
|
11
|
+
|
12
|
+
# Generate schnorr signature.
|
13
|
+
# @param message (String) A message to be signed with binary format.
|
14
|
+
# @param private_key (Integer) The private key.
|
15
|
+
# (The number of times to add the generator point to itself to get the public key.)
|
16
|
+
# @return (Schnorr::Signature)
|
17
|
+
def sign(message, private_key)
|
18
|
+
raise 'The message must be a 32-byte array.' unless message.bytesize == 32
|
19
|
+
p = GROUP.new_point(private_key)
|
20
|
+
seckey = p.has_square_y? ? private_key : GROUP.order - private_key
|
21
|
+
secret = ECDSA::Format::IntegerOctetString.encode(seckey, GROUP.byte_length)
|
22
|
+
|
23
|
+
k0 = ECDSA::Format::IntegerOctetString.decode(tagged_hash('BIPSchnorrDerive', secret + message)) % GROUP.order
|
24
|
+
raise 'Creation of signature failed. k is zero' if k0.zero?
|
25
|
+
|
26
|
+
r = GROUP.new_point(k0)
|
27
|
+
|
28
|
+
k = r.has_square_y? ? k0 : GROUP.order - k0
|
29
|
+
|
30
|
+
e = create_challenge(r.x, p, message, GROUP)
|
31
|
+
|
32
|
+
Schnorr::Signature.new(r.x, (k + e * seckey) % GROUP.order)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Verifies the given {Signature} and returns true if it is valid.
|
36
|
+
# @param message (String) A message to be signed with binary format.
|
37
|
+
# @param public_key (String) The public key with binary format.
|
38
|
+
# @param signature (String) The signature with binary format.
|
39
|
+
# @return (Boolean) whether signature is valid.
|
40
|
+
def valid_sig?(message, public_key, signature)
|
41
|
+
check_sig!(message, public_key, signature)
|
42
|
+
rescue InvalidSignatureError, ECDSA::Format::DecodeError
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
# Verifies the given {Signature} and raises an {InvalidSignatureError} if it is invalid.
|
47
|
+
# @param message (String) A message to be signed with binary format.
|
48
|
+
# @param public_key (String) The public key with binary format.
|
49
|
+
# @param signature (String) The signature with binary format.
|
50
|
+
# @return (Boolean)
|
51
|
+
def check_sig!(message, public_key, signature)
|
52
|
+
sig = Schnorr::Signature.decode(signature)
|
53
|
+
pubkey = ECDSA::Format::PointOctetString.decode(public_key, GROUP)
|
54
|
+
field = GROUP.field
|
55
|
+
|
56
|
+
raise Schnorr::InvalidSignatureError, 'Invalid signature: r is not in the field.' unless field.include?(sig.r)
|
57
|
+
raise Schnorr::InvalidSignatureError, 'Invalid signature: s is not in the field.' unless field.include?(sig.s)
|
58
|
+
raise Schnorr::InvalidSignatureError, 'Invalid signature: r is zero.' if sig.r.zero?
|
59
|
+
raise Schnorr::InvalidSignatureError, 'Invalid signature: s is zero.' if sig.s.zero?
|
60
|
+
raise Schnorr::InvalidSignatureError, 'Invalid signature: r is larger than field size.' if sig.r >= field.prime
|
61
|
+
raise Schnorr::InvalidSignatureError, 'Invalid signature: s is larger than group order.' if sig.s >= GROUP.order
|
62
|
+
|
63
|
+
e = create_challenge(sig.r, pubkey, message, GROUP)
|
64
|
+
|
65
|
+
r = GROUP.new_point(sig.s) + pubkey.multiply_by_scalar(GROUP.order - e)
|
66
|
+
|
67
|
+
if r.infinity? || !r.has_square_y? || r.x != sig.r
|
68
|
+
raise Schnorr::InvalidSignatureError, 'signature verification failed.'
|
69
|
+
end
|
70
|
+
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
# create signature digest.
|
75
|
+
# @param (Integer) x a x coordinate for R.
|
76
|
+
# @param (ECDSA::Point) p a public key.
|
77
|
+
# @param (ECDSA::Group) group the group of elliptic curve.
|
78
|
+
# @return (Integer) digest e.
|
79
|
+
def create_challenge(x, p, message, group)
|
80
|
+
r_x = ECDSA::Format::IntegerOctetString.encode(x, group.byte_length)
|
81
|
+
p_x = ECDSA::Format::IntegerOctetString.encode(p.x, group.byte_length)
|
82
|
+
(ECDSA.normalize_digest(tagged_hash('BIPSchnorr', r_x + p_x + message), group.bit_length)) % group.order
|
83
|
+
end
|
84
|
+
|
85
|
+
# Generate tagged hash value.
|
86
|
+
def tagged_hash(tag, msg)
|
87
|
+
tag_hash = Digest::SHA256.digest(tag)
|
88
|
+
Digest::SHA256.digest(tag_hash + tag_hash + msg)
|
89
|
+
end
|
90
|
+
|
91
|
+
class ::Integer
|
92
|
+
|
93
|
+
def to_hex
|
94
|
+
hex = to_s(16)
|
95
|
+
hex.rjust((hex.length / 2.0).ceil * 2, '0')
|
96
|
+
end
|
97
|
+
|
98
|
+
def method_missing(method, *args)
|
99
|
+
return mod_pow(args[0], args[1]) if method == :pow && args.length < 3
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
# alternative implementation of Integer#pow for ruby 2.4 and earlier.
|
104
|
+
def mod_pow(x, y)
|
105
|
+
return self ** x unless y
|
106
|
+
b = self
|
107
|
+
result = 1
|
108
|
+
while x > 0
|
109
|
+
result = (result * b) % y if (x & 1) == 1
|
110
|
+
x >>= 1
|
111
|
+
b = (b * b) % y
|
112
|
+
end
|
113
|
+
result
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# ECDSA gem elliptic curve point extension for bip-schnorr.
|
2
|
+
module ECDSA
|
3
|
+
class Point
|
4
|
+
|
5
|
+
# Check this point does not infinity and square?(y coordinate)
|
6
|
+
# @return (Boolean)
|
7
|
+
def has_square_y?
|
8
|
+
!infinity? && square?(y)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Check whether +x+ is a quadratic residue modulo p.
|
12
|
+
# @param x (Integer)
|
13
|
+
# @return (Boolean)
|
14
|
+
def square?(x)
|
15
|
+
x.pow((group.field.prime - 1) / 2, group.field.prime) == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module Format
|
21
|
+
|
22
|
+
module PointOctetString
|
23
|
+
|
24
|
+
def self.decode(string, group)
|
25
|
+
string = string.dup.force_encoding('BINARY')
|
26
|
+
|
27
|
+
raise DecodeError, 'Point octet string is empty.' if string.empty?
|
28
|
+
|
29
|
+
case string[0].ord
|
30
|
+
when 0
|
31
|
+
check_length string, 1
|
32
|
+
return group.infinity
|
33
|
+
when 2
|
34
|
+
decode_compressed string, group, 0
|
35
|
+
when 3
|
36
|
+
decode_compressed string, group, 1
|
37
|
+
when 4
|
38
|
+
decode_uncompressed string, group
|
39
|
+
else
|
40
|
+
return decode_from_x(string, group) if string.bytesize == 32
|
41
|
+
raise DecodeError, 'Unrecognized start byte for point octet string: 0x%x' % string[0].ord
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# decode from x coordinate.
|
46
|
+
def self.decode_from_x(x_string, group)
|
47
|
+
x = ECDSA::Format::FieldElementOctetString.decode(x_string, group.field)
|
48
|
+
y_sq = group.field.mod(x.pow(3, group.field.prime) + 7)
|
49
|
+
y = y_sq.pow((group.field.prime + 1)/4, group.field.prime)
|
50
|
+
raise DecodeError, 'Public key not on the curve.' unless y.pow(2, group.field.prime) == y_sq
|
51
|
+
finish_decode(x, y, group)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Schnorr
|
2
|
+
|
3
|
+
class InvalidSignatureError < StandardError; end
|
4
|
+
|
5
|
+
# Instances of this class represents Schnorr signatures,
|
6
|
+
# which are simply a pair of integers named `r` and `s`.
|
7
|
+
class Signature
|
8
|
+
|
9
|
+
attr_reader :r
|
10
|
+
attr_reader :s
|
11
|
+
|
12
|
+
# @param r (Integer) the value of r.
|
13
|
+
# @param s (Integer) the value of s.
|
14
|
+
def initialize(r, s)
|
15
|
+
@r, @s = r, s
|
16
|
+
r.is_a?(Integer) or raise ArgumentError, 'r is not an integer.'
|
17
|
+
s.is_a?(Integer) or raise ArgumentError, 's is not an integer.'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parse a string to a {Signature}.
|
21
|
+
# @param string (String) signature string with binary format.
|
22
|
+
# @return (Signature) signature instance.
|
23
|
+
def self.decode(string)
|
24
|
+
raise InvalidSignatureError, 'Invalid schnorr signature length.' unless string.bytesize == 64
|
25
|
+
r = string[0...32].unpack('H*').first.to_i(16)
|
26
|
+
s = string[32..-1].unpack('H*').first.to_i(16)
|
27
|
+
new(r, s)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Encode signature to string.
|
31
|
+
# @return (String) encoded signature.
|
32
|
+
def encode
|
33
|
+
ECDSA::Format::IntegerOctetString.encode(r, 32) + ECDSA::Format::IntegerOctetString.encode(s, 32)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bip-schnorr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- azuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ecdsa
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: The ruby implementation of bip-schnorr.
|
70
|
+
email:
|
71
|
+
- azuchi@chaintope.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- bip-schnorrrb.gemspec
|
89
|
+
- lib/schnorr.rb
|
90
|
+
- lib/schnorr/ec_point_ext.rb
|
91
|
+
- lib/schnorr/signature.rb
|
92
|
+
- lib/schnorr/version.rb
|
93
|
+
homepage: https://github.com/chaintope/bip-schnorrrb
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubygems_version: 3.0.3
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: The ruby implementation of bip-schnorr.
|
116
|
+
test_files: []
|