All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.civis.blockchain.ssm.client.domain.Agent Maven / Gradle / Ivy

Go to download

A SDK HTTP Client implementation to interact with signing state machines chaincode developped for Hyperleger Fabric.

The newest version!
package org.civis.blockchain.ssm.client.domain;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.bouncycastle.crypto.CryptoException;
import org.civis.blockchain.ssm.client.crypto.KeyPairReader;

import java.beans.Transient;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Objects;

public class Agent {

    public static Agent loadFromFile(String name) throws Exception {
        PublicKey pub = KeyPairReader.loadPublicKey(name);
        return new Agent(name, pub.getEncoded());
    }

    public static Agent loadFromFile(String name, String filename) throws Exception {
        PublicKey pub = KeyPairReader.loadPublicKey(filename);
        return new Agent(name, pub.getEncoded());
    }

    private String name;
    private byte[] pub;

    @JsonCreator
    public Agent(@JsonProperty("name") String name, @JsonProperty("pub") byte[] pub) {
        this.name = name;
        this.pub = pub;
    }

    public String getName() {
        return name;
    }

    public byte[] getPub() {
        return pub;
    }

    @Transient
    public PublicKey getPubAsKey() throws CryptoException {
        return KeyPairReader.fromByteArray(pub);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Agent agent = (Agent) o;
        return Objects.equals(name, agent.name) &&
                Arrays.equals(pub, agent.pub);
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(name);
        result = 31 * result + Arrays.hashCode(pub);
        return result;
    }

    @Override
    public String toString() {
        return "Agent{" +
                "name='" + name + '\'' +
                ", pub=" + Base64.getEncoder().encodeToString(pub) +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy