schnorrkel_rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ef372bbee013a28eaaff737011c2e6d14192ed9eb3a60d118a12ed6b44eea5f
4
+ data.tar.gz: cbaff3a51228d6f5779950694fdc1dd33760955cb63713d71328d4c600365ed7
5
+ SHA512:
6
+ metadata.gz: ae0f806894055ef26f8d9ebd03185150bacfe9bd606ac72ddaf3e0406dc57e6c3aab3d873daaaf66ef2137fecb476a0ae788b3de59f2884bd5f20320d8e173cc
7
+ data.tar.gz: bb2e4b4e384e738ceb4208e6af9a1b7e7ad9778ee17c95d8f8bc3713577ed80c0251652314fdfaa07fe1c7ba1c741e35355f930007439e14fb3fc1e179a8fd8f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at aki.wu@itering.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Cargo.lock ADDED
@@ -0,0 +1,285 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "arrayref"
7
+ version = "0.3.6"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
10
+
11
+ [[package]]
12
+ name = "arrayvec"
13
+ version = "0.7.2"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
16
+
17
+ [[package]]
18
+ name = "block-buffer"
19
+ version = "0.9.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
22
+ dependencies = [
23
+ "generic-array",
24
+ ]
25
+
26
+ [[package]]
27
+ name = "byteorder"
28
+ version = "1.4.3"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
31
+
32
+ [[package]]
33
+ name = "cfg-if"
34
+ version = "1.0.0"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
37
+
38
+ [[package]]
39
+ name = "cpufeatures"
40
+ version = "0.2.5"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
43
+ dependencies = [
44
+ "libc",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "curve25519-dalek-ng"
49
+ version = "4.1.1"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8"
52
+ dependencies = [
53
+ "byteorder",
54
+ "digest",
55
+ "rand_core",
56
+ "subtle-ng",
57
+ "zeroize",
58
+ ]
59
+
60
+ [[package]]
61
+ name = "digest"
62
+ version = "0.9.0"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
65
+ dependencies = [
66
+ "generic-array",
67
+ ]
68
+
69
+ [[package]]
70
+ name = "generic-array"
71
+ version = "0.14.6"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
74
+ dependencies = [
75
+ "typenum",
76
+ "version_check",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "getrandom"
81
+ version = "0.2.8"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
84
+ dependencies = [
85
+ "cfg-if",
86
+ "libc",
87
+ "wasi",
88
+ ]
89
+
90
+ [[package]]
91
+ name = "hex"
92
+ version = "0.4.3"
93
+ source = "registry+https://github.com/rust-lang/crates.io-index"
94
+ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
95
+
96
+ [[package]]
97
+ name = "keccak"
98
+ version = "0.1.2"
99
+ source = "registry+https://github.com/rust-lang/crates.io-index"
100
+ checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838"
101
+
102
+ [[package]]
103
+ name = "libc"
104
+ version = "0.2.136"
105
+ source = "registry+https://github.com/rust-lang/crates.io-index"
106
+ checksum = "55edcf6c0bb319052dea84732cf99db461780fd5e8d3eb46ab6ff312ab31f197"
107
+
108
+ [[package]]
109
+ name = "merlin"
110
+ version = "3.0.0"
111
+ source = "registry+https://github.com/rust-lang/crates.io-index"
112
+ checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d"
113
+ dependencies = [
114
+ "byteorder",
115
+ "keccak",
116
+ "rand_core",
117
+ "zeroize",
118
+ ]
119
+
120
+ [[package]]
121
+ name = "opaque-debug"
122
+ version = "0.3.0"
123
+ source = "registry+https://github.com/rust-lang/crates.io-index"
124
+ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
125
+
126
+ [[package]]
127
+ name = "proc-macro2"
128
+ version = "1.0.47"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
131
+ dependencies = [
132
+ "unicode-ident",
133
+ ]
134
+
135
+ [[package]]
136
+ name = "quote"
137
+ version = "1.0.21"
138
+ source = "registry+https://github.com/rust-lang/crates.io-index"
139
+ checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
140
+ dependencies = [
141
+ "proc-macro2",
142
+ ]
143
+
144
+ [[package]]
145
+ name = "rand_core"
146
+ version = "0.6.4"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
149
+ dependencies = [
150
+ "getrandom",
151
+ ]
152
+
153
+ [[package]]
154
+ name = "schnorrkel"
155
+ version = "0.1.0"
156
+ dependencies = [
157
+ "hex",
158
+ "libc",
159
+ "schnorrkel 0.10.2",
160
+ ]
161
+
162
+ [[package]]
163
+ name = "schnorrkel"
164
+ version = "0.10.2"
165
+ source = "registry+https://github.com/rust-lang/crates.io-index"
166
+ checksum = "844b7645371e6ecdf61ff246ba1958c29e802881a749ae3fb1993675d210d28d"
167
+ dependencies = [
168
+ "arrayref",
169
+ "arrayvec",
170
+ "curve25519-dalek-ng",
171
+ "merlin",
172
+ "rand_core",
173
+ "serde_bytes",
174
+ "sha2",
175
+ "subtle-ng",
176
+ "zeroize",
177
+ ]
178
+
179
+ [[package]]
180
+ name = "serde"
181
+ version = "1.0.147"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
184
+
185
+ [[package]]
186
+ name = "serde_bytes"
187
+ version = "0.11.7"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b"
190
+ dependencies = [
191
+ "serde",
192
+ ]
193
+
194
+ [[package]]
195
+ name = "sha2"
196
+ version = "0.9.9"
197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
198
+ checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
199
+ dependencies = [
200
+ "block-buffer",
201
+ "cfg-if",
202
+ "cpufeatures",
203
+ "digest",
204
+ "opaque-debug",
205
+ ]
206
+
207
+ [[package]]
208
+ name = "subtle-ng"
209
+ version = "2.5.0"
210
+ source = "registry+https://github.com/rust-lang/crates.io-index"
211
+ checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142"
212
+
213
+ [[package]]
214
+ name = "syn"
215
+ version = "1.0.103"
216
+ source = "registry+https://github.com/rust-lang/crates.io-index"
217
+ checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
218
+ dependencies = [
219
+ "proc-macro2",
220
+ "quote",
221
+ "unicode-ident",
222
+ ]
223
+
224
+ [[package]]
225
+ name = "synstructure"
226
+ version = "0.12.6"
227
+ source = "registry+https://github.com/rust-lang/crates.io-index"
228
+ checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
229
+ dependencies = [
230
+ "proc-macro2",
231
+ "quote",
232
+ "syn",
233
+ "unicode-xid",
234
+ ]
235
+
236
+ [[package]]
237
+ name = "typenum"
238
+ version = "1.15.0"
239
+ source = "registry+https://github.com/rust-lang/crates.io-index"
240
+ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
241
+
242
+ [[package]]
243
+ name = "unicode-ident"
244
+ version = "1.0.5"
245
+ source = "registry+https://github.com/rust-lang/crates.io-index"
246
+ checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
247
+
248
+ [[package]]
249
+ name = "unicode-xid"
250
+ version = "0.2.4"
251
+ source = "registry+https://github.com/rust-lang/crates.io-index"
252
+ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
253
+
254
+ [[package]]
255
+ name = "version_check"
256
+ version = "0.9.4"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
259
+
260
+ [[package]]
261
+ name = "wasi"
262
+ version = "0.11.0+wasi-snapshot-preview1"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
265
+
266
+ [[package]]
267
+ name = "zeroize"
268
+ version = "1.5.7"
269
+ source = "registry+https://github.com/rust-lang/crates.io-index"
270
+ checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f"
271
+ dependencies = [
272
+ "zeroize_derive",
273
+ ]
274
+
275
+ [[package]]
276
+ name = "zeroize_derive"
277
+ version = "1.3.2"
278
+ source = "registry+https://github.com/rust-lang/crates.io-index"
279
+ checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17"
280
+ dependencies = [
281
+ "proc-macro2",
282
+ "quote",
283
+ "syn",
284
+ "synstructure",
285
+ ]
data/Cargo.toml ADDED
@@ -0,0 +1,15 @@
1
+ [package]
2
+ name = "schnorrkel"
3
+ version = "0.1.0"
4
+ authors = ["Aki Wu <wuminzhe@gmail.com>"]
5
+ edition = "2018"
6
+
7
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+
9
+ [dependencies]
10
+ schnorrkel = "0.10.1"
11
+ hex = "0.4.3"
12
+ libc = "0.2.90"
13
+
14
+ [lib]
15
+ crate-type=["dylib"]
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in schnorrkel_rb.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ schnorrkel_rb (0.1.0)
5
+ ffi (~> 1.0)
6
+ thermite (~> 0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ diff-lcs (1.5.0)
13
+ ffi (1.15.5)
14
+ json (2.6.2)
15
+ minitar (0.9)
16
+ parallel (1.22.1)
17
+ parser (3.1.2.1)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.1.1)
20
+ rake (13.0.6)
21
+ regexp_parser (2.6.0)
22
+ rexml (3.2.5)
23
+ rspec (3.11.0)
24
+ rspec-core (~> 3.11.0)
25
+ rspec-expectations (~> 3.11.0)
26
+ rspec-mocks (~> 3.11.0)
27
+ rspec-core (3.11.0)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-expectations (3.11.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-mocks (3.11.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-support (3.11.1)
36
+ rubocop (1.37.1)
37
+ json (~> 2.3)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.1.2.1)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml (>= 3.2.5, < 4.0)
43
+ rubocop-ast (>= 1.23.0, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 3.0)
46
+ rubocop-ast (1.23.0)
47
+ parser (>= 3.1.1.0)
48
+ ruby-progressbar (1.11.0)
49
+ thermite (0.13.0)
50
+ minitar (~> 0.5)
51
+ rake (>= 10)
52
+ tomlrb (~> 1.2)
53
+ tomlrb (1.3.0)
54
+ unicode-display_width (2.3.0)
55
+
56
+ PLATFORMS
57
+ arm64-darwin-21
58
+
59
+ DEPENDENCIES
60
+ rake (~> 13.0)
61
+ rspec (~> 3.0)
62
+ rubocop (~> 1.21)
63
+ schnorrkel_rb!
64
+
65
+ BUNDLED WITH
66
+ 2.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Aki Wu
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,41 @@
1
+ # SchnorrkelRb
2
+
3
+ A Ruby wrapper to the Rust schnorrkel SR25519 signature library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'schnorrkel_rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install schnorrkel_rb
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wuminzhe/schnorrkel_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/wuminzhe/schnorrkel_rb/blob/main/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the SchnorrkelRb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/schnorrkel_rb/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/ext/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "thermite/tasks"
2
+
3
+ project_dir = File.dirname(File.dirname(__FILE__))
4
+ Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
5
+ task default: %w[thermite:build]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SchnorrkelRb
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "schnorrkel_rb/version"
4
+ require "ffi"
5
+
6
+ class Str < FFI::AutoPointer
7
+ def self.release(ptr)
8
+ SchnorrkelRb.free(ptr)
9
+ end
10
+
11
+ def to_s
12
+ @str ||= self.read_string.force_encoding('UTF-8')
13
+ end
14
+ end
15
+
16
+ module SchnorrkelRb
17
+ class Error < StandardError; end
18
+
19
+ extend FFI::Library
20
+ ffi_lib "#{__dir__}/../target/release/libschnorrkel." + FFI::Platform::LIBSUFFIX
21
+ attach_function :verify, :verify, %i[string string string], :bool
22
+ attach_function :sign_by_seed, :sign_by_seed, %i[string string], Str
23
+ attach_function :free, :free_s, [Str], :void
24
+
25
+ def self.sr25519_sign(seed, message)
26
+ message = message[2..] if message.start_with?('0x')
27
+ seed = seed[2..] if seed.start_with?('0x')
28
+ self.sign_by_seed(message, seed).to_s
29
+ end
30
+
31
+ def self.sr25519_verify(signature, message, pubkey)
32
+ pubkey = pubkey[2..] if pubkey.start_with?('0x')
33
+ message = message[2..] if message.start_with?('0x')
34
+ signature = signature[2..] if signature.start_with?('0x')
35
+ self.verify(signature, message, pubkey)
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/schnorrkel_rb/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "schnorrkel_rb"
7
+ spec.version = SchnorrkelRb::VERSION
8
+ spec.authors = ["Aki Wu"]
9
+ spec.email = ["wuminzhe@gmail.com"]
10
+
11
+ spec.summary = "Ruby SR25519 Signature"
12
+ spec.description = "A Ruby wrapper to the Rust schnorrkel SR25519 signature library."
13
+ spec.homepage = "https://github.com/wuminzhe/schnorrkel_rb"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.extensions << 'ext/Rakefile'
34
+ spec.add_runtime_dependency 'thermite', '~> 0'
35
+ spec.add_dependency "ffi", "~> 1.0"
36
+ end
@@ -0,0 +1,4 @@
1
+ module SchnorrkelRb
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/src/lib.rs ADDED
@@ -0,0 +1,147 @@
1
+ // modified from: https://github.com/paritytech/schnorrkel-js/blob/master/src/lib.rs
2
+
3
+ extern crate core;
4
+
5
+ mod wrapper;
6
+ use wrapper::*;
7
+
8
+ use libc::c_char;
9
+ use std::ffi::{CStr, CString};
10
+ use schnorrkel::{KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
11
+
12
+ // hex str pointer -> string
13
+ fn hex_pointer_to_string(s: *const c_char) -> String {
14
+ let c_str = unsafe {
15
+ assert!(!s.is_null());
16
+ CStr::from_ptr(s)
17
+ };
18
+ c_str.to_str().unwrap().to_owned()
19
+ }
20
+
21
+ fn hex_pointer_to_vecu8(s: *const c_char) -> Vec<u8> {
22
+ hex::decode(hex_pointer_to_string(s)).unwrap()
23
+ }
24
+
25
+ fn u8a_to_hex_pointer(u8a: &[u8]) -> *mut c_char {
26
+ let s = hex::encode(u8a.to_vec());
27
+ let c_str = CString::new(s).unwrap();
28
+ c_str.into_raw()
29
+ }
30
+
31
+ #[no_mangle]
32
+ pub extern "C" fn free_s(s: *mut c_char) {
33
+ unsafe {
34
+ if s.is_null() {
35
+ return;
36
+ }
37
+ CString::from_raw(s)
38
+ };
39
+ }
40
+
41
+ /// Perform a derivation on a secret
42
+ ///
43
+ /// * secret: hex pointer of 64 bytes
44
+ /// * cc: hex pointer of 32 bytes
45
+ ///
46
+ /// returned vector the derived keypair as hex pointer of 96 bytes
47
+ #[no_mangle]
48
+ pub extern "C" fn derive_keypair_hard(pair_p: *const c_char, cc_p: *const c_char) -> *mut c_char {
49
+ let pair = hex_pointer_to_vecu8(pair_p);
50
+ let cc = hex_pointer_to_vecu8(cc_p);
51
+ let d = __derive_keypair_hard(pair.as_slice(), cc.as_slice());
52
+ u8a_to_hex_pointer(&d)
53
+ }
54
+
55
+ /// Perform a derivation on a secret
56
+ ///
57
+ /// * secret: UIntArray with 64 bytes
58
+ /// * cc: UIntArray with 32 bytes
59
+ ///
60
+ /// returned vector the derived keypair as a array of 96 bytes
61
+ #[no_mangle]
62
+ pub fn derive_keypair_soft(pair_p: *const c_char, cc_p: *const c_char) -> *mut c_char {
63
+ let pair = hex_pointer_to_vecu8(pair_p);
64
+ let cc = hex_pointer_to_vecu8(cc_p);
65
+ let d = __derive_keypair_soft(pair.as_slice(), cc.as_slice());
66
+ u8a_to_hex_pointer(&d)
67
+ }
68
+
69
+ /// Sign a message
70
+ ///
71
+ /// The combination of both public and private key must be provided.
72
+ /// This is effectively equivalent to a keypair.
73
+ ///
74
+ /// * public: UIntArray with 32 element
75
+ /// * private: UIntArray with 64 element
76
+ /// * message: Arbitrary length hex pointer
77
+ ///
78
+ /// * returned vector is the signature consisting of 64 bytes.
79
+ /// Sign a message
80
+ ///
81
+ /// The combination of both public and private key must be provided.
82
+ /// This is effectively equivalent to a keypair.
83
+ ///
84
+ /// * public: UIntArray with 32 element
85
+ /// * private: UIntArray with 64 element
86
+ /// * message: Arbitrary length UIntArray
87
+ ///
88
+ /// * returned vector is the signature consisting of 64 bytes.
89
+ #[no_mangle]
90
+ pub fn sign(public_p: *const c_char, private_p: *const c_char, message_p: *const c_char) -> *mut c_char {
91
+ let public = hex_pointer_to_vecu8(public_p);
92
+ let private = hex_pointer_to_vecu8(private_p);
93
+ let message = hex_pointer_to_vecu8(message_p);
94
+ let signature = __sign(public.as_slice(), private.as_slice(), message.as_slice());
95
+ u8a_to_hex_pointer(&signature)
96
+ }
97
+
98
+ /// Verify a message and its corresponding against a public key;
99
+ ///
100
+ /// * signature: UIntArray with 64 element
101
+ /// * message: Arbitrary length UIntArray
102
+ /// * pubkey: UIntArray with 32 element
103
+ #[no_mangle]
104
+ pub fn verify(signature_p: *const c_char, message_p: *const c_char, pubkey_p: *const c_char) -> bool {
105
+ let signature = hex_pointer_to_vecu8(signature_p);
106
+ let pubkey = hex_pointer_to_vecu8(pubkey_p);
107
+ let message = hex_pointer_to_vecu8(message_p);
108
+ __verify(signature.as_slice(), message.as_slice(), pubkey.as_slice())
109
+ }
110
+
111
+ /// Generate a secret key (aka. private key) from a seed phrase.
112
+ ///
113
+ /// * seed: UIntArray with 32 element
114
+ ///
115
+ /// returned vector is the private key consisting of 64 bytes.
116
+ #[no_mangle]
117
+ pub fn secret_from_seed(seed_p: *const c_char) -> *mut c_char {
118
+ let seed = hex_pointer_to_vecu8(seed_p);
119
+ let secret = __secret_from_seed(seed.as_slice());
120
+ u8a_to_hex_pointer(&secret)
121
+ }
122
+
123
+ /// Generate a key pair. .
124
+ ///
125
+ /// * seed: UIntArray with 32 element
126
+ ///
127
+ /// returned vector is the concatenation of first the private key (64 bytes)
128
+ /// followed by the public key (32) bytes.
129
+ #[no_mangle]
130
+ pub fn keypair_from_seed(seed_p: *const c_char) -> *mut c_char {
131
+ let seed = hex_pointer_to_vecu8(seed_p);
132
+ let keypair = __keypair_from_seed(seed.as_slice());
133
+ u8a_to_hex_pointer(&keypair)
134
+ }
135
+
136
+ #[no_mangle]
137
+ pub extern "C" fn sign_by_seed(message_p: *const c_char, seed_p: *const c_char) -> *mut c_char {
138
+ let seed = hex_pointer_to_vecu8(seed_p);
139
+ let keypair = wrapper::__keypair_from_seed(seed.as_slice());
140
+ let private = &keypair[0..SECRET_KEY_LENGTH];
141
+ let public = &keypair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
142
+
143
+ let message = hex_pointer_to_vecu8(message_p);
144
+ let signature = wrapper::__sign(&public, &private, &message);
145
+ // println!("{:?}", signature);
146
+ u8a_to_hex_pointer(&signature)
147
+ }
data/src/wrapper.rs ADDED
@@ -0,0 +1,98 @@
1
+ // modified from: https://github.com/paritytech/schnorrkel-js/blob/master/src/wrapper.rs
2
+
3
+ use schnorrkel::keys::*;
4
+ use schnorrkel::context::{signing_context};
5
+ use schnorrkel::derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH};
6
+ use schnorrkel::sign::{Signature,SIGNATURE_LENGTH};
7
+
8
+ // We must make sure that this is the same as declared in the substrate source code.
9
+ const SIGNING_CTX: &'static [u8] = b"substrate";
10
+
11
+ /// Private helper function.
12
+ fn keypair_from_seed(seed: &[u8]) -> Keypair {
13
+ let mini_key: MiniSecretKey = MiniSecretKey::from_bytes(seed)
14
+ .expect("32 bytes can always build a key; qed");
15
+ mini_key.expand_to_keypair(ExpansionMode::Ed25519)
16
+ }
17
+
18
+ /// ChainCode construction helper
19
+ fn create_cc(data: &[u8]) -> ChainCode {
20
+ let mut cc = [0u8; CHAIN_CODE_LENGTH];
21
+
22
+ cc.copy_from_slice(&data);
23
+
24
+ ChainCode(cc)
25
+ }
26
+
27
+ pub fn __derive_keypair_hard(pair: &[u8], cc: &[u8]) -> [u8; KEYPAIR_LENGTH] {
28
+ let derived = match Keypair::from_bytes(pair) {
29
+ Ok(kp) => kp.hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0.expand_to_keypair(ExpansionMode::Ed25519),
30
+ Err(_) => panic!("Provided pair is invalid.")
31
+ };
32
+ let mut kp = [0u8; KEYPAIR_LENGTH];
33
+ kp.copy_from_slice(&derived.to_bytes());
34
+ kp
35
+ }
36
+
37
+ pub fn __derive_keypair_soft(pair: &[u8], cc: &[u8]) -> [u8; KEYPAIR_LENGTH] {
38
+ let derived = match Keypair::from_bytes(pair) {
39
+ Ok(kp) => kp.derived_key_simple(create_cc(cc), &[]).0,
40
+ Err(_) => panic!("Provided pair is invalid.")
41
+ };
42
+ let mut kp = [0u8; KEYPAIR_LENGTH];
43
+ kp.copy_from_slice(&derived.to_bytes());
44
+ kp
45
+ }
46
+
47
+ pub fn __derive_public_soft(public: &[u8], cc: &[u8]) -> [u8; PUBLIC_KEY_LENGTH] {
48
+ let derived = match PublicKey::from_bytes(public) {
49
+ Ok(pk) => pk.derived_key_simple(create_cc(cc), &[]).0,
50
+ Err(_) => panic!("Provided publickey is invalid.")
51
+ };
52
+ let mut pk = [0u8; PUBLIC_KEY_LENGTH];
53
+ pk.copy_from_slice(&derived.to_bytes());
54
+ pk
55
+ }
56
+
57
+ pub fn __keypair_from_seed(seed: &[u8]) -> [u8; KEYPAIR_LENGTH] {
58
+ let keypair = keypair_from_seed(seed).to_bytes();
59
+ let mut kp = [0u8; KEYPAIR_LENGTH];
60
+ kp.copy_from_slice(&keypair);
61
+ kp
62
+ }
63
+
64
+ pub fn __secret_from_seed(seed: &[u8]) -> [u8; SECRET_KEY_LENGTH] {
65
+ let secret = keypair_from_seed(seed).secret.to_bytes();
66
+ let mut s = [0u8; SECRET_KEY_LENGTH];
67
+ s.copy_from_slice(&secret);
68
+ s
69
+ }
70
+
71
+ pub fn __verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
72
+ let sig = match Signature::from_bytes(signature) {
73
+ Ok(some_sig) => some_sig,
74
+ Err(_) => return false
75
+ };
76
+ let pk = match PublicKey::from_bytes(pubkey) {
77
+ Ok(some_pk) => some_pk,
78
+ Err(_) => return false
79
+ };
80
+ let result = pk.verify_simple(SIGNING_CTX, message, &sig);
81
+ result.is_ok()
82
+ }
83
+
84
+ pub fn __sign(public: &[u8], private: &[u8], message: &[u8]) -> [u8; SIGNATURE_LENGTH] {
85
+ // despite being a method of KeyPair, only the secret is used for signing.
86
+ let secret = match SecretKey::from_bytes(private) {
87
+ Ok(some_secret) => some_secret,
88
+ Err(_) => panic!("Provided private key is invalid.")
89
+ };
90
+
91
+ let public = match PublicKey::from_bytes(public) {
92
+ Ok(some_public) => some_public,
93
+ Err(_) => panic!("Provided public key is invalid.")
94
+ };
95
+
96
+ let context = signing_context(SIGNING_CTX);
97
+ secret.sign(context.bytes(message), &public).to_bytes()
98
+ }
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schnorrkel_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aki Wu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thermite
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: A Ruby wrapper to the Rust schnorrkel SR25519 signature library.
42
+ email:
43
+ - wuminzhe@gmail.com
44
+ executables: []
45
+ extensions:
46
+ - ext/Rakefile
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Cargo.lock
53
+ - Cargo.toml
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - ext/Rakefile
60
+ - lib/schnorrkel_rb.rb
61
+ - lib/schnorrkel_rb/version.rb
62
+ - schnorrkel_rb.gemspec
63
+ - sig/schnorrkel_rb.rbs
64
+ - src/lib.rs
65
+ - src/wrapper.rs
66
+ homepage: https://github.com/wuminzhe/schnorrkel_rb
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ allowed_push_host: https://rubygems.org/
71
+ homepage_uri: https://github.com/wuminzhe/schnorrkel_rb
72
+ source_code_uri: https://github.com/wuminzhe/schnorrkel_rb
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.6.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.3.7
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Ruby SR25519 Signature
92
+ test_files: []