adequate_crypto_address 0.2.0 → 0.3.0
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/CHANGELOG.md +16 -0
- data/README.md +6 -5
- data/lib/adequate_crypto_address/atom.rb +53 -0
- data/lib/adequate_crypto_address/eth.rb +9 -0
- data/lib/adequate_crypto_address/trx.rb +12 -0
- data/lib/adequate_crypto_address/version.rb +1 -1
- data/lib/adequate_crypto_address/xtz.rb +18 -0
- data/lib/adequate_crypto_address.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df433b807d749cf8b119f5518093375a5634c1c1669ca7414ddb55085bc1f08b
|
|
4
|
+
data.tar.gz: 3dc0e213e7fcbc06b82cb0062af5c80caa3d56466ac67e8689c20fa48f01a952
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 358d49195d75675e1364617c1053795fc31e817534701e0758f2086653ef2e6aa11fc6198f596216fe5228dae1d73a73fd4b02c18b9d96ecdc4a14cb415230c2
|
|
7
|
+
data.tar.gz: 36a5d580408b7063de6765f031aaaeb2e9d3f2f98dcf8296bbdf314a8d4c37deadaacf271ffb458ba5edebfb8cebc270e1f030565e11682d704b7ed1125dd265
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.3.0] - 2026-09-02
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **TRON (TRX)** validation — Base58Check with the `0x41` version byte and
|
|
13
|
+
double-SHA256 checksum. Currency names: `trx`, `tron`. Type: `:prod`.
|
|
14
|
+
- **Tezos (XTZ)** validation — Base58Check with `tz1`/`tz2`/`tz3` implicit and
|
|
15
|
+
`KT1` originated (contract) prefixes. Currency names: `xtz`, `tezos`.
|
|
16
|
+
Types: `:implicit`, `:originated`.
|
|
17
|
+
- **Cosmos (ATOM)** validation — Bech32 with the `cosmos` human-readable part and
|
|
18
|
+
a 20-byte payload. Currency names: `atom`, `cosmos`. Type: `:prod`.
|
|
19
|
+
- **BNB Smart Chain (BSC)** validation — Ethereum-format addresses with the
|
|
20
|
+
EIP-55 checksum. Currency names: `bsc`, `binancesmartchain`. Type: `:bsc`.
|
|
21
|
+
|
|
22
|
+
[0.3.0]: https://github.com/vtm9/adequate_crypto_address/releases/tag/v0.3.0
|
|
23
|
+
|
|
8
24
|
## [0.2.0] - 2026-09-02
|
|
9
25
|
|
|
10
26
|
This release hardens the validators against malformed input found in the
|
data/README.md
CHANGED
|
@@ -4,7 +4,6 @@ AdequateCryptoAddress
|
|
|
4
4
|
|
|
5
5
|
[![Gem Version][gem-version-svg]][gem-version-link]
|
|
6
6
|
[![Build Status][build-status-svg]][build-status-link]
|
|
7
|
-
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
|
|
8
7
|
[![Coverage Status][coverage-status-svg]][coverage-status-link]
|
|
9
8
|
[![Downloads][downloads-svg]][downloads-link]
|
|
10
9
|
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
|
|
@@ -132,6 +131,10 @@ AdequateCryptoAddress.address_type('not a real address', :btc)
|
|
|
132
131
|
* Stellar/XLM, `'stellar'` or `'XLM'` types: `:account :muxed`
|
|
133
132
|
* Toncoin/TON, `'TON'` or `'Toncoin'` types: `:ton_mainnet :ton_testnet`
|
|
134
133
|
* Monero/XMR, `'monero'` or `'XMR'` types: `:standard :integrated :subaddress` (`.network` reports `:mainnet`/`:testnet`/`:stagenet`)
|
|
134
|
+
* TRON/TRX, `'tron'` or `'TRX'` type: `:prod`
|
|
135
|
+
* Tezos/XTZ, `'tezos'` or `'XTZ'` types: `:implicit :originated`
|
|
136
|
+
* Cosmos/ATOM, `'cosmos'` or `'ATOM'` type: `:prod`
|
|
137
|
+
* BNB Smart Chain/BSC, `'bsc'` or `'binancesmartchain'` type: `:bsc` (Ethereum-format address)
|
|
135
138
|
|
|
136
139
|
### Format coverage
|
|
137
140
|
|
|
@@ -264,16 +267,14 @@ Individual tasks are available as `mise run test`, `mise run lint`, and `mise ru
|
|
|
264
267
|
|
|
265
268
|
Bug reports and pull requests are welcome on GitHub at https://github.com/vtm9/adequate_crypto_address/issues
|
|
266
269
|
|
|
267
|
-
[gem-version-svg]: https://
|
|
270
|
+
[gem-version-svg]: https://img.shields.io/gem/v/adequate_crypto_address.svg
|
|
268
271
|
[gem-version-link]: https://rubygems.org/gems/adequate_crypto_address
|
|
269
|
-
[downloads-svg]:
|
|
272
|
+
[downloads-svg]: https://img.shields.io/gem/dt/adequate_crypto_address.svg
|
|
270
273
|
[downloads-link]: https://rubygems.org/gems/adequate_crypto_address
|
|
271
274
|
[build-status-svg]: https://github.com/vtm9/adequate_crypto_address/actions/workflows/ci.yml/badge.svg?branch=master
|
|
272
275
|
[build-status-link]: https://github.com/vtm9/adequate_crypto_address/actions/workflows/ci.yml
|
|
273
276
|
[coverage-status-svg]: https://coveralls.io/repos/vtm9/adequate_crypto_address/badge.svg?branch=master
|
|
274
277
|
[coverage-status-link]: https://coveralls.io/r/vtm9/adequate_crypto_address?branch=master
|
|
275
|
-
[codeclimate-status-svg]: https://codeclimate.com/github/vtm9/adequate_crypto_address.svg
|
|
276
|
-
[codeclimate-status-link]: https://codeclimate.com/github/vtm9/adequate_crypto_address
|
|
277
278
|
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
|
|
278
279
|
[docs-rubydoc-link]: http://www.rubydoc.info/gems/adequate_crypto_address/
|
|
279
280
|
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AdequateCryptoAddress
|
|
4
|
+
# Cosmos Hub (ATOM) account addresses are Bech32 (not Bech32m) with the
|
|
5
|
+
# `cosmos` human-readable part and a 20-byte address payload.
|
|
6
|
+
# https://docs.cosmos.network/main/build/spec/addresses/bech32
|
|
7
|
+
class Atom
|
|
8
|
+
HRP = 'cosmos'
|
|
9
|
+
PAYLOAD_BYTES = 20
|
|
10
|
+
MAX_LENGTH = 90
|
|
11
|
+
|
|
12
|
+
attr_reader :address, :type
|
|
13
|
+
|
|
14
|
+
def initialize(address)
|
|
15
|
+
@address = address
|
|
16
|
+
@type = detect_type
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def valid?(validated_type = nil)
|
|
20
|
+
return !type.nil? unless validated_type
|
|
21
|
+
|
|
22
|
+
type == validated_type.to_sym
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# :prod when the address is a valid cosmos account address, otherwise nil.
|
|
26
|
+
def address_type
|
|
27
|
+
type
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def detect_type
|
|
33
|
+
return nil if address.to_s.length > MAX_LENGTH
|
|
34
|
+
|
|
35
|
+
:prod if valid_bech32?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def valid_bech32?
|
|
39
|
+
decoded = Utils::Bech32.decode(address, include_encoding: true)
|
|
40
|
+
return false unless decoded
|
|
41
|
+
|
|
42
|
+
hrp, data, encoding = decoded
|
|
43
|
+
return false unless hrp == HRP && encoding == :bech32
|
|
44
|
+
|
|
45
|
+
bytes = Utils::Bech32.convert_bits(data, from_bits: 5, to_bits: 8, pad: false)
|
|
46
|
+
bytes&.length == PAYLOAD_BYTES
|
|
47
|
+
rescue StandardError
|
|
48
|
+
false
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
Cosmos = Atom
|
|
53
|
+
end
|
|
@@ -81,4 +81,13 @@ module AdequateCryptoAddress
|
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
Ethereum = Eth
|
|
84
|
+
|
|
85
|
+
# BNB Smart Chain uses the same address format and EIP-55 checksum as Ethereum.
|
|
86
|
+
class Bsc < Eth
|
|
87
|
+
def address_type
|
|
88
|
+
valid? ? :bsc : nil
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Binancesmartchain = Bsc
|
|
84
93
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AdequateCryptoAddress
|
|
4
|
+
# TRON mainnet addresses are Base58Check with the 0x41 version byte and a
|
|
5
|
+
# four-byte double-SHA256 checksum (25 bytes total, rendered as a 34-character
|
|
6
|
+
# string starting with "T"). https://developers.tron.network/docs/account
|
|
7
|
+
class Trx < Altcoin
|
|
8
|
+
ADDRESS_TYPES = { prod: %w[41] }.freeze
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
Tron = Trx
|
|
12
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AdequateCryptoAddress
|
|
4
|
+
# Tezos addresses are Base58Check with a four-byte double-SHA256 checksum and
|
|
5
|
+
# multi-byte version prefixes: tz1/tz2/tz3 implicit accounts and KT1 originated
|
|
6
|
+
# (contract) accounts, each wrapping a 20-byte hash (27 bytes total).
|
|
7
|
+
# https://tezos.gitlab.io/user/key-management.html
|
|
8
|
+
class Xtz < Altcoin
|
|
9
|
+
EXPECTED_LENGTH = 54 # 27 bytes rendered as hex
|
|
10
|
+
|
|
11
|
+
ADDRESS_TYPES = {
|
|
12
|
+
implicit: %w[06a19f 06a1a1 06a1a4], # tz1, tz2, tz3
|
|
13
|
+
originated: %w[025a79] # KT1
|
|
14
|
+
}.freeze
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Tezos = Xtz
|
|
18
|
+
end
|
|
@@ -19,6 +19,9 @@ require 'adequate_crypto_address/doge'
|
|
|
19
19
|
require 'adequate_crypto_address/sol'
|
|
20
20
|
require 'adequate_crypto_address/xlm'
|
|
21
21
|
require 'adequate_crypto_address/ada'
|
|
22
|
+
require 'adequate_crypto_address/trx'
|
|
23
|
+
require 'adequate_crypto_address/xtz'
|
|
24
|
+
require 'adequate_crypto_address/atom'
|
|
22
25
|
|
|
23
26
|
module AdequateCryptoAddress
|
|
24
27
|
class UnknownCurrency < StandardError; end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: adequate_crypto_address
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- vtm
|
|
@@ -50,6 +50,7 @@ files:
|
|
|
50
50
|
- lib/adequate_crypto_address.rb
|
|
51
51
|
- lib/adequate_crypto_address/ada.rb
|
|
52
52
|
- lib/adequate_crypto_address/altcoin.rb
|
|
53
|
+
- lib/adequate_crypto_address/atom.rb
|
|
53
54
|
- lib/adequate_crypto_address/bch.rb
|
|
54
55
|
- lib/adequate_crypto_address/btc.rb
|
|
55
56
|
- lib/adequate_crypto_address/dash.rb
|
|
@@ -58,6 +59,7 @@ files:
|
|
|
58
59
|
- lib/adequate_crypto_address/ltc.rb
|
|
59
60
|
- lib/adequate_crypto_address/sol.rb
|
|
60
61
|
- lib/adequate_crypto_address/ton.rb
|
|
62
|
+
- lib/adequate_crypto_address/trx.rb
|
|
61
63
|
- lib/adequate_crypto_address/utils/bch.rb
|
|
62
64
|
- lib/adequate_crypto_address/utils/bech32.rb
|
|
63
65
|
- lib/adequate_crypto_address/utils/monero_base58.rb
|
|
@@ -66,6 +68,7 @@ files:
|
|
|
66
68
|
- lib/adequate_crypto_address/xlm.rb
|
|
67
69
|
- lib/adequate_crypto_address/xmr.rb
|
|
68
70
|
- lib/adequate_crypto_address/xrp.rb
|
|
71
|
+
- lib/adequate_crypto_address/xtz.rb
|
|
69
72
|
- lib/adequate_crypto_address/zec.rb
|
|
70
73
|
homepage: https://github.com/vtm9/adequate_crypto_address
|
|
71
74
|
licenses:
|