adequate_crypto_address 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -10
- data/lib/adequate_crypto_address.rb +5 -2
- data/lib/adequate_crypto_address/altcoin.rb +60 -0
- data/lib/adequate_crypto_address/bch.rb +13 -15
- data/lib/adequate_crypto_address/btc.rb +13 -23
- data/lib/adequate_crypto_address/dash.rb +7 -0
- data/lib/adequate_crypto_address/version.rb +1 -1
- data/lib/adequate_crypto_address/xrp.rb +9 -0
- data/lib/adequate_crypto_address/zec.rb +9 -0
- data/spec/adequate_crypto_address_spec.rb +60 -14
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 396151caf8361e74bf9686d4ec10c913c6ba5f3c16a695fdf1c2a33dc3886abb
|
4
|
+
data.tar.gz: 51131dea9686bab8c4ea4996b53735c7db13b5d6c94869d39935b5517710b11b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0bb08404d180ee04be259d804aa298009136b57bfe023c3296bc09c792dca7e292a50f87a481e472210dacde055c58aff88b8c4f69800eacd566dac25b5451b
|
7
|
+
data.tar.gz: 4c18a2e6cdd22d5ac0e66eeb5bfcf2583f0114e945ea20a84aab8ab40d968f01848229e8e2d731d4f8b9b7499ba5af52a7c08d270eca6d64cd9700506050211f
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# AdequateCryptoAddress
|
2
|
+
Simple wallet address validator and normalizer for cryptocurrencies addresses in Ruby.
|
3
|
+
|
4
|
+
Inspired by [ognus/wallet-address-validator](https://github.com/ognus/wallet-address-validator).
|
2
5
|
|
3
6
|
[![Gem Version](https://badge.fury.io/rb/adequate_crypto_address.svg)](https://rubygems.org/gems/adequate_crypto_address)
|
4
7
|
[![Build Status](https://travis-ci.org/vtm9/adequate_crypto_address.svg?branch=master)](https://travis-ci.org/vtm9/adequate_crypto_address)
|
@@ -6,9 +9,6 @@
|
|
6
9
|
[![Coverage Status](https://coveralls.io/repos/vtm9/adequate_crypto_address/badge.svg?branch=master)](https://coveralls.io/r/vtm9/adequate_crypto_address?branch=master)
|
7
10
|
[![License](https://img.shields.io/github/license/RubyMoney/money.svg)](https://opensource.org/licenses/MIT)
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
12
|
## Installation
|
13
13
|
|
14
14
|
Add this line to your application's Gemfile:
|
@@ -17,13 +17,31 @@ Add this line to your application's Gemfile:
|
|
17
17
|
gem 'adequate_crypto_address'
|
18
18
|
```
|
19
19
|
|
20
|
-
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
gem install adequate_crypto_address
|
24
|
+
```
|
25
|
+
|
26
|
+
## Main API
|
21
27
|
|
22
|
-
|
28
|
+
##### .valid? (address [, currency = 'BTC'[, type = :prod]])
|
23
29
|
|
24
|
-
|
30
|
+
###### Parameters
|
31
|
+
* address - Wallet address to validate.
|
32
|
+
* currency - Currency name string or symbol in any case, `:bitcoin` or `'BTC'` or `:btc` or `'BitCoin'`
|
33
|
+
* type - Optional. You can enforce validation with specific type. Not all currencies support types.
|
25
34
|
|
26
|
-
|
35
|
+
> Returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies.
|
36
|
+
|
37
|
+
### Supported crypto currencies
|
38
|
+
|
39
|
+
* Bitcoin/BTC, `'bitcoin'` or `'BTC'` types: `:segwit_v0_keyhash :segwit_v0_scripthash :hash160 :p2sh`
|
40
|
+
* BitcoinCash/BCH, `'bitcoincash'` or `'BCH'` types: `:p2sh :p2pkh :p2pkhtest :p2shtest`
|
41
|
+
* Dash, `'dash'` or `'DASH'` types: `:prod :test`
|
42
|
+
* Zcash/ZEC, `'zcash'` or `'ZEC'` types: `:prod :test`
|
43
|
+
* Ethereum/ETH, `'ethereum'` or `'ETH'`
|
44
|
+
* Ripple/XRP, `'ripple'` or `'XRP'`
|
27
45
|
|
28
46
|
## Usage
|
29
47
|
|
@@ -36,8 +54,7 @@ AdequateCryptoAddress.valid?('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', :bitcoin, :p2
|
|
36
54
|
|
37
55
|
# BCH
|
38
56
|
AdequateCryptoAddress.valid?('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :bch) #=> true
|
39
|
-
AdequateCryptoAddress.valid?('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :
|
40
|
-
AdequateCryptoAddress.valid?('qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :BCH, :bitcoincash) #=> true
|
57
|
+
AdequateCryptoAddress.valid?('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :p2pkhtest) #=> true
|
41
58
|
|
42
59
|
# ETH
|
43
60
|
AdequateCryptoAddress.valid?('0xde709f2102306220921060314715629080e2fb77', :ETH) #=> true
|
@@ -49,13 +66,19 @@ AdequateCryptoAddress.valid?('de709f2102306220921060314715629080e2fb77', :ethere
|
|
49
66
|
require 'adequate_crypto_address'
|
50
67
|
|
51
68
|
# BCH
|
52
|
-
AdequateCryptoAddress.address('qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', 'bch').address #=> "bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk"
|
53
69
|
AdequateCryptoAddress.address('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', 'bch').cash_address #=> "bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf"
|
54
70
|
AdequateCryptoAddress.address('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', 'bch').legacy_address #=> "1LcerwTc1oPsMtByDCNUXFxReZpN1EXHoe"
|
55
71
|
|
72
|
+
address_string = 'qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk'
|
73
|
+
addr = AdequateCryptoAddress.address(address_string, 'bch')
|
74
|
+
addr.prefix #=> "bitcoincash"
|
75
|
+
addr.type #=> :p2pkh
|
76
|
+
addr.address #=> "bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk"
|
77
|
+
|
56
78
|
# ETH
|
57
79
|
AdequateCryptoAddress.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth').address #=> "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"
|
58
80
|
```
|
81
|
+
*Not all currencies support this feature.
|
59
82
|
|
60
83
|
## Development
|
61
84
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'adequate_crypto_address/utils/bech32'
|
2
2
|
require 'adequate_crypto_address/utils/bch'
|
3
3
|
|
4
|
+
require 'adequate_crypto_address/altcoin'
|
5
|
+
require 'adequate_crypto_address/bch'
|
4
6
|
require 'adequate_crypto_address/eth'
|
5
7
|
require 'adequate_crypto_address/btc'
|
6
|
-
require 'adequate_crypto_address/
|
7
|
-
|
8
|
+
require 'adequate_crypto_address/xrp'
|
9
|
+
require 'adequate_crypto_address/dash'
|
10
|
+
require 'adequate_crypto_address/zec'
|
8
11
|
|
9
12
|
module AdequateCryptoAddress
|
10
13
|
class UnknownCurrency < StandardError; end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AdequateCryptoAddress
|
4
|
+
# simple class for common altcoin addresses like legacy btc, ripple, dash, zec, etc.
|
5
|
+
class Altcoin
|
6
|
+
EXPECTED_LENGTH = 50
|
7
|
+
ADDRESS_TYPES = {}.freeze
|
8
|
+
ALPHABET_TYPE = :bitcoin
|
9
|
+
|
10
|
+
attr_reader :address, :type
|
11
|
+
alias raw_address address
|
12
|
+
|
13
|
+
def initialize(address)
|
14
|
+
@address = address
|
15
|
+
@type = address_type
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?(validated_type = nil)
|
19
|
+
if validated_type
|
20
|
+
type == validated_type.to_sym
|
21
|
+
else
|
22
|
+
!type.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :decoded
|
29
|
+
|
30
|
+
def address_type
|
31
|
+
@decoded = begin
|
32
|
+
decode_base58
|
33
|
+
rescue StandardError
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
if decoded && decoded.bytesize == self.class::EXPECTED_LENGTH && valid_address_checksum?
|
37
|
+
self.class::ADDRESS_TYPES.each do |net_type, net_prefixes|
|
38
|
+
net_prefixes.each do |net_prefix|
|
39
|
+
return net_type if decoded.start_with?(net_prefix)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def decode_base58
|
47
|
+
Base58.base58_to_binary(address, self.class::ALPHABET_TYPE).each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid_address_checksum?
|
51
|
+
return false unless decoded
|
52
|
+
|
53
|
+
checksum(decoded[0...-8]) == decoded[-8..-1]
|
54
|
+
end
|
55
|
+
|
56
|
+
def checksum(bytes)
|
57
|
+
Digest::SHA256.hexdigest(Digest::SHA256.digest([bytes].pack('H*')))[0...8]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -12,16 +12,16 @@ module AdequateCryptoAddress
|
|
12
12
|
|
13
13
|
TYPE_MAP = {
|
14
14
|
legacy: [
|
15
|
-
[:
|
16
|
-
[:
|
17
|
-
[:
|
18
|
-
[:
|
15
|
+
[:p2sh, 5],
|
16
|
+
[:p2pkh, 0],
|
17
|
+
[:p2shtest, 196],
|
18
|
+
[:p2pkhtest, 111]
|
19
19
|
],
|
20
20
|
cash: [
|
21
|
-
[:
|
22
|
-
[:
|
23
|
-
[:
|
24
|
-
[:
|
21
|
+
[:p2sh, 8],
|
22
|
+
[:p2pkh, 0],
|
23
|
+
[:p2shtest, 8],
|
24
|
+
[:p2pkhtest, 0]
|
25
25
|
]
|
26
26
|
}.freeze
|
27
27
|
DEFAULT_PREFIX = :bitcoincash
|
@@ -35,8 +35,6 @@ module AdequateCryptoAddress
|
|
35
35
|
|
36
36
|
def valid?(validated_type = nil)
|
37
37
|
if validated_type
|
38
|
-
puts type
|
39
|
-
puts validated_type
|
40
38
|
type == validated_type.to_sym
|
41
39
|
else
|
42
40
|
!type.nil?
|
@@ -97,8 +95,8 @@ module AdequateCryptoAddress
|
|
97
95
|
@type = address_type(:cash, converted[0].to_i)[0]
|
98
96
|
@payload = converted[1..-7]
|
99
97
|
|
100
|
-
@type = :
|
101
|
-
@type = :
|
98
|
+
@type = :p2shtest if prefix == 'bchtest' && type == :p2sh
|
99
|
+
@type = :p2pkhtest if prefix == 'bchtest' && type == :p2pkh
|
102
100
|
end
|
103
101
|
|
104
102
|
def from_legacy_string
|
@@ -114,9 +112,9 @@ module AdequateCryptoAddress
|
|
114
112
|
@digest = decoded[-4..-1]
|
115
113
|
@prefix = DEFAULT_PREFIX
|
116
114
|
|
117
|
-
@type = :
|
118
|
-
@type = :
|
119
|
-
@prefix = 'bchtest' if [:
|
115
|
+
@type = :p2shtest if prefix == 'bchtest' && type == :p2sh
|
116
|
+
@type = :p2pkhtest if prefix == 'bchtest' && type == :p2pkh
|
117
|
+
@prefix = 'bchtest' if [:p2shtest, :p2pkhtest].include?(type)
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
module AdequateCryptoAddress
|
4
4
|
class Btc
|
5
|
-
attr_reader :address
|
5
|
+
attr_reader :address, :type
|
6
6
|
alias raw_address address
|
7
7
|
|
8
8
|
def initialize(address)
|
9
9
|
@address = address
|
10
|
+
@type = address_type
|
10
11
|
end
|
11
12
|
|
12
13
|
def valid?(type = nil)
|
@@ -17,6 +18,8 @@ module AdequateCryptoAddress
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
private
|
22
|
+
|
20
23
|
def address_type
|
21
24
|
segwit_decoded = begin
|
22
25
|
decode_segwit_address
|
@@ -32,13 +35,13 @@ module AdequateCryptoAddress
|
|
32
35
|
return :segwit_v0_scripthash if witness_version == 0 && witness_program.bytesize == 32
|
33
36
|
end
|
34
37
|
|
35
|
-
|
38
|
+
base58_decoded = begin
|
36
39
|
decode_base58(address)
|
37
40
|
rescue StandardError
|
38
41
|
nil
|
39
42
|
end
|
40
|
-
if
|
41
|
-
case
|
43
|
+
if base58_decoded && base58_decoded.bytesize == 50 && valid_base58_address_checksum?(base58_decoded)
|
44
|
+
case base58_decoded[0...2]
|
42
45
|
when '00'
|
43
46
|
return :hash160
|
44
47
|
when '05'
|
@@ -49,8 +52,6 @@ module AdequateCryptoAddress
|
|
49
52
|
nil
|
50
53
|
end
|
51
54
|
|
52
|
-
private
|
53
|
-
|
54
55
|
def decode_segwit_address
|
55
56
|
actual_hrp, data = Utils::Bech32.decode(address)
|
56
57
|
|
@@ -72,29 +73,18 @@ module AdequateCryptoAddress
|
|
72
73
|
[data[0], program_hex]
|
73
74
|
end
|
74
75
|
|
75
|
-
def decode_base58(
|
76
|
-
|
77
|
-
s = '' if s == '00'
|
78
|
-
leading_zero_bytes = (base58_val =~ /^([1]+)/ ? Regexp.last_match(1) : '').size
|
79
|
-
s = ('00' * leading_zero_bytes) + s if leading_zero_bytes > 0
|
80
|
-
s
|
76
|
+
def decode_base58(_base58_val)
|
77
|
+
Base58.base58_to_binary(address, :bitcoin).each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
|
81
78
|
end
|
82
79
|
|
83
|
-
def
|
84
|
-
|
85
|
-
decode_base58(address)
|
86
|
-
rescue StandardError
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
return false unless hex
|
80
|
+
def valid_base58_address_checksum?(base58_decoded)
|
81
|
+
return false unless base58_decoded
|
90
82
|
|
91
|
-
checksum(
|
83
|
+
checksum(base58_decoded[0...-8]) == base58_decoded[-8..-1]
|
92
84
|
end
|
93
85
|
|
94
|
-
# checksum is a 4 bytes sha256-sha256 hexdigest.
|
95
86
|
def checksum(hex)
|
96
|
-
|
97
|
-
Digest::SHA256.hexdigest(Digest::SHA256.digest(b))[0...8]
|
87
|
+
Digest::SHA256.hexdigest(Digest::SHA256.digest([hex].pack('H*')))[0...8]
|
98
88
|
end
|
99
89
|
end
|
100
90
|
Bitcoin = Btc
|
@@ -17,7 +17,7 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
17
17
|
it 'validates segwit addresses' do
|
18
18
|
expect(described_class).to be_valid('BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4', 'BTC')
|
19
19
|
expect(described_class).to be_valid('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'bitcoin')
|
20
|
-
expect(described_class).to be_valid('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'bitcoin',
|
20
|
+
expect(described_class).to be_valid('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'bitcoin', :segwit_v0_keyhash)
|
21
21
|
expect(described_class).to be_valid('bc1qc7slrfxkknqcq2jevvvkdgvrt8080852dfjewde450xdlk4ugp7szw5tk9', 'BTC')
|
22
22
|
expect(described_class).to be_valid('bc1qc7slrfxkknqcq2jevvvkdgvrt8080852dfjewde450xdlk4ugp7szw5tk9', 'bitcoin', 'segwit_v0_scripthash')
|
23
23
|
end
|
@@ -41,23 +41,23 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
41
41
|
|
42
42
|
context 'Bitcoincash' do
|
43
43
|
it 'validates legacy addresses' do
|
44
|
-
expect(described_class).to be_valid('3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC', :bch, :
|
45
|
-
expect(described_class).to be_valid('155fzsEBHy9Ri2bMQ8uuuR3tv1YzcDywd4', 'bitcoincash', :
|
46
|
-
expect(described_class).to be_valid('2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc', 'BCH', :
|
47
|
-
expect(described_class).to be_valid('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :
|
44
|
+
expect(described_class).to be_valid('3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC', :bch, :p2sh)
|
45
|
+
expect(described_class).to be_valid('155fzsEBHy9Ri2bMQ8uuuR3tv1YzcDywd4', 'bitcoincash', :p2pkh)
|
46
|
+
expect(described_class).to be_valid('2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc', 'BCH', :p2shtest)
|
47
|
+
expect(described_class).to be_valid('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :p2pkhtest)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'validates cash addresses' do
|
51
|
-
expect(described_class).to be_valid('bitcoincash:qqkv9wr69ry2p9l53lxp635va4h86wv435995w8p2h', :bch, :
|
52
|
-
expect(described_class).to be_valid('bitcoincash:pqdg9uq52wzhf228hweext9j2jdjgdpj9qt7xxfngd', :bitcoincash, :
|
53
|
-
expect(described_class).to be_valid('bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf', :Bitcoincash, :
|
54
|
-
expect(described_class).to be_valid('bchtest:pp8f7ww2g6y07ypp9r4yendrgyznysc9kqxh6acwu3', :BCH, :
|
51
|
+
expect(described_class).to be_valid('bitcoincash:qqkv9wr69ry2p9l53lxp635va4h86wv435995w8p2h', :bch, :p2pkh)
|
52
|
+
expect(described_class).to be_valid('bitcoincash:pqdg9uq52wzhf228hweext9j2jdjgdpj9qt7xxfngd', :bitcoincash, :p2sh)
|
53
|
+
expect(described_class).to be_valid('bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf', :Bitcoincash, :p2pkhtest)
|
54
|
+
expect(described_class).to be_valid('bchtest:pp8f7ww2g6y07ypp9r4yendrgyznysc9kqxh6acwu3', :BCH, :p2shtest)
|
55
55
|
expect(described_class).to be_valid('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :bitcoincash)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'validates cash addresses without prefix addresses' do
|
59
59
|
expect(described_class).to be_valid('qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :bitcoincash)
|
60
|
-
expect(described_class).to be_valid('pqdg9uq52wzhf228hweext9j2jdjgdpj9qt7xxfngd', :bitcoincash, :
|
60
|
+
expect(described_class).to be_valid('pqdg9uq52wzhf228hweext9j2jdjgdpj9qt7xxfngd', :bitcoincash, :p2sh)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'validates wrong addresses' do
|
@@ -66,10 +66,10 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
66
66
|
expect(described_class).not_to be_valid('bitcoincash:wrong', :bch)
|
67
67
|
expect(described_class).not_to be_valid('bitcoincash:123', :bch)
|
68
68
|
|
69
|
-
expect(described_class).not_to be_valid('bitcoincash:qqkv9wr69ry2p9l53lxp635va4h86wv435995w8p2h', :bch, :
|
70
|
-
expect(described_class).not_to be_valid('bitcoincash:pqdg9uq52wzhf228hweext9j2jdjgdpj9qt7xxfngd', :bitcoincash, :
|
71
|
-
expect(described_class).not_to be_valid('bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf', :Bitcoincash, :
|
72
|
-
expect(described_class).not_to be_valid('bchtest:pp8f7ww2g6y07ypp9r4yendrgyznysc9kqxh6acwu3', :BCH, :
|
69
|
+
expect(described_class).not_to be_valid('bitcoincash:qqkv9wr69ry2p9l53lxp635va4h86wv435995w8p2h', :bch, :p2pkhtest)
|
70
|
+
expect(described_class).not_to be_valid('bitcoincash:pqdg9uq52wzhf228hweext9j2jdjgdpj9qt7xxfngd', :bitcoincash, :p2pkhtest)
|
71
|
+
expect(described_class).not_to be_valid('bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf', :Bitcoincash, :p2sh)
|
72
|
+
expect(described_class).not_to be_valid('bchtest:pp8f7ww2g6y07ypp9r4yendrgyznysc9kqxh6acwu3', :BCH, :p2sh)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -83,6 +83,7 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
83
83
|
expect(described_class).to be_valid('0x8617E340B3D01FA5F11F306F4090FD50E238070D', 'ETH')
|
84
84
|
expect(described_class).to be_valid('0xde709f2102306220921060314715629080e2fb77', 'ETH')
|
85
85
|
end
|
86
|
+
|
86
87
|
it 'validates without prefixes addresses' do
|
87
88
|
expect(described_class).to be_valid('27b1fdb04752bbc536007a920d24acb045561c26', 'ETH')
|
88
89
|
expect(described_class).to be_valid('5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', 'ETH')
|
@@ -96,6 +97,51 @@ RSpec.describe(AdequateCryptoAddress) do
|
|
96
97
|
expect(described_class).not_to be_valid('a10354276d2fC74ee91e37D085d35748613f4748', :ethereum)
|
97
98
|
end
|
98
99
|
end
|
100
|
+
|
101
|
+
context 'Ripple' do
|
102
|
+
it 'validates addresses' do
|
103
|
+
expect(described_class).to be_valid('rPMLwSwyyULN2acf5JKB1nj8F8Eu8pVMV8', :ripple)
|
104
|
+
expect(described_class).to be_valid('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn', :ripple)
|
105
|
+
expect(described_class).to be_valid('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn', 'RIPPLE')
|
106
|
+
expect(described_class).to be_valid('r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV', 'XRP')
|
107
|
+
expect(described_class).to be_valid('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', :XRP)
|
108
|
+
expect(described_class).to be_valid('rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN', 'XRP')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'validates wrong addresses' do
|
112
|
+
expect(described_class).not_to be_valid('r3kmLJN5D28dHuH8vZNUZpMC43pEHpaoc1', :xrp)
|
113
|
+
expect(described_class).not_to be_valid('r1kmLJN5D28dHuH8vZNUZpMC43pEHpaocV', 'ripple')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'Dash' do
|
118
|
+
it 'validates addresses' do
|
119
|
+
expect(described_class).to be_valid('Xx4dYKgz3Zcv6kheaqog3fynaKWjbahb6b', :dash)
|
120
|
+
expect(described_class).to be_valid('XcY4WJ6Z2Q8w7vcYER1JypC8s2oa3SQ1b1', 'DASH')
|
121
|
+
expect(described_class).to be_valid('XqMkVUZnqe3w4xvgdZRtZoe7gMitDudGs4', 'DASH', :prod)
|
122
|
+
expect(described_class).to be_valid('yPv7h2i8v3dJjfSH4L3x91JSJszjdbsJJA', :DASH, 'test')
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'validates wrong addresses' do
|
126
|
+
expect(described_class).not_to be_valid('yPv7h2i8v3dJ1fSH4L3x91JSJszjdbsJJA', :dash)
|
127
|
+
expect(described_class).not_to be_valid('XqMkVUZnqe3w4xvgdZRtZoe7gMitDudGs4', 'dash', :test)
|
128
|
+
expect(described_class).not_to be_valid('yPv7h2i8v3dJjfSH4L3x91JSJszjdbsJJA', :DASH, :prod)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'Zcash' do
|
133
|
+
it 'validates addresses' do
|
134
|
+
expect(described_class).to be_valid('t1U9yhDa5XEjgfnTgZoKddeSiEN1aoLkQxq', :zec)
|
135
|
+
expect(described_class).to be_valid('t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd', 'zcash', :prod)
|
136
|
+
expect(described_class).to be_valid('t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi', 'ZEC', :test)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'validates wrong addresses' do
|
140
|
+
expect(described_class).not_to be_valid('t1Y9yhDa5XEjgfnTgZoKddeSiEN1aoLkQxq', :zcash)
|
141
|
+
expect(described_class).not_to be_valid('t3Yz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd', :ZEC)
|
142
|
+
expect(described_class).not_to be_valid('t2YNzUUx8mWBCRYPRezvA363EYXyEpHokyi', :zcash, :test)
|
143
|
+
end
|
144
|
+
end
|
99
145
|
end
|
100
146
|
|
101
147
|
describe '.address' do
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vtm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|
@@ -98,12 +98,16 @@ files:
|
|
98
98
|
- adequate_crypto_address.gemspec
|
99
99
|
- bin/console
|
100
100
|
- lib/adequate_crypto_address.rb
|
101
|
+
- lib/adequate_crypto_address/altcoin.rb
|
101
102
|
- lib/adequate_crypto_address/bch.rb
|
102
103
|
- lib/adequate_crypto_address/btc.rb
|
104
|
+
- lib/adequate_crypto_address/dash.rb
|
103
105
|
- lib/adequate_crypto_address/eth.rb
|
104
106
|
- lib/adequate_crypto_address/utils/bch.rb
|
105
107
|
- lib/adequate_crypto_address/utils/bech32.rb
|
106
108
|
- lib/adequate_crypto_address/version.rb
|
109
|
+
- lib/adequate_crypto_address/xrp.rb
|
110
|
+
- lib/adequate_crypto_address/zec.rb
|
107
111
|
- spec/adequate_crypto_address/bch_spec.rb
|
108
112
|
- spec/adequate_crypto_address_spec.rb
|
109
113
|
- spec/spec_helper.rb
|