ripple-address-codec
encodes/decodes base58 encoded XRP Ledger identifiers
Last updated 5 years ago by intelliot .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install ripple-address-codec 
SYNC missed versions from official npm registry.

ripple-address-codec NPM

Functions for encoding and decoding XRP Ledger addresses and seeds. Also includes support for encoding/decoding rippled validator (node) public keys.

X-address Conversion

All tools and apps in the XRP Ledger ecosystem are encouraged to adopt support for the X-address format. The X-address format is a single Base58 string that encodes an 'Account ID', a (destination) tag, and whether the address is intended for a test network. This prevents users from unintentionally omitting the destination tag when sending and receiving payments and other transactions.

API

classicAddressToXAddress(classicAddress: string, tag: number | false, test: boolean): string

Convert a classic address and (optional) tag to an X-address. If tag is false, the returned X-address explicitly indicates that the recipient does not want a tag to be used. If test is true, consumers of the address will know that the address is intended for use on test network(s) and the address will start with T.

> const api = require('ripple-address-codec')
> api.classicAddressToXAddress('rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf', 4294967295)
'XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi'

xAddressToClassicAddress(xAddress: string): {classicAddress: string, tag: number | false, test: boolean}

Convert an X-address to a classic address and tag. If the X-address did not have a tag, the returned object will not have a tag field. If the X-address is intended for use on test network(s), test will be true; if it is intended for use on the main network (mainnet), test will be false.

> const api = require('ripple-address-codec')
> rippleAddressCodec.xAddressToClassicAddress('XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi')
{
  classicAddress: 'rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf',
  tag: 4294967295,
  test: true
}

isValidXAddress(xAddress: string): boolean

Returns true if the provided X-address is valid, or false otherwise.

> const api = require('ripple-address-codec')
> api.isValidXAddress('XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi')
true

Other functions

> var api = require('ripple-address-codec');
> api.decodeSeed('sEdTM1uX8pu2do5XvTnutH6HsouMaM2')
{ version: [ 1, 225, 75 ],
  bytes: [ 76, 58, 29, 33, 63, 189, 251, 20, 199, 194, 141, 96, 148, 105, 179, 65 ],
  type: 'ed25519' }
> api.decodeSeed('sn259rEFXrQrWyx3Q7XneWcwV6dfL')
{ version: 33,
  bytes: [ 207, 45, 227, 120, 251, 221, 126, 46, 232, 125, 72, 109, 251, 90, 123, 255 ],
  type: 'secp256k1' }
> api.decodeAccountID('rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN')
[ 186,
  142,
  120,
  98,
  110,
  228,
  44,
  65,
  180,
  109,
  70,
  195,
  4,
  141,
  243,
  161,
  195,
  200,
  112,
  114 ]

Tests

Run unit tests with:

yarn test

Use --watch to run in watch mode, so that when you modify the tests, they are automatically re-run:

yarn test --watch

Use --coverage to generate and display code coverage information:

yarn test --coverage

This tells jest to output code coverage info in the ./coverage directory, in addition to showing it on the command line.

Acknowledgements

This library references and adopts code and standards from the following sources:

Current Tags

  • 5.0.0-beta.1                                ...           beta (a year ago)
  • 5.0.0                                ...           latest (9 months ago)

45 Versions

  • 5.0.0                                ...           9 months ago
  • 5.0.0-beta.1                                ...           a year ago
  • 5.0.0-beta.0                                ...           a year ago
  • 4.3.1                                ...           a year ago
  • 4.3.0                                ...           a year ago
  • 4.2.5                                ...           2 years ago
  • 4.2.4                                ...           3 years ago
  • 4.2.3                                ...           3 years ago
  • 4.2.2                                ...           3 years ago
  • 4.2.1                                ...           3 years ago
  • 4.2.1-beta.0                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.3                                ...           4 years ago
  • 4.1.2                                ...           4 years ago
  • 4.1.1                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 4.0.0-b6                                ...           5 years ago
  • 4.0.0-b5                                ...           5 years ago
  • 4.0.0-b4                                ...           5 years ago
  • 4.0.0-b3                                ...           5 years ago
  • 4.0.0-b2                                ...           5 years ago
  • 3.1.0-b2                                ...           5 years ago
  • 3.1.0-b1                                ...           5 years ago
  • 3.0.4                                ...           5 years ago
  • 3.0.3                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.6.0                                ...           9 years ago
  • 1.5.2                                ...           9 years ago
  • 1.5.1                                ...           9 years ago
  • 1.5.0                                ...           9 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.1                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.2                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Downloads
Total 38
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 31
Dependencies (3)
Dev Dependencies (7)

© 2010 - cnpmjs.org x YWFE | Home | YWFE