2.3.0 • Published 2 months ago

ripple-binary-codec v2.3.0

Weekly downloads
17,283
License
ISC
Repository
github
Last release
2 months ago

ripple-binary-codec NPM

Functions to encode/decode to/from the ripple binary serialization format

NPM

API

> const api = require('ripple-binary-codec')

decode(binary: string): object

Decode a hex-string into a transaction object.

> api.decode('1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337')
{
  LedgerEntryType: 'AccountRoot',
  Flags: 0,
  Sequence: 1,
  PreviousTxnLgrSeq: 7,
  OwnerCount: 0,
  PreviousTxnID: 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
  Balance: '10000000000',
  Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv'
}

encode(json: object): string

Encode a transaction object into a hex-string. Note that encode filters out fields with undefined values.

> api.encode({
  LedgerEntryType: 'AccountRoot',
  Flags: 0,
  Sequence: 1,
  PreviousTxnLgrSeq: 7,
  OwnerCount: 0,
  PreviousTxnID: 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
  Balance: '10000000000',
  Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv' 
})
'1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337'

X-Address Compatibility

  • ripple-binary-codec handles X-addresses by looking for a few specific files (Account/SourceTag, Destination/DestinationTag).
  • If other fields (in the future) must to support X-addresses with tags, this library will need to be updated.
  • When decoding rippled binary, the output will always output classic address + tag, with no X-addresses. X-address support only applies when encoding to binary.

Encoding Currency Codes

  • The standard format for currency codes is a three-letter string such as USD. This is intended for use with ISO 4217 Currency Codes.
  • Currency codes must be exactly 3 ASCII characters in length and there are a few other rules.
  • ripple-binary-codec allows any 3-character ASCII string to be encoded as a currency code, although rippled may enforce tighter restrictions.
  • When decoding, if a currency code is three uppercase letters or numbers (/^[A-Z0-9]{3}$/), then it will be decoded into that string. For example,0000000000000000000000004142430000000000 decodes as ABC.
  • When decoding, if a currency code is does not match the regex, then it is not considered to be an ISO 4217 or pseudo-ISO currency. ripple-binary-codec will return a 160-bit hex-string (40 hex characters). For example, 0000000000000000000000006142430000000000 (aBC) decodes as 0000000000000000000000006142430000000000 because it contains a lowercase letter.

encodeForSigning(json: object): string

Encode the transaction object for signing.

encodeForSigningClaim(json: object): string

Encode the transaction object for payment channel claim.

encodeForMultisigning(json: object, signer: string): string

Encode the transaction object for multi-signing.

encodeQuality(value: string): string

> api.encodeQuality('195796912.5171664')
'5D06F4C3362FE1D0'

decodeQuality(value: string): string

> api.decodeQuality('5D06F4C3362FE1D0')
'195796912.5171664'

decodeLedgerData(binary: string): object

> api.decodeLedgerData("01E91435016340767BF1C4A3EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F873B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D521276CDE21276CE60A00")
{
  ledger_index: 32052277,
  total_coins: '99994494362043555',
  parent_hash: 'EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6',
  transaction_hash: 'DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F87',
  account_hash: '3B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D5',
  parent_close_time: 556231902,
  close_time: 556231910,
  close_time_resolution: 10,
  close_flags: 0
}

Tests

Run unit tests with:

npm test

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

npm test --coverage

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

