crypto-address 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/crypto-address.gemspec +24 -0
- data/lib/crypto-address.rb +63 -0
- data/lib/cryptoaddress/version.rb +3 -0
- data/spec/crypto_address_spec.rb +23 -0
- data/spec/spec_helper.rb +7 -0
- metadata +99 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ea07d996d22fcdb45574d3a6c5c658de70247786
|
|
4
|
+
data.tar.gz: eb1f5d83453ceb69077e48a89047e0399c3d62cb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 891f3a58ee0d7794d58f04f1b48b9095d2911479df015b40d1a091b1da1a1046ce0b1c24314c608f17e9e48e6217fddaab982e18e30155f7009c436314d19db0
|
|
7
|
+
data.tar.gz: 7c8aa347cf27061cc72e8ec685422b86066c425282b1d824d795fb0dcd985e4b50aded793a256fe658cb34fc49ad1a0fe97e30d9e780b477a4b2ba364d93f300
|
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.idea
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
crypto-address (0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.2.4)
|
|
10
|
+
rake (10.1.1)
|
|
11
|
+
rspec (2.13.0)
|
|
12
|
+
rspec-core (~> 2.13.0)
|
|
13
|
+
rspec-expectations (~> 2.13.0)
|
|
14
|
+
rspec-mocks (~> 2.13.0)
|
|
15
|
+
rspec-core (2.13.1)
|
|
16
|
+
rspec-expectations (2.13.0)
|
|
17
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
18
|
+
rspec-mocks (2.13.1)
|
|
19
|
+
|
|
20
|
+
PLATFORMS
|
|
21
|
+
ruby
|
|
22
|
+
|
|
23
|
+
DEPENDENCIES
|
|
24
|
+
bundler (~> 1.3)
|
|
25
|
+
crypto-address!
|
|
26
|
+
rake
|
|
27
|
+
rspec (~> 2.6)
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Noveltylab
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Crypto Address
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Add this line to your application's Gemfile:
|
|
6
|
+
|
|
7
|
+
gem "crypto-address"
|
|
8
|
+
|
|
9
|
+
And then execute:
|
|
10
|
+
|
|
11
|
+
$ bundle
|
|
12
|
+
|
|
13
|
+
Or install it yourself as:
|
|
14
|
+
|
|
15
|
+
$ gem install crypto-address
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
# will validate as BTC address by default
|
|
20
|
+
CryptoAddress.valid?('1FSG15yz41F3iH9pr6tQFfPrynVuyUz6KC')
|
|
21
|
+
|
|
22
|
+
# for reular and multisig addresses
|
|
23
|
+
CryptoAddress.valid?('DRmN5MHN1PDbiVHb7LufFVbsT1xn6ogvqH', :DOGE)
|
|
24
|
+
|
|
25
|
+
# testnet
|
|
26
|
+
CryptoAddress.valid?('D5eL9T9fHNLxtAA1Pzcse88wPxLqvVmSdf', :DOGE_TEST)
|
|
27
|
+
CryptoAddress.valid?('moEYD8dT52tF2KLTv9RQm2YFfQjrwe4Vse', :BTC_TEST)
|
|
28
|
+
|
|
29
|
+
# will return false
|
|
30
|
+
CryptoAddress.valid?('adsfasdfadsf', :BTC_TEST)
|
|
31
|
+
|
|
32
|
+
# will throw an exception
|
|
33
|
+
CryptoAddress.valid?('adsfasdfadsf', :UNKNOWN_TYPE)
|
|
34
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'cryptoaddress/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "crypto-address"
|
|
8
|
+
spec.version = CryptoAddress::VERSION
|
|
9
|
+
spec.authors = ["nixoid"]
|
|
10
|
+
spec.email = ["nixoid@noveltylab.com"]
|
|
11
|
+
spec.description = %q{Universal cryptocurrency address validator}
|
|
12
|
+
spec.summary = %q{Read description}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
|
24
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'cryptoaddress/version'
|
|
2
|
+
require 'digest'
|
|
3
|
+
|
|
4
|
+
module CryptoAddress
|
|
5
|
+
|
|
6
|
+
ADDRESS_TYPES = {
|
|
7
|
+
BTC: [0, 5],
|
|
8
|
+
LTC: [48, 5],
|
|
9
|
+
DOGE: [30, 22],
|
|
10
|
+
PPC: [55, 117],
|
|
11
|
+
DRK: [76, 05],
|
|
12
|
+
BC: [25, 85],
|
|
13
|
+
|
|
14
|
+
BTC_TEST: [111, 196],
|
|
15
|
+
LTC_TEST: [111, 196],
|
|
16
|
+
DOGE_TEST: [113, 196],
|
|
17
|
+
PPC_TEST: [111, 196],
|
|
18
|
+
DRK_TEST: [111, 196],
|
|
19
|
+
BC_TEST: [111, 196]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
|
|
25
|
+
def valid?(address, type = :BTC)
|
|
26
|
+
raise "Unknown currency" unless ADDRESS_TYPES.has_key?(type)
|
|
27
|
+
hex = decode_base58(address) rescue false
|
|
28
|
+
return false unless hex && hex.bytesize == 50
|
|
29
|
+
return false unless ADDRESS_TYPES[type].include?(hex[0...2].to_i(16))
|
|
30
|
+
checksum_valid?(hex)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def decode_base58(base58_val)
|
|
34
|
+
s = base58_to_int(base58_val).to_s(16); s = (s.bytesize.odd? ? '0'+s : s)
|
|
35
|
+
s = '' if s == '00'
|
|
36
|
+
leading_zero_bytes = (base58_val.match(/^([1]+)/) ? $1 : '').size
|
|
37
|
+
s = ("00"*leading_zero_bytes) + s if leading_zero_bytes > 0
|
|
38
|
+
s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def base58_to_int(base58_val)
|
|
42
|
+
alpha = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
43
|
+
int_val, base = 0, alpha.size
|
|
44
|
+
base58_val.reverse.each_char.with_index do |char,index|
|
|
45
|
+
raise ArgumentError, 'Value not a valid Base58 String.' unless char_index = alpha.index(char)
|
|
46
|
+
int_val += char_index*(base**index)
|
|
47
|
+
end
|
|
48
|
+
int_val
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def checksum_valid?(hex)
|
|
52
|
+
checksum( hex[0...42] ) == hex[-8..-1]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def checksum(hex)
|
|
56
|
+
b = [hex].pack("H*") # unpack hex
|
|
57
|
+
Digest::SHA256.hexdigest( Digest::SHA256.digest(b) )[0...8]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CryptoAddress do
|
|
4
|
+
describe "valid?" do
|
|
5
|
+
it "should return false if address is valid but type is not matching to what specified" do
|
|
6
|
+
CryptoAddress.valid?('BGYvHnVNezSJyzopYvJdXveSzVJkNUwjGt', :BTC).should == false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should return false if address is invalid" do
|
|
10
|
+
CryptoAddress.valid?('3P1TEdL5DJYeRTSxYsaooaaaaaaaaaaaaa', :BTC).should == false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should return true if address is valid" do
|
|
14
|
+
CryptoAddress.valid?('BGYvHnVNezSJyzopYvJdXveSzVJkNUwjGt', :BC).should == true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should throw exception if unknown address type is specified" do
|
|
18
|
+
expect {
|
|
19
|
+
CryptoAddress.valid?('someunkonwnaddress', :WTF)
|
|
20
|
+
}.to raise_error
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crypto-address
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '0.1'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- nixoid
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
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: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '2.6'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '2.6'
|
|
55
|
+
description: Universal cryptocurrency address validator
|
|
56
|
+
email:
|
|
57
|
+
- nixoid@noveltylab.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- Gemfile
|
|
64
|
+
- Gemfile.lock
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- crypto-address.gemspec
|
|
69
|
+
- lib/crypto-address.rb
|
|
70
|
+
- lib/cryptoaddress/version.rb
|
|
71
|
+
- spec/crypto_address_spec.rb
|
|
72
|
+
- spec/spec_helper.rb
|
|
73
|
+
homepage: ''
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
metadata: {}
|
|
77
|
+
post_install_message:
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - '>='
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
requirements: []
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 2.3.0
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Read description
|
|
97
|
+
test_files:
|
|
98
|
+
- spec/crypto_address_spec.rb
|
|
99
|
+
- spec/spec_helper.rb
|