toBytes method

List<int> toBytes([
  1. PubKeyModes mode = PubKeyModes.compressed
])

Returns the public key as a list of bytes based on the specified mode.

This method converts the public key to a list of bytes based on the provided mode, which defaults to PubKeyMode.compressed if not specified. It performs different operations based on the algorithm's curve type and the specified mode, and returns the resulting bytes representing the public key.

mode The mode for encoding the public key (compressed or uncompressed). returns A list of bytes representing the public key.

Implementation

List<int> toBytes([PubKeyModes mode = PubKeyModes.compressed]) {
  if (algorithm.curveType == EllipticCurveTypes.ed25519) {
    return List.from([
      ...Ed25519KeysConst.xrpPubKeyPrefix,
      ..._publicKey.compressed.sublist(1)
    ]);
  }
  if (mode == PubKeyModes.compressed) {
    return _publicKey.compressed;
  }
  return _publicKey.uncompressed;
}