@tyz-wallet/tyz-wallet-core-cryptoalebussesecux-connectcrypto-wallet-core-vitosxsj-devnode-blockchain-sdk@infinitebrahmanuniverse/nolb-rip@tequ/xrpl@everything-registry/sub-chunk-2670x-tokenizesxsjsxsj-appsxsj-nextsxsj-test@crossmarkio/xrpl-amm@crossmarkio/xrpl-sidechain@payburner/keyburner-corejachavaljichaolijiclibitgoiou-issuerripple-lib-1sologenic-ripple-lib-1-10-0-patchedsologenic-xrpl-stream-jssologenic-xrpl-stream-js-appsologenic-xrpl-stream-js-devsologenic-xrpl-stream-js-nextsologenic-xrpl-stream-js-nightlysologenic-nft-conversion-verifier@aqfr/aqfr-ripple-lib@aqfr/aqfr.js@adora-wallet/crypto-wallet-core@aloe2/sdk-coin-xrp@agoro-digital/xrpl-minter@bitgo-beta/sdk-coin-xrp@bitrupee/crypto-wallet-core@bitgo/sdk-coin-xrp@bithomp/xrpl-api@blockcore/crypto-wallet-core@chainz/moca-lib@abcpros/crypto-wallet-core@codewarriorr/live-common@coolwallet/xrp@coolwallets/xrpxpring-common-jsxrpl-crowdfund-backendxrpl-toolsxrp-replxrpl-validator-domainsxrpsignxrp-validation-loggerxrplxpopgen@ducatus/crypto-wallet-core@ducatus/ducatus-crypto-wallet-core-rev@ducatus/ducatuscore-crypto@gatehub/ripple-lib@futureverse/signer@lnssh/xrpl@ln1778/hwal@lnssh/hwal@ledgerhq/coin-xrp@keystonehq/keystone-sdk@ryan-bitgo/bitgo@o0o2022/crypto-wallet-core@o0o2022sg/crypto-wallet-core@owdin/live-common@secux/app-xrpmulticrypto-wallet-corenarademoscript-ripple-libsavour-snowsavourlabs-wallet-sdknbellanichnbellanich-1pkp-xrplpefish-ripple-libripple-sign-keypairsripple-zxlibripple-hashesripple-lib-1.6.5ripple-lib-2ripple-lib-compatripple-librippled-historical-databaserippled-ws-client-signripple-lib-orderbookripple-lib-peersaferippel-libripple-alpha-libriplle-libsilalvadohwalhw-ledger-providerhdwsdk@tatsujoestar/sdk-coin-xrp@swtrse/crypto-rpc@swtrse/crypto-wallet-core@xrpl-wallet-adapter/local-testonly@xrpl-wallet/adaptors
2.2.0

4 months ago

2.3.0-batch.0

2 months ago

2.3.0

2 months ago

4.0.1-mpt-beta

8 months ago

4.0.0-mpt-beta

8 months ago

1.0.3-mpt-beta

10 months ago

1.0.4-mpt-beta

10 months ago

2.1.0

11 months ago

1.0.1-mpt-beta

1 year ago

1.0.0-mpt-beta

1 year ago

2.0.0

1 year ago

1.11.0

1 year ago

2.0.0-beta.1

1 year ago

2.0.0-beta.0

2 years ago

1.10.0

2 years ago

1.8.0

2 years ago

1.6.0

2 years ago

1.9.0

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.10.0-beta.0

2 years ago

1.5.0-beta.4

2 years ago

1.4.3

2 years ago

1.5.0-beta.3

2 years ago

1.5.0-beta.2

2 years ago

1.6.0-beta.0

2 years ago

1.5.0-beta.0

3 years ago

1.5.0-beta.1

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.4-beta.1

3 years ago

1.1.4-beta.2

3 years ago

1.1.4-beta.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.1-beta.0

3 years ago

1.2.0

3 years ago

1.2.0-beta.1

3 years ago

1.1.3

4 years ago

1.1.3-beta.1

4 years ago

1.1.3-beta.0

4 years ago

1.1.2

4 years ago

1.1.2-beta.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.4-beta.1

4 years ago

1.1.0-beta.0

4 years ago

1.0.4-beta.0

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.7

5 years ago

1.0.0-rc3

5 years ago

1.0.0-rc2

5 years ago

1.0.0-rc1

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.3.0-rc1

5 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.5

8 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.7

9 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago