b58 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +6 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +37 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +44 -0
  11. data/Rakefile +14 -0
  12. data/b58.gemspec +28 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/ext/b58/b58.c +126 -0
  16. data/ext/b58/b58.h +6 -0
  17. data/ext/b58/extconf.rb +14 -0
  18. data/ext/libbase58/.gitignore +25 -0
  19. data/ext/libbase58/.travis.yml +48 -0
  20. data/ext/libbase58/AUTHORS +2 -0
  21. data/ext/libbase58/COPYING +19 -0
  22. data/ext/libbase58/INSTALL +20 -0
  23. data/ext/libbase58/Makefile.am +44 -0
  24. data/ext/libbase58/README.md +66 -0
  25. data/ext/libbase58/autogen.sh +11 -0
  26. data/ext/libbase58/base58.c +205 -0
  27. data/ext/libbase58/clitool.c +130 -0
  28. data/ext/libbase58/configure.ac +49 -0
  29. data/ext/libbase58/libbase58.h +23 -0
  30. data/ext/libbase58/libbase58.pc.in +10 -0
  31. data/ext/libbase58/tests/decode-b58c-fail.sh +2 -0
  32. data/ext/libbase58/tests/decode-b58c-null.sh +3 -0
  33. data/ext/libbase58/tests/decode-b58c-toolong.sh +2 -0
  34. data/ext/libbase58/tests/decode-b58c-tooshort.sh +2 -0
  35. data/ext/libbase58/tests/decode-b58c.sh +3 -0
  36. data/ext/libbase58/tests/decode-highbit-prefix.sh +3 -0
  37. data/ext/libbase58/tests/decode-highbit.sh +3 -0
  38. data/ext/libbase58/tests/decode-small.sh +3 -0
  39. data/ext/libbase58/tests/decode-zero.sh +3 -0
  40. data/ext/libbase58/tests/decode.sh +3 -0
  41. data/ext/libbase58/tests/encode-b58c-high.sh +3 -0
  42. data/ext/libbase58/tests/encode-b58c.sh +3 -0
  43. data/ext/libbase58/tests/encode-fail.sh +3 -0
  44. data/ext/libbase58/tests/encode-neg-index.sh +4 -0
  45. data/ext/libbase58/tests/encode-small.sh +3 -0
  46. data/ext/libbase58/tests/encode.sh +3 -0
  47. data/lib/b58.rb +7 -0
  48. data/lib/b58/version.rb +3 -0
  49. metadata +93 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43c014be31ac7d77ecba9426b5037e3d942029dea3c82c5e8f47b6b7bc7fcdd6
4
+ data.tar.gz: e8a762b838821958110908c7e03254a014cbe4fcee3172a868ad4e671b0d1825
5
+ SHA512:
6
+ metadata.gz: 9a65ea0ac061923d16c7f7a6e766dcc34bd9d791a3a7eabd9cdeced4cf56528383a11ded5a9454cebafaf067b8fc41822be4d19594bb18f3c9b1ecc8b4d63f64
7
+ data.tar.gz: 51cd54e9b36c5d030d4943ce2eac39d9ed0be5ad66c8636a474a3b0a856ef165748d34c5dbbde43f830b32553d35d26d4be7341bc5b712f7c68fabf83f52ee58
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
@@ -0,0 +1,3 @@
1
+ [submodule "ext/libbase58"]
2
+ path = ext/libbase58
3
+ url = https://github.com/luke-jr/libbase58
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.1
@@ -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 i.kerseymer@gmail.com. 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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in b58.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rake-compiler"
8
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ b58 (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (12.3.3)
11
+ rake-compiler (1.1.1)
12
+ rake
13
+ rspec (3.10.0)
14
+ rspec-core (~> 3.10.0)
15
+ rspec-expectations (~> 3.10.0)
16
+ rspec-mocks (~> 3.10.0)
17
+ rspec-core (3.10.1)
18
+ rspec-support (~> 3.10.0)
19
+ rspec-expectations (3.10.1)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.10.0)
22
+ rspec-mocks (3.10.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-support (3.10.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ b58!
32
+ rake (~> 12.0)
33
+ rake-compiler
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 2.1.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Ian Ker-Seymer
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.
@@ -0,0 +1,44 @@
1
+ # Base58
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/b58`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'b58'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install b58
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ianks/b58. 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/ianks/b58/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Base58 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ianks/b58/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rake/extensiontask"
7
+
8
+ task :build => :compile
9
+
10
+ Rake::ExtensionTask.new("b58") do |ext|
11
+ ext.lib_dir = "lib/b58"
12
+ end
13
+
14
+ task :default => [:clobber, :compile, :spec]
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/b58/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "b58"
5
+ spec.version = Base58::VERSION
6
+ spec.authors = ["Ian Ker-Seymer"]
7
+ spec.email = ["i.kerseymer@gmail.com"]
8
+
9
+ spec.summary = %q{A base58 encoder for Ruby}
10
+ spec.description = %q{Uses libbase58 to encode Ruby strings to base58}
11
+ spec.homepage = "https://github.com/ianks/b58"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files --recurse-submodules -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|tests)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.extensions = ["ext/b58/extconf.rb"]
28
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "b58"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,126 @@
1
+ #include "b58.h"
2
+ #include "./../libbase58/base58.c"
3
+
4
+ #include <openssl/sha.h>
5
+ #include <stdbool.h>
6
+ #include <unistd.h>
7
+
8
+ VALUE rb_mBase58;
9
+ VALUE rb_mBase58_Error;
10
+ VALUE rb_mBase58_EncodeError;
11
+ VALUE rb_mBase58_DecodeError;
12
+
13
+ static bool my_sha256(void *md, const void *input, size_t length) {
14
+ SHA256_CTX context;
15
+ if (!SHA256_Init(&context))
16
+ return false;
17
+
18
+ if (!SHA256_Update(&context, (unsigned char *)input, length))
19
+ return false;
20
+
21
+ if (!SHA256_Final(md, &context))
22
+ return false;
23
+
24
+ return true;
25
+ }
26
+
27
+ VALUE rb_mBase58_decode_58(VALUE self, VALUE str) {
28
+ Check_Type(str, T_STRING);
29
+
30
+ size_t input_size;
31
+ input_size = RSTRING_LEN(str);
32
+
33
+ size_t output_size;
34
+ output_size = input_size * 733 / 1000 + 1;
35
+
36
+ char outbuf[output_size];
37
+ char *plaintxt;
38
+
39
+ plaintxt = RSTRING_PTR(str);
40
+
41
+ bool rv;
42
+
43
+ rv = b58tobin(outbuf, &output_size, plaintxt, input_size);
44
+
45
+ if (!rv) {
46
+ rb_raise(rb_mBase58_EncodeError, "Could not encode string in base58");
47
+ return Qnil;
48
+ }
49
+
50
+ // Account for null termination
51
+ VALUE outstring;
52
+ outstring = rb_str_new(outbuf, output_size);
53
+ return outstring;
54
+ }
55
+
56
+ VALUE rb_mBase58_encode_58(VALUE self, VALUE str) {
57
+ Check_Type(str, T_STRING);
58
+
59
+ size_t input_size;
60
+ input_size = RSTRING_LEN(str);
61
+
62
+ size_t output_size;
63
+ output_size = input_size * 2;
64
+
65
+ char outbuf[output_size];
66
+ char *plaintxt;
67
+
68
+ plaintxt = RSTRING_PTR(str);
69
+
70
+ bool rv;
71
+
72
+ rv = b58enc(outbuf, &output_size, plaintxt, input_size);
73
+
74
+ if (!rv) {
75
+ rb_raise(rb_mBase58_EncodeError, "Could not encode string in base58");
76
+ return Qnil;
77
+ }
78
+
79
+ // Account for null termination
80
+ return rb_str_new(outbuf, output_size - 1);
81
+ }
82
+
83
+ VALUE rb_mBase58_check_58(VALUE self, VALUE str) {
84
+ Check_Type(str, T_STRING);
85
+
86
+ size_t input_size;
87
+ input_size = RSTRING_LEN(str);
88
+
89
+ size_t output_size;
90
+ output_size = input_size * 2;
91
+
92
+ char outbuf[output_size];
93
+
94
+ char *plaintxt;
95
+ plaintxt = RSTRING_PTR(str);
96
+
97
+ int version;
98
+ version = plaintxt[0];
99
+
100
+ bool rv;
101
+
102
+ rv =
103
+ b58check_enc(outbuf, &output_size, version, &plaintxt[1], input_size - 1);
104
+
105
+ if (rv) {
106
+ return Qtrue;
107
+ } else {
108
+ return Qfalse;
109
+ }
110
+ }
111
+
112
+ void Init_b58(void) {
113
+ b58_sha256_impl = my_sha256;
114
+
115
+ rb_mBase58 = rb_define_module("Base58");
116
+ rb_mBase58_Error =
117
+ rb_define_class_under(rb_mBase58, "Error", rb_eStandardError);
118
+ rb_mBase58_EncodeError =
119
+ rb_define_class_under(rb_mBase58, "EncodeError", rb_mBase58_Error);
120
+ rb_mBase58_DecodeError =
121
+ rb_define_class_under(rb_mBase58, "EncodeError", rb_mBase58_Error);
122
+
123
+ rb_define_module_function(rb_mBase58, "encode_58", rb_mBase58_encode_58, 1);
124
+ rb_define_module_function(rb_mBase58, "decode_58", rb_mBase58_decode_58, 1);
125
+ rb_define_module_function(rb_mBase58, "check_58", rb_mBase58_check_58, 1);
126
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef BASE_58_H
2
+ #define BASE_58_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* BASE_58_H */
@@ -0,0 +1,14 @@
1
+ require "mkmf"
2
+
3
+ $CFLAGS << " -std=c99 -Wno-declaration-after-statement"
4
+
5
+ have_library('crypto')
6
+ have_library('base58')
7
+
8
+ have_header("stdbool.h")
9
+ have_header("unistd.h")
10
+ have_header('openssl/sha.h')
11
+
12
+ dir_config "b58"
13
+
14
+ create_makefile("b58/b58")