b58 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 +16 -0
- data/.gitmodules +3 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/b58.gemspec +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/b58/b58.c +126 -0
- data/ext/b58/b58.h +6 -0
- data/ext/b58/extconf.rb +14 -0
- data/ext/libbase58/.gitignore +25 -0
- data/ext/libbase58/.travis.yml +48 -0
- data/ext/libbase58/AUTHORS +2 -0
- data/ext/libbase58/COPYING +19 -0
- data/ext/libbase58/INSTALL +20 -0
- data/ext/libbase58/Makefile.am +44 -0
- data/ext/libbase58/README.md +66 -0
- data/ext/libbase58/autogen.sh +11 -0
- data/ext/libbase58/base58.c +205 -0
- data/ext/libbase58/clitool.c +130 -0
- data/ext/libbase58/configure.ac +49 -0
- data/ext/libbase58/libbase58.h +23 -0
- data/ext/libbase58/libbase58.pc.in +10 -0
- data/ext/libbase58/tests/decode-b58c-fail.sh +2 -0
- data/ext/libbase58/tests/decode-b58c-null.sh +3 -0
- data/ext/libbase58/tests/decode-b58c-toolong.sh +2 -0
- data/ext/libbase58/tests/decode-b58c-tooshort.sh +2 -0
- data/ext/libbase58/tests/decode-b58c.sh +3 -0
- data/ext/libbase58/tests/decode-highbit-prefix.sh +3 -0
- data/ext/libbase58/tests/decode-highbit.sh +3 -0
- data/ext/libbase58/tests/decode-small.sh +3 -0
- data/ext/libbase58/tests/decode-zero.sh +3 -0
- data/ext/libbase58/tests/decode.sh +3 -0
- data/ext/libbase58/tests/encode-b58c-high.sh +3 -0
- data/ext/libbase58/tests/encode-b58c.sh +3 -0
- data/ext/libbase58/tests/encode-fail.sh +3 -0
- data/ext/libbase58/tests/encode-neg-index.sh +4 -0
- data/ext/libbase58/tests/encode-small.sh +3 -0
- data/ext/libbase58/tests/encode.sh +3 -0
- data/lib/b58.rb +7 -0
- data/lib/b58/version.rb +3 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -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
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
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 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
data/Gemfile.lock
ADDED
@@ -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
|
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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).
|
data/Rakefile
ADDED
@@ -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]
|
data/b58.gemspec
ADDED
@@ -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
|
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
data/ext/b58/b58.c
ADDED
@@ -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
|
+
}
|
data/ext/b58/b58.h
ADDED
data/ext/b58/extconf.rb
ADDED
@@ -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")
|