Signature.java

  1. package com.syntifi.near.api.model.key;

  2. import com.fasterxml.jackson.annotation.JsonCreator;
  3. import com.fasterxml.jackson.annotation.JsonValue;
  4. import com.syntifi.near.borshj.Borsh;
  5. import lombok.Builder;
  6. import lombok.EqualsAndHashCode;

  7. /**
  8.  * Holds a Near Signature
  9.  *
  10.  * @author Alexandre Carvalho
  11.  * @author Andre Bertolace
  12.  * @since 0.0.1
  13.  */
  14. @EqualsAndHashCode(callSuper = true)
  15. public class Signature extends KeySig implements Borsh {

  16.     private static final int SIGNATURE_SIZE = 64;

  17.     public Signature() {
  18.         // This solves the case for borsh deserialization for signatures of
  19.         // type ED25591 because to read the 'fixed' byte array we must know
  20.         // its size.
  21.         // If any other signature (and key) is implemented, a different
  22.         // approach is needed (like getters and setters annotation on borsh)
  23.         this.data = new byte[SIGNATURE_SIZE];
  24.     }

  25.     @Builder
  26.     public Signature(KeyType keyType, byte[] data) {
  27.         super(keyType, data);
  28.     }

  29.     @JsonCreator
  30.     public static Signature getPublicKeyFromJson(String base58String) {
  31.         return Signature.fromEncodedBase58String(base58String, Signature.class);
  32.     }

  33.     @JsonValue
  34.     public String getJsonPublicKey() {
  35.         return this.toEncodedBase58String();
  36.     }
  37. }