Class XrplBinaryCodec

java.lang.Object
org.xrpl.xrpl4j.codec.binary.XrplBinaryCodec

public class XrplBinaryCodec extends Object
  • Field Details

  • Constructor Details

    • XrplBinaryCodec

      public XrplBinaryCodec()
  • Method Details

    • getInstance

      public static XrplBinaryCodec getInstance()
      Get a singleton instance of XrplBinaryCodec.
      Returns:
      A singleton instance of XrplBinaryCodec.
    • encode

      public String encode(String json) throws com.fasterxml.jackson.core.JsonProcessingException
      Encodes JSON to canonical XRPL binary as a hex string.
      Parameters:
      json - A String containing JSON to be encoded.
      Returns:
      A String containing the hex-encoded representation of json.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if json is not valid JSON.
    • encodeForSigning

      public String encodeForSigning(String json) throws com.fasterxml.jackson.core.JsonProcessingException
      Encodes JSON to canonical XRPL binary as a hex string.
      Parameters:
      json - String containing JSON to be encoded.
      Returns:
      hex encoded representations
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if JSON is not valid.
    • encodeForMultiSigning

      public String encodeForMultiSigning(String json, String xrpAccountId) throws com.fasterxml.jackson.core.JsonProcessingException
      Encodes JSON to canonical XRPL binary as a hex string for signing purposes.
      Parameters:
      json - A String containing JSON to be encoded.
      xrpAccountId - A String containing the XRPL AccountId.
      Returns:
      hex encoded representations
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if JSON is not valid.
    • encodeForBatchInnerSigning

      public UnsignedByteArray encodeForBatchInnerSigning(Batch batch) throws com.fasterxml.jackson.core.JsonProcessingException
      Encodes a Batch transaction to canonical XRPL binary as a hex string for signing purposes. Note that this function slightly diverges from the pattern of the other encodeForSigning functions because the bytes to be signed for a Batch transaction are not simply the canonical binary representation of the JSON. Instead, we have distinct portions of the Batch transaction that are signed. Also, unlike encodeForSigning(String), which accepts JSON and then checks for JsonNode values, this implementation instead accepts a well-typed Java object and operates on that, for safety and correctness.
      Parameters:
      batch - A Batch containing JSON to be encoded.
      Returns:
      hex encoded representations
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if JSON is not valid.
    • encodeForBatchInnerMultiSigning

      public UnsignedByteArray encodeForBatchInnerMultiSigning(Batch batch, Address signerAddress) throws com.fasterxml.jackson.core.JsonProcessingException
      Encode a Batch for multi-signing by a specific signer. This is used when a multi-sig account acts as a BatchSigner with nested Signers. Per rippled's checkBatchMultiSign, this uses batch serialization (serializeBatch) followed by appending the signer's account ID (finishMultiSigningData).
      Parameters:
      batch - The Batch to encode.
      signerAddress - The address of the signer (will be appended as account ID suffix).
      Returns:
      An UnsignedByteArray containing the batch serialization with account ID suffix.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if there is an error processing the JSON.
    • encodeForSigningClaim

      public String encodeForSigningClaim(String json) throws com.fasterxml.jackson.core.JsonProcessingException
      Encodes JSON to canonical XRPL binary as a hex string for signing payment channel claims. The only JSON fields which will be encoded are "Channel" and "Amount".
      Parameters:
      json - String containing JSON to be encoded.
      Returns:
      The binary encoded JSON in hexadecimal form.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If the JSON is not valid.
    • decode

      public String decode(String encodedTransaction)
      Decodes canonical XRPL binary hex encoded transaction string to JSON.
      Parameters:
      encodedTransaction - A String value, in hex, to decode to JSON.
      Returns:
      A JSON String representing the decoded encodedTransaction.