-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #17 Governance CDDL object and new certificates
- Loading branch information
Showing
59 changed files
with
1,434 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
core/src/main/java/com/bloxbean/cardano/yaci/core/model/Credential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.bloxbean.cardano.yaci.core.model; | ||
|
||
import co.nstant.in.cbor.model.Array; | ||
import co.nstant.in.cbor.model.ByteString; | ||
import co.nstant.in.cbor.model.DataItem; | ||
import co.nstant.in.cbor.model.UnsignedInteger; | ||
import com.bloxbean.cardano.client.crypto.Blake2bUtil; | ||
import com.bloxbean.cardano.client.crypto.VerificationKey; | ||
import com.bloxbean.cardano.yaci.core.exception.CborRuntimeException; | ||
import com.bloxbean.cardano.yaci.core.model.certs.StakeCredType; | ||
import com.bloxbean.cardano.yaci.core.util.CborSerializationUtil; | ||
import com.bloxbean.cardano.yaci.core.util.HexUtil; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class Credential { | ||
private StakeCredType type; | ||
private String hash; | ||
|
||
private Credential(StakeCredType type, byte[] hashBytes) { | ||
this.type = type; | ||
if (hashBytes != null) | ||
this.hash = HexUtil.encodeHexString(hashBytes); | ||
else | ||
this.hash = null; | ||
} | ||
|
||
public static Credential fromKey(VerificationKey vkey) { | ||
Credential stakeCredential = fromKey(vkey.getBytes()); | ||
return stakeCredential; | ||
} | ||
|
||
public static Credential fromKey(byte[] key) { | ||
byte[] keyHash = Blake2bUtil.blake2bHash224(key); | ||
Credential stakeCredential = new Credential(StakeCredType.ADDR_KEYHASH, keyHash); | ||
return stakeCredential; | ||
} | ||
|
||
public static Credential fromKeyHash(byte[] keyHash) { | ||
Credential stakeCredential = new Credential(StakeCredType.ADDR_KEYHASH, keyHash); | ||
return stakeCredential; | ||
} | ||
|
||
public static Credential fromScriptHash(byte[] scriptHash) { | ||
Credential stakeCredential = new Credential(StakeCredType.SCRIPTHASH, scriptHash); | ||
return stakeCredential; | ||
} | ||
|
||
public static Credential deserialize(Array stakeCredArray) { | ||
List<DataItem> dataItemList = stakeCredArray.getDataItems(); | ||
if (dataItemList == null || dataItemList.size() != 2) | ||
throw new CborRuntimeException("StakeCredential deserialization failed. Invalid number of DataItem(s) : " | ||
+ (dataItemList != null ? String.valueOf(dataItemList.size()) : null)); | ||
|
||
UnsignedInteger typeDI = (UnsignedInteger) dataItemList.get(0); | ||
ByteString hashDI = (ByteString) dataItemList.get(1); | ||
|
||
BigInteger typeBI = typeDI.getValue(); | ||
if (typeBI.intValue() == 0) { | ||
return Credential.fromKeyHash(hashDI.getBytes()); | ||
} else if (typeBI.intValue() == 1) { | ||
return Credential.fromScriptHash(hashDI.getBytes()); | ||
} else { | ||
throw new CborRuntimeException("StakeCredential deserialization failed. Invalid StakeCredType : " | ||
+ typeBI.intValue()); | ||
} | ||
} | ||
|
||
public Array serialize() { | ||
Array array = new Array(); | ||
if (type == StakeCredType.ADDR_KEYHASH) { | ||
array.add(new UnsignedInteger(0)); | ||
} else if (type == StakeCredType.SCRIPTHASH) { | ||
array.add(new UnsignedInteger(1)); | ||
} else { | ||
throw new CborRuntimeException("Invalid stake credential type : " + type); | ||
} | ||
|
||
array.add(new ByteString(HexUtil.decodeHexString(hash))); | ||
return array; | ||
} | ||
|
||
@JsonIgnore | ||
public String getCborHex() { | ||
return HexUtil.encodeHexString(CborSerializationUtil.serialize(serialize())); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
core/src/main/java/com/bloxbean/cardano/yaci/core/model/CredentialType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.bloxbean.cardano.yaci.core.model; | ||
|
||
public enum CredentialType { | ||
ADDR_KEYHASH, SCRIPTHASH | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/AuthCommitteeHotCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.Credential; | ||
import lombok.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class AuthCommitteeHotCert implements Certificate { | ||
private final CertificateType type = CertificateType.AUTH_COMMITTEE_HOT_CERT; | ||
|
||
private Credential committeeColdCredential; | ||
private Credential committeeHotCredential; | ||
} |
26 changes: 24 additions & 2 deletions
26
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/CertificateType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
public enum CertificateType { | ||
STAKE_REGISTRATION, STAKE_DEREGISTRATION, STAKE_DELEGATION, POOL_REGISTRATION, POOL_RETIREMENT, GENESIS_KEY_DELEGATION, | ||
MOVE_INSTATENEOUS_REWARDS_CERT | ||
STAKE_REGISTRATION, | ||
STAKE_DEREGISTRATION, | ||
STAKE_DELEGATION, | ||
POOL_REGISTRATION, | ||
POOL_RETIREMENT, | ||
GENESIS_KEY_DELEGATION, | ||
MOVE_INSTATENEOUS_REWARDS_CERT, | ||
|
||
//conway | ||
//Delegation certs | ||
REG_CERT, | ||
UNREG_CERT, | ||
VOTE_DELEG_CERT, | ||
STAKE_VOTE_DELEG_CERT, | ||
STAKE_REG_DELEG_CERT, | ||
VOTE_REG_DELEG_CERT, | ||
STAKE_VOTE_REG_DELEG_CERT, | ||
|
||
//Gov certs | ||
AUTH_COMMITTEE_HOT_CERT, | ||
RESIGN_COMMITTEE_COLD_CERT, | ||
REG_DREP_CERT, | ||
UNREG_DREP_CERT, | ||
UPDATE_DREP_CERT | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/RegCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class RegCert implements Certificate { | ||
private final CertificateType type = CertificateType.REG_CERT; | ||
|
||
private StakeCredential stakeCredential; | ||
private BigInteger coin; | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/RegDrepCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.Credential; | ||
import com.bloxbean.cardano.yaci.core.model.governance.Anchor; | ||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class RegDrepCert implements Certificate { | ||
private final CertificateType type = CertificateType.REG_DREP_CERT; | ||
|
||
private Credential drepCredential; | ||
private BigInteger coin; | ||
private Anchor anchor; | ||
} |
16 changes: 16 additions & 0 deletions
16
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/ResignCommitteeColdCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.Credential; | ||
import lombok.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class ResignCommitteeColdCert implements Certificate { | ||
private final CertificateType type = CertificateType.RESIGN_COMMITTEE_COLD_CERT; | ||
|
||
private Credential committeeColdCredential; | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/StakeRegDelegCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class StakeRegDelegCert implements Certificate { | ||
private final CertificateType type = CertificateType.STAKE_REG_DELEG_CERT; | ||
|
||
private StakeCredential stakeCredential; | ||
private String poolKeyHash; | ||
private BigInteger coin; | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/StakeVoteDelegCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.governance.Drep; | ||
import lombok.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class StakeVoteDelegCert implements Certificate { | ||
private final CertificateType type = CertificateType.STAKE_VOTE_DELEG_CERT; | ||
|
||
private StakeCredential stakeCredential; | ||
private String poolKeyHash; | ||
private Drep drep; | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/StakeVoteRegDelegCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.governance.Drep; | ||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class StakeVoteRegDelegCert implements Certificate { | ||
private final CertificateType type = CertificateType.STAKE_VOTE_REG_DELEG_CERT; | ||
|
||
private StakeCredential stakeCredential; | ||
private String poolKeyHash; | ||
private Drep drep; | ||
private BigInteger coin; | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/UnregCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class UnregCert implements Certificate { | ||
private final CertificateType type = CertificateType.UNREG_CERT; | ||
|
||
private StakeCredential stakeCredential; | ||
private BigInteger coin; | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/UnregDrepCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.Credential; | ||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class UnregDrepCert implements Certificate { | ||
private final CertificateType type = CertificateType.UNREG_DREP_CERT; | ||
|
||
private Credential drepCredential; | ||
private BigInteger coin; | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/UpdateDrepCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.Credential; | ||
import com.bloxbean.cardano.yaci.core.model.governance.Anchor; | ||
import lombok.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class UpdateDrepCert implements Certificate { | ||
private final CertificateType type = CertificateType.UPDATE_DREP_CERT; | ||
|
||
private Credential drepCredential; | ||
private Anchor anchor; | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/main/java/com/bloxbean/cardano/yaci/core/model/certs/VoteDelegCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.bloxbean.cardano.yaci.core.model.certs; | ||
|
||
import com.bloxbean.cardano.yaci.core.model.governance.Drep; | ||
import lombok.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class VoteDelegCert implements Certificate { | ||
private final CertificateType type = CertificateType.VOTE_DELEG_CERT; | ||
|
||
private StakeCredential stakeCredential; | ||
private Drep drep; | ||
} |
Oops, something went wrong.