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

org.bitcoinj.crypto.BLSId Maven / Gradle / Ivy

There is a newer version: 21.1.2
Show newest version
package org.bitcoinj.crypto;

import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.ProtocolException;
import org.bitcoinj.core.Sha256Hash;

public class BLSId extends BLSAbstractObject {
    public static int BLS_CURVE_ID_SIZE  = 32;
    Sha256Hash hash;

    BLSId() {
        super(BLS_CURVE_ID_SIZE);
    }

    BLSId(Sha256Hash hash) {
        super(BLS_CURVE_ID_SIZE);
        valid = true;
        this.hash = Sha256Hash.wrap(hash.getBytes());
        updateHash();
    }

    public BLSId(NetworkParameters params, byte [] payload, int offset) {
        super(params, payload, offset, false);
    }

    @Override
    boolean internalSetBuffer(byte[] buffer) {
        try {
            hash = Sha256Hash.wrap(buffer);
            return true;
        } catch (Exception x) {
            return false;
        }
    }

    public static BLSId fromHash(Sha256Hash hash) {
        return new BLSId(hash);
    }

    @Override
    boolean internalGetBuffer(byte[] buffer, boolean legacy) {
        System.arraycopy(hash.getBytes(), 0, buffer, 0, buffer.length);
        return true;
    }

    @Override
    protected void parse() throws ProtocolException {
        byte[] buffer = readBytes(BLS_CURVE_ID_SIZE);
        internalSetBuffer(buffer);
        serializedSize = BLS_CURVE_ID_SIZE;
        length = cursor - offset;
    }

    public byte [] getBytes() {
        return hash.getBytes();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy