adequate_crypto_address 0.1.3 → 0.1.4
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 +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +73 -8
- data/lib/adequate_crypto_address.rb +1 -0
- data/lib/adequate_crypto_address/ltc.rb +8 -0
- data/lib/adequate_crypto_address/version.rb +1 -1
- data/spec/adequate_crypto_address_spec.rb +26 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66e0b65abfe56eac0be65f3edf9659e2e01cff5bd0316dd351e0e67147ae7869
|
4
|
+
data.tar.gz: 6d5a85caa8ed1a1370ef7247d320e9e74ec08a1f2719b2ec712c99f8e5b4e078
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2bab1c6a29e339533aca606a1b16164367886b31b7ef42f3624760e4098c1c49b8fc7867edbc840b7bbce70995769c9c0dc7b743e419e0a273f23053c74f1dd
|
7
|
+
data.tar.gz: 964a58d65459a09d9d73881f823dbf3d6c820972b2ce944f1610f9799d3a89839f0115735eabf427e232a46f9ef62ef58ba77c9b4f8ea83e61023ad49b5fbb23
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 vtm
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
AdequateCryptoAddress
|
3
|
+
===============
|
4
|
+
|
5
|
+
[![Gem Version][gem-version-svg]][gem-version-link]
|
6
|
+
[![Build Status][build-status-svg]][build-status-link]
|
7
|
+
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
|
8
|
+
[![Coverage Status][coverage-status-svg]][coverage-status-link]
|
9
|
+
[![Downloads][downloads-svg]][downloads-link]
|
10
|
+
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
|
11
|
+
[![License][license-svg]][license-link]
|
12
|
+
|
2
13
|
Simple wallet address validator and normalizer for cryptocurrencies addresses in Ruby.
|
3
14
|
|
4
15
|
Inspired by [ognus/wallet-address-validator](https://github.com/ognus/wallet-address-validator).
|
5
16
|
|
6
|
-
[](https://rubygems.org/gems/adequate_crypto_address)
|
7
|
-
[](https://travis-ci.org/vtm9/adequate_crypto_address)
|
8
|
-
[](https://codeclimate.com/github/vtm9/adequate_crypto_address)
|
9
|
-
[](https://coveralls.io/r/vtm9/adequate_crypto_address?branch=master)
|
10
|
-
[](https://opensource.org/licenses/MIT)
|
11
17
|
|
12
18
|
## Installation
|
13
19
|
|
@@ -25,7 +31,7 @@ gem install adequate_crypto_address
|
|
25
31
|
|
26
32
|
## Main API
|
27
33
|
|
28
|
-
##### .valid? (address
|
34
|
+
##### .valid? (address, currency [, type = :prod])
|
29
35
|
|
30
36
|
###### Parameters
|
31
37
|
* address - Wallet address to validate.
|
@@ -62,6 +68,7 @@ AdequateCryptoAddress.valid?('de709f2102306220921060314715629080e2fb77', :ethere
|
|
62
68
|
```
|
63
69
|
|
64
70
|
### Normalization
|
71
|
+
###### *Not all currencies support this feature.
|
65
72
|
``` ruby
|
66
73
|
require 'adequate_crypto_address'
|
67
74
|
|
@@ -78,7 +85,49 @@ addr.address #=> "bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk"
|
|
78
85
|
# ETH
|
79
86
|
AdequateCryptoAddress.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth').address #=> "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"
|
80
87
|
```
|
81
|
-
|
88
|
+
|
89
|
+
|
90
|
+
### ActiveRecord validation example
|
91
|
+
``` ruby
|
92
|
+
class Model < ActiveRecord::Base
|
93
|
+
attribute :address, :string
|
94
|
+
attribute :dest_tag, :string
|
95
|
+
attribute :currency, :string
|
96
|
+
|
97
|
+
validate :validate_address_type
|
98
|
+
validate :validate_destination_tag
|
99
|
+
|
100
|
+
def validate_address_type
|
101
|
+
errors.add(:address, 'invalid address') unless AdequateCryptoAddress.valid?(address, currency)
|
102
|
+
end
|
103
|
+
|
104
|
+
# for Ripple
|
105
|
+
def validate_destination_tag
|
106
|
+
errors.add(:dest_tag, 'invalid destination tag') if dest_tag.present? && !(dest_tag =~ /\A\d{1,10}\z/)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
```
|
111
|
+
### Add your currnecy
|
112
|
+
``` ruby
|
113
|
+
# frozen_string_literal: true
|
114
|
+
# for Rails /config/initializers/adequate_crypto_address.rb
|
115
|
+
module AdequateCryptoAddress
|
116
|
+
class Coin
|
117
|
+
attr_reader :address
|
118
|
+
|
119
|
+
def initialize(address_sring)
|
120
|
+
@address = address_sring
|
121
|
+
end
|
122
|
+
|
123
|
+
def valid?(_type)
|
124
|
+
address.present?
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
AdequateCryptoAddress.valid?('addr', :coin) #=> true
|
130
|
+
```
|
82
131
|
|
83
132
|
## Development
|
84
133
|
|
@@ -97,3 +146,19 @@ Run `rake spec` to run the tests. You can also run `bin/console` for an interact
|
|
97
146
|
## Notes
|
98
147
|
|
99
148
|
Bug reports and pull requests are welcome on GitHub at https://github.com/vtm9/adequate_crypto_address/issues
|
149
|
+
|
150
|
+
[gem-version-svg]: https://badge.fury.io/rb/adequate_crypto_address.svg
|
151
|
+
[gem-version-link]: https://rubygems.org/gems/adequate_crypto_address
|
152
|
+
[downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/adequate_crypto_address
|
153
|
+
[downloads-link]: https://rubygems.org/gems/adequate_crypto_address
|
154
|
+
[build-status-svg]: https://travis-ci.org/vtm9/adequate_crypto_address.svg?branch=master
|
155
|
+
[build-status-link]:https://travis-ci.org/vtm9/adequate_crypto_address
|
156
|
+
[coverage-status-svg]: https://coveralls.io/repos/vtm9/adequate_crypto_address/badge.svg?branch=master
|
157
|
+
[coverage-status-link]: https://coveralls.io/r/vtm9/adequate_crypto_address?branch=master
|
158
|
+
[codeclimate-status-svg]: https://codeclimate.com/github/vtm9/adequate_crypto_address.svg
|
159
|
+
[codeclimate-status-link]: https://codeclimate.com/github/vtm9/adequate_crypto_address
|
160
|
+
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
|
161
|
+
[docs-rubydoc-link]: http://www.rubydoc.info/gems/adequate_crypto_address/
|
162
|
+
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
|
163
|
+
[license-link]: https://github.com/vtm9/adequate_crypto_address/blob/master/LICENSE.txt
|
164
|
+
|
@@ -8,6 +8,7 @@ require 'adequate_crypto_address/btc'
|
|
8
8
|
require 'adequate_crypto_address/xrp'
|
9
9
|
require 'adequate_crypto_address/dash'
|
10
10
|
require 'adequate_crypto_address/zec'
|
11
|
+
require 'adequate_crypto_address/ltc'
|
11
12
|
|
12
13
|
module AdequateCryptoAddress
|
13
14
|
class UnknownCurrency < StandardError; end
|
@@ -93,6 +93,7 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'validates wrong addresses' do
|
96
|
+
expect(described_class).not_to be_valid('wrong', :ETH)
|
96
97
|
expect(described_class).not_to be_valid('0xD1110A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'ETH')
|
97
98
|
expect(described_class).not_to be_valid('a10354276d2fC74ee91e37D085d35748613f4748', :ethereum)
|
98
99
|
end
|
@@ -109,6 +110,7 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
109
110
|
end
|
110
111
|
|
111
112
|
it 'validates wrong addresses' do
|
113
|
+
expect(described_class).not_to be_valid('wrong', :xrp)
|
112
114
|
expect(described_class).not_to be_valid('r3kmLJN5D28dHuH8vZNUZpMC43pEHpaoc1', :xrp)
|
113
115
|
expect(described_class).not_to be_valid('r1kmLJN5D28dHuH8vZNUZpMC43pEHpaocV', 'ripple')
|
114
116
|
end
|
@@ -123,6 +125,7 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
123
125
|
end
|
124
126
|
|
125
127
|
it 'validates wrong addresses' do
|
128
|
+
expect(described_class).not_to be_valid('wrong', :dash)
|
126
129
|
expect(described_class).not_to be_valid('yPv7h2i8v3dJ1fSH4L3x91JSJszjdbsJJA', :dash)
|
127
130
|
expect(described_class).not_to be_valid('XqMkVUZnqe3w4xvgdZRtZoe7gMitDudGs4', 'dash', :test)
|
128
131
|
expect(described_class).not_to be_valid('yPv7h2i8v3dJjfSH4L3x91JSJszjdbsJJA', :DASH, :prod)
|
@@ -137,6 +140,29 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
137
140
|
end
|
138
141
|
|
139
142
|
it 'validates wrong addresses' do
|
143
|
+
expect(described_class).not_to be_valid('wrong', :zec)
|
144
|
+
expect(described_class).not_to be_valid('t1Y9yhDa5XEjgfnTgZoKddeSiEN1aoLkQxq', :zcash)
|
145
|
+
expect(described_class).not_to be_valid('t3Yz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd', :ZEC)
|
146
|
+
expect(described_class).not_to be_valid('t2YNzUUx8mWBCRYPRezvA363EYXyEpHokyi', :zcash, :test)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'Litecoin' do
|
151
|
+
it 'validates addresses' do
|
152
|
+
expect(described_class).to be_valid('LVg2kJoFNg45Nbpy53h7Fe1wKyeXVRhMH9', :ltc)
|
153
|
+
expect(described_class).to be_valid('LVg2kJoFNg45Nbpy53h7Fe1wKyeXVRhMH9', 'ltc', :prod)
|
154
|
+
expect(described_class).to be_valid('LTpYZG19YmfvY2bBDYtCKpunVRw7nVgRHW', 'LTC')
|
155
|
+
expect(described_class).to be_valid('Lb6wDP2kHGyWC7vrZuZAgV7V4ECyDdH7a6', 'Litecoin')
|
156
|
+
expect(described_class).to be_valid('mzBc4XEFSdzCDcTxAgf6EZXgsZWpztRhef', 'Litecoin', :test)
|
157
|
+
|
158
|
+
expect(described_class).to be_valid('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', 'LTC')
|
159
|
+
expect(described_class).to be_valid('2MxKEf2su6FGAUfCEAHreGFQvEYrfYNHvL7', 'LTC', :test)
|
160
|
+
expect(described_class).to be_valid('QW2SvwjaJU8LD6GSmtm1PHnBG2xPuxwZFy', 'LTC', :test)
|
161
|
+
expect(described_class).to be_valid('QjpzxpbLp5pCGsCczMbfh1uhC3P89QZavY', 'LTC', :test)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'validates wrong addresses' do
|
165
|
+
expect(described_class).not_to be_valid('wrong', :zec)
|
140
166
|
expect(described_class).not_to be_valid('t1Y9yhDa5XEjgfnTgZoKddeSiEN1aoLkQxq', :zcash)
|
141
167
|
expect(described_class).not_to be_valid('t3Yz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd', :ZEC)
|
142
168
|
expect(described_class).not_to be_valid('t2YNzUUx8mWBCRYPRezvA363EYXyEpHokyi', :zcash, :test)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adequate_crypto_address
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vtm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- ".rubocop.yml"
|
94
94
|
- ".travis.yml"
|
95
95
|
- Gemfile
|
96
|
+
- LICENSE.txt
|
96
97
|
- README.md
|
97
98
|
- Rakefile
|
98
99
|
- adequate_crypto_address.gemspec
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- lib/adequate_crypto_address/btc.rb
|
104
105
|
- lib/adequate_crypto_address/dash.rb
|
105
106
|
- lib/adequate_crypto_address/eth.rb
|
107
|
+
- lib/adequate_crypto_address/ltc.rb
|
106
108
|
- lib/adequate_crypto_address/utils/bch.rb
|
107
109
|
- lib/adequate_crypto_address/utils/bech32.rb
|
108
110
|
- lib/adequate_crypto_address/version.rb
|
@@ -130,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
132
|
- !ruby/object:Gem::Version
|
131
133
|
version: '0'
|
132
134
|
requirements: []
|
133
|
-
|
134
|
-
rubygems_version: 2.7.6
|
135
|
+
rubygems_version: 3.0.1
|
135
136
|
signing_key:
|
136
137
|
specification_version: 4
|
137
138
|
summary: A Ruby Library for dealing with validation cryptocurrency adresses.
|