Class: AddressCodec::XrpCodec
- Defined in:
- lib/address-codec/xrp_codec.rb
Direct Known Subclasses
Constant Summary collapse
- ACCOUNT_ID =
base58 encodings: xrpl.org/base58-encodings.html
0- ACCOUNT_PUBLIC_KEY =
Account address (20 bytes)
0x23- FAMILY_SEED =
Account public key (33 bytes)
0x21- NODE_PUBLIC =
33; Seed value (for secret keys) (16 bytes)
0x1c- ED25519_SEED =
28; Validation public key (33 bytes)
[0x01, 0xe1, 0x4b].freeze
Instance Method Summary collapse
-
#decode_account_id(account_id) ⇒ Array<Integer>
Decodes an account ID string into its underlying bytes.
-
#decode_account_public(base58string) ⇒ Array<Integer>
Decodes an account public key string into its underlying bytes.
-
#decode_node_public(base58string) ⇒ Array<Integer>
Decodes a node public key string into its underlying bytes.
-
#decode_seed(seed, opts = { version_types: ['ed25519', 'secp256k1'], versions: [ED25519_SEED, FAMILY_SEED], expected_length: 16 }) ⇒ Hash
Decodes a seed string into its underlying bytes and type.
-
#encode_account_id(bytes) ⇒ String
Encodes a byte array into an account ID string.
-
#encode_account_public(bytes) ⇒ String
Encodes a byte array into an account public key string.
-
#encode_node_public(bytes) ⇒ String
Encodes a byte array into a node public key string.
-
#encode_seed(entropy, type = nil) ⇒ String
Encodes entropy into a seed string.
-
#valid_classic_address?(address) ⇒ Boolean
Checks if a string is a valid classic XRPL address.
Methods inherited from Codec
#decode, #decode_checked, #encode, #encode_checked, #initialize
Constructor Details
This class inherits a constructor from AddressCodec::Codec
Instance Method Details
#decode_account_id(account_id) ⇒ Array<Integer>
Decodes an account ID string into its underlying bytes.
55 56 57 58 |
# File 'lib/address-codec/xrp_codec.rb', line 55 def decode_account_id(account_id) opts = { versions: [ACCOUNT_ID], expected_length: 20 } decode(account_id, opts)[:bytes] end |
#decode_account_public(base58string) ⇒ Array<Integer>
Decodes an account public key string into its underlying bytes.
87 88 89 90 |
# File 'lib/address-codec/xrp_codec.rb', line 87 def decode_account_public(base58string) opts = { versions: [ACCOUNT_PUBLIC_KEY], expected_length: 33 } decode(base58string, opts)[:bytes] end |
#decode_node_public(base58string) ⇒ Array<Integer>
Decodes a node public key string into its underlying bytes.
63 64 65 66 |
# File 'lib/address-codec/xrp_codec.rb', line 63 def decode_node_public(base58string) opts = { versions: [NODE_PUBLIC], expected_length: 33 } decode(base58string, opts)[:bytes] end |
#decode_seed(seed, opts = { version_types: ['ed25519', 'secp256k1'], versions: [ED25519_SEED, FAMILY_SEED], expected_length: 16 }) ⇒ Hash
Decodes a seed string into its underlying bytes and type.
36 37 38 39 40 41 42 |
# File 'lib/address-codec/xrp_codec.rb', line 36 def decode_seed(seed, opts = { version_types: ['ed25519', 'secp256k1'], versions: [ED25519_SEED, FAMILY_SEED], expected_length: 16 }) decode(seed, opts) end |
#encode_account_id(bytes) ⇒ String
Encodes a byte array into an account ID string.
47 48 49 50 |
# File 'lib/address-codec/xrp_codec.rb', line 47 def encode_account_id(bytes) opts = { versions: [ACCOUNT_ID], expected_length: 20 } encode(bytes, opts) end |
#encode_account_public(bytes) ⇒ String
Encodes a byte array into an account public key string.
79 80 81 82 |
# File 'lib/address-codec/xrp_codec.rb', line 79 def encode_account_public(bytes) opts = { versions: [ACCOUNT_PUBLIC_KEY], expected_length: 33 } encode(bytes, opts) end |
#encode_node_public(bytes) ⇒ String
Encodes a byte array into a node public key string.
71 72 73 74 |
# File 'lib/address-codec/xrp_codec.rb', line 71 def encode_node_public(bytes) opts = { versions: [NODE_PUBLIC], expected_length: 33 } encode(bytes, opts) end |
#encode_seed(entropy, type = nil) ⇒ String
Encodes entropy into a seed string.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/address-codec/xrp_codec.rb', line 18 def encode_seed(entropy, type = nil) unless check_byte_length(entropy, 16) raise 'entropy must have length 16' end opts = { expected_length: 16, versions: type == 'ed25519' ? ED25519_SEED : [FAMILY_SEED] } # prefixes entropy with version bytes encode(entropy, opts) end |
#valid_classic_address?(address) ⇒ Boolean
Checks if a string is a valid classic XRPL address.
95 96 97 98 99 100 101 102 |
# File 'lib/address-codec/xrp_codec.rb', line 95 def valid_classic_address?(address) begin decode_account_id(address) rescue return false end true end |